root / target-i386 / translate.c @ 989cebff
History | View | Annotate | Download (251.3 kB)
1 | 2c0262af | bellard | /*
|
---|---|---|---|
2 | 2c0262af | bellard | * i386 translation
|
3 | 5fafdf24 | ths | *
|
4 | 2c0262af | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 2c0262af | bellard | *
|
6 | 2c0262af | bellard | * This library is free software; you can redistribute it and/or
|
7 | 2c0262af | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | 2c0262af | bellard | * License as published by the Free Software Foundation; either
|
9 | 2c0262af | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | 2c0262af | bellard | *
|
11 | 2c0262af | bellard | * This library is distributed in the hope that it will be useful,
|
12 | 2c0262af | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 2c0262af | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 2c0262af | bellard | * Lesser General Public License for more details.
|
15 | 2c0262af | bellard | *
|
16 | 2c0262af | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | 2c0262af | bellard | * License along with this library; if not, write to the Free Software
|
18 | fad6cb1a | aurel32 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
|
19 | 2c0262af | bellard | */
|
20 | 2c0262af | bellard | #include <stdarg.h> |
21 | 2c0262af | bellard | #include <stdlib.h> |
22 | 2c0262af | bellard | #include <stdio.h> |
23 | 2c0262af | bellard | #include <string.h> |
24 | 2c0262af | bellard | #include <inttypes.h> |
25 | 2c0262af | bellard | #include <signal.h> |
26 | 2c0262af | bellard | #include <assert.h> |
27 | 2c0262af | bellard | |
28 | 2c0262af | bellard | #include "cpu.h" |
29 | 2c0262af | bellard | #include "exec-all.h" |
30 | 2c0262af | bellard | #include "disas.h" |
31 | 57fec1fe | bellard | #include "tcg-op.h" |
32 | 2c0262af | bellard | |
33 | a7812ae4 | pbrook | #include "helper.h" |
34 | a7812ae4 | pbrook | #define GEN_HELPER 1 |
35 | a7812ae4 | pbrook | #include "helper.h" |
36 | a7812ae4 | pbrook | |
37 | 2c0262af | bellard | #define PREFIX_REPZ 0x01 |
38 | 2c0262af | bellard | #define PREFIX_REPNZ 0x02 |
39 | 2c0262af | bellard | #define PREFIX_LOCK 0x04 |
40 | 2c0262af | bellard | #define PREFIX_DATA 0x08 |
41 | 2c0262af | bellard | #define PREFIX_ADR 0x10 |
42 | 2c0262af | bellard | |
43 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
44 | 14ce26e7 | bellard | #define X86_64_ONLY(x) x
|
45 | 14ce26e7 | bellard | #define X86_64_DEF(x...) x
|
46 | 14ce26e7 | bellard | #define CODE64(s) ((s)->code64)
|
47 | 14ce26e7 | bellard | #define REX_X(s) ((s)->rex_x)
|
48 | 14ce26e7 | bellard | #define REX_B(s) ((s)->rex_b)
|
49 | 14ce26e7 | bellard | /* XXX: gcc generates push/pop in some opcodes, so we cannot use them */
|
50 | 14ce26e7 | bellard | #if 1 |
51 | 14ce26e7 | bellard | #define BUGGY_64(x) NULL |
52 | 14ce26e7 | bellard | #endif
|
53 | 14ce26e7 | bellard | #else
|
54 | 14ce26e7 | bellard | #define X86_64_ONLY(x) NULL |
55 | 14ce26e7 | bellard | #define X86_64_DEF(x...)
|
56 | 14ce26e7 | bellard | #define CODE64(s) 0 |
57 | 14ce26e7 | bellard | #define REX_X(s) 0 |
58 | 14ce26e7 | bellard | #define REX_B(s) 0 |
59 | 14ce26e7 | bellard | #endif
|
60 | 14ce26e7 | bellard | |
61 | 57fec1fe | bellard | //#define MACRO_TEST 1
|
62 | 57fec1fe | bellard | |
63 | 57fec1fe | bellard | /* global register indexes */
|
64 | a7812ae4 | pbrook | static TCGv_ptr cpu_env;
|
65 | a7812ae4 | pbrook | static TCGv cpu_A0, cpu_cc_src, cpu_cc_dst, cpu_cc_tmp;
|
66 | a7812ae4 | pbrook | static TCGv_i32 cpu_cc_op;
|
67 | 1e4840bf | bellard | /* local temps */
|
68 | 1e4840bf | bellard | static TCGv cpu_T[2], cpu_T3; |
69 | 57fec1fe | bellard | /* local register indexes (only used inside old micro ops) */
|
70 | a7812ae4 | pbrook | static TCGv cpu_tmp0, cpu_tmp4;
|
71 | a7812ae4 | pbrook | static TCGv_ptr cpu_ptr0, cpu_ptr1;
|
72 | a7812ae4 | pbrook | static TCGv_i32 cpu_tmp2_i32, cpu_tmp3_i32;
|
73 | a7812ae4 | pbrook | static TCGv_i64 cpu_tmp1_i64;
|
74 | b6abf97d | bellard | static TCGv cpu_tmp5, cpu_tmp6;
|
75 | 57fec1fe | bellard | |
76 | 2e70f6ef | pbrook | #include "gen-icount.h" |
77 | 2e70f6ef | pbrook | |
78 | 57fec1fe | bellard | #ifdef TARGET_X86_64
|
79 | 57fec1fe | bellard | static int x86_64_hregs; |
80 | ae063a68 | bellard | #endif
|
81 | ae063a68 | bellard | |
82 | 2c0262af | bellard | typedef struct DisasContext { |
83 | 2c0262af | bellard | /* current insn context */
|
84 | 2c0262af | bellard | int override; /* -1 if no override */ |
85 | 2c0262af | bellard | int prefix;
|
86 | 2c0262af | bellard | int aflag, dflag;
|
87 | 14ce26e7 | bellard | target_ulong pc; /* pc = eip + cs_base */
|
88 | 2c0262af | bellard | int is_jmp; /* 1 = means jump (stop translation), 2 means CPU |
89 | 2c0262af | bellard | static state change (stop translation) */
|
90 | 2c0262af | bellard | /* current block context */
|
91 | 14ce26e7 | bellard | target_ulong cs_base; /* base of CS segment */
|
92 | 2c0262af | bellard | int pe; /* protected mode */ |
93 | 2c0262af | bellard | int code32; /* 32 bit code segment */ |
94 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
95 | 14ce26e7 | bellard | int lma; /* long mode active */ |
96 | 14ce26e7 | bellard | int code64; /* 64 bit code segment */ |
97 | 14ce26e7 | bellard | int rex_x, rex_b;
|
98 | 14ce26e7 | bellard | #endif
|
99 | 2c0262af | bellard | int ss32; /* 32 bit stack segment */ |
100 | 2c0262af | bellard | int cc_op; /* current CC operation */ |
101 | 2c0262af | bellard | int addseg; /* non zero if either DS/ES/SS have a non zero base */ |
102 | 2c0262af | bellard | int f_st; /* currently unused */ |
103 | 2c0262af | bellard | int vm86; /* vm86 mode */ |
104 | 2c0262af | bellard | int cpl;
|
105 | 2c0262af | bellard | int iopl;
|
106 | 2c0262af | bellard | int tf; /* TF cpu flag */ |
107 | 34865134 | bellard | int singlestep_enabled; /* "hardware" single step enabled */ |
108 | 2c0262af | bellard | int jmp_opt; /* use direct block chaining for direct jumps */ |
109 | 2c0262af | bellard | int mem_index; /* select memory access functions */ |
110 | c068688b | j_mayer | uint64_t flags; /* all execution flags */
|
111 | 2c0262af | bellard | struct TranslationBlock *tb;
|
112 | 2c0262af | bellard | int popl_esp_hack; /* for correct popl with esp base handling */ |
113 | 14ce26e7 | bellard | int rip_offset; /* only used in x86_64, but left for simplicity */ |
114 | 14ce26e7 | bellard | int cpuid_features;
|
115 | 3d7374c5 | bellard | int cpuid_ext_features;
|
116 | e771edab | aurel32 | int cpuid_ext2_features;
|
117 | 12e26b75 | bellard | int cpuid_ext3_features;
|
118 | 2c0262af | bellard | } DisasContext; |
119 | 2c0262af | bellard | |
120 | 2c0262af | bellard | static void gen_eob(DisasContext *s); |
121 | 14ce26e7 | bellard | static void gen_jmp(DisasContext *s, target_ulong eip); |
122 | 14ce26e7 | bellard | static void gen_jmp_tb(DisasContext *s, target_ulong eip, int tb_num); |
123 | 2c0262af | bellard | |
124 | 2c0262af | bellard | /* i386 arith/logic operations */
|
125 | 2c0262af | bellard | enum {
|
126 | 5fafdf24 | ths | OP_ADDL, |
127 | 5fafdf24 | ths | OP_ORL, |
128 | 5fafdf24 | ths | OP_ADCL, |
129 | 2c0262af | bellard | OP_SBBL, |
130 | 5fafdf24 | ths | OP_ANDL, |
131 | 5fafdf24 | ths | OP_SUBL, |
132 | 5fafdf24 | ths | OP_XORL, |
133 | 2c0262af | bellard | OP_CMPL, |
134 | 2c0262af | bellard | }; |
135 | 2c0262af | bellard | |
136 | 2c0262af | bellard | /* i386 shift ops */
|
137 | 2c0262af | bellard | enum {
|
138 | 5fafdf24 | ths | OP_ROL, |
139 | 5fafdf24 | ths | OP_ROR, |
140 | 5fafdf24 | ths | OP_RCL, |
141 | 5fafdf24 | ths | OP_RCR, |
142 | 5fafdf24 | ths | OP_SHL, |
143 | 5fafdf24 | ths | OP_SHR, |
144 | 2c0262af | bellard | OP_SHL1, /* undocumented */
|
145 | 2c0262af | bellard | OP_SAR = 7,
|
146 | 2c0262af | bellard | }; |
147 | 2c0262af | bellard | |
148 | 8e1c85e3 | bellard | enum {
|
149 | 8e1c85e3 | bellard | JCC_O, |
150 | 8e1c85e3 | bellard | JCC_B, |
151 | 8e1c85e3 | bellard | JCC_Z, |
152 | 8e1c85e3 | bellard | JCC_BE, |
153 | 8e1c85e3 | bellard | JCC_S, |
154 | 8e1c85e3 | bellard | JCC_P, |
155 | 8e1c85e3 | bellard | JCC_L, |
156 | 8e1c85e3 | bellard | JCC_LE, |
157 | 8e1c85e3 | bellard | }; |
158 | 8e1c85e3 | bellard | |
159 | 2c0262af | bellard | /* operand size */
|
160 | 2c0262af | bellard | enum {
|
161 | 2c0262af | bellard | OT_BYTE = 0,
|
162 | 2c0262af | bellard | OT_WORD, |
163 | 5fafdf24 | ths | OT_LONG, |
164 | 2c0262af | bellard | OT_QUAD, |
165 | 2c0262af | bellard | }; |
166 | 2c0262af | bellard | |
167 | 2c0262af | bellard | enum {
|
168 | 2c0262af | bellard | /* I386 int registers */
|
169 | 2c0262af | bellard | OR_EAX, /* MUST be even numbered */
|
170 | 2c0262af | bellard | OR_ECX, |
171 | 2c0262af | bellard | OR_EDX, |
172 | 2c0262af | bellard | OR_EBX, |
173 | 2c0262af | bellard | OR_ESP, |
174 | 2c0262af | bellard | OR_EBP, |
175 | 2c0262af | bellard | OR_ESI, |
176 | 2c0262af | bellard | OR_EDI, |
177 | 14ce26e7 | bellard | |
178 | 14ce26e7 | bellard | OR_TMP0 = 16, /* temporary operand register */ |
179 | 2c0262af | bellard | OR_TMP1, |
180 | 2c0262af | bellard | OR_A0, /* temporary register used when doing address evaluation */
|
181 | 2c0262af | bellard | }; |
182 | 2c0262af | bellard | |
183 | 57fec1fe | bellard | static inline void gen_op_movl_T0_0(void) |
184 | 57fec1fe | bellard | { |
185 | 57fec1fe | bellard | tcg_gen_movi_tl(cpu_T[0], 0); |
186 | 57fec1fe | bellard | } |
187 | 57fec1fe | bellard | |
188 | 57fec1fe | bellard | static inline void gen_op_movl_T0_im(int32_t val) |
189 | 57fec1fe | bellard | { |
190 | 57fec1fe | bellard | tcg_gen_movi_tl(cpu_T[0], val);
|
191 | 57fec1fe | bellard | } |
192 | 57fec1fe | bellard | |
193 | 57fec1fe | bellard | static inline void gen_op_movl_T0_imu(uint32_t val) |
194 | 57fec1fe | bellard | { |
195 | 57fec1fe | bellard | tcg_gen_movi_tl(cpu_T[0], val);
|
196 | 57fec1fe | bellard | } |
197 | 57fec1fe | bellard | |
198 | 57fec1fe | bellard | static inline void gen_op_movl_T1_im(int32_t val) |
199 | 57fec1fe | bellard | { |
200 | 57fec1fe | bellard | tcg_gen_movi_tl(cpu_T[1], val);
|
201 | 57fec1fe | bellard | } |
202 | 57fec1fe | bellard | |
203 | 57fec1fe | bellard | static inline void gen_op_movl_T1_imu(uint32_t val) |
204 | 57fec1fe | bellard | { |
205 | 57fec1fe | bellard | tcg_gen_movi_tl(cpu_T[1], val);
|
206 | 57fec1fe | bellard | } |
207 | 57fec1fe | bellard | |
208 | 57fec1fe | bellard | static inline void gen_op_movl_A0_im(uint32_t val) |
209 | 57fec1fe | bellard | { |
210 | 57fec1fe | bellard | tcg_gen_movi_tl(cpu_A0, val); |
211 | 57fec1fe | bellard | } |
212 | 57fec1fe | bellard | |
213 | 57fec1fe | bellard | #ifdef TARGET_X86_64
|
214 | 57fec1fe | bellard | static inline void gen_op_movq_A0_im(int64_t val) |
215 | 57fec1fe | bellard | { |
216 | 57fec1fe | bellard | tcg_gen_movi_tl(cpu_A0, val); |
217 | 57fec1fe | bellard | } |
218 | 57fec1fe | bellard | #endif
|
219 | 57fec1fe | bellard | |
220 | 57fec1fe | bellard | static inline void gen_movtl_T0_im(target_ulong val) |
221 | 57fec1fe | bellard | { |
222 | 57fec1fe | bellard | tcg_gen_movi_tl(cpu_T[0], val);
|
223 | 57fec1fe | bellard | } |
224 | 57fec1fe | bellard | |
225 | 57fec1fe | bellard | static inline void gen_movtl_T1_im(target_ulong val) |
226 | 57fec1fe | bellard | { |
227 | 57fec1fe | bellard | tcg_gen_movi_tl(cpu_T[1], val);
|
228 | 57fec1fe | bellard | } |
229 | 57fec1fe | bellard | |
230 | 57fec1fe | bellard | static inline void gen_op_andl_T0_ffff(void) |
231 | 57fec1fe | bellard | { |
232 | 57fec1fe | bellard | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0xffff); |
233 | 57fec1fe | bellard | } |
234 | 57fec1fe | bellard | |
235 | 57fec1fe | bellard | static inline void gen_op_andl_T0_im(uint32_t val) |
236 | 57fec1fe | bellard | { |
237 | 57fec1fe | bellard | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], val); |
238 | 57fec1fe | bellard | } |
239 | 57fec1fe | bellard | |
240 | 57fec1fe | bellard | static inline void gen_op_movl_T0_T1(void) |
241 | 57fec1fe | bellard | { |
242 | 57fec1fe | bellard | tcg_gen_mov_tl(cpu_T[0], cpu_T[1]); |
243 | 57fec1fe | bellard | } |
244 | 57fec1fe | bellard | |
245 | 57fec1fe | bellard | static inline void gen_op_andl_A0_ffff(void) |
246 | 57fec1fe | bellard | { |
247 | 57fec1fe | bellard | tcg_gen_andi_tl(cpu_A0, cpu_A0, 0xffff);
|
248 | 57fec1fe | bellard | } |
249 | 57fec1fe | bellard | |
250 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
251 | 14ce26e7 | bellard | |
252 | 14ce26e7 | bellard | #define NB_OP_SIZES 4 |
253 | 14ce26e7 | bellard | |
254 | 14ce26e7 | bellard | #else /* !TARGET_X86_64 */ |
255 | 14ce26e7 | bellard | |
256 | 14ce26e7 | bellard | #define NB_OP_SIZES 3 |
257 | 14ce26e7 | bellard | |
258 | 14ce26e7 | bellard | #endif /* !TARGET_X86_64 */ |
259 | 14ce26e7 | bellard | |
260 | 57fec1fe | bellard | #if defined(WORDS_BIGENDIAN)
|
261 | 57fec1fe | bellard | #define REG_B_OFFSET (sizeof(target_ulong) - 1) |
262 | 57fec1fe | bellard | #define REG_H_OFFSET (sizeof(target_ulong) - 2) |
263 | 57fec1fe | bellard | #define REG_W_OFFSET (sizeof(target_ulong) - 2) |
264 | 57fec1fe | bellard | #define REG_L_OFFSET (sizeof(target_ulong) - 4) |
265 | 57fec1fe | bellard | #define REG_LH_OFFSET (sizeof(target_ulong) - 8) |
266 | 14ce26e7 | bellard | #else
|
267 | 57fec1fe | bellard | #define REG_B_OFFSET 0 |
268 | 57fec1fe | bellard | #define REG_H_OFFSET 1 |
269 | 57fec1fe | bellard | #define REG_W_OFFSET 0 |
270 | 57fec1fe | bellard | #define REG_L_OFFSET 0 |
271 | 57fec1fe | bellard | #define REG_LH_OFFSET 4 |
272 | 14ce26e7 | bellard | #endif
|
273 | 57fec1fe | bellard | |
274 | 1e4840bf | bellard | static inline void gen_op_mov_reg_v(int ot, int reg, TCGv t0) |
275 | 57fec1fe | bellard | { |
276 | 57fec1fe | bellard | switch(ot) {
|
277 | 57fec1fe | bellard | case OT_BYTE:
|
278 | 57fec1fe | bellard | if (reg < 4 X86_64_DEF( || reg >= 8 || x86_64_hregs)) { |
279 | 1e4840bf | bellard | tcg_gen_st8_tl(t0, cpu_env, offsetof(CPUState, regs[reg]) + REG_B_OFFSET); |
280 | 57fec1fe | bellard | } else {
|
281 | 1e4840bf | bellard | tcg_gen_st8_tl(t0, cpu_env, offsetof(CPUState, regs[reg - 4]) + REG_H_OFFSET);
|
282 | 57fec1fe | bellard | } |
283 | 57fec1fe | bellard | break;
|
284 | 57fec1fe | bellard | case OT_WORD:
|
285 | 1e4840bf | bellard | tcg_gen_st16_tl(t0, cpu_env, offsetof(CPUState, regs[reg]) + REG_W_OFFSET); |
286 | 57fec1fe | bellard | break;
|
287 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
288 | 57fec1fe | bellard | case OT_LONG:
|
289 | 1e4840bf | bellard | tcg_gen_st32_tl(t0, cpu_env, offsetof(CPUState, regs[reg]) + REG_L_OFFSET); |
290 | 57fec1fe | bellard | /* high part of register set to zero */
|
291 | 57fec1fe | bellard | tcg_gen_movi_tl(cpu_tmp0, 0);
|
292 | 57fec1fe | bellard | tcg_gen_st32_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg]) + REG_LH_OFFSET); |
293 | 57fec1fe | bellard | break;
|
294 | 57fec1fe | bellard | default:
|
295 | 57fec1fe | bellard | case OT_QUAD:
|
296 | 1e4840bf | bellard | tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, regs[reg])); |
297 | 57fec1fe | bellard | break;
|
298 | 57fec1fe | bellard | #else
|
299 | 57fec1fe | bellard | default:
|
300 | 57fec1fe | bellard | case OT_LONG:
|
301 | 1e4840bf | bellard | tcg_gen_st32_tl(t0, cpu_env, offsetof(CPUState, regs[reg]) + REG_L_OFFSET); |
302 | 57fec1fe | bellard | break;
|
303 | 14ce26e7 | bellard | #endif
|
304 | 57fec1fe | bellard | } |
305 | 57fec1fe | bellard | } |
306 | 2c0262af | bellard | |
307 | 57fec1fe | bellard | static inline void gen_op_mov_reg_T0(int ot, int reg) |
308 | 57fec1fe | bellard | { |
309 | 1e4840bf | bellard | gen_op_mov_reg_v(ot, reg, cpu_T[0]);
|
310 | 57fec1fe | bellard | } |
311 | 57fec1fe | bellard | |
312 | 57fec1fe | bellard | static inline void gen_op_mov_reg_T1(int ot, int reg) |
313 | 57fec1fe | bellard | { |
314 | 1e4840bf | bellard | gen_op_mov_reg_v(ot, reg, cpu_T[1]);
|
315 | 57fec1fe | bellard | } |
316 | 57fec1fe | bellard | |
317 | 57fec1fe | bellard | static inline void gen_op_mov_reg_A0(int size, int reg) |
318 | 57fec1fe | bellard | { |
319 | 57fec1fe | bellard | switch(size) {
|
320 | 57fec1fe | bellard | case 0: |
321 | 57fec1fe | bellard | tcg_gen_st16_tl(cpu_A0, cpu_env, offsetof(CPUState, regs[reg]) + REG_W_OFFSET); |
322 | 57fec1fe | bellard | break;
|
323 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
324 | 57fec1fe | bellard | case 1: |
325 | 57fec1fe | bellard | tcg_gen_st32_tl(cpu_A0, cpu_env, offsetof(CPUState, regs[reg]) + REG_L_OFFSET); |
326 | 57fec1fe | bellard | /* high part of register set to zero */
|
327 | 57fec1fe | bellard | tcg_gen_movi_tl(cpu_tmp0, 0);
|
328 | 57fec1fe | bellard | tcg_gen_st32_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg]) + REG_LH_OFFSET); |
329 | 57fec1fe | bellard | break;
|
330 | 57fec1fe | bellard | default:
|
331 | 57fec1fe | bellard | case 2: |
332 | 57fec1fe | bellard | tcg_gen_st_tl(cpu_A0, cpu_env, offsetof(CPUState, regs[reg])); |
333 | 57fec1fe | bellard | break;
|
334 | 14ce26e7 | bellard | #else
|
335 | 57fec1fe | bellard | default:
|
336 | 57fec1fe | bellard | case 1: |
337 | 57fec1fe | bellard | tcg_gen_st32_tl(cpu_A0, cpu_env, offsetof(CPUState, regs[reg]) + REG_L_OFFSET); |
338 | 57fec1fe | bellard | break;
|
339 | 14ce26e7 | bellard | #endif
|
340 | 57fec1fe | bellard | } |
341 | 57fec1fe | bellard | } |
342 | 57fec1fe | bellard | |
343 | 1e4840bf | bellard | static inline void gen_op_mov_v_reg(int ot, TCGv t0, int reg) |
344 | 57fec1fe | bellard | { |
345 | 57fec1fe | bellard | switch(ot) {
|
346 | 57fec1fe | bellard | case OT_BYTE:
|
347 | 57fec1fe | bellard | if (reg < 4 X86_64_DEF( || reg >= 8 || x86_64_hregs)) { |
348 | 57fec1fe | bellard | goto std_case;
|
349 | 57fec1fe | bellard | } else {
|
350 | 1e4840bf | bellard | tcg_gen_ld8u_tl(t0, cpu_env, offsetof(CPUState, regs[reg - 4]) + REG_H_OFFSET);
|
351 | 57fec1fe | bellard | } |
352 | 57fec1fe | bellard | break;
|
353 | 57fec1fe | bellard | default:
|
354 | 57fec1fe | bellard | std_case:
|
355 | 1e4840bf | bellard | tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, regs[reg])); |
356 | 57fec1fe | bellard | break;
|
357 | 57fec1fe | bellard | } |
358 | 57fec1fe | bellard | } |
359 | 57fec1fe | bellard | |
360 | 1e4840bf | bellard | static inline void gen_op_mov_TN_reg(int ot, int t_index, int reg) |
361 | 1e4840bf | bellard | { |
362 | 1e4840bf | bellard | gen_op_mov_v_reg(ot, cpu_T[t_index], reg); |
363 | 1e4840bf | bellard | } |
364 | 1e4840bf | bellard | |
365 | 57fec1fe | bellard | static inline void gen_op_movl_A0_reg(int reg) |
366 | 57fec1fe | bellard | { |
367 | 57fec1fe | bellard | tcg_gen_ld32u_tl(cpu_A0, cpu_env, offsetof(CPUState, regs[reg]) + REG_L_OFFSET); |
368 | 57fec1fe | bellard | } |
369 | 57fec1fe | bellard | |
370 | 57fec1fe | bellard | static inline void gen_op_addl_A0_im(int32_t val) |
371 | 57fec1fe | bellard | { |
372 | 57fec1fe | bellard | tcg_gen_addi_tl(cpu_A0, cpu_A0, val); |
373 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
374 | 57fec1fe | bellard | tcg_gen_andi_tl(cpu_A0, cpu_A0, 0xffffffff);
|
375 | 14ce26e7 | bellard | #endif
|
376 | 57fec1fe | bellard | } |
377 | 2c0262af | bellard | |
378 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
379 | 57fec1fe | bellard | static inline void gen_op_addq_A0_im(int64_t val) |
380 | 57fec1fe | bellard | { |
381 | 57fec1fe | bellard | tcg_gen_addi_tl(cpu_A0, cpu_A0, val); |
382 | 57fec1fe | bellard | } |
383 | 14ce26e7 | bellard | #endif
|
384 | 57fec1fe | bellard | |
385 | 57fec1fe | bellard | static void gen_add_A0_im(DisasContext *s, int val) |
386 | 57fec1fe | bellard | { |
387 | 57fec1fe | bellard | #ifdef TARGET_X86_64
|
388 | 57fec1fe | bellard | if (CODE64(s))
|
389 | 57fec1fe | bellard | gen_op_addq_A0_im(val); |
390 | 57fec1fe | bellard | else
|
391 | 57fec1fe | bellard | #endif
|
392 | 57fec1fe | bellard | gen_op_addl_A0_im(val); |
393 | 57fec1fe | bellard | } |
394 | 2c0262af | bellard | |
395 | 57fec1fe | bellard | static inline void gen_op_addl_T0_T1(void) |
396 | 2c0262af | bellard | { |
397 | 57fec1fe | bellard | tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
398 | 57fec1fe | bellard | } |
399 | 57fec1fe | bellard | |
400 | 57fec1fe | bellard | static inline void gen_op_jmp_T0(void) |
401 | 57fec1fe | bellard | { |
402 | 57fec1fe | bellard | tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUState, eip));
|
403 | 57fec1fe | bellard | } |
404 | 57fec1fe | bellard | |
405 | 6e0d8677 | bellard | static inline void gen_op_add_reg_im(int size, int reg, int32_t val) |
406 | 57fec1fe | bellard | { |
407 | 6e0d8677 | bellard | switch(size) {
|
408 | 6e0d8677 | bellard | case 0: |
409 | 6e0d8677 | bellard | tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg])); |
410 | 6e0d8677 | bellard | tcg_gen_addi_tl(cpu_tmp0, cpu_tmp0, val); |
411 | 6e0d8677 | bellard | tcg_gen_st16_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg]) + REG_W_OFFSET); |
412 | 6e0d8677 | bellard | break;
|
413 | 6e0d8677 | bellard | case 1: |
414 | 6e0d8677 | bellard | tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg])); |
415 | 6e0d8677 | bellard | tcg_gen_addi_tl(cpu_tmp0, cpu_tmp0, val); |
416 | 6e0d8677 | bellard | #ifdef TARGET_X86_64
|
417 | 6e0d8677 | bellard | tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffff);
|
418 | 6e0d8677 | bellard | #endif
|
419 | 6e0d8677 | bellard | tcg_gen_st_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg])); |
420 | 6e0d8677 | bellard | break;
|
421 | 6e0d8677 | bellard | #ifdef TARGET_X86_64
|
422 | 6e0d8677 | bellard | case 2: |
423 | 6e0d8677 | bellard | tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg])); |
424 | 6e0d8677 | bellard | tcg_gen_addi_tl(cpu_tmp0, cpu_tmp0, val); |
425 | 6e0d8677 | bellard | tcg_gen_st_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg])); |
426 | 6e0d8677 | bellard | break;
|
427 | 6e0d8677 | bellard | #endif
|
428 | 6e0d8677 | bellard | } |
429 | 57fec1fe | bellard | } |
430 | 57fec1fe | bellard | |
431 | 6e0d8677 | bellard | static inline void gen_op_add_reg_T0(int size, int reg) |
432 | 57fec1fe | bellard | { |
433 | 6e0d8677 | bellard | switch(size) {
|
434 | 6e0d8677 | bellard | case 0: |
435 | 6e0d8677 | bellard | tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg])); |
436 | 6e0d8677 | bellard | tcg_gen_add_tl(cpu_tmp0, cpu_tmp0, cpu_T[0]);
|
437 | 6e0d8677 | bellard | tcg_gen_st16_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg]) + REG_W_OFFSET); |
438 | 6e0d8677 | bellard | break;
|
439 | 6e0d8677 | bellard | case 1: |
440 | 6e0d8677 | bellard | tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg])); |
441 | 6e0d8677 | bellard | tcg_gen_add_tl(cpu_tmp0, cpu_tmp0, cpu_T[0]);
|
442 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
443 | 6e0d8677 | bellard | tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffff);
|
444 | 14ce26e7 | bellard | #endif
|
445 | 6e0d8677 | bellard | tcg_gen_st_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg])); |
446 | 6e0d8677 | bellard | break;
|
447 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
448 | 6e0d8677 | bellard | case 2: |
449 | 6e0d8677 | bellard | tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg])); |
450 | 6e0d8677 | bellard | tcg_gen_add_tl(cpu_tmp0, cpu_tmp0, cpu_T[0]);
|
451 | 6e0d8677 | bellard | tcg_gen_st_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg])); |
452 | 6e0d8677 | bellard | break;
|
453 | 14ce26e7 | bellard | #endif
|
454 | 6e0d8677 | bellard | } |
455 | 6e0d8677 | bellard | } |
456 | 57fec1fe | bellard | |
457 | 57fec1fe | bellard | static inline void gen_op_set_cc_op(int32_t val) |
458 | 57fec1fe | bellard | { |
459 | b6abf97d | bellard | tcg_gen_movi_i32(cpu_cc_op, val); |
460 | 57fec1fe | bellard | } |
461 | 57fec1fe | bellard | |
462 | 57fec1fe | bellard | static inline void gen_op_addl_A0_reg_sN(int shift, int reg) |
463 | 57fec1fe | bellard | { |
464 | 57fec1fe | bellard | tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg])); |
465 | 57fec1fe | bellard | if (shift != 0) |
466 | 57fec1fe | bellard | tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, shift); |
467 | 57fec1fe | bellard | tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); |
468 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
469 | 57fec1fe | bellard | tcg_gen_andi_tl(cpu_A0, cpu_A0, 0xffffffff);
|
470 | 14ce26e7 | bellard | #endif
|
471 | 57fec1fe | bellard | } |
472 | 2c0262af | bellard | |
473 | 57fec1fe | bellard | static inline void gen_op_movl_A0_seg(int reg) |
474 | 57fec1fe | bellard | { |
475 | 57fec1fe | bellard | tcg_gen_ld32u_tl(cpu_A0, cpu_env, offsetof(CPUState, segs[reg].base) + REG_L_OFFSET); |
476 | 57fec1fe | bellard | } |
477 | 2c0262af | bellard | |
478 | 57fec1fe | bellard | static inline void gen_op_addl_A0_seg(int reg) |
479 | 57fec1fe | bellard | { |
480 | 57fec1fe | bellard | tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUState, segs[reg].base)); |
481 | 57fec1fe | bellard | tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); |
482 | 57fec1fe | bellard | #ifdef TARGET_X86_64
|
483 | 57fec1fe | bellard | tcg_gen_andi_tl(cpu_A0, cpu_A0, 0xffffffff);
|
484 | 57fec1fe | bellard | #endif
|
485 | 57fec1fe | bellard | } |
486 | 2c0262af | bellard | |
487 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
488 | 57fec1fe | bellard | static inline void gen_op_movq_A0_seg(int reg) |
489 | 57fec1fe | bellard | { |
490 | 57fec1fe | bellard | tcg_gen_ld_tl(cpu_A0, cpu_env, offsetof(CPUState, segs[reg].base)); |
491 | 57fec1fe | bellard | } |
492 | 14ce26e7 | bellard | |
493 | 57fec1fe | bellard | static inline void gen_op_addq_A0_seg(int reg) |
494 | 57fec1fe | bellard | { |
495 | 57fec1fe | bellard | tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUState, segs[reg].base)); |
496 | 57fec1fe | bellard | tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); |
497 | 57fec1fe | bellard | } |
498 | 57fec1fe | bellard | |
499 | 57fec1fe | bellard | static inline void gen_op_movq_A0_reg(int reg) |
500 | 57fec1fe | bellard | { |
501 | 57fec1fe | bellard | tcg_gen_ld_tl(cpu_A0, cpu_env, offsetof(CPUState, regs[reg])); |
502 | 57fec1fe | bellard | } |
503 | 57fec1fe | bellard | |
504 | 57fec1fe | bellard | static inline void gen_op_addq_A0_reg_sN(int shift, int reg) |
505 | 57fec1fe | bellard | { |
506 | 57fec1fe | bellard | tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg])); |
507 | 57fec1fe | bellard | if (shift != 0) |
508 | 57fec1fe | bellard | tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, shift); |
509 | 57fec1fe | bellard | tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); |
510 | 57fec1fe | bellard | } |
511 | 14ce26e7 | bellard | #endif
|
512 | 14ce26e7 | bellard | |
513 | 57fec1fe | bellard | static inline void gen_op_lds_T0_A0(int idx) |
514 | 57fec1fe | bellard | { |
515 | 57fec1fe | bellard | int mem_index = (idx >> 2) - 1; |
516 | 57fec1fe | bellard | switch(idx & 3) { |
517 | 57fec1fe | bellard | case 0: |
518 | 57fec1fe | bellard | tcg_gen_qemu_ld8s(cpu_T[0], cpu_A0, mem_index);
|
519 | 57fec1fe | bellard | break;
|
520 | 57fec1fe | bellard | case 1: |
521 | 57fec1fe | bellard | tcg_gen_qemu_ld16s(cpu_T[0], cpu_A0, mem_index);
|
522 | 57fec1fe | bellard | break;
|
523 | 57fec1fe | bellard | default:
|
524 | 57fec1fe | bellard | case 2: |
525 | 57fec1fe | bellard | tcg_gen_qemu_ld32s(cpu_T[0], cpu_A0, mem_index);
|
526 | 57fec1fe | bellard | break;
|
527 | 57fec1fe | bellard | } |
528 | 57fec1fe | bellard | } |
529 | 2c0262af | bellard | |
530 | 1e4840bf | bellard | static inline void gen_op_ld_v(int idx, TCGv t0, TCGv a0) |
531 | 57fec1fe | bellard | { |
532 | 57fec1fe | bellard | int mem_index = (idx >> 2) - 1; |
533 | 57fec1fe | bellard | switch(idx & 3) { |
534 | 57fec1fe | bellard | case 0: |
535 | 1e4840bf | bellard | tcg_gen_qemu_ld8u(t0, a0, mem_index); |
536 | 57fec1fe | bellard | break;
|
537 | 57fec1fe | bellard | case 1: |
538 | 1e4840bf | bellard | tcg_gen_qemu_ld16u(t0, a0, mem_index); |
539 | 57fec1fe | bellard | break;
|
540 | 57fec1fe | bellard | case 2: |
541 | 1e4840bf | bellard | tcg_gen_qemu_ld32u(t0, a0, mem_index); |
542 | 57fec1fe | bellard | break;
|
543 | 57fec1fe | bellard | default:
|
544 | 57fec1fe | bellard | case 3: |
545 | a7812ae4 | pbrook | /* Should never happen on 32-bit targets. */
|
546 | a7812ae4 | pbrook | #ifdef TARGET_X86_64
|
547 | 1e4840bf | bellard | tcg_gen_qemu_ld64(t0, a0, mem_index); |
548 | a7812ae4 | pbrook | #endif
|
549 | 57fec1fe | bellard | break;
|
550 | 57fec1fe | bellard | } |
551 | 57fec1fe | bellard | } |
552 | 2c0262af | bellard | |
553 | 1e4840bf | bellard | /* XXX: always use ldu or lds */
|
554 | 1e4840bf | bellard | static inline void gen_op_ld_T0_A0(int idx) |
555 | 1e4840bf | bellard | { |
556 | 1e4840bf | bellard | gen_op_ld_v(idx, cpu_T[0], cpu_A0);
|
557 | 1e4840bf | bellard | } |
558 | 1e4840bf | bellard | |
559 | 57fec1fe | bellard | static inline void gen_op_ldu_T0_A0(int idx) |
560 | 57fec1fe | bellard | { |
561 | 1e4840bf | bellard | gen_op_ld_v(idx, cpu_T[0], cpu_A0);
|
562 | 57fec1fe | bellard | } |
563 | 2c0262af | bellard | |
564 | 57fec1fe | bellard | static inline void gen_op_ld_T1_A0(int idx) |
565 | 57fec1fe | bellard | { |
566 | 1e4840bf | bellard | gen_op_ld_v(idx, cpu_T[1], cpu_A0);
|
567 | 1e4840bf | bellard | } |
568 | 1e4840bf | bellard | |
569 | 1e4840bf | bellard | static inline void gen_op_st_v(int idx, TCGv t0, TCGv a0) |
570 | 1e4840bf | bellard | { |
571 | 57fec1fe | bellard | int mem_index = (idx >> 2) - 1; |
572 | 57fec1fe | bellard | switch(idx & 3) { |
573 | 57fec1fe | bellard | case 0: |
574 | 1e4840bf | bellard | tcg_gen_qemu_st8(t0, a0, mem_index); |
575 | 57fec1fe | bellard | break;
|
576 | 57fec1fe | bellard | case 1: |
577 | 1e4840bf | bellard | tcg_gen_qemu_st16(t0, a0, mem_index); |
578 | 57fec1fe | bellard | break;
|
579 | 57fec1fe | bellard | case 2: |
580 | 1e4840bf | bellard | tcg_gen_qemu_st32(t0, a0, mem_index); |
581 | 57fec1fe | bellard | break;
|
582 | 57fec1fe | bellard | default:
|
583 | 57fec1fe | bellard | case 3: |
584 | a7812ae4 | pbrook | /* Should never happen on 32-bit targets. */
|
585 | a7812ae4 | pbrook | #ifdef TARGET_X86_64
|
586 | 1e4840bf | bellard | tcg_gen_qemu_st64(t0, a0, mem_index); |
587 | a7812ae4 | pbrook | #endif
|
588 | 57fec1fe | bellard | break;
|
589 | 57fec1fe | bellard | } |
590 | 57fec1fe | bellard | } |
591 | 4f31916f | bellard | |
592 | 57fec1fe | bellard | static inline void gen_op_st_T0_A0(int idx) |
593 | 57fec1fe | bellard | { |
594 | 1e4840bf | bellard | gen_op_st_v(idx, cpu_T[0], cpu_A0);
|
595 | 57fec1fe | bellard | } |
596 | 4f31916f | bellard | |
597 | 57fec1fe | bellard | static inline void gen_op_st_T1_A0(int idx) |
598 | 57fec1fe | bellard | { |
599 | 1e4840bf | bellard | gen_op_st_v(idx, cpu_T[1], cpu_A0);
|
600 | 57fec1fe | bellard | } |
601 | 4f31916f | bellard | |
602 | 14ce26e7 | bellard | static inline void gen_jmp_im(target_ulong pc) |
603 | 14ce26e7 | bellard | { |
604 | 57fec1fe | bellard | tcg_gen_movi_tl(cpu_tmp0, pc); |
605 | 57fec1fe | bellard | tcg_gen_st_tl(cpu_tmp0, cpu_env, offsetof(CPUState, eip)); |
606 | 14ce26e7 | bellard | } |
607 | 14ce26e7 | bellard | |
608 | 2c0262af | bellard | static inline void gen_string_movl_A0_ESI(DisasContext *s) |
609 | 2c0262af | bellard | { |
610 | 2c0262af | bellard | int override;
|
611 | 2c0262af | bellard | |
612 | 2c0262af | bellard | override = s->override; |
613 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
614 | 14ce26e7 | bellard | if (s->aflag == 2) { |
615 | 14ce26e7 | bellard | if (override >= 0) { |
616 | 57fec1fe | bellard | gen_op_movq_A0_seg(override); |
617 | 57fec1fe | bellard | gen_op_addq_A0_reg_sN(0, R_ESI);
|
618 | 14ce26e7 | bellard | } else {
|
619 | 57fec1fe | bellard | gen_op_movq_A0_reg(R_ESI); |
620 | 14ce26e7 | bellard | } |
621 | 14ce26e7 | bellard | } else
|
622 | 14ce26e7 | bellard | #endif
|
623 | 2c0262af | bellard | if (s->aflag) {
|
624 | 2c0262af | bellard | /* 32 bit address */
|
625 | 2c0262af | bellard | if (s->addseg && override < 0) |
626 | 2c0262af | bellard | override = R_DS; |
627 | 2c0262af | bellard | if (override >= 0) { |
628 | 57fec1fe | bellard | gen_op_movl_A0_seg(override); |
629 | 57fec1fe | bellard | gen_op_addl_A0_reg_sN(0, R_ESI);
|
630 | 2c0262af | bellard | } else {
|
631 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_ESI); |
632 | 2c0262af | bellard | } |
633 | 2c0262af | bellard | } else {
|
634 | 2c0262af | bellard | /* 16 address, always override */
|
635 | 2c0262af | bellard | if (override < 0) |
636 | 2c0262af | bellard | override = R_DS; |
637 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_ESI); |
638 | 2c0262af | bellard | gen_op_andl_A0_ffff(); |
639 | 57fec1fe | bellard | gen_op_addl_A0_seg(override); |
640 | 2c0262af | bellard | } |
641 | 2c0262af | bellard | } |
642 | 2c0262af | bellard | |
643 | 2c0262af | bellard | static inline void gen_string_movl_A0_EDI(DisasContext *s) |
644 | 2c0262af | bellard | { |
645 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
646 | 14ce26e7 | bellard | if (s->aflag == 2) { |
647 | 57fec1fe | bellard | gen_op_movq_A0_reg(R_EDI); |
648 | 14ce26e7 | bellard | } else
|
649 | 14ce26e7 | bellard | #endif
|
650 | 2c0262af | bellard | if (s->aflag) {
|
651 | 2c0262af | bellard | if (s->addseg) {
|
652 | 57fec1fe | bellard | gen_op_movl_A0_seg(R_ES); |
653 | 57fec1fe | bellard | gen_op_addl_A0_reg_sN(0, R_EDI);
|
654 | 2c0262af | bellard | } else {
|
655 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_EDI); |
656 | 2c0262af | bellard | } |
657 | 2c0262af | bellard | } else {
|
658 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_EDI); |
659 | 2c0262af | bellard | gen_op_andl_A0_ffff(); |
660 | 57fec1fe | bellard | gen_op_addl_A0_seg(R_ES); |
661 | 2c0262af | bellard | } |
662 | 2c0262af | bellard | } |
663 | 2c0262af | bellard | |
664 | 6e0d8677 | bellard | static inline void gen_op_movl_T0_Dshift(int ot) |
665 | 6e0d8677 | bellard | { |
666 | 6e0d8677 | bellard | tcg_gen_ld32s_tl(cpu_T[0], cpu_env, offsetof(CPUState, df));
|
667 | 6e0d8677 | bellard | tcg_gen_shli_tl(cpu_T[0], cpu_T[0], ot); |
668 | 2c0262af | bellard | }; |
669 | 2c0262af | bellard | |
670 | 6e0d8677 | bellard | static void gen_extu(int ot, TCGv reg) |
671 | 6e0d8677 | bellard | { |
672 | 6e0d8677 | bellard | switch(ot) {
|
673 | 6e0d8677 | bellard | case OT_BYTE:
|
674 | 6e0d8677 | bellard | tcg_gen_ext8u_tl(reg, reg); |
675 | 6e0d8677 | bellard | break;
|
676 | 6e0d8677 | bellard | case OT_WORD:
|
677 | 6e0d8677 | bellard | tcg_gen_ext16u_tl(reg, reg); |
678 | 6e0d8677 | bellard | break;
|
679 | 6e0d8677 | bellard | case OT_LONG:
|
680 | 6e0d8677 | bellard | tcg_gen_ext32u_tl(reg, reg); |
681 | 6e0d8677 | bellard | break;
|
682 | 6e0d8677 | bellard | default:
|
683 | 6e0d8677 | bellard | break;
|
684 | 6e0d8677 | bellard | } |
685 | 6e0d8677 | bellard | } |
686 | 3b46e624 | ths | |
687 | 6e0d8677 | bellard | static void gen_exts(int ot, TCGv reg) |
688 | 6e0d8677 | bellard | { |
689 | 6e0d8677 | bellard | switch(ot) {
|
690 | 6e0d8677 | bellard | case OT_BYTE:
|
691 | 6e0d8677 | bellard | tcg_gen_ext8s_tl(reg, reg); |
692 | 6e0d8677 | bellard | break;
|
693 | 6e0d8677 | bellard | case OT_WORD:
|
694 | 6e0d8677 | bellard | tcg_gen_ext16s_tl(reg, reg); |
695 | 6e0d8677 | bellard | break;
|
696 | 6e0d8677 | bellard | case OT_LONG:
|
697 | 6e0d8677 | bellard | tcg_gen_ext32s_tl(reg, reg); |
698 | 6e0d8677 | bellard | break;
|
699 | 6e0d8677 | bellard | default:
|
700 | 6e0d8677 | bellard | break;
|
701 | 6e0d8677 | bellard | } |
702 | 6e0d8677 | bellard | } |
703 | 2c0262af | bellard | |
704 | 6e0d8677 | bellard | static inline void gen_op_jnz_ecx(int size, int label1) |
705 | 6e0d8677 | bellard | { |
706 | 6e0d8677 | bellard | tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[R_ECX])); |
707 | 6e0d8677 | bellard | gen_extu(size + 1, cpu_tmp0);
|
708 | cb63669a | pbrook | tcg_gen_brcondi_tl(TCG_COND_NE, cpu_tmp0, 0, label1);
|
709 | 6e0d8677 | bellard | } |
710 | 6e0d8677 | bellard | |
711 | 6e0d8677 | bellard | static inline void gen_op_jz_ecx(int size, int label1) |
712 | 6e0d8677 | bellard | { |
713 | 6e0d8677 | bellard | tcg_gen_ld_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[R_ECX])); |
714 | 6e0d8677 | bellard | gen_extu(size + 1, cpu_tmp0);
|
715 | cb63669a | pbrook | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, label1);
|
716 | 6e0d8677 | bellard | } |
717 | 2c0262af | bellard | |
718 | a7812ae4 | pbrook | static void gen_helper_in_func(int ot, TCGv v, TCGv_i32 n) |
719 | a7812ae4 | pbrook | { |
720 | a7812ae4 | pbrook | switch (ot) {
|
721 | a7812ae4 | pbrook | case 0: gen_helper_inb(v, n); break; |
722 | a7812ae4 | pbrook | case 1: gen_helper_inw(v, n); break; |
723 | a7812ae4 | pbrook | case 2: gen_helper_inl(v, n); break; |
724 | a7812ae4 | pbrook | } |
725 | 2c0262af | bellard | |
726 | a7812ae4 | pbrook | } |
727 | 2c0262af | bellard | |
728 | a7812ae4 | pbrook | static void gen_helper_out_func(int ot, TCGv_i32 v, TCGv_i32 n) |
729 | a7812ae4 | pbrook | { |
730 | a7812ae4 | pbrook | switch (ot) {
|
731 | a7812ae4 | pbrook | case 0: gen_helper_outb(v, n); break; |
732 | a7812ae4 | pbrook | case 1: gen_helper_outw(v, n); break; |
733 | a7812ae4 | pbrook | case 2: gen_helper_outl(v, n); break; |
734 | a7812ae4 | pbrook | } |
735 | a7812ae4 | pbrook | |
736 | a7812ae4 | pbrook | } |
737 | f115e911 | bellard | |
738 | b8b6a50b | bellard | static void gen_check_io(DisasContext *s, int ot, target_ulong cur_eip, |
739 | b8b6a50b | bellard | uint32_t svm_flags) |
740 | f115e911 | bellard | { |
741 | b8b6a50b | bellard | int state_saved;
|
742 | b8b6a50b | bellard | target_ulong next_eip; |
743 | b8b6a50b | bellard | |
744 | b8b6a50b | bellard | state_saved = 0;
|
745 | f115e911 | bellard | if (s->pe && (s->cpl > s->iopl || s->vm86)) {
|
746 | f115e911 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
747 | f115e911 | bellard | gen_op_set_cc_op(s->cc_op); |
748 | 14ce26e7 | bellard | gen_jmp_im(cur_eip); |
749 | b8b6a50b | bellard | state_saved = 1;
|
750 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
751 | a7812ae4 | pbrook | switch (ot) {
|
752 | a7812ae4 | pbrook | case 0: gen_helper_check_iob(cpu_tmp2_i32); break; |
753 | a7812ae4 | pbrook | case 1: gen_helper_check_iow(cpu_tmp2_i32); break; |
754 | a7812ae4 | pbrook | case 2: gen_helper_check_iol(cpu_tmp2_i32); break; |
755 | a7812ae4 | pbrook | } |
756 | b8b6a50b | bellard | } |
757 | 872929aa | bellard | if(s->flags & HF_SVMI_MASK) {
|
758 | b8b6a50b | bellard | if (!state_saved) {
|
759 | b8b6a50b | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
760 | b8b6a50b | bellard | gen_op_set_cc_op(s->cc_op); |
761 | b8b6a50b | bellard | gen_jmp_im(cur_eip); |
762 | b8b6a50b | bellard | state_saved = 1;
|
763 | b8b6a50b | bellard | } |
764 | b8b6a50b | bellard | svm_flags |= (1 << (4 + ot)); |
765 | b8b6a50b | bellard | next_eip = s->pc - s->cs_base; |
766 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
767 | a7812ae4 | pbrook | gen_helper_svm_check_io(cpu_tmp2_i32, tcg_const_i32(svm_flags), |
768 | a7812ae4 | pbrook | tcg_const_i32(next_eip - cur_eip)); |
769 | f115e911 | bellard | } |
770 | f115e911 | bellard | } |
771 | f115e911 | bellard | |
772 | 2c0262af | bellard | static inline void gen_movs(DisasContext *s, int ot) |
773 | 2c0262af | bellard | { |
774 | 2c0262af | bellard | gen_string_movl_A0_ESI(s); |
775 | 57fec1fe | bellard | gen_op_ld_T0_A0(ot + s->mem_index); |
776 | 2c0262af | bellard | gen_string_movl_A0_EDI(s); |
777 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
778 | 6e0d8677 | bellard | gen_op_movl_T0_Dshift(ot); |
779 | 6e0d8677 | bellard | gen_op_add_reg_T0(s->aflag, R_ESI); |
780 | 6e0d8677 | bellard | gen_op_add_reg_T0(s->aflag, R_EDI); |
781 | 2c0262af | bellard | } |
782 | 2c0262af | bellard | |
783 | 2c0262af | bellard | static inline void gen_update_cc_op(DisasContext *s) |
784 | 2c0262af | bellard | { |
785 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC) {
|
786 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
787 | 2c0262af | bellard | s->cc_op = CC_OP_DYNAMIC; |
788 | 2c0262af | bellard | } |
789 | 2c0262af | bellard | } |
790 | 2c0262af | bellard | |
791 | b6abf97d | bellard | static void gen_op_update1_cc(void) |
792 | b6abf97d | bellard | { |
793 | b6abf97d | bellard | tcg_gen_discard_tl(cpu_cc_src); |
794 | b6abf97d | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
795 | b6abf97d | bellard | } |
796 | b6abf97d | bellard | |
797 | b6abf97d | bellard | static void gen_op_update2_cc(void) |
798 | b6abf97d | bellard | { |
799 | b6abf97d | bellard | tcg_gen_mov_tl(cpu_cc_src, cpu_T[1]);
|
800 | b6abf97d | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
801 | b6abf97d | bellard | } |
802 | b6abf97d | bellard | |
803 | b6abf97d | bellard | static inline void gen_op_cmpl_T0_T1_cc(void) |
804 | b6abf97d | bellard | { |
805 | b6abf97d | bellard | tcg_gen_mov_tl(cpu_cc_src, cpu_T[1]);
|
806 | b6abf97d | bellard | tcg_gen_sub_tl(cpu_cc_dst, cpu_T[0], cpu_T[1]); |
807 | b6abf97d | bellard | } |
808 | b6abf97d | bellard | |
809 | b6abf97d | bellard | static inline void gen_op_testl_T0_T1_cc(void) |
810 | b6abf97d | bellard | { |
811 | b6abf97d | bellard | tcg_gen_discard_tl(cpu_cc_src); |
812 | b6abf97d | bellard | tcg_gen_and_tl(cpu_cc_dst, cpu_T[0], cpu_T[1]); |
813 | b6abf97d | bellard | } |
814 | b6abf97d | bellard | |
815 | b6abf97d | bellard | static void gen_op_update_neg_cc(void) |
816 | b6abf97d | bellard | { |
817 | b6abf97d | bellard | tcg_gen_neg_tl(cpu_cc_src, cpu_T[0]);
|
818 | b6abf97d | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
819 | b6abf97d | bellard | } |
820 | b6abf97d | bellard | |
821 | 8e1c85e3 | bellard | /* compute eflags.C to reg */
|
822 | 8e1c85e3 | bellard | static void gen_compute_eflags_c(TCGv reg) |
823 | 8e1c85e3 | bellard | { |
824 | a7812ae4 | pbrook | gen_helper_cc_compute_c(cpu_tmp2_i32, cpu_cc_op); |
825 | 8e1c85e3 | bellard | tcg_gen_extu_i32_tl(reg, cpu_tmp2_i32); |
826 | 8e1c85e3 | bellard | } |
827 | 8e1c85e3 | bellard | |
828 | 8e1c85e3 | bellard | /* compute all eflags to cc_src */
|
829 | 8e1c85e3 | bellard | static void gen_compute_eflags(TCGv reg) |
830 | 8e1c85e3 | bellard | { |
831 | a7812ae4 | pbrook | gen_helper_cc_compute_all(cpu_tmp2_i32, cpu_cc_op); |
832 | 8e1c85e3 | bellard | tcg_gen_extu_i32_tl(reg, cpu_tmp2_i32); |
833 | 8e1c85e3 | bellard | } |
834 | 8e1c85e3 | bellard | |
835 | 1e4840bf | bellard | static inline void gen_setcc_slow_T0(DisasContext *s, int jcc_op) |
836 | 8e1c85e3 | bellard | { |
837 | 1e4840bf | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
838 | 1e4840bf | bellard | gen_op_set_cc_op(s->cc_op); |
839 | 1e4840bf | bellard | switch(jcc_op) {
|
840 | 8e1c85e3 | bellard | case JCC_O:
|
841 | 8e1c85e3 | bellard | gen_compute_eflags(cpu_T[0]);
|
842 | 8e1c85e3 | bellard | tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 11); |
843 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
844 | 8e1c85e3 | bellard | break;
|
845 | 8e1c85e3 | bellard | case JCC_B:
|
846 | 8e1c85e3 | bellard | gen_compute_eflags_c(cpu_T[0]);
|
847 | 8e1c85e3 | bellard | break;
|
848 | 8e1c85e3 | bellard | case JCC_Z:
|
849 | 8e1c85e3 | bellard | gen_compute_eflags(cpu_T[0]);
|
850 | 8e1c85e3 | bellard | tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 6); |
851 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
852 | 8e1c85e3 | bellard | break;
|
853 | 8e1c85e3 | bellard | case JCC_BE:
|
854 | 8e1c85e3 | bellard | gen_compute_eflags(cpu_tmp0); |
855 | 8e1c85e3 | bellard | tcg_gen_shri_tl(cpu_T[0], cpu_tmp0, 6); |
856 | 8e1c85e3 | bellard | tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_tmp0); |
857 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
858 | 8e1c85e3 | bellard | break;
|
859 | 8e1c85e3 | bellard | case JCC_S:
|
860 | 8e1c85e3 | bellard | gen_compute_eflags(cpu_T[0]);
|
861 | 8e1c85e3 | bellard | tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 7); |
862 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
863 | 8e1c85e3 | bellard | break;
|
864 | 8e1c85e3 | bellard | case JCC_P:
|
865 | 8e1c85e3 | bellard | gen_compute_eflags(cpu_T[0]);
|
866 | 8e1c85e3 | bellard | tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 2); |
867 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
868 | 8e1c85e3 | bellard | break;
|
869 | 8e1c85e3 | bellard | case JCC_L:
|
870 | 8e1c85e3 | bellard | gen_compute_eflags(cpu_tmp0); |
871 | 8e1c85e3 | bellard | tcg_gen_shri_tl(cpu_T[0], cpu_tmp0, 11); /* CC_O */ |
872 | 8e1c85e3 | bellard | tcg_gen_shri_tl(cpu_tmp0, cpu_tmp0, 7); /* CC_S */ |
873 | 8e1c85e3 | bellard | tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_tmp0); |
874 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
875 | 8e1c85e3 | bellard | break;
|
876 | 8e1c85e3 | bellard | default:
|
877 | 8e1c85e3 | bellard | case JCC_LE:
|
878 | 8e1c85e3 | bellard | gen_compute_eflags(cpu_tmp0); |
879 | 8e1c85e3 | bellard | tcg_gen_shri_tl(cpu_T[0], cpu_tmp0, 11); /* CC_O */ |
880 | 8e1c85e3 | bellard | tcg_gen_shri_tl(cpu_tmp4, cpu_tmp0, 7); /* CC_S */ |
881 | 8e1c85e3 | bellard | tcg_gen_shri_tl(cpu_tmp0, cpu_tmp0, 6); /* CC_Z */ |
882 | 8e1c85e3 | bellard | tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_tmp4); |
883 | 8e1c85e3 | bellard | tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_tmp0); |
884 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 1); |
885 | 8e1c85e3 | bellard | break;
|
886 | 8e1c85e3 | bellard | } |
887 | 8e1c85e3 | bellard | } |
888 | 8e1c85e3 | bellard | |
889 | 8e1c85e3 | bellard | /* return true if setcc_slow is not needed (WARNING: must be kept in
|
890 | 8e1c85e3 | bellard | sync with gen_jcc1) */
|
891 | 8e1c85e3 | bellard | static int is_fast_jcc_case(DisasContext *s, int b) |
892 | 8e1c85e3 | bellard | { |
893 | 8e1c85e3 | bellard | int jcc_op;
|
894 | 8e1c85e3 | bellard | jcc_op = (b >> 1) & 7; |
895 | 8e1c85e3 | bellard | switch(s->cc_op) {
|
896 | 8e1c85e3 | bellard | /* we optimize the cmp/jcc case */
|
897 | 8e1c85e3 | bellard | case CC_OP_SUBB:
|
898 | 8e1c85e3 | bellard | case CC_OP_SUBW:
|
899 | 8e1c85e3 | bellard | case CC_OP_SUBL:
|
900 | 8e1c85e3 | bellard | case CC_OP_SUBQ:
|
901 | 8e1c85e3 | bellard | if (jcc_op == JCC_O || jcc_op == JCC_P)
|
902 | 8e1c85e3 | bellard | goto slow_jcc;
|
903 | 8e1c85e3 | bellard | break;
|
904 | 8e1c85e3 | bellard | |
905 | 8e1c85e3 | bellard | /* some jumps are easy to compute */
|
906 | 8e1c85e3 | bellard | case CC_OP_ADDB:
|
907 | 8e1c85e3 | bellard | case CC_OP_ADDW:
|
908 | 8e1c85e3 | bellard | case CC_OP_ADDL:
|
909 | 8e1c85e3 | bellard | case CC_OP_ADDQ:
|
910 | 8e1c85e3 | bellard | |
911 | 8e1c85e3 | bellard | case CC_OP_LOGICB:
|
912 | 8e1c85e3 | bellard | case CC_OP_LOGICW:
|
913 | 8e1c85e3 | bellard | case CC_OP_LOGICL:
|
914 | 8e1c85e3 | bellard | case CC_OP_LOGICQ:
|
915 | 8e1c85e3 | bellard | |
916 | 8e1c85e3 | bellard | case CC_OP_INCB:
|
917 | 8e1c85e3 | bellard | case CC_OP_INCW:
|
918 | 8e1c85e3 | bellard | case CC_OP_INCL:
|
919 | 8e1c85e3 | bellard | case CC_OP_INCQ:
|
920 | 8e1c85e3 | bellard | |
921 | 8e1c85e3 | bellard | case CC_OP_DECB:
|
922 | 8e1c85e3 | bellard | case CC_OP_DECW:
|
923 | 8e1c85e3 | bellard | case CC_OP_DECL:
|
924 | 8e1c85e3 | bellard | case CC_OP_DECQ:
|
925 | 8e1c85e3 | bellard | |
926 | 8e1c85e3 | bellard | case CC_OP_SHLB:
|
927 | 8e1c85e3 | bellard | case CC_OP_SHLW:
|
928 | 8e1c85e3 | bellard | case CC_OP_SHLL:
|
929 | 8e1c85e3 | bellard | case CC_OP_SHLQ:
|
930 | 8e1c85e3 | bellard | if (jcc_op != JCC_Z && jcc_op != JCC_S)
|
931 | 8e1c85e3 | bellard | goto slow_jcc;
|
932 | 8e1c85e3 | bellard | break;
|
933 | 8e1c85e3 | bellard | default:
|
934 | 8e1c85e3 | bellard | slow_jcc:
|
935 | 8e1c85e3 | bellard | return 0; |
936 | 8e1c85e3 | bellard | } |
937 | 8e1c85e3 | bellard | return 1; |
938 | 8e1c85e3 | bellard | } |
939 | 8e1c85e3 | bellard | |
940 | 8e1c85e3 | bellard | /* generate a conditional jump to label 'l1' according to jump opcode
|
941 | 8e1c85e3 | bellard | value 'b'. In the fast case, T0 is guaranted not to be used. */
|
942 | 8e1c85e3 | bellard | static inline void gen_jcc1(DisasContext *s, int cc_op, int b, int l1) |
943 | 8e1c85e3 | bellard | { |
944 | 8e1c85e3 | bellard | int inv, jcc_op, size, cond;
|
945 | 8e1c85e3 | bellard | TCGv t0; |
946 | 8e1c85e3 | bellard | |
947 | 8e1c85e3 | bellard | inv = b & 1;
|
948 | 8e1c85e3 | bellard | jcc_op = (b >> 1) & 7; |
949 | 8e1c85e3 | bellard | |
950 | 8e1c85e3 | bellard | switch(cc_op) {
|
951 | 8e1c85e3 | bellard | /* we optimize the cmp/jcc case */
|
952 | 8e1c85e3 | bellard | case CC_OP_SUBB:
|
953 | 8e1c85e3 | bellard | case CC_OP_SUBW:
|
954 | 8e1c85e3 | bellard | case CC_OP_SUBL:
|
955 | 8e1c85e3 | bellard | case CC_OP_SUBQ:
|
956 | 8e1c85e3 | bellard | |
957 | 8e1c85e3 | bellard | size = cc_op - CC_OP_SUBB; |
958 | 8e1c85e3 | bellard | switch(jcc_op) {
|
959 | 8e1c85e3 | bellard | case JCC_Z:
|
960 | 8e1c85e3 | bellard | fast_jcc_z:
|
961 | 8e1c85e3 | bellard | switch(size) {
|
962 | 8e1c85e3 | bellard | case 0: |
963 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_tmp0, cpu_cc_dst, 0xff);
|
964 | 8e1c85e3 | bellard | t0 = cpu_tmp0; |
965 | 8e1c85e3 | bellard | break;
|
966 | 8e1c85e3 | bellard | case 1: |
967 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_tmp0, cpu_cc_dst, 0xffff);
|
968 | 8e1c85e3 | bellard | t0 = cpu_tmp0; |
969 | 8e1c85e3 | bellard | break;
|
970 | 8e1c85e3 | bellard | #ifdef TARGET_X86_64
|
971 | 8e1c85e3 | bellard | case 2: |
972 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_tmp0, cpu_cc_dst, 0xffffffff);
|
973 | 8e1c85e3 | bellard | t0 = cpu_tmp0; |
974 | 8e1c85e3 | bellard | break;
|
975 | 8e1c85e3 | bellard | #endif
|
976 | 8e1c85e3 | bellard | default:
|
977 | 8e1c85e3 | bellard | t0 = cpu_cc_dst; |
978 | 8e1c85e3 | bellard | break;
|
979 | 8e1c85e3 | bellard | } |
980 | cb63669a | pbrook | tcg_gen_brcondi_tl(inv ? TCG_COND_NE : TCG_COND_EQ, t0, 0, l1);
|
981 | 8e1c85e3 | bellard | break;
|
982 | 8e1c85e3 | bellard | case JCC_S:
|
983 | 8e1c85e3 | bellard | fast_jcc_s:
|
984 | 8e1c85e3 | bellard | switch(size) {
|
985 | 8e1c85e3 | bellard | case 0: |
986 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_tmp0, cpu_cc_dst, 0x80);
|
987 | cb63669a | pbrook | tcg_gen_brcondi_tl(inv ? TCG_COND_EQ : TCG_COND_NE, cpu_tmp0, |
988 | cb63669a | pbrook | 0, l1);
|
989 | 8e1c85e3 | bellard | break;
|
990 | 8e1c85e3 | bellard | case 1: |
991 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_tmp0, cpu_cc_dst, 0x8000);
|
992 | cb63669a | pbrook | tcg_gen_brcondi_tl(inv ? TCG_COND_EQ : TCG_COND_NE, cpu_tmp0, |
993 | cb63669a | pbrook | 0, l1);
|
994 | 8e1c85e3 | bellard | break;
|
995 | 8e1c85e3 | bellard | #ifdef TARGET_X86_64
|
996 | 8e1c85e3 | bellard | case 2: |
997 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_tmp0, cpu_cc_dst, 0x80000000);
|
998 | cb63669a | pbrook | tcg_gen_brcondi_tl(inv ? TCG_COND_EQ : TCG_COND_NE, cpu_tmp0, |
999 | cb63669a | pbrook | 0, l1);
|
1000 | 8e1c85e3 | bellard | break;
|
1001 | 8e1c85e3 | bellard | #endif
|
1002 | 8e1c85e3 | bellard | default:
|
1003 | cb63669a | pbrook | tcg_gen_brcondi_tl(inv ? TCG_COND_GE : TCG_COND_LT, cpu_cc_dst, |
1004 | cb63669a | pbrook | 0, l1);
|
1005 | 8e1c85e3 | bellard | break;
|
1006 | 8e1c85e3 | bellard | } |
1007 | 8e1c85e3 | bellard | break;
|
1008 | 8e1c85e3 | bellard | |
1009 | 8e1c85e3 | bellard | case JCC_B:
|
1010 | 8e1c85e3 | bellard | cond = inv ? TCG_COND_GEU : TCG_COND_LTU; |
1011 | 8e1c85e3 | bellard | goto fast_jcc_b;
|
1012 | 8e1c85e3 | bellard | case JCC_BE:
|
1013 | 8e1c85e3 | bellard | cond = inv ? TCG_COND_GTU : TCG_COND_LEU; |
1014 | 8e1c85e3 | bellard | fast_jcc_b:
|
1015 | 8e1c85e3 | bellard | tcg_gen_add_tl(cpu_tmp4, cpu_cc_dst, cpu_cc_src); |
1016 | 8e1c85e3 | bellard | switch(size) {
|
1017 | 8e1c85e3 | bellard | case 0: |
1018 | 8e1c85e3 | bellard | t0 = cpu_tmp0; |
1019 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_tmp4, cpu_tmp4, 0xff);
|
1020 | 8e1c85e3 | bellard | tcg_gen_andi_tl(t0, cpu_cc_src, 0xff);
|
1021 | 8e1c85e3 | bellard | break;
|
1022 | 8e1c85e3 | bellard | case 1: |
1023 | 8e1c85e3 | bellard | t0 = cpu_tmp0; |
1024 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_tmp4, cpu_tmp4, 0xffff);
|
1025 | 8e1c85e3 | bellard | tcg_gen_andi_tl(t0, cpu_cc_src, 0xffff);
|
1026 | 8e1c85e3 | bellard | break;
|
1027 | 8e1c85e3 | bellard | #ifdef TARGET_X86_64
|
1028 | 8e1c85e3 | bellard | case 2: |
1029 | 8e1c85e3 | bellard | t0 = cpu_tmp0; |
1030 | 8e1c85e3 | bellard | tcg_gen_andi_tl(cpu_tmp4, cpu_tmp4, 0xffffffff);
|
1031 | 8e1c85e3 | bellard | tcg_gen_andi_tl(t0, cpu_cc_src, 0xffffffff);
|
1032 | 8e1c85e3 | bellard | break;
|
1033 | 8e1c85e3 | bellard | #endif
|
1034 | 8e1c85e3 | bellard | default:
|
1035 | 8e1c85e3 | bellard | t0 = cpu_cc_src; |
1036 | 8e1c85e3 | bellard | break;
|
1037 | 8e1c85e3 | bellard | } |
1038 | 8e1c85e3 | bellard | tcg_gen_brcond_tl(cond, cpu_tmp4, t0, l1); |
1039 | 8e1c85e3 | bellard | break;
|
1040 | 8e1c85e3 | bellard | |
1041 | 8e1c85e3 | bellard | case JCC_L:
|
1042 | 8e1c85e3 | bellard | cond = inv ? TCG_COND_GE : TCG_COND_LT; |
1043 | 8e1c85e3 | bellard | goto fast_jcc_l;
|
1044 | 8e1c85e3 | bellard | case JCC_LE:
|
1045 | 8e1c85e3 | bellard | cond = inv ? TCG_COND_GT : TCG_COND_LE; |
1046 | 8e1c85e3 | bellard | fast_jcc_l:
|
1047 | 8e1c85e3 | bellard | tcg_gen_add_tl(cpu_tmp4, cpu_cc_dst, cpu_cc_src); |
1048 | 8e1c85e3 | bellard | switch(size) {
|
1049 | 8e1c85e3 | bellard | case 0: |
1050 | 8e1c85e3 | bellard | t0 = cpu_tmp0; |
1051 | 8e1c85e3 | bellard | tcg_gen_ext8s_tl(cpu_tmp4, cpu_tmp4); |
1052 | 8e1c85e3 | bellard | tcg_gen_ext8s_tl(t0, cpu_cc_src); |
1053 | 8e1c85e3 | bellard | break;
|
1054 | 8e1c85e3 | bellard | case 1: |
1055 | 8e1c85e3 | bellard | t0 = cpu_tmp0; |
1056 | 8e1c85e3 | bellard | tcg_gen_ext16s_tl(cpu_tmp4, cpu_tmp4); |
1057 | 8e1c85e3 | bellard | tcg_gen_ext16s_tl(t0, cpu_cc_src); |
1058 | 8e1c85e3 | bellard | break;
|
1059 | 8e1c85e3 | bellard | #ifdef TARGET_X86_64
|
1060 | 8e1c85e3 | bellard | case 2: |
1061 | 8e1c85e3 | bellard | t0 = cpu_tmp0; |
1062 | 8e1c85e3 | bellard | tcg_gen_ext32s_tl(cpu_tmp4, cpu_tmp4); |
1063 | 8e1c85e3 | bellard | tcg_gen_ext32s_tl(t0, cpu_cc_src); |
1064 | 8e1c85e3 | bellard | break;
|
1065 | 8e1c85e3 | bellard | #endif
|
1066 | 8e1c85e3 | bellard | default:
|
1067 | 8e1c85e3 | bellard | t0 = cpu_cc_src; |
1068 | 8e1c85e3 | bellard | break;
|
1069 | 8e1c85e3 | bellard | } |
1070 | 8e1c85e3 | bellard | tcg_gen_brcond_tl(cond, cpu_tmp4, t0, l1); |
1071 | 8e1c85e3 | bellard | break;
|
1072 | 8e1c85e3 | bellard | |
1073 | 8e1c85e3 | bellard | default:
|
1074 | 8e1c85e3 | bellard | goto slow_jcc;
|
1075 | 8e1c85e3 | bellard | } |
1076 | 8e1c85e3 | bellard | break;
|
1077 | 8e1c85e3 | bellard | |
1078 | 8e1c85e3 | bellard | /* some jumps are easy to compute */
|
1079 | 8e1c85e3 | bellard | case CC_OP_ADDB:
|
1080 | 8e1c85e3 | bellard | case CC_OP_ADDW:
|
1081 | 8e1c85e3 | bellard | case CC_OP_ADDL:
|
1082 | 8e1c85e3 | bellard | case CC_OP_ADDQ:
|
1083 | 8e1c85e3 | bellard | |
1084 | 8e1c85e3 | bellard | case CC_OP_ADCB:
|
1085 | 8e1c85e3 | bellard | case CC_OP_ADCW:
|
1086 | 8e1c85e3 | bellard | case CC_OP_ADCL:
|
1087 | 8e1c85e3 | bellard | case CC_OP_ADCQ:
|
1088 | 8e1c85e3 | bellard | |
1089 | 8e1c85e3 | bellard | case CC_OP_SBBB:
|
1090 | 8e1c85e3 | bellard | case CC_OP_SBBW:
|
1091 | 8e1c85e3 | bellard | case CC_OP_SBBL:
|
1092 | 8e1c85e3 | bellard | case CC_OP_SBBQ:
|
1093 | 8e1c85e3 | bellard | |
1094 | 8e1c85e3 | bellard | case CC_OP_LOGICB:
|
1095 | 8e1c85e3 | bellard | case CC_OP_LOGICW:
|
1096 | 8e1c85e3 | bellard | case CC_OP_LOGICL:
|
1097 | 8e1c85e3 | bellard | case CC_OP_LOGICQ:
|
1098 | 8e1c85e3 | bellard | |
1099 | 8e1c85e3 | bellard | case CC_OP_INCB:
|
1100 | 8e1c85e3 | bellard | case CC_OP_INCW:
|
1101 | 8e1c85e3 | bellard | case CC_OP_INCL:
|
1102 | 8e1c85e3 | bellard | case CC_OP_INCQ:
|
1103 | 8e1c85e3 | bellard | |
1104 | 8e1c85e3 | bellard | case CC_OP_DECB:
|
1105 | 8e1c85e3 | bellard | case CC_OP_DECW:
|
1106 | 8e1c85e3 | bellard | case CC_OP_DECL:
|
1107 | 8e1c85e3 | bellard | case CC_OP_DECQ:
|
1108 | 8e1c85e3 | bellard | |
1109 | 8e1c85e3 | bellard | case CC_OP_SHLB:
|
1110 | 8e1c85e3 | bellard | case CC_OP_SHLW:
|
1111 | 8e1c85e3 | bellard | case CC_OP_SHLL:
|
1112 | 8e1c85e3 | bellard | case CC_OP_SHLQ:
|
1113 | 8e1c85e3 | bellard | |
1114 | 8e1c85e3 | bellard | case CC_OP_SARB:
|
1115 | 8e1c85e3 | bellard | case CC_OP_SARW:
|
1116 | 8e1c85e3 | bellard | case CC_OP_SARL:
|
1117 | 8e1c85e3 | bellard | case CC_OP_SARQ:
|
1118 | 8e1c85e3 | bellard | switch(jcc_op) {
|
1119 | 8e1c85e3 | bellard | case JCC_Z:
|
1120 | 8e1c85e3 | bellard | size = (cc_op - CC_OP_ADDB) & 3;
|
1121 | 8e1c85e3 | bellard | goto fast_jcc_z;
|
1122 | 8e1c85e3 | bellard | case JCC_S:
|
1123 | 8e1c85e3 | bellard | size = (cc_op - CC_OP_ADDB) & 3;
|
1124 | 8e1c85e3 | bellard | goto fast_jcc_s;
|
1125 | 8e1c85e3 | bellard | default:
|
1126 | 8e1c85e3 | bellard | goto slow_jcc;
|
1127 | 8e1c85e3 | bellard | } |
1128 | 8e1c85e3 | bellard | break;
|
1129 | 8e1c85e3 | bellard | default:
|
1130 | 8e1c85e3 | bellard | slow_jcc:
|
1131 | 1e4840bf | bellard | gen_setcc_slow_T0(s, jcc_op); |
1132 | cb63669a | pbrook | tcg_gen_brcondi_tl(inv ? TCG_COND_EQ : TCG_COND_NE, |
1133 | cb63669a | pbrook | cpu_T[0], 0, l1); |
1134 | 8e1c85e3 | bellard | break;
|
1135 | 8e1c85e3 | bellard | } |
1136 | 8e1c85e3 | bellard | } |
1137 | 8e1c85e3 | bellard | |
1138 | 14ce26e7 | bellard | /* XXX: does not work with gdbstub "ice" single step - not a
|
1139 | 14ce26e7 | bellard | serious problem */
|
1140 | 14ce26e7 | bellard | static int gen_jz_ecx_string(DisasContext *s, target_ulong next_eip) |
1141 | 2c0262af | bellard | { |
1142 | 14ce26e7 | bellard | int l1, l2;
|
1143 | 14ce26e7 | bellard | |
1144 | 14ce26e7 | bellard | l1 = gen_new_label(); |
1145 | 14ce26e7 | bellard | l2 = gen_new_label(); |
1146 | 6e0d8677 | bellard | gen_op_jnz_ecx(s->aflag, l1); |
1147 | 14ce26e7 | bellard | gen_set_label(l2); |
1148 | 14ce26e7 | bellard | gen_jmp_tb(s, next_eip, 1);
|
1149 | 14ce26e7 | bellard | gen_set_label(l1); |
1150 | 14ce26e7 | bellard | return l2;
|
1151 | 2c0262af | bellard | } |
1152 | 2c0262af | bellard | |
1153 | 2c0262af | bellard | static inline void gen_stos(DisasContext *s, int ot) |
1154 | 2c0262af | bellard | { |
1155 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_LONG, 0, R_EAX);
|
1156 | 2c0262af | bellard | gen_string_movl_A0_EDI(s); |
1157 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
1158 | 6e0d8677 | bellard | gen_op_movl_T0_Dshift(ot); |
1159 | 6e0d8677 | bellard | gen_op_add_reg_T0(s->aflag, R_EDI); |
1160 | 2c0262af | bellard | } |
1161 | 2c0262af | bellard | |
1162 | 2c0262af | bellard | static inline void gen_lods(DisasContext *s, int ot) |
1163 | 2c0262af | bellard | { |
1164 | 2c0262af | bellard | gen_string_movl_A0_ESI(s); |
1165 | 57fec1fe | bellard | gen_op_ld_T0_A0(ot + s->mem_index); |
1166 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, R_EAX); |
1167 | 6e0d8677 | bellard | gen_op_movl_T0_Dshift(ot); |
1168 | 6e0d8677 | bellard | gen_op_add_reg_T0(s->aflag, R_ESI); |
1169 | 2c0262af | bellard | } |
1170 | 2c0262af | bellard | |
1171 | 2c0262af | bellard | static inline void gen_scas(DisasContext *s, int ot) |
1172 | 2c0262af | bellard | { |
1173 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_LONG, 0, R_EAX);
|
1174 | 2c0262af | bellard | gen_string_movl_A0_EDI(s); |
1175 | 57fec1fe | bellard | gen_op_ld_T1_A0(ot + s->mem_index); |
1176 | 2c0262af | bellard | gen_op_cmpl_T0_T1_cc(); |
1177 | 6e0d8677 | bellard | gen_op_movl_T0_Dshift(ot); |
1178 | 6e0d8677 | bellard | gen_op_add_reg_T0(s->aflag, R_EDI); |
1179 | 2c0262af | bellard | } |
1180 | 2c0262af | bellard | |
1181 | 2c0262af | bellard | static inline void gen_cmps(DisasContext *s, int ot) |
1182 | 2c0262af | bellard | { |
1183 | 2c0262af | bellard | gen_string_movl_A0_ESI(s); |
1184 | 57fec1fe | bellard | gen_op_ld_T0_A0(ot + s->mem_index); |
1185 | 2c0262af | bellard | gen_string_movl_A0_EDI(s); |
1186 | 57fec1fe | bellard | gen_op_ld_T1_A0(ot + s->mem_index); |
1187 | 2c0262af | bellard | gen_op_cmpl_T0_T1_cc(); |
1188 | 6e0d8677 | bellard | gen_op_movl_T0_Dshift(ot); |
1189 | 6e0d8677 | bellard | gen_op_add_reg_T0(s->aflag, R_ESI); |
1190 | 6e0d8677 | bellard | gen_op_add_reg_T0(s->aflag, R_EDI); |
1191 | 2c0262af | bellard | } |
1192 | 2c0262af | bellard | |
1193 | 2c0262af | bellard | static inline void gen_ins(DisasContext *s, int ot) |
1194 | 2c0262af | bellard | { |
1195 | 2e70f6ef | pbrook | if (use_icount)
|
1196 | 2e70f6ef | pbrook | gen_io_start(); |
1197 | 2c0262af | bellard | gen_string_movl_A0_EDI(s); |
1198 | 6e0d8677 | bellard | /* Note: we must do this dummy write first to be restartable in
|
1199 | 6e0d8677 | bellard | case of page fault. */
|
1200 | 9772c73b | bellard | gen_op_movl_T0_0(); |
1201 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
1202 | b8b6a50b | bellard | gen_op_mov_TN_reg(OT_WORD, 1, R_EDX);
|
1203 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[1]);
|
1204 | b6abf97d | bellard | tcg_gen_andi_i32(cpu_tmp2_i32, cpu_tmp2_i32, 0xffff);
|
1205 | a7812ae4 | pbrook | gen_helper_in_func(ot, cpu_T[0], cpu_tmp2_i32);
|
1206 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
1207 | 6e0d8677 | bellard | gen_op_movl_T0_Dshift(ot); |
1208 | 6e0d8677 | bellard | gen_op_add_reg_T0(s->aflag, R_EDI); |
1209 | 2e70f6ef | pbrook | if (use_icount)
|
1210 | 2e70f6ef | pbrook | gen_io_end(); |
1211 | 2c0262af | bellard | } |
1212 | 2c0262af | bellard | |
1213 | 2c0262af | bellard | static inline void gen_outs(DisasContext *s, int ot) |
1214 | 2c0262af | bellard | { |
1215 | 2e70f6ef | pbrook | if (use_icount)
|
1216 | 2e70f6ef | pbrook | gen_io_start(); |
1217 | 2c0262af | bellard | gen_string_movl_A0_ESI(s); |
1218 | 57fec1fe | bellard | gen_op_ld_T0_A0(ot + s->mem_index); |
1219 | b8b6a50b | bellard | |
1220 | b8b6a50b | bellard | gen_op_mov_TN_reg(OT_WORD, 1, R_EDX);
|
1221 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[1]);
|
1222 | b6abf97d | bellard | tcg_gen_andi_i32(cpu_tmp2_i32, cpu_tmp2_i32, 0xffff);
|
1223 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp3_i32, cpu_T[0]);
|
1224 | a7812ae4 | pbrook | gen_helper_out_func(ot, cpu_tmp2_i32, cpu_tmp3_i32); |
1225 | b8b6a50b | bellard | |
1226 | 6e0d8677 | bellard | gen_op_movl_T0_Dshift(ot); |
1227 | 6e0d8677 | bellard | gen_op_add_reg_T0(s->aflag, R_ESI); |
1228 | 2e70f6ef | pbrook | if (use_icount)
|
1229 | 2e70f6ef | pbrook | gen_io_end(); |
1230 | 2c0262af | bellard | } |
1231 | 2c0262af | bellard | |
1232 | 2c0262af | bellard | /* same method as Valgrind : we generate jumps to current or next
|
1233 | 2c0262af | bellard | instruction */
|
1234 | 2c0262af | bellard | #define GEN_REPZ(op) \
|
1235 | 2c0262af | bellard | static inline void gen_repz_ ## op(DisasContext *s, int ot, \ |
1236 | 14ce26e7 | bellard | target_ulong cur_eip, target_ulong next_eip) \ |
1237 | 2c0262af | bellard | { \ |
1238 | 14ce26e7 | bellard | int l2;\
|
1239 | 2c0262af | bellard | gen_update_cc_op(s); \ |
1240 | 14ce26e7 | bellard | l2 = gen_jz_ecx_string(s, next_eip); \ |
1241 | 2c0262af | bellard | gen_ ## op(s, ot); \ |
1242 | 6e0d8677 | bellard | gen_op_add_reg_im(s->aflag, R_ECX, -1); \
|
1243 | 2c0262af | bellard | /* a loop would cause two single step exceptions if ECX = 1 \
|
1244 | 2c0262af | bellard | before rep string_insn */ \
|
1245 | 2c0262af | bellard | if (!s->jmp_opt) \
|
1246 | 6e0d8677 | bellard | gen_op_jz_ecx(s->aflag, l2); \ |
1247 | 2c0262af | bellard | gen_jmp(s, cur_eip); \ |
1248 | 2c0262af | bellard | } |
1249 | 2c0262af | bellard | |
1250 | 2c0262af | bellard | #define GEN_REPZ2(op) \
|
1251 | 2c0262af | bellard | static inline void gen_repz_ ## op(DisasContext *s, int ot, \ |
1252 | 14ce26e7 | bellard | target_ulong cur_eip, \ |
1253 | 14ce26e7 | bellard | target_ulong next_eip, \ |
1254 | 2c0262af | bellard | int nz) \
|
1255 | 2c0262af | bellard | { \ |
1256 | 14ce26e7 | bellard | int l2;\
|
1257 | 2c0262af | bellard | gen_update_cc_op(s); \ |
1258 | 14ce26e7 | bellard | l2 = gen_jz_ecx_string(s, next_eip); \ |
1259 | 2c0262af | bellard | gen_ ## op(s, ot); \ |
1260 | 6e0d8677 | bellard | gen_op_add_reg_im(s->aflag, R_ECX, -1); \
|
1261 | 2c0262af | bellard | gen_op_set_cc_op(CC_OP_SUBB + ot); \ |
1262 | 8e1c85e3 | bellard | gen_jcc1(s, CC_OP_SUBB + ot, (JCC_Z << 1) | (nz ^ 1), l2); \ |
1263 | 2c0262af | bellard | if (!s->jmp_opt) \
|
1264 | 6e0d8677 | bellard | gen_op_jz_ecx(s->aflag, l2); \ |
1265 | 2c0262af | bellard | gen_jmp(s, cur_eip); \ |
1266 | 2c0262af | bellard | } |
1267 | 2c0262af | bellard | |
1268 | 2c0262af | bellard | GEN_REPZ(movs) |
1269 | 2c0262af | bellard | GEN_REPZ(stos) |
1270 | 2c0262af | bellard | GEN_REPZ(lods) |
1271 | 2c0262af | bellard | GEN_REPZ(ins) |
1272 | 2c0262af | bellard | GEN_REPZ(outs) |
1273 | 2c0262af | bellard | GEN_REPZ2(scas) |
1274 | 2c0262af | bellard | GEN_REPZ2(cmps) |
1275 | 2c0262af | bellard | |
1276 | a7812ae4 | pbrook | static void gen_helper_fp_arith_ST0_FT0(int op) |
1277 | a7812ae4 | pbrook | { |
1278 | a7812ae4 | pbrook | switch (op) {
|
1279 | a7812ae4 | pbrook | case 0: gen_helper_fadd_ST0_FT0(); break; |
1280 | a7812ae4 | pbrook | case 1: gen_helper_fmul_ST0_FT0(); break; |
1281 | a7812ae4 | pbrook | case 2: gen_helper_fcom_ST0_FT0(); break; |
1282 | a7812ae4 | pbrook | case 3: gen_helper_fcom_ST0_FT0(); break; |
1283 | a7812ae4 | pbrook | case 4: gen_helper_fsub_ST0_FT0(); break; |
1284 | a7812ae4 | pbrook | case 5: gen_helper_fsubr_ST0_FT0(); break; |
1285 | a7812ae4 | pbrook | case 6: gen_helper_fdiv_ST0_FT0(); break; |
1286 | a7812ae4 | pbrook | case 7: gen_helper_fdivr_ST0_FT0(); break; |
1287 | a7812ae4 | pbrook | } |
1288 | a7812ae4 | pbrook | } |
1289 | 2c0262af | bellard | |
1290 | 2c0262af | bellard | /* NOTE the exception in "r" op ordering */
|
1291 | a7812ae4 | pbrook | static void gen_helper_fp_arith_STN_ST0(int op, int opreg) |
1292 | a7812ae4 | pbrook | { |
1293 | a7812ae4 | pbrook | TCGv_i32 tmp = tcg_const_i32(opreg); |
1294 | a7812ae4 | pbrook | switch (op) {
|
1295 | a7812ae4 | pbrook | case 0: gen_helper_fadd_STN_ST0(tmp); break; |
1296 | a7812ae4 | pbrook | case 1: gen_helper_fmul_STN_ST0(tmp); break; |
1297 | a7812ae4 | pbrook | case 4: gen_helper_fsubr_STN_ST0(tmp); break; |
1298 | a7812ae4 | pbrook | case 5: gen_helper_fsub_STN_ST0(tmp); break; |
1299 | a7812ae4 | pbrook | case 6: gen_helper_fdivr_STN_ST0(tmp); break; |
1300 | a7812ae4 | pbrook | case 7: gen_helper_fdiv_STN_ST0(tmp); break; |
1301 | a7812ae4 | pbrook | } |
1302 | a7812ae4 | pbrook | } |
1303 | 2c0262af | bellard | |
1304 | 2c0262af | bellard | /* if d == OR_TMP0, it means memory operand (address in A0) */
|
1305 | 2c0262af | bellard | static void gen_op(DisasContext *s1, int op, int ot, int d) |
1306 | 2c0262af | bellard | { |
1307 | 2c0262af | bellard | if (d != OR_TMP0) {
|
1308 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, d);
|
1309 | 2c0262af | bellard | } else {
|
1310 | 57fec1fe | bellard | gen_op_ld_T0_A0(ot + s1->mem_index); |
1311 | 2c0262af | bellard | } |
1312 | 2c0262af | bellard | switch(op) {
|
1313 | 2c0262af | bellard | case OP_ADCL:
|
1314 | cad3a37d | bellard | if (s1->cc_op != CC_OP_DYNAMIC)
|
1315 | cad3a37d | bellard | gen_op_set_cc_op(s1->cc_op); |
1316 | cad3a37d | bellard | gen_compute_eflags_c(cpu_tmp4); |
1317 | cad3a37d | bellard | tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1318 | cad3a37d | bellard | tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_tmp4); |
1319 | cad3a37d | bellard | if (d != OR_TMP0)
|
1320 | cad3a37d | bellard | gen_op_mov_reg_T0(ot, d); |
1321 | cad3a37d | bellard | else
|
1322 | cad3a37d | bellard | gen_op_st_T0_A0(ot + s1->mem_index); |
1323 | cad3a37d | bellard | tcg_gen_mov_tl(cpu_cc_src, cpu_T[1]);
|
1324 | cad3a37d | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
1325 | cad3a37d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_tmp4); |
1326 | cad3a37d | bellard | tcg_gen_shli_i32(cpu_tmp2_i32, cpu_tmp2_i32, 2);
|
1327 | cad3a37d | bellard | tcg_gen_addi_i32(cpu_cc_op, cpu_tmp2_i32, CC_OP_ADDB + ot); |
1328 | cad3a37d | bellard | s1->cc_op = CC_OP_DYNAMIC; |
1329 | cad3a37d | bellard | break;
|
1330 | 2c0262af | bellard | case OP_SBBL:
|
1331 | 2c0262af | bellard | if (s1->cc_op != CC_OP_DYNAMIC)
|
1332 | 2c0262af | bellard | gen_op_set_cc_op(s1->cc_op); |
1333 | cad3a37d | bellard | gen_compute_eflags_c(cpu_tmp4); |
1334 | cad3a37d | bellard | tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1335 | cad3a37d | bellard | tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_tmp4); |
1336 | cad3a37d | bellard | if (d != OR_TMP0)
|
1337 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, d); |
1338 | cad3a37d | bellard | else
|
1339 | cad3a37d | bellard | gen_op_st_T0_A0(ot + s1->mem_index); |
1340 | cad3a37d | bellard | tcg_gen_mov_tl(cpu_cc_src, cpu_T[1]);
|
1341 | cad3a37d | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
1342 | cad3a37d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_tmp4); |
1343 | cad3a37d | bellard | tcg_gen_shli_i32(cpu_tmp2_i32, cpu_tmp2_i32, 2);
|
1344 | cad3a37d | bellard | tcg_gen_addi_i32(cpu_cc_op, cpu_tmp2_i32, CC_OP_SUBB + ot); |
1345 | 2c0262af | bellard | s1->cc_op = CC_OP_DYNAMIC; |
1346 | cad3a37d | bellard | break;
|
1347 | 2c0262af | bellard | case OP_ADDL:
|
1348 | 2c0262af | bellard | gen_op_addl_T0_T1(); |
1349 | cad3a37d | bellard | if (d != OR_TMP0)
|
1350 | cad3a37d | bellard | gen_op_mov_reg_T0(ot, d); |
1351 | cad3a37d | bellard | else
|
1352 | cad3a37d | bellard | gen_op_st_T0_A0(ot + s1->mem_index); |
1353 | cad3a37d | bellard | gen_op_update2_cc(); |
1354 | 2c0262af | bellard | s1->cc_op = CC_OP_ADDB + ot; |
1355 | 2c0262af | bellard | break;
|
1356 | 2c0262af | bellard | case OP_SUBL:
|
1357 | 57fec1fe | bellard | tcg_gen_sub_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1358 | cad3a37d | bellard | if (d != OR_TMP0)
|
1359 | cad3a37d | bellard | gen_op_mov_reg_T0(ot, d); |
1360 | cad3a37d | bellard | else
|
1361 | cad3a37d | bellard | gen_op_st_T0_A0(ot + s1->mem_index); |
1362 | cad3a37d | bellard | gen_op_update2_cc(); |
1363 | 2c0262af | bellard | s1->cc_op = CC_OP_SUBB + ot; |
1364 | 2c0262af | bellard | break;
|
1365 | 2c0262af | bellard | default:
|
1366 | 2c0262af | bellard | case OP_ANDL:
|
1367 | 57fec1fe | bellard | tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1368 | cad3a37d | bellard | if (d != OR_TMP0)
|
1369 | cad3a37d | bellard | gen_op_mov_reg_T0(ot, d); |
1370 | cad3a37d | bellard | else
|
1371 | cad3a37d | bellard | gen_op_st_T0_A0(ot + s1->mem_index); |
1372 | cad3a37d | bellard | gen_op_update1_cc(); |
1373 | 57fec1fe | bellard | s1->cc_op = CC_OP_LOGICB + ot; |
1374 | 57fec1fe | bellard | break;
|
1375 | 2c0262af | bellard | case OP_ORL:
|
1376 | 57fec1fe | bellard | tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1377 | cad3a37d | bellard | if (d != OR_TMP0)
|
1378 | cad3a37d | bellard | gen_op_mov_reg_T0(ot, d); |
1379 | cad3a37d | bellard | else
|
1380 | cad3a37d | bellard | gen_op_st_T0_A0(ot + s1->mem_index); |
1381 | cad3a37d | bellard | gen_op_update1_cc(); |
1382 | 57fec1fe | bellard | s1->cc_op = CC_OP_LOGICB + ot; |
1383 | 57fec1fe | bellard | break;
|
1384 | 2c0262af | bellard | case OP_XORL:
|
1385 | 57fec1fe | bellard | tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1386 | cad3a37d | bellard | if (d != OR_TMP0)
|
1387 | cad3a37d | bellard | gen_op_mov_reg_T0(ot, d); |
1388 | cad3a37d | bellard | else
|
1389 | cad3a37d | bellard | gen_op_st_T0_A0(ot + s1->mem_index); |
1390 | cad3a37d | bellard | gen_op_update1_cc(); |
1391 | 2c0262af | bellard | s1->cc_op = CC_OP_LOGICB + ot; |
1392 | 2c0262af | bellard | break;
|
1393 | 2c0262af | bellard | case OP_CMPL:
|
1394 | 2c0262af | bellard | gen_op_cmpl_T0_T1_cc(); |
1395 | 2c0262af | bellard | s1->cc_op = CC_OP_SUBB + ot; |
1396 | 2c0262af | bellard | break;
|
1397 | 2c0262af | bellard | } |
1398 | b6abf97d | bellard | } |
1399 | b6abf97d | bellard | |
1400 | 2c0262af | bellard | /* if d == OR_TMP0, it means memory operand (address in A0) */
|
1401 | 2c0262af | bellard | static void gen_inc(DisasContext *s1, int ot, int d, int c) |
1402 | 2c0262af | bellard | { |
1403 | 2c0262af | bellard | if (d != OR_TMP0)
|
1404 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, d);
|
1405 | 2c0262af | bellard | else
|
1406 | 57fec1fe | bellard | gen_op_ld_T0_A0(ot + s1->mem_index); |
1407 | 2c0262af | bellard | if (s1->cc_op != CC_OP_DYNAMIC)
|
1408 | 2c0262af | bellard | gen_op_set_cc_op(s1->cc_op); |
1409 | 2c0262af | bellard | if (c > 0) { |
1410 | b6abf97d | bellard | tcg_gen_addi_tl(cpu_T[0], cpu_T[0], 1); |
1411 | 2c0262af | bellard | s1->cc_op = CC_OP_INCB + ot; |
1412 | 2c0262af | bellard | } else {
|
1413 | b6abf97d | bellard | tcg_gen_addi_tl(cpu_T[0], cpu_T[0], -1); |
1414 | 2c0262af | bellard | s1->cc_op = CC_OP_DECB + ot; |
1415 | 2c0262af | bellard | } |
1416 | 2c0262af | bellard | if (d != OR_TMP0)
|
1417 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, d); |
1418 | 2c0262af | bellard | else
|
1419 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s1->mem_index); |
1420 | b6abf97d | bellard | gen_compute_eflags_c(cpu_cc_src); |
1421 | cd31fefa | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
1422 | 2c0262af | bellard | } |
1423 | 2c0262af | bellard | |
1424 | b6abf97d | bellard | static void gen_shift_rm_T1(DisasContext *s, int ot, int op1, |
1425 | b6abf97d | bellard | int is_right, int is_arith) |
1426 | 2c0262af | bellard | { |
1427 | b6abf97d | bellard | target_ulong mask; |
1428 | b6abf97d | bellard | int shift_label;
|
1429 | 1e4840bf | bellard | TCGv t0, t1; |
1430 | 1e4840bf | bellard | |
1431 | b6abf97d | bellard | if (ot == OT_QUAD)
|
1432 | b6abf97d | bellard | mask = 0x3f;
|
1433 | 2c0262af | bellard | else
|
1434 | b6abf97d | bellard | mask = 0x1f;
|
1435 | 3b46e624 | ths | |
1436 | b6abf97d | bellard | /* load */
|
1437 | b6abf97d | bellard | if (op1 == OR_TMP0)
|
1438 | b6abf97d | bellard | gen_op_ld_T0_A0(ot + s->mem_index); |
1439 | 2c0262af | bellard | else
|
1440 | b6abf97d | bellard | gen_op_mov_TN_reg(ot, 0, op1);
|
1441 | b6abf97d | bellard | |
1442 | b6abf97d | bellard | tcg_gen_andi_tl(cpu_T[1], cpu_T[1], mask); |
1443 | b6abf97d | bellard | |
1444 | b6abf97d | bellard | tcg_gen_addi_tl(cpu_tmp5, cpu_T[1], -1); |
1445 | b6abf97d | bellard | |
1446 | b6abf97d | bellard | if (is_right) {
|
1447 | b6abf97d | bellard | if (is_arith) {
|
1448 | f484d386 | bellard | gen_exts(ot, cpu_T[0]);
|
1449 | b6abf97d | bellard | tcg_gen_sar_tl(cpu_T3, cpu_T[0], cpu_tmp5);
|
1450 | b6abf97d | bellard | tcg_gen_sar_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1451 | b6abf97d | bellard | } else {
|
1452 | cad3a37d | bellard | gen_extu(ot, cpu_T[0]);
|
1453 | b6abf97d | bellard | tcg_gen_shr_tl(cpu_T3, cpu_T[0], cpu_tmp5);
|
1454 | b6abf97d | bellard | tcg_gen_shr_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1455 | b6abf97d | bellard | } |
1456 | b6abf97d | bellard | } else {
|
1457 | b6abf97d | bellard | tcg_gen_shl_tl(cpu_T3, cpu_T[0], cpu_tmp5);
|
1458 | b6abf97d | bellard | tcg_gen_shl_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
1459 | b6abf97d | bellard | } |
1460 | b6abf97d | bellard | |
1461 | b6abf97d | bellard | /* store */
|
1462 | b6abf97d | bellard | if (op1 == OR_TMP0)
|
1463 | b6abf97d | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
1464 | b6abf97d | bellard | else
|
1465 | b6abf97d | bellard | gen_op_mov_reg_T0(ot, op1); |
1466 | b6abf97d | bellard | |
1467 | b6abf97d | bellard | /* update eflags if non zero shift */
|
1468 | b6abf97d | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
1469 | b6abf97d | bellard | gen_op_set_cc_op(s->cc_op); |
1470 | b6abf97d | bellard | |
1471 | 1e4840bf | bellard | /* XXX: inefficient */
|
1472 | a7812ae4 | pbrook | t0 = tcg_temp_local_new(); |
1473 | a7812ae4 | pbrook | t1 = tcg_temp_local_new(); |
1474 | 1e4840bf | bellard | |
1475 | 1e4840bf | bellard | tcg_gen_mov_tl(t0, cpu_T[0]);
|
1476 | 1e4840bf | bellard | tcg_gen_mov_tl(t1, cpu_T3); |
1477 | 1e4840bf | bellard | |
1478 | b6abf97d | bellard | shift_label = gen_new_label(); |
1479 | cb63669a | pbrook | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_T[1], 0, shift_label); |
1480 | b6abf97d | bellard | |
1481 | 1e4840bf | bellard | tcg_gen_mov_tl(cpu_cc_src, t1); |
1482 | 1e4840bf | bellard | tcg_gen_mov_tl(cpu_cc_dst, t0); |
1483 | b6abf97d | bellard | if (is_right)
|
1484 | b6abf97d | bellard | tcg_gen_movi_i32(cpu_cc_op, CC_OP_SARB + ot); |
1485 | b6abf97d | bellard | else
|
1486 | b6abf97d | bellard | tcg_gen_movi_i32(cpu_cc_op, CC_OP_SHLB + ot); |
1487 | b6abf97d | bellard | |
1488 | b6abf97d | bellard | gen_set_label(shift_label); |
1489 | b6abf97d | bellard | s->cc_op = CC_OP_DYNAMIC; /* cannot predict flags after */
|
1490 | 1e4840bf | bellard | |
1491 | 1e4840bf | bellard | tcg_temp_free(t0); |
1492 | 1e4840bf | bellard | tcg_temp_free(t1); |
1493 | b6abf97d | bellard | } |
1494 | b6abf97d | bellard | |
1495 | c1c37968 | bellard | static void gen_shift_rm_im(DisasContext *s, int ot, int op1, int op2, |
1496 | c1c37968 | bellard | int is_right, int is_arith) |
1497 | c1c37968 | bellard | { |
1498 | c1c37968 | bellard | int mask;
|
1499 | c1c37968 | bellard | |
1500 | c1c37968 | bellard | if (ot == OT_QUAD)
|
1501 | c1c37968 | bellard | mask = 0x3f;
|
1502 | c1c37968 | bellard | else
|
1503 | c1c37968 | bellard | mask = 0x1f;
|
1504 | c1c37968 | bellard | |
1505 | c1c37968 | bellard | /* load */
|
1506 | c1c37968 | bellard | if (op1 == OR_TMP0)
|
1507 | c1c37968 | bellard | gen_op_ld_T0_A0(ot + s->mem_index); |
1508 | c1c37968 | bellard | else
|
1509 | c1c37968 | bellard | gen_op_mov_TN_reg(ot, 0, op1);
|
1510 | c1c37968 | bellard | |
1511 | c1c37968 | bellard | op2 &= mask; |
1512 | c1c37968 | bellard | if (op2 != 0) { |
1513 | c1c37968 | bellard | if (is_right) {
|
1514 | c1c37968 | bellard | if (is_arith) {
|
1515 | c1c37968 | bellard | gen_exts(ot, cpu_T[0]);
|
1516 | 2a449d14 | bellard | tcg_gen_sari_tl(cpu_tmp4, cpu_T[0], op2 - 1); |
1517 | c1c37968 | bellard | tcg_gen_sari_tl(cpu_T[0], cpu_T[0], op2); |
1518 | c1c37968 | bellard | } else {
|
1519 | c1c37968 | bellard | gen_extu(ot, cpu_T[0]);
|
1520 | 2a449d14 | bellard | tcg_gen_shri_tl(cpu_tmp4, cpu_T[0], op2 - 1); |
1521 | c1c37968 | bellard | tcg_gen_shri_tl(cpu_T[0], cpu_T[0], op2); |
1522 | c1c37968 | bellard | } |
1523 | c1c37968 | bellard | } else {
|
1524 | 2a449d14 | bellard | tcg_gen_shli_tl(cpu_tmp4, cpu_T[0], op2 - 1); |
1525 | c1c37968 | bellard | tcg_gen_shli_tl(cpu_T[0], cpu_T[0], op2); |
1526 | c1c37968 | bellard | } |
1527 | c1c37968 | bellard | } |
1528 | c1c37968 | bellard | |
1529 | c1c37968 | bellard | /* store */
|
1530 | c1c37968 | bellard | if (op1 == OR_TMP0)
|
1531 | c1c37968 | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
1532 | c1c37968 | bellard | else
|
1533 | c1c37968 | bellard | gen_op_mov_reg_T0(ot, op1); |
1534 | c1c37968 | bellard | |
1535 | c1c37968 | bellard | /* update eflags if non zero shift */
|
1536 | c1c37968 | bellard | if (op2 != 0) { |
1537 | 2a449d14 | bellard | tcg_gen_mov_tl(cpu_cc_src, cpu_tmp4); |
1538 | c1c37968 | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
1539 | c1c37968 | bellard | if (is_right)
|
1540 | c1c37968 | bellard | s->cc_op = CC_OP_SARB + ot; |
1541 | c1c37968 | bellard | else
|
1542 | c1c37968 | bellard | s->cc_op = CC_OP_SHLB + ot; |
1543 | c1c37968 | bellard | } |
1544 | c1c37968 | bellard | } |
1545 | c1c37968 | bellard | |
1546 | b6abf97d | bellard | static inline void tcg_gen_lshift(TCGv ret, TCGv arg1, target_long arg2) |
1547 | b6abf97d | bellard | { |
1548 | b6abf97d | bellard | if (arg2 >= 0) |
1549 | b6abf97d | bellard | tcg_gen_shli_tl(ret, arg1, arg2); |
1550 | b6abf97d | bellard | else
|
1551 | b6abf97d | bellard | tcg_gen_shri_tl(ret, arg1, -arg2); |
1552 | b6abf97d | bellard | } |
1553 | b6abf97d | bellard | |
1554 | b6abf97d | bellard | static void gen_rot_rm_T1(DisasContext *s, int ot, int op1, |
1555 | b6abf97d | bellard | int is_right)
|
1556 | b6abf97d | bellard | { |
1557 | b6abf97d | bellard | target_ulong mask; |
1558 | b6abf97d | bellard | int label1, label2, data_bits;
|
1559 | 1e4840bf | bellard | TCGv t0, t1, t2, a0; |
1560 | 1e4840bf | bellard | |
1561 | 1e4840bf | bellard | /* XXX: inefficient, but we must use local temps */
|
1562 | a7812ae4 | pbrook | t0 = tcg_temp_local_new(); |
1563 | a7812ae4 | pbrook | t1 = tcg_temp_local_new(); |
1564 | a7812ae4 | pbrook | t2 = tcg_temp_local_new(); |
1565 | a7812ae4 | pbrook | a0 = tcg_temp_local_new(); |
1566 | 1e4840bf | bellard | |
1567 | b6abf97d | bellard | if (ot == OT_QUAD)
|
1568 | b6abf97d | bellard | mask = 0x3f;
|
1569 | b6abf97d | bellard | else
|
1570 | b6abf97d | bellard | mask = 0x1f;
|
1571 | b6abf97d | bellard | |
1572 | b6abf97d | bellard | /* load */
|
1573 | 1e4840bf | bellard | if (op1 == OR_TMP0) {
|
1574 | 1e4840bf | bellard | tcg_gen_mov_tl(a0, cpu_A0); |
1575 | 1e4840bf | bellard | gen_op_ld_v(ot + s->mem_index, t0, a0); |
1576 | 1e4840bf | bellard | } else {
|
1577 | 1e4840bf | bellard | gen_op_mov_v_reg(ot, t0, op1); |
1578 | 1e4840bf | bellard | } |
1579 | b6abf97d | bellard | |
1580 | 1e4840bf | bellard | tcg_gen_mov_tl(t1, cpu_T[1]);
|
1581 | 1e4840bf | bellard | |
1582 | 1e4840bf | bellard | tcg_gen_andi_tl(t1, t1, mask); |
1583 | b6abf97d | bellard | |
1584 | b6abf97d | bellard | /* Must test zero case to avoid using undefined behaviour in TCG
|
1585 | b6abf97d | bellard | shifts. */
|
1586 | b6abf97d | bellard | label1 = gen_new_label(); |
1587 | 1e4840bf | bellard | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, label1);
|
1588 | b6abf97d | bellard | |
1589 | b6abf97d | bellard | if (ot <= OT_WORD)
|
1590 | 1e4840bf | bellard | tcg_gen_andi_tl(cpu_tmp0, t1, (1 << (3 + ot)) - 1); |
1591 | b6abf97d | bellard | else
|
1592 | 1e4840bf | bellard | tcg_gen_mov_tl(cpu_tmp0, t1); |
1593 | b6abf97d | bellard | |
1594 | 1e4840bf | bellard | gen_extu(ot, t0); |
1595 | 1e4840bf | bellard | tcg_gen_mov_tl(t2, t0); |
1596 | b6abf97d | bellard | |
1597 | b6abf97d | bellard | data_bits = 8 << ot;
|
1598 | b6abf97d | bellard | /* XXX: rely on behaviour of shifts when operand 2 overflows (XXX:
|
1599 | b6abf97d | bellard | fix TCG definition) */
|
1600 | b6abf97d | bellard | if (is_right) {
|
1601 | 1e4840bf | bellard | tcg_gen_shr_tl(cpu_tmp4, t0, cpu_tmp0); |
1602 | b6abf97d | bellard | tcg_gen_sub_tl(cpu_tmp0, tcg_const_tl(data_bits), cpu_tmp0); |
1603 | 1e4840bf | bellard | tcg_gen_shl_tl(t0, t0, cpu_tmp0); |
1604 | b6abf97d | bellard | } else {
|
1605 | 1e4840bf | bellard | tcg_gen_shl_tl(cpu_tmp4, t0, cpu_tmp0); |
1606 | b6abf97d | bellard | tcg_gen_sub_tl(cpu_tmp0, tcg_const_tl(data_bits), cpu_tmp0); |
1607 | 1e4840bf | bellard | tcg_gen_shr_tl(t0, t0, cpu_tmp0); |
1608 | b6abf97d | bellard | } |
1609 | 1e4840bf | bellard | tcg_gen_or_tl(t0, t0, cpu_tmp4); |
1610 | b6abf97d | bellard | |
1611 | b6abf97d | bellard | gen_set_label(label1); |
1612 | b6abf97d | bellard | /* store */
|
1613 | 1e4840bf | bellard | if (op1 == OR_TMP0) {
|
1614 | 1e4840bf | bellard | gen_op_st_v(ot + s->mem_index, t0, a0); |
1615 | 1e4840bf | bellard | } else {
|
1616 | 1e4840bf | bellard | gen_op_mov_reg_v(ot, op1, t0); |
1617 | 1e4840bf | bellard | } |
1618 | b6abf97d | bellard | |
1619 | b6abf97d | bellard | /* update eflags */
|
1620 | b6abf97d | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
1621 | b6abf97d | bellard | gen_op_set_cc_op(s->cc_op); |
1622 | b6abf97d | bellard | |
1623 | b6abf97d | bellard | label2 = gen_new_label(); |
1624 | 1e4840bf | bellard | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, label2);
|
1625 | b6abf97d | bellard | |
1626 | b6abf97d | bellard | gen_compute_eflags(cpu_cc_src); |
1627 | b6abf97d | bellard | tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, ~(CC_O | CC_C)); |
1628 | 1e4840bf | bellard | tcg_gen_xor_tl(cpu_tmp0, t2, t0); |
1629 | b6abf97d | bellard | tcg_gen_lshift(cpu_tmp0, cpu_tmp0, 11 - (data_bits - 1)); |
1630 | b6abf97d | bellard | tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, CC_O); |
1631 | b6abf97d | bellard | tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0); |
1632 | b6abf97d | bellard | if (is_right) {
|
1633 | 1e4840bf | bellard | tcg_gen_shri_tl(t0, t0, data_bits - 1);
|
1634 | b6abf97d | bellard | } |
1635 | 1e4840bf | bellard | tcg_gen_andi_tl(t0, t0, CC_C); |
1636 | 1e4840bf | bellard | tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, t0); |
1637 | b6abf97d | bellard | |
1638 | b6abf97d | bellard | tcg_gen_discard_tl(cpu_cc_dst); |
1639 | b6abf97d | bellard | tcg_gen_movi_i32(cpu_cc_op, CC_OP_EFLAGS); |
1640 | b6abf97d | bellard | |
1641 | b6abf97d | bellard | gen_set_label(label2); |
1642 | b6abf97d | bellard | s->cc_op = CC_OP_DYNAMIC; /* cannot predict flags after */
|
1643 | 1e4840bf | bellard | |
1644 | 1e4840bf | bellard | tcg_temp_free(t0); |
1645 | 1e4840bf | bellard | tcg_temp_free(t1); |
1646 | 1e4840bf | bellard | tcg_temp_free(t2); |
1647 | 1e4840bf | bellard | tcg_temp_free(a0); |
1648 | b6abf97d | bellard | } |
1649 | b6abf97d | bellard | |
1650 | 8cd6345d | malc | static void gen_rot_rm_im(DisasContext *s, int ot, int op1, int op2, |
1651 | 8cd6345d | malc | int is_right)
|
1652 | 8cd6345d | malc | { |
1653 | 8cd6345d | malc | int mask;
|
1654 | 8cd6345d | malc | int data_bits;
|
1655 | 8cd6345d | malc | TCGv t0, t1, a0; |
1656 | 8cd6345d | malc | |
1657 | 8cd6345d | malc | /* XXX: inefficient, but we must use local temps */
|
1658 | 8cd6345d | malc | t0 = tcg_temp_local_new(); |
1659 | 8cd6345d | malc | t1 = tcg_temp_local_new(); |
1660 | 8cd6345d | malc | a0 = tcg_temp_local_new(); |
1661 | 8cd6345d | malc | |
1662 | 8cd6345d | malc | if (ot == OT_QUAD)
|
1663 | 8cd6345d | malc | mask = 0x3f;
|
1664 | 8cd6345d | malc | else
|
1665 | 8cd6345d | malc | mask = 0x1f;
|
1666 | 8cd6345d | malc | |
1667 | 8cd6345d | malc | /* load */
|
1668 | 8cd6345d | malc | if (op1 == OR_TMP0) {
|
1669 | 8cd6345d | malc | tcg_gen_mov_tl(a0, cpu_A0); |
1670 | 8cd6345d | malc | gen_op_ld_v(ot + s->mem_index, t0, a0); |
1671 | 8cd6345d | malc | } else {
|
1672 | 8cd6345d | malc | gen_op_mov_v_reg(ot, t0, op1); |
1673 | 8cd6345d | malc | } |
1674 | 8cd6345d | malc | |
1675 | 8cd6345d | malc | gen_extu(ot, t0); |
1676 | 8cd6345d | malc | tcg_gen_mov_tl(t1, t0); |
1677 | 8cd6345d | malc | |
1678 | 8cd6345d | malc | op2 &= mask; |
1679 | 8cd6345d | malc | data_bits = 8 << ot;
|
1680 | 8cd6345d | malc | if (op2 != 0) { |
1681 | 8cd6345d | malc | int shift = op2 & ((1 << (3 + ot)) - 1); |
1682 | 8cd6345d | malc | if (is_right) {
|
1683 | 8cd6345d | malc | tcg_gen_shri_tl(cpu_tmp4, t0, shift); |
1684 | 8cd6345d | malc | tcg_gen_shli_tl(t0, t0, data_bits - shift); |
1685 | 8cd6345d | malc | } |
1686 | 8cd6345d | malc | else {
|
1687 | 8cd6345d | malc | tcg_gen_shli_tl(cpu_tmp4, t0, shift); |
1688 | 8cd6345d | malc | tcg_gen_shri_tl(t0, t0, data_bits - shift); |
1689 | 8cd6345d | malc | } |
1690 | 8cd6345d | malc | tcg_gen_or_tl(t0, t0, cpu_tmp4); |
1691 | 8cd6345d | malc | } |
1692 | 8cd6345d | malc | |
1693 | 8cd6345d | malc | /* store */
|
1694 | 8cd6345d | malc | if (op1 == OR_TMP0) {
|
1695 | 8cd6345d | malc | gen_op_st_v(ot + s->mem_index, t0, a0); |
1696 | 8cd6345d | malc | } else {
|
1697 | 8cd6345d | malc | gen_op_mov_reg_v(ot, op1, t0); |
1698 | 8cd6345d | malc | } |
1699 | 8cd6345d | malc | |
1700 | 8cd6345d | malc | if (op2 != 0) { |
1701 | 8cd6345d | malc | /* update eflags */
|
1702 | 8cd6345d | malc | if (s->cc_op != CC_OP_DYNAMIC)
|
1703 | 8cd6345d | malc | gen_op_set_cc_op(s->cc_op); |
1704 | 8cd6345d | malc | |
1705 | 8cd6345d | malc | gen_compute_eflags(cpu_cc_src); |
1706 | 8cd6345d | malc | tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, ~(CC_O | CC_C)); |
1707 | 8cd6345d | malc | tcg_gen_xor_tl(cpu_tmp0, t1, t0); |
1708 | 8cd6345d | malc | tcg_gen_lshift(cpu_tmp0, cpu_tmp0, 11 - (data_bits - 1)); |
1709 | 8cd6345d | malc | tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, CC_O); |
1710 | 8cd6345d | malc | tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0); |
1711 | 8cd6345d | malc | if (is_right) {
|
1712 | 8cd6345d | malc | tcg_gen_shri_tl(t0, t0, data_bits - 1);
|
1713 | 8cd6345d | malc | } |
1714 | 8cd6345d | malc | tcg_gen_andi_tl(t0, t0, CC_C); |
1715 | 8cd6345d | malc | tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, t0); |
1716 | 8cd6345d | malc | |
1717 | 8cd6345d | malc | tcg_gen_discard_tl(cpu_cc_dst); |
1718 | 8cd6345d | malc | tcg_gen_movi_i32(cpu_cc_op, CC_OP_EFLAGS); |
1719 | 8cd6345d | malc | s->cc_op = CC_OP_EFLAGS; |
1720 | 8cd6345d | malc | } |
1721 | 8cd6345d | malc | |
1722 | 8cd6345d | malc | tcg_temp_free(t0); |
1723 | 8cd6345d | malc | tcg_temp_free(t1); |
1724 | 8cd6345d | malc | tcg_temp_free(a0); |
1725 | 8cd6345d | malc | } |
1726 | 8cd6345d | malc | |
1727 | b6abf97d | bellard | /* XXX: add faster immediate = 1 case */
|
1728 | b6abf97d | bellard | static void gen_rotc_rm_T1(DisasContext *s, int ot, int op1, |
1729 | b6abf97d | bellard | int is_right)
|
1730 | b6abf97d | bellard | { |
1731 | b6abf97d | bellard | int label1;
|
1732 | b6abf97d | bellard | |
1733 | b6abf97d | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
1734 | b6abf97d | bellard | gen_op_set_cc_op(s->cc_op); |
1735 | b6abf97d | bellard | |
1736 | b6abf97d | bellard | /* load */
|
1737 | b6abf97d | bellard | if (op1 == OR_TMP0)
|
1738 | b6abf97d | bellard | gen_op_ld_T0_A0(ot + s->mem_index); |
1739 | b6abf97d | bellard | else
|
1740 | b6abf97d | bellard | gen_op_mov_TN_reg(ot, 0, op1);
|
1741 | b6abf97d | bellard | |
1742 | a7812ae4 | pbrook | if (is_right) {
|
1743 | a7812ae4 | pbrook | switch (ot) {
|
1744 | a7812ae4 | pbrook | case 0: gen_helper_rcrb(cpu_T[0], cpu_T[0], cpu_T[1]); break; |
1745 | a7812ae4 | pbrook | case 1: gen_helper_rcrw(cpu_T[0], cpu_T[0], cpu_T[1]); break; |
1746 | a7812ae4 | pbrook | case 2: gen_helper_rcrl(cpu_T[0], cpu_T[0], cpu_T[1]); break; |
1747 | a7812ae4 | pbrook | #ifdef TARGET_X86_64
|
1748 | a7812ae4 | pbrook | case 3: gen_helper_rcrq(cpu_T[0], cpu_T[0], cpu_T[1]); break; |
1749 | a7812ae4 | pbrook | #endif
|
1750 | a7812ae4 | pbrook | } |
1751 | a7812ae4 | pbrook | } else {
|
1752 | a7812ae4 | pbrook | switch (ot) {
|
1753 | a7812ae4 | pbrook | case 0: gen_helper_rclb(cpu_T[0], cpu_T[0], cpu_T[1]); break; |
1754 | a7812ae4 | pbrook | case 1: gen_helper_rclw(cpu_T[0], cpu_T[0], cpu_T[1]); break; |
1755 | a7812ae4 | pbrook | case 2: gen_helper_rcll(cpu_T[0], cpu_T[0], cpu_T[1]); break; |
1756 | a7812ae4 | pbrook | #ifdef TARGET_X86_64
|
1757 | a7812ae4 | pbrook | case 3: gen_helper_rclq(cpu_T[0], cpu_T[0], cpu_T[1]); break; |
1758 | a7812ae4 | pbrook | #endif
|
1759 | a7812ae4 | pbrook | } |
1760 | a7812ae4 | pbrook | } |
1761 | b6abf97d | bellard | /* store */
|
1762 | b6abf97d | bellard | if (op1 == OR_TMP0)
|
1763 | b6abf97d | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
1764 | b6abf97d | bellard | else
|
1765 | b6abf97d | bellard | gen_op_mov_reg_T0(ot, op1); |
1766 | b6abf97d | bellard | |
1767 | b6abf97d | bellard | /* update eflags */
|
1768 | b6abf97d | bellard | label1 = gen_new_label(); |
1769 | 1e4840bf | bellard | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_cc_tmp, -1, label1);
|
1770 | b6abf97d | bellard | |
1771 | 1e4840bf | bellard | tcg_gen_mov_tl(cpu_cc_src, cpu_cc_tmp); |
1772 | b6abf97d | bellard | tcg_gen_discard_tl(cpu_cc_dst); |
1773 | b6abf97d | bellard | tcg_gen_movi_i32(cpu_cc_op, CC_OP_EFLAGS); |
1774 | b6abf97d | bellard | |
1775 | b6abf97d | bellard | gen_set_label(label1); |
1776 | b6abf97d | bellard | s->cc_op = CC_OP_DYNAMIC; /* cannot predict flags after */
|
1777 | b6abf97d | bellard | } |
1778 | b6abf97d | bellard | |
1779 | b6abf97d | bellard | /* XXX: add faster immediate case */
|
1780 | b6abf97d | bellard | static void gen_shiftd_rm_T1_T3(DisasContext *s, int ot, int op1, |
1781 | b6abf97d | bellard | int is_right)
|
1782 | b6abf97d | bellard | { |
1783 | b6abf97d | bellard | int label1, label2, data_bits;
|
1784 | b6abf97d | bellard | target_ulong mask; |
1785 | 1e4840bf | bellard | TCGv t0, t1, t2, a0; |
1786 | 1e4840bf | bellard | |
1787 | a7812ae4 | pbrook | t0 = tcg_temp_local_new(); |
1788 | a7812ae4 | pbrook | t1 = tcg_temp_local_new(); |
1789 | a7812ae4 | pbrook | t2 = tcg_temp_local_new(); |
1790 | a7812ae4 | pbrook | a0 = tcg_temp_local_new(); |
1791 | b6abf97d | bellard | |
1792 | b6abf97d | bellard | if (ot == OT_QUAD)
|
1793 | b6abf97d | bellard | mask = 0x3f;
|
1794 | b6abf97d | bellard | else
|
1795 | b6abf97d | bellard | mask = 0x1f;
|
1796 | b6abf97d | bellard | |
1797 | b6abf97d | bellard | /* load */
|
1798 | 1e4840bf | bellard | if (op1 == OR_TMP0) {
|
1799 | 1e4840bf | bellard | tcg_gen_mov_tl(a0, cpu_A0); |
1800 | 1e4840bf | bellard | gen_op_ld_v(ot + s->mem_index, t0, a0); |
1801 | 1e4840bf | bellard | } else {
|
1802 | 1e4840bf | bellard | gen_op_mov_v_reg(ot, t0, op1); |
1803 | 1e4840bf | bellard | } |
1804 | b6abf97d | bellard | |
1805 | b6abf97d | bellard | tcg_gen_andi_tl(cpu_T3, cpu_T3, mask); |
1806 | 1e4840bf | bellard | |
1807 | 1e4840bf | bellard | tcg_gen_mov_tl(t1, cpu_T[1]);
|
1808 | 1e4840bf | bellard | tcg_gen_mov_tl(t2, cpu_T3); |
1809 | 1e4840bf | bellard | |
1810 | b6abf97d | bellard | /* Must test zero case to avoid using undefined behaviour in TCG
|
1811 | b6abf97d | bellard | shifts. */
|
1812 | b6abf97d | bellard | label1 = gen_new_label(); |
1813 | 1e4840bf | bellard | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, label1);
|
1814 | b6abf97d | bellard | |
1815 | 1e4840bf | bellard | tcg_gen_addi_tl(cpu_tmp5, t2, -1);
|
1816 | b6abf97d | bellard | if (ot == OT_WORD) {
|
1817 | b6abf97d | bellard | /* Note: we implement the Intel behaviour for shift count > 16 */
|
1818 | b6abf97d | bellard | if (is_right) {
|
1819 | 1e4840bf | bellard | tcg_gen_andi_tl(t0, t0, 0xffff);
|
1820 | 1e4840bf | bellard | tcg_gen_shli_tl(cpu_tmp0, t1, 16);
|
1821 | 1e4840bf | bellard | tcg_gen_or_tl(t0, t0, cpu_tmp0); |
1822 | 1e4840bf | bellard | tcg_gen_ext32u_tl(t0, t0); |
1823 | b6abf97d | bellard | |
1824 | 1e4840bf | bellard | tcg_gen_shr_tl(cpu_tmp4, t0, cpu_tmp5); |
1825 | b6abf97d | bellard | |
1826 | b6abf97d | bellard | /* only needed if count > 16, but a test would complicate */
|
1827 | 1e4840bf | bellard | tcg_gen_sub_tl(cpu_tmp5, tcg_const_tl(32), t2);
|
1828 | 1e4840bf | bellard | tcg_gen_shl_tl(cpu_tmp0, t0, cpu_tmp5); |
1829 | b6abf97d | bellard | |
1830 | 1e4840bf | bellard | tcg_gen_shr_tl(t0, t0, t2); |
1831 | b6abf97d | bellard | |
1832 | 1e4840bf | bellard | tcg_gen_or_tl(t0, t0, cpu_tmp0); |
1833 | b6abf97d | bellard | } else {
|
1834 | b6abf97d | bellard | /* XXX: not optimal */
|
1835 | 1e4840bf | bellard | tcg_gen_andi_tl(t0, t0, 0xffff);
|
1836 | 1e4840bf | bellard | tcg_gen_shli_tl(t1, t1, 16);
|
1837 | 1e4840bf | bellard | tcg_gen_or_tl(t1, t1, t0); |
1838 | 1e4840bf | bellard | tcg_gen_ext32u_tl(t1, t1); |
1839 | b6abf97d | bellard | |
1840 | 1e4840bf | bellard | tcg_gen_shl_tl(cpu_tmp4, t0, cpu_tmp5); |
1841 | b6abf97d | bellard | tcg_gen_sub_tl(cpu_tmp0, tcg_const_tl(32), cpu_tmp5);
|
1842 | 1e4840bf | bellard | tcg_gen_shr_tl(cpu_tmp6, t1, cpu_tmp0); |
1843 | b6abf97d | bellard | tcg_gen_or_tl(cpu_tmp4, cpu_tmp4, cpu_tmp6); |
1844 | b6abf97d | bellard | |
1845 | 1e4840bf | bellard | tcg_gen_shl_tl(t0, t0, t2); |
1846 | 1e4840bf | bellard | tcg_gen_sub_tl(cpu_tmp5, tcg_const_tl(32), t2);
|
1847 | 1e4840bf | bellard | tcg_gen_shr_tl(t1, t1, cpu_tmp5); |
1848 | 1e4840bf | bellard | tcg_gen_or_tl(t0, t0, t1); |
1849 | b6abf97d | bellard | } |
1850 | b6abf97d | bellard | } else {
|
1851 | b6abf97d | bellard | data_bits = 8 << ot;
|
1852 | b6abf97d | bellard | if (is_right) {
|
1853 | b6abf97d | bellard | if (ot == OT_LONG)
|
1854 | 1e4840bf | bellard | tcg_gen_ext32u_tl(t0, t0); |
1855 | b6abf97d | bellard | |
1856 | 1e4840bf | bellard | tcg_gen_shr_tl(cpu_tmp4, t0, cpu_tmp5); |
1857 | b6abf97d | bellard | |
1858 | 1e4840bf | bellard | tcg_gen_shr_tl(t0, t0, t2); |
1859 | 1e4840bf | bellard | tcg_gen_sub_tl(cpu_tmp5, tcg_const_tl(data_bits), t2); |
1860 | 1e4840bf | bellard | tcg_gen_shl_tl(t1, t1, cpu_tmp5); |
1861 | 1e4840bf | bellard | tcg_gen_or_tl(t0, t0, t1); |
1862 | b6abf97d | bellard | |
1863 | b6abf97d | bellard | } else {
|
1864 | b6abf97d | bellard | if (ot == OT_LONG)
|
1865 | 1e4840bf | bellard | tcg_gen_ext32u_tl(t1, t1); |
1866 | b6abf97d | bellard | |
1867 | 1e4840bf | bellard | tcg_gen_shl_tl(cpu_tmp4, t0, cpu_tmp5); |
1868 | b6abf97d | bellard | |
1869 | 1e4840bf | bellard | tcg_gen_shl_tl(t0, t0, t2); |
1870 | 1e4840bf | bellard | tcg_gen_sub_tl(cpu_tmp5, tcg_const_tl(data_bits), t2); |
1871 | 1e4840bf | bellard | tcg_gen_shr_tl(t1, t1, cpu_tmp5); |
1872 | 1e4840bf | bellard | tcg_gen_or_tl(t0, t0, t1); |
1873 | b6abf97d | bellard | } |
1874 | b6abf97d | bellard | } |
1875 | 1e4840bf | bellard | tcg_gen_mov_tl(t1, cpu_tmp4); |
1876 | b6abf97d | bellard | |
1877 | b6abf97d | bellard | gen_set_label(label1); |
1878 | b6abf97d | bellard | /* store */
|
1879 | 1e4840bf | bellard | if (op1 == OR_TMP0) {
|
1880 | 1e4840bf | bellard | gen_op_st_v(ot + s->mem_index, t0, a0); |
1881 | 1e4840bf | bellard | } else {
|
1882 | 1e4840bf | bellard | gen_op_mov_reg_v(ot, op1, t0); |
1883 | 1e4840bf | bellard | } |
1884 | b6abf97d | bellard | |
1885 | b6abf97d | bellard | /* update eflags */
|
1886 | b6abf97d | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
1887 | b6abf97d | bellard | gen_op_set_cc_op(s->cc_op); |
1888 | b6abf97d | bellard | |
1889 | b6abf97d | bellard | label2 = gen_new_label(); |
1890 | 1e4840bf | bellard | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, label2);
|
1891 | b6abf97d | bellard | |
1892 | 1e4840bf | bellard | tcg_gen_mov_tl(cpu_cc_src, t1); |
1893 | 1e4840bf | bellard | tcg_gen_mov_tl(cpu_cc_dst, t0); |
1894 | b6abf97d | bellard | if (is_right) {
|
1895 | b6abf97d | bellard | tcg_gen_movi_i32(cpu_cc_op, CC_OP_SARB + ot); |
1896 | b6abf97d | bellard | } else {
|
1897 | b6abf97d | bellard | tcg_gen_movi_i32(cpu_cc_op, CC_OP_SHLB + ot); |
1898 | b6abf97d | bellard | } |
1899 | b6abf97d | bellard | gen_set_label(label2); |
1900 | b6abf97d | bellard | s->cc_op = CC_OP_DYNAMIC; /* cannot predict flags after */
|
1901 | 1e4840bf | bellard | |
1902 | 1e4840bf | bellard | tcg_temp_free(t0); |
1903 | 1e4840bf | bellard | tcg_temp_free(t1); |
1904 | 1e4840bf | bellard | tcg_temp_free(t2); |
1905 | 1e4840bf | bellard | tcg_temp_free(a0); |
1906 | b6abf97d | bellard | } |
1907 | b6abf97d | bellard | |
1908 | b6abf97d | bellard | static void gen_shift(DisasContext *s1, int op, int ot, int d, int s) |
1909 | b6abf97d | bellard | { |
1910 | b6abf97d | bellard | if (s != OR_TMP1)
|
1911 | b6abf97d | bellard | gen_op_mov_TN_reg(ot, 1, s);
|
1912 | b6abf97d | bellard | switch(op) {
|
1913 | b6abf97d | bellard | case OP_ROL:
|
1914 | b6abf97d | bellard | gen_rot_rm_T1(s1, ot, d, 0);
|
1915 | b6abf97d | bellard | break;
|
1916 | b6abf97d | bellard | case OP_ROR:
|
1917 | b6abf97d | bellard | gen_rot_rm_T1(s1, ot, d, 1);
|
1918 | b6abf97d | bellard | break;
|
1919 | b6abf97d | bellard | case OP_SHL:
|
1920 | b6abf97d | bellard | case OP_SHL1:
|
1921 | b6abf97d | bellard | gen_shift_rm_T1(s1, ot, d, 0, 0); |
1922 | b6abf97d | bellard | break;
|
1923 | b6abf97d | bellard | case OP_SHR:
|
1924 | b6abf97d | bellard | gen_shift_rm_T1(s1, ot, d, 1, 0); |
1925 | b6abf97d | bellard | break;
|
1926 | b6abf97d | bellard | case OP_SAR:
|
1927 | b6abf97d | bellard | gen_shift_rm_T1(s1, ot, d, 1, 1); |
1928 | b6abf97d | bellard | break;
|
1929 | b6abf97d | bellard | case OP_RCL:
|
1930 | b6abf97d | bellard | gen_rotc_rm_T1(s1, ot, d, 0);
|
1931 | b6abf97d | bellard | break;
|
1932 | b6abf97d | bellard | case OP_RCR:
|
1933 | b6abf97d | bellard | gen_rotc_rm_T1(s1, ot, d, 1);
|
1934 | b6abf97d | bellard | break;
|
1935 | b6abf97d | bellard | } |
1936 | 2c0262af | bellard | } |
1937 | 2c0262af | bellard | |
1938 | 2c0262af | bellard | static void gen_shifti(DisasContext *s1, int op, int ot, int d, int c) |
1939 | 2c0262af | bellard | { |
1940 | c1c37968 | bellard | switch(op) {
|
1941 | 8cd6345d | malc | case OP_ROL:
|
1942 | 8cd6345d | malc | gen_rot_rm_im(s1, ot, d, c, 0);
|
1943 | 8cd6345d | malc | break;
|
1944 | 8cd6345d | malc | case OP_ROR:
|
1945 | 8cd6345d | malc | gen_rot_rm_im(s1, ot, d, c, 1);
|
1946 | 8cd6345d | malc | break;
|
1947 | c1c37968 | bellard | case OP_SHL:
|
1948 | c1c37968 | bellard | case OP_SHL1:
|
1949 | c1c37968 | bellard | gen_shift_rm_im(s1, ot, d, c, 0, 0); |
1950 | c1c37968 | bellard | break;
|
1951 | c1c37968 | bellard | case OP_SHR:
|
1952 | c1c37968 | bellard | gen_shift_rm_im(s1, ot, d, c, 1, 0); |
1953 | c1c37968 | bellard | break;
|
1954 | c1c37968 | bellard | case OP_SAR:
|
1955 | c1c37968 | bellard | gen_shift_rm_im(s1, ot, d, c, 1, 1); |
1956 | c1c37968 | bellard | break;
|
1957 | c1c37968 | bellard | default:
|
1958 | c1c37968 | bellard | /* currently not optimized */
|
1959 | c1c37968 | bellard | gen_op_movl_T1_im(c); |
1960 | c1c37968 | bellard | gen_shift(s1, op, ot, d, OR_TMP1); |
1961 | c1c37968 | bellard | break;
|
1962 | c1c37968 | bellard | } |
1963 | 2c0262af | bellard | } |
1964 | 2c0262af | bellard | |
1965 | 2c0262af | bellard | static void gen_lea_modrm(DisasContext *s, int modrm, int *reg_ptr, int *offset_ptr) |
1966 | 2c0262af | bellard | { |
1967 | 14ce26e7 | bellard | target_long disp; |
1968 | 2c0262af | bellard | int havesib;
|
1969 | 14ce26e7 | bellard | int base;
|
1970 | 2c0262af | bellard | int index;
|
1971 | 2c0262af | bellard | int scale;
|
1972 | 2c0262af | bellard | int opreg;
|
1973 | 2c0262af | bellard | int mod, rm, code, override, must_add_seg;
|
1974 | 2c0262af | bellard | |
1975 | 2c0262af | bellard | override = s->override; |
1976 | 2c0262af | bellard | must_add_seg = s->addseg; |
1977 | 2c0262af | bellard | if (override >= 0) |
1978 | 2c0262af | bellard | must_add_seg = 1;
|
1979 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
1980 | 2c0262af | bellard | rm = modrm & 7;
|
1981 | 2c0262af | bellard | |
1982 | 2c0262af | bellard | if (s->aflag) {
|
1983 | 2c0262af | bellard | |
1984 | 2c0262af | bellard | havesib = 0;
|
1985 | 2c0262af | bellard | base = rm; |
1986 | 2c0262af | bellard | index = 0;
|
1987 | 2c0262af | bellard | scale = 0;
|
1988 | 3b46e624 | ths | |
1989 | 2c0262af | bellard | if (base == 4) { |
1990 | 2c0262af | bellard | havesib = 1;
|
1991 | 61382a50 | bellard | code = ldub_code(s->pc++); |
1992 | 2c0262af | bellard | scale = (code >> 6) & 3; |
1993 | 14ce26e7 | bellard | index = ((code >> 3) & 7) | REX_X(s); |
1994 | 14ce26e7 | bellard | base = (code & 7);
|
1995 | 2c0262af | bellard | } |
1996 | 14ce26e7 | bellard | base |= REX_B(s); |
1997 | 2c0262af | bellard | |
1998 | 2c0262af | bellard | switch (mod) {
|
1999 | 2c0262af | bellard | case 0: |
2000 | 14ce26e7 | bellard | if ((base & 7) == 5) { |
2001 | 2c0262af | bellard | base = -1;
|
2002 | 14ce26e7 | bellard | disp = (int32_t)ldl_code(s->pc); |
2003 | 2c0262af | bellard | s->pc += 4;
|
2004 | 14ce26e7 | bellard | if (CODE64(s) && !havesib) {
|
2005 | 14ce26e7 | bellard | disp += s->pc + s->rip_offset; |
2006 | 14ce26e7 | bellard | } |
2007 | 2c0262af | bellard | } else {
|
2008 | 2c0262af | bellard | disp = 0;
|
2009 | 2c0262af | bellard | } |
2010 | 2c0262af | bellard | break;
|
2011 | 2c0262af | bellard | case 1: |
2012 | 61382a50 | bellard | disp = (int8_t)ldub_code(s->pc++); |
2013 | 2c0262af | bellard | break;
|
2014 | 2c0262af | bellard | default:
|
2015 | 2c0262af | bellard | case 2: |
2016 | 61382a50 | bellard | disp = ldl_code(s->pc); |
2017 | 2c0262af | bellard | s->pc += 4;
|
2018 | 2c0262af | bellard | break;
|
2019 | 2c0262af | bellard | } |
2020 | 3b46e624 | ths | |
2021 | 2c0262af | bellard | if (base >= 0) { |
2022 | 2c0262af | bellard | /* for correct popl handling with esp */
|
2023 | 2c0262af | bellard | if (base == 4 && s->popl_esp_hack) |
2024 | 2c0262af | bellard | disp += s->popl_esp_hack; |
2025 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
2026 | 14ce26e7 | bellard | if (s->aflag == 2) { |
2027 | 57fec1fe | bellard | gen_op_movq_A0_reg(base); |
2028 | 14ce26e7 | bellard | if (disp != 0) { |
2029 | 57fec1fe | bellard | gen_op_addq_A0_im(disp); |
2030 | 14ce26e7 | bellard | } |
2031 | 5fafdf24 | ths | } else
|
2032 | 14ce26e7 | bellard | #endif
|
2033 | 14ce26e7 | bellard | { |
2034 | 57fec1fe | bellard | gen_op_movl_A0_reg(base); |
2035 | 14ce26e7 | bellard | if (disp != 0) |
2036 | 14ce26e7 | bellard | gen_op_addl_A0_im(disp); |
2037 | 14ce26e7 | bellard | } |
2038 | 2c0262af | bellard | } else {
|
2039 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
2040 | 14ce26e7 | bellard | if (s->aflag == 2) { |
2041 | 57fec1fe | bellard | gen_op_movq_A0_im(disp); |
2042 | 5fafdf24 | ths | } else
|
2043 | 14ce26e7 | bellard | #endif
|
2044 | 14ce26e7 | bellard | { |
2045 | 14ce26e7 | bellard | gen_op_movl_A0_im(disp); |
2046 | 14ce26e7 | bellard | } |
2047 | 2c0262af | bellard | } |
2048 | 2c0262af | bellard | /* XXX: index == 4 is always invalid */
|
2049 | 2c0262af | bellard | if (havesib && (index != 4 || scale != 0)) { |
2050 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
2051 | 14ce26e7 | bellard | if (s->aflag == 2) { |
2052 | 57fec1fe | bellard | gen_op_addq_A0_reg_sN(scale, index); |
2053 | 5fafdf24 | ths | } else
|
2054 | 14ce26e7 | bellard | #endif
|
2055 | 14ce26e7 | bellard | { |
2056 | 57fec1fe | bellard | gen_op_addl_A0_reg_sN(scale, index); |
2057 | 14ce26e7 | bellard | } |
2058 | 2c0262af | bellard | } |
2059 | 2c0262af | bellard | if (must_add_seg) {
|
2060 | 2c0262af | bellard | if (override < 0) { |
2061 | 2c0262af | bellard | if (base == R_EBP || base == R_ESP)
|
2062 | 2c0262af | bellard | override = R_SS; |
2063 | 2c0262af | bellard | else
|
2064 | 2c0262af | bellard | override = R_DS; |
2065 | 2c0262af | bellard | } |
2066 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
2067 | 14ce26e7 | bellard | if (s->aflag == 2) { |
2068 | 57fec1fe | bellard | gen_op_addq_A0_seg(override); |
2069 | 5fafdf24 | ths | } else
|
2070 | 14ce26e7 | bellard | #endif
|
2071 | 14ce26e7 | bellard | { |
2072 | 57fec1fe | bellard | gen_op_addl_A0_seg(override); |
2073 | 14ce26e7 | bellard | } |
2074 | 2c0262af | bellard | } |
2075 | 2c0262af | bellard | } else {
|
2076 | 2c0262af | bellard | switch (mod) {
|
2077 | 2c0262af | bellard | case 0: |
2078 | 2c0262af | bellard | if (rm == 6) { |
2079 | 61382a50 | bellard | disp = lduw_code(s->pc); |
2080 | 2c0262af | bellard | s->pc += 2;
|
2081 | 2c0262af | bellard | gen_op_movl_A0_im(disp); |
2082 | 2c0262af | bellard | rm = 0; /* avoid SS override */ |
2083 | 2c0262af | bellard | goto no_rm;
|
2084 | 2c0262af | bellard | } else {
|
2085 | 2c0262af | bellard | disp = 0;
|
2086 | 2c0262af | bellard | } |
2087 | 2c0262af | bellard | break;
|
2088 | 2c0262af | bellard | case 1: |
2089 | 61382a50 | bellard | disp = (int8_t)ldub_code(s->pc++); |
2090 | 2c0262af | bellard | break;
|
2091 | 2c0262af | bellard | default:
|
2092 | 2c0262af | bellard | case 2: |
2093 | 61382a50 | bellard | disp = lduw_code(s->pc); |
2094 | 2c0262af | bellard | s->pc += 2;
|
2095 | 2c0262af | bellard | break;
|
2096 | 2c0262af | bellard | } |
2097 | 2c0262af | bellard | switch(rm) {
|
2098 | 2c0262af | bellard | case 0: |
2099 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_EBX); |
2100 | 57fec1fe | bellard | gen_op_addl_A0_reg_sN(0, R_ESI);
|
2101 | 2c0262af | bellard | break;
|
2102 | 2c0262af | bellard | case 1: |
2103 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_EBX); |
2104 | 57fec1fe | bellard | gen_op_addl_A0_reg_sN(0, R_EDI);
|
2105 | 2c0262af | bellard | break;
|
2106 | 2c0262af | bellard | case 2: |
2107 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_EBP); |
2108 | 57fec1fe | bellard | gen_op_addl_A0_reg_sN(0, R_ESI);
|
2109 | 2c0262af | bellard | break;
|
2110 | 2c0262af | bellard | case 3: |
2111 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_EBP); |
2112 | 57fec1fe | bellard | gen_op_addl_A0_reg_sN(0, R_EDI);
|
2113 | 2c0262af | bellard | break;
|
2114 | 2c0262af | bellard | case 4: |
2115 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_ESI); |
2116 | 2c0262af | bellard | break;
|
2117 | 2c0262af | bellard | case 5: |
2118 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_EDI); |
2119 | 2c0262af | bellard | break;
|
2120 | 2c0262af | bellard | case 6: |
2121 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_EBP); |
2122 | 2c0262af | bellard | break;
|
2123 | 2c0262af | bellard | default:
|
2124 | 2c0262af | bellard | case 7: |
2125 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_EBX); |
2126 | 2c0262af | bellard | break;
|
2127 | 2c0262af | bellard | } |
2128 | 2c0262af | bellard | if (disp != 0) |
2129 | 2c0262af | bellard | gen_op_addl_A0_im(disp); |
2130 | 2c0262af | bellard | gen_op_andl_A0_ffff(); |
2131 | 2c0262af | bellard | no_rm:
|
2132 | 2c0262af | bellard | if (must_add_seg) {
|
2133 | 2c0262af | bellard | if (override < 0) { |
2134 | 2c0262af | bellard | if (rm == 2 || rm == 3 || rm == 6) |
2135 | 2c0262af | bellard | override = R_SS; |
2136 | 2c0262af | bellard | else
|
2137 | 2c0262af | bellard | override = R_DS; |
2138 | 2c0262af | bellard | } |
2139 | 57fec1fe | bellard | gen_op_addl_A0_seg(override); |
2140 | 2c0262af | bellard | } |
2141 | 2c0262af | bellard | } |
2142 | 2c0262af | bellard | |
2143 | 2c0262af | bellard | opreg = OR_A0; |
2144 | 2c0262af | bellard | disp = 0;
|
2145 | 2c0262af | bellard | *reg_ptr = opreg; |
2146 | 2c0262af | bellard | *offset_ptr = disp; |
2147 | 2c0262af | bellard | } |
2148 | 2c0262af | bellard | |
2149 | e17a36ce | bellard | static void gen_nop_modrm(DisasContext *s, int modrm) |
2150 | e17a36ce | bellard | { |
2151 | e17a36ce | bellard | int mod, rm, base, code;
|
2152 | e17a36ce | bellard | |
2153 | e17a36ce | bellard | mod = (modrm >> 6) & 3; |
2154 | e17a36ce | bellard | if (mod == 3) |
2155 | e17a36ce | bellard | return;
|
2156 | e17a36ce | bellard | rm = modrm & 7;
|
2157 | e17a36ce | bellard | |
2158 | e17a36ce | bellard | if (s->aflag) {
|
2159 | e17a36ce | bellard | |
2160 | e17a36ce | bellard | base = rm; |
2161 | 3b46e624 | ths | |
2162 | e17a36ce | bellard | if (base == 4) { |
2163 | e17a36ce | bellard | code = ldub_code(s->pc++); |
2164 | e17a36ce | bellard | base = (code & 7);
|
2165 | e17a36ce | bellard | } |
2166 | 3b46e624 | ths | |
2167 | e17a36ce | bellard | switch (mod) {
|
2168 | e17a36ce | bellard | case 0: |
2169 | e17a36ce | bellard | if (base == 5) { |
2170 | e17a36ce | bellard | s->pc += 4;
|
2171 | e17a36ce | bellard | } |
2172 | e17a36ce | bellard | break;
|
2173 | e17a36ce | bellard | case 1: |
2174 | e17a36ce | bellard | s->pc++; |
2175 | e17a36ce | bellard | break;
|
2176 | e17a36ce | bellard | default:
|
2177 | e17a36ce | bellard | case 2: |
2178 | e17a36ce | bellard | s->pc += 4;
|
2179 | e17a36ce | bellard | break;
|
2180 | e17a36ce | bellard | } |
2181 | e17a36ce | bellard | } else {
|
2182 | e17a36ce | bellard | switch (mod) {
|
2183 | e17a36ce | bellard | case 0: |
2184 | e17a36ce | bellard | if (rm == 6) { |
2185 | e17a36ce | bellard | s->pc += 2;
|
2186 | e17a36ce | bellard | } |
2187 | e17a36ce | bellard | break;
|
2188 | e17a36ce | bellard | case 1: |
2189 | e17a36ce | bellard | s->pc++; |
2190 | e17a36ce | bellard | break;
|
2191 | e17a36ce | bellard | default:
|
2192 | e17a36ce | bellard | case 2: |
2193 | e17a36ce | bellard | s->pc += 2;
|
2194 | e17a36ce | bellard | break;
|
2195 | e17a36ce | bellard | } |
2196 | e17a36ce | bellard | } |
2197 | e17a36ce | bellard | } |
2198 | e17a36ce | bellard | |
2199 | 664e0f19 | bellard | /* used for LEA and MOV AX, mem */
|
2200 | 664e0f19 | bellard | static void gen_add_A0_ds_seg(DisasContext *s) |
2201 | 664e0f19 | bellard | { |
2202 | 664e0f19 | bellard | int override, must_add_seg;
|
2203 | 664e0f19 | bellard | must_add_seg = s->addseg; |
2204 | 664e0f19 | bellard | override = R_DS; |
2205 | 664e0f19 | bellard | if (s->override >= 0) { |
2206 | 664e0f19 | bellard | override = s->override; |
2207 | 664e0f19 | bellard | must_add_seg = 1;
|
2208 | 664e0f19 | bellard | } else {
|
2209 | 664e0f19 | bellard | override = R_DS; |
2210 | 664e0f19 | bellard | } |
2211 | 664e0f19 | bellard | if (must_add_seg) {
|
2212 | 8f091a59 | bellard | #ifdef TARGET_X86_64
|
2213 | 8f091a59 | bellard | if (CODE64(s)) {
|
2214 | 57fec1fe | bellard | gen_op_addq_A0_seg(override); |
2215 | 5fafdf24 | ths | } else
|
2216 | 8f091a59 | bellard | #endif
|
2217 | 8f091a59 | bellard | { |
2218 | 57fec1fe | bellard | gen_op_addl_A0_seg(override); |
2219 | 8f091a59 | bellard | } |
2220 | 664e0f19 | bellard | } |
2221 | 664e0f19 | bellard | } |
2222 | 664e0f19 | bellard | |
2223 | 222a3336 | balrog | /* generate modrm memory load or store of 'reg'. TMP0 is used if reg ==
|
2224 | 2c0262af | bellard | OR_TMP0 */
|
2225 | 2c0262af | bellard | static void gen_ldst_modrm(DisasContext *s, int modrm, int ot, int reg, int is_store) |
2226 | 2c0262af | bellard | { |
2227 | 2c0262af | bellard | int mod, rm, opreg, disp;
|
2228 | 2c0262af | bellard | |
2229 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
2230 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
2231 | 2c0262af | bellard | if (mod == 3) { |
2232 | 2c0262af | bellard | if (is_store) {
|
2233 | 2c0262af | bellard | if (reg != OR_TMP0)
|
2234 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, reg);
|
2235 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, rm); |
2236 | 2c0262af | bellard | } else {
|
2237 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, rm);
|
2238 | 2c0262af | bellard | if (reg != OR_TMP0)
|
2239 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, reg); |
2240 | 2c0262af | bellard | } |
2241 | 2c0262af | bellard | } else {
|
2242 | 2c0262af | bellard | gen_lea_modrm(s, modrm, &opreg, &disp); |
2243 | 2c0262af | bellard | if (is_store) {
|
2244 | 2c0262af | bellard | if (reg != OR_TMP0)
|
2245 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, reg);
|
2246 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
2247 | 2c0262af | bellard | } else {
|
2248 | 57fec1fe | bellard | gen_op_ld_T0_A0(ot + s->mem_index); |
2249 | 2c0262af | bellard | if (reg != OR_TMP0)
|
2250 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, reg); |
2251 | 2c0262af | bellard | } |
2252 | 2c0262af | bellard | } |
2253 | 2c0262af | bellard | } |
2254 | 2c0262af | bellard | |
2255 | 2c0262af | bellard | static inline uint32_t insn_get(DisasContext *s, int ot) |
2256 | 2c0262af | bellard | { |
2257 | 2c0262af | bellard | uint32_t ret; |
2258 | 2c0262af | bellard | |
2259 | 2c0262af | bellard | switch(ot) {
|
2260 | 2c0262af | bellard | case OT_BYTE:
|
2261 | 61382a50 | bellard | ret = ldub_code(s->pc); |
2262 | 2c0262af | bellard | s->pc++; |
2263 | 2c0262af | bellard | break;
|
2264 | 2c0262af | bellard | case OT_WORD:
|
2265 | 61382a50 | bellard | ret = lduw_code(s->pc); |
2266 | 2c0262af | bellard | s->pc += 2;
|
2267 | 2c0262af | bellard | break;
|
2268 | 2c0262af | bellard | default:
|
2269 | 2c0262af | bellard | case OT_LONG:
|
2270 | 61382a50 | bellard | ret = ldl_code(s->pc); |
2271 | 2c0262af | bellard | s->pc += 4;
|
2272 | 2c0262af | bellard | break;
|
2273 | 2c0262af | bellard | } |
2274 | 2c0262af | bellard | return ret;
|
2275 | 2c0262af | bellard | } |
2276 | 2c0262af | bellard | |
2277 | 14ce26e7 | bellard | static inline int insn_const_size(unsigned int ot) |
2278 | 14ce26e7 | bellard | { |
2279 | 14ce26e7 | bellard | if (ot <= OT_LONG)
|
2280 | 14ce26e7 | bellard | return 1 << ot; |
2281 | 14ce26e7 | bellard | else
|
2282 | 14ce26e7 | bellard | return 4; |
2283 | 14ce26e7 | bellard | } |
2284 | 14ce26e7 | bellard | |
2285 | 6e256c93 | bellard | static inline void gen_goto_tb(DisasContext *s, int tb_num, target_ulong eip) |
2286 | 6e256c93 | bellard | { |
2287 | 6e256c93 | bellard | TranslationBlock *tb; |
2288 | 6e256c93 | bellard | target_ulong pc; |
2289 | 6e256c93 | bellard | |
2290 | 6e256c93 | bellard | pc = s->cs_base + eip; |
2291 | 6e256c93 | bellard | tb = s->tb; |
2292 | 6e256c93 | bellard | /* NOTE: we handle the case where the TB spans two pages here */
|
2293 | 6e256c93 | bellard | if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) ||
|
2294 | 6e256c93 | bellard | (pc & TARGET_PAGE_MASK) == ((s->pc - 1) & TARGET_PAGE_MASK)) {
|
2295 | 6e256c93 | bellard | /* jump to same page: we can use a direct jump */
|
2296 | 57fec1fe | bellard | tcg_gen_goto_tb(tb_num); |
2297 | 6e256c93 | bellard | gen_jmp_im(eip); |
2298 | 57fec1fe | bellard | tcg_gen_exit_tb((long)tb + tb_num);
|
2299 | 6e256c93 | bellard | } else {
|
2300 | 6e256c93 | bellard | /* jump to another page: currently not optimized */
|
2301 | 6e256c93 | bellard | gen_jmp_im(eip); |
2302 | 6e256c93 | bellard | gen_eob(s); |
2303 | 6e256c93 | bellard | } |
2304 | 6e256c93 | bellard | } |
2305 | 6e256c93 | bellard | |
2306 | 5fafdf24 | ths | static inline void gen_jcc(DisasContext *s, int b, |
2307 | 14ce26e7 | bellard | target_ulong val, target_ulong next_eip) |
2308 | 2c0262af | bellard | { |
2309 | 8e1c85e3 | bellard | int l1, l2, cc_op;
|
2310 | 3b46e624 | ths | |
2311 | 8e1c85e3 | bellard | cc_op = s->cc_op; |
2312 | 8e1c85e3 | bellard | if (s->cc_op != CC_OP_DYNAMIC) {
|
2313 | 8e1c85e3 | bellard | gen_op_set_cc_op(s->cc_op); |
2314 | 8e1c85e3 | bellard | s->cc_op = CC_OP_DYNAMIC; |
2315 | 8e1c85e3 | bellard | } |
2316 | 2c0262af | bellard | if (s->jmp_opt) {
|
2317 | 14ce26e7 | bellard | l1 = gen_new_label(); |
2318 | 8e1c85e3 | bellard | gen_jcc1(s, cc_op, b, l1); |
2319 | 8e1c85e3 | bellard | |
2320 | 6e256c93 | bellard | gen_goto_tb(s, 0, next_eip);
|
2321 | 14ce26e7 | bellard | |
2322 | 14ce26e7 | bellard | gen_set_label(l1); |
2323 | 6e256c93 | bellard | gen_goto_tb(s, 1, val);
|
2324 | 2c0262af | bellard | s->is_jmp = 3;
|
2325 | 2c0262af | bellard | } else {
|
2326 | 14ce26e7 | bellard | |
2327 | 14ce26e7 | bellard | l1 = gen_new_label(); |
2328 | 14ce26e7 | bellard | l2 = gen_new_label(); |
2329 | 8e1c85e3 | bellard | gen_jcc1(s, cc_op, b, l1); |
2330 | 8e1c85e3 | bellard | |
2331 | 14ce26e7 | bellard | gen_jmp_im(next_eip); |
2332 | 8e1c85e3 | bellard | tcg_gen_br(l2); |
2333 | 8e1c85e3 | bellard | |
2334 | 14ce26e7 | bellard | gen_set_label(l1); |
2335 | 14ce26e7 | bellard | gen_jmp_im(val); |
2336 | 14ce26e7 | bellard | gen_set_label(l2); |
2337 | 2c0262af | bellard | gen_eob(s); |
2338 | 2c0262af | bellard | } |
2339 | 2c0262af | bellard | } |
2340 | 2c0262af | bellard | |
2341 | 2c0262af | bellard | static void gen_setcc(DisasContext *s, int b) |
2342 | 2c0262af | bellard | { |
2343 | 8e1c85e3 | bellard | int inv, jcc_op, l1;
|
2344 | 1e4840bf | bellard | TCGv t0; |
2345 | 14ce26e7 | bellard | |
2346 | 8e1c85e3 | bellard | if (is_fast_jcc_case(s, b)) {
|
2347 | 8e1c85e3 | bellard | /* nominal case: we use a jump */
|
2348 | 1e4840bf | bellard | /* XXX: make it faster by adding new instructions in TCG */
|
2349 | a7812ae4 | pbrook | t0 = tcg_temp_local_new(); |
2350 | 1e4840bf | bellard | tcg_gen_movi_tl(t0, 0);
|
2351 | 8e1c85e3 | bellard | l1 = gen_new_label(); |
2352 | 8e1c85e3 | bellard | gen_jcc1(s, s->cc_op, b ^ 1, l1);
|
2353 | 1e4840bf | bellard | tcg_gen_movi_tl(t0, 1);
|
2354 | 8e1c85e3 | bellard | gen_set_label(l1); |
2355 | 1e4840bf | bellard | tcg_gen_mov_tl(cpu_T[0], t0);
|
2356 | 1e4840bf | bellard | tcg_temp_free(t0); |
2357 | 8e1c85e3 | bellard | } else {
|
2358 | 8e1c85e3 | bellard | /* slow case: it is more efficient not to generate a jump,
|
2359 | 8e1c85e3 | bellard | although it is questionnable whether this optimization is
|
2360 | 8e1c85e3 | bellard | worth to */
|
2361 | 8e1c85e3 | bellard | inv = b & 1;
|
2362 | 8e1c85e3 | bellard | jcc_op = (b >> 1) & 7; |
2363 | 1e4840bf | bellard | gen_setcc_slow_T0(s, jcc_op); |
2364 | 8e1c85e3 | bellard | if (inv) {
|
2365 | 8e1c85e3 | bellard | tcg_gen_xori_tl(cpu_T[0], cpu_T[0], 1); |
2366 | 8e1c85e3 | bellard | } |
2367 | 2c0262af | bellard | } |
2368 | 2c0262af | bellard | } |
2369 | 2c0262af | bellard | |
2370 | 3bd7da9e | bellard | static inline void gen_op_movl_T0_seg(int seg_reg) |
2371 | 3bd7da9e | bellard | { |
2372 | 3bd7da9e | bellard | tcg_gen_ld32u_tl(cpu_T[0], cpu_env,
|
2373 | 3bd7da9e | bellard | offsetof(CPUX86State,segs[seg_reg].selector)); |
2374 | 3bd7da9e | bellard | } |
2375 | 3bd7da9e | bellard | |
2376 | 3bd7da9e | bellard | static inline void gen_op_movl_seg_T0_vm(int seg_reg) |
2377 | 3bd7da9e | bellard | { |
2378 | 3bd7da9e | bellard | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0xffff); |
2379 | 3bd7da9e | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env,
|
2380 | 3bd7da9e | bellard | offsetof(CPUX86State,segs[seg_reg].selector)); |
2381 | 3bd7da9e | bellard | tcg_gen_shli_tl(cpu_T[0], cpu_T[0], 4); |
2382 | 3bd7da9e | bellard | tcg_gen_st_tl(cpu_T[0], cpu_env,
|
2383 | 3bd7da9e | bellard | offsetof(CPUX86State,segs[seg_reg].base)); |
2384 | 3bd7da9e | bellard | } |
2385 | 3bd7da9e | bellard | |
2386 | 2c0262af | bellard | /* move T0 to seg_reg and compute if the CPU state may change. Never
|
2387 | 2c0262af | bellard | call this function with seg_reg == R_CS */
|
2388 | 14ce26e7 | bellard | static void gen_movl_seg_T0(DisasContext *s, int seg_reg, target_ulong cur_eip) |
2389 | 2c0262af | bellard | { |
2390 | 3415a4dd | bellard | if (s->pe && !s->vm86) {
|
2391 | 3415a4dd | bellard | /* XXX: optimize by finding processor state dynamically */
|
2392 | 3415a4dd | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
2393 | 3415a4dd | bellard | gen_op_set_cc_op(s->cc_op); |
2394 | 14ce26e7 | bellard | gen_jmp_im(cur_eip); |
2395 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
2396 | a7812ae4 | pbrook | gen_helper_load_seg(tcg_const_i32(seg_reg), cpu_tmp2_i32); |
2397 | dc196a57 | bellard | /* abort translation because the addseg value may change or
|
2398 | dc196a57 | bellard | because ss32 may change. For R_SS, translation must always
|
2399 | dc196a57 | bellard | stop as a special handling must be done to disable hardware
|
2400 | dc196a57 | bellard | interrupts for the next instruction */
|
2401 | dc196a57 | bellard | if (seg_reg == R_SS || (s->code32 && seg_reg < R_FS))
|
2402 | dc196a57 | bellard | s->is_jmp = 3;
|
2403 | 3415a4dd | bellard | } else {
|
2404 | 3bd7da9e | bellard | gen_op_movl_seg_T0_vm(seg_reg); |
2405 | dc196a57 | bellard | if (seg_reg == R_SS)
|
2406 | dc196a57 | bellard | s->is_jmp = 3;
|
2407 | 3415a4dd | bellard | } |
2408 | 2c0262af | bellard | } |
2409 | 2c0262af | bellard | |
2410 | 0573fbfc | ths | static inline int svm_is_rep(int prefixes) |
2411 | 0573fbfc | ths | { |
2412 | 0573fbfc | ths | return ((prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) ? 8 : 0); |
2413 | 0573fbfc | ths | } |
2414 | 0573fbfc | ths | |
2415 | 872929aa | bellard | static inline void |
2416 | 0573fbfc | ths | gen_svm_check_intercept_param(DisasContext *s, target_ulong pc_start, |
2417 | b8b6a50b | bellard | uint32_t type, uint64_t param) |
2418 | 0573fbfc | ths | { |
2419 | 872929aa | bellard | /* no SVM activated; fast case */
|
2420 | 872929aa | bellard | if (likely(!(s->flags & HF_SVMI_MASK)))
|
2421 | 872929aa | bellard | return;
|
2422 | 872929aa | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
2423 | 872929aa | bellard | gen_op_set_cc_op(s->cc_op); |
2424 | 872929aa | bellard | gen_jmp_im(pc_start - s->cs_base); |
2425 | a7812ae4 | pbrook | gen_helper_svm_check_intercept_param(tcg_const_i32(type), |
2426 | a7812ae4 | pbrook | tcg_const_i64(param)); |
2427 | 0573fbfc | ths | } |
2428 | 0573fbfc | ths | |
2429 | 872929aa | bellard | static inline void |
2430 | 0573fbfc | ths | gen_svm_check_intercept(DisasContext *s, target_ulong pc_start, uint64_t type) |
2431 | 0573fbfc | ths | { |
2432 | 872929aa | bellard | gen_svm_check_intercept_param(s, pc_start, type, 0);
|
2433 | 0573fbfc | ths | } |
2434 | 0573fbfc | ths | |
2435 | 4f31916f | bellard | static inline void gen_stack_update(DisasContext *s, int addend) |
2436 | 4f31916f | bellard | { |
2437 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
2438 | 14ce26e7 | bellard | if (CODE64(s)) {
|
2439 | 6e0d8677 | bellard | gen_op_add_reg_im(2, R_ESP, addend);
|
2440 | 14ce26e7 | bellard | } else
|
2441 | 14ce26e7 | bellard | #endif
|
2442 | 4f31916f | bellard | if (s->ss32) {
|
2443 | 6e0d8677 | bellard | gen_op_add_reg_im(1, R_ESP, addend);
|
2444 | 4f31916f | bellard | } else {
|
2445 | 6e0d8677 | bellard | gen_op_add_reg_im(0, R_ESP, addend);
|
2446 | 4f31916f | bellard | } |
2447 | 4f31916f | bellard | } |
2448 | 4f31916f | bellard | |
2449 | 2c0262af | bellard | /* generate a push. It depends on ss32, addseg and dflag */
|
2450 | 2c0262af | bellard | static void gen_push_T0(DisasContext *s) |
2451 | 2c0262af | bellard | { |
2452 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
2453 | 14ce26e7 | bellard | if (CODE64(s)) {
|
2454 | 57fec1fe | bellard | gen_op_movq_A0_reg(R_ESP); |
2455 | 8f091a59 | bellard | if (s->dflag) {
|
2456 | 57fec1fe | bellard | gen_op_addq_A0_im(-8);
|
2457 | 57fec1fe | bellard | gen_op_st_T0_A0(OT_QUAD + s->mem_index); |
2458 | 8f091a59 | bellard | } else {
|
2459 | 57fec1fe | bellard | gen_op_addq_A0_im(-2);
|
2460 | 57fec1fe | bellard | gen_op_st_T0_A0(OT_WORD + s->mem_index); |
2461 | 8f091a59 | bellard | } |
2462 | 57fec1fe | bellard | gen_op_mov_reg_A0(2, R_ESP);
|
2463 | 5fafdf24 | ths | } else
|
2464 | 14ce26e7 | bellard | #endif
|
2465 | 14ce26e7 | bellard | { |
2466 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_ESP); |
2467 | 14ce26e7 | bellard | if (!s->dflag)
|
2468 | 57fec1fe | bellard | gen_op_addl_A0_im(-2);
|
2469 | 14ce26e7 | bellard | else
|
2470 | 57fec1fe | bellard | gen_op_addl_A0_im(-4);
|
2471 | 14ce26e7 | bellard | if (s->ss32) {
|
2472 | 14ce26e7 | bellard | if (s->addseg) {
|
2473 | bbf662ee | bellard | tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2474 | 57fec1fe | bellard | gen_op_addl_A0_seg(R_SS); |
2475 | 14ce26e7 | bellard | } |
2476 | 14ce26e7 | bellard | } else {
|
2477 | 14ce26e7 | bellard | gen_op_andl_A0_ffff(); |
2478 | bbf662ee | bellard | tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2479 | 57fec1fe | bellard | gen_op_addl_A0_seg(R_SS); |
2480 | 2c0262af | bellard | } |
2481 | 57fec1fe | bellard | gen_op_st_T0_A0(s->dflag + 1 + s->mem_index);
|
2482 | 14ce26e7 | bellard | if (s->ss32 && !s->addseg)
|
2483 | 57fec1fe | bellard | gen_op_mov_reg_A0(1, R_ESP);
|
2484 | 14ce26e7 | bellard | else
|
2485 | 57fec1fe | bellard | gen_op_mov_reg_T1(s->ss32 + 1, R_ESP);
|
2486 | 2c0262af | bellard | } |
2487 | 2c0262af | bellard | } |
2488 | 2c0262af | bellard | |
2489 | 4f31916f | bellard | /* generate a push. It depends on ss32, addseg and dflag */
|
2490 | 4f31916f | bellard | /* slower version for T1, only used for call Ev */
|
2491 | 4f31916f | bellard | static void gen_push_T1(DisasContext *s) |
2492 | 2c0262af | bellard | { |
2493 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
2494 | 14ce26e7 | bellard | if (CODE64(s)) {
|
2495 | 57fec1fe | bellard | gen_op_movq_A0_reg(R_ESP); |
2496 | 8f091a59 | bellard | if (s->dflag) {
|
2497 | 57fec1fe | bellard | gen_op_addq_A0_im(-8);
|
2498 | 57fec1fe | bellard | gen_op_st_T1_A0(OT_QUAD + s->mem_index); |
2499 | 8f091a59 | bellard | } else {
|
2500 | 57fec1fe | bellard | gen_op_addq_A0_im(-2);
|
2501 | 57fec1fe | bellard | gen_op_st_T0_A0(OT_WORD + s->mem_index); |
2502 | 8f091a59 | bellard | } |
2503 | 57fec1fe | bellard | gen_op_mov_reg_A0(2, R_ESP);
|
2504 | 5fafdf24 | ths | } else
|
2505 | 14ce26e7 | bellard | #endif
|
2506 | 14ce26e7 | bellard | { |
2507 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_ESP); |
2508 | 14ce26e7 | bellard | if (!s->dflag)
|
2509 | 57fec1fe | bellard | gen_op_addl_A0_im(-2);
|
2510 | 14ce26e7 | bellard | else
|
2511 | 57fec1fe | bellard | gen_op_addl_A0_im(-4);
|
2512 | 14ce26e7 | bellard | if (s->ss32) {
|
2513 | 14ce26e7 | bellard | if (s->addseg) {
|
2514 | 57fec1fe | bellard | gen_op_addl_A0_seg(R_SS); |
2515 | 14ce26e7 | bellard | } |
2516 | 14ce26e7 | bellard | } else {
|
2517 | 14ce26e7 | bellard | gen_op_andl_A0_ffff(); |
2518 | 57fec1fe | bellard | gen_op_addl_A0_seg(R_SS); |
2519 | 2c0262af | bellard | } |
2520 | 57fec1fe | bellard | gen_op_st_T1_A0(s->dflag + 1 + s->mem_index);
|
2521 | 3b46e624 | ths | |
2522 | 14ce26e7 | bellard | if (s->ss32 && !s->addseg)
|
2523 | 57fec1fe | bellard | gen_op_mov_reg_A0(1, R_ESP);
|
2524 | 14ce26e7 | bellard | else
|
2525 | 14ce26e7 | bellard | gen_stack_update(s, (-2) << s->dflag);
|
2526 | 2c0262af | bellard | } |
2527 | 2c0262af | bellard | } |
2528 | 2c0262af | bellard | |
2529 | 4f31916f | bellard | /* two step pop is necessary for precise exceptions */
|
2530 | 4f31916f | bellard | static void gen_pop_T0(DisasContext *s) |
2531 | 2c0262af | bellard | { |
2532 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
2533 | 14ce26e7 | bellard | if (CODE64(s)) {
|
2534 | 57fec1fe | bellard | gen_op_movq_A0_reg(R_ESP); |
2535 | 57fec1fe | bellard | gen_op_ld_T0_A0((s->dflag ? OT_QUAD : OT_WORD) + s->mem_index); |
2536 | 5fafdf24 | ths | } else
|
2537 | 14ce26e7 | bellard | #endif
|
2538 | 14ce26e7 | bellard | { |
2539 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_ESP); |
2540 | 14ce26e7 | bellard | if (s->ss32) {
|
2541 | 14ce26e7 | bellard | if (s->addseg)
|
2542 | 57fec1fe | bellard | gen_op_addl_A0_seg(R_SS); |
2543 | 14ce26e7 | bellard | } else {
|
2544 | 14ce26e7 | bellard | gen_op_andl_A0_ffff(); |
2545 | 57fec1fe | bellard | gen_op_addl_A0_seg(R_SS); |
2546 | 14ce26e7 | bellard | } |
2547 | 57fec1fe | bellard | gen_op_ld_T0_A0(s->dflag + 1 + s->mem_index);
|
2548 | 2c0262af | bellard | } |
2549 | 2c0262af | bellard | } |
2550 | 2c0262af | bellard | |
2551 | 2c0262af | bellard | static void gen_pop_update(DisasContext *s) |
2552 | 2c0262af | bellard | { |
2553 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
2554 | 8f091a59 | bellard | if (CODE64(s) && s->dflag) {
|
2555 | 14ce26e7 | bellard | gen_stack_update(s, 8);
|
2556 | 14ce26e7 | bellard | } else
|
2557 | 14ce26e7 | bellard | #endif
|
2558 | 14ce26e7 | bellard | { |
2559 | 14ce26e7 | bellard | gen_stack_update(s, 2 << s->dflag);
|
2560 | 14ce26e7 | bellard | } |
2561 | 2c0262af | bellard | } |
2562 | 2c0262af | bellard | |
2563 | 2c0262af | bellard | static void gen_stack_A0(DisasContext *s) |
2564 | 2c0262af | bellard | { |
2565 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_ESP); |
2566 | 2c0262af | bellard | if (!s->ss32)
|
2567 | 2c0262af | bellard | gen_op_andl_A0_ffff(); |
2568 | bbf662ee | bellard | tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2569 | 2c0262af | bellard | if (s->addseg)
|
2570 | 57fec1fe | bellard | gen_op_addl_A0_seg(R_SS); |
2571 | 2c0262af | bellard | } |
2572 | 2c0262af | bellard | |
2573 | 2c0262af | bellard | /* NOTE: wrap around in 16 bit not fully handled */
|
2574 | 2c0262af | bellard | static void gen_pusha(DisasContext *s) |
2575 | 2c0262af | bellard | { |
2576 | 2c0262af | bellard | int i;
|
2577 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_ESP); |
2578 | 2c0262af | bellard | gen_op_addl_A0_im(-16 << s->dflag);
|
2579 | 2c0262af | bellard | if (!s->ss32)
|
2580 | 2c0262af | bellard | gen_op_andl_A0_ffff(); |
2581 | bbf662ee | bellard | tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2582 | 2c0262af | bellard | if (s->addseg)
|
2583 | 57fec1fe | bellard | gen_op_addl_A0_seg(R_SS); |
2584 | 2c0262af | bellard | for(i = 0;i < 8; i++) { |
2585 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_LONG, 0, 7 - i); |
2586 | 57fec1fe | bellard | gen_op_st_T0_A0(OT_WORD + s->dflag + s->mem_index); |
2587 | 2c0262af | bellard | gen_op_addl_A0_im(2 << s->dflag);
|
2588 | 2c0262af | bellard | } |
2589 | 57fec1fe | bellard | gen_op_mov_reg_T1(OT_WORD + s->ss32, R_ESP); |
2590 | 2c0262af | bellard | } |
2591 | 2c0262af | bellard | |
2592 | 2c0262af | bellard | /* NOTE: wrap around in 16 bit not fully handled */
|
2593 | 2c0262af | bellard | static void gen_popa(DisasContext *s) |
2594 | 2c0262af | bellard | { |
2595 | 2c0262af | bellard | int i;
|
2596 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_ESP); |
2597 | 2c0262af | bellard | if (!s->ss32)
|
2598 | 2c0262af | bellard | gen_op_andl_A0_ffff(); |
2599 | bbf662ee | bellard | tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2600 | bbf662ee | bellard | tcg_gen_addi_tl(cpu_T[1], cpu_T[1], 16 << s->dflag); |
2601 | 2c0262af | bellard | if (s->addseg)
|
2602 | 57fec1fe | bellard | gen_op_addl_A0_seg(R_SS); |
2603 | 2c0262af | bellard | for(i = 0;i < 8; i++) { |
2604 | 2c0262af | bellard | /* ESP is not reloaded */
|
2605 | 2c0262af | bellard | if (i != 3) { |
2606 | 57fec1fe | bellard | gen_op_ld_T0_A0(OT_WORD + s->dflag + s->mem_index); |
2607 | 57fec1fe | bellard | gen_op_mov_reg_T0(OT_WORD + s->dflag, 7 - i);
|
2608 | 2c0262af | bellard | } |
2609 | 2c0262af | bellard | gen_op_addl_A0_im(2 << s->dflag);
|
2610 | 2c0262af | bellard | } |
2611 | 57fec1fe | bellard | gen_op_mov_reg_T1(OT_WORD + s->ss32, R_ESP); |
2612 | 2c0262af | bellard | } |
2613 | 2c0262af | bellard | |
2614 | 2c0262af | bellard | static void gen_enter(DisasContext *s, int esp_addend, int level) |
2615 | 2c0262af | bellard | { |
2616 | 61a8c4ec | bellard | int ot, opsize;
|
2617 | 2c0262af | bellard | |
2618 | 2c0262af | bellard | level &= 0x1f;
|
2619 | 8f091a59 | bellard | #ifdef TARGET_X86_64
|
2620 | 8f091a59 | bellard | if (CODE64(s)) {
|
2621 | 8f091a59 | bellard | ot = s->dflag ? OT_QUAD : OT_WORD; |
2622 | 8f091a59 | bellard | opsize = 1 << ot;
|
2623 | 3b46e624 | ths | |
2624 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_ESP); |
2625 | 8f091a59 | bellard | gen_op_addq_A0_im(-opsize); |
2626 | bbf662ee | bellard | tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2627 | 8f091a59 | bellard | |
2628 | 8f091a59 | bellard | /* push bp */
|
2629 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_LONG, 0, R_EBP);
|
2630 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
2631 | 8f091a59 | bellard | if (level) {
|
2632 | b5b38f61 | bellard | /* XXX: must save state */
|
2633 | a7812ae4 | pbrook | gen_helper_enter64_level(tcg_const_i32(level), |
2634 | a7812ae4 | pbrook | tcg_const_i32((ot == OT_QUAD)), |
2635 | a7812ae4 | pbrook | cpu_T[1]);
|
2636 | 8f091a59 | bellard | } |
2637 | 57fec1fe | bellard | gen_op_mov_reg_T1(ot, R_EBP); |
2638 | bbf662ee | bellard | tcg_gen_addi_tl(cpu_T[1], cpu_T[1], -esp_addend + (-opsize * level)); |
2639 | 57fec1fe | bellard | gen_op_mov_reg_T1(OT_QUAD, R_ESP); |
2640 | 5fafdf24 | ths | } else
|
2641 | 8f091a59 | bellard | #endif
|
2642 | 8f091a59 | bellard | { |
2643 | 8f091a59 | bellard | ot = s->dflag + OT_WORD; |
2644 | 8f091a59 | bellard | opsize = 2 << s->dflag;
|
2645 | 3b46e624 | ths | |
2646 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_ESP); |
2647 | 8f091a59 | bellard | gen_op_addl_A0_im(-opsize); |
2648 | 8f091a59 | bellard | if (!s->ss32)
|
2649 | 8f091a59 | bellard | gen_op_andl_A0_ffff(); |
2650 | bbf662ee | bellard | tcg_gen_mov_tl(cpu_T[1], cpu_A0);
|
2651 | 8f091a59 | bellard | if (s->addseg)
|
2652 | 57fec1fe | bellard | gen_op_addl_A0_seg(R_SS); |
2653 | 8f091a59 | bellard | /* push bp */
|
2654 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_LONG, 0, R_EBP);
|
2655 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
2656 | 8f091a59 | bellard | if (level) {
|
2657 | b5b38f61 | bellard | /* XXX: must save state */
|
2658 | a7812ae4 | pbrook | gen_helper_enter_level(tcg_const_i32(level), |
2659 | a7812ae4 | pbrook | tcg_const_i32(s->dflag), |
2660 | a7812ae4 | pbrook | cpu_T[1]);
|
2661 | 8f091a59 | bellard | } |
2662 | 57fec1fe | bellard | gen_op_mov_reg_T1(ot, R_EBP); |
2663 | bbf662ee | bellard | tcg_gen_addi_tl(cpu_T[1], cpu_T[1], -esp_addend + (-opsize * level)); |
2664 | 57fec1fe | bellard | gen_op_mov_reg_T1(OT_WORD + s->ss32, R_ESP); |
2665 | 2c0262af | bellard | } |
2666 | 2c0262af | bellard | } |
2667 | 2c0262af | bellard | |
2668 | 14ce26e7 | bellard | static void gen_exception(DisasContext *s, int trapno, target_ulong cur_eip) |
2669 | 2c0262af | bellard | { |
2670 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
2671 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
2672 | 14ce26e7 | bellard | gen_jmp_im(cur_eip); |
2673 | a7812ae4 | pbrook | gen_helper_raise_exception(tcg_const_i32(trapno)); |
2674 | 2c0262af | bellard | s->is_jmp = 3;
|
2675 | 2c0262af | bellard | } |
2676 | 2c0262af | bellard | |
2677 | 2c0262af | bellard | /* an interrupt is different from an exception because of the
|
2678 | 7f75ffd3 | blueswir1 | privilege checks */
|
2679 | 5fafdf24 | ths | static void gen_interrupt(DisasContext *s, int intno, |
2680 | 14ce26e7 | bellard | target_ulong cur_eip, target_ulong next_eip) |
2681 | 2c0262af | bellard | { |
2682 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
2683 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
2684 | 14ce26e7 | bellard | gen_jmp_im(cur_eip); |
2685 | a7812ae4 | pbrook | gen_helper_raise_interrupt(tcg_const_i32(intno), |
2686 | a7812ae4 | pbrook | tcg_const_i32(next_eip - cur_eip)); |
2687 | 2c0262af | bellard | s->is_jmp = 3;
|
2688 | 2c0262af | bellard | } |
2689 | 2c0262af | bellard | |
2690 | 14ce26e7 | bellard | static void gen_debug(DisasContext *s, target_ulong cur_eip) |
2691 | 2c0262af | bellard | { |
2692 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
2693 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
2694 | 14ce26e7 | bellard | gen_jmp_im(cur_eip); |
2695 | a7812ae4 | pbrook | gen_helper_debug(); |
2696 | 2c0262af | bellard | s->is_jmp = 3;
|
2697 | 2c0262af | bellard | } |
2698 | 2c0262af | bellard | |
2699 | 2c0262af | bellard | /* generate a generic end of block. Trace exception is also generated
|
2700 | 2c0262af | bellard | if needed */
|
2701 | 2c0262af | bellard | static void gen_eob(DisasContext *s) |
2702 | 2c0262af | bellard | { |
2703 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
2704 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
2705 | a2cc3b24 | bellard | if (s->tb->flags & HF_INHIBIT_IRQ_MASK) {
|
2706 | a7812ae4 | pbrook | gen_helper_reset_inhibit_irq(); |
2707 | a2cc3b24 | bellard | } |
2708 | 34865134 | bellard | if (s->singlestep_enabled) {
|
2709 | a7812ae4 | pbrook | gen_helper_debug(); |
2710 | 34865134 | bellard | } else if (s->tf) { |
2711 | a7812ae4 | pbrook | gen_helper_single_step(); |
2712 | 2c0262af | bellard | } else {
|
2713 | 57fec1fe | bellard | tcg_gen_exit_tb(0);
|
2714 | 2c0262af | bellard | } |
2715 | 2c0262af | bellard | s->is_jmp = 3;
|
2716 | 2c0262af | bellard | } |
2717 | 2c0262af | bellard | |
2718 | 2c0262af | bellard | /* generate a jump to eip. No segment change must happen before as a
|
2719 | 2c0262af | bellard | direct call to the next block may occur */
|
2720 | 14ce26e7 | bellard | static void gen_jmp_tb(DisasContext *s, target_ulong eip, int tb_num) |
2721 | 2c0262af | bellard | { |
2722 | 2c0262af | bellard | if (s->jmp_opt) {
|
2723 | 6e256c93 | bellard | if (s->cc_op != CC_OP_DYNAMIC) {
|
2724 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
2725 | 6e256c93 | bellard | s->cc_op = CC_OP_DYNAMIC; |
2726 | 6e256c93 | bellard | } |
2727 | 6e256c93 | bellard | gen_goto_tb(s, tb_num, eip); |
2728 | 2c0262af | bellard | s->is_jmp = 3;
|
2729 | 2c0262af | bellard | } else {
|
2730 | 14ce26e7 | bellard | gen_jmp_im(eip); |
2731 | 2c0262af | bellard | gen_eob(s); |
2732 | 2c0262af | bellard | } |
2733 | 2c0262af | bellard | } |
2734 | 2c0262af | bellard | |
2735 | 14ce26e7 | bellard | static void gen_jmp(DisasContext *s, target_ulong eip) |
2736 | 14ce26e7 | bellard | { |
2737 | 14ce26e7 | bellard | gen_jmp_tb(s, eip, 0);
|
2738 | 14ce26e7 | bellard | } |
2739 | 14ce26e7 | bellard | |
2740 | 8686c490 | bellard | static inline void gen_ldq_env_A0(int idx, int offset) |
2741 | 8686c490 | bellard | { |
2742 | 8686c490 | bellard | int mem_index = (idx >> 2) - 1; |
2743 | b6abf97d | bellard | tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_A0, mem_index); |
2744 | b6abf97d | bellard | tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, offset); |
2745 | 8686c490 | bellard | } |
2746 | 664e0f19 | bellard | |
2747 | 8686c490 | bellard | static inline void gen_stq_env_A0(int idx, int offset) |
2748 | 8686c490 | bellard | { |
2749 | 8686c490 | bellard | int mem_index = (idx >> 2) - 1; |
2750 | b6abf97d | bellard | tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, offset); |
2751 | b6abf97d | bellard | tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_A0, mem_index); |
2752 | 8686c490 | bellard | } |
2753 | 664e0f19 | bellard | |
2754 | 8686c490 | bellard | static inline void gen_ldo_env_A0(int idx, int offset) |
2755 | 8686c490 | bellard | { |
2756 | 8686c490 | bellard | int mem_index = (idx >> 2) - 1; |
2757 | b6abf97d | bellard | tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_A0, mem_index); |
2758 | b6abf97d | bellard | tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, offset + offsetof(XMMReg, XMM_Q(0)));
|
2759 | 8686c490 | bellard | tcg_gen_addi_tl(cpu_tmp0, cpu_A0, 8);
|
2760 | b6abf97d | bellard | tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_tmp0, mem_index); |
2761 | b6abf97d | bellard | tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, offset + offsetof(XMMReg, XMM_Q(1)));
|
2762 | 8686c490 | bellard | } |
2763 | 14ce26e7 | bellard | |
2764 | 8686c490 | bellard | static inline void gen_sto_env_A0(int idx, int offset) |
2765 | 8686c490 | bellard | { |
2766 | 8686c490 | bellard | int mem_index = (idx >> 2) - 1; |
2767 | b6abf97d | bellard | tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, offset + offsetof(XMMReg, XMM_Q(0)));
|
2768 | b6abf97d | bellard | tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_A0, mem_index); |
2769 | 8686c490 | bellard | tcg_gen_addi_tl(cpu_tmp0, cpu_A0, 8);
|
2770 | b6abf97d | bellard | tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, offset + offsetof(XMMReg, XMM_Q(1)));
|
2771 | b6abf97d | bellard | tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_tmp0, mem_index); |
2772 | 8686c490 | bellard | } |
2773 | 14ce26e7 | bellard | |
2774 | 5af45186 | bellard | static inline void gen_op_movo(int d_offset, int s_offset) |
2775 | 5af45186 | bellard | { |
2776 | b6abf97d | bellard | tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, s_offset); |
2777 | b6abf97d | bellard | tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, d_offset); |
2778 | b6abf97d | bellard | tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, s_offset + 8);
|
2779 | b6abf97d | bellard | tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, d_offset + 8);
|
2780 | 5af45186 | bellard | } |
2781 | 5af45186 | bellard | |
2782 | 5af45186 | bellard | static inline void gen_op_movq(int d_offset, int s_offset) |
2783 | 5af45186 | bellard | { |
2784 | b6abf97d | bellard | tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, s_offset); |
2785 | b6abf97d | bellard | tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, d_offset); |
2786 | 5af45186 | bellard | } |
2787 | 5af45186 | bellard | |
2788 | 5af45186 | bellard | static inline void gen_op_movl(int d_offset, int s_offset) |
2789 | 5af45186 | bellard | { |
2790 | b6abf97d | bellard | tcg_gen_ld_i32(cpu_tmp2_i32, cpu_env, s_offset); |
2791 | b6abf97d | bellard | tcg_gen_st_i32(cpu_tmp2_i32, cpu_env, d_offset); |
2792 | 5af45186 | bellard | } |
2793 | 5af45186 | bellard | |
2794 | 5af45186 | bellard | static inline void gen_op_movq_env_0(int d_offset) |
2795 | 5af45186 | bellard | { |
2796 | b6abf97d | bellard | tcg_gen_movi_i64(cpu_tmp1_i64, 0);
|
2797 | b6abf97d | bellard | tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, d_offset); |
2798 | 5af45186 | bellard | } |
2799 | 664e0f19 | bellard | |
2800 | 5af45186 | bellard | #define SSE_SPECIAL ((void *)1) |
2801 | 5af45186 | bellard | #define SSE_DUMMY ((void *)2) |
2802 | 664e0f19 | bellard | |
2803 | a7812ae4 | pbrook | #define MMX_OP2(x) { gen_helper_ ## x ## _mmx, gen_helper_ ## x ## _xmm } |
2804 | a7812ae4 | pbrook | #define SSE_FOP(x) { gen_helper_ ## x ## ps, gen_helper_ ## x ## pd, \ |
2805 | a7812ae4 | pbrook | gen_helper_ ## x ## ss, gen_helper_ ## x ## sd, } |
2806 | 5af45186 | bellard | |
2807 | 5af45186 | bellard | static void *sse_op_table1[256][4] = { |
2808 | a35f3ec7 | aurel32 | /* 3DNow! extensions */
|
2809 | a35f3ec7 | aurel32 | [0x0e] = { SSE_DUMMY }, /* femms */ |
2810 | a35f3ec7 | aurel32 | [0x0f] = { SSE_DUMMY }, /* pf... */ |
2811 | 664e0f19 | bellard | /* pure SSE operations */
|
2812 | 664e0f19 | bellard | [0x10] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movups, movupd, movss, movsd */ |
2813 | 664e0f19 | bellard | [0x11] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movups, movupd, movss, movsd */ |
2814 | 465e9838 | bellard | [0x12] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movlps, movlpd, movsldup, movddup */ |
2815 | 664e0f19 | bellard | [0x13] = { SSE_SPECIAL, SSE_SPECIAL }, /* movlps, movlpd */ |
2816 | a7812ae4 | pbrook | [0x14] = { gen_helper_punpckldq_xmm, gen_helper_punpcklqdq_xmm },
|
2817 | a7812ae4 | pbrook | [0x15] = { gen_helper_punpckhdq_xmm, gen_helper_punpckhqdq_xmm },
|
2818 | 664e0f19 | bellard | [0x16] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movhps, movhpd, movshdup */ |
2819 | 664e0f19 | bellard | [0x17] = { SSE_SPECIAL, SSE_SPECIAL }, /* movhps, movhpd */ |
2820 | 664e0f19 | bellard | |
2821 | 664e0f19 | bellard | [0x28] = { SSE_SPECIAL, SSE_SPECIAL }, /* movaps, movapd */ |
2822 | 664e0f19 | bellard | [0x29] = { SSE_SPECIAL, SSE_SPECIAL }, /* movaps, movapd */ |
2823 | 664e0f19 | bellard | [0x2a] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* cvtpi2ps, cvtpi2pd, cvtsi2ss, cvtsi2sd */ |
2824 | 664e0f19 | bellard | [0x2b] = { SSE_SPECIAL, SSE_SPECIAL }, /* movntps, movntpd */ |
2825 | 664e0f19 | bellard | [0x2c] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* cvttps2pi, cvttpd2pi, cvttsd2si, cvttss2si */ |
2826 | 664e0f19 | bellard | [0x2d] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* cvtps2pi, cvtpd2pi, cvtsd2si, cvtss2si */ |
2827 | a7812ae4 | pbrook | [0x2e] = { gen_helper_ucomiss, gen_helper_ucomisd },
|
2828 | a7812ae4 | pbrook | [0x2f] = { gen_helper_comiss, gen_helper_comisd },
|
2829 | 664e0f19 | bellard | [0x50] = { SSE_SPECIAL, SSE_SPECIAL }, /* movmskps, movmskpd */ |
2830 | 664e0f19 | bellard | [0x51] = SSE_FOP(sqrt),
|
2831 | a7812ae4 | pbrook | [0x52] = { gen_helper_rsqrtps, NULL, gen_helper_rsqrtss, NULL }, |
2832 | a7812ae4 | pbrook | [0x53] = { gen_helper_rcpps, NULL, gen_helper_rcpss, NULL }, |
2833 | a7812ae4 | pbrook | [0x54] = { gen_helper_pand_xmm, gen_helper_pand_xmm }, /* andps, andpd */ |
2834 | a7812ae4 | pbrook | [0x55] = { gen_helper_pandn_xmm, gen_helper_pandn_xmm }, /* andnps, andnpd */ |
2835 | a7812ae4 | pbrook | [0x56] = { gen_helper_por_xmm, gen_helper_por_xmm }, /* orps, orpd */ |
2836 | a7812ae4 | pbrook | [0x57] = { gen_helper_pxor_xmm, gen_helper_pxor_xmm }, /* xorps, xorpd */ |
2837 | 664e0f19 | bellard | [0x58] = SSE_FOP(add),
|
2838 | 664e0f19 | bellard | [0x59] = SSE_FOP(mul),
|
2839 | a7812ae4 | pbrook | [0x5a] = { gen_helper_cvtps2pd, gen_helper_cvtpd2ps,
|
2840 | a7812ae4 | pbrook | gen_helper_cvtss2sd, gen_helper_cvtsd2ss }, |
2841 | a7812ae4 | pbrook | [0x5b] = { gen_helper_cvtdq2ps, gen_helper_cvtps2dq, gen_helper_cvttps2dq },
|
2842 | 664e0f19 | bellard | [0x5c] = SSE_FOP(sub),
|
2843 | 664e0f19 | bellard | [0x5d] = SSE_FOP(min),
|
2844 | 664e0f19 | bellard | [0x5e] = SSE_FOP(div),
|
2845 | 664e0f19 | bellard | [0x5f] = SSE_FOP(max),
|
2846 | 664e0f19 | bellard | |
2847 | 664e0f19 | bellard | [0xc2] = SSE_FOP(cmpeq),
|
2848 | a7812ae4 | pbrook | [0xc6] = { gen_helper_shufps, gen_helper_shufpd },
|
2849 | 664e0f19 | bellard | |
2850 | 222a3336 | balrog | [0x38] = { SSE_SPECIAL, SSE_SPECIAL, NULL, SSE_SPECIAL }, /* SSSE3/SSE4 */ |
2851 | 222a3336 | balrog | [0x3a] = { SSE_SPECIAL, SSE_SPECIAL }, /* SSSE3/SSE4 */ |
2852 | 4242b1bd | balrog | |
2853 | 664e0f19 | bellard | /* MMX ops and their SSE extensions */
|
2854 | 664e0f19 | bellard | [0x60] = MMX_OP2(punpcklbw),
|
2855 | 664e0f19 | bellard | [0x61] = MMX_OP2(punpcklwd),
|
2856 | 664e0f19 | bellard | [0x62] = MMX_OP2(punpckldq),
|
2857 | 664e0f19 | bellard | [0x63] = MMX_OP2(packsswb),
|
2858 | 664e0f19 | bellard | [0x64] = MMX_OP2(pcmpgtb),
|
2859 | 664e0f19 | bellard | [0x65] = MMX_OP2(pcmpgtw),
|
2860 | 664e0f19 | bellard | [0x66] = MMX_OP2(pcmpgtl),
|
2861 | 664e0f19 | bellard | [0x67] = MMX_OP2(packuswb),
|
2862 | 664e0f19 | bellard | [0x68] = MMX_OP2(punpckhbw),
|
2863 | 664e0f19 | bellard | [0x69] = MMX_OP2(punpckhwd),
|
2864 | 664e0f19 | bellard | [0x6a] = MMX_OP2(punpckhdq),
|
2865 | 664e0f19 | bellard | [0x6b] = MMX_OP2(packssdw),
|
2866 | a7812ae4 | pbrook | [0x6c] = { NULL, gen_helper_punpcklqdq_xmm }, |
2867 | a7812ae4 | pbrook | [0x6d] = { NULL, gen_helper_punpckhqdq_xmm }, |
2868 | 664e0f19 | bellard | [0x6e] = { SSE_SPECIAL, SSE_SPECIAL }, /* movd mm, ea */ |
2869 | 664e0f19 | bellard | [0x6f] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movq, movdqa, , movqdu */ |
2870 | a7812ae4 | pbrook | [0x70] = { gen_helper_pshufw_mmx,
|
2871 | a7812ae4 | pbrook | gen_helper_pshufd_xmm, |
2872 | a7812ae4 | pbrook | gen_helper_pshufhw_xmm, |
2873 | a7812ae4 | pbrook | gen_helper_pshuflw_xmm }, |
2874 | 664e0f19 | bellard | [0x71] = { SSE_SPECIAL, SSE_SPECIAL }, /* shiftw */ |
2875 | 664e0f19 | bellard | [0x72] = { SSE_SPECIAL, SSE_SPECIAL }, /* shiftd */ |
2876 | 664e0f19 | bellard | [0x73] = { SSE_SPECIAL, SSE_SPECIAL }, /* shiftq */ |
2877 | 664e0f19 | bellard | [0x74] = MMX_OP2(pcmpeqb),
|
2878 | 664e0f19 | bellard | [0x75] = MMX_OP2(pcmpeqw),
|
2879 | 664e0f19 | bellard | [0x76] = MMX_OP2(pcmpeql),
|
2880 | a35f3ec7 | aurel32 | [0x77] = { SSE_DUMMY }, /* emms */ |
2881 | a7812ae4 | pbrook | [0x7c] = { NULL, gen_helper_haddpd, NULL, gen_helper_haddps }, |
2882 | a7812ae4 | pbrook | [0x7d] = { NULL, gen_helper_hsubpd, NULL, gen_helper_hsubps }, |
2883 | 664e0f19 | bellard | [0x7e] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movd, movd, , movq */ |
2884 | 664e0f19 | bellard | [0x7f] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movq, movdqa, movdqu */ |
2885 | 664e0f19 | bellard | [0xc4] = { SSE_SPECIAL, SSE_SPECIAL }, /* pinsrw */ |
2886 | 664e0f19 | bellard | [0xc5] = { SSE_SPECIAL, SSE_SPECIAL }, /* pextrw */ |
2887 | a7812ae4 | pbrook | [0xd0] = { NULL, gen_helper_addsubpd, NULL, gen_helper_addsubps }, |
2888 | 664e0f19 | bellard | [0xd1] = MMX_OP2(psrlw),
|
2889 | 664e0f19 | bellard | [0xd2] = MMX_OP2(psrld),
|
2890 | 664e0f19 | bellard | [0xd3] = MMX_OP2(psrlq),
|
2891 | 664e0f19 | bellard | [0xd4] = MMX_OP2(paddq),
|
2892 | 664e0f19 | bellard | [0xd5] = MMX_OP2(pmullw),
|
2893 | 664e0f19 | bellard | [0xd6] = { NULL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, |
2894 | 664e0f19 | bellard | [0xd7] = { SSE_SPECIAL, SSE_SPECIAL }, /* pmovmskb */ |
2895 | 664e0f19 | bellard | [0xd8] = MMX_OP2(psubusb),
|
2896 | 664e0f19 | bellard | [0xd9] = MMX_OP2(psubusw),
|
2897 | 664e0f19 | bellard | [0xda] = MMX_OP2(pminub),
|
2898 | 664e0f19 | bellard | [0xdb] = MMX_OP2(pand),
|
2899 | 664e0f19 | bellard | [0xdc] = MMX_OP2(paddusb),
|
2900 | 664e0f19 | bellard | [0xdd] = MMX_OP2(paddusw),
|
2901 | 664e0f19 | bellard | [0xde] = MMX_OP2(pmaxub),
|
2902 | 664e0f19 | bellard | [0xdf] = MMX_OP2(pandn),
|
2903 | 664e0f19 | bellard | [0xe0] = MMX_OP2(pavgb),
|
2904 | 664e0f19 | bellard | [0xe1] = MMX_OP2(psraw),
|
2905 | 664e0f19 | bellard | [0xe2] = MMX_OP2(psrad),
|
2906 | 664e0f19 | bellard | [0xe3] = MMX_OP2(pavgw),
|
2907 | 664e0f19 | bellard | [0xe4] = MMX_OP2(pmulhuw),
|
2908 | 664e0f19 | bellard | [0xe5] = MMX_OP2(pmulhw),
|
2909 | a7812ae4 | pbrook | [0xe6] = { NULL, gen_helper_cvttpd2dq, gen_helper_cvtdq2pd, gen_helper_cvtpd2dq }, |
2910 | 664e0f19 | bellard | [0xe7] = { SSE_SPECIAL , SSE_SPECIAL }, /* movntq, movntq */ |
2911 | 664e0f19 | bellard | [0xe8] = MMX_OP2(psubsb),
|
2912 | 664e0f19 | bellard | [0xe9] = MMX_OP2(psubsw),
|
2913 | 664e0f19 | bellard | [0xea] = MMX_OP2(pminsw),
|
2914 | 664e0f19 | bellard | [0xeb] = MMX_OP2(por),
|
2915 | 664e0f19 | bellard | [0xec] = MMX_OP2(paddsb),
|
2916 | 664e0f19 | bellard | [0xed] = MMX_OP2(paddsw),
|
2917 | 664e0f19 | bellard | [0xee] = MMX_OP2(pmaxsw),
|
2918 | 664e0f19 | bellard | [0xef] = MMX_OP2(pxor),
|
2919 | 465e9838 | bellard | [0xf0] = { NULL, NULL, NULL, SSE_SPECIAL }, /* lddqu */ |
2920 | 664e0f19 | bellard | [0xf1] = MMX_OP2(psllw),
|
2921 | 664e0f19 | bellard | [0xf2] = MMX_OP2(pslld),
|
2922 | 664e0f19 | bellard | [0xf3] = MMX_OP2(psllq),
|
2923 | 664e0f19 | bellard | [0xf4] = MMX_OP2(pmuludq),
|
2924 | 664e0f19 | bellard | [0xf5] = MMX_OP2(pmaddwd),
|
2925 | 664e0f19 | bellard | [0xf6] = MMX_OP2(psadbw),
|
2926 | 664e0f19 | bellard | [0xf7] = MMX_OP2(maskmov),
|
2927 | 664e0f19 | bellard | [0xf8] = MMX_OP2(psubb),
|
2928 | 664e0f19 | bellard | [0xf9] = MMX_OP2(psubw),
|
2929 | 664e0f19 | bellard | [0xfa] = MMX_OP2(psubl),
|
2930 | 664e0f19 | bellard | [0xfb] = MMX_OP2(psubq),
|
2931 | 664e0f19 | bellard | [0xfc] = MMX_OP2(paddb),
|
2932 | 664e0f19 | bellard | [0xfd] = MMX_OP2(paddw),
|
2933 | 664e0f19 | bellard | [0xfe] = MMX_OP2(paddl),
|
2934 | 664e0f19 | bellard | }; |
2935 | 664e0f19 | bellard | |
2936 | 5af45186 | bellard | static void *sse_op_table2[3 * 8][2] = { |
2937 | 664e0f19 | bellard | [0 + 2] = MMX_OP2(psrlw), |
2938 | 664e0f19 | bellard | [0 + 4] = MMX_OP2(psraw), |
2939 | 664e0f19 | bellard | [0 + 6] = MMX_OP2(psllw), |
2940 | 664e0f19 | bellard | [8 + 2] = MMX_OP2(psrld), |
2941 | 664e0f19 | bellard | [8 + 4] = MMX_OP2(psrad), |
2942 | 664e0f19 | bellard | [8 + 6] = MMX_OP2(pslld), |
2943 | 664e0f19 | bellard | [16 + 2] = MMX_OP2(psrlq), |
2944 | a7812ae4 | pbrook | [16 + 3] = { NULL, gen_helper_psrldq_xmm }, |
2945 | 664e0f19 | bellard | [16 + 6] = MMX_OP2(psllq), |
2946 | a7812ae4 | pbrook | [16 + 7] = { NULL, gen_helper_pslldq_xmm }, |
2947 | 664e0f19 | bellard | }; |
2948 | 664e0f19 | bellard | |
2949 | 5af45186 | bellard | static void *sse_op_table3[4 * 3] = { |
2950 | a7812ae4 | pbrook | gen_helper_cvtsi2ss, |
2951 | a7812ae4 | pbrook | gen_helper_cvtsi2sd, |
2952 | a7812ae4 | pbrook | X86_64_ONLY(gen_helper_cvtsq2ss), |
2953 | a7812ae4 | pbrook | X86_64_ONLY(gen_helper_cvtsq2sd), |
2954 | a7812ae4 | pbrook | |
2955 | a7812ae4 | pbrook | gen_helper_cvttss2si, |
2956 | a7812ae4 | pbrook | gen_helper_cvttsd2si, |
2957 | a7812ae4 | pbrook | X86_64_ONLY(gen_helper_cvttss2sq), |
2958 | a7812ae4 | pbrook | X86_64_ONLY(gen_helper_cvttsd2sq), |
2959 | a7812ae4 | pbrook | |
2960 | a7812ae4 | pbrook | gen_helper_cvtss2si, |
2961 | a7812ae4 | pbrook | gen_helper_cvtsd2si, |
2962 | a7812ae4 | pbrook | X86_64_ONLY(gen_helper_cvtss2sq), |
2963 | a7812ae4 | pbrook | X86_64_ONLY(gen_helper_cvtsd2sq), |
2964 | 664e0f19 | bellard | }; |
2965 | 3b46e624 | ths | |
2966 | 5af45186 | bellard | static void *sse_op_table4[8][4] = { |
2967 | 664e0f19 | bellard | SSE_FOP(cmpeq), |
2968 | 664e0f19 | bellard | SSE_FOP(cmplt), |
2969 | 664e0f19 | bellard | SSE_FOP(cmple), |
2970 | 664e0f19 | bellard | SSE_FOP(cmpunord), |
2971 | 664e0f19 | bellard | SSE_FOP(cmpneq), |
2972 | 664e0f19 | bellard | SSE_FOP(cmpnlt), |
2973 | 664e0f19 | bellard | SSE_FOP(cmpnle), |
2974 | 664e0f19 | bellard | SSE_FOP(cmpord), |
2975 | 664e0f19 | bellard | }; |
2976 | 3b46e624 | ths | |
2977 | 5af45186 | bellard | static void *sse_op_table5[256] = { |
2978 | a7812ae4 | pbrook | [0x0c] = gen_helper_pi2fw,
|
2979 | a7812ae4 | pbrook | [0x0d] = gen_helper_pi2fd,
|
2980 | a7812ae4 | pbrook | [0x1c] = gen_helper_pf2iw,
|
2981 | a7812ae4 | pbrook | [0x1d] = gen_helper_pf2id,
|
2982 | a7812ae4 | pbrook | [0x8a] = gen_helper_pfnacc,
|
2983 | a7812ae4 | pbrook | [0x8e] = gen_helper_pfpnacc,
|
2984 | a7812ae4 | pbrook | [0x90] = gen_helper_pfcmpge,
|
2985 | a7812ae4 | pbrook | [0x94] = gen_helper_pfmin,
|
2986 | a7812ae4 | pbrook | [0x96] = gen_helper_pfrcp,
|
2987 | a7812ae4 | pbrook | [0x97] = gen_helper_pfrsqrt,
|
2988 | a7812ae4 | pbrook | [0x9a] = gen_helper_pfsub,
|
2989 | a7812ae4 | pbrook | [0x9e] = gen_helper_pfadd,
|
2990 | a7812ae4 | pbrook | [0xa0] = gen_helper_pfcmpgt,
|
2991 | a7812ae4 | pbrook | [0xa4] = gen_helper_pfmax,
|
2992 | a7812ae4 | pbrook | [0xa6] = gen_helper_movq, /* pfrcpit1; no need to actually increase precision */ |
2993 | a7812ae4 | pbrook | [0xa7] = gen_helper_movq, /* pfrsqit1 */ |
2994 | a7812ae4 | pbrook | [0xaa] = gen_helper_pfsubr,
|
2995 | a7812ae4 | pbrook | [0xae] = gen_helper_pfacc,
|
2996 | a7812ae4 | pbrook | [0xb0] = gen_helper_pfcmpeq,
|
2997 | a7812ae4 | pbrook | [0xb4] = gen_helper_pfmul,
|
2998 | a7812ae4 | pbrook | [0xb6] = gen_helper_movq, /* pfrcpit2 */ |
2999 | a7812ae4 | pbrook | [0xb7] = gen_helper_pmulhrw_mmx,
|
3000 | a7812ae4 | pbrook | [0xbb] = gen_helper_pswapd,
|
3001 | a7812ae4 | pbrook | [0xbf] = gen_helper_pavgb_mmx /* pavgusb */ |
3002 | a35f3ec7 | aurel32 | }; |
3003 | a35f3ec7 | aurel32 | |
3004 | 222a3336 | balrog | struct sse_op_helper_s {
|
3005 | 222a3336 | balrog | void *op[2]; uint32_t ext_mask; |
3006 | 222a3336 | balrog | }; |
3007 | 222a3336 | balrog | #define SSSE3_OP(x) { MMX_OP2(x), CPUID_EXT_SSSE3 }
|
3008 | a7812ae4 | pbrook | #define SSE41_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE41 } |
3009 | a7812ae4 | pbrook | #define SSE42_OP(x) { { NULL, gen_helper_ ## x ## _xmm }, CPUID_EXT_SSE42 } |
3010 | 222a3336 | balrog | #define SSE41_SPECIAL { { NULL, SSE_SPECIAL }, CPUID_EXT_SSE41 } |
3011 | 222a3336 | balrog | static struct sse_op_helper_s sse_op_table6[256] = { |
3012 | 222a3336 | balrog | [0x00] = SSSE3_OP(pshufb),
|
3013 | 222a3336 | balrog | [0x01] = SSSE3_OP(phaddw),
|
3014 | 222a3336 | balrog | [0x02] = SSSE3_OP(phaddd),
|
3015 | 222a3336 | balrog | [0x03] = SSSE3_OP(phaddsw),
|
3016 | 222a3336 | balrog | [0x04] = SSSE3_OP(pmaddubsw),
|
3017 | 222a3336 | balrog | [0x05] = SSSE3_OP(phsubw),
|
3018 | 222a3336 | balrog | [0x06] = SSSE3_OP(phsubd),
|
3019 | 222a3336 | balrog | [0x07] = SSSE3_OP(phsubsw),
|
3020 | 222a3336 | balrog | [0x08] = SSSE3_OP(psignb),
|
3021 | 222a3336 | balrog | [0x09] = SSSE3_OP(psignw),
|
3022 | 222a3336 | balrog | [0x0a] = SSSE3_OP(psignd),
|
3023 | 222a3336 | balrog | [0x0b] = SSSE3_OP(pmulhrsw),
|
3024 | 222a3336 | balrog | [0x10] = SSE41_OP(pblendvb),
|
3025 | 222a3336 | balrog | [0x14] = SSE41_OP(blendvps),
|
3026 | 222a3336 | balrog | [0x15] = SSE41_OP(blendvpd),
|
3027 | 222a3336 | balrog | [0x17] = SSE41_OP(ptest),
|
3028 | 222a3336 | balrog | [0x1c] = SSSE3_OP(pabsb),
|
3029 | 222a3336 | balrog | [0x1d] = SSSE3_OP(pabsw),
|
3030 | 222a3336 | balrog | [0x1e] = SSSE3_OP(pabsd),
|
3031 | 222a3336 | balrog | [0x20] = SSE41_OP(pmovsxbw),
|
3032 | 222a3336 | balrog | [0x21] = SSE41_OP(pmovsxbd),
|
3033 | 222a3336 | balrog | [0x22] = SSE41_OP(pmovsxbq),
|
3034 | 222a3336 | balrog | [0x23] = SSE41_OP(pmovsxwd),
|
3035 | 222a3336 | balrog | [0x24] = SSE41_OP(pmovsxwq),
|
3036 | 222a3336 | balrog | [0x25] = SSE41_OP(pmovsxdq),
|
3037 | 222a3336 | balrog | [0x28] = SSE41_OP(pmuldq),
|
3038 | 222a3336 | balrog | [0x29] = SSE41_OP(pcmpeqq),
|
3039 | 222a3336 | balrog | [0x2a] = SSE41_SPECIAL, /* movntqda */ |
3040 | 222a3336 | balrog | [0x2b] = SSE41_OP(packusdw),
|
3041 | 222a3336 | balrog | [0x30] = SSE41_OP(pmovzxbw),
|
3042 | 222a3336 | balrog | [0x31] = SSE41_OP(pmovzxbd),
|
3043 | 222a3336 | balrog | [0x32] = SSE41_OP(pmovzxbq),
|
3044 | 222a3336 | balrog | [0x33] = SSE41_OP(pmovzxwd),
|
3045 | 222a3336 | balrog | [0x34] = SSE41_OP(pmovzxwq),
|
3046 | 222a3336 | balrog | [0x35] = SSE41_OP(pmovzxdq),
|
3047 | 222a3336 | balrog | [0x37] = SSE42_OP(pcmpgtq),
|
3048 | 222a3336 | balrog | [0x38] = SSE41_OP(pminsb),
|
3049 | 222a3336 | balrog | [0x39] = SSE41_OP(pminsd),
|
3050 | 222a3336 | balrog | [0x3a] = SSE41_OP(pminuw),
|
3051 | 222a3336 | balrog | [0x3b] = SSE41_OP(pminud),
|
3052 | 222a3336 | balrog | [0x3c] = SSE41_OP(pmaxsb),
|
3053 | 222a3336 | balrog | [0x3d] = SSE41_OP(pmaxsd),
|
3054 | 222a3336 | balrog | [0x3e] = SSE41_OP(pmaxuw),
|
3055 | 222a3336 | balrog | [0x3f] = SSE41_OP(pmaxud),
|
3056 | 222a3336 | balrog | [0x40] = SSE41_OP(pmulld),
|
3057 | 222a3336 | balrog | [0x41] = SSE41_OP(phminposuw),
|
3058 | 4242b1bd | balrog | }; |
3059 | 4242b1bd | balrog | |
3060 | 222a3336 | balrog | static struct sse_op_helper_s sse_op_table7[256] = { |
3061 | 222a3336 | balrog | [0x08] = SSE41_OP(roundps),
|
3062 | 222a3336 | balrog | [0x09] = SSE41_OP(roundpd),
|
3063 | 222a3336 | balrog | [0x0a] = SSE41_OP(roundss),
|
3064 | 222a3336 | balrog | [0x0b] = SSE41_OP(roundsd),
|
3065 | 222a3336 | balrog | [0x0c] = SSE41_OP(blendps),
|
3066 | 222a3336 | balrog | [0x0d] = SSE41_OP(blendpd),
|
3067 | 222a3336 | balrog | [0x0e] = SSE41_OP(pblendw),
|
3068 | 222a3336 | balrog | [0x0f] = SSSE3_OP(palignr),
|
3069 | 222a3336 | balrog | [0x14] = SSE41_SPECIAL, /* pextrb */ |
3070 | 222a3336 | balrog | [0x15] = SSE41_SPECIAL, /* pextrw */ |
3071 | 222a3336 | balrog | [0x16] = SSE41_SPECIAL, /* pextrd/pextrq */ |
3072 | 222a3336 | balrog | [0x17] = SSE41_SPECIAL, /* extractps */ |
3073 | 222a3336 | balrog | [0x20] = SSE41_SPECIAL, /* pinsrb */ |
3074 | 222a3336 | balrog | [0x21] = SSE41_SPECIAL, /* insertps */ |
3075 | 222a3336 | balrog | [0x22] = SSE41_SPECIAL, /* pinsrd/pinsrq */ |
3076 | 222a3336 | balrog | [0x40] = SSE41_OP(dpps),
|
3077 | 222a3336 | balrog | [0x41] = SSE41_OP(dppd),
|
3078 | 222a3336 | balrog | [0x42] = SSE41_OP(mpsadbw),
|
3079 | 222a3336 | balrog | [0x60] = SSE42_OP(pcmpestrm),
|
3080 | 222a3336 | balrog | [0x61] = SSE42_OP(pcmpestri),
|
3081 | 222a3336 | balrog | [0x62] = SSE42_OP(pcmpistrm),
|
3082 | 222a3336 | balrog | [0x63] = SSE42_OP(pcmpistri),
|
3083 | 4242b1bd | balrog | }; |
3084 | 4242b1bd | balrog | |
3085 | 664e0f19 | bellard | static void gen_sse(DisasContext *s, int b, target_ulong pc_start, int rex_r) |
3086 | 664e0f19 | bellard | { |
3087 | 664e0f19 | bellard | int b1, op1_offset, op2_offset, is_xmm, val, ot;
|
3088 | 664e0f19 | bellard | int modrm, mod, rm, reg, reg_addr, offset_addr;
|
3089 | 5af45186 | bellard | void *sse_op2;
|
3090 | 664e0f19 | bellard | |
3091 | 664e0f19 | bellard | b &= 0xff;
|
3092 | 5fafdf24 | ths | if (s->prefix & PREFIX_DATA)
|
3093 | 664e0f19 | bellard | b1 = 1;
|
3094 | 5fafdf24 | ths | else if (s->prefix & PREFIX_REPZ) |
3095 | 664e0f19 | bellard | b1 = 2;
|
3096 | 5fafdf24 | ths | else if (s->prefix & PREFIX_REPNZ) |
3097 | 664e0f19 | bellard | b1 = 3;
|
3098 | 664e0f19 | bellard | else
|
3099 | 664e0f19 | bellard | b1 = 0;
|
3100 | 664e0f19 | bellard | sse_op2 = sse_op_table1[b][b1]; |
3101 | 5fafdf24 | ths | if (!sse_op2)
|
3102 | 664e0f19 | bellard | goto illegal_op;
|
3103 | a35f3ec7 | aurel32 | if ((b <= 0x5f && b >= 0x10) || b == 0xc6 || b == 0xc2) { |
3104 | 664e0f19 | bellard | is_xmm = 1;
|
3105 | 664e0f19 | bellard | } else {
|
3106 | 664e0f19 | bellard | if (b1 == 0) { |
3107 | 664e0f19 | bellard | /* MMX case */
|
3108 | 664e0f19 | bellard | is_xmm = 0;
|
3109 | 664e0f19 | bellard | } else {
|
3110 | 664e0f19 | bellard | is_xmm = 1;
|
3111 | 664e0f19 | bellard | } |
3112 | 664e0f19 | bellard | } |
3113 | 664e0f19 | bellard | /* simple MMX/SSE operation */
|
3114 | 664e0f19 | bellard | if (s->flags & HF_TS_MASK) {
|
3115 | 664e0f19 | bellard | gen_exception(s, EXCP07_PREX, pc_start - s->cs_base); |
3116 | 664e0f19 | bellard | return;
|
3117 | 664e0f19 | bellard | } |
3118 | 664e0f19 | bellard | if (s->flags & HF_EM_MASK) {
|
3119 | 664e0f19 | bellard | illegal_op:
|
3120 | 664e0f19 | bellard | gen_exception(s, EXCP06_ILLOP, pc_start - s->cs_base); |
3121 | 664e0f19 | bellard | return;
|
3122 | 664e0f19 | bellard | } |
3123 | 664e0f19 | bellard | if (is_xmm && !(s->flags & HF_OSFXSR_MASK))
|
3124 | 4242b1bd | balrog | if ((b != 0x38 && b != 0x3a) || (s->prefix & PREFIX_DATA)) |
3125 | 4242b1bd | balrog | goto illegal_op;
|
3126 | e771edab | aurel32 | if (b == 0x0e) { |
3127 | e771edab | aurel32 | if (!(s->cpuid_ext2_features & CPUID_EXT2_3DNOW))
|
3128 | e771edab | aurel32 | goto illegal_op;
|
3129 | e771edab | aurel32 | /* femms */
|
3130 | a7812ae4 | pbrook | gen_helper_emms(); |
3131 | e771edab | aurel32 | return;
|
3132 | e771edab | aurel32 | } |
3133 | e771edab | aurel32 | if (b == 0x77) { |
3134 | e771edab | aurel32 | /* emms */
|
3135 | a7812ae4 | pbrook | gen_helper_emms(); |
3136 | 664e0f19 | bellard | return;
|
3137 | 664e0f19 | bellard | } |
3138 | 664e0f19 | bellard | /* prepare MMX state (XXX: optimize by storing fptt and fptags in
|
3139 | 664e0f19 | bellard | the static cpu state) */
|
3140 | 664e0f19 | bellard | if (!is_xmm) {
|
3141 | a7812ae4 | pbrook | gen_helper_enter_mmx(); |
3142 | 664e0f19 | bellard | } |
3143 | 664e0f19 | bellard | |
3144 | 664e0f19 | bellard | modrm = ldub_code(s->pc++); |
3145 | 664e0f19 | bellard | reg = ((modrm >> 3) & 7); |
3146 | 664e0f19 | bellard | if (is_xmm)
|
3147 | 664e0f19 | bellard | reg |= rex_r; |
3148 | 664e0f19 | bellard | mod = (modrm >> 6) & 3; |
3149 | 664e0f19 | bellard | if (sse_op2 == SSE_SPECIAL) {
|
3150 | 664e0f19 | bellard | b |= (b1 << 8);
|
3151 | 664e0f19 | bellard | switch(b) {
|
3152 | 664e0f19 | bellard | case 0x0e7: /* movntq */ |
3153 | 5fafdf24 | ths | if (mod == 3) |
3154 | 664e0f19 | bellard | goto illegal_op;
|
3155 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3156 | 8686c490 | bellard | gen_stq_env_A0(s->mem_index, offsetof(CPUX86State,fpregs[reg].mmx)); |
3157 | 664e0f19 | bellard | break;
|
3158 | 664e0f19 | bellard | case 0x1e7: /* movntdq */ |
3159 | 664e0f19 | bellard | case 0x02b: /* movntps */ |
3160 | 664e0f19 | bellard | case 0x12b: /* movntps */ |
3161 | 465e9838 | bellard | case 0x3f0: /* lddqu */ |
3162 | 465e9838 | bellard | if (mod == 3) |
3163 | 664e0f19 | bellard | goto illegal_op;
|
3164 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3165 | 8686c490 | bellard | gen_sto_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg])); |
3166 | 664e0f19 | bellard | break;
|
3167 | 664e0f19 | bellard | case 0x6e: /* movd mm, ea */ |
3168 | dabd98dd | bellard | #ifdef TARGET_X86_64
|
3169 | dabd98dd | bellard | if (s->dflag == 2) { |
3170 | dabd98dd | bellard | gen_ldst_modrm(s, modrm, OT_QUAD, OR_TMP0, 0);
|
3171 | 5af45186 | bellard | tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,fpregs[reg].mmx));
|
3172 | 5fafdf24 | ths | } else
|
3173 | dabd98dd | bellard | #endif
|
3174 | dabd98dd | bellard | { |
3175 | dabd98dd | bellard | gen_ldst_modrm(s, modrm, OT_LONG, OR_TMP0, 0);
|
3176 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, |
3177 | 5af45186 | bellard | offsetof(CPUX86State,fpregs[reg].mmx)); |
3178 | a7812ae4 | pbrook | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
3179 | a7812ae4 | pbrook | gen_helper_movl_mm_T0_mmx(cpu_ptr0, cpu_tmp2_i32); |
3180 | dabd98dd | bellard | } |
3181 | 664e0f19 | bellard | break;
|
3182 | 664e0f19 | bellard | case 0x16e: /* movd xmm, ea */ |
3183 | dabd98dd | bellard | #ifdef TARGET_X86_64
|
3184 | dabd98dd | bellard | if (s->dflag == 2) { |
3185 | dabd98dd | bellard | gen_ldst_modrm(s, modrm, OT_QUAD, OR_TMP0, 0);
|
3186 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, |
3187 | 5af45186 | bellard | offsetof(CPUX86State,xmm_regs[reg])); |
3188 | a7812ae4 | pbrook | gen_helper_movq_mm_T0_xmm(cpu_ptr0, cpu_T[0]);
|
3189 | 5fafdf24 | ths | } else
|
3190 | dabd98dd | bellard | #endif
|
3191 | dabd98dd | bellard | { |
3192 | dabd98dd | bellard | gen_ldst_modrm(s, modrm, OT_LONG, OR_TMP0, 0);
|
3193 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, |
3194 | 5af45186 | bellard | offsetof(CPUX86State,xmm_regs[reg])); |
3195 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
3196 | a7812ae4 | pbrook | gen_helper_movl_mm_T0_xmm(cpu_ptr0, cpu_tmp2_i32); |
3197 | dabd98dd | bellard | } |
3198 | 664e0f19 | bellard | break;
|
3199 | 664e0f19 | bellard | case 0x6f: /* movq mm, ea */ |
3200 | 664e0f19 | bellard | if (mod != 3) { |
3201 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3202 | 8686c490 | bellard | gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,fpregs[reg].mmx)); |
3203 | 664e0f19 | bellard | } else {
|
3204 | 664e0f19 | bellard | rm = (modrm & 7);
|
3205 | b6abf97d | bellard | tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, |
3206 | 5af45186 | bellard | offsetof(CPUX86State,fpregs[rm].mmx)); |
3207 | b6abf97d | bellard | tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, |
3208 | 5af45186 | bellard | offsetof(CPUX86State,fpregs[reg].mmx)); |
3209 | 664e0f19 | bellard | } |
3210 | 664e0f19 | bellard | break;
|
3211 | 664e0f19 | bellard | case 0x010: /* movups */ |
3212 | 664e0f19 | bellard | case 0x110: /* movupd */ |
3213 | 664e0f19 | bellard | case 0x028: /* movaps */ |
3214 | 664e0f19 | bellard | case 0x128: /* movapd */ |
3215 | 664e0f19 | bellard | case 0x16f: /* movdqa xmm, ea */ |
3216 | 664e0f19 | bellard | case 0x26f: /* movdqu xmm, ea */ |
3217 | 664e0f19 | bellard | if (mod != 3) { |
3218 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3219 | 8686c490 | bellard | gen_ldo_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg])); |
3220 | 664e0f19 | bellard | } else {
|
3221 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3222 | 664e0f19 | bellard | gen_op_movo(offsetof(CPUX86State,xmm_regs[reg]), |
3223 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[rm])); |
3224 | 664e0f19 | bellard | } |
3225 | 664e0f19 | bellard | break;
|
3226 | 664e0f19 | bellard | case 0x210: /* movss xmm, ea */ |
3227 | 664e0f19 | bellard | if (mod != 3) { |
3228 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3229 | 57fec1fe | bellard | gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
3230 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(0))); |
3231 | 664e0f19 | bellard | gen_op_movl_T0_0(); |
3232 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(1))); |
3233 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(2))); |
3234 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(3))); |
3235 | 664e0f19 | bellard | } else {
|
3236 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3237 | 664e0f19 | bellard | gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(0)),
|
3238 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[rm].XMM_L(0)));
|
3239 | 664e0f19 | bellard | } |
3240 | 664e0f19 | bellard | break;
|
3241 | 664e0f19 | bellard | case 0x310: /* movsd xmm, ea */ |
3242 | 664e0f19 | bellard | if (mod != 3) { |
3243 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3244 | 8686c490 | bellard | gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3245 | 664e0f19 | bellard | gen_op_movl_T0_0(); |
3246 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(2))); |
3247 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(3))); |
3248 | 664e0f19 | bellard | } else {
|
3249 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3250 | 664e0f19 | bellard | gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)),
|
3251 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)));
|
3252 | 664e0f19 | bellard | } |
3253 | 664e0f19 | bellard | break;
|
3254 | 664e0f19 | bellard | case 0x012: /* movlps */ |
3255 | 664e0f19 | bellard | case 0x112: /* movlpd */ |
3256 | 664e0f19 | bellard | if (mod != 3) { |
3257 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3258 | 8686c490 | bellard | gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3259 | 664e0f19 | bellard | } else {
|
3260 | 664e0f19 | bellard | /* movhlps */
|
3261 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3262 | 664e0f19 | bellard | gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)),
|
3263 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[rm].XMM_Q(1)));
|
3264 | 664e0f19 | bellard | } |
3265 | 664e0f19 | bellard | break;
|
3266 | 465e9838 | bellard | case 0x212: /* movsldup */ |
3267 | 465e9838 | bellard | if (mod != 3) { |
3268 | 465e9838 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3269 | 8686c490 | bellard | gen_ldo_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg])); |
3270 | 465e9838 | bellard | } else {
|
3271 | 465e9838 | bellard | rm = (modrm & 7) | REX_B(s);
|
3272 | 465e9838 | bellard | gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(0)),
|
3273 | 465e9838 | bellard | offsetof(CPUX86State,xmm_regs[rm].XMM_L(0)));
|
3274 | 465e9838 | bellard | gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(2)),
|
3275 | 465e9838 | bellard | offsetof(CPUX86State,xmm_regs[rm].XMM_L(2)));
|
3276 | 465e9838 | bellard | } |
3277 | 465e9838 | bellard | gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(1)),
|
3278 | 465e9838 | bellard | offsetof(CPUX86State,xmm_regs[reg].XMM_L(0)));
|
3279 | 465e9838 | bellard | gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(3)),
|
3280 | 465e9838 | bellard | offsetof(CPUX86State,xmm_regs[reg].XMM_L(2)));
|
3281 | 465e9838 | bellard | break;
|
3282 | 465e9838 | bellard | case 0x312: /* movddup */ |
3283 | 465e9838 | bellard | if (mod != 3) { |
3284 | 465e9838 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3285 | 8686c490 | bellard | gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3286 | 465e9838 | bellard | } else {
|
3287 | 465e9838 | bellard | rm = (modrm & 7) | REX_B(s);
|
3288 | 465e9838 | bellard | gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)),
|
3289 | 465e9838 | bellard | offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)));
|
3290 | 465e9838 | bellard | } |
3291 | 465e9838 | bellard | gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(1)),
|
3292 | ba6526df | bellard | offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3293 | 465e9838 | bellard | break;
|
3294 | 664e0f19 | bellard | case 0x016: /* movhps */ |
3295 | 664e0f19 | bellard | case 0x116: /* movhpd */ |
3296 | 664e0f19 | bellard | if (mod != 3) { |
3297 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3298 | 8686c490 | bellard | gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(1)));
|
3299 | 664e0f19 | bellard | } else {
|
3300 | 664e0f19 | bellard | /* movlhps */
|
3301 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3302 | 664e0f19 | bellard | gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(1)),
|
3303 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)));
|
3304 | 664e0f19 | bellard | } |
3305 | 664e0f19 | bellard | break;
|
3306 | 664e0f19 | bellard | case 0x216: /* movshdup */ |
3307 | 664e0f19 | bellard | if (mod != 3) { |
3308 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3309 | 8686c490 | bellard | gen_ldo_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg])); |
3310 | 664e0f19 | bellard | } else {
|
3311 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3312 | 664e0f19 | bellard | gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(1)),
|
3313 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[rm].XMM_L(1)));
|
3314 | 664e0f19 | bellard | gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(3)),
|
3315 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[rm].XMM_L(3)));
|
3316 | 664e0f19 | bellard | } |
3317 | 664e0f19 | bellard | gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(0)),
|
3318 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[reg].XMM_L(1)));
|
3319 | 664e0f19 | bellard | gen_op_movl(offsetof(CPUX86State,xmm_regs[reg].XMM_L(2)),
|
3320 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[reg].XMM_L(3)));
|
3321 | 664e0f19 | bellard | break;
|
3322 | 664e0f19 | bellard | case 0x7e: /* movd ea, mm */ |
3323 | dabd98dd | bellard | #ifdef TARGET_X86_64
|
3324 | dabd98dd | bellard | if (s->dflag == 2) { |
3325 | 5af45186 | bellard | tcg_gen_ld_i64(cpu_T[0], cpu_env,
|
3326 | 5af45186 | bellard | offsetof(CPUX86State,fpregs[reg].mmx)); |
3327 | dabd98dd | bellard | gen_ldst_modrm(s, modrm, OT_QUAD, OR_TMP0, 1);
|
3328 | 5fafdf24 | ths | } else
|
3329 | dabd98dd | bellard | #endif
|
3330 | dabd98dd | bellard | { |
3331 | 5af45186 | bellard | tcg_gen_ld32u_tl(cpu_T[0], cpu_env,
|
3332 | 5af45186 | bellard | offsetof(CPUX86State,fpregs[reg].mmx.MMX_L(0)));
|
3333 | dabd98dd | bellard | gen_ldst_modrm(s, modrm, OT_LONG, OR_TMP0, 1);
|
3334 | dabd98dd | bellard | } |
3335 | 664e0f19 | bellard | break;
|
3336 | 664e0f19 | bellard | case 0x17e: /* movd ea, xmm */ |
3337 | dabd98dd | bellard | #ifdef TARGET_X86_64
|
3338 | dabd98dd | bellard | if (s->dflag == 2) { |
3339 | 5af45186 | bellard | tcg_gen_ld_i64(cpu_T[0], cpu_env,
|
3340 | 5af45186 | bellard | offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3341 | dabd98dd | bellard | gen_ldst_modrm(s, modrm, OT_QUAD, OR_TMP0, 1);
|
3342 | 5fafdf24 | ths | } else
|
3343 | dabd98dd | bellard | #endif
|
3344 | dabd98dd | bellard | { |
3345 | 5af45186 | bellard | tcg_gen_ld32u_tl(cpu_T[0], cpu_env,
|
3346 | 5af45186 | bellard | offsetof(CPUX86State,xmm_regs[reg].XMM_L(0)));
|
3347 | dabd98dd | bellard | gen_ldst_modrm(s, modrm, OT_LONG, OR_TMP0, 1);
|
3348 | dabd98dd | bellard | } |
3349 | 664e0f19 | bellard | break;
|
3350 | 664e0f19 | bellard | case 0x27e: /* movq xmm, ea */ |
3351 | 664e0f19 | bellard | if (mod != 3) { |
3352 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3353 | 8686c490 | bellard | gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3354 | 664e0f19 | bellard | } else {
|
3355 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3356 | 664e0f19 | bellard | gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)),
|
3357 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)));
|
3358 | 664e0f19 | bellard | } |
3359 | 664e0f19 | bellard | gen_op_movq_env_0(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(1)));
|
3360 | 664e0f19 | bellard | break;
|
3361 | 664e0f19 | bellard | case 0x7f: /* movq ea, mm */ |
3362 | 664e0f19 | bellard | if (mod != 3) { |
3363 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3364 | 8686c490 | bellard | gen_stq_env_A0(s->mem_index, offsetof(CPUX86State,fpregs[reg].mmx)); |
3365 | 664e0f19 | bellard | } else {
|
3366 | 664e0f19 | bellard | rm = (modrm & 7);
|
3367 | 664e0f19 | bellard | gen_op_movq(offsetof(CPUX86State,fpregs[rm].mmx), |
3368 | 664e0f19 | bellard | offsetof(CPUX86State,fpregs[reg].mmx)); |
3369 | 664e0f19 | bellard | } |
3370 | 664e0f19 | bellard | break;
|
3371 | 664e0f19 | bellard | case 0x011: /* movups */ |
3372 | 664e0f19 | bellard | case 0x111: /* movupd */ |
3373 | 664e0f19 | bellard | case 0x029: /* movaps */ |
3374 | 664e0f19 | bellard | case 0x129: /* movapd */ |
3375 | 664e0f19 | bellard | case 0x17f: /* movdqa ea, xmm */ |
3376 | 664e0f19 | bellard | case 0x27f: /* movdqu ea, xmm */ |
3377 | 664e0f19 | bellard | if (mod != 3) { |
3378 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3379 | 8686c490 | bellard | gen_sto_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg])); |
3380 | 664e0f19 | bellard | } else {
|
3381 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3382 | 664e0f19 | bellard | gen_op_movo(offsetof(CPUX86State,xmm_regs[rm]), |
3383 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[reg])); |
3384 | 664e0f19 | bellard | } |
3385 | 664e0f19 | bellard | break;
|
3386 | 664e0f19 | bellard | case 0x211: /* movss ea, xmm */ |
3387 | 664e0f19 | bellard | if (mod != 3) { |
3388 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3389 | 651ba608 | bellard | tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_regs[reg].XMM_L(0))); |
3390 | 57fec1fe | bellard | gen_op_st_T0_A0(OT_LONG + s->mem_index); |
3391 | 664e0f19 | bellard | } else {
|
3392 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3393 | 664e0f19 | bellard | gen_op_movl(offsetof(CPUX86State,xmm_regs[rm].XMM_L(0)),
|
3394 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[reg].XMM_L(0)));
|
3395 | 664e0f19 | bellard | } |
3396 | 664e0f19 | bellard | break;
|
3397 | 664e0f19 | bellard | case 0x311: /* movsd ea, xmm */ |
3398 | 664e0f19 | bellard | if (mod != 3) { |
3399 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3400 | 8686c490 | bellard | gen_stq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3401 | 664e0f19 | bellard | } else {
|
3402 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3403 | 664e0f19 | bellard | gen_op_movq(offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)),
|
3404 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3405 | 664e0f19 | bellard | } |
3406 | 664e0f19 | bellard | break;
|
3407 | 664e0f19 | bellard | case 0x013: /* movlps */ |
3408 | 664e0f19 | bellard | case 0x113: /* movlpd */ |
3409 | 664e0f19 | bellard | if (mod != 3) { |
3410 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3411 | 8686c490 | bellard | gen_stq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3412 | 664e0f19 | bellard | } else {
|
3413 | 664e0f19 | bellard | goto illegal_op;
|
3414 | 664e0f19 | bellard | } |
3415 | 664e0f19 | bellard | break;
|
3416 | 664e0f19 | bellard | case 0x017: /* movhps */ |
3417 | 664e0f19 | bellard | case 0x117: /* movhpd */ |
3418 | 664e0f19 | bellard | if (mod != 3) { |
3419 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3420 | 8686c490 | bellard | gen_stq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(1)));
|
3421 | 664e0f19 | bellard | } else {
|
3422 | 664e0f19 | bellard | goto illegal_op;
|
3423 | 664e0f19 | bellard | } |
3424 | 664e0f19 | bellard | break;
|
3425 | 664e0f19 | bellard | case 0x71: /* shift mm, im */ |
3426 | 664e0f19 | bellard | case 0x72: |
3427 | 664e0f19 | bellard | case 0x73: |
3428 | 664e0f19 | bellard | case 0x171: /* shift xmm, im */ |
3429 | 664e0f19 | bellard | case 0x172: |
3430 | 664e0f19 | bellard | case 0x173: |
3431 | 664e0f19 | bellard | val = ldub_code(s->pc++); |
3432 | 664e0f19 | bellard | if (is_xmm) {
|
3433 | 664e0f19 | bellard | gen_op_movl_T0_im(val); |
3434 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_t0.XMM_L(0))); |
3435 | 664e0f19 | bellard | gen_op_movl_T0_0(); |
3436 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_t0.XMM_L(1))); |
3437 | 664e0f19 | bellard | op1_offset = offsetof(CPUX86State,xmm_t0); |
3438 | 664e0f19 | bellard | } else {
|
3439 | 664e0f19 | bellard | gen_op_movl_T0_im(val); |
3440 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,mmx_t0.MMX_L(0))); |
3441 | 664e0f19 | bellard | gen_op_movl_T0_0(); |
3442 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,mmx_t0.MMX_L(1))); |
3443 | 664e0f19 | bellard | op1_offset = offsetof(CPUX86State,mmx_t0); |
3444 | 664e0f19 | bellard | } |
3445 | 664e0f19 | bellard | sse_op2 = sse_op_table2[((b - 1) & 3) * 8 + (((modrm >> 3)) & 7)][b1]; |
3446 | 664e0f19 | bellard | if (!sse_op2)
|
3447 | 664e0f19 | bellard | goto illegal_op;
|
3448 | 664e0f19 | bellard | if (is_xmm) {
|
3449 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3450 | 664e0f19 | bellard | op2_offset = offsetof(CPUX86State,xmm_regs[rm]); |
3451 | 664e0f19 | bellard | } else {
|
3452 | 664e0f19 | bellard | rm = (modrm & 7);
|
3453 | 664e0f19 | bellard | op2_offset = offsetof(CPUX86State,fpregs[rm].mmx); |
3454 | 664e0f19 | bellard | } |
3455 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op2_offset); |
3456 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op1_offset); |
3457 | a7812ae4 | pbrook | ((void (*)(TCGv_ptr, TCGv_ptr))sse_op2)(cpu_ptr0, cpu_ptr1);
|
3458 | 664e0f19 | bellard | break;
|
3459 | 664e0f19 | bellard | case 0x050: /* movmskps */ |
3460 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3461 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, |
3462 | 5af45186 | bellard | offsetof(CPUX86State,xmm_regs[rm])); |
3463 | a7812ae4 | pbrook | gen_helper_movmskps(cpu_tmp2_i32, cpu_ptr0); |
3464 | b6abf97d | bellard | tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
3465 | 57fec1fe | bellard | gen_op_mov_reg_T0(OT_LONG, reg); |
3466 | 664e0f19 | bellard | break;
|
3467 | 664e0f19 | bellard | case 0x150: /* movmskpd */ |
3468 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3469 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, |
3470 | 5af45186 | bellard | offsetof(CPUX86State,xmm_regs[rm])); |
3471 | a7812ae4 | pbrook | gen_helper_movmskpd(cpu_tmp2_i32, cpu_ptr0); |
3472 | b6abf97d | bellard | tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
3473 | 57fec1fe | bellard | gen_op_mov_reg_T0(OT_LONG, reg); |
3474 | 664e0f19 | bellard | break;
|
3475 | 664e0f19 | bellard | case 0x02a: /* cvtpi2ps */ |
3476 | 664e0f19 | bellard | case 0x12a: /* cvtpi2pd */ |
3477 | a7812ae4 | pbrook | gen_helper_enter_mmx(); |
3478 | 664e0f19 | bellard | if (mod != 3) { |
3479 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3480 | 664e0f19 | bellard | op2_offset = offsetof(CPUX86State,mmx_t0); |
3481 | 8686c490 | bellard | gen_ldq_env_A0(s->mem_index, op2_offset); |
3482 | 664e0f19 | bellard | } else {
|
3483 | 664e0f19 | bellard | rm = (modrm & 7);
|
3484 | 664e0f19 | bellard | op2_offset = offsetof(CPUX86State,fpregs[rm].mmx); |
3485 | 664e0f19 | bellard | } |
3486 | 664e0f19 | bellard | op1_offset = offsetof(CPUX86State,xmm_regs[reg]); |
3487 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
3488 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
3489 | 664e0f19 | bellard | switch(b >> 8) { |
3490 | 664e0f19 | bellard | case 0x0: |
3491 | a7812ae4 | pbrook | gen_helper_cvtpi2ps(cpu_ptr0, cpu_ptr1); |
3492 | 664e0f19 | bellard | break;
|
3493 | 664e0f19 | bellard | default:
|
3494 | 664e0f19 | bellard | case 0x1: |
3495 | a7812ae4 | pbrook | gen_helper_cvtpi2pd(cpu_ptr0, cpu_ptr1); |
3496 | 664e0f19 | bellard | break;
|
3497 | 664e0f19 | bellard | } |
3498 | 664e0f19 | bellard | break;
|
3499 | 664e0f19 | bellard | case 0x22a: /* cvtsi2ss */ |
3500 | 664e0f19 | bellard | case 0x32a: /* cvtsi2sd */ |
3501 | 664e0f19 | bellard | ot = (s->dflag == 2) ? OT_QUAD : OT_LONG;
|
3502 | 664e0f19 | bellard | gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
|
3503 | 664e0f19 | bellard | op1_offset = offsetof(CPUX86State,xmm_regs[reg]); |
3504 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
3505 | 5af45186 | bellard | sse_op2 = sse_op_table3[(s->dflag == 2) * 2 + ((b >> 8) - 2)]; |
3506 | 28e10711 | bellard | if (ot == OT_LONG) {
|
3507 | 28e10711 | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
3508 | a7812ae4 | pbrook | ((void (*)(TCGv_ptr, TCGv_i32))sse_op2)(cpu_ptr0, cpu_tmp2_i32);
|
3509 | 28e10711 | bellard | } else {
|
3510 | a7812ae4 | pbrook | ((void (*)(TCGv_ptr, TCGv))sse_op2)(cpu_ptr0, cpu_T[0]); |
3511 | 28e10711 | bellard | } |
3512 | 664e0f19 | bellard | break;
|
3513 | 664e0f19 | bellard | case 0x02c: /* cvttps2pi */ |
3514 | 664e0f19 | bellard | case 0x12c: /* cvttpd2pi */ |
3515 | 664e0f19 | bellard | case 0x02d: /* cvtps2pi */ |
3516 | 664e0f19 | bellard | case 0x12d: /* cvtpd2pi */ |
3517 | a7812ae4 | pbrook | gen_helper_enter_mmx(); |
3518 | 664e0f19 | bellard | if (mod != 3) { |
3519 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3520 | 664e0f19 | bellard | op2_offset = offsetof(CPUX86State,xmm_t0); |
3521 | 8686c490 | bellard | gen_ldo_env_A0(s->mem_index, op2_offset); |
3522 | 664e0f19 | bellard | } else {
|
3523 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3524 | 664e0f19 | bellard | op2_offset = offsetof(CPUX86State,xmm_regs[rm]); |
3525 | 664e0f19 | bellard | } |
3526 | 664e0f19 | bellard | op1_offset = offsetof(CPUX86State,fpregs[reg & 7].mmx);
|
3527 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
3528 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
3529 | 664e0f19 | bellard | switch(b) {
|
3530 | 664e0f19 | bellard | case 0x02c: |
3531 | a7812ae4 | pbrook | gen_helper_cvttps2pi(cpu_ptr0, cpu_ptr1); |
3532 | 664e0f19 | bellard | break;
|
3533 | 664e0f19 | bellard | case 0x12c: |
3534 | a7812ae4 | pbrook | gen_helper_cvttpd2pi(cpu_ptr0, cpu_ptr1); |
3535 | 664e0f19 | bellard | break;
|
3536 | 664e0f19 | bellard | case 0x02d: |
3537 | a7812ae4 | pbrook | gen_helper_cvtps2pi(cpu_ptr0, cpu_ptr1); |
3538 | 664e0f19 | bellard | break;
|
3539 | 664e0f19 | bellard | case 0x12d: |
3540 | a7812ae4 | pbrook | gen_helper_cvtpd2pi(cpu_ptr0, cpu_ptr1); |
3541 | 664e0f19 | bellard | break;
|
3542 | 664e0f19 | bellard | } |
3543 | 664e0f19 | bellard | break;
|
3544 | 664e0f19 | bellard | case 0x22c: /* cvttss2si */ |
3545 | 664e0f19 | bellard | case 0x32c: /* cvttsd2si */ |
3546 | 664e0f19 | bellard | case 0x22d: /* cvtss2si */ |
3547 | 664e0f19 | bellard | case 0x32d: /* cvtsd2si */ |
3548 | 664e0f19 | bellard | ot = (s->dflag == 2) ? OT_QUAD : OT_LONG;
|
3549 | 31313213 | bellard | if (mod != 3) { |
3550 | 31313213 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3551 | 31313213 | bellard | if ((b >> 8) & 1) { |
3552 | 8686c490 | bellard | gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_t0.XMM_Q(0)));
|
3553 | 31313213 | bellard | } else {
|
3554 | 57fec1fe | bellard | gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
3555 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_t0.XMM_L(0))); |
3556 | 31313213 | bellard | } |
3557 | 31313213 | bellard | op2_offset = offsetof(CPUX86State,xmm_t0); |
3558 | 31313213 | bellard | } else {
|
3559 | 31313213 | bellard | rm = (modrm & 7) | REX_B(s);
|
3560 | 31313213 | bellard | op2_offset = offsetof(CPUX86State,xmm_regs[rm]); |
3561 | 31313213 | bellard | } |
3562 | 5af45186 | bellard | sse_op2 = sse_op_table3[(s->dflag == 2) * 2 + ((b >> 8) - 2) + 4 + |
3563 | 5af45186 | bellard | (b & 1) * 4]; |
3564 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op2_offset); |
3565 | 5af45186 | bellard | if (ot == OT_LONG) {
|
3566 | a7812ae4 | pbrook | ((void (*)(TCGv_i32, TCGv_ptr))sse_op2)(cpu_tmp2_i32, cpu_ptr0);
|
3567 | b6abf97d | bellard | tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
3568 | 5af45186 | bellard | } else {
|
3569 | a7812ae4 | pbrook | ((void (*)(TCGv, TCGv_ptr))sse_op2)(cpu_T[0], cpu_ptr0); |
3570 | 5af45186 | bellard | } |
3571 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, reg); |
3572 | 664e0f19 | bellard | break;
|
3573 | 664e0f19 | bellard | case 0xc4: /* pinsrw */ |
3574 | 5fafdf24 | ths | case 0x1c4: |
3575 | d1e42c5c | bellard | s->rip_offset = 1;
|
3576 | 664e0f19 | bellard | gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
3577 | 664e0f19 | bellard | val = ldub_code(s->pc++); |
3578 | 664e0f19 | bellard | if (b1) {
|
3579 | 664e0f19 | bellard | val &= 7;
|
3580 | 5af45186 | bellard | tcg_gen_st16_tl(cpu_T[0], cpu_env,
|
3581 | 5af45186 | bellard | offsetof(CPUX86State,xmm_regs[reg].XMM_W(val))); |
3582 | 664e0f19 | bellard | } else {
|
3583 | 664e0f19 | bellard | val &= 3;
|
3584 | 5af45186 | bellard | tcg_gen_st16_tl(cpu_T[0], cpu_env,
|
3585 | 5af45186 | bellard | offsetof(CPUX86State,fpregs[reg].mmx.MMX_W(val))); |
3586 | 664e0f19 | bellard | } |
3587 | 664e0f19 | bellard | break;
|
3588 | 664e0f19 | bellard | case 0xc5: /* pextrw */ |
3589 | 5fafdf24 | ths | case 0x1c5: |
3590 | 664e0f19 | bellard | if (mod != 3) |
3591 | 664e0f19 | bellard | goto illegal_op;
|
3592 | 6dc2d0da | balrog | ot = (s->dflag == 2) ? OT_QUAD : OT_LONG;
|
3593 | 664e0f19 | bellard | val = ldub_code(s->pc++); |
3594 | 664e0f19 | bellard | if (b1) {
|
3595 | 664e0f19 | bellard | val &= 7;
|
3596 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3597 | 5af45186 | bellard | tcg_gen_ld16u_tl(cpu_T[0], cpu_env,
|
3598 | 5af45186 | bellard | offsetof(CPUX86State,xmm_regs[rm].XMM_W(val))); |
3599 | 664e0f19 | bellard | } else {
|
3600 | 664e0f19 | bellard | val &= 3;
|
3601 | 664e0f19 | bellard | rm = (modrm & 7);
|
3602 | 5af45186 | bellard | tcg_gen_ld16u_tl(cpu_T[0], cpu_env,
|
3603 | 5af45186 | bellard | offsetof(CPUX86State,fpregs[rm].mmx.MMX_W(val))); |
3604 | 664e0f19 | bellard | } |
3605 | 664e0f19 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
3606 | 6dc2d0da | balrog | gen_op_mov_reg_T0(ot, reg); |
3607 | 664e0f19 | bellard | break;
|
3608 | 664e0f19 | bellard | case 0x1d6: /* movq ea, xmm */ |
3609 | 664e0f19 | bellard | if (mod != 3) { |
3610 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3611 | 8686c490 | bellard | gen_stq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3612 | 664e0f19 | bellard | } else {
|
3613 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3614 | 664e0f19 | bellard | gen_op_movq(offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)),
|
3615 | 664e0f19 | bellard | offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)));
|
3616 | 664e0f19 | bellard | gen_op_movq_env_0(offsetof(CPUX86State,xmm_regs[rm].XMM_Q(1)));
|
3617 | 664e0f19 | bellard | } |
3618 | 664e0f19 | bellard | break;
|
3619 | 664e0f19 | bellard | case 0x2d6: /* movq2dq */ |
3620 | a7812ae4 | pbrook | gen_helper_enter_mmx(); |
3621 | 480c1cdb | bellard | rm = (modrm & 7);
|
3622 | 480c1cdb | bellard | gen_op_movq(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(0)),
|
3623 | 480c1cdb | bellard | offsetof(CPUX86State,fpregs[rm].mmx)); |
3624 | 480c1cdb | bellard | gen_op_movq_env_0(offsetof(CPUX86State,xmm_regs[reg].XMM_Q(1)));
|
3625 | 664e0f19 | bellard | break;
|
3626 | 664e0f19 | bellard | case 0x3d6: /* movdq2q */ |
3627 | a7812ae4 | pbrook | gen_helper_enter_mmx(); |
3628 | 480c1cdb | bellard | rm = (modrm & 7) | REX_B(s);
|
3629 | 480c1cdb | bellard | gen_op_movq(offsetof(CPUX86State,fpregs[reg & 7].mmx),
|
3630 | 480c1cdb | bellard | offsetof(CPUX86State,xmm_regs[rm].XMM_Q(0)));
|
3631 | 664e0f19 | bellard | break;
|
3632 | 664e0f19 | bellard | case 0xd7: /* pmovmskb */ |
3633 | 664e0f19 | bellard | case 0x1d7: |
3634 | 664e0f19 | bellard | if (mod != 3) |
3635 | 664e0f19 | bellard | goto illegal_op;
|
3636 | 664e0f19 | bellard | if (b1) {
|
3637 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3638 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, offsetof(CPUX86State,xmm_regs[rm])); |
3639 | a7812ae4 | pbrook | gen_helper_pmovmskb_xmm(cpu_tmp2_i32, cpu_ptr0); |
3640 | 664e0f19 | bellard | } else {
|
3641 | 664e0f19 | bellard | rm = (modrm & 7);
|
3642 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, offsetof(CPUX86State,fpregs[rm].mmx)); |
3643 | a7812ae4 | pbrook | gen_helper_pmovmskb_mmx(cpu_tmp2_i32, cpu_ptr0); |
3644 | 664e0f19 | bellard | } |
3645 | b6abf97d | bellard | tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
3646 | 664e0f19 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
3647 | 57fec1fe | bellard | gen_op_mov_reg_T0(OT_LONG, reg); |
3648 | 664e0f19 | bellard | break;
|
3649 | 4242b1bd | balrog | case 0x138: |
3650 | 000cacf6 | balrog | if (s->prefix & PREFIX_REPNZ)
|
3651 | 000cacf6 | balrog | goto crc32;
|
3652 | 000cacf6 | balrog | case 0x038: |
3653 | 4242b1bd | balrog | b = modrm; |
3654 | 4242b1bd | balrog | modrm = ldub_code(s->pc++); |
3655 | 4242b1bd | balrog | rm = modrm & 7;
|
3656 | 4242b1bd | balrog | reg = ((modrm >> 3) & 7) | rex_r; |
3657 | 4242b1bd | balrog | mod = (modrm >> 6) & 3; |
3658 | 4242b1bd | balrog | |
3659 | 222a3336 | balrog | sse_op2 = sse_op_table6[b].op[b1]; |
3660 | 4242b1bd | balrog | if (!sse_op2)
|
3661 | 4242b1bd | balrog | goto illegal_op;
|
3662 | 222a3336 | balrog | if (!(s->cpuid_ext_features & sse_op_table6[b].ext_mask))
|
3663 | 222a3336 | balrog | goto illegal_op;
|
3664 | 4242b1bd | balrog | |
3665 | 4242b1bd | balrog | if (b1) {
|
3666 | 4242b1bd | balrog | op1_offset = offsetof(CPUX86State,xmm_regs[reg]); |
3667 | 4242b1bd | balrog | if (mod == 3) { |
3668 | 4242b1bd | balrog | op2_offset = offsetof(CPUX86State,xmm_regs[rm | REX_B(s)]); |
3669 | 4242b1bd | balrog | } else {
|
3670 | 4242b1bd | balrog | op2_offset = offsetof(CPUX86State,xmm_t0); |
3671 | 4242b1bd | balrog | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3672 | 222a3336 | balrog | switch (b) {
|
3673 | 222a3336 | balrog | case 0x20: case 0x30: /* pmovsxbw, pmovzxbw */ |
3674 | 222a3336 | balrog | case 0x23: case 0x33: /* pmovsxwd, pmovzxwd */ |
3675 | 222a3336 | balrog | case 0x25: case 0x35: /* pmovsxdq, pmovzxdq */ |
3676 | 222a3336 | balrog | gen_ldq_env_A0(s->mem_index, op2_offset + |
3677 | 222a3336 | balrog | offsetof(XMMReg, XMM_Q(0)));
|
3678 | 222a3336 | balrog | break;
|
3679 | 222a3336 | balrog | case 0x21: case 0x31: /* pmovsxbd, pmovzxbd */ |
3680 | 222a3336 | balrog | case 0x24: case 0x34: /* pmovsxwq, pmovzxwq */ |
3681 | a7812ae4 | pbrook | tcg_gen_qemu_ld32u(cpu_tmp0, cpu_A0, |
3682 | 222a3336 | balrog | (s->mem_index >> 2) - 1); |
3683 | a7812ae4 | pbrook | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_tmp0); |
3684 | 222a3336 | balrog | tcg_gen_st_i32(cpu_tmp2_i32, cpu_env, op2_offset + |
3685 | 222a3336 | balrog | offsetof(XMMReg, XMM_L(0)));
|
3686 | 222a3336 | balrog | break;
|
3687 | 222a3336 | balrog | case 0x22: case 0x32: /* pmovsxbq, pmovzxbq */ |
3688 | 222a3336 | balrog | tcg_gen_qemu_ld16u(cpu_tmp0, cpu_A0, |
3689 | 222a3336 | balrog | (s->mem_index >> 2) - 1); |
3690 | 222a3336 | balrog | tcg_gen_st16_tl(cpu_tmp0, cpu_env, op2_offset + |
3691 | 222a3336 | balrog | offsetof(XMMReg, XMM_W(0)));
|
3692 | 222a3336 | balrog | break;
|
3693 | 222a3336 | balrog | case 0x2a: /* movntqda */ |
3694 | 222a3336 | balrog | gen_ldo_env_A0(s->mem_index, op1_offset); |
3695 | 222a3336 | balrog | return;
|
3696 | 222a3336 | balrog | default:
|
3697 | 222a3336 | balrog | gen_ldo_env_A0(s->mem_index, op2_offset); |
3698 | 222a3336 | balrog | } |
3699 | 4242b1bd | balrog | } |
3700 | 4242b1bd | balrog | } else {
|
3701 | 4242b1bd | balrog | op1_offset = offsetof(CPUX86State,fpregs[reg].mmx); |
3702 | 4242b1bd | balrog | if (mod == 3) { |
3703 | 4242b1bd | balrog | op2_offset = offsetof(CPUX86State,fpregs[rm].mmx); |
3704 | 4242b1bd | balrog | } else {
|
3705 | 4242b1bd | balrog | op2_offset = offsetof(CPUX86State,mmx_t0); |
3706 | 4242b1bd | balrog | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3707 | 4242b1bd | balrog | gen_ldq_env_A0(s->mem_index, op2_offset); |
3708 | 4242b1bd | balrog | } |
3709 | 4242b1bd | balrog | } |
3710 | 222a3336 | balrog | if (sse_op2 == SSE_SPECIAL)
|
3711 | 222a3336 | balrog | goto illegal_op;
|
3712 | 222a3336 | balrog | |
3713 | 4242b1bd | balrog | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
3714 | 4242b1bd | balrog | tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
3715 | a7812ae4 | pbrook | ((void (*)(TCGv_ptr, TCGv_ptr))sse_op2)(cpu_ptr0, cpu_ptr1);
|
3716 | 222a3336 | balrog | |
3717 | 222a3336 | balrog | if (b == 0x17) |
3718 | 222a3336 | balrog | s->cc_op = CC_OP_EFLAGS; |
3719 | 4242b1bd | balrog | break;
|
3720 | 222a3336 | balrog | case 0x338: /* crc32 */ |
3721 | 222a3336 | balrog | crc32:
|
3722 | 222a3336 | balrog | b = modrm; |
3723 | 222a3336 | balrog | modrm = ldub_code(s->pc++); |
3724 | 222a3336 | balrog | reg = ((modrm >> 3) & 7) | rex_r; |
3725 | 222a3336 | balrog | |
3726 | 222a3336 | balrog | if (b != 0xf0 && b != 0xf1) |
3727 | 222a3336 | balrog | goto illegal_op;
|
3728 | 222a3336 | balrog | if (!(s->cpuid_ext_features & CPUID_EXT_SSE42))
|
3729 | 4242b1bd | balrog | goto illegal_op;
|
3730 | 4242b1bd | balrog | |
3731 | 222a3336 | balrog | if (b == 0xf0) |
3732 | 222a3336 | balrog | ot = OT_BYTE; |
3733 | 222a3336 | balrog | else if (b == 0xf1 && s->dflag != 2) |
3734 | 222a3336 | balrog | if (s->prefix & PREFIX_DATA)
|
3735 | 222a3336 | balrog | ot = OT_WORD; |
3736 | 222a3336 | balrog | else
|
3737 | 222a3336 | balrog | ot = OT_LONG; |
3738 | 222a3336 | balrog | else
|
3739 | 222a3336 | balrog | ot = OT_QUAD; |
3740 | 222a3336 | balrog | |
3741 | 222a3336 | balrog | gen_op_mov_TN_reg(OT_LONG, 0, reg);
|
3742 | 222a3336 | balrog | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
3743 | 222a3336 | balrog | gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
|
3744 | a7812ae4 | pbrook | gen_helper_crc32(cpu_T[0], cpu_tmp2_i32,
|
3745 | a7812ae4 | pbrook | cpu_T[0], tcg_const_i32(8 << ot)); |
3746 | 222a3336 | balrog | |
3747 | 222a3336 | balrog | ot = (s->dflag == 2) ? OT_QUAD : OT_LONG;
|
3748 | 222a3336 | balrog | gen_op_mov_reg_T0(ot, reg); |
3749 | 222a3336 | balrog | break;
|
3750 | 222a3336 | balrog | case 0x03a: |
3751 | 222a3336 | balrog | case 0x13a: |
3752 | 4242b1bd | balrog | b = modrm; |
3753 | 4242b1bd | balrog | modrm = ldub_code(s->pc++); |
3754 | 4242b1bd | balrog | rm = modrm & 7;
|
3755 | 4242b1bd | balrog | reg = ((modrm >> 3) & 7) | rex_r; |
3756 | 4242b1bd | balrog | mod = (modrm >> 6) & 3; |
3757 | 4242b1bd | balrog | |
3758 | 222a3336 | balrog | sse_op2 = sse_op_table7[b].op[b1]; |
3759 | 4242b1bd | balrog | if (!sse_op2)
|
3760 | 4242b1bd | balrog | goto illegal_op;
|
3761 | 222a3336 | balrog | if (!(s->cpuid_ext_features & sse_op_table7[b].ext_mask))
|
3762 | 222a3336 | balrog | goto illegal_op;
|
3763 | 222a3336 | balrog | |
3764 | 222a3336 | balrog | if (sse_op2 == SSE_SPECIAL) {
|
3765 | 222a3336 | balrog | ot = (s->dflag == 2) ? OT_QUAD : OT_LONG;
|
3766 | 222a3336 | balrog | rm = (modrm & 7) | REX_B(s);
|
3767 | 222a3336 | balrog | if (mod != 3) |
3768 | 222a3336 | balrog | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3769 | 222a3336 | balrog | reg = ((modrm >> 3) & 7) | rex_r; |
3770 | 222a3336 | balrog | val = ldub_code(s->pc++); |
3771 | 222a3336 | balrog | switch (b) {
|
3772 | 222a3336 | balrog | case 0x14: /* pextrb */ |
3773 | 222a3336 | balrog | tcg_gen_ld8u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,
|
3774 | 222a3336 | balrog | xmm_regs[reg].XMM_B(val & 15)));
|
3775 | 222a3336 | balrog | if (mod == 3) |
3776 | 222a3336 | balrog | gen_op_mov_reg_T0(ot, rm); |
3777 | 222a3336 | balrog | else
|
3778 | 222a3336 | balrog | tcg_gen_qemu_st8(cpu_T[0], cpu_A0,
|
3779 | 222a3336 | balrog | (s->mem_index >> 2) - 1); |
3780 | 222a3336 | balrog | break;
|
3781 | 222a3336 | balrog | case 0x15: /* pextrw */ |
3782 | 222a3336 | balrog | tcg_gen_ld16u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,
|
3783 | 222a3336 | balrog | xmm_regs[reg].XMM_W(val & 7)));
|
3784 | 222a3336 | balrog | if (mod == 3) |
3785 | 222a3336 | balrog | gen_op_mov_reg_T0(ot, rm); |
3786 | 222a3336 | balrog | else
|
3787 | 222a3336 | balrog | tcg_gen_qemu_st16(cpu_T[0], cpu_A0,
|
3788 | 222a3336 | balrog | (s->mem_index >> 2) - 1); |
3789 | 222a3336 | balrog | break;
|
3790 | 222a3336 | balrog | case 0x16: |
3791 | 222a3336 | balrog | if (ot == OT_LONG) { /* pextrd */ |
3792 | 222a3336 | balrog | tcg_gen_ld_i32(cpu_tmp2_i32, cpu_env, |
3793 | 222a3336 | balrog | offsetof(CPUX86State, |
3794 | 222a3336 | balrog | xmm_regs[reg].XMM_L(val & 3)));
|
3795 | a7812ae4 | pbrook | tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
3796 | 222a3336 | balrog | if (mod == 3) |
3797 | a7812ae4 | pbrook | gen_op_mov_reg_v(ot, rm, cpu_T[0]);
|
3798 | 222a3336 | balrog | else
|
3799 | a7812ae4 | pbrook | tcg_gen_qemu_st32(cpu_T[0], cpu_A0,
|
3800 | 222a3336 | balrog | (s->mem_index >> 2) - 1); |
3801 | 222a3336 | balrog | } else { /* pextrq */ |
3802 | a7812ae4 | pbrook | #ifdef TARGET_X86_64
|
3803 | 222a3336 | balrog | tcg_gen_ld_i64(cpu_tmp1_i64, cpu_env, |
3804 | 222a3336 | balrog | offsetof(CPUX86State, |
3805 | 222a3336 | balrog | xmm_regs[reg].XMM_Q(val & 1)));
|
3806 | 222a3336 | balrog | if (mod == 3) |
3807 | 222a3336 | balrog | gen_op_mov_reg_v(ot, rm, cpu_tmp1_i64); |
3808 | 222a3336 | balrog | else
|
3809 | 222a3336 | balrog | tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_A0, |
3810 | 222a3336 | balrog | (s->mem_index >> 2) - 1); |
3811 | a7812ae4 | pbrook | #else
|
3812 | a7812ae4 | pbrook | goto illegal_op;
|
3813 | a7812ae4 | pbrook | #endif
|
3814 | 222a3336 | balrog | } |
3815 | 222a3336 | balrog | break;
|
3816 | 222a3336 | balrog | case 0x17: /* extractps */ |
3817 | 222a3336 | balrog | tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,
|
3818 | 222a3336 | balrog | xmm_regs[reg].XMM_L(val & 3)));
|
3819 | 222a3336 | balrog | if (mod == 3) |
3820 | 222a3336 | balrog | gen_op_mov_reg_T0(ot, rm); |
3821 | 222a3336 | balrog | else
|
3822 | 222a3336 | balrog | tcg_gen_qemu_st32(cpu_T[0], cpu_A0,
|
3823 | 222a3336 | balrog | (s->mem_index >> 2) - 1); |
3824 | 222a3336 | balrog | break;
|
3825 | 222a3336 | balrog | case 0x20: /* pinsrb */ |
3826 | 222a3336 | balrog | if (mod == 3) |
3827 | 222a3336 | balrog | gen_op_mov_TN_reg(OT_LONG, 0, rm);
|
3828 | 222a3336 | balrog | else
|
3829 | a7812ae4 | pbrook | tcg_gen_qemu_ld8u(cpu_tmp0, cpu_A0, |
3830 | 222a3336 | balrog | (s->mem_index >> 2) - 1); |
3831 | a7812ae4 | pbrook | tcg_gen_st8_tl(cpu_tmp0, cpu_env, offsetof(CPUX86State, |
3832 | 222a3336 | balrog | xmm_regs[reg].XMM_B(val & 15)));
|
3833 | 222a3336 | balrog | break;
|
3834 | 222a3336 | balrog | case 0x21: /* insertps */ |
3835 | a7812ae4 | pbrook | if (mod == 3) { |
3836 | 222a3336 | balrog | tcg_gen_ld_i32(cpu_tmp2_i32, cpu_env, |
3837 | 222a3336 | balrog | offsetof(CPUX86State,xmm_regs[rm] |
3838 | 222a3336 | balrog | .XMM_L((val >> 6) & 3))); |
3839 | a7812ae4 | pbrook | } else {
|
3840 | a7812ae4 | pbrook | tcg_gen_qemu_ld32u(cpu_tmp0, cpu_A0, |
3841 | 222a3336 | balrog | (s->mem_index >> 2) - 1); |
3842 | a7812ae4 | pbrook | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_tmp0); |
3843 | a7812ae4 | pbrook | } |
3844 | 222a3336 | balrog | tcg_gen_st_i32(cpu_tmp2_i32, cpu_env, |
3845 | 222a3336 | balrog | offsetof(CPUX86State,xmm_regs[reg] |
3846 | 222a3336 | balrog | .XMM_L((val >> 4) & 3))); |
3847 | 222a3336 | balrog | if ((val >> 0) & 1) |
3848 | 222a3336 | balrog | tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/), |
3849 | 222a3336 | balrog | cpu_env, offsetof(CPUX86State, |
3850 | 222a3336 | balrog | xmm_regs[reg].XMM_L(0)));
|
3851 | 222a3336 | balrog | if ((val >> 1) & 1) |
3852 | 222a3336 | balrog | tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/), |
3853 | 222a3336 | balrog | cpu_env, offsetof(CPUX86State, |
3854 | 222a3336 | balrog | xmm_regs[reg].XMM_L(1)));
|
3855 | 222a3336 | balrog | if ((val >> 2) & 1) |
3856 | 222a3336 | balrog | tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/), |
3857 | 222a3336 | balrog | cpu_env, offsetof(CPUX86State, |
3858 | 222a3336 | balrog | xmm_regs[reg].XMM_L(2)));
|
3859 | 222a3336 | balrog | if ((val >> 3) & 1) |
3860 | 222a3336 | balrog | tcg_gen_st_i32(tcg_const_i32(0 /*float32_zero*/), |
3861 | 222a3336 | balrog | cpu_env, offsetof(CPUX86State, |
3862 | 222a3336 | balrog | xmm_regs[reg].XMM_L(3)));
|
3863 | 222a3336 | balrog | break;
|
3864 | 222a3336 | balrog | case 0x22: |
3865 | 222a3336 | balrog | if (ot == OT_LONG) { /* pinsrd */ |
3866 | 222a3336 | balrog | if (mod == 3) |
3867 | a7812ae4 | pbrook | gen_op_mov_v_reg(ot, cpu_tmp0, rm); |
3868 | 222a3336 | balrog | else
|
3869 | a7812ae4 | pbrook | tcg_gen_qemu_ld32u(cpu_tmp0, cpu_A0, |
3870 | 222a3336 | balrog | (s->mem_index >> 2) - 1); |
3871 | a7812ae4 | pbrook | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_tmp0); |
3872 | 222a3336 | balrog | tcg_gen_st_i32(cpu_tmp2_i32, cpu_env, |
3873 | 222a3336 | balrog | offsetof(CPUX86State, |
3874 | 222a3336 | balrog | xmm_regs[reg].XMM_L(val & 3)));
|
3875 | 222a3336 | balrog | } else { /* pinsrq */ |
3876 | a7812ae4 | pbrook | #ifdef TARGET_X86_64
|
3877 | 222a3336 | balrog | if (mod == 3) |
3878 | 222a3336 | balrog | gen_op_mov_v_reg(ot, cpu_tmp1_i64, rm); |
3879 | 222a3336 | balrog | else
|
3880 | 222a3336 | balrog | tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_A0, |
3881 | 222a3336 | balrog | (s->mem_index >> 2) - 1); |
3882 | 222a3336 | balrog | tcg_gen_st_i64(cpu_tmp1_i64, cpu_env, |
3883 | 222a3336 | balrog | offsetof(CPUX86State, |
3884 | 222a3336 | balrog | xmm_regs[reg].XMM_Q(val & 1)));
|
3885 | a7812ae4 | pbrook | #else
|
3886 | a7812ae4 | pbrook | goto illegal_op;
|
3887 | a7812ae4 | pbrook | #endif
|
3888 | 222a3336 | balrog | } |
3889 | 222a3336 | balrog | break;
|
3890 | 222a3336 | balrog | } |
3891 | 222a3336 | balrog | return;
|
3892 | 222a3336 | balrog | } |
3893 | 4242b1bd | balrog | |
3894 | 4242b1bd | balrog | if (b1) {
|
3895 | 4242b1bd | balrog | op1_offset = offsetof(CPUX86State,xmm_regs[reg]); |
3896 | 4242b1bd | balrog | if (mod == 3) { |
3897 | 4242b1bd | balrog | op2_offset = offsetof(CPUX86State,xmm_regs[rm | REX_B(s)]); |
3898 | 4242b1bd | balrog | } else {
|
3899 | 4242b1bd | balrog | op2_offset = offsetof(CPUX86State,xmm_t0); |
3900 | 4242b1bd | balrog | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3901 | 4242b1bd | balrog | gen_ldo_env_A0(s->mem_index, op2_offset); |
3902 | 4242b1bd | balrog | } |
3903 | 4242b1bd | balrog | } else {
|
3904 | 4242b1bd | balrog | op1_offset = offsetof(CPUX86State,fpregs[reg].mmx); |
3905 | 4242b1bd | balrog | if (mod == 3) { |
3906 | 4242b1bd | balrog | op2_offset = offsetof(CPUX86State,fpregs[rm].mmx); |
3907 | 4242b1bd | balrog | } else {
|
3908 | 4242b1bd | balrog | op2_offset = offsetof(CPUX86State,mmx_t0); |
3909 | 4242b1bd | balrog | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3910 | 4242b1bd | balrog | gen_ldq_env_A0(s->mem_index, op2_offset); |
3911 | 4242b1bd | balrog | } |
3912 | 4242b1bd | balrog | } |
3913 | 4242b1bd | balrog | val = ldub_code(s->pc++); |
3914 | 4242b1bd | balrog | |
3915 | 222a3336 | balrog | if ((b & 0xfc) == 0x60) { /* pcmpXstrX */ |
3916 | 222a3336 | balrog | s->cc_op = CC_OP_EFLAGS; |
3917 | 222a3336 | balrog | |
3918 | 222a3336 | balrog | if (s->dflag == 2) |
3919 | 222a3336 | balrog | /* The helper must use entire 64-bit gp registers */
|
3920 | 222a3336 | balrog | val |= 1 << 8; |
3921 | 222a3336 | balrog | } |
3922 | 222a3336 | balrog | |
3923 | 4242b1bd | balrog | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
3924 | 4242b1bd | balrog | tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
3925 | a7812ae4 | pbrook | ((void (*)(TCGv_ptr, TCGv_ptr, TCGv_i32))sse_op2)(cpu_ptr0, cpu_ptr1, tcg_const_i32(val));
|
3926 | 4242b1bd | balrog | break;
|
3927 | 664e0f19 | bellard | default:
|
3928 | 664e0f19 | bellard | goto illegal_op;
|
3929 | 664e0f19 | bellard | } |
3930 | 664e0f19 | bellard | } else {
|
3931 | 664e0f19 | bellard | /* generic MMX or SSE operation */
|
3932 | d1e42c5c | bellard | switch(b) {
|
3933 | d1e42c5c | bellard | case 0x70: /* pshufx insn */ |
3934 | d1e42c5c | bellard | case 0xc6: /* pshufx insn */ |
3935 | d1e42c5c | bellard | case 0xc2: /* compare insns */ |
3936 | d1e42c5c | bellard | s->rip_offset = 1;
|
3937 | d1e42c5c | bellard | break;
|
3938 | d1e42c5c | bellard | default:
|
3939 | d1e42c5c | bellard | break;
|
3940 | 664e0f19 | bellard | } |
3941 | 664e0f19 | bellard | if (is_xmm) {
|
3942 | 664e0f19 | bellard | op1_offset = offsetof(CPUX86State,xmm_regs[reg]); |
3943 | 664e0f19 | bellard | if (mod != 3) { |
3944 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3945 | 664e0f19 | bellard | op2_offset = offsetof(CPUX86State,xmm_t0); |
3946 | 480c1cdb | bellard | if (b1 >= 2 && ((b >= 0x50 && b <= 0x5f && b != 0x5b) || |
3947 | 664e0f19 | bellard | b == 0xc2)) {
|
3948 | 664e0f19 | bellard | /* specific case for SSE single instructions */
|
3949 | 664e0f19 | bellard | if (b1 == 2) { |
3950 | 664e0f19 | bellard | /* 32 bit access */
|
3951 | 57fec1fe | bellard | gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
3952 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,xmm_t0.XMM_L(0))); |
3953 | 664e0f19 | bellard | } else {
|
3954 | 664e0f19 | bellard | /* 64 bit access */
|
3955 | 8686c490 | bellard | gen_ldq_env_A0(s->mem_index, offsetof(CPUX86State,xmm_t0.XMM_D(0)));
|
3956 | 664e0f19 | bellard | } |
3957 | 664e0f19 | bellard | } else {
|
3958 | 8686c490 | bellard | gen_ldo_env_A0(s->mem_index, op2_offset); |
3959 | 664e0f19 | bellard | } |
3960 | 664e0f19 | bellard | } else {
|
3961 | 664e0f19 | bellard | rm = (modrm & 7) | REX_B(s);
|
3962 | 664e0f19 | bellard | op2_offset = offsetof(CPUX86State,xmm_regs[rm]); |
3963 | 664e0f19 | bellard | } |
3964 | 664e0f19 | bellard | } else {
|
3965 | 664e0f19 | bellard | op1_offset = offsetof(CPUX86State,fpregs[reg].mmx); |
3966 | 664e0f19 | bellard | if (mod != 3) { |
3967 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3968 | 664e0f19 | bellard | op2_offset = offsetof(CPUX86State,mmx_t0); |
3969 | 8686c490 | bellard | gen_ldq_env_A0(s->mem_index, op2_offset); |
3970 | 664e0f19 | bellard | } else {
|
3971 | 664e0f19 | bellard | rm = (modrm & 7);
|
3972 | 664e0f19 | bellard | op2_offset = offsetof(CPUX86State,fpregs[rm].mmx); |
3973 | 664e0f19 | bellard | } |
3974 | 664e0f19 | bellard | } |
3975 | 664e0f19 | bellard | switch(b) {
|
3976 | a35f3ec7 | aurel32 | case 0x0f: /* 3DNow! data insns */ |
3977 | e771edab | aurel32 | if (!(s->cpuid_ext2_features & CPUID_EXT2_3DNOW))
|
3978 | e771edab | aurel32 | goto illegal_op;
|
3979 | a35f3ec7 | aurel32 | val = ldub_code(s->pc++); |
3980 | a35f3ec7 | aurel32 | sse_op2 = sse_op_table5[val]; |
3981 | a35f3ec7 | aurel32 | if (!sse_op2)
|
3982 | a35f3ec7 | aurel32 | goto illegal_op;
|
3983 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
3984 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
3985 | a7812ae4 | pbrook | ((void (*)(TCGv_ptr, TCGv_ptr))sse_op2)(cpu_ptr0, cpu_ptr1);
|
3986 | a35f3ec7 | aurel32 | break;
|
3987 | 664e0f19 | bellard | case 0x70: /* pshufx insn */ |
3988 | 664e0f19 | bellard | case 0xc6: /* pshufx insn */ |
3989 | 664e0f19 | bellard | val = ldub_code(s->pc++); |
3990 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
3991 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
3992 | a7812ae4 | pbrook | ((void (*)(TCGv_ptr, TCGv_ptr, TCGv_i32))sse_op2)(cpu_ptr0, cpu_ptr1, tcg_const_i32(val));
|
3993 | 664e0f19 | bellard | break;
|
3994 | 664e0f19 | bellard | case 0xc2: |
3995 | 664e0f19 | bellard | /* compare insns */
|
3996 | 664e0f19 | bellard | val = ldub_code(s->pc++); |
3997 | 664e0f19 | bellard | if (val >= 8) |
3998 | 664e0f19 | bellard | goto illegal_op;
|
3999 | 664e0f19 | bellard | sse_op2 = sse_op_table4[val][b1]; |
4000 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
4001 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
4002 | a7812ae4 | pbrook | ((void (*)(TCGv_ptr, TCGv_ptr))sse_op2)(cpu_ptr0, cpu_ptr1);
|
4003 | 664e0f19 | bellard | break;
|
4004 | b8b6a50b | bellard | case 0xf7: |
4005 | b8b6a50b | bellard | /* maskmov : we must prepare A0 */
|
4006 | b8b6a50b | bellard | if (mod != 3) |
4007 | b8b6a50b | bellard | goto illegal_op;
|
4008 | b8b6a50b | bellard | #ifdef TARGET_X86_64
|
4009 | b8b6a50b | bellard | if (s->aflag == 2) { |
4010 | b8b6a50b | bellard | gen_op_movq_A0_reg(R_EDI); |
4011 | b8b6a50b | bellard | } else
|
4012 | b8b6a50b | bellard | #endif
|
4013 | b8b6a50b | bellard | { |
4014 | b8b6a50b | bellard | gen_op_movl_A0_reg(R_EDI); |
4015 | b8b6a50b | bellard | if (s->aflag == 0) |
4016 | b8b6a50b | bellard | gen_op_andl_A0_ffff(); |
4017 | b8b6a50b | bellard | } |
4018 | b8b6a50b | bellard | gen_add_A0_ds_seg(s); |
4019 | b8b6a50b | bellard | |
4020 | b8b6a50b | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
4021 | b8b6a50b | bellard | tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
4022 | a7812ae4 | pbrook | ((void (*)(TCGv_ptr, TCGv_ptr, TCGv))sse_op2)(cpu_ptr0, cpu_ptr1, cpu_A0);
|
4023 | b8b6a50b | bellard | break;
|
4024 | 664e0f19 | bellard | default:
|
4025 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr0, cpu_env, op1_offset); |
4026 | 5af45186 | bellard | tcg_gen_addi_ptr(cpu_ptr1, cpu_env, op2_offset); |
4027 | a7812ae4 | pbrook | ((void (*)(TCGv_ptr, TCGv_ptr))sse_op2)(cpu_ptr0, cpu_ptr1);
|
4028 | 664e0f19 | bellard | break;
|
4029 | 664e0f19 | bellard | } |
4030 | 664e0f19 | bellard | if (b == 0x2e || b == 0x2f) { |
4031 | 664e0f19 | bellard | s->cc_op = CC_OP_EFLAGS; |
4032 | 664e0f19 | bellard | } |
4033 | 664e0f19 | bellard | } |
4034 | 664e0f19 | bellard | } |
4035 | 664e0f19 | bellard | |
4036 | 2c0262af | bellard | /* convert one instruction. s->is_jmp is set if the translation must
|
4037 | 2c0262af | bellard | be stopped. Return the next pc value */
|
4038 | 14ce26e7 | bellard | static target_ulong disas_insn(DisasContext *s, target_ulong pc_start)
|
4039 | 2c0262af | bellard | { |
4040 | 2c0262af | bellard | int b, prefixes, aflag, dflag;
|
4041 | 2c0262af | bellard | int shift, ot;
|
4042 | 2c0262af | bellard | int modrm, reg, rm, mod, reg_addr, op, opreg, offset_addr, val;
|
4043 | 14ce26e7 | bellard | target_ulong next_eip, tval; |
4044 | 14ce26e7 | bellard | int rex_w, rex_r;
|
4045 | 2c0262af | bellard | |
4046 | 8fec2b8c | aliguori | if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP)))
|
4047 | 70cff25e | bellard | tcg_gen_debug_insn_start(pc_start); |
4048 | 2c0262af | bellard | s->pc = pc_start; |
4049 | 2c0262af | bellard | prefixes = 0;
|
4050 | 2c0262af | bellard | aflag = s->code32; |
4051 | 2c0262af | bellard | dflag = s->code32; |
4052 | 2c0262af | bellard | s->override = -1;
|
4053 | 14ce26e7 | bellard | rex_w = -1;
|
4054 | 14ce26e7 | bellard | rex_r = 0;
|
4055 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
4056 | 14ce26e7 | bellard | s->rex_x = 0;
|
4057 | 14ce26e7 | bellard | s->rex_b = 0;
|
4058 | 5fafdf24 | ths | x86_64_hregs = 0;
|
4059 | 14ce26e7 | bellard | #endif
|
4060 | 14ce26e7 | bellard | s->rip_offset = 0; /* for relative ip address */ |
4061 | 2c0262af | bellard | next_byte:
|
4062 | 61382a50 | bellard | b = ldub_code(s->pc); |
4063 | 2c0262af | bellard | s->pc++; |
4064 | 2c0262af | bellard | /* check prefixes */
|
4065 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
4066 | 14ce26e7 | bellard | if (CODE64(s)) {
|
4067 | 14ce26e7 | bellard | switch (b) {
|
4068 | 14ce26e7 | bellard | case 0xf3: |
4069 | 14ce26e7 | bellard | prefixes |= PREFIX_REPZ; |
4070 | 14ce26e7 | bellard | goto next_byte;
|
4071 | 14ce26e7 | bellard | case 0xf2: |
4072 | 14ce26e7 | bellard | prefixes |= PREFIX_REPNZ; |
4073 | 14ce26e7 | bellard | goto next_byte;
|
4074 | 14ce26e7 | bellard | case 0xf0: |
4075 | 14ce26e7 | bellard | prefixes |= PREFIX_LOCK; |
4076 | 14ce26e7 | bellard | goto next_byte;
|
4077 | 14ce26e7 | bellard | case 0x2e: |
4078 | 14ce26e7 | bellard | s->override = R_CS; |
4079 | 14ce26e7 | bellard | goto next_byte;
|
4080 | 14ce26e7 | bellard | case 0x36: |
4081 | 14ce26e7 | bellard | s->override = R_SS; |
4082 | 14ce26e7 | bellard | goto next_byte;
|
4083 | 14ce26e7 | bellard | case 0x3e: |
4084 | 14ce26e7 | bellard | s->override = R_DS; |
4085 | 14ce26e7 | bellard | goto next_byte;
|
4086 | 14ce26e7 | bellard | case 0x26: |
4087 | 14ce26e7 | bellard | s->override = R_ES; |
4088 | 14ce26e7 | bellard | goto next_byte;
|
4089 | 14ce26e7 | bellard | case 0x64: |
4090 | 14ce26e7 | bellard | s->override = R_FS; |
4091 | 14ce26e7 | bellard | goto next_byte;
|
4092 | 14ce26e7 | bellard | case 0x65: |
4093 | 14ce26e7 | bellard | s->override = R_GS; |
4094 | 14ce26e7 | bellard | goto next_byte;
|
4095 | 14ce26e7 | bellard | case 0x66: |
4096 | 14ce26e7 | bellard | prefixes |= PREFIX_DATA; |
4097 | 14ce26e7 | bellard | goto next_byte;
|
4098 | 14ce26e7 | bellard | case 0x67: |
4099 | 14ce26e7 | bellard | prefixes |= PREFIX_ADR; |
4100 | 14ce26e7 | bellard | goto next_byte;
|
4101 | 14ce26e7 | bellard | case 0x40 ... 0x4f: |
4102 | 14ce26e7 | bellard | /* REX prefix */
|
4103 | 14ce26e7 | bellard | rex_w = (b >> 3) & 1; |
4104 | 14ce26e7 | bellard | rex_r = (b & 0x4) << 1; |
4105 | 14ce26e7 | bellard | s->rex_x = (b & 0x2) << 2; |
4106 | 14ce26e7 | bellard | REX_B(s) = (b & 0x1) << 3; |
4107 | 14ce26e7 | bellard | x86_64_hregs = 1; /* select uniform byte register addressing */ |
4108 | 14ce26e7 | bellard | goto next_byte;
|
4109 | 14ce26e7 | bellard | } |
4110 | 14ce26e7 | bellard | if (rex_w == 1) { |
4111 | 14ce26e7 | bellard | /* 0x66 is ignored if rex.w is set */
|
4112 | 14ce26e7 | bellard | dflag = 2;
|
4113 | 14ce26e7 | bellard | } else {
|
4114 | 14ce26e7 | bellard | if (prefixes & PREFIX_DATA)
|
4115 | 14ce26e7 | bellard | dflag ^= 1;
|
4116 | 14ce26e7 | bellard | } |
4117 | 14ce26e7 | bellard | if (!(prefixes & PREFIX_ADR))
|
4118 | 14ce26e7 | bellard | aflag = 2;
|
4119 | 5fafdf24 | ths | } else
|
4120 | 14ce26e7 | bellard | #endif
|
4121 | 14ce26e7 | bellard | { |
4122 | 14ce26e7 | bellard | switch (b) {
|
4123 | 14ce26e7 | bellard | case 0xf3: |
4124 | 14ce26e7 | bellard | prefixes |= PREFIX_REPZ; |
4125 | 14ce26e7 | bellard | goto next_byte;
|
4126 | 14ce26e7 | bellard | case 0xf2: |
4127 | 14ce26e7 | bellard | prefixes |= PREFIX_REPNZ; |
4128 | 14ce26e7 | bellard | goto next_byte;
|
4129 | 14ce26e7 | bellard | case 0xf0: |
4130 | 14ce26e7 | bellard | prefixes |= PREFIX_LOCK; |
4131 | 14ce26e7 | bellard | goto next_byte;
|
4132 | 14ce26e7 | bellard | case 0x2e: |
4133 | 14ce26e7 | bellard | s->override = R_CS; |
4134 | 14ce26e7 | bellard | goto next_byte;
|
4135 | 14ce26e7 | bellard | case 0x36: |
4136 | 14ce26e7 | bellard | s->override = R_SS; |
4137 | 14ce26e7 | bellard | goto next_byte;
|
4138 | 14ce26e7 | bellard | case 0x3e: |
4139 | 14ce26e7 | bellard | s->override = R_DS; |
4140 | 14ce26e7 | bellard | goto next_byte;
|
4141 | 14ce26e7 | bellard | case 0x26: |
4142 | 14ce26e7 | bellard | s->override = R_ES; |
4143 | 14ce26e7 | bellard | goto next_byte;
|
4144 | 14ce26e7 | bellard | case 0x64: |
4145 | 14ce26e7 | bellard | s->override = R_FS; |
4146 | 14ce26e7 | bellard | goto next_byte;
|
4147 | 14ce26e7 | bellard | case 0x65: |
4148 | 14ce26e7 | bellard | s->override = R_GS; |
4149 | 14ce26e7 | bellard | goto next_byte;
|
4150 | 14ce26e7 | bellard | case 0x66: |
4151 | 14ce26e7 | bellard | prefixes |= PREFIX_DATA; |
4152 | 14ce26e7 | bellard | goto next_byte;
|
4153 | 14ce26e7 | bellard | case 0x67: |
4154 | 14ce26e7 | bellard | prefixes |= PREFIX_ADR; |
4155 | 14ce26e7 | bellard | goto next_byte;
|
4156 | 14ce26e7 | bellard | } |
4157 | 14ce26e7 | bellard | if (prefixes & PREFIX_DATA)
|
4158 | 14ce26e7 | bellard | dflag ^= 1;
|
4159 | 14ce26e7 | bellard | if (prefixes & PREFIX_ADR)
|
4160 | 14ce26e7 | bellard | aflag ^= 1;
|
4161 | 2c0262af | bellard | } |
4162 | 2c0262af | bellard | |
4163 | 2c0262af | bellard | s->prefix = prefixes; |
4164 | 2c0262af | bellard | s->aflag = aflag; |
4165 | 2c0262af | bellard | s->dflag = dflag; |
4166 | 2c0262af | bellard | |
4167 | 2c0262af | bellard | /* lock generation */
|
4168 | 2c0262af | bellard | if (prefixes & PREFIX_LOCK)
|
4169 | a7812ae4 | pbrook | gen_helper_lock(); |
4170 | 2c0262af | bellard | |
4171 | 2c0262af | bellard | /* now check op code */
|
4172 | 2c0262af | bellard | reswitch:
|
4173 | 2c0262af | bellard | switch(b) {
|
4174 | 2c0262af | bellard | case 0x0f: |
4175 | 2c0262af | bellard | /**************************/
|
4176 | 2c0262af | bellard | /* extended op code */
|
4177 | 61382a50 | bellard | b = ldub_code(s->pc++) | 0x100;
|
4178 | 2c0262af | bellard | goto reswitch;
|
4179 | 3b46e624 | ths | |
4180 | 2c0262af | bellard | /**************************/
|
4181 | 2c0262af | bellard | /* arith & logic */
|
4182 | 2c0262af | bellard | case 0x00 ... 0x05: |
4183 | 2c0262af | bellard | case 0x08 ... 0x0d: |
4184 | 2c0262af | bellard | case 0x10 ... 0x15: |
4185 | 2c0262af | bellard | case 0x18 ... 0x1d: |
4186 | 2c0262af | bellard | case 0x20 ... 0x25: |
4187 | 2c0262af | bellard | case 0x28 ... 0x2d: |
4188 | 2c0262af | bellard | case 0x30 ... 0x35: |
4189 | 2c0262af | bellard | case 0x38 ... 0x3d: |
4190 | 2c0262af | bellard | { |
4191 | 2c0262af | bellard | int op, f, val;
|
4192 | 2c0262af | bellard | op = (b >> 3) & 7; |
4193 | 2c0262af | bellard | f = (b >> 1) & 3; |
4194 | 2c0262af | bellard | |
4195 | 2c0262af | bellard | if ((b & 1) == 0) |
4196 | 2c0262af | bellard | ot = OT_BYTE; |
4197 | 2c0262af | bellard | else
|
4198 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
4199 | 3b46e624 | ths | |
4200 | 2c0262af | bellard | switch(f) {
|
4201 | 2c0262af | bellard | case 0: /* OP Ev, Gv */ |
4202 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
4203 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
4204 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
4205 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
4206 | 2c0262af | bellard | if (mod != 3) { |
4207 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
4208 | 2c0262af | bellard | opreg = OR_TMP0; |
4209 | 2c0262af | bellard | } else if (op == OP_XORL && rm == reg) { |
4210 | 2c0262af | bellard | xor_zero:
|
4211 | 2c0262af | bellard | /* xor reg, reg optimisation */
|
4212 | 2c0262af | bellard | gen_op_movl_T0_0(); |
4213 | 2c0262af | bellard | s->cc_op = CC_OP_LOGICB + ot; |
4214 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, reg); |
4215 | 2c0262af | bellard | gen_op_update1_cc(); |
4216 | 2c0262af | bellard | break;
|
4217 | 2c0262af | bellard | } else {
|
4218 | 2c0262af | bellard | opreg = rm; |
4219 | 2c0262af | bellard | } |
4220 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 1, reg);
|
4221 | 2c0262af | bellard | gen_op(s, op, ot, opreg); |
4222 | 2c0262af | bellard | break;
|
4223 | 2c0262af | bellard | case 1: /* OP Gv, Ev */ |
4224 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
4225 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
4226 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
4227 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
4228 | 2c0262af | bellard | if (mod != 3) { |
4229 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
4230 | 57fec1fe | bellard | gen_op_ld_T1_A0(ot + s->mem_index); |
4231 | 2c0262af | bellard | } else if (op == OP_XORL && rm == reg) { |
4232 | 2c0262af | bellard | goto xor_zero;
|
4233 | 2c0262af | bellard | } else {
|
4234 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 1, rm);
|
4235 | 2c0262af | bellard | } |
4236 | 2c0262af | bellard | gen_op(s, op, ot, reg); |
4237 | 2c0262af | bellard | break;
|
4238 | 2c0262af | bellard | case 2: /* OP A, Iv */ |
4239 | 2c0262af | bellard | val = insn_get(s, ot); |
4240 | 2c0262af | bellard | gen_op_movl_T1_im(val); |
4241 | 2c0262af | bellard | gen_op(s, op, ot, OR_EAX); |
4242 | 2c0262af | bellard | break;
|
4243 | 2c0262af | bellard | } |
4244 | 2c0262af | bellard | } |
4245 | 2c0262af | bellard | break;
|
4246 | 2c0262af | bellard | |
4247 | ec9d6075 | bellard | case 0x82: |
4248 | ec9d6075 | bellard | if (CODE64(s))
|
4249 | ec9d6075 | bellard | goto illegal_op;
|
4250 | 2c0262af | bellard | case 0x80: /* GRP1 */ |
4251 | 2c0262af | bellard | case 0x81: |
4252 | 2c0262af | bellard | case 0x83: |
4253 | 2c0262af | bellard | { |
4254 | 2c0262af | bellard | int val;
|
4255 | 2c0262af | bellard | |
4256 | 2c0262af | bellard | if ((b & 1) == 0) |
4257 | 2c0262af | bellard | ot = OT_BYTE; |
4258 | 2c0262af | bellard | else
|
4259 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
4260 | 3b46e624 | ths | |
4261 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
4262 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
4263 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
4264 | 2c0262af | bellard | op = (modrm >> 3) & 7; |
4265 | 3b46e624 | ths | |
4266 | 2c0262af | bellard | if (mod != 3) { |
4267 | 14ce26e7 | bellard | if (b == 0x83) |
4268 | 14ce26e7 | bellard | s->rip_offset = 1;
|
4269 | 14ce26e7 | bellard | else
|
4270 | 14ce26e7 | bellard | s->rip_offset = insn_const_size(ot); |
4271 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
4272 | 2c0262af | bellard | opreg = OR_TMP0; |
4273 | 2c0262af | bellard | } else {
|
4274 | 14ce26e7 | bellard | opreg = rm; |
4275 | 2c0262af | bellard | } |
4276 | 2c0262af | bellard | |
4277 | 2c0262af | bellard | switch(b) {
|
4278 | 2c0262af | bellard | default:
|
4279 | 2c0262af | bellard | case 0x80: |
4280 | 2c0262af | bellard | case 0x81: |
4281 | d64477af | bellard | case 0x82: |
4282 | 2c0262af | bellard | val = insn_get(s, ot); |
4283 | 2c0262af | bellard | break;
|
4284 | 2c0262af | bellard | case 0x83: |
4285 | 2c0262af | bellard | val = (int8_t)insn_get(s, OT_BYTE); |
4286 | 2c0262af | bellard | break;
|
4287 | 2c0262af | bellard | } |
4288 | 2c0262af | bellard | gen_op_movl_T1_im(val); |
4289 | 2c0262af | bellard | gen_op(s, op, ot, opreg); |
4290 | 2c0262af | bellard | } |
4291 | 2c0262af | bellard | break;
|
4292 | 2c0262af | bellard | |
4293 | 2c0262af | bellard | /**************************/
|
4294 | 2c0262af | bellard | /* inc, dec, and other misc arith */
|
4295 | 2c0262af | bellard | case 0x40 ... 0x47: /* inc Gv */ |
4296 | 2c0262af | bellard | ot = dflag ? OT_LONG : OT_WORD; |
4297 | 2c0262af | bellard | gen_inc(s, ot, OR_EAX + (b & 7), 1); |
4298 | 2c0262af | bellard | break;
|
4299 | 2c0262af | bellard | case 0x48 ... 0x4f: /* dec Gv */ |
4300 | 2c0262af | bellard | ot = dflag ? OT_LONG : OT_WORD; |
4301 | 2c0262af | bellard | gen_inc(s, ot, OR_EAX + (b & 7), -1); |
4302 | 2c0262af | bellard | break;
|
4303 | 2c0262af | bellard | case 0xf6: /* GRP3 */ |
4304 | 2c0262af | bellard | case 0xf7: |
4305 | 2c0262af | bellard | if ((b & 1) == 0) |
4306 | 2c0262af | bellard | ot = OT_BYTE; |
4307 | 2c0262af | bellard | else
|
4308 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
4309 | 2c0262af | bellard | |
4310 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
4311 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
4312 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
4313 | 2c0262af | bellard | op = (modrm >> 3) & 7; |
4314 | 2c0262af | bellard | if (mod != 3) { |
4315 | 14ce26e7 | bellard | if (op == 0) |
4316 | 14ce26e7 | bellard | s->rip_offset = insn_const_size(ot); |
4317 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
4318 | 57fec1fe | bellard | gen_op_ld_T0_A0(ot + s->mem_index); |
4319 | 2c0262af | bellard | } else {
|
4320 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, rm);
|
4321 | 2c0262af | bellard | } |
4322 | 2c0262af | bellard | |
4323 | 2c0262af | bellard | switch(op) {
|
4324 | 2c0262af | bellard | case 0: /* test */ |
4325 | 2c0262af | bellard | val = insn_get(s, ot); |
4326 | 2c0262af | bellard | gen_op_movl_T1_im(val); |
4327 | 2c0262af | bellard | gen_op_testl_T0_T1_cc(); |
4328 | 2c0262af | bellard | s->cc_op = CC_OP_LOGICB + ot; |
4329 | 2c0262af | bellard | break;
|
4330 | 2c0262af | bellard | case 2: /* not */ |
4331 | b6abf97d | bellard | tcg_gen_not_tl(cpu_T[0], cpu_T[0]); |
4332 | 2c0262af | bellard | if (mod != 3) { |
4333 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
4334 | 2c0262af | bellard | } else {
|
4335 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, rm); |
4336 | 2c0262af | bellard | } |
4337 | 2c0262af | bellard | break;
|
4338 | 2c0262af | bellard | case 3: /* neg */ |
4339 | b6abf97d | bellard | tcg_gen_neg_tl(cpu_T[0], cpu_T[0]); |
4340 | 2c0262af | bellard | if (mod != 3) { |
4341 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
4342 | 2c0262af | bellard | } else {
|
4343 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, rm); |
4344 | 2c0262af | bellard | } |
4345 | 2c0262af | bellard | gen_op_update_neg_cc(); |
4346 | 2c0262af | bellard | s->cc_op = CC_OP_SUBB + ot; |
4347 | 2c0262af | bellard | break;
|
4348 | 2c0262af | bellard | case 4: /* mul */ |
4349 | 2c0262af | bellard | switch(ot) {
|
4350 | 2c0262af | bellard | case OT_BYTE:
|
4351 | 0211e5af | bellard | gen_op_mov_TN_reg(OT_BYTE, 1, R_EAX);
|
4352 | 0211e5af | bellard | tcg_gen_ext8u_tl(cpu_T[0], cpu_T[0]); |
4353 | 0211e5af | bellard | tcg_gen_ext8u_tl(cpu_T[1], cpu_T[1]); |
4354 | 0211e5af | bellard | /* XXX: use 32 bit mul which could be faster */
|
4355 | 0211e5af | bellard | tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4356 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_WORD, R_EAX); |
4357 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4358 | 0211e5af | bellard | tcg_gen_andi_tl(cpu_cc_src, cpu_T[0], 0xff00); |
4359 | d36cd60e | bellard | s->cc_op = CC_OP_MULB; |
4360 | 2c0262af | bellard | break;
|
4361 | 2c0262af | bellard | case OT_WORD:
|
4362 | 0211e5af | bellard | gen_op_mov_TN_reg(OT_WORD, 1, R_EAX);
|
4363 | 0211e5af | bellard | tcg_gen_ext16u_tl(cpu_T[0], cpu_T[0]); |
4364 | 0211e5af | bellard | tcg_gen_ext16u_tl(cpu_T[1], cpu_T[1]); |
4365 | 0211e5af | bellard | /* XXX: use 32 bit mul which could be faster */
|
4366 | 0211e5af | bellard | tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4367 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_WORD, R_EAX); |
4368 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4369 | 0211e5af | bellard | tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 16); |
4370 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_WORD, R_EDX); |
4371 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
|
4372 | d36cd60e | bellard | s->cc_op = CC_OP_MULW; |
4373 | 2c0262af | bellard | break;
|
4374 | 2c0262af | bellard | default:
|
4375 | 2c0262af | bellard | case OT_LONG:
|
4376 | 0211e5af | bellard | #ifdef TARGET_X86_64
|
4377 | 0211e5af | bellard | gen_op_mov_TN_reg(OT_LONG, 1, R_EAX);
|
4378 | 0211e5af | bellard | tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]); |
4379 | 0211e5af | bellard | tcg_gen_ext32u_tl(cpu_T[1], cpu_T[1]); |
4380 | 0211e5af | bellard | tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4381 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_LONG, R_EAX); |
4382 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4383 | 0211e5af | bellard | tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 32); |
4384 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_LONG, R_EDX); |
4385 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
|
4386 | 0211e5af | bellard | #else
|
4387 | 0211e5af | bellard | { |
4388 | a7812ae4 | pbrook | TCGv_i64 t0, t1; |
4389 | a7812ae4 | pbrook | t0 = tcg_temp_new_i64(); |
4390 | a7812ae4 | pbrook | t1 = tcg_temp_new_i64(); |
4391 | 0211e5af | bellard | gen_op_mov_TN_reg(OT_LONG, 1, R_EAX);
|
4392 | 0211e5af | bellard | tcg_gen_extu_i32_i64(t0, cpu_T[0]);
|
4393 | 0211e5af | bellard | tcg_gen_extu_i32_i64(t1, cpu_T[1]);
|
4394 | 0211e5af | bellard | tcg_gen_mul_i64(t0, t0, t1); |
4395 | 0211e5af | bellard | tcg_gen_trunc_i64_i32(cpu_T[0], t0);
|
4396 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_LONG, R_EAX); |
4397 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4398 | 0211e5af | bellard | tcg_gen_shri_i64(t0, t0, 32);
|
4399 | 0211e5af | bellard | tcg_gen_trunc_i64_i32(cpu_T[0], t0);
|
4400 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_LONG, R_EDX); |
4401 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_src, cpu_T[0]);
|
4402 | 0211e5af | bellard | } |
4403 | 0211e5af | bellard | #endif
|
4404 | d36cd60e | bellard | s->cc_op = CC_OP_MULL; |
4405 | 2c0262af | bellard | break;
|
4406 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
4407 | 14ce26e7 | bellard | case OT_QUAD:
|
4408 | a7812ae4 | pbrook | gen_helper_mulq_EAX_T0(cpu_T[0]);
|
4409 | 14ce26e7 | bellard | s->cc_op = CC_OP_MULQ; |
4410 | 14ce26e7 | bellard | break;
|
4411 | 14ce26e7 | bellard | #endif
|
4412 | 2c0262af | bellard | } |
4413 | 2c0262af | bellard | break;
|
4414 | 2c0262af | bellard | case 5: /* imul */ |
4415 | 2c0262af | bellard | switch(ot) {
|
4416 | 2c0262af | bellard | case OT_BYTE:
|
4417 | 0211e5af | bellard | gen_op_mov_TN_reg(OT_BYTE, 1, R_EAX);
|
4418 | 0211e5af | bellard | tcg_gen_ext8s_tl(cpu_T[0], cpu_T[0]); |
4419 | 0211e5af | bellard | tcg_gen_ext8s_tl(cpu_T[1], cpu_T[1]); |
4420 | 0211e5af | bellard | /* XXX: use 32 bit mul which could be faster */
|
4421 | 0211e5af | bellard | tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4422 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_WORD, R_EAX); |
4423 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4424 | 0211e5af | bellard | tcg_gen_ext8s_tl(cpu_tmp0, cpu_T[0]);
|
4425 | 0211e5af | bellard | tcg_gen_sub_tl(cpu_cc_src, cpu_T[0], cpu_tmp0);
|
4426 | d36cd60e | bellard | s->cc_op = CC_OP_MULB; |
4427 | 2c0262af | bellard | break;
|
4428 | 2c0262af | bellard | case OT_WORD:
|
4429 | 0211e5af | bellard | gen_op_mov_TN_reg(OT_WORD, 1, R_EAX);
|
4430 | 0211e5af | bellard | tcg_gen_ext16s_tl(cpu_T[0], cpu_T[0]); |
4431 | 0211e5af | bellard | tcg_gen_ext16s_tl(cpu_T[1], cpu_T[1]); |
4432 | 0211e5af | bellard | /* XXX: use 32 bit mul which could be faster */
|
4433 | 0211e5af | bellard | tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4434 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_WORD, R_EAX); |
4435 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4436 | 0211e5af | bellard | tcg_gen_ext16s_tl(cpu_tmp0, cpu_T[0]);
|
4437 | 0211e5af | bellard | tcg_gen_sub_tl(cpu_cc_src, cpu_T[0], cpu_tmp0);
|
4438 | 0211e5af | bellard | tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 16); |
4439 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_WORD, R_EDX); |
4440 | d36cd60e | bellard | s->cc_op = CC_OP_MULW; |
4441 | 2c0262af | bellard | break;
|
4442 | 2c0262af | bellard | default:
|
4443 | 2c0262af | bellard | case OT_LONG:
|
4444 | 0211e5af | bellard | #ifdef TARGET_X86_64
|
4445 | 0211e5af | bellard | gen_op_mov_TN_reg(OT_LONG, 1, R_EAX);
|
4446 | 0211e5af | bellard | tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]); |
4447 | 0211e5af | bellard | tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]); |
4448 | 0211e5af | bellard | tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4449 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_LONG, R_EAX); |
4450 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4451 | 0211e5af | bellard | tcg_gen_ext32s_tl(cpu_tmp0, cpu_T[0]);
|
4452 | 0211e5af | bellard | tcg_gen_sub_tl(cpu_cc_src, cpu_T[0], cpu_tmp0);
|
4453 | 0211e5af | bellard | tcg_gen_shri_tl(cpu_T[0], cpu_T[0], 32); |
4454 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_LONG, R_EDX); |
4455 | 0211e5af | bellard | #else
|
4456 | 0211e5af | bellard | { |
4457 | a7812ae4 | pbrook | TCGv_i64 t0, t1; |
4458 | a7812ae4 | pbrook | t0 = tcg_temp_new_i64(); |
4459 | a7812ae4 | pbrook | t1 = tcg_temp_new_i64(); |
4460 | 0211e5af | bellard | gen_op_mov_TN_reg(OT_LONG, 1, R_EAX);
|
4461 | 0211e5af | bellard | tcg_gen_ext_i32_i64(t0, cpu_T[0]);
|
4462 | 0211e5af | bellard | tcg_gen_ext_i32_i64(t1, cpu_T[1]);
|
4463 | 0211e5af | bellard | tcg_gen_mul_i64(t0, t0, t1); |
4464 | 0211e5af | bellard | tcg_gen_trunc_i64_i32(cpu_T[0], t0);
|
4465 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_LONG, R_EAX); |
4466 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4467 | 0211e5af | bellard | tcg_gen_sari_tl(cpu_tmp0, cpu_T[0], 31); |
4468 | 0211e5af | bellard | tcg_gen_shri_i64(t0, t0, 32);
|
4469 | 0211e5af | bellard | tcg_gen_trunc_i64_i32(cpu_T[0], t0);
|
4470 | 0211e5af | bellard | gen_op_mov_reg_T0(OT_LONG, R_EDX); |
4471 | 0211e5af | bellard | tcg_gen_sub_tl(cpu_cc_src, cpu_T[0], cpu_tmp0);
|
4472 | 0211e5af | bellard | } |
4473 | 0211e5af | bellard | #endif
|
4474 | d36cd60e | bellard | s->cc_op = CC_OP_MULL; |
4475 | 2c0262af | bellard | break;
|
4476 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
4477 | 14ce26e7 | bellard | case OT_QUAD:
|
4478 | a7812ae4 | pbrook | gen_helper_imulq_EAX_T0(cpu_T[0]);
|
4479 | 14ce26e7 | bellard | s->cc_op = CC_OP_MULQ; |
4480 | 14ce26e7 | bellard | break;
|
4481 | 14ce26e7 | bellard | #endif
|
4482 | 2c0262af | bellard | } |
4483 | 2c0262af | bellard | break;
|
4484 | 2c0262af | bellard | case 6: /* div */ |
4485 | 2c0262af | bellard | switch(ot) {
|
4486 | 2c0262af | bellard | case OT_BYTE:
|
4487 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
4488 | a7812ae4 | pbrook | gen_helper_divb_AL(cpu_T[0]);
|
4489 | 2c0262af | bellard | break;
|
4490 | 2c0262af | bellard | case OT_WORD:
|
4491 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
4492 | a7812ae4 | pbrook | gen_helper_divw_AX(cpu_T[0]);
|
4493 | 2c0262af | bellard | break;
|
4494 | 2c0262af | bellard | default:
|
4495 | 2c0262af | bellard | case OT_LONG:
|
4496 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
4497 | a7812ae4 | pbrook | gen_helper_divl_EAX(cpu_T[0]);
|
4498 | 14ce26e7 | bellard | break;
|
4499 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
4500 | 14ce26e7 | bellard | case OT_QUAD:
|
4501 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
4502 | a7812ae4 | pbrook | gen_helper_divq_EAX(cpu_T[0]);
|
4503 | 2c0262af | bellard | break;
|
4504 | 14ce26e7 | bellard | #endif
|
4505 | 2c0262af | bellard | } |
4506 | 2c0262af | bellard | break;
|
4507 | 2c0262af | bellard | case 7: /* idiv */ |
4508 | 2c0262af | bellard | switch(ot) {
|
4509 | 2c0262af | bellard | case OT_BYTE:
|
4510 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
4511 | a7812ae4 | pbrook | gen_helper_idivb_AL(cpu_T[0]);
|
4512 | 2c0262af | bellard | break;
|
4513 | 2c0262af | bellard | case OT_WORD:
|
4514 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
4515 | a7812ae4 | pbrook | gen_helper_idivw_AX(cpu_T[0]);
|
4516 | 2c0262af | bellard | break;
|
4517 | 2c0262af | bellard | default:
|
4518 | 2c0262af | bellard | case OT_LONG:
|
4519 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
4520 | a7812ae4 | pbrook | gen_helper_idivl_EAX(cpu_T[0]);
|
4521 | 14ce26e7 | bellard | break;
|
4522 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
4523 | 14ce26e7 | bellard | case OT_QUAD:
|
4524 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
4525 | a7812ae4 | pbrook | gen_helper_idivq_EAX(cpu_T[0]);
|
4526 | 2c0262af | bellard | break;
|
4527 | 14ce26e7 | bellard | #endif
|
4528 | 2c0262af | bellard | } |
4529 | 2c0262af | bellard | break;
|
4530 | 2c0262af | bellard | default:
|
4531 | 2c0262af | bellard | goto illegal_op;
|
4532 | 2c0262af | bellard | } |
4533 | 2c0262af | bellard | break;
|
4534 | 2c0262af | bellard | |
4535 | 2c0262af | bellard | case 0xfe: /* GRP4 */ |
4536 | 2c0262af | bellard | case 0xff: /* GRP5 */ |
4537 | 2c0262af | bellard | if ((b & 1) == 0) |
4538 | 2c0262af | bellard | ot = OT_BYTE; |
4539 | 2c0262af | bellard | else
|
4540 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
4541 | 2c0262af | bellard | |
4542 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
4543 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
4544 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
4545 | 2c0262af | bellard | op = (modrm >> 3) & 7; |
4546 | 2c0262af | bellard | if (op >= 2 && b == 0xfe) { |
4547 | 2c0262af | bellard | goto illegal_op;
|
4548 | 2c0262af | bellard | } |
4549 | 14ce26e7 | bellard | if (CODE64(s)) {
|
4550 | aba9d61e | bellard | if (op == 2 || op == 4) { |
4551 | 14ce26e7 | bellard | /* operand size for jumps is 64 bit */
|
4552 | 14ce26e7 | bellard | ot = OT_QUAD; |
4553 | aba9d61e | bellard | } else if (op == 3 || op == 5) { |
4554 | aba9d61e | bellard | /* for call calls, the operand is 16 or 32 bit, even
|
4555 | aba9d61e | bellard | in long mode */
|
4556 | aba9d61e | bellard | ot = dflag ? OT_LONG : OT_WORD; |
4557 | 14ce26e7 | bellard | } else if (op == 6) { |
4558 | 14ce26e7 | bellard | /* default push size is 64 bit */
|
4559 | 14ce26e7 | bellard | ot = dflag ? OT_QUAD : OT_WORD; |
4560 | 14ce26e7 | bellard | } |
4561 | 14ce26e7 | bellard | } |
4562 | 2c0262af | bellard | if (mod != 3) { |
4563 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
4564 | 2c0262af | bellard | if (op >= 2 && op != 3 && op != 5) |
4565 | 57fec1fe | bellard | gen_op_ld_T0_A0(ot + s->mem_index); |
4566 | 2c0262af | bellard | } else {
|
4567 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, rm);
|
4568 | 2c0262af | bellard | } |
4569 | 2c0262af | bellard | |
4570 | 2c0262af | bellard | switch(op) {
|
4571 | 2c0262af | bellard | case 0: /* inc Ev */ |
4572 | 2c0262af | bellard | if (mod != 3) |
4573 | 2c0262af | bellard | opreg = OR_TMP0; |
4574 | 2c0262af | bellard | else
|
4575 | 2c0262af | bellard | opreg = rm; |
4576 | 2c0262af | bellard | gen_inc(s, ot, opreg, 1);
|
4577 | 2c0262af | bellard | break;
|
4578 | 2c0262af | bellard | case 1: /* dec Ev */ |
4579 | 2c0262af | bellard | if (mod != 3) |
4580 | 2c0262af | bellard | opreg = OR_TMP0; |
4581 | 2c0262af | bellard | else
|
4582 | 2c0262af | bellard | opreg = rm; |
4583 | 2c0262af | bellard | gen_inc(s, ot, opreg, -1);
|
4584 | 2c0262af | bellard | break;
|
4585 | 2c0262af | bellard | case 2: /* call Ev */ |
4586 | 4f31916f | bellard | /* XXX: optimize if memory (no 'and' is necessary) */
|
4587 | 2c0262af | bellard | if (s->dflag == 0) |
4588 | 2c0262af | bellard | gen_op_andl_T0_ffff(); |
4589 | 2c0262af | bellard | next_eip = s->pc - s->cs_base; |
4590 | 1ef38687 | bellard | gen_movtl_T1_im(next_eip); |
4591 | 4f31916f | bellard | gen_push_T1(s); |
4592 | 4f31916f | bellard | gen_op_jmp_T0(); |
4593 | 2c0262af | bellard | gen_eob(s); |
4594 | 2c0262af | bellard | break;
|
4595 | 61382a50 | bellard | case 3: /* lcall Ev */ |
4596 | 57fec1fe | bellard | gen_op_ld_T1_A0(ot + s->mem_index); |
4597 | aba9d61e | bellard | gen_add_A0_im(s, 1 << (ot - OT_WORD + 1)); |
4598 | 57fec1fe | bellard | gen_op_ldu_T0_A0(OT_WORD + s->mem_index); |
4599 | 2c0262af | bellard | do_lcall:
|
4600 | 2c0262af | bellard | if (s->pe && !s->vm86) {
|
4601 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
4602 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
4603 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
4604 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
4605 | a7812ae4 | pbrook | gen_helper_lcall_protected(cpu_tmp2_i32, cpu_T[1],
|
4606 | a7812ae4 | pbrook | tcg_const_i32(dflag), |
4607 | a7812ae4 | pbrook | tcg_const_i32(s->pc - pc_start)); |
4608 | 2c0262af | bellard | } else {
|
4609 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
4610 | a7812ae4 | pbrook | gen_helper_lcall_real(cpu_tmp2_i32, cpu_T[1],
|
4611 | a7812ae4 | pbrook | tcg_const_i32(dflag), |
4612 | a7812ae4 | pbrook | tcg_const_i32(s->pc - s->cs_base)); |
4613 | 2c0262af | bellard | } |
4614 | 2c0262af | bellard | gen_eob(s); |
4615 | 2c0262af | bellard | break;
|
4616 | 2c0262af | bellard | case 4: /* jmp Ev */ |
4617 | 2c0262af | bellard | if (s->dflag == 0) |
4618 | 2c0262af | bellard | gen_op_andl_T0_ffff(); |
4619 | 2c0262af | bellard | gen_op_jmp_T0(); |
4620 | 2c0262af | bellard | gen_eob(s); |
4621 | 2c0262af | bellard | break;
|
4622 | 2c0262af | bellard | case 5: /* ljmp Ev */ |
4623 | 57fec1fe | bellard | gen_op_ld_T1_A0(ot + s->mem_index); |
4624 | aba9d61e | bellard | gen_add_A0_im(s, 1 << (ot - OT_WORD + 1)); |
4625 | 57fec1fe | bellard | gen_op_ldu_T0_A0(OT_WORD + s->mem_index); |
4626 | 2c0262af | bellard | do_ljmp:
|
4627 | 2c0262af | bellard | if (s->pe && !s->vm86) {
|
4628 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
4629 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
4630 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
4631 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
4632 | a7812ae4 | pbrook | gen_helper_ljmp_protected(cpu_tmp2_i32, cpu_T[1],
|
4633 | a7812ae4 | pbrook | tcg_const_i32(s->pc - pc_start)); |
4634 | 2c0262af | bellard | } else {
|
4635 | 3bd7da9e | bellard | gen_op_movl_seg_T0_vm(R_CS); |
4636 | 2c0262af | bellard | gen_op_movl_T0_T1(); |
4637 | 2c0262af | bellard | gen_op_jmp_T0(); |
4638 | 2c0262af | bellard | } |
4639 | 2c0262af | bellard | gen_eob(s); |
4640 | 2c0262af | bellard | break;
|
4641 | 2c0262af | bellard | case 6: /* push Ev */ |
4642 | 2c0262af | bellard | gen_push_T0(s); |
4643 | 2c0262af | bellard | break;
|
4644 | 2c0262af | bellard | default:
|
4645 | 2c0262af | bellard | goto illegal_op;
|
4646 | 2c0262af | bellard | } |
4647 | 2c0262af | bellard | break;
|
4648 | 2c0262af | bellard | |
4649 | 2c0262af | bellard | case 0x84: /* test Ev, Gv */ |
4650 | 5fafdf24 | ths | case 0x85: |
4651 | 2c0262af | bellard | if ((b & 1) == 0) |
4652 | 2c0262af | bellard | ot = OT_BYTE; |
4653 | 2c0262af | bellard | else
|
4654 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
4655 | 2c0262af | bellard | |
4656 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
4657 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
4658 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
4659 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
4660 | 3b46e624 | ths | |
4661 | 2c0262af | bellard | gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
|
4662 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 1, reg);
|
4663 | 2c0262af | bellard | gen_op_testl_T0_T1_cc(); |
4664 | 2c0262af | bellard | s->cc_op = CC_OP_LOGICB + ot; |
4665 | 2c0262af | bellard | break;
|
4666 | 3b46e624 | ths | |
4667 | 2c0262af | bellard | case 0xa8: /* test eAX, Iv */ |
4668 | 2c0262af | bellard | case 0xa9: |
4669 | 2c0262af | bellard | if ((b & 1) == 0) |
4670 | 2c0262af | bellard | ot = OT_BYTE; |
4671 | 2c0262af | bellard | else
|
4672 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
4673 | 2c0262af | bellard | val = insn_get(s, ot); |
4674 | 2c0262af | bellard | |
4675 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, OR_EAX);
|
4676 | 2c0262af | bellard | gen_op_movl_T1_im(val); |
4677 | 2c0262af | bellard | gen_op_testl_T0_T1_cc(); |
4678 | 2c0262af | bellard | s->cc_op = CC_OP_LOGICB + ot; |
4679 | 2c0262af | bellard | break;
|
4680 | 3b46e624 | ths | |
4681 | 2c0262af | bellard | case 0x98: /* CWDE/CBW */ |
4682 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
4683 | 14ce26e7 | bellard | if (dflag == 2) { |
4684 | e108dd01 | bellard | gen_op_mov_TN_reg(OT_LONG, 0, R_EAX);
|
4685 | e108dd01 | bellard | tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]); |
4686 | e108dd01 | bellard | gen_op_mov_reg_T0(OT_QUAD, R_EAX); |
4687 | 14ce26e7 | bellard | } else
|
4688 | 14ce26e7 | bellard | #endif
|
4689 | e108dd01 | bellard | if (dflag == 1) { |
4690 | e108dd01 | bellard | gen_op_mov_TN_reg(OT_WORD, 0, R_EAX);
|
4691 | e108dd01 | bellard | tcg_gen_ext16s_tl(cpu_T[0], cpu_T[0]); |
4692 | e108dd01 | bellard | gen_op_mov_reg_T0(OT_LONG, R_EAX); |
4693 | e108dd01 | bellard | } else {
|
4694 | e108dd01 | bellard | gen_op_mov_TN_reg(OT_BYTE, 0, R_EAX);
|
4695 | e108dd01 | bellard | tcg_gen_ext8s_tl(cpu_T[0], cpu_T[0]); |
4696 | e108dd01 | bellard | gen_op_mov_reg_T0(OT_WORD, R_EAX); |
4697 | e108dd01 | bellard | } |
4698 | 2c0262af | bellard | break;
|
4699 | 2c0262af | bellard | case 0x99: /* CDQ/CWD */ |
4700 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
4701 | 14ce26e7 | bellard | if (dflag == 2) { |
4702 | e108dd01 | bellard | gen_op_mov_TN_reg(OT_QUAD, 0, R_EAX);
|
4703 | e108dd01 | bellard | tcg_gen_sari_tl(cpu_T[0], cpu_T[0], 63); |
4704 | e108dd01 | bellard | gen_op_mov_reg_T0(OT_QUAD, R_EDX); |
4705 | 14ce26e7 | bellard | } else
|
4706 | 14ce26e7 | bellard | #endif
|
4707 | e108dd01 | bellard | if (dflag == 1) { |
4708 | e108dd01 | bellard | gen_op_mov_TN_reg(OT_LONG, 0, R_EAX);
|
4709 | e108dd01 | bellard | tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]); |
4710 | e108dd01 | bellard | tcg_gen_sari_tl(cpu_T[0], cpu_T[0], 31); |
4711 | e108dd01 | bellard | gen_op_mov_reg_T0(OT_LONG, R_EDX); |
4712 | e108dd01 | bellard | } else {
|
4713 | e108dd01 | bellard | gen_op_mov_TN_reg(OT_WORD, 0, R_EAX);
|
4714 | e108dd01 | bellard | tcg_gen_ext16s_tl(cpu_T[0], cpu_T[0]); |
4715 | e108dd01 | bellard | tcg_gen_sari_tl(cpu_T[0], cpu_T[0], 15); |
4716 | e108dd01 | bellard | gen_op_mov_reg_T0(OT_WORD, R_EDX); |
4717 | e108dd01 | bellard | } |
4718 | 2c0262af | bellard | break;
|
4719 | 2c0262af | bellard | case 0x1af: /* imul Gv, Ev */ |
4720 | 2c0262af | bellard | case 0x69: /* imul Gv, Ev, I */ |
4721 | 2c0262af | bellard | case 0x6b: |
4722 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
4723 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
4724 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
4725 | 14ce26e7 | bellard | if (b == 0x69) |
4726 | 14ce26e7 | bellard | s->rip_offset = insn_const_size(ot); |
4727 | 14ce26e7 | bellard | else if (b == 0x6b) |
4728 | 14ce26e7 | bellard | s->rip_offset = 1;
|
4729 | 2c0262af | bellard | gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
|
4730 | 2c0262af | bellard | if (b == 0x69) { |
4731 | 2c0262af | bellard | val = insn_get(s, ot); |
4732 | 2c0262af | bellard | gen_op_movl_T1_im(val); |
4733 | 2c0262af | bellard | } else if (b == 0x6b) { |
4734 | d64477af | bellard | val = (int8_t)insn_get(s, OT_BYTE); |
4735 | 2c0262af | bellard | gen_op_movl_T1_im(val); |
4736 | 2c0262af | bellard | } else {
|
4737 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 1, reg);
|
4738 | 2c0262af | bellard | } |
4739 | 2c0262af | bellard | |
4740 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
4741 | 14ce26e7 | bellard | if (ot == OT_QUAD) {
|
4742 | a7812ae4 | pbrook | gen_helper_imulq_T0_T1(cpu_T[0], cpu_T[0], cpu_T[1]); |
4743 | 14ce26e7 | bellard | } else
|
4744 | 14ce26e7 | bellard | #endif
|
4745 | 2c0262af | bellard | if (ot == OT_LONG) {
|
4746 | 0211e5af | bellard | #ifdef TARGET_X86_64
|
4747 | 0211e5af | bellard | tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]); |
4748 | 0211e5af | bellard | tcg_gen_ext32s_tl(cpu_T[1], cpu_T[1]); |
4749 | 0211e5af | bellard | tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4750 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4751 | 0211e5af | bellard | tcg_gen_ext32s_tl(cpu_tmp0, cpu_T[0]);
|
4752 | 0211e5af | bellard | tcg_gen_sub_tl(cpu_cc_src, cpu_T[0], cpu_tmp0);
|
4753 | 0211e5af | bellard | #else
|
4754 | 0211e5af | bellard | { |
4755 | a7812ae4 | pbrook | TCGv_i64 t0, t1; |
4756 | a7812ae4 | pbrook | t0 = tcg_temp_new_i64(); |
4757 | a7812ae4 | pbrook | t1 = tcg_temp_new_i64(); |
4758 | 0211e5af | bellard | tcg_gen_ext_i32_i64(t0, cpu_T[0]);
|
4759 | 0211e5af | bellard | tcg_gen_ext_i32_i64(t1, cpu_T[1]);
|
4760 | 0211e5af | bellard | tcg_gen_mul_i64(t0, t0, t1); |
4761 | 0211e5af | bellard | tcg_gen_trunc_i64_i32(cpu_T[0], t0);
|
4762 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4763 | 0211e5af | bellard | tcg_gen_sari_tl(cpu_tmp0, cpu_T[0], 31); |
4764 | 0211e5af | bellard | tcg_gen_shri_i64(t0, t0, 32);
|
4765 | 0211e5af | bellard | tcg_gen_trunc_i64_i32(cpu_T[1], t0);
|
4766 | 0211e5af | bellard | tcg_gen_sub_tl(cpu_cc_src, cpu_T[1], cpu_tmp0);
|
4767 | 0211e5af | bellard | } |
4768 | 0211e5af | bellard | #endif
|
4769 | 2c0262af | bellard | } else {
|
4770 | 0211e5af | bellard | tcg_gen_ext16s_tl(cpu_T[0], cpu_T[0]); |
4771 | 0211e5af | bellard | tcg_gen_ext16s_tl(cpu_T[1], cpu_T[1]); |
4772 | 0211e5af | bellard | /* XXX: use 32 bit mul which could be faster */
|
4773 | 0211e5af | bellard | tcg_gen_mul_tl(cpu_T[0], cpu_T[0], cpu_T[1]); |
4774 | 0211e5af | bellard | tcg_gen_mov_tl(cpu_cc_dst, cpu_T[0]);
|
4775 | 0211e5af | bellard | tcg_gen_ext16s_tl(cpu_tmp0, cpu_T[0]);
|
4776 | 0211e5af | bellard | tcg_gen_sub_tl(cpu_cc_src, cpu_T[0], cpu_tmp0);
|
4777 | 2c0262af | bellard | } |
4778 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, reg); |
4779 | d36cd60e | bellard | s->cc_op = CC_OP_MULB + ot; |
4780 | 2c0262af | bellard | break;
|
4781 | 2c0262af | bellard | case 0x1c0: |
4782 | 2c0262af | bellard | case 0x1c1: /* xadd Ev, Gv */ |
4783 | 2c0262af | bellard | if ((b & 1) == 0) |
4784 | 2c0262af | bellard | ot = OT_BYTE; |
4785 | 2c0262af | bellard | else
|
4786 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
4787 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
4788 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
4789 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
4790 | 2c0262af | bellard | if (mod == 3) { |
4791 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
4792 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, reg);
|
4793 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 1, rm);
|
4794 | 2c0262af | bellard | gen_op_addl_T0_T1(); |
4795 | 57fec1fe | bellard | gen_op_mov_reg_T1(ot, reg); |
4796 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, rm); |
4797 | 2c0262af | bellard | } else {
|
4798 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
4799 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, reg);
|
4800 | 57fec1fe | bellard | gen_op_ld_T1_A0(ot + s->mem_index); |
4801 | 2c0262af | bellard | gen_op_addl_T0_T1(); |
4802 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
4803 | 57fec1fe | bellard | gen_op_mov_reg_T1(ot, reg); |
4804 | 2c0262af | bellard | } |
4805 | 2c0262af | bellard | gen_op_update2_cc(); |
4806 | 2c0262af | bellard | s->cc_op = CC_OP_ADDB + ot; |
4807 | 2c0262af | bellard | break;
|
4808 | 2c0262af | bellard | case 0x1b0: |
4809 | 2c0262af | bellard | case 0x1b1: /* cmpxchg Ev, Gv */ |
4810 | cad3a37d | bellard | { |
4811 | 1130328e | bellard | int label1, label2;
|
4812 | 1e4840bf | bellard | TCGv t0, t1, t2, a0; |
4813 | cad3a37d | bellard | |
4814 | cad3a37d | bellard | if ((b & 1) == 0) |
4815 | cad3a37d | bellard | ot = OT_BYTE; |
4816 | cad3a37d | bellard | else
|
4817 | cad3a37d | bellard | ot = dflag + OT_WORD; |
4818 | cad3a37d | bellard | modrm = ldub_code(s->pc++); |
4819 | cad3a37d | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
4820 | cad3a37d | bellard | mod = (modrm >> 6) & 3; |
4821 | a7812ae4 | pbrook | t0 = tcg_temp_local_new(); |
4822 | a7812ae4 | pbrook | t1 = tcg_temp_local_new(); |
4823 | a7812ae4 | pbrook | t2 = tcg_temp_local_new(); |
4824 | a7812ae4 | pbrook | a0 = tcg_temp_local_new(); |
4825 | 1e4840bf | bellard | gen_op_mov_v_reg(ot, t1, reg); |
4826 | cad3a37d | bellard | if (mod == 3) { |
4827 | cad3a37d | bellard | rm = (modrm & 7) | REX_B(s);
|
4828 | 1e4840bf | bellard | gen_op_mov_v_reg(ot, t0, rm); |
4829 | cad3a37d | bellard | } else {
|
4830 | cad3a37d | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
4831 | 1e4840bf | bellard | tcg_gen_mov_tl(a0, cpu_A0); |
4832 | 1e4840bf | bellard | gen_op_ld_v(ot + s->mem_index, t0, a0); |
4833 | cad3a37d | bellard | rm = 0; /* avoid warning */ |
4834 | cad3a37d | bellard | } |
4835 | cad3a37d | bellard | label1 = gen_new_label(); |
4836 | 1e4840bf | bellard | tcg_gen_ld_tl(t2, cpu_env, offsetof(CPUState, regs[R_EAX])); |
4837 | 1e4840bf | bellard | tcg_gen_sub_tl(t2, t2, t0); |
4838 | 1e4840bf | bellard | gen_extu(ot, t2); |
4839 | 1e4840bf | bellard | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, label1);
|
4840 | cad3a37d | bellard | if (mod == 3) { |
4841 | 1130328e | bellard | label2 = gen_new_label(); |
4842 | 1e4840bf | bellard | gen_op_mov_reg_v(ot, R_EAX, t0); |
4843 | 1130328e | bellard | tcg_gen_br(label2); |
4844 | 1130328e | bellard | gen_set_label(label1); |
4845 | 1e4840bf | bellard | gen_op_mov_reg_v(ot, rm, t1); |
4846 | 1130328e | bellard | gen_set_label(label2); |
4847 | cad3a37d | bellard | } else {
|
4848 | 1e4840bf | bellard | tcg_gen_mov_tl(t1, t0); |
4849 | 1e4840bf | bellard | gen_op_mov_reg_v(ot, R_EAX, t0); |
4850 | 1130328e | bellard | gen_set_label(label1); |
4851 | 1130328e | bellard | /* always store */
|
4852 | 1e4840bf | bellard | gen_op_st_v(ot + s->mem_index, t1, a0); |
4853 | cad3a37d | bellard | } |
4854 | 1e4840bf | bellard | tcg_gen_mov_tl(cpu_cc_src, t0); |
4855 | 1e4840bf | bellard | tcg_gen_mov_tl(cpu_cc_dst, t2); |
4856 | cad3a37d | bellard | s->cc_op = CC_OP_SUBB + ot; |
4857 | 1e4840bf | bellard | tcg_temp_free(t0); |
4858 | 1e4840bf | bellard | tcg_temp_free(t1); |
4859 | 1e4840bf | bellard | tcg_temp_free(t2); |
4860 | 1e4840bf | bellard | tcg_temp_free(a0); |
4861 | 2c0262af | bellard | } |
4862 | 2c0262af | bellard | break;
|
4863 | 2c0262af | bellard | case 0x1c7: /* cmpxchg8b */ |
4864 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
4865 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
4866 | 71c3558e | balrog | if ((mod == 3) || ((modrm & 0x38) != 0x8)) |
4867 | 2c0262af | bellard | goto illegal_op;
|
4868 | 1b9d9ebb | bellard | #ifdef TARGET_X86_64
|
4869 | 1b9d9ebb | bellard | if (dflag == 2) { |
4870 | 1b9d9ebb | bellard | if (!(s->cpuid_ext_features & CPUID_EXT_CX16))
|
4871 | 1b9d9ebb | bellard | goto illegal_op;
|
4872 | 1b9d9ebb | bellard | gen_jmp_im(pc_start - s->cs_base); |
4873 | 1b9d9ebb | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
4874 | 1b9d9ebb | bellard | gen_op_set_cc_op(s->cc_op); |
4875 | 1b9d9ebb | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
4876 | a7812ae4 | pbrook | gen_helper_cmpxchg16b(cpu_A0); |
4877 | 1b9d9ebb | bellard | } else
|
4878 | 1b9d9ebb | bellard | #endif
|
4879 | 1b9d9ebb | bellard | { |
4880 | 1b9d9ebb | bellard | if (!(s->cpuid_features & CPUID_CX8))
|
4881 | 1b9d9ebb | bellard | goto illegal_op;
|
4882 | 1b9d9ebb | bellard | gen_jmp_im(pc_start - s->cs_base); |
4883 | 1b9d9ebb | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
4884 | 1b9d9ebb | bellard | gen_op_set_cc_op(s->cc_op); |
4885 | 1b9d9ebb | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
4886 | a7812ae4 | pbrook | gen_helper_cmpxchg8b(cpu_A0); |
4887 | 1b9d9ebb | bellard | } |
4888 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
4889 | 2c0262af | bellard | break;
|
4890 | 3b46e624 | ths | |
4891 | 2c0262af | bellard | /**************************/
|
4892 | 2c0262af | bellard | /* push/pop */
|
4893 | 2c0262af | bellard | case 0x50 ... 0x57: /* push */ |
4894 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_LONG, 0, (b & 7) | REX_B(s)); |
4895 | 2c0262af | bellard | gen_push_T0(s); |
4896 | 2c0262af | bellard | break;
|
4897 | 2c0262af | bellard | case 0x58 ... 0x5f: /* pop */ |
4898 | 14ce26e7 | bellard | if (CODE64(s)) {
|
4899 | 14ce26e7 | bellard | ot = dflag ? OT_QUAD : OT_WORD; |
4900 | 14ce26e7 | bellard | } else {
|
4901 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
4902 | 14ce26e7 | bellard | } |
4903 | 2c0262af | bellard | gen_pop_T0(s); |
4904 | 77729c24 | bellard | /* NOTE: order is important for pop %sp */
|
4905 | 2c0262af | bellard | gen_pop_update(s); |
4906 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, (b & 7) | REX_B(s));
|
4907 | 2c0262af | bellard | break;
|
4908 | 2c0262af | bellard | case 0x60: /* pusha */ |
4909 | 14ce26e7 | bellard | if (CODE64(s))
|
4910 | 14ce26e7 | bellard | goto illegal_op;
|
4911 | 2c0262af | bellard | gen_pusha(s); |
4912 | 2c0262af | bellard | break;
|
4913 | 2c0262af | bellard | case 0x61: /* popa */ |
4914 | 14ce26e7 | bellard | if (CODE64(s))
|
4915 | 14ce26e7 | bellard | goto illegal_op;
|
4916 | 2c0262af | bellard | gen_popa(s); |
4917 | 2c0262af | bellard | break;
|
4918 | 2c0262af | bellard | case 0x68: /* push Iv */ |
4919 | 2c0262af | bellard | case 0x6a: |
4920 | 14ce26e7 | bellard | if (CODE64(s)) {
|
4921 | 14ce26e7 | bellard | ot = dflag ? OT_QUAD : OT_WORD; |
4922 | 14ce26e7 | bellard | } else {
|
4923 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
4924 | 14ce26e7 | bellard | } |
4925 | 2c0262af | bellard | if (b == 0x68) |
4926 | 2c0262af | bellard | val = insn_get(s, ot); |
4927 | 2c0262af | bellard | else
|
4928 | 2c0262af | bellard | val = (int8_t)insn_get(s, OT_BYTE); |
4929 | 2c0262af | bellard | gen_op_movl_T0_im(val); |
4930 | 2c0262af | bellard | gen_push_T0(s); |
4931 | 2c0262af | bellard | break;
|
4932 | 2c0262af | bellard | case 0x8f: /* pop Ev */ |
4933 | 14ce26e7 | bellard | if (CODE64(s)) {
|
4934 | 14ce26e7 | bellard | ot = dflag ? OT_QUAD : OT_WORD; |
4935 | 14ce26e7 | bellard | } else {
|
4936 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
4937 | 14ce26e7 | bellard | } |
4938 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
4939 | 77729c24 | bellard | mod = (modrm >> 6) & 3; |
4940 | 2c0262af | bellard | gen_pop_T0(s); |
4941 | 77729c24 | bellard | if (mod == 3) { |
4942 | 77729c24 | bellard | /* NOTE: order is important for pop %sp */
|
4943 | 77729c24 | bellard | gen_pop_update(s); |
4944 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
4945 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, rm); |
4946 | 77729c24 | bellard | } else {
|
4947 | 77729c24 | bellard | /* NOTE: order is important too for MMU exceptions */
|
4948 | 14ce26e7 | bellard | s->popl_esp_hack = 1 << ot;
|
4949 | 77729c24 | bellard | gen_ldst_modrm(s, modrm, ot, OR_TMP0, 1);
|
4950 | 77729c24 | bellard | s->popl_esp_hack = 0;
|
4951 | 77729c24 | bellard | gen_pop_update(s); |
4952 | 77729c24 | bellard | } |
4953 | 2c0262af | bellard | break;
|
4954 | 2c0262af | bellard | case 0xc8: /* enter */ |
4955 | 2c0262af | bellard | { |
4956 | 2c0262af | bellard | int level;
|
4957 | 61382a50 | bellard | val = lduw_code(s->pc); |
4958 | 2c0262af | bellard | s->pc += 2;
|
4959 | 61382a50 | bellard | level = ldub_code(s->pc++); |
4960 | 2c0262af | bellard | gen_enter(s, val, level); |
4961 | 2c0262af | bellard | } |
4962 | 2c0262af | bellard | break;
|
4963 | 2c0262af | bellard | case 0xc9: /* leave */ |
4964 | 2c0262af | bellard | /* XXX: exception not precise (ESP is updated before potential exception) */
|
4965 | 14ce26e7 | bellard | if (CODE64(s)) {
|
4966 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_QUAD, 0, R_EBP);
|
4967 | 57fec1fe | bellard | gen_op_mov_reg_T0(OT_QUAD, R_ESP); |
4968 | 14ce26e7 | bellard | } else if (s->ss32) { |
4969 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_LONG, 0, R_EBP);
|
4970 | 57fec1fe | bellard | gen_op_mov_reg_T0(OT_LONG, R_ESP); |
4971 | 2c0262af | bellard | } else {
|
4972 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_WORD, 0, R_EBP);
|
4973 | 57fec1fe | bellard | gen_op_mov_reg_T0(OT_WORD, R_ESP); |
4974 | 2c0262af | bellard | } |
4975 | 2c0262af | bellard | gen_pop_T0(s); |
4976 | 14ce26e7 | bellard | if (CODE64(s)) {
|
4977 | 14ce26e7 | bellard | ot = dflag ? OT_QUAD : OT_WORD; |
4978 | 14ce26e7 | bellard | } else {
|
4979 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
4980 | 14ce26e7 | bellard | } |
4981 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, R_EBP); |
4982 | 2c0262af | bellard | gen_pop_update(s); |
4983 | 2c0262af | bellard | break;
|
4984 | 2c0262af | bellard | case 0x06: /* push es */ |
4985 | 2c0262af | bellard | case 0x0e: /* push cs */ |
4986 | 2c0262af | bellard | case 0x16: /* push ss */ |
4987 | 2c0262af | bellard | case 0x1e: /* push ds */ |
4988 | 14ce26e7 | bellard | if (CODE64(s))
|
4989 | 14ce26e7 | bellard | goto illegal_op;
|
4990 | 2c0262af | bellard | gen_op_movl_T0_seg(b >> 3);
|
4991 | 2c0262af | bellard | gen_push_T0(s); |
4992 | 2c0262af | bellard | break;
|
4993 | 2c0262af | bellard | case 0x1a0: /* push fs */ |
4994 | 2c0262af | bellard | case 0x1a8: /* push gs */ |
4995 | 2c0262af | bellard | gen_op_movl_T0_seg((b >> 3) & 7); |
4996 | 2c0262af | bellard | gen_push_T0(s); |
4997 | 2c0262af | bellard | break;
|
4998 | 2c0262af | bellard | case 0x07: /* pop es */ |
4999 | 2c0262af | bellard | case 0x17: /* pop ss */ |
5000 | 2c0262af | bellard | case 0x1f: /* pop ds */ |
5001 | 14ce26e7 | bellard | if (CODE64(s))
|
5002 | 14ce26e7 | bellard | goto illegal_op;
|
5003 | 2c0262af | bellard | reg = b >> 3;
|
5004 | 2c0262af | bellard | gen_pop_T0(s); |
5005 | 2c0262af | bellard | gen_movl_seg_T0(s, reg, pc_start - s->cs_base); |
5006 | 2c0262af | bellard | gen_pop_update(s); |
5007 | 2c0262af | bellard | if (reg == R_SS) {
|
5008 | a2cc3b24 | bellard | /* if reg == SS, inhibit interrupts/trace. */
|
5009 | a2cc3b24 | bellard | /* If several instructions disable interrupts, only the
|
5010 | a2cc3b24 | bellard | _first_ does it */
|
5011 | a2cc3b24 | bellard | if (!(s->tb->flags & HF_INHIBIT_IRQ_MASK))
|
5012 | a7812ae4 | pbrook | gen_helper_set_inhibit_irq(); |
5013 | 2c0262af | bellard | s->tf = 0;
|
5014 | 2c0262af | bellard | } |
5015 | 2c0262af | bellard | if (s->is_jmp) {
|
5016 | 14ce26e7 | bellard | gen_jmp_im(s->pc - s->cs_base); |
5017 | 2c0262af | bellard | gen_eob(s); |
5018 | 2c0262af | bellard | } |
5019 | 2c0262af | bellard | break;
|
5020 | 2c0262af | bellard | case 0x1a1: /* pop fs */ |
5021 | 2c0262af | bellard | case 0x1a9: /* pop gs */ |
5022 | 2c0262af | bellard | gen_pop_T0(s); |
5023 | 2c0262af | bellard | gen_movl_seg_T0(s, (b >> 3) & 7, pc_start - s->cs_base); |
5024 | 2c0262af | bellard | gen_pop_update(s); |
5025 | 2c0262af | bellard | if (s->is_jmp) {
|
5026 | 14ce26e7 | bellard | gen_jmp_im(s->pc - s->cs_base); |
5027 | 2c0262af | bellard | gen_eob(s); |
5028 | 2c0262af | bellard | } |
5029 | 2c0262af | bellard | break;
|
5030 | 2c0262af | bellard | |
5031 | 2c0262af | bellard | /**************************/
|
5032 | 2c0262af | bellard | /* mov */
|
5033 | 2c0262af | bellard | case 0x88: |
5034 | 2c0262af | bellard | case 0x89: /* mov Gv, Ev */ |
5035 | 2c0262af | bellard | if ((b & 1) == 0) |
5036 | 2c0262af | bellard | ot = OT_BYTE; |
5037 | 2c0262af | bellard | else
|
5038 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
5039 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
5040 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
5041 | 3b46e624 | ths | |
5042 | 2c0262af | bellard | /* generate a generic store */
|
5043 | 14ce26e7 | bellard | gen_ldst_modrm(s, modrm, ot, reg, 1);
|
5044 | 2c0262af | bellard | break;
|
5045 | 2c0262af | bellard | case 0xc6: |
5046 | 2c0262af | bellard | case 0xc7: /* mov Ev, Iv */ |
5047 | 2c0262af | bellard | if ((b & 1) == 0) |
5048 | 2c0262af | bellard | ot = OT_BYTE; |
5049 | 2c0262af | bellard | else
|
5050 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
5051 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
5052 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
5053 | 14ce26e7 | bellard | if (mod != 3) { |
5054 | 14ce26e7 | bellard | s->rip_offset = insn_const_size(ot); |
5055 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
5056 | 14ce26e7 | bellard | } |
5057 | 2c0262af | bellard | val = insn_get(s, ot); |
5058 | 2c0262af | bellard | gen_op_movl_T0_im(val); |
5059 | 2c0262af | bellard | if (mod != 3) |
5060 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
5061 | 2c0262af | bellard | else
|
5062 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, (modrm & 7) | REX_B(s));
|
5063 | 2c0262af | bellard | break;
|
5064 | 2c0262af | bellard | case 0x8a: |
5065 | 2c0262af | bellard | case 0x8b: /* mov Ev, Gv */ |
5066 | 2c0262af | bellard | if ((b & 1) == 0) |
5067 | 2c0262af | bellard | ot = OT_BYTE; |
5068 | 2c0262af | bellard | else
|
5069 | 14ce26e7 | bellard | ot = OT_WORD + dflag; |
5070 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
5071 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
5072 | 3b46e624 | ths | |
5073 | 2c0262af | bellard | gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
|
5074 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, reg); |
5075 | 2c0262af | bellard | break;
|
5076 | 2c0262af | bellard | case 0x8e: /* mov seg, Gv */ |
5077 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
5078 | 2c0262af | bellard | reg = (modrm >> 3) & 7; |
5079 | 2c0262af | bellard | if (reg >= 6 || reg == R_CS) |
5080 | 2c0262af | bellard | goto illegal_op;
|
5081 | 2c0262af | bellard | gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
5082 | 2c0262af | bellard | gen_movl_seg_T0(s, reg, pc_start - s->cs_base); |
5083 | 2c0262af | bellard | if (reg == R_SS) {
|
5084 | 2c0262af | bellard | /* if reg == SS, inhibit interrupts/trace */
|
5085 | a2cc3b24 | bellard | /* If several instructions disable interrupts, only the
|
5086 | a2cc3b24 | bellard | _first_ does it */
|
5087 | a2cc3b24 | bellard | if (!(s->tb->flags & HF_INHIBIT_IRQ_MASK))
|
5088 | a7812ae4 | pbrook | gen_helper_set_inhibit_irq(); |
5089 | 2c0262af | bellard | s->tf = 0;
|
5090 | 2c0262af | bellard | } |
5091 | 2c0262af | bellard | if (s->is_jmp) {
|
5092 | 14ce26e7 | bellard | gen_jmp_im(s->pc - s->cs_base); |
5093 | 2c0262af | bellard | gen_eob(s); |
5094 | 2c0262af | bellard | } |
5095 | 2c0262af | bellard | break;
|
5096 | 2c0262af | bellard | case 0x8c: /* mov Gv, seg */ |
5097 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
5098 | 2c0262af | bellard | reg = (modrm >> 3) & 7; |
5099 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
5100 | 2c0262af | bellard | if (reg >= 6) |
5101 | 2c0262af | bellard | goto illegal_op;
|
5102 | 2c0262af | bellard | gen_op_movl_T0_seg(reg); |
5103 | 14ce26e7 | bellard | if (mod == 3) |
5104 | 14ce26e7 | bellard | ot = OT_WORD + dflag; |
5105 | 14ce26e7 | bellard | else
|
5106 | 14ce26e7 | bellard | ot = OT_WORD; |
5107 | 2c0262af | bellard | gen_ldst_modrm(s, modrm, ot, OR_TMP0, 1);
|
5108 | 2c0262af | bellard | break;
|
5109 | 2c0262af | bellard | |
5110 | 2c0262af | bellard | case 0x1b6: /* movzbS Gv, Eb */ |
5111 | 2c0262af | bellard | case 0x1b7: /* movzwS Gv, Eb */ |
5112 | 2c0262af | bellard | case 0x1be: /* movsbS Gv, Eb */ |
5113 | 2c0262af | bellard | case 0x1bf: /* movswS Gv, Eb */ |
5114 | 2c0262af | bellard | { |
5115 | 2c0262af | bellard | int d_ot;
|
5116 | 2c0262af | bellard | /* d_ot is the size of destination */
|
5117 | 2c0262af | bellard | d_ot = dflag + OT_WORD; |
5118 | 2c0262af | bellard | /* ot is the size of source */
|
5119 | 2c0262af | bellard | ot = (b & 1) + OT_BYTE;
|
5120 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
5121 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
5122 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
5123 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
5124 | 3b46e624 | ths | |
5125 | 2c0262af | bellard | if (mod == 3) { |
5126 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, rm);
|
5127 | 2c0262af | bellard | switch(ot | (b & 8)) { |
5128 | 2c0262af | bellard | case OT_BYTE:
|
5129 | e108dd01 | bellard | tcg_gen_ext8u_tl(cpu_T[0], cpu_T[0]); |
5130 | 2c0262af | bellard | break;
|
5131 | 2c0262af | bellard | case OT_BYTE | 8: |
5132 | e108dd01 | bellard | tcg_gen_ext8s_tl(cpu_T[0], cpu_T[0]); |
5133 | 2c0262af | bellard | break;
|
5134 | 2c0262af | bellard | case OT_WORD:
|
5135 | e108dd01 | bellard | tcg_gen_ext16u_tl(cpu_T[0], cpu_T[0]); |
5136 | 2c0262af | bellard | break;
|
5137 | 2c0262af | bellard | default:
|
5138 | 2c0262af | bellard | case OT_WORD | 8: |
5139 | e108dd01 | bellard | tcg_gen_ext16s_tl(cpu_T[0], cpu_T[0]); |
5140 | 2c0262af | bellard | break;
|
5141 | 2c0262af | bellard | } |
5142 | 57fec1fe | bellard | gen_op_mov_reg_T0(d_ot, reg); |
5143 | 2c0262af | bellard | } else {
|
5144 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
5145 | 2c0262af | bellard | if (b & 8) { |
5146 | 57fec1fe | bellard | gen_op_lds_T0_A0(ot + s->mem_index); |
5147 | 2c0262af | bellard | } else {
|
5148 | 57fec1fe | bellard | gen_op_ldu_T0_A0(ot + s->mem_index); |
5149 | 2c0262af | bellard | } |
5150 | 57fec1fe | bellard | gen_op_mov_reg_T0(d_ot, reg); |
5151 | 2c0262af | bellard | } |
5152 | 2c0262af | bellard | } |
5153 | 2c0262af | bellard | break;
|
5154 | 2c0262af | bellard | |
5155 | 2c0262af | bellard | case 0x8d: /* lea */ |
5156 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
5157 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
5158 | 3a1d9b8b | bellard | mod = (modrm >> 6) & 3; |
5159 | 3a1d9b8b | bellard | if (mod == 3) |
5160 | 3a1d9b8b | bellard | goto illegal_op;
|
5161 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
5162 | 2c0262af | bellard | /* we must ensure that no segment is added */
|
5163 | 2c0262af | bellard | s->override = -1;
|
5164 | 2c0262af | bellard | val = s->addseg; |
5165 | 2c0262af | bellard | s->addseg = 0;
|
5166 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
5167 | 2c0262af | bellard | s->addseg = val; |
5168 | 57fec1fe | bellard | gen_op_mov_reg_A0(ot - OT_WORD, reg); |
5169 | 2c0262af | bellard | break;
|
5170 | 3b46e624 | ths | |
5171 | 2c0262af | bellard | case 0xa0: /* mov EAX, Ov */ |
5172 | 2c0262af | bellard | case 0xa1: |
5173 | 2c0262af | bellard | case 0xa2: /* mov Ov, EAX */ |
5174 | 2c0262af | bellard | case 0xa3: |
5175 | 2c0262af | bellard | { |
5176 | 14ce26e7 | bellard | target_ulong offset_addr; |
5177 | 14ce26e7 | bellard | |
5178 | 14ce26e7 | bellard | if ((b & 1) == 0) |
5179 | 14ce26e7 | bellard | ot = OT_BYTE; |
5180 | 14ce26e7 | bellard | else
|
5181 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
5182 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
5183 | 8f091a59 | bellard | if (s->aflag == 2) { |
5184 | 14ce26e7 | bellard | offset_addr = ldq_code(s->pc); |
5185 | 14ce26e7 | bellard | s->pc += 8;
|
5186 | 57fec1fe | bellard | gen_op_movq_A0_im(offset_addr); |
5187 | 5fafdf24 | ths | } else
|
5188 | 14ce26e7 | bellard | #endif
|
5189 | 14ce26e7 | bellard | { |
5190 | 14ce26e7 | bellard | if (s->aflag) {
|
5191 | 14ce26e7 | bellard | offset_addr = insn_get(s, OT_LONG); |
5192 | 14ce26e7 | bellard | } else {
|
5193 | 14ce26e7 | bellard | offset_addr = insn_get(s, OT_WORD); |
5194 | 14ce26e7 | bellard | } |
5195 | 14ce26e7 | bellard | gen_op_movl_A0_im(offset_addr); |
5196 | 14ce26e7 | bellard | } |
5197 | 664e0f19 | bellard | gen_add_A0_ds_seg(s); |
5198 | 14ce26e7 | bellard | if ((b & 2) == 0) { |
5199 | 57fec1fe | bellard | gen_op_ld_T0_A0(ot + s->mem_index); |
5200 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, R_EAX); |
5201 | 14ce26e7 | bellard | } else {
|
5202 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, R_EAX);
|
5203 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
5204 | 2c0262af | bellard | } |
5205 | 2c0262af | bellard | } |
5206 | 2c0262af | bellard | break;
|
5207 | 2c0262af | bellard | case 0xd7: /* xlat */ |
5208 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
5209 | 8f091a59 | bellard | if (s->aflag == 2) { |
5210 | 57fec1fe | bellard | gen_op_movq_A0_reg(R_EBX); |
5211 | bbf662ee | bellard | gen_op_mov_TN_reg(OT_QUAD, 0, R_EAX);
|
5212 | bbf662ee | bellard | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0xff); |
5213 | bbf662ee | bellard | tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_T[0]);
|
5214 | 5fafdf24 | ths | } else
|
5215 | 14ce26e7 | bellard | #endif
|
5216 | 14ce26e7 | bellard | { |
5217 | 57fec1fe | bellard | gen_op_movl_A0_reg(R_EBX); |
5218 | bbf662ee | bellard | gen_op_mov_TN_reg(OT_LONG, 0, R_EAX);
|
5219 | bbf662ee | bellard | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], 0xff); |
5220 | bbf662ee | bellard | tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_T[0]);
|
5221 | 14ce26e7 | bellard | if (s->aflag == 0) |
5222 | 14ce26e7 | bellard | gen_op_andl_A0_ffff(); |
5223 | bbf662ee | bellard | else
|
5224 | bbf662ee | bellard | tcg_gen_andi_tl(cpu_A0, cpu_A0, 0xffffffff);
|
5225 | 14ce26e7 | bellard | } |
5226 | 664e0f19 | bellard | gen_add_A0_ds_seg(s); |
5227 | 57fec1fe | bellard | gen_op_ldu_T0_A0(OT_BYTE + s->mem_index); |
5228 | 57fec1fe | bellard | gen_op_mov_reg_T0(OT_BYTE, R_EAX); |
5229 | 2c0262af | bellard | break;
|
5230 | 2c0262af | bellard | case 0xb0 ... 0xb7: /* mov R, Ib */ |
5231 | 2c0262af | bellard | val = insn_get(s, OT_BYTE); |
5232 | 2c0262af | bellard | gen_op_movl_T0_im(val); |
5233 | 57fec1fe | bellard | gen_op_mov_reg_T0(OT_BYTE, (b & 7) | REX_B(s));
|
5234 | 2c0262af | bellard | break;
|
5235 | 2c0262af | bellard | case 0xb8 ... 0xbf: /* mov R, Iv */ |
5236 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
5237 | 14ce26e7 | bellard | if (dflag == 2) { |
5238 | 14ce26e7 | bellard | uint64_t tmp; |
5239 | 14ce26e7 | bellard | /* 64 bit case */
|
5240 | 14ce26e7 | bellard | tmp = ldq_code(s->pc); |
5241 | 14ce26e7 | bellard | s->pc += 8;
|
5242 | 14ce26e7 | bellard | reg = (b & 7) | REX_B(s);
|
5243 | 14ce26e7 | bellard | gen_movtl_T0_im(tmp); |
5244 | 57fec1fe | bellard | gen_op_mov_reg_T0(OT_QUAD, reg); |
5245 | 5fafdf24 | ths | } else
|
5246 | 14ce26e7 | bellard | #endif
|
5247 | 14ce26e7 | bellard | { |
5248 | 14ce26e7 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
5249 | 14ce26e7 | bellard | val = insn_get(s, ot); |
5250 | 14ce26e7 | bellard | reg = (b & 7) | REX_B(s);
|
5251 | 14ce26e7 | bellard | gen_op_movl_T0_im(val); |
5252 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, reg); |
5253 | 14ce26e7 | bellard | } |
5254 | 2c0262af | bellard | break;
|
5255 | 2c0262af | bellard | |
5256 | 2c0262af | bellard | case 0x91 ... 0x97: /* xchg R, EAX */ |
5257 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
5258 | 14ce26e7 | bellard | reg = (b & 7) | REX_B(s);
|
5259 | 2c0262af | bellard | rm = R_EAX; |
5260 | 2c0262af | bellard | goto do_xchg_reg;
|
5261 | 2c0262af | bellard | case 0x86: |
5262 | 2c0262af | bellard | case 0x87: /* xchg Ev, Gv */ |
5263 | 2c0262af | bellard | if ((b & 1) == 0) |
5264 | 2c0262af | bellard | ot = OT_BYTE; |
5265 | 2c0262af | bellard | else
|
5266 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
5267 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
5268 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
5269 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
5270 | 2c0262af | bellard | if (mod == 3) { |
5271 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
5272 | 2c0262af | bellard | do_xchg_reg:
|
5273 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, reg);
|
5274 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 1, rm);
|
5275 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, rm); |
5276 | 57fec1fe | bellard | gen_op_mov_reg_T1(ot, reg); |
5277 | 2c0262af | bellard | } else {
|
5278 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
5279 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, reg);
|
5280 | 2c0262af | bellard | /* for xchg, lock is implicit */
|
5281 | 2c0262af | bellard | if (!(prefixes & PREFIX_LOCK))
|
5282 | a7812ae4 | pbrook | gen_helper_lock(); |
5283 | 57fec1fe | bellard | gen_op_ld_T1_A0(ot + s->mem_index); |
5284 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
5285 | 2c0262af | bellard | if (!(prefixes & PREFIX_LOCK))
|
5286 | a7812ae4 | pbrook | gen_helper_unlock(); |
5287 | 57fec1fe | bellard | gen_op_mov_reg_T1(ot, reg); |
5288 | 2c0262af | bellard | } |
5289 | 2c0262af | bellard | break;
|
5290 | 2c0262af | bellard | case 0xc4: /* les Gv */ |
5291 | 14ce26e7 | bellard | if (CODE64(s))
|
5292 | 14ce26e7 | bellard | goto illegal_op;
|
5293 | 2c0262af | bellard | op = R_ES; |
5294 | 2c0262af | bellard | goto do_lxx;
|
5295 | 2c0262af | bellard | case 0xc5: /* lds Gv */ |
5296 | 14ce26e7 | bellard | if (CODE64(s))
|
5297 | 14ce26e7 | bellard | goto illegal_op;
|
5298 | 2c0262af | bellard | op = R_DS; |
5299 | 2c0262af | bellard | goto do_lxx;
|
5300 | 2c0262af | bellard | case 0x1b2: /* lss Gv */ |
5301 | 2c0262af | bellard | op = R_SS; |
5302 | 2c0262af | bellard | goto do_lxx;
|
5303 | 2c0262af | bellard | case 0x1b4: /* lfs Gv */ |
5304 | 2c0262af | bellard | op = R_FS; |
5305 | 2c0262af | bellard | goto do_lxx;
|
5306 | 2c0262af | bellard | case 0x1b5: /* lgs Gv */ |
5307 | 2c0262af | bellard | op = R_GS; |
5308 | 2c0262af | bellard | do_lxx:
|
5309 | 2c0262af | bellard | ot = dflag ? OT_LONG : OT_WORD; |
5310 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
5311 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
5312 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
5313 | 2c0262af | bellard | if (mod == 3) |
5314 | 2c0262af | bellard | goto illegal_op;
|
5315 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
5316 | 57fec1fe | bellard | gen_op_ld_T1_A0(ot + s->mem_index); |
5317 | aba9d61e | bellard | gen_add_A0_im(s, 1 << (ot - OT_WORD + 1)); |
5318 | 2c0262af | bellard | /* load the segment first to handle exceptions properly */
|
5319 | 57fec1fe | bellard | gen_op_ldu_T0_A0(OT_WORD + s->mem_index); |
5320 | 2c0262af | bellard | gen_movl_seg_T0(s, op, pc_start - s->cs_base); |
5321 | 2c0262af | bellard | /* then put the data */
|
5322 | 57fec1fe | bellard | gen_op_mov_reg_T1(ot, reg); |
5323 | 2c0262af | bellard | if (s->is_jmp) {
|
5324 | 14ce26e7 | bellard | gen_jmp_im(s->pc - s->cs_base); |
5325 | 2c0262af | bellard | gen_eob(s); |
5326 | 2c0262af | bellard | } |
5327 | 2c0262af | bellard | break;
|
5328 | 3b46e624 | ths | |
5329 | 2c0262af | bellard | /************************/
|
5330 | 2c0262af | bellard | /* shifts */
|
5331 | 2c0262af | bellard | case 0xc0: |
5332 | 2c0262af | bellard | case 0xc1: |
5333 | 2c0262af | bellard | /* shift Ev,Ib */
|
5334 | 2c0262af | bellard | shift = 2;
|
5335 | 2c0262af | bellard | grp2:
|
5336 | 2c0262af | bellard | { |
5337 | 2c0262af | bellard | if ((b & 1) == 0) |
5338 | 2c0262af | bellard | ot = OT_BYTE; |
5339 | 2c0262af | bellard | else
|
5340 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
5341 | 3b46e624 | ths | |
5342 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
5343 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
5344 | 2c0262af | bellard | op = (modrm >> 3) & 7; |
5345 | 3b46e624 | ths | |
5346 | 2c0262af | bellard | if (mod != 3) { |
5347 | 14ce26e7 | bellard | if (shift == 2) { |
5348 | 14ce26e7 | bellard | s->rip_offset = 1;
|
5349 | 14ce26e7 | bellard | } |
5350 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
5351 | 2c0262af | bellard | opreg = OR_TMP0; |
5352 | 2c0262af | bellard | } else {
|
5353 | 14ce26e7 | bellard | opreg = (modrm & 7) | REX_B(s);
|
5354 | 2c0262af | bellard | } |
5355 | 2c0262af | bellard | |
5356 | 2c0262af | bellard | /* simpler op */
|
5357 | 2c0262af | bellard | if (shift == 0) { |
5358 | 2c0262af | bellard | gen_shift(s, op, ot, opreg, OR_ECX); |
5359 | 2c0262af | bellard | } else {
|
5360 | 2c0262af | bellard | if (shift == 2) { |
5361 | 61382a50 | bellard | shift = ldub_code(s->pc++); |
5362 | 2c0262af | bellard | } |
5363 | 2c0262af | bellard | gen_shifti(s, op, ot, opreg, shift); |
5364 | 2c0262af | bellard | } |
5365 | 2c0262af | bellard | } |
5366 | 2c0262af | bellard | break;
|
5367 | 2c0262af | bellard | case 0xd0: |
5368 | 2c0262af | bellard | case 0xd1: |
5369 | 2c0262af | bellard | /* shift Ev,1 */
|
5370 | 2c0262af | bellard | shift = 1;
|
5371 | 2c0262af | bellard | goto grp2;
|
5372 | 2c0262af | bellard | case 0xd2: |
5373 | 2c0262af | bellard | case 0xd3: |
5374 | 2c0262af | bellard | /* shift Ev,cl */
|
5375 | 2c0262af | bellard | shift = 0;
|
5376 | 2c0262af | bellard | goto grp2;
|
5377 | 2c0262af | bellard | |
5378 | 2c0262af | bellard | case 0x1a4: /* shld imm */ |
5379 | 2c0262af | bellard | op = 0;
|
5380 | 2c0262af | bellard | shift = 1;
|
5381 | 2c0262af | bellard | goto do_shiftd;
|
5382 | 2c0262af | bellard | case 0x1a5: /* shld cl */ |
5383 | 2c0262af | bellard | op = 0;
|
5384 | 2c0262af | bellard | shift = 0;
|
5385 | 2c0262af | bellard | goto do_shiftd;
|
5386 | 2c0262af | bellard | case 0x1ac: /* shrd imm */ |
5387 | 2c0262af | bellard | op = 1;
|
5388 | 2c0262af | bellard | shift = 1;
|
5389 | 2c0262af | bellard | goto do_shiftd;
|
5390 | 2c0262af | bellard | case 0x1ad: /* shrd cl */ |
5391 | 2c0262af | bellard | op = 1;
|
5392 | 2c0262af | bellard | shift = 0;
|
5393 | 2c0262af | bellard | do_shiftd:
|
5394 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
5395 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
5396 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
5397 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
5398 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
5399 | 2c0262af | bellard | if (mod != 3) { |
5400 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
5401 | b6abf97d | bellard | opreg = OR_TMP0; |
5402 | 2c0262af | bellard | } else {
|
5403 | b6abf97d | bellard | opreg = rm; |
5404 | 2c0262af | bellard | } |
5405 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 1, reg);
|
5406 | 3b46e624 | ths | |
5407 | 2c0262af | bellard | if (shift) {
|
5408 | 61382a50 | bellard | val = ldub_code(s->pc++); |
5409 | b6abf97d | bellard | tcg_gen_movi_tl(cpu_T3, val); |
5410 | 2c0262af | bellard | } else {
|
5411 | b6abf97d | bellard | tcg_gen_ld_tl(cpu_T3, cpu_env, offsetof(CPUState, regs[R_ECX])); |
5412 | 2c0262af | bellard | } |
5413 | b6abf97d | bellard | gen_shiftd_rm_T1_T3(s, ot, opreg, op); |
5414 | 2c0262af | bellard | break;
|
5415 | 2c0262af | bellard | |
5416 | 2c0262af | bellard | /************************/
|
5417 | 2c0262af | bellard | /* floats */
|
5418 | 5fafdf24 | ths | case 0xd8 ... 0xdf: |
5419 | 7eee2a50 | bellard | if (s->flags & (HF_EM_MASK | HF_TS_MASK)) {
|
5420 | 7eee2a50 | bellard | /* if CR0.EM or CR0.TS are set, generate an FPU exception */
|
5421 | 7eee2a50 | bellard | /* XXX: what to do if illegal op ? */
|
5422 | 7eee2a50 | bellard | gen_exception(s, EXCP07_PREX, pc_start - s->cs_base); |
5423 | 7eee2a50 | bellard | break;
|
5424 | 7eee2a50 | bellard | } |
5425 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
5426 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
5427 | 2c0262af | bellard | rm = modrm & 7;
|
5428 | 2c0262af | bellard | op = ((b & 7) << 3) | ((modrm >> 3) & 7); |
5429 | 2c0262af | bellard | if (mod != 3) { |
5430 | 2c0262af | bellard | /* memory op */
|
5431 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
5432 | 2c0262af | bellard | switch(op) {
|
5433 | 2c0262af | bellard | case 0x00 ... 0x07: /* fxxxs */ |
5434 | 2c0262af | bellard | case 0x10 ... 0x17: /* fixxxl */ |
5435 | 2c0262af | bellard | case 0x20 ... 0x27: /* fxxxl */ |
5436 | 2c0262af | bellard | case 0x30 ... 0x37: /* fixxx */ |
5437 | 2c0262af | bellard | { |
5438 | 2c0262af | bellard | int op1;
|
5439 | 2c0262af | bellard | op1 = op & 7;
|
5440 | 2c0262af | bellard | |
5441 | 2c0262af | bellard | switch(op >> 4) { |
5442 | 2c0262af | bellard | case 0: |
5443 | ba7cd150 | bellard | gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
5444 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5445 | a7812ae4 | pbrook | gen_helper_flds_FT0(cpu_tmp2_i32); |
5446 | 2c0262af | bellard | break;
|
5447 | 2c0262af | bellard | case 1: |
5448 | ba7cd150 | bellard | gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
5449 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5450 | a7812ae4 | pbrook | gen_helper_fildl_FT0(cpu_tmp2_i32); |
5451 | 2c0262af | bellard | break;
|
5452 | 2c0262af | bellard | case 2: |
5453 | b6abf97d | bellard | tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_A0, |
5454 | 19e6c4b8 | bellard | (s->mem_index >> 2) - 1); |
5455 | a7812ae4 | pbrook | gen_helper_fldl_FT0(cpu_tmp1_i64); |
5456 | 2c0262af | bellard | break;
|
5457 | 2c0262af | bellard | case 3: |
5458 | 2c0262af | bellard | default:
|
5459 | ba7cd150 | bellard | gen_op_lds_T0_A0(OT_WORD + s->mem_index); |
5460 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5461 | a7812ae4 | pbrook | gen_helper_fildl_FT0(cpu_tmp2_i32); |
5462 | 2c0262af | bellard | break;
|
5463 | 2c0262af | bellard | } |
5464 | 3b46e624 | ths | |
5465 | a7812ae4 | pbrook | gen_helper_fp_arith_ST0_FT0(op1); |
5466 | 2c0262af | bellard | if (op1 == 3) { |
5467 | 2c0262af | bellard | /* fcomp needs pop */
|
5468 | a7812ae4 | pbrook | gen_helper_fpop(); |
5469 | 2c0262af | bellard | } |
5470 | 2c0262af | bellard | } |
5471 | 2c0262af | bellard | break;
|
5472 | 2c0262af | bellard | case 0x08: /* flds */ |
5473 | 2c0262af | bellard | case 0x0a: /* fsts */ |
5474 | 2c0262af | bellard | case 0x0b: /* fstps */ |
5475 | 465e9838 | bellard | case 0x18 ... 0x1b: /* fildl, fisttpl, fistl, fistpl */ |
5476 | 465e9838 | bellard | case 0x28 ... 0x2b: /* fldl, fisttpll, fstl, fstpl */ |
5477 | 465e9838 | bellard | case 0x38 ... 0x3b: /* filds, fisttps, fists, fistps */ |
5478 | 2c0262af | bellard | switch(op & 7) { |
5479 | 2c0262af | bellard | case 0: |
5480 | 2c0262af | bellard | switch(op >> 4) { |
5481 | 2c0262af | bellard | case 0: |
5482 | ba7cd150 | bellard | gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
5483 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5484 | a7812ae4 | pbrook | gen_helper_flds_ST0(cpu_tmp2_i32); |
5485 | 2c0262af | bellard | break;
|
5486 | 2c0262af | bellard | case 1: |
5487 | ba7cd150 | bellard | gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
5488 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5489 | a7812ae4 | pbrook | gen_helper_fildl_ST0(cpu_tmp2_i32); |
5490 | 2c0262af | bellard | break;
|
5491 | 2c0262af | bellard | case 2: |
5492 | b6abf97d | bellard | tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_A0, |
5493 | 19e6c4b8 | bellard | (s->mem_index >> 2) - 1); |
5494 | a7812ae4 | pbrook | gen_helper_fldl_ST0(cpu_tmp1_i64); |
5495 | 2c0262af | bellard | break;
|
5496 | 2c0262af | bellard | case 3: |
5497 | 2c0262af | bellard | default:
|
5498 | ba7cd150 | bellard | gen_op_lds_T0_A0(OT_WORD + s->mem_index); |
5499 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5500 | a7812ae4 | pbrook | gen_helper_fildl_ST0(cpu_tmp2_i32); |
5501 | 2c0262af | bellard | break;
|
5502 | 2c0262af | bellard | } |
5503 | 2c0262af | bellard | break;
|
5504 | 465e9838 | bellard | case 1: |
5505 | 19e6c4b8 | bellard | /* XXX: the corresponding CPUID bit must be tested ! */
|
5506 | 465e9838 | bellard | switch(op >> 4) { |
5507 | 465e9838 | bellard | case 1: |
5508 | a7812ae4 | pbrook | gen_helper_fisttl_ST0(cpu_tmp2_i32); |
5509 | b6abf97d | bellard | tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5510 | ba7cd150 | bellard | gen_op_st_T0_A0(OT_LONG + s->mem_index); |
5511 | 465e9838 | bellard | break;
|
5512 | 465e9838 | bellard | case 2: |
5513 | a7812ae4 | pbrook | gen_helper_fisttll_ST0(cpu_tmp1_i64); |
5514 | b6abf97d | bellard | tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_A0, |
5515 | 19e6c4b8 | bellard | (s->mem_index >> 2) - 1); |
5516 | 465e9838 | bellard | break;
|
5517 | 465e9838 | bellard | case 3: |
5518 | 465e9838 | bellard | default:
|
5519 | a7812ae4 | pbrook | gen_helper_fistt_ST0(cpu_tmp2_i32); |
5520 | b6abf97d | bellard | tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5521 | ba7cd150 | bellard | gen_op_st_T0_A0(OT_WORD + s->mem_index); |
5522 | 19e6c4b8 | bellard | break;
|
5523 | 465e9838 | bellard | } |
5524 | a7812ae4 | pbrook | gen_helper_fpop(); |
5525 | 465e9838 | bellard | break;
|
5526 | 2c0262af | bellard | default:
|
5527 | 2c0262af | bellard | switch(op >> 4) { |
5528 | 2c0262af | bellard | case 0: |
5529 | a7812ae4 | pbrook | gen_helper_fsts_ST0(cpu_tmp2_i32); |
5530 | b6abf97d | bellard | tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5531 | ba7cd150 | bellard | gen_op_st_T0_A0(OT_LONG + s->mem_index); |
5532 | 2c0262af | bellard | break;
|
5533 | 2c0262af | bellard | case 1: |
5534 | a7812ae4 | pbrook | gen_helper_fistl_ST0(cpu_tmp2_i32); |
5535 | b6abf97d | bellard | tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5536 | ba7cd150 | bellard | gen_op_st_T0_A0(OT_LONG + s->mem_index); |
5537 | 2c0262af | bellard | break;
|
5538 | 2c0262af | bellard | case 2: |
5539 | a7812ae4 | pbrook | gen_helper_fstl_ST0(cpu_tmp1_i64); |
5540 | b6abf97d | bellard | tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_A0, |
5541 | 19e6c4b8 | bellard | (s->mem_index >> 2) - 1); |
5542 | 2c0262af | bellard | break;
|
5543 | 2c0262af | bellard | case 3: |
5544 | 2c0262af | bellard | default:
|
5545 | a7812ae4 | pbrook | gen_helper_fist_ST0(cpu_tmp2_i32); |
5546 | b6abf97d | bellard | tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5547 | ba7cd150 | bellard | gen_op_st_T0_A0(OT_WORD + s->mem_index); |
5548 | 2c0262af | bellard | break;
|
5549 | 2c0262af | bellard | } |
5550 | 2c0262af | bellard | if ((op & 7) == 3) |
5551 | a7812ae4 | pbrook | gen_helper_fpop(); |
5552 | 2c0262af | bellard | break;
|
5553 | 2c0262af | bellard | } |
5554 | 2c0262af | bellard | break;
|
5555 | 2c0262af | bellard | case 0x0c: /* fldenv mem */ |
5556 | 19e6c4b8 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
5557 | 19e6c4b8 | bellard | gen_op_set_cc_op(s->cc_op); |
5558 | 19e6c4b8 | bellard | gen_jmp_im(pc_start - s->cs_base); |
5559 | a7812ae4 | pbrook | gen_helper_fldenv( |
5560 | 19e6c4b8 | bellard | cpu_A0, tcg_const_i32(s->dflag)); |
5561 | 2c0262af | bellard | break;
|
5562 | 2c0262af | bellard | case 0x0d: /* fldcw mem */ |
5563 | 19e6c4b8 | bellard | gen_op_ld_T0_A0(OT_WORD + s->mem_index); |
5564 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
5565 | a7812ae4 | pbrook | gen_helper_fldcw(cpu_tmp2_i32); |
5566 | 2c0262af | bellard | break;
|
5567 | 2c0262af | bellard | case 0x0e: /* fnstenv mem */ |
5568 | 19e6c4b8 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
5569 | 19e6c4b8 | bellard | gen_op_set_cc_op(s->cc_op); |
5570 | 19e6c4b8 | bellard | gen_jmp_im(pc_start - s->cs_base); |
5571 | a7812ae4 | pbrook | gen_helper_fstenv(cpu_A0, tcg_const_i32(s->dflag)); |
5572 | 2c0262af | bellard | break;
|
5573 | 2c0262af | bellard | case 0x0f: /* fnstcw mem */ |
5574 | a7812ae4 | pbrook | gen_helper_fnstcw(cpu_tmp2_i32); |
5575 | b6abf97d | bellard | tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5576 | 19e6c4b8 | bellard | gen_op_st_T0_A0(OT_WORD + s->mem_index); |
5577 | 2c0262af | bellard | break;
|
5578 | 2c0262af | bellard | case 0x1d: /* fldt mem */ |
5579 | 19e6c4b8 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
5580 | 19e6c4b8 | bellard | gen_op_set_cc_op(s->cc_op); |
5581 | 19e6c4b8 | bellard | gen_jmp_im(pc_start - s->cs_base); |
5582 | a7812ae4 | pbrook | gen_helper_fldt_ST0(cpu_A0); |
5583 | 2c0262af | bellard | break;
|
5584 | 2c0262af | bellard | case 0x1f: /* fstpt mem */ |
5585 | 19e6c4b8 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
5586 | 19e6c4b8 | bellard | gen_op_set_cc_op(s->cc_op); |
5587 | 19e6c4b8 | bellard | gen_jmp_im(pc_start - s->cs_base); |
5588 | a7812ae4 | pbrook | gen_helper_fstt_ST0(cpu_A0); |
5589 | a7812ae4 | pbrook | gen_helper_fpop(); |
5590 | 2c0262af | bellard | break;
|
5591 | 2c0262af | bellard | case 0x2c: /* frstor mem */ |
5592 | 19e6c4b8 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
5593 | 19e6c4b8 | bellard | gen_op_set_cc_op(s->cc_op); |
5594 | 19e6c4b8 | bellard | gen_jmp_im(pc_start - s->cs_base); |
5595 | a7812ae4 | pbrook | gen_helper_frstor(cpu_A0, tcg_const_i32(s->dflag)); |
5596 | 2c0262af | bellard | break;
|
5597 | 2c0262af | bellard | case 0x2e: /* fnsave mem */ |
5598 | 19e6c4b8 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
5599 | 19e6c4b8 | bellard | gen_op_set_cc_op(s->cc_op); |
5600 | 19e6c4b8 | bellard | gen_jmp_im(pc_start - s->cs_base); |
5601 | a7812ae4 | pbrook | gen_helper_fsave(cpu_A0, tcg_const_i32(s->dflag)); |
5602 | 2c0262af | bellard | break;
|
5603 | 2c0262af | bellard | case 0x2f: /* fnstsw mem */ |
5604 | a7812ae4 | pbrook | gen_helper_fnstsw(cpu_tmp2_i32); |
5605 | b6abf97d | bellard | tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5606 | 19e6c4b8 | bellard | gen_op_st_T0_A0(OT_WORD + s->mem_index); |
5607 | 2c0262af | bellard | break;
|
5608 | 2c0262af | bellard | case 0x3c: /* fbld */ |
5609 | 19e6c4b8 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
5610 | 19e6c4b8 | bellard | gen_op_set_cc_op(s->cc_op); |
5611 | 19e6c4b8 | bellard | gen_jmp_im(pc_start - s->cs_base); |
5612 | a7812ae4 | pbrook | gen_helper_fbld_ST0(cpu_A0); |
5613 | 2c0262af | bellard | break;
|
5614 | 2c0262af | bellard | case 0x3e: /* fbstp */ |
5615 | 19e6c4b8 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
5616 | 19e6c4b8 | bellard | gen_op_set_cc_op(s->cc_op); |
5617 | 19e6c4b8 | bellard | gen_jmp_im(pc_start - s->cs_base); |
5618 | a7812ae4 | pbrook | gen_helper_fbst_ST0(cpu_A0); |
5619 | a7812ae4 | pbrook | gen_helper_fpop(); |
5620 | 2c0262af | bellard | break;
|
5621 | 2c0262af | bellard | case 0x3d: /* fildll */ |
5622 | b6abf97d | bellard | tcg_gen_qemu_ld64(cpu_tmp1_i64, cpu_A0, |
5623 | 19e6c4b8 | bellard | (s->mem_index >> 2) - 1); |
5624 | a7812ae4 | pbrook | gen_helper_fildll_ST0(cpu_tmp1_i64); |
5625 | 2c0262af | bellard | break;
|
5626 | 2c0262af | bellard | case 0x3f: /* fistpll */ |
5627 | a7812ae4 | pbrook | gen_helper_fistll_ST0(cpu_tmp1_i64); |
5628 | b6abf97d | bellard | tcg_gen_qemu_st64(cpu_tmp1_i64, cpu_A0, |
5629 | 19e6c4b8 | bellard | (s->mem_index >> 2) - 1); |
5630 | a7812ae4 | pbrook | gen_helper_fpop(); |
5631 | 2c0262af | bellard | break;
|
5632 | 2c0262af | bellard | default:
|
5633 | 2c0262af | bellard | goto illegal_op;
|
5634 | 2c0262af | bellard | } |
5635 | 2c0262af | bellard | } else {
|
5636 | 2c0262af | bellard | /* register float ops */
|
5637 | 2c0262af | bellard | opreg = rm; |
5638 | 2c0262af | bellard | |
5639 | 2c0262af | bellard | switch(op) {
|
5640 | 2c0262af | bellard | case 0x08: /* fld sti */ |
5641 | a7812ae4 | pbrook | gen_helper_fpush(); |
5642 | a7812ae4 | pbrook | gen_helper_fmov_ST0_STN(tcg_const_i32((opreg + 1) & 7)); |
5643 | 2c0262af | bellard | break;
|
5644 | 2c0262af | bellard | case 0x09: /* fxchg sti */ |
5645 | c169c906 | bellard | case 0x29: /* fxchg4 sti, undocumented op */ |
5646 | c169c906 | bellard | case 0x39: /* fxchg7 sti, undocumented op */ |
5647 | a7812ae4 | pbrook | gen_helper_fxchg_ST0_STN(tcg_const_i32(opreg)); |
5648 | 2c0262af | bellard | break;
|
5649 | 2c0262af | bellard | case 0x0a: /* grp d9/2 */ |
5650 | 2c0262af | bellard | switch(rm) {
|
5651 | 2c0262af | bellard | case 0: /* fnop */ |
5652 | 023fe10d | bellard | /* check exceptions (FreeBSD FPU probe) */
|
5653 | 023fe10d | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
5654 | 023fe10d | bellard | gen_op_set_cc_op(s->cc_op); |
5655 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
5656 | a7812ae4 | pbrook | gen_helper_fwait(); |
5657 | 2c0262af | bellard | break;
|
5658 | 2c0262af | bellard | default:
|
5659 | 2c0262af | bellard | goto illegal_op;
|
5660 | 2c0262af | bellard | } |
5661 | 2c0262af | bellard | break;
|
5662 | 2c0262af | bellard | case 0x0c: /* grp d9/4 */ |
5663 | 2c0262af | bellard | switch(rm) {
|
5664 | 2c0262af | bellard | case 0: /* fchs */ |
5665 | a7812ae4 | pbrook | gen_helper_fchs_ST0(); |
5666 | 2c0262af | bellard | break;
|
5667 | 2c0262af | bellard | case 1: /* fabs */ |
5668 | a7812ae4 | pbrook | gen_helper_fabs_ST0(); |
5669 | 2c0262af | bellard | break;
|
5670 | 2c0262af | bellard | case 4: /* ftst */ |
5671 | a7812ae4 | pbrook | gen_helper_fldz_FT0(); |
5672 | a7812ae4 | pbrook | gen_helper_fcom_ST0_FT0(); |
5673 | 2c0262af | bellard | break;
|
5674 | 2c0262af | bellard | case 5: /* fxam */ |
5675 | a7812ae4 | pbrook | gen_helper_fxam_ST0(); |
5676 | 2c0262af | bellard | break;
|
5677 | 2c0262af | bellard | default:
|
5678 | 2c0262af | bellard | goto illegal_op;
|
5679 | 2c0262af | bellard | } |
5680 | 2c0262af | bellard | break;
|
5681 | 2c0262af | bellard | case 0x0d: /* grp d9/5 */ |
5682 | 2c0262af | bellard | { |
5683 | 2c0262af | bellard | switch(rm) {
|
5684 | 2c0262af | bellard | case 0: |
5685 | a7812ae4 | pbrook | gen_helper_fpush(); |
5686 | a7812ae4 | pbrook | gen_helper_fld1_ST0(); |
5687 | 2c0262af | bellard | break;
|
5688 | 2c0262af | bellard | case 1: |
5689 | a7812ae4 | pbrook | gen_helper_fpush(); |
5690 | a7812ae4 | pbrook | gen_helper_fldl2t_ST0(); |
5691 | 2c0262af | bellard | break;
|
5692 | 2c0262af | bellard | case 2: |
5693 | a7812ae4 | pbrook | gen_helper_fpush(); |
5694 | a7812ae4 | pbrook | gen_helper_fldl2e_ST0(); |
5695 | 2c0262af | bellard | break;
|
5696 | 2c0262af | bellard | case 3: |
5697 | a7812ae4 | pbrook | gen_helper_fpush(); |
5698 | a7812ae4 | pbrook | gen_helper_fldpi_ST0(); |
5699 | 2c0262af | bellard | break;
|
5700 | 2c0262af | bellard | case 4: |
5701 | a7812ae4 | pbrook | gen_helper_fpush(); |
5702 | a7812ae4 | pbrook | gen_helper_fldlg2_ST0(); |
5703 | 2c0262af | bellard | break;
|
5704 | 2c0262af | bellard | case 5: |
5705 | a7812ae4 | pbrook | gen_helper_fpush(); |
5706 | a7812ae4 | pbrook | gen_helper_fldln2_ST0(); |
5707 | 2c0262af | bellard | break;
|
5708 | 2c0262af | bellard | case 6: |
5709 | a7812ae4 | pbrook | gen_helper_fpush(); |
5710 | a7812ae4 | pbrook | gen_helper_fldz_ST0(); |
5711 | 2c0262af | bellard | break;
|
5712 | 2c0262af | bellard | default:
|
5713 | 2c0262af | bellard | goto illegal_op;
|
5714 | 2c0262af | bellard | } |
5715 | 2c0262af | bellard | } |
5716 | 2c0262af | bellard | break;
|
5717 | 2c0262af | bellard | case 0x0e: /* grp d9/6 */ |
5718 | 2c0262af | bellard | switch(rm) {
|
5719 | 2c0262af | bellard | case 0: /* f2xm1 */ |
5720 | a7812ae4 | pbrook | gen_helper_f2xm1(); |
5721 | 2c0262af | bellard | break;
|
5722 | 2c0262af | bellard | case 1: /* fyl2x */ |
5723 | a7812ae4 | pbrook | gen_helper_fyl2x(); |
5724 | 2c0262af | bellard | break;
|
5725 | 2c0262af | bellard | case 2: /* fptan */ |
5726 | a7812ae4 | pbrook | gen_helper_fptan(); |
5727 | 2c0262af | bellard | break;
|
5728 | 2c0262af | bellard | case 3: /* fpatan */ |
5729 | a7812ae4 | pbrook | gen_helper_fpatan(); |
5730 | 2c0262af | bellard | break;
|
5731 | 2c0262af | bellard | case 4: /* fxtract */ |
5732 | a7812ae4 | pbrook | gen_helper_fxtract(); |
5733 | 2c0262af | bellard | break;
|
5734 | 2c0262af | bellard | case 5: /* fprem1 */ |
5735 | a7812ae4 | pbrook | gen_helper_fprem1(); |
5736 | 2c0262af | bellard | break;
|
5737 | 2c0262af | bellard | case 6: /* fdecstp */ |
5738 | a7812ae4 | pbrook | gen_helper_fdecstp(); |
5739 | 2c0262af | bellard | break;
|
5740 | 2c0262af | bellard | default:
|
5741 | 2c0262af | bellard | case 7: /* fincstp */ |
5742 | a7812ae4 | pbrook | gen_helper_fincstp(); |
5743 | 2c0262af | bellard | break;
|
5744 | 2c0262af | bellard | } |
5745 | 2c0262af | bellard | break;
|
5746 | 2c0262af | bellard | case 0x0f: /* grp d9/7 */ |
5747 | 2c0262af | bellard | switch(rm) {
|
5748 | 2c0262af | bellard | case 0: /* fprem */ |
5749 | a7812ae4 | pbrook | gen_helper_fprem(); |
5750 | 2c0262af | bellard | break;
|
5751 | 2c0262af | bellard | case 1: /* fyl2xp1 */ |
5752 | a7812ae4 | pbrook | gen_helper_fyl2xp1(); |
5753 | 2c0262af | bellard | break;
|
5754 | 2c0262af | bellard | case 2: /* fsqrt */ |
5755 | a7812ae4 | pbrook | gen_helper_fsqrt(); |
5756 | 2c0262af | bellard | break;
|
5757 | 2c0262af | bellard | case 3: /* fsincos */ |
5758 | a7812ae4 | pbrook | gen_helper_fsincos(); |
5759 | 2c0262af | bellard | break;
|
5760 | 2c0262af | bellard | case 5: /* fscale */ |
5761 | a7812ae4 | pbrook | gen_helper_fscale(); |
5762 | 2c0262af | bellard | break;
|
5763 | 2c0262af | bellard | case 4: /* frndint */ |
5764 | a7812ae4 | pbrook | gen_helper_frndint(); |
5765 | 2c0262af | bellard | break;
|
5766 | 2c0262af | bellard | case 6: /* fsin */ |
5767 | a7812ae4 | pbrook | gen_helper_fsin(); |
5768 | 2c0262af | bellard | break;
|
5769 | 2c0262af | bellard | default:
|
5770 | 2c0262af | bellard | case 7: /* fcos */ |
5771 | a7812ae4 | pbrook | gen_helper_fcos(); |
5772 | 2c0262af | bellard | break;
|
5773 | 2c0262af | bellard | } |
5774 | 2c0262af | bellard | break;
|
5775 | 2c0262af | bellard | case 0x00: case 0x01: case 0x04 ... 0x07: /* fxxx st, sti */ |
5776 | 2c0262af | bellard | case 0x20: case 0x21: case 0x24 ... 0x27: /* fxxx sti, st */ |
5777 | 2c0262af | bellard | case 0x30: case 0x31: case 0x34 ... 0x37: /* fxxxp sti, st */ |
5778 | 2c0262af | bellard | { |
5779 | 2c0262af | bellard | int op1;
|
5780 | 3b46e624 | ths | |
5781 | 2c0262af | bellard | op1 = op & 7;
|
5782 | 2c0262af | bellard | if (op >= 0x20) { |
5783 | a7812ae4 | pbrook | gen_helper_fp_arith_STN_ST0(op1, opreg); |
5784 | 2c0262af | bellard | if (op >= 0x30) |
5785 | a7812ae4 | pbrook | gen_helper_fpop(); |
5786 | 2c0262af | bellard | } else {
|
5787 | a7812ae4 | pbrook | gen_helper_fmov_FT0_STN(tcg_const_i32(opreg)); |
5788 | a7812ae4 | pbrook | gen_helper_fp_arith_ST0_FT0(op1); |
5789 | 2c0262af | bellard | } |
5790 | 2c0262af | bellard | } |
5791 | 2c0262af | bellard | break;
|
5792 | 2c0262af | bellard | case 0x02: /* fcom */ |
5793 | c169c906 | bellard | case 0x22: /* fcom2, undocumented op */ |
5794 | a7812ae4 | pbrook | gen_helper_fmov_FT0_STN(tcg_const_i32(opreg)); |
5795 | a7812ae4 | pbrook | gen_helper_fcom_ST0_FT0(); |
5796 | 2c0262af | bellard | break;
|
5797 | 2c0262af | bellard | case 0x03: /* fcomp */ |
5798 | c169c906 | bellard | case 0x23: /* fcomp3, undocumented op */ |
5799 | c169c906 | bellard | case 0x32: /* fcomp5, undocumented op */ |
5800 | a7812ae4 | pbrook | gen_helper_fmov_FT0_STN(tcg_const_i32(opreg)); |
5801 | a7812ae4 | pbrook | gen_helper_fcom_ST0_FT0(); |
5802 | a7812ae4 | pbrook | gen_helper_fpop(); |
5803 | 2c0262af | bellard | break;
|
5804 | 2c0262af | bellard | case 0x15: /* da/5 */ |
5805 | 2c0262af | bellard | switch(rm) {
|
5806 | 2c0262af | bellard | case 1: /* fucompp */ |
5807 | a7812ae4 | pbrook | gen_helper_fmov_FT0_STN(tcg_const_i32(1));
|
5808 | a7812ae4 | pbrook | gen_helper_fucom_ST0_FT0(); |
5809 | a7812ae4 | pbrook | gen_helper_fpop(); |
5810 | a7812ae4 | pbrook | gen_helper_fpop(); |
5811 | 2c0262af | bellard | break;
|
5812 | 2c0262af | bellard | default:
|
5813 | 2c0262af | bellard | goto illegal_op;
|
5814 | 2c0262af | bellard | } |
5815 | 2c0262af | bellard | break;
|
5816 | 2c0262af | bellard | case 0x1c: |
5817 | 2c0262af | bellard | switch(rm) {
|
5818 | 2c0262af | bellard | case 0: /* feni (287 only, just do nop here) */ |
5819 | 2c0262af | bellard | break;
|
5820 | 2c0262af | bellard | case 1: /* fdisi (287 only, just do nop here) */ |
5821 | 2c0262af | bellard | break;
|
5822 | 2c0262af | bellard | case 2: /* fclex */ |
5823 | a7812ae4 | pbrook | gen_helper_fclex(); |
5824 | 2c0262af | bellard | break;
|
5825 | 2c0262af | bellard | case 3: /* fninit */ |
5826 | a7812ae4 | pbrook | gen_helper_fninit(); |
5827 | 2c0262af | bellard | break;
|
5828 | 2c0262af | bellard | case 4: /* fsetpm (287 only, just do nop here) */ |
5829 | 2c0262af | bellard | break;
|
5830 | 2c0262af | bellard | default:
|
5831 | 2c0262af | bellard | goto illegal_op;
|
5832 | 2c0262af | bellard | } |
5833 | 2c0262af | bellard | break;
|
5834 | 2c0262af | bellard | case 0x1d: /* fucomi */ |
5835 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
5836 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
5837 | a7812ae4 | pbrook | gen_helper_fmov_FT0_STN(tcg_const_i32(opreg)); |
5838 | a7812ae4 | pbrook | gen_helper_fucomi_ST0_FT0(); |
5839 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
5840 | 2c0262af | bellard | break;
|
5841 | 2c0262af | bellard | case 0x1e: /* fcomi */ |
5842 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
5843 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
5844 | a7812ae4 | pbrook | gen_helper_fmov_FT0_STN(tcg_const_i32(opreg)); |
5845 | a7812ae4 | pbrook | gen_helper_fcomi_ST0_FT0(); |
5846 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
5847 | 2c0262af | bellard | break;
|
5848 | 658c8bda | bellard | case 0x28: /* ffree sti */ |
5849 | a7812ae4 | pbrook | gen_helper_ffree_STN(tcg_const_i32(opreg)); |
5850 | 5fafdf24 | ths | break;
|
5851 | 2c0262af | bellard | case 0x2a: /* fst sti */ |
5852 | a7812ae4 | pbrook | gen_helper_fmov_STN_ST0(tcg_const_i32(opreg)); |
5853 | 2c0262af | bellard | break;
|
5854 | 2c0262af | bellard | case 0x2b: /* fstp sti */ |
5855 | c169c906 | bellard | case 0x0b: /* fstp1 sti, undocumented op */ |
5856 | c169c906 | bellard | case 0x3a: /* fstp8 sti, undocumented op */ |
5857 | c169c906 | bellard | case 0x3b: /* fstp9 sti, undocumented op */ |
5858 | a7812ae4 | pbrook | gen_helper_fmov_STN_ST0(tcg_const_i32(opreg)); |
5859 | a7812ae4 | pbrook | gen_helper_fpop(); |
5860 | 2c0262af | bellard | break;
|
5861 | 2c0262af | bellard | case 0x2c: /* fucom st(i) */ |
5862 | a7812ae4 | pbrook | gen_helper_fmov_FT0_STN(tcg_const_i32(opreg)); |
5863 | a7812ae4 | pbrook | gen_helper_fucom_ST0_FT0(); |
5864 | 2c0262af | bellard | break;
|
5865 | 2c0262af | bellard | case 0x2d: /* fucomp st(i) */ |
5866 | a7812ae4 | pbrook | gen_helper_fmov_FT0_STN(tcg_const_i32(opreg)); |
5867 | a7812ae4 | pbrook | gen_helper_fucom_ST0_FT0(); |
5868 | a7812ae4 | pbrook | gen_helper_fpop(); |
5869 | 2c0262af | bellard | break;
|
5870 | 2c0262af | bellard | case 0x33: /* de/3 */ |
5871 | 2c0262af | bellard | switch(rm) {
|
5872 | 2c0262af | bellard | case 1: /* fcompp */ |
5873 | a7812ae4 | pbrook | gen_helper_fmov_FT0_STN(tcg_const_i32(1));
|
5874 | a7812ae4 | pbrook | gen_helper_fcom_ST0_FT0(); |
5875 | a7812ae4 | pbrook | gen_helper_fpop(); |
5876 | a7812ae4 | pbrook | gen_helper_fpop(); |
5877 | 2c0262af | bellard | break;
|
5878 | 2c0262af | bellard | default:
|
5879 | 2c0262af | bellard | goto illegal_op;
|
5880 | 2c0262af | bellard | } |
5881 | 2c0262af | bellard | break;
|
5882 | c169c906 | bellard | case 0x38: /* ffreep sti, undocumented op */ |
5883 | a7812ae4 | pbrook | gen_helper_ffree_STN(tcg_const_i32(opreg)); |
5884 | a7812ae4 | pbrook | gen_helper_fpop(); |
5885 | c169c906 | bellard | break;
|
5886 | 2c0262af | bellard | case 0x3c: /* df/4 */ |
5887 | 2c0262af | bellard | switch(rm) {
|
5888 | 2c0262af | bellard | case 0: |
5889 | a7812ae4 | pbrook | gen_helper_fnstsw(cpu_tmp2_i32); |
5890 | b6abf97d | bellard | tcg_gen_extu_i32_tl(cpu_T[0], cpu_tmp2_i32);
|
5891 | 19e6c4b8 | bellard | gen_op_mov_reg_T0(OT_WORD, R_EAX); |
5892 | 2c0262af | bellard | break;
|
5893 | 2c0262af | bellard | default:
|
5894 | 2c0262af | bellard | goto illegal_op;
|
5895 | 2c0262af | bellard | } |
5896 | 2c0262af | bellard | break;
|
5897 | 2c0262af | bellard | case 0x3d: /* fucomip */ |
5898 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
5899 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
5900 | a7812ae4 | pbrook | gen_helper_fmov_FT0_STN(tcg_const_i32(opreg)); |
5901 | a7812ae4 | pbrook | gen_helper_fucomi_ST0_FT0(); |
5902 | a7812ae4 | pbrook | gen_helper_fpop(); |
5903 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
5904 | 2c0262af | bellard | break;
|
5905 | 2c0262af | bellard | case 0x3e: /* fcomip */ |
5906 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
5907 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
5908 | a7812ae4 | pbrook | gen_helper_fmov_FT0_STN(tcg_const_i32(opreg)); |
5909 | a7812ae4 | pbrook | gen_helper_fcomi_ST0_FT0(); |
5910 | a7812ae4 | pbrook | gen_helper_fpop(); |
5911 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
5912 | 2c0262af | bellard | break;
|
5913 | a2cc3b24 | bellard | case 0x10 ... 0x13: /* fcmovxx */ |
5914 | a2cc3b24 | bellard | case 0x18 ... 0x1b: |
5915 | a2cc3b24 | bellard | { |
5916 | 19e6c4b8 | bellard | int op1, l1;
|
5917 | d70040bc | pbrook | static const uint8_t fcmov_cc[8] = { |
5918 | a2cc3b24 | bellard | (JCC_B << 1),
|
5919 | a2cc3b24 | bellard | (JCC_Z << 1),
|
5920 | a2cc3b24 | bellard | (JCC_BE << 1),
|
5921 | a2cc3b24 | bellard | (JCC_P << 1),
|
5922 | a2cc3b24 | bellard | }; |
5923 | 1e4840bf | bellard | op1 = fcmov_cc[op & 3] | (((op >> 3) & 1) ^ 1); |
5924 | 19e6c4b8 | bellard | l1 = gen_new_label(); |
5925 | 1e4840bf | bellard | gen_jcc1(s, s->cc_op, op1, l1); |
5926 | a7812ae4 | pbrook | gen_helper_fmov_ST0_STN(tcg_const_i32(opreg)); |
5927 | 19e6c4b8 | bellard | gen_set_label(l1); |
5928 | a2cc3b24 | bellard | } |
5929 | a2cc3b24 | bellard | break;
|
5930 | 2c0262af | bellard | default:
|
5931 | 2c0262af | bellard | goto illegal_op;
|
5932 | 2c0262af | bellard | } |
5933 | 2c0262af | bellard | } |
5934 | 2c0262af | bellard | break;
|
5935 | 2c0262af | bellard | /************************/
|
5936 | 2c0262af | bellard | /* string ops */
|
5937 | 2c0262af | bellard | |
5938 | 2c0262af | bellard | case 0xa4: /* movsS */ |
5939 | 2c0262af | bellard | case 0xa5: |
5940 | 2c0262af | bellard | if ((b & 1) == 0) |
5941 | 2c0262af | bellard | ot = OT_BYTE; |
5942 | 2c0262af | bellard | else
|
5943 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
5944 | 2c0262af | bellard | |
5945 | 2c0262af | bellard | if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
5946 | 2c0262af | bellard | gen_repz_movs(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
5947 | 2c0262af | bellard | } else {
|
5948 | 2c0262af | bellard | gen_movs(s, ot); |
5949 | 2c0262af | bellard | } |
5950 | 2c0262af | bellard | break;
|
5951 | 3b46e624 | ths | |
5952 | 2c0262af | bellard | case 0xaa: /* stosS */ |
5953 | 2c0262af | bellard | case 0xab: |
5954 | 2c0262af | bellard | if ((b & 1) == 0) |
5955 | 2c0262af | bellard | ot = OT_BYTE; |
5956 | 2c0262af | bellard | else
|
5957 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
5958 | 2c0262af | bellard | |
5959 | 2c0262af | bellard | if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
5960 | 2c0262af | bellard | gen_repz_stos(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
5961 | 2c0262af | bellard | } else {
|
5962 | 2c0262af | bellard | gen_stos(s, ot); |
5963 | 2c0262af | bellard | } |
5964 | 2c0262af | bellard | break;
|
5965 | 2c0262af | bellard | case 0xac: /* lodsS */ |
5966 | 2c0262af | bellard | case 0xad: |
5967 | 2c0262af | bellard | if ((b & 1) == 0) |
5968 | 2c0262af | bellard | ot = OT_BYTE; |
5969 | 2c0262af | bellard | else
|
5970 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
5971 | 2c0262af | bellard | if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
5972 | 2c0262af | bellard | gen_repz_lods(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
5973 | 2c0262af | bellard | } else {
|
5974 | 2c0262af | bellard | gen_lods(s, ot); |
5975 | 2c0262af | bellard | } |
5976 | 2c0262af | bellard | break;
|
5977 | 2c0262af | bellard | case 0xae: /* scasS */ |
5978 | 2c0262af | bellard | case 0xaf: |
5979 | 2c0262af | bellard | if ((b & 1) == 0) |
5980 | 2c0262af | bellard | ot = OT_BYTE; |
5981 | 2c0262af | bellard | else
|
5982 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
5983 | 2c0262af | bellard | if (prefixes & PREFIX_REPNZ) {
|
5984 | 2c0262af | bellard | gen_repz_scas(s, ot, pc_start - s->cs_base, s->pc - s->cs_base, 1);
|
5985 | 2c0262af | bellard | } else if (prefixes & PREFIX_REPZ) { |
5986 | 2c0262af | bellard | gen_repz_scas(s, ot, pc_start - s->cs_base, s->pc - s->cs_base, 0);
|
5987 | 2c0262af | bellard | } else {
|
5988 | 2c0262af | bellard | gen_scas(s, ot); |
5989 | 2c0262af | bellard | s->cc_op = CC_OP_SUBB + ot; |
5990 | 2c0262af | bellard | } |
5991 | 2c0262af | bellard | break;
|
5992 | 2c0262af | bellard | |
5993 | 2c0262af | bellard | case 0xa6: /* cmpsS */ |
5994 | 2c0262af | bellard | case 0xa7: |
5995 | 2c0262af | bellard | if ((b & 1) == 0) |
5996 | 2c0262af | bellard | ot = OT_BYTE; |
5997 | 2c0262af | bellard | else
|
5998 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
5999 | 2c0262af | bellard | if (prefixes & PREFIX_REPNZ) {
|
6000 | 2c0262af | bellard | gen_repz_cmps(s, ot, pc_start - s->cs_base, s->pc - s->cs_base, 1);
|
6001 | 2c0262af | bellard | } else if (prefixes & PREFIX_REPZ) { |
6002 | 2c0262af | bellard | gen_repz_cmps(s, ot, pc_start - s->cs_base, s->pc - s->cs_base, 0);
|
6003 | 2c0262af | bellard | } else {
|
6004 | 2c0262af | bellard | gen_cmps(s, ot); |
6005 | 2c0262af | bellard | s->cc_op = CC_OP_SUBB + ot; |
6006 | 2c0262af | bellard | } |
6007 | 2c0262af | bellard | break;
|
6008 | 2c0262af | bellard | case 0x6c: /* insS */ |
6009 | 2c0262af | bellard | case 0x6d: |
6010 | f115e911 | bellard | if ((b & 1) == 0) |
6011 | f115e911 | bellard | ot = OT_BYTE; |
6012 | f115e911 | bellard | else
|
6013 | f115e911 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
6014 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_WORD, 0, R_EDX);
|
6015 | 0573fbfc | ths | gen_op_andl_T0_ffff(); |
6016 | b8b6a50b | bellard | gen_check_io(s, ot, pc_start - s->cs_base, |
6017 | b8b6a50b | bellard | SVM_IOIO_TYPE_MASK | svm_is_rep(prefixes) | 4);
|
6018 | f115e911 | bellard | if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
6019 | f115e911 | bellard | gen_repz_ins(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
6020 | 2c0262af | bellard | } else {
|
6021 | f115e911 | bellard | gen_ins(s, ot); |
6022 | 2e70f6ef | pbrook | if (use_icount) {
|
6023 | 2e70f6ef | pbrook | gen_jmp(s, s->pc - s->cs_base); |
6024 | 2e70f6ef | pbrook | } |
6025 | 2c0262af | bellard | } |
6026 | 2c0262af | bellard | break;
|
6027 | 2c0262af | bellard | case 0x6e: /* outsS */ |
6028 | 2c0262af | bellard | case 0x6f: |
6029 | f115e911 | bellard | if ((b & 1) == 0) |
6030 | f115e911 | bellard | ot = OT_BYTE; |
6031 | f115e911 | bellard | else
|
6032 | f115e911 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
6033 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_WORD, 0, R_EDX);
|
6034 | 0573fbfc | ths | gen_op_andl_T0_ffff(); |
6035 | b8b6a50b | bellard | gen_check_io(s, ot, pc_start - s->cs_base, |
6036 | b8b6a50b | bellard | svm_is_rep(prefixes) | 4);
|
6037 | f115e911 | bellard | if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
6038 | f115e911 | bellard | gen_repz_outs(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
6039 | 2c0262af | bellard | } else {
|
6040 | f115e911 | bellard | gen_outs(s, ot); |
6041 | 2e70f6ef | pbrook | if (use_icount) {
|
6042 | 2e70f6ef | pbrook | gen_jmp(s, s->pc - s->cs_base); |
6043 | 2e70f6ef | pbrook | } |
6044 | 2c0262af | bellard | } |
6045 | 2c0262af | bellard | break;
|
6046 | 2c0262af | bellard | |
6047 | 2c0262af | bellard | /************************/
|
6048 | 2c0262af | bellard | /* port I/O */
|
6049 | 0573fbfc | ths | |
6050 | 2c0262af | bellard | case 0xe4: |
6051 | 2c0262af | bellard | case 0xe5: |
6052 | f115e911 | bellard | if ((b & 1) == 0) |
6053 | f115e911 | bellard | ot = OT_BYTE; |
6054 | f115e911 | bellard | else
|
6055 | f115e911 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
6056 | f115e911 | bellard | val = ldub_code(s->pc++); |
6057 | f115e911 | bellard | gen_op_movl_T0_im(val); |
6058 | b8b6a50b | bellard | gen_check_io(s, ot, pc_start - s->cs_base, |
6059 | b8b6a50b | bellard | SVM_IOIO_TYPE_MASK | svm_is_rep(prefixes)); |
6060 | 2e70f6ef | pbrook | if (use_icount)
|
6061 | 2e70f6ef | pbrook | gen_io_start(); |
6062 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
6063 | a7812ae4 | pbrook | gen_helper_in_func(ot, cpu_T[1], cpu_tmp2_i32);
|
6064 | 57fec1fe | bellard | gen_op_mov_reg_T1(ot, R_EAX); |
6065 | 2e70f6ef | pbrook | if (use_icount) {
|
6066 | 2e70f6ef | pbrook | gen_io_end(); |
6067 | 2e70f6ef | pbrook | gen_jmp(s, s->pc - s->cs_base); |
6068 | 2e70f6ef | pbrook | } |
6069 | 2c0262af | bellard | break;
|
6070 | 2c0262af | bellard | case 0xe6: |
6071 | 2c0262af | bellard | case 0xe7: |
6072 | f115e911 | bellard | if ((b & 1) == 0) |
6073 | f115e911 | bellard | ot = OT_BYTE; |
6074 | f115e911 | bellard | else
|
6075 | f115e911 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
6076 | f115e911 | bellard | val = ldub_code(s->pc++); |
6077 | f115e911 | bellard | gen_op_movl_T0_im(val); |
6078 | b8b6a50b | bellard | gen_check_io(s, ot, pc_start - s->cs_base, |
6079 | b8b6a50b | bellard | svm_is_rep(prefixes)); |
6080 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 1, R_EAX);
|
6081 | b8b6a50b | bellard | |
6082 | 2e70f6ef | pbrook | if (use_icount)
|
6083 | 2e70f6ef | pbrook | gen_io_start(); |
6084 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
6085 | b6abf97d | bellard | tcg_gen_andi_i32(cpu_tmp2_i32, cpu_tmp2_i32, 0xffff);
|
6086 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp3_i32, cpu_T[1]);
|
6087 | a7812ae4 | pbrook | gen_helper_out_func(ot, cpu_tmp2_i32, cpu_tmp3_i32); |
6088 | 2e70f6ef | pbrook | if (use_icount) {
|
6089 | 2e70f6ef | pbrook | gen_io_end(); |
6090 | 2e70f6ef | pbrook | gen_jmp(s, s->pc - s->cs_base); |
6091 | 2e70f6ef | pbrook | } |
6092 | 2c0262af | bellard | break;
|
6093 | 2c0262af | bellard | case 0xec: |
6094 | 2c0262af | bellard | case 0xed: |
6095 | f115e911 | bellard | if ((b & 1) == 0) |
6096 | f115e911 | bellard | ot = OT_BYTE; |
6097 | f115e911 | bellard | else
|
6098 | f115e911 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
6099 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_WORD, 0, R_EDX);
|
6100 | 4f31916f | bellard | gen_op_andl_T0_ffff(); |
6101 | b8b6a50b | bellard | gen_check_io(s, ot, pc_start - s->cs_base, |
6102 | b8b6a50b | bellard | SVM_IOIO_TYPE_MASK | svm_is_rep(prefixes)); |
6103 | 2e70f6ef | pbrook | if (use_icount)
|
6104 | 2e70f6ef | pbrook | gen_io_start(); |
6105 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
6106 | a7812ae4 | pbrook | gen_helper_in_func(ot, cpu_T[1], cpu_tmp2_i32);
|
6107 | 57fec1fe | bellard | gen_op_mov_reg_T1(ot, R_EAX); |
6108 | 2e70f6ef | pbrook | if (use_icount) {
|
6109 | 2e70f6ef | pbrook | gen_io_end(); |
6110 | 2e70f6ef | pbrook | gen_jmp(s, s->pc - s->cs_base); |
6111 | 2e70f6ef | pbrook | } |
6112 | 2c0262af | bellard | break;
|
6113 | 2c0262af | bellard | case 0xee: |
6114 | 2c0262af | bellard | case 0xef: |
6115 | f115e911 | bellard | if ((b & 1) == 0) |
6116 | f115e911 | bellard | ot = OT_BYTE; |
6117 | f115e911 | bellard | else
|
6118 | f115e911 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
6119 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_WORD, 0, R_EDX);
|
6120 | 4f31916f | bellard | gen_op_andl_T0_ffff(); |
6121 | b8b6a50b | bellard | gen_check_io(s, ot, pc_start - s->cs_base, |
6122 | b8b6a50b | bellard | svm_is_rep(prefixes)); |
6123 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 1, R_EAX);
|
6124 | b8b6a50b | bellard | |
6125 | 2e70f6ef | pbrook | if (use_icount)
|
6126 | 2e70f6ef | pbrook | gen_io_start(); |
6127 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
6128 | b6abf97d | bellard | tcg_gen_andi_i32(cpu_tmp2_i32, cpu_tmp2_i32, 0xffff);
|
6129 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp3_i32, cpu_T[1]);
|
6130 | a7812ae4 | pbrook | gen_helper_out_func(ot, cpu_tmp2_i32, cpu_tmp3_i32); |
6131 | 2e70f6ef | pbrook | if (use_icount) {
|
6132 | 2e70f6ef | pbrook | gen_io_end(); |
6133 | 2e70f6ef | pbrook | gen_jmp(s, s->pc - s->cs_base); |
6134 | 2e70f6ef | pbrook | } |
6135 | 2c0262af | bellard | break;
|
6136 | 2c0262af | bellard | |
6137 | 2c0262af | bellard | /************************/
|
6138 | 2c0262af | bellard | /* control */
|
6139 | 2c0262af | bellard | case 0xc2: /* ret im */ |
6140 | 61382a50 | bellard | val = ldsw_code(s->pc); |
6141 | 2c0262af | bellard | s->pc += 2;
|
6142 | 2c0262af | bellard | gen_pop_T0(s); |
6143 | 8f091a59 | bellard | if (CODE64(s) && s->dflag)
|
6144 | 8f091a59 | bellard | s->dflag = 2;
|
6145 | 2c0262af | bellard | gen_stack_update(s, val + (2 << s->dflag));
|
6146 | 2c0262af | bellard | if (s->dflag == 0) |
6147 | 2c0262af | bellard | gen_op_andl_T0_ffff(); |
6148 | 2c0262af | bellard | gen_op_jmp_T0(); |
6149 | 2c0262af | bellard | gen_eob(s); |
6150 | 2c0262af | bellard | break;
|
6151 | 2c0262af | bellard | case 0xc3: /* ret */ |
6152 | 2c0262af | bellard | gen_pop_T0(s); |
6153 | 2c0262af | bellard | gen_pop_update(s); |
6154 | 2c0262af | bellard | if (s->dflag == 0) |
6155 | 2c0262af | bellard | gen_op_andl_T0_ffff(); |
6156 | 2c0262af | bellard | gen_op_jmp_T0(); |
6157 | 2c0262af | bellard | gen_eob(s); |
6158 | 2c0262af | bellard | break;
|
6159 | 2c0262af | bellard | case 0xca: /* lret im */ |
6160 | 61382a50 | bellard | val = ldsw_code(s->pc); |
6161 | 2c0262af | bellard | s->pc += 2;
|
6162 | 2c0262af | bellard | do_lret:
|
6163 | 2c0262af | bellard | if (s->pe && !s->vm86) {
|
6164 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6165 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6166 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
6167 | a7812ae4 | pbrook | gen_helper_lret_protected(tcg_const_i32(s->dflag), |
6168 | a7812ae4 | pbrook | tcg_const_i32(val)); |
6169 | 2c0262af | bellard | } else {
|
6170 | 2c0262af | bellard | gen_stack_A0(s); |
6171 | 2c0262af | bellard | /* pop offset */
|
6172 | 57fec1fe | bellard | gen_op_ld_T0_A0(1 + s->dflag + s->mem_index);
|
6173 | 2c0262af | bellard | if (s->dflag == 0) |
6174 | 2c0262af | bellard | gen_op_andl_T0_ffff(); |
6175 | 2c0262af | bellard | /* NOTE: keeping EIP updated is not a problem in case of
|
6176 | 2c0262af | bellard | exception */
|
6177 | 2c0262af | bellard | gen_op_jmp_T0(); |
6178 | 2c0262af | bellard | /* pop selector */
|
6179 | 2c0262af | bellard | gen_op_addl_A0_im(2 << s->dflag);
|
6180 | 57fec1fe | bellard | gen_op_ld_T0_A0(1 + s->dflag + s->mem_index);
|
6181 | 3bd7da9e | bellard | gen_op_movl_seg_T0_vm(R_CS); |
6182 | 2c0262af | bellard | /* add stack offset */
|
6183 | 2c0262af | bellard | gen_stack_update(s, val + (4 << s->dflag));
|
6184 | 2c0262af | bellard | } |
6185 | 2c0262af | bellard | gen_eob(s); |
6186 | 2c0262af | bellard | break;
|
6187 | 2c0262af | bellard | case 0xcb: /* lret */ |
6188 | 2c0262af | bellard | val = 0;
|
6189 | 2c0262af | bellard | goto do_lret;
|
6190 | 2c0262af | bellard | case 0xcf: /* iret */ |
6191 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, SVM_EXIT_IRET); |
6192 | 2c0262af | bellard | if (!s->pe) {
|
6193 | 2c0262af | bellard | /* real mode */
|
6194 | a7812ae4 | pbrook | gen_helper_iret_real(tcg_const_i32(s->dflag)); |
6195 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
6196 | f115e911 | bellard | } else if (s->vm86) { |
6197 | f115e911 | bellard | if (s->iopl != 3) { |
6198 | f115e911 | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6199 | f115e911 | bellard | } else {
|
6200 | a7812ae4 | pbrook | gen_helper_iret_real(tcg_const_i32(s->dflag)); |
6201 | f115e911 | bellard | s->cc_op = CC_OP_EFLAGS; |
6202 | f115e911 | bellard | } |
6203 | 2c0262af | bellard | } else {
|
6204 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6205 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6206 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
6207 | a7812ae4 | pbrook | gen_helper_iret_protected(tcg_const_i32(s->dflag), |
6208 | a7812ae4 | pbrook | tcg_const_i32(s->pc - s->cs_base)); |
6209 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
6210 | 2c0262af | bellard | } |
6211 | 2c0262af | bellard | gen_eob(s); |
6212 | 2c0262af | bellard | break;
|
6213 | 2c0262af | bellard | case 0xe8: /* call im */ |
6214 | 2c0262af | bellard | { |
6215 | 14ce26e7 | bellard | if (dflag)
|
6216 | 14ce26e7 | bellard | tval = (int32_t)insn_get(s, OT_LONG); |
6217 | 14ce26e7 | bellard | else
|
6218 | 14ce26e7 | bellard | tval = (int16_t)insn_get(s, OT_WORD); |
6219 | 2c0262af | bellard | next_eip = s->pc - s->cs_base; |
6220 | 14ce26e7 | bellard | tval += next_eip; |
6221 | 2c0262af | bellard | if (s->dflag == 0) |
6222 | 14ce26e7 | bellard | tval &= 0xffff;
|
6223 | 14ce26e7 | bellard | gen_movtl_T0_im(next_eip); |
6224 | 2c0262af | bellard | gen_push_T0(s); |
6225 | 14ce26e7 | bellard | gen_jmp(s, tval); |
6226 | 2c0262af | bellard | } |
6227 | 2c0262af | bellard | break;
|
6228 | 2c0262af | bellard | case 0x9a: /* lcall im */ |
6229 | 2c0262af | bellard | { |
6230 | 2c0262af | bellard | unsigned int selector, offset; |
6231 | 3b46e624 | ths | |
6232 | 14ce26e7 | bellard | if (CODE64(s))
|
6233 | 14ce26e7 | bellard | goto illegal_op;
|
6234 | 2c0262af | bellard | ot = dflag ? OT_LONG : OT_WORD; |
6235 | 2c0262af | bellard | offset = insn_get(s, ot); |
6236 | 2c0262af | bellard | selector = insn_get(s, OT_WORD); |
6237 | 3b46e624 | ths | |
6238 | 2c0262af | bellard | gen_op_movl_T0_im(selector); |
6239 | 14ce26e7 | bellard | gen_op_movl_T1_imu(offset); |
6240 | 2c0262af | bellard | } |
6241 | 2c0262af | bellard | goto do_lcall;
|
6242 | ecada8a2 | bellard | case 0xe9: /* jmp im */ |
6243 | 14ce26e7 | bellard | if (dflag)
|
6244 | 14ce26e7 | bellard | tval = (int32_t)insn_get(s, OT_LONG); |
6245 | 14ce26e7 | bellard | else
|
6246 | 14ce26e7 | bellard | tval = (int16_t)insn_get(s, OT_WORD); |
6247 | 14ce26e7 | bellard | tval += s->pc - s->cs_base; |
6248 | 2c0262af | bellard | if (s->dflag == 0) |
6249 | 14ce26e7 | bellard | tval &= 0xffff;
|
6250 | 32938e12 | aurel32 | else if(!CODE64(s)) |
6251 | 32938e12 | aurel32 | tval &= 0xffffffff;
|
6252 | 14ce26e7 | bellard | gen_jmp(s, tval); |
6253 | 2c0262af | bellard | break;
|
6254 | 2c0262af | bellard | case 0xea: /* ljmp im */ |
6255 | 2c0262af | bellard | { |
6256 | 2c0262af | bellard | unsigned int selector, offset; |
6257 | 2c0262af | bellard | |
6258 | 14ce26e7 | bellard | if (CODE64(s))
|
6259 | 14ce26e7 | bellard | goto illegal_op;
|
6260 | 2c0262af | bellard | ot = dflag ? OT_LONG : OT_WORD; |
6261 | 2c0262af | bellard | offset = insn_get(s, ot); |
6262 | 2c0262af | bellard | selector = insn_get(s, OT_WORD); |
6263 | 3b46e624 | ths | |
6264 | 2c0262af | bellard | gen_op_movl_T0_im(selector); |
6265 | 14ce26e7 | bellard | gen_op_movl_T1_imu(offset); |
6266 | 2c0262af | bellard | } |
6267 | 2c0262af | bellard | goto do_ljmp;
|
6268 | 2c0262af | bellard | case 0xeb: /* jmp Jb */ |
6269 | 14ce26e7 | bellard | tval = (int8_t)insn_get(s, OT_BYTE); |
6270 | 14ce26e7 | bellard | tval += s->pc - s->cs_base; |
6271 | 2c0262af | bellard | if (s->dflag == 0) |
6272 | 14ce26e7 | bellard | tval &= 0xffff;
|
6273 | 14ce26e7 | bellard | gen_jmp(s, tval); |
6274 | 2c0262af | bellard | break;
|
6275 | 2c0262af | bellard | case 0x70 ... 0x7f: /* jcc Jb */ |
6276 | 14ce26e7 | bellard | tval = (int8_t)insn_get(s, OT_BYTE); |
6277 | 2c0262af | bellard | goto do_jcc;
|
6278 | 2c0262af | bellard | case 0x180 ... 0x18f: /* jcc Jv */ |
6279 | 2c0262af | bellard | if (dflag) {
|
6280 | 14ce26e7 | bellard | tval = (int32_t)insn_get(s, OT_LONG); |
6281 | 2c0262af | bellard | } else {
|
6282 | 5fafdf24 | ths | tval = (int16_t)insn_get(s, OT_WORD); |
6283 | 2c0262af | bellard | } |
6284 | 2c0262af | bellard | do_jcc:
|
6285 | 2c0262af | bellard | next_eip = s->pc - s->cs_base; |
6286 | 14ce26e7 | bellard | tval += next_eip; |
6287 | 2c0262af | bellard | if (s->dflag == 0) |
6288 | 14ce26e7 | bellard | tval &= 0xffff;
|
6289 | 14ce26e7 | bellard | gen_jcc(s, b, tval, next_eip); |
6290 | 2c0262af | bellard | break;
|
6291 | 2c0262af | bellard | |
6292 | 2c0262af | bellard | case 0x190 ... 0x19f: /* setcc Gv */ |
6293 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
6294 | 2c0262af | bellard | gen_setcc(s, b); |
6295 | 2c0262af | bellard | gen_ldst_modrm(s, modrm, OT_BYTE, OR_TMP0, 1);
|
6296 | 2c0262af | bellard | break;
|
6297 | 2c0262af | bellard | case 0x140 ... 0x14f: /* cmov Gv, Ev */ |
6298 | 8e1c85e3 | bellard | { |
6299 | 8e1c85e3 | bellard | int l1;
|
6300 | 1e4840bf | bellard | TCGv t0; |
6301 | 1e4840bf | bellard | |
6302 | 8e1c85e3 | bellard | ot = dflag + OT_WORD; |
6303 | 8e1c85e3 | bellard | modrm = ldub_code(s->pc++); |
6304 | 8e1c85e3 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
6305 | 8e1c85e3 | bellard | mod = (modrm >> 6) & 3; |
6306 | a7812ae4 | pbrook | t0 = tcg_temp_local_new(); |
6307 | 8e1c85e3 | bellard | if (mod != 3) { |
6308 | 8e1c85e3 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
6309 | 1e4840bf | bellard | gen_op_ld_v(ot + s->mem_index, t0, cpu_A0); |
6310 | 8e1c85e3 | bellard | } else {
|
6311 | 8e1c85e3 | bellard | rm = (modrm & 7) | REX_B(s);
|
6312 | 1e4840bf | bellard | gen_op_mov_v_reg(ot, t0, rm); |
6313 | 8e1c85e3 | bellard | } |
6314 | 8e1c85e3 | bellard | #ifdef TARGET_X86_64
|
6315 | 8e1c85e3 | bellard | if (ot == OT_LONG) {
|
6316 | 8e1c85e3 | bellard | /* XXX: specific Intel behaviour ? */
|
6317 | 8e1c85e3 | bellard | l1 = gen_new_label(); |
6318 | 8e1c85e3 | bellard | gen_jcc1(s, s->cc_op, b ^ 1, l1);
|
6319 | 1e4840bf | bellard | tcg_gen_st32_tl(t0, cpu_env, offsetof(CPUState, regs[reg]) + REG_L_OFFSET); |
6320 | 8e1c85e3 | bellard | gen_set_label(l1); |
6321 | 8e1c85e3 | bellard | tcg_gen_movi_tl(cpu_tmp0, 0);
|
6322 | 8e1c85e3 | bellard | tcg_gen_st32_tl(cpu_tmp0, cpu_env, offsetof(CPUState, regs[reg]) + REG_LH_OFFSET); |
6323 | 8e1c85e3 | bellard | } else
|
6324 | 8e1c85e3 | bellard | #endif
|
6325 | 8e1c85e3 | bellard | { |
6326 | 8e1c85e3 | bellard | l1 = gen_new_label(); |
6327 | 8e1c85e3 | bellard | gen_jcc1(s, s->cc_op, b ^ 1, l1);
|
6328 | 1e4840bf | bellard | gen_op_mov_reg_v(ot, reg, t0); |
6329 | 8e1c85e3 | bellard | gen_set_label(l1); |
6330 | 8e1c85e3 | bellard | } |
6331 | 1e4840bf | bellard | tcg_temp_free(t0); |
6332 | 2c0262af | bellard | } |
6333 | 2c0262af | bellard | break;
|
6334 | 3b46e624 | ths | |
6335 | 2c0262af | bellard | /************************/
|
6336 | 2c0262af | bellard | /* flags */
|
6337 | 2c0262af | bellard | case 0x9c: /* pushf */ |
6338 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, SVM_EXIT_PUSHF); |
6339 | 2c0262af | bellard | if (s->vm86 && s->iopl != 3) { |
6340 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6341 | 2c0262af | bellard | } else {
|
6342 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6343 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6344 | a7812ae4 | pbrook | gen_helper_read_eflags(cpu_T[0]);
|
6345 | 2c0262af | bellard | gen_push_T0(s); |
6346 | 2c0262af | bellard | } |
6347 | 2c0262af | bellard | break;
|
6348 | 2c0262af | bellard | case 0x9d: /* popf */ |
6349 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, SVM_EXIT_POPF); |
6350 | 2c0262af | bellard | if (s->vm86 && s->iopl != 3) { |
6351 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6352 | 2c0262af | bellard | } else {
|
6353 | 2c0262af | bellard | gen_pop_T0(s); |
6354 | 2c0262af | bellard | if (s->cpl == 0) { |
6355 | 2c0262af | bellard | if (s->dflag) {
|
6356 | a7812ae4 | pbrook | gen_helper_write_eflags(cpu_T[0],
|
6357 | bd7a7b33 | bellard | tcg_const_i32((TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK | IOPL_MASK))); |
6358 | 2c0262af | bellard | } else {
|
6359 | a7812ae4 | pbrook | gen_helper_write_eflags(cpu_T[0],
|
6360 | bd7a7b33 | bellard | tcg_const_i32((TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK | IOPL_MASK) & 0xffff));
|
6361 | 2c0262af | bellard | } |
6362 | 2c0262af | bellard | } else {
|
6363 | 4136f33c | bellard | if (s->cpl <= s->iopl) {
|
6364 | 4136f33c | bellard | if (s->dflag) {
|
6365 | a7812ae4 | pbrook | gen_helper_write_eflags(cpu_T[0],
|
6366 | bd7a7b33 | bellard | tcg_const_i32((TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK))); |
6367 | 4136f33c | bellard | } else {
|
6368 | a7812ae4 | pbrook | gen_helper_write_eflags(cpu_T[0],
|
6369 | bd7a7b33 | bellard | tcg_const_i32((TF_MASK | AC_MASK | ID_MASK | NT_MASK | IF_MASK) & 0xffff));
|
6370 | 4136f33c | bellard | } |
6371 | 2c0262af | bellard | } else {
|
6372 | 4136f33c | bellard | if (s->dflag) {
|
6373 | a7812ae4 | pbrook | gen_helper_write_eflags(cpu_T[0],
|
6374 | bd7a7b33 | bellard | tcg_const_i32((TF_MASK | AC_MASK | ID_MASK | NT_MASK))); |
6375 | 4136f33c | bellard | } else {
|
6376 | a7812ae4 | pbrook | gen_helper_write_eflags(cpu_T[0],
|
6377 | bd7a7b33 | bellard | tcg_const_i32((TF_MASK | AC_MASK | ID_MASK | NT_MASK) & 0xffff));
|
6378 | 4136f33c | bellard | } |
6379 | 2c0262af | bellard | } |
6380 | 2c0262af | bellard | } |
6381 | 2c0262af | bellard | gen_pop_update(s); |
6382 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
6383 | 2c0262af | bellard | /* abort translation because TF flag may change */
|
6384 | 14ce26e7 | bellard | gen_jmp_im(s->pc - s->cs_base); |
6385 | 2c0262af | bellard | gen_eob(s); |
6386 | 2c0262af | bellard | } |
6387 | 2c0262af | bellard | break;
|
6388 | 2c0262af | bellard | case 0x9e: /* sahf */ |
6389 | 12e26b75 | bellard | if (CODE64(s) && !(s->cpuid_ext3_features & CPUID_EXT3_LAHF_LM))
|
6390 | 14ce26e7 | bellard | goto illegal_op;
|
6391 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_BYTE, 0, R_AH);
|
6392 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6393 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6394 | bd7a7b33 | bellard | gen_compute_eflags(cpu_cc_src); |
6395 | bd7a7b33 | bellard | tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, CC_O); |
6396 | bd7a7b33 | bellard | tcg_gen_andi_tl(cpu_T[0], cpu_T[0], CC_S | CC_Z | CC_A | CC_P | CC_C); |
6397 | bd7a7b33 | bellard | tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_T[0]);
|
6398 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
6399 | 2c0262af | bellard | break;
|
6400 | 2c0262af | bellard | case 0x9f: /* lahf */ |
6401 | 12e26b75 | bellard | if (CODE64(s) && !(s->cpuid_ext3_features & CPUID_EXT3_LAHF_LM))
|
6402 | 14ce26e7 | bellard | goto illegal_op;
|
6403 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6404 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6405 | bd7a7b33 | bellard | gen_compute_eflags(cpu_T[0]);
|
6406 | bd7a7b33 | bellard | /* Note: gen_compute_eflags() only gives the condition codes */
|
6407 | bd7a7b33 | bellard | tcg_gen_ori_tl(cpu_T[0], cpu_T[0], 0x02); |
6408 | 57fec1fe | bellard | gen_op_mov_reg_T0(OT_BYTE, R_AH); |
6409 | 2c0262af | bellard | break;
|
6410 | 2c0262af | bellard | case 0xf5: /* cmc */ |
6411 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6412 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6413 | bd7a7b33 | bellard | gen_compute_eflags(cpu_cc_src); |
6414 | bd7a7b33 | bellard | tcg_gen_xori_tl(cpu_cc_src, cpu_cc_src, CC_C); |
6415 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
6416 | 2c0262af | bellard | break;
|
6417 | 2c0262af | bellard | case 0xf8: /* clc */ |
6418 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6419 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6420 | bd7a7b33 | bellard | gen_compute_eflags(cpu_cc_src); |
6421 | bd7a7b33 | bellard | tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, ~CC_C); |
6422 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
6423 | 2c0262af | bellard | break;
|
6424 | 2c0262af | bellard | case 0xf9: /* stc */ |
6425 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6426 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6427 | bd7a7b33 | bellard | gen_compute_eflags(cpu_cc_src); |
6428 | bd7a7b33 | bellard | tcg_gen_ori_tl(cpu_cc_src, cpu_cc_src, CC_C); |
6429 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
6430 | 2c0262af | bellard | break;
|
6431 | 2c0262af | bellard | case 0xfc: /* cld */ |
6432 | b6abf97d | bellard | tcg_gen_movi_i32(cpu_tmp2_i32, 1);
|
6433 | b6abf97d | bellard | tcg_gen_st_i32(cpu_tmp2_i32, cpu_env, offsetof(CPUState, df)); |
6434 | 2c0262af | bellard | break;
|
6435 | 2c0262af | bellard | case 0xfd: /* std */ |
6436 | b6abf97d | bellard | tcg_gen_movi_i32(cpu_tmp2_i32, -1);
|
6437 | b6abf97d | bellard | tcg_gen_st_i32(cpu_tmp2_i32, cpu_env, offsetof(CPUState, df)); |
6438 | 2c0262af | bellard | break;
|
6439 | 2c0262af | bellard | |
6440 | 2c0262af | bellard | /************************/
|
6441 | 2c0262af | bellard | /* bit operations */
|
6442 | 2c0262af | bellard | case 0x1ba: /* bt/bts/btr/btc Gv, im */ |
6443 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
6444 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
6445 | 33698e5f | bellard | op = (modrm >> 3) & 7; |
6446 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
6447 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
6448 | 2c0262af | bellard | if (mod != 3) { |
6449 | 14ce26e7 | bellard | s->rip_offset = 1;
|
6450 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
6451 | 57fec1fe | bellard | gen_op_ld_T0_A0(ot + s->mem_index); |
6452 | 2c0262af | bellard | } else {
|
6453 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, rm);
|
6454 | 2c0262af | bellard | } |
6455 | 2c0262af | bellard | /* load shift */
|
6456 | 61382a50 | bellard | val = ldub_code(s->pc++); |
6457 | 2c0262af | bellard | gen_op_movl_T1_im(val); |
6458 | 2c0262af | bellard | if (op < 4) |
6459 | 2c0262af | bellard | goto illegal_op;
|
6460 | 2c0262af | bellard | op -= 4;
|
6461 | f484d386 | bellard | goto bt_op;
|
6462 | 2c0262af | bellard | case 0x1a3: /* bt Gv, Ev */ |
6463 | 2c0262af | bellard | op = 0;
|
6464 | 2c0262af | bellard | goto do_btx;
|
6465 | 2c0262af | bellard | case 0x1ab: /* bts */ |
6466 | 2c0262af | bellard | op = 1;
|
6467 | 2c0262af | bellard | goto do_btx;
|
6468 | 2c0262af | bellard | case 0x1b3: /* btr */ |
6469 | 2c0262af | bellard | op = 2;
|
6470 | 2c0262af | bellard | goto do_btx;
|
6471 | 2c0262af | bellard | case 0x1bb: /* btc */ |
6472 | 2c0262af | bellard | op = 3;
|
6473 | 2c0262af | bellard | do_btx:
|
6474 | 14ce26e7 | bellard | ot = dflag + OT_WORD; |
6475 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
6476 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
6477 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
6478 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
6479 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_LONG, 1, reg);
|
6480 | 2c0262af | bellard | if (mod != 3) { |
6481 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
6482 | 2c0262af | bellard | /* specific case: we need to add a displacement */
|
6483 | f484d386 | bellard | gen_exts(ot, cpu_T[1]);
|
6484 | f484d386 | bellard | tcg_gen_sari_tl(cpu_tmp0, cpu_T[1], 3 + ot); |
6485 | f484d386 | bellard | tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, ot); |
6486 | f484d386 | bellard | tcg_gen_add_tl(cpu_A0, cpu_A0, cpu_tmp0); |
6487 | 57fec1fe | bellard | gen_op_ld_T0_A0(ot + s->mem_index); |
6488 | 2c0262af | bellard | } else {
|
6489 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, rm);
|
6490 | 2c0262af | bellard | } |
6491 | f484d386 | bellard | bt_op:
|
6492 | f484d386 | bellard | tcg_gen_andi_tl(cpu_T[1], cpu_T[1], (1 << (3 + ot)) - 1); |
6493 | f484d386 | bellard | switch(op) {
|
6494 | f484d386 | bellard | case 0: |
6495 | f484d386 | bellard | tcg_gen_shr_tl(cpu_cc_src, cpu_T[0], cpu_T[1]); |
6496 | f484d386 | bellard | tcg_gen_movi_tl(cpu_cc_dst, 0);
|
6497 | f484d386 | bellard | break;
|
6498 | f484d386 | bellard | case 1: |
6499 | f484d386 | bellard | tcg_gen_shr_tl(cpu_tmp4, cpu_T[0], cpu_T[1]); |
6500 | f484d386 | bellard | tcg_gen_movi_tl(cpu_tmp0, 1);
|
6501 | f484d386 | bellard | tcg_gen_shl_tl(cpu_tmp0, cpu_tmp0, cpu_T[1]);
|
6502 | f484d386 | bellard | tcg_gen_or_tl(cpu_T[0], cpu_T[0], cpu_tmp0); |
6503 | f484d386 | bellard | break;
|
6504 | f484d386 | bellard | case 2: |
6505 | f484d386 | bellard | tcg_gen_shr_tl(cpu_tmp4, cpu_T[0], cpu_T[1]); |
6506 | f484d386 | bellard | tcg_gen_movi_tl(cpu_tmp0, 1);
|
6507 | f484d386 | bellard | tcg_gen_shl_tl(cpu_tmp0, cpu_tmp0, cpu_T[1]);
|
6508 | f484d386 | bellard | tcg_gen_not_tl(cpu_tmp0, cpu_tmp0); |
6509 | f484d386 | bellard | tcg_gen_and_tl(cpu_T[0], cpu_T[0], cpu_tmp0); |
6510 | f484d386 | bellard | break;
|
6511 | f484d386 | bellard | default:
|
6512 | f484d386 | bellard | case 3: |
6513 | f484d386 | bellard | tcg_gen_shr_tl(cpu_tmp4, cpu_T[0], cpu_T[1]); |
6514 | f484d386 | bellard | tcg_gen_movi_tl(cpu_tmp0, 1);
|
6515 | f484d386 | bellard | tcg_gen_shl_tl(cpu_tmp0, cpu_tmp0, cpu_T[1]);
|
6516 | f484d386 | bellard | tcg_gen_xor_tl(cpu_T[0], cpu_T[0], cpu_tmp0); |
6517 | f484d386 | bellard | break;
|
6518 | f484d386 | bellard | } |
6519 | 2c0262af | bellard | s->cc_op = CC_OP_SARB + ot; |
6520 | 2c0262af | bellard | if (op != 0) { |
6521 | 2c0262af | bellard | if (mod != 3) |
6522 | 57fec1fe | bellard | gen_op_st_T0_A0(ot + s->mem_index); |
6523 | 2c0262af | bellard | else
|
6524 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, rm); |
6525 | f484d386 | bellard | tcg_gen_mov_tl(cpu_cc_src, cpu_tmp4); |
6526 | f484d386 | bellard | tcg_gen_movi_tl(cpu_cc_dst, 0);
|
6527 | 2c0262af | bellard | } |
6528 | 2c0262af | bellard | break;
|
6529 | 2c0262af | bellard | case 0x1bc: /* bsf */ |
6530 | 2c0262af | bellard | case 0x1bd: /* bsr */ |
6531 | 6191b059 | bellard | { |
6532 | 6191b059 | bellard | int label1;
|
6533 | 1e4840bf | bellard | TCGv t0; |
6534 | 1e4840bf | bellard | |
6535 | 6191b059 | bellard | ot = dflag + OT_WORD; |
6536 | 6191b059 | bellard | modrm = ldub_code(s->pc++); |
6537 | 6191b059 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
6538 | 6191b059 | bellard | gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
|
6539 | 6191b059 | bellard | gen_extu(ot, cpu_T[0]);
|
6540 | 6191b059 | bellard | label1 = gen_new_label(); |
6541 | 6191b059 | bellard | tcg_gen_movi_tl(cpu_cc_dst, 0);
|
6542 | a7812ae4 | pbrook | t0 = tcg_temp_local_new(); |
6543 | 1e4840bf | bellard | tcg_gen_mov_tl(t0, cpu_T[0]);
|
6544 | 1e4840bf | bellard | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, label1);
|
6545 | 6191b059 | bellard | if (b & 1) { |
6546 | a7812ae4 | pbrook | gen_helper_bsr(cpu_T[0], t0);
|
6547 | 6191b059 | bellard | } else {
|
6548 | a7812ae4 | pbrook | gen_helper_bsf(cpu_T[0], t0);
|
6549 | 6191b059 | bellard | } |
6550 | 6191b059 | bellard | gen_op_mov_reg_T0(ot, reg); |
6551 | 6191b059 | bellard | tcg_gen_movi_tl(cpu_cc_dst, 1);
|
6552 | 6191b059 | bellard | gen_set_label(label1); |
6553 | 6191b059 | bellard | tcg_gen_discard_tl(cpu_cc_src); |
6554 | 6191b059 | bellard | s->cc_op = CC_OP_LOGICB + ot; |
6555 | 1e4840bf | bellard | tcg_temp_free(t0); |
6556 | 6191b059 | bellard | } |
6557 | 2c0262af | bellard | break;
|
6558 | 2c0262af | bellard | /************************/
|
6559 | 2c0262af | bellard | /* bcd */
|
6560 | 2c0262af | bellard | case 0x27: /* daa */ |
6561 | 14ce26e7 | bellard | if (CODE64(s))
|
6562 | 14ce26e7 | bellard | goto illegal_op;
|
6563 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6564 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6565 | a7812ae4 | pbrook | gen_helper_daa(); |
6566 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
6567 | 2c0262af | bellard | break;
|
6568 | 2c0262af | bellard | case 0x2f: /* das */ |
6569 | 14ce26e7 | bellard | if (CODE64(s))
|
6570 | 14ce26e7 | bellard | goto illegal_op;
|
6571 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6572 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6573 | a7812ae4 | pbrook | gen_helper_das(); |
6574 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
6575 | 2c0262af | bellard | break;
|
6576 | 2c0262af | bellard | case 0x37: /* aaa */ |
6577 | 14ce26e7 | bellard | if (CODE64(s))
|
6578 | 14ce26e7 | bellard | goto illegal_op;
|
6579 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6580 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6581 | a7812ae4 | pbrook | gen_helper_aaa(); |
6582 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
6583 | 2c0262af | bellard | break;
|
6584 | 2c0262af | bellard | case 0x3f: /* aas */ |
6585 | 14ce26e7 | bellard | if (CODE64(s))
|
6586 | 14ce26e7 | bellard | goto illegal_op;
|
6587 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6588 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6589 | a7812ae4 | pbrook | gen_helper_aas(); |
6590 | 2c0262af | bellard | s->cc_op = CC_OP_EFLAGS; |
6591 | 2c0262af | bellard | break;
|
6592 | 2c0262af | bellard | case 0xd4: /* aam */ |
6593 | 14ce26e7 | bellard | if (CODE64(s))
|
6594 | 14ce26e7 | bellard | goto illegal_op;
|
6595 | 61382a50 | bellard | val = ldub_code(s->pc++); |
6596 | b6d7c3db | ths | if (val == 0) { |
6597 | b6d7c3db | ths | gen_exception(s, EXCP00_DIVZ, pc_start - s->cs_base); |
6598 | b6d7c3db | ths | } else {
|
6599 | a7812ae4 | pbrook | gen_helper_aam(tcg_const_i32(val)); |
6600 | b6d7c3db | ths | s->cc_op = CC_OP_LOGICB; |
6601 | b6d7c3db | ths | } |
6602 | 2c0262af | bellard | break;
|
6603 | 2c0262af | bellard | case 0xd5: /* aad */ |
6604 | 14ce26e7 | bellard | if (CODE64(s))
|
6605 | 14ce26e7 | bellard | goto illegal_op;
|
6606 | 61382a50 | bellard | val = ldub_code(s->pc++); |
6607 | a7812ae4 | pbrook | gen_helper_aad(tcg_const_i32(val)); |
6608 | 2c0262af | bellard | s->cc_op = CC_OP_LOGICB; |
6609 | 2c0262af | bellard | break;
|
6610 | 2c0262af | bellard | /************************/
|
6611 | 2c0262af | bellard | /* misc */
|
6612 | 2c0262af | bellard | case 0x90: /* nop */ |
6613 | 14ce26e7 | bellard | /* XXX: xchg + rex handling */
|
6614 | ab1f142b | bellard | /* XXX: correct lock test for all insn */
|
6615 | ab1f142b | bellard | if (prefixes & PREFIX_LOCK)
|
6616 | ab1f142b | bellard | goto illegal_op;
|
6617 | 0573fbfc | ths | if (prefixes & PREFIX_REPZ) {
|
6618 | 0573fbfc | ths | gen_svm_check_intercept(s, pc_start, SVM_EXIT_PAUSE); |
6619 | 0573fbfc | ths | } |
6620 | 2c0262af | bellard | break;
|
6621 | 2c0262af | bellard | case 0x9b: /* fwait */ |
6622 | 5fafdf24 | ths | if ((s->flags & (HF_MP_MASK | HF_TS_MASK)) ==
|
6623 | 7eee2a50 | bellard | (HF_MP_MASK | HF_TS_MASK)) { |
6624 | 7eee2a50 | bellard | gen_exception(s, EXCP07_PREX, pc_start - s->cs_base); |
6625 | 2ee73ac3 | bellard | } else {
|
6626 | 2ee73ac3 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6627 | 2ee73ac3 | bellard | gen_op_set_cc_op(s->cc_op); |
6628 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
6629 | a7812ae4 | pbrook | gen_helper_fwait(); |
6630 | 7eee2a50 | bellard | } |
6631 | 2c0262af | bellard | break;
|
6632 | 2c0262af | bellard | case 0xcc: /* int3 */ |
6633 | 2c0262af | bellard | gen_interrupt(s, EXCP03_INT3, pc_start - s->cs_base, s->pc - s->cs_base); |
6634 | 2c0262af | bellard | break;
|
6635 | 2c0262af | bellard | case 0xcd: /* int N */ |
6636 | 61382a50 | bellard | val = ldub_code(s->pc++); |
6637 | f115e911 | bellard | if (s->vm86 && s->iopl != 3) { |
6638 | 5fafdf24 | ths | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6639 | f115e911 | bellard | } else {
|
6640 | f115e911 | bellard | gen_interrupt(s, val, pc_start - s->cs_base, s->pc - s->cs_base); |
6641 | f115e911 | bellard | } |
6642 | 2c0262af | bellard | break;
|
6643 | 2c0262af | bellard | case 0xce: /* into */ |
6644 | 14ce26e7 | bellard | if (CODE64(s))
|
6645 | 14ce26e7 | bellard | goto illegal_op;
|
6646 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6647 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6648 | a8ede8ba | bellard | gen_jmp_im(pc_start - s->cs_base); |
6649 | a7812ae4 | pbrook | gen_helper_into(tcg_const_i32(s->pc - pc_start)); |
6650 | 2c0262af | bellard | break;
|
6651 | 0b97134b | aurel32 | #ifdef WANT_ICEBP
|
6652 | 2c0262af | bellard | case 0xf1: /* icebp (undocumented, exits to external debugger) */ |
6653 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, SVM_EXIT_ICEBP); |
6654 | aba9d61e | bellard | #if 1 |
6655 | 2c0262af | bellard | gen_debug(s, pc_start - s->cs_base); |
6656 | aba9d61e | bellard | #else
|
6657 | aba9d61e | bellard | /* start debug */
|
6658 | aba9d61e | bellard | tb_flush(cpu_single_env); |
6659 | aba9d61e | bellard | cpu_set_log(CPU_LOG_INT | CPU_LOG_TB_IN_ASM); |
6660 | aba9d61e | bellard | #endif
|
6661 | 2c0262af | bellard | break;
|
6662 | 0b97134b | aurel32 | #endif
|
6663 | 2c0262af | bellard | case 0xfa: /* cli */ |
6664 | 2c0262af | bellard | if (!s->vm86) {
|
6665 | 2c0262af | bellard | if (s->cpl <= s->iopl) {
|
6666 | a7812ae4 | pbrook | gen_helper_cli(); |
6667 | 2c0262af | bellard | } else {
|
6668 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6669 | 2c0262af | bellard | } |
6670 | 2c0262af | bellard | } else {
|
6671 | 2c0262af | bellard | if (s->iopl == 3) { |
6672 | a7812ae4 | pbrook | gen_helper_cli(); |
6673 | 2c0262af | bellard | } else {
|
6674 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6675 | 2c0262af | bellard | } |
6676 | 2c0262af | bellard | } |
6677 | 2c0262af | bellard | break;
|
6678 | 2c0262af | bellard | case 0xfb: /* sti */ |
6679 | 2c0262af | bellard | if (!s->vm86) {
|
6680 | 2c0262af | bellard | if (s->cpl <= s->iopl) {
|
6681 | 2c0262af | bellard | gen_sti:
|
6682 | a7812ae4 | pbrook | gen_helper_sti(); |
6683 | 2c0262af | bellard | /* interruptions are enabled only the first insn after sti */
|
6684 | a2cc3b24 | bellard | /* If several instructions disable interrupts, only the
|
6685 | a2cc3b24 | bellard | _first_ does it */
|
6686 | a2cc3b24 | bellard | if (!(s->tb->flags & HF_INHIBIT_IRQ_MASK))
|
6687 | a7812ae4 | pbrook | gen_helper_set_inhibit_irq(); |
6688 | 2c0262af | bellard | /* give a chance to handle pending irqs */
|
6689 | 14ce26e7 | bellard | gen_jmp_im(s->pc - s->cs_base); |
6690 | 2c0262af | bellard | gen_eob(s); |
6691 | 2c0262af | bellard | } else {
|
6692 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6693 | 2c0262af | bellard | } |
6694 | 2c0262af | bellard | } else {
|
6695 | 2c0262af | bellard | if (s->iopl == 3) { |
6696 | 2c0262af | bellard | goto gen_sti;
|
6697 | 2c0262af | bellard | } else {
|
6698 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6699 | 2c0262af | bellard | } |
6700 | 2c0262af | bellard | } |
6701 | 2c0262af | bellard | break;
|
6702 | 2c0262af | bellard | case 0x62: /* bound */ |
6703 | 14ce26e7 | bellard | if (CODE64(s))
|
6704 | 14ce26e7 | bellard | goto illegal_op;
|
6705 | 2c0262af | bellard | ot = dflag ? OT_LONG : OT_WORD; |
6706 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
6707 | 2c0262af | bellard | reg = (modrm >> 3) & 7; |
6708 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
6709 | 2c0262af | bellard | if (mod == 3) |
6710 | 2c0262af | bellard | goto illegal_op;
|
6711 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, reg);
|
6712 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
6713 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
6714 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
6715 | 2c0262af | bellard | if (ot == OT_WORD)
|
6716 | a7812ae4 | pbrook | gen_helper_boundw(cpu_A0, cpu_tmp2_i32); |
6717 | 2c0262af | bellard | else
|
6718 | a7812ae4 | pbrook | gen_helper_boundl(cpu_A0, cpu_tmp2_i32); |
6719 | 2c0262af | bellard | break;
|
6720 | 2c0262af | bellard | case 0x1c8 ... 0x1cf: /* bswap reg */ |
6721 | 14ce26e7 | bellard | reg = (b & 7) | REX_B(s);
|
6722 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
6723 | 14ce26e7 | bellard | if (dflag == 2) { |
6724 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_QUAD, 0, reg);
|
6725 | 66896cb8 | aurel32 | tcg_gen_bswap64_i64(cpu_T[0], cpu_T[0]); |
6726 | 57fec1fe | bellard | gen_op_mov_reg_T0(OT_QUAD, reg); |
6727 | 5fafdf24 | ths | } else
|
6728 | 8777643e | aurel32 | #endif
|
6729 | 57fec1fe | bellard | { |
6730 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_LONG, 0, reg);
|
6731 | 8777643e | aurel32 | tcg_gen_ext32u_tl(cpu_T[0], cpu_T[0]); |
6732 | 8777643e | aurel32 | tcg_gen_bswap32_tl(cpu_T[0], cpu_T[0]); |
6733 | 57fec1fe | bellard | gen_op_mov_reg_T0(OT_LONG, reg); |
6734 | 14ce26e7 | bellard | } |
6735 | 2c0262af | bellard | break;
|
6736 | 2c0262af | bellard | case 0xd6: /* salc */ |
6737 | 14ce26e7 | bellard | if (CODE64(s))
|
6738 | 14ce26e7 | bellard | goto illegal_op;
|
6739 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6740 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6741 | bd7a7b33 | bellard | gen_compute_eflags_c(cpu_T[0]);
|
6742 | bd7a7b33 | bellard | tcg_gen_neg_tl(cpu_T[0], cpu_T[0]); |
6743 | bd7a7b33 | bellard | gen_op_mov_reg_T0(OT_BYTE, R_EAX); |
6744 | 2c0262af | bellard | break;
|
6745 | 2c0262af | bellard | case 0xe0: /* loopnz */ |
6746 | 2c0262af | bellard | case 0xe1: /* loopz */ |
6747 | 2c0262af | bellard | case 0xe2: /* loop */ |
6748 | 2c0262af | bellard | case 0xe3: /* jecxz */ |
6749 | 14ce26e7 | bellard | { |
6750 | 6e0d8677 | bellard | int l1, l2, l3;
|
6751 | 14ce26e7 | bellard | |
6752 | 14ce26e7 | bellard | tval = (int8_t)insn_get(s, OT_BYTE); |
6753 | 14ce26e7 | bellard | next_eip = s->pc - s->cs_base; |
6754 | 14ce26e7 | bellard | tval += next_eip; |
6755 | 14ce26e7 | bellard | if (s->dflag == 0) |
6756 | 14ce26e7 | bellard | tval &= 0xffff;
|
6757 | 3b46e624 | ths | |
6758 | 14ce26e7 | bellard | l1 = gen_new_label(); |
6759 | 14ce26e7 | bellard | l2 = gen_new_label(); |
6760 | 6e0d8677 | bellard | l3 = gen_new_label(); |
6761 | 14ce26e7 | bellard | b &= 3;
|
6762 | 6e0d8677 | bellard | switch(b) {
|
6763 | 6e0d8677 | bellard | case 0: /* loopnz */ |
6764 | 6e0d8677 | bellard | case 1: /* loopz */ |
6765 | 6e0d8677 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6766 | 6e0d8677 | bellard | gen_op_set_cc_op(s->cc_op); |
6767 | 6e0d8677 | bellard | gen_op_add_reg_im(s->aflag, R_ECX, -1);
|
6768 | 6e0d8677 | bellard | gen_op_jz_ecx(s->aflag, l3); |
6769 | 6e0d8677 | bellard | gen_compute_eflags(cpu_tmp0); |
6770 | 6e0d8677 | bellard | tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, CC_Z); |
6771 | 6e0d8677 | bellard | if (b == 0) { |
6772 | cb63669a | pbrook | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, l1);
|
6773 | 6e0d8677 | bellard | } else {
|
6774 | cb63669a | pbrook | tcg_gen_brcondi_tl(TCG_COND_NE, cpu_tmp0, 0, l1);
|
6775 | 6e0d8677 | bellard | } |
6776 | 6e0d8677 | bellard | break;
|
6777 | 6e0d8677 | bellard | case 2: /* loop */ |
6778 | 6e0d8677 | bellard | gen_op_add_reg_im(s->aflag, R_ECX, -1);
|
6779 | 6e0d8677 | bellard | gen_op_jnz_ecx(s->aflag, l1); |
6780 | 6e0d8677 | bellard | break;
|
6781 | 6e0d8677 | bellard | default:
|
6782 | 6e0d8677 | bellard | case 3: /* jcxz */ |
6783 | 6e0d8677 | bellard | gen_op_jz_ecx(s->aflag, l1); |
6784 | 6e0d8677 | bellard | break;
|
6785 | 14ce26e7 | bellard | } |
6786 | 14ce26e7 | bellard | |
6787 | 6e0d8677 | bellard | gen_set_label(l3); |
6788 | 14ce26e7 | bellard | gen_jmp_im(next_eip); |
6789 | 8e1c85e3 | bellard | tcg_gen_br(l2); |
6790 | 6e0d8677 | bellard | |
6791 | 14ce26e7 | bellard | gen_set_label(l1); |
6792 | 14ce26e7 | bellard | gen_jmp_im(tval); |
6793 | 14ce26e7 | bellard | gen_set_label(l2); |
6794 | 14ce26e7 | bellard | gen_eob(s); |
6795 | 14ce26e7 | bellard | } |
6796 | 2c0262af | bellard | break;
|
6797 | 2c0262af | bellard | case 0x130: /* wrmsr */ |
6798 | 2c0262af | bellard | case 0x132: /* rdmsr */ |
6799 | 2c0262af | bellard | if (s->cpl != 0) { |
6800 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6801 | 2c0262af | bellard | } else {
|
6802 | 872929aa | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6803 | 872929aa | bellard | gen_op_set_cc_op(s->cc_op); |
6804 | 872929aa | bellard | gen_jmp_im(pc_start - s->cs_base); |
6805 | 0573fbfc | ths | if (b & 2) { |
6806 | a7812ae4 | pbrook | gen_helper_rdmsr(); |
6807 | 0573fbfc | ths | } else {
|
6808 | a7812ae4 | pbrook | gen_helper_wrmsr(); |
6809 | 0573fbfc | ths | } |
6810 | 2c0262af | bellard | } |
6811 | 2c0262af | bellard | break;
|
6812 | 2c0262af | bellard | case 0x131: /* rdtsc */ |
6813 | 872929aa | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6814 | 872929aa | bellard | gen_op_set_cc_op(s->cc_op); |
6815 | ecada8a2 | bellard | gen_jmp_im(pc_start - s->cs_base); |
6816 | efade670 | pbrook | if (use_icount)
|
6817 | efade670 | pbrook | gen_io_start(); |
6818 | a7812ae4 | pbrook | gen_helper_rdtsc(); |
6819 | efade670 | pbrook | if (use_icount) {
|
6820 | efade670 | pbrook | gen_io_end(); |
6821 | efade670 | pbrook | gen_jmp(s, s->pc - s->cs_base); |
6822 | efade670 | pbrook | } |
6823 | 2c0262af | bellard | break;
|
6824 | df01e0fc | balrog | case 0x133: /* rdpmc */ |
6825 | 872929aa | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6826 | 872929aa | bellard | gen_op_set_cc_op(s->cc_op); |
6827 | df01e0fc | balrog | gen_jmp_im(pc_start - s->cs_base); |
6828 | a7812ae4 | pbrook | gen_helper_rdpmc(); |
6829 | df01e0fc | balrog | break;
|
6830 | 023fe10d | bellard | case 0x134: /* sysenter */ |
6831 | 2436b61a | balrog | /* For Intel SYSENTER is valid on 64-bit */
|
6832 | 2436b61a | balrog | if (CODE64(s) && cpu_single_env->cpuid_vendor1 != CPUID_VENDOR_INTEL_1)
|
6833 | 14ce26e7 | bellard | goto illegal_op;
|
6834 | 023fe10d | bellard | if (!s->pe) {
|
6835 | 023fe10d | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6836 | 023fe10d | bellard | } else {
|
6837 | 023fe10d | bellard | if (s->cc_op != CC_OP_DYNAMIC) {
|
6838 | 023fe10d | bellard | gen_op_set_cc_op(s->cc_op); |
6839 | 023fe10d | bellard | s->cc_op = CC_OP_DYNAMIC; |
6840 | 023fe10d | bellard | } |
6841 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
6842 | a7812ae4 | pbrook | gen_helper_sysenter(); |
6843 | 023fe10d | bellard | gen_eob(s); |
6844 | 023fe10d | bellard | } |
6845 | 023fe10d | bellard | break;
|
6846 | 023fe10d | bellard | case 0x135: /* sysexit */ |
6847 | 2436b61a | balrog | /* For Intel SYSEXIT is valid on 64-bit */
|
6848 | 2436b61a | balrog | if (CODE64(s) && cpu_single_env->cpuid_vendor1 != CPUID_VENDOR_INTEL_1)
|
6849 | 14ce26e7 | bellard | goto illegal_op;
|
6850 | 023fe10d | bellard | if (!s->pe) {
|
6851 | 023fe10d | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6852 | 023fe10d | bellard | } else {
|
6853 | 023fe10d | bellard | if (s->cc_op != CC_OP_DYNAMIC) {
|
6854 | 023fe10d | bellard | gen_op_set_cc_op(s->cc_op); |
6855 | 023fe10d | bellard | s->cc_op = CC_OP_DYNAMIC; |
6856 | 023fe10d | bellard | } |
6857 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
6858 | a7812ae4 | pbrook | gen_helper_sysexit(tcg_const_i32(dflag)); |
6859 | 023fe10d | bellard | gen_eob(s); |
6860 | 023fe10d | bellard | } |
6861 | 023fe10d | bellard | break;
|
6862 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
6863 | 14ce26e7 | bellard | case 0x105: /* syscall */ |
6864 | 14ce26e7 | bellard | /* XXX: is it usable in real mode ? */
|
6865 | 14ce26e7 | bellard | if (s->cc_op != CC_OP_DYNAMIC) {
|
6866 | 14ce26e7 | bellard | gen_op_set_cc_op(s->cc_op); |
6867 | 14ce26e7 | bellard | s->cc_op = CC_OP_DYNAMIC; |
6868 | 14ce26e7 | bellard | } |
6869 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
6870 | a7812ae4 | pbrook | gen_helper_syscall(tcg_const_i32(s->pc - pc_start)); |
6871 | 14ce26e7 | bellard | gen_eob(s); |
6872 | 14ce26e7 | bellard | break;
|
6873 | 14ce26e7 | bellard | case 0x107: /* sysret */ |
6874 | 14ce26e7 | bellard | if (!s->pe) {
|
6875 | 14ce26e7 | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6876 | 14ce26e7 | bellard | } else {
|
6877 | 14ce26e7 | bellard | if (s->cc_op != CC_OP_DYNAMIC) {
|
6878 | 14ce26e7 | bellard | gen_op_set_cc_op(s->cc_op); |
6879 | 14ce26e7 | bellard | s->cc_op = CC_OP_DYNAMIC; |
6880 | 14ce26e7 | bellard | } |
6881 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
6882 | a7812ae4 | pbrook | gen_helper_sysret(tcg_const_i32(s->dflag)); |
6883 | aba9d61e | bellard | /* condition codes are modified only in long mode */
|
6884 | aba9d61e | bellard | if (s->lma)
|
6885 | aba9d61e | bellard | s->cc_op = CC_OP_EFLAGS; |
6886 | 14ce26e7 | bellard | gen_eob(s); |
6887 | 14ce26e7 | bellard | } |
6888 | 14ce26e7 | bellard | break;
|
6889 | 14ce26e7 | bellard | #endif
|
6890 | 2c0262af | bellard | case 0x1a2: /* cpuid */ |
6891 | 9575cb94 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6892 | 9575cb94 | bellard | gen_op_set_cc_op(s->cc_op); |
6893 | 9575cb94 | bellard | gen_jmp_im(pc_start - s->cs_base); |
6894 | a7812ae4 | pbrook | gen_helper_cpuid(); |
6895 | 2c0262af | bellard | break;
|
6896 | 2c0262af | bellard | case 0xf4: /* hlt */ |
6897 | 2c0262af | bellard | if (s->cpl != 0) { |
6898 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6899 | 2c0262af | bellard | } else {
|
6900 | 2c0262af | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6901 | 2c0262af | bellard | gen_op_set_cc_op(s->cc_op); |
6902 | 94451178 | bellard | gen_jmp_im(pc_start - s->cs_base); |
6903 | a7812ae4 | pbrook | gen_helper_hlt(tcg_const_i32(s->pc - pc_start)); |
6904 | 2c0262af | bellard | s->is_jmp = 3;
|
6905 | 2c0262af | bellard | } |
6906 | 2c0262af | bellard | break;
|
6907 | 2c0262af | bellard | case 0x100: |
6908 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
6909 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
6910 | 2c0262af | bellard | op = (modrm >> 3) & 7; |
6911 | 2c0262af | bellard | switch(op) {
|
6912 | 2c0262af | bellard | case 0: /* sldt */ |
6913 | f115e911 | bellard | if (!s->pe || s->vm86)
|
6914 | f115e911 | bellard | goto illegal_op;
|
6915 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, SVM_EXIT_LDTR_READ); |
6916 | 651ba608 | bellard | tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,ldt.selector));
|
6917 | 2c0262af | bellard | ot = OT_WORD; |
6918 | 2c0262af | bellard | if (mod == 3) |
6919 | 2c0262af | bellard | ot += s->dflag; |
6920 | 2c0262af | bellard | gen_ldst_modrm(s, modrm, ot, OR_TMP0, 1);
|
6921 | 2c0262af | bellard | break;
|
6922 | 2c0262af | bellard | case 2: /* lldt */ |
6923 | f115e911 | bellard | if (!s->pe || s->vm86)
|
6924 | f115e911 | bellard | goto illegal_op;
|
6925 | 2c0262af | bellard | if (s->cpl != 0) { |
6926 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6927 | 2c0262af | bellard | } else {
|
6928 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, SVM_EXIT_LDTR_WRITE); |
6929 | 2c0262af | bellard | gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
6930 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
6931 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
6932 | a7812ae4 | pbrook | gen_helper_lldt(cpu_tmp2_i32); |
6933 | 2c0262af | bellard | } |
6934 | 2c0262af | bellard | break;
|
6935 | 2c0262af | bellard | case 1: /* str */ |
6936 | f115e911 | bellard | if (!s->pe || s->vm86)
|
6937 | f115e911 | bellard | goto illegal_op;
|
6938 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, SVM_EXIT_TR_READ); |
6939 | 651ba608 | bellard | tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,tr.selector));
|
6940 | 2c0262af | bellard | ot = OT_WORD; |
6941 | 2c0262af | bellard | if (mod == 3) |
6942 | 2c0262af | bellard | ot += s->dflag; |
6943 | 2c0262af | bellard | gen_ldst_modrm(s, modrm, ot, OR_TMP0, 1);
|
6944 | 2c0262af | bellard | break;
|
6945 | 2c0262af | bellard | case 3: /* ltr */ |
6946 | f115e911 | bellard | if (!s->pe || s->vm86)
|
6947 | f115e911 | bellard | goto illegal_op;
|
6948 | 2c0262af | bellard | if (s->cpl != 0) { |
6949 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
6950 | 2c0262af | bellard | } else {
|
6951 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, SVM_EXIT_TR_WRITE); |
6952 | 2c0262af | bellard | gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
6953 | 14ce26e7 | bellard | gen_jmp_im(pc_start - s->cs_base); |
6954 | b6abf97d | bellard | tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]);
|
6955 | a7812ae4 | pbrook | gen_helper_ltr(cpu_tmp2_i32); |
6956 | 2c0262af | bellard | } |
6957 | 2c0262af | bellard | break;
|
6958 | 2c0262af | bellard | case 4: /* verr */ |
6959 | 2c0262af | bellard | case 5: /* verw */ |
6960 | f115e911 | bellard | if (!s->pe || s->vm86)
|
6961 | f115e911 | bellard | goto illegal_op;
|
6962 | f115e911 | bellard | gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
6963 | f115e911 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
6964 | f115e911 | bellard | gen_op_set_cc_op(s->cc_op); |
6965 | f115e911 | bellard | if (op == 4) |
6966 | a7812ae4 | pbrook | gen_helper_verr(cpu_T[0]);
|
6967 | f115e911 | bellard | else
|
6968 | a7812ae4 | pbrook | gen_helper_verw(cpu_T[0]);
|
6969 | f115e911 | bellard | s->cc_op = CC_OP_EFLAGS; |
6970 | f115e911 | bellard | break;
|
6971 | 2c0262af | bellard | default:
|
6972 | 2c0262af | bellard | goto illegal_op;
|
6973 | 2c0262af | bellard | } |
6974 | 2c0262af | bellard | break;
|
6975 | 2c0262af | bellard | case 0x101: |
6976 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
6977 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
6978 | 2c0262af | bellard | op = (modrm >> 3) & 7; |
6979 | 3d7374c5 | bellard | rm = modrm & 7;
|
6980 | 2c0262af | bellard | switch(op) {
|
6981 | 2c0262af | bellard | case 0: /* sgdt */ |
6982 | 2c0262af | bellard | if (mod == 3) |
6983 | 2c0262af | bellard | goto illegal_op;
|
6984 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, SVM_EXIT_GDTR_READ); |
6985 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
6986 | 651ba608 | bellard | tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State, gdt.limit));
|
6987 | 57fec1fe | bellard | gen_op_st_T0_A0(OT_WORD + s->mem_index); |
6988 | aba9d61e | bellard | gen_add_A0_im(s, 2);
|
6989 | 651ba608 | bellard | tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUX86State, gdt.base));
|
6990 | 2c0262af | bellard | if (!s->dflag)
|
6991 | 2c0262af | bellard | gen_op_andl_T0_im(0xffffff);
|
6992 | 57fec1fe | bellard | gen_op_st_T0_A0(CODE64(s) + OT_LONG + s->mem_index); |
6993 | 2c0262af | bellard | break;
|
6994 | 3d7374c5 | bellard | case 1: |
6995 | 3d7374c5 | bellard | if (mod == 3) { |
6996 | 3d7374c5 | bellard | switch (rm) {
|
6997 | 3d7374c5 | bellard | case 0: /* monitor */ |
6998 | 3d7374c5 | bellard | if (!(s->cpuid_ext_features & CPUID_EXT_MONITOR) ||
|
6999 | 3d7374c5 | bellard | s->cpl != 0)
|
7000 | 3d7374c5 | bellard | goto illegal_op;
|
7001 | 94451178 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
7002 | 94451178 | bellard | gen_op_set_cc_op(s->cc_op); |
7003 | 3d7374c5 | bellard | gen_jmp_im(pc_start - s->cs_base); |
7004 | 3d7374c5 | bellard | #ifdef TARGET_X86_64
|
7005 | 3d7374c5 | bellard | if (s->aflag == 2) { |
7006 | bbf662ee | bellard | gen_op_movq_A0_reg(R_EAX); |
7007 | 5fafdf24 | ths | } else
|
7008 | 3d7374c5 | bellard | #endif
|
7009 | 3d7374c5 | bellard | { |
7010 | bbf662ee | bellard | gen_op_movl_A0_reg(R_EAX); |
7011 | 3d7374c5 | bellard | if (s->aflag == 0) |
7012 | 3d7374c5 | bellard | gen_op_andl_A0_ffff(); |
7013 | 3d7374c5 | bellard | } |
7014 | 3d7374c5 | bellard | gen_add_A0_ds_seg(s); |
7015 | a7812ae4 | pbrook | gen_helper_monitor(cpu_A0); |
7016 | 3d7374c5 | bellard | break;
|
7017 | 3d7374c5 | bellard | case 1: /* mwait */ |
7018 | 3d7374c5 | bellard | if (!(s->cpuid_ext_features & CPUID_EXT_MONITOR) ||
|
7019 | 3d7374c5 | bellard | s->cpl != 0)
|
7020 | 3d7374c5 | bellard | goto illegal_op;
|
7021 | 3d7374c5 | bellard | if (s->cc_op != CC_OP_DYNAMIC) {
|
7022 | 3d7374c5 | bellard | gen_op_set_cc_op(s->cc_op); |
7023 | 3d7374c5 | bellard | s->cc_op = CC_OP_DYNAMIC; |
7024 | 3d7374c5 | bellard | } |
7025 | 94451178 | bellard | gen_jmp_im(pc_start - s->cs_base); |
7026 | a7812ae4 | pbrook | gen_helper_mwait(tcg_const_i32(s->pc - pc_start)); |
7027 | 3d7374c5 | bellard | gen_eob(s); |
7028 | 3d7374c5 | bellard | break;
|
7029 | 3d7374c5 | bellard | default:
|
7030 | 3d7374c5 | bellard | goto illegal_op;
|
7031 | 3d7374c5 | bellard | } |
7032 | 3d7374c5 | bellard | } else { /* sidt */ |
7033 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, SVM_EXIT_IDTR_READ); |
7034 | 3d7374c5 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
7035 | 651ba608 | bellard | tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State, idt.limit));
|
7036 | 57fec1fe | bellard | gen_op_st_T0_A0(OT_WORD + s->mem_index); |
7037 | 3d7374c5 | bellard | gen_add_A0_im(s, 2);
|
7038 | 651ba608 | bellard | tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUX86State, idt.base));
|
7039 | 3d7374c5 | bellard | if (!s->dflag)
|
7040 | 3d7374c5 | bellard | gen_op_andl_T0_im(0xffffff);
|
7041 | 57fec1fe | bellard | gen_op_st_T0_A0(CODE64(s) + OT_LONG + s->mem_index); |
7042 | 3d7374c5 | bellard | } |
7043 | 3d7374c5 | bellard | break;
|
7044 | 2c0262af | bellard | case 2: /* lgdt */ |
7045 | 2c0262af | bellard | case 3: /* lidt */ |
7046 | 0573fbfc | ths | if (mod == 3) { |
7047 | 872929aa | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
7048 | 872929aa | bellard | gen_op_set_cc_op(s->cc_op); |
7049 | 872929aa | bellard | gen_jmp_im(pc_start - s->cs_base); |
7050 | 0573fbfc | ths | switch(rm) {
|
7051 | 0573fbfc | ths | case 0: /* VMRUN */ |
7052 | 872929aa | bellard | if (!(s->flags & HF_SVME_MASK) || !s->pe)
|
7053 | 872929aa | bellard | goto illegal_op;
|
7054 | 872929aa | bellard | if (s->cpl != 0) { |
7055 | 872929aa | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7056 | 0573fbfc | ths | break;
|
7057 | 872929aa | bellard | } else {
|
7058 | a7812ae4 | pbrook | gen_helper_vmrun(tcg_const_i32(s->aflag), |
7059 | a7812ae4 | pbrook | tcg_const_i32(s->pc - pc_start)); |
7060 | db620f46 | bellard | tcg_gen_exit_tb(0);
|
7061 | db620f46 | bellard | s->is_jmp = 3;
|
7062 | 872929aa | bellard | } |
7063 | 0573fbfc | ths | break;
|
7064 | 0573fbfc | ths | case 1: /* VMMCALL */ |
7065 | 872929aa | bellard | if (!(s->flags & HF_SVME_MASK))
|
7066 | 872929aa | bellard | goto illegal_op;
|
7067 | a7812ae4 | pbrook | gen_helper_vmmcall(); |
7068 | 0573fbfc | ths | break;
|
7069 | 0573fbfc | ths | case 2: /* VMLOAD */ |
7070 | 872929aa | bellard | if (!(s->flags & HF_SVME_MASK) || !s->pe)
|
7071 | 872929aa | bellard | goto illegal_op;
|
7072 | 872929aa | bellard | if (s->cpl != 0) { |
7073 | 872929aa | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7074 | 872929aa | bellard | break;
|
7075 | 872929aa | bellard | } else {
|
7076 | a7812ae4 | pbrook | gen_helper_vmload(tcg_const_i32(s->aflag)); |
7077 | 872929aa | bellard | } |
7078 | 0573fbfc | ths | break;
|
7079 | 0573fbfc | ths | case 3: /* VMSAVE */ |
7080 | 872929aa | bellard | if (!(s->flags & HF_SVME_MASK) || !s->pe)
|
7081 | 872929aa | bellard | goto illegal_op;
|
7082 | 872929aa | bellard | if (s->cpl != 0) { |
7083 | 872929aa | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7084 | 872929aa | bellard | break;
|
7085 | 872929aa | bellard | } else {
|
7086 | a7812ae4 | pbrook | gen_helper_vmsave(tcg_const_i32(s->aflag)); |
7087 | 872929aa | bellard | } |
7088 | 0573fbfc | ths | break;
|
7089 | 0573fbfc | ths | case 4: /* STGI */ |
7090 | 872929aa | bellard | if ((!(s->flags & HF_SVME_MASK) &&
|
7091 | 872929aa | bellard | !(s->cpuid_ext3_features & CPUID_EXT3_SKINIT)) || |
7092 | 872929aa | bellard | !s->pe) |
7093 | 872929aa | bellard | goto illegal_op;
|
7094 | 872929aa | bellard | if (s->cpl != 0) { |
7095 | 872929aa | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7096 | 872929aa | bellard | break;
|
7097 | 872929aa | bellard | } else {
|
7098 | a7812ae4 | pbrook | gen_helper_stgi(); |
7099 | 872929aa | bellard | } |
7100 | 0573fbfc | ths | break;
|
7101 | 0573fbfc | ths | case 5: /* CLGI */ |
7102 | 872929aa | bellard | if (!(s->flags & HF_SVME_MASK) || !s->pe)
|
7103 | 872929aa | bellard | goto illegal_op;
|
7104 | 872929aa | bellard | if (s->cpl != 0) { |
7105 | 872929aa | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7106 | 872929aa | bellard | break;
|
7107 | 872929aa | bellard | } else {
|
7108 | a7812ae4 | pbrook | gen_helper_clgi(); |
7109 | 872929aa | bellard | } |
7110 | 0573fbfc | ths | break;
|
7111 | 0573fbfc | ths | case 6: /* SKINIT */ |
7112 | 872929aa | bellard | if ((!(s->flags & HF_SVME_MASK) &&
|
7113 | 872929aa | bellard | !(s->cpuid_ext3_features & CPUID_EXT3_SKINIT)) || |
7114 | 872929aa | bellard | !s->pe) |
7115 | 872929aa | bellard | goto illegal_op;
|
7116 | a7812ae4 | pbrook | gen_helper_skinit(); |
7117 | 0573fbfc | ths | break;
|
7118 | 0573fbfc | ths | case 7: /* INVLPGA */ |
7119 | 872929aa | bellard | if (!(s->flags & HF_SVME_MASK) || !s->pe)
|
7120 | 872929aa | bellard | goto illegal_op;
|
7121 | 872929aa | bellard | if (s->cpl != 0) { |
7122 | 872929aa | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7123 | 872929aa | bellard | break;
|
7124 | 872929aa | bellard | } else {
|
7125 | a7812ae4 | pbrook | gen_helper_invlpga(tcg_const_i32(s->aflag)); |
7126 | 872929aa | bellard | } |
7127 | 0573fbfc | ths | break;
|
7128 | 0573fbfc | ths | default:
|
7129 | 0573fbfc | ths | goto illegal_op;
|
7130 | 0573fbfc | ths | } |
7131 | 0573fbfc | ths | } else if (s->cpl != 0) { |
7132 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7133 | 2c0262af | bellard | } else {
|
7134 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, |
7135 | 872929aa | bellard | op==2 ? SVM_EXIT_GDTR_WRITE : SVM_EXIT_IDTR_WRITE);
|
7136 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
7137 | 57fec1fe | bellard | gen_op_ld_T1_A0(OT_WORD + s->mem_index); |
7138 | aba9d61e | bellard | gen_add_A0_im(s, 2);
|
7139 | 57fec1fe | bellard | gen_op_ld_T0_A0(CODE64(s) + OT_LONG + s->mem_index); |
7140 | 2c0262af | bellard | if (!s->dflag)
|
7141 | 2c0262af | bellard | gen_op_andl_T0_im(0xffffff);
|
7142 | 2c0262af | bellard | if (op == 2) { |
7143 | 651ba608 | bellard | tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,gdt.base));
|
7144 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[1], cpu_env, offsetof(CPUX86State,gdt.limit));
|
7145 | 2c0262af | bellard | } else {
|
7146 | 651ba608 | bellard | tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,idt.base));
|
7147 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[1], cpu_env, offsetof(CPUX86State,idt.limit));
|
7148 | 2c0262af | bellard | } |
7149 | 2c0262af | bellard | } |
7150 | 2c0262af | bellard | break;
|
7151 | 2c0262af | bellard | case 4: /* smsw */ |
7152 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, SVM_EXIT_READ_CR0); |
7153 | f60d2728 | malc | #if defined TARGET_X86_64 && defined WORDS_BIGENDIAN
|
7154 | f60d2728 | malc | tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,cr[0]) + 4); |
7155 | f60d2728 | malc | #else
|
7156 | 651ba608 | bellard | tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,cr[0])); |
7157 | f60d2728 | malc | #endif
|
7158 | 2c0262af | bellard | gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 1);
|
7159 | 2c0262af | bellard | break;
|
7160 | 2c0262af | bellard | case 6: /* lmsw */ |
7161 | 2c0262af | bellard | if (s->cpl != 0) { |
7162 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7163 | 2c0262af | bellard | } else {
|
7164 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, SVM_EXIT_WRITE_CR0); |
7165 | 2c0262af | bellard | gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
7166 | a7812ae4 | pbrook | gen_helper_lmsw(cpu_T[0]);
|
7167 | 14ce26e7 | bellard | gen_jmp_im(s->pc - s->cs_base); |
7168 | d71b9a8b | bellard | gen_eob(s); |
7169 | 2c0262af | bellard | } |
7170 | 2c0262af | bellard | break;
|
7171 | 2c0262af | bellard | case 7: /* invlpg */ |
7172 | 2c0262af | bellard | if (s->cpl != 0) { |
7173 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7174 | 2c0262af | bellard | } else {
|
7175 | 14ce26e7 | bellard | if (mod == 3) { |
7176 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
7177 | 3d7374c5 | bellard | if (CODE64(s) && rm == 0) { |
7178 | 14ce26e7 | bellard | /* swapgs */
|
7179 | 651ba608 | bellard | tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,segs[R_GS].base));
|
7180 | 651ba608 | bellard | tcg_gen_ld_tl(cpu_T[1], cpu_env, offsetof(CPUX86State,kernelgsbase));
|
7181 | 651ba608 | bellard | tcg_gen_st_tl(cpu_T[1], cpu_env, offsetof(CPUX86State,segs[R_GS].base));
|
7182 | 651ba608 | bellard | tcg_gen_st_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,kernelgsbase));
|
7183 | 5fafdf24 | ths | } else
|
7184 | 14ce26e7 | bellard | #endif
|
7185 | 14ce26e7 | bellard | { |
7186 | 14ce26e7 | bellard | goto illegal_op;
|
7187 | 14ce26e7 | bellard | } |
7188 | 14ce26e7 | bellard | } else {
|
7189 | 9575cb94 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
7190 | 9575cb94 | bellard | gen_op_set_cc_op(s->cc_op); |
7191 | 9575cb94 | bellard | gen_jmp_im(pc_start - s->cs_base); |
7192 | 14ce26e7 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
7193 | a7812ae4 | pbrook | gen_helper_invlpg(cpu_A0); |
7194 | 14ce26e7 | bellard | gen_jmp_im(s->pc - s->cs_base); |
7195 | 14ce26e7 | bellard | gen_eob(s); |
7196 | 14ce26e7 | bellard | } |
7197 | 2c0262af | bellard | } |
7198 | 2c0262af | bellard | break;
|
7199 | 2c0262af | bellard | default:
|
7200 | 2c0262af | bellard | goto illegal_op;
|
7201 | 2c0262af | bellard | } |
7202 | 2c0262af | bellard | break;
|
7203 | 3415a4dd | bellard | case 0x108: /* invd */ |
7204 | 3415a4dd | bellard | case 0x109: /* wbinvd */ |
7205 | 3415a4dd | bellard | if (s->cpl != 0) { |
7206 | 3415a4dd | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7207 | 3415a4dd | bellard | } else {
|
7208 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, (b & 2) ? SVM_EXIT_INVD : SVM_EXIT_WBINVD);
|
7209 | 3415a4dd | bellard | /* nothing to do */
|
7210 | 3415a4dd | bellard | } |
7211 | 3415a4dd | bellard | break;
|
7212 | 14ce26e7 | bellard | case 0x63: /* arpl or movslS (x86_64) */ |
7213 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
7214 | 14ce26e7 | bellard | if (CODE64(s)) {
|
7215 | 14ce26e7 | bellard | int d_ot;
|
7216 | 14ce26e7 | bellard | /* d_ot is the size of destination */
|
7217 | 14ce26e7 | bellard | d_ot = dflag + OT_WORD; |
7218 | 14ce26e7 | bellard | |
7219 | 14ce26e7 | bellard | modrm = ldub_code(s->pc++); |
7220 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
7221 | 14ce26e7 | bellard | mod = (modrm >> 6) & 3; |
7222 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
7223 | 3b46e624 | ths | |
7224 | 14ce26e7 | bellard | if (mod == 3) { |
7225 | 57fec1fe | bellard | gen_op_mov_TN_reg(OT_LONG, 0, rm);
|
7226 | 14ce26e7 | bellard | /* sign extend */
|
7227 | 14ce26e7 | bellard | if (d_ot == OT_QUAD)
|
7228 | e108dd01 | bellard | tcg_gen_ext32s_tl(cpu_T[0], cpu_T[0]); |
7229 | 57fec1fe | bellard | gen_op_mov_reg_T0(d_ot, reg); |
7230 | 14ce26e7 | bellard | } else {
|
7231 | 14ce26e7 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
7232 | 14ce26e7 | bellard | if (d_ot == OT_QUAD) {
|
7233 | 57fec1fe | bellard | gen_op_lds_T0_A0(OT_LONG + s->mem_index); |
7234 | 14ce26e7 | bellard | } else {
|
7235 | 57fec1fe | bellard | gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
7236 | 14ce26e7 | bellard | } |
7237 | 57fec1fe | bellard | gen_op_mov_reg_T0(d_ot, reg); |
7238 | 14ce26e7 | bellard | } |
7239 | 5fafdf24 | ths | } else
|
7240 | 14ce26e7 | bellard | #endif
|
7241 | 14ce26e7 | bellard | { |
7242 | 3bd7da9e | bellard | int label1;
|
7243 | 1e4840bf | bellard | TCGv t0, t1, t2; |
7244 | 1e4840bf | bellard | |
7245 | 14ce26e7 | bellard | if (!s->pe || s->vm86)
|
7246 | 14ce26e7 | bellard | goto illegal_op;
|
7247 | a7812ae4 | pbrook | t0 = tcg_temp_local_new(); |
7248 | a7812ae4 | pbrook | t1 = tcg_temp_local_new(); |
7249 | a7812ae4 | pbrook | t2 = tcg_temp_local_new(); |
7250 | 3bd7da9e | bellard | ot = OT_WORD; |
7251 | 14ce26e7 | bellard | modrm = ldub_code(s->pc++); |
7252 | 14ce26e7 | bellard | reg = (modrm >> 3) & 7; |
7253 | 14ce26e7 | bellard | mod = (modrm >> 6) & 3; |
7254 | 14ce26e7 | bellard | rm = modrm & 7;
|
7255 | 14ce26e7 | bellard | if (mod != 3) { |
7256 | 14ce26e7 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
7257 | 1e4840bf | bellard | gen_op_ld_v(ot + s->mem_index, t0, cpu_A0); |
7258 | 14ce26e7 | bellard | } else {
|
7259 | 1e4840bf | bellard | gen_op_mov_v_reg(ot, t0, rm); |
7260 | 14ce26e7 | bellard | } |
7261 | 1e4840bf | bellard | gen_op_mov_v_reg(ot, t1, reg); |
7262 | 1e4840bf | bellard | tcg_gen_andi_tl(cpu_tmp0, t0, 3);
|
7263 | 1e4840bf | bellard | tcg_gen_andi_tl(t1, t1, 3);
|
7264 | 1e4840bf | bellard | tcg_gen_movi_tl(t2, 0);
|
7265 | 3bd7da9e | bellard | label1 = gen_new_label(); |
7266 | 1e4840bf | bellard | tcg_gen_brcond_tl(TCG_COND_GE, cpu_tmp0, t1, label1); |
7267 | 1e4840bf | bellard | tcg_gen_andi_tl(t0, t0, ~3);
|
7268 | 1e4840bf | bellard | tcg_gen_or_tl(t0, t0, t1); |
7269 | 1e4840bf | bellard | tcg_gen_movi_tl(t2, CC_Z); |
7270 | 3bd7da9e | bellard | gen_set_label(label1); |
7271 | 14ce26e7 | bellard | if (mod != 3) { |
7272 | 1e4840bf | bellard | gen_op_st_v(ot + s->mem_index, t0, cpu_A0); |
7273 | 14ce26e7 | bellard | } else {
|
7274 | 1e4840bf | bellard | gen_op_mov_reg_v(ot, rm, t0); |
7275 | 14ce26e7 | bellard | } |
7276 | 3bd7da9e | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
7277 | 3bd7da9e | bellard | gen_op_set_cc_op(s->cc_op); |
7278 | 3bd7da9e | bellard | gen_compute_eflags(cpu_cc_src); |
7279 | 3bd7da9e | bellard | tcg_gen_andi_tl(cpu_cc_src, cpu_cc_src, ~CC_Z); |
7280 | 1e4840bf | bellard | tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, t2); |
7281 | 3bd7da9e | bellard | s->cc_op = CC_OP_EFLAGS; |
7282 | 1e4840bf | bellard | tcg_temp_free(t0); |
7283 | 1e4840bf | bellard | tcg_temp_free(t1); |
7284 | 1e4840bf | bellard | tcg_temp_free(t2); |
7285 | f115e911 | bellard | } |
7286 | f115e911 | bellard | break;
|
7287 | 2c0262af | bellard | case 0x102: /* lar */ |
7288 | 2c0262af | bellard | case 0x103: /* lsl */ |
7289 | cec6843e | bellard | { |
7290 | cec6843e | bellard | int label1;
|
7291 | 1e4840bf | bellard | TCGv t0; |
7292 | cec6843e | bellard | if (!s->pe || s->vm86)
|
7293 | cec6843e | bellard | goto illegal_op;
|
7294 | cec6843e | bellard | ot = dflag ? OT_LONG : OT_WORD; |
7295 | cec6843e | bellard | modrm = ldub_code(s->pc++); |
7296 | cec6843e | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
7297 | cec6843e | bellard | gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
7298 | a7812ae4 | pbrook | t0 = tcg_temp_local_new(); |
7299 | cec6843e | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
7300 | cec6843e | bellard | gen_op_set_cc_op(s->cc_op); |
7301 | cec6843e | bellard | if (b == 0x102) |
7302 | a7812ae4 | pbrook | gen_helper_lar(t0, cpu_T[0]);
|
7303 | cec6843e | bellard | else
|
7304 | a7812ae4 | pbrook | gen_helper_lsl(t0, cpu_T[0]);
|
7305 | cec6843e | bellard | tcg_gen_andi_tl(cpu_tmp0, cpu_cc_src, CC_Z); |
7306 | cec6843e | bellard | label1 = gen_new_label(); |
7307 | cb63669a | pbrook | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_tmp0, 0, label1);
|
7308 | 1e4840bf | bellard | gen_op_mov_reg_v(ot, reg, t0); |
7309 | cec6843e | bellard | gen_set_label(label1); |
7310 | cec6843e | bellard | s->cc_op = CC_OP_EFLAGS; |
7311 | 1e4840bf | bellard | tcg_temp_free(t0); |
7312 | cec6843e | bellard | } |
7313 | 2c0262af | bellard | break;
|
7314 | 2c0262af | bellard | case 0x118: |
7315 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
7316 | 2c0262af | bellard | mod = (modrm >> 6) & 3; |
7317 | 2c0262af | bellard | op = (modrm >> 3) & 7; |
7318 | 2c0262af | bellard | switch(op) {
|
7319 | 2c0262af | bellard | case 0: /* prefetchnta */ |
7320 | 2c0262af | bellard | case 1: /* prefetchnt0 */ |
7321 | 2c0262af | bellard | case 2: /* prefetchnt0 */ |
7322 | 2c0262af | bellard | case 3: /* prefetchnt0 */ |
7323 | 2c0262af | bellard | if (mod == 3) |
7324 | 2c0262af | bellard | goto illegal_op;
|
7325 | 2c0262af | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
7326 | 2c0262af | bellard | /* nothing more to do */
|
7327 | 2c0262af | bellard | break;
|
7328 | e17a36ce | bellard | default: /* nop (multi byte) */ |
7329 | e17a36ce | bellard | gen_nop_modrm(s, modrm); |
7330 | e17a36ce | bellard | break;
|
7331 | 2c0262af | bellard | } |
7332 | 2c0262af | bellard | break;
|
7333 | e17a36ce | bellard | case 0x119 ... 0x11f: /* nop (multi byte) */ |
7334 | e17a36ce | bellard | modrm = ldub_code(s->pc++); |
7335 | e17a36ce | bellard | gen_nop_modrm(s, modrm); |
7336 | e17a36ce | bellard | break;
|
7337 | 2c0262af | bellard | case 0x120: /* mov reg, crN */ |
7338 | 2c0262af | bellard | case 0x122: /* mov crN, reg */ |
7339 | 2c0262af | bellard | if (s->cpl != 0) { |
7340 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7341 | 2c0262af | bellard | } else {
|
7342 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
7343 | 2c0262af | bellard | if ((modrm & 0xc0) != 0xc0) |
7344 | 2c0262af | bellard | goto illegal_op;
|
7345 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
7346 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
7347 | 14ce26e7 | bellard | if (CODE64(s))
|
7348 | 14ce26e7 | bellard | ot = OT_QUAD; |
7349 | 14ce26e7 | bellard | else
|
7350 | 14ce26e7 | bellard | ot = OT_LONG; |
7351 | 2c0262af | bellard | switch(reg) {
|
7352 | 2c0262af | bellard | case 0: |
7353 | 2c0262af | bellard | case 2: |
7354 | 2c0262af | bellard | case 3: |
7355 | 2c0262af | bellard | case 4: |
7356 | 9230e66e | bellard | case 8: |
7357 | 872929aa | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
7358 | 872929aa | bellard | gen_op_set_cc_op(s->cc_op); |
7359 | 872929aa | bellard | gen_jmp_im(pc_start - s->cs_base); |
7360 | 2c0262af | bellard | if (b & 2) { |
7361 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, rm);
|
7362 | a7812ae4 | pbrook | gen_helper_write_crN(tcg_const_i32(reg), cpu_T[0]);
|
7363 | 14ce26e7 | bellard | gen_jmp_im(s->pc - s->cs_base); |
7364 | 2c0262af | bellard | gen_eob(s); |
7365 | 2c0262af | bellard | } else {
|
7366 | a7812ae4 | pbrook | gen_helper_read_crN(cpu_T[0], tcg_const_i32(reg));
|
7367 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, rm); |
7368 | 2c0262af | bellard | } |
7369 | 2c0262af | bellard | break;
|
7370 | 2c0262af | bellard | default:
|
7371 | 2c0262af | bellard | goto illegal_op;
|
7372 | 2c0262af | bellard | } |
7373 | 2c0262af | bellard | } |
7374 | 2c0262af | bellard | break;
|
7375 | 2c0262af | bellard | case 0x121: /* mov reg, drN */ |
7376 | 2c0262af | bellard | case 0x123: /* mov drN, reg */ |
7377 | 2c0262af | bellard | if (s->cpl != 0) { |
7378 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7379 | 2c0262af | bellard | } else {
|
7380 | 61382a50 | bellard | modrm = ldub_code(s->pc++); |
7381 | 2c0262af | bellard | if ((modrm & 0xc0) != 0xc0) |
7382 | 2c0262af | bellard | goto illegal_op;
|
7383 | 14ce26e7 | bellard | rm = (modrm & 7) | REX_B(s);
|
7384 | 14ce26e7 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
7385 | 14ce26e7 | bellard | if (CODE64(s))
|
7386 | 14ce26e7 | bellard | ot = OT_QUAD; |
7387 | 14ce26e7 | bellard | else
|
7388 | 14ce26e7 | bellard | ot = OT_LONG; |
7389 | 2c0262af | bellard | /* XXX: do it dynamically with CR4.DE bit */
|
7390 | 14ce26e7 | bellard | if (reg == 4 || reg == 5 || reg >= 8) |
7391 | 2c0262af | bellard | goto illegal_op;
|
7392 | 2c0262af | bellard | if (b & 2) { |
7393 | 0573fbfc | ths | gen_svm_check_intercept(s, pc_start, SVM_EXIT_WRITE_DR0 + reg); |
7394 | 57fec1fe | bellard | gen_op_mov_TN_reg(ot, 0, rm);
|
7395 | a7812ae4 | pbrook | gen_helper_movl_drN_T0(tcg_const_i32(reg), cpu_T[0]);
|
7396 | 14ce26e7 | bellard | gen_jmp_im(s->pc - s->cs_base); |
7397 | 2c0262af | bellard | gen_eob(s); |
7398 | 2c0262af | bellard | } else {
|
7399 | 0573fbfc | ths | gen_svm_check_intercept(s, pc_start, SVM_EXIT_READ_DR0 + reg); |
7400 | 651ba608 | bellard | tcg_gen_ld_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,dr[reg]));
|
7401 | 57fec1fe | bellard | gen_op_mov_reg_T0(ot, rm); |
7402 | 2c0262af | bellard | } |
7403 | 2c0262af | bellard | } |
7404 | 2c0262af | bellard | break;
|
7405 | 2c0262af | bellard | case 0x106: /* clts */ |
7406 | 2c0262af | bellard | if (s->cpl != 0) { |
7407 | 2c0262af | bellard | gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
7408 | 2c0262af | bellard | } else {
|
7409 | 0573fbfc | ths | gen_svm_check_intercept(s, pc_start, SVM_EXIT_WRITE_CR0); |
7410 | a7812ae4 | pbrook | gen_helper_clts(); |
7411 | 7eee2a50 | bellard | /* abort block because static cpu state changed */
|
7412 | 14ce26e7 | bellard | gen_jmp_im(s->pc - s->cs_base); |
7413 | 7eee2a50 | bellard | gen_eob(s); |
7414 | 2c0262af | bellard | } |
7415 | 2c0262af | bellard | break;
|
7416 | 222a3336 | balrog | /* MMX/3DNow!/SSE/SSE2/SSE3/SSSE3/SSE4 support */
|
7417 | 664e0f19 | bellard | case 0x1c3: /* MOVNTI reg, mem */ |
7418 | 664e0f19 | bellard | if (!(s->cpuid_features & CPUID_SSE2))
|
7419 | 14ce26e7 | bellard | goto illegal_op;
|
7420 | 664e0f19 | bellard | ot = s->dflag == 2 ? OT_QUAD : OT_LONG;
|
7421 | 664e0f19 | bellard | modrm = ldub_code(s->pc++); |
7422 | 664e0f19 | bellard | mod = (modrm >> 6) & 3; |
7423 | 664e0f19 | bellard | if (mod == 3) |
7424 | 664e0f19 | bellard | goto illegal_op;
|
7425 | 664e0f19 | bellard | reg = ((modrm >> 3) & 7) | rex_r; |
7426 | 664e0f19 | bellard | /* generate a generic store */
|
7427 | 664e0f19 | bellard | gen_ldst_modrm(s, modrm, ot, reg, 1);
|
7428 | 14ce26e7 | bellard | break;
|
7429 | 664e0f19 | bellard | case 0x1ae: |
7430 | 664e0f19 | bellard | modrm = ldub_code(s->pc++); |
7431 | 664e0f19 | bellard | mod = (modrm >> 6) & 3; |
7432 | 664e0f19 | bellard | op = (modrm >> 3) & 7; |
7433 | 664e0f19 | bellard | switch(op) {
|
7434 | 664e0f19 | bellard | case 0: /* fxsave */ |
7435 | 5fafdf24 | ths | if (mod == 3 || !(s->cpuid_features & CPUID_FXSR) || |
7436 | 0fd14b72 | bellard | (s->flags & HF_EM_MASK)) |
7437 | 14ce26e7 | bellard | goto illegal_op;
|
7438 | 0fd14b72 | bellard | if (s->flags & HF_TS_MASK) {
|
7439 | 0fd14b72 | bellard | gen_exception(s, EXCP07_PREX, pc_start - s->cs_base); |
7440 | 0fd14b72 | bellard | break;
|
7441 | 0fd14b72 | bellard | } |
7442 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
7443 | 19e6c4b8 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
7444 | 19e6c4b8 | bellard | gen_op_set_cc_op(s->cc_op); |
7445 | 19e6c4b8 | bellard | gen_jmp_im(pc_start - s->cs_base); |
7446 | a7812ae4 | pbrook | gen_helper_fxsave(cpu_A0, tcg_const_i32((s->dflag == 2)));
|
7447 | 664e0f19 | bellard | break;
|
7448 | 664e0f19 | bellard | case 1: /* fxrstor */ |
7449 | 5fafdf24 | ths | if (mod == 3 || !(s->cpuid_features & CPUID_FXSR) || |
7450 | 0fd14b72 | bellard | (s->flags & HF_EM_MASK)) |
7451 | 14ce26e7 | bellard | goto illegal_op;
|
7452 | 0fd14b72 | bellard | if (s->flags & HF_TS_MASK) {
|
7453 | 0fd14b72 | bellard | gen_exception(s, EXCP07_PREX, pc_start - s->cs_base); |
7454 | 0fd14b72 | bellard | break;
|
7455 | 0fd14b72 | bellard | } |
7456 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
7457 | 19e6c4b8 | bellard | if (s->cc_op != CC_OP_DYNAMIC)
|
7458 | 19e6c4b8 | bellard | gen_op_set_cc_op(s->cc_op); |
7459 | 19e6c4b8 | bellard | gen_jmp_im(pc_start - s->cs_base); |
7460 | a7812ae4 | pbrook | gen_helper_fxrstor(cpu_A0, tcg_const_i32((s->dflag == 2)));
|
7461 | 664e0f19 | bellard | break;
|
7462 | 664e0f19 | bellard | case 2: /* ldmxcsr */ |
7463 | 664e0f19 | bellard | case 3: /* stmxcsr */ |
7464 | 664e0f19 | bellard | if (s->flags & HF_TS_MASK) {
|
7465 | 664e0f19 | bellard | gen_exception(s, EXCP07_PREX, pc_start - s->cs_base); |
7466 | 664e0f19 | bellard | break;
|
7467 | 14ce26e7 | bellard | } |
7468 | 664e0f19 | bellard | if ((s->flags & HF_EM_MASK) || !(s->flags & HF_OSFXSR_MASK) ||
|
7469 | 664e0f19 | bellard | mod == 3)
|
7470 | 14ce26e7 | bellard | goto illegal_op;
|
7471 | 664e0f19 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
7472 | 664e0f19 | bellard | if (op == 2) { |
7473 | 57fec1fe | bellard | gen_op_ld_T0_A0(OT_LONG + s->mem_index); |
7474 | 651ba608 | bellard | tcg_gen_st32_tl(cpu_T[0], cpu_env, offsetof(CPUX86State, mxcsr));
|
7475 | 14ce26e7 | bellard | } else {
|
7476 | 651ba608 | bellard | tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State, mxcsr));
|
7477 | 57fec1fe | bellard | gen_op_st_T0_A0(OT_LONG + s->mem_index); |
7478 | 14ce26e7 | bellard | } |
7479 | 664e0f19 | bellard | break;
|
7480 | 664e0f19 | bellard | case 5: /* lfence */ |
7481 | 664e0f19 | bellard | case 6: /* mfence */ |
7482 | 664e0f19 | bellard | if ((modrm & 0xc7) != 0xc0 || !(s->cpuid_features & CPUID_SSE)) |
7483 | 664e0f19 | bellard | goto illegal_op;
|
7484 | 664e0f19 | bellard | break;
|
7485 | 8f091a59 | bellard | case 7: /* sfence / clflush */ |
7486 | 8f091a59 | bellard | if ((modrm & 0xc7) == 0xc0) { |
7487 | 8f091a59 | bellard | /* sfence */
|
7488 | a35f3ec7 | aurel32 | /* XXX: also check for cpuid_ext2_features & CPUID_EXT2_EMMX */
|
7489 | 8f091a59 | bellard | if (!(s->cpuid_features & CPUID_SSE))
|
7490 | 8f091a59 | bellard | goto illegal_op;
|
7491 | 8f091a59 | bellard | } else {
|
7492 | 8f091a59 | bellard | /* clflush */
|
7493 | 8f091a59 | bellard | if (!(s->cpuid_features & CPUID_CLFLUSH))
|
7494 | 8f091a59 | bellard | goto illegal_op;
|
7495 | 8f091a59 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
7496 | 8f091a59 | bellard | } |
7497 | 8f091a59 | bellard | break;
|
7498 | 664e0f19 | bellard | default:
|
7499 | 14ce26e7 | bellard | goto illegal_op;
|
7500 | 14ce26e7 | bellard | } |
7501 | 14ce26e7 | bellard | break;
|
7502 | a35f3ec7 | aurel32 | case 0x10d: /* 3DNow! prefetch(w) */ |
7503 | 8f091a59 | bellard | modrm = ldub_code(s->pc++); |
7504 | a35f3ec7 | aurel32 | mod = (modrm >> 6) & 3; |
7505 | a35f3ec7 | aurel32 | if (mod == 3) |
7506 | a35f3ec7 | aurel32 | goto illegal_op;
|
7507 | 8f091a59 | bellard | gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
7508 | 8f091a59 | bellard | /* ignore for now */
|
7509 | 8f091a59 | bellard | break;
|
7510 | 3b21e03e | bellard | case 0x1aa: /* rsm */ |
7511 | 872929aa | bellard | gen_svm_check_intercept(s, pc_start, SVM_EXIT_RSM); |
7512 | 3b21e03e | bellard | if (!(s->flags & HF_SMM_MASK))
|
7513 | 3b21e03e | bellard | goto illegal_op;
|
7514 | 3b21e03e | bellard | if (s->cc_op != CC_OP_DYNAMIC) {
|
7515 | 3b21e03e | bellard | gen_op_set_cc_op(s->cc_op); |
7516 | 3b21e03e | bellard | s->cc_op = CC_OP_DYNAMIC; |
7517 | 3b21e03e | bellard | } |
7518 | 3b21e03e | bellard | gen_jmp_im(s->pc - s->cs_base); |
7519 | a7812ae4 | pbrook | gen_helper_rsm(); |
7520 | 3b21e03e | bellard | gen_eob(s); |
7521 | 3b21e03e | bellard | break;
|
7522 | 222a3336 | balrog | case 0x1b8: /* SSE4.2 popcnt */ |
7523 | 222a3336 | balrog | if ((prefixes & (PREFIX_REPZ | PREFIX_LOCK | PREFIX_REPNZ)) !=
|
7524 | 222a3336 | balrog | PREFIX_REPZ) |
7525 | 222a3336 | balrog | goto illegal_op;
|
7526 | 222a3336 | balrog | if (!(s->cpuid_ext_features & CPUID_EXT_POPCNT))
|
7527 | 222a3336 | balrog | goto illegal_op;
|
7528 | 222a3336 | balrog | |
7529 | 222a3336 | balrog | modrm = ldub_code(s->pc++); |
7530 | 222a3336 | balrog | reg = ((modrm >> 3) & 7); |
7531 | 222a3336 | balrog | |
7532 | 222a3336 | balrog | if (s->prefix & PREFIX_DATA)
|
7533 | 222a3336 | balrog | ot = OT_WORD; |
7534 | 222a3336 | balrog | else if (s->dflag != 2) |
7535 | 222a3336 | balrog | ot = OT_LONG; |
7536 | 222a3336 | balrog | else
|
7537 | 222a3336 | balrog | ot = OT_QUAD; |
7538 | 222a3336 | balrog | |
7539 | 222a3336 | balrog | gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
|
7540 | a7812ae4 | pbrook | gen_helper_popcnt(cpu_T[0], cpu_T[0], tcg_const_i32(ot)); |
7541 | 222a3336 | balrog | gen_op_mov_reg_T0(ot, reg); |
7542 | fdb0d09d | balrog | |
7543 | fdb0d09d | balrog | s->cc_op = CC_OP_EFLAGS; |
7544 | 222a3336 | balrog | break;
|
7545 | a35f3ec7 | aurel32 | case 0x10e ... 0x10f: |
7546 | a35f3ec7 | aurel32 | /* 3DNow! instructions, ignore prefixes */
|
7547 | a35f3ec7 | aurel32 | s->prefix &= ~(PREFIX_REPZ | PREFIX_REPNZ | PREFIX_DATA); |
7548 | 664e0f19 | bellard | case 0x110 ... 0x117: |
7549 | 664e0f19 | bellard | case 0x128 ... 0x12f: |
7550 | 4242b1bd | balrog | case 0x138 ... 0x13a: |
7551 | 664e0f19 | bellard | case 0x150 ... 0x177: |
7552 | 664e0f19 | bellard | case 0x17c ... 0x17f: |
7553 | 664e0f19 | bellard | case 0x1c2: |
7554 | 664e0f19 | bellard | case 0x1c4 ... 0x1c6: |
7555 | 664e0f19 | bellard | case 0x1d0 ... 0x1fe: |
7556 | 664e0f19 | bellard | gen_sse(s, b, pc_start, rex_r); |
7557 | 664e0f19 | bellard | break;
|
7558 | 2c0262af | bellard | default:
|
7559 | 2c0262af | bellard | goto illegal_op;
|
7560 | 2c0262af | bellard | } |
7561 | 2c0262af | bellard | /* lock generation */
|
7562 | 2c0262af | bellard | if (s->prefix & PREFIX_LOCK)
|
7563 | a7812ae4 | pbrook | gen_helper_unlock(); |
7564 | 2c0262af | bellard | return s->pc;
|
7565 | 2c0262af | bellard | illegal_op:
|
7566 | ab1f142b | bellard | if (s->prefix & PREFIX_LOCK)
|
7567 | a7812ae4 | pbrook | gen_helper_unlock(); |
7568 | 2c0262af | bellard | /* XXX: ensure that no lock was generated */
|
7569 | 2c0262af | bellard | gen_exception(s, EXCP06_ILLOP, pc_start - s->cs_base); |
7570 | 2c0262af | bellard | return s->pc;
|
7571 | 2c0262af | bellard | } |
7572 | 2c0262af | bellard | |
7573 | 2c0262af | bellard | void optimize_flags_init(void) |
7574 | 2c0262af | bellard | { |
7575 | b6abf97d | bellard | #if TCG_TARGET_REG_BITS == 32 |
7576 | b6abf97d | bellard | assert(sizeof(CCTable) == (1 << 3)); |
7577 | b6abf97d | bellard | #else
|
7578 | b6abf97d | bellard | assert(sizeof(CCTable) == (1 << 4)); |
7579 | b6abf97d | bellard | #endif
|
7580 | a7812ae4 | pbrook | cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
|
7581 | a7812ae4 | pbrook | cpu_cc_op = tcg_global_mem_new_i32(TCG_AREG0, |
7582 | a7812ae4 | pbrook | offsetof(CPUState, cc_op), "cc_op");
|
7583 | a7812ae4 | pbrook | cpu_cc_src = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, cc_src), |
7584 | a7812ae4 | pbrook | "cc_src");
|
7585 | a7812ae4 | pbrook | cpu_cc_dst = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, cc_dst), |
7586 | a7812ae4 | pbrook | "cc_dst");
|
7587 | a7812ae4 | pbrook | cpu_cc_tmp = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, cc_tmp), |
7588 | a7812ae4 | pbrook | "cc_tmp");
|
7589 | 437a88a5 | bellard | |
7590 | 437a88a5 | bellard | /* register helpers */
|
7591 | a7812ae4 | pbrook | #define GEN_HELPER 2 |
7592 | 437a88a5 | bellard | #include "helper.h" |
7593 | 2c0262af | bellard | } |
7594 | 2c0262af | bellard | |
7595 | 2c0262af | bellard | /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
|
7596 | 2c0262af | bellard | basic block 'tb'. If search_pc is TRUE, also generate PC
|
7597 | 2c0262af | bellard | information for each intermediate instruction. */
|
7598 | 2cfc5f17 | ths | static inline void gen_intermediate_code_internal(CPUState *env, |
7599 | 2cfc5f17 | ths | TranslationBlock *tb, |
7600 | 2cfc5f17 | ths | int search_pc)
|
7601 | 2c0262af | bellard | { |
7602 | 2c0262af | bellard | DisasContext dc1, *dc = &dc1; |
7603 | 14ce26e7 | bellard | target_ulong pc_ptr; |
7604 | 2c0262af | bellard | uint16_t *gen_opc_end; |
7605 | a1d1bb31 | aliguori | CPUBreakpoint *bp; |
7606 | c068688b | j_mayer | int j, lj, cflags;
|
7607 | c068688b | j_mayer | uint64_t flags; |
7608 | 14ce26e7 | bellard | target_ulong pc_start; |
7609 | 14ce26e7 | bellard | target_ulong cs_base; |
7610 | 2e70f6ef | pbrook | int num_insns;
|
7611 | 2e70f6ef | pbrook | int max_insns;
|
7612 | 3b46e624 | ths | |
7613 | 2c0262af | bellard | /* generate intermediate code */
|
7614 | 14ce26e7 | bellard | pc_start = tb->pc; |
7615 | 14ce26e7 | bellard | cs_base = tb->cs_base; |
7616 | 2c0262af | bellard | flags = tb->flags; |
7617 | d720b93d | bellard | cflags = tb->cflags; |
7618 | 3a1d9b8b | bellard | |
7619 | 4f31916f | bellard | dc->pe = (flags >> HF_PE_SHIFT) & 1;
|
7620 | 2c0262af | bellard | dc->code32 = (flags >> HF_CS32_SHIFT) & 1;
|
7621 | 2c0262af | bellard | dc->ss32 = (flags >> HF_SS32_SHIFT) & 1;
|
7622 | 2c0262af | bellard | dc->addseg = (flags >> HF_ADDSEG_SHIFT) & 1;
|
7623 | 2c0262af | bellard | dc->f_st = 0;
|
7624 | 2c0262af | bellard | dc->vm86 = (flags >> VM_SHIFT) & 1;
|
7625 | 2c0262af | bellard | dc->cpl = (flags >> HF_CPL_SHIFT) & 3;
|
7626 | 2c0262af | bellard | dc->iopl = (flags >> IOPL_SHIFT) & 3;
|
7627 | 2c0262af | bellard | dc->tf = (flags >> TF_SHIFT) & 1;
|
7628 | 34865134 | bellard | dc->singlestep_enabled = env->singlestep_enabled; |
7629 | 2c0262af | bellard | dc->cc_op = CC_OP_DYNAMIC; |
7630 | 2c0262af | bellard | dc->cs_base = cs_base; |
7631 | 2c0262af | bellard | dc->tb = tb; |
7632 | 2c0262af | bellard | dc->popl_esp_hack = 0;
|
7633 | 2c0262af | bellard | /* select memory access functions */
|
7634 | 2c0262af | bellard | dc->mem_index = 0;
|
7635 | 2c0262af | bellard | if (flags & HF_SOFTMMU_MASK) {
|
7636 | 2c0262af | bellard | if (dc->cpl == 3) |
7637 | 14ce26e7 | bellard | dc->mem_index = 2 * 4; |
7638 | 2c0262af | bellard | else
|
7639 | 14ce26e7 | bellard | dc->mem_index = 1 * 4; |
7640 | 2c0262af | bellard | } |
7641 | 14ce26e7 | bellard | dc->cpuid_features = env->cpuid_features; |
7642 | 3d7374c5 | bellard | dc->cpuid_ext_features = env->cpuid_ext_features; |
7643 | e771edab | aurel32 | dc->cpuid_ext2_features = env->cpuid_ext2_features; |
7644 | 12e26b75 | bellard | dc->cpuid_ext3_features = env->cpuid_ext3_features; |
7645 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
7646 | 14ce26e7 | bellard | dc->lma = (flags >> HF_LMA_SHIFT) & 1;
|
7647 | 14ce26e7 | bellard | dc->code64 = (flags >> HF_CS64_SHIFT) & 1;
|
7648 | 14ce26e7 | bellard | #endif
|
7649 | 7eee2a50 | bellard | dc->flags = flags; |
7650 | a2cc3b24 | bellard | dc->jmp_opt = !(dc->tf || env->singlestep_enabled || |
7651 | a2cc3b24 | bellard | (flags & HF_INHIBIT_IRQ_MASK) |
7652 | 415fa2ea | bellard | #ifndef CONFIG_SOFTMMU
|
7653 | 2c0262af | bellard | || (flags & HF_SOFTMMU_MASK) |
7654 | 2c0262af | bellard | #endif
|
7655 | 2c0262af | bellard | ); |
7656 | 4f31916f | bellard | #if 0
|
7657 | 4f31916f | bellard | /* check addseg logic */
|
7658 | dc196a57 | bellard | if (!dc->addseg && (dc->vm86 || !dc->pe || !dc->code32))
|
7659 | 4f31916f | bellard | printf("ERROR addseg\n");
|
7660 | 4f31916f | bellard | #endif
|
7661 | 4f31916f | bellard | |
7662 | a7812ae4 | pbrook | cpu_T[0] = tcg_temp_new();
|
7663 | a7812ae4 | pbrook | cpu_T[1] = tcg_temp_new();
|
7664 | a7812ae4 | pbrook | cpu_A0 = tcg_temp_new(); |
7665 | a7812ae4 | pbrook | cpu_T3 = tcg_temp_new(); |
7666 | a7812ae4 | pbrook | |
7667 | a7812ae4 | pbrook | cpu_tmp0 = tcg_temp_new(); |
7668 | a7812ae4 | pbrook | cpu_tmp1_i64 = tcg_temp_new_i64(); |
7669 | a7812ae4 | pbrook | cpu_tmp2_i32 = tcg_temp_new_i32(); |
7670 | a7812ae4 | pbrook | cpu_tmp3_i32 = tcg_temp_new_i32(); |
7671 | a7812ae4 | pbrook | cpu_tmp4 = tcg_temp_new(); |
7672 | a7812ae4 | pbrook | cpu_tmp5 = tcg_temp_new(); |
7673 | a7812ae4 | pbrook | cpu_tmp6 = tcg_temp_new(); |
7674 | a7812ae4 | pbrook | cpu_ptr0 = tcg_temp_new_ptr(); |
7675 | a7812ae4 | pbrook | cpu_ptr1 = tcg_temp_new_ptr(); |
7676 | 57fec1fe | bellard | |
7677 | 2c0262af | bellard | gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; |
7678 | 2c0262af | bellard | |
7679 | 2c0262af | bellard | dc->is_jmp = DISAS_NEXT; |
7680 | 2c0262af | bellard | pc_ptr = pc_start; |
7681 | 2c0262af | bellard | lj = -1;
|
7682 | 2e70f6ef | pbrook | num_insns = 0;
|
7683 | 2e70f6ef | pbrook | max_insns = tb->cflags & CF_COUNT_MASK; |
7684 | 2e70f6ef | pbrook | if (max_insns == 0) |
7685 | 2e70f6ef | pbrook | max_insns = CF_COUNT_MASK; |
7686 | 2c0262af | bellard | |
7687 | 2e70f6ef | pbrook | gen_icount_start(); |
7688 | 2c0262af | bellard | for(;;) {
|
7689 | c0ce998e | aliguori | if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) {
|
7690 | c0ce998e | aliguori | TAILQ_FOREACH(bp, &env->breakpoints, entry) { |
7691 | a1d1bb31 | aliguori | if (bp->pc == pc_ptr) {
|
7692 | 2c0262af | bellard | gen_debug(dc, pc_ptr - dc->cs_base); |
7693 | 2c0262af | bellard | break;
|
7694 | 2c0262af | bellard | } |
7695 | 2c0262af | bellard | } |
7696 | 2c0262af | bellard | } |
7697 | 2c0262af | bellard | if (search_pc) {
|
7698 | 2c0262af | bellard | j = gen_opc_ptr - gen_opc_buf; |
7699 | 2c0262af | bellard | if (lj < j) {
|
7700 | 2c0262af | bellard | lj++; |
7701 | 2c0262af | bellard | while (lj < j)
|
7702 | 2c0262af | bellard | gen_opc_instr_start[lj++] = 0;
|
7703 | 2c0262af | bellard | } |
7704 | 14ce26e7 | bellard | gen_opc_pc[lj] = pc_ptr; |
7705 | 2c0262af | bellard | gen_opc_cc_op[lj] = dc->cc_op; |
7706 | 2c0262af | bellard | gen_opc_instr_start[lj] = 1;
|
7707 | 2e70f6ef | pbrook | gen_opc_icount[lj] = num_insns; |
7708 | 2c0262af | bellard | } |
7709 | 2e70f6ef | pbrook | if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) |
7710 | 2e70f6ef | pbrook | gen_io_start(); |
7711 | 2e70f6ef | pbrook | |
7712 | 2c0262af | bellard | pc_ptr = disas_insn(dc, pc_ptr); |
7713 | 2e70f6ef | pbrook | num_insns++; |
7714 | 2c0262af | bellard | /* stop translation if indicated */
|
7715 | 2c0262af | bellard | if (dc->is_jmp)
|
7716 | 2c0262af | bellard | break;
|
7717 | 2c0262af | bellard | /* if single step mode, we generate only one instruction and
|
7718 | 2c0262af | bellard | generate an exception */
|
7719 | a2cc3b24 | bellard | /* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear
|
7720 | a2cc3b24 | bellard | the flag and abort the translation to give the irqs a
|
7721 | a2cc3b24 | bellard | change to be happen */
|
7722 | 5fafdf24 | ths | if (dc->tf || dc->singlestep_enabled ||
|
7723 | 2e70f6ef | pbrook | (flags & HF_INHIBIT_IRQ_MASK)) { |
7724 | 14ce26e7 | bellard | gen_jmp_im(pc_ptr - dc->cs_base); |
7725 | 2c0262af | bellard | gen_eob(dc); |
7726 | 2c0262af | bellard | break;
|
7727 | 2c0262af | bellard | } |
7728 | 2c0262af | bellard | /* if too long translation, stop generation too */
|
7729 | 2c0262af | bellard | if (gen_opc_ptr >= gen_opc_end ||
|
7730 | 2e70f6ef | pbrook | (pc_ptr - pc_start) >= (TARGET_PAGE_SIZE - 32) ||
|
7731 | 2e70f6ef | pbrook | num_insns >= max_insns) { |
7732 | 14ce26e7 | bellard | gen_jmp_im(pc_ptr - dc->cs_base); |
7733 | 2c0262af | bellard | gen_eob(dc); |
7734 | 2c0262af | bellard | break;
|
7735 | 2c0262af | bellard | } |
7736 | 1b530a6d | aurel32 | if (singlestep) {
|
7737 | 1b530a6d | aurel32 | gen_jmp_im(pc_ptr - dc->cs_base); |
7738 | 1b530a6d | aurel32 | gen_eob(dc); |
7739 | 1b530a6d | aurel32 | break;
|
7740 | 1b530a6d | aurel32 | } |
7741 | 2c0262af | bellard | } |
7742 | 2e70f6ef | pbrook | if (tb->cflags & CF_LAST_IO)
|
7743 | 2e70f6ef | pbrook | gen_io_end(); |
7744 | 2e70f6ef | pbrook | gen_icount_end(tb, num_insns); |
7745 | 2c0262af | bellard | *gen_opc_ptr = INDEX_op_end; |
7746 | 2c0262af | bellard | /* we don't forget to fill the last values */
|
7747 | 2c0262af | bellard | if (search_pc) {
|
7748 | 2c0262af | bellard | j = gen_opc_ptr - gen_opc_buf; |
7749 | 2c0262af | bellard | lj++; |
7750 | 2c0262af | bellard | while (lj <= j)
|
7751 | 2c0262af | bellard | gen_opc_instr_start[lj++] = 0;
|
7752 | 2c0262af | bellard | } |
7753 | 3b46e624 | ths | |
7754 | 2c0262af | bellard | #ifdef DEBUG_DISAS
|
7755 | 93fcfe39 | aliguori | log_cpu_state_mask(CPU_LOG_TB_CPU, env, X86_DUMP_CCOP); |
7756 | 8fec2b8c | aliguori | if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
|
7757 | 14ce26e7 | bellard | int disas_flags;
|
7758 | 93fcfe39 | aliguori | qemu_log("----------------\n");
|
7759 | 93fcfe39 | aliguori | qemu_log("IN: %s\n", lookup_symbol(pc_start));
|
7760 | 14ce26e7 | bellard | #ifdef TARGET_X86_64
|
7761 | 14ce26e7 | bellard | if (dc->code64)
|
7762 | 14ce26e7 | bellard | disas_flags = 2;
|
7763 | 14ce26e7 | bellard | else
|
7764 | 14ce26e7 | bellard | #endif
|
7765 | 14ce26e7 | bellard | disas_flags = !dc->code32; |
7766 | 93fcfe39 | aliguori | log_target_disas(pc_start, pc_ptr - pc_start, disas_flags); |
7767 | 93fcfe39 | aliguori | qemu_log("\n");
|
7768 | 2c0262af | bellard | } |
7769 | 2c0262af | bellard | #endif
|
7770 | 2c0262af | bellard | |
7771 | 2e70f6ef | pbrook | if (!search_pc) {
|
7772 | 2c0262af | bellard | tb->size = pc_ptr - pc_start; |
7773 | 2e70f6ef | pbrook | tb->icount = num_insns; |
7774 | 2e70f6ef | pbrook | } |
7775 | 2c0262af | bellard | } |
7776 | 2c0262af | bellard | |
7777 | 2cfc5f17 | ths | void gen_intermediate_code(CPUState *env, TranslationBlock *tb)
|
7778 | 2c0262af | bellard | { |
7779 | 2cfc5f17 | ths | gen_intermediate_code_internal(env, tb, 0);
|
7780 | 2c0262af | bellard | } |
7781 | 2c0262af | bellard | |
7782 | 2cfc5f17 | ths | void gen_intermediate_code_pc(CPUState *env, TranslationBlock *tb)
|
7783 | 2c0262af | bellard | { |
7784 | 2cfc5f17 | ths | gen_intermediate_code_internal(env, tb, 1);
|
7785 | 2c0262af | bellard | } |
7786 | 2c0262af | bellard | |
7787 | d2856f1a | aurel32 | void gen_pc_load(CPUState *env, TranslationBlock *tb,
|
7788 | d2856f1a | aurel32 | unsigned long searched_pc, int pc_pos, void *puc) |
7789 | d2856f1a | aurel32 | { |
7790 | d2856f1a | aurel32 | int cc_op;
|
7791 | d2856f1a | aurel32 | #ifdef DEBUG_DISAS
|
7792 | 8fec2b8c | aliguori | if (qemu_loglevel_mask(CPU_LOG_TB_OP)) {
|
7793 | d2856f1a | aurel32 | int i;
|
7794 | 93fcfe39 | aliguori | qemu_log("RESTORE:\n");
|
7795 | d2856f1a | aurel32 | for(i = 0;i <= pc_pos; i++) { |
7796 | d2856f1a | aurel32 | if (gen_opc_instr_start[i]) {
|
7797 | 93fcfe39 | aliguori | qemu_log("0x%04x: " TARGET_FMT_lx "\n", i, gen_opc_pc[i]); |
7798 | d2856f1a | aurel32 | } |
7799 | d2856f1a | aurel32 | } |
7800 | 93fcfe39 | aliguori | qemu_log("spc=0x%08lx pc_pos=0x%x eip=" TARGET_FMT_lx " cs_base=%x\n", |
7801 | d2856f1a | aurel32 | searched_pc, pc_pos, gen_opc_pc[pc_pos] - tb->cs_base, |
7802 | d2856f1a | aurel32 | (uint32_t)tb->cs_base); |
7803 | d2856f1a | aurel32 | } |
7804 | d2856f1a | aurel32 | #endif
|
7805 | d2856f1a | aurel32 | env->eip = gen_opc_pc[pc_pos] - tb->cs_base; |
7806 | d2856f1a | aurel32 | cc_op = gen_opc_cc_op[pc_pos]; |
7807 | d2856f1a | aurel32 | if (cc_op != CC_OP_DYNAMIC)
|
7808 | d2856f1a | aurel32 | env->cc_op = cc_op; |
7809 | d2856f1a | aurel32 | } |