2007-09-26 23:23:03 +00:00
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
.text
|
|
|
|
|
|
|
|
#ifdef __x86_64__
|
|
|
|
|
2007-10-04 00:41:54 +00:00
|
|
|
.globl vmInvoke
|
|
|
|
vmInvoke:
|
2007-09-26 23:23:03 +00:00
|
|
|
pushq %rbp
|
|
|
|
movq %rsp,%rbp
|
|
|
|
|
2007-12-26 23:59:55 +00:00
|
|
|
// push callee-saved registers
|
2007-10-12 02:52:16 +00:00
|
|
|
pushq %rbx
|
2007-12-26 23:59:55 +00:00
|
|
|
pushq %r12
|
|
|
|
pushq %r13
|
|
|
|
pushq %r14
|
|
|
|
pushq %r15
|
2007-12-11 21:26:59 +00:00
|
|
|
|
|
|
|
// %rdi: thread
|
|
|
|
// %rsi: function
|
|
|
|
// %rdx: stack
|
|
|
|
// %rcx: stackSize
|
|
|
|
// %r8 : returnType
|
|
|
|
|
|
|
|
mov %rdi,%rbx
|
2007-12-20 01:42:12 +00:00
|
|
|
|
2007-12-26 23:59:55 +00:00
|
|
|
// copy arguments into place
|
2007-12-17 20:55:31 +00:00
|
|
|
pushq %rcx
|
2007-12-11 21:26:59 +00:00
|
|
|
movq $0,%r9
|
2007-09-26 23:23:03 +00:00
|
|
|
jmp test
|
|
|
|
|
|
|
|
loop:
|
2007-12-17 20:55:31 +00:00
|
|
|
push (%rdx,%r9,8)
|
|
|
|
inc %r9
|
2007-09-26 23:23:03 +00:00
|
|
|
|
|
|
|
test:
|
2007-12-11 21:26:59 +00:00
|
|
|
cmpq %rcx,%r9
|
2007-09-26 23:23:03 +00:00
|
|
|
jb loop
|
|
|
|
|
|
|
|
// call function
|
2007-12-11 21:26:59 +00:00
|
|
|
call *%rsi
|
2007-10-12 02:52:16 +00:00
|
|
|
|
|
|
|
// pop arguments
|
2007-12-26 23:59:55 +00:00
|
|
|
mov -48(%rbp),%rcx
|
2007-12-20 01:42:12 +00:00
|
|
|
sal $3,%rcx
|
|
|
|
addq %rcx,%rsp
|
|
|
|
|
|
|
|
// pop argument stack size
|
2007-10-12 02:52:16 +00:00
|
|
|
addq $8,%rsp
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-26 23:59:55 +00:00
|
|
|
// pop callee-saved registers
|
|
|
|
popq %r15
|
|
|
|
popq %r14
|
|
|
|
popq %r13
|
|
|
|
popq %r12
|
2007-10-12 02:52:16 +00:00
|
|
|
popq %rbx
|
2007-12-26 23:59:55 +00:00
|
|
|
|
2007-09-26 23:23:03 +00:00
|
|
|
movq %rbp,%rsp
|
|
|
|
popq %rbp
|
|
|
|
ret
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2007-09-26 23:23:03 +00:00
|
|
|
#elif defined __i386__
|
2007-12-20 23:22:40 +00:00
|
|
|
|
|
|
|
# if defined __APPLE__ || defined __MINGW32__
|
|
|
|
.globl _vmInvoke
|
|
|
|
_vmInvoke:
|
|
|
|
# else
|
2007-10-04 00:41:54 +00:00
|
|
|
.globl vmInvoke
|
|
|
|
vmInvoke:
|
2007-12-20 23:22:40 +00:00
|
|
|
# endif
|
2007-09-26 23:23:03 +00:00
|
|
|
pushl %ebp
|
|
|
|
movl %esp,%ebp
|
|
|
|
|
2007-10-12 02:52:16 +00:00
|
|
|
// ebx, esi and edi are callee-saved registers
|
|
|
|
pushl %ebx
|
|
|
|
pushl %esi
|
|
|
|
pushl %edi
|
|
|
|
|
2007-12-11 21:26:59 +00:00
|
|
|
// 8(%ebp): thread
|
|
|
|
// 12(%ebp): function
|
|
|
|
// 16(%ebp): stack
|
|
|
|
// 20(%ebp): stackSize
|
|
|
|
// 24(%ebp): returnType
|
|
|
|
|
2007-12-12 18:59:45 +00:00
|
|
|
mov 8(%ebp),%ebx
|
2007-09-26 23:23:03 +00:00
|
|
|
|
|
|
|
// copy arguments into place
|
|
|
|
movl $0,%ecx
|
2007-12-23 18:01:41 +00:00
|
|
|
mov 16(%ebp),%edx
|
2007-09-26 23:23:03 +00:00
|
|
|
jmp test
|
|
|
|
|
|
|
|
loop:
|
2007-12-20 01:42:12 +00:00
|
|
|
push (%edx,%ecx,4)
|
2007-12-17 20:55:31 +00:00
|
|
|
inc %ecx
|
2007-09-26 23:23:03 +00:00
|
|
|
|
|
|
|
test:
|
2007-12-11 21:26:59 +00:00
|
|
|
cmpl 20(%ebp),%ecx
|
2007-09-26 23:23:03 +00:00
|
|
|
jb loop
|
|
|
|
|
|
|
|
// call function
|
2007-12-11 21:26:59 +00:00
|
|
|
call *12(%ebp)
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-10-12 02:52:16 +00:00
|
|
|
// pop arguments
|
2007-12-20 01:42:12 +00:00
|
|
|
mov 20(%ebp),%ecx
|
|
|
|
sal $2,%ecx
|
|
|
|
addl %ecx,%esp
|
2007-10-12 02:52:16 +00:00
|
|
|
|
2007-09-26 23:23:03 +00:00
|
|
|
// handle return value based on expected type
|
2007-12-11 21:26:59 +00:00
|
|
|
movl 24(%ebp),%ecx
|
2007-09-26 23:23:03 +00:00
|
|
|
|
|
|
|
void:
|
|
|
|
cmpl $VOID_TYPE,%ecx
|
|
|
|
jne int64
|
|
|
|
jmp exit
|
|
|
|
|
|
|
|
int64:
|
|
|
|
cmpl $INT64_TYPE,%ecx
|
|
|
|
jne int32
|
|
|
|
jmp exit
|
|
|
|
|
|
|
|
int32:
|
|
|
|
movl $0,%edx
|
|
|
|
|
|
|
|
exit:
|
2007-10-12 02:52:16 +00:00
|
|
|
popl %edi
|
|
|
|
popl %esi
|
|
|
|
popl %ebx
|
2007-09-26 23:23:03 +00:00
|
|
|
movl %ebp,%esp
|
|
|
|
popl %ebp
|
|
|
|
ret
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2007-09-26 23:23:03 +00:00
|
|
|
#else
|
|
|
|
# error unsupported platform
|
|
|
|
#endif
|