root / target-i386 / op.c @ afc7df11
History | View | Annotate | Download (41.3 kB)
1 |
/*
|
---|---|
2 |
* i386 micro operations
|
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, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 |
*/
|
20 |
|
21 |
#define ASM_SOFTMMU
|
22 |
#include "exec.h" |
23 |
|
24 |
/* n must be a constant to be efficient */
|
25 |
static inline target_long lshift(target_long x, int n) |
26 |
{ |
27 |
if (n >= 0) |
28 |
return x << n;
|
29 |
else
|
30 |
return x >> (-n);
|
31 |
} |
32 |
|
33 |
/* we define the various pieces of code used by the JIT */
|
34 |
|
35 |
#define REG EAX
|
36 |
#define REGNAME _EAX
|
37 |
#include "opreg_template.h" |
38 |
#undef REG
|
39 |
#undef REGNAME
|
40 |
|
41 |
#define REG ECX
|
42 |
#define REGNAME _ECX
|
43 |
#include "opreg_template.h" |
44 |
#undef REG
|
45 |
#undef REGNAME
|
46 |
|
47 |
#define REG EDX
|
48 |
#define REGNAME _EDX
|
49 |
#include "opreg_template.h" |
50 |
#undef REG
|
51 |
#undef REGNAME
|
52 |
|
53 |
#define REG EBX
|
54 |
#define REGNAME _EBX
|
55 |
#include "opreg_template.h" |
56 |
#undef REG
|
57 |
#undef REGNAME
|
58 |
|
59 |
#define REG ESP
|
60 |
#define REGNAME _ESP
|
61 |
#include "opreg_template.h" |
62 |
#undef REG
|
63 |
#undef REGNAME
|
64 |
|
65 |
#define REG EBP
|
66 |
#define REGNAME _EBP
|
67 |
#include "opreg_template.h" |
68 |
#undef REG
|
69 |
#undef REGNAME
|
70 |
|
71 |
#define REG ESI
|
72 |
#define REGNAME _ESI
|
73 |
#include "opreg_template.h" |
74 |
#undef REG
|
75 |
#undef REGNAME
|
76 |
|
77 |
#define REG EDI
|
78 |
#define REGNAME _EDI
|
79 |
#include "opreg_template.h" |
80 |
#undef REG
|
81 |
#undef REGNAME
|
82 |
|
83 |
#ifdef TARGET_X86_64
|
84 |
|
85 |
#define REG (env->regs[8]) |
86 |
#define REGNAME _R8
|
87 |
#include "opreg_template.h" |
88 |
#undef REG
|
89 |
#undef REGNAME
|
90 |
|
91 |
#define REG (env->regs[9]) |
92 |
#define REGNAME _R9
|
93 |
#include "opreg_template.h" |
94 |
#undef REG
|
95 |
#undef REGNAME
|
96 |
|
97 |
#define REG (env->regs[10]) |
98 |
#define REGNAME _R10
|
99 |
#include "opreg_template.h" |
100 |
#undef REG
|
101 |
#undef REGNAME
|
102 |
|
103 |
#define REG (env->regs[11]) |
104 |
#define REGNAME _R11
|
105 |
#include "opreg_template.h" |
106 |
#undef REG
|
107 |
#undef REGNAME
|
108 |
|
109 |
#define REG (env->regs[12]) |
110 |
#define REGNAME _R12
|
111 |
#include "opreg_template.h" |
112 |
#undef REG
|
113 |
#undef REGNAME
|
114 |
|
115 |
#define REG (env->regs[13]) |
116 |
#define REGNAME _R13
|
117 |
#include "opreg_template.h" |
118 |
#undef REG
|
119 |
#undef REGNAME
|
120 |
|
121 |
#define REG (env->regs[14]) |
122 |
#define REGNAME _R14
|
123 |
#include "opreg_template.h" |
124 |
#undef REG
|
125 |
#undef REGNAME
|
126 |
|
127 |
#define REG (env->regs[15]) |
128 |
#define REGNAME _R15
|
129 |
#include "opreg_template.h" |
130 |
#undef REG
|
131 |
#undef REGNAME
|
132 |
|
133 |
#endif
|
134 |
|
135 |
/* operations with flags */
|
136 |
|
137 |
/* update flags with T0 and T1 (add/sub case) */
|
138 |
void OPPROTO op_update2_cc(void) |
139 |
{ |
140 |
CC_SRC = T1; |
141 |
CC_DST = T0; |
142 |
} |
143 |
|
144 |
/* update flags with T0 (logic operation case) */
|
145 |
void OPPROTO op_update1_cc(void) |
146 |
{ |
147 |
CC_DST = T0; |
148 |
} |
149 |
|
150 |
void OPPROTO op_update_neg_cc(void) |
151 |
{ |
152 |
CC_SRC = -T0; |
153 |
CC_DST = T0; |
154 |
} |
155 |
|
156 |
void OPPROTO op_cmpl_T0_T1_cc(void) |
157 |
{ |
158 |
CC_SRC = T1; |
159 |
CC_DST = T0 - T1; |
160 |
} |
161 |
|
162 |
void OPPROTO op_update_inc_cc(void) |
163 |
{ |
164 |
CC_SRC = cc_table[CC_OP].compute_c(); |
165 |
CC_DST = T0; |
166 |
} |
167 |
|
168 |
void OPPROTO op_testl_T0_T1_cc(void) |
169 |
{ |
170 |
CC_DST = T0 & T1; |
171 |
} |
172 |
|
173 |
/* operations without flags */
|
174 |
|
175 |
void OPPROTO op_addl_T0_T1(void) |
176 |
{ |
177 |
T0 += T1; |
178 |
} |
179 |
|
180 |
void OPPROTO op_orl_T0_T1(void) |
181 |
{ |
182 |
T0 |= T1; |
183 |
} |
184 |
|
185 |
void OPPROTO op_andl_T0_T1(void) |
186 |
{ |
187 |
T0 &= T1; |
188 |
} |
189 |
|
190 |
void OPPROTO op_subl_T0_T1(void) |
191 |
{ |
192 |
T0 -= T1; |
193 |
} |
194 |
|
195 |
void OPPROTO op_xorl_T0_T1(void) |
196 |
{ |
197 |
T0 ^= T1; |
198 |
} |
199 |
|
200 |
void OPPROTO op_negl_T0(void) |
201 |
{ |
202 |
T0 = -T0; |
203 |
} |
204 |
|
205 |
void OPPROTO op_incl_T0(void) |
206 |
{ |
207 |
T0++; |
208 |
} |
209 |
|
210 |
void OPPROTO op_decl_T0(void) |
211 |
{ |
212 |
T0--; |
213 |
} |
214 |
|
215 |
void OPPROTO op_notl_T0(void) |
216 |
{ |
217 |
T0 = ~T0; |
218 |
} |
219 |
|
220 |
void OPPROTO op_bswapl_T0(void) |
221 |
{ |
222 |
T0 = bswap32(T0); |
223 |
} |
224 |
|
225 |
#ifdef TARGET_X86_64
|
226 |
void OPPROTO op_bswapq_T0(void) |
227 |
{ |
228 |
T0 = bswap64(T0); |
229 |
} |
230 |
#endif
|
231 |
|
232 |
/* multiply/divide */
|
233 |
|
234 |
/* XXX: add eflags optimizations */
|
235 |
/* XXX: add non P4 style flags */
|
236 |
|
237 |
void OPPROTO op_mulb_AL_T0(void) |
238 |
{ |
239 |
unsigned int res; |
240 |
res = (uint8_t)EAX * (uint8_t)T0; |
241 |
EAX = (EAX & ~0xffff) | res;
|
242 |
CC_DST = res; |
243 |
CC_SRC = (res & 0xff00);
|
244 |
} |
245 |
|
246 |
void OPPROTO op_imulb_AL_T0(void) |
247 |
{ |
248 |
int res;
|
249 |
res = (int8_t)EAX * (int8_t)T0; |
250 |
EAX = (EAX & ~0xffff) | (res & 0xffff); |
251 |
CC_DST = res; |
252 |
CC_SRC = (res != (int8_t)res); |
253 |
} |
254 |
|
255 |
void OPPROTO op_mulw_AX_T0(void) |
256 |
{ |
257 |
unsigned int res; |
258 |
res = (uint16_t)EAX * (uint16_t)T0; |
259 |
EAX = (EAX & ~0xffff) | (res & 0xffff); |
260 |
EDX = (EDX & ~0xffff) | ((res >> 16) & 0xffff); |
261 |
CC_DST = res; |
262 |
CC_SRC = res >> 16;
|
263 |
} |
264 |
|
265 |
void OPPROTO op_imulw_AX_T0(void) |
266 |
{ |
267 |
int res;
|
268 |
res = (int16_t)EAX * (int16_t)T0; |
269 |
EAX = (EAX & ~0xffff) | (res & 0xffff); |
270 |
EDX = (EDX & ~0xffff) | ((res >> 16) & 0xffff); |
271 |
CC_DST = res; |
272 |
CC_SRC = (res != (int16_t)res); |
273 |
} |
274 |
|
275 |
void OPPROTO op_mull_EAX_T0(void) |
276 |
{ |
277 |
uint64_t res; |
278 |
res = (uint64_t)((uint32_t)EAX) * (uint64_t)((uint32_t)T0); |
279 |
EAX = (uint32_t)res; |
280 |
EDX = (uint32_t)(res >> 32);
|
281 |
CC_DST = (uint32_t)res; |
282 |
CC_SRC = (uint32_t)(res >> 32);
|
283 |
} |
284 |
|
285 |
void OPPROTO op_imull_EAX_T0(void) |
286 |
{ |
287 |
int64_t res; |
288 |
res = (int64_t)((int32_t)EAX) * (int64_t)((int32_t)T0); |
289 |
EAX = res; |
290 |
EDX = res >> 32;
|
291 |
CC_DST = res; |
292 |
CC_SRC = (res != (int32_t)res); |
293 |
} |
294 |
|
295 |
void OPPROTO op_imulw_T0_T1(void) |
296 |
{ |
297 |
int res;
|
298 |
res = (int16_t)T0 * (int16_t)T1; |
299 |
T0 = res; |
300 |
CC_DST = res; |
301 |
CC_SRC = (res != (int16_t)res); |
302 |
} |
303 |
|
304 |
void OPPROTO op_imull_T0_T1(void) |
305 |
{ |
306 |
int64_t res; |
307 |
res = (int64_t)((int32_t)T0) * (int64_t)((int32_t)T1); |
308 |
T0 = res; |
309 |
CC_DST = res; |
310 |
CC_SRC = (res != (int32_t)res); |
311 |
} |
312 |
|
313 |
#ifdef TARGET_X86_64
|
314 |
void OPPROTO op_mulq_EAX_T0(void) |
315 |
{ |
316 |
helper_mulq_EAX_T0(); |
317 |
} |
318 |
|
319 |
void OPPROTO op_imulq_EAX_T0(void) |
320 |
{ |
321 |
helper_imulq_EAX_T0(); |
322 |
} |
323 |
|
324 |
void OPPROTO op_imulq_T0_T1(void) |
325 |
{ |
326 |
helper_imulq_T0_T1(); |
327 |
} |
328 |
#endif
|
329 |
|
330 |
/* division, flags are undefined */
|
331 |
/* XXX: add exceptions for overflow */
|
332 |
|
333 |
void OPPROTO op_divb_AL_T0(void) |
334 |
{ |
335 |
unsigned int num, den, q, r; |
336 |
|
337 |
num = (EAX & 0xffff);
|
338 |
den = (T0 & 0xff);
|
339 |
if (den == 0) { |
340 |
raise_exception(EXCP00_DIVZ); |
341 |
} |
342 |
q = (num / den) & 0xff;
|
343 |
r = (num % den) & 0xff;
|
344 |
EAX = (EAX & ~0xffff) | (r << 8) | q; |
345 |
} |
346 |
|
347 |
void OPPROTO op_idivb_AL_T0(void) |
348 |
{ |
349 |
int num, den, q, r;
|
350 |
|
351 |
num = (int16_t)EAX; |
352 |
den = (int8_t)T0; |
353 |
if (den == 0) { |
354 |
raise_exception(EXCP00_DIVZ); |
355 |
} |
356 |
q = (num / den) & 0xff;
|
357 |
r = (num % den) & 0xff;
|
358 |
EAX = (EAX & ~0xffff) | (r << 8) | q; |
359 |
} |
360 |
|
361 |
void OPPROTO op_divw_AX_T0(void) |
362 |
{ |
363 |
unsigned int num, den, q, r; |
364 |
|
365 |
num = (EAX & 0xffff) | ((EDX & 0xffff) << 16); |
366 |
den = (T0 & 0xffff);
|
367 |
if (den == 0) { |
368 |
raise_exception(EXCP00_DIVZ); |
369 |
} |
370 |
q = (num / den) & 0xffff;
|
371 |
r = (num % den) & 0xffff;
|
372 |
EAX = (EAX & ~0xffff) | q;
|
373 |
EDX = (EDX & ~0xffff) | r;
|
374 |
} |
375 |
|
376 |
void OPPROTO op_idivw_AX_T0(void) |
377 |
{ |
378 |
int num, den, q, r;
|
379 |
|
380 |
num = (EAX & 0xffff) | ((EDX & 0xffff) << 16); |
381 |
den = (int16_t)T0; |
382 |
if (den == 0) { |
383 |
raise_exception(EXCP00_DIVZ); |
384 |
} |
385 |
q = (num / den) & 0xffff;
|
386 |
r = (num % den) & 0xffff;
|
387 |
EAX = (EAX & ~0xffff) | q;
|
388 |
EDX = (EDX & ~0xffff) | r;
|
389 |
} |
390 |
|
391 |
void OPPROTO op_divl_EAX_T0(void) |
392 |
{ |
393 |
helper_divl_EAX_T0(); |
394 |
} |
395 |
|
396 |
void OPPROTO op_idivl_EAX_T0(void) |
397 |
{ |
398 |
helper_idivl_EAX_T0(); |
399 |
} |
400 |
|
401 |
#ifdef TARGET_X86_64
|
402 |
void OPPROTO op_divq_EAX_T0(void) |
403 |
{ |
404 |
helper_divq_EAX_T0(); |
405 |
} |
406 |
|
407 |
void OPPROTO op_idivq_EAX_T0(void) |
408 |
{ |
409 |
helper_idivq_EAX_T0(); |
410 |
} |
411 |
#endif
|
412 |
|
413 |
/* constant load & misc op */
|
414 |
|
415 |
/* XXX: consistent names */
|
416 |
void OPPROTO op_movl_T0_imu(void) |
417 |
{ |
418 |
T0 = (uint32_t)PARAM1; |
419 |
} |
420 |
|
421 |
void OPPROTO op_movl_T0_im(void) |
422 |
{ |
423 |
T0 = (int32_t)PARAM1; |
424 |
} |
425 |
|
426 |
void OPPROTO op_addl_T0_im(void) |
427 |
{ |
428 |
T0 += PARAM1; |
429 |
} |
430 |
|
431 |
void OPPROTO op_andl_T0_ffff(void) |
432 |
{ |
433 |
T0 = T0 & 0xffff;
|
434 |
} |
435 |
|
436 |
void OPPROTO op_andl_T0_im(void) |
437 |
{ |
438 |
T0 = T0 & PARAM1; |
439 |
} |
440 |
|
441 |
void OPPROTO op_movl_T0_T1(void) |
442 |
{ |
443 |
T0 = T1; |
444 |
} |
445 |
|
446 |
void OPPROTO op_movl_T1_imu(void) |
447 |
{ |
448 |
T1 = (uint32_t)PARAM1; |
449 |
} |
450 |
|
451 |
void OPPROTO op_movl_T1_im(void) |
452 |
{ |
453 |
T1 = (int32_t)PARAM1; |
454 |
} |
455 |
|
456 |
void OPPROTO op_addl_T1_im(void) |
457 |
{ |
458 |
T1 += PARAM1; |
459 |
} |
460 |
|
461 |
void OPPROTO op_movl_T1_A0(void) |
462 |
{ |
463 |
T1 = A0; |
464 |
} |
465 |
|
466 |
void OPPROTO op_movl_A0_im(void) |
467 |
{ |
468 |
A0 = (uint32_t)PARAM1; |
469 |
} |
470 |
|
471 |
void OPPROTO op_addl_A0_im(void) |
472 |
{ |
473 |
A0 = (uint32_t)(A0 + PARAM1); |
474 |
} |
475 |
|
476 |
void OPPROTO op_movl_A0_seg(void) |
477 |
{ |
478 |
A0 = (uint32_t)*(target_ulong *)((char *)env + PARAM1);
|
479 |
} |
480 |
|
481 |
void OPPROTO op_addl_A0_seg(void) |
482 |
{ |
483 |
A0 = (uint32_t)(A0 + *(target_ulong *)((char *)env + PARAM1));
|
484 |
} |
485 |
|
486 |
void OPPROTO op_addl_A0_AL(void) |
487 |
{ |
488 |
A0 = (uint32_t)(A0 + (EAX & 0xff));
|
489 |
} |
490 |
|
491 |
#ifdef WORDS_BIGENDIAN
|
492 |
typedef union UREG64 { |
493 |
struct { uint16_t v3, v2, v1, v0; } w;
|
494 |
struct { uint32_t v1, v0; } l;
|
495 |
uint64_t q; |
496 |
} UREG64; |
497 |
#else
|
498 |
typedef union UREG64 { |
499 |
struct { uint16_t v0, v1, v2, v3; } w;
|
500 |
struct { uint32_t v0, v1; } l;
|
501 |
uint64_t q; |
502 |
} UREG64; |
503 |
#endif
|
504 |
|
505 |
#ifdef TARGET_X86_64
|
506 |
|
507 |
#define PARAMQ1 \
|
508 |
({\ |
509 |
UREG64 __p;\ |
510 |
__p.l.v1 = PARAM1;\ |
511 |
__p.l.v0 = PARAM2;\ |
512 |
__p.q;\ |
513 |
}) |
514 |
|
515 |
void OPPROTO op_movq_T0_im64(void) |
516 |
{ |
517 |
T0 = PARAMQ1; |
518 |
} |
519 |
|
520 |
void OPPROTO op_movq_T1_im64(void) |
521 |
{ |
522 |
T1 = PARAMQ1; |
523 |
} |
524 |
|
525 |
void OPPROTO op_movq_A0_im(void) |
526 |
{ |
527 |
A0 = (int32_t)PARAM1; |
528 |
} |
529 |
|
530 |
void OPPROTO op_movq_A0_im64(void) |
531 |
{ |
532 |
A0 = PARAMQ1; |
533 |
} |
534 |
|
535 |
void OPPROTO op_addq_A0_im(void) |
536 |
{ |
537 |
A0 = (A0 + (int32_t)PARAM1); |
538 |
} |
539 |
|
540 |
void OPPROTO op_addq_A0_im64(void) |
541 |
{ |
542 |
A0 = (A0 + PARAMQ1); |
543 |
} |
544 |
|
545 |
void OPPROTO op_movq_A0_seg(void) |
546 |
{ |
547 |
A0 = *(target_ulong *)((char *)env + PARAM1);
|
548 |
} |
549 |
|
550 |
void OPPROTO op_addq_A0_seg(void) |
551 |
{ |
552 |
A0 += *(target_ulong *)((char *)env + PARAM1);
|
553 |
} |
554 |
|
555 |
void OPPROTO op_addq_A0_AL(void) |
556 |
{ |
557 |
A0 = (A0 + (EAX & 0xff));
|
558 |
} |
559 |
|
560 |
#endif
|
561 |
|
562 |
void OPPROTO op_andl_A0_ffff(void) |
563 |
{ |
564 |
A0 = A0 & 0xffff;
|
565 |
} |
566 |
|
567 |
/* memory access */
|
568 |
|
569 |
#define MEMSUFFIX _raw
|
570 |
#include "ops_mem.h" |
571 |
|
572 |
#if !defined(CONFIG_USER_ONLY)
|
573 |
#define MEMSUFFIX _kernel
|
574 |
#include "ops_mem.h" |
575 |
|
576 |
#define MEMSUFFIX _user
|
577 |
#include "ops_mem.h" |
578 |
#endif
|
579 |
|
580 |
/* indirect jump */
|
581 |
|
582 |
void OPPROTO op_jmp_T0(void) |
583 |
{ |
584 |
EIP = T0; |
585 |
} |
586 |
|
587 |
void OPPROTO op_movl_eip_im(void) |
588 |
{ |
589 |
EIP = (uint32_t)PARAM1; |
590 |
} |
591 |
|
592 |
#ifdef TARGET_X86_64
|
593 |
void OPPROTO op_movq_eip_im(void) |
594 |
{ |
595 |
EIP = (int32_t)PARAM1; |
596 |
} |
597 |
|
598 |
void OPPROTO op_movq_eip_im64(void) |
599 |
{ |
600 |
EIP = PARAMQ1; |
601 |
} |
602 |
#endif
|
603 |
|
604 |
void OPPROTO op_hlt(void) |
605 |
{ |
606 |
env->hflags &= ~HF_INHIBIT_IRQ_MASK; /* needed if sti is just before */
|
607 |
env->exception_index = EXCP_HLT; |
608 |
cpu_loop_exit(); |
609 |
} |
610 |
|
611 |
void OPPROTO op_debug(void) |
612 |
{ |
613 |
env->exception_index = EXCP_DEBUG; |
614 |
cpu_loop_exit(); |
615 |
} |
616 |
|
617 |
void OPPROTO op_raise_interrupt(void) |
618 |
{ |
619 |
int intno, next_eip_addend;
|
620 |
intno = PARAM1; |
621 |
next_eip_addend = PARAM2; |
622 |
raise_interrupt(intno, 1, 0, next_eip_addend); |
623 |
} |
624 |
|
625 |
void OPPROTO op_raise_exception(void) |
626 |
{ |
627 |
int exception_index;
|
628 |
exception_index = PARAM1; |
629 |
raise_exception(exception_index); |
630 |
} |
631 |
|
632 |
void OPPROTO op_into(void) |
633 |
{ |
634 |
int eflags;
|
635 |
eflags = cc_table[CC_OP].compute_all(); |
636 |
if (eflags & CC_O) {
|
637 |
raise_interrupt(EXCP04_INTO, 1, 0, PARAM1); |
638 |
} |
639 |
FORCE_RET(); |
640 |
} |
641 |
|
642 |
void OPPROTO op_cli(void) |
643 |
{ |
644 |
env->eflags &= ~IF_MASK; |
645 |
} |
646 |
|
647 |
void OPPROTO op_sti(void) |
648 |
{ |
649 |
env->eflags |= IF_MASK; |
650 |
} |
651 |
|
652 |
void OPPROTO op_set_inhibit_irq(void) |
653 |
{ |
654 |
env->hflags |= HF_INHIBIT_IRQ_MASK; |
655 |
} |
656 |
|
657 |
void OPPROTO op_reset_inhibit_irq(void) |
658 |
{ |
659 |
env->hflags &= ~HF_INHIBIT_IRQ_MASK; |
660 |
} |
661 |
|
662 |
#if 0
|
663 |
/* vm86plus instructions */
|
664 |
void OPPROTO op_cli_vm(void)
|
665 |
{
|
666 |
env->eflags &= ~VIF_MASK;
|
667 |
}
|
668 |
|
669 |
void OPPROTO op_sti_vm(void)
|
670 |
{
|
671 |
env->eflags |= VIF_MASK;
|
672 |
if (env->eflags & VIP_MASK) {
|
673 |
EIP = PARAM1;
|
674 |
raise_exception(EXCP0D_GPF);
|
675 |
}
|
676 |
FORCE_RET();
|
677 |
}
|
678 |
#endif
|
679 |
|
680 |
void OPPROTO op_boundw(void) |
681 |
{ |
682 |
int low, high, v;
|
683 |
low = ldsw(A0); |
684 |
high = ldsw(A0 + 2);
|
685 |
v = (int16_t)T0; |
686 |
if (v < low || v > high) {
|
687 |
raise_exception(EXCP05_BOUND); |
688 |
} |
689 |
FORCE_RET(); |
690 |
} |
691 |
|
692 |
void OPPROTO op_boundl(void) |
693 |
{ |
694 |
int low, high, v;
|
695 |
low = ldl(A0); |
696 |
high = ldl(A0 + 4);
|
697 |
v = T0; |
698 |
if (v < low || v > high) {
|
699 |
raise_exception(EXCP05_BOUND); |
700 |
} |
701 |
FORCE_RET(); |
702 |
} |
703 |
|
704 |
void OPPROTO op_cmpxchg8b(void) |
705 |
{ |
706 |
helper_cmpxchg8b(); |
707 |
} |
708 |
|
709 |
void OPPROTO op_movl_T0_0(void) |
710 |
{ |
711 |
T0 = 0;
|
712 |
} |
713 |
|
714 |
void OPPROTO op_exit_tb(void) |
715 |
{ |
716 |
EXIT_TB(); |
717 |
} |
718 |
|
719 |
/* multiple size ops */
|
720 |
|
721 |
#define ldul ldl
|
722 |
|
723 |
#define SHIFT 0 |
724 |
#include "ops_template.h" |
725 |
#undef SHIFT
|
726 |
|
727 |
#define SHIFT 1 |
728 |
#include "ops_template.h" |
729 |
#undef SHIFT
|
730 |
|
731 |
#define SHIFT 2 |
732 |
#include "ops_template.h" |
733 |
#undef SHIFT
|
734 |
|
735 |
#ifdef TARGET_X86_64
|
736 |
|
737 |
#define SHIFT 3 |
738 |
#include "ops_template.h" |
739 |
#undef SHIFT
|
740 |
|
741 |
#endif
|
742 |
|
743 |
/* sign extend */
|
744 |
|
745 |
void OPPROTO op_movsbl_T0_T0(void) |
746 |
{ |
747 |
T0 = (int8_t)T0; |
748 |
} |
749 |
|
750 |
void OPPROTO op_movzbl_T0_T0(void) |
751 |
{ |
752 |
T0 = (uint8_t)T0; |
753 |
} |
754 |
|
755 |
void OPPROTO op_movswl_T0_T0(void) |
756 |
{ |
757 |
T0 = (int16_t)T0; |
758 |
} |
759 |
|
760 |
void OPPROTO op_movzwl_T0_T0(void) |
761 |
{ |
762 |
T0 = (uint16_t)T0; |
763 |
} |
764 |
|
765 |
void OPPROTO op_movswl_EAX_AX(void) |
766 |
{ |
767 |
EAX = (int16_t)EAX; |
768 |
} |
769 |
|
770 |
#ifdef TARGET_X86_64
|
771 |
void OPPROTO op_movslq_T0_T0(void) |
772 |
{ |
773 |
T0 = (int32_t)T0; |
774 |
} |
775 |
|
776 |
void OPPROTO op_movslq_RAX_EAX(void) |
777 |
{ |
778 |
EAX = (int32_t)EAX; |
779 |
} |
780 |
#endif
|
781 |
|
782 |
void OPPROTO op_movsbw_AX_AL(void) |
783 |
{ |
784 |
EAX = (EAX & ~0xffff) | ((int8_t)EAX & 0xffff); |
785 |
} |
786 |
|
787 |
void OPPROTO op_movslq_EDX_EAX(void) |
788 |
{ |
789 |
EDX = (int32_t)EAX >> 31;
|
790 |
} |
791 |
|
792 |
void OPPROTO op_movswl_DX_AX(void) |
793 |
{ |
794 |
EDX = (EDX & ~0xffff) | (((int16_t)EAX >> 15) & 0xffff); |
795 |
} |
796 |
|
797 |
#ifdef TARGET_X86_64
|
798 |
void OPPROTO op_movsqo_RDX_RAX(void) |
799 |
{ |
800 |
EDX = (int64_t)EAX >> 63;
|
801 |
} |
802 |
#endif
|
803 |
|
804 |
/* string ops helpers */
|
805 |
|
806 |
void OPPROTO op_addl_ESI_T0(void) |
807 |
{ |
808 |
ESI = (uint32_t)(ESI + T0); |
809 |
} |
810 |
|
811 |
void OPPROTO op_addw_ESI_T0(void) |
812 |
{ |
813 |
ESI = (ESI & ~0xffff) | ((ESI + T0) & 0xffff); |
814 |
} |
815 |
|
816 |
void OPPROTO op_addl_EDI_T0(void) |
817 |
{ |
818 |
EDI = (uint32_t)(EDI + T0); |
819 |
} |
820 |
|
821 |
void OPPROTO op_addw_EDI_T0(void) |
822 |
{ |
823 |
EDI = (EDI & ~0xffff) | ((EDI + T0) & 0xffff); |
824 |
} |
825 |
|
826 |
void OPPROTO op_decl_ECX(void) |
827 |
{ |
828 |
ECX = (uint32_t)(ECX - 1);
|
829 |
} |
830 |
|
831 |
void OPPROTO op_decw_ECX(void) |
832 |
{ |
833 |
ECX = (ECX & ~0xffff) | ((ECX - 1) & 0xffff); |
834 |
} |
835 |
|
836 |
#ifdef TARGET_X86_64
|
837 |
void OPPROTO op_addq_ESI_T0(void) |
838 |
{ |
839 |
ESI = (ESI + T0); |
840 |
} |
841 |
|
842 |
void OPPROTO op_addq_EDI_T0(void) |
843 |
{ |
844 |
EDI = (EDI + T0); |
845 |
} |
846 |
|
847 |
void OPPROTO op_decq_ECX(void) |
848 |
{ |
849 |
ECX--; |
850 |
} |
851 |
#endif
|
852 |
|
853 |
/* push/pop utils */
|
854 |
|
855 |
void op_addl_A0_SS(void) |
856 |
{ |
857 |
A0 += (long)env->segs[R_SS].base;
|
858 |
} |
859 |
|
860 |
void op_subl_A0_2(void) |
861 |
{ |
862 |
A0 = (uint32_t)(A0 - 2);
|
863 |
} |
864 |
|
865 |
void op_subl_A0_4(void) |
866 |
{ |
867 |
A0 = (uint32_t)(A0 - 4);
|
868 |
} |
869 |
|
870 |
void op_addl_ESP_4(void) |
871 |
{ |
872 |
ESP = (uint32_t)(ESP + 4);
|
873 |
} |
874 |
|
875 |
void op_addl_ESP_2(void) |
876 |
{ |
877 |
ESP = (uint32_t)(ESP + 2);
|
878 |
} |
879 |
|
880 |
void op_addw_ESP_4(void) |
881 |
{ |
882 |
ESP = (ESP & ~0xffff) | ((ESP + 4) & 0xffff); |
883 |
} |
884 |
|
885 |
void op_addw_ESP_2(void) |
886 |
{ |
887 |
ESP = (ESP & ~0xffff) | ((ESP + 2) & 0xffff); |
888 |
} |
889 |
|
890 |
void op_addl_ESP_im(void) |
891 |
{ |
892 |
ESP = (uint32_t)(ESP + PARAM1); |
893 |
} |
894 |
|
895 |
void op_addw_ESP_im(void) |
896 |
{ |
897 |
ESP = (ESP & ~0xffff) | ((ESP + PARAM1) & 0xffff); |
898 |
} |
899 |
|
900 |
#ifdef TARGET_X86_64
|
901 |
void op_subq_A0_8(void) |
902 |
{ |
903 |
A0 -= 8;
|
904 |
} |
905 |
|
906 |
void op_addq_ESP_8(void) |
907 |
{ |
908 |
ESP += 8;
|
909 |
} |
910 |
|
911 |
void op_addq_ESP_im(void) |
912 |
{ |
913 |
ESP += PARAM1; |
914 |
} |
915 |
#endif
|
916 |
|
917 |
void OPPROTO op_rdtsc(void) |
918 |
{ |
919 |
helper_rdtsc(); |
920 |
} |
921 |
|
922 |
void OPPROTO op_cpuid(void) |
923 |
{ |
924 |
helper_cpuid(); |
925 |
} |
926 |
|
927 |
void OPPROTO op_enter_level(void) |
928 |
{ |
929 |
helper_enter_level(PARAM1, PARAM2); |
930 |
} |
931 |
|
932 |
void OPPROTO op_sysenter(void) |
933 |
{ |
934 |
helper_sysenter(); |
935 |
} |
936 |
|
937 |
void OPPROTO op_sysexit(void) |
938 |
{ |
939 |
helper_sysexit(); |
940 |
} |
941 |
|
942 |
#ifdef TARGET_X86_64
|
943 |
void OPPROTO op_syscall(void) |
944 |
{ |
945 |
helper_syscall(PARAM1); |
946 |
} |
947 |
|
948 |
void OPPROTO op_sysret(void) |
949 |
{ |
950 |
helper_sysret(PARAM1); |
951 |
} |
952 |
#endif
|
953 |
|
954 |
void OPPROTO op_rdmsr(void) |
955 |
{ |
956 |
helper_rdmsr(); |
957 |
} |
958 |
|
959 |
void OPPROTO op_wrmsr(void) |
960 |
{ |
961 |
helper_wrmsr(); |
962 |
} |
963 |
|
964 |
/* bcd */
|
965 |
|
966 |
/* XXX: exception */
|
967 |
void OPPROTO op_aam(void) |
968 |
{ |
969 |
int base = PARAM1;
|
970 |
int al, ah;
|
971 |
al = EAX & 0xff;
|
972 |
ah = al / base; |
973 |
al = al % base; |
974 |
EAX = (EAX & ~0xffff) | al | (ah << 8); |
975 |
CC_DST = al; |
976 |
} |
977 |
|
978 |
void OPPROTO op_aad(void) |
979 |
{ |
980 |
int base = PARAM1;
|
981 |
int al, ah;
|
982 |
al = EAX & 0xff;
|
983 |
ah = (EAX >> 8) & 0xff; |
984 |
al = ((ah * base) + al) & 0xff;
|
985 |
EAX = (EAX & ~0xffff) | al;
|
986 |
CC_DST = al; |
987 |
} |
988 |
|
989 |
void OPPROTO op_aaa(void) |
990 |
{ |
991 |
int icarry;
|
992 |
int al, ah, af;
|
993 |
int eflags;
|
994 |
|
995 |
eflags = cc_table[CC_OP].compute_all(); |
996 |
af = eflags & CC_A; |
997 |
al = EAX & 0xff;
|
998 |
ah = (EAX >> 8) & 0xff; |
999 |
|
1000 |
icarry = (al > 0xf9);
|
1001 |
if (((al & 0x0f) > 9 ) || af) { |
1002 |
al = (al + 6) & 0x0f; |
1003 |
ah = (ah + 1 + icarry) & 0xff; |
1004 |
eflags |= CC_C | CC_A; |
1005 |
} else {
|
1006 |
eflags &= ~(CC_C | CC_A); |
1007 |
al &= 0x0f;
|
1008 |
} |
1009 |
EAX = (EAX & ~0xffff) | al | (ah << 8); |
1010 |
CC_SRC = eflags; |
1011 |
} |
1012 |
|
1013 |
void OPPROTO op_aas(void) |
1014 |
{ |
1015 |
int icarry;
|
1016 |
int al, ah, af;
|
1017 |
int eflags;
|
1018 |
|
1019 |
eflags = cc_table[CC_OP].compute_all(); |
1020 |
af = eflags & CC_A; |
1021 |
al = EAX & 0xff;
|
1022 |
ah = (EAX >> 8) & 0xff; |
1023 |
|
1024 |
icarry = (al < 6);
|
1025 |
if (((al & 0x0f) > 9 ) || af) { |
1026 |
al = (al - 6) & 0x0f; |
1027 |
ah = (ah - 1 - icarry) & 0xff; |
1028 |
eflags |= CC_C | CC_A; |
1029 |
} else {
|
1030 |
eflags &= ~(CC_C | CC_A); |
1031 |
al &= 0x0f;
|
1032 |
} |
1033 |
EAX = (EAX & ~0xffff) | al | (ah << 8); |
1034 |
CC_SRC = eflags; |
1035 |
} |
1036 |
|
1037 |
void OPPROTO op_daa(void) |
1038 |
{ |
1039 |
int al, af, cf;
|
1040 |
int eflags;
|
1041 |
|
1042 |
eflags = cc_table[CC_OP].compute_all(); |
1043 |
cf = eflags & CC_C; |
1044 |
af = eflags & CC_A; |
1045 |
al = EAX & 0xff;
|
1046 |
|
1047 |
eflags = 0;
|
1048 |
if (((al & 0x0f) > 9 ) || af) { |
1049 |
al = (al + 6) & 0xff; |
1050 |
eflags |= CC_A; |
1051 |
} |
1052 |
if ((al > 0x9f) || cf) { |
1053 |
al = (al + 0x60) & 0xff; |
1054 |
eflags |= CC_C; |
1055 |
} |
1056 |
EAX = (EAX & ~0xff) | al;
|
1057 |
/* well, speed is not an issue here, so we compute the flags by hand */
|
1058 |
eflags |= (al == 0) << 6; /* zf */ |
1059 |
eflags |= parity_table[al]; /* pf */
|
1060 |
eflags |= (al & 0x80); /* sf */ |
1061 |
CC_SRC = eflags; |
1062 |
} |
1063 |
|
1064 |
void OPPROTO op_das(void) |
1065 |
{ |
1066 |
int al, al1, af, cf;
|
1067 |
int eflags;
|
1068 |
|
1069 |
eflags = cc_table[CC_OP].compute_all(); |
1070 |
cf = eflags & CC_C; |
1071 |
af = eflags & CC_A; |
1072 |
al = EAX & 0xff;
|
1073 |
|
1074 |
eflags = 0;
|
1075 |
al1 = al; |
1076 |
if (((al & 0x0f) > 9 ) || af) { |
1077 |
eflags |= CC_A; |
1078 |
if (al < 6 || cf) |
1079 |
eflags |= CC_C; |
1080 |
al = (al - 6) & 0xff; |
1081 |
} |
1082 |
if ((al1 > 0x99) || cf) { |
1083 |
al = (al - 0x60) & 0xff; |
1084 |
eflags |= CC_C; |
1085 |
} |
1086 |
EAX = (EAX & ~0xff) | al;
|
1087 |
/* well, speed is not an issue here, so we compute the flags by hand */
|
1088 |
eflags |= (al == 0) << 6; /* zf */ |
1089 |
eflags |= parity_table[al]; /* pf */
|
1090 |
eflags |= (al & 0x80); /* sf */ |
1091 |
CC_SRC = eflags; |
1092 |
} |
1093 |
|
1094 |
/* segment handling */
|
1095 |
|
1096 |
/* never use it with R_CS */
|
1097 |
void OPPROTO op_movl_seg_T0(void) |
1098 |
{ |
1099 |
load_seg(PARAM1, T0); |
1100 |
} |
1101 |
|
1102 |
/* faster VM86 version */
|
1103 |
void OPPROTO op_movl_seg_T0_vm(void) |
1104 |
{ |
1105 |
int selector;
|
1106 |
SegmentCache *sc; |
1107 |
|
1108 |
selector = T0 & 0xffff;
|
1109 |
/* env->segs[] access */
|
1110 |
sc = (SegmentCache *)((char *)env + PARAM1);
|
1111 |
sc->selector = selector; |
1112 |
sc->base = (selector << 4);
|
1113 |
} |
1114 |
|
1115 |
void OPPROTO op_movl_T0_seg(void) |
1116 |
{ |
1117 |
T0 = env->segs[PARAM1].selector; |
1118 |
} |
1119 |
|
1120 |
void OPPROTO op_lsl(void) |
1121 |
{ |
1122 |
helper_lsl(); |
1123 |
} |
1124 |
|
1125 |
void OPPROTO op_lar(void) |
1126 |
{ |
1127 |
helper_lar(); |
1128 |
} |
1129 |
|
1130 |
void OPPROTO op_verr(void) |
1131 |
{ |
1132 |
helper_verr(); |
1133 |
} |
1134 |
|
1135 |
void OPPROTO op_verw(void) |
1136 |
{ |
1137 |
helper_verw(); |
1138 |
} |
1139 |
|
1140 |
void OPPROTO op_arpl(void) |
1141 |
{ |
1142 |
if ((T0 & 3) < (T1 & 3)) { |
1143 |
/* XXX: emulate bug or 0xff3f0000 oring as in bochs ? */
|
1144 |
T0 = (T0 & ~3) | (T1 & 3); |
1145 |
T1 = CC_Z; |
1146 |
} else {
|
1147 |
T1 = 0;
|
1148 |
} |
1149 |
FORCE_RET(); |
1150 |
} |
1151 |
|
1152 |
void OPPROTO op_arpl_update(void) |
1153 |
{ |
1154 |
int eflags;
|
1155 |
eflags = cc_table[CC_OP].compute_all(); |
1156 |
CC_SRC = (eflags & ~CC_Z) | T1; |
1157 |
} |
1158 |
|
1159 |
/* T0: segment, T1:eip */
|
1160 |
void OPPROTO op_ljmp_protected_T0_T1(void) |
1161 |
{ |
1162 |
helper_ljmp_protected_T0_T1(PARAM1); |
1163 |
} |
1164 |
|
1165 |
void OPPROTO op_lcall_real_T0_T1(void) |
1166 |
{ |
1167 |
helper_lcall_real_T0_T1(PARAM1, PARAM2); |
1168 |
} |
1169 |
|
1170 |
void OPPROTO op_lcall_protected_T0_T1(void) |
1171 |
{ |
1172 |
helper_lcall_protected_T0_T1(PARAM1, PARAM2); |
1173 |
} |
1174 |
|
1175 |
void OPPROTO op_iret_real(void) |
1176 |
{ |
1177 |
helper_iret_real(PARAM1); |
1178 |
} |
1179 |
|
1180 |
void OPPROTO op_iret_protected(void) |
1181 |
{ |
1182 |
helper_iret_protected(PARAM1, PARAM2); |
1183 |
} |
1184 |
|
1185 |
void OPPROTO op_lret_protected(void) |
1186 |
{ |
1187 |
helper_lret_protected(PARAM1, PARAM2); |
1188 |
} |
1189 |
|
1190 |
void OPPROTO op_lldt_T0(void) |
1191 |
{ |
1192 |
helper_lldt_T0(); |
1193 |
} |
1194 |
|
1195 |
void OPPROTO op_ltr_T0(void) |
1196 |
{ |
1197 |
helper_ltr_T0(); |
1198 |
} |
1199 |
|
1200 |
/* CR registers access */
|
1201 |
void OPPROTO op_movl_crN_T0(void) |
1202 |
{ |
1203 |
helper_movl_crN_T0(PARAM1); |
1204 |
} |
1205 |
|
1206 |
#if !defined(CONFIG_USER_ONLY)
|
1207 |
void OPPROTO op_movtl_T0_cr8(void) |
1208 |
{ |
1209 |
T0 = cpu_get_apic_tpr(env); |
1210 |
} |
1211 |
#endif
|
1212 |
|
1213 |
/* DR registers access */
|
1214 |
void OPPROTO op_movl_drN_T0(void) |
1215 |
{ |
1216 |
helper_movl_drN_T0(PARAM1); |
1217 |
} |
1218 |
|
1219 |
void OPPROTO op_lmsw_T0(void) |
1220 |
{ |
1221 |
/* only 4 lower bits of CR0 are modified. PE cannot be set to zero
|
1222 |
if already set to one. */
|
1223 |
T0 = (env->cr[0] & ~0xe) | (T0 & 0xf); |
1224 |
helper_movl_crN_T0(0);
|
1225 |
} |
1226 |
|
1227 |
void OPPROTO op_invlpg_A0(void) |
1228 |
{ |
1229 |
helper_invlpg(A0); |
1230 |
} |
1231 |
|
1232 |
void OPPROTO op_movl_T0_env(void) |
1233 |
{ |
1234 |
T0 = *(uint32_t *)((char *)env + PARAM1);
|
1235 |
} |
1236 |
|
1237 |
void OPPROTO op_movl_env_T0(void) |
1238 |
{ |
1239 |
*(uint32_t *)((char *)env + PARAM1) = T0;
|
1240 |
} |
1241 |
|
1242 |
void OPPROTO op_movl_env_T1(void) |
1243 |
{ |
1244 |
*(uint32_t *)((char *)env + PARAM1) = T1;
|
1245 |
} |
1246 |
|
1247 |
void OPPROTO op_movtl_T0_env(void) |
1248 |
{ |
1249 |
T0 = *(target_ulong *)((char *)env + PARAM1);
|
1250 |
} |
1251 |
|
1252 |
void OPPROTO op_movtl_env_T0(void) |
1253 |
{ |
1254 |
*(target_ulong *)((char *)env + PARAM1) = T0;
|
1255 |
} |
1256 |
|
1257 |
void OPPROTO op_movtl_T1_env(void) |
1258 |
{ |
1259 |
T1 = *(target_ulong *)((char *)env + PARAM1);
|
1260 |
} |
1261 |
|
1262 |
void OPPROTO op_movtl_env_T1(void) |
1263 |
{ |
1264 |
*(target_ulong *)((char *)env + PARAM1) = T1;
|
1265 |
} |
1266 |
|
1267 |
void OPPROTO op_clts(void) |
1268 |
{ |
1269 |
env->cr[0] &= ~CR0_TS_MASK;
|
1270 |
env->hflags &= ~HF_TS_MASK; |
1271 |
} |
1272 |
|
1273 |
/* flags handling */
|
1274 |
|
1275 |
void OPPROTO op_goto_tb0(void) |
1276 |
{ |
1277 |
GOTO_TB(op_goto_tb0, PARAM1, 0);
|
1278 |
} |
1279 |
|
1280 |
void OPPROTO op_goto_tb1(void) |
1281 |
{ |
1282 |
GOTO_TB(op_goto_tb1, PARAM1, 1);
|
1283 |
} |
1284 |
|
1285 |
void OPPROTO op_jmp_label(void) |
1286 |
{ |
1287 |
GOTO_LABEL_PARAM(1);
|
1288 |
} |
1289 |
|
1290 |
void OPPROTO op_jnz_T0_label(void) |
1291 |
{ |
1292 |
if (T0)
|
1293 |
GOTO_LABEL_PARAM(1);
|
1294 |
FORCE_RET(); |
1295 |
} |
1296 |
|
1297 |
void OPPROTO op_jz_T0_label(void) |
1298 |
{ |
1299 |
if (!T0)
|
1300 |
GOTO_LABEL_PARAM(1);
|
1301 |
FORCE_RET(); |
1302 |
} |
1303 |
|
1304 |
/* slow set cases (compute x86 flags) */
|
1305 |
void OPPROTO op_seto_T0_cc(void) |
1306 |
{ |
1307 |
int eflags;
|
1308 |
eflags = cc_table[CC_OP].compute_all(); |
1309 |
T0 = (eflags >> 11) & 1; |
1310 |
} |
1311 |
|
1312 |
void OPPROTO op_setb_T0_cc(void) |
1313 |
{ |
1314 |
T0 = cc_table[CC_OP].compute_c(); |
1315 |
} |
1316 |
|
1317 |
void OPPROTO op_setz_T0_cc(void) |
1318 |
{ |
1319 |
int eflags;
|
1320 |
eflags = cc_table[CC_OP].compute_all(); |
1321 |
T0 = (eflags >> 6) & 1; |
1322 |
} |
1323 |
|
1324 |
void OPPROTO op_setbe_T0_cc(void) |
1325 |
{ |
1326 |
int eflags;
|
1327 |
eflags = cc_table[CC_OP].compute_all(); |
1328 |
T0 = (eflags & (CC_Z | CC_C)) != 0;
|
1329 |
} |
1330 |
|
1331 |
void OPPROTO op_sets_T0_cc(void) |
1332 |
{ |
1333 |
int eflags;
|
1334 |
eflags = cc_table[CC_OP].compute_all(); |
1335 |
T0 = (eflags >> 7) & 1; |
1336 |
} |
1337 |
|
1338 |
void OPPROTO op_setp_T0_cc(void) |
1339 |
{ |
1340 |
int eflags;
|
1341 |
eflags = cc_table[CC_OP].compute_all(); |
1342 |
T0 = (eflags >> 2) & 1; |
1343 |
} |
1344 |
|
1345 |
void OPPROTO op_setl_T0_cc(void) |
1346 |
{ |
1347 |
int eflags;
|
1348 |
eflags = cc_table[CC_OP].compute_all(); |
1349 |
T0 = ((eflags ^ (eflags >> 4)) >> 7) & 1; |
1350 |
} |
1351 |
|
1352 |
void OPPROTO op_setle_T0_cc(void) |
1353 |
{ |
1354 |
int eflags;
|
1355 |
eflags = cc_table[CC_OP].compute_all(); |
1356 |
T0 = (((eflags ^ (eflags >> 4)) & 0x80) || (eflags & CC_Z)) != 0; |
1357 |
} |
1358 |
|
1359 |
void OPPROTO op_xor_T0_1(void) |
1360 |
{ |
1361 |
T0 ^= 1;
|
1362 |
} |
1363 |
|
1364 |
void OPPROTO op_set_cc_op(void) |
1365 |
{ |
1366 |
CC_OP = PARAM1; |
1367 |
} |
1368 |
|
1369 |
void OPPROTO op_mov_T0_cc(void) |
1370 |
{ |
1371 |
T0 = cc_table[CC_OP].compute_all(); |
1372 |
} |
1373 |
|
1374 |
/* XXX: clear VIF/VIP in all ops ? */
|
1375 |
|
1376 |
void OPPROTO op_movl_eflags_T0(void) |
1377 |
{ |
1378 |
load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK)); |
1379 |
} |
1380 |
|
1381 |
void OPPROTO op_movw_eflags_T0(void) |
1382 |
{ |
1383 |
load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK) & 0xffff);
|
1384 |
} |
1385 |
|
1386 |
void OPPROTO op_movl_eflags_T0_io(void) |
1387 |
{ |
1388 |
load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK)); |
1389 |
} |
1390 |
|
1391 |
void OPPROTO op_movw_eflags_T0_io(void) |
1392 |
{ |
1393 |
load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK) & 0xffff);
|
1394 |
} |
1395 |
|
1396 |
void OPPROTO op_movl_eflags_T0_cpl0(void) |
1397 |
{ |
1398 |
load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK | IOPL_MASK)); |
1399 |
} |
1400 |
|
1401 |
void OPPROTO op_movw_eflags_T0_cpl0(void) |
1402 |
{ |
1403 |
load_eflags(T0, (TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK | IOPL_MASK) & 0xffff);
|
1404 |
} |
1405 |
|
1406 |
#if 0
|
1407 |
/* vm86plus version */
|
1408 |
void OPPROTO op_movw_eflags_T0_vm(void)
|
1409 |
{
|
1410 |
int eflags;
|
1411 |
eflags = T0;
|
1412 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
|
1413 |
DF = 1 - (2 * ((eflags >> 10) & 1));
|
1414 |
/* we also update some system flags as in user mode */
|
1415 |
env->eflags = (env->eflags & ~(FL_UPDATE_MASK16 | VIF_MASK)) |
|
1416 |
(eflags & FL_UPDATE_MASK16);
|
1417 |
if (eflags & IF_MASK) {
|
1418 |
env->eflags |= VIF_MASK;
|
1419 |
if (env->eflags & VIP_MASK) {
|
1420 |
EIP = PARAM1;
|
1421 |
raise_exception(EXCP0D_GPF);
|
1422 |
}
|
1423 |
}
|
1424 |
FORCE_RET();
|
1425 |
}
|
1426 |
|
1427 |
void OPPROTO op_movl_eflags_T0_vm(void)
|
1428 |
{
|
1429 |
int eflags;
|
1430 |
eflags = T0;
|
1431 |
CC_SRC = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
|
1432 |
DF = 1 - (2 * ((eflags >> 10) & 1));
|
1433 |
/* we also update some system flags as in user mode */
|
1434 |
env->eflags = (env->eflags & ~(FL_UPDATE_MASK32 | VIF_MASK)) |
|
1435 |
(eflags & FL_UPDATE_MASK32);
|
1436 |
if (eflags & IF_MASK) {
|
1437 |
env->eflags |= VIF_MASK;
|
1438 |
if (env->eflags & VIP_MASK) {
|
1439 |
EIP = PARAM1;
|
1440 |
raise_exception(EXCP0D_GPF);
|
1441 |
}
|
1442 |
}
|
1443 |
FORCE_RET();
|
1444 |
}
|
1445 |
#endif
|
1446 |
|
1447 |
/* XXX: compute only O flag */
|
1448 |
void OPPROTO op_movb_eflags_T0(void) |
1449 |
{ |
1450 |
int of;
|
1451 |
of = cc_table[CC_OP].compute_all() & CC_O; |
1452 |
CC_SRC = (T0 & (CC_S | CC_Z | CC_A | CC_P | CC_C)) | of; |
1453 |
} |
1454 |
|
1455 |
void OPPROTO op_movl_T0_eflags(void) |
1456 |
{ |
1457 |
int eflags;
|
1458 |
eflags = cc_table[CC_OP].compute_all(); |
1459 |
eflags |= (DF & DF_MASK); |
1460 |
eflags |= env->eflags & ~(VM_MASK | RF_MASK); |
1461 |
T0 = eflags; |
1462 |
} |
1463 |
|
1464 |
/* vm86plus version */
|
1465 |
#if 0
|
1466 |
void OPPROTO op_movl_T0_eflags_vm(void)
|
1467 |
{
|
1468 |
int eflags;
|
1469 |
eflags = cc_table[CC_OP].compute_all();
|
1470 |
eflags |= (DF & DF_MASK);
|
1471 |
eflags |= env->eflags & ~(VM_MASK | RF_MASK | IF_MASK);
|
1472 |
if (env->eflags & VIF_MASK)
|
1473 |
eflags |= IF_MASK;
|
1474 |
T0 = eflags;
|
1475 |
}
|
1476 |
#endif
|
1477 |
|
1478 |
void OPPROTO op_cld(void) |
1479 |
{ |
1480 |
DF = 1;
|
1481 |
} |
1482 |
|
1483 |
void OPPROTO op_std(void) |
1484 |
{ |
1485 |
DF = -1;
|
1486 |
} |
1487 |
|
1488 |
void OPPROTO op_clc(void) |
1489 |
{ |
1490 |
int eflags;
|
1491 |
eflags = cc_table[CC_OP].compute_all(); |
1492 |
eflags &= ~CC_C; |
1493 |
CC_SRC = eflags; |
1494 |
} |
1495 |
|
1496 |
void OPPROTO op_stc(void) |
1497 |
{ |
1498 |
int eflags;
|
1499 |
eflags = cc_table[CC_OP].compute_all(); |
1500 |
eflags |= CC_C; |
1501 |
CC_SRC = eflags; |
1502 |
} |
1503 |
|
1504 |
void OPPROTO op_cmc(void) |
1505 |
{ |
1506 |
int eflags;
|
1507 |
eflags = cc_table[CC_OP].compute_all(); |
1508 |
eflags ^= CC_C; |
1509 |
CC_SRC = eflags; |
1510 |
} |
1511 |
|
1512 |
void OPPROTO op_salc(void) |
1513 |
{ |
1514 |
int cf;
|
1515 |
cf = cc_table[CC_OP].compute_c(); |
1516 |
EAX = (EAX & ~0xff) | ((-cf) & 0xff); |
1517 |
} |
1518 |
|
1519 |
static int compute_all_eflags(void) |
1520 |
{ |
1521 |
return CC_SRC;
|
1522 |
} |
1523 |
|
1524 |
static int compute_c_eflags(void) |
1525 |
{ |
1526 |
return CC_SRC & CC_C;
|
1527 |
} |
1528 |
|
1529 |
CCTable cc_table[CC_OP_NB] = { |
1530 |
[CC_OP_DYNAMIC] = { /* should never happen */ },
|
1531 |
|
1532 |
[CC_OP_EFLAGS] = { compute_all_eflags, compute_c_eflags }, |
1533 |
|
1534 |
[CC_OP_MULB] = { compute_all_mulb, compute_c_mull }, |
1535 |
[CC_OP_MULW] = { compute_all_mulw, compute_c_mull }, |
1536 |
[CC_OP_MULL] = { compute_all_mull, compute_c_mull }, |
1537 |
|
1538 |
[CC_OP_ADDB] = { compute_all_addb, compute_c_addb }, |
1539 |
[CC_OP_ADDW] = { compute_all_addw, compute_c_addw }, |
1540 |
[CC_OP_ADDL] = { compute_all_addl, compute_c_addl }, |
1541 |
|
1542 |
[CC_OP_ADCB] = { compute_all_adcb, compute_c_adcb }, |
1543 |
[CC_OP_ADCW] = { compute_all_adcw, compute_c_adcw }, |
1544 |
[CC_OP_ADCL] = { compute_all_adcl, compute_c_adcl }, |
1545 |
|
1546 |
[CC_OP_SUBB] = { compute_all_subb, compute_c_subb }, |
1547 |
[CC_OP_SUBW] = { compute_all_subw, compute_c_subw }, |
1548 |
[CC_OP_SUBL] = { compute_all_subl, compute_c_subl }, |
1549 |
|
1550 |
[CC_OP_SBBB] = { compute_all_sbbb, compute_c_sbbb }, |
1551 |
[CC_OP_SBBW] = { compute_all_sbbw, compute_c_sbbw }, |
1552 |
[CC_OP_SBBL] = { compute_all_sbbl, compute_c_sbbl }, |
1553 |
|
1554 |
[CC_OP_LOGICB] = { compute_all_logicb, compute_c_logicb }, |
1555 |
[CC_OP_LOGICW] = { compute_all_logicw, compute_c_logicw }, |
1556 |
[CC_OP_LOGICL] = { compute_all_logicl, compute_c_logicl }, |
1557 |
|
1558 |
[CC_OP_INCB] = { compute_all_incb, compute_c_incl }, |
1559 |
[CC_OP_INCW] = { compute_all_incw, compute_c_incl }, |
1560 |
[CC_OP_INCL] = { compute_all_incl, compute_c_incl }, |
1561 |
|
1562 |
[CC_OP_DECB] = { compute_all_decb, compute_c_incl }, |
1563 |
[CC_OP_DECW] = { compute_all_decw, compute_c_incl }, |
1564 |
[CC_OP_DECL] = { compute_all_decl, compute_c_incl }, |
1565 |
|
1566 |
[CC_OP_SHLB] = { compute_all_shlb, compute_c_shlb }, |
1567 |
[CC_OP_SHLW] = { compute_all_shlw, compute_c_shlw }, |
1568 |
[CC_OP_SHLL] = { compute_all_shll, compute_c_shll }, |
1569 |
|
1570 |
[CC_OP_SARB] = { compute_all_sarb, compute_c_sarl }, |
1571 |
[CC_OP_SARW] = { compute_all_sarw, compute_c_sarl }, |
1572 |
[CC_OP_SARL] = { compute_all_sarl, compute_c_sarl }, |
1573 |
|
1574 |
#ifdef TARGET_X86_64
|
1575 |
[CC_OP_MULQ] = { compute_all_mulq, compute_c_mull }, |
1576 |
|
1577 |
[CC_OP_ADDQ] = { compute_all_addq, compute_c_addq }, |
1578 |
|
1579 |
[CC_OP_ADCQ] = { compute_all_adcq, compute_c_adcq }, |
1580 |
|
1581 |
[CC_OP_SUBQ] = { compute_all_subq, compute_c_subq }, |
1582 |
|
1583 |
[CC_OP_SBBQ] = { compute_all_sbbq, compute_c_sbbq }, |
1584 |
|
1585 |
[CC_OP_LOGICQ] = { compute_all_logicq, compute_c_logicq }, |
1586 |
|
1587 |
[CC_OP_INCQ] = { compute_all_incq, compute_c_incl }, |
1588 |
|
1589 |
[CC_OP_DECQ] = { compute_all_decq, compute_c_incl }, |
1590 |
|
1591 |
[CC_OP_SHLQ] = { compute_all_shlq, compute_c_shlq }, |
1592 |
|
1593 |
[CC_OP_SARQ] = { compute_all_sarq, compute_c_sarl }, |
1594 |
#endif
|
1595 |
}; |
1596 |
|
1597 |
/* floating point support. Some of the code for complicated x87
|
1598 |
functions comes from the LGPL'ed x86 emulator found in the Willows
|
1599 |
TWIN windows emulator. */
|
1600 |
|
1601 |
#if defined(__powerpc__)
|
1602 |
extern CPU86_LDouble copysign(CPU86_LDouble, CPU86_LDouble);
|
1603 |
|
1604 |
/* correct (but slow) PowerPC rint() (glibc version is incorrect) */
|
1605 |
double qemu_rint(double x) |
1606 |
{ |
1607 |
double y = 4503599627370496.0; |
1608 |
if (fabs(x) >= y)
|
1609 |
return x;
|
1610 |
if (x < 0) |
1611 |
y = -y; |
1612 |
y = (x + y) - y; |
1613 |
if (y == 0.0) |
1614 |
y = copysign(y, x); |
1615 |
return y;
|
1616 |
} |
1617 |
|
1618 |
#define rint qemu_rint
|
1619 |
#endif
|
1620 |
|
1621 |
/* fp load FT0 */
|
1622 |
|
1623 |
void OPPROTO op_flds_FT0_A0(void) |
1624 |
{ |
1625 |
#ifdef USE_FP_CONVERT
|
1626 |
FP_CONVERT.i32 = ldl(A0); |
1627 |
FT0 = FP_CONVERT.f; |
1628 |
#else
|
1629 |
FT0 = ldfl(A0); |
1630 |
#endif
|
1631 |
} |
1632 |
|
1633 |
void OPPROTO op_fldl_FT0_A0(void) |
1634 |
{ |
1635 |
#ifdef USE_FP_CONVERT
|
1636 |
FP_CONVERT.i64 = ldq(A0); |
1637 |
FT0 = FP_CONVERT.d; |
1638 |
#else
|
1639 |
FT0 = ldfq(A0); |
1640 |
#endif
|
1641 |
} |
1642 |
|
1643 |
/* helpers are needed to avoid static constant reference. XXX: find a better way */
|
1644 |
#ifdef USE_INT_TO_FLOAT_HELPERS
|
1645 |
|
1646 |
void helper_fild_FT0_A0(void) |
1647 |
{ |
1648 |
FT0 = (CPU86_LDouble)ldsw(A0); |
1649 |
} |
1650 |
|
1651 |
void helper_fildl_FT0_A0(void) |
1652 |
{ |
1653 |
FT0 = (CPU86_LDouble)((int32_t)ldl(A0)); |
1654 |
} |
1655 |
|
1656 |
void helper_fildll_FT0_A0(void) |
1657 |
{ |
1658 |
FT0 = (CPU86_LDouble)((int64_t)ldq(A0)); |
1659 |
} |
1660 |
|
1661 |
void OPPROTO op_fild_FT0_A0(void) |
1662 |
{ |
1663 |
helper_fild_FT0_A0(); |
1664 |
} |
1665 |
|
1666 |
void OPPROTO op_fildl_FT0_A0(void) |
1667 |
{ |
1668 |
helper_fildl_FT0_A0(); |
1669 |
} |
1670 |
|
1671 |
void OPPROTO op_fildll_FT0_A0(void) |
1672 |
{ |
1673 |
helper_fildll_FT0_A0(); |
1674 |
} |
1675 |
|
1676 |
#else
|
1677 |
|
1678 |
void OPPROTO op_fild_FT0_A0(void) |
1679 |
{ |
1680 |
#ifdef USE_FP_CONVERT
|
1681 |
FP_CONVERT.i32 = ldsw(A0); |
1682 |
FT0 = (CPU86_LDouble)FP_CONVERT.i32; |
1683 |
#else
|
1684 |
FT0 = (CPU86_LDouble)ldsw(A0); |
1685 |
#endif
|
1686 |
} |
1687 |
|
1688 |
void OPPROTO op_fildl_FT0_A0(void) |
1689 |
{ |
1690 |
#ifdef USE_FP_CONVERT
|
1691 |
FP_CONVERT.i32 = (int32_t) ldl(A0); |
1692 |
FT0 = (CPU86_LDouble)FP_CONVERT.i32; |
1693 |
#else
|
1694 |
FT0 = (CPU86_LDouble)((int32_t)ldl(A0)); |
1695 |
#endif
|
1696 |
} |
1697 |
|
1698 |
void OPPROTO op_fildll_FT0_A0(void) |
1699 |
{ |
1700 |
#ifdef USE_FP_CONVERT
|
1701 |
FP_CONVERT.i64 = (int64_t) ldq(A0); |
1702 |
FT0 = (CPU86_LDouble)FP_CONVERT.i64; |
1703 |
#else
|
1704 |
FT0 = (CPU86_LDouble)((int64_t)ldq(A0)); |
1705 |
#endif
|
1706 |
} |
1707 |
#endif
|
1708 |
|
1709 |
/* fp load ST0 */
|
1710 |
|
1711 |
void OPPROTO op_flds_ST0_A0(void) |
1712 |
{ |
1713 |
int new_fpstt;
|
1714 |
new_fpstt = (env->fpstt - 1) & 7; |
1715 |
#ifdef USE_FP_CONVERT
|
1716 |
FP_CONVERT.i32 = ldl(A0); |
1717 |
env->fpregs[new_fpstt].d = FP_CONVERT.f; |
1718 |
#else
|
1719 |
env->fpregs[new_fpstt].d = ldfl(A0); |
1720 |
#endif
|
1721 |
env->fpstt = new_fpstt; |
1722 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1723 |
} |
1724 |
|
1725 |
void OPPROTO op_fldl_ST0_A0(void) |
1726 |
{ |
1727 |
int new_fpstt;
|
1728 |
new_fpstt = (env->fpstt - 1) & 7; |
1729 |
#ifdef USE_FP_CONVERT
|
1730 |
FP_CONVERT.i64 = ldq(A0); |
1731 |
env->fpregs[new_fpstt].d = FP_CONVERT.d; |
1732 |
#else
|
1733 |
env->fpregs[new_fpstt].d = ldfq(A0); |
1734 |
#endif
|
1735 |
env->fpstt = new_fpstt; |
1736 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1737 |
} |
1738 |
|
1739 |
void OPPROTO op_fldt_ST0_A0(void) |
1740 |
{ |
1741 |
helper_fldt_ST0_A0(); |
1742 |
} |
1743 |
|
1744 |
/* helpers are needed to avoid static constant reference. XXX: find a better way */
|
1745 |
#ifdef USE_INT_TO_FLOAT_HELPERS
|
1746 |
|
1747 |
void helper_fild_ST0_A0(void) |
1748 |
{ |
1749 |
int new_fpstt;
|
1750 |
new_fpstt = (env->fpstt - 1) & 7; |
1751 |
env->fpregs[new_fpstt].d = (CPU86_LDouble)ldsw(A0); |
1752 |
env->fpstt = new_fpstt; |
1753 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1754 |
} |
1755 |
|
1756 |
void helper_fildl_ST0_A0(void) |
1757 |
{ |
1758 |
int new_fpstt;
|
1759 |
new_fpstt = (env->fpstt - 1) & 7; |
1760 |
env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0)); |
1761 |
env->fpstt = new_fpstt; |
1762 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1763 |
} |
1764 |
|
1765 |
void helper_fildll_ST0_A0(void) |
1766 |
{ |
1767 |
int new_fpstt;
|
1768 |
new_fpstt = (env->fpstt - 1) & 7; |
1769 |
env->fpregs[new_fpstt].d = (CPU86_LDouble)((int64_t)ldq(A0)); |
1770 |
env->fpstt = new_fpstt; |
1771 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1772 |
} |
1773 |
|
1774 |
void OPPROTO op_fild_ST0_A0(void) |
1775 |
{ |
1776 |
helper_fild_ST0_A0(); |
1777 |
} |
1778 |
|
1779 |
void OPPROTO op_fildl_ST0_A0(void) |
1780 |
{ |
1781 |
helper_fildl_ST0_A0(); |
1782 |
} |
1783 |
|
1784 |
void OPPROTO op_fildll_ST0_A0(void) |
1785 |
{ |
1786 |
helper_fildll_ST0_A0(); |
1787 |
} |
1788 |
|
1789 |
#else
|
1790 |
|
1791 |
void OPPROTO op_fild_ST0_A0(void) |
1792 |
{ |
1793 |
int new_fpstt;
|
1794 |
new_fpstt = (env->fpstt - 1) & 7; |
1795 |
#ifdef USE_FP_CONVERT
|
1796 |
FP_CONVERT.i32 = ldsw(A0); |
1797 |
env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i32; |
1798 |
#else
|
1799 |
env->fpregs[new_fpstt].d = (CPU86_LDouble)ldsw(A0); |
1800 |
#endif
|
1801 |
env->fpstt = new_fpstt; |
1802 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1803 |
} |
1804 |
|
1805 |
void OPPROTO op_fildl_ST0_A0(void) |
1806 |
{ |
1807 |
int new_fpstt;
|
1808 |
new_fpstt = (env->fpstt - 1) & 7; |
1809 |
#ifdef USE_FP_CONVERT
|
1810 |
FP_CONVERT.i32 = (int32_t) ldl(A0); |
1811 |
env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i32; |
1812 |
#else
|
1813 |
env->fpregs[new_fpstt].d = (CPU86_LDouble)((int32_t)ldl(A0)); |
1814 |
#endif
|
1815 |
env->fpstt = new_fpstt; |
1816 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1817 |
} |
1818 |
|
1819 |
void OPPROTO op_fildll_ST0_A0(void) |
1820 |
{ |
1821 |
int new_fpstt;
|
1822 |
new_fpstt = (env->fpstt - 1) & 7; |
1823 |
#ifdef USE_FP_CONVERT
|
1824 |
FP_CONVERT.i64 = (int64_t) ldq(A0); |
1825 |
env->fpregs[new_fpstt].d = (CPU86_LDouble)FP_CONVERT.i64; |
1826 |
#else
|
1827 |
env->fpregs[new_fpstt].d = (CPU86_LDouble)((int64_t)ldq(A0)); |
1828 |
#endif
|
1829 |
env->fpstt = new_fpstt; |
1830 |
env->fptags[new_fpstt] = 0; /* validate stack entry */ |
1831 |
} |
1832 |
|
1833 |
#endif
|
1834 |
|
1835 |
/* fp store */
|
1836 |
|
1837 |
void OPPROTO op_fsts_ST0_A0(void) |
1838 |
{ |
1839 |
#ifdef USE_FP_CONVERT
|
1840 |
FP_CONVERT.f = (float)ST0;
|
1841 |
stfl(A0, FP_CONVERT.f); |
1842 |
#else
|
1843 |
stfl(A0, (float)ST0);
|
1844 |
#endif
|
1845 |
} |
1846 |
|
1847 |
void OPPROTO op_fstl_ST0_A0(void) |
1848 |
{ |
1849 |
stfq(A0, (double)ST0);
|
1850 |
} |
1851 |
|
1852 |
void OPPROTO op_fstt_ST0_A0(void) |
1853 |
{ |
1854 |
helper_fstt_ST0_A0(); |
1855 |
} |
1856 |
|
1857 |
void OPPROTO op_fist_ST0_A0(void) |
1858 |
{ |
1859 |
#if defined(__sparc__) && !defined(__sparc_v9__)
|
1860 |
register CPU86_LDouble d asm("o0"); |
1861 |
#else
|
1862 |
CPU86_LDouble d; |
1863 |
#endif
|
1864 |
int val;
|
1865 |
|
1866 |
d = ST0; |
1867 |
val = lrint(d); |
1868 |
if (val != (int16_t)val)
|
1869 |
val = -32768;
|
1870 |
stw(A0, val); |
1871 |
} |
1872 |
|
1873 |
void OPPROTO op_fistl_ST0_A0(void) |
1874 |
{ |
1875 |
#if defined(__sparc__) && !defined(__sparc_v9__)
|
1876 |
register CPU86_LDouble d asm("o0"); |
1877 |
#else
|
1878 |
CPU86_LDouble d; |
1879 |
#endif
|
1880 |
int val;
|
1881 |
|
1882 |
d = ST0; |
1883 |
val = lrint(d); |
1884 |
stl(A0, val); |
1885 |
} |
1886 |
|
1887 |
void OPPROTO op_fistll_ST0_A0(void) |
1888 |
{ |
1889 |
#if defined(__sparc__) && !defined(__sparc_v9__)
|
1890 |
register CPU86_LDouble d asm("o0"); |
1891 |
#else
|
1892 |
CPU86_LDouble d; |
1893 |
#endif
|
1894 |
int64_t val; |
1895 |
|
1896 |
d = ST0; |
1897 |
val = llrint(d); |
1898 |
stq(A0, val); |
1899 |
} |
1900 |
|
1901 |
void OPPROTO op_fbld_ST0_A0(void) |
1902 |
{ |
1903 |
helper_fbld_ST0_A0(); |
1904 |
} |
1905 |
|
1906 |
void OPPROTO op_fbst_ST0_A0(void) |
1907 |
{ |
1908 |
helper_fbst_ST0_A0(); |
1909 |
} |
1910 |
|
1911 |
/* FPU move */
|
1912 |
|
1913 |
void OPPROTO op_fpush(void) |
1914 |
{ |
1915 |
fpush(); |
1916 |
} |
1917 |
|
1918 |
void OPPROTO op_fpop(void) |
1919 |
{ |
1920 |
fpop(); |
1921 |
} |
1922 |
|
1923 |
void OPPROTO op_fdecstp(void) |
1924 |
{ |
1925 |
env->fpstt = (env->fpstt - 1) & 7; |
1926 |
env->fpus &= (~0x4700);
|
1927 |
} |
1928 |
|
1929 |
void OPPROTO op_fincstp(void) |
1930 |
{ |
1931 |
env->fpstt = (env->fpstt + 1) & 7; |
1932 |
env->fpus &= (~0x4700);
|
1933 |
} |
1934 |
|
1935 |
void OPPROTO op_ffree_STN(void) |
1936 |
{ |
1937 |
env->fptags[(env->fpstt + PARAM1) & 7] = 1; |
1938 |
} |
1939 |
|
1940 |
void OPPROTO op_fmov_ST0_FT0(void) |
1941 |
{ |
1942 |
ST0 = FT0; |
1943 |
} |
1944 |
|
1945 |
void OPPROTO op_fmov_FT0_STN(void) |
1946 |
{ |
1947 |
FT0 = ST(PARAM1); |
1948 |
} |
1949 |
|
1950 |
void OPPROTO op_fmov_ST0_STN(void) |
1951 |
{ |
1952 |
ST0 = ST(PARAM1); |
1953 |
} |
1954 |
|
1955 |
void OPPROTO op_fmov_STN_ST0(void) |
1956 |
{ |
1957 |
ST(PARAM1) = ST0; |
1958 |
} |
1959 |
|
1960 |
void OPPROTO op_fxchg_ST0_STN(void) |
1961 |
{ |
1962 |
CPU86_LDouble tmp; |
1963 |
tmp = ST(PARAM1); |
1964 |
ST(PARAM1) = ST0; |
1965 |
ST0 = tmp; |
1966 |
} |
1967 |
|
1968 |
/* FPU operations */
|
1969 |
|
1970 |
/* XXX: handle nans */
|
1971 |
void OPPROTO op_fcom_ST0_FT0(void) |
1972 |
{ |
1973 |
env->fpus &= (~0x4500); /* (C3,C2,C0) <-- 000 */ |
1974 |
if (ST0 < FT0)
|
1975 |
env->fpus |= 0x100; /* (C3,C2,C0) <-- 001 */ |
1976 |
else if (ST0 == FT0) |
1977 |
env->fpus |= 0x4000; /* (C3,C2,C0) <-- 100 */ |
1978 |
FORCE_RET(); |
1979 |
} |
1980 |
|
1981 |
/* XXX: handle nans */
|
1982 |
void OPPROTO op_fucom_ST0_FT0(void) |
1983 |
{ |
1984 |
env->fpus &= (~0x4500); /* (C3,C2,C0) <-- 000 */ |
1985 |
if (ST0 < FT0)
|
1986 |
env->fpus |= 0x100; /* (C3,C2,C0) <-- 001 */ |
1987 |
else if (ST0 == FT0) |
1988 |
env->fpus |= 0x4000; /* (C3,C2,C0) <-- 100 */ |
1989 |
FORCE_RET(); |
1990 |
} |
1991 |
|
1992 |
/* XXX: handle nans */
|
1993 |
void OPPROTO op_fcomi_ST0_FT0(void) |
1994 |
{ |
1995 |
int eflags;
|
1996 |
eflags = cc_table[CC_OP].compute_all(); |
1997 |
eflags &= ~(CC_Z | CC_P | CC_C); |
1998 |
if (ST0 < FT0)
|
1999 |
eflags |= CC_C; |
2000 |
else if (ST0 == FT0) |
2001 |
eflags |= CC_Z; |
2002 |
CC_SRC = eflags; |
2003 |
FORCE_RET(); |
2004 |
} |
2005 |
|
2006 |
/* XXX: handle nans */
|
2007 |
void OPPROTO op_fucomi_ST0_FT0(void) |
2008 |
{ |
2009 |
int eflags;
|
2010 |
eflags = cc_table[CC_OP].compute_all(); |
2011 |
eflags &= ~(CC_Z | CC_P | CC_C); |
2012 |
if (ST0 < FT0)
|
2013 |
eflags |= CC_C; |
2014 |
else if (ST0 == FT0) |
2015 |
eflags |= CC_Z; |
2016 |
CC_SRC = eflags; |
2017 |
FORCE_RET(); |
2018 |
} |
2019 |
|
2020 |
void OPPROTO op_fcmov_ST0_STN_T0(void) |
2021 |
{ |
2022 |
if (T0) {
|
2023 |
ST0 = ST(PARAM1); |
2024 |
} |
2025 |
FORCE_RET(); |
2026 |
} |
2027 |
|
2028 |
void OPPROTO op_fadd_ST0_FT0(void) |
2029 |
{ |
2030 |
ST0 += FT0; |
2031 |
} |
2032 |
|
2033 |
void OPPROTO op_fmul_ST0_FT0(void) |
2034 |
{ |
2035 |
ST0 *= FT0; |
2036 |
} |
2037 |
|
2038 |
void OPPROTO op_fsub_ST0_FT0(void) |
2039 |
{ |
2040 |
ST0 -= FT0; |
2041 |
} |
2042 |
|
2043 |
void OPPROTO op_fsubr_ST0_FT0(void) |
2044 |
{ |
2045 |
ST0 = FT0 - ST0; |
2046 |
} |
2047 |
|
2048 |
void OPPROTO op_fdiv_ST0_FT0(void) |
2049 |
{ |
2050 |
ST0 = helper_fdiv(ST0, FT0); |
2051 |
} |
2052 |
|
2053 |
void OPPROTO op_fdivr_ST0_FT0(void) |
2054 |
{ |
2055 |
ST0 = helper_fdiv(FT0, ST0); |
2056 |
} |
2057 |
|
2058 |
/* fp operations between STN and ST0 */
|
2059 |
|
2060 |
void OPPROTO op_fadd_STN_ST0(void) |
2061 |
{ |
2062 |
ST(PARAM1) += ST0; |
2063 |
} |
2064 |
|
2065 |
void OPPROTO op_fmul_STN_ST0(void) |
2066 |
{ |
2067 |
ST(PARAM1) *= ST0; |
2068 |
} |
2069 |
|
2070 |
void OPPROTO op_fsub_STN_ST0(void) |
2071 |
{ |
2072 |
ST(PARAM1) -= ST0; |
2073 |
} |
2074 |
|
2075 |
void OPPROTO op_fsubr_STN_ST0(void) |
2076 |
{ |
2077 |
CPU86_LDouble *p; |
2078 |
p = &ST(PARAM1); |
2079 |
*p = ST0 - *p; |
2080 |
} |
2081 |
|
2082 |
void OPPROTO op_fdiv_STN_ST0(void) |
2083 |
{ |
2084 |
CPU86_LDouble *p; |
2085 |
p = &ST(PARAM1); |
2086 |
*p = helper_fdiv(*p, ST0); |
2087 |
} |
2088 |
|
2089 |
void OPPROTO op_fdivr_STN_ST0(void) |
2090 |
{ |
2091 |
CPU86_LDouble *p; |
2092 |
p = &ST(PARAM1); |
2093 |
*p = helper_fdiv(ST0, *p); |
2094 |
} |
2095 |
|
2096 |
/* misc FPU operations */
|
2097 |
void OPPROTO op_fchs_ST0(void) |
2098 |
{ |
2099 |
ST0 = -ST0; |
2100 |
} |
2101 |
|
2102 |
void OPPROTO op_fabs_ST0(void) |
2103 |
{ |
2104 |
ST0 = fabs(ST0); |
2105 |
} |
2106 |
|
2107 |
void OPPROTO op_fxam_ST0(void) |
2108 |
{ |
2109 |
helper_fxam_ST0(); |
2110 |
} |
2111 |
|
2112 |
void OPPROTO op_fld1_ST0(void) |
2113 |
{ |
2114 |
ST0 = f15rk[1];
|
2115 |
} |
2116 |
|
2117 |
void OPPROTO op_fldl2t_ST0(void) |
2118 |
{ |
2119 |
ST0 = f15rk[6];
|
2120 |
} |
2121 |
|
2122 |
void OPPROTO op_fldl2e_ST0(void) |
2123 |
{ |
2124 |
ST0 = f15rk[5];
|
2125 |
} |
2126 |
|
2127 |
void OPPROTO op_fldpi_ST0(void) |
2128 |
{ |
2129 |
ST0 = f15rk[2];
|
2130 |
} |
2131 |
|
2132 |
void OPPROTO op_fldlg2_ST0(void) |
2133 |
{ |
2134 |
ST0 = f15rk[3];
|
2135 |
} |
2136 |
|
2137 |
void OPPROTO op_fldln2_ST0(void) |
2138 |
{ |
2139 |
ST0 = f15rk[4];
|
2140 |
} |
2141 |
|
2142 |
void OPPROTO op_fldz_ST0(void) |
2143 |
{ |
2144 |
ST0 = f15rk[0];
|
2145 |
} |
2146 |
|
2147 |
void OPPROTO op_fldz_FT0(void) |
2148 |
{ |
2149 |
FT0 = f15rk[0];
|
2150 |
} |
2151 |
|
2152 |
/* associated heplers to reduce generated code length and to simplify
|
2153 |
relocation (FP constants are usually stored in .rodata section) */
|
2154 |
|
2155 |
void OPPROTO op_f2xm1(void) |
2156 |
{ |
2157 |
helper_f2xm1(); |
2158 |
} |
2159 |
|
2160 |
void OPPROTO op_fyl2x(void) |
2161 |
{ |
2162 |
helper_fyl2x(); |
2163 |
} |
2164 |
|
2165 |
void OPPROTO op_fptan(void) |
2166 |
{ |
2167 |
helper_fptan(); |
2168 |
} |
2169 |
|
2170 |
void OPPROTO op_fpatan(void) |
2171 |
{ |
2172 |
helper_fpatan(); |
2173 |
} |
2174 |
|
2175 |
void OPPROTO op_fxtract(void) |
2176 |
{ |
2177 |
helper_fxtract(); |
2178 |
} |
2179 |
|
2180 |
void OPPROTO op_fprem1(void) |
2181 |
{ |
2182 |
helper_fprem1(); |
2183 |
} |
2184 |
|
2185 |
|
2186 |
void OPPROTO op_fprem(void) |
2187 |
{ |
2188 |
helper_fprem(); |
2189 |
} |
2190 |
|
2191 |
void OPPROTO op_fyl2xp1(void) |
2192 |
{ |
2193 |
helper_fyl2xp1(); |
2194 |
} |
2195 |
|
2196 |
void OPPROTO op_fsqrt(void) |
2197 |
{ |
2198 |
helper_fsqrt(); |
2199 |
} |
2200 |
|
2201 |
void OPPROTO op_fsincos(void) |
2202 |
{ |
2203 |
helper_fsincos(); |
2204 |
} |
2205 |
|
2206 |
void OPPROTO op_frndint(void) |
2207 |
{ |
2208 |
helper_frndint(); |
2209 |
} |
2210 |
|
2211 |
void OPPROTO op_fscale(void) |
2212 |
{ |
2213 |
helper_fscale(); |
2214 |
} |
2215 |
|
2216 |
void OPPROTO op_fsin(void) |
2217 |
{ |
2218 |
helper_fsin(); |
2219 |
} |
2220 |
|
2221 |
void OPPROTO op_fcos(void) |
2222 |
{ |
2223 |
helper_fcos(); |
2224 |
} |
2225 |
|
2226 |
void OPPROTO op_fnstsw_A0(void) |
2227 |
{ |
2228 |
int fpus;
|
2229 |
fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; |
2230 |
stw(A0, fpus); |
2231 |
} |
2232 |
|
2233 |
void OPPROTO op_fnstsw_EAX(void) |
2234 |
{ |
2235 |
int fpus;
|
2236 |
fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; |
2237 |
EAX = (EAX & ~0xffff) | fpus;
|
2238 |
} |
2239 |
|
2240 |
void OPPROTO op_fnstcw_A0(void) |
2241 |
{ |
2242 |
stw(A0, env->fpuc); |
2243 |
} |
2244 |
|
2245 |
void OPPROTO op_fldcw_A0(void) |
2246 |
{ |
2247 |
int rnd_type;
|
2248 |
env->fpuc = lduw(A0); |
2249 |
/* set rounding mode */
|
2250 |
switch(env->fpuc & RC_MASK) {
|
2251 |
default:
|
2252 |
case RC_NEAR:
|
2253 |
rnd_type = FE_TONEAREST; |
2254 |
break;
|
2255 |
case RC_DOWN:
|
2256 |
rnd_type = FE_DOWNWARD; |
2257 |
break;
|
2258 |
case RC_UP:
|
2259 |
rnd_type = FE_UPWARD; |
2260 |
break;
|
2261 |
case RC_CHOP:
|
2262 |
rnd_type = FE_TOWARDZERO; |
2263 |
break;
|
2264 |
} |
2265 |
fesetround(rnd_type); |
2266 |
} |
2267 |
|
2268 |
void OPPROTO op_fclex(void) |
2269 |
{ |
2270 |
env->fpus &= 0x7f00;
|
2271 |
} |
2272 |
|
2273 |
void OPPROTO op_fwait(void) |
2274 |
{ |
2275 |
if (env->fpus & FPUS_SE)
|
2276 |
fpu_raise_exception(); |
2277 |
FORCE_RET(); |
2278 |
} |
2279 |
|
2280 |
void OPPROTO op_fninit(void) |
2281 |
{ |
2282 |
env->fpus = 0;
|
2283 |
env->fpstt = 0;
|
2284 |
env->fpuc = 0x37f;
|
2285 |
env->fptags[0] = 1; |
2286 |
env->fptags[1] = 1; |
2287 |
env->fptags[2] = 1; |
2288 |
env->fptags[3] = 1; |
2289 |
env->fptags[4] = 1; |
2290 |
env->fptags[5] = 1; |
2291 |
env->fptags[6] = 1; |
2292 |
env->fptags[7] = 1; |
2293 |
} |
2294 |
|
2295 |
void OPPROTO op_fnstenv_A0(void) |
2296 |
{ |
2297 |
helper_fstenv(A0, PARAM1); |
2298 |
} |
2299 |
|
2300 |
void OPPROTO op_fldenv_A0(void) |
2301 |
{ |
2302 |
helper_fldenv(A0, PARAM1); |
2303 |
} |
2304 |
|
2305 |
void OPPROTO op_fnsave_A0(void) |
2306 |
{ |
2307 |
helper_fsave(A0, PARAM1); |
2308 |
} |
2309 |
|
2310 |
void OPPROTO op_frstor_A0(void) |
2311 |
{ |
2312 |
helper_frstor(A0, PARAM1); |
2313 |
} |
2314 |
|
2315 |
/* threading support */
|
2316 |
void OPPROTO op_lock(void) |
2317 |
{ |
2318 |
cpu_lock(); |
2319 |
} |
2320 |
|
2321 |
void OPPROTO op_unlock(void) |
2322 |
{ |
2323 |
cpu_unlock(); |
2324 |
} |
2325 |
|
2326 |
/* SSE support */
|
2327 |
static inline void memcpy16(void *d, void *s) |
2328 |
{ |
2329 |
((uint32_t *)d)[0] = ((uint32_t *)s)[0]; |
2330 |
((uint32_t *)d)[1] = ((uint32_t *)s)[1]; |
2331 |
((uint32_t *)d)[2] = ((uint32_t *)s)[2]; |
2332 |
((uint32_t *)d)[3] = ((uint32_t *)s)[3]; |
2333 |
} |
2334 |
|
2335 |
void OPPROTO op_movo(void) |
2336 |
{ |
2337 |
/* XXX: badly generated code */
|
2338 |
XMMReg *d, *s; |
2339 |
d = (XMMReg *)((char *)env + PARAM1);
|
2340 |
s = (XMMReg *)((char *)env + PARAM2);
|
2341 |
memcpy16(d, s); |
2342 |
} |
2343 |
|
2344 |
void OPPROTO op_movq(void) |
2345 |
{ |
2346 |
uint64_t *d, *s; |
2347 |
d = (uint64_t *)((char *)env + PARAM1);
|
2348 |
s = (uint64_t *)((char *)env + PARAM2);
|
2349 |
*d = *s; |
2350 |
} |
2351 |
|
2352 |
void OPPROTO op_movl(void) |
2353 |
{ |
2354 |
uint32_t *d, *s; |
2355 |
d = (uint32_t *)((char *)env + PARAM1);
|
2356 |
s = (uint32_t *)((char *)env + PARAM2);
|
2357 |
*d = *s; |
2358 |
} |
2359 |
|
2360 |
void OPPROTO op_movq_env_0(void) |
2361 |
{ |
2362 |
uint64_t *d; |
2363 |
d = (uint64_t *)((char *)env + PARAM1);
|
2364 |
*d = 0;
|
2365 |
} |
2366 |
|
2367 |
void OPPROTO op_fxsave_A0(void) |
2368 |
{ |
2369 |
helper_fxsave(A0, PARAM1); |
2370 |
} |
2371 |
|
2372 |
void OPPROTO op_fxrstor_A0(void) |
2373 |
{ |
2374 |
helper_fxrstor(A0, PARAM1); |
2375 |
} |
2376 |
|
2377 |
/* XXX: optimize by storing fptt and fptags in the static cpu state */
|
2378 |
void OPPROTO op_enter_mmx(void) |
2379 |
{ |
2380 |
env->fpstt = 0;
|
2381 |
*(uint32_t *)(env->fptags) = 0;
|
2382 |
*(uint32_t *)(env->fptags + 4) = 0; |
2383 |
} |
2384 |
|
2385 |
void OPPROTO op_emms(void) |
2386 |
{ |
2387 |
/* set to empty state */
|
2388 |
*(uint32_t *)(env->fptags) = 0x01010101;
|
2389 |
*(uint32_t *)(env->fptags + 4) = 0x01010101; |
2390 |
} |
2391 |
|
2392 |
#define SHIFT 0 |
2393 |
#include "ops_sse.h" |
2394 |
|
2395 |
#define SHIFT 1 |
2396 |
#include "ops_sse.h" |