root / target-i386 / translate.c @ 4f31916f
History | View | Annotate | Download (130.6 kB)
1 |
/*
|
---|---|
2 |
* i386 translation
|
3 |
*
|
4 |
* Copyright (c) 2003 Fabrice Bellard
|
5 |
*
|
6 |
* This library is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU Lesser General Public
|
8 |
* License as published by the Free Software Foundation; either
|
9 |
* version 2 of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This library is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
* Lesser General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU Lesser General Public
|
17 |
* License along with this library; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 |
*/
|
20 |
#include <stdarg.h> |
21 |
#include <stdlib.h> |
22 |
#include <stdio.h> |
23 |
#include <string.h> |
24 |
#include <inttypes.h> |
25 |
#include <signal.h> |
26 |
#include <assert.h> |
27 |
#include <sys/mman.h> |
28 |
|
29 |
#include "cpu.h" |
30 |
#include "exec-all.h" |
31 |
#include "disas.h" |
32 |
|
33 |
/* XXX: move that elsewhere */
|
34 |
static uint16_t *gen_opc_ptr;
|
35 |
static uint32_t *gen_opparam_ptr;
|
36 |
|
37 |
#define PREFIX_REPZ 0x01 |
38 |
#define PREFIX_REPNZ 0x02 |
39 |
#define PREFIX_LOCK 0x04 |
40 |
#define PREFIX_DATA 0x08 |
41 |
#define PREFIX_ADR 0x10 |
42 |
|
43 |
typedef struct DisasContext { |
44 |
/* current insn context */
|
45 |
int override; /* -1 if no override */ |
46 |
int prefix;
|
47 |
int aflag, dflag;
|
48 |
uint8_t *pc; /* pc = eip + cs_base */
|
49 |
int is_jmp; /* 1 = means jump (stop translation), 2 means CPU |
50 |
static state change (stop translation) */
|
51 |
/* current block context */
|
52 |
uint8_t *cs_base; /* base of CS segment */
|
53 |
int pe; /* protected mode */ |
54 |
int code32; /* 32 bit code segment */ |
55 |
int ss32; /* 32 bit stack segment */ |
56 |
int cc_op; /* current CC operation */ |
57 |
int addseg; /* non zero if either DS/ES/SS have a non zero base */ |
58 |
int f_st; /* currently unused */ |
59 |
int vm86; /* vm86 mode */ |
60 |
int cpl;
|
61 |
int iopl;
|
62 |
int tf; /* TF cpu flag */ |
63 |
int singlestep_enabled; /* "hardware" single step enabled */ |
64 |
int jmp_opt; /* use direct block chaining for direct jumps */ |
65 |
int mem_index; /* select memory access functions */ |
66 |
struct TranslationBlock *tb;
|
67 |
int popl_esp_hack; /* for correct popl with esp base handling */ |
68 |
} DisasContext; |
69 |
|
70 |
static void gen_eob(DisasContext *s); |
71 |
static void gen_jmp(DisasContext *s, unsigned int eip); |
72 |
|
73 |
/* i386 arith/logic operations */
|
74 |
enum {
|
75 |
OP_ADDL, |
76 |
OP_ORL, |
77 |
OP_ADCL, |
78 |
OP_SBBL, |
79 |
OP_ANDL, |
80 |
OP_SUBL, |
81 |
OP_XORL, |
82 |
OP_CMPL, |
83 |
}; |
84 |
|
85 |
/* i386 shift ops */
|
86 |
enum {
|
87 |
OP_ROL, |
88 |
OP_ROR, |
89 |
OP_RCL, |
90 |
OP_RCR, |
91 |
OP_SHL, |
92 |
OP_SHR, |
93 |
OP_SHL1, /* undocumented */
|
94 |
OP_SAR = 7,
|
95 |
}; |
96 |
|
97 |
enum {
|
98 |
#define DEF(s, n, copy_size) INDEX_op_ ## s, |
99 |
#include "opc.h" |
100 |
#undef DEF
|
101 |
NB_OPS, |
102 |
}; |
103 |
|
104 |
#include "gen-op.h" |
105 |
|
106 |
/* operand size */
|
107 |
enum {
|
108 |
OT_BYTE = 0,
|
109 |
OT_WORD, |
110 |
OT_LONG, |
111 |
OT_QUAD, |
112 |
}; |
113 |
|
114 |
enum {
|
115 |
/* I386 int registers */
|
116 |
OR_EAX, /* MUST be even numbered */
|
117 |
OR_ECX, |
118 |
OR_EDX, |
119 |
OR_EBX, |
120 |
OR_ESP, |
121 |
OR_EBP, |
122 |
OR_ESI, |
123 |
OR_EDI, |
124 |
OR_TMP0, /* temporary operand register */
|
125 |
OR_TMP1, |
126 |
OR_A0, /* temporary register used when doing address evaluation */
|
127 |
OR_ZERO, /* fixed zero register */
|
128 |
NB_OREGS, |
129 |
}; |
130 |
|
131 |
typedef void (GenOpFunc)(void); |
132 |
typedef void (GenOpFunc1)(long); |
133 |
typedef void (GenOpFunc2)(long, long); |
134 |
typedef void (GenOpFunc3)(long, long, long); |
135 |
|
136 |
static GenOpFunc *gen_op_mov_reg_T0[3][8] = { |
137 |
[OT_BYTE] = { |
138 |
gen_op_movb_EAX_T0, |
139 |
gen_op_movb_ECX_T0, |
140 |
gen_op_movb_EDX_T0, |
141 |
gen_op_movb_EBX_T0, |
142 |
gen_op_movh_EAX_T0, |
143 |
gen_op_movh_ECX_T0, |
144 |
gen_op_movh_EDX_T0, |
145 |
gen_op_movh_EBX_T0, |
146 |
}, |
147 |
[OT_WORD] = { |
148 |
gen_op_movw_EAX_T0, |
149 |
gen_op_movw_ECX_T0, |
150 |
gen_op_movw_EDX_T0, |
151 |
gen_op_movw_EBX_T0, |
152 |
gen_op_movw_ESP_T0, |
153 |
gen_op_movw_EBP_T0, |
154 |
gen_op_movw_ESI_T0, |
155 |
gen_op_movw_EDI_T0, |
156 |
}, |
157 |
[OT_LONG] = { |
158 |
gen_op_movl_EAX_T0, |
159 |
gen_op_movl_ECX_T0, |
160 |
gen_op_movl_EDX_T0, |
161 |
gen_op_movl_EBX_T0, |
162 |
gen_op_movl_ESP_T0, |
163 |
gen_op_movl_EBP_T0, |
164 |
gen_op_movl_ESI_T0, |
165 |
gen_op_movl_EDI_T0, |
166 |
}, |
167 |
}; |
168 |
|
169 |
static GenOpFunc *gen_op_mov_reg_T1[3][8] = { |
170 |
[OT_BYTE] = { |
171 |
gen_op_movb_EAX_T1, |
172 |
gen_op_movb_ECX_T1, |
173 |
gen_op_movb_EDX_T1, |
174 |
gen_op_movb_EBX_T1, |
175 |
gen_op_movh_EAX_T1, |
176 |
gen_op_movh_ECX_T1, |
177 |
gen_op_movh_EDX_T1, |
178 |
gen_op_movh_EBX_T1, |
179 |
}, |
180 |
[OT_WORD] = { |
181 |
gen_op_movw_EAX_T1, |
182 |
gen_op_movw_ECX_T1, |
183 |
gen_op_movw_EDX_T1, |
184 |
gen_op_movw_EBX_T1, |
185 |
gen_op_movw_ESP_T1, |
186 |
gen_op_movw_EBP_T1, |
187 |
gen_op_movw_ESI_T1, |
188 |
gen_op_movw_EDI_T1, |
189 |
}, |
190 |
[OT_LONG] = { |
191 |
gen_op_movl_EAX_T1, |
192 |
gen_op_movl_ECX_T1, |
193 |
gen_op_movl_EDX_T1, |
194 |
gen_op_movl_EBX_T1, |
195 |
gen_op_movl_ESP_T1, |
196 |
gen_op_movl_EBP_T1, |
197 |
gen_op_movl_ESI_T1, |
198 |
gen_op_movl_EDI_T1, |
199 |
}, |
200 |
}; |
201 |
|
202 |
static GenOpFunc *gen_op_mov_reg_A0[2][8] = { |
203 |
[0] = {
|
204 |
gen_op_movw_EAX_A0, |
205 |
gen_op_movw_ECX_A0, |
206 |
gen_op_movw_EDX_A0, |
207 |
gen_op_movw_EBX_A0, |
208 |
gen_op_movw_ESP_A0, |
209 |
gen_op_movw_EBP_A0, |
210 |
gen_op_movw_ESI_A0, |
211 |
gen_op_movw_EDI_A0, |
212 |
}, |
213 |
[1] = {
|
214 |
gen_op_movl_EAX_A0, |
215 |
gen_op_movl_ECX_A0, |
216 |
gen_op_movl_EDX_A0, |
217 |
gen_op_movl_EBX_A0, |
218 |
gen_op_movl_ESP_A0, |
219 |
gen_op_movl_EBP_A0, |
220 |
gen_op_movl_ESI_A0, |
221 |
gen_op_movl_EDI_A0, |
222 |
}, |
223 |
}; |
224 |
|
225 |
static GenOpFunc *gen_op_mov_TN_reg[3][2][8] = |
226 |
{ |
227 |
[OT_BYTE] = { |
228 |
{ |
229 |
gen_op_movl_T0_EAX, |
230 |
gen_op_movl_T0_ECX, |
231 |
gen_op_movl_T0_EDX, |
232 |
gen_op_movl_T0_EBX, |
233 |
gen_op_movh_T0_EAX, |
234 |
gen_op_movh_T0_ECX, |
235 |
gen_op_movh_T0_EDX, |
236 |
gen_op_movh_T0_EBX, |
237 |
}, |
238 |
{ |
239 |
gen_op_movl_T1_EAX, |
240 |
gen_op_movl_T1_ECX, |
241 |
gen_op_movl_T1_EDX, |
242 |
gen_op_movl_T1_EBX, |
243 |
gen_op_movh_T1_EAX, |
244 |
gen_op_movh_T1_ECX, |
245 |
gen_op_movh_T1_EDX, |
246 |
gen_op_movh_T1_EBX, |
247 |
}, |
248 |
}, |
249 |
[OT_WORD] = { |
250 |
{ |
251 |
gen_op_movl_T0_EAX, |
252 |
gen_op_movl_T0_ECX, |
253 |
gen_op_movl_T0_EDX, |
254 |
gen_op_movl_T0_EBX, |
255 |
gen_op_movl_T0_ESP, |
256 |
gen_op_movl_T0_EBP, |
257 |
gen_op_movl_T0_ESI, |
258 |
gen_op_movl_T0_EDI, |
259 |
}, |
260 |
{ |
261 |
gen_op_movl_T1_EAX, |
262 |
gen_op_movl_T1_ECX, |
263 |
gen_op_movl_T1_EDX, |
264 |
gen_op_movl_T1_EBX, |
265 |
gen_op_movl_T1_ESP, |
266 |
gen_op_movl_T1_EBP, |
267 |
gen_op_movl_T1_ESI, |
268 |
gen_op_movl_T1_EDI, |
269 |
}, |
270 |
}, |
271 |
[OT_LONG] = { |
272 |
{ |
273 |
gen_op_movl_T0_EAX, |
274 |
gen_op_movl_T0_ECX, |
275 |
gen_op_movl_T0_EDX, |
276 |
gen_op_movl_T0_EBX, |
277 |
gen_op_movl_T0_ESP, |
278 |
gen_op_movl_T0_EBP, |
279 |
gen_op_movl_T0_ESI, |
280 |
gen_op_movl_T0_EDI, |
281 |
}, |
282 |
{ |
283 |
gen_op_movl_T1_EAX, |
284 |
gen_op_movl_T1_ECX, |
285 |
gen_op_movl_T1_EDX, |
286 |
gen_op_movl_T1_EBX, |
287 |
gen_op_movl_T1_ESP, |
288 |
gen_op_movl_T1_EBP, |
289 |
gen_op_movl_T1_ESI, |
290 |
gen_op_movl_T1_EDI, |
291 |
}, |
292 |
}, |
293 |
}; |
294 |
|
295 |
static GenOpFunc *gen_op_movl_A0_reg[8] = { |
296 |
gen_op_movl_A0_EAX, |
297 |
gen_op_movl_A0_ECX, |
298 |
gen_op_movl_A0_EDX, |
299 |
gen_op_movl_A0_EBX, |
300 |
gen_op_movl_A0_ESP, |
301 |
gen_op_movl_A0_EBP, |
302 |
gen_op_movl_A0_ESI, |
303 |
gen_op_movl_A0_EDI, |
304 |
}; |
305 |
|
306 |
static GenOpFunc *gen_op_addl_A0_reg_sN[4][8] = { |
307 |
[0] = {
|
308 |
gen_op_addl_A0_EAX, |
309 |
gen_op_addl_A0_ECX, |
310 |
gen_op_addl_A0_EDX, |
311 |
gen_op_addl_A0_EBX, |
312 |
gen_op_addl_A0_ESP, |
313 |
gen_op_addl_A0_EBP, |
314 |
gen_op_addl_A0_ESI, |
315 |
gen_op_addl_A0_EDI, |
316 |
}, |
317 |
[1] = {
|
318 |
gen_op_addl_A0_EAX_s1, |
319 |
gen_op_addl_A0_ECX_s1, |
320 |
gen_op_addl_A0_EDX_s1, |
321 |
gen_op_addl_A0_EBX_s1, |
322 |
gen_op_addl_A0_ESP_s1, |
323 |
gen_op_addl_A0_EBP_s1, |
324 |
gen_op_addl_A0_ESI_s1, |
325 |
gen_op_addl_A0_EDI_s1, |
326 |
}, |
327 |
[2] = {
|
328 |
gen_op_addl_A0_EAX_s2, |
329 |
gen_op_addl_A0_ECX_s2, |
330 |
gen_op_addl_A0_EDX_s2, |
331 |
gen_op_addl_A0_EBX_s2, |
332 |
gen_op_addl_A0_ESP_s2, |
333 |
gen_op_addl_A0_EBP_s2, |
334 |
gen_op_addl_A0_ESI_s2, |
335 |
gen_op_addl_A0_EDI_s2, |
336 |
}, |
337 |
[3] = {
|
338 |
gen_op_addl_A0_EAX_s3, |
339 |
gen_op_addl_A0_ECX_s3, |
340 |
gen_op_addl_A0_EDX_s3, |
341 |
gen_op_addl_A0_EBX_s3, |
342 |
gen_op_addl_A0_ESP_s3, |
343 |
gen_op_addl_A0_EBP_s3, |
344 |
gen_op_addl_A0_ESI_s3, |
345 |
gen_op_addl_A0_EDI_s3, |
346 |
}, |
347 |
}; |
348 |
|
349 |
static GenOpFunc *gen_op_cmov_reg_T1_T0[2][8] = { |
350 |
[0] = {
|
351 |
gen_op_cmovw_EAX_T1_T0, |
352 |
gen_op_cmovw_ECX_T1_T0, |
353 |
gen_op_cmovw_EDX_T1_T0, |
354 |
gen_op_cmovw_EBX_T1_T0, |
355 |
gen_op_cmovw_ESP_T1_T0, |
356 |
gen_op_cmovw_EBP_T1_T0, |
357 |
gen_op_cmovw_ESI_T1_T0, |
358 |
gen_op_cmovw_EDI_T1_T0, |
359 |
}, |
360 |
[1] = {
|
361 |
gen_op_cmovl_EAX_T1_T0, |
362 |
gen_op_cmovl_ECX_T1_T0, |
363 |
gen_op_cmovl_EDX_T1_T0, |
364 |
gen_op_cmovl_EBX_T1_T0, |
365 |
gen_op_cmovl_ESP_T1_T0, |
366 |
gen_op_cmovl_EBP_T1_T0, |
367 |
gen_op_cmovl_ESI_T1_T0, |
368 |
gen_op_cmovl_EDI_T1_T0, |
369 |
}, |
370 |
}; |
371 |
|
372 |
static GenOpFunc *gen_op_arith_T0_T1_cc[8] = { |
373 |
NULL,
|
374 |
gen_op_orl_T0_T1, |
375 |
NULL,
|
376 |
NULL,
|
377 |
gen_op_andl_T0_T1, |
378 |
NULL,
|
379 |
gen_op_xorl_T0_T1, |
380 |
NULL,
|
381 |
}; |
382 |
|
383 |
#define DEF_ARITHC(SUFFIX)\
|
384 |
{\ |
385 |
gen_op_adcb ## SUFFIX ## _T0_T1_cc,\ |
386 |
gen_op_sbbb ## SUFFIX ## _T0_T1_cc,\ |
387 |
},\ |
388 |
{\ |
389 |
gen_op_adcw ## SUFFIX ## _T0_T1_cc,\ |
390 |
gen_op_sbbw ## SUFFIX ## _T0_T1_cc,\ |
391 |
},\ |
392 |
{\ |
393 |
gen_op_adcl ## SUFFIX ## _T0_T1_cc,\ |
394 |
gen_op_sbbl ## SUFFIX ## _T0_T1_cc,\ |
395 |
}, |
396 |
|
397 |
static GenOpFunc *gen_op_arithc_T0_T1_cc[3][2] = { |
398 |
DEF_ARITHC() |
399 |
}; |
400 |
|
401 |
static GenOpFunc *gen_op_arithc_mem_T0_T1_cc[9][2] = { |
402 |
DEF_ARITHC(_raw) |
403 |
#ifndef CONFIG_USER_ONLY
|
404 |
DEF_ARITHC(_kernel) |
405 |
DEF_ARITHC(_user) |
406 |
#endif
|
407 |
}; |
408 |
|
409 |
static const int cc_op_arithb[8] = { |
410 |
CC_OP_ADDB, |
411 |
CC_OP_LOGICB, |
412 |
CC_OP_ADDB, |
413 |
CC_OP_SUBB, |
414 |
CC_OP_LOGICB, |
415 |
CC_OP_SUBB, |
416 |
CC_OP_LOGICB, |
417 |
CC_OP_SUBB, |
418 |
}; |
419 |
|
420 |
#define DEF_CMPXCHG(SUFFIX)\
|
421 |
gen_op_cmpxchgb ## SUFFIX ## _T0_T1_EAX_cc,\ |
422 |
gen_op_cmpxchgw ## SUFFIX ## _T0_T1_EAX_cc,\ |
423 |
gen_op_cmpxchgl ## SUFFIX ## _T0_T1_EAX_cc, |
424 |
|
425 |
|
426 |
static GenOpFunc *gen_op_cmpxchg_T0_T1_EAX_cc[3] = { |
427 |
DEF_CMPXCHG() |
428 |
}; |
429 |
|
430 |
static GenOpFunc *gen_op_cmpxchg_mem_T0_T1_EAX_cc[9] = { |
431 |
DEF_CMPXCHG(_raw) |
432 |
#ifndef CONFIG_USER_ONLY
|
433 |
DEF_CMPXCHG(_kernel) |
434 |
DEF_CMPXCHG(_user) |
435 |
#endif
|
436 |
}; |
437 |
|
438 |
#define DEF_SHIFT(SUFFIX)\
|
439 |
{\ |
440 |
gen_op_rolb ## SUFFIX ## _T0_T1_cc,\ |
441 |
gen_op_rorb ## SUFFIX ## _T0_T1_cc,\ |
442 |
gen_op_rclb ## SUFFIX ## _T0_T1_cc,\ |
443 |
gen_op_rcrb ## SUFFIX ## _T0_T1_cc,\ |
444 |
gen_op_shlb ## SUFFIX ## _T0_T1_cc,\ |
445 |
gen_op_shrb ## SUFFIX ## _T0_T1_cc,\ |
446 |
gen_op_shlb ## SUFFIX ## _T0_T1_cc,\ |
447 |
gen_op_sarb ## SUFFIX ## _T0_T1_cc,\ |
448 |
},\ |
449 |
{\ |
450 |
gen_op_rolw ## SUFFIX ## _T0_T1_cc,\ |
451 |
gen_op_rorw ## SUFFIX ## _T0_T1_cc,\ |
452 |
gen_op_rclw ## SUFFIX ## _T0_T1_cc,\ |
453 |
gen_op_rcrw ## SUFFIX ## _T0_T1_cc,\ |
454 |
gen_op_shlw ## SUFFIX ## _T0_T1_cc,\ |
455 |
gen_op_shrw ## SUFFIX ## _T0_T1_cc,\ |
456 |
gen_op_shlw ## SUFFIX ## _T0_T1_cc,\ |
457 |
gen_op_sarw ## SUFFIX ## _T0_T1_cc,\ |
458 |
},\ |
459 |
{\ |
460 |
gen_op_roll ## SUFFIX ## _T0_T1_cc,\ |
461 |
gen_op_rorl ## SUFFIX ## _T0_T1_cc,\ |
462 |
gen_op_rcll ## SUFFIX ## _T0_T1_cc,\ |
463 |
gen_op_rcrl ## SUFFIX ## _T0_T1_cc,\ |
464 |
gen_op_shll ## SUFFIX ## _T0_T1_cc,\ |
465 |
gen_op_shrl ## SUFFIX ## _T0_T1_cc,\ |
466 |
gen_op_shll ## SUFFIX ## _T0_T1_cc,\ |
467 |
gen_op_sarl ## SUFFIX ## _T0_T1_cc,\ |
468 |
}, |
469 |
|
470 |
static GenOpFunc *gen_op_shift_T0_T1_cc[3][8] = { |
471 |
DEF_SHIFT() |
472 |
}; |
473 |
|
474 |
static GenOpFunc *gen_op_shift_mem_T0_T1_cc[9][8] = { |
475 |
DEF_SHIFT(_raw) |
476 |
#ifndef CONFIG_USER_ONLY
|
477 |
DEF_SHIFT(_kernel) |
478 |
DEF_SHIFT(_user) |
479 |
#endif
|
480 |
}; |
481 |
|
482 |
#define DEF_SHIFTD(SUFFIX, op)\
|
483 |
{\ |
484 |
NULL,\
|
485 |
NULL,\
|
486 |
},\ |
487 |
{\ |
488 |
gen_op_shldw ## SUFFIX ## _T0_T1_ ## op ## _cc,\ |
489 |
gen_op_shrdw ## SUFFIX ## _T0_T1_ ## op ## _cc,\ |
490 |
},\ |
491 |
{\ |
492 |
gen_op_shldl ## SUFFIX ## _T0_T1_ ## op ## _cc,\ |
493 |
gen_op_shrdl ## SUFFIX ## _T0_T1_ ## op ## _cc,\ |
494 |
}, |
495 |
|
496 |
|
497 |
static GenOpFunc1 *gen_op_shiftd_T0_T1_im_cc[3][2] = { |
498 |
DEF_SHIFTD(, im) |
499 |
}; |
500 |
|
501 |
static GenOpFunc *gen_op_shiftd_T0_T1_ECX_cc[3][2] = { |
502 |
DEF_SHIFTD(, ECX) |
503 |
}; |
504 |
|
505 |
static GenOpFunc1 *gen_op_shiftd_mem_T0_T1_im_cc[9][2] = { |
506 |
DEF_SHIFTD(_raw, im) |
507 |
#ifndef CONFIG_USER_ONLY
|
508 |
DEF_SHIFTD(_kernel, im) |
509 |
DEF_SHIFTD(_user, im) |
510 |
#endif
|
511 |
}; |
512 |
|
513 |
static GenOpFunc *gen_op_shiftd_mem_T0_T1_ECX_cc[9][2] = { |
514 |
DEF_SHIFTD(_raw, ECX) |
515 |
#ifndef CONFIG_USER_ONLY
|
516 |
DEF_SHIFTD(_kernel, ECX) |
517 |
DEF_SHIFTD(_user, ECX) |
518 |
#endif
|
519 |
}; |
520 |
|
521 |
static GenOpFunc *gen_op_btx_T0_T1_cc[2][4] = { |
522 |
[0] = {
|
523 |
gen_op_btw_T0_T1_cc, |
524 |
gen_op_btsw_T0_T1_cc, |
525 |
gen_op_btrw_T0_T1_cc, |
526 |
gen_op_btcw_T0_T1_cc, |
527 |
}, |
528 |
[1] = {
|
529 |
gen_op_btl_T0_T1_cc, |
530 |
gen_op_btsl_T0_T1_cc, |
531 |
gen_op_btrl_T0_T1_cc, |
532 |
gen_op_btcl_T0_T1_cc, |
533 |
}, |
534 |
}; |
535 |
|
536 |
static GenOpFunc *gen_op_bsx_T0_cc[2][2] = { |
537 |
[0] = {
|
538 |
gen_op_bsfw_T0_cc, |
539 |
gen_op_bsrw_T0_cc, |
540 |
}, |
541 |
[1] = {
|
542 |
gen_op_bsfl_T0_cc, |
543 |
gen_op_bsrl_T0_cc, |
544 |
}, |
545 |
}; |
546 |
|
547 |
static GenOpFunc *gen_op_lds_T0_A0[3 * 3] = { |
548 |
gen_op_ldsb_raw_T0_A0, |
549 |
gen_op_ldsw_raw_T0_A0, |
550 |
NULL,
|
551 |
#ifndef CONFIG_USER_ONLY
|
552 |
gen_op_ldsb_kernel_T0_A0, |
553 |
gen_op_ldsw_kernel_T0_A0, |
554 |
NULL,
|
555 |
|
556 |
gen_op_ldsb_user_T0_A0, |
557 |
gen_op_ldsw_user_T0_A0, |
558 |
NULL,
|
559 |
#endif
|
560 |
}; |
561 |
|
562 |
static GenOpFunc *gen_op_ldu_T0_A0[3 * 3] = { |
563 |
gen_op_ldub_raw_T0_A0, |
564 |
gen_op_lduw_raw_T0_A0, |
565 |
NULL,
|
566 |
|
567 |
#ifndef CONFIG_USER_ONLY
|
568 |
gen_op_ldub_kernel_T0_A0, |
569 |
gen_op_lduw_kernel_T0_A0, |
570 |
NULL,
|
571 |
|
572 |
gen_op_ldub_user_T0_A0, |
573 |
gen_op_lduw_user_T0_A0, |
574 |
NULL,
|
575 |
#endif
|
576 |
}; |
577 |
|
578 |
/* sign does not matter, except for lidt/lgdt call (TODO: fix it) */
|
579 |
static GenOpFunc *gen_op_ld_T0_A0[3 * 3] = { |
580 |
gen_op_ldub_raw_T0_A0, |
581 |
gen_op_lduw_raw_T0_A0, |
582 |
gen_op_ldl_raw_T0_A0, |
583 |
|
584 |
#ifndef CONFIG_USER_ONLY
|
585 |
gen_op_ldub_kernel_T0_A0, |
586 |
gen_op_lduw_kernel_T0_A0, |
587 |
gen_op_ldl_kernel_T0_A0, |
588 |
|
589 |
gen_op_ldub_user_T0_A0, |
590 |
gen_op_lduw_user_T0_A0, |
591 |
gen_op_ldl_user_T0_A0, |
592 |
#endif
|
593 |
}; |
594 |
|
595 |
static GenOpFunc *gen_op_ld_T1_A0[3 * 3] = { |
596 |
gen_op_ldub_raw_T1_A0, |
597 |
gen_op_lduw_raw_T1_A0, |
598 |
gen_op_ldl_raw_T1_A0, |
599 |
|
600 |
#ifndef CONFIG_USER_ONLY
|
601 |
gen_op_ldub_kernel_T1_A0, |
602 |
gen_op_lduw_kernel_T1_A0, |
603 |
gen_op_ldl_kernel_T1_A0, |
604 |
|
605 |
gen_op_ldub_user_T1_A0, |
606 |
gen_op_lduw_user_T1_A0, |
607 |
gen_op_ldl_user_T1_A0, |
608 |
#endif
|
609 |
}; |
610 |
|
611 |
static GenOpFunc *gen_op_st_T0_A0[3 * 3] = { |
612 |
gen_op_stb_raw_T0_A0, |
613 |
gen_op_stw_raw_T0_A0, |
614 |
gen_op_stl_raw_T0_A0, |
615 |
|
616 |
#ifndef CONFIG_USER_ONLY
|
617 |
gen_op_stb_kernel_T0_A0, |
618 |
gen_op_stw_kernel_T0_A0, |
619 |
gen_op_stl_kernel_T0_A0, |
620 |
|
621 |
gen_op_stb_user_T0_A0, |
622 |
gen_op_stw_user_T0_A0, |
623 |
gen_op_stl_user_T0_A0, |
624 |
#endif
|
625 |
}; |
626 |
|
627 |
static GenOpFunc *gen_op_st_T1_A0[3 * 3] = { |
628 |
NULL,
|
629 |
gen_op_stw_raw_T1_A0, |
630 |
gen_op_stl_raw_T1_A0, |
631 |
|
632 |
#ifndef CONFIG_USER_ONLY
|
633 |
NULL,
|
634 |
gen_op_stw_kernel_T1_A0, |
635 |
gen_op_stl_kernel_T1_A0, |
636 |
|
637 |
NULL,
|
638 |
gen_op_stw_user_T1_A0, |
639 |
gen_op_stl_user_T1_A0, |
640 |
#endif
|
641 |
}; |
642 |
|
643 |
static inline void gen_string_movl_A0_ESI(DisasContext *s) |
644 |
{ |
645 |
int override;
|
646 |
|
647 |
override = s->override; |
648 |
if (s->aflag) {
|
649 |
/* 32 bit address */
|
650 |
if (s->addseg && override < 0) |
651 |
override = R_DS; |
652 |
if (override >= 0) { |
653 |
gen_op_movl_A0_seg(offsetof(CPUX86State,segs[override].base)); |
654 |
gen_op_addl_A0_reg_sN[0][R_ESI]();
|
655 |
} else {
|
656 |
gen_op_movl_A0_reg[R_ESI](); |
657 |
} |
658 |
} else {
|
659 |
/* 16 address, always override */
|
660 |
if (override < 0) |
661 |
override = R_DS; |
662 |
gen_op_movl_A0_reg[R_ESI](); |
663 |
gen_op_andl_A0_ffff(); |
664 |
gen_op_addl_A0_seg(offsetof(CPUX86State,segs[override].base)); |
665 |
} |
666 |
} |
667 |
|
668 |
static inline void gen_string_movl_A0_EDI(DisasContext *s) |
669 |
{ |
670 |
if (s->aflag) {
|
671 |
if (s->addseg) {
|
672 |
gen_op_movl_A0_seg(offsetof(CPUX86State,segs[R_ES].base)); |
673 |
gen_op_addl_A0_reg_sN[0][R_EDI]();
|
674 |
} else {
|
675 |
gen_op_movl_A0_reg[R_EDI](); |
676 |
} |
677 |
} else {
|
678 |
gen_op_movl_A0_reg[R_EDI](); |
679 |
gen_op_andl_A0_ffff(); |
680 |
gen_op_addl_A0_seg(offsetof(CPUX86State,segs[R_ES].base)); |
681 |
} |
682 |
} |
683 |
|
684 |
static GenOpFunc *gen_op_movl_T0_Dshift[3] = { |
685 |
gen_op_movl_T0_Dshiftb, |
686 |
gen_op_movl_T0_Dshiftw, |
687 |
gen_op_movl_T0_Dshiftl, |
688 |
}; |
689 |
|
690 |
static GenOpFunc2 *gen_op_jz_ecx[2] = { |
691 |
gen_op_jz_ecxw, |
692 |
gen_op_jz_ecxl, |
693 |
}; |
694 |
|
695 |
static GenOpFunc1 *gen_op_jz_ecx_im[2] = { |
696 |
gen_op_jz_ecxw_im, |
697 |
gen_op_jz_ecxl_im, |
698 |
}; |
699 |
|
700 |
static GenOpFunc *gen_op_dec_ECX[2] = { |
701 |
gen_op_decw_ECX, |
702 |
gen_op_decl_ECX, |
703 |
}; |
704 |
|
705 |
static GenOpFunc1 *gen_op_string_jnz_sub[2][3] = { |
706 |
{ |
707 |
gen_op_string_jnz_subb, |
708 |
gen_op_string_jnz_subw, |
709 |
gen_op_string_jnz_subl, |
710 |
}, |
711 |
{ |
712 |
gen_op_string_jz_subb, |
713 |
gen_op_string_jz_subw, |
714 |
gen_op_string_jz_subl, |
715 |
}, |
716 |
}; |
717 |
|
718 |
static GenOpFunc1 *gen_op_string_jnz_sub_im[2][3] = { |
719 |
{ |
720 |
gen_op_string_jnz_subb_im, |
721 |
gen_op_string_jnz_subw_im, |
722 |
gen_op_string_jnz_subl_im, |
723 |
}, |
724 |
{ |
725 |
gen_op_string_jz_subb_im, |
726 |
gen_op_string_jz_subw_im, |
727 |
gen_op_string_jz_subl_im, |
728 |
}, |
729 |
}; |
730 |
|
731 |
static GenOpFunc *gen_op_in_DX_T0[3] = { |
732 |
gen_op_inb_DX_T0, |
733 |
gen_op_inw_DX_T0, |
734 |
gen_op_inl_DX_T0, |
735 |
}; |
736 |
|
737 |
static GenOpFunc *gen_op_out_DX_T0[3] = { |
738 |
gen_op_outb_DX_T0, |
739 |
gen_op_outw_DX_T0, |
740 |
gen_op_outl_DX_T0, |
741 |
}; |
742 |
|
743 |
static GenOpFunc *gen_op_in[3] = { |
744 |
gen_op_inb_T0_T1, |
745 |
gen_op_inw_T0_T1, |
746 |
gen_op_inl_T0_T1, |
747 |
}; |
748 |
|
749 |
static GenOpFunc *gen_op_out[3] = { |
750 |
gen_op_outb_T0_T1, |
751 |
gen_op_outw_T0_T1, |
752 |
gen_op_outl_T0_T1, |
753 |
}; |
754 |
|
755 |
static GenOpFunc *gen_check_io_T0[3] = { |
756 |
gen_op_check_iob_T0, |
757 |
gen_op_check_iow_T0, |
758 |
gen_op_check_iol_T0, |
759 |
}; |
760 |
|
761 |
static GenOpFunc *gen_check_io_DX[3] = { |
762 |
gen_op_check_iob_DX, |
763 |
gen_op_check_iow_DX, |
764 |
gen_op_check_iol_DX, |
765 |
}; |
766 |
|
767 |
static void gen_check_io(DisasContext *s, int ot, int use_dx, int cur_eip) |
768 |
{ |
769 |
if (s->pe && (s->cpl > s->iopl || s->vm86)) {
|
770 |
if (s->cc_op != CC_OP_DYNAMIC)
|
771 |
gen_op_set_cc_op(s->cc_op); |
772 |
gen_op_jmp_im(cur_eip); |
773 |
if (use_dx)
|
774 |
gen_check_io_DX[ot](); |
775 |
else
|
776 |
gen_check_io_T0[ot](); |
777 |
} |
778 |
} |
779 |
|
780 |
static inline void gen_movs(DisasContext *s, int ot) |
781 |
{ |
782 |
gen_string_movl_A0_ESI(s); |
783 |
gen_op_ld_T0_A0[ot + s->mem_index](); |
784 |
gen_string_movl_A0_EDI(s); |
785 |
gen_op_st_T0_A0[ot + s->mem_index](); |
786 |
gen_op_movl_T0_Dshift[ot](); |
787 |
if (s->aflag) {
|
788 |
gen_op_addl_ESI_T0(); |
789 |
gen_op_addl_EDI_T0(); |
790 |
} else {
|
791 |
gen_op_addw_ESI_T0(); |
792 |
gen_op_addw_EDI_T0(); |
793 |
} |
794 |
} |
795 |
|
796 |
static inline void gen_update_cc_op(DisasContext *s) |
797 |
{ |
798 |
if (s->cc_op != CC_OP_DYNAMIC) {
|
799 |
gen_op_set_cc_op(s->cc_op); |
800 |
s->cc_op = CC_OP_DYNAMIC; |
801 |
} |
802 |
} |
803 |
|
804 |
static inline void gen_jz_ecx_string(DisasContext *s, unsigned int next_eip) |
805 |
{ |
806 |
if (s->jmp_opt) {
|
807 |
gen_op_jz_ecx[s->aflag]((long)s->tb, next_eip);
|
808 |
} else {
|
809 |
/* XXX: does not work with gdbstub "ice" single step - not a
|
810 |
serious problem */
|
811 |
gen_op_jz_ecx_im[s->aflag](next_eip); |
812 |
} |
813 |
} |
814 |
|
815 |
static inline void gen_stos(DisasContext *s, int ot) |
816 |
{ |
817 |
gen_op_mov_TN_reg[OT_LONG][0][R_EAX]();
|
818 |
gen_string_movl_A0_EDI(s); |
819 |
gen_op_st_T0_A0[ot + s->mem_index](); |
820 |
gen_op_movl_T0_Dshift[ot](); |
821 |
if (s->aflag) {
|
822 |
gen_op_addl_EDI_T0(); |
823 |
} else {
|
824 |
gen_op_addw_EDI_T0(); |
825 |
} |
826 |
} |
827 |
|
828 |
static inline void gen_lods(DisasContext *s, int ot) |
829 |
{ |
830 |
gen_string_movl_A0_ESI(s); |
831 |
gen_op_ld_T0_A0[ot + s->mem_index](); |
832 |
gen_op_mov_reg_T0[ot][R_EAX](); |
833 |
gen_op_movl_T0_Dshift[ot](); |
834 |
if (s->aflag) {
|
835 |
gen_op_addl_ESI_T0(); |
836 |
} else {
|
837 |
gen_op_addw_ESI_T0(); |
838 |
} |
839 |
} |
840 |
|
841 |
static inline void gen_scas(DisasContext *s, int ot) |
842 |
{ |
843 |
gen_op_mov_TN_reg[OT_LONG][0][R_EAX]();
|
844 |
gen_string_movl_A0_EDI(s); |
845 |
gen_op_ld_T1_A0[ot + s->mem_index](); |
846 |
gen_op_cmpl_T0_T1_cc(); |
847 |
gen_op_movl_T0_Dshift[ot](); |
848 |
if (s->aflag) {
|
849 |
gen_op_addl_EDI_T0(); |
850 |
} else {
|
851 |
gen_op_addw_EDI_T0(); |
852 |
} |
853 |
} |
854 |
|
855 |
static inline void gen_cmps(DisasContext *s, int ot) |
856 |
{ |
857 |
gen_string_movl_A0_ESI(s); |
858 |
gen_op_ld_T0_A0[ot + s->mem_index](); |
859 |
gen_string_movl_A0_EDI(s); |
860 |
gen_op_ld_T1_A0[ot + s->mem_index](); |
861 |
gen_op_cmpl_T0_T1_cc(); |
862 |
gen_op_movl_T0_Dshift[ot](); |
863 |
if (s->aflag) {
|
864 |
gen_op_addl_ESI_T0(); |
865 |
gen_op_addl_EDI_T0(); |
866 |
} else {
|
867 |
gen_op_addw_ESI_T0(); |
868 |
gen_op_addw_EDI_T0(); |
869 |
} |
870 |
} |
871 |
|
872 |
static inline void gen_ins(DisasContext *s, int ot) |
873 |
{ |
874 |
gen_op_in_DX_T0[ot](); |
875 |
gen_string_movl_A0_EDI(s); |
876 |
gen_op_st_T0_A0[ot + s->mem_index](); |
877 |
gen_op_movl_T0_Dshift[ot](); |
878 |
if (s->aflag) {
|
879 |
gen_op_addl_EDI_T0(); |
880 |
} else {
|
881 |
gen_op_addw_EDI_T0(); |
882 |
} |
883 |
} |
884 |
|
885 |
static inline void gen_outs(DisasContext *s, int ot) |
886 |
{ |
887 |
gen_string_movl_A0_ESI(s); |
888 |
gen_op_ld_T0_A0[ot + s->mem_index](); |
889 |
gen_op_out_DX_T0[ot](); |
890 |
gen_op_movl_T0_Dshift[ot](); |
891 |
if (s->aflag) {
|
892 |
gen_op_addl_ESI_T0(); |
893 |
} else {
|
894 |
gen_op_addw_ESI_T0(); |
895 |
} |
896 |
} |
897 |
|
898 |
/* same method as Valgrind : we generate jumps to current or next
|
899 |
instruction */
|
900 |
#define GEN_REPZ(op) \
|
901 |
static inline void gen_repz_ ## op(DisasContext *s, int ot, \ |
902 |
unsigned int cur_eip, unsigned int next_eip) \ |
903 |
{ \ |
904 |
gen_update_cc_op(s); \ |
905 |
gen_jz_ecx_string(s, next_eip); \ |
906 |
gen_ ## op(s, ot); \ |
907 |
gen_op_dec_ECX[s->aflag](); \ |
908 |
/* a loop would cause two single step exceptions if ECX = 1 \
|
909 |
before rep string_insn */ \
|
910 |
if (!s->jmp_opt) \
|
911 |
gen_op_jz_ecx_im[s->aflag](next_eip); \ |
912 |
gen_jmp(s, cur_eip); \ |
913 |
} |
914 |
|
915 |
#define GEN_REPZ2(op) \
|
916 |
static inline void gen_repz_ ## op(DisasContext *s, int ot, \ |
917 |
unsigned int cur_eip, \ |
918 |
unsigned int next_eip, \ |
919 |
int nz) \
|
920 |
{ \ |
921 |
gen_update_cc_op(s); \ |
922 |
gen_jz_ecx_string(s, next_eip); \ |
923 |
gen_ ## op(s, ot); \ |
924 |
gen_op_dec_ECX[s->aflag](); \ |
925 |
gen_op_set_cc_op(CC_OP_SUBB + ot); \ |
926 |
if (!s->jmp_opt) \
|
927 |
gen_op_string_jnz_sub_im[nz][ot](next_eip); \ |
928 |
else \
|
929 |
gen_op_string_jnz_sub[nz][ot]((long)s->tb); \
|
930 |
if (!s->jmp_opt) \
|
931 |
gen_op_jz_ecx_im[s->aflag](next_eip); \ |
932 |
gen_jmp(s, cur_eip); \ |
933 |
} |
934 |
|
935 |
GEN_REPZ(movs) |
936 |
GEN_REPZ(stos) |
937 |
GEN_REPZ(lods) |
938 |
GEN_REPZ(ins) |
939 |
GEN_REPZ(outs) |
940 |
GEN_REPZ2(scas) |
941 |
GEN_REPZ2(cmps) |
942 |
|
943 |
enum {
|
944 |
JCC_O, |
945 |
JCC_B, |
946 |
JCC_Z, |
947 |
JCC_BE, |
948 |
JCC_S, |
949 |
JCC_P, |
950 |
JCC_L, |
951 |
JCC_LE, |
952 |
}; |
953 |
|
954 |
static GenOpFunc3 *gen_jcc_sub[3][8] = { |
955 |
[OT_BYTE] = { |
956 |
NULL,
|
957 |
gen_op_jb_subb, |
958 |
gen_op_jz_subb, |
959 |
gen_op_jbe_subb, |
960 |
gen_op_js_subb, |
961 |
NULL,
|
962 |
gen_op_jl_subb, |
963 |
gen_op_jle_subb, |
964 |
}, |
965 |
[OT_WORD] = { |
966 |
NULL,
|
967 |
gen_op_jb_subw, |
968 |
gen_op_jz_subw, |
969 |
gen_op_jbe_subw, |
970 |
gen_op_js_subw, |
971 |
NULL,
|
972 |
gen_op_jl_subw, |
973 |
gen_op_jle_subw, |
974 |
}, |
975 |
[OT_LONG] = { |
976 |
NULL,
|
977 |
gen_op_jb_subl, |
978 |
gen_op_jz_subl, |
979 |
gen_op_jbe_subl, |
980 |
gen_op_js_subl, |
981 |
NULL,
|
982 |
gen_op_jl_subl, |
983 |
gen_op_jle_subl, |
984 |
}, |
985 |
}; |
986 |
static GenOpFunc2 *gen_op_loop[2][4] = { |
987 |
[0] = {
|
988 |
gen_op_loopnzw, |
989 |
gen_op_loopzw, |
990 |
gen_op_loopw, |
991 |
gen_op_jecxzw, |
992 |
}, |
993 |
[1] = {
|
994 |
gen_op_loopnzl, |
995 |
gen_op_loopzl, |
996 |
gen_op_loopl, |
997 |
gen_op_jecxzl, |
998 |
}, |
999 |
}; |
1000 |
|
1001 |
static GenOpFunc *gen_setcc_slow[8] = { |
1002 |
gen_op_seto_T0_cc, |
1003 |
gen_op_setb_T0_cc, |
1004 |
gen_op_setz_T0_cc, |
1005 |
gen_op_setbe_T0_cc, |
1006 |
gen_op_sets_T0_cc, |
1007 |
gen_op_setp_T0_cc, |
1008 |
gen_op_setl_T0_cc, |
1009 |
gen_op_setle_T0_cc, |
1010 |
}; |
1011 |
|
1012 |
static GenOpFunc *gen_setcc_sub[3][8] = { |
1013 |
[OT_BYTE] = { |
1014 |
NULL,
|
1015 |
gen_op_setb_T0_subb, |
1016 |
gen_op_setz_T0_subb, |
1017 |
gen_op_setbe_T0_subb, |
1018 |
gen_op_sets_T0_subb, |
1019 |
NULL,
|
1020 |
gen_op_setl_T0_subb, |
1021 |
gen_op_setle_T0_subb, |
1022 |
}, |
1023 |
[OT_WORD] = { |
1024 |
NULL,
|
1025 |
gen_op_setb_T0_subw, |
1026 |
gen_op_setz_T0_subw, |
1027 |
gen_op_setbe_T0_subw, |
1028 |
gen_op_sets_T0_subw, |
1029 |
NULL,
|
1030 |
gen_op_setl_T0_subw, |
1031 |
gen_op_setle_T0_subw, |
1032 |
}, |
1033 |
[OT_LONG] = { |
1034 |
NULL,
|
1035 |
gen_op_setb_T0_subl, |
1036 |
gen_op_setz_T0_subl, |
1037 |
gen_op_setbe_T0_subl, |
1038 |
gen_op_sets_T0_subl, |
1039 |
NULL,
|
1040 |
gen_op_setl_T0_subl, |
1041 |
gen_op_setle_T0_subl, |
1042 |
}, |
1043 |
}; |
1044 |
|
1045 |
static GenOpFunc *gen_op_fp_arith_ST0_FT0[8] = { |
1046 |
gen_op_fadd_ST0_FT0, |
1047 |
gen_op_fmul_ST0_FT0, |
1048 |
gen_op_fcom_ST0_FT0, |
1049 |
gen_op_fcom_ST0_FT0, |
1050 |
gen_op_fsub_ST0_FT0, |
1051 |
gen_op_fsubr_ST0_FT0, |
1052 |
gen_op_fdiv_ST0_FT0, |
1053 |
gen_op_fdivr_ST0_FT0, |
1054 |
}; |
1055 |
|
1056 |
/* NOTE the exception in "r" op ordering */
|
1057 |
static GenOpFunc1 *gen_op_fp_arith_STN_ST0[8] = { |
1058 |
gen_op_fadd_STN_ST0, |
1059 |
gen_op_fmul_STN_ST0, |
1060 |
NULL,
|
1061 |
NULL,
|
1062 |
gen_op_fsubr_STN_ST0, |
1063 |
gen_op_fsub_STN_ST0, |
1064 |
gen_op_fdivr_STN_ST0, |
1065 |
gen_op_fdiv_STN_ST0, |
1066 |
}; |
1067 |
|
1068 |
/* if d == OR_TMP0, it means memory operand (address in A0) */
|
1069 |
static void gen_op(DisasContext *s1, int op, int ot, int d) |
1070 |
{ |
1071 |
GenOpFunc *gen_update_cc; |
1072 |
|
1073 |
if (d != OR_TMP0) {
|
1074 |
gen_op_mov_TN_reg[ot][0][d]();
|
1075 |
} else {
|
1076 |
gen_op_ld_T0_A0[ot + s1->mem_index](); |
1077 |
} |
1078 |
switch(op) {
|
1079 |
case OP_ADCL:
|
1080 |
case OP_SBBL:
|
1081 |
if (s1->cc_op != CC_OP_DYNAMIC)
|
1082 |
gen_op_set_cc_op(s1->cc_op); |
1083 |
if (d != OR_TMP0) {
|
1084 |
gen_op_arithc_T0_T1_cc[ot][op - OP_ADCL](); |
1085 |
gen_op_mov_reg_T0[ot][d](); |
1086 |
} else {
|
1087 |
gen_op_arithc_mem_T0_T1_cc[ot + s1->mem_index][op - OP_ADCL](); |
1088 |
} |
1089 |
s1->cc_op = CC_OP_DYNAMIC; |
1090 |
goto the_end;
|
1091 |
case OP_ADDL:
|
1092 |
gen_op_addl_T0_T1(); |
1093 |
s1->cc_op = CC_OP_ADDB + ot; |
1094 |
gen_update_cc = gen_op_update2_cc; |
1095 |
break;
|
1096 |
case OP_SUBL:
|
1097 |
gen_op_subl_T0_T1(); |
1098 |
s1->cc_op = CC_OP_SUBB + ot; |
1099 |
gen_update_cc = gen_op_update2_cc; |
1100 |
break;
|
1101 |
default:
|
1102 |
case OP_ANDL:
|
1103 |
case OP_ORL:
|
1104 |
case OP_XORL:
|
1105 |
gen_op_arith_T0_T1_cc[op](); |
1106 |
s1->cc_op = CC_OP_LOGICB + ot; |
1107 |
gen_update_cc = gen_op_update1_cc; |
1108 |
break;
|
1109 |
case OP_CMPL:
|
1110 |
gen_op_cmpl_T0_T1_cc(); |
1111 |
s1->cc_op = CC_OP_SUBB + ot; |
1112 |
gen_update_cc = NULL;
|
1113 |
break;
|
1114 |
} |
1115 |
if (op != OP_CMPL) {
|
1116 |
if (d != OR_TMP0)
|
1117 |
gen_op_mov_reg_T0[ot][d](); |
1118 |
else
|
1119 |
gen_op_st_T0_A0[ot + s1->mem_index](); |
1120 |
} |
1121 |
/* the flags update must happen after the memory write (precise
|
1122 |
exception support) */
|
1123 |
if (gen_update_cc)
|
1124 |
gen_update_cc(); |
1125 |
the_end: ;
|
1126 |
} |
1127 |
|
1128 |
/* if d == OR_TMP0, it means memory operand (address in A0) */
|
1129 |
static void gen_inc(DisasContext *s1, int ot, int d, int c) |
1130 |
{ |
1131 |
if (d != OR_TMP0)
|
1132 |
gen_op_mov_TN_reg[ot][0][d]();
|
1133 |
else
|
1134 |
gen_op_ld_T0_A0[ot + s1->mem_index](); |
1135 |
if (s1->cc_op != CC_OP_DYNAMIC)
|
1136 |
gen_op_set_cc_op(s1->cc_op); |
1137 |
if (c > 0) { |
1138 |
gen_op_incl_T0(); |
1139 |
s1->cc_op = CC_OP_INCB + ot; |
1140 |
} else {
|
1141 |
gen_op_decl_T0(); |
1142 |
s1->cc_op = CC_OP_DECB + ot; |
1143 |
} |
1144 |
if (d != OR_TMP0)
|
1145 |
gen_op_mov_reg_T0[ot][d](); |
1146 |
else
|
1147 |
gen_op_st_T0_A0[ot + s1->mem_index](); |
1148 |
gen_op_update_inc_cc(); |
1149 |
} |
1150 |
|
1151 |
static void gen_shift(DisasContext *s1, int op, int ot, int d, int s) |
1152 |
{ |
1153 |
if (d != OR_TMP0)
|
1154 |
gen_op_mov_TN_reg[ot][0][d]();
|
1155 |
else
|
1156 |
gen_op_ld_T0_A0[ot + s1->mem_index](); |
1157 |
if (s != OR_TMP1)
|
1158 |
gen_op_mov_TN_reg[ot][1][s]();
|
1159 |
/* for zero counts, flags are not updated, so must do it dynamically */
|
1160 |
if (s1->cc_op != CC_OP_DYNAMIC)
|
1161 |
gen_op_set_cc_op(s1->cc_op); |
1162 |
|
1163 |
if (d != OR_TMP0)
|
1164 |
gen_op_shift_T0_T1_cc[ot][op](); |
1165 |
else
|
1166 |
gen_op_shift_mem_T0_T1_cc[ot + s1->mem_index][op](); |
1167 |
if (d != OR_TMP0)
|
1168 |
gen_op_mov_reg_T0[ot][d](); |
1169 |
s1->cc_op = CC_OP_DYNAMIC; /* cannot predict flags after */
|
1170 |
} |
1171 |
|
1172 |
static void gen_shifti(DisasContext *s1, int op, int ot, int d, int c) |
1173 |
{ |
1174 |
/* currently not optimized */
|
1175 |
gen_op_movl_T1_im(c); |
1176 |
gen_shift(s1, op, ot, d, OR_TMP1); |
1177 |
} |
1178 |
|
1179 |
static void gen_lea_modrm(DisasContext *s, int modrm, int *reg_ptr, int *offset_ptr) |
1180 |
{ |
1181 |
int havesib;
|
1182 |
int base, disp;
|
1183 |
int index;
|
1184 |
int scale;
|
1185 |
int opreg;
|
1186 |
int mod, rm, code, override, must_add_seg;
|
1187 |
|
1188 |
override = s->override; |
1189 |
must_add_seg = s->addseg; |
1190 |
if (override >= 0) |
1191 |
must_add_seg = 1;
|
1192 |
mod = (modrm >> 6) & 3; |
1193 |
rm = modrm & 7;
|
1194 |
|
1195 |
if (s->aflag) {
|
1196 |
|
1197 |
havesib = 0;
|
1198 |
base = rm; |
1199 |
index = 0;
|
1200 |
scale = 0;
|
1201 |
|
1202 |
if (base == 4) { |
1203 |
havesib = 1;
|
1204 |
code = ldub_code(s->pc++); |
1205 |
scale = (code >> 6) & 3; |
1206 |
index = (code >> 3) & 7; |
1207 |
base = code & 7;
|
1208 |
} |
1209 |
|
1210 |
switch (mod) {
|
1211 |
case 0: |
1212 |
if (base == 5) { |
1213 |
base = -1;
|
1214 |
disp = ldl_code(s->pc); |
1215 |
s->pc += 4;
|
1216 |
} else {
|
1217 |
disp = 0;
|
1218 |
} |
1219 |
break;
|
1220 |
case 1: |
1221 |
disp = (int8_t)ldub_code(s->pc++); |
1222 |
break;
|
1223 |
default:
|
1224 |
case 2: |
1225 |
disp = ldl_code(s->pc); |
1226 |
s->pc += 4;
|
1227 |
break;
|
1228 |
} |
1229 |
|
1230 |
if (base >= 0) { |
1231 |
/* for correct popl handling with esp */
|
1232 |
if (base == 4 && s->popl_esp_hack) |
1233 |
disp += s->popl_esp_hack; |
1234 |
gen_op_movl_A0_reg[base](); |
1235 |
if (disp != 0) |
1236 |
gen_op_addl_A0_im(disp); |
1237 |
} else {
|
1238 |
gen_op_movl_A0_im(disp); |
1239 |
} |
1240 |
/* XXX: index == 4 is always invalid */
|
1241 |
if (havesib && (index != 4 || scale != 0)) { |
1242 |
gen_op_addl_A0_reg_sN[scale][index](); |
1243 |
} |
1244 |
if (must_add_seg) {
|
1245 |
if (override < 0) { |
1246 |
if (base == R_EBP || base == R_ESP)
|
1247 |
override = R_SS; |
1248 |
else
|
1249 |
override = R_DS; |
1250 |
} |
1251 |
gen_op_addl_A0_seg(offsetof(CPUX86State,segs[override].base)); |
1252 |
} |
1253 |
} else {
|
1254 |
switch (mod) {
|
1255 |
case 0: |
1256 |
if (rm == 6) { |
1257 |
disp = lduw_code(s->pc); |
1258 |
s->pc += 2;
|
1259 |
gen_op_movl_A0_im(disp); |
1260 |
rm = 0; /* avoid SS override */ |
1261 |
goto no_rm;
|
1262 |
} else {
|
1263 |
disp = 0;
|
1264 |
} |
1265 |
break;
|
1266 |
case 1: |
1267 |
disp = (int8_t)ldub_code(s->pc++); |
1268 |
break;
|
1269 |
default:
|
1270 |
case 2: |
1271 |
disp = lduw_code(s->pc); |
1272 |
s->pc += 2;
|
1273 |
break;
|
1274 |
} |
1275 |
switch(rm) {
|
1276 |
case 0: |
1277 |
gen_op_movl_A0_reg[R_EBX](); |
1278 |
gen_op_addl_A0_reg_sN[0][R_ESI]();
|
1279 |
break;
|
1280 |
case 1: |
1281 |
gen_op_movl_A0_reg[R_EBX](); |
1282 |
gen_op_addl_A0_reg_sN[0][R_EDI]();
|
1283 |
break;
|
1284 |
case 2: |
1285 |
gen_op_movl_A0_reg[R_EBP](); |
1286 |
gen_op_addl_A0_reg_sN[0][R_ESI]();
|
1287 |
break;
|
1288 |
case 3: |
1289 |
gen_op_movl_A0_reg[R_EBP](); |
1290 |
gen_op_addl_A0_reg_sN[0][R_EDI]();
|
1291 |
break;
|
1292 |
case 4: |
1293 |
gen_op_movl_A0_reg[R_ESI](); |
1294 |
break;
|
1295 |
case 5: |
1296 |
gen_op_movl_A0_reg[R_EDI](); |
1297 |
break;
|
1298 |
case 6: |
1299 |
gen_op_movl_A0_reg[R_EBP](); |
1300 |
break;
|
1301 |
default:
|
1302 |
case 7: |
1303 |
gen_op_movl_A0_reg[R_EBX](); |
1304 |
break;
|
1305 |
} |
1306 |
if (disp != 0) |
1307 |
gen_op_addl_A0_im(disp); |
1308 |
gen_op_andl_A0_ffff(); |
1309 |
no_rm:
|
1310 |
if (must_add_seg) {
|
1311 |
if (override < 0) { |
1312 |
if (rm == 2 || rm == 3 || rm == 6) |
1313 |
override = R_SS; |
1314 |
else
|
1315 |
override = R_DS; |
1316 |
} |
1317 |
gen_op_addl_A0_seg(offsetof(CPUX86State,segs[override].base)); |
1318 |
} |
1319 |
} |
1320 |
|
1321 |
opreg = OR_A0; |
1322 |
disp = 0;
|
1323 |
*reg_ptr = opreg; |
1324 |
*offset_ptr = disp; |
1325 |
} |
1326 |
|
1327 |
/* generate modrm memory load or store of 'reg'. TMP0 is used if reg !=
|
1328 |
OR_TMP0 */
|
1329 |
static void gen_ldst_modrm(DisasContext *s, int modrm, int ot, int reg, int is_store) |
1330 |
{ |
1331 |
int mod, rm, opreg, disp;
|
1332 |
|
1333 |
mod = (modrm >> 6) & 3; |
1334 |
rm = modrm & 7;
|
1335 |
if (mod == 3) { |
1336 |
if (is_store) {
|
1337 |
if (reg != OR_TMP0)
|
1338 |
gen_op_mov_TN_reg[ot][0][reg]();
|
1339 |
gen_op_mov_reg_T0[ot][rm](); |
1340 |
} else {
|
1341 |
gen_op_mov_TN_reg[ot][0][rm]();
|
1342 |
if (reg != OR_TMP0)
|
1343 |
gen_op_mov_reg_T0[ot][reg](); |
1344 |
} |
1345 |
} else {
|
1346 |
gen_lea_modrm(s, modrm, &opreg, &disp); |
1347 |
if (is_store) {
|
1348 |
if (reg != OR_TMP0)
|
1349 |
gen_op_mov_TN_reg[ot][0][reg]();
|
1350 |
gen_op_st_T0_A0[ot + s->mem_index](); |
1351 |
} else {
|
1352 |
gen_op_ld_T0_A0[ot + s->mem_index](); |
1353 |
if (reg != OR_TMP0)
|
1354 |
gen_op_mov_reg_T0[ot][reg](); |
1355 |
} |
1356 |
} |
1357 |
} |
1358 |
|
1359 |
static inline uint32_t insn_get(DisasContext *s, int ot) |
1360 |
{ |
1361 |
uint32_t ret; |
1362 |
|
1363 |
switch(ot) {
|
1364 |
case OT_BYTE:
|
1365 |
ret = ldub_code(s->pc); |
1366 |
s->pc++; |
1367 |
break;
|
1368 |
case OT_WORD:
|
1369 |
ret = lduw_code(s->pc); |
1370 |
s->pc += 2;
|
1371 |
break;
|
1372 |
default:
|
1373 |
case OT_LONG:
|
1374 |
ret = ldl_code(s->pc); |
1375 |
s->pc += 4;
|
1376 |
break;
|
1377 |
} |
1378 |
return ret;
|
1379 |
} |
1380 |
|
1381 |
static inline void gen_jcc(DisasContext *s, int b, int val, int next_eip) |
1382 |
{ |
1383 |
TranslationBlock *tb; |
1384 |
int inv, jcc_op;
|
1385 |
GenOpFunc3 *func; |
1386 |
|
1387 |
inv = b & 1;
|
1388 |
jcc_op = (b >> 1) & 7; |
1389 |
|
1390 |
if (s->jmp_opt) {
|
1391 |
switch(s->cc_op) {
|
1392 |
/* we optimize the cmp/jcc case */
|
1393 |
case CC_OP_SUBB:
|
1394 |
case CC_OP_SUBW:
|
1395 |
case CC_OP_SUBL:
|
1396 |
func = gen_jcc_sub[s->cc_op - CC_OP_SUBB][jcc_op]; |
1397 |
break;
|
1398 |
|
1399 |
/* some jumps are easy to compute */
|
1400 |
case CC_OP_ADDB:
|
1401 |
case CC_OP_ADDW:
|
1402 |
case CC_OP_ADDL:
|
1403 |
case CC_OP_ADCB:
|
1404 |
case CC_OP_ADCW:
|
1405 |
case CC_OP_ADCL:
|
1406 |
case CC_OP_SBBB:
|
1407 |
case CC_OP_SBBW:
|
1408 |
case CC_OP_SBBL:
|
1409 |
case CC_OP_LOGICB:
|
1410 |
case CC_OP_LOGICW:
|
1411 |
case CC_OP_LOGICL:
|
1412 |
case CC_OP_INCB:
|
1413 |
case CC_OP_INCW:
|
1414 |
case CC_OP_INCL:
|
1415 |
case CC_OP_DECB:
|
1416 |
case CC_OP_DECW:
|
1417 |
case CC_OP_DECL:
|
1418 |
case CC_OP_SHLB:
|
1419 |
case CC_OP_SHLW:
|
1420 |
case CC_OP_SHLL:
|
1421 |
case CC_OP_SARB:
|
1422 |
case CC_OP_SARW:
|
1423 |
case CC_OP_SARL:
|
1424 |
switch(jcc_op) {
|
1425 |
case JCC_Z:
|
1426 |
func = gen_jcc_sub[(s->cc_op - CC_OP_ADDB) % 3][jcc_op];
|
1427 |
break;
|
1428 |
case JCC_S:
|
1429 |
func = gen_jcc_sub[(s->cc_op - CC_OP_ADDB) % 3][jcc_op];
|
1430 |
break;
|
1431 |
default:
|
1432 |
func = NULL;
|
1433 |
break;
|
1434 |
} |
1435 |
break;
|
1436 |
default:
|
1437 |
func = NULL;
|
1438 |
break;
|
1439 |
} |
1440 |
|
1441 |
if (s->cc_op != CC_OP_DYNAMIC)
|
1442 |
gen_op_set_cc_op(s->cc_op); |
1443 |
|
1444 |
if (!func) {
|
1445 |
gen_setcc_slow[jcc_op](); |
1446 |
func = gen_op_jcc; |
1447 |
} |
1448 |
|
1449 |
tb = s->tb; |
1450 |
if (!inv) {
|
1451 |
func((long)tb, val, next_eip);
|
1452 |
} else {
|
1453 |
func((long)tb, next_eip, val);
|
1454 |
} |
1455 |
s->is_jmp = 3;
|
1456 |
} else {
|
1457 |
if (s->cc_op != CC_OP_DYNAMIC) {
|
1458 |
gen_op_set_cc_op(s->cc_op); |
1459 |
s->cc_op = CC_OP_DYNAMIC; |
1460 |
} |
1461 |
gen_setcc_slow[jcc_op](); |
1462 |
if (!inv) {
|
1463 |
gen_op_jcc_im(val, next_eip); |
1464 |
} else {
|
1465 |
gen_op_jcc_im(next_eip, val); |
1466 |
} |
1467 |
gen_eob(s); |
1468 |
} |
1469 |
} |
1470 |
|
1471 |
static void gen_setcc(DisasContext *s, int b) |
1472 |
{ |
1473 |
int inv, jcc_op;
|
1474 |
GenOpFunc *func; |
1475 |
|
1476 |
inv = b & 1;
|
1477 |
jcc_op = (b >> 1) & 7; |
1478 |
switch(s->cc_op) {
|
1479 |
/* we optimize the cmp/jcc case */
|
1480 |
case CC_OP_SUBB:
|
1481 |
case CC_OP_SUBW:
|
1482 |
case CC_OP_SUBL:
|
1483 |
func = gen_setcc_sub[s->cc_op - CC_OP_SUBB][jcc_op]; |
1484 |
if (!func)
|
1485 |
goto slow_jcc;
|
1486 |
break;
|
1487 |
|
1488 |
/* some jumps are easy to compute */
|
1489 |
case CC_OP_ADDB:
|
1490 |
case CC_OP_ADDW:
|
1491 |
case CC_OP_ADDL:
|
1492 |
case CC_OP_LOGICB:
|
1493 |
case CC_OP_LOGICW:
|
1494 |
case CC_OP_LOGICL:
|
1495 |
case CC_OP_INCB:
|
1496 |
case CC_OP_INCW:
|
1497 |
case CC_OP_INCL:
|
1498 |
case CC_OP_DECB:
|
1499 |
case CC_OP_DECW:
|
1500 |
case CC_OP_DECL:
|
1501 |
case CC_OP_SHLB:
|
1502 |
case CC_OP_SHLW:
|
1503 |
case CC_OP_SHLL:
|
1504 |
switch(jcc_op) {
|
1505 |
case JCC_Z:
|
1506 |
func = gen_setcc_sub[(s->cc_op - CC_OP_ADDB) % 3][jcc_op];
|
1507 |
break;
|
1508 |
case JCC_S:
|
1509 |
func = gen_setcc_sub[(s->cc_op - CC_OP_ADDB) % 3][jcc_op];
|
1510 |
break;
|
1511 |
default:
|
1512 |
goto slow_jcc;
|
1513 |
} |
1514 |
break;
|
1515 |
default:
|
1516 |
slow_jcc:
|
1517 |
if (s->cc_op != CC_OP_DYNAMIC)
|
1518 |
gen_op_set_cc_op(s->cc_op); |
1519 |
func = gen_setcc_slow[jcc_op]; |
1520 |
break;
|
1521 |
} |
1522 |
func(); |
1523 |
if (inv) {
|
1524 |
gen_op_xor_T0_1(); |
1525 |
} |
1526 |
} |
1527 |
|
1528 |
/* move T0 to seg_reg and compute if the CPU state may change. Never
|
1529 |
call this function with seg_reg == R_CS */
|
1530 |
static void gen_movl_seg_T0(DisasContext *s, int seg_reg, unsigned int cur_eip) |
1531 |
{ |
1532 |
if (s->pe && !s->vm86) {
|
1533 |
/* XXX: optimize by finding processor state dynamically */
|
1534 |
if (s->cc_op != CC_OP_DYNAMIC)
|
1535 |
gen_op_set_cc_op(s->cc_op); |
1536 |
gen_op_jmp_im(cur_eip); |
1537 |
gen_op_movl_seg_T0(seg_reg); |
1538 |
} else {
|
1539 |
gen_op_movl_seg_T0_vm(offsetof(CPUX86State,segs[seg_reg])); |
1540 |
} |
1541 |
/* abort translation because the register may have a non zero base
|
1542 |
or because ss32 may change. For R_SS, translation must always
|
1543 |
stop as a special handling must be done to disable hardware
|
1544 |
interrupts for the next instruction */
|
1545 |
if (seg_reg == R_SS || (!s->addseg && seg_reg < R_FS))
|
1546 |
s->is_jmp = 3;
|
1547 |
} |
1548 |
|
1549 |
static inline void gen_stack_update(DisasContext *s, int addend) |
1550 |
{ |
1551 |
if (s->ss32) {
|
1552 |
if (addend == 2) |
1553 |
gen_op_addl_ESP_2(); |
1554 |
else if (addend == 4) |
1555 |
gen_op_addl_ESP_4(); |
1556 |
else
|
1557 |
gen_op_addl_ESP_im(addend); |
1558 |
} else {
|
1559 |
if (addend == 2) |
1560 |
gen_op_addw_ESP_2(); |
1561 |
else if (addend == 4) |
1562 |
gen_op_addw_ESP_4(); |
1563 |
else
|
1564 |
gen_op_addw_ESP_im(addend); |
1565 |
} |
1566 |
} |
1567 |
|
1568 |
/* generate a push. It depends on ss32, addseg and dflag */
|
1569 |
static void gen_push_T0(DisasContext *s) |
1570 |
{ |
1571 |
gen_op_movl_A0_reg[R_ESP](); |
1572 |
if (!s->dflag)
|
1573 |
gen_op_subl_A0_2(); |
1574 |
else
|
1575 |
gen_op_subl_A0_4(); |
1576 |
if (s->ss32) {
|
1577 |
if (s->addseg) {
|
1578 |
gen_op_movl_T1_A0(); |
1579 |
gen_op_addl_A0_SS(); |
1580 |
} |
1581 |
} else {
|
1582 |
gen_op_andl_A0_ffff(); |
1583 |
gen_op_movl_T1_A0(); |
1584 |
gen_op_addl_A0_SS(); |
1585 |
} |
1586 |
gen_op_st_T0_A0[s->dflag + 1 + s->mem_index]();
|
1587 |
if (s->ss32 && !s->addseg)
|
1588 |
gen_op_movl_ESP_A0(); |
1589 |
else
|
1590 |
gen_op_mov_reg_T1[s->ss32 + 1][R_ESP]();
|
1591 |
} |
1592 |
|
1593 |
/* generate a push. It depends on ss32, addseg and dflag */
|
1594 |
/* slower version for T1, only used for call Ev */
|
1595 |
static void gen_push_T1(DisasContext *s) |
1596 |
{ |
1597 |
gen_op_movl_A0_reg[R_ESP](); |
1598 |
if (!s->dflag)
|
1599 |
gen_op_subl_A0_2(); |
1600 |
else
|
1601 |
gen_op_subl_A0_4(); |
1602 |
if (s->ss32) {
|
1603 |
if (s->addseg) {
|
1604 |
gen_op_addl_A0_SS(); |
1605 |
} |
1606 |
} else {
|
1607 |
gen_op_andl_A0_ffff(); |
1608 |
gen_op_addl_A0_SS(); |
1609 |
} |
1610 |
gen_op_st_T1_A0[s->dflag + 1 + s->mem_index]();
|
1611 |
|
1612 |
if (s->ss32 && !s->addseg)
|
1613 |
gen_op_movl_ESP_A0(); |
1614 |
else
|
1615 |
gen_stack_update(s, (-2) << s->dflag);
|
1616 |
} |
1617 |
|
1618 |
/* two step pop is necessary for precise exceptions */
|
1619 |
static void gen_pop_T0(DisasContext *s) |
1620 |
{ |
1621 |
gen_op_movl_A0_reg[R_ESP](); |
1622 |
if (s->ss32) {
|
1623 |
if (s->addseg)
|
1624 |
gen_op_addl_A0_SS(); |
1625 |
} else {
|
1626 |
gen_op_andl_A0_ffff(); |
1627 |
gen_op_addl_A0_SS(); |
1628 |
} |
1629 |
gen_op_ld_T0_A0[s->dflag + 1 + s->mem_index]();
|
1630 |
} |
1631 |
|
1632 |
static void gen_pop_update(DisasContext *s) |
1633 |
{ |
1634 |
gen_stack_update(s, 2 << s->dflag);
|
1635 |
} |
1636 |
|
1637 |
static void gen_stack_A0(DisasContext *s) |
1638 |
{ |
1639 |
gen_op_movl_A0_ESP(); |
1640 |
if (!s->ss32)
|
1641 |
gen_op_andl_A0_ffff(); |
1642 |
gen_op_movl_T1_A0(); |
1643 |
if (s->addseg)
|
1644 |
gen_op_addl_A0_seg(offsetof(CPUX86State,segs[R_SS].base)); |
1645 |
} |
1646 |
|
1647 |
/* NOTE: wrap around in 16 bit not fully handled */
|
1648 |
static void gen_pusha(DisasContext *s) |
1649 |
{ |
1650 |
int i;
|
1651 |
gen_op_movl_A0_ESP(); |
1652 |
gen_op_addl_A0_im(-16 << s->dflag);
|
1653 |
if (!s->ss32)
|
1654 |
gen_op_andl_A0_ffff(); |
1655 |
gen_op_movl_T1_A0(); |
1656 |
if (s->addseg)
|
1657 |
gen_op_addl_A0_seg(offsetof(CPUX86State,segs[R_SS].base)); |
1658 |
for(i = 0;i < 8; i++) { |
1659 |
gen_op_mov_TN_reg[OT_LONG][0][7 - i](); |
1660 |
gen_op_st_T0_A0[OT_WORD + s->dflag + s->mem_index](); |
1661 |
gen_op_addl_A0_im(2 << s->dflag);
|
1662 |
} |
1663 |
gen_op_mov_reg_T1[OT_WORD + s->dflag][R_ESP](); |
1664 |
} |
1665 |
|
1666 |
/* NOTE: wrap around in 16 bit not fully handled */
|
1667 |
static void gen_popa(DisasContext *s) |
1668 |
{ |
1669 |
int i;
|
1670 |
gen_op_movl_A0_ESP(); |
1671 |
if (!s->ss32)
|
1672 |
gen_op_andl_A0_ffff(); |
1673 |
gen_op_movl_T1_A0(); |
1674 |
gen_op_addl_T1_im(16 << s->dflag);
|
1675 |
if (s->addseg)
|
1676 |
gen_op_addl_A0_seg(offsetof(CPUX86State,segs[R_SS].base)); |
1677 |
for(i = 0;i < 8; i++) { |
1678 |
/* ESP is not reloaded */
|
1679 |
if (i != 3) { |
1680 |
gen_op_ld_T0_A0[OT_WORD + s->dflag + s->mem_index](); |
1681 |
gen_op_mov_reg_T0[OT_WORD + s->dflag][7 - i]();
|
1682 |
} |
1683 |
gen_op_addl_A0_im(2 << s->dflag);
|
1684 |
} |
1685 |
gen_op_mov_reg_T1[OT_WORD + s->dflag][R_ESP](); |
1686 |
} |
1687 |
|
1688 |
/* NOTE: wrap around in 16 bit not fully handled */
|
1689 |
/* XXX: check this */
|
1690 |
static void gen_enter(DisasContext *s, int esp_addend, int level) |
1691 |
{ |
1692 |
int ot, level1, addend, opsize;
|
1693 |
|
1694 |
ot = s->dflag + OT_WORD; |
1695 |
level &= 0x1f;
|
1696 |
level1 = level; |
1697 |
opsize = 2 << s->dflag;
|
1698 |
|
1699 |
gen_op_movl_A0_ESP(); |
1700 |
gen_op_addl_A0_im(-opsize); |
1701 |
if (!s->ss32)
|
1702 |
gen_op_andl_A0_ffff(); |
1703 |
gen_op_movl_T1_A0(); |
1704 |
if (s->addseg)
|
1705 |
gen_op_addl_A0_seg(offsetof(CPUX86State,segs[R_SS].base)); |
1706 |
/* push bp */
|
1707 |
gen_op_mov_TN_reg[OT_LONG][0][R_EBP]();
|
1708 |
gen_op_st_T0_A0[ot + s->mem_index](); |
1709 |
if (level) {
|
1710 |
while (level--) {
|
1711 |
gen_op_addl_A0_im(-opsize); |
1712 |
gen_op_addl_T0_im(-opsize); |
1713 |
gen_op_st_T0_A0[ot + s->mem_index](); |
1714 |
} |
1715 |
gen_op_addl_A0_im(-opsize); |
1716 |
gen_op_st_T1_A0[ot + s->mem_index](); |
1717 |
} |
1718 |
gen_op_mov_reg_T1[ot][R_EBP](); |
1719 |
addend = -esp_addend; |
1720 |
if (level1)
|
1721 |
addend -= opsize * (level1 + 1);
|
1722 |
gen_op_addl_T1_im(addend); |
1723 |
gen_op_mov_reg_T1[ot][R_ESP](); |
1724 |
} |
1725 |
|
1726 |
static void gen_exception(DisasContext *s, int trapno, unsigned int cur_eip) |
1727 |
{ |
1728 |
if (s->cc_op != CC_OP_DYNAMIC)
|
1729 |
gen_op_set_cc_op(s->cc_op); |
1730 |
gen_op_jmp_im(cur_eip); |
1731 |
gen_op_raise_exception(trapno); |
1732 |
s->is_jmp = 3;
|
1733 |
} |
1734 |
|
1735 |
/* an interrupt is different from an exception because of the
|
1736 |
priviledge checks */
|
1737 |
static void gen_interrupt(DisasContext *s, int intno, |
1738 |
unsigned int cur_eip, unsigned int next_eip) |
1739 |
{ |
1740 |
if (s->cc_op != CC_OP_DYNAMIC)
|
1741 |
gen_op_set_cc_op(s->cc_op); |
1742 |
gen_op_jmp_im(cur_eip); |
1743 |
gen_op_raise_interrupt(intno, next_eip); |
1744 |
s->is_jmp = 3;
|
1745 |
} |
1746 |
|
1747 |
static void gen_debug(DisasContext *s, unsigned int cur_eip) |
1748 |
{ |
1749 |
if (s->cc_op != CC_OP_DYNAMIC)
|
1750 |
gen_op_set_cc_op(s->cc_op); |
1751 |
gen_op_jmp_im(cur_eip); |
1752 |
gen_op_debug(); |
1753 |
s->is_jmp = 3;
|
1754 |
} |
1755 |
|
1756 |
/* generate a generic end of block. Trace exception is also generated
|
1757 |
if needed */
|
1758 |
static void gen_eob(DisasContext *s) |
1759 |
{ |
1760 |
if (s->cc_op != CC_OP_DYNAMIC)
|
1761 |
gen_op_set_cc_op(s->cc_op); |
1762 |
if (s->tb->flags & HF_INHIBIT_IRQ_MASK) {
|
1763 |
gen_op_reset_inhibit_irq(); |
1764 |
} |
1765 |
if (s->singlestep_enabled) {
|
1766 |
gen_op_debug(); |
1767 |
} else if (s->tf) { |
1768 |
gen_op_raise_exception(EXCP01_SSTP); |
1769 |
} else {
|
1770 |
gen_op_movl_T0_0(); |
1771 |
gen_op_exit_tb(); |
1772 |
} |
1773 |
s->is_jmp = 3;
|
1774 |
} |
1775 |
|
1776 |
/* generate a jump to eip. No segment change must happen before as a
|
1777 |
direct call to the next block may occur */
|
1778 |
static void gen_jmp(DisasContext *s, unsigned int eip) |
1779 |
{ |
1780 |
TranslationBlock *tb = s->tb; |
1781 |
|
1782 |
if (s->jmp_opt) {
|
1783 |
if (s->cc_op != CC_OP_DYNAMIC)
|
1784 |
gen_op_set_cc_op(s->cc_op); |
1785 |
gen_op_jmp((long)tb, eip);
|
1786 |
s->is_jmp = 3;
|
1787 |
} else {
|
1788 |
gen_op_jmp_im(eip); |
1789 |
gen_eob(s); |
1790 |
} |
1791 |
} |
1792 |
|
1793 |
/* convert one instruction. s->is_jmp is set if the translation must
|
1794 |
be stopped. Return the next pc value */
|
1795 |
static uint8_t *disas_insn(DisasContext *s, uint8_t *pc_start)
|
1796 |
{ |
1797 |
int b, prefixes, aflag, dflag;
|
1798 |
int shift, ot;
|
1799 |
int modrm, reg, rm, mod, reg_addr, op, opreg, offset_addr, val;
|
1800 |
unsigned int next_eip; |
1801 |
|
1802 |
s->pc = pc_start; |
1803 |
prefixes = 0;
|
1804 |
aflag = s->code32; |
1805 |
dflag = s->code32; |
1806 |
s->override = -1;
|
1807 |
next_byte:
|
1808 |
b = ldub_code(s->pc); |
1809 |
s->pc++; |
1810 |
/* check prefixes */
|
1811 |
switch (b) {
|
1812 |
case 0xf3: |
1813 |
prefixes |= PREFIX_REPZ; |
1814 |
goto next_byte;
|
1815 |
case 0xf2: |
1816 |
prefixes |= PREFIX_REPNZ; |
1817 |
goto next_byte;
|
1818 |
case 0xf0: |
1819 |
prefixes |= PREFIX_LOCK; |
1820 |
goto next_byte;
|
1821 |
case 0x2e: |
1822 |
s->override = R_CS; |
1823 |
goto next_byte;
|
1824 |
case 0x36: |
1825 |
s->override = R_SS; |
1826 |
goto next_byte;
|
1827 |
case 0x3e: |
1828 |
s->override = R_DS; |
1829 |
goto next_byte;
|
1830 |
case 0x26: |
1831 |
s->override = R_ES; |
1832 |
goto next_byte;
|
1833 |
case 0x64: |
1834 |
s->override = R_FS; |
1835 |
goto next_byte;
|
1836 |
case 0x65: |
1837 |
s->override = R_GS; |
1838 |
goto next_byte;
|
1839 |
case 0x66: |
1840 |
prefixes |= PREFIX_DATA; |
1841 |
goto next_byte;
|
1842 |
case 0x67: |
1843 |
prefixes |= PREFIX_ADR; |
1844 |
goto next_byte;
|
1845 |
} |
1846 |
|
1847 |
if (prefixes & PREFIX_DATA)
|
1848 |
dflag ^= 1;
|
1849 |
if (prefixes & PREFIX_ADR)
|
1850 |
aflag ^= 1;
|
1851 |
|
1852 |
s->prefix = prefixes; |
1853 |
s->aflag = aflag; |
1854 |
s->dflag = dflag; |
1855 |
|
1856 |
/* lock generation */
|
1857 |
if (prefixes & PREFIX_LOCK)
|
1858 |
gen_op_lock(); |
1859 |
|
1860 |
/* now check op code */
|
1861 |
reswitch:
|
1862 |
switch(b) {
|
1863 |
case 0x0f: |
1864 |
/**************************/
|
1865 |
/* extended op code */
|
1866 |
b = ldub_code(s->pc++) | 0x100;
|
1867 |
goto reswitch;
|
1868 |
|
1869 |
/**************************/
|
1870 |
/* arith & logic */
|
1871 |
case 0x00 ... 0x05: |
1872 |
case 0x08 ... 0x0d: |
1873 |
case 0x10 ... 0x15: |
1874 |
case 0x18 ... 0x1d: |
1875 |
case 0x20 ... 0x25: |
1876 |
case 0x28 ... 0x2d: |
1877 |
case 0x30 ... 0x35: |
1878 |
case 0x38 ... 0x3d: |
1879 |
{ |
1880 |
int op, f, val;
|
1881 |
op = (b >> 3) & 7; |
1882 |
f = (b >> 1) & 3; |
1883 |
|
1884 |
if ((b & 1) == 0) |
1885 |
ot = OT_BYTE; |
1886 |
else
|
1887 |
ot = dflag ? OT_LONG : OT_WORD; |
1888 |
|
1889 |
switch(f) {
|
1890 |
case 0: /* OP Ev, Gv */ |
1891 |
modrm = ldub_code(s->pc++); |
1892 |
reg = ((modrm >> 3) & 7); |
1893 |
mod = (modrm >> 6) & 3; |
1894 |
rm = modrm & 7;
|
1895 |
if (mod != 3) { |
1896 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
1897 |
opreg = OR_TMP0; |
1898 |
} else if (op == OP_XORL && rm == reg) { |
1899 |
xor_zero:
|
1900 |
/* xor reg, reg optimisation */
|
1901 |
gen_op_movl_T0_0(); |
1902 |
s->cc_op = CC_OP_LOGICB + ot; |
1903 |
gen_op_mov_reg_T0[ot][reg](); |
1904 |
gen_op_update1_cc(); |
1905 |
break;
|
1906 |
} else {
|
1907 |
opreg = rm; |
1908 |
} |
1909 |
gen_op_mov_TN_reg[ot][1][reg]();
|
1910 |
gen_op(s, op, ot, opreg); |
1911 |
break;
|
1912 |
case 1: /* OP Gv, Ev */ |
1913 |
modrm = ldub_code(s->pc++); |
1914 |
mod = (modrm >> 6) & 3; |
1915 |
reg = ((modrm >> 3) & 7); |
1916 |
rm = modrm & 7;
|
1917 |
if (mod != 3) { |
1918 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
1919 |
gen_op_ld_T1_A0[ot + s->mem_index](); |
1920 |
} else if (op == OP_XORL && rm == reg) { |
1921 |
goto xor_zero;
|
1922 |
} else {
|
1923 |
gen_op_mov_TN_reg[ot][1][rm]();
|
1924 |
} |
1925 |
gen_op(s, op, ot, reg); |
1926 |
break;
|
1927 |
case 2: /* OP A, Iv */ |
1928 |
val = insn_get(s, ot); |
1929 |
gen_op_movl_T1_im(val); |
1930 |
gen_op(s, op, ot, OR_EAX); |
1931 |
break;
|
1932 |
} |
1933 |
} |
1934 |
break;
|
1935 |
|
1936 |
case 0x80: /* GRP1 */ |
1937 |
case 0x81: |
1938 |
case 0x83: |
1939 |
{ |
1940 |
int val;
|
1941 |
|
1942 |
if ((b & 1) == 0) |
1943 |
ot = OT_BYTE; |
1944 |
else
|
1945 |
ot = dflag ? OT_LONG : OT_WORD; |
1946 |
|
1947 |
modrm = ldub_code(s->pc++); |
1948 |
mod = (modrm >> 6) & 3; |
1949 |
rm = modrm & 7;
|
1950 |
op = (modrm >> 3) & 7; |
1951 |
|
1952 |
if (mod != 3) { |
1953 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
1954 |
opreg = OR_TMP0; |
1955 |
} else {
|
1956 |
opreg = rm + OR_EAX; |
1957 |
} |
1958 |
|
1959 |
switch(b) {
|
1960 |
default:
|
1961 |
case 0x80: |
1962 |
case 0x81: |
1963 |
val = insn_get(s, ot); |
1964 |
break;
|
1965 |
case 0x83: |
1966 |
val = (int8_t)insn_get(s, OT_BYTE); |
1967 |
break;
|
1968 |
} |
1969 |
gen_op_movl_T1_im(val); |
1970 |
gen_op(s, op, ot, opreg); |
1971 |
} |
1972 |
break;
|
1973 |
|
1974 |
/**************************/
|
1975 |
/* inc, dec, and other misc arith */
|
1976 |
case 0x40 ... 0x47: /* inc Gv */ |
1977 |
ot = dflag ? OT_LONG : OT_WORD; |
1978 |
gen_inc(s, ot, OR_EAX + (b & 7), 1); |
1979 |
break;
|
1980 |
case 0x48 ... 0x4f: /* dec Gv */ |
1981 |
ot = dflag ? OT_LONG : OT_WORD; |
1982 |
gen_inc(s, ot, OR_EAX + (b & 7), -1); |
1983 |
break;
|
1984 |
case 0xf6: /* GRP3 */ |
1985 |
case 0xf7: |
1986 |
if ((b & 1) == 0) |
1987 |
ot = OT_BYTE; |
1988 |
else
|
1989 |
ot = dflag ? OT_LONG : OT_WORD; |
1990 |
|
1991 |
modrm = ldub_code(s->pc++); |
1992 |
mod = (modrm >> 6) & 3; |
1993 |
rm = modrm & 7;
|
1994 |
op = (modrm >> 3) & 7; |
1995 |
if (mod != 3) { |
1996 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
1997 |
gen_op_ld_T0_A0[ot + s->mem_index](); |
1998 |
} else {
|
1999 |
gen_op_mov_TN_reg[ot][0][rm]();
|
2000 |
} |
2001 |
|
2002 |
switch(op) {
|
2003 |
case 0: /* test */ |
2004 |
val = insn_get(s, ot); |
2005 |
gen_op_movl_T1_im(val); |
2006 |
gen_op_testl_T0_T1_cc(); |
2007 |
s->cc_op = CC_OP_LOGICB + ot; |
2008 |
break;
|
2009 |
case 2: /* not */ |
2010 |
gen_op_notl_T0(); |
2011 |
if (mod != 3) { |
2012 |
gen_op_st_T0_A0[ot + s->mem_index](); |
2013 |
} else {
|
2014 |
gen_op_mov_reg_T0[ot][rm](); |
2015 |
} |
2016 |
break;
|
2017 |
case 3: /* neg */ |
2018 |
gen_op_negl_T0(); |
2019 |
if (mod != 3) { |
2020 |
gen_op_st_T0_A0[ot + s->mem_index](); |
2021 |
} else {
|
2022 |
gen_op_mov_reg_T0[ot][rm](); |
2023 |
} |
2024 |
gen_op_update_neg_cc(); |
2025 |
s->cc_op = CC_OP_SUBB + ot; |
2026 |
break;
|
2027 |
case 4: /* mul */ |
2028 |
switch(ot) {
|
2029 |
case OT_BYTE:
|
2030 |
gen_op_mulb_AL_T0(); |
2031 |
s->cc_op = CC_OP_MULB; |
2032 |
break;
|
2033 |
case OT_WORD:
|
2034 |
gen_op_mulw_AX_T0(); |
2035 |
s->cc_op = CC_OP_MULW; |
2036 |
break;
|
2037 |
default:
|
2038 |
case OT_LONG:
|
2039 |
gen_op_mull_EAX_T0(); |
2040 |
s->cc_op = CC_OP_MULL; |
2041 |
break;
|
2042 |
} |
2043 |
break;
|
2044 |
case 5: /* imul */ |
2045 |
switch(ot) {
|
2046 |
case OT_BYTE:
|
2047 |
gen_op_imulb_AL_T0(); |
2048 |
s->cc_op = CC_OP_MULB; |
2049 |
break;
|
2050 |
case OT_WORD:
|
2051 |
gen_op_imulw_AX_T0(); |
2052 |
s->cc_op = CC_OP_MULW; |
2053 |
break;
|
2054 |
default:
|
2055 |
case OT_LONG:
|
2056 |
gen_op_imull_EAX_T0(); |
2057 |
s->cc_op = CC_OP_MULL; |
2058 |
break;
|
2059 |
} |
2060 |
break;
|
2061 |
case 6: /* div */ |
2062 |
switch(ot) {
|
2063 |
case OT_BYTE:
|
2064 |
gen_op_divb_AL_T0(pc_start - s->cs_base); |
2065 |
break;
|
2066 |
case OT_WORD:
|
2067 |
gen_op_divw_AX_T0(pc_start - s->cs_base); |
2068 |
break;
|
2069 |
default:
|
2070 |
case OT_LONG:
|
2071 |
gen_op_divl_EAX_T0(pc_start - s->cs_base); |
2072 |
break;
|
2073 |
} |
2074 |
break;
|
2075 |
case 7: /* idiv */ |
2076 |
switch(ot) {
|
2077 |
case OT_BYTE:
|
2078 |
gen_op_idivb_AL_T0(pc_start - s->cs_base); |
2079 |
break;
|
2080 |
case OT_WORD:
|
2081 |
gen_op_idivw_AX_T0(pc_start - s->cs_base); |
2082 |
break;
|
2083 |
default:
|
2084 |
case OT_LONG:
|
2085 |
gen_op_idivl_EAX_T0(pc_start - s->cs_base); |
2086 |
break;
|
2087 |
} |
2088 |
break;
|
2089 |
default:
|
2090 |
goto illegal_op;
|
2091 |
} |
2092 |
break;
|
2093 |
|
2094 |
case 0xfe: /* GRP4 */ |
2095 |
case 0xff: /* GRP5 */ |
2096 |
if ((b & 1) == 0) |
2097 |
ot = OT_BYTE; |
2098 |
else
|
2099 |
ot = dflag ? OT_LONG : OT_WORD; |
2100 |
|
2101 |
modrm = ldub_code(s->pc++); |
2102 |
mod = (modrm >> 6) & 3; |
2103 |
rm = modrm & 7;
|
2104 |
op = (modrm >> 3) & 7; |
2105 |
if (op >= 2 && b == 0xfe) { |
2106 |
goto illegal_op;
|
2107 |
} |
2108 |
if (mod != 3) { |
2109 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
2110 |
if (op >= 2 && op != 3 && op != 5) |
2111 |
gen_op_ld_T0_A0[ot + s->mem_index](); |
2112 |
} else {
|
2113 |
gen_op_mov_TN_reg[ot][0][rm]();
|
2114 |
} |
2115 |
|
2116 |
switch(op) {
|
2117 |
case 0: /* inc Ev */ |
2118 |
if (mod != 3) |
2119 |
opreg = OR_TMP0; |
2120 |
else
|
2121 |
opreg = rm; |
2122 |
gen_inc(s, ot, opreg, 1);
|
2123 |
break;
|
2124 |
case 1: /* dec Ev */ |
2125 |
if (mod != 3) |
2126 |
opreg = OR_TMP0; |
2127 |
else
|
2128 |
opreg = rm; |
2129 |
gen_inc(s, ot, opreg, -1);
|
2130 |
break;
|
2131 |
case 2: /* call Ev */ |
2132 |
/* XXX: optimize if memory (no 'and' is necessary) */
|
2133 |
if (s->dflag == 0) |
2134 |
gen_op_andl_T0_ffff(); |
2135 |
next_eip = s->pc - s->cs_base; |
2136 |
gen_op_movl_T1_im(next_eip); |
2137 |
gen_push_T1(s); |
2138 |
gen_op_jmp_T0(); |
2139 |
gen_eob(s); |
2140 |
break;
|
2141 |
case 3: /* lcall Ev */ |
2142 |
gen_op_ld_T1_A0[ot + s->mem_index](); |
2143 |
gen_op_addl_A0_im(1 << (ot - OT_WORD + 1)); |
2144 |
gen_op_ldu_T0_A0[OT_WORD + s->mem_index](); |
2145 |
do_lcall:
|
2146 |
if (s->pe && !s->vm86) {
|
2147 |
if (s->cc_op != CC_OP_DYNAMIC)
|
2148 |
gen_op_set_cc_op(s->cc_op); |
2149 |
gen_op_jmp_im(pc_start - s->cs_base); |
2150 |
gen_op_lcall_protected_T0_T1(dflag, s->pc - s->cs_base); |
2151 |
} else {
|
2152 |
gen_op_lcall_real_T0_T1(dflag, s->pc - s->cs_base); |
2153 |
} |
2154 |
gen_eob(s); |
2155 |
break;
|
2156 |
case 4: /* jmp Ev */ |
2157 |
if (s->dflag == 0) |
2158 |
gen_op_andl_T0_ffff(); |
2159 |
gen_op_jmp_T0(); |
2160 |
gen_eob(s); |
2161 |
break;
|
2162 |
case 5: /* ljmp Ev */ |
2163 |
gen_op_ld_T1_A0[ot + s->mem_index](); |
2164 |
gen_op_addl_A0_im(1 << (ot - OT_WORD + 1)); |
2165 |
gen_op_ldu_T0_A0[OT_WORD + s->mem_index](); |
2166 |
do_ljmp:
|
2167 |
if (s->pe && !s->vm86) {
|
2168 |
if (s->cc_op != CC_OP_DYNAMIC)
|
2169 |
gen_op_set_cc_op(s->cc_op); |
2170 |
gen_op_jmp_im(pc_start - s->cs_base); |
2171 |
gen_op_ljmp_protected_T0_T1(); |
2172 |
} else {
|
2173 |
gen_op_movl_seg_T0_vm(offsetof(CPUX86State,segs[R_CS])); |
2174 |
gen_op_movl_T0_T1(); |
2175 |
gen_op_jmp_T0(); |
2176 |
} |
2177 |
gen_eob(s); |
2178 |
break;
|
2179 |
case 6: /* push Ev */ |
2180 |
gen_push_T0(s); |
2181 |
break;
|
2182 |
default:
|
2183 |
goto illegal_op;
|
2184 |
} |
2185 |
break;
|
2186 |
|
2187 |
case 0x84: /* test Ev, Gv */ |
2188 |
case 0x85: |
2189 |
if ((b & 1) == 0) |
2190 |
ot = OT_BYTE; |
2191 |
else
|
2192 |
ot = dflag ? OT_LONG : OT_WORD; |
2193 |
|
2194 |
modrm = ldub_code(s->pc++); |
2195 |
mod = (modrm >> 6) & 3; |
2196 |
rm = modrm & 7;
|
2197 |
reg = (modrm >> 3) & 7; |
2198 |
|
2199 |
gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
|
2200 |
gen_op_mov_TN_reg[ot][1][reg + OR_EAX]();
|
2201 |
gen_op_testl_T0_T1_cc(); |
2202 |
s->cc_op = CC_OP_LOGICB + ot; |
2203 |
break;
|
2204 |
|
2205 |
case 0xa8: /* test eAX, Iv */ |
2206 |
case 0xa9: |
2207 |
if ((b & 1) == 0) |
2208 |
ot = OT_BYTE; |
2209 |
else
|
2210 |
ot = dflag ? OT_LONG : OT_WORD; |
2211 |
val = insn_get(s, ot); |
2212 |
|
2213 |
gen_op_mov_TN_reg[ot][0][OR_EAX]();
|
2214 |
gen_op_movl_T1_im(val); |
2215 |
gen_op_testl_T0_T1_cc(); |
2216 |
s->cc_op = CC_OP_LOGICB + ot; |
2217 |
break;
|
2218 |
|
2219 |
case 0x98: /* CWDE/CBW */ |
2220 |
if (dflag)
|
2221 |
gen_op_movswl_EAX_AX(); |
2222 |
else
|
2223 |
gen_op_movsbw_AX_AL(); |
2224 |
break;
|
2225 |
case 0x99: /* CDQ/CWD */ |
2226 |
if (dflag)
|
2227 |
gen_op_movslq_EDX_EAX(); |
2228 |
else
|
2229 |
gen_op_movswl_DX_AX(); |
2230 |
break;
|
2231 |
case 0x1af: /* imul Gv, Ev */ |
2232 |
case 0x69: /* imul Gv, Ev, I */ |
2233 |
case 0x6b: |
2234 |
ot = dflag ? OT_LONG : OT_WORD; |
2235 |
modrm = ldub_code(s->pc++); |
2236 |
reg = ((modrm >> 3) & 7) + OR_EAX; |
2237 |
gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
|
2238 |
if (b == 0x69) { |
2239 |
val = insn_get(s, ot); |
2240 |
gen_op_movl_T1_im(val); |
2241 |
} else if (b == 0x6b) { |
2242 |
val = insn_get(s, OT_BYTE); |
2243 |
gen_op_movl_T1_im(val); |
2244 |
} else {
|
2245 |
gen_op_mov_TN_reg[ot][1][reg]();
|
2246 |
} |
2247 |
|
2248 |
if (ot == OT_LONG) {
|
2249 |
gen_op_imull_T0_T1(); |
2250 |
} else {
|
2251 |
gen_op_imulw_T0_T1(); |
2252 |
} |
2253 |
gen_op_mov_reg_T0[ot][reg](); |
2254 |
s->cc_op = CC_OP_MULB + ot; |
2255 |
break;
|
2256 |
case 0x1c0: |
2257 |
case 0x1c1: /* xadd Ev, Gv */ |
2258 |
if ((b & 1) == 0) |
2259 |
ot = OT_BYTE; |
2260 |
else
|
2261 |
ot = dflag ? OT_LONG : OT_WORD; |
2262 |
modrm = ldub_code(s->pc++); |
2263 |
reg = (modrm >> 3) & 7; |
2264 |
mod = (modrm >> 6) & 3; |
2265 |
if (mod == 3) { |
2266 |
rm = modrm & 7;
|
2267 |
gen_op_mov_TN_reg[ot][0][reg]();
|
2268 |
gen_op_mov_TN_reg[ot][1][rm]();
|
2269 |
gen_op_addl_T0_T1(); |
2270 |
gen_op_mov_reg_T0[ot][rm](); |
2271 |
gen_op_mov_reg_T1[ot][reg](); |
2272 |
} else {
|
2273 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
2274 |
gen_op_mov_TN_reg[ot][0][reg]();
|
2275 |
gen_op_ld_T1_A0[ot + s->mem_index](); |
2276 |
gen_op_addl_T0_T1(); |
2277 |
gen_op_st_T0_A0[ot + s->mem_index](); |
2278 |
gen_op_mov_reg_T1[ot][reg](); |
2279 |
} |
2280 |
gen_op_update2_cc(); |
2281 |
s->cc_op = CC_OP_ADDB + ot; |
2282 |
break;
|
2283 |
case 0x1b0: |
2284 |
case 0x1b1: /* cmpxchg Ev, Gv */ |
2285 |
if ((b & 1) == 0) |
2286 |
ot = OT_BYTE; |
2287 |
else
|
2288 |
ot = dflag ? OT_LONG : OT_WORD; |
2289 |
modrm = ldub_code(s->pc++); |
2290 |
reg = (modrm >> 3) & 7; |
2291 |
mod = (modrm >> 6) & 3; |
2292 |
gen_op_mov_TN_reg[ot][1][reg]();
|
2293 |
if (mod == 3) { |
2294 |
rm = modrm & 7;
|
2295 |
gen_op_mov_TN_reg[ot][0][rm]();
|
2296 |
gen_op_cmpxchg_T0_T1_EAX_cc[ot](); |
2297 |
gen_op_mov_reg_T0[ot][rm](); |
2298 |
} else {
|
2299 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
2300 |
gen_op_ld_T0_A0[ot + s->mem_index](); |
2301 |
gen_op_cmpxchg_mem_T0_T1_EAX_cc[ot + s->mem_index](); |
2302 |
} |
2303 |
s->cc_op = CC_OP_SUBB + ot; |
2304 |
break;
|
2305 |
case 0x1c7: /* cmpxchg8b */ |
2306 |
modrm = ldub_code(s->pc++); |
2307 |
mod = (modrm >> 6) & 3; |
2308 |
if (mod == 3) |
2309 |
goto illegal_op;
|
2310 |
if (s->cc_op != CC_OP_DYNAMIC)
|
2311 |
gen_op_set_cc_op(s->cc_op); |
2312 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
2313 |
gen_op_cmpxchg8b(); |
2314 |
s->cc_op = CC_OP_EFLAGS; |
2315 |
break;
|
2316 |
|
2317 |
/**************************/
|
2318 |
/* push/pop */
|
2319 |
case 0x50 ... 0x57: /* push */ |
2320 |
gen_op_mov_TN_reg[OT_LONG][0][b & 7](); |
2321 |
gen_push_T0(s); |
2322 |
break;
|
2323 |
case 0x58 ... 0x5f: /* pop */ |
2324 |
ot = dflag ? OT_LONG : OT_WORD; |
2325 |
gen_pop_T0(s); |
2326 |
/* NOTE: order is important for pop %sp */
|
2327 |
gen_pop_update(s); |
2328 |
gen_op_mov_reg_T0[ot][b & 7]();
|
2329 |
break;
|
2330 |
case 0x60: /* pusha */ |
2331 |
gen_pusha(s); |
2332 |
break;
|
2333 |
case 0x61: /* popa */ |
2334 |
gen_popa(s); |
2335 |
break;
|
2336 |
case 0x68: /* push Iv */ |
2337 |
case 0x6a: |
2338 |
ot = dflag ? OT_LONG : OT_WORD; |
2339 |
if (b == 0x68) |
2340 |
val = insn_get(s, ot); |
2341 |
else
|
2342 |
val = (int8_t)insn_get(s, OT_BYTE); |
2343 |
gen_op_movl_T0_im(val); |
2344 |
gen_push_T0(s); |
2345 |
break;
|
2346 |
case 0x8f: /* pop Ev */ |
2347 |
ot = dflag ? OT_LONG : OT_WORD; |
2348 |
modrm = ldub_code(s->pc++); |
2349 |
mod = (modrm >> 6) & 3; |
2350 |
gen_pop_T0(s); |
2351 |
if (mod == 3) { |
2352 |
/* NOTE: order is important for pop %sp */
|
2353 |
gen_pop_update(s); |
2354 |
rm = modrm & 7;
|
2355 |
gen_op_mov_reg_T0[ot][rm](); |
2356 |
} else {
|
2357 |
/* NOTE: order is important too for MMU exceptions */
|
2358 |
s->popl_esp_hack = 2 << dflag;
|
2359 |
gen_ldst_modrm(s, modrm, ot, OR_TMP0, 1);
|
2360 |
s->popl_esp_hack = 0;
|
2361 |
gen_pop_update(s); |
2362 |
} |
2363 |
break;
|
2364 |
case 0xc8: /* enter */ |
2365 |
{ |
2366 |
int level;
|
2367 |
val = lduw_code(s->pc); |
2368 |
s->pc += 2;
|
2369 |
level = ldub_code(s->pc++); |
2370 |
gen_enter(s, val, level); |
2371 |
} |
2372 |
break;
|
2373 |
case 0xc9: /* leave */ |
2374 |
/* XXX: exception not precise (ESP is updated before potential exception) */
|
2375 |
if (s->ss32) {
|
2376 |
gen_op_mov_TN_reg[OT_LONG][0][R_EBP]();
|
2377 |
gen_op_mov_reg_T0[OT_LONG][R_ESP](); |
2378 |
} else {
|
2379 |
gen_op_mov_TN_reg[OT_WORD][0][R_EBP]();
|
2380 |
gen_op_mov_reg_T0[OT_WORD][R_ESP](); |
2381 |
} |
2382 |
gen_pop_T0(s); |
2383 |
ot = dflag ? OT_LONG : OT_WORD; |
2384 |
gen_op_mov_reg_T0[ot][R_EBP](); |
2385 |
gen_pop_update(s); |
2386 |
break;
|
2387 |
case 0x06: /* push es */ |
2388 |
case 0x0e: /* push cs */ |
2389 |
case 0x16: /* push ss */ |
2390 |
case 0x1e: /* push ds */ |
2391 |
gen_op_movl_T0_seg(b >> 3);
|
2392 |
gen_push_T0(s); |
2393 |
break;
|
2394 |
case 0x1a0: /* push fs */ |
2395 |
case 0x1a8: /* push gs */ |
2396 |
gen_op_movl_T0_seg((b >> 3) & 7); |
2397 |
gen_push_T0(s); |
2398 |
break;
|
2399 |
case 0x07: /* pop es */ |
2400 |
case 0x17: /* pop ss */ |
2401 |
case 0x1f: /* pop ds */ |
2402 |
reg = b >> 3;
|
2403 |
gen_pop_T0(s); |
2404 |
gen_movl_seg_T0(s, reg, pc_start - s->cs_base); |
2405 |
gen_pop_update(s); |
2406 |
if (reg == R_SS) {
|
2407 |
/* if reg == SS, inhibit interrupts/trace. */
|
2408 |
/* If several instructions disable interrupts, only the
|
2409 |
_first_ does it */
|
2410 |
if (!(s->tb->flags & HF_INHIBIT_IRQ_MASK))
|
2411 |
gen_op_set_inhibit_irq(); |
2412 |
s->tf = 0;
|
2413 |
} |
2414 |
if (s->is_jmp) {
|
2415 |
gen_op_jmp_im(s->pc - s->cs_base); |
2416 |
gen_eob(s); |
2417 |
} |
2418 |
break;
|
2419 |
case 0x1a1: /* pop fs */ |
2420 |
case 0x1a9: /* pop gs */ |
2421 |
gen_pop_T0(s); |
2422 |
gen_movl_seg_T0(s, (b >> 3) & 7, pc_start - s->cs_base); |
2423 |
gen_pop_update(s); |
2424 |
if (s->is_jmp) {
|
2425 |
gen_op_jmp_im(s->pc - s->cs_base); |
2426 |
gen_eob(s); |
2427 |
} |
2428 |
break;
|
2429 |
|
2430 |
/**************************/
|
2431 |
/* mov */
|
2432 |
case 0x88: |
2433 |
case 0x89: /* mov Gv, Ev */ |
2434 |
if ((b & 1) == 0) |
2435 |
ot = OT_BYTE; |
2436 |
else
|
2437 |
ot = dflag ? OT_LONG : OT_WORD; |
2438 |
modrm = ldub_code(s->pc++); |
2439 |
reg = (modrm >> 3) & 7; |
2440 |
|
2441 |
/* generate a generic store */
|
2442 |
gen_ldst_modrm(s, modrm, ot, OR_EAX + reg, 1);
|
2443 |
break;
|
2444 |
case 0xc6: |
2445 |
case 0xc7: /* mov Ev, Iv */ |
2446 |
if ((b & 1) == 0) |
2447 |
ot = OT_BYTE; |
2448 |
else
|
2449 |
ot = dflag ? OT_LONG : OT_WORD; |
2450 |
modrm = ldub_code(s->pc++); |
2451 |
mod = (modrm >> 6) & 3; |
2452 |
if (mod != 3) |
2453 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
2454 |
val = insn_get(s, ot); |
2455 |
gen_op_movl_T0_im(val); |
2456 |
if (mod != 3) |
2457 |
gen_op_st_T0_A0[ot + s->mem_index](); |
2458 |
else
|
2459 |
gen_op_mov_reg_T0[ot][modrm & 7]();
|
2460 |
break;
|
2461 |
case 0x8a: |
2462 |
case 0x8b: /* mov Ev, Gv */ |
2463 |
if ((b & 1) == 0) |
2464 |
ot = OT_BYTE; |
2465 |
else
|
2466 |
ot = dflag ? OT_LONG : OT_WORD; |
2467 |
modrm = ldub_code(s->pc++); |
2468 |
reg = (modrm >> 3) & 7; |
2469 |
|
2470 |
gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
|
2471 |
gen_op_mov_reg_T0[ot][reg](); |
2472 |
break;
|
2473 |
case 0x8e: /* mov seg, Gv */ |
2474 |
modrm = ldub_code(s->pc++); |
2475 |
reg = (modrm >> 3) & 7; |
2476 |
if (reg >= 6 || reg == R_CS) |
2477 |
goto illegal_op;
|
2478 |
gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
2479 |
gen_movl_seg_T0(s, reg, pc_start - s->cs_base); |
2480 |
if (reg == R_SS) {
|
2481 |
/* if reg == SS, inhibit interrupts/trace */
|
2482 |
/* If several instructions disable interrupts, only the
|
2483 |
_first_ does it */
|
2484 |
if (!(s->tb->flags & HF_INHIBIT_IRQ_MASK))
|
2485 |
gen_op_set_inhibit_irq(); |
2486 |
s->tf = 0;
|
2487 |
} |
2488 |
if (s->is_jmp) {
|
2489 |
gen_op_jmp_im(s->pc - s->cs_base); |
2490 |
gen_eob(s); |
2491 |
} |
2492 |
break;
|
2493 |
case 0x8c: /* mov Gv, seg */ |
2494 |
modrm = ldub_code(s->pc++); |
2495 |
reg = (modrm >> 3) & 7; |
2496 |
mod = (modrm >> 6) & 3; |
2497 |
if (reg >= 6) |
2498 |
goto illegal_op;
|
2499 |
gen_op_movl_T0_seg(reg); |
2500 |
ot = OT_WORD; |
2501 |
if (mod == 3 && dflag) |
2502 |
ot = OT_LONG; |
2503 |
gen_ldst_modrm(s, modrm, ot, OR_TMP0, 1);
|
2504 |
break;
|
2505 |
|
2506 |
case 0x1b6: /* movzbS Gv, Eb */ |
2507 |
case 0x1b7: /* movzwS Gv, Eb */ |
2508 |
case 0x1be: /* movsbS Gv, Eb */ |
2509 |
case 0x1bf: /* movswS Gv, Eb */ |
2510 |
{ |
2511 |
int d_ot;
|
2512 |
/* d_ot is the size of destination */
|
2513 |
d_ot = dflag + OT_WORD; |
2514 |
/* ot is the size of source */
|
2515 |
ot = (b & 1) + OT_BYTE;
|
2516 |
modrm = ldub_code(s->pc++); |
2517 |
reg = ((modrm >> 3) & 7) + OR_EAX; |
2518 |
mod = (modrm >> 6) & 3; |
2519 |
rm = modrm & 7;
|
2520 |
|
2521 |
if (mod == 3) { |
2522 |
gen_op_mov_TN_reg[ot][0][rm]();
|
2523 |
switch(ot | (b & 8)) { |
2524 |
case OT_BYTE:
|
2525 |
gen_op_movzbl_T0_T0(); |
2526 |
break;
|
2527 |
case OT_BYTE | 8: |
2528 |
gen_op_movsbl_T0_T0(); |
2529 |
break;
|
2530 |
case OT_WORD:
|
2531 |
gen_op_movzwl_T0_T0(); |
2532 |
break;
|
2533 |
default:
|
2534 |
case OT_WORD | 8: |
2535 |
gen_op_movswl_T0_T0(); |
2536 |
break;
|
2537 |
} |
2538 |
gen_op_mov_reg_T0[d_ot][reg](); |
2539 |
} else {
|
2540 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
2541 |
if (b & 8) { |
2542 |
gen_op_lds_T0_A0[ot + s->mem_index](); |
2543 |
} else {
|
2544 |
gen_op_ldu_T0_A0[ot + s->mem_index](); |
2545 |
} |
2546 |
gen_op_mov_reg_T0[d_ot][reg](); |
2547 |
} |
2548 |
} |
2549 |
break;
|
2550 |
|
2551 |
case 0x8d: /* lea */ |
2552 |
ot = dflag ? OT_LONG : OT_WORD; |
2553 |
modrm = ldub_code(s->pc++); |
2554 |
reg = (modrm >> 3) & 7; |
2555 |
/* we must ensure that no segment is added */
|
2556 |
s->override = -1;
|
2557 |
val = s->addseg; |
2558 |
s->addseg = 0;
|
2559 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
2560 |
s->addseg = val; |
2561 |
gen_op_mov_reg_A0[ot - OT_WORD][reg](); |
2562 |
break;
|
2563 |
|
2564 |
case 0xa0: /* mov EAX, Ov */ |
2565 |
case 0xa1: |
2566 |
case 0xa2: /* mov Ov, EAX */ |
2567 |
case 0xa3: |
2568 |
if ((b & 1) == 0) |
2569 |
ot = OT_BYTE; |
2570 |
else
|
2571 |
ot = dflag ? OT_LONG : OT_WORD; |
2572 |
if (s->aflag)
|
2573 |
offset_addr = insn_get(s, OT_LONG); |
2574 |
else
|
2575 |
offset_addr = insn_get(s, OT_WORD); |
2576 |
gen_op_movl_A0_im(offset_addr); |
2577 |
/* handle override */
|
2578 |
{ |
2579 |
int override, must_add_seg;
|
2580 |
must_add_seg = s->addseg; |
2581 |
if (s->override >= 0) { |
2582 |
override = s->override; |
2583 |
must_add_seg = 1;
|
2584 |
} else {
|
2585 |
override = R_DS; |
2586 |
} |
2587 |
if (must_add_seg) {
|
2588 |
gen_op_addl_A0_seg(offsetof(CPUX86State,segs[override].base)); |
2589 |
} |
2590 |
} |
2591 |
if ((b & 2) == 0) { |
2592 |
gen_op_ld_T0_A0[ot + s->mem_index](); |
2593 |
gen_op_mov_reg_T0[ot][R_EAX](); |
2594 |
} else {
|
2595 |
gen_op_mov_TN_reg[ot][0][R_EAX]();
|
2596 |
gen_op_st_T0_A0[ot + s->mem_index](); |
2597 |
} |
2598 |
break;
|
2599 |
case 0xd7: /* xlat */ |
2600 |
gen_op_movl_A0_reg[R_EBX](); |
2601 |
gen_op_addl_A0_AL(); |
2602 |
if (s->aflag == 0) |
2603 |
gen_op_andl_A0_ffff(); |
2604 |
/* handle override */
|
2605 |
{ |
2606 |
int override, must_add_seg;
|
2607 |
must_add_seg = s->addseg; |
2608 |
override = R_DS; |
2609 |
if (s->override >= 0) { |
2610 |
override = s->override; |
2611 |
must_add_seg = 1;
|
2612 |
} else {
|
2613 |
override = R_DS; |
2614 |
} |
2615 |
if (must_add_seg) {
|
2616 |
gen_op_addl_A0_seg(offsetof(CPUX86State,segs[override].base)); |
2617 |
} |
2618 |
} |
2619 |
gen_op_ldu_T0_A0[OT_BYTE + s->mem_index](); |
2620 |
gen_op_mov_reg_T0[OT_BYTE][R_EAX](); |
2621 |
break;
|
2622 |
case 0xb0 ... 0xb7: /* mov R, Ib */ |
2623 |
val = insn_get(s, OT_BYTE); |
2624 |
gen_op_movl_T0_im(val); |
2625 |
gen_op_mov_reg_T0[OT_BYTE][b & 7]();
|
2626 |
break;
|
2627 |
case 0xb8 ... 0xbf: /* mov R, Iv */ |
2628 |
ot = dflag ? OT_LONG : OT_WORD; |
2629 |
val = insn_get(s, ot); |
2630 |
reg = OR_EAX + (b & 7);
|
2631 |
gen_op_movl_T0_im(val); |
2632 |
gen_op_mov_reg_T0[ot][reg](); |
2633 |
break;
|
2634 |
|
2635 |
case 0x91 ... 0x97: /* xchg R, EAX */ |
2636 |
ot = dflag ? OT_LONG : OT_WORD; |
2637 |
reg = b & 7;
|
2638 |
rm = R_EAX; |
2639 |
goto do_xchg_reg;
|
2640 |
case 0x86: |
2641 |
case 0x87: /* xchg Ev, Gv */ |
2642 |
if ((b & 1) == 0) |
2643 |
ot = OT_BYTE; |
2644 |
else
|
2645 |
ot = dflag ? OT_LONG : OT_WORD; |
2646 |
modrm = ldub_code(s->pc++); |
2647 |
reg = (modrm >> 3) & 7; |
2648 |
mod = (modrm >> 6) & 3; |
2649 |
if (mod == 3) { |
2650 |
rm = modrm & 7;
|
2651 |
do_xchg_reg:
|
2652 |
gen_op_mov_TN_reg[ot][0][reg]();
|
2653 |
gen_op_mov_TN_reg[ot][1][rm]();
|
2654 |
gen_op_mov_reg_T0[ot][rm](); |
2655 |
gen_op_mov_reg_T1[ot][reg](); |
2656 |
} else {
|
2657 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
2658 |
gen_op_mov_TN_reg[ot][0][reg]();
|
2659 |
/* for xchg, lock is implicit */
|
2660 |
if (!(prefixes & PREFIX_LOCK))
|
2661 |
gen_op_lock(); |
2662 |
gen_op_ld_T1_A0[ot + s->mem_index](); |
2663 |
gen_op_st_T0_A0[ot + s->mem_index](); |
2664 |
if (!(prefixes & PREFIX_LOCK))
|
2665 |
gen_op_unlock(); |
2666 |
gen_op_mov_reg_T1[ot][reg](); |
2667 |
} |
2668 |
break;
|
2669 |
case 0xc4: /* les Gv */ |
2670 |
op = R_ES; |
2671 |
goto do_lxx;
|
2672 |
case 0xc5: /* lds Gv */ |
2673 |
op = R_DS; |
2674 |
goto do_lxx;
|
2675 |
case 0x1b2: /* lss Gv */ |
2676 |
op = R_SS; |
2677 |
goto do_lxx;
|
2678 |
case 0x1b4: /* lfs Gv */ |
2679 |
op = R_FS; |
2680 |
goto do_lxx;
|
2681 |
case 0x1b5: /* lgs Gv */ |
2682 |
op = R_GS; |
2683 |
do_lxx:
|
2684 |
ot = dflag ? OT_LONG : OT_WORD; |
2685 |
modrm = ldub_code(s->pc++); |
2686 |
reg = (modrm >> 3) & 7; |
2687 |
mod = (modrm >> 6) & 3; |
2688 |
if (mod == 3) |
2689 |
goto illegal_op;
|
2690 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
2691 |
gen_op_ld_T1_A0[ot + s->mem_index](); |
2692 |
gen_op_addl_A0_im(1 << (ot - OT_WORD + 1)); |
2693 |
/* load the segment first to handle exceptions properly */
|
2694 |
gen_op_ldu_T0_A0[OT_WORD + s->mem_index](); |
2695 |
gen_movl_seg_T0(s, op, pc_start - s->cs_base); |
2696 |
/* then put the data */
|
2697 |
gen_op_mov_reg_T1[ot][reg](); |
2698 |
if (s->is_jmp) {
|
2699 |
gen_op_jmp_im(s->pc - s->cs_base); |
2700 |
gen_eob(s); |
2701 |
} |
2702 |
break;
|
2703 |
|
2704 |
/************************/
|
2705 |
/* shifts */
|
2706 |
case 0xc0: |
2707 |
case 0xc1: |
2708 |
/* shift Ev,Ib */
|
2709 |
shift = 2;
|
2710 |
grp2:
|
2711 |
{ |
2712 |
if ((b & 1) == 0) |
2713 |
ot = OT_BYTE; |
2714 |
else
|
2715 |
ot = dflag ? OT_LONG : OT_WORD; |
2716 |
|
2717 |
modrm = ldub_code(s->pc++); |
2718 |
mod = (modrm >> 6) & 3; |
2719 |
rm = modrm & 7;
|
2720 |
op = (modrm >> 3) & 7; |
2721 |
|
2722 |
if (mod != 3) { |
2723 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
2724 |
opreg = OR_TMP0; |
2725 |
} else {
|
2726 |
opreg = rm + OR_EAX; |
2727 |
} |
2728 |
|
2729 |
/* simpler op */
|
2730 |
if (shift == 0) { |
2731 |
gen_shift(s, op, ot, opreg, OR_ECX); |
2732 |
} else {
|
2733 |
if (shift == 2) { |
2734 |
shift = ldub_code(s->pc++); |
2735 |
} |
2736 |
gen_shifti(s, op, ot, opreg, shift); |
2737 |
} |
2738 |
} |
2739 |
break;
|
2740 |
case 0xd0: |
2741 |
case 0xd1: |
2742 |
/* shift Ev,1 */
|
2743 |
shift = 1;
|
2744 |
goto grp2;
|
2745 |
case 0xd2: |
2746 |
case 0xd3: |
2747 |
/* shift Ev,cl */
|
2748 |
shift = 0;
|
2749 |
goto grp2;
|
2750 |
|
2751 |
case 0x1a4: /* shld imm */ |
2752 |
op = 0;
|
2753 |
shift = 1;
|
2754 |
goto do_shiftd;
|
2755 |
case 0x1a5: /* shld cl */ |
2756 |
op = 0;
|
2757 |
shift = 0;
|
2758 |
goto do_shiftd;
|
2759 |
case 0x1ac: /* shrd imm */ |
2760 |
op = 1;
|
2761 |
shift = 1;
|
2762 |
goto do_shiftd;
|
2763 |
case 0x1ad: /* shrd cl */ |
2764 |
op = 1;
|
2765 |
shift = 0;
|
2766 |
do_shiftd:
|
2767 |
ot = dflag ? OT_LONG : OT_WORD; |
2768 |
modrm = ldub_code(s->pc++); |
2769 |
mod = (modrm >> 6) & 3; |
2770 |
rm = modrm & 7;
|
2771 |
reg = (modrm >> 3) & 7; |
2772 |
|
2773 |
if (mod != 3) { |
2774 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
2775 |
gen_op_ld_T0_A0[ot + s->mem_index](); |
2776 |
} else {
|
2777 |
gen_op_mov_TN_reg[ot][0][rm]();
|
2778 |
} |
2779 |
gen_op_mov_TN_reg[ot][1][reg]();
|
2780 |
|
2781 |
if (shift) {
|
2782 |
val = ldub_code(s->pc++); |
2783 |
val &= 0x1f;
|
2784 |
if (val) {
|
2785 |
if (mod == 3) |
2786 |
gen_op_shiftd_T0_T1_im_cc[ot][op](val); |
2787 |
else
|
2788 |
gen_op_shiftd_mem_T0_T1_im_cc[ot + s->mem_index][op](val); |
2789 |
if (op == 0 && ot != OT_WORD) |
2790 |
s->cc_op = CC_OP_SHLB + ot; |
2791 |
else
|
2792 |
s->cc_op = CC_OP_SARB + ot; |
2793 |
} |
2794 |
} else {
|
2795 |
if (s->cc_op != CC_OP_DYNAMIC)
|
2796 |
gen_op_set_cc_op(s->cc_op); |
2797 |
if (mod == 3) |
2798 |
gen_op_shiftd_T0_T1_ECX_cc[ot][op](); |
2799 |
else
|
2800 |
gen_op_shiftd_mem_T0_T1_ECX_cc[ot + s->mem_index][op](); |
2801 |
s->cc_op = CC_OP_DYNAMIC; /* cannot predict flags after */
|
2802 |
} |
2803 |
if (mod == 3) { |
2804 |
gen_op_mov_reg_T0[ot][rm](); |
2805 |
} |
2806 |
break;
|
2807 |
|
2808 |
/************************/
|
2809 |
/* floats */
|
2810 |
case 0xd8 ... 0xdf: |
2811 |
modrm = ldub_code(s->pc++); |
2812 |
mod = (modrm >> 6) & 3; |
2813 |
rm = modrm & 7;
|
2814 |
op = ((b & 7) << 3) | ((modrm >> 3) & 7); |
2815 |
|
2816 |
if (mod != 3) { |
2817 |
/* memory op */
|
2818 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
2819 |
switch(op) {
|
2820 |
case 0x00 ... 0x07: /* fxxxs */ |
2821 |
case 0x10 ... 0x17: /* fixxxl */ |
2822 |
case 0x20 ... 0x27: /* fxxxl */ |
2823 |
case 0x30 ... 0x37: /* fixxx */ |
2824 |
{ |
2825 |
int op1;
|
2826 |
op1 = op & 7;
|
2827 |
|
2828 |
switch(op >> 4) { |
2829 |
case 0: |
2830 |
gen_op_flds_FT0_A0(); |
2831 |
break;
|
2832 |
case 1: |
2833 |
gen_op_fildl_FT0_A0(); |
2834 |
break;
|
2835 |
case 2: |
2836 |
gen_op_fldl_FT0_A0(); |
2837 |
break;
|
2838 |
case 3: |
2839 |
default:
|
2840 |
gen_op_fild_FT0_A0(); |
2841 |
break;
|
2842 |
} |
2843 |
|
2844 |
gen_op_fp_arith_ST0_FT0[op1](); |
2845 |
if (op1 == 3) { |
2846 |
/* fcomp needs pop */
|
2847 |
gen_op_fpop(); |
2848 |
} |
2849 |
} |
2850 |
break;
|
2851 |
case 0x08: /* flds */ |
2852 |
case 0x0a: /* fsts */ |
2853 |
case 0x0b: /* fstps */ |
2854 |
case 0x18: /* fildl */ |
2855 |
case 0x1a: /* fistl */ |
2856 |
case 0x1b: /* fistpl */ |
2857 |
case 0x28: /* fldl */ |
2858 |
case 0x2a: /* fstl */ |
2859 |
case 0x2b: /* fstpl */ |
2860 |
case 0x38: /* filds */ |
2861 |
case 0x3a: /* fists */ |
2862 |
case 0x3b: /* fistps */ |
2863 |
|
2864 |
switch(op & 7) { |
2865 |
case 0: |
2866 |
switch(op >> 4) { |
2867 |
case 0: |
2868 |
gen_op_flds_ST0_A0(); |
2869 |
break;
|
2870 |
case 1: |
2871 |
gen_op_fildl_ST0_A0(); |
2872 |
break;
|
2873 |
case 2: |
2874 |
gen_op_fldl_ST0_A0(); |
2875 |
break;
|
2876 |
case 3: |
2877 |
default:
|
2878 |
gen_op_fild_ST0_A0(); |
2879 |
break;
|
2880 |
} |
2881 |
break;
|
2882 |
default:
|
2883 |
switch(op >> 4) { |
2884 |
case 0: |
2885 |
gen_op_fsts_ST0_A0(); |
2886 |
break;
|
2887 |
case 1: |
2888 |
gen_op_fistl_ST0_A0(); |
2889 |
break;
|
2890 |
case 2: |
2891 |
gen_op_fstl_ST0_A0(); |
2892 |
break;
|
2893 |
case 3: |
2894 |
default:
|
2895 |
gen_op_fist_ST0_A0(); |
2896 |
break;
|
2897 |
} |
2898 |
if ((op & 7) == 3) |
2899 |
gen_op_fpop(); |
2900 |
break;
|
2901 |
} |
2902 |
break;
|
2903 |
case 0x0c: /* fldenv mem */ |
2904 |
gen_op_fldenv_A0(s->dflag); |
2905 |
break;
|
2906 |
case 0x0d: /* fldcw mem */ |
2907 |
gen_op_fldcw_A0(); |
2908 |
break;
|
2909 |
case 0x0e: /* fnstenv mem */ |
2910 |
gen_op_fnstenv_A0(s->dflag); |
2911 |
break;
|
2912 |
case 0x0f: /* fnstcw mem */ |
2913 |
gen_op_fnstcw_A0(); |
2914 |
break;
|
2915 |
case 0x1d: /* fldt mem */ |
2916 |
gen_op_fldt_ST0_A0(); |
2917 |
break;
|
2918 |
case 0x1f: /* fstpt mem */ |
2919 |
gen_op_fstt_ST0_A0(); |
2920 |
gen_op_fpop(); |
2921 |
break;
|
2922 |
case 0x2c: /* frstor mem */ |
2923 |
gen_op_frstor_A0(s->dflag); |
2924 |
break;
|
2925 |
case 0x2e: /* fnsave mem */ |
2926 |
gen_op_fnsave_A0(s->dflag); |
2927 |
break;
|
2928 |
case 0x2f: /* fnstsw mem */ |
2929 |
gen_op_fnstsw_A0(); |
2930 |
break;
|
2931 |
case 0x3c: /* fbld */ |
2932 |
gen_op_fbld_ST0_A0(); |
2933 |
break;
|
2934 |
case 0x3e: /* fbstp */ |
2935 |
gen_op_fbst_ST0_A0(); |
2936 |
gen_op_fpop(); |
2937 |
break;
|
2938 |
case 0x3d: /* fildll */ |
2939 |
gen_op_fildll_ST0_A0(); |
2940 |
break;
|
2941 |
case 0x3f: /* fistpll */ |
2942 |
gen_op_fistll_ST0_A0(); |
2943 |
gen_op_fpop(); |
2944 |
break;
|
2945 |
default:
|
2946 |
goto illegal_op;
|
2947 |
} |
2948 |
} else {
|
2949 |
/* register float ops */
|
2950 |
opreg = rm; |
2951 |
|
2952 |
switch(op) {
|
2953 |
case 0x08: /* fld sti */ |
2954 |
gen_op_fpush(); |
2955 |
gen_op_fmov_ST0_STN((opreg + 1) & 7); |
2956 |
break;
|
2957 |
case 0x09: /* fxchg sti */ |
2958 |
gen_op_fxchg_ST0_STN(opreg); |
2959 |
break;
|
2960 |
case 0x0a: /* grp d9/2 */ |
2961 |
switch(rm) {
|
2962 |
case 0: /* fnop */ |
2963 |
break;
|
2964 |
default:
|
2965 |
goto illegal_op;
|
2966 |
} |
2967 |
break;
|
2968 |
case 0x0c: /* grp d9/4 */ |
2969 |
switch(rm) {
|
2970 |
case 0: /* fchs */ |
2971 |
gen_op_fchs_ST0(); |
2972 |
break;
|
2973 |
case 1: /* fabs */ |
2974 |
gen_op_fabs_ST0(); |
2975 |
break;
|
2976 |
case 4: /* ftst */ |
2977 |
gen_op_fldz_FT0(); |
2978 |
gen_op_fcom_ST0_FT0(); |
2979 |
break;
|
2980 |
case 5: /* fxam */ |
2981 |
gen_op_fxam_ST0(); |
2982 |
break;
|
2983 |
default:
|
2984 |
goto illegal_op;
|
2985 |
} |
2986 |
break;
|
2987 |
case 0x0d: /* grp d9/5 */ |
2988 |
{ |
2989 |
switch(rm) {
|
2990 |
case 0: |
2991 |
gen_op_fpush(); |
2992 |
gen_op_fld1_ST0(); |
2993 |
break;
|
2994 |
case 1: |
2995 |
gen_op_fpush(); |
2996 |
gen_op_fldl2t_ST0(); |
2997 |
break;
|
2998 |
case 2: |
2999 |
gen_op_fpush(); |
3000 |
gen_op_fldl2e_ST0(); |
3001 |
break;
|
3002 |
case 3: |
3003 |
gen_op_fpush(); |
3004 |
gen_op_fldpi_ST0(); |
3005 |
break;
|
3006 |
case 4: |
3007 |
gen_op_fpush(); |
3008 |
gen_op_fldlg2_ST0(); |
3009 |
break;
|
3010 |
case 5: |
3011 |
gen_op_fpush(); |
3012 |
gen_op_fldln2_ST0(); |
3013 |
break;
|
3014 |
case 6: |
3015 |
gen_op_fpush(); |
3016 |
gen_op_fldz_ST0(); |
3017 |
break;
|
3018 |
default:
|
3019 |
goto illegal_op;
|
3020 |
} |
3021 |
} |
3022 |
break;
|
3023 |
case 0x0e: /* grp d9/6 */ |
3024 |
switch(rm) {
|
3025 |
case 0: /* f2xm1 */ |
3026 |
gen_op_f2xm1(); |
3027 |
break;
|
3028 |
case 1: /* fyl2x */ |
3029 |
gen_op_fyl2x(); |
3030 |
break;
|
3031 |
case 2: /* fptan */ |
3032 |
gen_op_fptan(); |
3033 |
break;
|
3034 |
case 3: /* fpatan */ |
3035 |
gen_op_fpatan(); |
3036 |
break;
|
3037 |
case 4: /* fxtract */ |
3038 |
gen_op_fxtract(); |
3039 |
break;
|
3040 |
case 5: /* fprem1 */ |
3041 |
gen_op_fprem1(); |
3042 |
break;
|
3043 |
case 6: /* fdecstp */ |
3044 |
gen_op_fdecstp(); |
3045 |
break;
|
3046 |
default:
|
3047 |
case 7: /* fincstp */ |
3048 |
gen_op_fincstp(); |
3049 |
break;
|
3050 |
} |
3051 |
break;
|
3052 |
case 0x0f: /* grp d9/7 */ |
3053 |
switch(rm) {
|
3054 |
case 0: /* fprem */ |
3055 |
gen_op_fprem(); |
3056 |
break;
|
3057 |
case 1: /* fyl2xp1 */ |
3058 |
gen_op_fyl2xp1(); |
3059 |
break;
|
3060 |
case 2: /* fsqrt */ |
3061 |
gen_op_fsqrt(); |
3062 |
break;
|
3063 |
case 3: /* fsincos */ |
3064 |
gen_op_fsincos(); |
3065 |
break;
|
3066 |
case 5: /* fscale */ |
3067 |
gen_op_fscale(); |
3068 |
break;
|
3069 |
case 4: /* frndint */ |
3070 |
gen_op_frndint(); |
3071 |
break;
|
3072 |
case 6: /* fsin */ |
3073 |
gen_op_fsin(); |
3074 |
break;
|
3075 |
default:
|
3076 |
case 7: /* fcos */ |
3077 |
gen_op_fcos(); |
3078 |
break;
|
3079 |
} |
3080 |
break;
|
3081 |
case 0x00: case 0x01: case 0x04 ... 0x07: /* fxxx st, sti */ |
3082 |
case 0x20: case 0x21: case 0x24 ... 0x27: /* fxxx sti, st */ |
3083 |
case 0x30: case 0x31: case 0x34 ... 0x37: /* fxxxp sti, st */ |
3084 |
{ |
3085 |
int op1;
|
3086 |
|
3087 |
op1 = op & 7;
|
3088 |
if (op >= 0x20) { |
3089 |
gen_op_fp_arith_STN_ST0[op1](opreg); |
3090 |
if (op >= 0x30) |
3091 |
gen_op_fpop(); |
3092 |
} else {
|
3093 |
gen_op_fmov_FT0_STN(opreg); |
3094 |
gen_op_fp_arith_ST0_FT0[op1](); |
3095 |
} |
3096 |
} |
3097 |
break;
|
3098 |
case 0x02: /* fcom */ |
3099 |
gen_op_fmov_FT0_STN(opreg); |
3100 |
gen_op_fcom_ST0_FT0(); |
3101 |
break;
|
3102 |
case 0x03: /* fcomp */ |
3103 |
gen_op_fmov_FT0_STN(opreg); |
3104 |
gen_op_fcom_ST0_FT0(); |
3105 |
gen_op_fpop(); |
3106 |
break;
|
3107 |
case 0x15: /* da/5 */ |
3108 |
switch(rm) {
|
3109 |
case 1: /* fucompp */ |
3110 |
gen_op_fmov_FT0_STN(1);
|
3111 |
gen_op_fucom_ST0_FT0(); |
3112 |
gen_op_fpop(); |
3113 |
gen_op_fpop(); |
3114 |
break;
|
3115 |
default:
|
3116 |
goto illegal_op;
|
3117 |
} |
3118 |
break;
|
3119 |
case 0x1c: |
3120 |
switch(rm) {
|
3121 |
case 0: /* feni (287 only, just do nop here) */ |
3122 |
break;
|
3123 |
case 1: /* fdisi (287 only, just do nop here) */ |
3124 |
break;
|
3125 |
case 2: /* fclex */ |
3126 |
gen_op_fclex(); |
3127 |
break;
|
3128 |
case 3: /* fninit */ |
3129 |
gen_op_fninit(); |
3130 |
break;
|
3131 |
case 4: /* fsetpm (287 only, just do nop here) */ |
3132 |
break;
|
3133 |
default:
|
3134 |
goto illegal_op;
|
3135 |
} |
3136 |
break;
|
3137 |
case 0x1d: /* fucomi */ |
3138 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3139 |
gen_op_set_cc_op(s->cc_op); |
3140 |
gen_op_fmov_FT0_STN(opreg); |
3141 |
gen_op_fucomi_ST0_FT0(); |
3142 |
s->cc_op = CC_OP_EFLAGS; |
3143 |
break;
|
3144 |
case 0x1e: /* fcomi */ |
3145 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3146 |
gen_op_set_cc_op(s->cc_op); |
3147 |
gen_op_fmov_FT0_STN(opreg); |
3148 |
gen_op_fcomi_ST0_FT0(); |
3149 |
s->cc_op = CC_OP_EFLAGS; |
3150 |
break;
|
3151 |
case 0x2a: /* fst sti */ |
3152 |
gen_op_fmov_STN_ST0(opreg); |
3153 |
break;
|
3154 |
case 0x2b: /* fstp sti */ |
3155 |
gen_op_fmov_STN_ST0(opreg); |
3156 |
gen_op_fpop(); |
3157 |
break;
|
3158 |
case 0x2c: /* fucom st(i) */ |
3159 |
gen_op_fmov_FT0_STN(opreg); |
3160 |
gen_op_fucom_ST0_FT0(); |
3161 |
break;
|
3162 |
case 0x2d: /* fucomp st(i) */ |
3163 |
gen_op_fmov_FT0_STN(opreg); |
3164 |
gen_op_fucom_ST0_FT0(); |
3165 |
gen_op_fpop(); |
3166 |
break;
|
3167 |
case 0x33: /* de/3 */ |
3168 |
switch(rm) {
|
3169 |
case 1: /* fcompp */ |
3170 |
gen_op_fmov_FT0_STN(1);
|
3171 |
gen_op_fcom_ST0_FT0(); |
3172 |
gen_op_fpop(); |
3173 |
gen_op_fpop(); |
3174 |
break;
|
3175 |
default:
|
3176 |
goto illegal_op;
|
3177 |
} |
3178 |
break;
|
3179 |
case 0x3c: /* df/4 */ |
3180 |
switch(rm) {
|
3181 |
case 0: |
3182 |
gen_op_fnstsw_EAX(); |
3183 |
break;
|
3184 |
default:
|
3185 |
goto illegal_op;
|
3186 |
} |
3187 |
break;
|
3188 |
case 0x3d: /* fucomip */ |
3189 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3190 |
gen_op_set_cc_op(s->cc_op); |
3191 |
gen_op_fmov_FT0_STN(opreg); |
3192 |
gen_op_fucomi_ST0_FT0(); |
3193 |
gen_op_fpop(); |
3194 |
s->cc_op = CC_OP_EFLAGS; |
3195 |
break;
|
3196 |
case 0x3e: /* fcomip */ |
3197 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3198 |
gen_op_set_cc_op(s->cc_op); |
3199 |
gen_op_fmov_FT0_STN(opreg); |
3200 |
gen_op_fcomi_ST0_FT0(); |
3201 |
gen_op_fpop(); |
3202 |
s->cc_op = CC_OP_EFLAGS; |
3203 |
break;
|
3204 |
case 0x10 ... 0x13: /* fcmovxx */ |
3205 |
case 0x18 ... 0x1b: |
3206 |
{ |
3207 |
int op1;
|
3208 |
const static uint8_t fcmov_cc[8] = { |
3209 |
(JCC_B << 1),
|
3210 |
(JCC_Z << 1),
|
3211 |
(JCC_BE << 1),
|
3212 |
(JCC_P << 1),
|
3213 |
}; |
3214 |
op1 = fcmov_cc[op & 3] | ((op >> 3) & 1); |
3215 |
gen_setcc(s, op1); |
3216 |
gen_op_fcmov_ST0_STN_T0(opreg); |
3217 |
} |
3218 |
break;
|
3219 |
default:
|
3220 |
goto illegal_op;
|
3221 |
} |
3222 |
} |
3223 |
break;
|
3224 |
/************************/
|
3225 |
/* string ops */
|
3226 |
|
3227 |
case 0xa4: /* movsS */ |
3228 |
case 0xa5: |
3229 |
if ((b & 1) == 0) |
3230 |
ot = OT_BYTE; |
3231 |
else
|
3232 |
ot = dflag ? OT_LONG : OT_WORD; |
3233 |
|
3234 |
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
3235 |
gen_repz_movs(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
3236 |
} else {
|
3237 |
gen_movs(s, ot); |
3238 |
} |
3239 |
break;
|
3240 |
|
3241 |
case 0xaa: /* stosS */ |
3242 |
case 0xab: |
3243 |
if ((b & 1) == 0) |
3244 |
ot = OT_BYTE; |
3245 |
else
|
3246 |
ot = dflag ? OT_LONG : OT_WORD; |
3247 |
|
3248 |
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
3249 |
gen_repz_stos(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
3250 |
} else {
|
3251 |
gen_stos(s, ot); |
3252 |
} |
3253 |
break;
|
3254 |
case 0xac: /* lodsS */ |
3255 |
case 0xad: |
3256 |
if ((b & 1) == 0) |
3257 |
ot = OT_BYTE; |
3258 |
else
|
3259 |
ot = dflag ? OT_LONG : OT_WORD; |
3260 |
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
3261 |
gen_repz_lods(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
3262 |
} else {
|
3263 |
gen_lods(s, ot); |
3264 |
} |
3265 |
break;
|
3266 |
case 0xae: /* scasS */ |
3267 |
case 0xaf: |
3268 |
if ((b & 1) == 0) |
3269 |
ot = OT_BYTE; |
3270 |
else
|
3271 |
ot = dflag ? OT_LONG : OT_WORD; |
3272 |
if (prefixes & PREFIX_REPNZ) {
|
3273 |
gen_repz_scas(s, ot, pc_start - s->cs_base, s->pc - s->cs_base, 1);
|
3274 |
} else if (prefixes & PREFIX_REPZ) { |
3275 |
gen_repz_scas(s, ot, pc_start - s->cs_base, s->pc - s->cs_base, 0);
|
3276 |
} else {
|
3277 |
gen_scas(s, ot); |
3278 |
s->cc_op = CC_OP_SUBB + ot; |
3279 |
} |
3280 |
break;
|
3281 |
|
3282 |
case 0xa6: /* cmpsS */ |
3283 |
case 0xa7: |
3284 |
if ((b & 1) == 0) |
3285 |
ot = OT_BYTE; |
3286 |
else
|
3287 |
ot = dflag ? OT_LONG : OT_WORD; |
3288 |
if (prefixes & PREFIX_REPNZ) {
|
3289 |
gen_repz_cmps(s, ot, pc_start - s->cs_base, s->pc - s->cs_base, 1);
|
3290 |
} else if (prefixes & PREFIX_REPZ) { |
3291 |
gen_repz_cmps(s, ot, pc_start - s->cs_base, s->pc - s->cs_base, 0);
|
3292 |
} else {
|
3293 |
gen_cmps(s, ot); |
3294 |
s->cc_op = CC_OP_SUBB + ot; |
3295 |
} |
3296 |
break;
|
3297 |
case 0x6c: /* insS */ |
3298 |
case 0x6d: |
3299 |
if ((b & 1) == 0) |
3300 |
ot = OT_BYTE; |
3301 |
else
|
3302 |
ot = dflag ? OT_LONG : OT_WORD; |
3303 |
gen_check_io(s, ot, 1, pc_start - s->cs_base);
|
3304 |
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
3305 |
gen_repz_ins(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
3306 |
} else {
|
3307 |
gen_ins(s, ot); |
3308 |
} |
3309 |
break;
|
3310 |
case 0x6e: /* outsS */ |
3311 |
case 0x6f: |
3312 |
if ((b & 1) == 0) |
3313 |
ot = OT_BYTE; |
3314 |
else
|
3315 |
ot = dflag ? OT_LONG : OT_WORD; |
3316 |
gen_check_io(s, ot, 1, pc_start - s->cs_base);
|
3317 |
if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ)) {
|
3318 |
gen_repz_outs(s, ot, pc_start - s->cs_base, s->pc - s->cs_base); |
3319 |
} else {
|
3320 |
gen_outs(s, ot); |
3321 |
} |
3322 |
break;
|
3323 |
|
3324 |
/************************/
|
3325 |
/* port I/O */
|
3326 |
case 0xe4: |
3327 |
case 0xe5: |
3328 |
if ((b & 1) == 0) |
3329 |
ot = OT_BYTE; |
3330 |
else
|
3331 |
ot = dflag ? OT_LONG : OT_WORD; |
3332 |
val = ldub_code(s->pc++); |
3333 |
gen_op_movl_T0_im(val); |
3334 |
gen_check_io(s, ot, 0, pc_start - s->cs_base);
|
3335 |
gen_op_in[ot](); |
3336 |
gen_op_mov_reg_T1[ot][R_EAX](); |
3337 |
break;
|
3338 |
case 0xe6: |
3339 |
case 0xe7: |
3340 |
if ((b & 1) == 0) |
3341 |
ot = OT_BYTE; |
3342 |
else
|
3343 |
ot = dflag ? OT_LONG : OT_WORD; |
3344 |
val = ldub_code(s->pc++); |
3345 |
gen_op_movl_T0_im(val); |
3346 |
gen_check_io(s, ot, 0, pc_start - s->cs_base);
|
3347 |
gen_op_mov_TN_reg[ot][1][R_EAX]();
|
3348 |
gen_op_out[ot](); |
3349 |
break;
|
3350 |
case 0xec: |
3351 |
case 0xed: |
3352 |
if ((b & 1) == 0) |
3353 |
ot = OT_BYTE; |
3354 |
else
|
3355 |
ot = dflag ? OT_LONG : OT_WORD; |
3356 |
gen_op_mov_TN_reg[OT_WORD][0][R_EDX]();
|
3357 |
gen_op_andl_T0_ffff(); |
3358 |
gen_check_io(s, ot, 0, pc_start - s->cs_base);
|
3359 |
gen_op_in[ot](); |
3360 |
gen_op_mov_reg_T1[ot][R_EAX](); |
3361 |
break;
|
3362 |
case 0xee: |
3363 |
case 0xef: |
3364 |
if ((b & 1) == 0) |
3365 |
ot = OT_BYTE; |
3366 |
else
|
3367 |
ot = dflag ? OT_LONG : OT_WORD; |
3368 |
gen_op_mov_TN_reg[OT_WORD][0][R_EDX]();
|
3369 |
gen_op_andl_T0_ffff(); |
3370 |
gen_check_io(s, ot, 0, pc_start - s->cs_base);
|
3371 |
gen_op_mov_TN_reg[ot][1][R_EAX]();
|
3372 |
gen_op_out[ot](); |
3373 |
break;
|
3374 |
|
3375 |
/************************/
|
3376 |
/* control */
|
3377 |
case 0xc2: /* ret im */ |
3378 |
val = ldsw_code(s->pc); |
3379 |
s->pc += 2;
|
3380 |
gen_pop_T0(s); |
3381 |
gen_stack_update(s, val + (2 << s->dflag));
|
3382 |
if (s->dflag == 0) |
3383 |
gen_op_andl_T0_ffff(); |
3384 |
gen_op_jmp_T0(); |
3385 |
gen_eob(s); |
3386 |
break;
|
3387 |
case 0xc3: /* ret */ |
3388 |
gen_pop_T0(s); |
3389 |
gen_pop_update(s); |
3390 |
if (s->dflag == 0) |
3391 |
gen_op_andl_T0_ffff(); |
3392 |
gen_op_jmp_T0(); |
3393 |
gen_eob(s); |
3394 |
break;
|
3395 |
case 0xca: /* lret im */ |
3396 |
val = ldsw_code(s->pc); |
3397 |
s->pc += 2;
|
3398 |
do_lret:
|
3399 |
if (s->pe && !s->vm86) {
|
3400 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3401 |
gen_op_set_cc_op(s->cc_op); |
3402 |
gen_op_jmp_im(pc_start - s->cs_base); |
3403 |
gen_op_lret_protected(s->dflag, val); |
3404 |
} else {
|
3405 |
gen_stack_A0(s); |
3406 |
/* pop offset */
|
3407 |
gen_op_ld_T0_A0[1 + s->dflag + s->mem_index]();
|
3408 |
if (s->dflag == 0) |
3409 |
gen_op_andl_T0_ffff(); |
3410 |
/* NOTE: keeping EIP updated is not a problem in case of
|
3411 |
exception */
|
3412 |
gen_op_jmp_T0(); |
3413 |
/* pop selector */
|
3414 |
gen_op_addl_A0_im(2 << s->dflag);
|
3415 |
gen_op_ld_T0_A0[1 + s->dflag + s->mem_index]();
|
3416 |
gen_op_movl_seg_T0_vm(offsetof(CPUX86State,segs[R_CS])); |
3417 |
/* add stack offset */
|
3418 |
gen_stack_update(s, val + (4 << s->dflag));
|
3419 |
} |
3420 |
gen_eob(s); |
3421 |
break;
|
3422 |
case 0xcb: /* lret */ |
3423 |
val = 0;
|
3424 |
goto do_lret;
|
3425 |
case 0xcf: /* iret */ |
3426 |
if (!s->pe) {
|
3427 |
/* real mode */
|
3428 |
gen_op_iret_real(s->dflag); |
3429 |
s->cc_op = CC_OP_EFLAGS; |
3430 |
} else if (s->vm86) { |
3431 |
if (s->iopl != 3) { |
3432 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3433 |
} else {
|
3434 |
gen_op_iret_real(s->dflag); |
3435 |
s->cc_op = CC_OP_EFLAGS; |
3436 |
} |
3437 |
} else {
|
3438 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3439 |
gen_op_set_cc_op(s->cc_op); |
3440 |
gen_op_jmp_im(pc_start - s->cs_base); |
3441 |
gen_op_iret_protected(s->dflag); |
3442 |
s->cc_op = CC_OP_EFLAGS; |
3443 |
} |
3444 |
gen_eob(s); |
3445 |
break;
|
3446 |
case 0xe8: /* call im */ |
3447 |
{ |
3448 |
unsigned int next_eip; |
3449 |
ot = dflag ? OT_LONG : OT_WORD; |
3450 |
val = insn_get(s, ot); |
3451 |
next_eip = s->pc - s->cs_base; |
3452 |
val += next_eip; |
3453 |
if (s->dflag == 0) |
3454 |
val &= 0xffff;
|
3455 |
gen_op_movl_T0_im(next_eip); |
3456 |
gen_push_T0(s); |
3457 |
gen_jmp(s, val); |
3458 |
} |
3459 |
break;
|
3460 |
case 0x9a: /* lcall im */ |
3461 |
{ |
3462 |
unsigned int selector, offset; |
3463 |
|
3464 |
ot = dflag ? OT_LONG : OT_WORD; |
3465 |
offset = insn_get(s, ot); |
3466 |
selector = insn_get(s, OT_WORD); |
3467 |
|
3468 |
gen_op_movl_T0_im(selector); |
3469 |
gen_op_movl_T1_im(offset); |
3470 |
} |
3471 |
goto do_lcall;
|
3472 |
case 0xe9: /* jmp */ |
3473 |
ot = dflag ? OT_LONG : OT_WORD; |
3474 |
val = insn_get(s, ot); |
3475 |
val += s->pc - s->cs_base; |
3476 |
if (s->dflag == 0) |
3477 |
val = val & 0xffff;
|
3478 |
gen_jmp(s, val); |
3479 |
break;
|
3480 |
case 0xea: /* ljmp im */ |
3481 |
{ |
3482 |
unsigned int selector, offset; |
3483 |
|
3484 |
ot = dflag ? OT_LONG : OT_WORD; |
3485 |
offset = insn_get(s, ot); |
3486 |
selector = insn_get(s, OT_WORD); |
3487 |
|
3488 |
gen_op_movl_T0_im(selector); |
3489 |
gen_op_movl_T1_im(offset); |
3490 |
} |
3491 |
goto do_ljmp;
|
3492 |
case 0xeb: /* jmp Jb */ |
3493 |
val = (int8_t)insn_get(s, OT_BYTE); |
3494 |
val += s->pc - s->cs_base; |
3495 |
if (s->dflag == 0) |
3496 |
val = val & 0xffff;
|
3497 |
gen_jmp(s, val); |
3498 |
break;
|
3499 |
case 0x70 ... 0x7f: /* jcc Jb */ |
3500 |
val = (int8_t)insn_get(s, OT_BYTE); |
3501 |
goto do_jcc;
|
3502 |
case 0x180 ... 0x18f: /* jcc Jv */ |
3503 |
if (dflag) {
|
3504 |
val = insn_get(s, OT_LONG); |
3505 |
} else {
|
3506 |
val = (int16_t)insn_get(s, OT_WORD); |
3507 |
} |
3508 |
do_jcc:
|
3509 |
next_eip = s->pc - s->cs_base; |
3510 |
val += next_eip; |
3511 |
if (s->dflag == 0) |
3512 |
val &= 0xffff;
|
3513 |
gen_jcc(s, b, val, next_eip); |
3514 |
break;
|
3515 |
|
3516 |
case 0x190 ... 0x19f: /* setcc Gv */ |
3517 |
modrm = ldub_code(s->pc++); |
3518 |
gen_setcc(s, b); |
3519 |
gen_ldst_modrm(s, modrm, OT_BYTE, OR_TMP0, 1);
|
3520 |
break;
|
3521 |
case 0x140 ... 0x14f: /* cmov Gv, Ev */ |
3522 |
ot = dflag ? OT_LONG : OT_WORD; |
3523 |
modrm = ldub_code(s->pc++); |
3524 |
reg = (modrm >> 3) & 7; |
3525 |
mod = (modrm >> 6) & 3; |
3526 |
gen_setcc(s, b); |
3527 |
if (mod != 3) { |
3528 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3529 |
gen_op_ld_T1_A0[ot + s->mem_index](); |
3530 |
} else {
|
3531 |
rm = modrm & 7;
|
3532 |
gen_op_mov_TN_reg[ot][1][rm]();
|
3533 |
} |
3534 |
gen_op_cmov_reg_T1_T0[ot - OT_WORD][reg](); |
3535 |
break;
|
3536 |
|
3537 |
/************************/
|
3538 |
/* flags */
|
3539 |
case 0x9c: /* pushf */ |
3540 |
if (s->vm86 && s->iopl != 3) { |
3541 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3542 |
} else {
|
3543 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3544 |
gen_op_set_cc_op(s->cc_op); |
3545 |
gen_op_movl_T0_eflags(); |
3546 |
gen_push_T0(s); |
3547 |
} |
3548 |
break;
|
3549 |
case 0x9d: /* popf */ |
3550 |
if (s->vm86 && s->iopl != 3) { |
3551 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3552 |
} else {
|
3553 |
gen_pop_T0(s); |
3554 |
if (s->cpl == 0) { |
3555 |
if (s->dflag) {
|
3556 |
gen_op_movl_eflags_T0_cpl0(); |
3557 |
} else {
|
3558 |
gen_op_movw_eflags_T0_cpl0(); |
3559 |
} |
3560 |
} else {
|
3561 |
if (s->cpl <= s->iopl) {
|
3562 |
if (s->dflag) {
|
3563 |
gen_op_movl_eflags_T0_io(); |
3564 |
} else {
|
3565 |
gen_op_movw_eflags_T0_io(); |
3566 |
} |
3567 |
} else {
|
3568 |
if (s->dflag) {
|
3569 |
gen_op_movl_eflags_T0(); |
3570 |
} else {
|
3571 |
gen_op_movw_eflags_T0(); |
3572 |
} |
3573 |
} |
3574 |
} |
3575 |
gen_pop_update(s); |
3576 |
s->cc_op = CC_OP_EFLAGS; |
3577 |
/* abort translation because TF flag may change */
|
3578 |
gen_op_jmp_im(s->pc - s->cs_base); |
3579 |
gen_eob(s); |
3580 |
} |
3581 |
break;
|
3582 |
case 0x9e: /* sahf */ |
3583 |
gen_op_mov_TN_reg[OT_BYTE][0][R_AH]();
|
3584 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3585 |
gen_op_set_cc_op(s->cc_op); |
3586 |
gen_op_movb_eflags_T0(); |
3587 |
s->cc_op = CC_OP_EFLAGS; |
3588 |
break;
|
3589 |
case 0x9f: /* lahf */ |
3590 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3591 |
gen_op_set_cc_op(s->cc_op); |
3592 |
gen_op_movl_T0_eflags(); |
3593 |
gen_op_mov_reg_T0[OT_BYTE][R_AH](); |
3594 |
break;
|
3595 |
case 0xf5: /* cmc */ |
3596 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3597 |
gen_op_set_cc_op(s->cc_op); |
3598 |
gen_op_cmc(); |
3599 |
s->cc_op = CC_OP_EFLAGS; |
3600 |
break;
|
3601 |
case 0xf8: /* clc */ |
3602 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3603 |
gen_op_set_cc_op(s->cc_op); |
3604 |
gen_op_clc(); |
3605 |
s->cc_op = CC_OP_EFLAGS; |
3606 |
break;
|
3607 |
case 0xf9: /* stc */ |
3608 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3609 |
gen_op_set_cc_op(s->cc_op); |
3610 |
gen_op_stc(); |
3611 |
s->cc_op = CC_OP_EFLAGS; |
3612 |
break;
|
3613 |
case 0xfc: /* cld */ |
3614 |
gen_op_cld(); |
3615 |
break;
|
3616 |
case 0xfd: /* std */ |
3617 |
gen_op_std(); |
3618 |
break;
|
3619 |
|
3620 |
/************************/
|
3621 |
/* bit operations */
|
3622 |
case 0x1ba: /* bt/bts/btr/btc Gv, im */ |
3623 |
ot = dflag ? OT_LONG : OT_WORD; |
3624 |
modrm = ldub_code(s->pc++); |
3625 |
op = (modrm >> 3) & 7; |
3626 |
mod = (modrm >> 6) & 3; |
3627 |
rm = modrm & 7;
|
3628 |
if (mod != 3) { |
3629 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3630 |
gen_op_ld_T0_A0[ot + s->mem_index](); |
3631 |
} else {
|
3632 |
gen_op_mov_TN_reg[ot][0][rm]();
|
3633 |
} |
3634 |
/* load shift */
|
3635 |
val = ldub_code(s->pc++); |
3636 |
gen_op_movl_T1_im(val); |
3637 |
if (op < 4) |
3638 |
goto illegal_op;
|
3639 |
op -= 4;
|
3640 |
gen_op_btx_T0_T1_cc[ot - OT_WORD][op](); |
3641 |
s->cc_op = CC_OP_SARB + ot; |
3642 |
if (op != 0) { |
3643 |
if (mod != 3) |
3644 |
gen_op_st_T0_A0[ot + s->mem_index](); |
3645 |
else
|
3646 |
gen_op_mov_reg_T0[ot][rm](); |
3647 |
gen_op_update_bt_cc(); |
3648 |
} |
3649 |
break;
|
3650 |
case 0x1a3: /* bt Gv, Ev */ |
3651 |
op = 0;
|
3652 |
goto do_btx;
|
3653 |
case 0x1ab: /* bts */ |
3654 |
op = 1;
|
3655 |
goto do_btx;
|
3656 |
case 0x1b3: /* btr */ |
3657 |
op = 2;
|
3658 |
goto do_btx;
|
3659 |
case 0x1bb: /* btc */ |
3660 |
op = 3;
|
3661 |
do_btx:
|
3662 |
ot = dflag ? OT_LONG : OT_WORD; |
3663 |
modrm = ldub_code(s->pc++); |
3664 |
reg = (modrm >> 3) & 7; |
3665 |
mod = (modrm >> 6) & 3; |
3666 |
rm = modrm & 7;
|
3667 |
gen_op_mov_TN_reg[OT_LONG][1][reg]();
|
3668 |
if (mod != 3) { |
3669 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3670 |
/* specific case: we need to add a displacement */
|
3671 |
if (ot == OT_WORD)
|
3672 |
gen_op_add_bitw_A0_T1(); |
3673 |
else
|
3674 |
gen_op_add_bitl_A0_T1(); |
3675 |
gen_op_ld_T0_A0[ot + s->mem_index](); |
3676 |
} else {
|
3677 |
gen_op_mov_TN_reg[ot][0][rm]();
|
3678 |
} |
3679 |
gen_op_btx_T0_T1_cc[ot - OT_WORD][op](); |
3680 |
s->cc_op = CC_OP_SARB + ot; |
3681 |
if (op != 0) { |
3682 |
if (mod != 3) |
3683 |
gen_op_st_T0_A0[ot + s->mem_index](); |
3684 |
else
|
3685 |
gen_op_mov_reg_T0[ot][rm](); |
3686 |
gen_op_update_bt_cc(); |
3687 |
} |
3688 |
break;
|
3689 |
case 0x1bc: /* bsf */ |
3690 |
case 0x1bd: /* bsr */ |
3691 |
ot = dflag ? OT_LONG : OT_WORD; |
3692 |
modrm = ldub_code(s->pc++); |
3693 |
reg = (modrm >> 3) & 7; |
3694 |
gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
|
3695 |
gen_op_bsx_T0_cc[ot - OT_WORD][b & 1]();
|
3696 |
/* NOTE: we always write back the result. Intel doc says it is
|
3697 |
undefined if T0 == 0 */
|
3698 |
gen_op_mov_reg_T0[ot][reg](); |
3699 |
s->cc_op = CC_OP_LOGICB + ot; |
3700 |
break;
|
3701 |
/************************/
|
3702 |
/* bcd */
|
3703 |
case 0x27: /* daa */ |
3704 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3705 |
gen_op_set_cc_op(s->cc_op); |
3706 |
gen_op_daa(); |
3707 |
s->cc_op = CC_OP_EFLAGS; |
3708 |
break;
|
3709 |
case 0x2f: /* das */ |
3710 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3711 |
gen_op_set_cc_op(s->cc_op); |
3712 |
gen_op_das(); |
3713 |
s->cc_op = CC_OP_EFLAGS; |
3714 |
break;
|
3715 |
case 0x37: /* aaa */ |
3716 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3717 |
gen_op_set_cc_op(s->cc_op); |
3718 |
gen_op_aaa(); |
3719 |
s->cc_op = CC_OP_EFLAGS; |
3720 |
break;
|
3721 |
case 0x3f: /* aas */ |
3722 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3723 |
gen_op_set_cc_op(s->cc_op); |
3724 |
gen_op_aas(); |
3725 |
s->cc_op = CC_OP_EFLAGS; |
3726 |
break;
|
3727 |
case 0xd4: /* aam */ |
3728 |
val = ldub_code(s->pc++); |
3729 |
gen_op_aam(val); |
3730 |
s->cc_op = CC_OP_LOGICB; |
3731 |
break;
|
3732 |
case 0xd5: /* aad */ |
3733 |
val = ldub_code(s->pc++); |
3734 |
gen_op_aad(val); |
3735 |
s->cc_op = CC_OP_LOGICB; |
3736 |
break;
|
3737 |
/************************/
|
3738 |
/* misc */
|
3739 |
case 0x90: /* nop */ |
3740 |
break;
|
3741 |
case 0x9b: /* fwait */ |
3742 |
break;
|
3743 |
case 0xcc: /* int3 */ |
3744 |
gen_interrupt(s, EXCP03_INT3, pc_start - s->cs_base, s->pc - s->cs_base); |
3745 |
break;
|
3746 |
case 0xcd: /* int N */ |
3747 |
val = ldub_code(s->pc++); |
3748 |
if (s->vm86 && s->iopl != 3) { |
3749 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3750 |
} else {
|
3751 |
gen_interrupt(s, val, pc_start - s->cs_base, s->pc - s->cs_base); |
3752 |
} |
3753 |
break;
|
3754 |
case 0xce: /* into */ |
3755 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3756 |
gen_op_set_cc_op(s->cc_op); |
3757 |
gen_op_into(s->pc - s->cs_base); |
3758 |
break;
|
3759 |
case 0xf1: /* icebp (undocumented, exits to external debugger) */ |
3760 |
gen_debug(s, pc_start - s->cs_base); |
3761 |
break;
|
3762 |
case 0xfa: /* cli */ |
3763 |
if (!s->vm86) {
|
3764 |
if (s->cpl <= s->iopl) {
|
3765 |
gen_op_cli(); |
3766 |
} else {
|
3767 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3768 |
} |
3769 |
} else {
|
3770 |
if (s->iopl == 3) { |
3771 |
gen_op_cli(); |
3772 |
} else {
|
3773 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3774 |
} |
3775 |
} |
3776 |
break;
|
3777 |
case 0xfb: /* sti */ |
3778 |
if (!s->vm86) {
|
3779 |
if (s->cpl <= s->iopl) {
|
3780 |
gen_sti:
|
3781 |
gen_op_sti(); |
3782 |
/* interruptions are enabled only the first insn after sti */
|
3783 |
/* If several instructions disable interrupts, only the
|
3784 |
_first_ does it */
|
3785 |
if (!(s->tb->flags & HF_INHIBIT_IRQ_MASK))
|
3786 |
gen_op_set_inhibit_irq(); |
3787 |
/* give a chance to handle pending irqs */
|
3788 |
gen_op_jmp_im(s->pc - s->cs_base); |
3789 |
gen_eob(s); |
3790 |
} else {
|
3791 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3792 |
} |
3793 |
} else {
|
3794 |
if (s->iopl == 3) { |
3795 |
goto gen_sti;
|
3796 |
} else {
|
3797 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3798 |
} |
3799 |
} |
3800 |
break;
|
3801 |
case 0x62: /* bound */ |
3802 |
ot = dflag ? OT_LONG : OT_WORD; |
3803 |
modrm = ldub_code(s->pc++); |
3804 |
reg = (modrm >> 3) & 7; |
3805 |
mod = (modrm >> 6) & 3; |
3806 |
if (mod == 3) |
3807 |
goto illegal_op;
|
3808 |
gen_op_mov_reg_T0[ot][reg](); |
3809 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3810 |
if (ot == OT_WORD)
|
3811 |
gen_op_boundw(pc_start - s->cs_base); |
3812 |
else
|
3813 |
gen_op_boundl(pc_start - s->cs_base); |
3814 |
break;
|
3815 |
case 0x1c8 ... 0x1cf: /* bswap reg */ |
3816 |
reg = b & 7;
|
3817 |
gen_op_mov_TN_reg[OT_LONG][0][reg]();
|
3818 |
gen_op_bswapl_T0(); |
3819 |
gen_op_mov_reg_T0[OT_LONG][reg](); |
3820 |
break;
|
3821 |
case 0xd6: /* salc */ |
3822 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3823 |
gen_op_set_cc_op(s->cc_op); |
3824 |
gen_op_salc(); |
3825 |
break;
|
3826 |
case 0xe0: /* loopnz */ |
3827 |
case 0xe1: /* loopz */ |
3828 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3829 |
gen_op_set_cc_op(s->cc_op); |
3830 |
/* FALL THRU */
|
3831 |
case 0xe2: /* loop */ |
3832 |
case 0xe3: /* jecxz */ |
3833 |
val = (int8_t)insn_get(s, OT_BYTE); |
3834 |
next_eip = s->pc - s->cs_base; |
3835 |
val += next_eip; |
3836 |
if (s->dflag == 0) |
3837 |
val &= 0xffff;
|
3838 |
gen_op_loop[s->aflag][b & 3](val, next_eip);
|
3839 |
gen_eob(s); |
3840 |
break;
|
3841 |
case 0x130: /* wrmsr */ |
3842 |
case 0x132: /* rdmsr */ |
3843 |
if (s->cpl != 0) { |
3844 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3845 |
} else {
|
3846 |
if (b & 2) |
3847 |
gen_op_rdmsr(); |
3848 |
else
|
3849 |
gen_op_wrmsr(); |
3850 |
} |
3851 |
break;
|
3852 |
case 0x131: /* rdtsc */ |
3853 |
gen_op_rdtsc(); |
3854 |
break;
|
3855 |
case 0x1a2: /* cpuid */ |
3856 |
gen_op_cpuid(); |
3857 |
break;
|
3858 |
case 0xf4: /* hlt */ |
3859 |
if (s->cpl != 0) { |
3860 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3861 |
} else {
|
3862 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3863 |
gen_op_set_cc_op(s->cc_op); |
3864 |
gen_op_jmp_im(s->pc - s->cs_base); |
3865 |
gen_op_hlt(); |
3866 |
s->is_jmp = 3;
|
3867 |
} |
3868 |
break;
|
3869 |
case 0x100: |
3870 |
modrm = ldub_code(s->pc++); |
3871 |
mod = (modrm >> 6) & 3; |
3872 |
op = (modrm >> 3) & 7; |
3873 |
switch(op) {
|
3874 |
case 0: /* sldt */ |
3875 |
if (!s->pe || s->vm86)
|
3876 |
goto illegal_op;
|
3877 |
gen_op_movl_T0_env(offsetof(CPUX86State,ldt.selector)); |
3878 |
ot = OT_WORD; |
3879 |
if (mod == 3) |
3880 |
ot += s->dflag; |
3881 |
gen_ldst_modrm(s, modrm, ot, OR_TMP0, 1);
|
3882 |
break;
|
3883 |
case 2: /* lldt */ |
3884 |
if (!s->pe || s->vm86)
|
3885 |
goto illegal_op;
|
3886 |
if (s->cpl != 0) { |
3887 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3888 |
} else {
|
3889 |
gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
3890 |
gen_op_jmp_im(pc_start - s->cs_base); |
3891 |
gen_op_lldt_T0(); |
3892 |
} |
3893 |
break;
|
3894 |
case 1: /* str */ |
3895 |
if (!s->pe || s->vm86)
|
3896 |
goto illegal_op;
|
3897 |
gen_op_movl_T0_env(offsetof(CPUX86State,tr.selector)); |
3898 |
ot = OT_WORD; |
3899 |
if (mod == 3) |
3900 |
ot += s->dflag; |
3901 |
gen_ldst_modrm(s, modrm, ot, OR_TMP0, 1);
|
3902 |
break;
|
3903 |
case 3: /* ltr */ |
3904 |
if (!s->pe || s->vm86)
|
3905 |
goto illegal_op;
|
3906 |
if (s->cpl != 0) { |
3907 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3908 |
} else {
|
3909 |
gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
3910 |
gen_op_jmp_im(pc_start - s->cs_base); |
3911 |
gen_op_ltr_T0(); |
3912 |
} |
3913 |
break;
|
3914 |
case 4: /* verr */ |
3915 |
case 5: /* verw */ |
3916 |
if (!s->pe || s->vm86)
|
3917 |
goto illegal_op;
|
3918 |
gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
3919 |
if (s->cc_op != CC_OP_DYNAMIC)
|
3920 |
gen_op_set_cc_op(s->cc_op); |
3921 |
if (op == 4) |
3922 |
gen_op_verr(); |
3923 |
else
|
3924 |
gen_op_verw(); |
3925 |
s->cc_op = CC_OP_EFLAGS; |
3926 |
break;
|
3927 |
default:
|
3928 |
goto illegal_op;
|
3929 |
} |
3930 |
break;
|
3931 |
case 0x101: |
3932 |
modrm = ldub_code(s->pc++); |
3933 |
mod = (modrm >> 6) & 3; |
3934 |
op = (modrm >> 3) & 7; |
3935 |
switch(op) {
|
3936 |
case 0: /* sgdt */ |
3937 |
case 1: /* sidt */ |
3938 |
if (mod == 3) |
3939 |
goto illegal_op;
|
3940 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3941 |
if (op == 0) |
3942 |
gen_op_movl_T0_env(offsetof(CPUX86State,gdt.limit)); |
3943 |
else
|
3944 |
gen_op_movl_T0_env(offsetof(CPUX86State,idt.limit)); |
3945 |
gen_op_st_T0_A0[OT_WORD + s->mem_index](); |
3946 |
gen_op_addl_A0_im(2);
|
3947 |
if (op == 0) |
3948 |
gen_op_movl_T0_env(offsetof(CPUX86State,gdt.base)); |
3949 |
else
|
3950 |
gen_op_movl_T0_env(offsetof(CPUX86State,idt.base)); |
3951 |
if (!s->dflag)
|
3952 |
gen_op_andl_T0_im(0xffffff);
|
3953 |
gen_op_st_T0_A0[OT_LONG + s->mem_index](); |
3954 |
break;
|
3955 |
case 2: /* lgdt */ |
3956 |
case 3: /* lidt */ |
3957 |
if (mod == 3) |
3958 |
goto illegal_op;
|
3959 |
if (s->cpl != 0) { |
3960 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3961 |
} else {
|
3962 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3963 |
gen_op_ld_T1_A0[OT_WORD + s->mem_index](); |
3964 |
gen_op_addl_A0_im(2);
|
3965 |
gen_op_ld_T0_A0[OT_LONG + s->mem_index](); |
3966 |
if (!s->dflag)
|
3967 |
gen_op_andl_T0_im(0xffffff);
|
3968 |
if (op == 2) { |
3969 |
gen_op_movl_env_T0(offsetof(CPUX86State,gdt.base)); |
3970 |
gen_op_movl_env_T1(offsetof(CPUX86State,gdt.limit)); |
3971 |
} else {
|
3972 |
gen_op_movl_env_T0(offsetof(CPUX86State,idt.base)); |
3973 |
gen_op_movl_env_T1(offsetof(CPUX86State,idt.limit)); |
3974 |
} |
3975 |
} |
3976 |
break;
|
3977 |
case 4: /* smsw */ |
3978 |
gen_op_movl_T0_env(offsetof(CPUX86State,cr[0]));
|
3979 |
gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 1);
|
3980 |
break;
|
3981 |
case 6: /* lmsw */ |
3982 |
if (s->cpl != 0) { |
3983 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3984 |
} else {
|
3985 |
gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0);
|
3986 |
gen_op_lmsw_T0(); |
3987 |
gen_op_jmp_im(s->pc - s->cs_base); |
3988 |
gen_eob(s); |
3989 |
} |
3990 |
break;
|
3991 |
case 7: /* invlpg */ |
3992 |
if (s->cpl != 0) { |
3993 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
3994 |
} else {
|
3995 |
if (mod == 3) |
3996 |
goto illegal_op;
|
3997 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
3998 |
gen_op_invlpg_A0(); |
3999 |
gen_op_jmp_im(s->pc - s->cs_base); |
4000 |
gen_eob(s); |
4001 |
} |
4002 |
break;
|
4003 |
default:
|
4004 |
goto illegal_op;
|
4005 |
} |
4006 |
break;
|
4007 |
case 0x108: /* invd */ |
4008 |
case 0x109: /* wbinvd */ |
4009 |
if (s->cpl != 0) { |
4010 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
4011 |
} else {
|
4012 |
/* nothing to do */
|
4013 |
} |
4014 |
break;
|
4015 |
case 0x63: /* arpl */ |
4016 |
if (!s->pe || s->vm86)
|
4017 |
goto illegal_op;
|
4018 |
ot = dflag ? OT_LONG : OT_WORD; |
4019 |
modrm = ldub_code(s->pc++); |
4020 |
reg = (modrm >> 3) & 7; |
4021 |
mod = (modrm >> 6) & 3; |
4022 |
rm = modrm & 7;
|
4023 |
if (mod != 3) { |
4024 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
4025 |
gen_op_ld_T0_A0[ot + s->mem_index](); |
4026 |
} else {
|
4027 |
gen_op_mov_TN_reg[ot][0][rm]();
|
4028 |
} |
4029 |
if (s->cc_op != CC_OP_DYNAMIC)
|
4030 |
gen_op_set_cc_op(s->cc_op); |
4031 |
gen_op_arpl(); |
4032 |
s->cc_op = CC_OP_EFLAGS; |
4033 |
if (mod != 3) { |
4034 |
gen_op_st_T0_A0[ot + s->mem_index](); |
4035 |
} else {
|
4036 |
gen_op_mov_reg_T0[ot][rm](); |
4037 |
} |
4038 |
gen_op_arpl_update(); |
4039 |
break;
|
4040 |
case 0x102: /* lar */ |
4041 |
case 0x103: /* lsl */ |
4042 |
if (!s->pe || s->vm86)
|
4043 |
goto illegal_op;
|
4044 |
ot = dflag ? OT_LONG : OT_WORD; |
4045 |
modrm = ldub_code(s->pc++); |
4046 |
reg = (modrm >> 3) & 7; |
4047 |
gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
|
4048 |
gen_op_mov_TN_reg[ot][1][reg]();
|
4049 |
if (s->cc_op != CC_OP_DYNAMIC)
|
4050 |
gen_op_set_cc_op(s->cc_op); |
4051 |
if (b == 0x102) |
4052 |
gen_op_lar(); |
4053 |
else
|
4054 |
gen_op_lsl(); |
4055 |
s->cc_op = CC_OP_EFLAGS; |
4056 |
gen_op_mov_reg_T1[ot][reg](); |
4057 |
break;
|
4058 |
case 0x118: |
4059 |
modrm = ldub_code(s->pc++); |
4060 |
mod = (modrm >> 6) & 3; |
4061 |
op = (modrm >> 3) & 7; |
4062 |
switch(op) {
|
4063 |
case 0: /* prefetchnta */ |
4064 |
case 1: /* prefetchnt0 */ |
4065 |
case 2: /* prefetchnt0 */ |
4066 |
case 3: /* prefetchnt0 */ |
4067 |
if (mod == 3) |
4068 |
goto illegal_op;
|
4069 |
gen_lea_modrm(s, modrm, ®_addr, &offset_addr); |
4070 |
/* nothing more to do */
|
4071 |
break;
|
4072 |
default:
|
4073 |
goto illegal_op;
|
4074 |
} |
4075 |
break;
|
4076 |
case 0x120: /* mov reg, crN */ |
4077 |
case 0x122: /* mov crN, reg */ |
4078 |
if (s->cpl != 0) { |
4079 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
4080 |
} else {
|
4081 |
modrm = ldub_code(s->pc++); |
4082 |
if ((modrm & 0xc0) != 0xc0) |
4083 |
goto illegal_op;
|
4084 |
rm = modrm & 7;
|
4085 |
reg = (modrm >> 3) & 7; |
4086 |
switch(reg) {
|
4087 |
case 0: |
4088 |
case 2: |
4089 |
case 3: |
4090 |
case 4: |
4091 |
if (b & 2) { |
4092 |
gen_op_mov_TN_reg[OT_LONG][0][rm]();
|
4093 |
gen_op_movl_crN_T0(reg); |
4094 |
gen_op_jmp_im(s->pc - s->cs_base); |
4095 |
gen_eob(s); |
4096 |
} else {
|
4097 |
gen_op_movl_T0_env(offsetof(CPUX86State,cr[reg])); |
4098 |
gen_op_mov_reg_T0[OT_LONG][rm](); |
4099 |
} |
4100 |
break;
|
4101 |
default:
|
4102 |
goto illegal_op;
|
4103 |
} |
4104 |
} |
4105 |
break;
|
4106 |
case 0x121: /* mov reg, drN */ |
4107 |
case 0x123: /* mov drN, reg */ |
4108 |
if (s->cpl != 0) { |
4109 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
4110 |
} else {
|
4111 |
modrm = ldub_code(s->pc++); |
4112 |
if ((modrm & 0xc0) != 0xc0) |
4113 |
goto illegal_op;
|
4114 |
rm = modrm & 7;
|
4115 |
reg = (modrm >> 3) & 7; |
4116 |
/* XXX: do it dynamically with CR4.DE bit */
|
4117 |
if (reg == 4 || reg == 5) |
4118 |
goto illegal_op;
|
4119 |
if (b & 2) { |
4120 |
gen_op_mov_TN_reg[OT_LONG][0][rm]();
|
4121 |
gen_op_movl_drN_T0(reg); |
4122 |
gen_op_jmp_im(s->pc - s->cs_base); |
4123 |
gen_eob(s); |
4124 |
} else {
|
4125 |
gen_op_movl_T0_env(offsetof(CPUX86State,dr[reg])); |
4126 |
gen_op_mov_reg_T0[OT_LONG][rm](); |
4127 |
} |
4128 |
} |
4129 |
break;
|
4130 |
case 0x106: /* clts */ |
4131 |
if (s->cpl != 0) { |
4132 |
gen_exception(s, EXCP0D_GPF, pc_start - s->cs_base); |
4133 |
} else {
|
4134 |
gen_op_clts(); |
4135 |
} |
4136 |
break;
|
4137 |
default:
|
4138 |
goto illegal_op;
|
4139 |
} |
4140 |
/* lock generation */
|
4141 |
if (s->prefix & PREFIX_LOCK)
|
4142 |
gen_op_unlock(); |
4143 |
return s->pc;
|
4144 |
illegal_op:
|
4145 |
/* XXX: ensure that no lock was generated */
|
4146 |
gen_exception(s, EXCP06_ILLOP, pc_start - s->cs_base); |
4147 |
return s->pc;
|
4148 |
} |
4149 |
|
4150 |
#define CC_OSZAPC (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C)
|
4151 |
#define CC_OSZAP (CC_O | CC_S | CC_Z | CC_A | CC_P)
|
4152 |
|
4153 |
/* flags read by an operation */
|
4154 |
static uint16_t opc_read_flags[NB_OPS] = {
|
4155 |
[INDEX_op_aas] = CC_A, |
4156 |
[INDEX_op_aaa] = CC_A, |
4157 |
[INDEX_op_das] = CC_A | CC_C, |
4158 |
[INDEX_op_daa] = CC_A | CC_C, |
4159 |
|
4160 |
/* subtle: due to the incl/decl implementation, C is used */
|
4161 |
[INDEX_op_update_inc_cc] = CC_C, |
4162 |
|
4163 |
[INDEX_op_into] = CC_O, |
4164 |
|
4165 |
[INDEX_op_jb_subb] = CC_C, |
4166 |
[INDEX_op_jb_subw] = CC_C, |
4167 |
[INDEX_op_jb_subl] = CC_C, |
4168 |
|
4169 |
[INDEX_op_jz_subb] = CC_Z, |
4170 |
[INDEX_op_jz_subw] = CC_Z, |
4171 |
[INDEX_op_jz_subl] = CC_Z, |
4172 |
|
4173 |
[INDEX_op_jbe_subb] = CC_Z | CC_C, |
4174 |
[INDEX_op_jbe_subw] = CC_Z | CC_C, |
4175 |
[INDEX_op_jbe_subl] = CC_Z | CC_C, |
4176 |
|
4177 |
[INDEX_op_js_subb] = CC_S, |
4178 |
[INDEX_op_js_subw] = CC_S, |
4179 |
[INDEX_op_js_subl] = CC_S, |
4180 |
|
4181 |
[INDEX_op_jl_subb] = CC_O | CC_S, |
4182 |
[INDEX_op_jl_subw] = CC_O | CC_S, |
4183 |
[INDEX_op_jl_subl] = CC_O | CC_S, |
4184 |
|
4185 |
[INDEX_op_jle_subb] = CC_O | CC_S | CC_Z, |
4186 |
[INDEX_op_jle_subw] = CC_O | CC_S | CC_Z, |
4187 |
[INDEX_op_jle_subl] = CC_O | CC_S | CC_Z, |
4188 |
|
4189 |
[INDEX_op_loopnzw] = CC_Z, |
4190 |
[INDEX_op_loopnzl] = CC_Z, |
4191 |
[INDEX_op_loopzw] = CC_Z, |
4192 |
[INDEX_op_loopzl] = CC_Z, |
4193 |
|
4194 |
[INDEX_op_seto_T0_cc] = CC_O, |
4195 |
[INDEX_op_setb_T0_cc] = CC_C, |
4196 |
[INDEX_op_setz_T0_cc] = CC_Z, |
4197 |
[INDEX_op_setbe_T0_cc] = CC_Z | CC_C, |
4198 |
[INDEX_op_sets_T0_cc] = CC_S, |
4199 |
[INDEX_op_setp_T0_cc] = CC_P, |
4200 |
[INDEX_op_setl_T0_cc] = CC_O | CC_S, |
4201 |
[INDEX_op_setle_T0_cc] = CC_O | CC_S | CC_Z, |
4202 |
|
4203 |
[INDEX_op_setb_T0_subb] = CC_C, |
4204 |
[INDEX_op_setb_T0_subw] = CC_C, |
4205 |
[INDEX_op_setb_T0_subl] = CC_C, |
4206 |
|
4207 |
[INDEX_op_setz_T0_subb] = CC_Z, |
4208 |
[INDEX_op_setz_T0_subw] = CC_Z, |
4209 |
[INDEX_op_setz_T0_subl] = CC_Z, |
4210 |
|
4211 |
[INDEX_op_setbe_T0_subb] = CC_Z | CC_C, |
4212 |
[INDEX_op_setbe_T0_subw] = CC_Z | CC_C, |
4213 |
[INDEX_op_setbe_T0_subl] = CC_Z | CC_C, |
4214 |
|
4215 |
[INDEX_op_sets_T0_subb] = CC_S, |
4216 |
[INDEX_op_sets_T0_subw] = CC_S, |
4217 |
[INDEX_op_sets_T0_subl] = CC_S, |
4218 |
|
4219 |
[INDEX_op_setl_T0_subb] = CC_O | CC_S, |
4220 |
[INDEX_op_setl_T0_subw] = CC_O | CC_S, |
4221 |
[INDEX_op_setl_T0_subl] = CC_O | CC_S, |
4222 |
|
4223 |
[INDEX_op_setle_T0_subb] = CC_O | CC_S | CC_Z, |
4224 |
[INDEX_op_setle_T0_subw] = CC_O | CC_S | CC_Z, |
4225 |
[INDEX_op_setle_T0_subl] = CC_O | CC_S | CC_Z, |
4226 |
|
4227 |
[INDEX_op_movl_T0_eflags] = CC_OSZAPC, |
4228 |
[INDEX_op_cmc] = CC_C, |
4229 |
[INDEX_op_salc] = CC_C, |
4230 |
|
4231 |
#define DEF_READF(SUFFIX)\
|
4232 |
[INDEX_op_adcb ## SUFFIX ## _T0_T1_cc] = CC_C,\ |
4233 |
[INDEX_op_adcw ## SUFFIX ## _T0_T1_cc] = CC_C,\ |
4234 |
[INDEX_op_adcl ## SUFFIX ## _T0_T1_cc] = CC_C,\ |
4235 |
[INDEX_op_sbbb ## SUFFIX ## _T0_T1_cc] = CC_C,\ |
4236 |
[INDEX_op_sbbw ## SUFFIX ## _T0_T1_cc] = CC_C,\ |
4237 |
[INDEX_op_sbbl ## SUFFIX ## _T0_T1_cc] = CC_C,\ |
4238 |
\ |
4239 |
[INDEX_op_rclb ## SUFFIX ## _T0_T1_cc] = CC_C,\ |
4240 |
[INDEX_op_rclw ## SUFFIX ## _T0_T1_cc] = CC_C,\ |
4241 |
[INDEX_op_rcll ## SUFFIX ## _T0_T1_cc] = CC_C,\ |
4242 |
[INDEX_op_rcrb ## SUFFIX ## _T0_T1_cc] = CC_C,\ |
4243 |
[INDEX_op_rcrw ## SUFFIX ## _T0_T1_cc] = CC_C,\ |
4244 |
[INDEX_op_rcrl ## SUFFIX ## _T0_T1_cc] = CC_C, |
4245 |
|
4246 |
|
4247 |
DEF_READF() |
4248 |
DEF_READF(_raw) |
4249 |
#ifndef CONFIG_USER_ONLY
|
4250 |
DEF_READF(_kernel) |
4251 |
DEF_READF(_user) |
4252 |
#endif
|
4253 |
}; |
4254 |
|
4255 |
/* flags written by an operation */
|
4256 |
static uint16_t opc_write_flags[NB_OPS] = {
|
4257 |
[INDEX_op_update2_cc] = CC_OSZAPC, |
4258 |
[INDEX_op_update1_cc] = CC_OSZAPC, |
4259 |
[INDEX_op_cmpl_T0_T1_cc] = CC_OSZAPC, |
4260 |
[INDEX_op_update_neg_cc] = CC_OSZAPC, |
4261 |
/* subtle: due to the incl/decl implementation, C is used */
|
4262 |
[INDEX_op_update_inc_cc] = CC_OSZAPC, |
4263 |
[INDEX_op_testl_T0_T1_cc] = CC_OSZAPC, |
4264 |
|
4265 |
[INDEX_op_mulb_AL_T0] = CC_OSZAPC, |
4266 |
[INDEX_op_imulb_AL_T0] = CC_OSZAPC, |
4267 |
[INDEX_op_mulw_AX_T0] = CC_OSZAPC, |
4268 |
[INDEX_op_imulw_AX_T0] = CC_OSZAPC, |
4269 |
[INDEX_op_mull_EAX_T0] = CC_OSZAPC, |
4270 |
[INDEX_op_imull_EAX_T0] = CC_OSZAPC, |
4271 |
[INDEX_op_imulw_T0_T1] = CC_OSZAPC, |
4272 |
[INDEX_op_imull_T0_T1] = CC_OSZAPC, |
4273 |
|
4274 |
/* bcd */
|
4275 |
[INDEX_op_aam] = CC_OSZAPC, |
4276 |
[INDEX_op_aad] = CC_OSZAPC, |
4277 |
[INDEX_op_aas] = CC_OSZAPC, |
4278 |
[INDEX_op_aaa] = CC_OSZAPC, |
4279 |
[INDEX_op_das] = CC_OSZAPC, |
4280 |
[INDEX_op_daa] = CC_OSZAPC, |
4281 |
|
4282 |
[INDEX_op_movb_eflags_T0] = CC_S | CC_Z | CC_A | CC_P | CC_C, |
4283 |
[INDEX_op_movw_eflags_T0] = CC_OSZAPC, |
4284 |
[INDEX_op_movl_eflags_T0] = CC_OSZAPC, |
4285 |
[INDEX_op_movw_eflags_T0_io] = CC_OSZAPC, |
4286 |
[INDEX_op_movl_eflags_T0_io] = CC_OSZAPC, |
4287 |
[INDEX_op_movw_eflags_T0_cpl0] = CC_OSZAPC, |
4288 |
[INDEX_op_movl_eflags_T0_cpl0] = CC_OSZAPC, |
4289 |
[INDEX_op_clc] = CC_C, |
4290 |
[INDEX_op_stc] = CC_C, |
4291 |
[INDEX_op_cmc] = CC_C, |
4292 |
|
4293 |
[INDEX_op_btw_T0_T1_cc] = CC_OSZAPC, |
4294 |
[INDEX_op_btl_T0_T1_cc] = CC_OSZAPC, |
4295 |
[INDEX_op_btsw_T0_T1_cc] = CC_OSZAPC, |
4296 |
[INDEX_op_btsl_T0_T1_cc] = CC_OSZAPC, |
4297 |
[INDEX_op_btrw_T0_T1_cc] = CC_OSZAPC, |
4298 |
[INDEX_op_btrl_T0_T1_cc] = CC_OSZAPC, |
4299 |
[INDEX_op_btcw_T0_T1_cc] = CC_OSZAPC, |
4300 |
[INDEX_op_btcl_T0_T1_cc] = CC_OSZAPC, |
4301 |
|
4302 |
[INDEX_op_bsfw_T0_cc] = CC_OSZAPC, |
4303 |
[INDEX_op_bsfl_T0_cc] = CC_OSZAPC, |
4304 |
[INDEX_op_bsrw_T0_cc] = CC_OSZAPC, |
4305 |
[INDEX_op_bsrl_T0_cc] = CC_OSZAPC, |
4306 |
|
4307 |
[INDEX_op_cmpxchgb_T0_T1_EAX_cc] = CC_OSZAPC, |
4308 |
[INDEX_op_cmpxchgw_T0_T1_EAX_cc] = CC_OSZAPC, |
4309 |
[INDEX_op_cmpxchgl_T0_T1_EAX_cc] = CC_OSZAPC, |
4310 |
|
4311 |
[INDEX_op_cmpxchg8b] = CC_Z, |
4312 |
[INDEX_op_lar] = CC_Z, |
4313 |
[INDEX_op_lsl] = CC_Z, |
4314 |
[INDEX_op_fcomi_ST0_FT0] = CC_Z | CC_P | CC_C, |
4315 |
[INDEX_op_fucomi_ST0_FT0] = CC_Z | CC_P | CC_C, |
4316 |
|
4317 |
#define DEF_WRITEF(SUFFIX)\
|
4318 |
[INDEX_op_adcb ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4319 |
[INDEX_op_adcw ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4320 |
[INDEX_op_adcl ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4321 |
[INDEX_op_sbbb ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4322 |
[INDEX_op_sbbw ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4323 |
[INDEX_op_sbbl ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4324 |
\ |
4325 |
[INDEX_op_rolb ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\ |
4326 |
[INDEX_op_rolw ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\ |
4327 |
[INDEX_op_roll ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\ |
4328 |
[INDEX_op_rorb ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\ |
4329 |
[INDEX_op_rorw ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\ |
4330 |
[INDEX_op_rorl ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\ |
4331 |
\ |
4332 |
[INDEX_op_rclb ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\ |
4333 |
[INDEX_op_rclw ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\ |
4334 |
[INDEX_op_rcll ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\ |
4335 |
[INDEX_op_rcrb ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\ |
4336 |
[INDEX_op_rcrw ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\ |
4337 |
[INDEX_op_rcrl ## SUFFIX ## _T0_T1_cc] = CC_O | CC_C,\ |
4338 |
\ |
4339 |
[INDEX_op_shlb ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4340 |
[INDEX_op_shlw ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4341 |
[INDEX_op_shll ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4342 |
\ |
4343 |
[INDEX_op_shrb ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4344 |
[INDEX_op_shrw ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4345 |
[INDEX_op_shrl ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4346 |
\ |
4347 |
[INDEX_op_sarb ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4348 |
[INDEX_op_sarw ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4349 |
[INDEX_op_sarl ## SUFFIX ## _T0_T1_cc] = CC_OSZAPC,\ |
4350 |
\ |
4351 |
[INDEX_op_shldw ## SUFFIX ## _T0_T1_ECX_cc] = CC_OSZAPC,\ |
4352 |
[INDEX_op_shldl ## SUFFIX ## _T0_T1_ECX_cc] = CC_OSZAPC,\ |
4353 |
[INDEX_op_shldw ## SUFFIX ## _T0_T1_im_cc] = CC_OSZAPC,\ |
4354 |
[INDEX_op_shldl ## SUFFIX ## _T0_T1_im_cc] = CC_OSZAPC,\ |
4355 |
\ |
4356 |
[INDEX_op_shrdw ## SUFFIX ## _T0_T1_ECX_cc] = CC_OSZAPC,\ |
4357 |
[INDEX_op_shrdl ## SUFFIX ## _T0_T1_ECX_cc] = CC_OSZAPC,\ |
4358 |
[INDEX_op_shrdw ## SUFFIX ## _T0_T1_im_cc] = CC_OSZAPC,\ |
4359 |
[INDEX_op_shrdl ## SUFFIX ## _T0_T1_im_cc] = CC_OSZAPC,\ |
4360 |
\ |
4361 |
[INDEX_op_cmpxchgb ## SUFFIX ## _T0_T1_EAX_cc] = CC_OSZAPC,\ |
4362 |
[INDEX_op_cmpxchgw ## SUFFIX ## _T0_T1_EAX_cc] = CC_OSZAPC,\ |
4363 |
[INDEX_op_cmpxchgl ## SUFFIX ## _T0_T1_EAX_cc] = CC_OSZAPC, |
4364 |
|
4365 |
|
4366 |
DEF_WRITEF() |
4367 |
DEF_WRITEF(_raw) |
4368 |
#ifndef CONFIG_USER_ONLY
|
4369 |
DEF_WRITEF(_kernel) |
4370 |
DEF_WRITEF(_user) |
4371 |
#endif
|
4372 |
}; |
4373 |
|
4374 |
/* simpler form of an operation if no flags need to be generated */
|
4375 |
static uint16_t opc_simpler[NB_OPS] = {
|
4376 |
[INDEX_op_update2_cc] = INDEX_op_nop, |
4377 |
[INDEX_op_update1_cc] = INDEX_op_nop, |
4378 |
[INDEX_op_update_neg_cc] = INDEX_op_nop, |
4379 |
#if 0
|
4380 |
/* broken: CC_OP logic must be rewritten */
|
4381 |
[INDEX_op_update_inc_cc] = INDEX_op_nop,
|
4382 |
#endif
|
4383 |
|
4384 |
[INDEX_op_shlb_T0_T1_cc] = INDEX_op_shlb_T0_T1, |
4385 |
[INDEX_op_shlw_T0_T1_cc] = INDEX_op_shlw_T0_T1, |
4386 |
[INDEX_op_shll_T0_T1_cc] = INDEX_op_shll_T0_T1, |
4387 |
|
4388 |
[INDEX_op_shrb_T0_T1_cc] = INDEX_op_shrb_T0_T1, |
4389 |
[INDEX_op_shrw_T0_T1_cc] = INDEX_op_shrw_T0_T1, |
4390 |
[INDEX_op_shrl_T0_T1_cc] = INDEX_op_shrl_T0_T1, |
4391 |
|
4392 |
[INDEX_op_sarb_T0_T1_cc] = INDEX_op_sarb_T0_T1, |
4393 |
[INDEX_op_sarw_T0_T1_cc] = INDEX_op_sarw_T0_T1, |
4394 |
[INDEX_op_sarl_T0_T1_cc] = INDEX_op_sarl_T0_T1, |
4395 |
|
4396 |
#define DEF_SIMPLER(SUFFIX)\
|
4397 |
[INDEX_op_rolb ## SUFFIX ## _T0_T1_cc] = INDEX_op_rolb ## SUFFIX ## _T0_T1,\ |
4398 |
[INDEX_op_rolw ## SUFFIX ## _T0_T1_cc] = INDEX_op_rolw ## SUFFIX ## _T0_T1,\ |
4399 |
[INDEX_op_roll ## SUFFIX ## _T0_T1_cc] = INDEX_op_roll ## SUFFIX ## _T0_T1,\ |
4400 |
\ |
4401 |
[INDEX_op_rorb ## SUFFIX ## _T0_T1_cc] = INDEX_op_rorb ## SUFFIX ## _T0_T1,\ |
4402 |
[INDEX_op_rorw ## SUFFIX ## _T0_T1_cc] = INDEX_op_rorw ## SUFFIX ## _T0_T1,\ |
4403 |
[INDEX_op_rorl ## SUFFIX ## _T0_T1_cc] = INDEX_op_rorl ## SUFFIX ## _T0_T1, |
4404 |
|
4405 |
DEF_SIMPLER() |
4406 |
DEF_SIMPLER(_raw) |
4407 |
#ifndef CONFIG_USER_ONLY
|
4408 |
DEF_SIMPLER(_kernel) |
4409 |
DEF_SIMPLER(_user) |
4410 |
#endif
|
4411 |
}; |
4412 |
|
4413 |
void optimize_flags_init(void) |
4414 |
{ |
4415 |
int i;
|
4416 |
/* put default values in arrays */
|
4417 |
for(i = 0; i < NB_OPS; i++) { |
4418 |
if (opc_simpler[i] == 0) |
4419 |
opc_simpler[i] = i; |
4420 |
} |
4421 |
} |
4422 |
|
4423 |
/* CPU flags computation optimization: we move backward thru the
|
4424 |
generated code to see which flags are needed. The operation is
|
4425 |
modified if suitable */
|
4426 |
static void optimize_flags(uint16_t *opc_buf, int opc_buf_len) |
4427 |
{ |
4428 |
uint16_t *opc_ptr; |
4429 |
int live_flags, write_flags, op;
|
4430 |
|
4431 |
opc_ptr = opc_buf + opc_buf_len; |
4432 |
/* live_flags contains the flags needed by the next instructions
|
4433 |
in the code. At the end of the bloc, we consider that all the
|
4434 |
flags are live. */
|
4435 |
live_flags = CC_OSZAPC; |
4436 |
while (opc_ptr > opc_buf) {
|
4437 |
op = *--opc_ptr; |
4438 |
/* if none of the flags written by the instruction is used,
|
4439 |
then we can try to find a simpler instruction */
|
4440 |
write_flags = opc_write_flags[op]; |
4441 |
if ((live_flags & write_flags) == 0) { |
4442 |
*opc_ptr = opc_simpler[op]; |
4443 |
} |
4444 |
/* compute the live flags before the instruction */
|
4445 |
live_flags &= ~write_flags; |
4446 |
live_flags |= opc_read_flags[op]; |
4447 |
} |
4448 |
} |
4449 |
|
4450 |
/* generate intermediate code in gen_opc_buf and gen_opparam_buf for
|
4451 |
basic block 'tb'. If search_pc is TRUE, also generate PC
|
4452 |
information for each intermediate instruction. */
|
4453 |
static inline int gen_intermediate_code_internal(CPUState *env, |
4454 |
TranslationBlock *tb, |
4455 |
int search_pc)
|
4456 |
{ |
4457 |
DisasContext dc1, *dc = &dc1; |
4458 |
uint8_t *pc_ptr; |
4459 |
uint16_t *gen_opc_end; |
4460 |
int flags, j, lj;
|
4461 |
uint8_t *pc_start; |
4462 |
uint8_t *cs_base; |
4463 |
|
4464 |
/* generate intermediate code */
|
4465 |
pc_start = (uint8_t *)tb->pc; |
4466 |
cs_base = (uint8_t *)tb->cs_base; |
4467 |
flags = tb->flags; |
4468 |
|
4469 |
dc->pe = (flags >> HF_PE_SHIFT) & 1;
|
4470 |
dc->code32 = (flags >> HF_CS32_SHIFT) & 1;
|
4471 |
dc->ss32 = (flags >> HF_SS32_SHIFT) & 1;
|
4472 |
dc->addseg = (flags >> HF_ADDSEG_SHIFT) & 1;
|
4473 |
dc->f_st = 0;
|
4474 |
dc->vm86 = (flags >> VM_SHIFT) & 1;
|
4475 |
dc->cpl = (flags >> HF_CPL_SHIFT) & 3;
|
4476 |
dc->iopl = (flags >> IOPL_SHIFT) & 3;
|
4477 |
dc->tf = (flags >> TF_SHIFT) & 1;
|
4478 |
dc->singlestep_enabled = env->singlestep_enabled; |
4479 |
dc->cc_op = CC_OP_DYNAMIC; |
4480 |
dc->cs_base = cs_base; |
4481 |
dc->tb = tb; |
4482 |
dc->popl_esp_hack = 0;
|
4483 |
/* select memory access functions */
|
4484 |
dc->mem_index = 0;
|
4485 |
if (flags & HF_SOFTMMU_MASK) {
|
4486 |
if (dc->cpl == 3) |
4487 |
dc->mem_index = 6;
|
4488 |
else
|
4489 |
dc->mem_index = 3;
|
4490 |
} |
4491 |
dc->jmp_opt = !(dc->tf || env->singlestep_enabled || |
4492 |
(flags & HF_INHIBIT_IRQ_MASK) |
4493 |
#ifndef CONFIG_SOFTMMU
|
4494 |
|| (flags & HF_SOFTMMU_MASK) |
4495 |
#endif
|
4496 |
); |
4497 |
#if 0
|
4498 |
/* check addseg logic */
|
4499 |
if (!dc->addseg && (dc->vm86 || !dc->pe))
|
4500 |
printf("ERROR addseg\n");
|
4501 |
#endif
|
4502 |
|
4503 |
gen_opc_ptr = gen_opc_buf; |
4504 |
gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; |
4505 |
gen_opparam_ptr = gen_opparam_buf; |
4506 |
|
4507 |
dc->is_jmp = DISAS_NEXT; |
4508 |
pc_ptr = pc_start; |
4509 |
lj = -1;
|
4510 |
|
4511 |
for(;;) {
|
4512 |
if (env->nb_breakpoints > 0) { |
4513 |
for(j = 0; j < env->nb_breakpoints; j++) { |
4514 |
if (env->breakpoints[j] == (unsigned long)pc_ptr) { |
4515 |
gen_debug(dc, pc_ptr - dc->cs_base); |
4516 |
break;
|
4517 |
} |
4518 |
} |
4519 |
} |
4520 |
if (search_pc) {
|
4521 |
j = gen_opc_ptr - gen_opc_buf; |
4522 |
if (lj < j) {
|
4523 |
lj++; |
4524 |
while (lj < j)
|
4525 |
gen_opc_instr_start[lj++] = 0;
|
4526 |
} |
4527 |
gen_opc_pc[lj] = (uint32_t)pc_ptr; |
4528 |
gen_opc_cc_op[lj] = dc->cc_op; |
4529 |
gen_opc_instr_start[lj] = 1;
|
4530 |
} |
4531 |
pc_ptr = disas_insn(dc, pc_ptr); |
4532 |
/* stop translation if indicated */
|
4533 |
if (dc->is_jmp)
|
4534 |
break;
|
4535 |
/* if single step mode, we generate only one instruction and
|
4536 |
generate an exception */
|
4537 |
/* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear
|
4538 |
the flag and abort the translation to give the irqs a
|
4539 |
change to be happen */
|
4540 |
if (dc->tf || dc->singlestep_enabled ||
|
4541 |
(flags & HF_INHIBIT_IRQ_MASK)) { |
4542 |
gen_op_jmp_im(pc_ptr - dc->cs_base); |
4543 |
gen_eob(dc); |
4544 |
break;
|
4545 |
} |
4546 |
/* if too long translation, stop generation too */
|
4547 |
if (gen_opc_ptr >= gen_opc_end ||
|
4548 |
(pc_ptr - pc_start) >= (TARGET_PAGE_SIZE - 32)) {
|
4549 |
gen_op_jmp_im(pc_ptr - dc->cs_base); |
4550 |
gen_eob(dc); |
4551 |
break;
|
4552 |
} |
4553 |
} |
4554 |
*gen_opc_ptr = INDEX_op_end; |
4555 |
/* we don't forget to fill the last values */
|
4556 |
if (search_pc) {
|
4557 |
j = gen_opc_ptr - gen_opc_buf; |
4558 |
lj++; |
4559 |
while (lj <= j)
|
4560 |
gen_opc_instr_start[lj++] = 0;
|
4561 |
} |
4562 |
|
4563 |
#ifdef DEBUG_DISAS
|
4564 |
if (loglevel) {
|
4565 |
fprintf(logfile, "----------------\n");
|
4566 |
fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
|
4567 |
disas(logfile, pc_start, pc_ptr - pc_start, 0, !dc->code32);
|
4568 |
fprintf(logfile, "\n");
|
4569 |
fprintf(logfile, "OP:\n");
|
4570 |
dump_ops(gen_opc_buf, gen_opparam_buf); |
4571 |
fprintf(logfile, "\n");
|
4572 |
} |
4573 |
#endif
|
4574 |
|
4575 |
/* optimize flag computations */
|
4576 |
optimize_flags(gen_opc_buf, gen_opc_ptr - gen_opc_buf); |
4577 |
|
4578 |
#ifdef DEBUG_DISAS
|
4579 |
if (loglevel) {
|
4580 |
fprintf(logfile, "AFTER FLAGS OPT:\n");
|
4581 |
dump_ops(gen_opc_buf, gen_opparam_buf); |
4582 |
fprintf(logfile, "\n");
|
4583 |
} |
4584 |
#endif
|
4585 |
if (!search_pc)
|
4586 |
tb->size = pc_ptr - pc_start; |
4587 |
return 0; |
4588 |
} |
4589 |
|
4590 |
int gen_intermediate_code(CPUState *env, TranslationBlock *tb)
|
4591 |
{ |
4592 |
return gen_intermediate_code_internal(env, tb, 0); |
4593 |
} |
4594 |
|
4595 |
int gen_intermediate_code_pc(CPUState *env, TranslationBlock *tb)
|
4596 |
{ |
4597 |
return gen_intermediate_code_internal(env, tb, 1); |
4598 |
} |
4599 |
|