root / target-i386 / exec.h @ 95ea3fa1
History | View | Annotate | Download (12.9 kB)
1 | 2c0262af | bellard | /*
|
---|---|---|---|
2 | 2c0262af | bellard | * i386 execution defines
|
3 | 2c0262af | bellard | *
|
4 | 2c0262af | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 2c0262af | bellard | *
|
6 | 2c0262af | bellard | * This library is free software; you can redistribute it and/or
|
7 | 2c0262af | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | 2c0262af | bellard | * License as published by the Free Software Foundation; either
|
9 | 2c0262af | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | 2c0262af | bellard | *
|
11 | 2c0262af | bellard | * This library is distributed in the hope that it will be useful,
|
12 | 2c0262af | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 2c0262af | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 2c0262af | bellard | * Lesser General Public License for more details.
|
15 | 2c0262af | bellard | *
|
16 | 2c0262af | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | 2c0262af | bellard | * License along with this library; if not, write to the Free Software
|
18 | 2c0262af | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | 2c0262af | bellard | */
|
20 | 7d3505c5 | bellard | #include "config.h" |
21 | 2c0262af | bellard | #include "dyngen-exec.h" |
22 | 2c0262af | bellard | |
23 | 2c0262af | bellard | /* at least 4 register variables are defines */
|
24 | 2c0262af | bellard | register struct CPUX86State *env asm(AREG0); |
25 | 2c0262af | bellard | register uint32_t T0 asm(AREG1); |
26 | 2c0262af | bellard | register uint32_t T1 asm(AREG2); |
27 | 2c0262af | bellard | register uint32_t T2 asm(AREG3); |
28 | 2c0262af | bellard | |
29 | 2c0262af | bellard | #define A0 T2
|
30 | 2c0262af | bellard | |
31 | 2c0262af | bellard | /* if more registers are available, we define some registers too */
|
32 | 2c0262af | bellard | #ifdef AREG4
|
33 | 2c0262af | bellard | register uint32_t EAX asm(AREG4); |
34 | 2c0262af | bellard | #define reg_EAX
|
35 | 2c0262af | bellard | #endif
|
36 | 2c0262af | bellard | |
37 | 2c0262af | bellard | #ifdef AREG5
|
38 | 2c0262af | bellard | register uint32_t ESP asm(AREG5); |
39 | 2c0262af | bellard | #define reg_ESP
|
40 | 2c0262af | bellard | #endif
|
41 | 2c0262af | bellard | |
42 | 2c0262af | bellard | #ifdef AREG6
|
43 | 2c0262af | bellard | register uint32_t EBP asm(AREG6); |
44 | 2c0262af | bellard | #define reg_EBP
|
45 | 2c0262af | bellard | #endif
|
46 | 2c0262af | bellard | |
47 | 2c0262af | bellard | #ifdef AREG7
|
48 | 2c0262af | bellard | register uint32_t ECX asm(AREG7); |
49 | 2c0262af | bellard | #define reg_ECX
|
50 | 2c0262af | bellard | #endif
|
51 | 2c0262af | bellard | |
52 | 2c0262af | bellard | #ifdef AREG8
|
53 | 2c0262af | bellard | register uint32_t EDX asm(AREG8); |
54 | 2c0262af | bellard | #define reg_EDX
|
55 | 2c0262af | bellard | #endif
|
56 | 2c0262af | bellard | |
57 | 2c0262af | bellard | #ifdef AREG9
|
58 | 2c0262af | bellard | register uint32_t EBX asm(AREG9); |
59 | 2c0262af | bellard | #define reg_EBX
|
60 | 2c0262af | bellard | #endif
|
61 | 2c0262af | bellard | |
62 | 2c0262af | bellard | #ifdef AREG10
|
63 | 2c0262af | bellard | register uint32_t ESI asm(AREG10); |
64 | 2c0262af | bellard | #define reg_ESI
|
65 | 2c0262af | bellard | #endif
|
66 | 2c0262af | bellard | |
67 | 2c0262af | bellard | #ifdef AREG11
|
68 | 2c0262af | bellard | register uint32_t EDI asm(AREG11); |
69 | 2c0262af | bellard | #define reg_EDI
|
70 | 2c0262af | bellard | #endif
|
71 | 2c0262af | bellard | |
72 | 2c0262af | bellard | extern FILE *logfile;
|
73 | 2c0262af | bellard | extern int loglevel; |
74 | 2c0262af | bellard | |
75 | 2c0262af | bellard | #ifndef reg_EAX
|
76 | 2c0262af | bellard | #define EAX (env->regs[R_EAX])
|
77 | 2c0262af | bellard | #endif
|
78 | 2c0262af | bellard | #ifndef reg_ECX
|
79 | 2c0262af | bellard | #define ECX (env->regs[R_ECX])
|
80 | 2c0262af | bellard | #endif
|
81 | 2c0262af | bellard | #ifndef reg_EDX
|
82 | 2c0262af | bellard | #define EDX (env->regs[R_EDX])
|
83 | 2c0262af | bellard | #endif
|
84 | 2c0262af | bellard | #ifndef reg_EBX
|
85 | 2c0262af | bellard | #define EBX (env->regs[R_EBX])
|
86 | 2c0262af | bellard | #endif
|
87 | 2c0262af | bellard | #ifndef reg_ESP
|
88 | 2c0262af | bellard | #define ESP (env->regs[R_ESP])
|
89 | 2c0262af | bellard | #endif
|
90 | 2c0262af | bellard | #ifndef reg_EBP
|
91 | 2c0262af | bellard | #define EBP (env->regs[R_EBP])
|
92 | 2c0262af | bellard | #endif
|
93 | 2c0262af | bellard | #ifndef reg_ESI
|
94 | 2c0262af | bellard | #define ESI (env->regs[R_ESI])
|
95 | 2c0262af | bellard | #endif
|
96 | 2c0262af | bellard | #ifndef reg_EDI
|
97 | 2c0262af | bellard | #define EDI (env->regs[R_EDI])
|
98 | 2c0262af | bellard | #endif
|
99 | 2c0262af | bellard | #define EIP (env->eip)
|
100 | 2c0262af | bellard | #define DF (env->df)
|
101 | 2c0262af | bellard | |
102 | 2c0262af | bellard | #define CC_SRC (env->cc_src)
|
103 | 2c0262af | bellard | #define CC_DST (env->cc_dst)
|
104 | 2c0262af | bellard | #define CC_OP (env->cc_op)
|
105 | 2c0262af | bellard | |
106 | 2c0262af | bellard | /* float macros */
|
107 | 2c0262af | bellard | #define FT0 (env->ft0)
|
108 | 2c0262af | bellard | #define ST0 (env->fpregs[env->fpstt])
|
109 | 2c0262af | bellard | #define ST(n) (env->fpregs[(env->fpstt + (n)) & 7]) |
110 | 2c0262af | bellard | #define ST1 ST(1) |
111 | 2c0262af | bellard | |
112 | 2c0262af | bellard | #ifdef USE_FP_CONVERT
|
113 | 2c0262af | bellard | #define FP_CONVERT (env->fp_convert)
|
114 | 2c0262af | bellard | #endif
|
115 | 2c0262af | bellard | |
116 | 2c0262af | bellard | #include "cpu.h" |
117 | 2c0262af | bellard | #include "exec-all.h" |
118 | 2c0262af | bellard | |
119 | 2c0262af | bellard | typedef struct CCTable { |
120 | 2c0262af | bellard | int (*compute_all)(void); /* return all the flags */ |
121 | 2c0262af | bellard | int (*compute_c)(void); /* return the C flag */ |
122 | 2c0262af | bellard | } CCTable; |
123 | 2c0262af | bellard | |
124 | 2c0262af | bellard | extern CCTable cc_table[];
|
125 | 2c0262af | bellard | |
126 | 8e682019 | bellard | void load_seg(int seg_reg, int selector); |
127 | 08cea4ee | bellard | void helper_ljmp_protected_T0_T1(int next_eip); |
128 | 2c0262af | bellard | void helper_lcall_real_T0_T1(int shift, int next_eip); |
129 | 2c0262af | bellard | void helper_lcall_protected_T0_T1(int shift, int next_eip); |
130 | 2c0262af | bellard | void helper_iret_real(int shift); |
131 | 08cea4ee | bellard | void helper_iret_protected(int shift, int next_eip); |
132 | 2c0262af | bellard | void helper_lret_protected(int shift, int addend); |
133 | 2c0262af | bellard | void helper_lldt_T0(void); |
134 | 2c0262af | bellard | void helper_ltr_T0(void); |
135 | 2c0262af | bellard | void helper_movl_crN_T0(int reg); |
136 | 2c0262af | bellard | void helper_movl_drN_T0(int reg); |
137 | 2c0262af | bellard | void helper_invlpg(unsigned int addr); |
138 | 1ac157da | bellard | void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0);
|
139 | 1ac157da | bellard | void cpu_x86_update_cr3(CPUX86State *env, uint32_t new_cr3);
|
140 | 1ac157da | bellard | void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4);
|
141 | 2c0262af | bellard | void cpu_x86_flush_tlb(CPUX86State *env, uint32_t addr);
|
142 | 61382a50 | bellard | int cpu_x86_handle_mmu_fault(CPUX86State *env, uint32_t addr,
|
143 | 61382a50 | bellard | int is_write, int is_user, int is_softmmu); |
144 | 61382a50 | bellard | void tlb_fill(unsigned long addr, int is_write, int is_user, |
145 | 61382a50 | bellard | void *retaddr);
|
146 | 2c0262af | bellard | void __hidden cpu_lock(void); |
147 | 2c0262af | bellard | void __hidden cpu_unlock(void); |
148 | 2c0262af | bellard | void do_interrupt(int intno, int is_int, int error_code, |
149 | 2c0262af | bellard | unsigned int next_eip, int is_hw); |
150 | 2c0262af | bellard | void do_interrupt_user(int intno, int is_int, int error_code, |
151 | 2c0262af | bellard | unsigned int next_eip); |
152 | 2c0262af | bellard | void raise_interrupt(int intno, int is_int, int error_code, |
153 | 2c0262af | bellard | unsigned int next_eip); |
154 | 2c0262af | bellard | void raise_exception_err(int exception_index, int error_code); |
155 | 2c0262af | bellard | void raise_exception(int exception_index); |
156 | 2c0262af | bellard | void __hidden cpu_loop_exit(void); |
157 | 2c0262af | bellard | void helper_fsave(uint8_t *ptr, int data32); |
158 | 2c0262af | bellard | void helper_frstor(uint8_t *ptr, int data32); |
159 | 2c0262af | bellard | |
160 | 2c0262af | bellard | void OPPROTO op_movl_eflags_T0(void); |
161 | 2c0262af | bellard | void OPPROTO op_movl_T0_eflags(void); |
162 | 2c0262af | bellard | void raise_interrupt(int intno, int is_int, int error_code, |
163 | 2c0262af | bellard | unsigned int next_eip); |
164 | 2c0262af | bellard | void raise_exception_err(int exception_index, int error_code); |
165 | 2c0262af | bellard | void raise_exception(int exception_index); |
166 | 2c0262af | bellard | void helper_divl_EAX_T0(uint32_t eip);
|
167 | 2c0262af | bellard | void helper_idivl_EAX_T0(uint32_t eip);
|
168 | 2c0262af | bellard | void helper_cmpxchg8b(void); |
169 | 2c0262af | bellard | void helper_cpuid(void); |
170 | 023fe10d | bellard | void helper_sysenter(void); |
171 | 023fe10d | bellard | void helper_sysexit(void); |
172 | 2c0262af | bellard | void helper_rdtsc(void); |
173 | 2c0262af | bellard | void helper_rdmsr(void); |
174 | 2c0262af | bellard | void helper_wrmsr(void); |
175 | 2c0262af | bellard | void helper_lsl(void); |
176 | 2c0262af | bellard | void helper_lar(void); |
177 | 3ab493de | bellard | void helper_verr(void); |
178 | 3ab493de | bellard | void helper_verw(void); |
179 | 2c0262af | bellard | |
180 | 3e25f951 | bellard | void check_iob_T0(void); |
181 | 3e25f951 | bellard | void check_iow_T0(void); |
182 | 3e25f951 | bellard | void check_iol_T0(void); |
183 | 3e25f951 | bellard | void check_iob_DX(void); |
184 | 3e25f951 | bellard | void check_iow_DX(void); |
185 | 3e25f951 | bellard | void check_iol_DX(void); |
186 | 3e25f951 | bellard | |
187 | 9951bf39 | bellard | /* XXX: move that to a generic header */
|
188 | 9951bf39 | bellard | #if !defined(CONFIG_USER_ONLY)
|
189 | 9951bf39 | bellard | |
190 | 9951bf39 | bellard | #define ldul_user ldl_user
|
191 | 9951bf39 | bellard | #define ldul_kernel ldl_kernel
|
192 | 9951bf39 | bellard | |
193 | 9951bf39 | bellard | #define ACCESS_TYPE 0 |
194 | 9951bf39 | bellard | #define MEMSUFFIX _kernel
|
195 | 9951bf39 | bellard | #define DATA_SIZE 1 |
196 | 9951bf39 | bellard | #include "softmmu_header.h" |
197 | 9951bf39 | bellard | |
198 | 9951bf39 | bellard | #define DATA_SIZE 2 |
199 | 9951bf39 | bellard | #include "softmmu_header.h" |
200 | 9951bf39 | bellard | |
201 | 9951bf39 | bellard | #define DATA_SIZE 4 |
202 | 9951bf39 | bellard | #include "softmmu_header.h" |
203 | 9951bf39 | bellard | |
204 | 9951bf39 | bellard | #define DATA_SIZE 8 |
205 | 9951bf39 | bellard | #include "softmmu_header.h" |
206 | 9951bf39 | bellard | #undef ACCESS_TYPE
|
207 | 9951bf39 | bellard | #undef MEMSUFFIX
|
208 | 9951bf39 | bellard | |
209 | 9951bf39 | bellard | #define ACCESS_TYPE 1 |
210 | 9951bf39 | bellard | #define MEMSUFFIX _user
|
211 | 9951bf39 | bellard | #define DATA_SIZE 1 |
212 | 9951bf39 | bellard | #include "softmmu_header.h" |
213 | 9951bf39 | bellard | |
214 | 9951bf39 | bellard | #define DATA_SIZE 2 |
215 | 9951bf39 | bellard | #include "softmmu_header.h" |
216 | 9951bf39 | bellard | |
217 | 9951bf39 | bellard | #define DATA_SIZE 4 |
218 | 9951bf39 | bellard | #include "softmmu_header.h" |
219 | 9951bf39 | bellard | |
220 | 9951bf39 | bellard | #define DATA_SIZE 8 |
221 | 9951bf39 | bellard | #include "softmmu_header.h" |
222 | 9951bf39 | bellard | #undef ACCESS_TYPE
|
223 | 9951bf39 | bellard | #undef MEMSUFFIX
|
224 | 9951bf39 | bellard | |
225 | 9951bf39 | bellard | /* these access are slower, they must be as rare as possible */
|
226 | 9951bf39 | bellard | #define ACCESS_TYPE 2 |
227 | 9951bf39 | bellard | #define MEMSUFFIX _data
|
228 | 9951bf39 | bellard | #define DATA_SIZE 1 |
229 | 9951bf39 | bellard | #include "softmmu_header.h" |
230 | 9951bf39 | bellard | |
231 | 9951bf39 | bellard | #define DATA_SIZE 2 |
232 | 9951bf39 | bellard | #include "softmmu_header.h" |
233 | 9951bf39 | bellard | |
234 | 9951bf39 | bellard | #define DATA_SIZE 4 |
235 | 9951bf39 | bellard | #include "softmmu_header.h" |
236 | 9951bf39 | bellard | |
237 | 9951bf39 | bellard | #define DATA_SIZE 8 |
238 | 9951bf39 | bellard | #include "softmmu_header.h" |
239 | 9951bf39 | bellard | #undef ACCESS_TYPE
|
240 | 9951bf39 | bellard | #undef MEMSUFFIX
|
241 | 9951bf39 | bellard | |
242 | 9951bf39 | bellard | #define ldub(p) ldub_data(p)
|
243 | 9951bf39 | bellard | #define ldsb(p) ldsb_data(p)
|
244 | 9951bf39 | bellard | #define lduw(p) lduw_data(p)
|
245 | 9951bf39 | bellard | #define ldsw(p) ldsw_data(p)
|
246 | 9951bf39 | bellard | #define ldl(p) ldl_data(p)
|
247 | 9951bf39 | bellard | #define ldq(p) ldq_data(p)
|
248 | 9951bf39 | bellard | |
249 | 9951bf39 | bellard | #define stb(p, v) stb_data(p, v)
|
250 | 9951bf39 | bellard | #define stw(p, v) stw_data(p, v)
|
251 | 9951bf39 | bellard | #define stl(p, v) stl_data(p, v)
|
252 | 9951bf39 | bellard | #define stq(p, v) stq_data(p, v)
|
253 | 9951bf39 | bellard | |
254 | 9951bf39 | bellard | static inline double ldfq(void *ptr) |
255 | 9951bf39 | bellard | { |
256 | 9951bf39 | bellard | union {
|
257 | 9951bf39 | bellard | double d;
|
258 | 9951bf39 | bellard | uint64_t i; |
259 | 9951bf39 | bellard | } u; |
260 | 9951bf39 | bellard | u.i = ldq(ptr); |
261 | 9951bf39 | bellard | return u.d;
|
262 | 9951bf39 | bellard | } |
263 | 9951bf39 | bellard | |
264 | 9951bf39 | bellard | static inline void stfq(void *ptr, double v) |
265 | 9951bf39 | bellard | { |
266 | 9951bf39 | bellard | union {
|
267 | 9951bf39 | bellard | double d;
|
268 | 9951bf39 | bellard | uint64_t i; |
269 | 9951bf39 | bellard | } u; |
270 | 9951bf39 | bellard | u.d = v; |
271 | 9951bf39 | bellard | stq(ptr, u.i); |
272 | 9951bf39 | bellard | } |
273 | 9951bf39 | bellard | |
274 | 9951bf39 | bellard | static inline float ldfl(void *ptr) |
275 | 9951bf39 | bellard | { |
276 | 9951bf39 | bellard | union {
|
277 | 9951bf39 | bellard | float f;
|
278 | 9951bf39 | bellard | uint32_t i; |
279 | 9951bf39 | bellard | } u; |
280 | 9951bf39 | bellard | u.i = ldl(ptr); |
281 | 9951bf39 | bellard | return u.f;
|
282 | 9951bf39 | bellard | } |
283 | 9951bf39 | bellard | |
284 | 9951bf39 | bellard | static inline void stfl(void *ptr, float v) |
285 | 9951bf39 | bellard | { |
286 | 9951bf39 | bellard | union {
|
287 | 9951bf39 | bellard | float f;
|
288 | 9951bf39 | bellard | uint32_t i; |
289 | 9951bf39 | bellard | } u; |
290 | 9951bf39 | bellard | u.f = v; |
291 | 9951bf39 | bellard | stl(ptr, u.i); |
292 | 9951bf39 | bellard | } |
293 | 9951bf39 | bellard | |
294 | 9951bf39 | bellard | #endif /* !defined(CONFIG_USER_ONLY) */ |
295 | 9951bf39 | bellard | |
296 | 2c0262af | bellard | #ifdef USE_X86LDOUBLE
|
297 | 2c0262af | bellard | /* use long double functions */
|
298 | 2c0262af | bellard | #define lrint lrintl
|
299 | 2c0262af | bellard | #define llrint llrintl
|
300 | 2c0262af | bellard | #define fabs fabsl
|
301 | 2c0262af | bellard | #define sin sinl
|
302 | 2c0262af | bellard | #define cos cosl
|
303 | 2c0262af | bellard | #define sqrt sqrtl
|
304 | 2c0262af | bellard | #define pow powl
|
305 | 2c0262af | bellard | #define log logl
|
306 | 2c0262af | bellard | #define tan tanl
|
307 | 2c0262af | bellard | #define atan2 atan2l
|
308 | 2c0262af | bellard | #define floor floorl
|
309 | 2c0262af | bellard | #define ceil ceill
|
310 | 2c0262af | bellard | #define rint rintl
|
311 | 2c0262af | bellard | #endif
|
312 | 2c0262af | bellard | |
313 | 7d3505c5 | bellard | #if !defined(_BSD)
|
314 | 2c0262af | bellard | extern int lrint(CPU86_LDouble x); |
315 | 2c0262af | bellard | extern int64_t llrint(CPU86_LDouble x);
|
316 | 7d3505c5 | bellard | #else
|
317 | 7d3505c5 | bellard | #define lrint(d) ((int)rint(d)) |
318 | 7d3505c5 | bellard | #define llrint(d) ((int)rint(d)) |
319 | 7d3505c5 | bellard | #endif
|
320 | 2c0262af | bellard | extern CPU86_LDouble fabs(CPU86_LDouble x);
|
321 | 2c0262af | bellard | extern CPU86_LDouble sin(CPU86_LDouble x);
|
322 | 2c0262af | bellard | extern CPU86_LDouble cos(CPU86_LDouble x);
|
323 | 2c0262af | bellard | extern CPU86_LDouble sqrt(CPU86_LDouble x);
|
324 | 2c0262af | bellard | extern CPU86_LDouble pow(CPU86_LDouble, CPU86_LDouble);
|
325 | 2c0262af | bellard | extern CPU86_LDouble log(CPU86_LDouble x);
|
326 | 2c0262af | bellard | extern CPU86_LDouble tan(CPU86_LDouble x);
|
327 | 2c0262af | bellard | extern CPU86_LDouble atan2(CPU86_LDouble, CPU86_LDouble);
|
328 | 2c0262af | bellard | extern CPU86_LDouble floor(CPU86_LDouble x);
|
329 | 2c0262af | bellard | extern CPU86_LDouble ceil(CPU86_LDouble x);
|
330 | 2c0262af | bellard | extern CPU86_LDouble rint(CPU86_LDouble x);
|
331 | 2c0262af | bellard | |
332 | 2c0262af | bellard | #define RC_MASK 0xc00 |
333 | 2c0262af | bellard | #define RC_NEAR 0x000 |
334 | 2c0262af | bellard | #define RC_DOWN 0x400 |
335 | 2c0262af | bellard | #define RC_UP 0x800 |
336 | 2c0262af | bellard | #define RC_CHOP 0xc00 |
337 | 2c0262af | bellard | |
338 | 2c0262af | bellard | #define MAXTAN 9223372036854775808.0 |
339 | 2c0262af | bellard | |
340 | 2c0262af | bellard | #ifdef __arm__
|
341 | 2c0262af | bellard | /* we have no way to do correct rounding - a FPU emulator is needed */
|
342 | 2c0262af | bellard | #define FE_DOWNWARD FE_TONEAREST
|
343 | 2c0262af | bellard | #define FE_UPWARD FE_TONEAREST
|
344 | 2c0262af | bellard | #define FE_TOWARDZERO FE_TONEAREST
|
345 | 2c0262af | bellard | #endif
|
346 | 2c0262af | bellard | |
347 | 2c0262af | bellard | #ifdef USE_X86LDOUBLE
|
348 | 2c0262af | bellard | |
349 | 2c0262af | bellard | /* only for x86 */
|
350 | 2c0262af | bellard | typedef union { |
351 | 2c0262af | bellard | long double d; |
352 | 2c0262af | bellard | struct {
|
353 | 2c0262af | bellard | unsigned long long lower; |
354 | 2c0262af | bellard | unsigned short upper; |
355 | 2c0262af | bellard | } l; |
356 | 2c0262af | bellard | } CPU86_LDoubleU; |
357 | 2c0262af | bellard | |
358 | 2c0262af | bellard | /* the following deal with x86 long double-precision numbers */
|
359 | 2c0262af | bellard | #define MAXEXPD 0x7fff |
360 | 2c0262af | bellard | #define EXPBIAS 16383 |
361 | 2c0262af | bellard | #define EXPD(fp) (fp.l.upper & 0x7fff) |
362 | 2c0262af | bellard | #define SIGND(fp) ((fp.l.upper) & 0x8000) |
363 | 2c0262af | bellard | #define MANTD(fp) (fp.l.lower)
|
364 | 2c0262af | bellard | #define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7fff)) | EXPBIAS |
365 | 2c0262af | bellard | |
366 | 2c0262af | bellard | #else
|
367 | 2c0262af | bellard | |
368 | 2c0262af | bellard | /* NOTE: arm is horrible as double 32 bit words are stored in big endian ! */
|
369 | 2c0262af | bellard | typedef union { |
370 | 2c0262af | bellard | double d;
|
371 | 2c0262af | bellard | #if !defined(WORDS_BIGENDIAN) && !defined(__arm__)
|
372 | 2c0262af | bellard | struct {
|
373 | 2c0262af | bellard | uint32_t lower; |
374 | 2c0262af | bellard | int32_t upper; |
375 | 2c0262af | bellard | } l; |
376 | 2c0262af | bellard | #else
|
377 | 2c0262af | bellard | struct {
|
378 | 2c0262af | bellard | int32_t upper; |
379 | 2c0262af | bellard | uint32_t lower; |
380 | 2c0262af | bellard | } l; |
381 | 2c0262af | bellard | #endif
|
382 | 2c0262af | bellard | #ifndef __arm__
|
383 | 2c0262af | bellard | int64_t ll; |
384 | 2c0262af | bellard | #endif
|
385 | 2c0262af | bellard | } CPU86_LDoubleU; |
386 | 2c0262af | bellard | |
387 | 2c0262af | bellard | /* the following deal with IEEE double-precision numbers */
|
388 | 2c0262af | bellard | #define MAXEXPD 0x7ff |
389 | 2c0262af | bellard | #define EXPBIAS 1023 |
390 | 2c0262af | bellard | #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) |
391 | 2c0262af | bellard | #define SIGND(fp) ((fp.l.upper) & 0x80000000) |
392 | 2c0262af | bellard | #ifdef __arm__
|
393 | 2c0262af | bellard | #define MANTD(fp) (fp.l.lower | ((uint64_t)(fp.l.upper & ((1 << 20) - 1)) << 32)) |
394 | 2c0262af | bellard | #else
|
395 | 2c0262af | bellard | #define MANTD(fp) (fp.ll & ((1LL << 52) - 1)) |
396 | 2c0262af | bellard | #endif
|
397 | 2c0262af | bellard | #define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7ff << 20)) | (EXPBIAS << 20) |
398 | 2c0262af | bellard | #endif
|
399 | 2c0262af | bellard | |
400 | 2c0262af | bellard | static inline void fpush(void) |
401 | 2c0262af | bellard | { |
402 | 2c0262af | bellard | env->fpstt = (env->fpstt - 1) & 7; |
403 | 2c0262af | bellard | env->fptags[env->fpstt] = 0; /* validate stack entry */ |
404 | 2c0262af | bellard | } |
405 | 2c0262af | bellard | |
406 | 2c0262af | bellard | static inline void fpop(void) |
407 | 2c0262af | bellard | { |
408 | 2c0262af | bellard | env->fptags[env->fpstt] = 1; /* invvalidate stack entry */ |
409 | 2c0262af | bellard | env->fpstt = (env->fpstt + 1) & 7; |
410 | 2c0262af | bellard | } |
411 | 2c0262af | bellard | |
412 | 2c0262af | bellard | #ifndef USE_X86LDOUBLE
|
413 | 2c0262af | bellard | static inline CPU86_LDouble helper_fldt(uint8_t *ptr) |
414 | 2c0262af | bellard | { |
415 | 2c0262af | bellard | CPU86_LDoubleU temp; |
416 | 2c0262af | bellard | int upper, e;
|
417 | 2c0262af | bellard | uint64_t ll; |
418 | 2c0262af | bellard | |
419 | 2c0262af | bellard | /* mantissa */
|
420 | 2c0262af | bellard | upper = lduw(ptr + 8);
|
421 | 2c0262af | bellard | /* XXX: handle overflow ? */
|
422 | 2c0262af | bellard | e = (upper & 0x7fff) - 16383 + EXPBIAS; /* exponent */ |
423 | 2c0262af | bellard | e |= (upper >> 4) & 0x800; /* sign */ |
424 | 2c0262af | bellard | ll = (ldq(ptr) >> 11) & ((1LL << 52) - 1); |
425 | 2c0262af | bellard | #ifdef __arm__
|
426 | 2c0262af | bellard | temp.l.upper = (e << 20) | (ll >> 32); |
427 | 2c0262af | bellard | temp.l.lower = ll; |
428 | 2c0262af | bellard | #else
|
429 | 2c0262af | bellard | temp.ll = ll | ((uint64_t)e << 52);
|
430 | 2c0262af | bellard | #endif
|
431 | 2c0262af | bellard | return temp.d;
|
432 | 2c0262af | bellard | } |
433 | 2c0262af | bellard | |
434 | 2c0262af | bellard | static inline void helper_fstt(CPU86_LDouble f, uint8_t *ptr) |
435 | 2c0262af | bellard | { |
436 | 2c0262af | bellard | CPU86_LDoubleU temp; |
437 | 2c0262af | bellard | int e;
|
438 | 2c0262af | bellard | |
439 | 2c0262af | bellard | temp.d = f; |
440 | 2c0262af | bellard | /* mantissa */
|
441 | 2c0262af | bellard | stq(ptr, (MANTD(temp) << 11) | (1LL << 63)); |
442 | 2c0262af | bellard | /* exponent + sign */
|
443 | 2c0262af | bellard | e = EXPD(temp) - EXPBIAS + 16383;
|
444 | 2c0262af | bellard | e |= SIGND(temp) >> 16;
|
445 | 2c0262af | bellard | stw(ptr + 8, e);
|
446 | 2c0262af | bellard | } |
447 | 9951bf39 | bellard | #else
|
448 | 9951bf39 | bellard | |
449 | 9951bf39 | bellard | /* XXX: same endianness assumed */
|
450 | 9951bf39 | bellard | |
451 | 9951bf39 | bellard | #ifdef CONFIG_USER_ONLY
|
452 | 9951bf39 | bellard | |
453 | 9951bf39 | bellard | static inline CPU86_LDouble helper_fldt(uint8_t *ptr) |
454 | 9951bf39 | bellard | { |
455 | 9951bf39 | bellard | return *(CPU86_LDouble *)ptr;
|
456 | 9951bf39 | bellard | } |
457 | 9951bf39 | bellard | |
458 | 9951bf39 | bellard | static inline void helper_fstt(CPU86_LDouble f, uint8_t *ptr) |
459 | 9951bf39 | bellard | { |
460 | 9951bf39 | bellard | *(CPU86_LDouble *)ptr = f; |
461 | 9951bf39 | bellard | } |
462 | 9951bf39 | bellard | |
463 | 9951bf39 | bellard | #else
|
464 | 9951bf39 | bellard | |
465 | 9951bf39 | bellard | /* we use memory access macros */
|
466 | 9951bf39 | bellard | |
467 | 9951bf39 | bellard | static inline CPU86_LDouble helper_fldt(uint8_t *ptr) |
468 | 9951bf39 | bellard | { |
469 | 9951bf39 | bellard | CPU86_LDoubleU temp; |
470 | 9951bf39 | bellard | |
471 | 9951bf39 | bellard | temp.l.lower = ldq(ptr); |
472 | 9951bf39 | bellard | temp.l.upper = lduw(ptr + 8);
|
473 | 9951bf39 | bellard | return temp.d;
|
474 | 9951bf39 | bellard | } |
475 | 9951bf39 | bellard | |
476 | 9951bf39 | bellard | static inline void helper_fstt(CPU86_LDouble f, uint8_t *ptr) |
477 | 9951bf39 | bellard | { |
478 | 9951bf39 | bellard | CPU86_LDoubleU temp; |
479 | 9951bf39 | bellard | |
480 | 9951bf39 | bellard | temp.d = f; |
481 | 9951bf39 | bellard | stq(ptr, temp.l.lower); |
482 | 9951bf39 | bellard | stw(ptr + 8, temp.l.upper);
|
483 | 9951bf39 | bellard | } |
484 | 9951bf39 | bellard | |
485 | 9951bf39 | bellard | #endif /* !CONFIG_USER_ONLY */ |
486 | 9951bf39 | bellard | |
487 | 9951bf39 | bellard | #endif /* USE_X86LDOUBLE */ |
488 | 2c0262af | bellard | |
489 | 2ee73ac3 | bellard | #define FPUS_IE (1 << 0) |
490 | 2ee73ac3 | bellard | #define FPUS_DE (1 << 1) |
491 | 2ee73ac3 | bellard | #define FPUS_ZE (1 << 2) |
492 | 2ee73ac3 | bellard | #define FPUS_OE (1 << 3) |
493 | 2ee73ac3 | bellard | #define FPUS_UE (1 << 4) |
494 | 2ee73ac3 | bellard | #define FPUS_PE (1 << 5) |
495 | 2ee73ac3 | bellard | #define FPUS_SF (1 << 6) |
496 | 2ee73ac3 | bellard | #define FPUS_SE (1 << 7) |
497 | 2ee73ac3 | bellard | #define FPUS_B (1 << 15) |
498 | 2ee73ac3 | bellard | |
499 | 2ee73ac3 | bellard | #define FPUC_EM 0x3f |
500 | 2ee73ac3 | bellard | |
501 | 2c0262af | bellard | const CPU86_LDouble f15rk[7]; |
502 | 2c0262af | bellard | |
503 | 2c0262af | bellard | void helper_fldt_ST0_A0(void); |
504 | 2c0262af | bellard | void helper_fstt_ST0_A0(void); |
505 | 2ee73ac3 | bellard | void fpu_raise_exception(void); |
506 | 2ee73ac3 | bellard | CPU86_LDouble helper_fdiv(CPU86_LDouble a, CPU86_LDouble b); |
507 | 2c0262af | bellard | void helper_fbld_ST0_A0(void); |
508 | 2c0262af | bellard | void helper_fbst_ST0_A0(void); |
509 | 2c0262af | bellard | void helper_f2xm1(void); |
510 | 2c0262af | bellard | void helper_fyl2x(void); |
511 | 2c0262af | bellard | void helper_fptan(void); |
512 | 2c0262af | bellard | void helper_fpatan(void); |
513 | 2c0262af | bellard | void helper_fxtract(void); |
514 | 2c0262af | bellard | void helper_fprem1(void); |
515 | 2c0262af | bellard | void helper_fprem(void); |
516 | 2c0262af | bellard | void helper_fyl2xp1(void); |
517 | 2c0262af | bellard | void helper_fsqrt(void); |
518 | 2c0262af | bellard | void helper_fsincos(void); |
519 | 2c0262af | bellard | void helper_frndint(void); |
520 | 2c0262af | bellard | void helper_fscale(void); |
521 | 2c0262af | bellard | void helper_fsin(void); |
522 | 2c0262af | bellard | void helper_fcos(void); |
523 | 2c0262af | bellard | void helper_fxam_ST0(void); |
524 | 2c0262af | bellard | void helper_fstenv(uint8_t *ptr, int data32); |
525 | 2c0262af | bellard | void helper_fldenv(uint8_t *ptr, int data32); |
526 | 2c0262af | bellard | void helper_fsave(uint8_t *ptr, int data32); |
527 | 2c0262af | bellard | void helper_frstor(uint8_t *ptr, int data32); |
528 | 03857e31 | bellard | void restore_native_fp_state(CPUState *env);
|
529 | 03857e31 | bellard | void save_native_fp_state(CPUState *env);
|
530 | 2c0262af | bellard | |
531 | 2c0262af | bellard | const uint8_t parity_table[256]; |
532 | 2c0262af | bellard | const uint8_t rclw_table[32]; |
533 | 2c0262af | bellard | const uint8_t rclb_table[32]; |
534 | 2c0262af | bellard | |
535 | 2c0262af | bellard | static inline uint32_t compute_eflags(void) |
536 | 2c0262af | bellard | { |
537 | 2c0262af | bellard | return env->eflags | cc_table[CC_OP].compute_all() | (DF & DF_MASK);
|
538 | 2c0262af | bellard | } |
539 | 2c0262af | bellard | |
540 | 2c0262af | bellard | /* NOTE: CC_OP must be modified manually to CC_OP_EFLAGS */
|
541 | 2c0262af | bellard | static inline void load_eflags(int eflags, int update_mask) |
542 | 2c0262af | bellard | { |
543 | 2c0262af | bellard | CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
544 | 2c0262af | bellard | DF = 1 - (2 * ((eflags >> 10) & 1)); |
545 | 2c0262af | bellard | env->eflags = (env->eflags & ~update_mask) | |
546 | 2c0262af | bellard | (eflags & update_mask); |
547 | 2c0262af | bellard | } |