root / target-i386 / translate.c @ b27fc131
History | View | Annotate | Download (263.6 kB)
1 |
/*
|
---|---|
2 |
* i386 translation
|
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 |
#include <stdarg.h> |
20 |
#include <stdlib.h> |
21 |
#include <stdio.h> |
22 |
#include <string.h> |
23 |
#include <inttypes.h> |
24 |
#include <signal.h> |
25 |
|
26 |
#include "cpu.h" |
27 |
#include "disas/disas.h" |
28 |
#include "tcg-op.h" |
29 |
|
30 |
#include "helper.h" |
31 |
#define GEN_HELPER 1 |
32 |
#include "helper.h" |
33 |
|
34 |
#define PREFIX_REPZ 0x01 |
35 |
#define PREFIX_REPNZ 0x02 |
36 |
#define PREFIX_LOCK 0x04 |
37 |
#define PREFIX_DATA 0x08 |
38 |
#define PREFIX_ADR 0x10 |
39 |
|
40 |
#ifdef TARGET_X86_64
|
41 |
#define CODE64(s) ((s)->code64)
|
42 |
#define REX_X(s) ((s)->rex_x)
|
43 |
#define REX_B(s) ((s)->rex_b)
|
44 |
#else
|
45 |
#define CODE64(s) 0 |
46 |
#define REX_X(s) 0 |
47 |
#define REX_B(s) 0 |
48 |
#endif
|
49 |
|
50 |
//#define MACRO_TEST 1
|
51 |
|
52 |
/* global register indexes */
|
53 |
static TCGv_ptr cpu_env;
|
54 |
static TCGv cpu_A0, cpu_cc_src, cpu_cc_dst, cpu_cc_tmp;
|
55 |
static TCGv_i32 cpu_cc_op;
|
56 |
static TCGv cpu_regs[CPU_NB_REGS];
|
57 |
/* local temps */
|
58 |
static TCGv cpu_T[2], cpu_T3; |
59 |
/* local register indexes (only used inside old micro ops) */
|
60 |
static TCGv cpu_tmp0, cpu_tmp4;
|
61 |
static TCGv_ptr cpu_ptr0, cpu_ptr1;
|
62 |
static TCGv_i32 cpu_tmp2_i32, cpu_tmp3_i32;
|
63 |
static TCGv_i64 cpu_tmp1_i64;
|
64 |
static TCGv cpu_tmp5;
|
65 |
|
66 |
static uint8_t gen_opc_cc_op[OPC_BUF_SIZE];
|
67 |
|
68 |
#include "exec/gen-icount.h" |
69 |
|
70 |
#ifdef TARGET_X86_64
|
71 |
static int x86_64_hregs; |
72 |
#endif
|
73 |
|
74 |
typedef struct DisasContext { |
75 |
/* current insn context */
|
76 |
int override; /* -1 if no override */ |
77 |
int prefix;
|
78 |
int aflag, dflag;
|
79 |
target_ulong pc; /* pc = eip + cs_base */
|
80 |
int is_jmp; /* 1 = means jump (stop translation), 2 means CPU |
81 |
static state change (stop translation) */
|
82 |
/* current block context */
|
83 |
target_ulong cs_base; /* base of CS segment */
|
84 |
int pe; /* protected mode */ |
85 |
int code32; /* 32 bit code segment */ |
86 |
#ifdef TARGET_X86_64
|
87 |
int lma; /* long mode active */ |
88 |
int code64; /* 64 bit code segment */ |
89 |
int rex_x, rex_b;
|
90 |
#endif
|
91 |
int ss32; /* 32 bit stack segment */ |
92 |
int cc_op; /* current CC operation */ |
93 |
int addseg; /* non zero if either DS/ES/SS have a non zero base */ |
94 |
int f_st; /* currently unused */ |
95 |
int vm86; /* vm86 mode */ |
96 |
int cpl;
|
97 |
int iopl;
|
98 |
int tf; /* TF cpu flag */ |
99 |
int singlestep_enabled; /* "hardware" single step enabled */ |
100 |
int jmp_opt; /* use direct block chaining for direct jumps */ |
101 |
int mem_index; /* select memory access functions */ |
102 |
uint64_t flags; /* all execution flags */
|
103 |
struct TranslationBlock *tb;
|
104 |
int popl_esp_hack; /* for correct popl with esp base handling */ |
105 |
int rip_offset; /* only used in x86_64, but left for simplicity */ |
106 |
int cpuid_features;
|
107 |
int cpuid_ext_features;
|
108 |
int cpuid_ext2_features;
|
109 |
int cpuid_ext3_features;
|
110 |
int cpuid_7_0_ebx_features;
|
111 |
} DisasContext; |
112 |
|
113 |
static void gen_eob(DisasContext *s); |
114 |
static void gen_jmp(DisasContext *s, target_ulong eip); |
115 |
static void gen_jmp_tb(DisasContext *s, target_ulong eip, int tb_num); |
116 |
|
117 |
/* i386 arith/logic operations */
|
118 |
enum {
|
119 |
OP_ADDL, |
120 |
OP_ORL, |
121 |
OP_ADCL, |
122 |
OP_SBBL, |
123 |
OP_ANDL, |
124 |
OP_SUBL, |
125 |
OP_XORL, |
126 |
OP_CMPL, |
127 |
}; |
128 |
|
129 |
/* i386 shift ops */
|
130 |
enum {
|
131 |
OP_ROL, |
132 |
OP_ROR, |
133 |
OP_RCL, |
134 |
OP_RCR, |
135 |
OP_SHL, |
136 |
OP_SHR, |
137 |
OP_SHL1, /* undocumented */
|
138 |
OP_SAR = 7,
|
139 |
}; |
140 |
|
141 |
enum {
|
142 |
JCC_O, |
143 |
JCC_B, |
144 |
JCC_Z, |
145 |
JCC_BE, |
146 |
JCC_S, |
147 |
JCC_P, |
148 |
JCC_L, |
149 |
JCC_LE, |
150 |
}; |
151 |
|
152 |
/* operand size */
|
153 |
enum {
|
154 |
OT_BYTE = 0,
|
155 |
OT_WORD, |
156 |
OT_LONG, |
157 |
OT_QUAD, |
158 |
}; |
159 |
|
160 |
enum {
|
161 |
/* I386 int registers */
|
162 |
OR_EAX, /* MUST be even numbered */
|
163 |
OR_ECX, |
164 |
OR_EDX, |
165 |
OR_EBX, |
166 |
OR_ESP, |
167 |
OR_EBP, |
168 |
OR_ESI, |
169 |
OR_EDI, |
170 |
|
171 |
OR_TMP0 = 16, /* temporary operand register */ |
172 |
OR_TMP1, |
173 |
OR_A0, /* temporary register used when doing address evaluation */
|
174 |
}; |
175 |
|
176 |
static inline void gen_op_movl_T0_0(void) |
177 |
{ |
178 |
tcg_gen_movi_tl(cpu_T[0], 0); |
179 |
} |
180 |
|
181 |
static inline void gen_op_movl_T0_im(int32_t val) |
182 |
{ |
183 |
tcg_gen_movi_tl(cpu_T[0], val);
|
184 |
} |
185 |
|
186 |
static inline void gen_op_movl_T0_imu(uint32_t val) |
187 |
{ |
188 |
tcg_gen_movi_tl(cpu_T[0], val);
|
189 |
} |
190 |
|
191 |
static inline void gen_op_movl_T1_im(int32_t val) |
192 |
{ |
193 |
tcg_gen_movi_tl(cpu_T[1], val);
|
194 |
} |
195 |
|
196 |
static inline void gen_op_movl_T1_imu(uint32_t val) |
197 |
{ |
198 |
tcg_gen_movi_tl(cpu_T[1], val);
|
199 |
} |
200 |
|
201 |
static inline void gen_op_movl_A0_im(uint32_t val) |
202 |
{ |
203 |
tcg_gen_movi_tl(cpu_A0, val); |
204 |
} |
205 |
|
206 |
#ifdef TARGET_X86_64
|
207 |
static inline void gen_op_movq_A0_im(int64_t val) |
208 |
{ |
209 |
tcg_gen_movi_tl(cpu_A0, val); |
210 |
} |
211 |
#endif
|
212 |
|
213 |
static inline void gen_movtl_T0_im(target_ulong val) |
214 |
{ |
215 |
tcg_gen_movi_tl(cpu_T[0], val);
|
216 |
} |
217 |
|
218 |
static inline void gen_movtl_T1_im(target_ulong val) |
219 |
{ |
220 |
tcg_gen_movi_tl(cpu_T[1], val);
|
221 |
} |
222 |
|
223 |
static inline void gen_op_andl_T0_ffff(void) |
224 |
{ |
225 |
tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0xffff); |
226 |
} |
227 |
|
228 |
static inline void gen_op_andl_T0_im(uint32_t val) |
229 |
{ |
230 |
tcg_gen_andi_tl(cpu_T[0], cpu_T[0], val); |
231 |
} |
232 |
|
233 |
static inline void gen_op_movl_T0_T1(void) |
234 |
{ |
235 |
tcg_gen_mov_tl(cpu_T[0], cpu_T[1]); |
236 |
} |
237 |
|
238 |
static inline void gen_op_andl_A0_ffff(void) |
239 |
{ |
240 |
tcg_gen_andi_tl(cpu_A0, cpu_A0, 0xffff);
|
241 |
} |
242 |
|
243 |
#ifdef TARGET_X86_64
|
244 |
|
245 |
#define NB_OP_SIZES 4 |
246 |
|
247 |
#else /* !TARGET_X86_64 */ |
248 |
|
249 |
#define NB_OP_SIZES 3 |
250 |
|
251 |
#endif /* !TARGET_X86_64 */ |
252 |
|
253 |
#if defined(HOST_WORDS_BIGENDIAN)
|
254 |
#define REG_B_OFFSET (sizeof(target_ulong) - 1) |
255 |
#define REG_H_OFFSET (sizeof(target_ulong) - 2) |
256 |
#define REG_W_OFFSET (sizeof(target_ulong) - 2) |
257 |
#define REG_L_OFFSET (sizeof(target_ulong) - 4) |
258 |
#define REG_LH_OFFSET (sizeof(target_ulong) - 8) |
259 |
#else
|
260 |
#define REG_B_OFFSET 0 |
261 |
#define REG_H_OFFSET 1 |
262 |
#define REG_W_OFFSET 0 |
263 |
#define REG_L_OFFSET 0 |
264 |
#define REG_LH_OFFSET 4 |
265 |
#endif
|
266 |
|
267 |
/* In instruction encodings for byte register accesses the
|
268 |
* register number usually indicates "low 8 bits of register N";
|
269 |
* however there are some special cases where N 4..7 indicates
|
270 |
* [AH, CH, DH, BH], ie "bits 15..8 of register N-4". Return
|
271 |
* true for this special case, false otherwise.
|
272 |
*/
|
273 |
static inline bool byte_reg_is_xH(int reg) |
274 |
{ |
275 |
if (reg < 4) { |
276 |
return false; |
277 |
} |
278 |
#ifdef TARGET_X86_64
|
279 |
if (reg >= 8 || x86_64_hregs) { |
280 |
return false; |
281 |
} |
282 |
#endif
|
283 |
return true; |
284 |
} |
285 |
|
286 |
static inline void gen_op_mov_reg_v(int ot, int reg, TCGv t0) |
287 |
{ |
288 |
switch(ot) {
|
289 |
case OT_BYTE:
|
290 |
if (!byte_reg_is_xH(reg)) {
|
291 |
tcg_gen_deposit_tl(cpu_regs[reg], cpu_regs[reg], t0, 0, 8); |
292 |
} else {
|
293 |
tcg_gen_deposit_tl(cpu_regs[reg - 4], cpu_regs[reg - 4], t0, 8, 8); |
294 |
} |
295 |
break;
|
296 |
case OT_WORD:
|
297 |
tcg_gen_deposit_tl(cpu_regs[reg], cpu_regs[reg], t0, 0, 16); |
298 |
break;
|
299 |
default: /* XXX this shouldn't be reached; abort? */ |
300 |
case OT_LONG:
|
301 |
/* For x86_64, this sets the higher half of register to zero.
|
302 |
For i386, this is equivalent to a mov. */
|
303 |
tcg_gen_ext32u_tl(cpu_regs[reg], t0); |
304 |
break;
|
305 |
#ifdef TARGET_X86_64
|
306 |
case OT_QUAD:
|
307 |
tcg_gen_mov_tl(cpu_regs[reg], t0); |
308 |
break;
|
309 |
#endif
|
310 |
} |
311 |
} |
312 |
|
313 |
static inline void gen_op_mov_reg_T0(int ot, int reg) |
314 |
{ |
315 |
gen_op_mov_reg_v(ot, reg, cpu_T[0]);
|
316 |
} |
317 |
|
318 |
static inline void gen_op_mov_reg_T1(int ot, int reg) |
319 |
{ |
320 |
gen_op_mov_reg_v(ot, reg, cpu_T[1]);
|
321 |
} |
322 |
|
323 |
static inline void gen_op_mov_reg_A0(int size, int reg) |
324 |
{ |
325 |
switch(size) {
|
326 |
case OT_BYTE:
|
327 |
tcg_gen_deposit_tl(cpu_regs[reg], cpu_regs[reg], cpu_A0, 0, 16); |
328 |
break;
|
329 |
default: /* XXX this shouldn't be reached; abort? */ |
330 |
case OT_WORD:
|
331 |
/* For x86_64, this sets the higher half of register to zero.
|
332 |
For i386, this is equivalent to a mov. */
|
333 |
tcg_gen_ext32u_tl(cpu_regs[reg], cpu_A0); |
334 |
break;
|
335 |
#ifdef TARGET_X86_64
|
336 |
case OT_LONG:
|
337 |
tcg_gen_mov_tl(cpu_regs[reg], cpu_A0); |
338 |
break;
|
339 |
#endif
|
340 |
} |
341 |
} |
342 |
|
343 |
static inline void gen_op_mov_v_reg(int ot, TCGv t0, int reg) |
344 |
{ |
345 |
if (ot == OT_BYTE && byte_reg_is_xH(reg)) {
|
346 |
tcg_gen_shri_tl(t0, cpu_regs[reg - 4], 8); |
347 |
tcg_gen_ext8u_tl(t0, t0); |
348 |
} else {
|
349 |
tcg_gen_mov_tl(t0, cpu_regs[reg]); |
350 |
} |
351 |
} |
352 |
|
353 |
static inline void gen_op_mov_TN_reg(int ot, int t_index, int reg) |
354 |
{ |
355 |
gen_op_mov_v_reg(ot, cpu_T[t_index], reg); |
356 |
} |
357 |
|
358 |
static inline void gen_op_movl_A0_reg(int reg) |
359 |
{ |
360 |
tcg_gen_mov_tl(cpu_A0, cpu_regs[reg]); |
361 |
} |
362 |
|
363 |
static inline void gen_op_addl_A0_im(int32_t val) |
364 |
{ |
365 |
tcg_gen_addi_tl(cpu_A0, cpu_A0, val); |
366 |
#ifdef TARGET_X86_64
|
367 |
tcg_gen_andi_tl(cpu_A0, cpu_A0, 0xffffffff);
|
368 |
#endif
|
369 |
} |
370 |
|
371 |
#ifdef TARGET_X86_64
|
372 |
static inline void gen_op_addq_A0_im(int64_t val) |
373 |
{ |
374 |
tcg_gen_addi_tl(cpu_A0, cpu_A0, val); |
375 |
} |
376 |
#endif
|
377 |
|
378 |
static void gen_add_A0_im(DisasContext *s, int val) |
379 |
{ |
380 |
#ifdef TARGET_X86_64
|
381 |
if (CODE64(s))
|
382 |
gen_op_addq_A0_im(val); |
383 |
else
|
384 |
#endif
|
385 |
gen_op_addl_A0_im(val); |
386 |
} |
387 |
|
388 |
static inline void gen_op_addl_T0_T1(void) |
389 |
{ |
390 |
tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
391 |
} |
392 |
|
393 |
static inline void gen_op_jmp_T0(void) |
394 |
{ |
395 |
tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUX86State, eip));
|
396 |
} |
397 |
|
398 |
static inline void gen_op_add_reg_im(int size, int reg, int32_t val) |
399 |
{ |
400 |
switch(size) {
|
401 |
case OT_BYTE:
|
402 |
tcg_gen_addi_tl(cpu_tmp0, cpu_regs[reg], val); |
403 |
tcg_gen_deposit_tl(cpu_regs[reg], cpu_regs[reg], cpu_tmp0, 0, 16); |
404 |
break;
|
405 |
case OT_WORD:
|
406 |
tcg_gen_addi_tl(cpu_tmp0, cpu_regs[reg], val); |
407 |
/* For x86_64, this sets the higher half of register to zero.
|
408 |
For i386, this is equivalent to a nop. */
|
409 |
tcg_gen_ext32u_tl(cpu_tmp0, cpu_tmp0); |
410 |
tcg_gen_mov_tl(cpu_regs[reg], cpu_tmp0); |
411 |
break;
|
412 |
#ifdef TARGET_X86_64
|
413 |
case OT_LONG:
|
414 |
tcg_gen_addi_tl(cpu_regs[reg], cpu_regs[reg], val); |
415 |
break;
|
416 |
#endif
|
417 |
} |
418 |
} |
419 |
|
420 |
static inline void gen_op_add_reg_T0(int size, int reg) |
421 |
{ |
422 |
switch(size) {
|
423 |
case OT_BYTE:
|
424 |
tcg_gen_add_tl(cpu_tmp0, cpu_regs[reg], cpu_T[0]);
|
425 |
tcg_gen_deposit_tl(cpu_regs[reg], cpu_regs[reg], cpu_tmp0, 0, 16); |
426 |
break;
|
427 |
case OT_WORD:
|
428 |
tcg_gen_add_tl(cpu_tmp0, cpu_regs[reg], cpu_T[0]);
|
429 |
/* For x86_64, this sets the higher half of register to zero.
|
430 |
For i386, this is equivalent to a nop. */
|
431 |
tcg_gen_ext32u_tl(cpu_tmp0, cpu_tmp0); |
432 |
tcg_gen_mov_tl(cpu_regs[reg], cpu_tmp0); |
433 |
break;
|
434 |
#ifdef TARGET_X86_64
|
435 |
case OT_LONG:
|
436 |
tcg_gen_add_tl(cpu_regs[reg], cpu_regs[reg], cpu_T[0]);
|
437 |
break;
|
438 |
#endif
|
439 |
} |
440 |
} |
441 |
|
442 |
static inline void gen_op_set_cc_op(int32_t val) |
443 |
{ |
444 |
tcg_gen_movi_i32(cpu_cc_op, val); |
445 |
} |
446 |
|
447 |
static inline void gen_op_addl_A0_reg_sN(int shift, int reg) |
448 |
{ |
449 |
tcg_gen_mov_tl(cpu_tmp0, cpu_regs[reg]); |
450 |
if (shift != 0) |
451 |
tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, shift); |
452 |
tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); |
453 |
/* For x86_64, this sets the higher half of register to zero.
|
454 |
For i386, this is equivalent to a nop. */
|
455 |
tcg_gen_ext32u_tl(cpu_A0, cpu_A0); |
456 |
} |
457 |
|
458 |
static inline void gen_op_movl_A0_seg(int reg) |
459 |
{ |
460 |
tcg_gen_ld32u_tl(cpu_A0, cpu_env, offsetof(CPUX86State, segs[reg].base) + REG_L_OFFSET); |
461 |
} |
462 |
|
463 |
static inline void gen_op_addl_A0_seg(DisasContext *s, int reg) |
464 |
{ |
465 |
tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUX86State, segs[reg].base)); |
466 |
#ifdef TARGET_X86_64
|
467 |
if (CODE64(s)) {
|
468 |
tcg_gen_andi_tl(cpu_A0, cpu_A0, 0xffffffff);
|
469 |
tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); |
470 |
} else {
|
471 |
tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); |
472 |
tcg_gen_andi_tl(cpu_A0, cpu_A0, 0xffffffff);
|
473 |
} |
474 |
#else
|
475 |
tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); |
476 |
#endif
|
477 |
} |
478 |
|
479 |
#ifdef TARGET_X86_64
|
480 |
static inline void gen_op_movq_A0_seg(int reg) |
481 |
{ |
482 |
tcg_gen_ld_tl(cpu_A0, cpu_env, offsetof(CPUX86State, segs[reg].base)); |
483 |
} |
484 |
|
485 |
static inline void gen_op_addq_A0_seg(int reg) |
486 |
{ |
487 |
tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUX86State, segs[reg].base)); |
488 |
tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); |
489 |
} |
490 |
|
491 |
static inline void gen_op_movq_A0_reg(int reg) |
492 |
{ |
493 |
tcg_gen_mov_tl(cpu_A0, cpu_regs[reg]); |
494 |
} |
495 |
|
496 |
static inline void gen_op_addq_A0_reg_sN(int shift, int reg) |
497 |
{ |
498 |
tcg_gen_mov_tl(cpu_tmp0, cpu_regs[reg]); |
499 |
if (shift != 0) |
500 |
tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, shift); |
501 |
tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); |
502 |
} |
503 |
#endif
|
504 |
|
505 |
static inline void gen_op_lds_T0_A0(int idx) |
506 |
{ |
507 |
int mem_index = (idx >> 2) - 1; |
508 |
switch(idx & 3) { |
509 |
case OT_BYTE:
|
510 |
tcg_gen_qemu_ld8s(cpu_T[0], cpu_A0, mem_index);
|
511 |
break;
|
512 |
case OT_WORD:
|
513 |
tcg_gen_qemu_ld16s(cpu_T[0], cpu_A0, mem_index);
|
514 |
break;
|
515 |
default:
|
516 |
case OT_LONG:
|
517 |
tcg_gen_qemu_ld32s(cpu_T[0], cpu_A0, mem_index);
|
518 |
break;
|
519 |
} |
520 |
} |
521 |
|
522 |
static inline void gen_op_ld_v(int idx, TCGv t0, TCGv a0) |
523 |
{ |
524 |
int mem_index = (idx >> 2) - 1; |
525 |
switch(idx & 3) { |
526 |
case OT_BYTE:
|
527 |
tcg_gen_qemu_ld8u(t0, a0, mem_index); |
528 |
break;
|
529 |
case OT_WORD:
|
530 |
tcg_gen_qemu_ld16u(t0, a0, mem_index); |
531 |
break;
|
532 |
case OT_LONG:
|
533 |
tcg_gen_qemu_ld32u(t0, a0, mem_index); |
534 |
break;
|
535 |
default:
|
536 |
case OT_QUAD:
|
537 |
/* Should never happen on 32-bit targets. */
|
538 |
#ifdef TARGET_X86_64
|
539 |
tcg_gen_qemu_ld64(t0, a0, mem_index); |
540 |
#endif
|
541 |
break;
|
542 |
} |
543 |
} |
544 |
|
545 |
/* XXX: always use ldu or lds */
|
546 |
static inline void gen_op_ld_T0_A0(int idx) |
547 |
{ |
548 |
gen_op_ld_v(idx, cpu_T[0], cpu_A0);
|
549 |
} |
550 |
|
551 |
static inline void gen_op_ldu_T0_A0(int idx) |
552 |
{ |
553 |
gen_op_ld_v(idx, cpu_T[0], cpu_A0);
|
554 |
} |
555 |
|
556 |
static inline void gen_op_ld_T1_A0(int idx) |
557 |
{ |
558 |
gen_op_ld_v(idx, cpu_T[1], cpu_A0);
|
559 |
} |
560 |
|
561 |
static inline void gen_op_st_v(int idx, TCGv t0, TCGv a0) |
562 |
{ |
563 |
int mem_index = (idx >> 2) - 1; |
564 |
switch(idx & 3) { |
565 |
case OT_BYTE:
|
566 |
tcg_gen_qemu_st8(t0, a0, mem_index); |
567 |
break;
|
568 |
case OT_WORD:
|
569 |
tcg_gen_qemu_st16(t0, a0, mem_index); |
570 |
break;
|
571 |
case OT_LONG:
|
572 |
tcg_gen_qemu_st32(t0, a0, mem_index); |
573 |
break;
|
574 |
default:
|
575 |
case OT_QUAD:
|
576 |
/* Should never happen on 32-bit targets. */
|
577 |
#ifdef TARGET_X86_64
|
578 |
tcg_gen_qemu_st64(t0, a0, mem_index); |
579 |
#endif
|
580 |
break;
|
581 |
} |
582 |
} |
583 |
|
584 |
static inline void gen_op_st_T0_A0(int idx) |
585 |
{ |
586 |
gen_op_st_v(idx, cpu_T[0], cpu_A0);
|
587 |
} |
588 |
|
589 |
static inline void gen_op_st_T1_A0(int idx) |
590 |
{ |
591 |
gen_op_st_v(idx, cpu_T[1], cpu_A0);
|
592 |
} |
593 |
|
594 |
static inline void gen_jmp_im(target_ulong pc) |
595 |
{ |
596 |
tcg_gen_movi_tl(cpu_tmp0, pc); |
597 |
tcg_gen_st_tl(cpu_tmp0, cpu_env, offsetof(CPUX86State, eip)); |
598 |
} |
599 |
|
600 |
static inline void gen_string_movl_A0_ESI(DisasContext *s) |
601 |
{ |
602 |
int override;
|
603 |
|
604 |
override = s->override; |
605 |
#ifdef TARGET_X86_64
|
606 |
if (s->aflag == 2) { |
607 |
if (override >= 0) { |
608 |
gen_op_movq_A0_seg(override); |
609 |
gen_op_addq_A0_reg_sN(0, R_ESI);
|
610 |
} else {
|
611 |
gen_op_movq_A0_reg(R_ESI); |
612 |
} |
613 |
} else
|
614 |
#endif
|
615 |
if (s->aflag) {
|
616 |
/* 32 bit address */
|
617 |
if (s->addseg && override < 0) |
618 |
override = R_DS; |
619 |
if (override >= 0) { |
620 |
gen_op_movl_A0_seg(override); |
621 |
gen_op_addl_A0_reg_sN(0, R_ESI);
|
622 |
} else {
|
623 |
gen_op_movl_A0_reg(R_ESI); |
624 |
} |
625 |
} else {
|
626 |
/* 16 address, always override */
|
627 |
if (override < 0) |
628 |
override = R_DS; |
629 |
gen_op_movl_A0_reg(R_ESI); |
630 |
gen_op_andl_A0_ffff(); |
631 |
gen_op_addl_A0_seg(s, override); |
632 |
} |
633 |
} |
634 |
|
635 |
static inline void gen_string_movl_A0_EDI(DisasContext *s) |
636 |
{ |
637 |
#ifdef TARGET_X86_64
|
638 |
if (s->aflag == 2) { |
639 |
gen_op_movq_A0_reg(R_EDI); |
640 |
} else
|
641 |
#endif
|
642 |
if (s->aflag) {
|
643 |
if (s->addseg) {
|
644 |
gen_op_movl_A0_seg(R_ES); |
645 |
gen_op_addl_A0_reg_sN(0, R_EDI);
|
646 |
} else {
|
647 |
gen_op_movl_A0_reg(R_EDI); |
648 |
} |
649 |
} else {
|
650 |
gen_op_movl_A0_reg(R_EDI); |
651 |
gen_op_andl_A0_ffff(); |
652 |
gen_op_addl_A0_seg(s, R_ES); |
653 |
} |
654 |
} |
655 |
|
656 |
static inline void gen_op_movl_T0_Dshift(int ot) |
657 |
{ |
658 |
tcg_gen_ld32s_tl(cpu_T[0], cpu_env, offsetof(CPUX86State, df));
|
659 |
tcg_gen_shli_tl(cpu_T[0], cpu_T[0], ot); |
660 |
}; |
661 |
|
662 |
static TCGv gen_ext_tl(TCGv dst, TCGv src, int size, bool sign) |
663 |
{ |
664 |
switch (size) {
|
665 |
case OT_BYTE:
|
666 |
if (sign) {
|
667 |
tcg_gen_ext8s_tl(dst, src); |
668 |
} else {
|
669 |
tcg_gen_ext8u_tl(dst, src); |
670 |
} |
671 |
return dst;
|
672 |
case OT_WORD:
|
673 |
if (sign) {
|
674 |
tcg_gen_ext16s_tl(dst, src); |
675 |
} else {
|
676 |
tcg_gen_ext16u_tl(dst, src); |
677 |
} |
678 |
return dst;
|
679 |
#ifdef TARGET_X86_64
|
680 |
case OT_LONG:
|
681 |
if (sign) {
|
682 |
tcg_gen_ext32s_tl(dst, src); |
683 |
} else {
|
684 |
tcg_gen_ext32u_tl(dst, src); |
685 |
} |
686 |
return dst;
|
687 |
#endif
|
688 |
default:
|
689 |
return src;
|
690 |
} |
691 |
} |
692 |
|
693 |
static void gen_extu(int ot, TCGv reg) |
694 |
{ |
695 |
gen_ext_tl(reg, reg, ot, false);
|
696 |
} |
697 |
|
698 |
static void gen_exts(int ot, TCGv reg) |
699 |
{ |
700 |
gen_ext_tl(reg, reg, ot, true);
|
701 |
} |
702 |
|
703 |
static inline void gen_op_jnz_ecx(int size, int label1) |
704 |
{ |
705 |
tcg_gen_mov_tl(cpu_tmp0, cpu_regs[R_ECX]); |
706 |
gen_extu(size + 1, cpu_tmp0);
|
707 |
tcg_gen_brcondi_tl(TCG_COND_NE, cpu_tmp0, 0, label1);
|
708 |
} |
709 |
|
710 |
static inline void gen_op_jz_ecx(int size, int label1) |
711 |
{ |
712 |
tcg_gen_mov_tl(cpu_tmp0, cpu_regs[R_ECX]); |
713 |
gen_extu(size + 1, cpu_tmp0);
|
714 |
tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, label1);
|
715 |
} |
716 |
|
717 |
static void gen_helper_in_func(int ot, TCGv v, TCGv_i32 n) |
718 |
{ |
719 |
switch (ot) {
|
720 |
case OT_BYTE:
|
721 |
gen_helper_inb(v, n); |
722 |
break;
|
723 |
case OT_WORD:
|
724 |
gen_helper_inw(v, n); |
725 |
break;
|
726 |
case OT_LONG:
|
727 |
gen_helper_inl(v, n); |
728 |
break;
|
729 |
} |
730 |
} |
731 |
|
732 |
static void gen_helper_out_func(int ot, TCGv_i32 v, TCGv_i32 n) |
733 |
{ |
734 |
switch (ot) {
|
735 |
case OT_BYTE:
|
736 |
gen_helper_outb(v, n); |
737 |
break;
|
738 |
case OT_WORD:
|
739 |
gen_helper_outw(v, n); |
740 |
break;
|
741 |
case OT_LONG:
|
742 |
gen_helper_outl(v, n); |
743 |
break;
|
744 |
} |
745 |
} |
746 |
|
747 |
static void gen_check_io(DisasContext *s, int ot, target_ulong cur_eip, |
748 |
uint32_t svm_flags) |
749 |
{ |
750 |
int state_saved;
|
751 |
target_ulong next_eip; |
752 |
|
753 |
state_saved = 0;
|
754 |
if (s->pe && (s->cpl > s->iopl || s->vm86)) {
|
755 |
if (s->cc_op != CC_OP_DYNAMIC)
|
756 |
gen_op_set_cc_op(s->cc_op); |
757 |
gen_jmp_im(cur_eip); |
758 |
state_saved = 1;
|
759 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
760 |
switch (ot) {
|
761 |
case OT_BYTE:
|
762 |
gen_helper_check_iob(cpu_env, cpu_tmp2_i32); |
763 |
break;
|
764 |
case OT_WORD:
|
765 |
gen_helper_check_iow(cpu_env, cpu_tmp2_i32); |
766 |
break;
|
767 |
case OT_LONG:
|
768 |
gen_helper_check_iol(cpu_env, cpu_tmp2_i32); |
769 |
break;
|
770 |
} |
771 |
} |
772 |
if(s->flags & HF_SVMI_MASK) {
|
773 |
if (!state_saved) {
|
774 |
if (s->cc_op != CC_OP_DYNAMIC)
|
775 |
gen_op_set_cc_op(s->cc_op); |
776 |
gen_jmp_im(cur_eip); |
777 |
} |
778 |
svm_flags |= (1 << (4 + ot)); |
779 |
next_eip = s->pc - s->cs_base; |
780 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
781 |
gen_helper_svm_check_io(cpu_env, cpu_tmp2_i32, |
782 |
tcg_const_i32(svm_flags), |
783 |
tcg_const_i32(next_eip - cur_eip)); |
784 |
} |
785 |
} |
786 |
|
787 |
static inline void gen_movs(DisasContext *s, int ot) |
788 |
{ |
789 |
gen_string_movl_A0_ESI(s); |
790 |
gen_op_ld_T0_A0(ot + s->mem_index); |
791 |
gen_string_movl_A0_EDI(s); |
792 |
gen_op_st_T0_A0(ot + s->mem_index); |
793 |
gen_op_movl_T0_Dshift(ot); |
794 |
gen_op_add_reg_T0(s->aflag, R_ESI); |
795 |
gen_op_add_reg_T0(s->aflag, R_EDI); |
796 |
} |
797 |
|
798 |
static inline void gen_update_cc_op(DisasContext *s) |
799 |
{ |
800 |
if (s->cc_op != CC_OP_DYNAMIC) {
|
801 |
gen_op_set_cc_op(s->cc_op); |
802 |
s->cc_op = CC_OP_DYNAMIC; |
803 |
} |
804 |
} |
805 |
|
806 |
static void gen_op_update1_cc(void) |
807 |
{ |
808 |
tcg_gen_discard_tl(cpu_cc_src); |
809 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
810 |
} |
811 |
|
812 |
static void gen_op_update2_cc(void) |
813 |
{ |
814 |
tcg_gen_mov_tl(cpu_cc_src, cpu_T[1]);
|
815 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
816 |
} |
817 |
|
818 |
static inline void gen_op_cmpl_T0_T1_cc(void) |
819 |
{ |
820 |
tcg_gen_mov_tl(cpu_cc_src, cpu_T[1]);
|
821 |
tcg_gen_sub_tl(cpu_cc_dst, cpu_T[0], cpu_T[1]); |
822 |
} |
823 |
|
824 |
static inline void gen_op_testl_T0_T1_cc(void) |
825 |
{ |
826 |
tcg_gen_discard_tl(cpu_cc_src); |
827 |
tcg_gen_and_tl(cpu_cc_dst, cpu_T[0], cpu_T[1]); |
828 |
} |
829 |
|
830 |
static void gen_op_update_neg_cc(void) |
831 |
{ |
832 |
tcg_gen_neg_tl(cpu_cc_src, cpu_T[0]);
|
833 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
834 |
} |
835 |
|
836 |
/* compute eflags.C to reg */
|
837 |
static void gen_compute_eflags_c(TCGv reg) |
838 |
{ |
839 |
gen_helper_cc_compute_c(cpu_tmp2_i32, cpu_env, cpu_cc_op); |
840 |
tcg_gen_extu_i32_tl(reg, cpu_tmp2_i32); |
841 |
} |
842 |
|
843 |
/* compute all eflags to cc_src */
|
844 |
static void gen_compute_eflags(TCGv reg) |
845 |
{ |
846 |
gen_helper_cc_compute_all(cpu_tmp2_i32, cpu_env, cpu_cc_op); |
847 |
tcg_gen_extu_i32_tl(reg, cpu_tmp2_i32); |
848 |
} |
849 |
|
850 |
static inline void gen_setcc_slow_T0(DisasContext *s, int jcc_op) |
851 |
{ |
852 |
if (s->cc_op != CC_OP_DYNAMIC)
|
853 |
gen_op_set_cc_op(s->cc_op); |
854 |
switch(jcc_op) {
|
855 |
case JCC_O:
|
856 |
gen_compute_eflags(cpu_T[0]);
|
857 |
tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 11); |
858 |
tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
859 |
break;
|
860 |
case JCC_B:
|
861 |
gen_compute_eflags_c(cpu_T[0]);
|
862 |
break;
|
863 |
case JCC_Z:
|
864 |
gen_compute_eflags(cpu_T[0]);
|
865 |
tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 6); |
866 |
tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
867 |
break;
|
868 |
case JCC_BE:
|
869 |
gen_compute_eflags(cpu_tmp0); |
870 |
tcg_gen_shri_tl(cpu_T[0], cpu_tmp0, 6); |
871 |
tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_tmp0); |
872 |
tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
873 |
break;
|
874 |
case JCC_S:
|
875 |
gen_compute_eflags(cpu_T[0]);
|
876 |
tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 7); |
877 |
tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
878 |
break;
|
879 |
case JCC_P:
|
880 |
gen_compute_eflags(cpu_T[0]);
|
881 |
tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 2); |
882 |
tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
883 |
break;
|
884 |
case JCC_L:
|
885 |
gen_compute_eflags(cpu_tmp0); |
886 |
tcg_gen_shri_tl(cpu_T[0], cpu_tmp0, 11); /* CC_O */ |
887 |
tcg_gen_shri_tl(cpu_tmp0, cpu_tmp0, 7); /* CC_S */ |
888 |
tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_tmp0); |
889 |
tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
890 |
break;
|
891 |
default:
|
892 |
case JCC_LE:
|
893 |
gen_compute_eflags(cpu_tmp0); |
894 |
tcg_gen_shri_tl(cpu_T[0], cpu_tmp0, 11); /* CC_O */ |
895 |
tcg_gen_shri_tl(cpu_tmp4, cpu_tmp0, 7); /* CC_S */ |
896 |
tcg_gen_shri_tl(cpu_tmp0, cpu_tmp0, 6); /* CC_Z */ |
897 |
tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_tmp4); |
898 |
tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_tmp0); |
899 |
tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
900 |
break;
|
901 |
} |
902 |
} |
903 |
|
904 |
/* return true if setcc_slow is not needed (WARNING: must be kept in
|
905 |
sync with gen_jcc1) */
|
906 |
static int is_fast_jcc_case(DisasContext *s, int b) |
907 |
{ |
908 |
int jcc_op;
|
909 |
jcc_op = (b >> 1) & 7; |
910 |
switch(s->cc_op) {
|
911 |
/* we optimize the cmp/jcc case */
|
912 |
case CC_OP_SUBB:
|
913 |
case CC_OP_SUBW:
|
914 |
case CC_OP_SUBL:
|
915 |
case CC_OP_SUBQ:
|
916 |
if (jcc_op == JCC_O || jcc_op == JCC_P)
|
917 |
goto slow_jcc;
|
918 |
break;
|
919 |
|
920 |
/* some jumps are easy to compute */
|
921 |
case CC_OP_ADDB:
|
922 |
case CC_OP_ADDW:
|
923 |
case CC_OP_ADDL:
|
924 |
case CC_OP_ADDQ:
|
925 |
|
926 |
case CC_OP_LOGICB:
|
927 |
case CC_OP_LOGICW:
|
928 |
case CC_OP_LOGICL:
|
929 |
case CC_OP_LOGICQ:
|
930 |
|
931 |
case CC_OP_INCB:
|
932 |
case CC_OP_INCW:
|
933 |
case CC_OP_INCL:
|
934 |
case CC_OP_INCQ:
|
935 |
|
936 |
case CC_OP_DECB:
|
937 |
case CC_OP_DECW:
|
938 |
case CC_OP_DECL:
|
939 |
case CC_OP_DECQ:
|
940 |
|
941 |
case CC_OP_SHLB:
|
942 |
case CC_OP_SHLW:
|
943 |
case CC_OP_SHLL:
|
944 |
case CC_OP_SHLQ:
|
945 |
if (jcc_op != JCC_Z && jcc_op != JCC_S)
|
946 |
goto slow_jcc;
|
947 |
break;
|
948 |
default:
|
949 |
slow_jcc:
|
950 |
return 0; |
951 |
} |
952 |
return 1; |
953 |
} |
954 |
|
955 |
/* generate a conditional jump to label 'l1' according to jump opcode
|
956 |
value 'b'. In the fast case, T0 is guaranted not to be used. */
|
957 |
static inline void gen_jcc1(DisasContext *s, int b, int l1) |
958 |
{ |
959 |
int inv, jcc_op, size, cond;
|
960 |
TCGv t0; |
961 |
|
962 |
inv = b & 1;
|
963 |
jcc_op = (b >> 1) & 7; |
964 |
|
965 |
switch (s->cc_op) {
|
966 |
/* we optimize the cmp/jcc case */
|
967 |
case CC_OP_SUBB:
|
968 |
case CC_OP_SUBW:
|
969 |
case CC_OP_SUBL:
|
970 |
case CC_OP_SUBQ:
|
971 |
|
972 |
size = s->cc_op - CC_OP_SUBB; |
973 |
switch(jcc_op) {
|
974 |
case JCC_Z:
|
975 |
fast_jcc_z:
|
976 |
t0 = gen_ext_tl(cpu_tmp0, cpu_cc_dst, size, false);
|
977 |
tcg_gen_brcondi_tl(inv ? TCG_COND_NE : TCG_COND_EQ, t0, 0, l1);
|
978 |
break;
|
979 |
case JCC_S:
|
980 |
fast_jcc_s:
|
981 |
t0 = gen_ext_tl(cpu_tmp0, cpu_cc_dst, size, true);
|
982 |
tcg_gen_brcondi_tl(inv ? TCG_COND_GE : TCG_COND_LT, t0, 0, l1);
|
983 |
break;
|
984 |
|
985 |
case JCC_B:
|
986 |
cond = inv ? TCG_COND_GEU : TCG_COND_LTU; |
987 |
goto fast_jcc_b;
|
988 |
case JCC_BE:
|
989 |
cond = inv ? TCG_COND_GTU : TCG_COND_LEU; |
990 |
fast_jcc_b:
|
991 |
tcg_gen_add_tl(cpu_tmp4, cpu_cc_dst, cpu_cc_src); |
992 |
gen_extu(size, cpu_tmp4); |
993 |
t0 = gen_ext_tl(cpu_tmp0, cpu_cc_src, size, false);
|
994 |
tcg_gen_brcond_tl(cond, cpu_tmp4, t0, l1); |
995 |
break;
|
996 |
|
997 |
case JCC_L:
|
998 |
cond = inv ? TCG_COND_GE : TCG_COND_LT; |
999 |
goto fast_jcc_l;
|
1000 |
case JCC_LE:
|
1001 |
cond = inv ? TCG_COND_GT : TCG_COND_LE; |
1002 |
fast_jcc_l:
|
1003 |
tcg_gen_add_tl(cpu_tmp4, cpu_cc_dst, cpu_cc_src); |
1004 |
gen_exts(size, cpu_tmp4); |
1005 |
t0 = gen_ext_tl(cpu_tmp0, cpu_cc_src, size, true);
|
1006 |
tcg_gen_brcond_tl(cond, cpu_tmp4, t0, l1); |
1007 |
break;
|
1008 |
|
1009 |
default:
|
1010 |
goto slow_jcc;
|
1011 |
} |
1012 |
break;
|
1013 |
|
1014 |
/* some jumps are easy to compute */
|
1015 |
case CC_OP_ADDB:
|
1016 |
case CC_OP_ADDW:
|
1017 |
case CC_OP_ADDL:
|
1018 |
case CC_OP_ADDQ:
|
1019 |
|
1020 |
case CC_OP_ADCB:
|
1021 |
case CC_OP_ADCW:
|
1022 |
case CC_OP_ADCL:
|
1023 |
case CC_OP_ADCQ:
|
1024 |
|
1025 |
case CC_OP_SBBB:
|
1026 |
case CC_OP_SBBW:
|
1027 |
case CC_OP_SBBL:
|
1028 |
case CC_OP_SBBQ:
|
1029 |
|
1030 |
case CC_OP_LOGICB:
|
1031 |
case CC_OP_LOGICW:
|
1032 |
case CC_OP_LOGICL:
|
1033 |
case CC_OP_LOGICQ:
|
1034 |
|
1035 |
case CC_OP_INCB:
|
1036 |
case CC_OP_INCW:
|
1037 |
case CC_OP_INCL:
|
1038 |
case CC_OP_INCQ:
|
1039 |
|
1040 |
case CC_OP_DECB:
|
1041 |
case CC_OP_DECW:
|
1042 |
case CC_OP_DECL:
|
1043 |
case CC_OP_DECQ:
|
1044 |
|
1045 |
case CC_OP_SHLB:
|
1046 |
case CC_OP_SHLW:
|
1047 |
case CC_OP_SHLL:
|
1048 |
case CC_OP_SHLQ:
|
1049 |
|
1050 |
case CC_OP_SARB:
|
1051 |
case CC_OP_SARW:
|
1052 |
case CC_OP_SARL:
|
1053 |
case CC_OP_SARQ:
|
1054 |
switch(jcc_op) {
|
1055 |
case JCC_Z:
|
1056 |
size = (s->cc_op - CC_OP_ADDB) & 3;
|
1057 |
goto fast_jcc_z;
|
1058 |
case JCC_S:
|
1059 |
size = (s->cc_op - CC_OP_ADDB) & 3;
|
1060 |
goto fast_jcc_s;
|
1061 |
default:
|
1062 |
goto slow_jcc;
|
1063 |
} |
1064 |
break;
|
1065 |
default:
|
1066 |
slow_jcc:
|
1067 |
gen_setcc_slow_T0(s, jcc_op); |
1068 |
tcg_gen_brcondi_tl(inv ? TCG_COND_EQ : TCG_COND_NE, |
1069 |
cpu_T[0], 0, l1); |
1070 |
break;
|
1071 |
} |
1072 |
} |
1073 |
|
1074 |
/* XXX: does not work with gdbstub "ice" single step - not a
|
1075 |
serious problem */
|
1076 |
static int gen_jz_ecx_string(DisasContext *s, target_ulong next_eip) |
1077 |
{ |
1078 |
int l1, l2;
|
1079 |
|
1080 |
l1 = gen_new_label(); |
1081 |
l2 = gen_new_label(); |
1082 |
gen_op_jnz_ecx(s->aflag, l1); |
1083 |
gen_set_label(l2); |
1084 |
gen_jmp_tb(s, next_eip, 1);
|
1085 |
gen_set_label(l1); |
1086 |
return l2;
|
1087 |
} |
1088 |
|
1089 |
static inline void gen_stos(DisasContext *s, int ot) |
1090 |
{ |
1091 |
gen_op_mov_TN_reg(OT_LONG, 0, R_EAX);
|
1092 |
gen_string_movl_A0_EDI(s); |
1093 |
gen_op_st_T0_A0(ot + s->mem_index); |
1094 |
gen_op_movl_T0_Dshift(ot); |
1095 |
gen_op_add_reg_T0(s->aflag, R_EDI); |
1096 |
} |
1097 |
|
1098 |
static inline void gen_lods(DisasContext *s, int ot) |
1099 |
{ |
1100 |
gen_string_movl_A0_ESI(s); |
1101 |
gen_op_ld_T0_A0(ot + s->mem_index); |
1102 |
gen_op_mov_reg_T0(ot, R_EAX); |
1103 |
gen_op_movl_T0_Dshift(ot); |
1104 |
gen_op_add_reg_T0(s->aflag, R_ESI); |
1105 |
} |
1106 |
|
1107 |
static inline void gen_scas(DisasContext *s, int ot) |
1108 |
{ |
1109 |
gen_op_mov_TN_reg(OT_LONG, 0, R_EAX);
|
1110 |
gen_string_movl_A0_EDI(s); |
1111 |
gen_op_ld_T1_A0(ot + s->mem_index); |
1112 |
gen_op_cmpl_T0_T1_cc(); |
1113 |
gen_op_movl_T0_Dshift(ot); |
1114 |
gen_op_add_reg_T0(s->aflag, R_EDI); |
1115 |
s->cc_op = CC_OP_SUBB + ot; |
1116 |
} |
1117 |
|
1118 |
static inline void gen_cmps(DisasContext *s, int ot) |
1119 |
{ |
1120 |
gen_string_movl_A0_ESI(s); |
1121 |
gen_op_ld_T0_A0(ot + s->mem_index); |
1122 |
gen_string_movl_A0_EDI(s); |
1123 |
gen_op_ld_T1_A0(ot + s->mem_index); |
1124 |
gen_op_cmpl_T0_T1_cc(); |
1125 |
gen_op_movl_T0_Dshift(ot); |
1126 |
gen_op_add_reg_T0(s->aflag, R_ESI); |
1127 |
gen_op_add_reg_T0(s->aflag, R_EDI); |
1128 |
s->cc_op = CC_OP_SUBB + ot; |
1129 |
} |
1130 |
|
1131 |
static inline void gen_ins(DisasContext *s, int ot) |
1132 |
{ |
1133 |
if (use_icount)
|
1134 |
gen_io_start(); |
1135 |
gen_string_movl_A0_EDI(s); |
1136 |
/* Note: we must do this dummy write first to be restartable in
|
1137 |
case of page fault. */
|
1138 |
gen_op_movl_T0_0(); |
1139 |
gen_op_st_T0_A0(ot + s->mem_index); |
1140 |
gen_op_mov_TN_reg(OT_WORD, 1, R_EDX);
|
1141 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[1]);
|
1142 |
tcg_gen_andi_i32(cpu_tmp2_i32, cpu_tmp2_i32, 0xffff);
|
1143 |
gen_helper_in_func(ot, cpu_T[0], cpu_tmp2_i32);
|
1144 |
gen_op_st_T0_A0(ot + s->mem_index); |
1145 |
gen_op_movl_T0_Dshift(ot); |
1146 |
gen_op_add_reg_T0(s->aflag, R_EDI); |
1147 |
if (use_icount)
|
1148 |
gen_io_end(); |
1149 |
} |
1150 |
|
1151 |
static inline void gen_outs(DisasContext *s, int ot) |
1152 |
{ |
1153 |
if (use_icount)
|
1154 |
gen_io_start(); |
1155 |
gen_string_movl_A0_ESI(s); |
1156 |
gen_op_ld_T0_A0(ot + s->mem_index); |
1157 |
|
1158 |
gen_op_mov_TN_reg(OT_WORD, 1, R_EDX);
|
1159 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[1]);
|
1160 |
tcg_gen_andi_i32(cpu_tmp2_i32, cpu_tmp2_i32, 0xffff);
|
1161 |
tcg_gen_trunc_tl_i32(cpu_tmp3_i32, cpu_T[0]);
|
1162 |
gen_helper_out_func(ot, cpu_tmp2_i32, cpu_tmp3_i32); |
1163 |
|
1164 |
gen_op_movl_T0_Dshift(ot); |
1165 |
gen_op_add_reg_T0(s->aflag, R_ESI); |
1166 |
if (use_icount)
|
1167 |
gen_io_end(); |
1168 |
} |
1169 |
|
1170 |
/* same method as Valgrind : we generate jumps to current or next
|
1171 |
instruction */
|
1172 |
#define GEN_REPZ(op) \
|
1173 |
static inline void gen_repz_ ## op(DisasContext *s, int ot, \ |
1174 |
target_ulong cur_eip, target_ulong next_eip) \ |
1175 |
{ \ |
1176 |
int l2;\
|
1177 |
gen_update_cc_op(s); \ |
1178 |
l2 = gen_jz_ecx_string(s, next_eip); \ |
1179 |
gen_ ## op(s, ot); \ |
1180 |
gen_op_add_reg_im(s->aflag, R_ECX, -1); \
|
1181 |
/* a loop would cause two single step exceptions if ECX = 1 \
|
1182 |
before rep string_insn */ \
|
1183 |
if (!s->jmp_opt) \
|
1184 |
gen_op_jz_ecx(s->aflag, l2); \ |
1185 |
gen_jmp(s, cur_eip); \ |
1186 |
} |
1187 |
|
1188 |
#define GEN_REPZ2(op) \
|
1189 |
static inline void gen_repz_ ## op(DisasContext *s, int ot, \ |
1190 |
target_ulong cur_eip, \ |
1191 |
target_ulong next_eip, \ |
1192 |
int nz) \
|
1193 |
{ \ |
1194 |
int l2;\
|
1195 |
gen_update_cc_op(s); \ |
1196 |
l2 = gen_jz_ecx_string(s, next_eip); \ |
1197 |
gen_ ## op(s, ot); \ |
1198 |
gen_op_add_reg_im(s->aflag, R_ECX, -1); \
|
1199 |
gen_op_set_cc_op(s->cc_op); \ |
1200 |
gen_jcc1(s, (JCC_Z << 1) | (nz ^ 1), l2); \ |
1201 |
if (!s->jmp_opt) \
|
1202 |
gen_op_jz_ecx(s->aflag, l2); \ |
1203 |
gen_jmp(s, cur_eip); \ |
1204 |
s->cc_op = CC_OP_DYNAMIC; \ |
1205 |
} |
1206 |
|
1207 |
GEN_REPZ(movs) |
1208 |
GEN_REPZ(stos) |
1209 |
GEN_REPZ(lods) |
1210 |
GEN_REPZ(ins) |
1211 |
GEN_REPZ(outs) |
1212 |
GEN_REPZ2(scas) |
1213 |
GEN_REPZ2(cmps) |
1214 |
|
1215 |
static void gen_helper_fp_arith_ST0_FT0(int op) |
1216 |
{ |
1217 |
switch (op) {
|
1218 |
case 0: |
1219 |
gen_helper_fadd_ST0_FT0(cpu_env); |
1220 |
break;
|
1221 |
case 1: |
1222 |
gen_helper_fmul_ST0_FT0(cpu_env); |
1223 |
break;
|
1224 |
case 2: |
1225 |
gen_helper_fcom_ST0_FT0(cpu_env); |
1226 |
break;
|
1227 |
case 3: |
1228 |
gen_helper_fcom_ST0_FT0(cpu_env); |
1229 |
break;
|
1230 |
case 4: |
1231 |
gen_helper_fsub_ST0_FT0(cpu_env); |
1232 |
break;
|
1233 |
case 5: |
1234 |
gen_helper_fsubr_ST0_FT0(cpu_env); |
1235 |
break;
|
1236 |
case 6: |
1237 |
gen_helper_fdiv_ST0_FT0(cpu_env); |
1238 |
break;
|
1239 |
case 7: |
1240 |
gen_helper_fdivr_ST0_FT0(cpu_env); |
1241 |
break;
|
1242 |
} |
1243 |
} |
1244 |
|
1245 |
/* NOTE the exception in "r" op ordering */
|
1246 |
static void gen_helper_fp_arith_STN_ST0(int op, int opreg) |
1247 |
{ |
1248 |
TCGv_i32 tmp = tcg_const_i32(opreg); |
1249 |
switch (op) {
|
1250 |
case 0: |
1251 |
gen_helper_fadd_STN_ST0(cpu_env, tmp); |
1252 |
break;
|
1253 |
case 1: |
1254 |
gen_helper_fmul_STN_ST0(cpu_env, tmp); |
1255 |
break;
|
1256 |
case 4: |
1257 |
gen_helper_fsubr_STN_ST0(cpu_env, tmp); |
1258 |
break;
|
1259 |
case 5: |
1260 |
gen_helper_fsub_STN_ST0(cpu_env, tmp); |
1261 |
break;
|
1262 |
case 6: |
1263 |
gen_helper_fdivr_STN_ST0(cpu_env, tmp); |
1264 |
break;
|
1265 |
case 7: |
1266 |
gen_helper_fdiv_STN_ST0(cpu_env, tmp); |
1267 |
break;
|
1268 |
} |
1269 |
} |
1270 |
|
1271 |
/* if d == OR_TMP0, it means memory operand (address in A0) */
|
1272 |
static void gen_op(DisasContext *s1, int op, int ot, int d) |
1273 |
{ |
1274 |
if (d != OR_TMP0) {
|
1275 |
gen_op_mov_TN_reg(ot, 0, d);
|
1276 |
} else {
|
1277 |
gen_op_ld_T0_A0(ot + s1->mem_index); |
1278 |
} |
1279 |
switch(op) {
|
1280 |
case OP_ADCL:
|
1281 |
if (s1->cc_op != CC_OP_DYNAMIC)
|
1282 |
gen_op_set_cc_op(s1->cc_op); |
1283 |
gen_compute_eflags_c(cpu_tmp4); |
1284 |
tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1285 |
tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_tmp4); |
1286 |
if (d != OR_TMP0)
|
1287 |
gen_op_mov_reg_T0(ot, d); |
1288 |
else
|
1289 |
gen_op_st_T0_A0(ot + s1->mem_index); |
1290 |
tcg_gen_mov_tl(cpu_cc_src, cpu_T[1]);
|
1291 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
1292 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_tmp4); |
1293 |
tcg_gen_shli_i32(cpu_tmp2_i32, cpu_tmp2_i32, 2);
|
1294 |
tcg_gen_addi_i32(cpu_cc_op, cpu_tmp2_i32, CC_OP_ADDB + ot); |
1295 |
s1->cc_op = CC_OP_DYNAMIC; |
1296 |
break;
|
1297 |
case OP_SBBL:
|
1298 |
if (s1->cc_op != CC_OP_DYNAMIC)
|
1299 |
gen_op_set_cc_op(s1->cc_op); |
1300 |
gen_compute_eflags_c(cpu_tmp4); |
1301 |
tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1302 |
tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_tmp4); |
1303 |
if (d != OR_TMP0)
|
1304 |
gen_op_mov_reg_T0(ot, d); |
1305 |
else
|
1306 |
gen_op_st_T0_A0(ot + s1->mem_index); |
1307 |
tcg_gen_mov_tl(cpu_cc_src, cpu_T[1]);
|
1308 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
1309 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_tmp4); |
1310 |
tcg_gen_shli_i32(cpu_tmp2_i32, cpu_tmp2_i32, 2);
|
1311 |
tcg_gen_addi_i32(cpu_cc_op, cpu_tmp2_i32, CC_OP_SUBB + ot); |
1312 |
s1->cc_op = CC_OP_DYNAMIC; |
1313 |
break;
|
1314 |
case OP_ADDL:
|
1315 |
gen_op_addl_T0_T1(); |
1316 |
if (d != OR_TMP0)
|
1317 |
gen_op_mov_reg_T0(ot, d); |
1318 |
else
|
1319 |
gen_op_st_T0_A0(ot + s1->mem_index); |
1320 |
gen_op_update2_cc(); |
1321 |
s1->cc_op = CC_OP_ADDB + ot; |
1322 |
break;
|
1323 |
case OP_SUBL:
|
1324 |
tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1325 |
if (d != OR_TMP0)
|
1326 |
gen_op_mov_reg_T0(ot, d); |
1327 |
else
|
1328 |
gen_op_st_T0_A0(ot + s1->mem_index); |
1329 |
gen_op_update2_cc(); |
1330 |
s1->cc_op = CC_OP_SUBB + ot; |
1331 |
break;
|
1332 |
default:
|
1333 |
case OP_ANDL:
|
1334 |
tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1335 |
if (d != OR_TMP0)
|
1336 |
gen_op_mov_reg_T0(ot, d); |
1337 |
else
|
1338 |
gen_op_st_T0_A0(ot + s1->mem_index); |
1339 |
gen_op_update1_cc(); |
1340 |
s1->cc_op = CC_OP_LOGICB + ot; |
1341 |
break;
|
1342 |
case OP_ORL:
|
1343 |
tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1344 |
if (d != OR_TMP0)
|
1345 |
gen_op_mov_reg_T0(ot, d); |
1346 |
else
|
1347 |
gen_op_st_T0_A0(ot + s1->mem_index); |
1348 |
gen_op_update1_cc(); |
1349 |
s1->cc_op = CC_OP_LOGICB + ot; |
1350 |
break;
|
1351 |
case OP_XORL:
|
1352 |
tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1353 |
if (d != OR_TMP0)
|
1354 |
gen_op_mov_reg_T0(ot, d); |
1355 |
else
|
1356 |
gen_op_st_T0_A0(ot + s1->mem_index); |
1357 |
gen_op_update1_cc(); |
1358 |
s1->cc_op = CC_OP_LOGICB + ot; |
1359 |
break;
|
1360 |
case OP_CMPL:
|
1361 |
gen_op_cmpl_T0_T1_cc(); |
1362 |
s1->cc_op = CC_OP_SUBB + ot; |
1363 |
break;
|
1364 |
} |
1365 |
} |
1366 |
|
1367 |
/* if d == OR_TMP0, it means memory operand (address in A0) */
|
1368 |
static void gen_inc(DisasContext *s1, int ot, int d, int c) |
1369 |
{ |
1370 |
if (d != OR_TMP0)
|
1371 |
gen_op_mov_TN_reg(ot, 0, d);
|
1372 |
else
|
1373 |
gen_op_ld_T0_A0(ot + s1->mem_index); |
1374 |
if (s1->cc_op != CC_OP_DYNAMIC)
|
1375 |
gen_op_set_cc_op(s1->cc_op); |
1376 |
if (c > 0) { |
1377 |
tcg_gen_addi_tl(cpu_T[0], cpu_T[0], 1); |
1378 |
s1->cc_op = CC_OP_INCB + ot; |
1379 |
} else {
|
1380 |
tcg_gen_addi_tl(cpu_T[0], cpu_T[0], -1); |
1381 |
s1->cc_op = CC_OP_DECB + ot; |
1382 |
} |
1383 |
if (d != OR_TMP0)
|
1384 |
gen_op_mov_reg_T0(ot, d); |
1385 |
else
|
1386 |
gen_op_st_T0_A0(ot + s1->mem_index); |
1387 |
gen_compute_eflags_c(cpu_cc_src); |
1388 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
1389 |
} |
1390 |
|
1391 |
static void gen_shift_rm_T1(DisasContext *s, int ot, int op1, |
1392 |
int is_right, int is_arith) |
1393 |
{ |
1394 |
target_ulong mask; |
1395 |
int shift_label;
|
1396 |
TCGv t0, t1, t2; |
1397 |
|
1398 |
if (ot == OT_QUAD) {
|
1399 |
mask = 0x3f;
|
1400 |
} else {
|
1401 |
mask = 0x1f;
|
1402 |
} |
1403 |
|
1404 |
/* load */
|
1405 |
if (op1 == OR_TMP0) {
|
1406 |
gen_op_ld_T0_A0(ot + s->mem_index); |
1407 |
} else {
|
1408 |
gen_op_mov_TN_reg(ot, 0, op1);
|
1409 |
} |
1410 |
|
1411 |
t0 = tcg_temp_local_new(); |
1412 |
t1 = tcg_temp_local_new(); |
1413 |
t2 = tcg_temp_local_new(); |
1414 |
|
1415 |
tcg_gen_andi_tl(t2, cpu_T[1], mask);
|
1416 |
|
1417 |
if (is_right) {
|
1418 |
if (is_arith) {
|
1419 |
gen_exts(ot, cpu_T[0]);
|
1420 |
tcg_gen_mov_tl(t0, cpu_T[0]);
|
1421 |
tcg_gen_sar_tl(cpu_T[0], cpu_T[0], t2); |
1422 |
} else {
|
1423 |
gen_extu(ot, cpu_T[0]);
|
1424 |
tcg_gen_mov_tl(t0, cpu_T[0]);
|
1425 |
tcg_gen_shr_tl(cpu_T[0], cpu_T[0], t2); |
1426 |
} |
1427 |
} else {
|
1428 |
tcg_gen_mov_tl(t0, cpu_T[0]);
|
1429 |
tcg_gen_shl_tl(cpu_T[0], cpu_T[0], t2); |
1430 |
} |
1431 |
|
1432 |
/* store */
|
1433 |
if (op1 == OR_TMP0) {
|
1434 |
gen_op_st_T0_A0(ot + s->mem_index); |
1435 |
} else {
|
1436 |
gen_op_mov_reg_T0(ot, op1); |
1437 |
} |
1438 |
|
1439 |
/* update eflags if non zero shift */
|
1440 |
if (s->cc_op != CC_OP_DYNAMIC) {
|
1441 |
gen_op_set_cc_op(s->cc_op); |
1442 |
} |
1443 |
|
1444 |
tcg_gen_mov_tl(t1, cpu_T[0]);
|
1445 |
|
1446 |
shift_label = gen_new_label(); |
1447 |
tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, shift_label);
|
1448 |
|
1449 |
tcg_gen_addi_tl(t2, t2, -1);
|
1450 |
tcg_gen_mov_tl(cpu_cc_dst, t1); |
1451 |
|
1452 |
if (is_right) {
|
1453 |
if (is_arith) {
|
1454 |
tcg_gen_sar_tl(cpu_cc_src, t0, t2); |
1455 |
} else {
|
1456 |
tcg_gen_shr_tl(cpu_cc_src, t0, t2); |
1457 |
} |
1458 |
} else {
|
1459 |
tcg_gen_shl_tl(cpu_cc_src, t0, t2); |
1460 |
} |
1461 |
|
1462 |
if (is_right) {
|
1463 |
tcg_gen_movi_i32(cpu_cc_op, CC_OP_SARB + ot); |
1464 |
} else {
|
1465 |
tcg_gen_movi_i32(cpu_cc_op, CC_OP_SHLB + ot); |
1466 |
} |
1467 |
|
1468 |
gen_set_label(shift_label); |
1469 |
s->cc_op = CC_OP_DYNAMIC; /* cannot predict flags after */
|
1470 |
|
1471 |
tcg_temp_free(t0); |
1472 |
tcg_temp_free(t1); |
1473 |
tcg_temp_free(t2); |
1474 |
} |
1475 |
|
1476 |
static void gen_shift_rm_im(DisasContext *s, int ot, int op1, int op2, |
1477 |
int is_right, int is_arith) |
1478 |
{ |
1479 |
int mask;
|
1480 |
|
1481 |
if (ot == OT_QUAD)
|
1482 |
mask = 0x3f;
|
1483 |
else
|
1484 |
mask = 0x1f;
|
1485 |
|
1486 |
/* load */
|
1487 |
if (op1 == OR_TMP0)
|
1488 |
gen_op_ld_T0_A0(ot + s->mem_index); |
1489 |
else
|
1490 |
gen_op_mov_TN_reg(ot, 0, op1);
|
1491 |
|
1492 |
op2 &= mask; |
1493 |
if (op2 != 0) { |
1494 |
if (is_right) {
|
1495 |
if (is_arith) {
|
1496 |
gen_exts(ot, cpu_T[0]);
|
1497 |
tcg_gen_sari_tl(cpu_tmp4, cpu_T[0], op2 - 1); |
1498 |
tcg_gen_sari_tl(cpu_T[0], cpu_T[0], op2); |
1499 |
} else {
|
1500 |
gen_extu(ot, cpu_T[0]);
|
1501 |
tcg_gen_shri_tl(cpu_tmp4, cpu_T[0], op2 - 1); |
1502 |
tcg_gen_shri_tl(cpu_T[0], cpu_T[0], op2); |
1503 |
} |
1504 |
} else {
|
1505 |
tcg_gen_shli_tl(cpu_tmp4, cpu_T[0], op2 - 1); |
1506 |
tcg_gen_shli_tl(cpu_T[0], cpu_T[0], op2); |
1507 |
} |
1508 |
} |
1509 |
|
1510 |
/* store */
|
1511 |
if (op1 == OR_TMP0)
|
1512 |
gen_op_st_T0_A0(ot + s->mem_index); |
1513 |
else
|
1514 |
gen_op_mov_reg_T0(ot, op1); |
1515 |
|
1516 |
/* update eflags if non zero shift */
|
1517 |
if (op2 != 0) { |
1518 |
tcg_gen_mov_tl(cpu_cc_src, cpu_tmp4); |
1519 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
1520 |
if (is_right)
|
1521 |
s->cc_op = CC_OP_SARB + ot; |
1522 |
else
|
1523 |
s->cc_op = CC_OP_SHLB + ot; |
1524 |
} |
1525 |
} |
1526 |
|
1527 |
static inline void tcg_gen_lshift(TCGv ret, TCGv arg1, target_long arg2) |
1528 |
{ |
1529 |
if (arg2 >= 0) |
1530 |
tcg_gen_shli_tl(ret, arg1, arg2); |
1531 |
else
|
1532 |
tcg_gen_shri_tl(ret, arg1, -arg2); |
1533 |
} |
1534 |
|
1535 |
static void gen_rot_rm_T1(DisasContext *s, int ot, int op1, |
1536 |
int is_right)
|
1537 |
{ |
1538 |
target_ulong mask; |
1539 |
int label1, label2, data_bits;
|
1540 |
TCGv t0, t1, t2, a0; |
1541 |
|
1542 |
/* XXX: inefficient, but we must use local temps */
|
1543 |
t0 = tcg_temp_local_new(); |
1544 |
t1 = tcg_temp_local_new(); |
1545 |
t2 = tcg_temp_local_new(); |
1546 |
a0 = tcg_temp_local_new(); |
1547 |
|
1548 |
if (ot == OT_QUAD)
|
1549 |
mask = 0x3f;
|
1550 |
else
|
1551 |
mask = 0x1f;
|
1552 |
|
1553 |
/* load */
|
1554 |
if (op1 == OR_TMP0) {
|
1555 |
tcg_gen_mov_tl(a0, cpu_A0); |
1556 |
gen_op_ld_v(ot + s->mem_index, t0, a0); |
1557 |
} else {
|
1558 |
gen_op_mov_v_reg(ot, t0, op1); |
1559 |
} |
1560 |
|
1561 |
tcg_gen_mov_tl(t1, cpu_T[1]);
|
1562 |
|
1563 |
tcg_gen_andi_tl(t1, t1, mask); |
1564 |
|
1565 |
/* Must test zero case to avoid using undefined behaviour in TCG
|
1566 |
shifts. */
|
1567 |
label1 = gen_new_label(); |
1568 |
tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, label1);
|
1569 |
|
1570 |
if (ot <= OT_WORD)
|
1571 |
tcg_gen_andi_tl(cpu_tmp0, t1, (1 << (3 + ot)) - 1); |
1572 |
else
|
1573 |
tcg_gen_mov_tl(cpu_tmp0, t1); |
1574 |
|
1575 |
gen_extu(ot, t0); |
1576 |
tcg_gen_mov_tl(t2, t0); |
1577 |
|
1578 |
data_bits = 8 << ot;
|
1579 |
/* XXX: rely on behaviour of shifts when operand 2 overflows (XXX:
|
1580 |
fix TCG definition) */
|
1581 |
if (is_right) {
|
1582 |
tcg_gen_shr_tl(cpu_tmp4, t0, cpu_tmp0); |
1583 |
tcg_gen_subfi_tl(cpu_tmp0, data_bits, cpu_tmp0); |
1584 |
tcg_gen_shl_tl(t0, t0, cpu_tmp0); |
1585 |
} else {
|
1586 |
tcg_gen_shl_tl(cpu_tmp4, t0, cpu_tmp0); |
1587 |
tcg_gen_subfi_tl(cpu_tmp0, data_bits, cpu_tmp0); |
1588 |
tcg_gen_shr_tl(t0, t0, cpu_tmp0); |
1589 |
} |
1590 |
tcg_gen_or_tl(t0, t0, cpu_tmp4); |
1591 |
|
1592 |
gen_set_label(label1); |
1593 |
/* store */
|
1594 |
if (op1 == OR_TMP0) {
|
1595 |
gen_op_st_v(ot + s->mem_index, t0, a0); |
1596 |
} else {
|
1597 |
gen_op_mov_reg_v(ot, op1, t0); |
1598 |
} |
1599 |
|
1600 |
/* update eflags */
|
1601 |
if (s->cc_op != CC_OP_DYNAMIC)
|
1602 |
gen_op_set_cc_op(s->cc_op); |
1603 |
|
1604 |
label2 = gen_new_label(); |
1605 |
tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, label2);
|
1606 |
|
1607 |
gen_compute_eflags(cpu_cc_src); |
1608 |
tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, ~(CC_O | CC_C)); |
1609 |
tcg_gen_xor_tl(cpu_tmp0, t2, t0); |
1610 |
tcg_gen_lshift(cpu_tmp0, cpu_tmp0, 11 - (data_bits - 1)); |
1611 |
tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, CC_O); |
1612 |
tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0); |
1613 |
if (is_right) {
|
1614 |
tcg_gen_shri_tl(t0, t0, data_bits - 1);
|
1615 |
} |
1616 |
tcg_gen_andi_tl(t0, t0, CC_C); |
1617 |
tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, t0); |
1618 |
|
1619 |
tcg_gen_discard_tl(cpu_cc_dst); |
1620 |
tcg_gen_movi_i32(cpu_cc_op, CC_OP_EFLAGS); |
1621 |
|
1622 |
gen_set_label(label2); |
1623 |
s->cc_op = CC_OP_DYNAMIC; /* cannot predict flags after */
|
1624 |
|
1625 |
tcg_temp_free(t0); |
1626 |
tcg_temp_free(t1); |
1627 |
tcg_temp_free(t2); |
1628 |
tcg_temp_free(a0); |
1629 |
} |
1630 |
|
1631 |
static void gen_rot_rm_im(DisasContext *s, int ot, int op1, int op2, |
1632 |
int is_right)
|
1633 |
{ |
1634 |
int mask;
|
1635 |
int data_bits;
|
1636 |
TCGv t0, t1, a0; |
1637 |
|
1638 |
/* XXX: inefficient, but we must use local temps */
|
1639 |
t0 = tcg_temp_local_new(); |
1640 |
t1 = tcg_temp_local_new(); |
1641 |
a0 = tcg_temp_local_new(); |
1642 |
|
1643 |
if (ot == OT_QUAD)
|
1644 |
mask = 0x3f;
|
1645 |
else
|
1646 |
mask = 0x1f;
|
1647 |
|
1648 |
/* load */
|
1649 |
if (op1 == OR_TMP0) {
|
1650 |
tcg_gen_mov_tl(a0, cpu_A0); |
1651 |
gen_op_ld_v(ot + s->mem_index, t0, a0); |
1652 |
} else {
|
1653 |
gen_op_mov_v_reg(ot, t0, op1); |
1654 |
} |
1655 |
|
1656 |
gen_extu(ot, t0); |
1657 |
tcg_gen_mov_tl(t1, t0); |
1658 |
|
1659 |
op2 &= mask; |
1660 |
data_bits = 8 << ot;
|
1661 |
if (op2 != 0) { |
1662 |
int shift = op2 & ((1 << (3 + ot)) - 1); |
1663 |
if (is_right) {
|
1664 |
tcg_gen_shri_tl(cpu_tmp4, t0, shift); |
1665 |
tcg_gen_shli_tl(t0, t0, data_bits - shift); |
1666 |
} |
1667 |
else {
|
1668 |
tcg_gen_shli_tl(cpu_tmp4, t0, shift); |
1669 |
tcg_gen_shri_tl(t0, t0, data_bits - shift); |
1670 |
} |
1671 |
tcg_gen_or_tl(t0, t0, cpu_tmp4); |
1672 |
} |
1673 |
|
1674 |
/* store */
|
1675 |
if (op1 == OR_TMP0) {
|
1676 |
gen_op_st_v(ot + s->mem_index, t0, a0); |
1677 |
} else {
|
1678 |
gen_op_mov_reg_v(ot, op1, t0); |
1679 |
} |
1680 |
|
1681 |
if (op2 != 0) { |
1682 |
/* update eflags */
|
1683 |
if (s->cc_op != CC_OP_DYNAMIC)
|
1684 |
gen_op_set_cc_op(s->cc_op); |
1685 |
|
1686 |
gen_compute_eflags(cpu_cc_src); |
1687 |
tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, ~(CC_O | CC_C)); |
1688 |
tcg_gen_xor_tl(cpu_tmp0, t1, t0); |
1689 |
tcg_gen_lshift(cpu_tmp0, cpu_tmp0, 11 - (data_bits - 1)); |
1690 |
tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, CC_O); |
1691 |
tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0); |
1692 |
if (is_right) {
|
1693 |
tcg_gen_shri_tl(t0, t0, data_bits - 1);
|
1694 |
} |
1695 |
tcg_gen_andi_tl(t0, t0, CC_C); |
1696 |
tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, t0); |
1697 |
|
1698 |
tcg_gen_discard_tl(cpu_cc_dst); |
1699 |
tcg_gen_movi_i32(cpu_cc_op, CC_OP_EFLAGS); |
1700 |
s->cc_op = CC_OP_EFLAGS; |
1701 |
} |
1702 |
|
1703 |
tcg_temp_free(t0); |
1704 |
tcg_temp_free(t1); |
1705 |
tcg_temp_free(a0); |
1706 |
} |
1707 |
|
1708 |
/* XXX: add faster immediate = 1 case */
|
1709 |
static void gen_rotc_rm_T1(DisasContext *s, int ot, int op1, |
1710 |
int is_right)
|
1711 |
{ |
1712 |
int label1;
|
1713 |
|
1714 |
if (s->cc_op != CC_OP_DYNAMIC)
|
1715 |
gen_op_set_cc_op(s->cc_op); |
1716 |
|
1717 |
/* load */
|
1718 |
if (op1 == OR_TMP0)
|
1719 |
gen_op_ld_T0_A0(ot + s->mem_index); |
1720 |
else
|
1721 |
gen_op_mov_TN_reg(ot, 0, op1);
|
1722 |
|
1723 |
if (is_right) {
|
1724 |
switch (ot) {
|
1725 |
case OT_BYTE:
|
1726 |
gen_helper_rcrb(cpu_T[0], cpu_env, cpu_T[0], cpu_T[1]); |
1727 |
break;
|
1728 |
case OT_WORD:
|
1729 |
gen_helper_rcrw(cpu_T[0], cpu_env, cpu_T[0], cpu_T[1]); |
1730 |
break;
|
1731 |
case OT_LONG:
|
1732 |
gen_helper_rcrl(cpu_T[0], cpu_env, cpu_T[0], cpu_T[1]); |
1733 |
break;
|
1734 |
#ifdef TARGET_X86_64
|
1735 |
case OT_QUAD:
|
1736 |
gen_helper_rcrq(cpu_T[0], cpu_env, cpu_T[0], cpu_T[1]); |
1737 |
break;
|
1738 |
#endif
|
1739 |
} |
1740 |
} else {
|
1741 |
switch (ot) {
|
1742 |
case OT_BYTE:
|
1743 |
gen_helper_rclb(cpu_T[0], cpu_env, cpu_T[0], cpu_T[1]); |
1744 |
break;
|
1745 |
case OT_WORD:
|
1746 |
gen_helper_rclw(cpu_T[0], cpu_env, cpu_T[0], cpu_T[1]); |
1747 |
break;
|
1748 |
case OT_LONG:
|
1749 |
gen_helper_rcll(cpu_T[0], cpu_env, cpu_T[0], cpu_T[1]); |
1750 |
break;
|
1751 |
#ifdef TARGET_X86_64
|
1752 |
case OT_QUAD:
|
1753 |
gen_helper_rclq(cpu_T[0], cpu_env, cpu_T[0], cpu_T[1]); |
1754 |
break;
|
1755 |
#endif
|
1756 |
} |
1757 |
} |
1758 |
/* store */
|
1759 |
if (op1 == OR_TMP0)
|
1760 |
gen_op_st_T0_A0(ot + s->mem_index); |
1761 |
else
|
1762 |
gen_op_mov_reg_T0(ot, op1); |
1763 |
|
1764 |
/* update eflags */
|
1765 |
label1 = gen_new_label(); |
1766 |
tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_cc_tmp, -1, label1);
|
1767 |
|
1768 |
tcg_gen_mov_tl(cpu_cc_src, cpu_cc_tmp); |
1769 |
tcg_gen_discard_tl(cpu_cc_dst); |
1770 |
tcg_gen_movi_i32(cpu_cc_op, CC_OP_EFLAGS); |
1771 |
|
1772 |
gen_set_label(label1); |
1773 |
s->cc_op = CC_OP_DYNAMIC; /* cannot predict flags after */
|
1774 |
} |
1775 |
|
1776 |
/* XXX: add faster immediate case */
|
1777 |
static void gen_shiftd_rm_T1_T3(DisasContext *s, int ot, int op1, |
1778 |
int is_right)
|
1779 |
{ |
1780 |
int label1, label2, data_bits;
|
1781 |
target_ulong mask; |
1782 |
TCGv t0, t1, t2, a0; |
1783 |
|
1784 |
t0 = tcg_temp_local_new(); |
1785 |
t1 = tcg_temp_local_new(); |
1786 |
t2 = tcg_temp_local_new(); |
1787 |
a0 = tcg_temp_local_new(); |
1788 |
|
1789 |
if (ot == OT_QUAD)
|
1790 |
mask = 0x3f;
|
1791 |
else
|
1792 |
mask = 0x1f;
|
1793 |
|
1794 |
/* load */
|
1795 |
if (op1 == OR_TMP0) {
|
1796 |
tcg_gen_mov_tl(a0, cpu_A0); |
1797 |
gen_op_ld_v(ot + s->mem_index, t0, a0); |
1798 |
} else {
|
1799 |
gen_op_mov_v_reg(ot, t0, op1); |
1800 |
} |
1801 |
|
1802 |
tcg_gen_andi_tl(cpu_T3, cpu_T3, mask); |
1803 |
|
1804 |
tcg_gen_mov_tl(t1, cpu_T[1]);
|
1805 |
tcg_gen_mov_tl(t2, cpu_T3); |
1806 |
|
1807 |
/* Must test zero case to avoid using undefined behaviour in TCG
|
1808 |
shifts. */
|
1809 |
label1 = gen_new_label(); |
1810 |
tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, label1);
|
1811 |
|
1812 |
tcg_gen_addi_tl(cpu_tmp5, t2, -1);
|
1813 |
if (ot == OT_WORD) {
|
1814 |
/* Note: we implement the Intel behaviour for shift count > 16 */
|
1815 |
if (is_right) {
|
1816 |
tcg_gen_andi_tl(t0, t0, 0xffff);
|
1817 |
tcg_gen_shli_tl(cpu_tmp0, t1, 16);
|
1818 |
tcg_gen_or_tl(t0, t0, cpu_tmp0); |
1819 |
tcg_gen_ext32u_tl(t0, t0); |
1820 |
|
1821 |
tcg_gen_shr_tl(cpu_tmp4, t0, cpu_tmp5); |
1822 |
|
1823 |
/* only needed if count > 16, but a test would complicate */
|
1824 |
tcg_gen_subfi_tl(cpu_tmp5, 32, t2);
|
1825 |
tcg_gen_shl_tl(cpu_tmp0, t0, cpu_tmp5); |
1826 |
|
1827 |
tcg_gen_shr_tl(t0, t0, t2); |
1828 |
|
1829 |
tcg_gen_or_tl(t0, t0, cpu_tmp0); |
1830 |
} else {
|
1831 |
/* XXX: not optimal */
|
1832 |
tcg_gen_andi_tl(t0, t0, 0xffff);
|
1833 |
tcg_gen_shli_tl(t1, t1, 16);
|
1834 |
tcg_gen_or_tl(t1, t1, t0); |
1835 |
tcg_gen_ext32u_tl(t1, t1); |
1836 |
|
1837 |
tcg_gen_shl_tl(cpu_tmp4, t0, cpu_tmp5); |
1838 |
tcg_gen_subfi_tl(cpu_tmp0, 32, cpu_tmp5);
|
1839 |
tcg_gen_shr_tl(cpu_tmp5, t1, cpu_tmp0); |
1840 |
tcg_gen_or_tl(cpu_tmp4, cpu_tmp4, cpu_tmp5); |
1841 |
|
1842 |
tcg_gen_shl_tl(t0, t0, t2); |
1843 |
tcg_gen_subfi_tl(cpu_tmp5, 32, t2);
|
1844 |
tcg_gen_shr_tl(t1, t1, cpu_tmp5); |
1845 |
tcg_gen_or_tl(t0, t0, t1); |
1846 |
} |
1847 |
} else {
|
1848 |
data_bits = 8 << ot;
|
1849 |
if (is_right) {
|
1850 |
if (ot == OT_LONG)
|
1851 |
tcg_gen_ext32u_tl(t0, t0); |
1852 |
|
1853 |
tcg_gen_shr_tl(cpu_tmp4, t0, cpu_tmp5); |
1854 |
|
1855 |
tcg_gen_shr_tl(t0, t0, t2); |
1856 |
tcg_gen_subfi_tl(cpu_tmp5, data_bits, t2); |
1857 |
tcg_gen_shl_tl(t1, t1, cpu_tmp5); |
1858 |
tcg_gen_or_tl(t0, t0, t1); |
1859 |
|
1860 |
} else {
|
1861 |
if (ot == OT_LONG)
|
1862 |
tcg_gen_ext32u_tl(t1, t1); |
1863 |
|
1864 |
tcg_gen_shl_tl(cpu_tmp4, t0, cpu_tmp5); |
1865 |
|
1866 |
tcg_gen_shl_tl(t0, t0, t2); |
1867 |
tcg_gen_subfi_tl(cpu_tmp5, data_bits, t2); |
1868 |
tcg_gen_shr_tl(t1, t1, cpu_tmp5); |
1869 |
tcg_gen_or_tl(t0, t0, t1); |
1870 |
} |
1871 |
} |
1872 |
tcg_gen_mov_tl(t1, cpu_tmp4); |
1873 |
|
1874 |
gen_set_label(label1); |
1875 |
/* store */
|
1876 |
if (op1 == OR_TMP0) {
|
1877 |
gen_op_st_v(ot + s->mem_index, t0, a0); |
1878 |
} else {
|
1879 |
gen_op_mov_reg_v(ot, op1, t0); |
1880 |
} |
1881 |
|
1882 |
/* update eflags */
|
1883 |
if (s->cc_op != CC_OP_DYNAMIC)
|
1884 |
gen_op_set_cc_op(s->cc_op); |
1885 |
|
1886 |
label2 = gen_new_label(); |
1887 |
tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, label2);
|
1888 |
|
1889 |
tcg_gen_mov_tl(cpu_cc_src, t1); |
1890 |
tcg_gen_mov_tl(cpu_cc_dst, t0); |
1891 |
if (is_right) {
|
1892 |
tcg_gen_movi_i32(cpu_cc_op, CC_OP_SARB + ot); |
1893 |
} else {
|
1894 |
tcg_gen_movi_i32(cpu_cc_op, CC_OP_SHLB + ot); |
1895 |
} |
1896 |
gen_set_label(label2); |
1897 |
s->cc_op = CC_OP_DYNAMIC; /* cannot predict flags after */
|
1898 |
|
1899 |
tcg_temp_free(t0); |
1900 |
tcg_temp_free(t1); |
1901 |
tcg_temp_free(t2); |
1902 |
tcg_temp_free(a0); |
1903 |
} |
1904 |
|
1905 |
static void gen_shift(DisasContext *s1, int op, int ot, int d, int s) |
1906 |
{ |
1907 |
if (s != OR_TMP1)
|
1908 |
gen_op_mov_TN_reg(ot, 1, s);
|
1909 |
switch(op) {
|
1910 |
case OP_ROL:
|
1911 |
gen_rot_rm_T1(s1, ot, d, 0);
|
1912 |
break;
|
1913 |
case OP_ROR:
|
1914 |
gen_rot_rm_T1(s1, ot, d, 1);
|
1915 |
break;
|
1916 |
case OP_SHL:
|
1917 |
case OP_SHL1:
|
1918 |
gen_shift_rm_T1(s1, ot, d, 0, 0); |
1919 |
break;
|
1920 |
case OP_SHR:
|
1921 |
gen_shift_rm_T1(s1, ot, d, 1, 0); |
1922 |
break;
|
1923 |
case OP_SAR:
|
1924 |
gen_shift_rm_T1(s1, ot, d, 1, 1); |
1925 |
break;
|
1926 |
case OP_RCL:
|
1927 |
gen_rotc_rm_T1(s1, ot, d, 0);
|
1928 |
break;
|
1929 |
case OP_RCR:
|
1930 |
gen_rotc_rm_T1(s1, ot, d, 1);
|
1931 |
break;
|
1932 |
} |
1933 |
} |
1934 |
|
1935 |
static void gen_shifti(DisasContext *s1, int op, int ot, int d, int c) |
1936 |
{ |
1937 |
switch(op) {
|
1938 |
case OP_ROL:
|
1939 |
gen_rot_rm_im(s1, ot, d, c, 0);
|
1940 |
break;
|
1941 |
case OP_ROR:
|
1942 |
gen_rot_rm_im(s1, ot, d, c, 1);
|
1943 |
break;
|
1944 |
case OP_SHL:
|
1945 |
case OP_SHL1:
|
1946 |
gen_shift_rm_im(s1, ot, d, c, 0, 0); |
1947 |
break;
|
1948 |
case OP_SHR:
|
1949 |
gen_shift_rm_im(s1, ot, d, c, 1, 0); |
1950 |
break;
|
1951 |
case OP_SAR:
|
1952 |
gen_shift_rm_im(s1, ot, d, c, 1, 1); |
1953 |
break;
|
1954 |
default:
|
1955 |
/* currently not optimized */
|
1956 |
gen_op_movl_T1_im(c); |
1957 |
gen_shift(s1, op, ot, d, OR_TMP1); |
1958 |
break;
|
1959 |
} |
1960 |
} |
1961 |
|
1962 |
static void gen_lea_modrm(CPUX86State *env, DisasContext *s, int modrm, |
1963 |
int *reg_ptr, int *offset_ptr) |
1964 |
{ |
1965 |
target_long disp; |
1966 |
int havesib;
|
1967 |
int base;
|
1968 |
int index;
|
1969 |
int scale;
|
1970 |
int opreg;
|
1971 |
int mod, rm, code, override, must_add_seg;
|
1972 |
|
1973 |
override = s->override; |
1974 |
must_add_seg = s->addseg; |
1975 |
if (override >= 0) |
1976 |
must_add_seg = 1;
|
1977 |
mod = (modrm >> 6) & 3; |
1978 |
rm = modrm & 7;
|
1979 |
|
1980 |
if (s->aflag) {
|
1981 |
|
1982 |
havesib = 0;
|
1983 |
base = rm; |
1984 |
index = 0;
|
1985 |
scale = 0;
|
1986 |
|
1987 |
if (base == 4) { |
1988 |
havesib = 1;
|
1989 |
code = cpu_ldub_code(env, s->pc++); |
1990 |
scale = (code >> 6) & 3; |
1991 |
index = ((code >> 3) & 7) | REX_X(s); |
1992 |
base = (code & 7);
|
1993 |
} |
1994 |
base |= REX_B(s); |
1995 |
|
1996 |
switch (mod) {
|
1997 |
case 0: |
1998 |
if ((base & 7) == 5) { |
1999 |
base = -1;
|
2000 |
disp = (int32_t)cpu_ldl_code(env, s->pc); |
2001 |
s->pc += 4;
|
2002 |
if (CODE64(s) && !havesib) {
|
2003 |
disp += s->pc + s->rip_offset; |
2004 |
} |
2005 |
} else {
|
2006 |
disp = 0;
|
2007 |
} |
2008 |
break;
|
2009 |
case 1: |
2010 |
disp = (int8_t)cpu_ldub_code(env, s->pc++); |
2011 |
break;
|
2012 |
default:
|
2013 |
case 2: |
2014 |
disp = (int32_t)cpu_ldl_code(env, s->pc); |
2015 |
s->pc += 4;
|
2016 |
break;
|
2017 |
} |
2018 |
|
2019 |
if (base >= 0) { |
2020 |
/* for correct popl handling with esp */
|
2021 |
if (base == 4 && s->popl_esp_hack) |
2022 |
disp += s->popl_esp_hack; |
2023 |
#ifdef TARGET_X86_64
|
2024 |
if (s->aflag == 2) { |
2025 |
gen_op_movq_A0_reg(base); |
2026 |
if (disp != 0) { |
2027 |
gen_op_addq_A0_im(disp); |
2028 |
} |
2029 |
} else
|
2030 |
#endif
|
2031 |
{ |
2032 |
gen_op_movl_A0_reg(base); |
2033 |
if (disp != 0) |
2034 |
gen_op_addl_A0_im(disp); |
2035 |
} |
2036 |
} else {
|
2037 |
#ifdef TARGET_X86_64
|
2038 |
if (s->aflag == 2) { |
2039 |
gen_op_movq_A0_im(disp); |
2040 |
} else
|
2041 |
#endif
|
2042 |
{ |
2043 |
gen_op_movl_A0_im(disp); |
2044 |
} |
2045 |
} |
2046 |
/* index == 4 means no index */
|
2047 |
if (havesib && (index != 4)) { |
2048 |
#ifdef TARGET_X86_64
|
2049 |
if (s->aflag == 2) { |
2050 |
gen_op_addq_A0_reg_sN(scale, index); |
2051 |
} else
|
2052 |
#endif
|
2053 |
{ |
2054 |
gen_op_addl_A0_reg_sN(scale, index); |
2055 |
} |
2056 |
} |
2057 |
if (must_add_seg) {
|
2058 |
if (override < 0) { |
2059 |
if (base == R_EBP || base == R_ESP)
|
2060 |
override = R_SS; |
2061 |
else
|
2062 |
override = R_DS; |
2063 |
} |
2064 |
#ifdef TARGET_X86_64
|
2065 |
if (s->aflag == 2) { |
2066 |
gen_op_addq_A0_seg(override); |
2067 |
} else
|
2068 |
#endif
|
2069 |
{ |
2070 |
gen_op_addl_A0_seg(s, override); |
2071 |
} |
2072 |
} |
2073 |
} else {
|
2074 |
switch (mod) {
|
2075 |
case 0: |
2076 |
if (rm == 6) { |
2077 |
disp = cpu_lduw_code(env, s->pc); |
2078 |
s->pc += 2;
|
2079 |
gen_op_movl_A0_im(disp); |
2080 |
rm = 0; /* avoid SS override */ |
2081 |
goto no_rm;
|
2082 |
} else {
|
2083 |
disp = 0;
|
2084 |
} |
2085 |
break;
|
2086 |
case 1: |
2087 |
disp = (int8_t)cpu_ldub_code(env, s->pc++); |
2088 |
break;
|
2089 |
default:
|
2090 |
case 2: |
2091 |
disp = cpu_lduw_code(env, s->pc); |
2092 |
s->pc += 2;
|
2093 |
break;
|
2094 |
} |
2095 |
switch(rm) {
|
2096 |
case 0: |
2097 |
gen_op_movl_A0_reg(R_EBX); |
2098 |
gen_op_addl_A0_reg_sN(0, R_ESI);
|
2099 |
break;
|
2100 |
case 1: |
2101 |
gen_op_movl_A0_reg(R_EBX); |
2102 |
gen_op_addl_A0_reg_sN(0, R_EDI);
|
2103 |
break;
|
2104 |
case 2: |
2105 |
gen_op_movl_A0_reg(R_EBP); |
2106 |
gen_op_addl_A0_reg_sN(0, R_ESI);
|
2107 |
break;
|
2108 |
case 3: |
2109 |
gen_op_movl_A0_reg(R_EBP); |
2110 |
gen_op_addl_A0_reg_sN(0, R_EDI);
|
2111 |
break;
|
2112 |
case 4: |
2113 |
gen_op_movl_A0_reg(R_ESI); |
2114 |
break;
|
2115 |
case 5: |
2116 |
gen_op_movl_A0_reg(R_EDI); |
2117 |
break;
|
2118 |
case 6: |
2119 |
gen_op_movl_A0_reg(R_EBP); |
2120 |
break;
|
2121 |
default:
|
2122 |
case 7: |
2123 |
gen_op_movl_A0_reg(R_EBX); |
2124 |
break;
|
2125 |
} |
2126 |
if (disp != 0) |
2127 |
gen_op_addl_A0_im(disp); |
2128 |
gen_op_andl_A0_ffff(); |
2129 |
no_rm:
|
2130 |
if (must_add_seg) {
|
2131 |
if (override < 0) { |
2132 |
if (rm == 2 || rm == 3 || rm == 6) |
2133 |
override = R_SS; |
2134 |
else
|
2135 |
override = R_DS; |
2136 |
} |
2137 |
gen_op_addl_A0_seg(s, override); |
2138 |
} |
2139 |
} |
2140 |
|
2141 |
opreg = OR_A0; |
2142 |
disp = 0;
|
2143 |
*reg_ptr = opreg; |
2144 |
*offset_ptr = disp; |
2145 |
} |
2146 |
|
2147 |
static void gen_nop_modrm(CPUX86State *env, DisasContext *s, int modrm) |
2148 |
{ |
2149 |
int mod, rm, base, code;
|
2150 |
|
2151 |
mod = (modrm >> 6) & 3; |
2152 |
if (mod == 3) |
2153 |
return;
|
2154 |
rm = modrm & 7;
|
2155 |
|
2156 |
if (s->aflag) {
|
2157 |
|
2158 |
base = rm; |
2159 |
|
2160 |
if (base == 4) { |
2161 |
code = cpu_ldub_code(env, s->pc++); |
2162 |
base = (code & 7);
|
2163 |
} |
2164 |
|
2165 |
switch (mod) {
|
2166 |
case 0: |
2167 |
if (base == 5) { |
2168 |
s->pc += 4;
|
2169 |
} |
2170 |
break;
|
2171 |
case 1: |
2172 |
s->pc++; |
2173 |
break;
|
2174 |
default:
|
2175 |
case 2: |
2176 |
s->pc += 4;
|
2177 |
break;
|
2178 |
} |
2179 |
} else {
|
2180 |
switch (mod) {
|
2181 |
case 0: |
2182 |
if (rm == 6) { |
2183 |
s->pc += 2;
|
2184 |
} |
2185 |
break;
|
2186 |
case 1: |
2187 |
s->pc++; |
2188 |
break;
|
2189 |
default:
|
2190 |
case 2: |
2191 |
s->pc += 2;
|
2192 |
break;
|
2193 |
} |
2194 |
} |
2195 |
} |
2196 |
|
2197 |
/* used for LEA and MOV AX, mem */
|
2198 |
static void gen_add_A0_ds_seg(DisasContext *s) |
2199 |
{ |
2200 |
int override, must_add_seg;
|
2201 |
must_add_seg = s->addseg; |
2202 |
override = R_DS; |
2203 |
if (s->override >= 0) { |
2204 |
override = s->override; |
2205 |
must_add_seg = 1;
|
2206 |
} |
2207 |
if (must_add_seg) {
|
2208 |
#ifdef TARGET_X86_64
|
2209 |
if (CODE64(s)) {
|
2210 |
gen_op_addq_A0_seg(override); |
2211 |
} else
|
2212 |
#endif
|
2213 |
{ |
2214 |
gen_op_addl_A0_seg(s, override); |
2215 |
} |
2216 |
} |
2217 |
} |
2218 |
|
2219 |
/* generate modrm memory load or store of 'reg'. TMP0 is used if reg ==
|
2220 |
OR_TMP0 */
|
2221 |
static void gen_ldst_modrm(CPUX86State *env, DisasContext *s, int modrm, |
2222 |
int ot, int reg, int is_store) |
2223 |
{ |
2224 |
int mod, rm, opreg, disp;
|
2225 |
|
2226 |
mod = (modrm >> 6) & 3; |
2227 |
rm = (modrm & 7) | REX_B(s);
|
2228 |
if (mod == 3) { |
2229 |
if (is_store) {
|
2230 |
if (reg != OR_TMP0)
|
2231 |
gen_op_mov_TN_reg(ot, 0, reg);
|
2232 |
gen_op_mov_reg_T0(ot, rm); |
2233 |
} else {
|
2234 |
gen_op_mov_TN_reg(ot, 0, rm);
|
2235 |
if (reg != OR_TMP0)
|
2236 |
gen_op_mov_reg_T0(ot, reg); |
2237 |
} |
2238 |
} else {
|
2239 |
gen_lea_modrm(env, s, modrm, &opreg, &disp); |
2240 |
if (is_store) {
|
2241 |
if (reg != OR_TMP0)
|
2242 |
gen_op_mov_TN_reg(ot, 0, reg);
|
2243 |
gen_op_st_T0_A0(ot + s->mem_index); |
2244 |
} else {
|
2245 |
gen_op_ld_T0_A0(ot + s->mem_index); |
2246 |
if (reg != OR_TMP0)
|
2247 |
gen_op_mov_reg_T0(ot, reg); |
2248 |
} |
2249 |
} |
2250 |
} |
2251 |
|
2252 |
static inline uint32_t insn_get(CPUX86State *env, DisasContext *s, int ot) |
2253 |
{ |
2254 |
uint32_t ret; |
2255 |
|
2256 |
switch(ot) {
|
2257 |
case OT_BYTE:
|
2258 |
ret = cpu_ldub_code(env, s->pc); |
2259 |
s->pc++; |
2260 |
break;
|
2261 |
case OT_WORD:
|
2262 |
ret = cpu_lduw_code(env, s->pc); |
2263 |
s->pc += 2;
|
2264 |
break;
|
2265 |
default:
|
2266 |
case OT_LONG:
|
2267 |
ret = cpu_ldl_code(env, s->pc); |
2268 |
s->pc += 4;
|
2269 |
break;
|
2270 |
} |
2271 |
return ret;
|
2272 |
} |
2273 |
|
2274 |
static inline int insn_const_size(unsigned int ot) |
2275 |
{ |
2276 |
if (ot <= OT_LONG)
|
2277 |
return 1 << ot; |
2278 |
else
|
2279 |
return 4; |
2280 |
} |
2281 |
|
2282 |
static inline void gen_goto_tb(DisasContext *s, int tb_num, target_ulong eip) |
2283 |
{ |
2284 |
TranslationBlock *tb; |
2285 |
target_ulong pc; |
2286 |
|
2287 |
pc = s->cs_base + eip; |
2288 |
tb = s->tb; |
2289 |
/* NOTE: we handle the case where the TB spans two pages here */
|
2290 |
if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) ||
|
2291 |
(pc & TARGET_PAGE_MASK) == ((s->pc - 1) & TARGET_PAGE_MASK)) {
|
2292 |
/* jump to same page: we can use a direct jump */
|
2293 |
tcg_gen_goto_tb(tb_num); |
2294 |
gen_jmp_im(eip); |
2295 |
tcg_gen_exit_tb((tcg_target_long)tb + tb_num); |
2296 |
} else {
|
2297 |
/* jump to another page: currently not optimized */
|
2298 |
gen_jmp_im(eip); |
2299 |
gen_eob(s); |
2300 |
} |
2301 |
} |
2302 |
|
2303 |
static inline void gen_jcc(DisasContext *s, int b, |
2304 |
target_ulong val, target_ulong next_eip) |
2305 |
{ |
2306 |
int l1, l2;
|
2307 |
|
2308 |
if (s->cc_op != CC_OP_DYNAMIC) {
|
2309 |
gen_op_set_cc_op(s->cc_op); |
2310 |
} |
2311 |
if (s->jmp_opt) {
|
2312 |
l1 = gen_new_label(); |
2313 |
gen_jcc1(s, b, l1); |
2314 |
s->cc_op = CC_OP_DYNAMIC; |
2315 |
|
2316 |
gen_goto_tb(s, 0, next_eip);
|
2317 |
|
2318 |
gen_set_label(l1); |
2319 |
gen_goto_tb(s, 1, val);
|
2320 |
s->is_jmp = DISAS_TB_JUMP; |
2321 |
} else {
|
2322 |
|
2323 |
l1 = gen_new_label(); |
2324 |
l2 = gen_new_label(); |
2325 |
gen_jcc1(s, b, l1); |
2326 |
s->cc_op = CC_OP_DYNAMIC; |
2327 |
|
2328 |
gen_jmp_im(next_eip); |
2329 |
tcg_gen_br(l2); |
2330 |
|
2331 |
gen_set_label(l1); |
2332 |
gen_jmp_im(val); |
2333 |
gen_set_label(l2); |
2334 |
gen_eob(s); |
2335 |
} |
2336 |
} |
2337 |
|
2338 |
static void gen_setcc(DisasContext *s, int b) |
2339 |
{ |
2340 |
int inv, jcc_op, l1;
|
2341 |
TCGv t0; |
2342 |
|
2343 |
if (is_fast_jcc_case(s, b)) {
|
2344 |
/* nominal case: we use a jump */
|
2345 |
/* XXX: make it faster by adding new instructions in TCG */
|
2346 |
t0 = tcg_temp_local_new(); |
2347 |
tcg_gen_movi_tl(t0, 0);
|
2348 |
l1 = gen_new_label(); |
2349 |
gen_jcc1(s, b ^ 1, l1);
|
2350 |
tcg_gen_movi_tl(t0, 1);
|
2351 |
gen_set_label(l1); |
2352 |
tcg_gen_mov_tl(cpu_T[0], t0);
|
2353 |
tcg_temp_free(t0); |
2354 |
} else {
|
2355 |
/* slow case: it is more efficient not to generate a jump,
|
2356 |
although it is questionnable whether this optimization is
|
2357 |
worth to */
|
2358 |
inv = b & 1;
|
2359 |
jcc_op = (b >> 1) & 7; |
2360 |
gen_setcc_slow_T0(s, jcc_op); |
2361 |
if (inv) {
|
2362 |
tcg_gen_xori_tl(cpu_T[0], cpu_T[0], 1); |
2363 |
} |
2364 |
} |
2365 |
} |
2366 |
|
2367 |
static inline void gen_op_movl_T0_seg(int seg_reg) |
2368 |
{ |
2369 |
tcg_gen_ld32u_tl(cpu_T[0], cpu_env,
|
2370 |
offsetof(CPUX86State,segs[seg_reg].selector)); |
2371 |
} |
2372 |
|
2373 |
static inline void gen_op_movl_seg_T0_vm(int seg_reg) |
2374 |
{ |
2375 |
tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0xffff); |
2376 |
tcg_gen_st32_tl(cpu_T[0], cpu_env,
|
2377 |
offsetof(CPUX86State,segs[seg_reg].selector)); |
2378 |
tcg_gen_shli_tl(cpu_T[0], cpu_T[0], 4); |
2379 |
tcg_gen_st_tl(cpu_T[0], cpu_env,
|
2380 |
offsetof(CPUX86State,segs[seg_reg].base)); |
2381 |
} |
2382 |
|
2383 |
/* move T0 to seg_reg and compute if the CPU state may change. Never
|
2384 |
call this function with seg_reg == R_CS */
|
2385 |
static void gen_movl_seg_T0(DisasContext *s, int seg_reg, target_ulong cur_eip) |
2386 |
{ |
2387 |
if (s->pe && !s->vm86) {
|
2388 |
/* XXX: optimize by finding processor state dynamically */
|
2389 |
if (s->cc_op != CC_OP_DYNAMIC)
|
2390 |
gen_op_set_cc_op(s->cc_op); |
2391 |
gen_jmp_im(cur_eip); |
2392 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
2393 |
gen_helper_load_seg(cpu_env, tcg_const_i32(seg_reg), cpu_tmp2_i32); |
2394 |
/* abort translation because the addseg value may change or
|
2395 |
because ss32 may change. For R_SS, translation must always
|
2396 |
stop as a special handling must be done to disable hardware
|
2397 |
interrupts for the next instruction */
|
2398 |
if (seg_reg == R_SS || (s->code32 && seg_reg < R_FS))
|
2399 |
s->is_jmp = DISAS_TB_JUMP; |
2400 |
} else {
|
2401 |
gen_op_movl_seg_T0_vm(seg_reg); |
2402 |
if (seg_reg == R_SS)
|
2403 |
s->is_jmp = DISAS_TB_JUMP; |
2404 |
} |
2405 |
} |
2406 |
|
2407 |
static inline int svm_is_rep(int prefixes) |
2408 |
{ |
2409 |
return ((prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) ? 8 : 0); |
2410 |
} |
2411 |
|
2412 |
static inline void |
2413 |
gen_svm_check_intercept_param(DisasContext *s, target_ulong pc_start, |
2414 |
uint32_t type, uint64_t param) |
2415 |
{ |
2416 |
/* no SVM activated; fast case */
|
2417 |
if (likely(!(s->flags & HF_SVMI_MASK)))
|
2418 |
return;
|
2419 |
if (s->cc_op != CC_OP_DYNAMIC)
|
2420 |
gen_op_set_cc_op(s->cc_op); |
2421 |
gen_jmp_im(pc_start - s->cs_base); |
2422 |
gen_helper_svm_check_intercept_param(cpu_env, tcg_const_i32(type), |
2423 |
tcg_const_i64(param)); |
2424 |
} |
2425 |
|
2426 |
static inline void |
2427 |
gen_svm_check_intercept(DisasContext *s, target_ulong pc_start, uint64_t type) |
2428 |
{ |
2429 |
gen_svm_check_intercept_param(s, pc_start, type, 0);
|
2430 |
} |
2431 |
|
2432 |
static inline void gen_stack_update(DisasContext *s, int addend) |
2433 |
{ |
2434 |
#ifdef TARGET_X86_64
|
2435 |
if (CODE64(s)) {
|
2436 |
gen_op_add_reg_im(2, R_ESP, addend);
|
2437 |
} else
|
2438 |
#endif
|
2439 |
if (s->ss32) {
|
2440 |
gen_op_add_reg_im(1, R_ESP, addend);
|
2441 |
} else {
|
2442 |
gen_op_add_reg_im(0, R_ESP, addend);
|
2443 |
} |
2444 |
} |
2445 |
|
2446 |
/* generate a push. It depends on ss32, addseg and dflag */
|
2447 |
static void gen_push_T0(DisasContext *s) |
2448 |
{ |
2449 |
#ifdef TARGET_X86_64
|
2450 |
if (CODE64(s)) {
|
2451 |
gen_op_movq_A0_reg(R_ESP); |
2452 |
if (s->dflag) {
|
2453 |
gen_op_addq_A0_im(-8);
|
2454 |
gen_op_st_T0_A0(OT_QUAD + s->mem_index); |
2455 |
} else {
|
2456 |
gen_op_addq_A0_im(-2);
|
2457 |
gen_op_st_T0_A0(OT_WORD + s->mem_index); |
2458 |
} |
2459 |
gen_op_mov_reg_A0(2, R_ESP);
|
2460 |
} else
|
2461 |
#endif
|
2462 |
{ |
2463 |
gen_op_movl_A0_reg(R_ESP); |
2464 |
if (!s->dflag)
|
2465 |
gen_op_addl_A0_im(-2);
|
2466 |
else
|
2467 |
gen_op_addl_A0_im(-4);
|
2468 |
if (s->ss32) {
|
2469 |
if (s->addseg) {
|
2470 |
tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2471 |
gen_op_addl_A0_seg(s, R_SS); |
2472 |
} |
2473 |
} else {
|
2474 |
gen_op_andl_A0_ffff(); |
2475 |
tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2476 |
gen_op_addl_A0_seg(s, R_SS); |
2477 |
} |
2478 |
gen_op_st_T0_A0(s->dflag + 1 + s->mem_index);
|
2479 |
if (s->ss32 && !s->addseg)
|
2480 |
gen_op_mov_reg_A0(1, R_ESP);
|
2481 |
else
|
2482 |
gen_op_mov_reg_T1(s->ss32 + 1, R_ESP);
|
2483 |
} |
2484 |
} |
2485 |
|
2486 |
/* generate a push. It depends on ss32, addseg and dflag */
|
2487 |
/* slower version for T1, only used for call Ev */
|
2488 |
static void gen_push_T1(DisasContext *s) |
2489 |
{ |
2490 |
#ifdef TARGET_X86_64
|
2491 |
if (CODE64(s)) {
|
2492 |
gen_op_movq_A0_reg(R_ESP); |
2493 |
if (s->dflag) {
|
2494 |
gen_op_addq_A0_im(-8);
|
2495 |
gen_op_st_T1_A0(OT_QUAD + s->mem_index); |
2496 |
} else {
|
2497 |
gen_op_addq_A0_im(-2);
|
2498 |
gen_op_st_T0_A0(OT_WORD + s->mem_index); |
2499 |
} |
2500 |
gen_op_mov_reg_A0(2, R_ESP);
|
2501 |
} else
|
2502 |
#endif
|
2503 |
{ |
2504 |
gen_op_movl_A0_reg(R_ESP); |
2505 |
if (!s->dflag)
|
2506 |
gen_op_addl_A0_im(-2);
|
2507 |
else
|
2508 |
gen_op_addl_A0_im(-4);
|
2509 |
if (s->ss32) {
|
2510 |
if (s->addseg) {
|
2511 |
gen_op_addl_A0_seg(s, R_SS); |
2512 |
} |
2513 |
} else {
|
2514 |
gen_op_andl_A0_ffff(); |
2515 |
gen_op_addl_A0_seg(s, R_SS); |
2516 |
} |
2517 |
gen_op_st_T1_A0(s->dflag + 1 + s->mem_index);
|
2518 |
|
2519 |
if (s->ss32 && !s->addseg)
|
2520 |
gen_op_mov_reg_A0(1, R_ESP);
|
2521 |
else
|
2522 |
gen_stack_update(s, (-2) << s->dflag);
|
2523 |
} |
2524 |
} |
2525 |
|
2526 |
/* two step pop is necessary for precise exceptions */
|
2527 |
static void gen_pop_T0(DisasContext *s) |
2528 |
{ |
2529 |
#ifdef TARGET_X86_64
|
2530 |
if (CODE64(s)) {
|
2531 |
gen_op_movq_A0_reg(R_ESP); |
2532 |
gen_op_ld_T0_A0((s->dflag ? OT_QUAD : OT_WORD) + s->mem_index); |
2533 |
} else
|
2534 |
#endif
|
2535 |
{ |
2536 |
gen_op_movl_A0_reg(R_ESP); |
2537 |
if (s->ss32) {
|
2538 |
if (s->addseg)
|
2539 |
gen_op_addl_A0_seg(s, R_SS); |
2540 |
} else {
|
2541 |
gen_op_andl_A0_ffff(); |
2542 |
gen_op_addl_A0_seg(s, R_SS); |
2543 |
} |
2544 |
gen_op_ld_T0_A0(s->dflag + 1 + s->mem_index);
|
2545 |
} |
2546 |
} |
2547 |
|
2548 |
static void gen_pop_update(DisasContext *s) |
2549 |
{ |
2550 |
#ifdef TARGET_X86_64
|
2551 |
if (CODE64(s) && s->dflag) {
|
2552 |
gen_stack_update(s, 8);
|
2553 |
} else
|
2554 |
#endif
|
2555 |
{ |
2556 |
gen_stack_update(s, 2 << s->dflag);
|
2557 |
} |
2558 |
} |
2559 |
|
2560 |
static void gen_stack_A0(DisasContext *s) |
2561 |
{ |
2562 |
gen_op_movl_A0_reg(R_ESP); |
2563 |
if (!s->ss32)
|
2564 |
gen_op_andl_A0_ffff(); |
2565 |
tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2566 |
if (s->addseg)
|
2567 |
gen_op_addl_A0_seg(s, R_SS); |
2568 |
} |
2569 |
|
2570 |
/* NOTE: wrap around in 16 bit not fully handled */
|
2571 |
static void gen_pusha(DisasContext *s) |
2572 |
{ |
2573 |
int i;
|
2574 |
gen_op_movl_A0_reg(R_ESP); |
2575 |
gen_op_addl_A0_im(-16 << s->dflag);
|
2576 |
if (!s->ss32)
|
2577 |
gen_op_andl_A0_ffff(); |
2578 |
tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2579 |
if (s->addseg)
|
2580 |
gen_op_addl_A0_seg(s, R_SS); |
2581 |
for(i = 0;i < 8; i++) { |
2582 |
gen_op_mov_TN_reg(OT_LONG, 0, 7 - i); |
2583 |
gen_op_st_T0_A0(OT_WORD + s->dflag + s->mem_index); |
2584 |
gen_op_addl_A0_im(2 << s->dflag);
|
2585 |
} |
2586 |
gen_op_mov_reg_T1(OT_WORD + s->ss32, R_ESP); |
2587 |
} |
2588 |
|
2589 |
/* NOTE: wrap around in 16 bit not fully handled */
|
2590 |
static void gen_popa(DisasContext *s) |
2591 |
{ |
2592 |
int i;
|
2593 |
gen_op_movl_A0_reg(R_ESP); |
2594 |
if (!s->ss32)
|
2595 |
gen_op_andl_A0_ffff(); |
2596 |
tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2597 |
tcg_gen_addi_tl(cpu_T[1], cpu_T[1], 16 << s->dflag); |
2598 |
if (s->addseg)
|
2599 |
gen_op_addl_A0_seg(s, R_SS); |
2600 |
for(i = 0;i < 8; i++) { |
2601 |
/* ESP is not reloaded */
|
2602 |
if (i != 3) { |
2603 |
gen_op_ld_T0_A0(OT_WORD + s->dflag + s->mem_index); |
2604 |
gen_op_mov_reg_T0(OT_WORD + s->dflag, 7 - i);
|
2605 |
} |
2606 |
gen_op_addl_A0_im(2 << s->dflag);
|
2607 |
} |
2608 |
gen_op_mov_reg_T1(OT_WORD + s->ss32, R_ESP); |
2609 |
} |
2610 |
|
2611 |
static void gen_enter(DisasContext *s, int esp_addend, int level) |
2612 |
{ |
2613 |
int ot, opsize;
|
2614 |
|
2615 |
level &= 0x1f;
|
2616 |
#ifdef TARGET_X86_64
|
2617 |
if (CODE64(s)) {
|
2618 |
ot = s->dflag ? OT_QUAD : OT_WORD; |
2619 |
opsize = 1 << ot;
|
2620 |
|
2621 |
gen_op_movl_A0_reg(R_ESP); |
2622 |
gen_op_addq_A0_im(-opsize); |
2623 |
tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2624 |
|
2625 |
/* push bp */
|
2626 |
gen_op_mov_TN_reg(OT_LONG, 0, R_EBP);
|
2627 |
gen_op_st_T0_A0(ot + s->mem_index); |
2628 |
if (level) {
|
2629 |
/* XXX: must save state */
|
2630 |
gen_helper_enter64_level(cpu_env, tcg_const_i32(level), |
2631 |
tcg_const_i32((ot == OT_QUAD)), |
2632 |
cpu_T[1]);
|
2633 |
} |
2634 |
gen_op_mov_reg_T1(ot, R_EBP); |
2635 |
tcg_gen_addi_tl(cpu_T[1], cpu_T[1], -esp_addend + (-opsize * level)); |
2636 |
gen_op_mov_reg_T1(OT_QUAD, R_ESP); |
2637 |
} else
|
2638 |
#endif
|
2639 |
{ |
2640 |
ot = s->dflag + OT_WORD; |
2641 |
opsize = 2 << s->dflag;
|
2642 |
|
2643 |
gen_op_movl_A0_reg(R_ESP); |
2644 |
gen_op_addl_A0_im(-opsize); |
2645 |
if (!s->ss32)
|
2646 |
gen_op_andl_A0_ffff(); |
2647 |
tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2648 |
if (s->addseg)
|
2649 |
gen_op_addl_A0_seg(s, R_SS); |
2650 |
/* push bp */
|
2651 |
gen_op_mov_TN_reg(OT_LONG, 0, R_EBP);
|
2652 |
gen_op_st_T0_A0(ot + s->mem_index); |
2653 |
if (level) {
|
2654 |
/* XXX: must save state */
|
2655 |
gen_helper_enter_level(cpu_env, tcg_const_i32(level), |
2656 |
tcg_const_i32(s->dflag), |
2657 |
cpu_T[1]);
|
2658 |
} |
2659 |
gen_op_mov_reg_T1(ot, R_EBP); |
2660 |
tcg_gen_addi_tl(cpu_T[1], cpu_T[1], -esp_addend + (-opsize * level)); |
2661 |
gen_op_mov_reg_T1(OT_WORD + s->ss32, R_ESP); |
2662 |
} |
2663 |
} |
2664 |
|
2665 |
static void gen_exception(DisasContext *s, int trapno, target_ulong cur_eip) |
2666 |
{ |
2667 |
if (s->cc_op != CC_OP_DYNAMIC)
|
2668 |
gen_op_set_cc_op(s->cc_op); |
2669 |
gen_jmp_im(cur_eip); |
2670 |
gen_helper_raise_exception(cpu_env, tcg_const_i32(trapno)); |
2671 |
s->is_jmp = DISAS_TB_JUMP; |
2672 |
} |
2673 |
|
2674 |
/* an interrupt is different from an exception because of the
|
2675 |
privilege checks */
|
2676 |
static void gen_interrupt(DisasContext *s, int intno, |
2677 |
target_ulong cur_eip, target_ulong next_eip) |
2678 |
{ |
2679 |
if (s->cc_op != CC_OP_DYNAMIC)
|
2680 |
gen_op_set_cc_op(s->cc_op); |
2681 |
gen_jmp_im(cur_eip); |
2682 |
gen_helper_raise_interrupt(cpu_env, tcg_const_i32(intno), |
2683 |
tcg_const_i32(next_eip - cur_eip)); |
2684 |
s->is_jmp = DISAS_TB_JUMP; |
2685 |
} |
2686 |
|
2687 |
static void gen_debug(DisasContext *s, target_ulong cur_eip) |
2688 |
{ |
2689 |
if (s->cc_op != CC_OP_DYNAMIC)
|
2690 |
gen_op_set_cc_op(s->cc_op); |
2691 |
gen_jmp_im(cur_eip); |
2692 |
gen_helper_debug(cpu_env); |
2693 |
s->is_jmp = DISAS_TB_JUMP; |
2694 |
} |
2695 |
|
2696 |
/* generate a generic end of block. Trace exception is also generated
|
2697 |
if needed */
|
2698 |
static void gen_eob(DisasContext *s) |
2699 |
{ |
2700 |
if (s->cc_op != CC_OP_DYNAMIC)
|
2701 |
gen_op_set_cc_op(s->cc_op); |
2702 |
if (s->tb->flags & HF_INHIBIT_IRQ_MASK) {
|
2703 |
gen_helper_reset_inhibit_irq(cpu_env); |
2704 |
} |
2705 |
if (s->tb->flags & HF_RF_MASK) {
|
2706 |
gen_helper_reset_rf(cpu_env); |
2707 |
} |
2708 |
if (s->singlestep_enabled) {
|
2709 |
gen_helper_debug(cpu_env); |
2710 |
} else if (s->tf) { |
2711 |
gen_helper_single_step(cpu_env); |
2712 |
} else {
|
2713 |
tcg_gen_exit_tb(0);
|
2714 |
} |
2715 |
s->is_jmp = DISAS_TB_JUMP; |
2716 |
} |
2717 |
|
2718 |
/* generate a jump to eip. No segment change must happen before as a
|
2719 |
direct call to the next block may occur */
|
2720 |
static void gen_jmp_tb(DisasContext *s, target_ulong eip, int tb_num) |
2721 |
{ |
2722 |
if (s->jmp_opt) {
|
2723 |
gen_update_cc_op(s); |
2724 |
gen_goto_tb(s, tb_num, eip); |
2725 |
s->is_jmp = DISAS_TB_JUMP; |
2726 |
} else {
|
2727 |
gen_jmp_im(eip); |
2728 |
gen_eob(s); |
2729 |
} |
2730 |
} |
2731 |
|
2732 |
static void gen_jmp(DisasContext *s, target_ulong eip) |
2733 |
{ |
2734 |
gen_jmp_tb(s, eip, 0);
|
2735 |
} |
2736 |
|
2737 |
static inline void gen_ldq_env_A0(int idx, int offset) |
2738 |
{ |
2739 |
int mem_index = (idx >> 2) - 1; |
2740 |
tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_A0, mem_index); |
2741 |
tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, offset); |
2742 |
} |
2743 |
|
2744 |
static inline void gen_stq_env_A0(int idx, int offset) |
2745 |
{ |
2746 |
int mem_index = (idx >> 2) - 1; |
2747 |
tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, offset); |
2748 |
tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_A0, mem_index); |
2749 |
} |
2750 |
|
2751 |
static inline void gen_ldo_env_A0(int idx, int offset) |
2752 |
{ |
2753 |
int mem_index = (idx >> 2) - 1; |
2754 |
tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_A0, mem_index); |
2755 |
tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, offset + offsetof(XMMReg, XMM_Q(0)));
|
2756 |
tcg_gen_addi_tl(cpu_tmp0, cpu_A0, 8);
|
2757 |
tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_tmp0, mem_index); |
2758 |
tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, offset + offsetof(XMMReg, XMM_Q(1)));
|
2759 |
} |
2760 |
|
2761 |
static inline void gen_sto_env_A0(int idx, int offset) |
2762 |
{ |
2763 |
int mem_index = (idx >> 2) - 1; |
2764 |
tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, offset + offsetof(XMMReg, XMM_Q(0)));
|
2765 |
tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_A0, mem_index); |
2766 |
tcg_gen_addi_tl(cpu_tmp0, cpu_A0, 8);
|
2767 |
tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, offset + offsetof(XMMReg, XMM_Q(1)));
|
2768 |
tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_tmp0, mem_index); |
2769 |
} |
2770 |
|
2771 |
static inline void gen_op_movo(int d_offset, int s_offset) |
2772 |
{ |
2773 |
tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, s_offset); |
2774 |
tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, d_offset); |
2775 |
tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, s_offset + 8);
|
2776 |
tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, d_offset + 8);
|
2777 |
} |
2778 |
|
2779 |
static inline void gen_op_movq(int d_offset, int s_offset) |
2780 |
{ |
2781 |
tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, s_offset); |
2782 |
tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, d_offset); |
2783 |
} |
2784 |
|
2785 |
static inline void gen_op_movl(int d_offset, int s_offset) |
2786 |
{ |
2787 |
tcg_gen_ld_i32(cpu_tmp2_i32, cpu_env, s_offset); |
2788 |
tcg_gen_st_i32(cpu_tmp2_i32, cpu_env, d_offset); |
2789 |
} |
2790 |
|
2791 |
static inline void gen_op_movq_env_0(int d_offset) |
2792 |
{ |
2793 |
tcg_gen_movi_i64(cpu_tmp1_i64, 0);
|
2794 |
tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, d_offset); |
2795 |
} |
2796 |
|
2797 |
typedef void (*SSEFunc_i_ep)(TCGv_i32 val, TCGv_ptr env, TCGv_ptr reg); |
2798 |
typedef void (*SSEFunc_l_ep)(TCGv_i64 val, TCGv_ptr env, TCGv_ptr reg); |
2799 |
typedef void (*SSEFunc_0_epi)(TCGv_ptr env, TCGv_ptr reg, TCGv_i32 val); |
2800 |
typedef void (*SSEFunc_0_epl)(TCGv_ptr env, TCGv_ptr reg, TCGv_i64 val); |
2801 |
typedef void (*SSEFunc_0_epp)(TCGv_ptr env, TCGv_ptr reg_a, TCGv_ptr reg_b); |
2802 |
typedef void (*SSEFunc_0_eppi)(TCGv_ptr env, TCGv_ptr reg_a, TCGv_ptr reg_b, |
2803 |
TCGv_i32 val); |
2804 |
typedef void (*SSEFunc_0_ppi)(TCGv_ptr reg_a, TCGv_ptr reg_b, TCGv_i32 val); |
2805 |
typedef void (*SSEFunc_0_eppt)(TCGv_ptr env, TCGv_ptr reg_a, TCGv_ptr reg_b, |
2806 |
TCGv val); |
2807 |
|
2808 |
#define SSE_SPECIAL ((void *)1) |
2809 |
#define SSE_DUMMY ((void *)2) |
2810 |
|
2811 |
#define MMX_OP2(x) { gen_helper_ ## x ## _mmx, gen_helper_ ## x ## _xmm } |
2812 |
#define SSE_FOP(x) { gen_helper_ ## x ## ps, gen_helper_ ## x ## pd, \ |
2813 |
gen_helper_ ## x ## ss, gen_helper_ ## x ## sd, } |
2814 |
|
2815 |
static const SSEFunc_0_epp sse_op_table1[256][4] = { |
2816 |
/* 3DNow! extensions */
|
2817 |
[0x0e] = { SSE_DUMMY }, /* femms */ |
2818 |
[0x0f] = { SSE_DUMMY }, /* pf... */ |
2819 |
/* pure SSE operations */
|
2820 |
[0x10] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movups, movupd, movss, movsd */ |
2821 |
[0x11] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movups, movupd, movss, movsd */ |
2822 |
[0x12] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movlps, movlpd, movsldup, movddup */ |
2823 |
[0x13] = { SSE_SPECIAL, SSE_SPECIAL }, /* movlps, movlpd */ |
2824 |
[0x14] = { gen_helper_punpckldq_xmm, gen_helper_punpcklqdq_xmm },
|
2825 |
[0x15] = { gen_helper_punpckhdq_xmm, gen_helper_punpckhqdq_xmm },
|
2826 |
[0x16] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movhps, movhpd, movshdup */ |
2827 |
[0x17] = { SSE_SPECIAL, SSE_SPECIAL }, /* movhps, movhpd */ |
2828 |
|
2829 |
[0x28] = { SSE_SPECIAL, SSE_SPECIAL }, /* movaps, movapd */ |
2830 |
[0x29] = { SSE_SPECIAL, SSE_SPECIAL }, /* movaps, movapd */ |
2831 |
[0x2a] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* cvtpi2ps, cvtpi2pd, cvtsi2ss, cvtsi2sd */ |
2832 |
[0x2b] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movntps, movntpd, movntss, movntsd */ |
2833 |
[0x2c] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* cvttps2pi, cvttpd2pi, cvttsd2si, cvttss2si */ |
2834 |
[0x2d] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* cvtps2pi, cvtpd2pi, cvtsd2si, cvtss2si */ |
2835 |
[0x2e] = { gen_helper_ucomiss, gen_helper_ucomisd },
|
2836 |
[0x2f] = { gen_helper_comiss, gen_helper_comisd },
|
2837 |
[0x50] = { SSE_SPECIAL, SSE_SPECIAL }, /* movmskps, movmskpd */ |
2838 |
[0x51] = SSE_FOP(sqrt),
|
2839 |
[0x52] = { gen_helper_rsqrtps, NULL, gen_helper_rsqrtss, NULL }, |
2840 |
[0x53] = { gen_helper_rcpps, NULL, gen_helper_rcpss, NULL }, |
2841 |
[0x54] = { gen_helper_pand_xmm, gen_helper_pand_xmm }, /* andps, andpd */ |
2842 |
[0x55] = { gen_helper_pandn_xmm, gen_helper_pandn_xmm }, /* andnps, andnpd */ |
2843 |
[0x56] = { gen_helper_por_xmm, gen_helper_por_xmm }, /* orps, orpd */ |
2844 |
[0x57] = { gen_helper_pxor_xmm, gen_helper_pxor_xmm }, /* xorps, xorpd */ |
2845 |
[0x58] = SSE_FOP(add),
|
2846 |
[0x59] = SSE_FOP(mul),
|
2847 |
[0x5a] = { gen_helper_cvtps2pd, gen_helper_cvtpd2ps,
|
2848 |
gen_helper_cvtss2sd, gen_helper_cvtsd2ss }, |
2849 |
[0x5b] = { gen_helper_cvtdq2ps, gen_helper_cvtps2dq, gen_helper_cvttps2dq },
|
2850 |
[0x5c] = SSE_FOP(sub),
|
2851 |
[0x5d] = SSE_FOP(min),
|
2852 |
[0x5e] = SSE_FOP(div),
|
2853 |
[0x5f] = SSE_FOP(max),
|
2854 |
|
2855 |
[0xc2] = SSE_FOP(cmpeq),
|
2856 |
[0xc6] = { (SSEFunc_0_epp)gen_helper_shufps,
|
2857 |
(SSEFunc_0_epp)gen_helper_shufpd }, /* XXX: casts */
|
2858 |
|
2859 |
[0x38] = { SSE_SPECIAL, SSE_SPECIAL, NULL, SSE_SPECIAL }, /* SSSE3/SSE4 */ |
2860 |
[0x3a] = { SSE_SPECIAL, SSE_SPECIAL }, /* SSSE3/SSE4 */ |
2861 |
|
2862 |
/* MMX ops and their SSE extensions */
|
2863 |
[0x60] = MMX_OP2(punpcklbw),
|
2864 |
[0x61] = MMX_OP2(punpcklwd),
|
2865 |
[0x62] = MMX_OP2(punpckldq),
|
2866 |
[0x63] = MMX_OP2(packsswb),
|
2867 |
[0x64] = MMX_OP2(pcmpgtb),
|
2868 |
[0x65] = MMX_OP2(pcmpgtw),
|
2869 |
[0x66] = MMX_OP2(pcmpgtl),
|
2870 |
[0x67] = MMX_OP2(packuswb),
|
2871 |
[0x68] = MMX_OP2(punpckhbw),
|
2872 |
[0x69] = MMX_OP2(punpckhwd),
|
2873 |
[0x6a] = MMX_OP2(punpckhdq),
|
2874 |
[0x6b] = MMX_OP2(packssdw),
|
2875 |
[0x6c] = { NULL, gen_helper_punpcklqdq_xmm }, |
2876 |
[0x6d] = { NULL, gen_helper_punpckhqdq_xmm }, |
2877 |
[0x6e] = { SSE_SPECIAL, SSE_SPECIAL }, /* movd mm, ea */ |
2878 |
[0x6f] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movq, movdqa, , movqdu */ |
2879 |
[0x70] = { (SSEFunc_0_epp)gen_helper_pshufw_mmx,
|
2880 |
(SSEFunc_0_epp)gen_helper_pshufd_xmm, |
2881 |
(SSEFunc_0_epp)gen_helper_pshufhw_xmm, |
2882 |
(SSEFunc_0_epp)gen_helper_pshuflw_xmm }, /* XXX: casts */
|
2883 |
[0x71] = { SSE_SPECIAL, SSE_SPECIAL }, /* shiftw */ |
2884 |
[0x72] = { SSE_SPECIAL, SSE_SPECIAL }, /* shiftd */ |
2885 |
[0x73] = { SSE_SPECIAL, SSE_SPECIAL }, /* shiftq */ |
2886 |
[0x74] = MMX_OP2(pcmpeqb),
|
2887 |
[0x75] = MMX_OP2(pcmpeqw),
|
2888 |
[0x76] = MMX_OP2(pcmpeql),
|
2889 |
[0x77] = { SSE_DUMMY }, /* emms */ |
2890 |
[0x78] = { NULL, SSE_SPECIAL, NULL, SSE_SPECIAL }, /* extrq_i, insertq_i */ |
2891 |
[0x79] = { NULL, gen_helper_extrq_r, NULL, gen_helper_insertq_r }, |
2892 |
[0x7c] = { NULL, gen_helper_haddpd, NULL, gen_helper_haddps }, |
2893 |
[0x7d] = { NULL, gen_helper_hsubpd, NULL, gen_helper_hsubps }, |
2894 |
[0x7e] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movd, movd, , movq */ |
2895 |
[0x7f] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movq, movdqa, movdqu */ |
2896 |
[0xc4] = { SSE_SPECIAL, SSE_SPECIAL }, /* pinsrw */ |
2897 |
[0xc5] = { SSE_SPECIAL, SSE_SPECIAL }, /* pextrw */ |
2898 |
[0xd0] = { NULL, gen_helper_addsubpd, NULL, gen_helper_addsubps }, |
2899 |
[0xd1] = MMX_OP2(psrlw),
|
2900 |
[0xd2] = MMX_OP2(psrld),
|
2901 |
[0xd3] = MMX_OP2(psrlq),
|
2902 |
[0xd4] = MMX_OP2(paddq),
|
2903 |
[0xd5] = MMX_OP2(pmullw),
|
2904 |
[0xd6] = { NULL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, |
2905 |
[0xd7] = { SSE_SPECIAL, SSE_SPECIAL }, /* pmovmskb */ |
2906 |
[0xd8] = MMX_OP2(psubusb),
|
2907 |
[0xd9] = MMX_OP2(psubusw),
|
2908 |
[0xda] = MMX_OP2(pminub),
|
2909 |
[0xdb] = MMX_OP2(pand),
|
2910 |
[0xdc] = MMX_OP2(paddusb),
|
2911 |
[0xdd] = MMX_OP2(paddusw),
|
2912 |
[0xde] = MMX_OP2(pmaxub),
|
2913 |
[0xdf] = MMX_OP2(pandn),
|
2914 |
[0xe0] = MMX_OP2(pavgb),
|
2915 |
[0xe1] = MMX_OP2(psraw),
|
2916 |
[0xe2] = MMX_OP2(psrad),
|
2917 |
[0xe3] = MMX_OP2(pavgw),
|
2918 |
[0xe4] = MMX_OP2(pmulhuw),
|
2919 |
[0xe5] = MMX_OP2(pmulhw),
|
2920 |
[0xe6] = { NULL, gen_helper_cvttpd2dq, gen_helper_cvtdq2pd, gen_helper_cvtpd2dq }, |
2921 |
[0xe7] = { SSE_SPECIAL , SSE_SPECIAL }, /* movntq, movntq */ |
2922 |
[0xe8] = MMX_OP2(psubsb),
|
2923 |
[0xe9] = MMX_OP2(psubsw),
|
2924 |
[0xea] = MMX_OP2(pminsw),
|
2925 |
[0xeb] = MMX_OP2(por),
|
2926 |
[0xec] = MMX_OP2(paddsb),
|
2927 |
[0xed] = MMX_OP2(paddsw),
|
2928 |
[0xee] = MMX_OP2(pmaxsw),
|
2929 |
[0xef] = MMX_OP2(pxor),
|
2930 |
[0xf0] = { NULL, NULL, NULL, SSE_SPECIAL }, /* lddqu */ |
2931 |
[0xf1] = MMX_OP2(psllw),
|
2932 |
[0xf2] = MMX_OP2(pslld),
|
2933 |
[0xf3] = MMX_OP2(psllq),
|
2934 |
[0xf4] = MMX_OP2(pmuludq),
|
2935 |
[0xf5] = MMX_OP2(pmaddwd),
|
2936 |
[0xf6] = MMX_OP2(psadbw),
|
2937 |
[0xf7] = { (SSEFunc_0_epp)gen_helper_maskmov_mmx,
|
2938 |
(SSEFunc_0_epp)gen_helper_maskmov_xmm }, /* XXX: casts */
|
2939 |
[0xf8] = MMX_OP2(psubb),
|
2940 |
[0xf9] = MMX_OP2(psubw),
|
2941 |
[0xfa] = MMX_OP2(psubl),
|
2942 |
[0xfb] = MMX_OP2(psubq),
|
2943 |
[0xfc] = MMX_OP2(paddb),
|
2944 |
[0xfd] = MMX_OP2(paddw),
|
2945 |
[0xfe] = MMX_OP2(paddl),
|
2946 |
}; |
2947 |
|
2948 |
static const SSEFunc_0_epp sse_op_table2[3 * 8][2] = { |
2949 |
[0 + 2] = MMX_OP2(psrlw), |
2950 |
[0 + 4] = MMX_OP2(psraw), |
2951 |
[0 + 6] = MMX_OP2(psllw), |
2952 |
[8 + 2] = MMX_OP2(psrld), |
2953 |
[8 + 4] = MMX_OP2(psrad), |
2954 |
[8 + 6] = MMX_OP2(pslld), |
2955 |
[16 + 2] = MMX_OP2(psrlq), |
2956 |
[16 + 3] = { NULL, gen_helper_psrldq_xmm }, |
2957 |
[16 + 6] = MMX_OP2(psllq), |
2958 |
[16 + 7] = { NULL, gen_helper_pslldq_xmm }, |
2959 |
}; |
2960 |
|
2961 |
static const SSEFunc_0_epi sse_op_table3ai[] = { |
2962 |
gen_helper_cvtsi2ss, |
2963 |
gen_helper_cvtsi2sd |
2964 |
}; |
2965 |
|
2966 |
#ifdef TARGET_X86_64
|
2967 |
static const SSEFunc_0_epl sse_op_table3aq[] = { |
2968 |
gen_helper_cvtsq2ss, |
2969 |
gen_helper_cvtsq2sd |
2970 |
}; |
2971 |
#endif
|
2972 |
|
2973 |
static const SSEFunc_i_ep sse_op_table3bi[] = { |
2974 |
gen_helper_cvttss2si, |
2975 |
gen_helper_cvtss2si, |
2976 |
gen_helper_cvttsd2si, |
2977 |
gen_helper_cvtsd2si |
2978 |
}; |
2979 |
|
2980 |
#ifdef TARGET_X86_64
|
2981 |
static const SSEFunc_l_ep sse_op_table3bq[] = { |
2982 |
gen_helper_cvttss2sq, |
2983 |
gen_helper_cvtss2sq, |
2984 |
gen_helper_cvttsd2sq, |
2985 |
gen_helper_cvtsd2sq |
2986 |
}; |
2987 |
#endif
|
2988 |
|
2989 |
static const SSEFunc_0_epp sse_op_table4[8][4] = { |
2990 |
SSE_FOP(cmpeq), |
2991 |
SSE_FOP(cmplt), |
2992 |
SSE_FOP(cmple), |
2993 |
SSE_FOP(cmpunord), |
2994 |
SSE_FOP(cmpneq), |
2995 |
SSE_FOP(cmpnlt), |
2996 |
SSE_FOP(cmpnle), |
2997 |
SSE_FOP(cmpord), |
2998 |
}; |
2999 |
|
3000 |
static const SSEFunc_0_epp sse_op_table5[256] = { |
3001 |
[0x0c] = gen_helper_pi2fw,
|
3002 |
[0x0d] = gen_helper_pi2fd,
|
3003 |
[0x1c] = gen_helper_pf2iw,
|
3004 |
[0x1d] = gen_helper_pf2id,
|
3005 |
[0x8a] = gen_helper_pfnacc,
|
3006 |
[0x8e] = gen_helper_pfpnacc,
|
3007 |
[0x90] = gen_helper_pfcmpge,
|
3008 |
[0x94] = gen_helper_pfmin,
|
3009 |
[0x96] = gen_helper_pfrcp,
|
3010 |
[0x97] = gen_helper_pfrsqrt,
|
3011 |
[0x9a] = gen_helper_pfsub,
|
3012 |
[0x9e] = gen_helper_pfadd,
|
3013 |
[0xa0] = gen_helper_pfcmpgt,
|
3014 |
[0xa4] = gen_helper_pfmax,
|
3015 |
[0xa6] = gen_helper_movq, /* pfrcpit1; no need to actually increase precision */ |
3016 |
[0xa7] = gen_helper_movq, /* pfrsqit1 */ |
3017 |
[0xaa] = gen_helper_pfsubr,
|
3018 |
[0xae] = gen_helper_pfacc,
|
3019 |
[0xb0] = gen_helper_pfcmpeq,
|
3020 |
[0xb4] = gen_helper_pfmul,
|
3021 |
[0xb6] = gen_helper_movq, /* pfrcpit2 */ |
3022 |
[0xb7] = gen_helper_pmulhrw_mmx,
|
3023 |
[0xbb] = gen_helper_pswapd,
|
3024 |
[0xbf] = gen_helper_pavgb_mmx /* pavgusb */ |
3025 |
}; |
3026 |
|
3027 |
struct SSEOpHelper_epp {
|
3028 |
SSEFunc_0_epp op[2];
|
3029 |
uint32_t ext_mask; |
3030 |
}; |
3031 |
|
3032 |
struct SSEOpHelper_eppi {
|
3033 |
SSEFunc_0_eppi op[2];
|
3034 |
uint32_t ext_mask; |
3035 |
}; |
3036 |
|
3037 |
#define SSSE3_OP(x) { MMX_OP2(x), CPUID_EXT_SSSE3 }
|
3038 |
#define SSE41_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE41 } |
3039 |
#define SSE42_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE42 } |
3040 |
#define SSE41_SPECIAL { { NULL, SSE_SPECIAL }, CPUID_EXT_SSE41 } |
3041 |
|
3042 |
static const struct SSEOpHelper_epp sse_op_table6[256] = { |
3043 |
[0x00] = SSSE3_OP(pshufb),
|
3044 |
[0x01] = SSSE3_OP(phaddw),
|
3045 |
[0x02] = SSSE3_OP(phaddd),
|
3046 |
[0x03] = SSSE3_OP(phaddsw),
|
3047 |
[0x04] = SSSE3_OP(pmaddubsw),
|
3048 |
[0x05] = SSSE3_OP(phsubw),
|
3049 |
[0x06] = SSSE3_OP(phsubd),
|
3050 |
[0x07] = SSSE3_OP(phsubsw),
|
3051 |
[0x08] = SSSE3_OP(psignb),
|
3052 |
[0x09] = SSSE3_OP(psignw),
|
3053 |
[0x0a] = SSSE3_OP(psignd),
|
3054 |
[0x0b] = SSSE3_OP(pmulhrsw),
|
3055 |
[0x10] = SSE41_OP(pblendvb),
|
3056 |
[0x14] = SSE41_OP(blendvps),
|
3057 |
[0x15] = SSE41_OP(blendvpd),
|
3058 |
[0x17] = SSE41_OP(ptest),
|
3059 |
[0x1c] = SSSE3_OP(pabsb),
|
3060 |
[0x1d] = SSSE3_OP(pabsw),
|
3061 |
[0x1e] = SSSE3_OP(pabsd),
|
3062 |
[0x20] = SSE41_OP(pmovsxbw),
|
3063 |
[0x21] = SSE41_OP(pmovsxbd),
|
3064 |
[0x22] = SSE41_OP(pmovsxbq),
|
3065 |
[0x23] = SSE41_OP(pmovsxwd),
|
3066 |
[0x24] = SSE41_OP(pmovsxwq),
|
3067 |
[0x25] = SSE41_OP(pmovsxdq),
|
3068 |
[0x28] = SSE41_OP(pmuldq),
|
3069 |
[0x29] = SSE41_OP(pcmpeqq),
|
3070 |
[0x2a] = SSE41_SPECIAL, /* movntqda */ |
3071 |
[0x2b] = SSE41_OP(packusdw),
|
3072 |
[0x30] = SSE41_OP(pmovzxbw),
|
3073 |
[0x31] = SSE41_OP(pmovzxbd),
|
3074 |
[0x32] = SSE41_OP(pmovzxbq),
|
3075 |
[0x33] = SSE41_OP(pmovzxwd),
|
3076 |
[0x34] = SSE41_OP(pmovzxwq),
|
3077 |
[0x35] = SSE41_OP(pmovzxdq),
|
3078 |
[0x37] = SSE42_OP(pcmpgtq),
|
3079 |
[0x38] = SSE41_OP(pminsb),
|
3080 |
[0x39] = SSE41_OP(pminsd),
|
3081 |
[0x3a] = SSE41_OP(pminuw),
|
3082 |
[0x3b] = SSE41_OP(pminud),
|
3083 |
[0x3c] = SSE41_OP(pmaxsb),
|
3084 |
[0x3d] = SSE41_OP(pmaxsd),
|
3085 |
[0x3e] = SSE41_OP(pmaxuw),
|
3086 |
[0x3f] = SSE41_OP(pmaxud),
|
3087 |
[0x40] = SSE41_OP(pmulld),
|
3088 |
[0x41] = SSE41_OP(phminposuw),
|
3089 |
}; |
3090 |
|
3091 |
static const struct SSEOpHelper_eppi sse_op_table7[256] = { |
3092 |
[0x08] = SSE41_OP(roundps),
|
3093 |
[0x09] = SSE41_OP(roundpd),
|
3094 |
[0x0a] = SSE41_OP(roundss),
|
3095 |
[0x0b] = SSE41_OP(roundsd),
|
3096 |
[0x0c] = SSE41_OP(blendps),
|
3097 |
[0x0d] = SSE41_OP(blendpd),
|
3098 |
[0x0e] = SSE41_OP(pblendw),
|
3099 |
[0x0f] = SSSE3_OP(palignr),
|
3100 |
[0x14] = SSE41_SPECIAL, /* pextrb */ |
3101 |
[0x15] = SSE41_SPECIAL, /* pextrw */ |
3102 |
[0x16] = SSE41_SPECIAL, /* pextrd/pextrq */ |
3103 |
[0x17] = SSE41_SPECIAL, /* extractps */ |
3104 |
[0x20] = SSE41_SPECIAL, /* pinsrb */ |
3105 |
[0x21] = SSE41_SPECIAL, /* insertps */ |
3106 |
[0x22] = SSE41_SPECIAL, /* pinsrd/pinsrq */ |
3107 |
[0x40] = SSE41_OP(dpps),
|
3108 |
[0x41] = SSE41_OP(dppd),
|
3109 |
[0x42] = SSE41_OP(mpsadbw),
|
3110 |
[0x60] = SSE42_OP(pcmpestrm),
|
3111 |
[0x61] = SSE42_OP(pcmpestri),
|
3112 |
[0x62] = SSE42_OP(pcmpistrm),
|
3113 |
[0x63] = SSE42_OP(pcmpistri),
|
3114 |
}; |
3115 |
|
3116 |
static void gen_sse(CPUX86State *env, DisasContext *s, int b, |
3117 |
target_ulong pc_start, int rex_r)
|
3118 |
{ |
3119 |
int b1, op1_offset, op2_offset, is_xmm, val, ot;
|
3120 |
int modrm, mod, rm, reg, reg_addr, offset_addr;
|
3121 |
SSEFunc_0_epp sse_fn_epp; |
3122 |
SSEFunc_0_eppi sse_fn_eppi; |
3123 |
SSEFunc_0_ppi sse_fn_ppi; |
3124 |
SSEFunc_0_eppt sse_fn_eppt; |
3125 |
|
3126 |
b &= 0xff;
|
3127 |
if (s->prefix & PREFIX_DATA)
|
3128 |
b1 = 1;
|
3129 |
else if (s->prefix & PREFIX_REPZ) |
3130 |
b1 = 2;
|
3131 |
else if (s->prefix & PREFIX_REPNZ) |
3132 |
b1 = 3;
|
3133 |
else
|
3134 |
b1 = 0;
|
3135 |
sse_fn_epp = sse_op_table1[b][b1]; |
3136 |
if (!sse_fn_epp) {
|
3137 |
goto illegal_op;
|
3138 |
} |
3139 |
if ((b <= 0x5f && b >= 0x10) || b == 0xc6 || b == 0xc2) { |
3140 |
is_xmm = 1;
|
3141 |
} else {
|
3142 |
if (b1 == 0) { |
3143 |
/* MMX case */
|
3144 |
is_xmm = 0;
|
3145 |
} else {
|
3146 |
is_xmm = 1;
|
3147 |
} |
3148 |
} |
3149 |
/* simple MMX/SSE operation */
|
3150 |
if (s->flags & HF_TS_MASK) {
|
3151 |
gen_exception(s, EXCP07_PREX, pc_start - s->cs_base); |
3152 |
return;
|
3153 |
} |
3154 |
if (s->flags & HF_EM_MASK) {
|
3155 |
illegal_op:
|
3156 |
gen_exception(s, EXCP06_ILLOP, pc_start - s->cs_base); |
3157 |
return;
|
3158 |
} |
3159 |
if (is_xmm && !(s->flags & HF_OSFXSR_MASK))
|
3160 |
if ((b != 0x38 && b != 0x3a) || (s->prefix & PREFIX_DATA)) |
3161 |
goto illegal_op;
|
3162 |
if (b == 0x0e) { |
3163 |
if (!(s->cpuid_ext2_features & CPUID_EXT2_3DNOW))
|
3164 |
goto illegal_op;
|
3165 |
/* femms */
|
3166 |
gen_helper_emms(cpu_env); |
3167 |
return;
|
3168 |
} |
3169 |
if (b == 0x77) { |
3170 |
/* emms */
|
3171 |
gen_helper_emms(cpu_env); |
3172 |
return;
|
3173 |
} |
3174 |
/* prepare MMX state (XXX: optimize by storing fptt and fptags in
|
3175 |
the static cpu state) */
|
3176 |
if (!is_xmm) {
|
3177 |
gen_helper_enter_mmx(cpu_env); |
3178 |
} |
3179 |
|
3180 |
modrm = cpu_ldub_code(env, s->pc++); |
3181 |
reg = ((modrm >> 3) & 7); |
3182 |
if (is_xmm)
|
3183 |
reg |= rex_r; |
3184 |
mod = (modrm >> 6) & 3; |
3185 |
if (sse_fn_epp == SSE_SPECIAL) {
|
3186 |
b |= (b1 << 8);
|
3187 |
switch(b) {
|
3188 |
case 0x0e7: /* movntq */ |
3189 |
if (mod == 3) |
3190 |
goto illegal_op;
|
3191 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3192 |
gen_stq_env_A0(s->mem_index, offsetof(CPUX86State,fpregs[reg].mmx)); |
3193 |
break;
|
3194 |
case 0x1e7: /* movntdq */ |
3195 |
case 0x02b: /* movntps */ |
3196 |
case 0x12b: /* movntps */ |
3197 |
if (mod == 3) |
3198 |
goto illegal_op;
|
3199 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3200 |
gen_sto_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg])); |
3201 |
break;
|
3202 |
case 0x3f0: /* lddqu */ |
3203 |
if (mod == 3) |
3204 |
goto illegal_op;
|
3205 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3206 |
gen_ldo_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg])); |
3207 |
break;
|
3208 |
case 0x22b: /* movntss */ |
3209 |
case 0x32b: /* movntsd */ |
3210 |
if (mod == 3) |
3211 |
goto illegal_op;
|
3212 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3213 |
if (b1 & 1) { |
3214 |
gen_stq_env_A0(s->mem_index, offsetof(CPUX86State, |
3215 |
xmm_regs[reg])); |
3216 |
} else {
|
3217 |
tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,
|
3218 |
xmm_regs[reg].XMM_L(0)));
|
3219 |
gen_op_st_T0_A0(OT_LONG + s->mem_index); |
3220 |
} |
3221 |
break;
|
3222 |
case 0x6e: /* movd mm, ea */ |
3223 |
#ifdef TARGET_X86_64
|
3224 |
if (s->dflag == 2) { |
3225 |
gen_ldst_modrm(env, s, modrm, OT_QUAD, OR_TMP0, 0);
|
3226 |
tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,fpregs[reg].mmx));
|
3227 |
} else
|
3228 |
#endif
|
3229 |
{ |
3230 |
gen_ldst_modrm(env, s, modrm, OT_LONG, OR_TMP0, 0);
|
3231 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, |
3232 |
offsetof(CPUX86State,fpregs[reg].mmx)); |
3233 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
3234 |
gen_helper_movl_mm_T0_mmx(cpu_ptr0, cpu_tmp2_i32); |
3235 |
} |
3236 |
break;
|
3237 |
case 0x16e: /* movd xmm, ea */ |
3238 |
#ifdef TARGET_X86_64
|
3239 |
if (s->dflag == 2) { |
3240 |
gen_ldst_modrm(env, s, modrm, OT_QUAD, OR_TMP0, 0);
|
3241 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, |
3242 |
offsetof(CPUX86State,xmm_regs[reg])); |
3243 |
gen_helper_movq_mm_T0_xmm(cpu_ptr0, cpu_T[0]);
|
3244 |
} else
|
3245 |
#endif
|
3246 |
{ |
3247 |
gen_ldst_modrm(env, s, modrm, OT_LONG, OR_TMP0, 0);
|
3248 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, |
3249 |
offsetof(CPUX86State,xmm_regs[reg])); |
3250 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
3251 |
gen_helper_movl_mm_T0_xmm(cpu_ptr0, cpu_tmp2_i32); |
3252 |
} |
3253 |
break;
|
3254 |
case 0x6f: /* movq mm, ea */ |
3255 |
if (mod != 3) { |
3256 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3257 |
gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,fpregs[reg].mmx)); |
3258 |
} else {
|
3259 |
rm = (modrm & 7);
|
3260 |
tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, |
3261 |
offsetof(CPUX86State,fpregs[rm].mmx)); |
3262 |
tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, |
3263 |
offsetof(CPUX86State,fpregs[reg].mmx)); |
3264 |
} |
3265 |
break;
|
3266 |
case 0x010: /* movups */ |
3267 |
case 0x110: /* movupd */ |
3268 |
case 0x028: /* movaps */ |
3269 |
case 0x128: /* movapd */ |
3270 |
case 0x16f: /* movdqa xmm, ea */ |
3271 |
case 0x26f: /* movdqu xmm, ea */ |
3272 |
if (mod != 3) { |
3273 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3274 |
gen_ldo_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg])); |
3275 |
} else {
|
3276 |
rm = (modrm & 7) | REX_B(s);
|
3277 |
gen_op_movo(offsetof(CPUX86State,xmm_regs[reg]), |
3278 |
offsetof(CPUX86State,xmm_regs[rm])); |
3279 |
} |
3280 |
break;
|
3281 |
case 0x210: /* movss xmm, ea */ |
3282 |
if (mod != 3) { |
3283 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3284 |
gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
3285 |
tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(0))); |
3286 |
gen_op_movl_T0_0(); |
3287 |
tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(1))); |
3288 |
tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(2))); |
3289 |
tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(3))); |
3290 |
} else {
|
3291 |
rm = (modrm & 7) | REX_B(s);
|
3292 |
gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(0)),
|
3293 |
offsetof(CPUX86State,xmm_regs[rm].XMM_L(0)));
|
3294 |
} |
3295 |
break;
|
3296 |
case 0x310: /* movsd xmm, ea */ |
3297 |
if (mod != 3) { |
3298 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3299 |
gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3300 |
gen_op_movl_T0_0(); |
3301 |
tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(2))); |
3302 |
tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(3))); |
3303 |
} else {
|
3304 |
rm = (modrm & 7) | REX_B(s);
|
3305 |
gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)),
|
3306 |
offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)));
|
3307 |
} |
3308 |
break;
|
3309 |
case 0x012: /* movlps */ |
3310 |
case 0x112: /* movlpd */ |
3311 |
if (mod != 3) { |
3312 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3313 |
gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3314 |
} else {
|
3315 |
/* movhlps */
|
3316 |
rm = (modrm & 7) | REX_B(s);
|
3317 |
gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)),
|
3318 |
offsetof(CPUX86State,xmm_regs[rm].XMM_Q(1)));
|
3319 |
} |
3320 |
break;
|
3321 |
case 0x212: /* movsldup */ |
3322 |
if (mod != 3) { |
3323 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3324 |
gen_ldo_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg])); |
3325 |
} else {
|
3326 |
rm = (modrm & 7) | REX_B(s);
|
3327 |
gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(0)),
|
3328 |
offsetof(CPUX86State,xmm_regs[rm].XMM_L(0)));
|
3329 |
gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(2)),
|
3330 |
offsetof(CPUX86State,xmm_regs[rm].XMM_L(2)));
|
3331 |
} |
3332 |
gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(1)),
|
3333 |
offsetof(CPUX86State,xmm_regs[reg].XMM_L(0)));
|
3334 |
gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(3)),
|
3335 |
offsetof(CPUX86State,xmm_regs[reg].XMM_L(2)));
|
3336 |
break;
|
3337 |
case 0x312: /* movddup */ |
3338 |
if (mod != 3) { |
3339 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3340 |
gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3341 |
} else {
|
3342 |
rm = (modrm & 7) | REX_B(s);
|
3343 |
gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)),
|
3344 |
offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)));
|
3345 |
} |
3346 |
gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(1)),
|
3347 |
offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3348 |
break;
|
3349 |
case 0x016: /* movhps */ |
3350 |
case 0x116: /* movhpd */ |
3351 |
if (mod != 3) { |
3352 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3353 |
gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(1)));
|
3354 |
} else {
|
3355 |
/* movlhps */
|
3356 |
rm = (modrm & 7) | REX_B(s);
|
3357 |
gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(1)),
|
3358 |
offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)));
|
3359 |
} |
3360 |
break;
|
3361 |
case 0x216: /* movshdup */ |
3362 |
if (mod != 3) { |
3363 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3364 |
gen_ldo_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg])); |
3365 |
} else {
|
3366 |
rm = (modrm & 7) | REX_B(s);
|
3367 |
gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(1)),
|
3368 |
offsetof(CPUX86State,xmm_regs[rm].XMM_L(1)));
|
3369 |
gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(3)),
|
3370 |
offsetof(CPUX86State,xmm_regs[rm].XMM_L(3)));
|
3371 |
} |
3372 |
gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(0)),
|
3373 |
offsetof(CPUX86State,xmm_regs[reg].XMM_L(1)));
|
3374 |
gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(2)),
|
3375 |
offsetof(CPUX86State,xmm_regs[reg].XMM_L(3)));
|
3376 |
break;
|
3377 |
case 0x178: |
3378 |
case 0x378: |
3379 |
{ |
3380 |
int bit_index, field_length;
|
3381 |
|
3382 |
if (b1 == 1 && reg != 0) |
3383 |
goto illegal_op;
|
3384 |
field_length = cpu_ldub_code(env, s->pc++) & 0x3F;
|
3385 |
bit_index = cpu_ldub_code(env, s->pc++) & 0x3F;
|
3386 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, |
3387 |
offsetof(CPUX86State,xmm_regs[reg])); |
3388 |
if (b1 == 1) |
3389 |
gen_helper_extrq_i(cpu_env, cpu_ptr0, |
3390 |
tcg_const_i32(bit_index), |
3391 |
tcg_const_i32(field_length)); |
3392 |
else
|
3393 |
gen_helper_insertq_i(cpu_env, cpu_ptr0, |
3394 |
tcg_const_i32(bit_index), |
3395 |
tcg_const_i32(field_length)); |
3396 |
} |
3397 |
break;
|
3398 |
case 0x7e: /* movd ea, mm */ |
3399 |
#ifdef TARGET_X86_64
|
3400 |
if (s->dflag == 2) { |
3401 |
tcg_gen_ld_i64(cpu_T[0], cpu_env,
|
3402 |
offsetof(CPUX86State,fpregs[reg].mmx)); |
3403 |
gen_ldst_modrm(env, s, modrm, OT_QUAD, OR_TMP0, 1);
|
3404 |
} else
|
3405 |
#endif
|
3406 |
{ |
3407 |
tcg_gen_ld32u_tl(cpu_T[0], cpu_env,
|
3408 |
offsetof(CPUX86State,fpregs[reg].mmx.MMX_L(0)));
|
3409 |
gen_ldst_modrm(env, s, modrm, OT_LONG, OR_TMP0, 1);
|
3410 |
} |
3411 |
break;
|
3412 |
case 0x17e: /* movd ea, xmm */ |
3413 |
#ifdef TARGET_X86_64
|
3414 |
if (s->dflag == 2) { |
3415 |
tcg_gen_ld_i64(cpu_T[0], cpu_env,
|
3416 |
offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3417 |
gen_ldst_modrm(env, s, modrm, OT_QUAD, OR_TMP0, 1);
|
3418 |
} else
|
3419 |
#endif
|
3420 |
{ |
3421 |
tcg_gen_ld32u_tl(cpu_T[0], cpu_env,
|
3422 |
offsetof(CPUX86State,xmm_regs[reg].XMM_L(0)));
|
3423 |
gen_ldst_modrm(env, s, modrm, OT_LONG, OR_TMP0, 1);
|
3424 |
} |
3425 |
break;
|
3426 |
case 0x27e: /* movq xmm, ea */ |
3427 |
if (mod != 3) { |
3428 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3429 |
gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3430 |
} else {
|
3431 |
rm = (modrm & 7) | REX_B(s);
|
3432 |
gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)),
|
3433 |
offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)));
|
3434 |
} |
3435 |
gen_op_movq_env_0(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(1)));
|
3436 |
break;
|
3437 |
case 0x7f: /* movq ea, mm */ |
3438 |
if (mod != 3) { |
3439 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3440 |
gen_stq_env_A0(s->mem_index, offsetof(CPUX86State,fpregs[reg].mmx)); |
3441 |
} else {
|
3442 |
rm = (modrm & 7);
|
3443 |
gen_op_movq(offsetof(CPUX86State,fpregs[rm].mmx), |
3444 |
offsetof(CPUX86State,fpregs[reg].mmx)); |
3445 |
} |
3446 |
break;
|
3447 |
case 0x011: /* movups */ |
3448 |
case 0x111: /* movupd */ |
3449 |
case 0x029: /* movaps */ |
3450 |
case 0x129: /* movapd */ |
3451 |
case 0x17f: /* movdqa ea, xmm */ |
3452 |
case 0x27f: /* movdqu ea, xmm */ |
3453 |
if (mod != 3) { |
3454 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3455 |
gen_sto_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg])); |
3456 |
} else {
|
3457 |
rm = (modrm & 7) | REX_B(s);
|
3458 |
gen_op_movo(offsetof(CPUX86State,xmm_regs[rm]), |
3459 |
offsetof(CPUX86State,xmm_regs[reg])); |
3460 |
} |
3461 |
break;
|
3462 |
case 0x211: /* movss ea, xmm */ |
3463 |
if (mod != 3) { |
3464 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3465 |
tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(0))); |
3466 |
gen_op_st_T0_A0(OT_LONG + s->mem_index); |
3467 |
} else {
|
3468 |
rm = (modrm & 7) | REX_B(s);
|
3469 |
gen_op_movl(offsetof(CPUX86State,xmm_regs[rm].XMM_L(0)),
|
3470 |
offsetof(CPUX86State,xmm_regs[reg].XMM_L(0)));
|
3471 |
} |
3472 |
break;
|
3473 |
case 0x311: /* movsd ea, xmm */ |
3474 |
if (mod != 3) { |
3475 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3476 |
gen_stq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3477 |
} else {
|
3478 |
rm = (modrm & 7) | REX_B(s);
|
3479 |
gen_op_movq(offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)),
|
3480 |
offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3481 |
} |
3482 |
break;
|
3483 |
case 0x013: /* movlps */ |
3484 |
case 0x113: /* movlpd */ |
3485 |
if (mod != 3) { |
3486 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3487 |
gen_stq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3488 |
} else {
|
3489 |
goto illegal_op;
|
3490 |
} |
3491 |
break;
|
3492 |
case 0x017: /* movhps */ |
3493 |
case 0x117: /* movhpd */ |
3494 |
if (mod != 3) { |
3495 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3496 |
gen_stq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(1)));
|
3497 |
} else {
|
3498 |
goto illegal_op;
|
3499 |
} |
3500 |
break;
|
3501 |
case 0x71: /* shift mm, im */ |
3502 |
case 0x72: |
3503 |
case 0x73: |
3504 |
case 0x171: /* shift xmm, im */ |
3505 |
case 0x172: |
3506 |
case 0x173: |
3507 |
if (b1 >= 2) { |
3508 |
goto illegal_op;
|
3509 |
} |
3510 |
val = cpu_ldub_code(env, s->pc++); |
3511 |
if (is_xmm) {
|
3512 |
gen_op_movl_T0_im(val); |
3513 |
tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_t0.XMM_L(0))); |
3514 |
gen_op_movl_T0_0(); |
3515 |
tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_t0.XMM_L(1))); |
3516 |
op1_offset = offsetof(CPUX86State,xmm_t0); |
3517 |
} else {
|
3518 |
gen_op_movl_T0_im(val); |
3519 |
tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,mmx_t0.MMX_L(0))); |
3520 |
gen_op_movl_T0_0(); |
3521 |
tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,mmx_t0.MMX_L(1))); |
3522 |
op1_offset = offsetof(CPUX86State,mmx_t0); |
3523 |
} |
3524 |
sse_fn_epp = sse_op_table2[((b - 1) & 3) * 8 + |
3525 |
(((modrm >> 3)) & 7)][b1]; |
3526 |
if (!sse_fn_epp) {
|
3527 |
goto illegal_op;
|
3528 |
} |
3529 |
if (is_xmm) {
|
3530 |
rm = (modrm & 7) | REX_B(s);
|
3531 |
op2_offset = offsetof(CPUX86State,xmm_regs[rm]); |
3532 |
} else {
|
3533 |
rm = (modrm & 7);
|
3534 |
op2_offset = offsetof(CPUX86State,fpregs[rm].mmx); |
3535 |
} |
3536 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op2_offset); |
3537 |
tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op1_offset); |
3538 |
sse_fn_epp(cpu_env, cpu_ptr0, cpu_ptr1); |
3539 |
break;
|
3540 |
case 0x050: /* movmskps */ |
3541 |
rm = (modrm & 7) | REX_B(s);
|
3542 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, |
3543 |
offsetof(CPUX86State,xmm_regs[rm])); |
3544 |
gen_helper_movmskps(cpu_tmp2_i32, cpu_env, cpu_ptr0); |
3545 |
tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
3546 |
gen_op_mov_reg_T0(OT_LONG, reg); |
3547 |
break;
|
3548 |
case 0x150: /* movmskpd */ |
3549 |
rm = (modrm & 7) | REX_B(s);
|
3550 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, |
3551 |
offsetof(CPUX86State,xmm_regs[rm])); |
3552 |
gen_helper_movmskpd(cpu_tmp2_i32, cpu_env, cpu_ptr0); |
3553 |
tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
3554 |
gen_op_mov_reg_T0(OT_LONG, reg); |
3555 |
break;
|
3556 |
case 0x02a: /* cvtpi2ps */ |
3557 |
case 0x12a: /* cvtpi2pd */ |
3558 |
gen_helper_enter_mmx(cpu_env); |
3559 |
if (mod != 3) { |
3560 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3561 |
op2_offset = offsetof(CPUX86State,mmx_t0); |
3562 |
gen_ldq_env_A0(s->mem_index, op2_offset); |
3563 |
} else {
|
3564 |
rm = (modrm & 7);
|
3565 |
op2_offset = offsetof(CPUX86State,fpregs[rm].mmx); |
3566 |
} |
3567 |
op1_offset = offsetof(CPUX86State,xmm_regs[reg]); |
3568 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
3569 |
tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
3570 |
switch(b >> 8) { |
3571 |
case 0x0: |
3572 |
gen_helper_cvtpi2ps(cpu_env, cpu_ptr0, cpu_ptr1); |
3573 |
break;
|
3574 |
default:
|
3575 |
case 0x1: |
3576 |
gen_helper_cvtpi2pd(cpu_env, cpu_ptr0, cpu_ptr1); |
3577 |
break;
|
3578 |
} |
3579 |
break;
|
3580 |
case 0x22a: /* cvtsi2ss */ |
3581 |
case 0x32a: /* cvtsi2sd */ |
3582 |
ot = (s->dflag == 2) ? OT_QUAD : OT_LONG;
|
3583 |
gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0);
|
3584 |
op1_offset = offsetof(CPUX86State,xmm_regs[reg]); |
3585 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
3586 |
if (ot == OT_LONG) {
|
3587 |
SSEFunc_0_epi sse_fn_epi = sse_op_table3ai[(b >> 8) & 1]; |
3588 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
3589 |
sse_fn_epi(cpu_env, cpu_ptr0, cpu_tmp2_i32); |
3590 |
} else {
|
3591 |
#ifdef TARGET_X86_64
|
3592 |
SSEFunc_0_epl sse_fn_epl = sse_op_table3aq[(b >> 8) & 1]; |
3593 |
sse_fn_epl(cpu_env, cpu_ptr0, cpu_T[0]);
|
3594 |
#else
|
3595 |
goto illegal_op;
|
3596 |
#endif
|
3597 |
} |
3598 |
break;
|
3599 |
case 0x02c: /* cvttps2pi */ |
3600 |
case 0x12c: /* cvttpd2pi */ |
3601 |
case 0x02d: /* cvtps2pi */ |
3602 |
case 0x12d: /* cvtpd2pi */ |
3603 |
gen_helper_enter_mmx(cpu_env); |
3604 |
if (mod != 3) { |
3605 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3606 |
op2_offset = offsetof(CPUX86State,xmm_t0); |
3607 |
gen_ldo_env_A0(s->mem_index, op2_offset); |
3608 |
} else {
|
3609 |
rm = (modrm & 7) | REX_B(s);
|
3610 |
op2_offset = offsetof(CPUX86State,xmm_regs[rm]); |
3611 |
} |
3612 |
op1_offset = offsetof(CPUX86State,fpregs[reg & 7].mmx);
|
3613 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
3614 |
tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
3615 |
switch(b) {
|
3616 |
case 0x02c: |
3617 |
gen_helper_cvttps2pi(cpu_env, cpu_ptr0, cpu_ptr1); |
3618 |
break;
|
3619 |
case 0x12c: |
3620 |
gen_helper_cvttpd2pi(cpu_env, cpu_ptr0, cpu_ptr1); |
3621 |
break;
|
3622 |
case 0x02d: |
3623 |
gen_helper_cvtps2pi(cpu_env, cpu_ptr0, cpu_ptr1); |
3624 |
break;
|
3625 |
case 0x12d: |
3626 |
gen_helper_cvtpd2pi(cpu_env, cpu_ptr0, cpu_ptr1); |
3627 |
break;
|
3628 |
} |
3629 |
break;
|
3630 |
case 0x22c: /* cvttss2si */ |
3631 |
case 0x32c: /* cvttsd2si */ |
3632 |
case 0x22d: /* cvtss2si */ |
3633 |
case 0x32d: /* cvtsd2si */ |
3634 |
ot = (s->dflag == 2) ? OT_QUAD : OT_LONG;
|
3635 |
if (mod != 3) { |
3636 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3637 |
if ((b >> 8) & 1) { |
3638 |
gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_t0.XMM_Q(0)));
|
3639 |
} else {
|
3640 |
gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
3641 |
tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_t0.XMM_L(0))); |
3642 |
} |
3643 |
op2_offset = offsetof(CPUX86State,xmm_t0); |
3644 |
} else {
|
3645 |
rm = (modrm & 7) | REX_B(s);
|
3646 |
op2_offset = offsetof(CPUX86State,xmm_regs[rm]); |
3647 |
} |
3648 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op2_offset); |
3649 |
if (ot == OT_LONG) {
|
3650 |
SSEFunc_i_ep sse_fn_i_ep = |
3651 |
sse_op_table3bi[((b >> 7) & 2) | (b & 1)]; |
3652 |
sse_fn_i_ep(cpu_tmp2_i32, cpu_env, cpu_ptr0); |
3653 |
tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
3654 |
} else {
|
3655 |
#ifdef TARGET_X86_64
|
3656 |
SSEFunc_l_ep sse_fn_l_ep = |
3657 |
sse_op_table3bq[((b >> 7) & 2) | (b & 1)]; |
3658 |
sse_fn_l_ep(cpu_T[0], cpu_env, cpu_ptr0);
|
3659 |
#else
|
3660 |
goto illegal_op;
|
3661 |
#endif
|
3662 |
} |
3663 |
gen_op_mov_reg_T0(ot, reg); |
3664 |
break;
|
3665 |
case 0xc4: /* pinsrw */ |
3666 |
case 0x1c4: |
3667 |
s->rip_offset = 1;
|
3668 |
gen_ldst_modrm(env, s, modrm, OT_WORD, OR_TMP0, 0);
|
3669 |
val = cpu_ldub_code(env, s->pc++); |
3670 |
if (b1) {
|
3671 |
val &= 7;
|
3672 |
tcg_gen_st16_tl(cpu_T[0], cpu_env,
|
3673 |
offsetof(CPUX86State,xmm_regs[reg].XMM_W(val))); |
3674 |
} else {
|
3675 |
val &= 3;
|
3676 |
tcg_gen_st16_tl(cpu_T[0], cpu_env,
|
3677 |
offsetof(CPUX86State,fpregs[reg].mmx.MMX_W(val))); |
3678 |
} |
3679 |
break;
|
3680 |
case 0xc5: /* pextrw */ |
3681 |
case 0x1c5: |
3682 |
if (mod != 3) |
3683 |
goto illegal_op;
|
3684 |
ot = (s->dflag == 2) ? OT_QUAD : OT_LONG;
|
3685 |
val = cpu_ldub_code(env, s->pc++); |
3686 |
if (b1) {
|
3687 |
val &= 7;
|
3688 |
rm = (modrm & 7) | REX_B(s);
|
3689 |
tcg_gen_ld16u_tl(cpu_T[0], cpu_env,
|
3690 |
offsetof(CPUX86State,xmm_regs[rm].XMM_W(val))); |
3691 |
} else {
|
3692 |
val &= 3;
|
3693 |
rm = (modrm & 7);
|
3694 |
tcg_gen_ld16u_tl(cpu_T[0], cpu_env,
|
3695 |
offsetof(CPUX86State,fpregs[rm].mmx.MMX_W(val))); |
3696 |
} |
3697 |
reg = ((modrm >> 3) & 7) | rex_r; |
3698 |
gen_op_mov_reg_T0(ot, reg); |
3699 |
break;
|
3700 |
case 0x1d6: /* movq ea, xmm */ |
3701 |
if (mod != 3) { |
3702 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3703 |
gen_stq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3704 |
} else {
|
3705 |
rm = (modrm & 7) | REX_B(s);
|
3706 |
gen_op_movq(offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)),
|
3707 |
offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3708 |
gen_op_movq_env_0(offsetof(CPUX86State,xmm_regs[rm].XMM_Q(1)));
|
3709 |
} |
3710 |
break;
|
3711 |
case 0x2d6: /* movq2dq */ |
3712 |
gen_helper_enter_mmx(cpu_env); |
3713 |
rm = (modrm & 7);
|
3714 |
gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)),
|
3715 |
offsetof(CPUX86State,fpregs[rm].mmx)); |
3716 |
gen_op_movq_env_0(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(1)));
|
3717 |
break;
|
3718 |
case 0x3d6: /* movdq2q */ |
3719 |
gen_helper_enter_mmx(cpu_env); |
3720 |
rm = (modrm & 7) | REX_B(s);
|
3721 |
gen_op_movq(offsetof(CPUX86State,fpregs[reg & 7].mmx),
|
3722 |
offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)));
|
3723 |
break;
|
3724 |
case 0xd7: /* pmovmskb */ |
3725 |
case 0x1d7: |
3726 |
if (mod != 3) |
3727 |
goto illegal_op;
|
3728 |
if (b1) {
|
3729 |
rm = (modrm & 7) | REX_B(s);
|
3730 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, offsetof(CPUX86State,xmm_regs[rm])); |
3731 |
gen_helper_pmovmskb_xmm(cpu_tmp2_i32, cpu_env, cpu_ptr0); |
3732 |
} else {
|
3733 |
rm = (modrm & 7);
|
3734 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, offsetof(CPUX86State,fpregs[rm].mmx)); |
3735 |
gen_helper_pmovmskb_mmx(cpu_tmp2_i32, cpu_env, cpu_ptr0); |
3736 |
} |
3737 |
tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
3738 |
reg = ((modrm >> 3) & 7) | rex_r; |
3739 |
gen_op_mov_reg_T0(OT_LONG, reg); |
3740 |
break;
|
3741 |
case 0x138: |
3742 |
if (s->prefix & PREFIX_REPNZ)
|
3743 |
goto crc32;
|
3744 |
case 0x038: |
3745 |
b = modrm; |
3746 |
modrm = cpu_ldub_code(env, s->pc++); |
3747 |
rm = modrm & 7;
|
3748 |
reg = ((modrm >> 3) & 7) | rex_r; |
3749 |
mod = (modrm >> 6) & 3; |
3750 |
if (b1 >= 2) { |
3751 |
goto illegal_op;
|
3752 |
} |
3753 |
|
3754 |
sse_fn_epp = sse_op_table6[b].op[b1]; |
3755 |
if (!sse_fn_epp) {
|
3756 |
goto illegal_op;
|
3757 |
} |
3758 |
if (!(s->cpuid_ext_features & sse_op_table6[b].ext_mask))
|
3759 |
goto illegal_op;
|
3760 |
|
3761 |
if (b1) {
|
3762 |
op1_offset = offsetof(CPUX86State,xmm_regs[reg]); |
3763 |
if (mod == 3) { |
3764 |
op2_offset = offsetof(CPUX86State,xmm_regs[rm | REX_B(s)]); |
3765 |
} else {
|
3766 |
op2_offset = offsetof(CPUX86State,xmm_t0); |
3767 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3768 |
switch (b) {
|
3769 |
case 0x20: case 0x30: /* pmovsxbw, pmovzxbw */ |
3770 |
case 0x23: case 0x33: /* pmovsxwd, pmovzxwd */ |
3771 |
case 0x25: case 0x35: /* pmovsxdq, pmovzxdq */ |
3772 |
gen_ldq_env_A0(s->mem_index, op2_offset + |
3773 |
offsetof(XMMReg, XMM_Q(0)));
|
3774 |
break;
|
3775 |
case 0x21: case 0x31: /* pmovsxbd, pmovzxbd */ |
3776 |
case 0x24: case 0x34: /* pmovsxwq, pmovzxwq */ |
3777 |
tcg_gen_qemu_ld32u(cpu_tmp0, cpu_A0, |
3778 |
(s->mem_index >> 2) - 1); |
3779 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_tmp0); |
3780 |
tcg_gen_st_i32(cpu_tmp2_i32, cpu_env, op2_offset + |
3781 |
offsetof(XMMReg, XMM_L(0)));
|
3782 |
break;
|
3783 |
case 0x22: case 0x32: /* pmovsxbq, pmovzxbq */ |
3784 |
tcg_gen_qemu_ld16u(cpu_tmp0, cpu_A0, |
3785 |
(s->mem_index >> 2) - 1); |
3786 |
tcg_gen_st16_tl(cpu_tmp0, cpu_env, op2_offset + |
3787 |
offsetof(XMMReg, XMM_W(0)));
|
3788 |
break;
|
3789 |
case 0x2a: /* movntqda */ |
3790 |
gen_ldo_env_A0(s->mem_index, op1_offset); |
3791 |
return;
|
3792 |
default:
|
3793 |
gen_ldo_env_A0(s->mem_index, op2_offset); |
3794 |
} |
3795 |
} |
3796 |
} else {
|
3797 |
op1_offset = offsetof(CPUX86State,fpregs[reg].mmx); |
3798 |
if (mod == 3) { |
3799 |
op2_offset = offsetof(CPUX86State,fpregs[rm].mmx); |
3800 |
} else {
|
3801 |
op2_offset = offsetof(CPUX86State,mmx_t0); |
3802 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3803 |
gen_ldq_env_A0(s->mem_index, op2_offset); |
3804 |
} |
3805 |
} |
3806 |
if (sse_fn_epp == SSE_SPECIAL) {
|
3807 |
goto illegal_op;
|
3808 |
} |
3809 |
|
3810 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
3811 |
tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
3812 |
sse_fn_epp(cpu_env, cpu_ptr0, cpu_ptr1); |
3813 |
|
3814 |
if (b == 0x17) |
3815 |
s->cc_op = CC_OP_EFLAGS; |
3816 |
break;
|
3817 |
case 0x338: /* crc32 */ |
3818 |
crc32:
|
3819 |
b = modrm; |
3820 |
modrm = cpu_ldub_code(env, s->pc++); |
3821 |
reg = ((modrm >> 3) & 7) | rex_r; |
3822 |
|
3823 |
if (b != 0xf0 && b != 0xf1) |
3824 |
goto illegal_op;
|
3825 |
if (!(s->cpuid_ext_features & CPUID_EXT_SSE42))
|
3826 |
goto illegal_op;
|
3827 |
|
3828 |
if (b == 0xf0) |
3829 |
ot = OT_BYTE; |
3830 |
else if (b == 0xf1 && s->dflag != 2) |
3831 |
if (s->prefix & PREFIX_DATA)
|
3832 |
ot = OT_WORD; |
3833 |
else
|
3834 |
ot = OT_LONG; |
3835 |
else
|
3836 |
ot = OT_QUAD; |
3837 |
|
3838 |
gen_op_mov_TN_reg(OT_LONG, 0, reg);
|
3839 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
3840 |
gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0);
|
3841 |
gen_helper_crc32(cpu_T[0], cpu_tmp2_i32,
|
3842 |
cpu_T[0], tcg_const_i32(8 << ot)); |
3843 |
|
3844 |
ot = (s->dflag == 2) ? OT_QUAD : OT_LONG;
|
3845 |
gen_op_mov_reg_T0(ot, reg); |
3846 |
break;
|
3847 |
case 0x03a: |
3848 |
case 0x13a: |
3849 |
b = modrm; |
3850 |
modrm = cpu_ldub_code(env, s->pc++); |
3851 |
rm = modrm & 7;
|
3852 |
reg = ((modrm >> 3) & 7) | rex_r; |
3853 |
mod = (modrm >> 6) & 3; |
3854 |
if (b1 >= 2) { |
3855 |
goto illegal_op;
|
3856 |
} |
3857 |
|
3858 |
sse_fn_eppi = sse_op_table7[b].op[b1]; |
3859 |
if (!sse_fn_eppi) {
|
3860 |
goto illegal_op;
|
3861 |
} |
3862 |
if (!(s->cpuid_ext_features & sse_op_table7[b].ext_mask))
|
3863 |
goto illegal_op;
|
3864 |
|
3865 |
if (sse_fn_eppi == SSE_SPECIAL) {
|
3866 |
ot = (s->dflag == 2) ? OT_QUAD : OT_LONG;
|
3867 |
rm = (modrm & 7) | REX_B(s);
|
3868 |
if (mod != 3) |
3869 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
3870 |
reg = ((modrm >> 3) & 7) | rex_r; |
3871 |
val = cpu_ldub_code(env, s->pc++); |
3872 |
switch (b) {
|
3873 |
case 0x14: /* pextrb */ |
3874 |
tcg_gen_ld8u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,
|
3875 |
xmm_regs[reg].XMM_B(val & 15)));
|
3876 |
if (mod == 3) |
3877 |
gen_op_mov_reg_T0(ot, rm); |
3878 |
else
|
3879 |
tcg_gen_qemu_st8(cpu_T[0], cpu_A0,
|
3880 |
(s->mem_index >> 2) - 1); |
3881 |
break;
|
3882 |
case 0x15: /* pextrw */ |
3883 |
tcg_gen_ld16u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,
|
3884 |
xmm_regs[reg].XMM_W(val & 7)));
|
3885 |
if (mod == 3) |
3886 |
gen_op_mov_reg_T0(ot, rm); |
3887 |
else
|
3888 |
tcg_gen_qemu_st16(cpu_T[0], cpu_A0,
|
3889 |
(s->mem_index >> 2) - 1); |
3890 |
break;
|
3891 |
case 0x16: |
3892 |
if (ot == OT_LONG) { /* pextrd */ |
3893 |
tcg_gen_ld_i32(cpu_tmp2_i32, cpu_env, |
3894 |
offsetof(CPUX86State, |
3895 |
xmm_regs[reg].XMM_L(val & 3)));
|
3896 |
tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
3897 |
if (mod == 3) |
3898 |
gen_op_mov_reg_v(ot, rm, cpu_T[0]);
|
3899 |
else
|
3900 |
tcg_gen_qemu_st32(cpu_T[0], cpu_A0,
|
3901 |
(s->mem_index >> 2) - 1); |
3902 |
} else { /* pextrq */ |
3903 |
#ifdef TARGET_X86_64
|
3904 |
tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, |
3905 |
offsetof(CPUX86State, |
3906 |
xmm_regs[reg].XMM_Q(val & 1)));
|
3907 |
if (mod == 3) |
3908 |
gen_op_mov_reg_v(ot, rm, cpu_tmp1_i64); |
3909 |
else
|
3910 |
tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_A0, |
3911 |
(s->mem_index >> 2) - 1); |
3912 |
#else
|
3913 |
goto illegal_op;
|
3914 |
#endif
|
3915 |
} |
3916 |
break;
|
3917 |
case 0x17: /* extractps */ |
3918 |
tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,
|
3919 |
xmm_regs[reg].XMM_L(val & 3)));
|
3920 |
if (mod == 3) |
3921 |
gen_op_mov_reg_T0(ot, rm); |
3922 |
else
|
3923 |
tcg_gen_qemu_st32(cpu_T[0], cpu_A0,
|
3924 |
(s->mem_index >> 2) - 1); |
3925 |
break;
|
3926 |
case 0x20: /* pinsrb */ |
3927 |
if (mod == 3) |
3928 |
gen_op_mov_TN_reg(OT_LONG, 0, rm);
|
3929 |
else
|
3930 |
tcg_gen_qemu_ld8u(cpu_tmp0, cpu_A0, |
3931 |
(s->mem_index >> 2) - 1); |
3932 |
tcg_gen_st8_tl(cpu_tmp0, cpu_env, offsetof(CPUX86State, |
3933 |
xmm_regs[reg].XMM_B(val & 15)));
|
3934 |
break;
|
3935 |
case 0x21: /* insertps */ |
3936 |
if (mod == 3) { |
3937 |
tcg_gen_ld_i32(cpu_tmp2_i32, cpu_env, |
3938 |
offsetof(CPUX86State,xmm_regs[rm] |
3939 |
.XMM_L((val >> 6) & 3))); |
3940 |
} else {
|
3941 |
tcg_gen_qemu_ld32u(cpu_tmp0, cpu_A0, |
3942 |
(s->mem_index >> 2) - 1); |
3943 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_tmp0); |
3944 |
} |
3945 |
tcg_gen_st_i32(cpu_tmp2_i32, cpu_env, |
3946 |
offsetof(CPUX86State,xmm_regs[reg] |
3947 |
.XMM_L((val >> 4) & 3))); |
3948 |
if ((val >> 0) & 1) |
3949 |
tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/), |
3950 |
cpu_env, offsetof(CPUX86State, |
3951 |
xmm_regs[reg].XMM_L(0)));
|
3952 |
if ((val >> 1) & 1) |
3953 |
tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/), |
3954 |
cpu_env, offsetof(CPUX86State, |
3955 |
xmm_regs[reg].XMM_L(1)));
|
3956 |
if ((val >> 2) & 1) |
3957 |
tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/), |
3958 |
cpu_env, offsetof(CPUX86State, |
3959 |
xmm_regs[reg].XMM_L(2)));
|
3960 |
if ((val >> 3) & 1) |
3961 |
tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/), |
3962 |
cpu_env, offsetof(CPUX86State, |
3963 |
xmm_regs[reg].XMM_L(3)));
|
3964 |
break;
|
3965 |
case 0x22: |
3966 |
if (ot == OT_LONG) { /* pinsrd */ |
3967 |
if (mod == 3) |
3968 |
gen_op_mov_v_reg(ot, cpu_tmp0, rm); |
3969 |
else
|
3970 |
tcg_gen_qemu_ld32u(cpu_tmp0, cpu_A0, |
3971 |
(s->mem_index >> 2) - 1); |
3972 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_tmp0); |
3973 |
tcg_gen_st_i32(cpu_tmp2_i32, cpu_env, |
3974 |
offsetof(CPUX86State, |
3975 |
xmm_regs[reg].XMM_L(val & 3)));
|
3976 |
} else { /* pinsrq */ |
3977 |
#ifdef TARGET_X86_64
|
3978 |
if (mod == 3) |
3979 |
gen_op_mov_v_reg(ot, cpu_tmp1_i64, rm); |
3980 |
else
|
3981 |
tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_A0, |
3982 |
(s->mem_index >> 2) - 1); |
3983 |
tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, |
3984 |
offsetof(CPUX86State, |
3985 |
xmm_regs[reg].XMM_Q(val & 1)));
|
3986 |
#else
|
3987 |
goto illegal_op;
|
3988 |
#endif
|
3989 |
} |
3990 |
break;
|
3991 |
} |
3992 |
return;
|
3993 |
} |
3994 |
|
3995 |
if (b1) {
|
3996 |
op1_offset = offsetof(CPUX86State,xmm_regs[reg]); |
3997 |
if (mod == 3) { |
3998 |
op2_offset = offsetof(CPUX86State,xmm_regs[rm | REX_B(s)]); |
3999 |
} else {
|
4000 |
op2_offset = offsetof(CPUX86State,xmm_t0); |
4001 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
4002 |
gen_ldo_env_A0(s->mem_index, op2_offset); |
4003 |
} |
4004 |
} else {
|
4005 |
op1_offset = offsetof(CPUX86State,fpregs[reg].mmx); |
4006 |
if (mod == 3) { |
4007 |
op2_offset = offsetof(CPUX86State,fpregs[rm].mmx); |
4008 |
} else {
|
4009 |
op2_offset = offsetof(CPUX86State,mmx_t0); |
4010 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
4011 |
gen_ldq_env_A0(s->mem_index, op2_offset); |
4012 |
} |
4013 |
} |
4014 |
val = cpu_ldub_code(env, s->pc++); |
4015 |
|
4016 |
if ((b & 0xfc) == 0x60) { /* pcmpXstrX */ |
4017 |
s->cc_op = CC_OP_EFLAGS; |
4018 |
|
4019 |
if (s->dflag == 2) |
4020 |
/* The helper must use entire 64-bit gp registers */
|
4021 |
val |= 1 << 8; |
4022 |
} |
4023 |
|
4024 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
4025 |
tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
4026 |
sse_fn_eppi(cpu_env, cpu_ptr0, cpu_ptr1, tcg_const_i32(val)); |
4027 |
break;
|
4028 |
default:
|
4029 |
goto illegal_op;
|
4030 |
} |
4031 |
} else {
|
4032 |
/* generic MMX or SSE operation */
|
4033 |
switch(b) {
|
4034 |
case 0x70: /* pshufx insn */ |
4035 |
case 0xc6: /* pshufx insn */ |
4036 |
case 0xc2: /* compare insns */ |
4037 |
s->rip_offset = 1;
|
4038 |
break;
|
4039 |
default:
|
4040 |
break;
|
4041 |
} |
4042 |
if (is_xmm) {
|
4043 |
op1_offset = offsetof(CPUX86State,xmm_regs[reg]); |
4044 |
if (mod != 3) { |
4045 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
4046 |
op2_offset = offsetof(CPUX86State,xmm_t0); |
4047 |
if (b1 >= 2 && ((b >= 0x50 && b <= 0x5f && b != 0x5b) || |
4048 |
b == 0xc2)) {
|
4049 |
/* specific case for SSE single instructions */
|
4050 |
if (b1 == 2) { |
4051 |
/* 32 bit access */
|
4052 |
gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
4053 |
tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_t0.XMM_L(0))); |
4054 |
} else {
|
4055 |
/* 64 bit access */
|
4056 |
gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_t0.XMM_D(0)));
|
4057 |
} |
4058 |
} else {
|
4059 |
gen_ldo_env_A0(s->mem_index, op2_offset); |
4060 |
} |
4061 |
} else {
|
4062 |
rm = (modrm & 7) | REX_B(s);
|
4063 |
op2_offset = offsetof(CPUX86State,xmm_regs[rm]); |
4064 |
} |
4065 |
} else {
|
4066 |
op1_offset = offsetof(CPUX86State,fpregs[reg].mmx); |
4067 |
if (mod != 3) { |
4068 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
4069 |
op2_offset = offsetof(CPUX86State,mmx_t0); |
4070 |
gen_ldq_env_A0(s->mem_index, op2_offset); |
4071 |
} else {
|
4072 |
rm = (modrm & 7);
|
4073 |
op2_offset = offsetof(CPUX86State,fpregs[rm].mmx); |
4074 |
} |
4075 |
} |
4076 |
switch(b) {
|
4077 |
case 0x0f: /* 3DNow! data insns */ |
4078 |
if (!(s->cpuid_ext2_features & CPUID_EXT2_3DNOW))
|
4079 |
goto illegal_op;
|
4080 |
val = cpu_ldub_code(env, s->pc++); |
4081 |
sse_fn_epp = sse_op_table5[val]; |
4082 |
if (!sse_fn_epp) {
|
4083 |
goto illegal_op;
|
4084 |
} |
4085 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
4086 |
tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
4087 |
sse_fn_epp(cpu_env, cpu_ptr0, cpu_ptr1); |
4088 |
break;
|
4089 |
case 0x70: /* pshufx insn */ |
4090 |
case 0xc6: /* pshufx insn */ |
4091 |
val = cpu_ldub_code(env, s->pc++); |
4092 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
4093 |
tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
4094 |
/* XXX: introduce a new table? */
|
4095 |
sse_fn_ppi = (SSEFunc_0_ppi)sse_fn_epp; |
4096 |
sse_fn_ppi(cpu_ptr0, cpu_ptr1, tcg_const_i32(val)); |
4097 |
break;
|
4098 |
case 0xc2: |
4099 |
/* compare insns */
|
4100 |
val = cpu_ldub_code(env, s->pc++); |
4101 |
if (val >= 8) |
4102 |
goto illegal_op;
|
4103 |
sse_fn_epp = sse_op_table4[val][b1]; |
4104 |
|
4105 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
4106 |
tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
4107 |
sse_fn_epp(cpu_env, cpu_ptr0, cpu_ptr1); |
4108 |
break;
|
4109 |
case 0xf7: |
4110 |
/* maskmov : we must prepare A0 */
|
4111 |
if (mod != 3) |
4112 |
goto illegal_op;
|
4113 |
#ifdef TARGET_X86_64
|
4114 |
if (s->aflag == 2) { |
4115 |
gen_op_movq_A0_reg(R_EDI); |
4116 |
} else
|
4117 |
#endif
|
4118 |
{ |
4119 |
gen_op_movl_A0_reg(R_EDI); |
4120 |
if (s->aflag == 0) |
4121 |
gen_op_andl_A0_ffff(); |
4122 |
} |
4123 |
gen_add_A0_ds_seg(s); |
4124 |
|
4125 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
4126 |
tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
4127 |
/* XXX: introduce a new table? */
|
4128 |
sse_fn_eppt = (SSEFunc_0_eppt)sse_fn_epp; |
4129 |
sse_fn_eppt(cpu_env, cpu_ptr0, cpu_ptr1, cpu_A0); |
4130 |
break;
|
4131 |
default:
|
4132 |
tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
4133 |
tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
4134 |
sse_fn_epp(cpu_env, cpu_ptr0, cpu_ptr1); |
4135 |
break;
|
4136 |
} |
4137 |
if (b == 0x2e || b == 0x2f) { |
4138 |
s->cc_op = CC_OP_EFLAGS; |
4139 |
} |
4140 |
} |
4141 |
} |
4142 |
|
4143 |
/* convert one instruction. s->is_jmp is set if the translation must
|
4144 |
be stopped. Return the next pc value */
|
4145 |
static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
|
4146 |
target_ulong pc_start) |
4147 |
{ |
4148 |
int b, prefixes, aflag, dflag;
|
4149 |
int shift, ot;
|
4150 |
int modrm, reg, rm, mod, reg_addr, op, opreg, offset_addr, val;
|
4151 |
target_ulong next_eip, tval; |
4152 |
int rex_w, rex_r;
|
4153 |
|
4154 |
if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
|
4155 |
tcg_gen_debug_insn_start(pc_start); |
4156 |
} |
4157 |
s->pc = pc_start; |
4158 |
prefixes = 0;
|
4159 |
aflag = s->code32; |
4160 |
dflag = s->code32; |
4161 |
s->override = -1;
|
4162 |
rex_w = -1;
|
4163 |
rex_r = 0;
|
4164 |
#ifdef TARGET_X86_64
|
4165 |
s->rex_x = 0;
|
4166 |
s->rex_b = 0;
|
4167 |
x86_64_hregs = 0;
|
4168 |
#endif
|
4169 |
s->rip_offset = 0; /* for relative ip address */ |
4170 |
next_byte:
|
4171 |
b = cpu_ldub_code(env, s->pc); |
4172 |
s->pc++; |
4173 |
/* check prefixes */
|
4174 |
#ifdef TARGET_X86_64
|
4175 |
if (CODE64(s)) {
|
4176 |
switch (b) {
|
4177 |
case 0xf3: |
4178 |
prefixes |= PREFIX_REPZ; |
4179 |
goto next_byte;
|
4180 |
case 0xf2: |
4181 |
prefixes |= PREFIX_REPNZ; |
4182 |
goto next_byte;
|
4183 |
case 0xf0: |
4184 |
prefixes |= PREFIX_LOCK; |
4185 |
goto next_byte;
|
4186 |
case 0x2e: |
4187 |
s->override = R_CS; |
4188 |
goto next_byte;
|
4189 |
case 0x36: |
4190 |
s->override = R_SS; |
4191 |
goto next_byte;
|
4192 |
case 0x3e: |
4193 |
s->override = R_DS; |
4194 |
goto next_byte;
|
4195 |
case 0x26: |
4196 |
s->override = R_ES; |
4197 |
goto next_byte;
|
4198 |
case 0x64: |
4199 |
s->override = R_FS; |
4200 |
goto next_byte;
|
4201 |
case 0x65: |
4202 |
s->override = R_GS; |
4203 |
goto next_byte;
|
4204 |
case 0x66: |
4205 |
prefixes |= PREFIX_DATA; |
4206 |
goto next_byte;
|
4207 |
case 0x67: |
4208 |
prefixes |= PREFIX_ADR; |
4209 |
goto next_byte;
|
4210 |
case 0x40 ... 0x4f: |
4211 |
/* REX prefix */
|
4212 |
rex_w = (b >> 3) & 1; |
4213 |
rex_r = (b & 0x4) << 1; |
4214 |
s->rex_x = (b & 0x2) << 2; |
4215 |
REX_B(s) = (b & 0x1) << 3; |
4216 |
x86_64_hregs = 1; /* select uniform byte register addressing */ |
4217 |
goto next_byte;
|
4218 |
} |
4219 |
if (rex_w == 1) { |
4220 |
/* 0x66 is ignored if rex.w is set */
|
4221 |
dflag = 2;
|
4222 |
} else {
|
4223 |
if (prefixes & PREFIX_DATA)
|
4224 |
dflag ^= 1;
|
4225 |
} |
4226 |
if (!(prefixes & PREFIX_ADR))
|
4227 |
aflag = 2;
|
4228 |
} else
|
4229 |
#endif
|
4230 |
{ |
4231 |
switch (b) {
|
4232 |
case 0xf3: |
4233 |
prefixes |= PREFIX_REPZ; |
4234 |
goto next_byte;
|
4235 |
case 0xf2: |
4236 |
prefixes |= PREFIX_REPNZ; |
4237 |
goto next_byte;
|
4238 |
case 0xf0: |
4239 |
prefixes |= PREFIX_LOCK; |
4240 |
goto next_byte;
|
4241 |
case 0x2e: |
4242 |
s->override = R_CS; |
4243 |
goto next_byte;
|
4244 |
case 0x36: |
4245 |
s->override = R_SS; |
4246 |
goto next_byte;
|
4247 |
case 0x3e: |
4248 |
s->override = R_DS; |
4249 |
goto next_byte;
|
4250 |
case 0x26: |
4251 |
s->override = R_ES; |
4252 |
goto next_byte;
|
4253 |
case 0x64: |
4254 |
s->override = R_FS; |
4255 |
goto next_byte;
|
4256 |
case 0x65: |
4257 |
s->override = R_GS; |
4258 |
goto next_byte;
|
4259 |
case 0x66: |
4260 |
prefixes |= PREFIX_DATA; |
4261 |
goto next_byte;
|
4262 |
case 0x67: |
4263 |
prefixes |= PREFIX_ADR; |
4264 |
goto next_byte;
|
4265 |
} |
4266 |
if (prefixes & PREFIX_DATA)
|
4267 |
dflag ^= 1;
|
4268 |
if (prefixes & PREFIX_ADR)
|
4269 |
aflag ^= 1;
|
4270 |
} |
4271 |
|
4272 |
s->prefix = prefixes; |
4273 |
s->aflag = aflag; |
4274 |
s->dflag = dflag; |
4275 |
|
4276 |
/* lock generation */
|
4277 |
if (prefixes & PREFIX_LOCK)
|
4278 |
gen_helper_lock(); |
4279 |
|
4280 |
/* now check op code */
|
4281 |
reswitch:
|
4282 |
switch(b) {
|
4283 |
case 0x0f: |
4284 |
/**************************/
|
4285 |
/* extended op code */
|
4286 |
b = cpu_ldub_code(env, s->pc++) | 0x100;
|
4287 |
goto reswitch;
|
4288 |
|
4289 |
/**************************/
|
4290 |
/* arith & logic */
|
4291 |
case 0x00 ... 0x05: |
4292 |
case 0x08 ... 0x0d: |
4293 |
case 0x10 ... 0x15: |
4294 |
case 0x18 ... 0x1d: |
4295 |
case 0x20 ... 0x25: |
4296 |
case 0x28 ... 0x2d: |
4297 |
case 0x30 ... 0x35: |
4298 |
case 0x38 ... 0x3d: |
4299 |
{ |
4300 |
int op, f, val;
|
4301 |
op = (b >> 3) & 7; |
4302 |
f = (b >> 1) & 3; |
4303 |
|
4304 |
if ((b & 1) == 0) |
4305 |
ot = OT_BYTE; |
4306 |
else
|
4307 |
ot = dflag + OT_WORD; |
4308 |
|
4309 |
switch(f) {
|
4310 |
case 0: /* OP Ev, Gv */ |
4311 |
modrm = cpu_ldub_code(env, s->pc++); |
4312 |
reg = ((modrm >> 3) & 7) | rex_r; |
4313 |
mod = (modrm >> 6) & 3; |
4314 |
rm = (modrm & 7) | REX_B(s);
|
4315 |
if (mod != 3) { |
4316 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
4317 |
opreg = OR_TMP0; |
4318 |
} else if (op == OP_XORL && rm == reg) { |
4319 |
xor_zero:
|
4320 |
/* xor reg, reg optimisation */
|
4321 |
gen_op_movl_T0_0(); |
4322 |
s->cc_op = CC_OP_LOGICB + ot; |
4323 |
gen_op_mov_reg_T0(ot, reg); |
4324 |
gen_op_update1_cc(); |
4325 |
break;
|
4326 |
} else {
|
4327 |
opreg = rm; |
4328 |
} |
4329 |
gen_op_mov_TN_reg(ot, 1, reg);
|
4330 |
gen_op(s, op, ot, opreg); |
4331 |
break;
|
4332 |
case 1: /* OP Gv, Ev */ |
4333 |
modrm = cpu_ldub_code(env, s->pc++); |
4334 |
mod = (modrm >> 6) & 3; |
4335 |
reg = ((modrm >> 3) & 7) | rex_r; |
4336 |
rm = (modrm & 7) | REX_B(s);
|
4337 |
if (mod != 3) { |
4338 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
4339 |
gen_op_ld_T1_A0(ot + s->mem_index); |
4340 |
} else if (op == OP_XORL && rm == reg) { |
4341 |
goto xor_zero;
|
4342 |
} else {
|
4343 |
gen_op_mov_TN_reg(ot, 1, rm);
|
4344 |
} |
4345 |
gen_op(s, op, ot, reg); |
4346 |
break;
|
4347 |
case 2: /* OP A, Iv */ |
4348 |
val = insn_get(env, s, ot); |
4349 |
gen_op_movl_T1_im(val); |
4350 |
gen_op(s, op, ot, OR_EAX); |
4351 |
break;
|
4352 |
} |
4353 |
} |
4354 |
break;
|
4355 |
|
4356 |
case 0x82: |
4357 |
if (CODE64(s))
|
4358 |
goto illegal_op;
|
4359 |
case 0x80: /* GRP1 */ |
4360 |
case 0x81: |
4361 |
case 0x83: |
4362 |
{ |
4363 |
int val;
|
4364 |
|
4365 |
if ((b & 1) == 0) |
4366 |
ot = OT_BYTE; |
4367 |
else
|
4368 |
ot = dflag + OT_WORD; |
4369 |
|
4370 |
modrm = cpu_ldub_code(env, s->pc++); |
4371 |
mod = (modrm >> 6) & 3; |
4372 |
rm = (modrm & 7) | REX_B(s);
|
4373 |
op = (modrm >> 3) & 7; |
4374 |
|
4375 |
if (mod != 3) { |
4376 |
if (b == 0x83) |
4377 |
s->rip_offset = 1;
|
4378 |
else
|
4379 |
s->rip_offset = insn_const_size(ot); |
4380 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
4381 |
opreg = OR_TMP0; |
4382 |
} else {
|
4383 |
opreg = rm; |
4384 |
} |
4385 |
|
4386 |
switch(b) {
|
4387 |
default:
|
4388 |
case 0x80: |
4389 |
case 0x81: |
4390 |
case 0x82: |
4391 |
val = insn_get(env, s, ot); |
4392 |
break;
|
4393 |
case 0x83: |
4394 |
val = (int8_t)insn_get(env, s, OT_BYTE); |
4395 |
break;
|
4396 |
} |
4397 |
gen_op_movl_T1_im(val); |
4398 |
gen_op(s, op, ot, opreg); |
4399 |
} |
4400 |
break;
|
4401 |
|
4402 |
/**************************/
|
4403 |
/* inc, dec, and other misc arith */
|
4404 |
case 0x40 ... 0x47: /* inc Gv */ |
4405 |
ot = dflag ? OT_LONG : OT_WORD; |
4406 |
gen_inc(s, ot, OR_EAX + (b & 7), 1); |
4407 |
break;
|
4408 |
case 0x48 ... 0x4f: /* dec Gv */ |
4409 |
ot = dflag ? OT_LONG : OT_WORD; |
4410 |
gen_inc(s, ot, OR_EAX + (b & 7), -1); |
4411 |
break;
|
4412 |
case 0xf6: /* GRP3 */ |
4413 |
case 0xf7: |
4414 |
if ((b & 1) == 0) |
4415 |
ot = OT_BYTE; |
4416 |
else
|
4417 |
ot = dflag + OT_WORD; |
4418 |
|
4419 |
modrm = cpu_ldub_code(env, s->pc++); |
4420 |
mod = (modrm >> 6) & 3; |
4421 |
rm = (modrm & 7) | REX_B(s);
|
4422 |
op = (modrm >> 3) & 7; |
4423 |
if (mod != 3) { |
4424 |
if (op == 0) |
4425 |
s->rip_offset = insn_const_size(ot); |
4426 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
4427 |
gen_op_ld_T0_A0(ot + s->mem_index); |
4428 |
} else {
|
4429 |
gen_op_mov_TN_reg(ot, 0, rm);
|
4430 |
} |
4431 |
|
4432 |
switch(op) {
|
4433 |
case 0: /* test */ |
4434 |
val = insn_get(env, s, ot); |
4435 |
gen_op_movl_T1_im(val); |
4436 |
gen_op_testl_T0_T1_cc(); |
4437 |
s->cc_op = CC_OP_LOGICB + ot; |
4438 |
break;
|
4439 |
case 2: /* not */ |
4440 |
tcg_gen_not_tl(cpu_T[0], cpu_T[0]); |
4441 |
if (mod != 3) { |
4442 |
gen_op_st_T0_A0(ot + s->mem_index); |
4443 |
} else {
|
4444 |
gen_op_mov_reg_T0(ot, rm); |
4445 |
} |
4446 |
break;
|
4447 |
case 3: /* neg */ |
4448 |
tcg_gen_neg_tl(cpu_T[0], cpu_T[0]); |
4449 |
if (mod != 3) { |
4450 |
gen_op_st_T0_A0(ot + s->mem_index); |
4451 |
} else {
|
4452 |
gen_op_mov_reg_T0(ot, rm); |
4453 |
} |
4454 |
gen_op_update_neg_cc(); |
4455 |
s->cc_op = CC_OP_SUBB + ot; |
4456 |
break;
|
4457 |
case 4: /* mul */ |
4458 |
switch(ot) {
|
4459 |
case OT_BYTE:
|
4460 |
gen_op_mov_TN_reg(OT_BYTE, 1, R_EAX);
|
4461 |
tcg_gen_ext8u_tl(cpu_T[0], cpu_T[0]); |
4462 |
tcg_gen_ext8u_tl(cpu_T[1], cpu_T[1]); |
4463 |
/* XXX: use 32 bit mul which could be faster */
|
4464 |
tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4465 |
gen_op_mov_reg_T0(OT_WORD, R_EAX); |
4466 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4467 |
tcg_gen_andi_tl(cpu_cc_src, cpu_T[0], 0xff00); |
4468 |
s->cc_op = CC_OP_MULB; |
4469 |
break;
|
4470 |
case OT_WORD:
|
4471 |
gen_op_mov_TN_reg(OT_WORD, 1, R_EAX);
|
4472 |
tcg_gen_ext16u_tl(cpu_T[0], cpu_T[0]); |
4473 |
tcg_gen_ext16u_tl(cpu_T[1], cpu_T[1]); |
4474 |
/* XXX: use 32 bit mul which could be faster */
|
4475 |
tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4476 |
gen_op_mov_reg_T0(OT_WORD, R_EAX); |
4477 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4478 |
tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 16); |
4479 |
gen_op_mov_reg_T0(OT_WORD, R_EDX); |
4480 |
tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
|
4481 |
s->cc_op = CC_OP_MULW; |
4482 |
break;
|
4483 |
default:
|
4484 |
case OT_LONG:
|
4485 |
#ifdef TARGET_X86_64
|
4486 |
gen_op_mov_TN_reg(OT_LONG, 1, R_EAX);
|
4487 |
tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]); |
4488 |
tcg_gen_ext32u_tl(cpu_T[1], cpu_T[1]); |
4489 |
tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4490 |
gen_op_mov_reg_T0(OT_LONG, R_EAX); |
4491 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4492 |
tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 32); |
4493 |
gen_op_mov_reg_T0(OT_LONG, R_EDX); |
4494 |
tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
|
4495 |
#else
|
4496 |
{ |
4497 |
TCGv_i64 t0, t1; |
4498 |
t0 = tcg_temp_new_i64(); |
4499 |
t1 = tcg_temp_new_i64(); |
4500 |
gen_op_mov_TN_reg(OT_LONG, 1, R_EAX);
|
4501 |
tcg_gen_extu_i32_i64(t0, cpu_T[0]);
|
4502 |
tcg_gen_extu_i32_i64(t1, cpu_T[1]);
|
4503 |
tcg_gen_mul_i64(t0, t0, t1); |
4504 |
tcg_gen_trunc_i64_i32(cpu_T[0], t0);
|
4505 |
gen_op_mov_reg_T0(OT_LONG, R_EAX); |
4506 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4507 |
tcg_gen_shri_i64(t0, t0, 32);
|
4508 |
tcg_gen_trunc_i64_i32(cpu_T[0], t0);
|
4509 |
gen_op_mov_reg_T0(OT_LONG, R_EDX); |
4510 |
tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
|
4511 |
} |
4512 |
#endif
|
4513 |
s->cc_op = CC_OP_MULL; |
4514 |
break;
|
4515 |
#ifdef TARGET_X86_64
|
4516 |
case OT_QUAD:
|
4517 |
gen_helper_mulq_EAX_T0(cpu_env, cpu_T[0]);
|
4518 |
s->cc_op = CC_OP_MULQ; |
4519 |
break;
|
4520 |
#endif
|
4521 |
} |
4522 |
break;
|
4523 |
case 5: /* imul */ |
4524 |
switch(ot) {
|
4525 |
case OT_BYTE:
|
4526 |
gen_op_mov_TN_reg(OT_BYTE, 1, R_EAX);
|
4527 |
tcg_gen_ext8s_tl(cpu_T[0], cpu_T[0]); |
4528 |
tcg_gen_ext8s_tl(cpu_T[1], cpu_T[1]); |
4529 |
/* XXX: use 32 bit mul which could be faster */
|
4530 |
tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4531 |
gen_op_mov_reg_T0(OT_WORD, R_EAX); |
4532 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4533 |
tcg_gen_ext8s_tl(cpu_tmp0, cpu_T[0]);
|
4534 |
tcg_gen_sub_tl(cpu_cc_src, cpu_T[0], cpu_tmp0);
|
4535 |
s->cc_op = CC_OP_MULB; |
4536 |
break;
|
4537 |
case OT_WORD:
|
4538 |
gen_op_mov_TN_reg(OT_WORD, 1, R_EAX);
|
4539 |
tcg_gen_ext16s_tl(cpu_T[0], cpu_T[0]); |
4540 |
tcg_gen_ext16s_tl(cpu_T[1], cpu_T[1]); |
4541 |
/* XXX: use 32 bit mul which could be faster */
|
4542 |
tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4543 |
gen_op_mov_reg_T0(OT_WORD, R_EAX); |
4544 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4545 |
tcg_gen_ext16s_tl(cpu_tmp0, cpu_T[0]);
|
4546 |
tcg_gen_sub_tl(cpu_cc_src, cpu_T[0], cpu_tmp0);
|
4547 |
tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 16); |
4548 |
gen_op_mov_reg_T0(OT_WORD, R_EDX); |
4549 |
s->cc_op = CC_OP_MULW; |
4550 |
break;
|
4551 |
default:
|
4552 |
case OT_LONG:
|
4553 |
#ifdef TARGET_X86_64
|
4554 |
gen_op_mov_TN_reg(OT_LONG, 1, R_EAX);
|
4555 |
tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]); |
4556 |
tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]); |
4557 |
tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4558 |
gen_op_mov_reg_T0(OT_LONG, R_EAX); |
4559 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4560 |
tcg_gen_ext32s_tl(cpu_tmp0, cpu_T[0]);
|
4561 |
tcg_gen_sub_tl(cpu_cc_src, cpu_T[0], cpu_tmp0);
|
4562 |
tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 32); |
4563 |
gen_op_mov_reg_T0(OT_LONG, R_EDX); |
4564 |
#else
|
4565 |
{ |
4566 |
TCGv_i64 t0, t1; |
4567 |
t0 = tcg_temp_new_i64(); |
4568 |
t1 = tcg_temp_new_i64(); |
4569 |
gen_op_mov_TN_reg(OT_LONG, 1, R_EAX);
|
4570 |
tcg_gen_ext_i32_i64(t0, cpu_T[0]);
|
4571 |
tcg_gen_ext_i32_i64(t1, cpu_T[1]);
|
4572 |
tcg_gen_mul_i64(t0, t0, t1); |
4573 |
tcg_gen_trunc_i64_i32(cpu_T[0], t0);
|
4574 |
gen_op_mov_reg_T0(OT_LONG, R_EAX); |
4575 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4576 |
tcg_gen_sari_tl(cpu_tmp0, cpu_T[0], 31); |
4577 |
tcg_gen_shri_i64(t0, t0, 32);
|
4578 |
tcg_gen_trunc_i64_i32(cpu_T[0], t0);
|
4579 |
gen_op_mov_reg_T0(OT_LONG, R_EDX); |
4580 |
tcg_gen_sub_tl(cpu_cc_src, cpu_T[0], cpu_tmp0);
|
4581 |
} |
4582 |
#endif
|
4583 |
s->cc_op = CC_OP_MULL; |
4584 |
break;
|
4585 |
#ifdef TARGET_X86_64
|
4586 |
case OT_QUAD:
|
4587 |
gen_helper_imulq_EAX_T0(cpu_env, cpu_T[0]);
|
4588 |
s->cc_op = CC_OP_MULQ; |
4589 |
break;
|
4590 |
#endif
|
4591 |
} |
4592 |
break;
|
4593 |
case 6: /* div */ |
4594 |
switch(ot) {
|
4595 |
case OT_BYTE:
|
4596 |
gen_jmp_im(pc_start - s->cs_base); |
4597 |
gen_helper_divb_AL(cpu_env, cpu_T[0]);
|
4598 |
break;
|
4599 |
case OT_WORD:
|
4600 |
gen_jmp_im(pc_start - s->cs_base); |
4601 |
gen_helper_divw_AX(cpu_env, cpu_T[0]);
|
4602 |
break;
|
4603 |
default:
|
4604 |
case OT_LONG:
|
4605 |
gen_jmp_im(pc_start - s->cs_base); |
4606 |
gen_helper_divl_EAX(cpu_env, cpu_T[0]);
|
4607 |
break;
|
4608 |
#ifdef TARGET_X86_64
|
4609 |
case OT_QUAD:
|
4610 |
gen_jmp_im(pc_start - s->cs_base); |
4611 |
gen_helper_divq_EAX(cpu_env, cpu_T[0]);
|
4612 |
break;
|
4613 |
#endif
|
4614 |
} |
4615 |
break;
|
4616 |
case 7: /* idiv */ |
4617 |
switch(ot) {
|
4618 |
case OT_BYTE:
|
4619 |
gen_jmp_im(pc_start - s->cs_base); |
4620 |
gen_helper_idivb_AL(cpu_env, cpu_T[0]);
|
4621 |
break;
|
4622 |
case OT_WORD:
|
4623 |
gen_jmp_im(pc_start - s->cs_base); |
4624 |
gen_helper_idivw_AX(cpu_env, cpu_T[0]);
|
4625 |
break;
|
4626 |
default:
|
4627 |
case OT_LONG:
|
4628 |
gen_jmp_im(pc_start - s->cs_base); |
4629 |
gen_helper_idivl_EAX(cpu_env, cpu_T[0]);
|
4630 |
break;
|
4631 |
#ifdef TARGET_X86_64
|
4632 |
case OT_QUAD:
|
4633 |
gen_jmp_im(pc_start - s->cs_base); |
4634 |
gen_helper_idivq_EAX(cpu_env, cpu_T[0]);
|
4635 |
break;
|
4636 |
#endif
|
4637 |
} |
4638 |
break;
|
4639 |
default:
|
4640 |
goto illegal_op;
|
4641 |
} |
4642 |
break;
|
4643 |
|
4644 |
case 0xfe: /* GRP4 */ |
4645 |
case 0xff: /* GRP5 */ |
4646 |
if ((b & 1) == 0) |
4647 |
ot = OT_BYTE; |
4648 |
else
|
4649 |
ot = dflag + OT_WORD; |
4650 |
|
4651 |
modrm = cpu_ldub_code(env, s->pc++); |
4652 |
mod = (modrm >> 6) & 3; |
4653 |
rm = (modrm & 7) | REX_B(s);
|
4654 |
op = (modrm >> 3) & 7; |
4655 |
if (op >= 2 && b == 0xfe) { |
4656 |
goto illegal_op;
|
4657 |
} |
4658 |
if (CODE64(s)) {
|
4659 |
if (op == 2 || op == 4) { |
4660 |
/* operand size for jumps is 64 bit */
|
4661 |
ot = OT_QUAD; |
4662 |
} else if (op == 3 || op == 5) { |
4663 |
ot = dflag ? OT_LONG + (rex_w == 1) : OT_WORD;
|
4664 |
} else if (op == 6) { |
4665 |
/* default push size is 64 bit */
|
4666 |
ot = dflag ? OT_QUAD : OT_WORD; |
4667 |
} |
4668 |
} |
4669 |
if (mod != 3) { |
4670 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
4671 |
if (op >= 2 && op != 3 && op != 5) |
4672 |
gen_op_ld_T0_A0(ot + s->mem_index); |
4673 |
} else {
|
4674 |
gen_op_mov_TN_reg(ot, 0, rm);
|
4675 |
} |
4676 |
|
4677 |
switch(op) {
|
4678 |
case 0: /* inc Ev */ |
4679 |
if (mod != 3) |
4680 |
opreg = OR_TMP0; |
4681 |
else
|
4682 |
opreg = rm; |
4683 |
gen_inc(s, ot, opreg, 1);
|
4684 |
break;
|
4685 |
case 1: /* dec Ev */ |
4686 |
if (mod != 3) |
4687 |
opreg = OR_TMP0; |
4688 |
else
|
4689 |
opreg = rm; |
4690 |
gen_inc(s, ot, opreg, -1);
|
4691 |
break;
|
4692 |
case 2: /* call Ev */ |
4693 |
/* XXX: optimize if memory (no 'and' is necessary) */
|
4694 |
if (s->dflag == 0) |
4695 |
gen_op_andl_T0_ffff(); |
4696 |
next_eip = s->pc - s->cs_base; |
4697 |
gen_movtl_T1_im(next_eip); |
4698 |
gen_push_T1(s); |
4699 |
gen_op_jmp_T0(); |
4700 |
gen_eob(s); |
4701 |
break;
|
4702 |
case 3: /* lcall Ev */ |
4703 |
gen_op_ld_T1_A0(ot + s->mem_index); |
4704 |
gen_add_A0_im(s, 1 << (ot - OT_WORD + 1)); |
4705 |
gen_op_ldu_T0_A0(OT_WORD + s->mem_index); |
4706 |
do_lcall:
|
4707 |
if (s->pe && !s->vm86) {
|
4708 |
if (s->cc_op != CC_OP_DYNAMIC)
|
4709 |
gen_op_set_cc_op(s->cc_op); |
4710 |
gen_jmp_im(pc_start - s->cs_base); |
4711 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
4712 |
gen_helper_lcall_protected(cpu_env, cpu_tmp2_i32, cpu_T[1],
|
4713 |
tcg_const_i32(dflag), |
4714 |
tcg_const_i32(s->pc - pc_start)); |
4715 |
} else {
|
4716 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
4717 |
gen_helper_lcall_real(cpu_env, cpu_tmp2_i32, cpu_T[1],
|
4718 |
tcg_const_i32(dflag), |
4719 |
tcg_const_i32(s->pc - s->cs_base)); |
4720 |
} |
4721 |
gen_eob(s); |
4722 |
break;
|
4723 |
case 4: /* jmp Ev */ |
4724 |
if (s->dflag == 0) |
4725 |
gen_op_andl_T0_ffff(); |
4726 |
gen_op_jmp_T0(); |
4727 |
gen_eob(s); |
4728 |
break;
|
4729 |
case 5: /* ljmp Ev */ |
4730 |
gen_op_ld_T1_A0(ot + s->mem_index); |
4731 |
gen_add_A0_im(s, 1 << (ot - OT_WORD + 1)); |
4732 |
gen_op_ldu_T0_A0(OT_WORD + s->mem_index); |
4733 |
do_ljmp:
|
4734 |
if (s->pe && !s->vm86) {
|
4735 |
if (s->cc_op != CC_OP_DYNAMIC)
|
4736 |
gen_op_set_cc_op(s->cc_op); |
4737 |
gen_jmp_im(pc_start - s->cs_base); |
4738 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
4739 |
gen_helper_ljmp_protected(cpu_env, cpu_tmp2_i32, cpu_T[1],
|
4740 |
tcg_const_i32(s->pc - pc_start)); |
4741 |
} else {
|
4742 |
gen_op_movl_seg_T0_vm(R_CS); |
4743 |
gen_op_movl_T0_T1(); |
4744 |
gen_op_jmp_T0(); |
4745 |
} |
4746 |
gen_eob(s); |
4747 |
break;
|
4748 |
case 6: /* push Ev */ |
4749 |
gen_push_T0(s); |
4750 |
break;
|
4751 |
default:
|
4752 |
goto illegal_op;
|
4753 |
} |
4754 |
break;
|
4755 |
|
4756 |
case 0x84: /* test Ev, Gv */ |
4757 |
case 0x85: |
4758 |
if ((b & 1) == 0) |
4759 |
ot = OT_BYTE; |
4760 |
else
|
4761 |
ot = dflag + OT_WORD; |
4762 |
|
4763 |
modrm = cpu_ldub_code(env, s->pc++); |
4764 |
reg = ((modrm >> 3) & 7) | rex_r; |
4765 |
|
4766 |
gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0);
|
4767 |
gen_op_mov_TN_reg(ot, 1, reg);
|
4768 |
gen_op_testl_T0_T1_cc(); |
4769 |
s->cc_op = CC_OP_LOGICB + ot; |
4770 |
break;
|
4771 |
|
4772 |
case 0xa8: /* test eAX, Iv */ |
4773 |
case 0xa9: |
4774 |
if ((b & 1) == 0) |
4775 |
ot = OT_BYTE; |
4776 |
else
|
4777 |
ot = dflag + OT_WORD; |
4778 |
val = insn_get(env, s, ot); |
4779 |
|
4780 |
gen_op_mov_TN_reg(ot, 0, OR_EAX);
|
4781 |
gen_op_movl_T1_im(val); |
4782 |
gen_op_testl_T0_T1_cc(); |
4783 |
s->cc_op = CC_OP_LOGICB + ot; |
4784 |
break;
|
4785 |
|
4786 |
case 0x98: /* CWDE/CBW */ |
4787 |
#ifdef TARGET_X86_64
|
4788 |
if (dflag == 2) { |
4789 |
gen_op_mov_TN_reg(OT_LONG, 0, R_EAX);
|
4790 |
tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]); |
4791 |
gen_op_mov_reg_T0(OT_QUAD, R_EAX); |
4792 |
} else
|
4793 |
#endif
|
4794 |
if (dflag == 1) { |
4795 |
gen_op_mov_TN_reg(OT_WORD, 0, R_EAX);
|
4796 |
tcg_gen_ext16s_tl(cpu_T[0], cpu_T[0]); |
4797 |
gen_op_mov_reg_T0(OT_LONG, R_EAX); |
4798 |
} else {
|
4799 |
gen_op_mov_TN_reg(OT_BYTE, 0, R_EAX);
|
4800 |
tcg_gen_ext8s_tl(cpu_T[0], cpu_T[0]); |
4801 |
gen_op_mov_reg_T0(OT_WORD, R_EAX); |
4802 |
} |
4803 |
break;
|
4804 |
case 0x99: /* CDQ/CWD */ |
4805 |
#ifdef TARGET_X86_64
|
4806 |
if (dflag == 2) { |
4807 |
gen_op_mov_TN_reg(OT_QUAD, 0, R_EAX);
|
4808 |
tcg_gen_sari_tl(cpu_T[0], cpu_T[0], 63); |
4809 |
gen_op_mov_reg_T0(OT_QUAD, R_EDX); |
4810 |
} else
|
4811 |
#endif
|
4812 |
if (dflag == 1) { |
4813 |
gen_op_mov_TN_reg(OT_LONG, 0, R_EAX);
|
4814 |
tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]); |
4815 |
tcg_gen_sari_tl(cpu_T[0], cpu_T[0], 31); |
4816 |
gen_op_mov_reg_T0(OT_LONG, R_EDX); |
4817 |
} else {
|
4818 |
gen_op_mov_TN_reg(OT_WORD, 0, R_EAX);
|
4819 |
tcg_gen_ext16s_tl(cpu_T[0], cpu_T[0]); |
4820 |
tcg_gen_sari_tl(cpu_T[0], cpu_T[0], 15); |
4821 |
gen_op_mov_reg_T0(OT_WORD, R_EDX); |
4822 |
} |
4823 |
break;
|
4824 |
case 0x1af: /* imul Gv, Ev */ |
4825 |
case 0x69: /* imul Gv, Ev, I */ |
4826 |
case 0x6b: |
4827 |
ot = dflag + OT_WORD; |
4828 |
modrm = cpu_ldub_code(env, s->pc++); |
4829 |
reg = ((modrm >> 3) & 7) | rex_r; |
4830 |
if (b == 0x69) |
4831 |
s->rip_offset = insn_const_size(ot); |
4832 |
else if (b == 0x6b) |
4833 |
s->rip_offset = 1;
|
4834 |
gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0);
|
4835 |
if (b == 0x69) { |
4836 |
val = insn_get(env, s, ot); |
4837 |
gen_op_movl_T1_im(val); |
4838 |
} else if (b == 0x6b) { |
4839 |
val = (int8_t)insn_get(env, s, OT_BYTE); |
4840 |
gen_op_movl_T1_im(val); |
4841 |
} else {
|
4842 |
gen_op_mov_TN_reg(ot, 1, reg);
|
4843 |
} |
4844 |
|
4845 |
#ifdef TARGET_X86_64
|
4846 |
if (ot == OT_QUAD) {
|
4847 |
gen_helper_imulq_T0_T1(cpu_T[0], cpu_env, cpu_T[0], cpu_T[1]); |
4848 |
} else
|
4849 |
#endif
|
4850 |
if (ot == OT_LONG) {
|
4851 |
#ifdef TARGET_X86_64
|
4852 |
tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]); |
4853 |
tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]); |
4854 |
tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4855 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4856 |
tcg_gen_ext32s_tl(cpu_tmp0, cpu_T[0]);
|
4857 |
tcg_gen_sub_tl(cpu_cc_src, cpu_T[0], cpu_tmp0);
|
4858 |
#else
|
4859 |
{ |
4860 |
TCGv_i64 t0, t1; |
4861 |
t0 = tcg_temp_new_i64(); |
4862 |
t1 = tcg_temp_new_i64(); |
4863 |
tcg_gen_ext_i32_i64(t0, cpu_T[0]);
|
4864 |
tcg_gen_ext_i32_i64(t1, cpu_T[1]);
|
4865 |
tcg_gen_mul_i64(t0, t0, t1); |
4866 |
tcg_gen_trunc_i64_i32(cpu_T[0], t0);
|
4867 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4868 |
tcg_gen_sari_tl(cpu_tmp0, cpu_T[0], 31); |
4869 |
tcg_gen_shri_i64(t0, t0, 32);
|
4870 |
tcg_gen_trunc_i64_i32(cpu_T[1], t0);
|
4871 |
tcg_gen_sub_tl(cpu_cc_src, cpu_T[1], cpu_tmp0);
|
4872 |
} |
4873 |
#endif
|
4874 |
} else {
|
4875 |
tcg_gen_ext16s_tl(cpu_T[0], cpu_T[0]); |
4876 |
tcg_gen_ext16s_tl(cpu_T[1], cpu_T[1]); |
4877 |
/* XXX: use 32 bit mul which could be faster */
|
4878 |
tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4879 |
tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4880 |
tcg_gen_ext16s_tl(cpu_tmp0, cpu_T[0]);
|
4881 |
tcg_gen_sub_tl(cpu_cc_src, cpu_T[0], cpu_tmp0);
|
4882 |
} |
4883 |
gen_op_mov_reg_T0(ot, reg); |
4884 |
s->cc_op = CC_OP_MULB + ot; |
4885 |
break;
|
4886 |
case 0x1c0: |
4887 |
case 0x1c1: /* xadd Ev, Gv */ |
4888 |
if ((b & 1) == 0) |
4889 |
ot = OT_BYTE; |
4890 |
else
|
4891 |
ot = dflag + OT_WORD; |
4892 |
modrm = cpu_ldub_code(env, s->pc++); |
4893 |
reg = ((modrm >> 3) & 7) | rex_r; |
4894 |
mod = (modrm >> 6) & 3; |
4895 |
if (mod == 3) { |
4896 |
rm = (modrm & 7) | REX_B(s);
|
4897 |
gen_op_mov_TN_reg(ot, 0, reg);
|
4898 |
gen_op_mov_TN_reg(ot, 1, rm);
|
4899 |
gen_op_addl_T0_T1(); |
4900 |
gen_op_mov_reg_T1(ot, reg); |
4901 |
gen_op_mov_reg_T0(ot, rm); |
4902 |
} else {
|
4903 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
4904 |
gen_op_mov_TN_reg(ot, 0, reg);
|
4905 |
gen_op_ld_T1_A0(ot + s->mem_index); |
4906 |
gen_op_addl_T0_T1(); |
4907 |
gen_op_st_T0_A0(ot + s->mem_index); |
4908 |
gen_op_mov_reg_T1(ot, reg); |
4909 |
} |
4910 |
gen_op_update2_cc(); |
4911 |
s->cc_op = CC_OP_ADDB + ot; |
4912 |
break;
|
4913 |
case 0x1b0: |
4914 |
case 0x1b1: /* cmpxchg Ev, Gv */ |
4915 |
{ |
4916 |
int label1, label2;
|
4917 |
TCGv t0, t1, t2, a0; |
4918 |
|
4919 |
if ((b & 1) == 0) |
4920 |
ot = OT_BYTE; |
4921 |
else
|
4922 |
ot = dflag + OT_WORD; |
4923 |
modrm = cpu_ldub_code(env, s->pc++); |
4924 |
reg = ((modrm >> 3) & 7) | rex_r; |
4925 |
mod = (modrm >> 6) & 3; |
4926 |
t0 = tcg_temp_local_new(); |
4927 |
t1 = tcg_temp_local_new(); |
4928 |
t2 = tcg_temp_local_new(); |
4929 |
a0 = tcg_temp_local_new(); |
4930 |
gen_op_mov_v_reg(ot, t1, reg); |
4931 |
if (mod == 3) { |
4932 |
rm = (modrm & 7) | REX_B(s);
|
4933 |
gen_op_mov_v_reg(ot, t0, rm); |
4934 |
} else {
|
4935 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
4936 |
tcg_gen_mov_tl(a0, cpu_A0); |
4937 |
gen_op_ld_v(ot + s->mem_index, t0, a0); |
4938 |
rm = 0; /* avoid warning */ |
4939 |
} |
4940 |
label1 = gen_new_label(); |
4941 |
tcg_gen_sub_tl(t2, cpu_regs[R_EAX], t0); |
4942 |
gen_extu(ot, t2); |
4943 |
tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, label1);
|
4944 |
label2 = gen_new_label(); |
4945 |
if (mod == 3) { |
4946 |
gen_op_mov_reg_v(ot, R_EAX, t0); |
4947 |
tcg_gen_br(label2); |
4948 |
gen_set_label(label1); |
4949 |
gen_op_mov_reg_v(ot, rm, t1); |
4950 |
} else {
|
4951 |
/* perform no-op store cycle like physical cpu; must be
|
4952 |
before changing accumulator to ensure idempotency if
|
4953 |
the store faults and the instruction is restarted */
|
4954 |
gen_op_st_v(ot + s->mem_index, t0, a0); |
4955 |
gen_op_mov_reg_v(ot, R_EAX, t0); |
4956 |
tcg_gen_br(label2); |
4957 |
gen_set_label(label1); |
4958 |
gen_op_st_v(ot + s->mem_index, t1, a0); |
4959 |
} |
4960 |
gen_set_label(label2); |
4961 |
tcg_gen_mov_tl(cpu_cc_src, t0); |
4962 |
tcg_gen_mov_tl(cpu_cc_dst, t2); |
4963 |
s->cc_op = CC_OP_SUBB + ot; |
4964 |
tcg_temp_free(t0); |
4965 |
tcg_temp_free(t1); |
4966 |
tcg_temp_free(t2); |
4967 |
tcg_temp_free(a0); |
4968 |
} |
4969 |
break;
|
4970 |
case 0x1c7: /* cmpxchg8b */ |
4971 |
modrm = cpu_ldub_code(env, s->pc++); |
4972 |
mod = (modrm >> 6) & 3; |
4973 |
if ((mod == 3) || ((modrm & 0x38) != 0x8)) |
4974 |
goto illegal_op;
|
4975 |
#ifdef TARGET_X86_64
|
4976 |
if (dflag == 2) { |
4977 |
if (!(s->cpuid_ext_features & CPUID_EXT_CX16))
|
4978 |
goto illegal_op;
|
4979 |
gen_jmp_im(pc_start - s->cs_base); |
4980 |
if (s->cc_op != CC_OP_DYNAMIC)
|
4981 |
gen_op_set_cc_op(s->cc_op); |
4982 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
4983 |
gen_helper_cmpxchg16b(cpu_env, cpu_A0); |
4984 |
} else
|
4985 |
#endif
|
4986 |
{ |
4987 |
if (!(s->cpuid_features & CPUID_CX8))
|
4988 |
goto illegal_op;
|
4989 |
gen_jmp_im(pc_start - s->cs_base); |
4990 |
if (s->cc_op != CC_OP_DYNAMIC)
|
4991 |
gen_op_set_cc_op(s->cc_op); |
4992 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
4993 |
gen_helper_cmpxchg8b(cpu_env, cpu_A0); |
4994 |
} |
4995 |
s->cc_op = CC_OP_EFLAGS; |
4996 |
break;
|
4997 |
|
4998 |
/**************************/
|
4999 |
/* push/pop */
|
5000 |
case 0x50 ... 0x57: /* push */ |
5001 |
gen_op_mov_TN_reg(OT_LONG, 0, (b & 7) | REX_B(s)); |
5002 |
gen_push_T0(s); |
5003 |
break;
|
5004 |
case 0x58 ... 0x5f: /* pop */ |
5005 |
if (CODE64(s)) {
|
5006 |
ot = dflag ? OT_QUAD : OT_WORD; |
5007 |
} else {
|
5008 |
ot = dflag + OT_WORD; |
5009 |
} |
5010 |
gen_pop_T0(s); |
5011 |
/* NOTE: order is important for pop %sp */
|
5012 |
gen_pop_update(s); |
5013 |
gen_op_mov_reg_T0(ot, (b & 7) | REX_B(s));
|
5014 |
break;
|
5015 |
case 0x60: /* pusha */ |
5016 |
if (CODE64(s))
|
5017 |
goto illegal_op;
|
5018 |
gen_pusha(s); |
5019 |
break;
|
5020 |
case 0x61: /* popa */ |
5021 |
if (CODE64(s))
|
5022 |
goto illegal_op;
|
5023 |
gen_popa(s); |
5024 |
break;
|
5025 |
case 0x68: /* push Iv */ |
5026 |
case 0x6a: |
5027 |
if (CODE64(s)) {
|
5028 |
ot = dflag ? OT_QUAD : OT_WORD; |
5029 |
} else {
|
5030 |
ot = dflag + OT_WORD; |
5031 |
} |
5032 |
if (b == 0x68) |
5033 |
val = insn_get(env, s, ot); |
5034 |
else
|
5035 |
val = (int8_t)insn_get(env, s, OT_BYTE); |
5036 |
gen_op_movl_T0_im(val); |
5037 |
gen_push_T0(s); |
5038 |
break;
|
5039 |
case 0x8f: /* pop Ev */ |
5040 |
if (CODE64(s)) {
|
5041 |
ot = dflag ? OT_QUAD : OT_WORD; |
5042 |
} else {
|
5043 |
ot = dflag + OT_WORD; |
5044 |
} |
5045 |
modrm = cpu_ldub_code(env, s->pc++); |
5046 |
mod = (modrm >> 6) & 3; |
5047 |
gen_pop_T0(s); |
5048 |
if (mod == 3) { |
5049 |
/* NOTE: order is important for pop %sp */
|
5050 |
gen_pop_update(s); |
5051 |
rm = (modrm & 7) | REX_B(s);
|
5052 |
gen_op_mov_reg_T0(ot, rm); |
5053 |
} else {
|
5054 |
/* NOTE: order is important too for MMU exceptions */
|
5055 |
s->popl_esp_hack = 1 << ot;
|
5056 |
gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 1);
|
5057 |
s->popl_esp_hack = 0;
|
5058 |
gen_pop_update(s); |
5059 |
} |
5060 |
break;
|
5061 |
case 0xc8: /* enter */ |
5062 |
{ |
5063 |
int level;
|
5064 |
val = cpu_lduw_code(env, s->pc); |
5065 |
s->pc += 2;
|
5066 |
level = cpu_ldub_code(env, s->pc++); |
5067 |
gen_enter(s, val, level); |
5068 |
} |
5069 |
break;
|
5070 |
case 0xc9: /* leave */ |
5071 |
/* XXX: exception not precise (ESP is updated before potential exception) */
|
5072 |
if (CODE64(s)) {
|
5073 |
gen_op_mov_TN_reg(OT_QUAD, 0, R_EBP);
|
5074 |
gen_op_mov_reg_T0(OT_QUAD, R_ESP); |
5075 |
} else if (s->ss32) { |
5076 |
gen_op_mov_TN_reg(OT_LONG, 0, R_EBP);
|
5077 |
gen_op_mov_reg_T0(OT_LONG, R_ESP); |
5078 |
} else {
|
5079 |
gen_op_mov_TN_reg(OT_WORD, 0, R_EBP);
|
5080 |
gen_op_mov_reg_T0(OT_WORD, R_ESP); |
5081 |
} |
5082 |
gen_pop_T0(s); |
5083 |
if (CODE64(s)) {
|
5084 |
ot = dflag ? OT_QUAD : OT_WORD; |
5085 |
} else {
|
5086 |
ot = dflag + OT_WORD; |
5087 |
} |
5088 |
gen_op_mov_reg_T0(ot, R_EBP); |
5089 |
gen_pop_update(s); |
5090 |
break;
|
5091 |
case 0x06: /* push es */ |
5092 |
case 0x0e: /* push cs */ |
5093 |
case 0x16: /* push ss */ |
5094 |
case 0x1e: /* push ds */ |
5095 |
if (CODE64(s))
|
5096 |
goto illegal_op;
|
5097 |
gen_op_movl_T0_seg(b >> 3);
|
5098 |
gen_push_T0(s); |
5099 |
break;
|
5100 |
case 0x1a0: /* push fs */ |
5101 |
case 0x1a8: /* push gs */ |
5102 |
gen_op_movl_T0_seg((b >> 3) & 7); |
5103 |
gen_push_T0(s); |
5104 |
break;
|
5105 |
case 0x07: /* pop es */ |
5106 |
case 0x17: /* pop ss */ |
5107 |
case 0x1f: /* pop ds */ |
5108 |
if (CODE64(s))
|
5109 |
goto illegal_op;
|
5110 |
reg = b >> 3;
|
5111 |
gen_pop_T0(s); |
5112 |
gen_movl_seg_T0(s, reg, pc_start - s->cs_base); |
5113 |
gen_pop_update(s); |
5114 |
if (reg == R_SS) {
|
5115 |
/* if reg == SS, inhibit interrupts/trace. */
|
5116 |
/* If several instructions disable interrupts, only the
|
5117 |
_first_ does it */
|
5118 |
if (!(s->tb->flags & HF_INHIBIT_IRQ_MASK))
|
5119 |
gen_helper_set_inhibit_irq(cpu_env); |
5120 |
s->tf = 0;
|
5121 |
} |
5122 |
if (s->is_jmp) {
|
5123 |
gen_jmp_im(s->pc - s->cs_base); |
5124 |
gen_eob(s); |
5125 |
} |
5126 |
break;
|
5127 |
case 0x1a1: /* pop fs */ |
5128 |
case 0x1a9: /* pop gs */ |
5129 |
gen_pop_T0(s); |
5130 |
gen_movl_seg_T0(s, (b >> 3) & 7, pc_start - s->cs_base); |
5131 |
gen_pop_update(s); |
5132 |
if (s->is_jmp) {
|
5133 |
gen_jmp_im(s->pc - s->cs_base); |
5134 |
gen_eob(s); |
5135 |
} |
5136 |
break;
|
5137 |
|
5138 |
/**************************/
|
5139 |
/* mov */
|
5140 |
case 0x88: |
5141 |
case 0x89: /* mov Gv, Ev */ |
5142 |
if ((b & 1) == 0) |
5143 |
ot = OT_BYTE; |
5144 |
else
|
5145 |
ot = dflag + OT_WORD; |
5146 |
modrm = cpu_ldub_code(env, s->pc++); |
5147 |
reg = ((modrm >> 3) & 7) | rex_r; |
5148 |
|
5149 |
/* generate a generic store */
|
5150 |
gen_ldst_modrm(env, s, modrm, ot, reg, 1);
|
5151 |
break;
|
5152 |
case 0xc6: |
5153 |
case 0xc7: /* mov Ev, Iv */ |
5154 |
if ((b & 1) == 0) |
5155 |
ot = OT_BYTE; |
5156 |
else
|
5157 |
ot = dflag + OT_WORD; |
5158 |
modrm = cpu_ldub_code(env, s->pc++); |
5159 |
mod = (modrm >> 6) & 3; |
5160 |
if (mod != 3) { |
5161 |
s->rip_offset = insn_const_size(ot); |
5162 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
5163 |
} |
5164 |
val = insn_get(env, s, ot); |
5165 |
gen_op_movl_T0_im(val); |
5166 |
if (mod != 3) |
5167 |
gen_op_st_T0_A0(ot + s->mem_index); |
5168 |
else
|
5169 |
gen_op_mov_reg_T0(ot, (modrm & 7) | REX_B(s));
|
5170 |
break;
|
5171 |
case 0x8a: |
5172 |
case 0x8b: /* mov Ev, Gv */ |
5173 |
if ((b & 1) == 0) |
5174 |
ot = OT_BYTE; |
5175 |
else
|
5176 |
ot = OT_WORD + dflag; |
5177 |
modrm = cpu_ldub_code(env, s->pc++); |
5178 |
reg = ((modrm >> 3) & 7) | rex_r; |
5179 |
|
5180 |
gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0);
|
5181 |
gen_op_mov_reg_T0(ot, reg); |
5182 |
break;
|
5183 |
case 0x8e: /* mov seg, Gv */ |
5184 |
modrm = cpu_ldub_code(env, s->pc++); |
5185 |
reg = (modrm >> 3) & 7; |
5186 |
if (reg >= 6 || reg == R_CS) |
5187 |
goto illegal_op;
|
5188 |
gen_ldst_modrm(env, s, modrm, OT_WORD, OR_TMP0, 0);
|
5189 |
gen_movl_seg_T0(s, reg, pc_start - s->cs_base); |
5190 |
if (reg == R_SS) {
|
5191 |
/* if reg == SS, inhibit interrupts/trace */
|
5192 |
/* If several instructions disable interrupts, only the
|
5193 |
_first_ does it */
|
5194 |
if (!(s->tb->flags & HF_INHIBIT_IRQ_MASK))
|
5195 |
gen_helper_set_inhibit_irq(cpu_env); |
5196 |
s->tf = 0;
|
5197 |
} |
5198 |
if (s->is_jmp) {
|
5199 |
gen_jmp_im(s->pc - s->cs_base); |
5200 |
gen_eob(s); |
5201 |
} |
5202 |
break;
|
5203 |
case 0x8c: /* mov Gv, seg */ |
5204 |
modrm = cpu_ldub_code(env, s->pc++); |
5205 |
reg = (modrm >> 3) & 7; |
5206 |
mod = (modrm >> 6) & 3; |
5207 |
if (reg >= 6) |
5208 |
goto illegal_op;
|
5209 |
gen_op_movl_T0_seg(reg); |
5210 |
if (mod == 3) |
5211 |
ot = OT_WORD + dflag; |
5212 |
else
|
5213 |
ot = OT_WORD; |
5214 |
gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 1);
|
5215 |
break;
|
5216 |
|
5217 |
case 0x1b6: /* movzbS Gv, Eb */ |
5218 |
case 0x1b7: /* movzwS Gv, Eb */ |
5219 |
case 0x1be: /* movsbS Gv, Eb */ |
5220 |
case 0x1bf: /* movswS Gv, Eb */ |
5221 |
{ |
5222 |
int d_ot;
|
5223 |
/* d_ot is the size of destination */
|
5224 |
d_ot = dflag + OT_WORD; |
5225 |
/* ot is the size of source */
|
5226 |
ot = (b & 1) + OT_BYTE;
|
5227 |
modrm = cpu_ldub_code(env, s->pc++); |
5228 |
reg = ((modrm >> 3) & 7) | rex_r; |
5229 |
mod = (modrm >> 6) & 3; |
5230 |
rm = (modrm & 7) | REX_B(s);
|
5231 |
|
5232 |
if (mod == 3) { |
5233 |
gen_op_mov_TN_reg(ot, 0, rm);
|
5234 |
switch(ot | (b & 8)) { |
5235 |
case OT_BYTE:
|
5236 |
tcg_gen_ext8u_tl(cpu_T[0], cpu_T[0]); |
5237 |
break;
|
5238 |
case OT_BYTE | 8: |
5239 |
tcg_gen_ext8s_tl(cpu_T[0], cpu_T[0]); |
5240 |
break;
|
5241 |
case OT_WORD:
|
5242 |
tcg_gen_ext16u_tl(cpu_T[0], cpu_T[0]); |
5243 |
break;
|
5244 |
default:
|
5245 |
case OT_WORD | 8: |
5246 |
tcg_gen_ext16s_tl(cpu_T[0], cpu_T[0]); |
5247 |
break;
|
5248 |
} |
5249 |
gen_op_mov_reg_T0(d_ot, reg); |
5250 |
} else {
|
5251 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
5252 |
if (b & 8) { |
5253 |
gen_op_lds_T0_A0(ot + s->mem_index); |
5254 |
} else {
|
5255 |
gen_op_ldu_T0_A0(ot + s->mem_index); |
5256 |
} |
5257 |
gen_op_mov_reg_T0(d_ot, reg); |
5258 |
} |
5259 |
} |
5260 |
break;
|
5261 |
|
5262 |
case 0x8d: /* lea */ |
5263 |
ot = dflag + OT_WORD; |
5264 |
modrm = cpu_ldub_code(env, s->pc++); |
5265 |
mod = (modrm >> 6) & 3; |
5266 |
if (mod == 3) |
5267 |
goto illegal_op;
|
5268 |
reg = ((modrm >> 3) & 7) | rex_r; |
5269 |
/* we must ensure that no segment is added */
|
5270 |
s->override = -1;
|
5271 |
val = s->addseg; |
5272 |
s->addseg = 0;
|
5273 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
5274 |
s->addseg = val; |
5275 |
gen_op_mov_reg_A0(ot - OT_WORD, reg); |
5276 |
break;
|
5277 |
|
5278 |
case 0xa0: /* mov EAX, Ov */ |
5279 |
case 0xa1: |
5280 |
case 0xa2: /* mov Ov, EAX */ |
5281 |
case 0xa3: |
5282 |
{ |
5283 |
target_ulong offset_addr; |
5284 |
|
5285 |
if ((b & 1) == 0) |
5286 |
ot = OT_BYTE; |
5287 |
else
|
5288 |
ot = dflag + OT_WORD; |
5289 |
#ifdef TARGET_X86_64
|
5290 |
if (s->aflag == 2) { |
5291 |
offset_addr = cpu_ldq_code(env, s->pc); |
5292 |
s->pc += 8;
|
5293 |
gen_op_movq_A0_im(offset_addr); |
5294 |
} else
|
5295 |
#endif
|
5296 |
{ |
5297 |
if (s->aflag) {
|
5298 |
offset_addr = insn_get(env, s, OT_LONG); |
5299 |
} else {
|
5300 |
offset_addr = insn_get(env, s, OT_WORD); |
5301 |
} |
5302 |
gen_op_movl_A0_im(offset_addr); |
5303 |
} |
5304 |
gen_add_A0_ds_seg(s); |
5305 |
if ((b & 2) == 0) { |
5306 |
gen_op_ld_T0_A0(ot + s->mem_index); |
5307 |
gen_op_mov_reg_T0(ot, R_EAX); |
5308 |
} else {
|
5309 |
gen_op_mov_TN_reg(ot, 0, R_EAX);
|
5310 |
gen_op_st_T0_A0(ot + s->mem_index); |
5311 |
} |
5312 |
} |
5313 |
break;
|
5314 |
case 0xd7: /* xlat */ |
5315 |
#ifdef TARGET_X86_64
|
5316 |
if (s->aflag == 2) { |
5317 |
gen_op_movq_A0_reg(R_EBX); |
5318 |
gen_op_mov_TN_reg(OT_QUAD, 0, R_EAX);
|
5319 |
tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0xff); |
5320 |
tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_T[0]);
|
5321 |
} else
|
5322 |
#endif
|
5323 |
{ |
5324 |
gen_op_movl_A0_reg(R_EBX); |
5325 |
gen_op_mov_TN_reg(OT_LONG, 0, R_EAX);
|
5326 |
tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0xff); |
5327 |
tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_T[0]);
|
5328 |
if (s->aflag == 0) |
5329 |
gen_op_andl_A0_ffff(); |
5330 |
else
|
5331 |
tcg_gen_andi_tl(cpu_A0, cpu_A0, 0xffffffff);
|
5332 |
} |
5333 |
gen_add_A0_ds_seg(s); |
5334 |
gen_op_ldu_T0_A0(OT_BYTE + s->mem_index); |
5335 |
gen_op_mov_reg_T0(OT_BYTE, R_EAX); |
5336 |
break;
|
5337 |
case 0xb0 ... 0xb7: /* mov R, Ib */ |
5338 |
val = insn_get(env, s, OT_BYTE); |
5339 |
gen_op_movl_T0_im(val); |
5340 |
gen_op_mov_reg_T0(OT_BYTE, (b & 7) | REX_B(s));
|
5341 |
break;
|
5342 |
case 0xb8 ... 0xbf: /* mov R, Iv */ |
5343 |
#ifdef TARGET_X86_64
|
5344 |
if (dflag == 2) { |
5345 |
uint64_t tmp; |
5346 |
/* 64 bit case */
|
5347 |
tmp = cpu_ldq_code(env, s->pc); |
5348 |
s->pc += 8;
|
5349 |
reg = (b & 7) | REX_B(s);
|
5350 |
gen_movtl_T0_im(tmp); |
5351 |
gen_op_mov_reg_T0(OT_QUAD, reg); |
5352 |
} else
|
5353 |
#endif
|
5354 |
{ |
5355 |
ot = dflag ? OT_LONG : OT_WORD; |
5356 |
val = insn_get(env, s, ot); |
5357 |
reg = (b & 7) | REX_B(s);
|
5358 |
gen_op_movl_T0_im(val); |
5359 |
gen_op_mov_reg_T0(ot, reg); |
5360 |
} |
5361 |
break;
|
5362 |
|
5363 |
case 0x91 ... 0x97: /* xchg R, EAX */ |
5364 |
do_xchg_reg_eax: |
5365 |
ot = dflag + OT_WORD; |
5366 |
reg = (b & 7) | REX_B(s);
|
5367 |
rm = R_EAX; |
5368 |
goto do_xchg_reg;
|
5369 |
case 0x86: |
5370 |
case 0x87: /* xchg Ev, Gv */ |
5371 |
if ((b & 1) == 0) |
5372 |
ot = OT_BYTE; |
5373 |
else
|
5374 |
ot = dflag + OT_WORD; |
5375 |
modrm = cpu_ldub_code(env, s->pc++); |
5376 |
reg = ((modrm >> 3) & 7) | rex_r; |
5377 |
mod = (modrm >> 6) & 3; |
5378 |
if (mod == 3) { |
5379 |
rm = (modrm & 7) | REX_B(s);
|
5380 |
do_xchg_reg:
|
5381 |
gen_op_mov_TN_reg(ot, 0, reg);
|
5382 |
gen_op_mov_TN_reg(ot, 1, rm);
|
5383 |
gen_op_mov_reg_T0(ot, rm); |
5384 |
gen_op_mov_reg_T1(ot, reg); |
5385 |
} else {
|
5386 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
5387 |
gen_op_mov_TN_reg(ot, 0, reg);
|
5388 |
/* for xchg, lock is implicit */
|
5389 |
if (!(prefixes & PREFIX_LOCK))
|
5390 |
gen_helper_lock(); |
5391 |
gen_op_ld_T1_A0(ot + s->mem_index); |
5392 |
gen_op_st_T0_A0(ot + s->mem_index); |
5393 |
if (!(prefixes & PREFIX_LOCK))
|
5394 |
gen_helper_unlock(); |
5395 |
gen_op_mov_reg_T1(ot, reg); |
5396 |
} |
5397 |
break;
|
5398 |
case 0xc4: /* les Gv */ |
5399 |
if (CODE64(s))
|
5400 |
goto illegal_op;
|
5401 |
op = R_ES; |
5402 |
goto do_lxx;
|
5403 |
case 0xc5: /* lds Gv */ |
5404 |
if (CODE64(s))
|
5405 |
goto illegal_op;
|
5406 |
op = R_DS; |
5407 |
goto do_lxx;
|
5408 |
case 0x1b2: /* lss Gv */ |
5409 |
op = R_SS; |
5410 |
goto do_lxx;
|
5411 |
case 0x1b4: /* lfs Gv */ |
5412 |
op = R_FS; |
5413 |
goto do_lxx;
|
5414 |
case 0x1b5: /* lgs Gv */ |
5415 |
op = R_GS; |
5416 |
do_lxx:
|
5417 |
ot = dflag ? OT_LONG : OT_WORD; |
5418 |
modrm = cpu_ldub_code(env, s->pc++); |
5419 |
reg = ((modrm >> 3) & 7) | rex_r; |
5420 |
mod = (modrm >> 6) & 3; |
5421 |
if (mod == 3) |
5422 |
goto illegal_op;
|
5423 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
5424 |
gen_op_ld_T1_A0(ot + s->mem_index); |
5425 |
gen_add_A0_im(s, 1 << (ot - OT_WORD + 1)); |
5426 |
/* load the segment first to handle exceptions properly */
|
5427 |
gen_op_ldu_T0_A0(OT_WORD + s->mem_index); |
5428 |
gen_movl_seg_T0(s, op, pc_start - s->cs_base); |
5429 |
/* then put the data */
|
5430 |
gen_op_mov_reg_T1(ot, reg); |
5431 |
if (s->is_jmp) {
|
5432 |
gen_jmp_im(s->pc - s->cs_base); |
5433 |
gen_eob(s); |
5434 |
} |
5435 |
break;
|
5436 |
|
5437 |
/************************/
|
5438 |
/* shifts */
|
5439 |
case 0xc0: |
5440 |
case 0xc1: |
5441 |
/* shift Ev,Ib */
|
5442 |
shift = 2;
|
5443 |
grp2:
|
5444 |
{ |
5445 |
if ((b & 1) == 0) |
5446 |
ot = OT_BYTE; |
5447 |
else
|
5448 |
ot = dflag + OT_WORD; |
5449 |
|
5450 |
modrm = cpu_ldub_code(env, s->pc++); |
5451 |
mod = (modrm >> 6) & 3; |
5452 |
op = (modrm >> 3) & 7; |
5453 |
|
5454 |
if (mod != 3) { |
5455 |
if (shift == 2) { |
5456 |
s->rip_offset = 1;
|
5457 |
} |
5458 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
5459 |
opreg = OR_TMP0; |
5460 |
} else {
|
5461 |
opreg = (modrm & 7) | REX_B(s);
|
5462 |
} |
5463 |
|
5464 |
/* simpler op */
|
5465 |
if (shift == 0) { |
5466 |
gen_shift(s, op, ot, opreg, OR_ECX); |
5467 |
} else {
|
5468 |
if (shift == 2) { |
5469 |
shift = cpu_ldub_code(env, s->pc++); |
5470 |
} |
5471 |
gen_shifti(s, op, ot, opreg, shift); |
5472 |
} |
5473 |
} |
5474 |
break;
|
5475 |
case 0xd0: |
5476 |
case 0xd1: |
5477 |
/* shift Ev,1 */
|
5478 |
shift = 1;
|
5479 |
goto grp2;
|
5480 |
case 0xd2: |
5481 |
case 0xd3: |
5482 |
/* shift Ev,cl */
|
5483 |
shift = 0;
|
5484 |
goto grp2;
|
5485 |
|
5486 |
case 0x1a4: /* shld imm */ |
5487 |
op = 0;
|
5488 |
shift = 1;
|
5489 |
goto do_shiftd;
|
5490 |
case 0x1a5: /* shld cl */ |
5491 |
op = 0;
|
5492 |
shift = 0;
|
5493 |
goto do_shiftd;
|
5494 |
case 0x1ac: /* shrd imm */ |
5495 |
op = 1;
|
5496 |
shift = 1;
|
5497 |
goto do_shiftd;
|
5498 |
case 0x1ad: /* shrd cl */ |
5499 |
op = 1;
|
5500 |
shift = 0;
|
5501 |
do_shiftd:
|
5502 |
ot = dflag + OT_WORD; |
5503 |
modrm = cpu_ldub_code(env, s->pc++); |
5504 |
mod = (modrm >> 6) & 3; |
5505 |
rm = (modrm & 7) | REX_B(s);
|
5506 |
reg = ((modrm >> 3) & 7) | rex_r; |
5507 |
if (mod != 3) { |
5508 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
5509 |
opreg = OR_TMP0; |
5510 |
} else {
|
5511 |
opreg = rm; |
5512 |
} |
5513 |
gen_op_mov_TN_reg(ot, 1, reg);
|
5514 |
|
5515 |
if (shift) {
|
5516 |
val = cpu_ldub_code(env, s->pc++); |
5517 |
tcg_gen_movi_tl(cpu_T3, val); |
5518 |
} else {
|
5519 |
tcg_gen_mov_tl(cpu_T3, cpu_regs[R_ECX]); |
5520 |
} |
5521 |
gen_shiftd_rm_T1_T3(s, ot, opreg, op); |
5522 |
break;
|
5523 |
|
5524 |
/************************/
|
5525 |
/* floats */
|
5526 |
case 0xd8 ... 0xdf: |
5527 |
if (s->flags & (HF_EM_MASK | HF_TS_MASK)) {
|
5528 |
/* if CR0.EM or CR0.TS are set, generate an FPU exception */
|
5529 |
/* XXX: what to do if illegal op ? */
|
5530 |
gen_exception(s, EXCP07_PREX, pc_start - s->cs_base); |
5531 |
break;
|
5532 |
} |
5533 |
modrm = cpu_ldub_code(env, s->pc++); |
5534 |
mod = (modrm >> 6) & 3; |
5535 |
rm = modrm & 7;
|
5536 |
op = ((b & 7) << 3) | ((modrm >> 3) & 7); |
5537 |
if (mod != 3) { |
5538 |
/* memory op */
|
5539 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
5540 |
switch(op) {
|
5541 |
case 0x00 ... 0x07: /* fxxxs */ |
5542 |
case 0x10 ... 0x17: /* fixxxl */ |
5543 |
case 0x20 ... 0x27: /* fxxxl */ |
5544 |
case 0x30 ... 0x37: /* fixxx */ |
5545 |
{ |
5546 |
int op1;
|
5547 |
op1 = op & 7;
|
5548 |
|
5549 |
switch(op >> 4) { |
5550 |
case 0: |
5551 |
gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
5552 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5553 |
gen_helper_flds_FT0(cpu_env, cpu_tmp2_i32); |
5554 |
break;
|
5555 |
case 1: |
5556 |
gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
5557 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5558 |
gen_helper_fildl_FT0(cpu_env, cpu_tmp2_i32); |
5559 |
break;
|
5560 |
case 2: |
5561 |
tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_A0, |
5562 |
(s->mem_index >> 2) - 1); |
5563 |
gen_helper_fldl_FT0(cpu_env, cpu_tmp1_i64); |
5564 |
break;
|
5565 |
case 3: |
5566 |
default:
|
5567 |
gen_op_lds_T0_A0(OT_WORD + s->mem_index); |
5568 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5569 |
gen_helper_fildl_FT0(cpu_env, cpu_tmp2_i32); |
5570 |
break;
|
5571 |
} |
5572 |
|
5573 |
gen_helper_fp_arith_ST0_FT0(op1); |
5574 |
if (op1 == 3) { |
5575 |
/* fcomp needs pop */
|
5576 |
gen_helper_fpop(cpu_env); |
5577 |
} |
5578 |
} |
5579 |
break;
|
5580 |
case 0x08: /* flds */ |
5581 |
case 0x0a: /* fsts */ |
5582 |
case 0x0b: /* fstps */ |
5583 |
case 0x18 ... 0x1b: /* fildl, fisttpl, fistl, fistpl */ |
5584 |
case 0x28 ... 0x2b: /* fldl, fisttpll, fstl, fstpl */ |
5585 |
case 0x38 ... 0x3b: /* filds, fisttps, fists, fistps */ |
5586 |
switch(op & 7) { |
5587 |
case 0: |
5588 |
switch(op >> 4) { |
5589 |
case 0: |
5590 |
gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
5591 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5592 |
gen_helper_flds_ST0(cpu_env, cpu_tmp2_i32); |
5593 |
break;
|
5594 |
case 1: |
5595 |
gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
5596 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5597 |
gen_helper_fildl_ST0(cpu_env, cpu_tmp2_i32); |
5598 |
break;
|
5599 |
case 2: |
5600 |
tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_A0, |
5601 |
(s->mem_index >> 2) - 1); |
5602 |
gen_helper_fldl_ST0(cpu_env, cpu_tmp1_i64); |
5603 |
break;
|
5604 |
case 3: |
5605 |
default:
|
5606 |
gen_op_lds_T0_A0(OT_WORD + s->mem_index); |
5607 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5608 |
gen_helper_fildl_ST0(cpu_env, cpu_tmp2_i32); |
5609 |
break;
|
5610 |
} |
5611 |
break;
|
5612 |
case 1: |
5613 |
/* XXX: the corresponding CPUID bit must be tested ! */
|
5614 |
switch(op >> 4) { |
5615 |
case 1: |
5616 |
gen_helper_fisttl_ST0(cpu_tmp2_i32, cpu_env); |
5617 |
tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5618 |
gen_op_st_T0_A0(OT_LONG + s->mem_index); |
5619 |
break;
|
5620 |
case 2: |
5621 |
gen_helper_fisttll_ST0(cpu_tmp1_i64, cpu_env); |
5622 |
tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_A0, |
5623 |
(s->mem_index >> 2) - 1); |
5624 |
break;
|
5625 |
case 3: |
5626 |
default:
|
5627 |
gen_helper_fistt_ST0(cpu_tmp2_i32, cpu_env); |
5628 |
tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5629 |
gen_op_st_T0_A0(OT_WORD + s->mem_index); |
5630 |
break;
|
5631 |
} |
5632 |
gen_helper_fpop(cpu_env); |
5633 |
break;
|
5634 |
default:
|
5635 |
switch(op >> 4) { |
5636 |
case 0: |
5637 |
gen_helper_fsts_ST0(cpu_tmp2_i32, cpu_env); |
5638 |
tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5639 |
gen_op_st_T0_A0(OT_LONG + s->mem_index); |
5640 |
break;
|
5641 |
case 1: |
5642 |
gen_helper_fistl_ST0(cpu_tmp2_i32, cpu_env); |
5643 |
tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5644 |
gen_op_st_T0_A0(OT_LONG + s->mem_index); |
5645 |
break;
|
5646 |
case 2: |
5647 |
gen_helper_fstl_ST0(cpu_tmp1_i64, cpu_env); |
5648 |
tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_A0, |
5649 |
(s->mem_index >> 2) - 1); |
5650 |
break;
|
5651 |
case 3: |
5652 |
default:
|
5653 |
gen_helper_fist_ST0(cpu_tmp2_i32, cpu_env); |
5654 |
tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5655 |
gen_op_st_T0_A0(OT_WORD + s->mem_index); |
5656 |
break;
|
5657 |
} |
5658 |
if ((op & 7) == 3) |
5659 |
gen_helper_fpop(cpu_env); |
5660 |
break;
|
5661 |
} |
5662 |
break;
|
5663 |
case 0x0c: /* fldenv mem */ |
5664 |
if (s->cc_op != CC_OP_DYNAMIC)
|
5665 |
gen_op_set_cc_op(s->cc_op); |
5666 |
gen_jmp_im(pc_start - s->cs_base); |
5667 |
gen_helper_fldenv(cpu_env, cpu_A0, tcg_const_i32(s->dflag)); |
5668 |
break;
|
5669 |
case 0x0d: /* fldcw mem */ |
5670 |
gen_op_ld_T0_A0(OT_WORD + s->mem_index); |
5671 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5672 |
gen_helper_fldcw(cpu_env, cpu_tmp2_i32); |
5673 |
break;
|
5674 |
case 0x0e: /* fnstenv mem */ |
5675 |
if (s->cc_op != CC_OP_DYNAMIC)
|
5676 |
gen_op_set_cc_op(s->cc_op); |
5677 |
gen_jmp_im(pc_start - s->cs_base); |
5678 |
gen_helper_fstenv(cpu_env, cpu_A0, tcg_const_i32(s->dflag)); |
5679 |
break;
|
5680 |
case 0x0f: /* fnstcw mem */ |
5681 |
gen_helper_fnstcw(cpu_tmp2_i32, cpu_env); |
5682 |
tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5683 |
gen_op_st_T0_A0(OT_WORD + s->mem_index); |
5684 |
break;
|
5685 |
case 0x1d: /* fldt mem */ |
5686 |
if (s->cc_op != CC_OP_DYNAMIC)
|
5687 |
gen_op_set_cc_op(s->cc_op); |
5688 |
gen_jmp_im(pc_start - s->cs_base); |
5689 |
gen_helper_fldt_ST0(cpu_env, cpu_A0); |
5690 |
break;
|
5691 |
case 0x1f: /* fstpt mem */ |
5692 |
if (s->cc_op != CC_OP_DYNAMIC)
|
5693 |
gen_op_set_cc_op(s->cc_op); |
5694 |
gen_jmp_im(pc_start - s->cs_base); |
5695 |
gen_helper_fstt_ST0(cpu_env, cpu_A0); |
5696 |
gen_helper_fpop(cpu_env); |
5697 |
break;
|
5698 |
case 0x2c: /* frstor mem */ |
5699 |
if (s->cc_op != CC_OP_DYNAMIC)
|
5700 |
gen_op_set_cc_op(s->cc_op); |
5701 |
gen_jmp_im(pc_start - s->cs_base); |
5702 |
gen_helper_frstor(cpu_env, cpu_A0, tcg_const_i32(s->dflag)); |
5703 |
break;
|
5704 |
case 0x2e: /* fnsave mem */ |
5705 |
if (s->cc_op != CC_OP_DYNAMIC)
|
5706 |
gen_op_set_cc_op(s->cc_op); |
5707 |
gen_jmp_im(pc_start - s->cs_base); |
5708 |
gen_helper_fsave(cpu_env, cpu_A0, tcg_const_i32(s->dflag)); |
5709 |
break;
|
5710 |
case 0x2f: /* fnstsw mem */ |
5711 |
gen_helper_fnstsw(cpu_tmp2_i32, cpu_env); |
5712 |
tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5713 |
gen_op_st_T0_A0(OT_WORD + s->mem_index); |
5714 |
break;
|
5715 |
case 0x3c: /* fbld */ |
5716 |
if (s->cc_op != CC_OP_DYNAMIC)
|
5717 |
gen_op_set_cc_op(s->cc_op); |
5718 |
gen_jmp_im(pc_start - s->cs_base); |
5719 |
gen_helper_fbld_ST0(cpu_env, cpu_A0); |
5720 |
break;
|
5721 |
case 0x3e: /* fbstp */ |
5722 |
if (s->cc_op != CC_OP_DYNAMIC)
|
5723 |
gen_op_set_cc_op(s->cc_op); |
5724 |
gen_jmp_im(pc_start - s->cs_base); |
5725 |
gen_helper_fbst_ST0(cpu_env, cpu_A0); |
5726 |
gen_helper_fpop(cpu_env); |
5727 |
break;
|
5728 |
case 0x3d: /* fildll */ |
5729 |
tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_A0, |
5730 |
(s->mem_index >> 2) - 1); |
5731 |
gen_helper_fildll_ST0(cpu_env, cpu_tmp1_i64); |
5732 |
break;
|
5733 |
case 0x3f: /* fistpll */ |
5734 |
gen_helper_fistll_ST0(cpu_tmp1_i64, cpu_env); |
5735 |
tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_A0, |
5736 |
(s->mem_index >> 2) - 1); |
5737 |
gen_helper_fpop(cpu_env); |
5738 |
break;
|
5739 |
default:
|
5740 |
goto illegal_op;
|
5741 |
} |
5742 |
} else {
|
5743 |
/* register float ops */
|
5744 |
opreg = rm; |
5745 |
|
5746 |
switch(op) {
|
5747 |
case 0x08: /* fld sti */ |
5748 |
gen_helper_fpush(cpu_env); |
5749 |
gen_helper_fmov_ST0_STN(cpu_env, |
5750 |
tcg_const_i32((opreg + 1) & 7)); |
5751 |
break;
|
5752 |
case 0x09: /* fxchg sti */ |
5753 |
case 0x29: /* fxchg4 sti, undocumented op */ |
5754 |
case 0x39: /* fxchg7 sti, undocumented op */ |
5755 |
gen_helper_fxchg_ST0_STN(cpu_env, tcg_const_i32(opreg)); |
5756 |
break;
|
5757 |
case 0x0a: /* grp d9/2 */ |
5758 |
switch(rm) {
|
5759 |
case 0: /* fnop */ |
5760 |
/* check exceptions (FreeBSD FPU probe) */
|
5761 |
if (s->cc_op != CC_OP_DYNAMIC)
|
5762 |
gen_op_set_cc_op(s->cc_op); |
5763 |
gen_jmp_im(pc_start - s->cs_base); |
5764 |
gen_helper_fwait(cpu_env); |
5765 |
break;
|
5766 |
default:
|
5767 |
goto illegal_op;
|
5768 |
} |
5769 |
break;
|
5770 |
case 0x0c: /* grp d9/4 */ |
5771 |
switch(rm) {
|
5772 |
case 0: /* fchs */ |
5773 |
gen_helper_fchs_ST0(cpu_env); |
5774 |
break;
|
5775 |
case 1: /* fabs */ |
5776 |
gen_helper_fabs_ST0(cpu_env); |
5777 |
break;
|
5778 |
case 4: /* ftst */ |
5779 |
gen_helper_fldz_FT0(cpu_env); |
5780 |
gen_helper_fcom_ST0_FT0(cpu_env); |
5781 |
break;
|
5782 |
case 5: /* fxam */ |
5783 |
gen_helper_fxam_ST0(cpu_env); |
5784 |
break;
|
5785 |
default:
|
5786 |
goto illegal_op;
|
5787 |
} |
5788 |
break;
|
5789 |
case 0x0d: /* grp d9/5 */ |
5790 |
{ |
5791 |
switch(rm) {
|
5792 |
case 0: |
5793 |
gen_helper_fpush(cpu_env); |
5794 |
gen_helper_fld1_ST0(cpu_env); |
5795 |
break;
|
5796 |
case 1: |
5797 |
gen_helper_fpush(cpu_env); |
5798 |
gen_helper_fldl2t_ST0(cpu_env); |
5799 |
break;
|
5800 |
case 2: |
5801 |
gen_helper_fpush(cpu_env); |
5802 |
gen_helper_fldl2e_ST0(cpu_env); |
5803 |
break;
|
5804 |
case 3: |
5805 |
gen_helper_fpush(cpu_env); |
5806 |
gen_helper_fldpi_ST0(cpu_env); |
5807 |
break;
|
5808 |
case 4: |
5809 |
gen_helper_fpush(cpu_env); |
5810 |
gen_helper_fldlg2_ST0(cpu_env); |
5811 |
break;
|
5812 |
case 5: |
5813 |
gen_helper_fpush(cpu_env); |
5814 |
gen_helper_fldln2_ST0(cpu_env); |
5815 |
break;
|
5816 |
case 6: |
5817 |
gen_helper_fpush(cpu_env); |
5818 |
gen_helper_fldz_ST0(cpu_env); |
5819 |
break;
|
5820 |
default:
|
5821 |
goto illegal_op;
|
5822 |
} |
5823 |
} |
5824 |
break;
|
5825 |
case 0x0e: /* grp d9/6 */ |
5826 |
switch(rm) {
|
5827 |
case 0: /* f2xm1 */ |
5828 |
gen_helper_f2xm1(cpu_env); |
5829 |
break;
|
5830 |
case 1: /* fyl2x */ |
5831 |
gen_helper_fyl2x(cpu_env); |
5832 |
break;
|
5833 |
case 2: /* fptan */ |
5834 |
gen_helper_fptan(cpu_env); |
5835 |
break;
|
5836 |
case 3: /* fpatan */ |
5837 |
gen_helper_fpatan(cpu_env); |
5838 |
break;
|
5839 |
case 4: /* fxtract */ |
5840 |
gen_helper_fxtract(cpu_env); |
5841 |
break;
|
5842 |
case 5: /* fprem1 */ |
5843 |
gen_helper_fprem1(cpu_env); |
5844 |
break;
|
5845 |
case 6: /* fdecstp */ |
5846 |
gen_helper_fdecstp(cpu_env); |
5847 |
break;
|
5848 |
default:
|
5849 |
case 7: /* fincstp */ |
5850 |
gen_helper_fincstp(cpu_env); |
5851 |
break;
|
5852 |
} |
5853 |
break;
|
5854 |
case 0x0f: /* grp d9/7 */ |
5855 |
switch(rm) {
|
5856 |
case 0: /* fprem */ |
5857 |
gen_helper_fprem(cpu_env); |
5858 |
break;
|
5859 |
case 1: /* fyl2xp1 */ |
5860 |
gen_helper_fyl2xp1(cpu_env); |
5861 |
break;
|
5862 |
case 2: /* fsqrt */ |
5863 |
gen_helper_fsqrt(cpu_env); |
5864 |
break;
|
5865 |
case 3: /* fsincos */ |
5866 |
gen_helper_fsincos(cpu_env); |
5867 |
break;
|
5868 |
case 5: /* fscale */ |
5869 |
gen_helper_fscale(cpu_env); |
5870 |
break;
|
5871 |
case 4: /* frndint */ |
5872 |
gen_helper_frndint(cpu_env); |
5873 |
break;
|
5874 |
case 6: /* fsin */ |
5875 |
gen_helper_fsin(cpu_env); |
5876 |
break;
|
5877 |
default:
|
5878 |
case 7: /* fcos */ |
5879 |
gen_helper_fcos(cpu_env); |
5880 |
break;
|
5881 |
} |
5882 |
break;
|
5883 |
case 0x00: case 0x01: case 0x04 ... 0x07: /* fxxx st, sti */ |
5884 |
case 0x20: case 0x21: case 0x24 ... 0x27: /* fxxx sti, st */ |
5885 |
case 0x30: case 0x31: case 0x34 ... 0x37: /* fxxxp sti, st */ |
5886 |
{ |
5887 |
int op1;
|
5888 |
|
5889 |
op1 = op & 7;
|
5890 |
if (op >= 0x20) { |
5891 |
gen_helper_fp_arith_STN_ST0(op1, opreg); |
5892 |
if (op >= 0x30) |
5893 |
gen_helper_fpop(cpu_env); |
5894 |
} else {
|
5895 |
gen_helper_fmov_FT0_STN(cpu_env, tcg_const_i32(opreg)); |
5896 |
gen_helper_fp_arith_ST0_FT0(op1); |
5897 |
} |
5898 |
} |
5899 |
break;
|
5900 |
case 0x02: /* fcom */ |
5901 |
case 0x22: /* fcom2, undocumented op */ |
5902 |
gen_helper_fmov_FT0_STN(cpu_env, tcg_const_i32(opreg)); |
5903 |
gen_helper_fcom_ST0_FT0(cpu_env); |
5904 |
break;
|
5905 |
case 0x03: /* fcomp */ |
5906 |
case 0x23: /* fcomp3, undocumented op */ |
5907 |
case 0x32: /* fcomp5, undocumented op */ |
5908 |
gen_helper_fmov_FT0_STN(cpu_env, tcg_const_i32(opreg)); |
5909 |
gen_helper_fcom_ST0_FT0(cpu_env); |
5910 |
gen_helper_fpop(cpu_env); |
5911 |
break;
|
5912 |
case 0x15: /* da/5 */ |
5913 |
switch(rm) {
|
5914 |
case 1: /* fucompp */ |
5915 |
gen_helper_fmov_FT0_STN(cpu_env, tcg_const_i32(1));
|
5916 |
gen_helper_fucom_ST0_FT0(cpu_env); |
5917 |
gen_helper_fpop(cpu_env); |
5918 |
gen_helper_fpop(cpu_env); |
5919 |
break;
|
5920 |
default:
|
5921 |
goto illegal_op;
|
5922 |
} |
5923 |
break;
|
5924 |
case 0x1c: |
5925 |
switch(rm) {
|
5926 |
case 0: /* feni (287 only, just do nop here) */ |
5927 |
break;
|
5928 |
case 1: /* fdisi (287 only, just do nop here) */ |
5929 |
break;
|
5930 |
case 2: /* fclex */ |
5931 |
gen_helper_fclex(cpu_env); |
5932 |
break;
|
5933 |
case 3: /* fninit */ |
5934 |
gen_helper_fninit(cpu_env); |
5935 |
break;
|
5936 |
case 4: /* fsetpm (287 only, just do nop here) */ |
5937 |
break;
|
5938 |
default:
|
5939 |
goto illegal_op;
|
5940 |
} |
5941 |
break;
|
5942 |
case 0x1d: /* fucomi */ |
5943 |
if (s->cc_op != CC_OP_DYNAMIC)
|
5944 |
gen_op_set_cc_op(s->cc_op); |
5945 |
gen_helper_fmov_FT0_STN(cpu_env, tcg_const_i32(opreg)); |
5946 |
gen_helper_fucomi_ST0_FT0(cpu_env); |
5947 |
s->cc_op = CC_OP_EFLAGS; |
5948 |
break;
|
5949 |
case 0x1e: /* fcomi */ |
5950 |
if (s->cc_op != CC_OP_DYNAMIC)
|
5951 |
gen_op_set_cc_op(s->cc_op); |
5952 |
gen_helper_fmov_FT0_STN(cpu_env, tcg_const_i32(opreg)); |
5953 |
gen_helper_fcomi_ST0_FT0(cpu_env); |
5954 |
s->cc_op = CC_OP_EFLAGS; |
5955 |
break;
|
5956 |
case 0x28: /* ffree sti */ |
5957 |
gen_helper_ffree_STN(cpu_env, tcg_const_i32(opreg)); |
5958 |
break;
|
5959 |
case 0x2a: /* fst sti */ |
5960 |
gen_helper_fmov_STN_ST0(cpu_env, tcg_const_i32(opreg)); |
5961 |
break;
|
5962 |
case 0x2b: /* fstp sti */ |
5963 |
case 0x0b: /* fstp1 sti, undocumented op */ |
5964 |
case 0x3a: /* fstp8 sti, undocumented op */ |
5965 |
case 0x3b: /* fstp9 sti, undocumented op */ |
5966 |
gen_helper_fmov_STN_ST0(cpu_env, tcg_const_i32(opreg)); |
5967 |
gen_helper_fpop(cpu_env); |
5968 |
break;
|
5969 |
case 0x2c: /* fucom st(i) */ |
5970 |
gen_helper_fmov_FT0_STN(cpu_env, tcg_const_i32(opreg)); |
5971 |
gen_helper_fucom_ST0_FT0(cpu_env); |
5972 |
break;
|
5973 |
case 0x2d: /* fucomp st(i) */ |
5974 |
gen_helper_fmov_FT0_STN(cpu_env, tcg_const_i32(opreg)); |
5975 |
gen_helper_fucom_ST0_FT0(cpu_env); |
5976 |
gen_helper_fpop(cpu_env); |
5977 |
break;
|
5978 |
case 0x33: /* de/3 */ |
5979 |
switch(rm) {
|
5980 |
case 1: /* fcompp */ |
5981 |
gen_helper_fmov_FT0_STN(cpu_env, tcg_const_i32(1));
|
5982 |
gen_helper_fcom_ST0_FT0(cpu_env); |
5983 |
gen_helper_fpop(cpu_env); |
5984 |
gen_helper_fpop(cpu_env); |
5985 |
break;
|
5986 |
default:
|
5987 |
goto illegal_op;
|
5988 |
} |
5989 |
break;
|
5990 |
case 0x38: /* ffreep sti, undocumented op */ |
5991 |
gen_helper_ffree_STN(cpu_env, tcg_const_i32(opreg)); |
5992 |
gen_helper_fpop(cpu_env); |
5993 |
break;
|
5994 |
case 0x3c: /* df/4 */ |
5995 |
switch(rm) {
|
5996 |
case 0: |
5997 |
gen_helper_fnstsw(cpu_tmp2_i32, cpu_env); |
5998 |
tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5999 |
gen_op_mov_reg_T0(OT_WORD, R_EAX); |
6000 |
break;
|
6001 |
default:
|
6002 |
goto illegal_op;
|
6003 |
} |
6004 |
break;
|
6005 |
case 0x3d: /* fucomip */ |
6006 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6007 |
gen_op_set_cc_op(s->cc_op); |
6008 |
gen_helper_fmov_FT0_STN(cpu_env, tcg_const_i32(opreg)); |
6009 |
gen_helper_fucomi_ST0_FT0(cpu_env); |
6010 |
gen_helper_fpop(cpu_env); |
6011 |
s->cc_op = CC_OP_EFLAGS; |
6012 |
break;
|
6013 |
case 0x3e: /* fcomip */ |
6014 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6015 |
gen_op_set_cc_op(s->cc_op); |
6016 |
gen_helper_fmov_FT0_STN(cpu_env, tcg_const_i32(opreg)); |
6017 |
gen_helper_fcomi_ST0_FT0(cpu_env); |
6018 |
gen_helper_fpop(cpu_env); |
6019 |
s->cc_op = CC_OP_EFLAGS; |
6020 |
break;
|
6021 |
case 0x10 ... 0x13: /* fcmovxx */ |
6022 |
case 0x18 ... 0x1b: |
6023 |
{ |
6024 |
int op1, l1;
|
6025 |
static const uint8_t fcmov_cc[8] = { |
6026 |
(JCC_B << 1),
|
6027 |
(JCC_Z << 1),
|
6028 |
(JCC_BE << 1),
|
6029 |
(JCC_P << 1),
|
6030 |
}; |
6031 |
op1 = fcmov_cc[op & 3] | (((op >> 3) & 1) ^ 1); |
6032 |
l1 = gen_new_label(); |
6033 |
gen_jcc1(s, op1, l1); |
6034 |
gen_helper_fmov_ST0_STN(cpu_env, tcg_const_i32(opreg)); |
6035 |
gen_set_label(l1); |
6036 |
} |
6037 |
break;
|
6038 |
default:
|
6039 |
goto illegal_op;
|
6040 |
} |
6041 |
} |
6042 |
break;
|
6043 |
/************************/
|
6044 |
/* string ops */
|
6045 |
|
6046 |
case 0xa4: /* movsS */ |
6047 |
case 0xa5: |
6048 |
if ((b & 1) == 0) |
6049 |
ot = OT_BYTE; |
6050 |
else
|
6051 |
ot = dflag + OT_WORD; |
6052 |
|
6053 |
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
6054 |
gen_repz_movs(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
6055 |
} else {
|
6056 |
gen_movs(s, ot); |
6057 |
} |
6058 |
break;
|
6059 |
|
6060 |
case 0xaa: /* stosS */ |
6061 |
case 0xab: |
6062 |
if ((b & 1) == 0) |
6063 |
ot = OT_BYTE; |
6064 |
else
|
6065 |
ot = dflag + OT_WORD; |
6066 |
|
6067 |
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
6068 |
gen_repz_stos(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
6069 |
} else {
|
6070 |
gen_stos(s, ot); |
6071 |
} |
6072 |
break;
|
6073 |
case 0xac: /* lodsS */ |
6074 |
case 0xad: |
6075 |
if ((b & 1) == 0) |
6076 |
ot = OT_BYTE; |
6077 |
else
|
6078 |
ot = dflag + OT_WORD; |
6079 |
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
6080 |
gen_repz_lods(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
6081 |
} else {
|
6082 |
gen_lods(s, ot); |
6083 |
} |
6084 |
break;
|
6085 |
case 0xae: /* scasS */ |
6086 |
case 0xaf: |
6087 |
if ((b & 1) == 0) |
6088 |
ot = OT_BYTE; |
6089 |
else
|
6090 |
ot = dflag + OT_WORD; |
6091 |
if (prefixes & PREFIX_REPNZ) {
|
6092 |
gen_repz_scas(s, ot, pc_start - s->cs_base, s->pc - s->cs_base, 1);
|
6093 |
} else if (prefixes & PREFIX_REPZ) { |
6094 |
gen_repz_scas(s, ot, pc_start - s->cs_base, s->pc - s->cs_base, 0);
|
6095 |
} else {
|
6096 |
gen_scas(s, ot); |
6097 |
} |
6098 |
break;
|
6099 |
|
6100 |
case 0xa6: /* cmpsS */ |
6101 |
case 0xa7: |
6102 |
if ((b & 1) == 0) |
6103 |
ot = OT_BYTE; |
6104 |
else
|
6105 |
ot = dflag + OT_WORD; |
6106 |
if (prefixes & PREFIX_REPNZ) {
|
6107 |
gen_repz_cmps(s, ot, pc_start - s->cs_base, s->pc - s->cs_base, 1);
|
6108 |
} else if (prefixes & PREFIX_REPZ) { |
6109 |
gen_repz_cmps(s, ot, pc_start - s->cs_base, s->pc - s->cs_base, 0);
|
6110 |
} else {
|
6111 |
gen_cmps(s, ot); |
6112 |
} |
6113 |
break;
|
6114 |
case 0x6c: /* insS */ |
6115 |
case 0x6d: |
6116 |
if ((b & 1) == 0) |
6117 |
ot = OT_BYTE; |
6118 |
else
|
6119 |
ot = dflag ? OT_LONG : OT_WORD; |
6120 |
gen_op_mov_TN_reg(OT_WORD, 0, R_EDX);
|
6121 |
gen_op_andl_T0_ffff(); |
6122 |
gen_check_io(s, ot, pc_start - s->cs_base, |
6123 |
SVM_IOIO_TYPE_MASK | svm_is_rep(prefixes) | 4);
|
6124 |
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
6125 |
gen_repz_ins(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
6126 |
} else {
|
6127 |
gen_ins(s, ot); |
6128 |
if (use_icount) {
|
6129 |
gen_jmp(s, s->pc - s->cs_base); |
6130 |
} |
6131 |
} |
6132 |
break;
|
6133 |
case 0x6e: /* outsS */ |
6134 |
case 0x6f: |
6135 |
if ((b & 1) == 0) |
6136 |
ot = OT_BYTE; |
6137 |
else
|
6138 |
ot = dflag ? OT_LONG : OT_WORD; |
6139 |
gen_op_mov_TN_reg(OT_WORD, 0, R_EDX);
|
6140 |
gen_op_andl_T0_ffff(); |
6141 |
gen_check_io(s, ot, pc_start - s->cs_base, |
6142 |
svm_is_rep(prefixes) | 4);
|
6143 |
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
6144 |
gen_repz_outs(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
6145 |
} else {
|
6146 |
gen_outs(s, ot); |
6147 |
if (use_icount) {
|
6148 |
gen_jmp(s, s->pc - s->cs_base); |
6149 |
} |
6150 |
} |
6151 |
break;
|
6152 |
|
6153 |
/************************/
|
6154 |
/* port I/O */
|
6155 |
|
6156 |
case 0xe4: |
6157 |
case 0xe5: |
6158 |
if ((b & 1) == 0) |
6159 |
ot = OT_BYTE; |
6160 |
else
|
6161 |
ot = dflag ? OT_LONG : OT_WORD; |
6162 |
val = cpu_ldub_code(env, s->pc++); |
6163 |
gen_op_movl_T0_im(val); |
6164 |
gen_check_io(s, ot, pc_start - s->cs_base, |
6165 |
SVM_IOIO_TYPE_MASK | svm_is_rep(prefixes)); |
6166 |
if (use_icount)
|
6167 |
gen_io_start(); |
6168 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
6169 |
gen_helper_in_func(ot, cpu_T[1], cpu_tmp2_i32);
|
6170 |
gen_op_mov_reg_T1(ot, R_EAX); |
6171 |
if (use_icount) {
|
6172 |
gen_io_end(); |
6173 |
gen_jmp(s, s->pc - s->cs_base); |
6174 |
} |
6175 |
break;
|
6176 |
case 0xe6: |
6177 |
case 0xe7: |
6178 |
if ((b & 1) == 0) |
6179 |
ot = OT_BYTE; |
6180 |
else
|
6181 |
ot = dflag ? OT_LONG : OT_WORD; |
6182 |
val = cpu_ldub_code(env, s->pc++); |
6183 |
gen_op_movl_T0_im(val); |
6184 |
gen_check_io(s, ot, pc_start - s->cs_base, |
6185 |
svm_is_rep(prefixes)); |
6186 |
gen_op_mov_TN_reg(ot, 1, R_EAX);
|
6187 |
|
6188 |
if (use_icount)
|
6189 |
gen_io_start(); |
6190 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
6191 |
tcg_gen_trunc_tl_i32(cpu_tmp3_i32, cpu_T[1]);
|
6192 |
gen_helper_out_func(ot, cpu_tmp2_i32, cpu_tmp3_i32); |
6193 |
if (use_icount) {
|
6194 |
gen_io_end(); |
6195 |
gen_jmp(s, s->pc - s->cs_base); |
6196 |
} |
6197 |
break;
|
6198 |
case 0xec: |
6199 |
case 0xed: |
6200 |
if ((b & 1) == 0) |
6201 |
ot = OT_BYTE; |
6202 |
else
|
6203 |
ot = dflag ? OT_LONG : OT_WORD; |
6204 |
gen_op_mov_TN_reg(OT_WORD, 0, R_EDX);
|
6205 |
gen_op_andl_T0_ffff(); |
6206 |
gen_check_io(s, ot, pc_start - s->cs_base, |
6207 |
SVM_IOIO_TYPE_MASK | svm_is_rep(prefixes)); |
6208 |
if (use_icount)
|
6209 |
gen_io_start(); |
6210 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
6211 |
gen_helper_in_func(ot, cpu_T[1], cpu_tmp2_i32);
|
6212 |
gen_op_mov_reg_T1(ot, R_EAX); |
6213 |
if (use_icount) {
|
6214 |
gen_io_end(); |
6215 |
gen_jmp(s, s->pc - s->cs_base); |
6216 |
} |
6217 |
break;
|
6218 |
case 0xee: |
6219 |
case 0xef: |
6220 |
if ((b & 1) == 0) |
6221 |
ot = OT_BYTE; |
6222 |
else
|
6223 |
ot = dflag ? OT_LONG : OT_WORD; |
6224 |
gen_op_mov_TN_reg(OT_WORD, 0, R_EDX);
|
6225 |
gen_op_andl_T0_ffff(); |
6226 |
gen_check_io(s, ot, pc_start - s->cs_base, |
6227 |
svm_is_rep(prefixes)); |
6228 |
gen_op_mov_TN_reg(ot, 1, R_EAX);
|
6229 |
|
6230 |
if (use_icount)
|
6231 |
gen_io_start(); |
6232 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
6233 |
tcg_gen_trunc_tl_i32(cpu_tmp3_i32, cpu_T[1]);
|
6234 |
gen_helper_out_func(ot, cpu_tmp2_i32, cpu_tmp3_i32); |
6235 |
if (use_icount) {
|
6236 |
gen_io_end(); |
6237 |
gen_jmp(s, s->pc - s->cs_base); |
6238 |
} |
6239 |
break;
|
6240 |
|
6241 |
/************************/
|
6242 |
/* control */
|
6243 |
case 0xc2: /* ret im */ |
6244 |
val = cpu_ldsw_code(env, s->pc); |
6245 |
s->pc += 2;
|
6246 |
gen_pop_T0(s); |
6247 |
if (CODE64(s) && s->dflag)
|
6248 |
s->dflag = 2;
|
6249 |
gen_stack_update(s, val + (2 << s->dflag));
|
6250 |
if (s->dflag == 0) |
6251 |
gen_op_andl_T0_ffff(); |
6252 |
gen_op_jmp_T0(); |
6253 |
gen_eob(s); |
6254 |
break;
|
6255 |
case 0xc3: /* ret */ |
6256 |
gen_pop_T0(s); |
6257 |
gen_pop_update(s); |
6258 |
if (s->dflag == 0) |
6259 |
gen_op_andl_T0_ffff(); |
6260 |
gen_op_jmp_T0(); |
6261 |
gen_eob(s); |
6262 |
break;
|
6263 |
case 0xca: /* lret im */ |
6264 |
val = cpu_ldsw_code(env, s->pc); |
6265 |
s->pc += 2;
|
6266 |
do_lret:
|
6267 |
if (s->pe && !s->vm86) {
|
6268 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6269 |
gen_op_set_cc_op(s->cc_op); |
6270 |
gen_jmp_im(pc_start - s->cs_base); |
6271 |
gen_helper_lret_protected(cpu_env, tcg_const_i32(s->dflag), |
6272 |
tcg_const_i32(val)); |
6273 |
} else {
|
6274 |
gen_stack_A0(s); |
6275 |
/* pop offset */
|
6276 |
gen_op_ld_T0_A0(1 + s->dflag + s->mem_index);
|
6277 |
if (s->dflag == 0) |
6278 |
gen_op_andl_T0_ffff(); |
6279 |
/* NOTE: keeping EIP updated is not a problem in case of
|
6280 |
exception */
|
6281 |
gen_op_jmp_T0(); |
6282 |
/* pop selector */
|
6283 |
gen_op_addl_A0_im(2 << s->dflag);
|
6284 |
gen_op_ld_T0_A0(1 + s->dflag + s->mem_index);
|
6285 |
gen_op_movl_seg_T0_vm(R_CS); |
6286 |
/* add stack offset */
|
6287 |
gen_stack_update(s, val + (4 << s->dflag));
|
6288 |
} |
6289 |
gen_eob(s); |
6290 |
break;
|
6291 |
case 0xcb: /* lret */ |
6292 |
val = 0;
|
6293 |
goto do_lret;
|
6294 |
case 0xcf: /* iret */ |
6295 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_IRET); |
6296 |
if (!s->pe) {
|
6297 |
/* real mode */
|
6298 |
gen_helper_iret_real(cpu_env, tcg_const_i32(s->dflag)); |
6299 |
s->cc_op = CC_OP_EFLAGS; |
6300 |
} else if (s->vm86) { |
6301 |
if (s->iopl != 3) { |
6302 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6303 |
} else {
|
6304 |
gen_helper_iret_real(cpu_env, tcg_const_i32(s->dflag)); |
6305 |
s->cc_op = CC_OP_EFLAGS; |
6306 |
} |
6307 |
} else {
|
6308 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6309 |
gen_op_set_cc_op(s->cc_op); |
6310 |
gen_jmp_im(pc_start - s->cs_base); |
6311 |
gen_helper_iret_protected(cpu_env, tcg_const_i32(s->dflag), |
6312 |
tcg_const_i32(s->pc - s->cs_base)); |
6313 |
s->cc_op = CC_OP_EFLAGS; |
6314 |
} |
6315 |
gen_eob(s); |
6316 |
break;
|
6317 |
case 0xe8: /* call im */ |
6318 |
{ |
6319 |
if (dflag)
|
6320 |
tval = (int32_t)insn_get(env, s, OT_LONG); |
6321 |
else
|
6322 |
tval = (int16_t)insn_get(env, s, OT_WORD); |
6323 |
next_eip = s->pc - s->cs_base; |
6324 |
tval += next_eip; |
6325 |
if (s->dflag == 0) |
6326 |
tval &= 0xffff;
|
6327 |
else if(!CODE64(s)) |
6328 |
tval &= 0xffffffff;
|
6329 |
gen_movtl_T0_im(next_eip); |
6330 |
gen_push_T0(s); |
6331 |
gen_jmp(s, tval); |
6332 |
} |
6333 |
break;
|
6334 |
case 0x9a: /* lcall im */ |
6335 |
{ |
6336 |
unsigned int selector, offset; |
6337 |
|
6338 |
if (CODE64(s))
|
6339 |
goto illegal_op;
|
6340 |
ot = dflag ? OT_LONG : OT_WORD; |
6341 |
offset = insn_get(env, s, ot); |
6342 |
selector = insn_get(env, s, OT_WORD); |
6343 |
|
6344 |
gen_op_movl_T0_im(selector); |
6345 |
gen_op_movl_T1_imu(offset); |
6346 |
} |
6347 |
goto do_lcall;
|
6348 |
case 0xe9: /* jmp im */ |
6349 |
if (dflag)
|
6350 |
tval = (int32_t)insn_get(env, s, OT_LONG); |
6351 |
else
|
6352 |
tval = (int16_t)insn_get(env, s, OT_WORD); |
6353 |
tval += s->pc - s->cs_base; |
6354 |
if (s->dflag == 0) |
6355 |
tval &= 0xffff;
|
6356 |
else if(!CODE64(s)) |
6357 |
tval &= 0xffffffff;
|
6358 |
gen_jmp(s, tval); |
6359 |
break;
|
6360 |
case 0xea: /* ljmp im */ |
6361 |
{ |
6362 |
unsigned int selector, offset; |
6363 |
|
6364 |
if (CODE64(s))
|
6365 |
goto illegal_op;
|
6366 |
ot = dflag ? OT_LONG : OT_WORD; |
6367 |
offset = insn_get(env, s, ot); |
6368 |
selector = insn_get(env, s, OT_WORD); |
6369 |
|
6370 |
gen_op_movl_T0_im(selector); |
6371 |
gen_op_movl_T1_imu(offset); |
6372 |
} |
6373 |
goto do_ljmp;
|
6374 |
case 0xeb: /* jmp Jb */ |
6375 |
tval = (int8_t)insn_get(env, s, OT_BYTE); |
6376 |
tval += s->pc - s->cs_base; |
6377 |
if (s->dflag == 0) |
6378 |
tval &= 0xffff;
|
6379 |
gen_jmp(s, tval); |
6380 |
break;
|
6381 |
case 0x70 ... 0x7f: /* jcc Jb */ |
6382 |
tval = (int8_t)insn_get(env, s, OT_BYTE); |
6383 |
goto do_jcc;
|
6384 |
case 0x180 ... 0x18f: /* jcc Jv */ |
6385 |
if (dflag) {
|
6386 |
tval = (int32_t)insn_get(env, s, OT_LONG); |
6387 |
} else {
|
6388 |
tval = (int16_t)insn_get(env, s, OT_WORD); |
6389 |
} |
6390 |
do_jcc:
|
6391 |
next_eip = s->pc - s->cs_base; |
6392 |
tval += next_eip; |
6393 |
if (s->dflag == 0) |
6394 |
tval &= 0xffff;
|
6395 |
gen_jcc(s, b, tval, next_eip); |
6396 |
break;
|
6397 |
|
6398 |
case 0x190 ... 0x19f: /* setcc Gv */ |
6399 |
modrm = cpu_ldub_code(env, s->pc++); |
6400 |
gen_setcc(s, b); |
6401 |
gen_ldst_modrm(env, s, modrm, OT_BYTE, OR_TMP0, 1);
|
6402 |
break;
|
6403 |
case 0x140 ... 0x14f: /* cmov Gv, Ev */ |
6404 |
{ |
6405 |
int l1;
|
6406 |
TCGv t0; |
6407 |
|
6408 |
ot = dflag + OT_WORD; |
6409 |
modrm = cpu_ldub_code(env, s->pc++); |
6410 |
reg = ((modrm >> 3) & 7) | rex_r; |
6411 |
mod = (modrm >> 6) & 3; |
6412 |
t0 = tcg_temp_local_new(); |
6413 |
if (mod != 3) { |
6414 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
6415 |
gen_op_ld_v(ot + s->mem_index, t0, cpu_A0); |
6416 |
} else {
|
6417 |
rm = (modrm & 7) | REX_B(s);
|
6418 |
gen_op_mov_v_reg(ot, t0, rm); |
6419 |
} |
6420 |
#ifdef TARGET_X86_64
|
6421 |
if (ot == OT_LONG) {
|
6422 |
/* XXX: specific Intel behaviour ? */
|
6423 |
l1 = gen_new_label(); |
6424 |
gen_jcc1(s, b ^ 1, l1);
|
6425 |
tcg_gen_mov_tl(cpu_regs[reg], t0); |
6426 |
gen_set_label(l1); |
6427 |
tcg_gen_ext32u_tl(cpu_regs[reg], cpu_regs[reg]); |
6428 |
} else
|
6429 |
#endif
|
6430 |
{ |
6431 |
l1 = gen_new_label(); |
6432 |
gen_jcc1(s, b ^ 1, l1);
|
6433 |
gen_op_mov_reg_v(ot, reg, t0); |
6434 |
gen_set_label(l1); |
6435 |
} |
6436 |
tcg_temp_free(t0); |
6437 |
} |
6438 |
break;
|
6439 |
|
6440 |
/************************/
|
6441 |
/* flags */
|
6442 |
case 0x9c: /* pushf */ |
6443 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_PUSHF); |
6444 |
if (s->vm86 && s->iopl != 3) { |
6445 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6446 |
} else {
|
6447 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6448 |
gen_op_set_cc_op(s->cc_op); |
6449 |
gen_helper_read_eflags(cpu_T[0], cpu_env);
|
6450 |
gen_push_T0(s); |
6451 |
} |
6452 |
break;
|
6453 |
case 0x9d: /* popf */ |
6454 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_POPF); |
6455 |
if (s->vm86 && s->iopl != 3) { |
6456 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6457 |
} else {
|
6458 |
gen_pop_T0(s); |
6459 |
if (s->cpl == 0) { |
6460 |
if (s->dflag) {
|
6461 |
gen_helper_write_eflags(cpu_env, cpu_T[0],
|
6462 |
tcg_const_i32((TF_MASK | AC_MASK | |
6463 |
ID_MASK | NT_MASK | |
6464 |
IF_MASK | |
6465 |
IOPL_MASK))); |
6466 |
} else {
|
6467 |
gen_helper_write_eflags(cpu_env, cpu_T[0],
|
6468 |
tcg_const_i32((TF_MASK | AC_MASK | |
6469 |
ID_MASK | NT_MASK | |
6470 |
IF_MASK | IOPL_MASK) |
6471 |
& 0xffff));
|
6472 |
} |
6473 |
} else {
|
6474 |
if (s->cpl <= s->iopl) {
|
6475 |
if (s->dflag) {
|
6476 |
gen_helper_write_eflags(cpu_env, cpu_T[0],
|
6477 |
tcg_const_i32((TF_MASK | |
6478 |
AC_MASK | |
6479 |
ID_MASK | |
6480 |
NT_MASK | |
6481 |
IF_MASK))); |
6482 |
} else {
|
6483 |
gen_helper_write_eflags(cpu_env, cpu_T[0],
|
6484 |
tcg_const_i32((TF_MASK | |
6485 |
AC_MASK | |
6486 |
ID_MASK | |
6487 |
NT_MASK | |
6488 |
IF_MASK) |
6489 |
& 0xffff));
|
6490 |
} |
6491 |
} else {
|
6492 |
if (s->dflag) {
|
6493 |
gen_helper_write_eflags(cpu_env, cpu_T[0],
|
6494 |
tcg_const_i32((TF_MASK | AC_MASK | |
6495 |
ID_MASK | NT_MASK))); |
6496 |
} else {
|
6497 |
gen_helper_write_eflags(cpu_env, cpu_T[0],
|
6498 |
tcg_const_i32((TF_MASK | AC_MASK | |
6499 |
ID_MASK | NT_MASK) |
6500 |
& 0xffff));
|
6501 |
} |
6502 |
} |
6503 |
} |
6504 |
gen_pop_update(s); |
6505 |
s->cc_op = CC_OP_EFLAGS; |
6506 |
/* abort translation because TF/AC flag may change */
|
6507 |
gen_jmp_im(s->pc - s->cs_base); |
6508 |
gen_eob(s); |
6509 |
} |
6510 |
break;
|
6511 |
case 0x9e: /* sahf */ |
6512 |
if (CODE64(s) && !(s->cpuid_ext3_features & CPUID_EXT3_LAHF_LM))
|
6513 |
goto illegal_op;
|
6514 |
gen_op_mov_TN_reg(OT_BYTE, 0, R_AH);
|
6515 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6516 |
gen_op_set_cc_op(s->cc_op); |
6517 |
gen_compute_eflags(cpu_cc_src); |
6518 |
tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, CC_O); |
6519 |
tcg_gen_andi_tl(cpu_T[0], cpu_T[0], CC_S | CC_Z | CC_A | CC_P | CC_C); |
6520 |
tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_T[0]);
|
6521 |
s->cc_op = CC_OP_EFLAGS; |
6522 |
break;
|
6523 |
case 0x9f: /* lahf */ |
6524 |
if (CODE64(s) && !(s->cpuid_ext3_features & CPUID_EXT3_LAHF_LM))
|
6525 |
goto illegal_op;
|
6526 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6527 |
gen_op_set_cc_op(s->cc_op); |
6528 |
gen_compute_eflags(cpu_T[0]);
|
6529 |
/* Note: gen_compute_eflags() only gives the condition codes */
|
6530 |
tcg_gen_ori_tl(cpu_T[0], cpu_T[0], 0x02); |
6531 |
gen_op_mov_reg_T0(OT_BYTE, R_AH); |
6532 |
break;
|
6533 |
case 0xf5: /* cmc */ |
6534 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6535 |
gen_op_set_cc_op(s->cc_op); |
6536 |
gen_compute_eflags(cpu_cc_src); |
6537 |
tcg_gen_xori_tl(cpu_cc_src, cpu_cc_src, CC_C); |
6538 |
s->cc_op = CC_OP_EFLAGS; |
6539 |
break;
|
6540 |
case 0xf8: /* clc */ |
6541 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6542 |
gen_op_set_cc_op(s->cc_op); |
6543 |
gen_compute_eflags(cpu_cc_src); |
6544 |
tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, ~CC_C); |
6545 |
s->cc_op = CC_OP_EFLAGS; |
6546 |
break;
|
6547 |
case 0xf9: /* stc */ |
6548 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6549 |
gen_op_set_cc_op(s->cc_op); |
6550 |
gen_compute_eflags(cpu_cc_src); |
6551 |
tcg_gen_ori_tl(cpu_cc_src, cpu_cc_src, CC_C); |
6552 |
s->cc_op = CC_OP_EFLAGS; |
6553 |
break;
|
6554 |
case 0xfc: /* cld */ |
6555 |
tcg_gen_movi_i32(cpu_tmp2_i32, 1);
|
6556 |
tcg_gen_st_i32(cpu_tmp2_i32, cpu_env, offsetof(CPUX86State, df)); |
6557 |
break;
|
6558 |
case 0xfd: /* std */ |
6559 |
tcg_gen_movi_i32(cpu_tmp2_i32, -1);
|
6560 |
tcg_gen_st_i32(cpu_tmp2_i32, cpu_env, offsetof(CPUX86State, df)); |
6561 |
break;
|
6562 |
|
6563 |
/************************/
|
6564 |
/* bit operations */
|
6565 |
case 0x1ba: /* bt/bts/btr/btc Gv, im */ |
6566 |
ot = dflag + OT_WORD; |
6567 |
modrm = cpu_ldub_code(env, s->pc++); |
6568 |
op = (modrm >> 3) & 7; |
6569 |
mod = (modrm >> 6) & 3; |
6570 |
rm = (modrm & 7) | REX_B(s);
|
6571 |
if (mod != 3) { |
6572 |
s->rip_offset = 1;
|
6573 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
6574 |
gen_op_ld_T0_A0(ot + s->mem_index); |
6575 |
} else {
|
6576 |
gen_op_mov_TN_reg(ot, 0, rm);
|
6577 |
} |
6578 |
/* load shift */
|
6579 |
val = cpu_ldub_code(env, s->pc++); |
6580 |
gen_op_movl_T1_im(val); |
6581 |
if (op < 4) |
6582 |
goto illegal_op;
|
6583 |
op -= 4;
|
6584 |
goto bt_op;
|
6585 |
case 0x1a3: /* bt Gv, Ev */ |
6586 |
op = 0;
|
6587 |
goto do_btx;
|
6588 |
case 0x1ab: /* bts */ |
6589 |
op = 1;
|
6590 |
goto do_btx;
|
6591 |
case 0x1b3: /* btr */ |
6592 |
op = 2;
|
6593 |
goto do_btx;
|
6594 |
case 0x1bb: /* btc */ |
6595 |
op = 3;
|
6596 |
do_btx:
|
6597 |
ot = dflag + OT_WORD; |
6598 |
modrm = cpu_ldub_code(env, s->pc++); |
6599 |
reg = ((modrm >> 3) & 7) | rex_r; |
6600 |
mod = (modrm >> 6) & 3; |
6601 |
rm = (modrm & 7) | REX_B(s);
|
6602 |
gen_op_mov_TN_reg(OT_LONG, 1, reg);
|
6603 |
if (mod != 3) { |
6604 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
6605 |
/* specific case: we need to add a displacement */
|
6606 |
gen_exts(ot, cpu_T[1]);
|
6607 |
tcg_gen_sari_tl(cpu_tmp0, cpu_T[1], 3 + ot); |
6608 |
tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, ot); |
6609 |
tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); |
6610 |
gen_op_ld_T0_A0(ot + s->mem_index); |
6611 |
} else {
|
6612 |
gen_op_mov_TN_reg(ot, 0, rm);
|
6613 |
} |
6614 |
bt_op:
|
6615 |
tcg_gen_andi_tl(cpu_T[1], cpu_T[1], (1 << (3 + ot)) - 1); |
6616 |
switch(op) {
|
6617 |
case 0: |
6618 |
tcg_gen_shr_tl(cpu_cc_src, cpu_T[0], cpu_T[1]); |
6619 |
tcg_gen_movi_tl(cpu_cc_dst, 0);
|
6620 |
break;
|
6621 |
case 1: |
6622 |
tcg_gen_shr_tl(cpu_tmp4, cpu_T[0], cpu_T[1]); |
6623 |
tcg_gen_movi_tl(cpu_tmp0, 1);
|
6624 |
tcg_gen_shl_tl(cpu_tmp0, cpu_tmp0, cpu_T[1]);
|
6625 |
tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_tmp0); |
6626 |
break;
|
6627 |
case 2: |
6628 |
tcg_gen_shr_tl(cpu_tmp4, cpu_T[0], cpu_T[1]); |
6629 |
tcg_gen_movi_tl(cpu_tmp0, 1);
|
6630 |
tcg_gen_shl_tl(cpu_tmp0, cpu_tmp0, cpu_T[1]);
|
6631 |
tcg_gen_not_tl(cpu_tmp0, cpu_tmp0); |
6632 |
tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_tmp0); |
6633 |
break;
|
6634 |
default:
|
6635 |
case 3: |
6636 |
tcg_gen_shr_tl(cpu_tmp4, cpu_T[0], cpu_T[1]); |
6637 |
tcg_gen_movi_tl(cpu_tmp0, 1);
|
6638 |
tcg_gen_shl_tl(cpu_tmp0, cpu_tmp0, cpu_T[1]);
|
6639 |
tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_tmp0); |
6640 |
break;
|
6641 |
} |
6642 |
s->cc_op = CC_OP_SARB + ot; |
6643 |
if (op != 0) { |
6644 |
if (mod != 3) |
6645 |
gen_op_st_T0_A0(ot + s->mem_index); |
6646 |
else
|
6647 |
gen_op_mov_reg_T0(ot, rm); |
6648 |
tcg_gen_mov_tl(cpu_cc_src, cpu_tmp4); |
6649 |
tcg_gen_movi_tl(cpu_cc_dst, 0);
|
6650 |
} |
6651 |
break;
|
6652 |
case 0x1bc: /* bsf */ |
6653 |
case 0x1bd: /* bsr */ |
6654 |
{ |
6655 |
int label1;
|
6656 |
TCGv t0; |
6657 |
|
6658 |
ot = dflag + OT_WORD; |
6659 |
modrm = cpu_ldub_code(env, s->pc++); |
6660 |
reg = ((modrm >> 3) & 7) | rex_r; |
6661 |
gen_ldst_modrm(env, s,modrm, ot, OR_TMP0, 0);
|
6662 |
gen_extu(ot, cpu_T[0]);
|
6663 |
t0 = tcg_temp_local_new(); |
6664 |
tcg_gen_mov_tl(t0, cpu_T[0]);
|
6665 |
if ((b & 1) && (prefixes & PREFIX_REPZ) && |
6666 |
(s->cpuid_ext3_features & CPUID_EXT3_ABM)) { |
6667 |
switch(ot) {
|
6668 |
case OT_WORD: gen_helper_lzcnt(cpu_T[0], t0, |
6669 |
tcg_const_i32(16)); break; |
6670 |
case OT_LONG: gen_helper_lzcnt(cpu_T[0], t0, |
6671 |
tcg_const_i32(32)); break; |
6672 |
case OT_QUAD: gen_helper_lzcnt(cpu_T[0], t0, |
6673 |
tcg_const_i32(64)); break; |
6674 |
} |
6675 |
gen_op_mov_reg_T0(ot, reg); |
6676 |
} else {
|
6677 |
label1 = gen_new_label(); |
6678 |
tcg_gen_movi_tl(cpu_cc_dst, 0);
|
6679 |
tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, label1);
|
6680 |
if (b & 1) { |
6681 |
gen_helper_bsr(cpu_T[0], t0);
|
6682 |
} else {
|
6683 |
gen_helper_bsf(cpu_T[0], t0);
|
6684 |
} |
6685 |
gen_op_mov_reg_T0(ot, reg); |
6686 |
tcg_gen_movi_tl(cpu_cc_dst, 1);
|
6687 |
gen_set_label(label1); |
6688 |
tcg_gen_discard_tl(cpu_cc_src); |
6689 |
s->cc_op = CC_OP_LOGICB + ot; |
6690 |
} |
6691 |
tcg_temp_free(t0); |
6692 |
} |
6693 |
break;
|
6694 |
/************************/
|
6695 |
/* bcd */
|
6696 |
case 0x27: /* daa */ |
6697 |
if (CODE64(s))
|
6698 |
goto illegal_op;
|
6699 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6700 |
gen_op_set_cc_op(s->cc_op); |
6701 |
gen_helper_daa(cpu_env); |
6702 |
s->cc_op = CC_OP_EFLAGS; |
6703 |
break;
|
6704 |
case 0x2f: /* das */ |
6705 |
if (CODE64(s))
|
6706 |
goto illegal_op;
|
6707 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6708 |
gen_op_set_cc_op(s->cc_op); |
6709 |
gen_helper_das(cpu_env); |
6710 |
s->cc_op = CC_OP_EFLAGS; |
6711 |
break;
|
6712 |
case 0x37: /* aaa */ |
6713 |
if (CODE64(s))
|
6714 |
goto illegal_op;
|
6715 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6716 |
gen_op_set_cc_op(s->cc_op); |
6717 |
gen_helper_aaa(cpu_env); |
6718 |
s->cc_op = CC_OP_EFLAGS; |
6719 |
break;
|
6720 |
case 0x3f: /* aas */ |
6721 |
if (CODE64(s))
|
6722 |
goto illegal_op;
|
6723 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6724 |
gen_op_set_cc_op(s->cc_op); |
6725 |
gen_helper_aas(cpu_env); |
6726 |
s->cc_op = CC_OP_EFLAGS; |
6727 |
break;
|
6728 |
case 0xd4: /* aam */ |
6729 |
if (CODE64(s))
|
6730 |
goto illegal_op;
|
6731 |
val = cpu_ldub_code(env, s->pc++); |
6732 |
if (val == 0) { |
6733 |
gen_exception(s, EXCP00_DIVZ, pc_start - s->cs_base); |
6734 |
} else {
|
6735 |
gen_helper_aam(cpu_env, tcg_const_i32(val)); |
6736 |
s->cc_op = CC_OP_LOGICB; |
6737 |
} |
6738 |
break;
|
6739 |
case 0xd5: /* aad */ |
6740 |
if (CODE64(s))
|
6741 |
goto illegal_op;
|
6742 |
val = cpu_ldub_code(env, s->pc++); |
6743 |
gen_helper_aad(cpu_env, tcg_const_i32(val)); |
6744 |
s->cc_op = CC_OP_LOGICB; |
6745 |
break;
|
6746 |
/************************/
|
6747 |
/* misc */
|
6748 |
case 0x90: /* nop */ |
6749 |
/* XXX: correct lock test for all insn */
|
6750 |
if (prefixes & PREFIX_LOCK) {
|
6751 |
goto illegal_op;
|
6752 |
} |
6753 |
/* If REX_B is set, then this is xchg eax, r8d, not a nop. */
|
6754 |
if (REX_B(s)) {
|
6755 |
goto do_xchg_reg_eax;
|
6756 |
} |
6757 |
if (prefixes & PREFIX_REPZ) {
|
6758 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_PAUSE); |
6759 |
} |
6760 |
break;
|
6761 |
case 0x9b: /* fwait */ |
6762 |
if ((s->flags & (HF_MP_MASK | HF_TS_MASK)) ==
|
6763 |
(HF_MP_MASK | HF_TS_MASK)) { |
6764 |
gen_exception(s, EXCP07_PREX, pc_start - s->cs_base); |
6765 |
} else {
|
6766 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6767 |
gen_op_set_cc_op(s->cc_op); |
6768 |
gen_jmp_im(pc_start - s->cs_base); |
6769 |
gen_helper_fwait(cpu_env); |
6770 |
} |
6771 |
break;
|
6772 |
case 0xcc: /* int3 */ |
6773 |
gen_interrupt(s, EXCP03_INT3, pc_start - s->cs_base, s->pc - s->cs_base); |
6774 |
break;
|
6775 |
case 0xcd: /* int N */ |
6776 |
val = cpu_ldub_code(env, s->pc++); |
6777 |
if (s->vm86 && s->iopl != 3) { |
6778 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6779 |
} else {
|
6780 |
gen_interrupt(s, val, pc_start - s->cs_base, s->pc - s->cs_base); |
6781 |
} |
6782 |
break;
|
6783 |
case 0xce: /* into */ |
6784 |
if (CODE64(s))
|
6785 |
goto illegal_op;
|
6786 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6787 |
gen_op_set_cc_op(s->cc_op); |
6788 |
gen_jmp_im(pc_start - s->cs_base); |
6789 |
gen_helper_into(cpu_env, tcg_const_i32(s->pc - pc_start)); |
6790 |
break;
|
6791 |
#ifdef WANT_ICEBP
|
6792 |
case 0xf1: /* icebp (undocumented, exits to external debugger) */ |
6793 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_ICEBP); |
6794 |
#if 1 |
6795 |
gen_debug(s, pc_start - s->cs_base); |
6796 |
#else
|
6797 |
/* start debug */
|
6798 |
tb_flush(env); |
6799 |
qemu_set_log(CPU_LOG_INT | CPU_LOG_TB_IN_ASM); |
6800 |
#endif
|
6801 |
break;
|
6802 |
#endif
|
6803 |
case 0xfa: /* cli */ |
6804 |
if (!s->vm86) {
|
6805 |
if (s->cpl <= s->iopl) {
|
6806 |
gen_helper_cli(cpu_env); |
6807 |
} else {
|
6808 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6809 |
} |
6810 |
} else {
|
6811 |
if (s->iopl == 3) { |
6812 |
gen_helper_cli(cpu_env); |
6813 |
} else {
|
6814 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6815 |
} |
6816 |
} |
6817 |
break;
|
6818 |
case 0xfb: /* sti */ |
6819 |
if (!s->vm86) {
|
6820 |
if (s->cpl <= s->iopl) {
|
6821 |
gen_sti:
|
6822 |
gen_helper_sti(cpu_env); |
6823 |
/* interruptions are enabled only the first insn after sti */
|
6824 |
/* If several instructions disable interrupts, only the
|
6825 |
_first_ does it */
|
6826 |
if (!(s->tb->flags & HF_INHIBIT_IRQ_MASK))
|
6827 |
gen_helper_set_inhibit_irq(cpu_env); |
6828 |
/* give a chance to handle pending irqs */
|
6829 |
gen_jmp_im(s->pc - s->cs_base); |
6830 |
gen_eob(s); |
6831 |
} else {
|
6832 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6833 |
} |
6834 |
} else {
|
6835 |
if (s->iopl == 3) { |
6836 |
goto gen_sti;
|
6837 |
} else {
|
6838 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6839 |
} |
6840 |
} |
6841 |
break;
|
6842 |
case 0x62: /* bound */ |
6843 |
if (CODE64(s))
|
6844 |
goto illegal_op;
|
6845 |
ot = dflag ? OT_LONG : OT_WORD; |
6846 |
modrm = cpu_ldub_code(env, s->pc++); |
6847 |
reg = (modrm >> 3) & 7; |
6848 |
mod = (modrm >> 6) & 3; |
6849 |
if (mod == 3) |
6850 |
goto illegal_op;
|
6851 |
gen_op_mov_TN_reg(ot, 0, reg);
|
6852 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
6853 |
gen_jmp_im(pc_start - s->cs_base); |
6854 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
6855 |
if (ot == OT_WORD) {
|
6856 |
gen_helper_boundw(cpu_env, cpu_A0, cpu_tmp2_i32); |
6857 |
} else {
|
6858 |
gen_helper_boundl(cpu_env, cpu_A0, cpu_tmp2_i32); |
6859 |
} |
6860 |
break;
|
6861 |
case 0x1c8 ... 0x1cf: /* bswap reg */ |
6862 |
reg = (b & 7) | REX_B(s);
|
6863 |
#ifdef TARGET_X86_64
|
6864 |
if (dflag == 2) { |
6865 |
gen_op_mov_TN_reg(OT_QUAD, 0, reg);
|
6866 |
tcg_gen_bswap64_i64(cpu_T[0], cpu_T[0]); |
6867 |
gen_op_mov_reg_T0(OT_QUAD, reg); |
6868 |
} else
|
6869 |
#endif
|
6870 |
{ |
6871 |
gen_op_mov_TN_reg(OT_LONG, 0, reg);
|
6872 |
tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]); |
6873 |
tcg_gen_bswap32_tl(cpu_T[0], cpu_T[0]); |
6874 |
gen_op_mov_reg_T0(OT_LONG, reg); |
6875 |
} |
6876 |
break;
|
6877 |
case 0xd6: /* salc */ |
6878 |
if (CODE64(s))
|
6879 |
goto illegal_op;
|
6880 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6881 |
gen_op_set_cc_op(s->cc_op); |
6882 |
gen_compute_eflags_c(cpu_T[0]);
|
6883 |
tcg_gen_neg_tl(cpu_T[0], cpu_T[0]); |
6884 |
gen_op_mov_reg_T0(OT_BYTE, R_EAX); |
6885 |
break;
|
6886 |
case 0xe0: /* loopnz */ |
6887 |
case 0xe1: /* loopz */ |
6888 |
case 0xe2: /* loop */ |
6889 |
case 0xe3: /* jecxz */ |
6890 |
{ |
6891 |
int l1, l2, l3;
|
6892 |
|
6893 |
tval = (int8_t)insn_get(env, s, OT_BYTE); |
6894 |
next_eip = s->pc - s->cs_base; |
6895 |
tval += next_eip; |
6896 |
if (s->dflag == 0) |
6897 |
tval &= 0xffff;
|
6898 |
|
6899 |
l1 = gen_new_label(); |
6900 |
l2 = gen_new_label(); |
6901 |
l3 = gen_new_label(); |
6902 |
b &= 3;
|
6903 |
switch(b) {
|
6904 |
case 0: /* loopnz */ |
6905 |
case 1: /* loopz */ |
6906 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6907 |
gen_op_set_cc_op(s->cc_op); |
6908 |
gen_op_add_reg_im(s->aflag, R_ECX, -1);
|
6909 |
gen_op_jz_ecx(s->aflag, l3); |
6910 |
gen_compute_eflags(cpu_tmp0); |
6911 |
tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, CC_Z); |
6912 |
if (b == 0) { |
6913 |
tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
|
6914 |
} else {
|
6915 |
tcg_gen_brcondi_tl(TCG_COND_NE, cpu_tmp0, 0, l1);
|
6916 |
} |
6917 |
break;
|
6918 |
case 2: /* loop */ |
6919 |
gen_op_add_reg_im(s->aflag, R_ECX, -1);
|
6920 |
gen_op_jnz_ecx(s->aflag, l1); |
6921 |
break;
|
6922 |
default:
|
6923 |
case 3: /* jcxz */ |
6924 |
gen_op_jz_ecx(s->aflag, l1); |
6925 |
break;
|
6926 |
} |
6927 |
|
6928 |
gen_set_label(l3); |
6929 |
gen_jmp_im(next_eip); |
6930 |
tcg_gen_br(l2); |
6931 |
|
6932 |
gen_set_label(l1); |
6933 |
gen_jmp_im(tval); |
6934 |
gen_set_label(l2); |
6935 |
gen_eob(s); |
6936 |
} |
6937 |
break;
|
6938 |
case 0x130: /* wrmsr */ |
6939 |
case 0x132: /* rdmsr */ |
6940 |
if (s->cpl != 0) { |
6941 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6942 |
} else {
|
6943 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6944 |
gen_op_set_cc_op(s->cc_op); |
6945 |
gen_jmp_im(pc_start - s->cs_base); |
6946 |
if (b & 2) { |
6947 |
gen_helper_rdmsr(cpu_env); |
6948 |
} else {
|
6949 |
gen_helper_wrmsr(cpu_env); |
6950 |
} |
6951 |
} |
6952 |
break;
|
6953 |
case 0x131: /* rdtsc */ |
6954 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6955 |
gen_op_set_cc_op(s->cc_op); |
6956 |
gen_jmp_im(pc_start - s->cs_base); |
6957 |
if (use_icount)
|
6958 |
gen_io_start(); |
6959 |
gen_helper_rdtsc(cpu_env); |
6960 |
if (use_icount) {
|
6961 |
gen_io_end(); |
6962 |
gen_jmp(s, s->pc - s->cs_base); |
6963 |
} |
6964 |
break;
|
6965 |
case 0x133: /* rdpmc */ |
6966 |
if (s->cc_op != CC_OP_DYNAMIC)
|
6967 |
gen_op_set_cc_op(s->cc_op); |
6968 |
gen_jmp_im(pc_start - s->cs_base); |
6969 |
gen_helper_rdpmc(cpu_env); |
6970 |
break;
|
6971 |
case 0x134: /* sysenter */ |
6972 |
/* For Intel SYSENTER is valid on 64-bit */
|
6973 |
if (CODE64(s) && env->cpuid_vendor1 != CPUID_VENDOR_INTEL_1)
|
6974 |
goto illegal_op;
|
6975 |
if (!s->pe) {
|
6976 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6977 |
} else {
|
6978 |
gen_update_cc_op(s); |
6979 |
gen_jmp_im(pc_start - s->cs_base); |
6980 |
gen_helper_sysenter(cpu_env); |
6981 |
gen_eob(s); |
6982 |
} |
6983 |
break;
|
6984 |
case 0x135: /* sysexit */ |
6985 |
/* For Intel SYSEXIT is valid on 64-bit */
|
6986 |
if (CODE64(s) && env->cpuid_vendor1 != CPUID_VENDOR_INTEL_1)
|
6987 |
goto illegal_op;
|
6988 |
if (!s->pe) {
|
6989 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6990 |
} else {
|
6991 |
gen_update_cc_op(s); |
6992 |
gen_jmp_im(pc_start - s->cs_base); |
6993 |
gen_helper_sysexit(cpu_env, tcg_const_i32(dflag)); |
6994 |
gen_eob(s); |
6995 |
} |
6996 |
break;
|
6997 |
#ifdef TARGET_X86_64
|
6998 |
case 0x105: /* syscall */ |
6999 |
/* XXX: is it usable in real mode ? */
|
7000 |
gen_update_cc_op(s); |
7001 |
gen_jmp_im(pc_start - s->cs_base); |
7002 |
gen_helper_syscall(cpu_env, tcg_const_i32(s->pc - pc_start)); |
7003 |
gen_eob(s); |
7004 |
break;
|
7005 |
case 0x107: /* sysret */ |
7006 |
if (!s->pe) {
|
7007 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7008 |
} else {
|
7009 |
gen_update_cc_op(s); |
7010 |
gen_jmp_im(pc_start - s->cs_base); |
7011 |
gen_helper_sysret(cpu_env, tcg_const_i32(s->dflag)); |
7012 |
/* condition codes are modified only in long mode */
|
7013 |
if (s->lma)
|
7014 |
s->cc_op = CC_OP_EFLAGS; |
7015 |
gen_eob(s); |
7016 |
} |
7017 |
break;
|
7018 |
#endif
|
7019 |
case 0x1a2: /* cpuid */ |
7020 |
if (s->cc_op != CC_OP_DYNAMIC)
|
7021 |
gen_op_set_cc_op(s->cc_op); |
7022 |
gen_jmp_im(pc_start - s->cs_base); |
7023 |
gen_helper_cpuid(cpu_env); |
7024 |
break;
|
7025 |
case 0xf4: /* hlt */ |
7026 |
if (s->cpl != 0) { |
7027 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7028 |
} else {
|
7029 |
if (s->cc_op != CC_OP_DYNAMIC)
|
7030 |
gen_op_set_cc_op(s->cc_op); |
7031 |
gen_jmp_im(pc_start - s->cs_base); |
7032 |
gen_helper_hlt(cpu_env, tcg_const_i32(s->pc - pc_start)); |
7033 |
s->is_jmp = DISAS_TB_JUMP; |
7034 |
} |
7035 |
break;
|
7036 |
case 0x100: |
7037 |
modrm = cpu_ldub_code(env, s->pc++); |
7038 |
mod = (modrm >> 6) & 3; |
7039 |
op = (modrm >> 3) & 7; |
7040 |
switch(op) {
|
7041 |
case 0: /* sldt */ |
7042 |
if (!s->pe || s->vm86)
|
7043 |
goto illegal_op;
|
7044 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_LDTR_READ); |
7045 |
tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,ldt.selector));
|
7046 |
ot = OT_WORD; |
7047 |
if (mod == 3) |
7048 |
ot += s->dflag; |
7049 |
gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 1);
|
7050 |
break;
|
7051 |
case 2: /* lldt */ |
7052 |
if (!s->pe || s->vm86)
|
7053 |
goto illegal_op;
|
7054 |
if (s->cpl != 0) { |
7055 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7056 |
} else {
|
7057 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_LDTR_WRITE); |
7058 |
gen_ldst_modrm(env, s, modrm, OT_WORD, OR_TMP0, 0);
|
7059 |
gen_jmp_im(pc_start - s->cs_base); |
7060 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
7061 |
gen_helper_lldt(cpu_env, cpu_tmp2_i32); |
7062 |
} |
7063 |
break;
|
7064 |
case 1: /* str */ |
7065 |
if (!s->pe || s->vm86)
|
7066 |
goto illegal_op;
|
7067 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_TR_READ); |
7068 |
tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,tr.selector));
|
7069 |
ot = OT_WORD; |
7070 |
if (mod == 3) |
7071 |
ot += s->dflag; |
7072 |
gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 1);
|
7073 |
break;
|
7074 |
case 3: /* ltr */ |
7075 |
if (!s->pe || s->vm86)
|
7076 |
goto illegal_op;
|
7077 |
if (s->cpl != 0) { |
7078 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7079 |
} else {
|
7080 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_TR_WRITE); |
7081 |
gen_ldst_modrm(env, s, modrm, OT_WORD, OR_TMP0, 0);
|
7082 |
gen_jmp_im(pc_start - s->cs_base); |
7083 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
7084 |
gen_helper_ltr(cpu_env, cpu_tmp2_i32); |
7085 |
} |
7086 |
break;
|
7087 |
case 4: /* verr */ |
7088 |
case 5: /* verw */ |
7089 |
if (!s->pe || s->vm86)
|
7090 |
goto illegal_op;
|
7091 |
gen_ldst_modrm(env, s, modrm, OT_WORD, OR_TMP0, 0);
|
7092 |
if (s->cc_op != CC_OP_DYNAMIC)
|
7093 |
gen_op_set_cc_op(s->cc_op); |
7094 |
if (op == 4) { |
7095 |
gen_helper_verr(cpu_env, cpu_T[0]);
|
7096 |
} else {
|
7097 |
gen_helper_verw(cpu_env, cpu_T[0]);
|
7098 |
} |
7099 |
s->cc_op = CC_OP_EFLAGS; |
7100 |
break;
|
7101 |
default:
|
7102 |
goto illegal_op;
|
7103 |
} |
7104 |
break;
|
7105 |
case 0x101: |
7106 |
modrm = cpu_ldub_code(env, s->pc++); |
7107 |
mod = (modrm >> 6) & 3; |
7108 |
op = (modrm >> 3) & 7; |
7109 |
rm = modrm & 7;
|
7110 |
switch(op) {
|
7111 |
case 0: /* sgdt */ |
7112 |
if (mod == 3) |
7113 |
goto illegal_op;
|
7114 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_GDTR_READ); |
7115 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
7116 |
tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State, gdt.limit));
|
7117 |
gen_op_st_T0_A0(OT_WORD + s->mem_index); |
7118 |
gen_add_A0_im(s, 2);
|
7119 |
tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUX86State, gdt.base));
|
7120 |
if (!s->dflag)
|
7121 |
gen_op_andl_T0_im(0xffffff);
|
7122 |
gen_op_st_T0_A0(CODE64(s) + OT_LONG + s->mem_index); |
7123 |
break;
|
7124 |
case 1: |
7125 |
if (mod == 3) { |
7126 |
switch (rm) {
|
7127 |
case 0: /* monitor */ |
7128 |
if (!(s->cpuid_ext_features & CPUID_EXT_MONITOR) ||
|
7129 |
s->cpl != 0)
|
7130 |
goto illegal_op;
|
7131 |
if (s->cc_op != CC_OP_DYNAMIC)
|
7132 |
gen_op_set_cc_op(s->cc_op); |
7133 |
gen_jmp_im(pc_start - s->cs_base); |
7134 |
#ifdef TARGET_X86_64
|
7135 |
if (s->aflag == 2) { |
7136 |
gen_op_movq_A0_reg(R_EAX); |
7137 |
} else
|
7138 |
#endif
|
7139 |
{ |
7140 |
gen_op_movl_A0_reg(R_EAX); |
7141 |
if (s->aflag == 0) |
7142 |
gen_op_andl_A0_ffff(); |
7143 |
} |
7144 |
gen_add_A0_ds_seg(s); |
7145 |
gen_helper_monitor(cpu_env, cpu_A0); |
7146 |
break;
|
7147 |
case 1: /* mwait */ |
7148 |
if (!(s->cpuid_ext_features & CPUID_EXT_MONITOR) ||
|
7149 |
s->cpl != 0)
|
7150 |
goto illegal_op;
|
7151 |
gen_update_cc_op(s); |
7152 |
gen_jmp_im(pc_start - s->cs_base); |
7153 |
gen_helper_mwait(cpu_env, tcg_const_i32(s->pc - pc_start)); |
7154 |
gen_eob(s); |
7155 |
break;
|
7156 |
case 2: /* clac */ |
7157 |
if (!(s->cpuid_7_0_ebx_features & CPUID_7_0_EBX_SMAP) ||
|
7158 |
s->cpl != 0) {
|
7159 |
goto illegal_op;
|
7160 |
} |
7161 |
gen_helper_clac(cpu_env); |
7162 |
gen_jmp_im(s->pc - s->cs_base); |
7163 |
gen_eob(s); |
7164 |
break;
|
7165 |
case 3: /* stac */ |
7166 |
if (!(s->cpuid_7_0_ebx_features & CPUID_7_0_EBX_SMAP) ||
|
7167 |
s->cpl != 0) {
|
7168 |
goto illegal_op;
|
7169 |
} |
7170 |
gen_helper_stac(cpu_env); |
7171 |
gen_jmp_im(s->pc - s->cs_base); |
7172 |
gen_eob(s); |
7173 |
break;
|
7174 |
default:
|
7175 |
goto illegal_op;
|
7176 |
} |
7177 |
} else { /* sidt */ |
7178 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_IDTR_READ); |
7179 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
7180 |
tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State, idt.limit));
|
7181 |
gen_op_st_T0_A0(OT_WORD + s->mem_index); |
7182 |
gen_add_A0_im(s, 2);
|
7183 |
tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUX86State, idt.base));
|
7184 |
if (!s->dflag)
|
7185 |
gen_op_andl_T0_im(0xffffff);
|
7186 |
gen_op_st_T0_A0(CODE64(s) + OT_LONG + s->mem_index); |
7187 |
} |
7188 |
break;
|
7189 |
case 2: /* lgdt */ |
7190 |
case 3: /* lidt */ |
7191 |
if (mod == 3) { |
7192 |
if (s->cc_op != CC_OP_DYNAMIC)
|
7193 |
gen_op_set_cc_op(s->cc_op); |
7194 |
gen_jmp_im(pc_start - s->cs_base); |
7195 |
switch(rm) {
|
7196 |
case 0: /* VMRUN */ |
7197 |
if (!(s->flags & HF_SVME_MASK) || !s->pe)
|
7198 |
goto illegal_op;
|
7199 |
if (s->cpl != 0) { |
7200 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7201 |
break;
|
7202 |
} else {
|
7203 |
gen_helper_vmrun(cpu_env, tcg_const_i32(s->aflag), |
7204 |
tcg_const_i32(s->pc - pc_start)); |
7205 |
tcg_gen_exit_tb(0);
|
7206 |
s->is_jmp = DISAS_TB_JUMP; |
7207 |
} |
7208 |
break;
|
7209 |
case 1: /* VMMCALL */ |
7210 |
if (!(s->flags & HF_SVME_MASK))
|
7211 |
goto illegal_op;
|
7212 |
gen_helper_vmmcall(cpu_env); |
7213 |
break;
|
7214 |
case 2: /* VMLOAD */ |
7215 |
if (!(s->flags & HF_SVME_MASK) || !s->pe)
|
7216 |
goto illegal_op;
|
7217 |
if (s->cpl != 0) { |
7218 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7219 |
break;
|
7220 |
} else {
|
7221 |
gen_helper_vmload(cpu_env, tcg_const_i32(s->aflag)); |
7222 |
} |
7223 |
break;
|
7224 |
case 3: /* VMSAVE */ |
7225 |
if (!(s->flags & HF_SVME_MASK) || !s->pe)
|
7226 |
goto illegal_op;
|
7227 |
if (s->cpl != 0) { |
7228 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7229 |
break;
|
7230 |
} else {
|
7231 |
gen_helper_vmsave(cpu_env, tcg_const_i32(s->aflag)); |
7232 |
} |
7233 |
break;
|
7234 |
case 4: /* STGI */ |
7235 |
if ((!(s->flags & HF_SVME_MASK) &&
|
7236 |
!(s->cpuid_ext3_features & CPUID_EXT3_SKINIT)) || |
7237 |
!s->pe) |
7238 |
goto illegal_op;
|
7239 |
if (s->cpl != 0) { |
7240 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7241 |
break;
|
7242 |
} else {
|
7243 |
gen_helper_stgi(cpu_env); |
7244 |
} |
7245 |
break;
|
7246 |
case 5: /* CLGI */ |
7247 |
if (!(s->flags & HF_SVME_MASK) || !s->pe)
|
7248 |
goto illegal_op;
|
7249 |
if (s->cpl != 0) { |
7250 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7251 |
break;
|
7252 |
} else {
|
7253 |
gen_helper_clgi(cpu_env); |
7254 |
} |
7255 |
break;
|
7256 |
case 6: /* SKINIT */ |
7257 |
if ((!(s->flags & HF_SVME_MASK) &&
|
7258 |
!(s->cpuid_ext3_features & CPUID_EXT3_SKINIT)) || |
7259 |
!s->pe) |
7260 |
goto illegal_op;
|
7261 |
gen_helper_skinit(cpu_env); |
7262 |
break;
|
7263 |
case 7: /* INVLPGA */ |
7264 |
if (!(s->flags & HF_SVME_MASK) || !s->pe)
|
7265 |
goto illegal_op;
|
7266 |
if (s->cpl != 0) { |
7267 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7268 |
break;
|
7269 |
} else {
|
7270 |
gen_helper_invlpga(cpu_env, tcg_const_i32(s->aflag)); |
7271 |
} |
7272 |
break;
|
7273 |
default:
|
7274 |
goto illegal_op;
|
7275 |
} |
7276 |
} else if (s->cpl != 0) { |
7277 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7278 |
} else {
|
7279 |
gen_svm_check_intercept(s, pc_start, |
7280 |
op==2 ? SVM_EXIT_GDTR_WRITE : SVM_EXIT_IDTR_WRITE);
|
7281 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
7282 |
gen_op_ld_T1_A0(OT_WORD + s->mem_index); |
7283 |
gen_add_A0_im(s, 2);
|
7284 |
gen_op_ld_T0_A0(CODE64(s) + OT_LONG + s->mem_index); |
7285 |
if (!s->dflag)
|
7286 |
gen_op_andl_T0_im(0xffffff);
|
7287 |
if (op == 2) { |
7288 |
tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,gdt.base));
|
7289 |
tcg_gen_st32_tl(cpu_T[1], cpu_env, offsetof(CPUX86State,gdt.limit));
|
7290 |
} else {
|
7291 |
tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,idt.base));
|
7292 |
tcg_gen_st32_tl(cpu_T[1], cpu_env, offsetof(CPUX86State,idt.limit));
|
7293 |
} |
7294 |
} |
7295 |
break;
|
7296 |
case 4: /* smsw */ |
7297 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_READ_CR0); |
7298 |
#if defined TARGET_X86_64 && defined HOST_WORDS_BIGENDIAN
|
7299 |
tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,cr[0]) + 4); |
7300 |
#else
|
7301 |
tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,cr[0])); |
7302 |
#endif
|
7303 |
gen_ldst_modrm(env, s, modrm, OT_WORD, OR_TMP0, 1);
|
7304 |
break;
|
7305 |
case 6: /* lmsw */ |
7306 |
if (s->cpl != 0) { |
7307 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7308 |
} else {
|
7309 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_WRITE_CR0); |
7310 |
gen_ldst_modrm(env, s, modrm, OT_WORD, OR_TMP0, 0);
|
7311 |
gen_helper_lmsw(cpu_env, cpu_T[0]);
|
7312 |
gen_jmp_im(s->pc - s->cs_base); |
7313 |
gen_eob(s); |
7314 |
} |
7315 |
break;
|
7316 |
case 7: |
7317 |
if (mod != 3) { /* invlpg */ |
7318 |
if (s->cpl != 0) { |
7319 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7320 |
} else {
|
7321 |
if (s->cc_op != CC_OP_DYNAMIC)
|
7322 |
gen_op_set_cc_op(s->cc_op); |
7323 |
gen_jmp_im(pc_start - s->cs_base); |
7324 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
7325 |
gen_helper_invlpg(cpu_env, cpu_A0); |
7326 |
gen_jmp_im(s->pc - s->cs_base); |
7327 |
gen_eob(s); |
7328 |
} |
7329 |
} else {
|
7330 |
switch (rm) {
|
7331 |
case 0: /* swapgs */ |
7332 |
#ifdef TARGET_X86_64
|
7333 |
if (CODE64(s)) {
|
7334 |
if (s->cpl != 0) { |
7335 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7336 |
} else {
|
7337 |
tcg_gen_ld_tl(cpu_T[0], cpu_env,
|
7338 |
offsetof(CPUX86State,segs[R_GS].base)); |
7339 |
tcg_gen_ld_tl(cpu_T[1], cpu_env,
|
7340 |
offsetof(CPUX86State,kernelgsbase)); |
7341 |
tcg_gen_st_tl(cpu_T[1], cpu_env,
|
7342 |
offsetof(CPUX86State,segs[R_GS].base)); |
7343 |
tcg_gen_st_tl(cpu_T[0], cpu_env,
|
7344 |
offsetof(CPUX86State,kernelgsbase)); |
7345 |
} |
7346 |
} else
|
7347 |
#endif
|
7348 |
{ |
7349 |
goto illegal_op;
|
7350 |
} |
7351 |
break;
|
7352 |
case 1: /* rdtscp */ |
7353 |
if (!(s->cpuid_ext2_features & CPUID_EXT2_RDTSCP))
|
7354 |
goto illegal_op;
|
7355 |
if (s->cc_op != CC_OP_DYNAMIC)
|
7356 |
gen_op_set_cc_op(s->cc_op); |
7357 |
gen_jmp_im(pc_start - s->cs_base); |
7358 |
if (use_icount)
|
7359 |
gen_io_start(); |
7360 |
gen_helper_rdtscp(cpu_env); |
7361 |
if (use_icount) {
|
7362 |
gen_io_end(); |
7363 |
gen_jmp(s, s->pc - s->cs_base); |
7364 |
} |
7365 |
break;
|
7366 |
default:
|
7367 |
goto illegal_op;
|
7368 |
} |
7369 |
} |
7370 |
break;
|
7371 |
default:
|
7372 |
goto illegal_op;
|
7373 |
} |
7374 |
break;
|
7375 |
case 0x108: /* invd */ |
7376 |
case 0x109: /* wbinvd */ |
7377 |
if (s->cpl != 0) { |
7378 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7379 |
} else {
|
7380 |
gen_svm_check_intercept(s, pc_start, (b & 2) ? SVM_EXIT_INVD : SVM_EXIT_WBINVD);
|
7381 |
/* nothing to do */
|
7382 |
} |
7383 |
break;
|
7384 |
case 0x63: /* arpl or movslS (x86_64) */ |
7385 |
#ifdef TARGET_X86_64
|
7386 |
if (CODE64(s)) {
|
7387 |
int d_ot;
|
7388 |
/* d_ot is the size of destination */
|
7389 |
d_ot = dflag + OT_WORD; |
7390 |
|
7391 |
modrm = cpu_ldub_code(env, s->pc++); |
7392 |
reg = ((modrm >> 3) & 7) | rex_r; |
7393 |
mod = (modrm >> 6) & 3; |
7394 |
rm = (modrm & 7) | REX_B(s);
|
7395 |
|
7396 |
if (mod == 3) { |
7397 |
gen_op_mov_TN_reg(OT_LONG, 0, rm);
|
7398 |
/* sign extend */
|
7399 |
if (d_ot == OT_QUAD)
|
7400 |
tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]); |
7401 |
gen_op_mov_reg_T0(d_ot, reg); |
7402 |
} else {
|
7403 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
7404 |
if (d_ot == OT_QUAD) {
|
7405 |
gen_op_lds_T0_A0(OT_LONG + s->mem_index); |
7406 |
} else {
|
7407 |
gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
7408 |
} |
7409 |
gen_op_mov_reg_T0(d_ot, reg); |
7410 |
} |
7411 |
} else
|
7412 |
#endif
|
7413 |
{ |
7414 |
int label1;
|
7415 |
TCGv t0, t1, t2, a0; |
7416 |
|
7417 |
if (!s->pe || s->vm86)
|
7418 |
goto illegal_op;
|
7419 |
t0 = tcg_temp_local_new(); |
7420 |
t1 = tcg_temp_local_new(); |
7421 |
t2 = tcg_temp_local_new(); |
7422 |
ot = OT_WORD; |
7423 |
modrm = cpu_ldub_code(env, s->pc++); |
7424 |
reg = (modrm >> 3) & 7; |
7425 |
mod = (modrm >> 6) & 3; |
7426 |
rm = modrm & 7;
|
7427 |
if (mod != 3) { |
7428 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
7429 |
gen_op_ld_v(ot + s->mem_index, t0, cpu_A0); |
7430 |
a0 = tcg_temp_local_new(); |
7431 |
tcg_gen_mov_tl(a0, cpu_A0); |
7432 |
} else {
|
7433 |
gen_op_mov_v_reg(ot, t0, rm); |
7434 |
TCGV_UNUSED(a0); |
7435 |
} |
7436 |
gen_op_mov_v_reg(ot, t1, reg); |
7437 |
tcg_gen_andi_tl(cpu_tmp0, t0, 3);
|
7438 |
tcg_gen_andi_tl(t1, t1, 3);
|
7439 |
tcg_gen_movi_tl(t2, 0);
|
7440 |
label1 = gen_new_label(); |
7441 |
tcg_gen_brcond_tl(TCG_COND_GE, cpu_tmp0, t1, label1); |
7442 |
tcg_gen_andi_tl(t0, t0, ~3);
|
7443 |
tcg_gen_or_tl(t0, t0, t1); |
7444 |
tcg_gen_movi_tl(t2, CC_Z); |
7445 |
gen_set_label(label1); |
7446 |
if (mod != 3) { |
7447 |
gen_op_st_v(ot + s->mem_index, t0, a0); |
7448 |
tcg_temp_free(a0); |
7449 |
} else {
|
7450 |
gen_op_mov_reg_v(ot, rm, t0); |
7451 |
} |
7452 |
if (s->cc_op != CC_OP_DYNAMIC)
|
7453 |
gen_op_set_cc_op(s->cc_op); |
7454 |
gen_compute_eflags(cpu_cc_src); |
7455 |
tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, ~CC_Z); |
7456 |
tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, t2); |
7457 |
s->cc_op = CC_OP_EFLAGS; |
7458 |
tcg_temp_free(t0); |
7459 |
tcg_temp_free(t1); |
7460 |
tcg_temp_free(t2); |
7461 |
} |
7462 |
break;
|
7463 |
case 0x102: /* lar */ |
7464 |
case 0x103: /* lsl */ |
7465 |
{ |
7466 |
int label1;
|
7467 |
TCGv t0; |
7468 |
if (!s->pe || s->vm86)
|
7469 |
goto illegal_op;
|
7470 |
ot = dflag ? OT_LONG : OT_WORD; |
7471 |
modrm = cpu_ldub_code(env, s->pc++); |
7472 |
reg = ((modrm >> 3) & 7) | rex_r; |
7473 |
gen_ldst_modrm(env, s, modrm, OT_WORD, OR_TMP0, 0);
|
7474 |
t0 = tcg_temp_local_new(); |
7475 |
if (s->cc_op != CC_OP_DYNAMIC)
|
7476 |
gen_op_set_cc_op(s->cc_op); |
7477 |
if (b == 0x102) { |
7478 |
gen_helper_lar(t0, cpu_env, cpu_T[0]);
|
7479 |
} else {
|
7480 |
gen_helper_lsl(t0, cpu_env, cpu_T[0]);
|
7481 |
} |
7482 |
tcg_gen_andi_tl(cpu_tmp0, cpu_cc_src, CC_Z); |
7483 |
label1 = gen_new_label(); |
7484 |
tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, label1);
|
7485 |
gen_op_mov_reg_v(ot, reg, t0); |
7486 |
gen_set_label(label1); |
7487 |
s->cc_op = CC_OP_EFLAGS; |
7488 |
tcg_temp_free(t0); |
7489 |
} |
7490 |
break;
|
7491 |
case 0x118: |
7492 |
modrm = cpu_ldub_code(env, s->pc++); |
7493 |
mod = (modrm >> 6) & 3; |
7494 |
op = (modrm >> 3) & 7; |
7495 |
switch(op) {
|
7496 |
case 0: /* prefetchnta */ |
7497 |
case 1: /* prefetchnt0 */ |
7498 |
case 2: /* prefetchnt0 */ |
7499 |
case 3: /* prefetchnt0 */ |
7500 |
if (mod == 3) |
7501 |
goto illegal_op;
|
7502 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
7503 |
/* nothing more to do */
|
7504 |
break;
|
7505 |
default: /* nop (multi byte) */ |
7506 |
gen_nop_modrm(env, s, modrm); |
7507 |
break;
|
7508 |
} |
7509 |
break;
|
7510 |
case 0x119 ... 0x11f: /* nop (multi byte) */ |
7511 |
modrm = cpu_ldub_code(env, s->pc++); |
7512 |
gen_nop_modrm(env, s, modrm); |
7513 |
break;
|
7514 |
case 0x120: /* mov reg, crN */ |
7515 |
case 0x122: /* mov crN, reg */ |
7516 |
if (s->cpl != 0) { |
7517 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7518 |
} else {
|
7519 |
modrm = cpu_ldub_code(env, s->pc++); |
7520 |
/* Ignore the mod bits (assume (modrm&0xc0)==0xc0).
|
7521 |
* AMD documentation (24594.pdf) and testing of
|
7522 |
* intel 386 and 486 processors all show that the mod bits
|
7523 |
* are assumed to be 1's, regardless of actual values.
|
7524 |
*/
|
7525 |
rm = (modrm & 7) | REX_B(s);
|
7526 |
reg = ((modrm >> 3) & 7) | rex_r; |
7527 |
if (CODE64(s))
|
7528 |
ot = OT_QUAD; |
7529 |
else
|
7530 |
ot = OT_LONG; |
7531 |
if ((prefixes & PREFIX_LOCK) && (reg == 0) && |
7532 |
(s->cpuid_ext3_features & CPUID_EXT3_CR8LEG)) { |
7533 |
reg = 8;
|
7534 |
} |
7535 |
switch(reg) {
|
7536 |
case 0: |
7537 |
case 2: |
7538 |
case 3: |
7539 |
case 4: |
7540 |
case 8: |
7541 |
if (s->cc_op != CC_OP_DYNAMIC)
|
7542 |
gen_op_set_cc_op(s->cc_op); |
7543 |
gen_jmp_im(pc_start - s->cs_base); |
7544 |
if (b & 2) { |
7545 |
gen_op_mov_TN_reg(ot, 0, rm);
|
7546 |
gen_helper_write_crN(cpu_env, tcg_const_i32(reg), |
7547 |
cpu_T[0]);
|
7548 |
gen_jmp_im(s->pc - s->cs_base); |
7549 |
gen_eob(s); |
7550 |
} else {
|
7551 |
gen_helper_read_crN(cpu_T[0], cpu_env, tcg_const_i32(reg));
|
7552 |
gen_op_mov_reg_T0(ot, rm); |
7553 |
} |
7554 |
break;
|
7555 |
default:
|
7556 |
goto illegal_op;
|
7557 |
} |
7558 |
} |
7559 |
break;
|
7560 |
case 0x121: /* mov reg, drN */ |
7561 |
case 0x123: /* mov drN, reg */ |
7562 |
if (s->cpl != 0) { |
7563 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7564 |
} else {
|
7565 |
modrm = cpu_ldub_code(env, s->pc++); |
7566 |
/* Ignore the mod bits (assume (modrm&0xc0)==0xc0).
|
7567 |
* AMD documentation (24594.pdf) and testing of
|
7568 |
* intel 386 and 486 processors all show that the mod bits
|
7569 |
* are assumed to be 1's, regardless of actual values.
|
7570 |
*/
|
7571 |
rm = (modrm & 7) | REX_B(s);
|
7572 |
reg = ((modrm >> 3) & 7) | rex_r; |
7573 |
if (CODE64(s))
|
7574 |
ot = OT_QUAD; |
7575 |
else
|
7576 |
ot = OT_LONG; |
7577 |
/* XXX: do it dynamically with CR4.DE bit */
|
7578 |
if (reg == 4 || reg == 5 || reg >= 8) |
7579 |
goto illegal_op;
|
7580 |
if (b & 2) { |
7581 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_WRITE_DR0 + reg); |
7582 |
gen_op_mov_TN_reg(ot, 0, rm);
|
7583 |
gen_helper_movl_drN_T0(cpu_env, tcg_const_i32(reg), cpu_T[0]);
|
7584 |
gen_jmp_im(s->pc - s->cs_base); |
7585 |
gen_eob(s); |
7586 |
} else {
|
7587 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_READ_DR0 + reg); |
7588 |
tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,dr[reg]));
|
7589 |
gen_op_mov_reg_T0(ot, rm); |
7590 |
} |
7591 |
} |
7592 |
break;
|
7593 |
case 0x106: /* clts */ |
7594 |
if (s->cpl != 0) { |
7595 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7596 |
} else {
|
7597 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_WRITE_CR0); |
7598 |
gen_helper_clts(cpu_env); |
7599 |
/* abort block because static cpu state changed */
|
7600 |
gen_jmp_im(s->pc - s->cs_base); |
7601 |
gen_eob(s); |
7602 |
} |
7603 |
break;
|
7604 |
/* MMX/3DNow!/SSE/SSE2/SSE3/SSSE3/SSE4 support */
|
7605 |
case 0x1c3: /* MOVNTI reg, mem */ |
7606 |
if (!(s->cpuid_features & CPUID_SSE2))
|
7607 |
goto illegal_op;
|
7608 |
ot = s->dflag == 2 ? OT_QUAD : OT_LONG;
|
7609 |
modrm = cpu_ldub_code(env, s->pc++); |
7610 |
mod = (modrm >> 6) & 3; |
7611 |
if (mod == 3) |
7612 |
goto illegal_op;
|
7613 |
reg = ((modrm >> 3) & 7) | rex_r; |
7614 |
/* generate a generic store */
|
7615 |
gen_ldst_modrm(env, s, modrm, ot, reg, 1);
|
7616 |
break;
|
7617 |
case 0x1ae: |
7618 |
modrm = cpu_ldub_code(env, s->pc++); |
7619 |
mod = (modrm >> 6) & 3; |
7620 |
op = (modrm >> 3) & 7; |
7621 |
switch(op) {
|
7622 |
case 0: /* fxsave */ |
7623 |
if (mod == 3 || !(s->cpuid_features & CPUID_FXSR) || |
7624 |
(s->prefix & PREFIX_LOCK)) |
7625 |
goto illegal_op;
|
7626 |
if ((s->flags & HF_EM_MASK) || (s->flags & HF_TS_MASK)) {
|
7627 |
gen_exception(s, EXCP07_PREX, pc_start - s->cs_base); |
7628 |
break;
|
7629 |
} |
7630 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
7631 |
if (s->cc_op != CC_OP_DYNAMIC)
|
7632 |
gen_op_set_cc_op(s->cc_op); |
7633 |
gen_jmp_im(pc_start - s->cs_base); |
7634 |
gen_helper_fxsave(cpu_env, cpu_A0, tcg_const_i32((s->dflag == 2)));
|
7635 |
break;
|
7636 |
case 1: /* fxrstor */ |
7637 |
if (mod == 3 || !(s->cpuid_features & CPUID_FXSR) || |
7638 |
(s->prefix & PREFIX_LOCK)) |
7639 |
goto illegal_op;
|
7640 |
if ((s->flags & HF_EM_MASK) || (s->flags & HF_TS_MASK)) {
|
7641 |
gen_exception(s, EXCP07_PREX, pc_start - s->cs_base); |
7642 |
break;
|
7643 |
} |
7644 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
7645 |
if (s->cc_op != CC_OP_DYNAMIC)
|
7646 |
gen_op_set_cc_op(s->cc_op); |
7647 |
gen_jmp_im(pc_start - s->cs_base); |
7648 |
gen_helper_fxrstor(cpu_env, cpu_A0, |
7649 |
tcg_const_i32((s->dflag == 2)));
|
7650 |
break;
|
7651 |
case 2: /* ldmxcsr */ |
7652 |
case 3: /* stmxcsr */ |
7653 |
if (s->flags & HF_TS_MASK) {
|
7654 |
gen_exception(s, EXCP07_PREX, pc_start - s->cs_base); |
7655 |
break;
|
7656 |
} |
7657 |
if ((s->flags & HF_EM_MASK) || !(s->flags & HF_OSFXSR_MASK) ||
|
7658 |
mod == 3)
|
7659 |
goto illegal_op;
|
7660 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
7661 |
if (op == 2) { |
7662 |
gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
7663 |
tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
7664 |
gen_helper_ldmxcsr(cpu_env, cpu_tmp2_i32); |
7665 |
} else {
|
7666 |
tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State, mxcsr));
|
7667 |
gen_op_st_T0_A0(OT_LONG + s->mem_index); |
7668 |
} |
7669 |
break;
|
7670 |
case 5: /* lfence */ |
7671 |
case 6: /* mfence */ |
7672 |
if ((modrm & 0xc7) != 0xc0 || !(s->cpuid_features & CPUID_SSE2)) |
7673 |
goto illegal_op;
|
7674 |
break;
|
7675 |
case 7: /* sfence / clflush */ |
7676 |
if ((modrm & 0xc7) == 0xc0) { |
7677 |
/* sfence */
|
7678 |
/* XXX: also check for cpuid_ext2_features & CPUID_EXT2_EMMX */
|
7679 |
if (!(s->cpuid_features & CPUID_SSE))
|
7680 |
goto illegal_op;
|
7681 |
} else {
|
7682 |
/* clflush */
|
7683 |
if (!(s->cpuid_features & CPUID_CLFLUSH))
|
7684 |
goto illegal_op;
|
7685 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
7686 |
} |
7687 |
break;
|
7688 |
default:
|
7689 |
goto illegal_op;
|
7690 |
} |
7691 |
break;
|
7692 |
case 0x10d: /* 3DNow! prefetch(w) */ |
7693 |
modrm = cpu_ldub_code(env, s->pc++); |
7694 |
mod = (modrm >> 6) & 3; |
7695 |
if (mod == 3) |
7696 |
goto illegal_op;
|
7697 |
gen_lea_modrm(env, s, modrm, ®_addr, &offset_addr); |
7698 |
/* ignore for now */
|
7699 |
break;
|
7700 |
case 0x1aa: /* rsm */ |
7701 |
gen_svm_check_intercept(s, pc_start, SVM_EXIT_RSM); |
7702 |
if (!(s->flags & HF_SMM_MASK))
|
7703 |
goto illegal_op;
|
7704 |
gen_update_cc_op(s); |
7705 |
gen_jmp_im(s->pc - s->cs_base); |
7706 |
gen_helper_rsm(cpu_env); |
7707 |
gen_eob(s); |
7708 |
break;
|
7709 |
case 0x1b8: /* SSE4.2 popcnt */ |
7710 |
if ((prefixes & (PREFIX_REPZ | PREFIX_LOCK | PREFIX_REPNZ)) !=
|
7711 |
PREFIX_REPZ) |
7712 |
goto illegal_op;
|
7713 |
if (!(s->cpuid_ext_features & CPUID_EXT_POPCNT))
|
7714 |
goto illegal_op;
|
7715 |
|
7716 |
modrm = cpu_ldub_code(env, s->pc++); |
7717 |
reg = ((modrm >> 3) & 7) | rex_r; |
7718 |
|
7719 |
if (s->prefix & PREFIX_DATA)
|
7720 |
ot = OT_WORD; |
7721 |
else if (s->dflag != 2) |
7722 |
ot = OT_LONG; |
7723 |
else
|
7724 |
ot = OT_QUAD; |
7725 |
|
7726 |
gen_ldst_modrm(env, s, modrm, ot, OR_TMP0, 0);
|
7727 |
gen_helper_popcnt(cpu_T[0], cpu_env, cpu_T[0], tcg_const_i32(ot)); |
7728 |
gen_op_mov_reg_T0(ot, reg); |
7729 |
|
7730 |
s->cc_op = CC_OP_EFLAGS; |
7731 |
break;
|
7732 |
case 0x10e ... 0x10f: |
7733 |
/* 3DNow! instructions, ignore prefixes */
|
7734 |
s->prefix &= ~(PREFIX_REPZ | PREFIX_REPNZ | PREFIX_DATA); |
7735 |
case 0x110 ... 0x117: |
7736 |
case 0x128 ... 0x12f: |
7737 |
case 0x138 ... 0x13a: |
7738 |
case 0x150 ... 0x179: |
7739 |
case 0x17c ... 0x17f: |
7740 |
case 0x1c2: |
7741 |
case 0x1c4 ... 0x1c6: |
7742 |
case 0x1d0 ... 0x1fe: |
7743 |
gen_sse(env, s, b, pc_start, rex_r); |
7744 |
break;
|
7745 |
default:
|
7746 |
goto illegal_op;
|
7747 |
} |
7748 |
/* lock generation */
|
7749 |
if (s->prefix & PREFIX_LOCK)
|
7750 |
gen_helper_unlock(); |
7751 |
return s->pc;
|
7752 |
illegal_op:
|
7753 |
if (s->prefix & PREFIX_LOCK)
|
7754 |
gen_helper_unlock(); |
7755 |
/* XXX: ensure that no lock was generated */
|
7756 |
gen_exception(s, EXCP06_ILLOP, pc_start - s->cs_base); |
7757 |
return s->pc;
|
7758 |
} |
7759 |
|
7760 |
void optimize_flags_init(void) |
7761 |
{ |
7762 |
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
|
7763 |
cpu_cc_op = tcg_global_mem_new_i32(TCG_AREG0, |
7764 |
offsetof(CPUX86State, cc_op), "cc_op");
|
7765 |
cpu_cc_src = tcg_global_mem_new(TCG_AREG0, offsetof(CPUX86State, cc_src), |
7766 |
"cc_src");
|
7767 |
cpu_cc_dst = tcg_global_mem_new(TCG_AREG0, offsetof(CPUX86State, cc_dst), |
7768 |
"cc_dst");
|
7769 |
cpu_cc_tmp = tcg_global_mem_new(TCG_AREG0, offsetof(CPUX86State, cc_tmp), |
7770 |
"cc_tmp");
|
7771 |
|
7772 |
#ifdef TARGET_X86_64
|
7773 |
cpu_regs[R_EAX] = tcg_global_mem_new_i64(TCG_AREG0, |
7774 |
offsetof(CPUX86State, regs[R_EAX]), "rax");
|
7775 |
cpu_regs[R_ECX] = tcg_global_mem_new_i64(TCG_AREG0, |
7776 |
offsetof(CPUX86State, regs[R_ECX]), "rcx");
|
7777 |
cpu_regs[R_EDX] = tcg_global_mem_new_i64(TCG_AREG0, |
7778 |
offsetof(CPUX86State, regs[R_EDX]), "rdx");
|
7779 |
cpu_regs[R_EBX] = tcg_global_mem_new_i64(TCG_AREG0, |
7780 |
offsetof(CPUX86State, regs[R_EBX]), "rbx");
|
7781 |
cpu_regs[R_ESP] = tcg_global_mem_new_i64(TCG_AREG0, |
7782 |
offsetof(CPUX86State, regs[R_ESP]), "rsp");
|
7783 |
cpu_regs[R_EBP] = tcg_global_mem_new_i64(TCG_AREG0, |
7784 |
offsetof(CPUX86State, regs[R_EBP]), "rbp");
|
7785 |
cpu_regs[R_ESI] = tcg_global_mem_new_i64(TCG_AREG0, |
7786 |
offsetof(CPUX86State, regs[R_ESI]), "rsi");
|
7787 |
cpu_regs[R_EDI] = tcg_global_mem_new_i64(TCG_AREG0, |
7788 |
offsetof(CPUX86State, regs[R_EDI]), "rdi");
|
7789 |
cpu_regs[8] = tcg_global_mem_new_i64(TCG_AREG0,
|
7790 |
offsetof(CPUX86State, regs[8]), "r8"); |
7791 |
cpu_regs[9] = tcg_global_mem_new_i64(TCG_AREG0,
|
7792 |
offsetof(CPUX86State, regs[9]), "r9"); |
7793 |
cpu_regs[10] = tcg_global_mem_new_i64(TCG_AREG0,
|
7794 |
offsetof(CPUX86State, regs[10]), "r10"); |
7795 |
cpu_regs[11] = tcg_global_mem_new_i64(TCG_AREG0,
|
7796 |
offsetof(CPUX86State, regs[11]), "r11"); |
7797 |
cpu_regs[12] = tcg_global_mem_new_i64(TCG_AREG0,
|
7798 |
offsetof(CPUX86State, regs[12]), "r12"); |
7799 |
cpu_regs[13] = tcg_global_mem_new_i64(TCG_AREG0,
|
7800 |
offsetof(CPUX86State, regs[13]), "r13"); |
7801 |
cpu_regs[14] = tcg_global_mem_new_i64(TCG_AREG0,
|
7802 |
offsetof(CPUX86State, regs[14]), "r14"); |
7803 |
cpu_regs[15] = tcg_global_mem_new_i64(TCG_AREG0,
|
7804 |
offsetof(CPUX86State, regs[15]), "r15"); |
7805 |
#else
|
7806 |
cpu_regs[R_EAX] = tcg_global_mem_new_i32(TCG_AREG0, |
7807 |
offsetof(CPUX86State, regs[R_EAX]), "eax");
|
7808 |
cpu_regs[R_ECX] = tcg_global_mem_new_i32(TCG_AREG0, |
7809 |
offsetof(CPUX86State, regs[R_ECX]), "ecx");
|
7810 |
cpu_regs[R_EDX] = tcg_global_mem_new_i32(TCG_AREG0, |
7811 |
offsetof(CPUX86State, regs[R_EDX]), "edx");
|
7812 |
cpu_regs[R_EBX] = tcg_global_mem_new_i32(TCG_AREG0, |
7813 |
offsetof(CPUX86State, regs[R_EBX]), "ebx");
|
7814 |
cpu_regs[R_ESP] = tcg_global_mem_new_i32(TCG_AREG0, |
7815 |
offsetof(CPUX86State, regs[R_ESP]), "esp");
|
7816 |
cpu_regs[R_EBP] = tcg_global_mem_new_i32(TCG_AREG0, |
7817 |
offsetof(CPUX86State, regs[R_EBP]), "ebp");
|
7818 |
cpu_regs[R_ESI] = tcg_global_mem_new_i32(TCG_AREG0, |
7819 |
offsetof(CPUX86State, regs[R_ESI]), "esi");
|
7820 |
cpu_regs[R_EDI] = tcg_global_mem_new_i32(TCG_AREG0, |
7821 |
offsetof(CPUX86State, regs[R_EDI]), "edi");
|
7822 |
#endif
|
7823 |
|
7824 |
/* register helpers */
|
7825 |
#define GEN_HELPER 2 |
7826 |
#include "helper.h" |
7827 |
} |
7828 |
|
7829 |
/* generate intermediate code in gen_opc_buf and gen_opparam_buf for
|
7830 |
basic block 'tb'. If search_pc is TRUE, also generate PC
|
7831 |
information for each intermediate instruction. */
|
7832 |
static inline void gen_intermediate_code_internal(CPUX86State *env, |
7833 |
TranslationBlock *tb, |
7834 |
int search_pc)
|
7835 |
{ |
7836 |
DisasContext dc1, *dc = &dc1; |
7837 |
target_ulong pc_ptr; |
7838 |
uint16_t *gen_opc_end; |
7839 |
CPUBreakpoint *bp; |
7840 |
int j, lj;
|
7841 |
uint64_t flags; |
7842 |
target_ulong pc_start; |
7843 |
target_ulong cs_base; |
7844 |
int num_insns;
|
7845 |
int max_insns;
|
7846 |
|
7847 |
/* generate intermediate code */
|
7848 |
pc_start = tb->pc; |
7849 |
cs_base = tb->cs_base; |
7850 |
flags = tb->flags; |
7851 |
|
7852 |
dc->pe = (flags >> HF_PE_SHIFT) & 1;
|
7853 |
dc->code32 = (flags >> HF_CS32_SHIFT) & 1;
|
7854 |
dc->ss32 = (flags >> HF_SS32_SHIFT) & 1;
|
7855 |
dc->addseg = (flags >> HF_ADDSEG_SHIFT) & 1;
|
7856 |
dc->f_st = 0;
|
7857 |
dc->vm86 = (flags >> VM_SHIFT) & 1;
|
7858 |
dc->cpl = (flags >> HF_CPL_SHIFT) & 3;
|
7859 |
dc->iopl = (flags >> IOPL_SHIFT) & 3;
|
7860 |
dc->tf = (flags >> TF_SHIFT) & 1;
|
7861 |
dc->singlestep_enabled = env->singlestep_enabled; |
7862 |
dc->cc_op = CC_OP_DYNAMIC; |
7863 |
dc->cs_base = cs_base; |
7864 |
dc->tb = tb; |
7865 |
dc->popl_esp_hack = 0;
|
7866 |
/* select memory access functions */
|
7867 |
dc->mem_index = 0;
|
7868 |
if (flags & HF_SOFTMMU_MASK) {
|
7869 |
dc->mem_index = (cpu_mmu_index(env) + 1) << 2; |
7870 |
} |
7871 |
dc->cpuid_features = env->cpuid_features; |
7872 |
dc->cpuid_ext_features = env->cpuid_ext_features; |
7873 |
dc->cpuid_ext2_features = env->cpuid_ext2_features; |
7874 |
dc->cpuid_ext3_features = env->cpuid_ext3_features; |
7875 |
dc->cpuid_7_0_ebx_features = env->cpuid_7_0_ebx_features; |
7876 |
#ifdef TARGET_X86_64
|
7877 |
dc->lma = (flags >> HF_LMA_SHIFT) & 1;
|
7878 |
dc->code64 = (flags >> HF_CS64_SHIFT) & 1;
|
7879 |
#endif
|
7880 |
dc->flags = flags; |
7881 |
dc->jmp_opt = !(dc->tf || env->singlestep_enabled || |
7882 |
(flags & HF_INHIBIT_IRQ_MASK) |
7883 |
#ifndef CONFIG_SOFTMMU
|
7884 |
|| (flags & HF_SOFTMMU_MASK) |
7885 |
#endif
|
7886 |
); |
7887 |
#if 0
|
7888 |
/* check addseg logic */
|
7889 |
if (!dc->addseg && (dc->vm86 || !dc->pe || !dc->code32))
|
7890 |
printf("ERROR addseg\n");
|
7891 |
#endif
|
7892 |
|
7893 |
cpu_T[0] = tcg_temp_new();
|
7894 |
cpu_T[1] = tcg_temp_new();
|
7895 |
cpu_A0 = tcg_temp_new(); |
7896 |
cpu_T3 = tcg_temp_new(); |
7897 |
|
7898 |
cpu_tmp0 = tcg_temp_new(); |
7899 |
cpu_tmp1_i64 = tcg_temp_new_i64(); |
7900 |
cpu_tmp2_i32 = tcg_temp_new_i32(); |
7901 |
cpu_tmp3_i32 = tcg_temp_new_i32(); |
7902 |
cpu_tmp4 = tcg_temp_new(); |
7903 |
cpu_tmp5 = tcg_temp_new(); |
7904 |
cpu_ptr0 = tcg_temp_new_ptr(); |
7905 |
cpu_ptr1 = tcg_temp_new_ptr(); |
7906 |
|
7907 |
gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE; |
7908 |
|
7909 |
dc->is_jmp = DISAS_NEXT; |
7910 |
pc_ptr = pc_start; |
7911 |
lj = -1;
|
7912 |
num_insns = 0;
|
7913 |
max_insns = tb->cflags & CF_COUNT_MASK; |
7914 |
if (max_insns == 0) |
7915 |
max_insns = CF_COUNT_MASK; |
7916 |
|
7917 |
gen_icount_start(); |
7918 |
for(;;) {
|
7919 |
if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
|
7920 |
QTAILQ_FOREACH(bp, &env->breakpoints, entry) { |
7921 |
if (bp->pc == pc_ptr &&
|
7922 |
!((bp->flags & BP_CPU) && (tb->flags & HF_RF_MASK))) { |
7923 |
gen_debug(dc, pc_ptr - dc->cs_base); |
7924 |
break;
|
7925 |
} |
7926 |
} |
7927 |
} |
7928 |
if (search_pc) {
|
7929 |
j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; |
7930 |
if (lj < j) {
|
7931 |
lj++; |
7932 |
while (lj < j)
|
7933 |
tcg_ctx.gen_opc_instr_start[lj++] = 0;
|
7934 |
} |
7935 |
tcg_ctx.gen_opc_pc[lj] = pc_ptr; |
7936 |
gen_opc_cc_op[lj] = dc->cc_op; |
7937 |
tcg_ctx.gen_opc_instr_start[lj] = 1;
|
7938 |
tcg_ctx.gen_opc_icount[lj] = num_insns; |
7939 |
} |
7940 |
if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) |
7941 |
gen_io_start(); |
7942 |
|
7943 |
pc_ptr = disas_insn(env, dc, pc_ptr); |
7944 |
num_insns++; |
7945 |
/* stop translation if indicated */
|
7946 |
if (dc->is_jmp)
|
7947 |
break;
|
7948 |
/* if single step mode, we generate only one instruction and
|
7949 |
generate an exception */
|
7950 |
/* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear
|
7951 |
the flag and abort the translation to give the irqs a
|
7952 |
change to be happen */
|
7953 |
if (dc->tf || dc->singlestep_enabled ||
|
7954 |
(flags & HF_INHIBIT_IRQ_MASK)) { |
7955 |
gen_jmp_im(pc_ptr - dc->cs_base); |
7956 |
gen_eob(dc); |
7957 |
break;
|
7958 |
} |
7959 |
/* if too long translation, stop generation too */
|
7960 |
if (tcg_ctx.gen_opc_ptr >= gen_opc_end ||
|
7961 |
(pc_ptr - pc_start) >= (TARGET_PAGE_SIZE - 32) ||
|
7962 |
num_insns >= max_insns) { |
7963 |
gen_jmp_im(pc_ptr - dc->cs_base); |
7964 |
gen_eob(dc); |
7965 |
break;
|
7966 |
} |
7967 |
if (singlestep) {
|
7968 |
gen_jmp_im(pc_ptr - dc->cs_base); |
7969 |
gen_eob(dc); |
7970 |
break;
|
7971 |
} |
7972 |
} |
7973 |
if (tb->cflags & CF_LAST_IO)
|
7974 |
gen_io_end(); |
7975 |
gen_icount_end(tb, num_insns); |
7976 |
*tcg_ctx.gen_opc_ptr = INDEX_op_end; |
7977 |
/* we don't forget to fill the last values */
|
7978 |
if (search_pc) {
|
7979 |
j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; |
7980 |
lj++; |
7981 |
while (lj <= j)
|
7982 |
tcg_ctx.gen_opc_instr_start[lj++] = 0;
|
7983 |
} |
7984 |
|
7985 |
#ifdef DEBUG_DISAS
|
7986 |
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
|
7987 |
int disas_flags;
|
7988 |
qemu_log("----------------\n");
|
7989 |
qemu_log("IN: %s\n", lookup_symbol(pc_start));
|
7990 |
#ifdef TARGET_X86_64
|
7991 |
if (dc->code64)
|
7992 |
disas_flags = 2;
|
7993 |
else
|
7994 |
#endif
|
7995 |
disas_flags = !dc->code32; |
7996 |
log_target_disas(env, pc_start, pc_ptr - pc_start, disas_flags); |
7997 |
qemu_log("\n");
|
7998 |
} |
7999 |
#endif
|
8000 |
|
8001 |
if (!search_pc) {
|
8002 |
tb->size = pc_ptr - pc_start; |
8003 |
tb->icount = num_insns; |
8004 |
} |
8005 |
} |
8006 |
|
8007 |
void gen_intermediate_code(CPUX86State *env, TranslationBlock *tb)
|
8008 |
{ |
8009 |
gen_intermediate_code_internal(env, tb, 0);
|
8010 |
} |
8011 |
|
8012 |
void gen_intermediate_code_pc(CPUX86State *env, TranslationBlock *tb)
|
8013 |
{ |
8014 |
gen_intermediate_code_internal(env, tb, 1);
|
8015 |
} |
8016 |
|
8017 |
void restore_state_to_opc(CPUX86State *env, TranslationBlock *tb, int pc_pos) |
8018 |
{ |
8019 |
int cc_op;
|
8020 |
#ifdef DEBUG_DISAS
|
8021 |
if (qemu_loglevel_mask(CPU_LOG_TB_OP)) {
|
8022 |
int i;
|
8023 |
qemu_log("RESTORE:\n");
|
8024 |
for(i = 0;i <= pc_pos; i++) { |
8025 |
if (tcg_ctx.gen_opc_instr_start[i]) {
|
8026 |
qemu_log("0x%04x: " TARGET_FMT_lx "\n", i, |
8027 |
tcg_ctx.gen_opc_pc[i]); |
8028 |
} |
8029 |
} |
8030 |
qemu_log("pc_pos=0x%x eip=" TARGET_FMT_lx " cs_base=%x\n", |
8031 |
pc_pos, tcg_ctx.gen_opc_pc[pc_pos] - tb->cs_base, |
8032 |
(uint32_t)tb->cs_base); |
8033 |
} |
8034 |
#endif
|
8035 |
env->eip = tcg_ctx.gen_opc_pc[pc_pos] - tb->cs_base; |
8036 |
cc_op = gen_opc_cc_op[pc_pos]; |
8037 |
if (cc_op != CC_OP_DYNAMIC)
|
8038 |
env->cc_op = cc_op; |
8039 |
} |