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-10-12 02:52:16 +00:00
|
|
|
// rbx is a callee-saved register (so are r12-r15, but we don't use those)
|
|
|
|
pushq %rbx
|
2007-12-11 21:26:59 +00:00
|
|
|
|
|
|
|
// %rdi: thread
|
|
|
|
// %rsi: function
|
|
|
|
// %rdx: stack
|
|
|
|
// %rcx: stackSize
|
|
|
|
// %r8 : returnType
|
|
|
|
|
|
|
|
mov %rdi,%rbx
|
2007-10-12 02:52:16 +00:00
|
|
|
|
2007-09-26 23:23:03 +00:00
|
|
|
// reserve space for arguments
|
2007-12-11 21:26:59 +00:00
|
|
|
pushq %rcx
|
|
|
|
subq %rcx,%rsp
|
2007-09-26 23:23:03 +00:00
|
|
|
|
|
|
|
// copy memory arguments into place
|
2007-12-11 21:26:59 +00:00
|
|
|
movq $0,%r9
|
2007-09-26 23:23:03 +00:00
|
|
|
jmp test
|
|
|
|
|
|
|
|
loop:
|
2007-12-11 21:26:59 +00:00
|
|
|
movq %r9,%rax
|
|
|
|
movq %r9,%r10
|
|
|
|
addq %rsp,%r10
|
|
|
|
addq %rdx,%rax
|
2007-09-26 23:23:03 +00:00
|
|
|
movq (%rax),%rax
|
2007-12-11 21:26:59 +00:00
|
|
|
movq %rax,(%r10)
|
|
|
|
addq $8,%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
|
|
|
|
addq -16(%rbp),%rsp
|
|
|
|
addq $8,%rsp
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-10-12 02:52:16 +00:00
|
|
|
popq %rbx
|
2007-09-26 23:23:03 +00:00
|
|
|
movq %rbp,%rsp
|
|
|
|
popq %rbp
|
|
|
|
ret
|
2007-10-04 00:41:54 +00:00
|
|
|
|
|
|
|
.globl vmJump
|
|
|
|
vmJump:
|
2007-10-04 22:41:19 +00:00
|
|
|
movq %rsi,%rbp
|
|
|
|
movq %rdx,%rsp
|
2007-12-16 01:00:25 +00:00
|
|
|
movq %rcx,%rbx
|
2007-10-04 22:41:19 +00:00
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
// reserve space for arguments
|
2007-12-11 21:26:59 +00:00
|
|
|
subl 20(%ebp),%esp
|
2007-09-26 23:23:03 +00:00
|
|
|
|
|
|
|
// copy arguments into place
|
|
|
|
movl $0,%ecx
|
|
|
|
jmp test
|
|
|
|
|
|
|
|
loop:
|
|
|
|
movl %ecx,%eax
|
|
|
|
movl %ecx,%edx
|
|
|
|
addl %esp,%edx
|
2007-12-11 21:26:59 +00:00
|
|
|
addl 16(%ebp),%eax
|
2007-09-26 23:23:03 +00:00
|
|
|
movl (%eax),%eax
|
|
|
|
movl %eax,(%edx)
|
|
|
|
addl $4,%ecx
|
|
|
|
|
|
|
|
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-11 21:26:59 +00:00
|
|
|
addl 20(%ebp),%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
|
|
|
|
|
|
|
.globl vmJump
|
|
|
|
vmJump:
|
2007-10-04 03:19:39 +00:00
|
|
|
movl 4(%esp),%eax
|
2007-10-04 22:41:19 +00:00
|
|
|
movl 8(%esp),%ebp
|
|
|
|
movl 12(%esp),%esp
|
2007-12-16 01:00:25 +00:00
|
|
|
movl 16(%esp),%ebx
|
2007-10-04 03:19:39 +00:00
|
|
|
jmp *%eax
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2007-09-26 23:23:03 +00:00
|
|
|
#else
|
|
|
|
# error unsupported platform
|
|
|
|
#endif
|