]> gitweb.factorcode.org Git - factor.git/blob - vm/cpu-x86.32.S
factor out x86 and ppc backends for math.floats.env; update both x87 and SSE state...
[factor.git] / vm / cpu-x86.32.S
1 #include "asm.h"
2
3 #define ARG0 %eax
4 #define ARG1 %edx
5 #define STACK_REG %esp
6 #define DS_REG %esi
7 #define RETURN_REG %eax
8
9 #define NV_TEMP_REG %ebx
10
11 #define ARITH_TEMP_1 %ebp
12 #define ARITH_TEMP_2 %ebx
13 #define DIV_RESULT %eax
14
15 #define CELL_SIZE 4
16 #define STACK_PADDING 12
17
18 #define PUSH_NONVOLATILE \
19         push %ebx ; \
20         push %ebp ; \
21         push %ebp
22
23 #define POP_NONVOLATILE \
24         pop %ebp ; \
25         pop %ebp ; \
26         pop %ebx
27
28 #define QUOT_XT_OFFSET 12
29
30 /* We pass a function pointer to memcpy to work around a Mac OS X
31 ABI limitation which would otherwise require us to do a bizzaro PC-relative
32 trampoline to retrieve the function address */
33 DEF(void,set_callstack,(F_STACK_FRAME *to, F_STACK_FRAME *from, CELL length, void *memcpy)):
34         mov 4(%esp),%ebp                   /* to */
35         mov 8(%esp),%edx                   /* from */
36         mov 12(%esp),%ecx                  /* length */
37         mov 16(%esp),%eax                  /* memcpy */
38         sub %ecx,%ebp                      /* compute new stack pointer */
39         mov %ebp,%esp
40         push %ecx                          /* pass length */
41         push %edx                          /* pass src */
42         push %ebp                          /* pass dst */
43         call *%eax                         /* call memcpy */
44         add $12,%esp                       /* pop args from the stack */
45         ret                                /* return _with new stack_ */
46
47 /* cpu.x86.32 calls this */
48 DEF(bool,check_sse2,(void)):
49         push %ebx
50         mov $1,%eax
51         cpuid
52         shr $26,%edx
53         and $1,%edx
54         pop %ebx
55         mov %edx,%eax
56         ret
57
58 DEF(long long,read_timestamp_counter,(void)):
59         rdtsc
60         ret
61
62 DEF(void,primitive_inline_cache_miss,(void)):
63         mov (%esp),%ebx
64 DEF(void,primitive_inline_cache_miss_tail,(void)):
65         sub $8,%esp
66         push %ebx
67         call MANGLE(inline_cache_miss)
68         add $12,%esp
69         jmp *%eax
70
71 DEF(void,get_sse_env,(void*)):
72     movl 4(%esp), %eax
73     stmxcsr (%eax)
74     ret
75
76 DEF(void,set_sse_env,(const void*)):
77     movl 4(%esp), %eax
78     ldmxcsr (%eax)
79     ret
80
81 DEF(void,get_x87_env,(void*)):
82     movl 4(%esp), %eax
83     fnstsw (%eax)
84     fnstcw 2(%eax)
85     ret
86
87 DEF(void,set_x87_env,(const void*)):
88     movl 4(%esp), %eax
89     fldcw 2(%eax)
90     movb 4(%eax), %dl
91     test %dl, %dl
92     jz 1f
93     fnclex
94 1:
95     ret
96
97 #include "cpu-x86.S"
98
99 #ifdef WINDOWS
100         .section .drectve
101         .ascii " -export:check_sse2"
102         .ascii " -export:read_timestamp_counter"
103         .ascii " -export:get_sse_env"
104         .ascii " -export:set_sse_env"
105         .ascii " -export:get_x87_env"
106         .ascii " -export:set_x87_env"
107 #endif