x64ABI.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2008 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "Common/BitSet.h"
  5. #include "Common/x64Reg.h"
  6. // x64 ABI:s, and helpers to help follow them when JIT-ing code.
  7. // All convensions return values in EAX (+ possibly EDX).
  8. // Windows 64-bit
  9. // * 4-reg "fastcall" variant, very new-skool stack handling
  10. // * Callee moves stack pointer, to make room for shadow regs for the biggest function _it itself
  11. // calls_
  12. // * Parameters passed in RCX, RDX, ... further parameters are MOVed into the allocated stack space.
  13. // Scratch: RAX RCX RDX R8 R9 R10 R11
  14. // Callee-save: RBX RSI RDI RBP R12 R13 R14 R15
  15. // Parameters: RCX RDX R8 R9, further MOV-ed
  16. // Linux 64-bit
  17. // * 6-reg "fastcall" variant, old skool stack handling (parameters are pushed)
  18. // Scratch: RAX RCX RDX RSI RDI R8 R9 R10 R11
  19. // Callee-save: RBX RBP R12 R13 R14 R15
  20. // Parameters: RDI RSI RDX RCX R8 R9
  21. #define ABI_ALL_FPRS BitSet32(0xffff0000)
  22. #define ABI_ALL_GPRS BitSet32(0x0000ffff)
  23. #ifdef _WIN32 // 64-bit Windows - the really exotic calling convention
  24. #define ABI_PARAM1 RCX
  25. #define ABI_PARAM2 RDX
  26. #define ABI_PARAM3 R8
  27. #define ABI_PARAM4 R9
  28. // xmm0-xmm15 use the upper 16 bits in the functions that push/pop registers.
  29. #define ABI_ALL_CALLER_SAVED \
  30. (BitSet32{RAX, RCX, RDX, R8, R9, R10, R11, XMM0 + 16, XMM1 + 16, XMM2 + 16, XMM3 + 16, \
  31. XMM4 + 16, XMM5 + 16})
  32. #else // 64-bit Unix / OS X
  33. #define ABI_PARAM1 RDI
  34. #define ABI_PARAM2 RSI
  35. #define ABI_PARAM3 RDX
  36. #define ABI_PARAM4 RCX
  37. #define ABI_PARAM5 R8
  38. #define ABI_PARAM6 R9
  39. // FIXME: avoid pushing all 16 XMM registers when possible? most functions we call probably
  40. // don't actually clobber them.
  41. #define ABI_ALL_CALLER_SAVED (BitSet32{RAX, RCX, RDX, RDI, RSI, R8, R9, R10, R11} | ABI_ALL_FPRS)
  42. #endif // _WIN32
  43. #define ABI_ALL_CALLEE_SAVED (~ABI_ALL_CALLER_SAVED)
  44. #define ABI_RETURN RAX