summaryrefslogtreecommitdiff
path: root/src/qcommon/vm_x86.c
diff options
context:
space:
mode:
authorThilo Schulz <arny@ats.s.bawue.de>2011-05-17 12:07:56 +0000
committerTim Angus <tim@ngus.net>2013-01-09 22:29:02 +0000
commit1078b66fb2e20c892937ae68a9beb2b0e72d7fd0 (patch)
tree5fcb42bbc0ee4fd88c847f604270394139208848 /src/qcommon/vm_x86.c
parent104c19ddaae1f7a7bac6c254afc2e7adba5688eb (diff)
- Use edx for CALLs instead of ecx, as the latter does not require any push to stack - Make Linux AT&T asm code consistent with the MASM codeblock
Diffstat (limited to 'src/qcommon/vm_x86.c')
-rw-r--r--src/qcommon/vm_x86.c43
1 files changed, 19 insertions, 24 deletions
diff --git a/src/qcommon/vm_x86.c b/src/qcommon/vm_x86.c
index 8a24c650..47c8b6c1 100644
--- a/src/qcommon/vm_x86.c
+++ b/src/qcommon/vm_x86.c
@@ -330,7 +330,7 @@ qboolean EmitMovEBXEDI(vm_t *vm, int andit) {
/*
=================
DoSyscall
-Uses asm to get arguments from stack to work around different calling conventions
+Uses asm to retrieve arguments from registers to work around different calling conventions
=================
*/
@@ -343,7 +343,6 @@ static void DoSyscall(void)
int programStack;
int *opStack;
- // Get arguments directly from registers to work around different calling conventions
#ifdef _MSC_VER
__asm
{
@@ -418,8 +417,8 @@ int EmitCallProcedure(vm_t *vm)
retval = compiledOfs;
EmitString("F7 D0"); // not eax
- // use ecx register to store DoSyscall address
- EmitString("B9"); // mov ecx, DoSyscall
+ // use edx register to store DoSyscall address
+ EmitString("BA"); // mov edx, DoSyscall
Emit4((intptr_t) DoSyscall);
// align the stack pointer to a 16-byte-boundary
@@ -428,7 +427,7 @@ int EmitCallProcedure(vm_t *vm)
EmitString("83 E4 F0"); // and esp, 0xFFFFFFF0
// call the syscall wrapper function
- EmitString("FF D1"); // call ecx
+ EmitString("FF D2"); // call edx
// reset the stack pointer to its previous value
EmitString("89 EC"); // mov esp, ebp
@@ -443,26 +442,24 @@ int EmitCallProcedure(vm_t *vm)
void EmitCall(vm_t *vm, int sysCallOfs)
{
- EmitString("51"); // push ecx
- EmitString("8B 0D"); // mov ecx, dword ptr [&vm->codeBase]
+ EmitString("8B 15"); // mov edx, [dword ptr vm->codeBase]
Emit4((intptr_t) &vm->codeBase);
if(sysCallOfs)
{
if(sysCallOfs < 0x80 || sysCallOfs > 0x7f)
{
- EmitString("83 C1"); // add ecx, sysCallOfs
+ EmitString("83 C2"); // add edx, sysCallOfs
Emit1(sysCallOfs);
}
else
{
- EmitString("81 C1"); // add ecx, sysCallOfs
+ EmitString("81 C2"); // add edx, sysCallOfs
Emit4(sysCallOfs);
}
}
- EmitString("FF D1"); // call ecx
- EmitString("59"); // pop ecx
+ EmitString("FF D2"); // call edx
}
/*
@@ -1259,7 +1256,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
break;
case OP_DIVI:
EmitString( "8B 47 FC" ); // mov eax,dword ptr [edi-4]
- EmitString( "99" ); // cdq
+ EmitString( "99" ); // cdq
EmitString( "F7 3F" ); // idiv dword ptr [edi]
EmitString( "89 47 FC" ); // mov dword ptr [edi-4],eax
EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4
@@ -1273,7 +1270,7 @@ void VM_Compile( vm_t *vm, vmHeader_t *header ) {
break;
case OP_MODI:
EmitString( "8B 47 FC" ); // mov eax,dword ptr [edi-4]
- EmitString( "99" ); // cdq
+ EmitString( "99" ); // cdq
EmitString( "F7 3F" ); // idiv dword ptr [edi]
EmitString( "89 57 FC" ); // mov dword ptr [edi-4],edx
EmitCommand(LAST_COMMAND_SUB_DI_4); // sub edi, 4
@@ -1547,18 +1544,16 @@ int VM_CallCompiled( vm_t *vm, int *args ) {
popad
}
#else
- /* These registers are used as scratch registers and are destroyed after the
- * call. Do not use clobber, so they can be used as input for the asm. */
- unsigned eax;
- unsigned ebx;
- unsigned ecx;
- unsigned edx;
-
__asm__ volatile(
- "call *%6"
- : "+S" (programStack), "+D" (opStack),
- "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
- : "mr" (vm->codeBase + vm->entryOfs)
+ "pushal\r\n"
+ "movl %0, %%esi\r\n"
+ "movl %1, %%edi\r\n"
+ "call *%2\r\n"
+ "movl %%edi, %1\r\n"
+ "movl %%esi, %0\r\n"
+ "popal\r\n"
+ : "+g" (programStack), "+g" (opStack)
+ : "g" (vm->codeBase + vm->entryOfs)
: "cc", "memory"
);
#endif