Kaydet (Commit) e8c13442 authored tarafından Herbert Dürr's avatar Herbert Dürr

on OSX the ECX register is not preserved for IA32 stdcalls

the function call convention for IA32 apps on OSX documented at
http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/LowLevelABI/130-IA-32_Function_Calling_Conventions/IA32.html
indicates that ECX is not preserved.
üst 68e707bb
...@@ -78,19 +78,22 @@ void callVirtualMethod( ...@@ -78,19 +78,22 @@ void callVirtualMethod(
// never called // never called
if (! pAdjustedThisPtr) CPPU_CURRENT_NAMESPACE::dummy_can_throw_anything("xxx"); // address something if (! pAdjustedThisPtr) CPPU_CURRENT_NAMESPACE::dummy_can_throw_anything("xxx"); // address something
// see the function call convention for IA32 apps on OSX at
// http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/LowLevelABI/130-IA-32_Function_Calling_Conventions/IA32.html
// though it mentions that virtual functions may use something different in practice both gcc and clang use the stdcall convention
volatile long edx = 0, eax = 0; // for register returns volatile long edx = 0, eax = 0; // for register returns
void * stackptr; void * stackptr;
asm volatile ( asm volatile (
"mov %%esp, %6\n\t" "mov %%esp, %6\n\t"
"mov %0, %%eax\n\t" "mov %0, %%eax\n\t"
"mov %%eax, %%edx\n\t" "mov %%eax, %%edx\n\t"
// stack padding to keep stack aligned: // padding to keep stack 16-byte aligned
"shl $2, %%eax\n\t" "shl $2, %%eax\n\t"
"neg %%eax\n\t" "neg %%eax\n\t"
"add %%esp, %%eax\n\t" "add %%esp, %%eax\n\t"
"and $0xf, %%eax\n\t" "and $0xf, %%eax\n\t"
"sub %%eax, %%esp\n\t" "sub %%eax, %%esp\n\t"
// copy: // push the arguments onto the stack
"mov %%edx, %%eax\n\t" "mov %%edx, %%eax\n\t"
"dec %%edx\n\t" "dec %%edx\n\t"
"shl $2, %%edx\n\t" "shl $2, %%edx\n\t"
...@@ -101,22 +104,22 @@ void callVirtualMethod( ...@@ -101,22 +104,22 @@ void callVirtualMethod(
"dec %%eax\n\t" "dec %%eax\n\t"
"jne Lcopy\n\t" "jne Lcopy\n\t"
// do the actual call // do the actual call
"mov %2, %%edx\n\t" "mov %2, %%edx\n\t" // edx = this
"mov 0(%%edx), %%edx\n\t" "mov 0(%%edx), %%edx\n\t" // edx = vtable
"mov %3, %%eax\n\t" "mov %3, %%eax\n\t"
"shl $2, %%eax\n\t" "shl $2, %%eax\n\t"
"add %%eax, %%edx\n\t" "add %%eax, %%edx\n\t" // func** edx = vtable[n]
"mov 0(%%edx), %%edx\n\t" "mov 0(%%edx), %%edx\n\t" // func* edx
"call *%%edx\n\t" "call *%%edx\n\t"
// save return registers // save return registers
"mov %%eax, %4\n\t" "mov %%eax, %4\n\t"
"mov %%edx, %5\n\t" "mov %%edx, %5\n\t"
// cleanup stack // restore stack
"mov %6, %%esp\n\t" "mov %6, %%esp\n\t"
: :
: "m"(nStackLongs), "m"(pStackLongs), "m"(pAdjustedThisPtr), : "m"(nStackLongs), "m"(pStackLongs), "m"(pAdjustedThisPtr),
"m"(nVtableIndex), "m"(eax), "m"(edx), "m"(stackptr) "m"(nVtableIndex), "m"(eax), "m"(edx), "m"(stackptr)
: "eax", "edx" ); : "eax", "ecx", "edx" );
switch( pReturnTypeDescr->eTypeClass ) switch( pReturnTypeDescr->eTypeClass )
{ {
case typelib_TypeClass_VOID: case typelib_TypeClass_VOID:
...@@ -124,6 +127,7 @@ void callVirtualMethod( ...@@ -124,6 +127,7 @@ void callVirtualMethod(
case typelib_TypeClass_HYPER: case typelib_TypeClass_HYPER:
case typelib_TypeClass_UNSIGNED_HYPER: case typelib_TypeClass_UNSIGNED_HYPER:
((long*)pRegisterReturn)[1] = edx; ((long*)pRegisterReturn)[1] = edx;
// fall through
case typelib_TypeClass_LONG: case typelib_TypeClass_LONG:
case typelib_TypeClass_UNSIGNED_LONG: case typelib_TypeClass_UNSIGNED_LONG:
case typelib_TypeClass_CHAR: case typelib_TypeClass_CHAR:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment