2008-02-19 18:06:52 +00:00
|
|
|
/* Copyright (c) 2008, Avian Contributors
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2007-09-26 23:23:03 +00:00
|
|
|
#include "types.h"
|
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
#define LOCAL(x) .L##x
|
|
|
|
|
2007-09-26 23:23:03 +00:00
|
|
|
.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
|
|
|
|
|
2009-02-16 15:21:12 +00:00
|
|
|
// we use rbx to hold the thread pointer, by convention
|
2007-12-11 21:26:59 +00:00
|
|
|
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
|
2008-06-15 18:49:37 +00:00
|
|
|
jmp LOCAL(test)
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(loop):
|
2007-12-17 20:55:31 +00:00
|
|
|
push (%rdx,%r9,8)
|
|
|
|
inc %r9
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(test):
|
2007-12-11 21:26:59 +00:00
|
|
|
cmpq %rcx,%r9
|
2008-06-15 18:49:37 +00:00
|
|
|
jb LOCAL(loop)
|
2007-09-26 23:23:03 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2009-02-16 15:21:12 +00:00
|
|
|
// we use ebx to hold the thread pointer, by convention
|
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
|
2008-06-15 18:49:37 +00:00
|
|
|
jmp LOCAL(test)
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(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
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(test):
|
2007-12-11 21:26:59 +00:00
|
|
|
cmpl 20(%ebp),%ecx
|
2008-06-15 18:49:37 +00:00
|
|
|
jb LOCAL(loop)
|
2007-09-26 23:23:03 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(void):
|
2007-09-26 23:23:03 +00:00
|
|
|
cmpl $VOID_TYPE,%ecx
|
2008-06-15 18:49:37 +00:00
|
|
|
jne LOCAL(int64)
|
|
|
|
jmp LOCAL(exit)
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(int64):
|
2007-09-26 23:23:03 +00:00
|
|
|
cmpl $INT64_TYPE,%ecx
|
2008-06-15 18:49:37 +00:00
|
|
|
jne LOCAL(int32)
|
|
|
|
jmp LOCAL(exit)
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(int32):
|
2007-09-26 23:23:03 +00:00
|
|
|
movl $0,%edx
|
|
|
|
|
2008-06-15 18:49:37 +00:00
|
|
|
LOCAL(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
|