abi.h 2.0 KB

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