corda/src/compile.S

135 lines
1.9 KiB
ArmAsm
Raw Normal View History

#include "types.h"
.text
#ifdef __x86_64__
2007-10-04 00:41:54 +00:00
.globl vmInvoke
vmInvoke:
pushq %rbp
movq %rsp,%rbp
// push callee-saved registers
pushq %rbx
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
// copy arguments into place
pushq %rcx
2007-12-11 21:26:59 +00:00
movq $0,%r9
jmp test
loop:
push (%rdx,%r9,8)
inc %r9
test:
2007-12-11 21:26:59 +00:00
cmpq %rcx,%r9
jb loop
// call function
2007-12-11 21:26:59 +00:00
call *%rsi
// pop arguments
mov -48(%rbp),%rcx
2007-12-20 01:42:12 +00:00
sal $3,%rcx
addq %rcx,%rsp
// pop argument stack size
addq $8,%rsp
// pop callee-saved registers
popq %r15
popq %r14
popq %r13
popq %r12
popq %rbx
movq %rbp,%rsp
popq %rbp
ret
2007-10-04 00:41:54 +00:00
#elif defined __i386__
# if defined __APPLE__ || defined __MINGW32__
.globl _vmInvoke
_vmInvoke:
# else
2007-10-04 00:41:54 +00:00
.globl vmInvoke
vmInvoke:
# endif
pushl %ebp
movl %esp,%ebp
// 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
mov 8(%ebp),%ebx
// copy arguments into place
movl $0,%ecx
mov 16(%ebp),%edx
jmp test
loop:
2007-12-20 01:42:12 +00:00
push (%edx,%ecx,4)
inc %ecx
test:
2007-12-11 21:26:59 +00:00
cmpl 20(%ebp),%ecx
jb loop
// call function
2007-12-11 21:26:59 +00:00
call *12(%ebp)
// pop arguments
2007-12-20 01:42:12 +00:00
mov 20(%ebp),%ecx
sal $2,%ecx
addl %ecx,%esp
// handle return value based on expected type
2007-12-11 21:26:59 +00:00
movl 24(%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:
popl %edi
popl %esi
popl %ebx
movl %ebp,%esp
popl %ebp
ret
2007-10-04 00:41:54 +00:00
#else
# error unsupported platform
#endif