diff options
Diffstat (limited to 'src/common/x64/abi.h')
| -rw-r--r-- | src/common/x64/abi.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/common/x64/abi.h b/src/common/x64/abi.h new file mode 100644 index 000000000..7e9c156ae --- /dev/null +++ b/src/common/x64/abi.h | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | // Copyright (C) 2003 Dolphin Project. | ||
| 2 | |||
| 3 | // This program is free software: you can redistribute it and/or modify | ||
| 4 | // it under the terms of the GNU General Public License as published by | ||
| 5 | // the Free Software Foundation, version 2.0 or later versions. | ||
| 6 | |||
| 7 | // This program is distributed in the hope that it will be useful, | ||
| 8 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 9 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 10 | // GNU General Public License 2.0 for more details. | ||
| 11 | |||
| 12 | // A copy of the GPL 2.0 should have been included with the program. | ||
| 13 | // If not, see http://www.gnu.org/licenses/ | ||
| 14 | |||
| 15 | // Official SVN repository and contact information can be found at | ||
| 16 | // http://code.google.com/p/dolphin-emu/ | ||
| 17 | |||
| 18 | #pragma once | ||
| 19 | |||
| 20 | #include "common/common_types.h" | ||
| 21 | |||
| 22 | // x86/x64 ABI:s, and helpers to help follow them when JIT-ing code. | ||
| 23 | // All convensions return values in EAX (+ possibly EDX). | ||
| 24 | |||
| 25 | // Linux 32-bit, Windows 32-bit (cdecl, System V): | ||
| 26 | // * Caller pushes left to right | ||
| 27 | // * Caller fixes stack after call | ||
| 28 | // * function subtract from stack for local storage only. | ||
| 29 | // Scratch: EAX ECX EDX | ||
| 30 | // Callee-save: EBX ESI EDI EBP | ||
| 31 | // Parameters: - | ||
| 32 | |||
| 33 | // Windows 64-bit | ||
| 34 | // * 4-reg "fastcall" variant, very new-skool stack handling | ||
| 35 | // * Callee moves stack pointer, to make room for shadow regs for the biggest function _it itself calls_ | ||
| 36 | // * Parameters passed in RCX, RDX, ... further parameters are MOVed into the allocated stack space. | ||
| 37 | // Scratch: RAX RCX RDX R8 R9 R10 R11 | ||
| 38 | // Callee-save: RBX RSI RDI RBP R12 R13 R14 R15 | ||
| 39 | // Parameters: RCX RDX R8 R9, further MOV-ed | ||
| 40 | |||
| 41 | // Linux 64-bit | ||
| 42 | // * 6-reg "fastcall" variant, old skool stack handling (parameters are pushed) | ||
| 43 | // Scratch: RAX RCX RDX RSI RDI R8 R9 R10 R11 | ||
| 44 | // Callee-save: RBX RBP R12 R13 R14 R15 | ||
| 45 | // Parameters: RDI RSI RDX RCX R8 R9 | ||
| 46 | |||
| 47 | #ifdef _M_IX86 // 32 bit calling convention, shared by all | ||
| 48 | |||
| 49 | // 32-bit don't pass parameters in regs, but these are convenient to have anyway when we have to | ||
| 50 | // choose regs to put stuff in. | ||
| 51 | #define ABI_PARAM1 RCX | ||
| 52 | #define ABI_PARAM2 RDX | ||
| 53 | |||
| 54 | // There are no ABI_PARAM* here, since args are pushed. | ||
| 55 | // 32-bit bog standard cdecl, shared between linux and windows | ||
| 56 | // MacOSX 32-bit is same as System V with a few exceptions that we probably don't care much about. | ||
| 57 | |||
| 58 | #elif ARCHITECTURE_x86_64 // 64 bit calling convention | ||
| 59 | |||
| 60 | #ifdef _WIN32 // 64-bit Windows - the really exotic calling convention | ||
| 61 | |||
| 62 | #define ABI_PARAM1 RCX | ||
| 63 | #define ABI_PARAM2 RDX | ||
| 64 | #define ABI_PARAM3 R8 | ||
| 65 | #define ABI_PARAM4 R9 | ||
| 66 | |||
| 67 | #else //64-bit Unix (hopefully MacOSX too) | ||
| 68 | |||
| 69 | #define ABI_PARAM1 RDI | ||
| 70 | #define ABI_PARAM2 RSI | ||
| 71 | #define ABI_PARAM3 RDX | ||
| 72 | #define ABI_PARAM4 RCX | ||
| 73 | #define ABI_PARAM5 R8 | ||
| 74 | #define ABI_PARAM6 R9 | ||
| 75 | |||
| 76 | #endif // WIN32 | ||
| 77 | |||
| 78 | #endif // X86 | ||