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