1
// Copyright (C) 2003 Dolphin Project.
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.
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.
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
15
// Official SVN repository and contact information can be found at
16
// http://code.google.com/p/dolphin-emu/
22
// x86/x64 ABI:s, and helpers to help follow them when JIT-ing code.
23
// All convensions return values in EAX (+ possibly EDX).
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
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
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
47
#ifdef _M_IX86 // 32 bit calling convention, shared by all
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
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.
58
#elif _M_X64 // 64 bit calling convention
60
#ifdef _WIN32 // 64-bit Windows - the really exotic calling convention
62
#define ABI_PARAM1 RCX
63
#define ABI_PARAM2 RDX
67
#else //64-bit Unix (hopefully MacOSX too)
69
#define ABI_PARAM1 RDI
70
#define ABI_PARAM2 RSI
71
#define ABI_PARAM3 RDX
72
#define ABI_PARAM4 RCX