factor/vm/cpu-x86.32.S

125 lines
2.8 KiB
ArmAsm
Raw Normal View History

2007-09-21 22:56:01 -04:00
#include "asm.h"
#define ARG0 %eax
#define ARG1 %edx
#define ARG2 %ecx
2007-09-21 22:56:01 -04:00
#define STACK_REG %esp
2007-09-22 00:44:27 -04:00
#define DS_REG %esi
#define RS_REG %edi
2007-09-26 00:34:37 -04:00
#define RETURN_REG %eax
2007-09-21 22:56:01 -04:00
#define NV0 %ebx
#define NV1 %ebp
2008-11-08 21:32:23 -05:00
2007-09-21 22:56:01 -04:00
#define CELL_SIZE 4
2008-11-07 21:33:32 -05:00
#define STACK_PADDING 12
2007-09-21 22:56:01 -04:00
#define PUSH_NONVOLATILE \
2007-09-22 00:44:27 -04:00
push %ebx ; \
push %ebp ; \
push %esi ; \
push %edi
2007-09-21 22:56:01 -04:00
#define POP_NONVOLATILE \
pop %edi ; \
pop %esi ; \
2007-09-22 00:44:27 -04:00
pop %ebp ; \
2007-09-21 22:56:01 -04:00
pop %ebx
#define QUOT_XT_OFFSET 12
2007-09-21 22:56:01 -04:00
DEF(void,set_callstack,(void *vm, stack_frame *to, stack_frame *from, cell length, void *memcpy)):
mov 4(%esp),%ebx /* vm */
mov 8(%esp),%ebp /* to */
mov 12(%esp),%edx /* from */
mov 16(%esp),%ecx /* length */
mov 20(%esp),%eax /* memcpy */
2007-09-21 22:56:01 -04:00
sub %ecx,%ebp /* compute new stack pointer */
mov %ebp,%esp
push %ecx /* pass length */
push %edx /* pass src */
push %ebp /* pass dst */
call *%eax /* call memcpy */
add $12,%esp /* pop args from the stack */
mov (%ebx),%ebx /* load context */
mov 8(%ebx),DS_REG /* load datastack */
mov 12(%ebx),RS_REG /* load retainstack */
2007-09-21 22:56:01 -04:00
ret /* return _with new stack_ */
DEF(void,throw_impl,(cell quot, void *new_stack, void *vm)):
/* clear x87 stack, but preserve rounding mode and exception flags */
sub $2,%esp
fnstcw (%esp)
fninit
fldcw (%esp)
add $2,%esp
/* load quotation and vm parameters */
mov 4(%esp),%eax
mov 12(%esp),%edx
/* load new stack pointer */
mov 8(%esp),%esp
/* load context */
mov (%edx),%ebx
/* load datastack */
mov 8(%ebx),DS_REG
/* load retainstack */
mov 12(%ebx),RS_REG
/* call the error handler */
jmp *QUOT_XT_OFFSET(%eax)
DEF(VM_ASM_API void,lazy_jit_compile,(cell quot, void *vm)):
/* load context */
mov (ARG1),%ebx
/* save callstack */
lea -4(%esp),%ebp
mov %ebp,(%ebx)
/* save datastack */
mov DS_REG,8(%ebx)
/* save retainstack */
mov RS_REG,12(%ebx)
/* compile quotation */
sub $4,%esp
push ARG1
push ARG0
call MANGLE(lazy_jit_compile_impl)
add $12,%esp
/* call quotation */
jmp *QUOT_XT_OFFSET(%eax)
DEF(long long,read_timestamp_counter,(void)):
rdtsc
ret
DEF(void,get_sse_env,(void*)):
2009-09-14 04:14:48 -04:00
movl 4(%esp), %eax
stmxcsr (%eax)
ret
DEF(void,set_sse_env,(const void*)):
2009-09-14 04:14:48 -04:00
movl 4(%esp), %eax
ldmxcsr (%eax)
ret
DEF(void,get_x87_env,(void*)):
2009-09-14 04:14:48 -04:00
movl 4(%esp), %eax
fnstsw (%eax)
fnstcw 2(%eax)
ret
DEF(void,set_x87_env,(const void*)):
2009-09-14 04:14:48 -04:00
movl 4(%esp), %eax
fnclex
fldcw 2(%eax)
ret
2007-09-21 22:56:01 -04:00
#include "cpu-x86.S"
#ifdef WINDOWS
.section .drectve
2009-05-31 16:16:40 -04:00
.ascii " -export:read_timestamp_counter"
.ascii " -export:get_sse_env"
.ascii " -export:set_sse_env"
.ascii " -export:get_x87_env"
.ascii " -export:set_x87_env"
#endif