]>
Commit | Line | Data |
---|---|---|
2c0262af | 1 | /* |
5fafdf24 | 2 | * i386 execution defines |
2c0262af FB |
3 | * |
4 | * Copyright (c) 2003 Fabrice Bellard | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
8167ee88 | 17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
2c0262af | 18 | */ |
7d3505c5 | 19 | #include "config.h" |
2c0262af FB |
20 | #include "dyngen-exec.h" |
21 | ||
14ce26e7 | 22 | /* XXX: factorize this mess */ |
14ce26e7 FB |
23 | #ifdef TARGET_X86_64 |
24 | #define TARGET_LONG_BITS 64 | |
25 | #else | |
26 | #define TARGET_LONG_BITS 32 | |
27 | #endif | |
28 | ||
d785e6be FB |
29 | #include "cpu-defs.h" |
30 | ||
2c0262af | 31 | register struct CPUX86State *env asm(AREG0); |
14ce26e7 | 32 | |
7d99a001 | 33 | #include "qemu-common.h" |
79383c9c | 34 | #include "qemu-log.h" |
2c0262af | 35 | |
aba1d00a | 36 | #undef EAX |
2c0262af | 37 | #define EAX (env->regs[R_EAX]) |
aba1d00a | 38 | #undef ECX |
2c0262af | 39 | #define ECX (env->regs[R_ECX]) |
aba1d00a | 40 | #undef EDX |
2c0262af | 41 | #define EDX (env->regs[R_EDX]) |
aba1d00a | 42 | #undef EBX |
2c0262af | 43 | #define EBX (env->regs[R_EBX]) |
aba1d00a | 44 | #undef ESP |
2c0262af | 45 | #define ESP (env->regs[R_ESP]) |
aba1d00a | 46 | #undef EBP |
2c0262af | 47 | #define EBP (env->regs[R_EBP]) |
aba1d00a | 48 | #undef ESI |
2c0262af | 49 | #define ESI (env->regs[R_ESI]) |
aba1d00a | 50 | #undef EDI |
2c0262af | 51 | #define EDI (env->regs[R_EDI]) |
aba1d00a | 52 | #undef EIP |
1e4840bf | 53 | #define EIP (env->eip) |
2c0262af FB |
54 | #define DF (env->df) |
55 | ||
56 | #define CC_SRC (env->cc_src) | |
57 | #define CC_DST (env->cc_dst) | |
58 | #define CC_OP (env->cc_op) | |
59 | ||
60 | /* float macros */ | |
61 | #define FT0 (env->ft0) | |
664e0f19 FB |
62 | #define ST0 (env->fpregs[env->fpstt].d) |
63 | #define ST(n) (env->fpregs[(env->fpstt + (n)) & 7].d) | |
2c0262af FB |
64 | #define ST1 ST(1) |
65 | ||
2c0262af FB |
66 | #include "cpu.h" |
67 | #include "exec-all.h" | |
68 | ||
d9957a8b | 69 | /* op_helper.c */ |
5fafdf24 | 70 | void do_interrupt(int intno, int is_int, int error_code, |
14ce26e7 | 71 | target_ulong next_eip, int is_hw); |
5fafdf24 | 72 | void do_interrupt_user(int intno, int is_int, int error_code, |
14ce26e7 | 73 | target_ulong next_eip); |
a5e50b26 | 74 | void QEMU_NORETURN raise_exception_err(int exception_index, int error_code); |
75 | void QEMU_NORETURN raise_exception(int exception_index); | |
63a54736 | 76 | void QEMU_NORETURN raise_exception_env(int exception_index, CPUState *nenv); |
3b21e03e | 77 | void do_smm_enter(void); |
2c0262af | 78 | |
b6abf97d FB |
79 | /* n must be a constant to be efficient */ |
80 | static inline target_long lshift(target_long x, int n) | |
81 | { | |
82 | if (n >= 0) | |
83 | return x << n; | |
84 | else | |
85 | return x >> (-n); | |
86 | } | |
87 | ||
57fec1fe FB |
88 | #include "helper.h" |
89 | ||
b8b6a50b FB |
90 | static inline void svm_check_intercept(uint32_t type) |
91 | { | |
92 | helper_svm_check_intercept_param(type, 0); | |
93 | } | |
3e25f951 | 94 | |
9951bf39 FB |
95 | #if !defined(CONFIG_USER_ONLY) |
96 | ||
a9049a07 | 97 | #include "softmmu_exec.h" |
9951bf39 | 98 | |
9951bf39 FB |
99 | #endif /* !defined(CONFIG_USER_ONLY) */ |
100 | ||
2c0262af FB |
101 | #ifdef USE_X86LDOUBLE |
102 | /* use long double functions */ | |
7a0e1f41 FB |
103 | #define floatx_to_int32 floatx80_to_int32 |
104 | #define floatx_to_int64 floatx80_to_int64 | |
465e9838 FB |
105 | #define floatx_to_int32_round_to_zero floatx80_to_int32_round_to_zero |
106 | #define floatx_to_int64_round_to_zero floatx80_to_int64_round_to_zero | |
19e6c4b8 FB |
107 | #define int32_to_floatx int32_to_floatx80 |
108 | #define int64_to_floatx int64_to_floatx80 | |
109 | #define float32_to_floatx float32_to_floatx80 | |
110 | #define float64_to_floatx float64_to_floatx80 | |
111 | #define floatx_to_float32 floatx80_to_float32 | |
112 | #define floatx_to_float64 floatx80_to_float64 | |
67dd64bf | 113 | #define floatx_add floatx80_add |
13822781 | 114 | #define floatx_div floatx80_div |
67dd64bf AJ |
115 | #define floatx_mul floatx80_mul |
116 | #define floatx_sub floatx80_sub | |
7a0e1f41 FB |
117 | #define floatx_abs floatx80_abs |
118 | #define floatx_chs floatx80_chs | |
be1c17c7 | 119 | #define floatx_scalbn floatx80_scalbn |
7a0e1f41 | 120 | #define floatx_round_to_int floatx80_round_to_int |
8422b113 FB |
121 | #define floatx_compare floatx80_compare |
122 | #define floatx_compare_quiet floatx80_compare_quiet | |
be1c17c7 | 123 | #define floatx_is_any_nan floatx80_is_any_nan |
13822781 | 124 | #define floatx_is_zero floatx80_is_zero |
7d3505c5 | 125 | #else |
7a0e1f41 FB |
126 | #define floatx_to_int32 float64_to_int32 |
127 | #define floatx_to_int64 float64_to_int64 | |
465e9838 FB |
128 | #define floatx_to_int32_round_to_zero float64_to_int32_round_to_zero |
129 | #define floatx_to_int64_round_to_zero float64_to_int64_round_to_zero | |
19e6c4b8 FB |
130 | #define int32_to_floatx int32_to_float64 |
131 | #define int64_to_floatx int64_to_float64 | |
132 | #define float32_to_floatx float32_to_float64 | |
133 | #define float64_to_floatx(x, e) (x) | |
134 | #define floatx_to_float32 float64_to_float32 | |
135 | #define floatx_to_float64(x, e) (x) | |
67dd64bf | 136 | #define floatx_add float64_add |
13822781 | 137 | #define floatx_div float64_div |
67dd64bf AJ |
138 | #define floatx_mul float64_mul |
139 | #define floatx_sub float64_sub | |
7a0e1f41 FB |
140 | #define floatx_abs float64_abs |
141 | #define floatx_chs float64_chs | |
be1c17c7 | 142 | #define floatx_scalbn float64_scalbn |
7a0e1f41 | 143 | #define floatx_round_to_int float64_round_to_int |
8422b113 FB |
144 | #define floatx_compare float64_compare |
145 | #define floatx_compare_quiet float64_compare_quiet | |
be1c17c7 | 146 | #define floatx_is_any_nan float64_is_any_nan |
13822781 | 147 | #define floatx_is_zero float64_is_zero |
7d3505c5 | 148 | #endif |
7a0e1f41 | 149 | |
2c0262af FB |
150 | #define RC_MASK 0xc00 |
151 | #define RC_NEAR 0x000 | |
152 | #define RC_DOWN 0x400 | |
153 | #define RC_UP 0x800 | |
154 | #define RC_CHOP 0xc00 | |
155 | ||
156 | #define MAXTAN 9223372036854775808.0 | |
157 | ||
2c0262af FB |
158 | #ifdef USE_X86LDOUBLE |
159 | ||
160 | /* only for x86 */ | |
c4137223 | 161 | typedef CPU_LDoubleU CPU86_LDoubleU; |
2c0262af FB |
162 | |
163 | /* the following deal with x86 long double-precision numbers */ | |
164 | #define MAXEXPD 0x7fff | |
165 | #define EXPBIAS 16383 | |
166 | #define EXPD(fp) (fp.l.upper & 0x7fff) | |
167 | #define SIGND(fp) ((fp.l.upper) & 0x8000) | |
168 | #define MANTD(fp) (fp.l.lower) | |
169 | #define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7fff)) | EXPBIAS | |
170 | ||
171 | #else | |
172 | ||
c4137223 | 173 | typedef CPU_DoubleU CPU86_LDoubleU; |
2c0262af FB |
174 | |
175 | /* the following deal with IEEE double-precision numbers */ | |
176 | #define MAXEXPD 0x7ff | |
177 | #define EXPBIAS 1023 | |
178 | #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) | |
179 | #define SIGND(fp) ((fp.l.upper) & 0x80000000) | |
180 | #ifdef __arm__ | |
181 | #define MANTD(fp) (fp.l.lower | ((uint64_t)(fp.l.upper & ((1 << 20) - 1)) << 32)) | |
182 | #else | |
183 | #define MANTD(fp) (fp.ll & ((1LL << 52) - 1)) | |
184 | #endif | |
185 | #define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7ff << 20)) | (EXPBIAS << 20) | |
186 | #endif | |
187 | ||
188 | static inline void fpush(void) | |
189 | { | |
190 | env->fpstt = (env->fpstt - 1) & 7; | |
191 | env->fptags[env->fpstt] = 0; /* validate stack entry */ | |
192 | } | |
193 | ||
194 | static inline void fpop(void) | |
195 | { | |
196 | env->fptags[env->fpstt] = 1; /* invvalidate stack entry */ | |
197 | env->fpstt = (env->fpstt + 1) & 7; | |
198 | } | |
199 | ||
200 | #ifndef USE_X86LDOUBLE | |
14ce26e7 | 201 | static inline CPU86_LDouble helper_fldt(target_ulong ptr) |
2c0262af FB |
202 | { |
203 | CPU86_LDoubleU temp; | |
204 | int upper, e; | |
205 | uint64_t ll; | |
206 | ||
207 | /* mantissa */ | |
208 | upper = lduw(ptr + 8); | |
209 | /* XXX: handle overflow ? */ | |
210 | e = (upper & 0x7fff) - 16383 + EXPBIAS; /* exponent */ | |
211 | e |= (upper >> 4) & 0x800; /* sign */ | |
212 | ll = (ldq(ptr) >> 11) & ((1LL << 52) - 1); | |
213 | #ifdef __arm__ | |
214 | temp.l.upper = (e << 20) | (ll >> 32); | |
215 | temp.l.lower = ll; | |
216 | #else | |
217 | temp.ll = ll | ((uint64_t)e << 52); | |
218 | #endif | |
219 | return temp.d; | |
220 | } | |
221 | ||
664e0f19 | 222 | static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr) |
2c0262af FB |
223 | { |
224 | CPU86_LDoubleU temp; | |
225 | int e; | |
226 | ||
227 | temp.d = f; | |
228 | /* mantissa */ | |
229 | stq(ptr, (MANTD(temp) << 11) | (1LL << 63)); | |
230 | /* exponent + sign */ | |
231 | e = EXPD(temp) - EXPBIAS + 16383; | |
232 | e |= SIGND(temp) >> 16; | |
233 | stw(ptr + 8, e); | |
234 | } | |
9951bf39 FB |
235 | #else |
236 | ||
9951bf39 FB |
237 | /* we use memory access macros */ |
238 | ||
14ce26e7 | 239 | static inline CPU86_LDouble helper_fldt(target_ulong ptr) |
9951bf39 FB |
240 | { |
241 | CPU86_LDoubleU temp; | |
242 | ||
243 | temp.l.lower = ldq(ptr); | |
244 | temp.l.upper = lduw(ptr + 8); | |
245 | return temp.d; | |
246 | } | |
247 | ||
14ce26e7 | 248 | static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr) |
9951bf39 FB |
249 | { |
250 | CPU86_LDoubleU temp; | |
3b46e624 | 251 | |
9951bf39 FB |
252 | temp.d = f; |
253 | stq(ptr, temp.l.lower); | |
254 | stw(ptr + 8, temp.l.upper); | |
255 | } | |
256 | ||
9951bf39 | 257 | #endif /* USE_X86LDOUBLE */ |
2c0262af | 258 | |
2ee73ac3 FB |
259 | #define FPUS_IE (1 << 0) |
260 | #define FPUS_DE (1 << 1) | |
261 | #define FPUS_ZE (1 << 2) | |
262 | #define FPUS_OE (1 << 3) | |
263 | #define FPUS_UE (1 << 4) | |
264 | #define FPUS_PE (1 << 5) | |
265 | #define FPUS_SF (1 << 6) | |
266 | #define FPUS_SE (1 << 7) | |
267 | #define FPUS_B (1 << 15) | |
268 | ||
269 | #define FPUC_EM 0x3f | |
270 | ||
2c0262af FB |
271 | static inline uint32_t compute_eflags(void) |
272 | { | |
a7812ae4 | 273 | return env->eflags | helper_cc_compute_all(CC_OP) | (DF & DF_MASK); |
2c0262af FB |
274 | } |
275 | ||
2c0262af FB |
276 | /* NOTE: CC_OP must be modified manually to CC_OP_EFLAGS */ |
277 | static inline void load_eflags(int eflags, int update_mask) | |
278 | { | |
279 | CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); | |
280 | DF = 1 - (2 * ((eflags >> 10) & 1)); | |
5fafdf24 | 281 | env->eflags = (env->eflags & ~update_mask) | |
093f8f06 | 282 | (eflags & update_mask) | 0x2; |
2c0262af FB |
283 | } |
284 | ||
6a4955a8 AL |
285 | static inline int cpu_has_work(CPUState *env) |
286 | { | |
ac098781 JK |
287 | return ((env->interrupt_request & CPU_INTERRUPT_HARD) && |
288 | (env->eflags & IF_MASK)) || | |
289 | (env->interrupt_request & (CPU_INTERRUPT_NMI | | |
290 | CPU_INTERRUPT_INIT | | |
291 | CPU_INTERRUPT_SIPI | | |
292 | CPU_INTERRUPT_MCE)); | |
6a4955a8 AL |
293 | } |
294 | ||
5efc27bb FB |
295 | /* load efer and update the corresponding hflags. XXX: do consistency |
296 | checks with cpuid bits ? */ | |
297 | static inline void cpu_load_efer(CPUState *env, uint64_t val) | |
298 | { | |
299 | env->efer = val; | |
300 | env->hflags &= ~(HF_LMA_MASK | HF_SVME_MASK); | |
301 | if (env->efer & MSR_EFER_LMA) | |
302 | env->hflags |= HF_LMA_MASK; | |
303 | if (env->efer & MSR_EFER_SVME) | |
304 | env->hflags |= HF_SVME_MASK; | |
305 | } | |
10eb0cc0 PB |
306 | |
307 | static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb) | |
308 | { | |
309 | env->eip = tb->pc - tb->cs_base; | |
310 | } | |
311 |