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