root / target-i386 / exec.h @ 1d6e34fd
History | View | Annotate | Download (15.1 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 | 14ce26e7 | bellard | /* XXX: factorize this mess */
|
24 | 14ce26e7 | bellard | #if defined(__alpha__) || defined (__ia64__) || defined(__x86_64__)
|
25 | 14ce26e7 | bellard | #define HOST_LONG_BITS 64 |
26 | 14ce26e7 | bellard | #else
|
27 | 14ce26e7 | bellard | #define HOST_LONG_BITS 32 |
28 | 14ce26e7 | bellard | #endif
|
29 | 14ce26e7 | bellard | |
30 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
31 | 14ce26e7 | bellard | #define TARGET_LONG_BITS 64 |
32 | 14ce26e7 | bellard | #else
|
33 | 14ce26e7 | bellard | #define TARGET_LONG_BITS 32 |
34 | 14ce26e7 | bellard | #endif
|
35 | 14ce26e7 | bellard | |
36 | 0d1a29f9 | bellard | /* at least 4 register variables are defined */
|
37 | 2c0262af | bellard | register struct CPUX86State *env asm(AREG0); |
38 | 14ce26e7 | bellard | |
39 | 14ce26e7 | bellard | /* XXX: use 64 bit regs if HOST_LONG_BITS == 64 */
|
40 | 14ce26e7 | bellard | #if TARGET_LONG_BITS == 32 |
41 | 14ce26e7 | bellard | |
42 | 2c0262af | bellard | register uint32_t T0 asm(AREG1); |
43 | 2c0262af | bellard | register uint32_t T1 asm(AREG2); |
44 | 2c0262af | bellard | register uint32_t T2 asm(AREG3); |
45 | 2c0262af | bellard | |
46 | 2c0262af | bellard | /* if more registers are available, we define some registers too */
|
47 | 2c0262af | bellard | #ifdef AREG4
|
48 | 2c0262af | bellard | register uint32_t EAX asm(AREG4); |
49 | 2c0262af | bellard | #define reg_EAX
|
50 | 2c0262af | bellard | #endif
|
51 | 2c0262af | bellard | |
52 | 2c0262af | bellard | #ifdef AREG5
|
53 | 2c0262af | bellard | register uint32_t ESP asm(AREG5); |
54 | 2c0262af | bellard | #define reg_ESP
|
55 | 2c0262af | bellard | #endif
|
56 | 2c0262af | bellard | |
57 | 2c0262af | bellard | #ifdef AREG6
|
58 | 2c0262af | bellard | register uint32_t EBP asm(AREG6); |
59 | 2c0262af | bellard | #define reg_EBP
|
60 | 2c0262af | bellard | #endif
|
61 | 2c0262af | bellard | |
62 | 2c0262af | bellard | #ifdef AREG7
|
63 | 2c0262af | bellard | register uint32_t ECX asm(AREG7); |
64 | 2c0262af | bellard | #define reg_ECX
|
65 | 2c0262af | bellard | #endif
|
66 | 2c0262af | bellard | |
67 | 2c0262af | bellard | #ifdef AREG8
|
68 | 2c0262af | bellard | register uint32_t EDX asm(AREG8); |
69 | 2c0262af | bellard | #define reg_EDX
|
70 | 2c0262af | bellard | #endif
|
71 | 2c0262af | bellard | |
72 | 2c0262af | bellard | #ifdef AREG9
|
73 | 2c0262af | bellard | register uint32_t EBX asm(AREG9); |
74 | 2c0262af | bellard | #define reg_EBX
|
75 | 2c0262af | bellard | #endif
|
76 | 2c0262af | bellard | |
77 | 2c0262af | bellard | #ifdef AREG10
|
78 | 2c0262af | bellard | register uint32_t ESI asm(AREG10); |
79 | 2c0262af | bellard | #define reg_ESI
|
80 | 2c0262af | bellard | #endif
|
81 | 2c0262af | bellard | |
82 | 2c0262af | bellard | #ifdef AREG11
|
83 | 2c0262af | bellard | register uint32_t EDI asm(AREG11); |
84 | 2c0262af | bellard | #define reg_EDI
|
85 | 2c0262af | bellard | #endif
|
86 | 2c0262af | bellard | |
87 | 14ce26e7 | bellard | #else
|
88 | 14ce26e7 | bellard | |
89 | 14ce26e7 | bellard | /* no registers can be used */
|
90 | 14ce26e7 | bellard | #define T0 (env->t0)
|
91 | 14ce26e7 | bellard | #define T1 (env->t1)
|
92 | 14ce26e7 | bellard | #define T2 (env->t2)
|
93 | 14ce26e7 | bellard | |
94 | 14ce26e7 | bellard | #endif
|
95 | 14ce26e7 | bellard | |
96 | 14ce26e7 | bellard | #define A0 T2
|
97 | 14ce26e7 | bellard | |
98 | 2c0262af | bellard | extern FILE *logfile;
|
99 | 2c0262af | bellard | extern int loglevel; |
100 | 2c0262af | bellard | |
101 | 2c0262af | bellard | #ifndef reg_EAX
|
102 | 2c0262af | bellard | #define EAX (env->regs[R_EAX])
|
103 | 2c0262af | bellard | #endif
|
104 | 2c0262af | bellard | #ifndef reg_ECX
|
105 | 2c0262af | bellard | #define ECX (env->regs[R_ECX])
|
106 | 2c0262af | bellard | #endif
|
107 | 2c0262af | bellard | #ifndef reg_EDX
|
108 | 2c0262af | bellard | #define EDX (env->regs[R_EDX])
|
109 | 2c0262af | bellard | #endif
|
110 | 2c0262af | bellard | #ifndef reg_EBX
|
111 | 2c0262af | bellard | #define EBX (env->regs[R_EBX])
|
112 | 2c0262af | bellard | #endif
|
113 | 2c0262af | bellard | #ifndef reg_ESP
|
114 | 2c0262af | bellard | #define ESP (env->regs[R_ESP])
|
115 | 2c0262af | bellard | #endif
|
116 | 2c0262af | bellard | #ifndef reg_EBP
|
117 | 2c0262af | bellard | #define EBP (env->regs[R_EBP])
|
118 | 2c0262af | bellard | #endif
|
119 | 2c0262af | bellard | #ifndef reg_ESI
|
120 | 2c0262af | bellard | #define ESI (env->regs[R_ESI])
|
121 | 2c0262af | bellard | #endif
|
122 | 2c0262af | bellard | #ifndef reg_EDI
|
123 | 2c0262af | bellard | #define EDI (env->regs[R_EDI])
|
124 | 2c0262af | bellard | #endif
|
125 | 2c0262af | bellard | #define EIP (env->eip)
|
126 | 2c0262af | bellard | #define DF (env->df)
|
127 | 2c0262af | bellard | |
128 | 2c0262af | bellard | #define CC_SRC (env->cc_src)
|
129 | 2c0262af | bellard | #define CC_DST (env->cc_dst)
|
130 | 2c0262af | bellard | #define CC_OP (env->cc_op)
|
131 | 2c0262af | bellard | |
132 | 2c0262af | bellard | /* float macros */
|
133 | 2c0262af | bellard | #define FT0 (env->ft0)
|
134 | 664e0f19 | bellard | #define ST0 (env->fpregs[env->fpstt].d)
|
135 | 664e0f19 | bellard | #define ST(n) (env->fpregs[(env->fpstt + (n)) & 7].d) |
136 | 2c0262af | bellard | #define ST1 ST(1) |
137 | 2c0262af | bellard | |
138 | 2c0262af | bellard | #ifdef USE_FP_CONVERT
|
139 | 2c0262af | bellard | #define FP_CONVERT (env->fp_convert)
|
140 | 2c0262af | bellard | #endif
|
141 | 2c0262af | bellard | |
142 | 2c0262af | bellard | #include "cpu.h" |
143 | 2c0262af | bellard | #include "exec-all.h" |
144 | 2c0262af | bellard | |
145 | 79f91c27 | bellard | /* XXX: add a generic FPU library */
|
146 | 79f91c27 | bellard | |
147 | 79f91c27 | bellard | static inline double float32_to_float64(float a) |
148 | 79f91c27 | bellard | { |
149 | 79f91c27 | bellard | return a;
|
150 | 79f91c27 | bellard | } |
151 | 79f91c27 | bellard | |
152 | 79f91c27 | bellard | static inline float float64_to_float32(double a) |
153 | 79f91c27 | bellard | { |
154 | 79f91c27 | bellard | return a;
|
155 | 79f91c27 | bellard | } |
156 | 79f91c27 | bellard | |
157 | 79f91c27 | bellard | #if defined(__powerpc__)
|
158 | 79f91c27 | bellard | /* better to call an helper on ppc */
|
159 | 79f91c27 | bellard | float int32_to_float32(int32_t a);
|
160 | 79f91c27 | bellard | double int32_to_float64(int32_t a);
|
161 | 79f91c27 | bellard | #else
|
162 | 79f91c27 | bellard | static inline float int32_to_float32(int32_t a) |
163 | 79f91c27 | bellard | { |
164 | 79f91c27 | bellard | return (float)a; |
165 | 79f91c27 | bellard | } |
166 | 79f91c27 | bellard | |
167 | 79f91c27 | bellard | static inline double int32_to_float64(int32_t a) |
168 | 79f91c27 | bellard | { |
169 | 79f91c27 | bellard | return (double)a; |
170 | 79f91c27 | bellard | } |
171 | 79f91c27 | bellard | #endif
|
172 | 79f91c27 | bellard | |
173 | 79f91c27 | bellard | static inline float int64_to_float32(int64_t a) |
174 | 79f91c27 | bellard | { |
175 | 79f91c27 | bellard | return (float)a; |
176 | 79f91c27 | bellard | } |
177 | 79f91c27 | bellard | |
178 | 79f91c27 | bellard | static inline double int64_to_float64(int64_t a) |
179 | 79f91c27 | bellard | { |
180 | 79f91c27 | bellard | return (double)a; |
181 | 79f91c27 | bellard | } |
182 | 79f91c27 | bellard | |
183 | 2c0262af | bellard | typedef struct CCTable { |
184 | 2c0262af | bellard | int (*compute_all)(void); /* return all the flags */ |
185 | 2c0262af | bellard | int (*compute_c)(void); /* return the C flag */ |
186 | 2c0262af | bellard | } CCTable; |
187 | 2c0262af | bellard | |
188 | 2c0262af | bellard | extern CCTable cc_table[];
|
189 | 2c0262af | bellard | |
190 | 8e682019 | bellard | void load_seg(int seg_reg, int selector); |
191 | 08cea4ee | bellard | void helper_ljmp_protected_T0_T1(int next_eip); |
192 | 2c0262af | bellard | void helper_lcall_real_T0_T1(int shift, int next_eip); |
193 | 2c0262af | bellard | void helper_lcall_protected_T0_T1(int shift, int next_eip); |
194 | 2c0262af | bellard | void helper_iret_real(int shift); |
195 | 08cea4ee | bellard | void helper_iret_protected(int shift, int next_eip); |
196 | 2c0262af | bellard | void helper_lret_protected(int shift, int addend); |
197 | 2c0262af | bellard | void helper_lldt_T0(void); |
198 | 2c0262af | bellard | void helper_ltr_T0(void); |
199 | 2c0262af | bellard | void helper_movl_crN_T0(int reg); |
200 | 2c0262af | bellard | void helper_movl_drN_T0(int reg); |
201 | 2c0262af | bellard | void helper_invlpg(unsigned int addr); |
202 | 1ac157da | bellard | void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0);
|
203 | 14ce26e7 | bellard | void cpu_x86_update_cr3(CPUX86State *env, target_ulong new_cr3);
|
204 | 1ac157da | bellard | void cpu_x86_update_cr4(CPUX86State *env, uint32_t new_cr4);
|
205 | 2c0262af | bellard | void cpu_x86_flush_tlb(CPUX86State *env, uint32_t addr);
|
206 | 14ce26e7 | bellard | int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr,
|
207 | 61382a50 | bellard | int is_write, int is_user, int is_softmmu); |
208 | 14ce26e7 | bellard | void tlb_fill(target_ulong addr, int is_write, int is_user, |
209 | 61382a50 | bellard | void *retaddr);
|
210 | 2c0262af | bellard | void __hidden cpu_lock(void); |
211 | 2c0262af | bellard | void __hidden cpu_unlock(void); |
212 | 2c0262af | bellard | void do_interrupt(int intno, int is_int, int error_code, |
213 | 14ce26e7 | bellard | target_ulong next_eip, int is_hw);
|
214 | 2c0262af | bellard | void do_interrupt_user(int intno, int is_int, int error_code, |
215 | 14ce26e7 | bellard | target_ulong next_eip); |
216 | 2c0262af | bellard | void raise_interrupt(int intno, int is_int, int error_code, |
217 | a8ede8ba | bellard | int next_eip_addend);
|
218 | 2c0262af | bellard | void raise_exception_err(int exception_index, int error_code); |
219 | 2c0262af | bellard | void raise_exception(int exception_index); |
220 | 2c0262af | bellard | void __hidden cpu_loop_exit(void); |
221 | 2c0262af | bellard | |
222 | 2c0262af | bellard | void OPPROTO op_movl_eflags_T0(void); |
223 | 2c0262af | bellard | void OPPROTO op_movl_T0_eflags(void); |
224 | 14ce26e7 | bellard | void helper_divl_EAX_T0(void); |
225 | 14ce26e7 | bellard | void helper_idivl_EAX_T0(void); |
226 | 14ce26e7 | bellard | void helper_mulq_EAX_T0(void); |
227 | 14ce26e7 | bellard | void helper_imulq_EAX_T0(void); |
228 | 14ce26e7 | bellard | void helper_imulq_T0_T1(void); |
229 | 14ce26e7 | bellard | void helper_divq_EAX_T0(void); |
230 | 14ce26e7 | bellard | void helper_idivq_EAX_T0(void); |
231 | 2c0262af | bellard | void helper_cmpxchg8b(void); |
232 | 2c0262af | bellard | void helper_cpuid(void); |
233 | 61a8c4ec | bellard | void helper_enter_level(int level, int data32); |
234 | 023fe10d | bellard | void helper_sysenter(void); |
235 | 023fe10d | bellard | void helper_sysexit(void); |
236 | 06c2f506 | bellard | void helper_syscall(int next_eip_addend); |
237 | 14ce26e7 | bellard | void helper_sysret(int dflag); |
238 | 2c0262af | bellard | void helper_rdtsc(void); |
239 | 2c0262af | bellard | void helper_rdmsr(void); |
240 | 2c0262af | bellard | void helper_wrmsr(void); |
241 | 2c0262af | bellard | void helper_lsl(void); |
242 | 2c0262af | bellard | void helper_lar(void); |
243 | 3ab493de | bellard | void helper_verr(void); |
244 | 3ab493de | bellard | void helper_verw(void); |
245 | 2c0262af | bellard | |
246 | 3e25f951 | bellard | void check_iob_T0(void); |
247 | 3e25f951 | bellard | void check_iow_T0(void); |
248 | 3e25f951 | bellard | void check_iol_T0(void); |
249 | 3e25f951 | bellard | void check_iob_DX(void); |
250 | 3e25f951 | bellard | void check_iow_DX(void); |
251 | 3e25f951 | bellard | void check_iol_DX(void); |
252 | 3e25f951 | bellard | |
253 | 9951bf39 | bellard | /* XXX: move that to a generic header */
|
254 | 9951bf39 | bellard | #if !defined(CONFIG_USER_ONLY)
|
255 | 9951bf39 | bellard | |
256 | 9951bf39 | bellard | #define ldul_user ldl_user
|
257 | 9951bf39 | bellard | #define ldul_kernel ldl_kernel
|
258 | 9951bf39 | bellard | |
259 | 9951bf39 | bellard | #define ACCESS_TYPE 0 |
260 | 9951bf39 | bellard | #define MEMSUFFIX _kernel
|
261 | 9951bf39 | bellard | #define DATA_SIZE 1 |
262 | 9951bf39 | bellard | #include "softmmu_header.h" |
263 | 9951bf39 | bellard | |
264 | 9951bf39 | bellard | #define DATA_SIZE 2 |
265 | 9951bf39 | bellard | #include "softmmu_header.h" |
266 | 9951bf39 | bellard | |
267 | 9951bf39 | bellard | #define DATA_SIZE 4 |
268 | 9951bf39 | bellard | #include "softmmu_header.h" |
269 | 9951bf39 | bellard | |
270 | 9951bf39 | bellard | #define DATA_SIZE 8 |
271 | 9951bf39 | bellard | #include "softmmu_header.h" |
272 | 9951bf39 | bellard | #undef ACCESS_TYPE
|
273 | 9951bf39 | bellard | #undef MEMSUFFIX
|
274 | 9951bf39 | bellard | |
275 | 9951bf39 | bellard | #define ACCESS_TYPE 1 |
276 | 9951bf39 | bellard | #define MEMSUFFIX _user
|
277 | 9951bf39 | bellard | #define DATA_SIZE 1 |
278 | 9951bf39 | bellard | #include "softmmu_header.h" |
279 | 9951bf39 | bellard | |
280 | 9951bf39 | bellard | #define DATA_SIZE 2 |
281 | 9951bf39 | bellard | #include "softmmu_header.h" |
282 | 9951bf39 | bellard | |
283 | 9951bf39 | bellard | #define DATA_SIZE 4 |
284 | 9951bf39 | bellard | #include "softmmu_header.h" |
285 | 9951bf39 | bellard | |
286 | 9951bf39 | bellard | #define DATA_SIZE 8 |
287 | 9951bf39 | bellard | #include "softmmu_header.h" |
288 | 9951bf39 | bellard | #undef ACCESS_TYPE
|
289 | 9951bf39 | bellard | #undef MEMSUFFIX
|
290 | 9951bf39 | bellard | |
291 | 9951bf39 | bellard | /* these access are slower, they must be as rare as possible */
|
292 | 9951bf39 | bellard | #define ACCESS_TYPE 2 |
293 | 9951bf39 | bellard | #define MEMSUFFIX _data
|
294 | 9951bf39 | bellard | #define DATA_SIZE 1 |
295 | 9951bf39 | bellard | #include "softmmu_header.h" |
296 | 9951bf39 | bellard | |
297 | 9951bf39 | bellard | #define DATA_SIZE 2 |
298 | 9951bf39 | bellard | #include "softmmu_header.h" |
299 | 9951bf39 | bellard | |
300 | 9951bf39 | bellard | #define DATA_SIZE 4 |
301 | 9951bf39 | bellard | #include "softmmu_header.h" |
302 | 9951bf39 | bellard | |
303 | 9951bf39 | bellard | #define DATA_SIZE 8 |
304 | 9951bf39 | bellard | #include "softmmu_header.h" |
305 | 9951bf39 | bellard | #undef ACCESS_TYPE
|
306 | 9951bf39 | bellard | #undef MEMSUFFIX
|
307 | 9951bf39 | bellard | |
308 | 9951bf39 | bellard | #define ldub(p) ldub_data(p)
|
309 | 9951bf39 | bellard | #define ldsb(p) ldsb_data(p)
|
310 | 9951bf39 | bellard | #define lduw(p) lduw_data(p)
|
311 | 9951bf39 | bellard | #define ldsw(p) ldsw_data(p)
|
312 | 9951bf39 | bellard | #define ldl(p) ldl_data(p)
|
313 | 9951bf39 | bellard | #define ldq(p) ldq_data(p)
|
314 | 9951bf39 | bellard | |
315 | 9951bf39 | bellard | #define stb(p, v) stb_data(p, v)
|
316 | 9951bf39 | bellard | #define stw(p, v) stw_data(p, v)
|
317 | 9951bf39 | bellard | #define stl(p, v) stl_data(p, v)
|
318 | 9951bf39 | bellard | #define stq(p, v) stq_data(p, v)
|
319 | 9951bf39 | bellard | |
320 | 14ce26e7 | bellard | static inline double ldfq(target_ulong ptr) |
321 | 9951bf39 | bellard | { |
322 | 9951bf39 | bellard | union {
|
323 | 9951bf39 | bellard | double d;
|
324 | 9951bf39 | bellard | uint64_t i; |
325 | 9951bf39 | bellard | } u; |
326 | 9951bf39 | bellard | u.i = ldq(ptr); |
327 | 9951bf39 | bellard | return u.d;
|
328 | 9951bf39 | bellard | } |
329 | 9951bf39 | bellard | |
330 | 14ce26e7 | bellard | static inline void stfq(target_ulong ptr, double v) |
331 | 9951bf39 | bellard | { |
332 | 9951bf39 | bellard | union {
|
333 | 9951bf39 | bellard | double d;
|
334 | 9951bf39 | bellard | uint64_t i; |
335 | 9951bf39 | bellard | } u; |
336 | 9951bf39 | bellard | u.d = v; |
337 | 9951bf39 | bellard | stq(ptr, u.i); |
338 | 9951bf39 | bellard | } |
339 | 9951bf39 | bellard | |
340 | 14ce26e7 | bellard | static inline float ldfl(target_ulong ptr) |
341 | 9951bf39 | bellard | { |
342 | 9951bf39 | bellard | union {
|
343 | 9951bf39 | bellard | float f;
|
344 | 9951bf39 | bellard | uint32_t i; |
345 | 9951bf39 | bellard | } u; |
346 | 9951bf39 | bellard | u.i = ldl(ptr); |
347 | 9951bf39 | bellard | return u.f;
|
348 | 9951bf39 | bellard | } |
349 | 9951bf39 | bellard | |
350 | 14ce26e7 | bellard | static inline void stfl(target_ulong ptr, float v) |
351 | 9951bf39 | bellard | { |
352 | 9951bf39 | bellard | union {
|
353 | 9951bf39 | bellard | float f;
|
354 | 9951bf39 | bellard | uint32_t i; |
355 | 9951bf39 | bellard | } u; |
356 | 9951bf39 | bellard | u.f = v; |
357 | 9951bf39 | bellard | stl(ptr, u.i); |
358 | 9951bf39 | bellard | } |
359 | 9951bf39 | bellard | |
360 | 9951bf39 | bellard | #endif /* !defined(CONFIG_USER_ONLY) */ |
361 | 9951bf39 | bellard | |
362 | 2c0262af | bellard | #ifdef USE_X86LDOUBLE
|
363 | 2c0262af | bellard | /* use long double functions */
|
364 | 2c0262af | bellard | #define lrint lrintl
|
365 | 2c0262af | bellard | #define llrint llrintl
|
366 | 2c0262af | bellard | #define fabs fabsl
|
367 | 2c0262af | bellard | #define sin sinl
|
368 | 2c0262af | bellard | #define cos cosl
|
369 | 2c0262af | bellard | #define sqrt sqrtl
|
370 | 2c0262af | bellard | #define pow powl
|
371 | 2c0262af | bellard | #define log logl
|
372 | 2c0262af | bellard | #define tan tanl
|
373 | 2c0262af | bellard | #define atan2 atan2l
|
374 | 2c0262af | bellard | #define floor floorl
|
375 | 2c0262af | bellard | #define ceil ceill
|
376 | 2c0262af | bellard | #define rint rintl
|
377 | 2c0262af | bellard | #endif
|
378 | 2c0262af | bellard | |
379 | 7d3505c5 | bellard | #if !defined(_BSD)
|
380 | 2c0262af | bellard | extern int lrint(CPU86_LDouble x); |
381 | 2c0262af | bellard | extern int64_t llrint(CPU86_LDouble x);
|
382 | 7d3505c5 | bellard | #else
|
383 | 7d3505c5 | bellard | #define lrint(d) ((int)rint(d)) |
384 | 7d3505c5 | bellard | #define llrint(d) ((int)rint(d)) |
385 | 7d3505c5 | bellard | #endif
|
386 | 2c0262af | bellard | extern CPU86_LDouble fabs(CPU86_LDouble x);
|
387 | 2c0262af | bellard | extern CPU86_LDouble sin(CPU86_LDouble x);
|
388 | 2c0262af | bellard | extern CPU86_LDouble cos(CPU86_LDouble x);
|
389 | 2c0262af | bellard | extern CPU86_LDouble sqrt(CPU86_LDouble x);
|
390 | 2c0262af | bellard | extern CPU86_LDouble pow(CPU86_LDouble, CPU86_LDouble);
|
391 | 2c0262af | bellard | extern CPU86_LDouble log(CPU86_LDouble x);
|
392 | 2c0262af | bellard | extern CPU86_LDouble tan(CPU86_LDouble x);
|
393 | 2c0262af | bellard | extern CPU86_LDouble atan2(CPU86_LDouble, CPU86_LDouble);
|
394 | 2c0262af | bellard | extern CPU86_LDouble floor(CPU86_LDouble x);
|
395 | 2c0262af | bellard | extern CPU86_LDouble ceil(CPU86_LDouble x);
|
396 | 2c0262af | bellard | extern CPU86_LDouble rint(CPU86_LDouble x);
|
397 | 2c0262af | bellard | |
398 | 2c0262af | bellard | #define RC_MASK 0xc00 |
399 | 2c0262af | bellard | #define RC_NEAR 0x000 |
400 | 2c0262af | bellard | #define RC_DOWN 0x400 |
401 | 2c0262af | bellard | #define RC_UP 0x800 |
402 | 2c0262af | bellard | #define RC_CHOP 0xc00 |
403 | 2c0262af | bellard | |
404 | 2c0262af | bellard | #define MAXTAN 9223372036854775808.0 |
405 | 2c0262af | bellard | |
406 | 2c0262af | bellard | #ifdef __arm__
|
407 | 2c0262af | bellard | /* we have no way to do correct rounding - a FPU emulator is needed */
|
408 | 2c0262af | bellard | #define FE_DOWNWARD FE_TONEAREST
|
409 | 2c0262af | bellard | #define FE_UPWARD FE_TONEAREST
|
410 | 2c0262af | bellard | #define FE_TOWARDZERO FE_TONEAREST
|
411 | 2c0262af | bellard | #endif
|
412 | 2c0262af | bellard | |
413 | 2c0262af | bellard | #ifdef USE_X86LDOUBLE
|
414 | 2c0262af | bellard | |
415 | 2c0262af | bellard | /* only for x86 */
|
416 | 2c0262af | bellard | typedef union { |
417 | 2c0262af | bellard | long double d; |
418 | 2c0262af | bellard | struct {
|
419 | 2c0262af | bellard | unsigned long long lower; |
420 | 2c0262af | bellard | unsigned short upper; |
421 | 2c0262af | bellard | } l; |
422 | 2c0262af | bellard | } CPU86_LDoubleU; |
423 | 2c0262af | bellard | |
424 | 2c0262af | bellard | /* the following deal with x86 long double-precision numbers */
|
425 | 2c0262af | bellard | #define MAXEXPD 0x7fff |
426 | 2c0262af | bellard | #define EXPBIAS 16383 |
427 | 2c0262af | bellard | #define EXPD(fp) (fp.l.upper & 0x7fff) |
428 | 2c0262af | bellard | #define SIGND(fp) ((fp.l.upper) & 0x8000) |
429 | 2c0262af | bellard | #define MANTD(fp) (fp.l.lower)
|
430 | 2c0262af | bellard | #define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7fff)) | EXPBIAS |
431 | 2c0262af | bellard | |
432 | 2c0262af | bellard | #else
|
433 | 2c0262af | bellard | |
434 | 2c0262af | bellard | /* NOTE: arm is horrible as double 32 bit words are stored in big endian ! */
|
435 | 2c0262af | bellard | typedef union { |
436 | 2c0262af | bellard | double d;
|
437 | 2c0262af | bellard | #if !defined(WORDS_BIGENDIAN) && !defined(__arm__)
|
438 | 2c0262af | bellard | struct {
|
439 | 2c0262af | bellard | uint32_t lower; |
440 | 2c0262af | bellard | int32_t upper; |
441 | 2c0262af | bellard | } l; |
442 | 2c0262af | bellard | #else
|
443 | 2c0262af | bellard | struct {
|
444 | 2c0262af | bellard | int32_t upper; |
445 | 2c0262af | bellard | uint32_t lower; |
446 | 2c0262af | bellard | } l; |
447 | 2c0262af | bellard | #endif
|
448 | 2c0262af | bellard | #ifndef __arm__
|
449 | 2c0262af | bellard | int64_t ll; |
450 | 2c0262af | bellard | #endif
|
451 | 2c0262af | bellard | } CPU86_LDoubleU; |
452 | 2c0262af | bellard | |
453 | 2c0262af | bellard | /* the following deal with IEEE double-precision numbers */
|
454 | 2c0262af | bellard | #define MAXEXPD 0x7ff |
455 | 2c0262af | bellard | #define EXPBIAS 1023 |
456 | 2c0262af | bellard | #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) |
457 | 2c0262af | bellard | #define SIGND(fp) ((fp.l.upper) & 0x80000000) |
458 | 2c0262af | bellard | #ifdef __arm__
|
459 | 2c0262af | bellard | #define MANTD(fp) (fp.l.lower | ((uint64_t)(fp.l.upper & ((1 << 20) - 1)) << 32)) |
460 | 2c0262af | bellard | #else
|
461 | 2c0262af | bellard | #define MANTD(fp) (fp.ll & ((1LL << 52) - 1)) |
462 | 2c0262af | bellard | #endif
|
463 | 2c0262af | bellard | #define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7ff << 20)) | (EXPBIAS << 20) |
464 | 2c0262af | bellard | #endif
|
465 | 2c0262af | bellard | |
466 | 2c0262af | bellard | static inline void fpush(void) |
467 | 2c0262af | bellard | { |
468 | 2c0262af | bellard | env->fpstt = (env->fpstt - 1) & 7; |
469 | 2c0262af | bellard | env->fptags[env->fpstt] = 0; /* validate stack entry */ |
470 | 2c0262af | bellard | } |
471 | 2c0262af | bellard | |
472 | 2c0262af | bellard | static inline void fpop(void) |
473 | 2c0262af | bellard | { |
474 | 2c0262af | bellard | env->fptags[env->fpstt] = 1; /* invvalidate stack entry */ |
475 | 2c0262af | bellard | env->fpstt = (env->fpstt + 1) & 7; |
476 | 2c0262af | bellard | } |
477 | 2c0262af | bellard | |
478 | 2c0262af | bellard | #ifndef USE_X86LDOUBLE
|
479 | 14ce26e7 | bellard | static inline CPU86_LDouble helper_fldt(target_ulong ptr) |
480 | 2c0262af | bellard | { |
481 | 2c0262af | bellard | CPU86_LDoubleU temp; |
482 | 2c0262af | bellard | int upper, e;
|
483 | 2c0262af | bellard | uint64_t ll; |
484 | 2c0262af | bellard | |
485 | 2c0262af | bellard | /* mantissa */
|
486 | 2c0262af | bellard | upper = lduw(ptr + 8);
|
487 | 2c0262af | bellard | /* XXX: handle overflow ? */
|
488 | 2c0262af | bellard | e = (upper & 0x7fff) - 16383 + EXPBIAS; /* exponent */ |
489 | 2c0262af | bellard | e |= (upper >> 4) & 0x800; /* sign */ |
490 | 2c0262af | bellard | ll = (ldq(ptr) >> 11) & ((1LL << 52) - 1); |
491 | 2c0262af | bellard | #ifdef __arm__
|
492 | 2c0262af | bellard | temp.l.upper = (e << 20) | (ll >> 32); |
493 | 2c0262af | bellard | temp.l.lower = ll; |
494 | 2c0262af | bellard | #else
|
495 | 2c0262af | bellard | temp.ll = ll | ((uint64_t)e << 52);
|
496 | 2c0262af | bellard | #endif
|
497 | 2c0262af | bellard | return temp.d;
|
498 | 2c0262af | bellard | } |
499 | 2c0262af | bellard | |
500 | 664e0f19 | bellard | static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr) |
501 | 2c0262af | bellard | { |
502 | 2c0262af | bellard | CPU86_LDoubleU temp; |
503 | 2c0262af | bellard | int e;
|
504 | 2c0262af | bellard | |
505 | 2c0262af | bellard | temp.d = f; |
506 | 2c0262af | bellard | /* mantissa */
|
507 | 2c0262af | bellard | stq(ptr, (MANTD(temp) << 11) | (1LL << 63)); |
508 | 2c0262af | bellard | /* exponent + sign */
|
509 | 2c0262af | bellard | e = EXPD(temp) - EXPBIAS + 16383;
|
510 | 2c0262af | bellard | e |= SIGND(temp) >> 16;
|
511 | 2c0262af | bellard | stw(ptr + 8, e);
|
512 | 2c0262af | bellard | } |
513 | 9951bf39 | bellard | #else
|
514 | 9951bf39 | bellard | |
515 | 9951bf39 | bellard | /* XXX: same endianness assumed */
|
516 | 9951bf39 | bellard | |
517 | 9951bf39 | bellard | #ifdef CONFIG_USER_ONLY
|
518 | 9951bf39 | bellard | |
519 | 14ce26e7 | bellard | static inline CPU86_LDouble helper_fldt(target_ulong ptr) |
520 | 9951bf39 | bellard | { |
521 | 9951bf39 | bellard | return *(CPU86_LDouble *)ptr;
|
522 | 9951bf39 | bellard | } |
523 | 9951bf39 | bellard | |
524 | 14ce26e7 | bellard | static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr) |
525 | 9951bf39 | bellard | { |
526 | 9951bf39 | bellard | *(CPU86_LDouble *)ptr = f; |
527 | 9951bf39 | bellard | } |
528 | 9951bf39 | bellard | |
529 | 9951bf39 | bellard | #else
|
530 | 9951bf39 | bellard | |
531 | 9951bf39 | bellard | /* we use memory access macros */
|
532 | 9951bf39 | bellard | |
533 | 14ce26e7 | bellard | static inline CPU86_LDouble helper_fldt(target_ulong ptr) |
534 | 9951bf39 | bellard | { |
535 | 9951bf39 | bellard | CPU86_LDoubleU temp; |
536 | 9951bf39 | bellard | |
537 | 9951bf39 | bellard | temp.l.lower = ldq(ptr); |
538 | 9951bf39 | bellard | temp.l.upper = lduw(ptr + 8);
|
539 | 9951bf39 | bellard | return temp.d;
|
540 | 9951bf39 | bellard | } |
541 | 9951bf39 | bellard | |
542 | 14ce26e7 | bellard | static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr) |
543 | 9951bf39 | bellard | { |
544 | 9951bf39 | bellard | CPU86_LDoubleU temp; |
545 | 9951bf39 | bellard | |
546 | 9951bf39 | bellard | temp.d = f; |
547 | 9951bf39 | bellard | stq(ptr, temp.l.lower); |
548 | 9951bf39 | bellard | stw(ptr + 8, temp.l.upper);
|
549 | 9951bf39 | bellard | } |
550 | 9951bf39 | bellard | |
551 | 9951bf39 | bellard | #endif /* !CONFIG_USER_ONLY */ |
552 | 9951bf39 | bellard | |
553 | 9951bf39 | bellard | #endif /* USE_X86LDOUBLE */ |
554 | 2c0262af | bellard | |
555 | 2ee73ac3 | bellard | #define FPUS_IE (1 << 0) |
556 | 2ee73ac3 | bellard | #define FPUS_DE (1 << 1) |
557 | 2ee73ac3 | bellard | #define FPUS_ZE (1 << 2) |
558 | 2ee73ac3 | bellard | #define FPUS_OE (1 << 3) |
559 | 2ee73ac3 | bellard | #define FPUS_UE (1 << 4) |
560 | 2ee73ac3 | bellard | #define FPUS_PE (1 << 5) |
561 | 2ee73ac3 | bellard | #define FPUS_SF (1 << 6) |
562 | 2ee73ac3 | bellard | #define FPUS_SE (1 << 7) |
563 | 2ee73ac3 | bellard | #define FPUS_B (1 << 15) |
564 | 2ee73ac3 | bellard | |
565 | 2ee73ac3 | bellard | #define FPUC_EM 0x3f |
566 | 2ee73ac3 | bellard | |
567 | 83fb7adf | bellard | extern const CPU86_LDouble f15rk[7]; |
568 | 2c0262af | bellard | |
569 | 2c0262af | bellard | void helper_fldt_ST0_A0(void); |
570 | 2c0262af | bellard | void helper_fstt_ST0_A0(void); |
571 | 2ee73ac3 | bellard | void fpu_raise_exception(void); |
572 | 2ee73ac3 | bellard | CPU86_LDouble helper_fdiv(CPU86_LDouble a, CPU86_LDouble b); |
573 | 2c0262af | bellard | void helper_fbld_ST0_A0(void); |
574 | 2c0262af | bellard | void helper_fbst_ST0_A0(void); |
575 | 2c0262af | bellard | void helper_f2xm1(void); |
576 | 2c0262af | bellard | void helper_fyl2x(void); |
577 | 2c0262af | bellard | void helper_fptan(void); |
578 | 2c0262af | bellard | void helper_fpatan(void); |
579 | 2c0262af | bellard | void helper_fxtract(void); |
580 | 2c0262af | bellard | void helper_fprem1(void); |
581 | 2c0262af | bellard | void helper_fprem(void); |
582 | 2c0262af | bellard | void helper_fyl2xp1(void); |
583 | 2c0262af | bellard | void helper_fsqrt(void); |
584 | 2c0262af | bellard | void helper_fsincos(void); |
585 | 2c0262af | bellard | void helper_frndint(void); |
586 | 2c0262af | bellard | void helper_fscale(void); |
587 | 2c0262af | bellard | void helper_fsin(void); |
588 | 2c0262af | bellard | void helper_fcos(void); |
589 | 2c0262af | bellard | void helper_fxam_ST0(void); |
590 | 14ce26e7 | bellard | void helper_fstenv(target_ulong ptr, int data32); |
591 | 14ce26e7 | bellard | void helper_fldenv(target_ulong ptr, int data32); |
592 | 14ce26e7 | bellard | void helper_fsave(target_ulong ptr, int data32); |
593 | 14ce26e7 | bellard | void helper_frstor(target_ulong ptr, int data32); |
594 | 14ce26e7 | bellard | void helper_fxsave(target_ulong ptr, int data64); |
595 | 14ce26e7 | bellard | void helper_fxrstor(target_ulong ptr, int data64); |
596 | 03857e31 | bellard | void restore_native_fp_state(CPUState *env);
|
597 | 03857e31 | bellard | void save_native_fp_state(CPUState *env);
|
598 | 664e0f19 | bellard | float approx_rsqrt(float a); |
599 | 664e0f19 | bellard | float approx_rcp(float a); |
600 | 79f91c27 | bellard | double helper_sqrt(double a); |
601 | 664e0f19 | bellard | int fpu_isnan(double a); |
602 | 2c0262af | bellard | |
603 | 83fb7adf | bellard | extern const uint8_t parity_table[256]; |
604 | 83fb7adf | bellard | extern const uint8_t rclw_table[32]; |
605 | 83fb7adf | bellard | extern const uint8_t rclb_table[32]; |
606 | 2c0262af | bellard | |
607 | 2c0262af | bellard | static inline uint32_t compute_eflags(void) |
608 | 2c0262af | bellard | { |
609 | 2c0262af | bellard | return env->eflags | cc_table[CC_OP].compute_all() | (DF & DF_MASK);
|
610 | 2c0262af | bellard | } |
611 | 2c0262af | bellard | |
612 | 2c0262af | bellard | /* NOTE: CC_OP must be modified manually to CC_OP_EFLAGS */
|
613 | 2c0262af | bellard | static inline void load_eflags(int eflags, int update_mask) |
614 | 2c0262af | bellard | { |
615 | 2c0262af | bellard | CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
616 | 2c0262af | bellard | DF = 1 - (2 * ((eflags >> 10) & 1)); |
617 | 2c0262af | bellard | env->eflags = (env->eflags & ~update_mask) | |
618 | 2c0262af | bellard | (eflags & update_mask); |
619 | 2c0262af | bellard | } |
620 | 2c0262af | bellard | |
621 | 0d1a29f9 | bellard | static inline void env_to_regs(void) |
622 | 0d1a29f9 | bellard | { |
623 | 0d1a29f9 | bellard | #ifdef reg_EAX
|
624 | 0d1a29f9 | bellard | EAX = env->regs[R_EAX]; |
625 | 0d1a29f9 | bellard | #endif
|
626 | 0d1a29f9 | bellard | #ifdef reg_ECX
|
627 | 0d1a29f9 | bellard | ECX = env->regs[R_ECX]; |
628 | 0d1a29f9 | bellard | #endif
|
629 | 0d1a29f9 | bellard | #ifdef reg_EDX
|
630 | 0d1a29f9 | bellard | EDX = env->regs[R_EDX]; |
631 | 0d1a29f9 | bellard | #endif
|
632 | 0d1a29f9 | bellard | #ifdef reg_EBX
|
633 | 0d1a29f9 | bellard | EBX = env->regs[R_EBX]; |
634 | 0d1a29f9 | bellard | #endif
|
635 | 0d1a29f9 | bellard | #ifdef reg_ESP
|
636 | 0d1a29f9 | bellard | ESP = env->regs[R_ESP]; |
637 | 0d1a29f9 | bellard | #endif
|
638 | 0d1a29f9 | bellard | #ifdef reg_EBP
|
639 | 0d1a29f9 | bellard | EBP = env->regs[R_EBP]; |
640 | 0d1a29f9 | bellard | #endif
|
641 | 0d1a29f9 | bellard | #ifdef reg_ESI
|
642 | 0d1a29f9 | bellard | ESI = env->regs[R_ESI]; |
643 | 0d1a29f9 | bellard | #endif
|
644 | 0d1a29f9 | bellard | #ifdef reg_EDI
|
645 | 0d1a29f9 | bellard | EDI = env->regs[R_EDI]; |
646 | 0d1a29f9 | bellard | #endif
|
647 | 0d1a29f9 | bellard | } |
648 | 0d1a29f9 | bellard | |
649 | 0d1a29f9 | bellard | static inline void regs_to_env(void) |
650 | 0d1a29f9 | bellard | { |
651 | 0d1a29f9 | bellard | #ifdef reg_EAX
|
652 | 0d1a29f9 | bellard | env->regs[R_EAX] = EAX; |
653 | 0d1a29f9 | bellard | #endif
|
654 | 0d1a29f9 | bellard | #ifdef reg_ECX
|
655 | 0d1a29f9 | bellard | env->regs[R_ECX] = ECX; |
656 | 0d1a29f9 | bellard | #endif
|
657 | 0d1a29f9 | bellard | #ifdef reg_EDX
|
658 | 0d1a29f9 | bellard | env->regs[R_EDX] = EDX; |
659 | 0d1a29f9 | bellard | #endif
|
660 | 0d1a29f9 | bellard | #ifdef reg_EBX
|
661 | 0d1a29f9 | bellard | env->regs[R_EBX] = EBX; |
662 | 0d1a29f9 | bellard | #endif
|
663 | 0d1a29f9 | bellard | #ifdef reg_ESP
|
664 | 0d1a29f9 | bellard | env->regs[R_ESP] = ESP; |
665 | 0d1a29f9 | bellard | #endif
|
666 | 0d1a29f9 | bellard | #ifdef reg_EBP
|
667 | 0d1a29f9 | bellard | env->regs[R_EBP] = EBP; |
668 | 0d1a29f9 | bellard | #endif
|
669 | 0d1a29f9 | bellard | #ifdef reg_ESI
|
670 | 0d1a29f9 | bellard | env->regs[R_ESI] = ESI; |
671 | 0d1a29f9 | bellard | #endif
|
672 | 0d1a29f9 | bellard | #ifdef reg_EDI
|
673 | 0d1a29f9 | bellard | env->regs[R_EDI] = EDI; |
674 | 0d1a29f9 | bellard | #endif
|
675 | 0d1a29f9 | bellard | } |