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
|
|
|
|
|
|
|
|
// %rdi: function
|
|
|
|
// %rsi: stack
|
|
|
|
// %rdx: stackSize
|
|
|
|
// %rcx: returnType
|
|
|
|
|
|
|
|
// reserve space for arguments
|
|
|
|
subq %rdx,%rsp
|
|
|
|
|
|
|
|
// copy memory arguments into place
|
|
|
|
movq $0,%r8
|
|
|
|
jmp test
|
|
|
|
|
|
|
|
loop:
|
|
|
|
movq %r8,%rax
|
|
|
|
movq %r8,%r9
|
|
|
|
addq %rsp,%r9
|
|
|
|
addq %rsi,%rax
|
|
|
|
movq (%rax),%rax
|
|
|
|
movq %rax,(%r9)
|
|
|
|
addq $8,%r8
|
|
|
|
|
|
|
|
test:
|
|
|
|
cmpq %rdx,%r8
|
|
|
|
jb loop
|
|
|
|
|
|
|
|
// call function
|
|
|
|
call *%rdi
|
|
|
|
|
|
|
|
movq %rbp,%rsp
|
|
|
|
popq %rbp
|
|
|
|
ret
|
2007-10-04 00:41:54 +00:00
|
|
|
|
|
|
|
.globl vmJump
|
|
|
|
vmJump:
|
|
|
|
// %rdi: address
|
|
|
|
// %rsi: base
|
|
|
|
movq %rsi,%rsp
|
|
|
|
popq %rbp
|
|
|
|
jmp *(%rdi)
|
2007-09-26 23:23:03 +00:00
|
|
|
|
|
|
|
#elif defined __i386__
|
|
|
|
|
2007-10-04 00:41:54 +00:00
|
|
|
.globl vmInvoke
|
|
|
|
vmInvoke:
|
2007-09-26 23:23:03 +00:00
|
|
|
pushl %ebp
|
|
|
|
movl %esp,%ebp
|
|
|
|
|
|
|
|
// 8(%ebp): function
|
|
|
|
// 12(%ebp): stack
|
|
|
|
// 16(%ebp): stackSize
|
|
|
|
// 20(%ebp): returnType
|
|
|
|
|
|
|
|
// reserve space for arguments
|
|
|
|
movl 16(%ebp),%ecx
|
|
|
|
|
|
|
|
subl %ecx,%esp
|
|
|
|
|
|
|
|
// copy arguments into place
|
|
|
|
movl $0,%ecx
|
|
|
|
jmp test
|
|
|
|
|
|
|
|
loop:
|
|
|
|
movl %ecx,%eax
|
|
|
|
movl %ecx,%edx
|
|
|
|
addl %esp,%edx
|
|
|
|
addl 12(%ebp),%eax
|
|
|
|
movl (%eax),%eax
|
|
|
|
movl %eax,(%edx)
|
|
|
|
addl $4,%ecx
|
|
|
|
|
|
|
|
test:
|
|
|
|
cmpl 16(%ebp),%ecx
|
|
|
|
jb loop
|
|
|
|
|
|
|
|
// call function
|
|
|
|
call *8(%ebp)
|
|
|
|
|
|
|
|
// handle return value based on expected type
|
|
|
|
movl 20(%ebp),%ecx
|
|
|
|
|
|
|
|
void:
|
|
|
|
cmpl $VOID_TYPE,%ecx
|
|
|
|
jne int64
|
|
|
|
jmp exit
|
|
|
|
|
|
|
|
int64:
|
|
|
|
cmpl $INT64_TYPE,%ecx
|
|
|
|
jne int32
|
|
|
|
jmp exit
|
|
|
|
|
|
|
|
int32:
|
|
|
|
movl $0,%edx
|
|
|
|
|
|
|
|
exit:
|
|
|
|
movl %ebp,%esp
|
|
|
|
popl %ebp
|
|
|
|
ret
|
2007-10-04 00:41:54 +00:00
|
|
|
|
|
|
|
.globl vmJump
|
|
|
|
vmJump:
|
|
|
|
// 8(%ebp): address
|
|
|
|
// 12(%ebp): base
|
|
|
|
movq 8(%ebp),%eax
|
|
|
|
movq 12(%ebp),%rsp
|
|
|
|
popq %rbp
|
|
|
|
jmp *(%eax)
|
|
|
|
|
2007-09-26 23:23:03 +00:00
|
|
|
#else
|
|
|
|
# error unsupported platform
|
|
|
|
#endif
|