summaryrefslogtreecommitdiff
path: root/Source/Core/Common
diff options
context:
space:
mode:
authorhrydgard <hrydgard@gmail.com>2008-07-31 20:22:35 +0000
committerhrydgard <hrydgard@gmail.com>2008-07-31 20:22:35 +0000
commitd8fa3113ea34508dca2fc0acb0ae37d870235c3d (patch)
treeb101bbb69886fe1dccc835d5a44769664ba5de1f /Source/Core/Common
parent60ac064e0cac7dc814d07eed4c7f03911c9aeb3c (diff)
Cleanup, preparations for Linux/Mac JIT (not yet working)
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@114 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/Common')
-rw-r--r--Source/Core/Common/Common.vcproj12
-rw-r--r--Source/Core/Common/Src/ABI.cpp111
-rw-r--r--Source/Core/Common/Src/ABI.h93
-rw-r--r--Source/Core/Common/Src/SConscript3
-rw-r--r--Source/Core/Common/Src/x64Emitter.h7
5 files changed, 220 insertions, 6 deletions
diff --git a/Source/Core/Common/Common.vcproj b/Source/Core/Common/Common.vcproj
index 0e4a21c9fd..03d5d9dbca 100644
--- a/Source/Core/Common/Common.vcproj
+++ b/Source/Core/Common/Common.vcproj
@@ -448,6 +448,14 @@
</References>
<Files>
<File
+ RelativePath=".\Src\ABI.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Src\ABI.h"
+ >
+ </File>
+ <File
RelativePath=".\Src\Common.cpp"
>
</File>
@@ -560,6 +568,10 @@
>
</File>
<File
+ RelativePath=".\Src\SConscript"
+ >
+ </File>
+ <File
RelativePath=".\Src\stdafx.cpp"
>
<FileConfiguration
diff --git a/Source/Core/Common/Src/ABI.cpp b/Source/Core/Common/Src/ABI.cpp
new file mode 100644
index 0000000000..c182f5e0cb
--- /dev/null
+++ b/Source/Core/Common/Src/ABI.cpp
@@ -0,0 +1,111 @@
+#include "Common.h"
+#include "x64Emitter.h"
+#include "ABI.h"
+
+using namespace Gen;
+
+#ifdef _M_IX86 // All32
+
+// Shared code between Win32 and Unix32
+// ====================================
+
+void ABI_CallFunctionC(void *func, u32 param1) {
+ PUSH(32, Imm32(param1));
+ CALL(func);
+ ADD(32, R(ESP), Imm8(4));
+}
+
+void ABI_CallFunctionCC(void *func, u32 param1, u32 param2) {
+ PUSH(32, Imm32(param2));
+ PUSH(32, Imm32(param1));
+ CALL(func);
+ ADD(32, R(ESP), Imm8(8));
+}
+
+// Pass a register as a paremeter.
+void ABI_CallFunctionR(void *func, X64Reg reg1) {
+ PUSH(32, R(reg1));
+ CALL(func);
+ ADD(32, R(ESP), Imm8(4));
+}
+
+void ABI_PushAllCalleeSavedRegsAndAdjustStack() {
+ PUSH(EBP);
+ PUSH(EBX);
+ PUSH(ESI);
+ PUSH(EDI);
+}
+
+void ABI_PopAllCalleeSavedRegsAndAdjustStack() {
+ POP(EDI);
+ POP(ESI);
+ POP(EBX);
+ POP(EBP);
+}
+
+#else
+
+// Shared code between Win64 and Unix64
+// ====================================
+
+void ABI_CallFunctionC(void *func, u32 param1) {
+ MOV(32, R(ABI_PARAM1), Imm32(param1));
+ CALL(func);
+}
+
+void ABI_CallFunctionCC(void *func, u32 param1, u32 param2) {
+ MOV(32, R(ABI_PARAM1), Imm32(param1));
+ MOV(32, R(ABI_PARAM2), Imm32(param2));
+ CALL(func);
+}
+
+// Pass a register as a paremeter.
+void ABI_CallFunctionR(void *func, X64Reg reg1) {
+ if (reg1 != ABI_PARAM1)
+ MOV(32, R(ABI_PARAM1), R(reg1));
+ CALL(func);
+}
+
+#ifdef _WIN32
+// Win64 Specific Code
+// ====================================
+void ABI_PushAllCalleeSavedRegsAndAdjustStack() {
+ //we only want to do this once
+ PUSH(RBX);
+ PUSH(RSI);
+ PUSH(RDI);
+ PUSH(RBP);
+ PUSH(R12);
+ PUSH(R13);
+ PUSH(R14);
+ PUSH(R15);
+ //TODO: Also preserve XMM0-3?
+ SUB(64, R(RSP), Imm8(0x20));
+}
+
+void ABI_PopAllCalleeSavedRegsAndAdjustStack() {
+ ADD(64, R(RSP), Imm8(0x20));
+ POP(R15);
+ POP(R14);
+ POP(R13);
+ POP(R12);
+ POP(RBP);
+ POP(RDI);
+ POP(RSI);
+ POP(RBX);
+}
+
+#else
+// Unix64 Specific Code
+// ====================================
+void ABI_PushAllCalleeSavedRegsAndAdjustStack() {
+
+}
+
+void ABI_PopAllCalleeSavedRegsAndAdjustStack() {
+
+}
+
+#endif
+
+#endif \ No newline at end of file
diff --git a/Source/Core/Common/Src/ABI.h b/Source/Core/Common/Src/ABI.h
new file mode 100644
index 0000000000..1f610b6db1
--- /dev/null
+++ b/Source/Core/Common/Src/ABI.h
@@ -0,0 +1,93 @@
+// Copyright (C) 2003-2008 Dolphin Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official SVN repository and contact information can be found at
+// http://code.google.com/p/dolphin-emu/
+
+#ifndef _JIT_ABI_H
+#define _JIT_ABI_H
+
+#include "x64Emitter.h"
+
+// x86/x64 ABI:s, and helpers to help follow them when JIT-ing code.
+// All convensions return values in EAX (+ possibly EDX).
+
+// Linux 32-bit, Windows 32-bit (cdecl, System V):
+// * Caller pushes left to right
+// * Caller fixes stack after call
+// * function subtract from stack for local storage only.
+// Scratch: EAX ECX EDX
+// Callee-save: EBX ESI EDI EBP
+// Parameters: -
+
+// 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
+
+// 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
+
+#ifdef _M_IX86
+// 32 bit calling convention, shared by all
+
+// There are no ABI_PARAM* here, since args are pushed.
+
+// === 32-bit bog standard cdecl, shared between linux and windows ============================
+// MacOSX 32-bit is same as System V with a few exceptions that we probably don't care much about.
+
+#else
+// 64 bit calling convention
+
+#ifdef _WIN32
+// === 64-bit Windows - the really exotic calling convention ==================================
+
+#define ABI_PARAM1 RCX
+#define ABI_PARAM2 RDX
+#define ABI_PARAM3 R8
+#define ABI_PARAM4 R9
+
+#else
+// === 64-bit Unix (hopefully MacOSX too) =====================================================
+
+#define ABI_PARAM1 RDI
+#define ABI_PARAM2 RSI
+#define ABI_PARAM3 RDX
+#define ABI_PARAM4 RCX
+#define ABI_PARAM5 R8
+#define ABI_PARAM6 R9
+
+#endif
+
+#endif
+
+// Utility functions
+// These only support u32 parameters, but that's enough for a lot of uses.
+// These will destroy the 1 or 2 first "parameter regs".
+void ABI_CallFunctionC(void *func, u32 param1);
+void ABI_CallFunctionCC(void *func, u32 param1, u32 param2);
+
+// Pass a register as a paremeter.
+void ABI_CallFunctionR(void *func, Gen::X64Reg reg1);
+
+void ABI_PushAllCalleeSavedRegsAndAdjustStack();
+void ABI_PopAllCalleeSavedRegsAndAdjustStack();
+
+#endif // _JIT_ABI_H \ No newline at end of file
diff --git a/Source/Core/Common/Src/SConscript b/Source/Core/Common/Src/SConscript
index d14efd2c5d..839e7382b1 100644
--- a/Source/Core/Common/Src/SConscript
+++ b/Source/Core/Common/Src/SConscript
@@ -1,6 +1,7 @@
Import('env')
-files = ["Common.cpp",
+files = ["ABI.cpp",
+ "Common.cpp",
"CPUDetect.cpp",
"DynamicLibrary.cpp",
"Hash.cpp",
diff --git a/Source/Core/Common/Src/x64Emitter.h b/Source/Core/Common/Src/x64Emitter.h
index a3fe7b1198..a408b36adf 100644
--- a/Source/Core/Common/Src/x64Emitter.h
+++ b/Source/Core/Common/Src/x64Emitter.h
@@ -305,7 +305,7 @@ namespace Gen
void XCHG_AHAL();
void BSWAP(int bits, X64Reg reg);
- void MOVSX(int dbits, int sbits, X64Reg dest, OpArg src); //auto uses MOVSXD if necessary
+ void MOVSX(int dbits, int sbits, X64Reg dest, OpArg src); //automatically uses MOVSXD if necessary
void MOVZX(int dbits, int sbits, X64Reg dest, OpArg src);
enum SSECompare
@@ -320,13 +320,11 @@ namespace Gen
ORD,
};
-
- //SSE2
// WARNING - These two take 11-13 cycles and are VectorPath! (AMD64)
void STMXCSR(OpArg memloc);
void LDMXCSR(OpArg memloc);
- //Regular SSE instructions
+ // Regular SSE/SSE2 instructions
void ADDSS(X64Reg regOp, OpArg arg);
void ADDSD(X64Reg regOp, OpArg arg);
void SUBSS(X64Reg regOp, OpArg arg);
@@ -492,7 +490,6 @@ namespace Gen
void PMOVMSKB(X64Reg dest, OpArg arg);
-
namespace Util
{
// Sets up a __cdecl function.