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