2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-10-17 02:21:55 +00:00
|
|
|
#include "Common/BitSet.h"
|
2016-09-01 00:51:02 +00:00
|
|
|
#include "Common/x64Reg.h"
|
2008-12-20 06:41:15 +00:00
|
|
|
|
2014-08-03 18:42:06 +00:00
|
|
|
// x64 ABI:s, and helpers to help follow them when JIT-ing code.
|
2008-07-31 20:22:35 +00:00
|
|
|
// All convensions return values in EAX (+ possibly EDX).
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2008-07-31 20:22:35 +00:00
|
|
|
// Windows 64-bit
|
|
|
|
// * 4-reg "fastcall" variant, very new-skool stack handling
|
|
|
|
// * Callee moves stack pointer, to make room for shadow regs for the biggest function _it itself
|
|
|
|
// calls_
|
|
|
|
// * Parameters passed in RCX, RDX, ... further parameters are MOVed into the allocated stack space.
|
|
|
|
// Scratch: RAX RCX RDX R8 R9 R10 R11
|
|
|
|
// Callee-save: RBX RSI RDI RBP R12 R13 R14 R15
|
|
|
|
// Parameters: RCX RDX R8 R9, further MOV-ed
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2008-07-31 20:22:35 +00:00
|
|
|
// Linux 64-bit
|
|
|
|
// * 6-reg "fastcall" variant, old skool stack handling (parameters are pushed)
|
|
|
|
// Scratch: RAX RCX RDX RSI RDI R8 R9 R10 R11
|
|
|
|
// Callee-save: RBX RBP R12 R13 R14 R15
|
|
|
|
// Parameters: RDI RSI RDX RCX R8 R9
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-10-17 02:21:55 +00:00
|
|
|
#define ABI_ALL_FPRS BitSet32(0xffff0000)
|
|
|
|
#define ABI_ALL_GPRS BitSet32(0x0000ffff)
|
|
|
|
|
2009-02-28 01:26:56 +00:00
|
|
|
#ifdef _WIN32 // 64-bit Windows - the really exotic calling convention
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2008-07-31 20:22:35 +00:00
|
|
|
#define ABI_PARAM1 RCX
|
|
|
|
#define ABI_PARAM2 RDX
|
|
|
|
#define ABI_PARAM3 R8
|
|
|
|
#define ABI_PARAM4 R9
|
2009-02-28 01:26:56 +00:00
|
|
|
|
2014-09-01 04:44:16 +00:00
|
|
|
// xmm0-xmm15 use the upper 16 bits in the functions that push/pop registers.
|
2014-10-17 02:21:55 +00:00
|
|
|
#define ABI_ALL_CALLER_SAVED \
|
|
|
|
(BitSet32{RAX, RCX, RDX, R8, R9, R10, R11, XMM0 + 16, XMM1 + 16, XMM2 + 16, XMM3 + 16, \
|
|
|
|
XMM4 + 16, XMM5 + 16})
|
2013-10-04 19:26:20 +00:00
|
|
|
#else // 64-bit Unix / OS X
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2008-07-31 20:22:35 +00:00
|
|
|
#define ABI_PARAM1 RDI
|
|
|
|
#define ABI_PARAM2 RSI
|
|
|
|
#define ABI_PARAM3 RDX
|
|
|
|
#define ABI_PARAM4 RCX
|
|
|
|
#define ABI_PARAM5 R8
|
|
|
|
#define ABI_PARAM6 R9
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-09-01 04:44:16 +00:00
|
|
|
// FIXME: avoid pushing all 16 XMM registers when possible? most functions we call probably
|
|
|
|
// don't actually clobber them.
|
2014-10-17 02:21:55 +00:00
|
|
|
#define ABI_ALL_CALLER_SAVED (BitSet32{RAX, RCX, RDX, RDI, RSI, R8, R9, R10, R11} | ABI_ALL_FPRS)
|
2024-08-13 04:38:03 +00:00
|
|
|
#endif // _WIN32
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-10-17 02:21:55 +00:00
|
|
|
#define ABI_ALL_CALLEE_SAVED (~ABI_ALL_CALLER_SAVED)
|
Improve code and clarify parameters to ABI_Push/PopRegistersAndAdjustStack.
- Factor common work into a helper function.
- Replace confusingly named "noProlog" with "rsp_alignment". Now that
x86 is not supported, we can just specify it explicitly as 8 for
clarity.
- Add the option to include more frame size, which I'll need later.
- Revert a change by magumagu in March which replaced MOVAPD with MOVUPD
on account of 32-bit Windows, since it's no longer supported. True,
apparently recent processors don't execute the former any faster if the
pointer is, in fact, aligned, but there's no point using MOVUPD for
something that's guaranteed to be aligned...
(I discovered that GenFrsqrte and GenFres were incorrectly passing false
to noProlog - they were, in fact, functions without prologs, the
original meaning of the parameter - which caused the previous change to
break. This is now fixed.)
2014-09-07 18:06:48 +00:00
|
|
|
|
2014-09-06 00:17:13 +00:00
|
|
|
#define ABI_RETURN RAX
|