Rebase from GCC
This commit is contained in:
@@ -45,6 +45,7 @@ _TEXT SEGMENT
|
||||
ffi_call_win32 PROC NEAR,
|
||||
ffi_prep_args : NEAR PTR DWORD,
|
||||
ecif : NEAR PTR DWORD,
|
||||
cif_abi : DWORD,
|
||||
cif_bytes : DWORD,
|
||||
cif_flags : DWORD,
|
||||
rvalue : NEAR PTR DWORD,
|
||||
@@ -64,6 +65,19 @@ ffi_call_win32 PROC NEAR,
|
||||
;; Return stack to previous state and call the function
|
||||
add esp, 8
|
||||
|
||||
;; Handle thiscall and fastcall
|
||||
cmp cif_abi, 3 ;; FFI_THISCALL
|
||||
jz do_thiscall
|
||||
cmp cif_abi, 4 ;; FFI_FASTCALL
|
||||
jnz do_stdcall
|
||||
mov ecx, DWORD PTR [esp]
|
||||
mov edx, DWORD PTR [esp+4]
|
||||
add esp, 8
|
||||
jmp do_stdcall
|
||||
do_thiscall:
|
||||
mov ecx, DWORD PTR [esp]
|
||||
add esp, 4
|
||||
do_stdcall:
|
||||
call fn
|
||||
|
||||
;; cdecl: we restore esp in the epilogue, so there's no need to
|
||||
@@ -405,7 +419,7 @@ _ffi_call_win32:
|
||||
movl %esp,%ebp
|
||||
.LCFI1:
|
||||
# Make room for all of the new args.
|
||||
movl 16(%ebp),%ecx
|
||||
movl 20(%ebp),%ecx
|
||||
subl %ecx,%esp
|
||||
|
||||
movl %esp,%eax
|
||||
@@ -417,19 +431,34 @@ _ffi_call_win32:
|
||||
|
||||
# Return stack to previous state and call the function
|
||||
addl $8,%esp
|
||||
|
||||
|
||||
# Handle fastcall and thiscall
|
||||
cmpl $3, 16(%ebp) # FFI_THISCALL
|
||||
jz .do_thiscall
|
||||
cmpl $4, 16(%ebp) # FFI_FASTCALL
|
||||
jnz .do_fncall
|
||||
movl (%esp), %ecx
|
||||
movl 4(%esp), %edx
|
||||
addl $8, %esp
|
||||
jmp .do_fncall
|
||||
.do_thiscall:
|
||||
movl (%esp), %ecx
|
||||
addl $4, %esp
|
||||
|
||||
.do_fncall:
|
||||
|
||||
# FIXME: Align the stack to a 128-bit boundary to avoid
|
||||
# potential performance hits.
|
||||
|
||||
call *28(%ebp)
|
||||
call *32(%ebp)
|
||||
|
||||
# stdcall functions pop arguments off the stack themselves
|
||||
|
||||
# Load %ecx with the return type code
|
||||
movl 20(%ebp),%ecx
|
||||
movl 24(%ebp),%ecx
|
||||
|
||||
# If the return value pointer is NULL, assume no return value.
|
||||
cmpl $0,24(%ebp)
|
||||
cmpl $0,28(%ebp)
|
||||
jne 0f
|
||||
|
||||
# Even if there is no space for the return value, we are
|
||||
@@ -488,50 +517,50 @@ _ffi_call_win32:
|
||||
|
||||
.Lretint:
|
||||
# Load %ecx with the pointer to storage for the return value
|
||||
movl 24(%ebp),%ecx
|
||||
movl 28(%ebp),%ecx
|
||||
movl %eax,0(%ecx)
|
||||
jmp .Lepilogue
|
||||
|
||||
.Lretfloat:
|
||||
# Load %ecx with the pointer to storage for the return value
|
||||
movl 24(%ebp),%ecx
|
||||
movl 28(%ebp),%ecx
|
||||
fstps (%ecx)
|
||||
jmp .Lepilogue
|
||||
|
||||
.Lretdouble:
|
||||
# Load %ecx with the pointer to storage for the return value
|
||||
movl 24(%ebp),%ecx
|
||||
movl 28(%ebp),%ecx
|
||||
fstpl (%ecx)
|
||||
jmp .Lepilogue
|
||||
|
||||
.Lretlongdouble:
|
||||
# Load %ecx with the pointer to storage for the return value
|
||||
movl 24(%ebp),%ecx
|
||||
movl 28(%ebp),%ecx
|
||||
fstpt (%ecx)
|
||||
jmp .Lepilogue
|
||||
|
||||
.Lretint64:
|
||||
# Load %ecx with the pointer to storage for the return value
|
||||
movl 24(%ebp),%ecx
|
||||
movl 28(%ebp),%ecx
|
||||
movl %eax,0(%ecx)
|
||||
movl %edx,4(%ecx)
|
||||
jmp .Lepilogue
|
||||
|
||||
.Lretstruct1b:
|
||||
# Load %ecx with the pointer to storage for the return value
|
||||
movl 24(%ebp),%ecx
|
||||
movl 28(%ebp),%ecx
|
||||
movb %al,0(%ecx)
|
||||
jmp .Lepilogue
|
||||
|
||||
.Lretstruct2b:
|
||||
# Load %ecx with the pointer to storage for the return value
|
||||
movl 24(%ebp),%ecx
|
||||
movl 28(%ebp),%ecx
|
||||
movw %ax,0(%ecx)
|
||||
jmp .Lepilogue
|
||||
|
||||
.Lretstruct4b:
|
||||
# Load %ecx with the pointer to storage for the return value
|
||||
movl 24(%ebp),%ecx
|
||||
movl 28(%ebp),%ecx
|
||||
movl %eax,0(%ecx)
|
||||
jmp .Lepilogue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user