VirtualBox

source: vbox/trunk/src/recompiler/target-i386/exec.h@ 61793

Last change on this file since 61793 was 53624, checked in by vboxsync, 10 years ago

scm automatic cleanups.

  • Property svn:eol-style set to native
File size: 9.5 KB
Line 
1/*
2 * i386 execution defines
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
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
22 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
23 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
24 * a choice of LGPL license versions is made available with the language indicating
25 * that LGPLv2 or any later version may be used, or where a choice of which version
26 * of the LGPL is applied is otherwise unspecified.
27 */
28
29#include "config.h"
30#include "dyngen-exec.h"
31
32/* XXX: factorize this mess */
33#ifdef TARGET_X86_64
34#define TARGET_LONG_BITS 64
35#else
36#define TARGET_LONG_BITS 32
37#endif
38
39#include "cpu-defs.h"
40
41register struct CPUX86State *env asm(AREG0);
42
43#include "qemu-common.h"
44#include "qemu-log.h"
45
46#undef EAX
47#define EAX (env->regs[R_EAX])
48#undef ECX
49#define ECX (env->regs[R_ECX])
50#undef EDX
51#define EDX (env->regs[R_EDX])
52#undef EBX
53#define EBX (env->regs[R_EBX])
54#undef ESP
55#define ESP (env->regs[R_ESP])
56#undef EBP
57#define EBP (env->regs[R_EBP])
58#undef ESI
59#define ESI (env->regs[R_ESI])
60#undef EDI
61#define EDI (env->regs[R_EDI])
62#undef EIP
63#define EIP (env->eip)
64#define DF (env->df)
65
66#define CC_SRC (env->cc_src)
67#define CC_DST (env->cc_dst)
68#define CC_OP (env->cc_op)
69
70/* float macros */
71#define FT0 (env->ft0)
72#define ST0 (env->fpregs[env->fpstt].d)
73#define ST(n) (env->fpregs[(env->fpstt + (n)) & 7].d)
74#define ST1 ST(1)
75
76#include "cpu.h"
77#include "exec-all.h"
78
79/* op_helper.c */
80void do_interrupt(int intno, int is_int, int error_code,
81 target_ulong next_eip, int is_hw);
82void do_interrupt_user(int intno, int is_int, int error_code,
83 target_ulong next_eip);
84void QEMU_NORETURN raise_exception_err(int exception_index, int error_code);
85void QEMU_NORETURN raise_exception(int exception_index);
86void QEMU_NORETURN raise_exception_env(int exception_index, CPUState *nenv);
87void do_smm_enter(void);
88
89/* n must be a constant to be efficient */
90static inline target_long lshift(target_long x, int n)
91{
92 if (n >= 0)
93 return x << n;
94 else
95 return x >> (-n);
96}
97
98#include "helper.h"
99
100static inline void svm_check_intercept(uint32_t type)
101{
102 helper_svm_check_intercept_param(type, 0);
103}
104
105#if !defined(CONFIG_USER_ONLY)
106
107#include "softmmu_exec.h"
108
109#endif /* !defined(CONFIG_USER_ONLY) */
110
111#ifdef USE_X86LDOUBLE
112/* use long double functions */
113#define floatx_to_int32 floatx80_to_int32
114#define floatx_to_int64 floatx80_to_int64
115#define floatx_to_int32_round_to_zero floatx80_to_int32_round_to_zero
116#define floatx_to_int64_round_to_zero floatx80_to_int64_round_to_zero
117#define int32_to_floatx int32_to_floatx80
118#define int64_to_floatx int64_to_floatx80
119#define float32_to_floatx float32_to_floatx80
120#define float64_to_floatx float64_to_floatx80
121#define floatx_to_float32 floatx80_to_float32
122#define floatx_to_float64 floatx80_to_float64
123#define floatx_abs floatx80_abs
124#define floatx_chs floatx80_chs
125#define floatx_round_to_int floatx80_round_to_int
126#define floatx_compare floatx80_compare
127#define floatx_compare_quiet floatx80_compare_quiet
128#else
129#define floatx_to_int32 float64_to_int32
130#define floatx_to_int64 float64_to_int64
131#define floatx_to_int32_round_to_zero float64_to_int32_round_to_zero
132#define floatx_to_int64_round_to_zero float64_to_int64_round_to_zero
133#define int32_to_floatx int32_to_float64
134#define int64_to_floatx int64_to_float64
135#define float32_to_floatx float32_to_float64
136#define float64_to_floatx(x, e) (x)
137#define floatx_to_float32 float64_to_float32
138#define floatx_to_float64(x, e) (x)
139#define floatx_abs float64_abs
140#define floatx_chs float64_chs
141#define floatx_round_to_int float64_round_to_int
142#define floatx_compare float64_compare
143#define floatx_compare_quiet float64_compare_quiet
144#endif
145
146#ifdef VBOX
147# ifdef IPRT_NO_CRT
148# undef sin
149# undef cos
150# undef sqrt
151# undef pow
152# undef log
153# undef tan
154# undef atan2
155# undef floor
156# undef ceil
157# undef ldexp
158# define sin sinl
159# define cos cosl
160# define sqrt sqrtl
161# define pow powl
162# define log logl
163# define tan tanl
164# define atan2 atan2l
165# define floor floorl
166# define ceil ceill
167# define ldexp ldexpl
168# endif
169#endif
170
171#define RC_MASK 0xc00
172#define RC_NEAR 0x000
173#define RC_DOWN 0x400
174#define RC_UP 0x800
175#define RC_CHOP 0xc00
176
177#define MAXTAN 9223372036854775808.0
178
179#ifdef USE_X86LDOUBLE
180
181/* only for x86 */
182typedef union {
183 long double d;
184 struct {
185 unsigned long long lower;
186 unsigned short upper;
187 } l;
188} CPU86_LDoubleU;
189
190/* the following deal with x86 long double-precision numbers */
191#define MAXEXPD 0x7fff
192#define EXPBIAS 16383
193#define EXPD(fp) (fp.l.upper & 0x7fff)
194#define SIGND(fp) ((fp.l.upper) & 0x8000)
195#define MANTD(fp) (fp.l.lower)
196#define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7fff)) | EXPBIAS
197
198#else
199
200/* NOTE: arm is horrible as double 32 bit words are stored in big endian ! */
201typedef union {
202 double d;
203#if !defined(HOST_WORDS_BIGENDIAN) && !defined(__arm__)
204 struct {
205 uint32_t lower;
206 int32_t upper;
207 } l;
208#else
209 struct {
210 int32_t upper;
211 uint32_t lower;
212 } l;
213#endif
214#ifndef __arm__
215 int64_t ll;
216#endif
217} CPU86_LDoubleU;
218
219/* the following deal with IEEE double-precision numbers */
220#define MAXEXPD 0x7ff
221#define EXPBIAS 1023
222#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
223#define SIGND(fp) ((fp.l.upper) & 0x80000000)
224#ifdef __arm__
225#define MANTD(fp) (fp.l.lower | ((uint64_t)(fp.l.upper & ((1 << 20) - 1)) << 32))
226#else
227#define MANTD(fp) (fp.ll & ((1LL << 52) - 1))
228#endif
229#define BIASEXPONENT(fp) fp.l.upper = (fp.l.upper & ~(0x7ff << 20)) | (EXPBIAS << 20)
230#endif
231
232static inline void fpush(void)
233{
234 env->fpstt = (env->fpstt - 1) & 7;
235 env->fptags[env->fpstt] = 0; /* validate stack entry */
236}
237
238static inline void fpop(void)
239{
240 env->fptags[env->fpstt] = 1; /* invvalidate stack entry */
241 env->fpstt = (env->fpstt + 1) & 7;
242}
243
244#ifndef USE_X86LDOUBLE
245static inline CPU86_LDouble helper_fldt(target_ulong ptr)
246{
247 CPU86_LDoubleU temp;
248 int upper, e;
249 uint64_t ll;
250
251 /* mantissa */
252 upper = lduw(ptr + 8);
253 /* XXX: handle overflow ? */
254 e = (upper & 0x7fff) - 16383 + EXPBIAS; /* exponent */
255 e |= (upper >> 4) & 0x800; /* sign */
256 ll = (ldq(ptr) >> 11) & ((1LL << 52) - 1);
257#ifdef __arm__
258 temp.l.upper = (e << 20) | (ll >> 32);
259 temp.l.lower = ll;
260#else
261 temp.ll = ll | ((uint64_t)e << 52);
262#endif
263 return temp.d;
264}
265
266static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr)
267{
268 CPU86_LDoubleU temp;
269 int e;
270
271 temp.d = f;
272 /* mantissa */
273 stq(ptr, (MANTD(temp) << 11) | (1LL << 63));
274 /* exponent + sign */
275 e = EXPD(temp) - EXPBIAS + 16383;
276 e |= SIGND(temp) >> 16;
277 stw(ptr + 8, e);
278}
279#else
280
281/* we use memory access macros */
282
283static inline CPU86_LDouble helper_fldt(target_ulong ptr)
284{
285 CPU86_LDoubleU temp;
286
287 temp.l.lower = ldq(ptr);
288 temp.l.upper = lduw(ptr + 8);
289 return temp.d;
290}
291
292static inline void helper_fstt(CPU86_LDouble f, target_ulong ptr)
293{
294 CPU86_LDoubleU temp;
295
296 temp.d = f;
297 stq(ptr, temp.l.lower);
298 stw(ptr + 8, temp.l.upper);
299}
300
301#endif /* USE_X86LDOUBLE */
302
303#define FPUS_IE (1 << 0)
304#define FPUS_DE (1 << 1)
305#define FPUS_ZE (1 << 2)
306#define FPUS_OE (1 << 3)
307#define FPUS_UE (1 << 4)
308#define FPUS_PE (1 << 5)
309#define FPUS_SF (1 << 6)
310#define FPUS_SE (1 << 7)
311#define FPUS_B (1 << 15)
312
313#define FPUC_EM 0x3f
314
315static inline uint32_t compute_eflags(void)
316{
317 return env->eflags | helper_cc_compute_all(CC_OP) | (DF & DF_MASK);
318}
319
320/* NOTE: CC_OP must be modified manually to CC_OP_EFLAGS */
321static inline void load_eflags(int eflags, int update_mask)
322{
323 CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
324 DF = 1 - (2 * ((eflags >> 10) & 1));
325 env->eflags = (env->eflags & ~update_mask) |
326 (eflags & update_mask) | 0x2;
327}
328
329static inline int cpu_has_work(CPUState *env)
330{
331 int work;
332
333 work = (env->interrupt_request & CPU_INTERRUPT_HARD) &&
334 (env->eflags & IF_MASK);
335 work |= env->interrupt_request & CPU_INTERRUPT_NMI;
336 work |= env->interrupt_request & CPU_INTERRUPT_INIT;
337 work |= env->interrupt_request & CPU_INTERRUPT_SIPI;
338
339 return work;
340}
341
342static inline int cpu_halted(CPUState *env) {
343 /* handle exit of HALTED state */
344 if (!env->halted)
345 return 0;
346 /* disable halt condition */
347 if (cpu_has_work(env)) {
348 env->halted = 0;
349 return 0;
350 }
351 return EXCP_HALTED;
352}
353
354/* load efer and update the corresponding hflags. XXX: do consistency
355 checks with cpuid bits ? */
356static inline void cpu_load_efer(CPUState *env, uint64_t val)
357{
358 env->efer = val;
359 env->hflags &= ~(HF_LMA_MASK | HF_SVME_MASK);
360 if (env->efer & MSR_EFER_LMA)
361 env->hflags |= HF_LMA_MASK;
362 if (env->efer & MSR_EFER_SVME)
363 env->hflags |= HF_SVME_MASK;
364}
365
366static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
367{
368 env->eip = tb->pc - tb->cs_base;
369}
370
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette