]> gitweb.factorcode.org Git - factor.git/blob - vm/cpu-x86.32.S
042924ca4f5a04bb543255d44c5bb22fd77aa0d3
[factor.git] / vm / cpu-x86.32.S
1 #include "asm.h"
2
3 #define ARG0 %eax
4 #define ARG1 %edx
5 #define ARG2 %ecx
6 #define STACK_REG %esp
7 #define DS_REG %esi
8 #define RETURN_REG %eax
9
10 #define NV_TEMP_REG %ebx
11
12 #define ARITH_TEMP_1 %ebp
13 #define ARITH_TEMP_2 %ebx
14 #define DIV_RESULT %eax
15
16 #define CELL_SIZE 4
17 #define STACK_PADDING 12
18
19 #define PUSH_NONVOLATILE \
20         push %ebx ; \
21         push %ebp ; \
22         push %ebp
23
24 #define POP_NONVOLATILE \
25         pop %ebp ; \
26         pop %ebp ; \
27         pop %ebx
28
29 #define QUOT_XT_OFFSET 12
30
31 /* We pass a function pointer to memcpy to work around a Mac OS X
32 ABI limitation which would otherwise require us to do a bizzaro PC-relative
33 trampoline to retrieve the function address */
34 DEF(void,set_callstack,(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy)):
35         mov 4(%esp),%ebp                   /* to */
36         mov 8(%esp),%edx                   /* from */
37         mov 12(%esp),%ecx                  /* length */
38         mov 16(%esp),%eax                  /* memcpy */
39         sub %ecx,%ebp                      /* compute new stack pointer */
40         mov %ebp,%esp
41         push %ecx                          /* pass length */
42         push %edx                          /* pass src */
43         push %ebp                          /* pass dst */
44         call *%eax                         /* call memcpy */
45         add $12,%esp                       /* pop args from the stack */
46         ret                                /* return _with new stack_ */
47
48 DEF(long long,read_timestamp_counter,(void)):
49         rdtsc
50         ret
51
52 DEF(void,primitive_inline_cache_miss,(void *vm)):
53         mov (%esp),%ebx
54 DEF(void,primitive_inline_cache_miss_tail,(void *vm)):
55         sub $8,%esp
56         push ARG0   /* push vm ptr */
57         push %ebx
58         call MANGLE(inline_cache_miss)
59         add $16,%esp
60         jmp *%eax
61
62 DEF(void,get_sse_env,(void*)):
63         movl 4(%esp), %eax
64         stmxcsr (%eax)
65         ret
66
67 DEF(void,set_sse_env,(const void*)):
68         movl 4(%esp), %eax
69         ldmxcsr (%eax)
70         ret
71
72 DEF(void,get_x87_env,(void*)):
73         movl 4(%esp), %eax
74         fnstsw (%eax)
75         fnstcw 2(%eax)
76         ret
77
78 DEF(void,set_x87_env,(const void*)):
79         movl 4(%esp), %eax
80         fnclex
81         fldcw 2(%eax)
82         ret
83
84 DEF(F_FASTCALL void,throw_impl,(CELL quot, F_STACK_FRAME *rewind_to, void *vm)):
85         mov CELL_SIZE(STACK_REG),NV_TEMP_REG  /* get vm ptr in case quot_xt = lazy_jit_compile */               
86         /* clear x87 stack, but preserve rounding mode and exception flags */
87         sub $2,STACK_REG
88         fnstcw (STACK_REG)
89         fninit
90         fldcw (STACK_REG)
91         /* rewind_to */
92         mov ARG1,STACK_REG
93         mov NV_TEMP_REG,ARG1
94         jmp *QUOT_XT_OFFSET(ARG0)
95
96
97 DEF(F_FASTCALL void,lazy_jit_compile,(CELL quot, void *vm)):
98         mov ARG1,NV_TEMP_REG         /* stash vm ptr */
99         mov STACK_REG,ARG1           /* Save stack pointer */
100         sub $STACK_PADDING,STACK_REG
101         push NV_TEMP_REG             /* push vm ptr as arg3 */
102         call MANGLE(lazy_jit_compile_impl)
103         pop NV_TEMP_REG
104         mov RETURN_REG,ARG0          /* No-op on 32-bit */
105         add $STACK_PADDING,STACK_REG
106         jmp *QUOT_XT_OFFSET(ARG0)    /* Call the quotation */
107
108         
109 #include "cpu-x86.S"
110
111 #ifdef WINDOWS
112         .section .drectve
113         .ascii " -export:read_timestamp_counter"
114         .ascii " -export:get_sse_env"
115         .ascii " -export:set_sse_env"
116         .ascii " -export:get_x87_env"
117         .ascii " -export:set_x87_env"
118 #endif