root / target-i386 / translate-copy.c @ 97eb5b14
History | View | Annotate | Download (33.6 kB)
1 | 58fe2f10 | bellard | /*
|
---|---|---|---|
2 | 58fe2f10 | bellard | * i386 on i386 translation
|
3 | 58fe2f10 | bellard | *
|
4 | 58fe2f10 | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 58fe2f10 | bellard | *
|
6 | 58fe2f10 | bellard | * This library is free software; you can redistribute it and/or
|
7 | 58fe2f10 | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | 58fe2f10 | bellard | * License as published by the Free Software Foundation; either
|
9 | 58fe2f10 | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | 58fe2f10 | bellard | *
|
11 | 58fe2f10 | bellard | * This library is distributed in the hope that it will be useful,
|
12 | 58fe2f10 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 58fe2f10 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 58fe2f10 | bellard | * Lesser General Public License for more details.
|
15 | 58fe2f10 | bellard | *
|
16 | 58fe2f10 | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | 58fe2f10 | bellard | * License along with this library; if not, write to the Free Software
|
18 | 58fe2f10 | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | 58fe2f10 | bellard | */
|
20 | 58fe2f10 | bellard | #include <stdarg.h> |
21 | 58fe2f10 | bellard | #include <stdlib.h> |
22 | 58fe2f10 | bellard | #include <stdio.h> |
23 | 58fe2f10 | bellard | #include <string.h> |
24 | 58fe2f10 | bellard | #include <inttypes.h> |
25 | 58fe2f10 | bellard | #include <signal.h> |
26 | 58fe2f10 | bellard | #include <assert.h> |
27 | 58fe2f10 | bellard | #include <sys/mman.h> |
28 | 58fe2f10 | bellard | #include <sys/ucontext.h> |
29 | 58fe2f10 | bellard | |
30 | 58fe2f10 | bellard | #include "cpu.h" |
31 | 58fe2f10 | bellard | #include "exec-all.h" |
32 | 58fe2f10 | bellard | #include "disas.h" |
33 | 58fe2f10 | bellard | |
34 | 42c3c0cc | bellard | #ifdef USE_CODE_COPY
|
35 | 42c3c0cc | bellard | |
36 | 58fe2f10 | bellard | extern char exec_loop; |
37 | 58fe2f10 | bellard | |
38 | 58fe2f10 | bellard | /* operand size */
|
39 | 58fe2f10 | bellard | enum {
|
40 | 58fe2f10 | bellard | OT_BYTE = 0,
|
41 | 58fe2f10 | bellard | OT_WORD, |
42 | 58fe2f10 | bellard | OT_LONG, |
43 | 58fe2f10 | bellard | OT_QUAD, |
44 | 58fe2f10 | bellard | }; |
45 | 58fe2f10 | bellard | |
46 | 58fe2f10 | bellard | #define PREFIX_REPZ 0x01 |
47 | 58fe2f10 | bellard | #define PREFIX_REPNZ 0x02 |
48 | 58fe2f10 | bellard | #define PREFIX_LOCK 0x04 |
49 | 58fe2f10 | bellard | #define PREFIX_DATA 0x08 |
50 | 58fe2f10 | bellard | #define PREFIX_ADR 0x10 |
51 | 58fe2f10 | bellard | |
52 | 58fe2f10 | bellard | typedef struct DisasContext { |
53 | 58fe2f10 | bellard | /* current insn context */
|
54 | 58fe2f10 | bellard | int override; /* -1 if no override */ |
55 | 58fe2f10 | bellard | int prefix;
|
56 | 58fe2f10 | bellard | int aflag, dflag;
|
57 | 58fe2f10 | bellard | uint8_t *pc; /* pc = eip + cs_base */
|
58 | 58fe2f10 | bellard | int is_jmp; /* 1 = means jump (stop translation), 2 means CPU |
59 | 58fe2f10 | bellard | static state change (stop translation) */
|
60 | 58fe2f10 | bellard | /* code output */
|
61 | 58fe2f10 | bellard | uint8_t *gen_code_ptr; |
62 | 58fe2f10 | bellard | uint8_t *gen_code_start; |
63 | 58fe2f10 | bellard | |
64 | 58fe2f10 | bellard | /* current block context */
|
65 | 58fe2f10 | bellard | uint8_t *cs_base; /* base of CS segment */
|
66 | 58fe2f10 | bellard | int pe; /* protected mode */ |
67 | 58fe2f10 | bellard | int code32; /* 32 bit code segment */ |
68 | 58fe2f10 | bellard | int f_st; /* currently unused */ |
69 | 58fe2f10 | bellard | int vm86; /* vm86 mode */ |
70 | 58fe2f10 | bellard | int cpl;
|
71 | 58fe2f10 | bellard | int iopl;
|
72 | 42c3c0cc | bellard | int flags;
|
73 | 58fe2f10 | bellard | struct TranslationBlock *tb;
|
74 | 58fe2f10 | bellard | } DisasContext; |
75 | 58fe2f10 | bellard | |
76 | 58fe2f10 | bellard | #define CPU_FIELD_OFFSET(field) offsetof(CPUState, field)
|
77 | 58fe2f10 | bellard | |
78 | 58fe2f10 | bellard | #define CPU_SEG 0x64 /* fs override */ |
79 | 58fe2f10 | bellard | |
80 | 58fe2f10 | bellard | static inline void gb(DisasContext *s, uint32_t val) |
81 | 58fe2f10 | bellard | { |
82 | 58fe2f10 | bellard | *s->gen_code_ptr++ = val; |
83 | 58fe2f10 | bellard | } |
84 | 58fe2f10 | bellard | |
85 | 58fe2f10 | bellard | static inline void gw(DisasContext *s, uint32_t val) |
86 | 58fe2f10 | bellard | { |
87 | 58fe2f10 | bellard | *s->gen_code_ptr++ = val; |
88 | 58fe2f10 | bellard | *s->gen_code_ptr++ = val >> 8;
|
89 | 58fe2f10 | bellard | } |
90 | 58fe2f10 | bellard | |
91 | 58fe2f10 | bellard | static inline void gl(DisasContext *s, uint32_t val) |
92 | 58fe2f10 | bellard | { |
93 | 58fe2f10 | bellard | *s->gen_code_ptr++ = val; |
94 | 58fe2f10 | bellard | *s->gen_code_ptr++ = val >> 8;
|
95 | 58fe2f10 | bellard | *s->gen_code_ptr++ = val >> 16;
|
96 | 58fe2f10 | bellard | *s->gen_code_ptr++ = val >> 24;
|
97 | 58fe2f10 | bellard | } |
98 | 58fe2f10 | bellard | |
99 | 58fe2f10 | bellard | static inline void gjmp(DisasContext *s, long val) |
100 | 58fe2f10 | bellard | { |
101 | 58fe2f10 | bellard | gb(s, 0xe9); /* jmp */ |
102 | 58fe2f10 | bellard | gl(s, val - (long)(s->gen_code_ptr + 4)); |
103 | 58fe2f10 | bellard | } |
104 | 58fe2f10 | bellard | |
105 | 58fe2f10 | bellard | static inline void gen_movl_addr_im(DisasContext *s, |
106 | 58fe2f10 | bellard | uint32_t addr, uint32_t val) |
107 | 58fe2f10 | bellard | { |
108 | 58fe2f10 | bellard | gb(s, CPU_SEG); /* seg movl im, addr */
|
109 | 58fe2f10 | bellard | gb(s, 0xc7);
|
110 | 58fe2f10 | bellard | gb(s, 0x05);
|
111 | 58fe2f10 | bellard | gl(s, addr); |
112 | 58fe2f10 | bellard | gl(s, val); |
113 | 58fe2f10 | bellard | } |
114 | 58fe2f10 | bellard | |
115 | 58fe2f10 | bellard | static inline void gen_movw_addr_im(DisasContext *s, |
116 | 58fe2f10 | bellard | uint32_t addr, uint32_t val) |
117 | 58fe2f10 | bellard | { |
118 | 58fe2f10 | bellard | gb(s, CPU_SEG); /* seg movl im, addr */
|
119 | 58fe2f10 | bellard | gb(s, 0x66);
|
120 | 58fe2f10 | bellard | gb(s, 0xc7);
|
121 | 58fe2f10 | bellard | gb(s, 0x05);
|
122 | 58fe2f10 | bellard | gl(s, addr); |
123 | 58fe2f10 | bellard | gw(s, val); |
124 | 58fe2f10 | bellard | } |
125 | 58fe2f10 | bellard | |
126 | 58fe2f10 | bellard | |
127 | 58fe2f10 | bellard | static void gen_jmp(DisasContext *s, uint32_t target_eip) |
128 | 58fe2f10 | bellard | { |
129 | 58fe2f10 | bellard | TranslationBlock *tb = s->tb; |
130 | 58fe2f10 | bellard | |
131 | 58fe2f10 | bellard | gb(s, 0xe9); /* jmp */ |
132 | 58fe2f10 | bellard | tb->tb_jmp_offset[0] = s->gen_code_ptr - s->gen_code_start;
|
133 | 58fe2f10 | bellard | gl(s, 0);
|
134 | 58fe2f10 | bellard | |
135 | 58fe2f10 | bellard | tb->tb_next_offset[0] = s->gen_code_ptr - s->gen_code_start;
|
136 | 58fe2f10 | bellard | gen_movl_addr_im(s, CPU_FIELD_OFFSET(eip), target_eip); |
137 | 58fe2f10 | bellard | gen_movl_addr_im(s, CPU_FIELD_OFFSET(tmp0), (uint32_t)tb); |
138 | 58fe2f10 | bellard | gjmp(s, (long)&exec_loop);
|
139 | 58fe2f10 | bellard | |
140 | 58fe2f10 | bellard | s->is_jmp = 1;
|
141 | 58fe2f10 | bellard | } |
142 | 58fe2f10 | bellard | |
143 | 58fe2f10 | bellard | static void gen_jcc(DisasContext *s, int op, |
144 | 58fe2f10 | bellard | uint32_t target_eip, uint32_t next_eip) |
145 | 58fe2f10 | bellard | { |
146 | 58fe2f10 | bellard | TranslationBlock *tb = s->tb; |
147 | 58fe2f10 | bellard | |
148 | 58fe2f10 | bellard | gb(s, 0x0f); /* jcc */ |
149 | 58fe2f10 | bellard | gb(s, 0x80 + op);
|
150 | 58fe2f10 | bellard | tb->tb_jmp_offset[0] = s->gen_code_ptr - s->gen_code_start;
|
151 | 58fe2f10 | bellard | gl(s, 0);
|
152 | 58fe2f10 | bellard | gb(s, 0xe9); /* jmp */ |
153 | 58fe2f10 | bellard | tb->tb_jmp_offset[1] = s->gen_code_ptr - s->gen_code_start;
|
154 | 58fe2f10 | bellard | gl(s, 0);
|
155 | 58fe2f10 | bellard | |
156 | 58fe2f10 | bellard | tb->tb_next_offset[0] = s->gen_code_ptr - s->gen_code_start;
|
157 | 58fe2f10 | bellard | gen_movl_addr_im(s, CPU_FIELD_OFFSET(eip), target_eip); |
158 | 58fe2f10 | bellard | gen_movl_addr_im(s, CPU_FIELD_OFFSET(tmp0), (uint32_t)tb); |
159 | 58fe2f10 | bellard | gjmp(s, (long)&exec_loop);
|
160 | 58fe2f10 | bellard | |
161 | 58fe2f10 | bellard | tb->tb_next_offset[1] = s->gen_code_ptr - s->gen_code_start;
|
162 | 58fe2f10 | bellard | gen_movl_addr_im(s, CPU_FIELD_OFFSET(eip), next_eip); |
163 | 58fe2f10 | bellard | gen_movl_addr_im(s, CPU_FIELD_OFFSET(tmp0), (uint32_t)tb | 1);
|
164 | 58fe2f10 | bellard | gjmp(s, (long)&exec_loop);
|
165 | 58fe2f10 | bellard | |
166 | 58fe2f10 | bellard | s->is_jmp = 1;
|
167 | 58fe2f10 | bellard | } |
168 | 58fe2f10 | bellard | |
169 | 58fe2f10 | bellard | static void gen_eob(DisasContext *s) |
170 | 58fe2f10 | bellard | { |
171 | 58fe2f10 | bellard | gen_movl_addr_im(s, CPU_FIELD_OFFSET(tmp0), 0);
|
172 | 58fe2f10 | bellard | gjmp(s, (long)&exec_loop);
|
173 | 58fe2f10 | bellard | |
174 | 58fe2f10 | bellard | s->is_jmp = 1;
|
175 | 58fe2f10 | bellard | } |
176 | 58fe2f10 | bellard | |
177 | 58fe2f10 | bellard | static inline void gen_lea_modrm(DisasContext *s, int modrm) |
178 | 58fe2f10 | bellard | { |
179 | 58fe2f10 | bellard | int havesib;
|
180 | 58fe2f10 | bellard | int base, disp;
|
181 | 58fe2f10 | bellard | int index;
|
182 | 58fe2f10 | bellard | int scale;
|
183 | 58fe2f10 | bellard | int mod, rm, code;
|
184 | 58fe2f10 | bellard | |
185 | 58fe2f10 | bellard | mod = (modrm >> 6) & 3; |
186 | 58fe2f10 | bellard | rm = modrm & 7;
|
187 | 58fe2f10 | bellard | |
188 | 58fe2f10 | bellard | if (s->aflag) {
|
189 | 58fe2f10 | bellard | |
190 | 58fe2f10 | bellard | havesib = 0;
|
191 | 58fe2f10 | bellard | base = rm; |
192 | 58fe2f10 | bellard | index = 0;
|
193 | 58fe2f10 | bellard | scale = 0;
|
194 | 58fe2f10 | bellard | |
195 | 58fe2f10 | bellard | if (base == 4) { |
196 | 58fe2f10 | bellard | havesib = 1;
|
197 | 58fe2f10 | bellard | code = ldub_code(s->pc++); |
198 | 58fe2f10 | bellard | scale = (code >> 6) & 3; |
199 | 58fe2f10 | bellard | index = (code >> 3) & 7; |
200 | 58fe2f10 | bellard | base = code & 7;
|
201 | 58fe2f10 | bellard | } |
202 | 58fe2f10 | bellard | |
203 | 58fe2f10 | bellard | switch (mod) {
|
204 | 58fe2f10 | bellard | case 0: |
205 | 58fe2f10 | bellard | if (base == 5) { |
206 | 58fe2f10 | bellard | base = -1;
|
207 | 58fe2f10 | bellard | disp = ldl_code(s->pc); |
208 | 58fe2f10 | bellard | s->pc += 4;
|
209 | 58fe2f10 | bellard | } else {
|
210 | 58fe2f10 | bellard | disp = 0;
|
211 | 58fe2f10 | bellard | } |
212 | 58fe2f10 | bellard | break;
|
213 | 58fe2f10 | bellard | case 1: |
214 | 58fe2f10 | bellard | disp = (int8_t)ldub_code(s->pc++); |
215 | 58fe2f10 | bellard | break;
|
216 | 58fe2f10 | bellard | default:
|
217 | 58fe2f10 | bellard | case 2: |
218 | 58fe2f10 | bellard | disp = ldl_code(s->pc); |
219 | 58fe2f10 | bellard | s->pc += 4;
|
220 | 58fe2f10 | bellard | break;
|
221 | 58fe2f10 | bellard | } |
222 | 58fe2f10 | bellard | |
223 | 58fe2f10 | bellard | } else {
|
224 | 58fe2f10 | bellard | switch (mod) {
|
225 | 58fe2f10 | bellard | case 0: |
226 | 58fe2f10 | bellard | if (rm == 6) { |
227 | 58fe2f10 | bellard | disp = lduw_code(s->pc); |
228 | 58fe2f10 | bellard | s->pc += 2;
|
229 | 58fe2f10 | bellard | } else {
|
230 | 58fe2f10 | bellard | disp = 0;
|
231 | 58fe2f10 | bellard | } |
232 | 58fe2f10 | bellard | break;
|
233 | 58fe2f10 | bellard | case 1: |
234 | 58fe2f10 | bellard | disp = (int8_t)ldub_code(s->pc++); |
235 | 58fe2f10 | bellard | break;
|
236 | 58fe2f10 | bellard | default:
|
237 | 58fe2f10 | bellard | case 2: |
238 | 58fe2f10 | bellard | disp = lduw_code(s->pc); |
239 | 58fe2f10 | bellard | s->pc += 2;
|
240 | 58fe2f10 | bellard | break;
|
241 | 58fe2f10 | bellard | } |
242 | 58fe2f10 | bellard | } |
243 | 58fe2f10 | bellard | } |
244 | 58fe2f10 | bellard | |
245 | 58fe2f10 | bellard | static inline void parse_modrm(DisasContext *s, int modrm) |
246 | 58fe2f10 | bellard | { |
247 | 58fe2f10 | bellard | if ((modrm & 0xc0) != 0xc0) |
248 | 58fe2f10 | bellard | gen_lea_modrm(s, modrm); |
249 | 58fe2f10 | bellard | } |
250 | 58fe2f10 | bellard | |
251 | 58fe2f10 | bellard | static inline uint32_t insn_get(DisasContext *s, int ot) |
252 | 58fe2f10 | bellard | { |
253 | 58fe2f10 | bellard | uint32_t ret; |
254 | 58fe2f10 | bellard | |
255 | 58fe2f10 | bellard | switch(ot) {
|
256 | 58fe2f10 | bellard | case OT_BYTE:
|
257 | 58fe2f10 | bellard | ret = ldub_code(s->pc); |
258 | 58fe2f10 | bellard | s->pc++; |
259 | 58fe2f10 | bellard | break;
|
260 | 58fe2f10 | bellard | case OT_WORD:
|
261 | 58fe2f10 | bellard | ret = lduw_code(s->pc); |
262 | 58fe2f10 | bellard | s->pc += 2;
|
263 | 58fe2f10 | bellard | break;
|
264 | 58fe2f10 | bellard | default:
|
265 | 58fe2f10 | bellard | case OT_LONG:
|
266 | 58fe2f10 | bellard | ret = ldl_code(s->pc); |
267 | 58fe2f10 | bellard | s->pc += 4;
|
268 | 58fe2f10 | bellard | break;
|
269 | 58fe2f10 | bellard | } |
270 | 58fe2f10 | bellard | return ret;
|
271 | 58fe2f10 | bellard | } |
272 | 58fe2f10 | bellard | |
273 | 58fe2f10 | bellard | /* convert one instruction. s->is_jmp is set if the translation must
|
274 | 58fe2f10 | bellard | be stopped. */
|
275 | 58fe2f10 | bellard | static int disas_insn(DisasContext *s) |
276 | 58fe2f10 | bellard | { |
277 | 58fe2f10 | bellard | uint8_t *pc_start, *pc_tmp, *pc_start_insn; |
278 | 58fe2f10 | bellard | int b, prefixes, aflag, dflag, next_eip, val;
|
279 | 58fe2f10 | bellard | int ot;
|
280 | 42c3c0cc | bellard | int modrm, mod, op, rm;
|
281 | 58fe2f10 | bellard | |
282 | 58fe2f10 | bellard | pc_start = s->pc; |
283 | 58fe2f10 | bellard | prefixes = 0;
|
284 | 58fe2f10 | bellard | aflag = s->code32; |
285 | 58fe2f10 | bellard | dflag = s->code32; |
286 | 58fe2f10 | bellard | s->override = -1;
|
287 | 58fe2f10 | bellard | next_byte:
|
288 | 58fe2f10 | bellard | b = ldub_code(s->pc); |
289 | 58fe2f10 | bellard | s->pc++; |
290 | 58fe2f10 | bellard | /* check prefixes */
|
291 | 58fe2f10 | bellard | switch (b) {
|
292 | 58fe2f10 | bellard | case 0xf3: |
293 | 58fe2f10 | bellard | prefixes |= PREFIX_REPZ; |
294 | 58fe2f10 | bellard | goto next_byte;
|
295 | 58fe2f10 | bellard | case 0xf2: |
296 | 58fe2f10 | bellard | prefixes |= PREFIX_REPNZ; |
297 | 58fe2f10 | bellard | goto next_byte;
|
298 | 58fe2f10 | bellard | case 0xf0: |
299 | 58fe2f10 | bellard | prefixes |= PREFIX_LOCK; |
300 | 58fe2f10 | bellard | goto next_byte;
|
301 | 58fe2f10 | bellard | case 0x2e: |
302 | 58fe2f10 | bellard | s->override = R_CS; |
303 | 58fe2f10 | bellard | goto next_byte;
|
304 | 58fe2f10 | bellard | case 0x36: |
305 | 58fe2f10 | bellard | s->override = R_SS; |
306 | 58fe2f10 | bellard | goto next_byte;
|
307 | 58fe2f10 | bellard | case 0x3e: |
308 | 58fe2f10 | bellard | s->override = R_DS; |
309 | 58fe2f10 | bellard | goto next_byte;
|
310 | 58fe2f10 | bellard | case 0x26: |
311 | 58fe2f10 | bellard | s->override = R_ES; |
312 | 58fe2f10 | bellard | goto next_byte;
|
313 | 58fe2f10 | bellard | case 0x64: |
314 | 58fe2f10 | bellard | s->override = R_FS; |
315 | 58fe2f10 | bellard | goto next_byte;
|
316 | 58fe2f10 | bellard | case 0x65: |
317 | 58fe2f10 | bellard | s->override = R_GS; |
318 | 58fe2f10 | bellard | goto next_byte;
|
319 | 58fe2f10 | bellard | case 0x66: |
320 | 58fe2f10 | bellard | prefixes |= PREFIX_DATA; |
321 | 58fe2f10 | bellard | goto next_byte;
|
322 | 58fe2f10 | bellard | case 0x67: |
323 | 58fe2f10 | bellard | prefixes |= PREFIX_ADR; |
324 | 58fe2f10 | bellard | goto next_byte;
|
325 | 58fe2f10 | bellard | } |
326 | 58fe2f10 | bellard | |
327 | 58fe2f10 | bellard | if (prefixes & PREFIX_DATA)
|
328 | 58fe2f10 | bellard | dflag ^= 1;
|
329 | 58fe2f10 | bellard | if (prefixes & PREFIX_ADR)
|
330 | 58fe2f10 | bellard | aflag ^= 1;
|
331 | 58fe2f10 | bellard | |
332 | 58fe2f10 | bellard | s->prefix = prefixes; |
333 | 58fe2f10 | bellard | s->aflag = aflag; |
334 | 58fe2f10 | bellard | s->dflag = dflag; |
335 | 58fe2f10 | bellard | |
336 | 58fe2f10 | bellard | /* lock generation */
|
337 | 58fe2f10 | bellard | if (prefixes & PREFIX_LOCK)
|
338 | 58fe2f10 | bellard | goto unsupported_op;
|
339 | 58fe2f10 | bellard | if (s->override == R_FS || s->override == R_GS || s->override == R_CS)
|
340 | 58fe2f10 | bellard | goto unsupported_op;
|
341 | 58fe2f10 | bellard | |
342 | 58fe2f10 | bellard | pc_start_insn = s->pc - 1;
|
343 | 58fe2f10 | bellard | /* now check op code */
|
344 | 58fe2f10 | bellard | reswitch:
|
345 | 58fe2f10 | bellard | switch(b) {
|
346 | 58fe2f10 | bellard | case 0x0f: |
347 | 58fe2f10 | bellard | /**************************/
|
348 | 58fe2f10 | bellard | /* extended op code */
|
349 | 58fe2f10 | bellard | b = ldub_code(s->pc++) | 0x100;
|
350 | 58fe2f10 | bellard | goto reswitch;
|
351 | 58fe2f10 | bellard | |
352 | 58fe2f10 | bellard | /**************************/
|
353 | 58fe2f10 | bellard | /* arith & logic */
|
354 | 58fe2f10 | bellard | case 0x00 ... 0x05: |
355 | 58fe2f10 | bellard | case 0x08 ... 0x0d: |
356 | 58fe2f10 | bellard | case 0x10 ... 0x15: |
357 | 58fe2f10 | bellard | case 0x18 ... 0x1d: |
358 | 58fe2f10 | bellard | case 0x20 ... 0x25: |
359 | 58fe2f10 | bellard | case 0x28 ... 0x2d: |
360 | 58fe2f10 | bellard | case 0x30 ... 0x35: |
361 | 58fe2f10 | bellard | case 0x38 ... 0x3d: |
362 | 58fe2f10 | bellard | { |
363 | 58fe2f10 | bellard | int f;
|
364 | 58fe2f10 | bellard | f = (b >> 1) & 3; |
365 | 58fe2f10 | bellard | |
366 | 58fe2f10 | bellard | if ((b & 1) == 0) |
367 | 58fe2f10 | bellard | ot = OT_BYTE; |
368 | 58fe2f10 | bellard | else
|
369 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
370 | 58fe2f10 | bellard | |
371 | 58fe2f10 | bellard | switch(f) {
|
372 | 58fe2f10 | bellard | case 0: /* OP Ev, Gv */ |
373 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
374 | 58fe2f10 | bellard | parse_modrm(s, modrm); |
375 | 58fe2f10 | bellard | break;
|
376 | 58fe2f10 | bellard | case 1: /* OP Gv, Ev */ |
377 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
378 | 58fe2f10 | bellard | parse_modrm(s, modrm); |
379 | 58fe2f10 | bellard | break;
|
380 | 58fe2f10 | bellard | case 2: /* OP A, Iv */ |
381 | 58fe2f10 | bellard | insn_get(s, ot); |
382 | 58fe2f10 | bellard | break;
|
383 | 58fe2f10 | bellard | } |
384 | 58fe2f10 | bellard | } |
385 | 58fe2f10 | bellard | break;
|
386 | 58fe2f10 | bellard | |
387 | 58fe2f10 | bellard | case 0x80: /* GRP1 */ |
388 | 58fe2f10 | bellard | case 0x81: |
389 | 58fe2f10 | bellard | case 0x83: |
390 | 58fe2f10 | bellard | { |
391 | 58fe2f10 | bellard | if ((b & 1) == 0) |
392 | 58fe2f10 | bellard | ot = OT_BYTE; |
393 | 58fe2f10 | bellard | else
|
394 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
395 | 58fe2f10 | bellard | |
396 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
397 | 58fe2f10 | bellard | parse_modrm(s, modrm); |
398 | 58fe2f10 | bellard | |
399 | 58fe2f10 | bellard | switch(b) {
|
400 | 58fe2f10 | bellard | default:
|
401 | 58fe2f10 | bellard | case 0x80: |
402 | 58fe2f10 | bellard | case 0x81: |
403 | 58fe2f10 | bellard | insn_get(s, ot); |
404 | 58fe2f10 | bellard | break;
|
405 | 58fe2f10 | bellard | case 0x83: |
406 | 58fe2f10 | bellard | insn_get(s, OT_BYTE); |
407 | 58fe2f10 | bellard | break;
|
408 | 58fe2f10 | bellard | } |
409 | 58fe2f10 | bellard | } |
410 | 58fe2f10 | bellard | break;
|
411 | 58fe2f10 | bellard | |
412 | 58fe2f10 | bellard | /**************************/
|
413 | 58fe2f10 | bellard | /* inc, dec, and other misc arith */
|
414 | 58fe2f10 | bellard | case 0x40 ... 0x47: /* inc Gv */ |
415 | 58fe2f10 | bellard | break;
|
416 | 58fe2f10 | bellard | case 0x48 ... 0x4f: /* dec Gv */ |
417 | 58fe2f10 | bellard | break;
|
418 | 58fe2f10 | bellard | case 0xf6: /* GRP3 */ |
419 | 58fe2f10 | bellard | case 0xf7: |
420 | 58fe2f10 | bellard | if ((b & 1) == 0) |
421 | 58fe2f10 | bellard | ot = OT_BYTE; |
422 | 58fe2f10 | bellard | else
|
423 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
424 | 58fe2f10 | bellard | |
425 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
426 | 58fe2f10 | bellard | op = (modrm >> 3) & 7; |
427 | 58fe2f10 | bellard | parse_modrm(s, modrm); |
428 | 58fe2f10 | bellard | |
429 | 58fe2f10 | bellard | switch(op) {
|
430 | 58fe2f10 | bellard | case 0: /* test */ |
431 | 58fe2f10 | bellard | insn_get(s, ot); |
432 | 58fe2f10 | bellard | break;
|
433 | 58fe2f10 | bellard | case 2: /* not */ |
434 | 58fe2f10 | bellard | break;
|
435 | 58fe2f10 | bellard | case 3: /* neg */ |
436 | 58fe2f10 | bellard | break;
|
437 | 58fe2f10 | bellard | case 4: /* mul */ |
438 | 58fe2f10 | bellard | break;
|
439 | 58fe2f10 | bellard | case 5: /* imul */ |
440 | 58fe2f10 | bellard | break;
|
441 | 58fe2f10 | bellard | case 6: /* div */ |
442 | 58fe2f10 | bellard | break;
|
443 | 58fe2f10 | bellard | case 7: /* idiv */ |
444 | 58fe2f10 | bellard | break;
|
445 | 58fe2f10 | bellard | default:
|
446 | 58fe2f10 | bellard | goto illegal_op;
|
447 | 58fe2f10 | bellard | } |
448 | 58fe2f10 | bellard | break;
|
449 | 58fe2f10 | bellard | |
450 | 58fe2f10 | bellard | case 0xfe: /* GRP4 */ |
451 | 58fe2f10 | bellard | case 0xff: /* GRP5 */ |
452 | 58fe2f10 | bellard | if ((b & 1) == 0) |
453 | 58fe2f10 | bellard | ot = OT_BYTE; |
454 | 58fe2f10 | bellard | else
|
455 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
456 | 58fe2f10 | bellard | |
457 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
458 | 58fe2f10 | bellard | mod = (modrm >> 6) & 3; |
459 | 58fe2f10 | bellard | op = (modrm >> 3) & 7; |
460 | 58fe2f10 | bellard | if (op >= 2 && b == 0xfe) { |
461 | 58fe2f10 | bellard | goto illegal_op;
|
462 | 58fe2f10 | bellard | } |
463 | 58fe2f10 | bellard | pc_tmp = s->pc; |
464 | 58fe2f10 | bellard | parse_modrm(s, modrm); |
465 | 58fe2f10 | bellard | |
466 | 58fe2f10 | bellard | switch(op) {
|
467 | 58fe2f10 | bellard | case 0: /* inc Ev */ |
468 | 58fe2f10 | bellard | break;
|
469 | 58fe2f10 | bellard | case 1: /* dec Ev */ |
470 | 58fe2f10 | bellard | break;
|
471 | 58fe2f10 | bellard | case 2: /* call Ev */ |
472 | 58fe2f10 | bellard | /* XXX: optimize and handle MEM exceptions specifically
|
473 | 58fe2f10 | bellard | fs movl %eax, regs[0]
|
474 | 58fe2f10 | bellard | movl Ev, %eax
|
475 | 58fe2f10 | bellard | pushl next_eip
|
476 | 58fe2f10 | bellard | fs movl %eax, eip
|
477 | 58fe2f10 | bellard | */
|
478 | 58fe2f10 | bellard | goto unsupported_op;
|
479 | 58fe2f10 | bellard | case 3: /* lcall Ev */ |
480 | 58fe2f10 | bellard | goto unsupported_op;
|
481 | 58fe2f10 | bellard | case 4: /* jmp Ev */ |
482 | 58fe2f10 | bellard | /* XXX: optimize and handle MEM exceptions specifically
|
483 | 58fe2f10 | bellard | fs movl %eax, regs[0]
|
484 | 58fe2f10 | bellard | movl Ev, %eax
|
485 | 58fe2f10 | bellard | fs movl %eax, eip
|
486 | 58fe2f10 | bellard | */
|
487 | 58fe2f10 | bellard | goto unsupported_op;
|
488 | 58fe2f10 | bellard | case 5: /* ljmp Ev */ |
489 | 58fe2f10 | bellard | goto unsupported_op;
|
490 | 58fe2f10 | bellard | case 6: /* push Ev */ |
491 | 58fe2f10 | bellard | break;
|
492 | 58fe2f10 | bellard | default:
|
493 | 58fe2f10 | bellard | goto illegal_op;
|
494 | 58fe2f10 | bellard | } |
495 | 58fe2f10 | bellard | break;
|
496 | 58fe2f10 | bellard | case 0xa8: /* test eAX, Iv */ |
497 | 58fe2f10 | bellard | case 0xa9: |
498 | 58fe2f10 | bellard | if ((b & 1) == 0) |
499 | 58fe2f10 | bellard | ot = OT_BYTE; |
500 | 58fe2f10 | bellard | else
|
501 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
502 | 58fe2f10 | bellard | insn_get(s, ot); |
503 | 58fe2f10 | bellard | break;
|
504 | 58fe2f10 | bellard | |
505 | 58fe2f10 | bellard | case 0x98: /* CWDE/CBW */ |
506 | 58fe2f10 | bellard | break;
|
507 | 58fe2f10 | bellard | case 0x99: /* CDQ/CWD */ |
508 | 58fe2f10 | bellard | break;
|
509 | 58fe2f10 | bellard | case 0x1af: /* imul Gv, Ev */ |
510 | 58fe2f10 | bellard | case 0x69: /* imul Gv, Ev, I */ |
511 | 58fe2f10 | bellard | case 0x6b: |
512 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
513 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
514 | 58fe2f10 | bellard | parse_modrm(s, modrm); |
515 | 58fe2f10 | bellard | if (b == 0x69) { |
516 | 58fe2f10 | bellard | insn_get(s, ot); |
517 | 58fe2f10 | bellard | } else if (b == 0x6b) { |
518 | 58fe2f10 | bellard | insn_get(s, OT_BYTE); |
519 | 58fe2f10 | bellard | } else {
|
520 | 58fe2f10 | bellard | } |
521 | 58fe2f10 | bellard | break;
|
522 | 58fe2f10 | bellard | |
523 | 58fe2f10 | bellard | case 0x84: /* test Ev, Gv */ |
524 | 58fe2f10 | bellard | case 0x85: |
525 | 58fe2f10 | bellard | |
526 | 58fe2f10 | bellard | case 0x1c0: |
527 | 58fe2f10 | bellard | case 0x1c1: /* xadd Ev, Gv */ |
528 | 58fe2f10 | bellard | |
529 | 58fe2f10 | bellard | case 0x1b0: |
530 | 58fe2f10 | bellard | case 0x1b1: /* cmpxchg Ev, Gv */ |
531 | 58fe2f10 | bellard | |
532 | 58fe2f10 | bellard | case 0x8f: /* pop Ev */ |
533 | 58fe2f10 | bellard | |
534 | 58fe2f10 | bellard | case 0x88: |
535 | 58fe2f10 | bellard | case 0x89: /* mov Gv, Ev */ |
536 | 58fe2f10 | bellard | |
537 | 58fe2f10 | bellard | case 0x8a: |
538 | 58fe2f10 | bellard | case 0x8b: /* mov Ev, Gv */ |
539 | 58fe2f10 | bellard | |
540 | 58fe2f10 | bellard | case 0x1b6: /* movzbS Gv, Eb */ |
541 | 58fe2f10 | bellard | case 0x1b7: /* movzwS Gv, Eb */ |
542 | 58fe2f10 | bellard | case 0x1be: /* movsbS Gv, Eb */ |
543 | 58fe2f10 | bellard | case 0x1bf: /* movswS Gv, Eb */ |
544 | 58fe2f10 | bellard | |
545 | 58fe2f10 | bellard | case 0x86: |
546 | 58fe2f10 | bellard | case 0x87: /* xchg Ev, Gv */ |
547 | 58fe2f10 | bellard | |
548 | 58fe2f10 | bellard | case 0xd0: |
549 | 58fe2f10 | bellard | case 0xd1: /* shift Ev,1 */ |
550 | 58fe2f10 | bellard | |
551 | 58fe2f10 | bellard | case 0xd2: |
552 | 58fe2f10 | bellard | case 0xd3: /* shift Ev,cl */ |
553 | 58fe2f10 | bellard | |
554 | 58fe2f10 | bellard | case 0x1a5: /* shld cl */ |
555 | 58fe2f10 | bellard | case 0x1ad: /* shrd cl */ |
556 | 58fe2f10 | bellard | |
557 | 58fe2f10 | bellard | case 0x190 ... 0x19f: /* setcc Gv */ |
558 | 58fe2f10 | bellard | |
559 | 58fe2f10 | bellard | /* XXX: emulate cmov if not available ? */
|
560 | 58fe2f10 | bellard | case 0x140 ... 0x14f: /* cmov Gv, Ev */ |
561 | 58fe2f10 | bellard | |
562 | 58fe2f10 | bellard | case 0x1a3: /* bt Gv, Ev */ |
563 | 58fe2f10 | bellard | case 0x1ab: /* bts */ |
564 | 58fe2f10 | bellard | case 0x1b3: /* btr */ |
565 | 58fe2f10 | bellard | case 0x1bb: /* btc */ |
566 | 58fe2f10 | bellard | |
567 | 58fe2f10 | bellard | case 0x1bc: /* bsf */ |
568 | 58fe2f10 | bellard | case 0x1bd: /* bsr */ |
569 | 58fe2f10 | bellard | |
570 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
571 | 58fe2f10 | bellard | parse_modrm(s, modrm); |
572 | 58fe2f10 | bellard | break;
|
573 | 58fe2f10 | bellard | |
574 | 58fe2f10 | bellard | case 0x1c7: /* cmpxchg8b */ |
575 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
576 | 58fe2f10 | bellard | mod = (modrm >> 6) & 3; |
577 | 58fe2f10 | bellard | if (mod == 3) |
578 | 58fe2f10 | bellard | goto illegal_op;
|
579 | 58fe2f10 | bellard | parse_modrm(s, modrm); |
580 | 58fe2f10 | bellard | break;
|
581 | 58fe2f10 | bellard | |
582 | 58fe2f10 | bellard | /**************************/
|
583 | 58fe2f10 | bellard | /* push/pop */
|
584 | 58fe2f10 | bellard | case 0x50 ... 0x57: /* push */ |
585 | 58fe2f10 | bellard | case 0x58 ... 0x5f: /* pop */ |
586 | 58fe2f10 | bellard | case 0x60: /* pusha */ |
587 | 58fe2f10 | bellard | case 0x61: /* popa */ |
588 | 58fe2f10 | bellard | break;
|
589 | 58fe2f10 | bellard | |
590 | 58fe2f10 | bellard | case 0x68: /* push Iv */ |
591 | 58fe2f10 | bellard | case 0x6a: |
592 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
593 | 58fe2f10 | bellard | if (b == 0x68) |
594 | 58fe2f10 | bellard | insn_get(s, ot); |
595 | 58fe2f10 | bellard | else
|
596 | 58fe2f10 | bellard | insn_get(s, OT_BYTE); |
597 | 58fe2f10 | bellard | break;
|
598 | 58fe2f10 | bellard | case 0xc8: /* enter */ |
599 | 58fe2f10 | bellard | lduw_code(s->pc); |
600 | 58fe2f10 | bellard | s->pc += 2;
|
601 | 58fe2f10 | bellard | ldub_code(s->pc++); |
602 | 58fe2f10 | bellard | break;
|
603 | 58fe2f10 | bellard | case 0xc9: /* leave */ |
604 | 58fe2f10 | bellard | break;
|
605 | 58fe2f10 | bellard | |
606 | 58fe2f10 | bellard | case 0x06: /* push es */ |
607 | 58fe2f10 | bellard | case 0x0e: /* push cs */ |
608 | 58fe2f10 | bellard | case 0x16: /* push ss */ |
609 | 58fe2f10 | bellard | case 0x1e: /* push ds */ |
610 | 58fe2f10 | bellard | /* XXX: optimize:
|
611 | 58fe2f10 | bellard | push segs[n].selector
|
612 | 58fe2f10 | bellard | */
|
613 | 58fe2f10 | bellard | goto unsupported_op;
|
614 | 58fe2f10 | bellard | case 0x1a0: /* push fs */ |
615 | 58fe2f10 | bellard | case 0x1a8: /* push gs */ |
616 | 58fe2f10 | bellard | goto unsupported_op;
|
617 | 58fe2f10 | bellard | case 0x07: /* pop es */ |
618 | 58fe2f10 | bellard | case 0x17: /* pop ss */ |
619 | 58fe2f10 | bellard | case 0x1f: /* pop ds */ |
620 | 58fe2f10 | bellard | goto unsupported_op;
|
621 | 58fe2f10 | bellard | case 0x1a1: /* pop fs */ |
622 | 58fe2f10 | bellard | case 0x1a9: /* pop gs */ |
623 | 58fe2f10 | bellard | goto unsupported_op;
|
624 | 58fe2f10 | bellard | case 0x8e: /* mov seg, Gv */ |
625 | 58fe2f10 | bellard | /* XXX: optimize:
|
626 | 58fe2f10 | bellard | fs movl r, regs[]
|
627 | 58fe2f10 | bellard | movl segs[].selector, r
|
628 | 58fe2f10 | bellard | mov r, Gv
|
629 | 58fe2f10 | bellard | fs movl regs[], r
|
630 | 58fe2f10 | bellard | */
|
631 | 58fe2f10 | bellard | goto unsupported_op;
|
632 | 58fe2f10 | bellard | case 0x8c: /* mov Gv, seg */ |
633 | 58fe2f10 | bellard | goto unsupported_op;
|
634 | 58fe2f10 | bellard | case 0xc4: /* les Gv */ |
635 | 58fe2f10 | bellard | op = R_ES; |
636 | 58fe2f10 | bellard | goto do_lxx;
|
637 | 58fe2f10 | bellard | case 0xc5: /* lds Gv */ |
638 | 58fe2f10 | bellard | op = R_DS; |
639 | 58fe2f10 | bellard | goto do_lxx;
|
640 | 58fe2f10 | bellard | case 0x1b2: /* lss Gv */ |
641 | 58fe2f10 | bellard | op = R_SS; |
642 | 58fe2f10 | bellard | goto do_lxx;
|
643 | 58fe2f10 | bellard | case 0x1b4: /* lfs Gv */ |
644 | 58fe2f10 | bellard | op = R_FS; |
645 | 58fe2f10 | bellard | goto do_lxx;
|
646 | 58fe2f10 | bellard | case 0x1b5: /* lgs Gv */ |
647 | 58fe2f10 | bellard | op = R_GS; |
648 | 58fe2f10 | bellard | do_lxx:
|
649 | 58fe2f10 | bellard | goto unsupported_op;
|
650 | 58fe2f10 | bellard | /************************/
|
651 | 58fe2f10 | bellard | /* floats */
|
652 | 58fe2f10 | bellard | case 0xd8 ... 0xdf: |
653 | 42c3c0cc | bellard | #if 1 |
654 | 42c3c0cc | bellard | /* currently not stable enough */
|
655 | 42c3c0cc | bellard | goto unsupported_op;
|
656 | 42c3c0cc | bellard | #else
|
657 | 42c3c0cc | bellard | if (s->flags & (HF_EM_MASK | HF_TS_MASK))
|
658 | 42c3c0cc | bellard | goto unsupported_op;
|
659 | 42c3c0cc | bellard | #endif
|
660 | 42c3c0cc | bellard | #if 0
|
661 | 42c3c0cc | bellard | /* for testing FPU context switch */
|
662 | 42c3c0cc | bellard | {
|
663 | 42c3c0cc | bellard | static int count;
|
664 | 42c3c0cc | bellard | count = (count + 1) % 3;
|
665 | 42c3c0cc | bellard | if (count != 0)
|
666 | 42c3c0cc | bellard | goto unsupported_op;
|
667 | 42c3c0cc | bellard | }
|
668 | 42c3c0cc | bellard | #endif
|
669 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
670 | 58fe2f10 | bellard | mod = (modrm >> 6) & 3; |
671 | 58fe2f10 | bellard | rm = modrm & 7;
|
672 | 58fe2f10 | bellard | op = ((b & 7) << 3) | ((modrm >> 3) & 7); |
673 | 58fe2f10 | bellard | if (mod != 3) { |
674 | 58fe2f10 | bellard | /* memory op */
|
675 | 42c3c0cc | bellard | parse_modrm(s, modrm); |
676 | 58fe2f10 | bellard | switch(op) {
|
677 | 58fe2f10 | bellard | case 0x00 ... 0x07: /* fxxxs */ |
678 | 58fe2f10 | bellard | case 0x10 ... 0x17: /* fixxxl */ |
679 | 58fe2f10 | bellard | case 0x20 ... 0x27: /* fxxxl */ |
680 | 58fe2f10 | bellard | case 0x30 ... 0x37: /* fixxx */ |
681 | 58fe2f10 | bellard | break;
|
682 | 58fe2f10 | bellard | case 0x08: /* flds */ |
683 | 58fe2f10 | bellard | case 0x0a: /* fsts */ |
684 | 58fe2f10 | bellard | case 0x0b: /* fstps */ |
685 | 58fe2f10 | bellard | case 0x18: /* fildl */ |
686 | 58fe2f10 | bellard | case 0x1a: /* fistl */ |
687 | 58fe2f10 | bellard | case 0x1b: /* fistpl */ |
688 | 58fe2f10 | bellard | case 0x28: /* fldl */ |
689 | 58fe2f10 | bellard | case 0x2a: /* fstl */ |
690 | 58fe2f10 | bellard | case 0x2b: /* fstpl */ |
691 | 58fe2f10 | bellard | case 0x38: /* filds */ |
692 | 58fe2f10 | bellard | case 0x3a: /* fists */ |
693 | 58fe2f10 | bellard | case 0x3b: /* fistps */ |
694 | 58fe2f10 | bellard | case 0x0c: /* fldenv mem */ |
695 | 58fe2f10 | bellard | case 0x0d: /* fldcw mem */ |
696 | 58fe2f10 | bellard | case 0x0e: /* fnstenv mem */ |
697 | 58fe2f10 | bellard | case 0x0f: /* fnstcw mem */ |
698 | 58fe2f10 | bellard | case 0x1d: /* fldt mem */ |
699 | 58fe2f10 | bellard | case 0x1f: /* fstpt mem */ |
700 | 58fe2f10 | bellard | case 0x2c: /* frstor mem */ |
701 | 58fe2f10 | bellard | case 0x2e: /* fnsave mem */ |
702 | 58fe2f10 | bellard | case 0x2f: /* fnstsw mem */ |
703 | 58fe2f10 | bellard | case 0x3c: /* fbld */ |
704 | 58fe2f10 | bellard | case 0x3e: /* fbstp */ |
705 | 58fe2f10 | bellard | case 0x3d: /* fildll */ |
706 | 58fe2f10 | bellard | case 0x3f: /* fistpll */ |
707 | 58fe2f10 | bellard | break;
|
708 | 58fe2f10 | bellard | default:
|
709 | 58fe2f10 | bellard | goto illegal_op;
|
710 | 58fe2f10 | bellard | } |
711 | 58fe2f10 | bellard | } else {
|
712 | 58fe2f10 | bellard | /* register float ops */
|
713 | 58fe2f10 | bellard | switch(op) {
|
714 | 58fe2f10 | bellard | case 0x08: /* fld sti */ |
715 | 58fe2f10 | bellard | case 0x09: /* fxchg sti */ |
716 | 58fe2f10 | bellard | break;
|
717 | 58fe2f10 | bellard | case 0x0a: /* grp d9/2 */ |
718 | 58fe2f10 | bellard | switch(rm) {
|
719 | 58fe2f10 | bellard | case 0: /* fnop */ |
720 | 58fe2f10 | bellard | break;
|
721 | 58fe2f10 | bellard | default:
|
722 | 58fe2f10 | bellard | goto illegal_op;
|
723 | 58fe2f10 | bellard | } |
724 | 58fe2f10 | bellard | break;
|
725 | 58fe2f10 | bellard | case 0x0c: /* grp d9/4 */ |
726 | 58fe2f10 | bellard | switch(rm) {
|
727 | 58fe2f10 | bellard | case 0: /* fchs */ |
728 | 58fe2f10 | bellard | case 1: /* fabs */ |
729 | 58fe2f10 | bellard | case 4: /* ftst */ |
730 | 58fe2f10 | bellard | case 5: /* fxam */ |
731 | 58fe2f10 | bellard | break;
|
732 | 58fe2f10 | bellard | default:
|
733 | 58fe2f10 | bellard | goto illegal_op;
|
734 | 58fe2f10 | bellard | } |
735 | 58fe2f10 | bellard | break;
|
736 | 58fe2f10 | bellard | case 0x0d: /* grp d9/5 */ |
737 | 58fe2f10 | bellard | switch(rm) {
|
738 | 42c3c0cc | bellard | case 0: |
739 | 42c3c0cc | bellard | case 1: |
740 | 42c3c0cc | bellard | case 2: |
741 | 42c3c0cc | bellard | case 3: |
742 | 42c3c0cc | bellard | case 4: |
743 | 42c3c0cc | bellard | case 5: |
744 | 42c3c0cc | bellard | case 6: |
745 | 58fe2f10 | bellard | break;
|
746 | 58fe2f10 | bellard | default:
|
747 | 42c3c0cc | bellard | goto illegal_op;
|
748 | 58fe2f10 | bellard | } |
749 | 58fe2f10 | bellard | break;
|
750 | 42c3c0cc | bellard | case 0x0e: /* grp d9/6 */ |
751 | 42c3c0cc | bellard | break;
|
752 | 58fe2f10 | bellard | case 0x0f: /* grp d9/7 */ |
753 | 58fe2f10 | bellard | break;
|
754 | 58fe2f10 | bellard | case 0x00: case 0x01: case 0x04 ... 0x07: /* fxxx st, sti */ |
755 | 58fe2f10 | bellard | case 0x20: case 0x21: case 0x24 ... 0x27: /* fxxx sti, st */ |
756 | 58fe2f10 | bellard | case 0x30: case 0x31: case 0x34 ... 0x37: /* fxxxp sti, st */ |
757 | 58fe2f10 | bellard | break;
|
758 | 58fe2f10 | bellard | case 0x02: /* fcom */ |
759 | 58fe2f10 | bellard | break;
|
760 | 58fe2f10 | bellard | case 0x03: /* fcomp */ |
761 | 58fe2f10 | bellard | break;
|
762 | 58fe2f10 | bellard | case 0x15: /* da/5 */ |
763 | 58fe2f10 | bellard | switch(rm) {
|
764 | 58fe2f10 | bellard | case 1: /* fucompp */ |
765 | 58fe2f10 | bellard | break;
|
766 | 58fe2f10 | bellard | default:
|
767 | 58fe2f10 | bellard | goto illegal_op;
|
768 | 58fe2f10 | bellard | } |
769 | 58fe2f10 | bellard | break;
|
770 | 58fe2f10 | bellard | case 0x1c: |
771 | 58fe2f10 | bellard | switch(rm) {
|
772 | 58fe2f10 | bellard | case 0: /* feni (287 only, just do nop here) */ |
773 | 58fe2f10 | bellard | case 1: /* fdisi (287 only, just do nop here) */ |
774 | 42c3c0cc | bellard | goto unsupported_op;
|
775 | 58fe2f10 | bellard | case 2: /* fclex */ |
776 | 58fe2f10 | bellard | case 3: /* fninit */ |
777 | 58fe2f10 | bellard | case 4: /* fsetpm (287 only, just do nop here) */ |
778 | 58fe2f10 | bellard | break;
|
779 | 58fe2f10 | bellard | default:
|
780 | 58fe2f10 | bellard | goto illegal_op;
|
781 | 58fe2f10 | bellard | } |
782 | 58fe2f10 | bellard | break;
|
783 | 58fe2f10 | bellard | case 0x1d: /* fucomi */ |
784 | 58fe2f10 | bellard | break;
|
785 | 58fe2f10 | bellard | case 0x1e: /* fcomi */ |
786 | 58fe2f10 | bellard | break;
|
787 | 58fe2f10 | bellard | case 0x2a: /* fst sti */ |
788 | 58fe2f10 | bellard | break;
|
789 | 58fe2f10 | bellard | case 0x2b: /* fstp sti */ |
790 | 58fe2f10 | bellard | break;
|
791 | 58fe2f10 | bellard | case 0x2c: /* fucom st(i) */ |
792 | 58fe2f10 | bellard | break;
|
793 | 58fe2f10 | bellard | case 0x2d: /* fucomp st(i) */ |
794 | 58fe2f10 | bellard | break;
|
795 | 58fe2f10 | bellard | case 0x33: /* de/3 */ |
796 | 58fe2f10 | bellard | switch(rm) {
|
797 | 58fe2f10 | bellard | case 1: /* fcompp */ |
798 | 58fe2f10 | bellard | break;
|
799 | 58fe2f10 | bellard | default:
|
800 | 58fe2f10 | bellard | goto illegal_op;
|
801 | 58fe2f10 | bellard | } |
802 | 58fe2f10 | bellard | break;
|
803 | 58fe2f10 | bellard | case 0x3c: /* df/4 */ |
804 | 58fe2f10 | bellard | switch(rm) {
|
805 | 58fe2f10 | bellard | case 0: |
806 | 58fe2f10 | bellard | break;
|
807 | 58fe2f10 | bellard | default:
|
808 | 58fe2f10 | bellard | goto illegal_op;
|
809 | 58fe2f10 | bellard | } |
810 | 58fe2f10 | bellard | break;
|
811 | 58fe2f10 | bellard | case 0x3d: /* fucomip */ |
812 | 58fe2f10 | bellard | break;
|
813 | 58fe2f10 | bellard | case 0x3e: /* fcomip */ |
814 | 58fe2f10 | bellard | break;
|
815 | 58fe2f10 | bellard | case 0x10 ... 0x13: /* fcmovxx */ |
816 | 58fe2f10 | bellard | case 0x18 ... 0x1b: |
817 | 58fe2f10 | bellard | break;
|
818 | 58fe2f10 | bellard | default:
|
819 | 58fe2f10 | bellard | goto illegal_op;
|
820 | 58fe2f10 | bellard | } |
821 | 58fe2f10 | bellard | } |
822 | 42c3c0cc | bellard | s->tb->cflags |= CF_TB_FP_USED; |
823 | 58fe2f10 | bellard | break;
|
824 | 42c3c0cc | bellard | |
825 | 58fe2f10 | bellard | /**************************/
|
826 | 58fe2f10 | bellard | /* mov */
|
827 | 58fe2f10 | bellard | case 0xc6: |
828 | 58fe2f10 | bellard | case 0xc7: /* mov Ev, Iv */ |
829 | 58fe2f10 | bellard | if ((b & 1) == 0) |
830 | 58fe2f10 | bellard | ot = OT_BYTE; |
831 | 58fe2f10 | bellard | else
|
832 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
833 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
834 | 58fe2f10 | bellard | parse_modrm(s, modrm); |
835 | 58fe2f10 | bellard | insn_get(s, ot); |
836 | 58fe2f10 | bellard | break;
|
837 | 58fe2f10 | bellard | |
838 | 58fe2f10 | bellard | case 0x8d: /* lea */ |
839 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
840 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
841 | 58fe2f10 | bellard | mod = (modrm >> 6) & 3; |
842 | 58fe2f10 | bellard | if (mod == 3) |
843 | 58fe2f10 | bellard | goto illegal_op;
|
844 | 58fe2f10 | bellard | parse_modrm(s, modrm); |
845 | 58fe2f10 | bellard | break;
|
846 | 58fe2f10 | bellard | |
847 | 58fe2f10 | bellard | case 0xa0: /* mov EAX, Ov */ |
848 | 58fe2f10 | bellard | case 0xa1: |
849 | 58fe2f10 | bellard | case 0xa2: /* mov Ov, EAX */ |
850 | 58fe2f10 | bellard | case 0xa3: |
851 | 58fe2f10 | bellard | if ((b & 1) == 0) |
852 | 58fe2f10 | bellard | ot = OT_BYTE; |
853 | 58fe2f10 | bellard | else
|
854 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
855 | 58fe2f10 | bellard | if (s->aflag)
|
856 | 58fe2f10 | bellard | insn_get(s, OT_LONG); |
857 | 58fe2f10 | bellard | else
|
858 | 58fe2f10 | bellard | insn_get(s, OT_WORD); |
859 | 58fe2f10 | bellard | break;
|
860 | 58fe2f10 | bellard | case 0xd7: /* xlat */ |
861 | 58fe2f10 | bellard | break;
|
862 | 58fe2f10 | bellard | case 0xb0 ... 0xb7: /* mov R, Ib */ |
863 | 58fe2f10 | bellard | insn_get(s, OT_BYTE); |
864 | 58fe2f10 | bellard | break;
|
865 | 58fe2f10 | bellard | case 0xb8 ... 0xbf: /* mov R, Iv */ |
866 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
867 | 58fe2f10 | bellard | insn_get(s, ot); |
868 | 58fe2f10 | bellard | break;
|
869 | 58fe2f10 | bellard | |
870 | 58fe2f10 | bellard | case 0x91 ... 0x97: /* xchg R, EAX */ |
871 | 58fe2f10 | bellard | break;
|
872 | 58fe2f10 | bellard | |
873 | 58fe2f10 | bellard | /************************/
|
874 | 58fe2f10 | bellard | /* shifts */
|
875 | 58fe2f10 | bellard | case 0xc0: |
876 | 58fe2f10 | bellard | case 0xc1: /* shift Ev,imm */ |
877 | 58fe2f10 | bellard | |
878 | 58fe2f10 | bellard | case 0x1a4: /* shld imm */ |
879 | 58fe2f10 | bellard | case 0x1ac: /* shrd imm */ |
880 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
881 | 58fe2f10 | bellard | parse_modrm(s, modrm); |
882 | 58fe2f10 | bellard | ldub_code(s->pc++); |
883 | 58fe2f10 | bellard | break;
|
884 | 58fe2f10 | bellard | |
885 | 58fe2f10 | bellard | /************************/
|
886 | 58fe2f10 | bellard | /* string ops */
|
887 | 58fe2f10 | bellard | |
888 | 58fe2f10 | bellard | case 0xa4: /* movsS */ |
889 | 58fe2f10 | bellard | case 0xa5: |
890 | 58fe2f10 | bellard | break;
|
891 | 58fe2f10 | bellard | |
892 | 58fe2f10 | bellard | case 0xaa: /* stosS */ |
893 | 58fe2f10 | bellard | case 0xab: |
894 | 58fe2f10 | bellard | break;
|
895 | 58fe2f10 | bellard | |
896 | 58fe2f10 | bellard | case 0xac: /* lodsS */ |
897 | 58fe2f10 | bellard | case 0xad: |
898 | 58fe2f10 | bellard | break;
|
899 | 58fe2f10 | bellard | |
900 | 58fe2f10 | bellard | case 0xae: /* scasS */ |
901 | 58fe2f10 | bellard | case 0xaf: |
902 | 58fe2f10 | bellard | break;
|
903 | 58fe2f10 | bellard | |
904 | 58fe2f10 | bellard | case 0xa6: /* cmpsS */ |
905 | 58fe2f10 | bellard | case 0xa7: |
906 | 58fe2f10 | bellard | break;
|
907 | 58fe2f10 | bellard | |
908 | 58fe2f10 | bellard | case 0x6c: /* insS */ |
909 | 58fe2f10 | bellard | case 0x6d: |
910 | 58fe2f10 | bellard | goto unsupported_op;
|
911 | 58fe2f10 | bellard | |
912 | 58fe2f10 | bellard | case 0x6e: /* outsS */ |
913 | 58fe2f10 | bellard | case 0x6f: |
914 | 58fe2f10 | bellard | goto unsupported_op;
|
915 | 58fe2f10 | bellard | |
916 | 58fe2f10 | bellard | /************************/
|
917 | 58fe2f10 | bellard | /* port I/O */
|
918 | 58fe2f10 | bellard | case 0xe4: |
919 | 58fe2f10 | bellard | case 0xe5: |
920 | 58fe2f10 | bellard | goto unsupported_op;
|
921 | 58fe2f10 | bellard | |
922 | 58fe2f10 | bellard | case 0xe6: |
923 | 58fe2f10 | bellard | case 0xe7: |
924 | 58fe2f10 | bellard | goto unsupported_op;
|
925 | 58fe2f10 | bellard | |
926 | 58fe2f10 | bellard | case 0xec: |
927 | 58fe2f10 | bellard | case 0xed: |
928 | 58fe2f10 | bellard | goto unsupported_op;
|
929 | 58fe2f10 | bellard | |
930 | 58fe2f10 | bellard | case 0xee: |
931 | 58fe2f10 | bellard | case 0xef: |
932 | 58fe2f10 | bellard | goto unsupported_op;
|
933 | 58fe2f10 | bellard | |
934 | 58fe2f10 | bellard | /************************/
|
935 | 58fe2f10 | bellard | /* control */
|
936 | 58fe2f10 | bellard | #if 0
|
937 | 58fe2f10 | bellard | case 0xc2: /* ret im */
|
938 | 58fe2f10 | bellard | val = ldsw_code(s->pc);
|
939 | 58fe2f10 | bellard | s->pc += 2;
|
940 | 58fe2f10 | bellard | gen_pop_T0(s);
|
941 | 58fe2f10 | bellard | gen_stack_update(s, val + (2 << s->dflag));
|
942 | 58fe2f10 | bellard | if (s->dflag == 0)
|
943 | 58fe2f10 | bellard | gen_op_andl_T0_ffff();
|
944 | 58fe2f10 | bellard | gen_op_jmp_T0();
|
945 | 58fe2f10 | bellard | gen_eob(s);
|
946 | 58fe2f10 | bellard | break;
|
947 | 58fe2f10 | bellard | #endif
|
948 | 58fe2f10 | bellard | |
949 | 58fe2f10 | bellard | case 0xc3: /* ret */ |
950 | 58fe2f10 | bellard | gb(s, CPU_SEG); |
951 | 58fe2f10 | bellard | if (!s->dflag)
|
952 | 58fe2f10 | bellard | gb(s, 0x66); /* d16 */ |
953 | 58fe2f10 | bellard | gb(s, 0x8f); /* pop addr */ |
954 | 58fe2f10 | bellard | gb(s, 0x05);
|
955 | 58fe2f10 | bellard | gl(s, CPU_FIELD_OFFSET(eip)); |
956 | 58fe2f10 | bellard | if (!s->dflag) {
|
957 | 58fe2f10 | bellard | /* reset high bits of EIP */
|
958 | 58fe2f10 | bellard | gen_movw_addr_im(s, CPU_FIELD_OFFSET(eip) + 2, 0); |
959 | 58fe2f10 | bellard | } |
960 | 58fe2f10 | bellard | gen_eob(s); |
961 | 58fe2f10 | bellard | goto no_copy;
|
962 | 58fe2f10 | bellard | case 0xca: /* lret im */ |
963 | 58fe2f10 | bellard | case 0xcb: /* lret */ |
964 | 58fe2f10 | bellard | case 0xcf: /* iret */ |
965 | 58fe2f10 | bellard | case 0x9a: /* lcall im */ |
966 | 58fe2f10 | bellard | case 0xea: /* ljmp im */ |
967 | 58fe2f10 | bellard | goto unsupported_op;
|
968 | 58fe2f10 | bellard | |
969 | 58fe2f10 | bellard | case 0xe8: /* call im */ |
970 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
971 | 58fe2f10 | bellard | val = insn_get(s, ot); |
972 | 58fe2f10 | bellard | next_eip = s->pc - s->cs_base; |
973 | 58fe2f10 | bellard | val += next_eip; |
974 | 58fe2f10 | bellard | if (s->dflag) {
|
975 | 58fe2f10 | bellard | gb(s, 0x68); /* pushl imm */ |
976 | 58fe2f10 | bellard | gl(s, next_eip); |
977 | 58fe2f10 | bellard | } else {
|
978 | 58fe2f10 | bellard | gb(s, 0x66); /* pushw imm */ |
979 | 58fe2f10 | bellard | gb(s, 0x68);
|
980 | 58fe2f10 | bellard | gw(s, next_eip); |
981 | 58fe2f10 | bellard | val &= 0xffff;
|
982 | 58fe2f10 | bellard | } |
983 | 58fe2f10 | bellard | gen_jmp(s, val); |
984 | 58fe2f10 | bellard | goto no_copy;
|
985 | 58fe2f10 | bellard | case 0xe9: /* jmp */ |
986 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
987 | 58fe2f10 | bellard | val = insn_get(s, ot); |
988 | 58fe2f10 | bellard | val += s->pc - s->cs_base; |
989 | 58fe2f10 | bellard | if (s->dflag == 0) |
990 | 58fe2f10 | bellard | val = val & 0xffff;
|
991 | 58fe2f10 | bellard | gen_jmp(s, val); |
992 | 58fe2f10 | bellard | goto no_copy;
|
993 | 58fe2f10 | bellard | case 0xeb: /* jmp Jb */ |
994 | 58fe2f10 | bellard | val = (int8_t)insn_get(s, OT_BYTE); |
995 | 58fe2f10 | bellard | val += s->pc - s->cs_base; |
996 | 58fe2f10 | bellard | if (s->dflag == 0) |
997 | 58fe2f10 | bellard | val = val & 0xffff;
|
998 | 58fe2f10 | bellard | gen_jmp(s, val); |
999 | 58fe2f10 | bellard | goto no_copy;
|
1000 | 58fe2f10 | bellard | case 0x70 ... 0x7f: /* jcc Jb */ |
1001 | 58fe2f10 | bellard | val = (int8_t)insn_get(s, OT_BYTE); |
1002 | 58fe2f10 | bellard | goto do_jcc;
|
1003 | 58fe2f10 | bellard | case 0x180 ... 0x18f: /* jcc Jv */ |
1004 | 58fe2f10 | bellard | if (dflag) {
|
1005 | 58fe2f10 | bellard | val = insn_get(s, OT_LONG); |
1006 | 58fe2f10 | bellard | } else {
|
1007 | 58fe2f10 | bellard | val = (int16_t)insn_get(s, OT_WORD); |
1008 | 58fe2f10 | bellard | } |
1009 | 58fe2f10 | bellard | do_jcc:
|
1010 | 58fe2f10 | bellard | next_eip = s->pc - s->cs_base; |
1011 | 58fe2f10 | bellard | val += next_eip; |
1012 | 58fe2f10 | bellard | if (s->dflag == 0) |
1013 | 58fe2f10 | bellard | val &= 0xffff;
|
1014 | 58fe2f10 | bellard | gen_jcc(s, b & 0xf, val, next_eip);
|
1015 | 58fe2f10 | bellard | goto no_copy;
|
1016 | 58fe2f10 | bellard | |
1017 | 58fe2f10 | bellard | /************************/
|
1018 | 58fe2f10 | bellard | /* flags */
|
1019 | 58fe2f10 | bellard | case 0x9c: /* pushf */ |
1020 | 58fe2f10 | bellard | /* XXX: put specific code ? */
|
1021 | 58fe2f10 | bellard | goto unsupported_op;
|
1022 | 58fe2f10 | bellard | case 0x9d: /* popf */ |
1023 | 58fe2f10 | bellard | goto unsupported_op;
|
1024 | 58fe2f10 | bellard | |
1025 | 58fe2f10 | bellard | case 0x9e: /* sahf */ |
1026 | 58fe2f10 | bellard | case 0x9f: /* lahf */ |
1027 | 58fe2f10 | bellard | case 0xf5: /* cmc */ |
1028 | 58fe2f10 | bellard | case 0xf8: /* clc */ |
1029 | 58fe2f10 | bellard | case 0xf9: /* stc */ |
1030 | 58fe2f10 | bellard | case 0xfc: /* cld */ |
1031 | 58fe2f10 | bellard | case 0xfd: /* std */ |
1032 | 58fe2f10 | bellard | break;
|
1033 | 58fe2f10 | bellard | |
1034 | 58fe2f10 | bellard | /************************/
|
1035 | 58fe2f10 | bellard | /* bit operations */
|
1036 | 58fe2f10 | bellard | case 0x1ba: /* bt/bts/btr/btc Gv, im */ |
1037 | 58fe2f10 | bellard | ot = dflag ? OT_LONG : OT_WORD; |
1038 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
1039 | 58fe2f10 | bellard | op = (modrm >> 3) & 7; |
1040 | 58fe2f10 | bellard | parse_modrm(s, modrm); |
1041 | 58fe2f10 | bellard | /* load shift */
|
1042 | 58fe2f10 | bellard | ldub_code(s->pc++); |
1043 | 58fe2f10 | bellard | if (op < 4) |
1044 | 58fe2f10 | bellard | goto illegal_op;
|
1045 | 58fe2f10 | bellard | break;
|
1046 | 58fe2f10 | bellard | /************************/
|
1047 | 58fe2f10 | bellard | /* bcd */
|
1048 | 58fe2f10 | bellard | case 0x27: /* daa */ |
1049 | 58fe2f10 | bellard | break;
|
1050 | 58fe2f10 | bellard | case 0x2f: /* das */ |
1051 | 58fe2f10 | bellard | break;
|
1052 | 58fe2f10 | bellard | case 0x37: /* aaa */ |
1053 | 58fe2f10 | bellard | break;
|
1054 | 58fe2f10 | bellard | case 0x3f: /* aas */ |
1055 | 58fe2f10 | bellard | break;
|
1056 | 58fe2f10 | bellard | case 0xd4: /* aam */ |
1057 | 58fe2f10 | bellard | ldub_code(s->pc++); |
1058 | 58fe2f10 | bellard | break;
|
1059 | 58fe2f10 | bellard | case 0xd5: /* aad */ |
1060 | 58fe2f10 | bellard | ldub_code(s->pc++); |
1061 | 58fe2f10 | bellard | break;
|
1062 | 58fe2f10 | bellard | /************************/
|
1063 | 58fe2f10 | bellard | /* misc */
|
1064 | 58fe2f10 | bellard | case 0x90: /* nop */ |
1065 | 58fe2f10 | bellard | break;
|
1066 | 58fe2f10 | bellard | case 0x9b: /* fwait */ |
1067 | 42c3c0cc | bellard | if ((s->flags & (HF_MP_MASK | HF_TS_MASK)) ==
|
1068 | 42c3c0cc | bellard | (HF_MP_MASK | HF_TS_MASK)) { |
1069 | 42c3c0cc | bellard | goto unsupported_op;
|
1070 | 42c3c0cc | bellard | } |
1071 | 58fe2f10 | bellard | break;
|
1072 | 58fe2f10 | bellard | case 0xcc: /* int3 */ |
1073 | 58fe2f10 | bellard | goto unsupported_op;
|
1074 | 58fe2f10 | bellard | case 0xcd: /* int N */ |
1075 | 58fe2f10 | bellard | goto unsupported_op;
|
1076 | 58fe2f10 | bellard | case 0xce: /* into */ |
1077 | 58fe2f10 | bellard | goto unsupported_op;
|
1078 | 58fe2f10 | bellard | case 0xf1: /* icebp (undocumented, exits to external debugger) */ |
1079 | 58fe2f10 | bellard | goto unsupported_op;
|
1080 | 58fe2f10 | bellard | case 0xfa: /* cli */ |
1081 | 58fe2f10 | bellard | goto unsupported_op;
|
1082 | 58fe2f10 | bellard | case 0xfb: /* sti */ |
1083 | 58fe2f10 | bellard | goto unsupported_op;
|
1084 | 58fe2f10 | bellard | case 0x62: /* bound */ |
1085 | 58fe2f10 | bellard | modrm = ldub_code(s->pc++); |
1086 | 58fe2f10 | bellard | mod = (modrm >> 6) & 3; |
1087 | 58fe2f10 | bellard | if (mod == 3) |
1088 | 58fe2f10 | bellard | goto illegal_op;
|
1089 | 58fe2f10 | bellard | parse_modrm(s, modrm); |
1090 | 58fe2f10 | bellard | break;
|
1091 | 58fe2f10 | bellard | case 0x1c8 ... 0x1cf: /* bswap reg */ |
1092 | 58fe2f10 | bellard | break;
|
1093 | 58fe2f10 | bellard | case 0xd6: /* salc */ |
1094 | 58fe2f10 | bellard | break;
|
1095 | 58fe2f10 | bellard | case 0xe0: /* loopnz */ |
1096 | 58fe2f10 | bellard | case 0xe1: /* loopz */ |
1097 | 58fe2f10 | bellard | case 0xe2: /* loop */ |
1098 | 58fe2f10 | bellard | case 0xe3: /* jecxz */ |
1099 | 58fe2f10 | bellard | goto unsupported_op;
|
1100 | 58fe2f10 | bellard | |
1101 | 58fe2f10 | bellard | case 0x130: /* wrmsr */ |
1102 | 58fe2f10 | bellard | case 0x132: /* rdmsr */ |
1103 | 58fe2f10 | bellard | goto unsupported_op;
|
1104 | 58fe2f10 | bellard | case 0x131: /* rdtsc */ |
1105 | 58fe2f10 | bellard | goto unsupported_op;
|
1106 | 58fe2f10 | bellard | case 0x1a2: /* cpuid */ |
1107 | 58fe2f10 | bellard | goto unsupported_op;
|
1108 | 58fe2f10 | bellard | case 0xf4: /* hlt */ |
1109 | 58fe2f10 | bellard | goto unsupported_op;
|
1110 | 58fe2f10 | bellard | case 0x100: |
1111 | 58fe2f10 | bellard | goto unsupported_op;
|
1112 | 58fe2f10 | bellard | case 0x101: |
1113 | 58fe2f10 | bellard | goto unsupported_op;
|
1114 | 58fe2f10 | bellard | case 0x108: /* invd */ |
1115 | 58fe2f10 | bellard | case 0x109: /* wbinvd */ |
1116 | 58fe2f10 | bellard | goto unsupported_op;
|
1117 | 58fe2f10 | bellard | case 0x63: /* arpl */ |
1118 | 58fe2f10 | bellard | goto unsupported_op;
|
1119 | 58fe2f10 | bellard | case 0x102: /* lar */ |
1120 | 58fe2f10 | bellard | case 0x103: /* lsl */ |
1121 | 58fe2f10 | bellard | goto unsupported_op;
|
1122 | 58fe2f10 | bellard | case 0x118: |
1123 | 58fe2f10 | bellard | goto unsupported_op;
|
1124 | 58fe2f10 | bellard | case 0x120: /* mov reg, crN */ |
1125 | 58fe2f10 | bellard | case 0x122: /* mov crN, reg */ |
1126 | 58fe2f10 | bellard | goto unsupported_op;
|
1127 | 58fe2f10 | bellard | case 0x121: /* mov reg, drN */ |
1128 | 58fe2f10 | bellard | case 0x123: /* mov drN, reg */ |
1129 | 58fe2f10 | bellard | goto unsupported_op;
|
1130 | 58fe2f10 | bellard | case 0x106: /* clts */ |
1131 | 58fe2f10 | bellard | goto unsupported_op;
|
1132 | 58fe2f10 | bellard | default:
|
1133 | 58fe2f10 | bellard | goto illegal_op;
|
1134 | 58fe2f10 | bellard | } |
1135 | 58fe2f10 | bellard | |
1136 | 58fe2f10 | bellard | /* just copy the code */
|
1137 | 58fe2f10 | bellard | |
1138 | 58fe2f10 | bellard | /* no override yet */
|
1139 | 58fe2f10 | bellard | if (!s->dflag)
|
1140 | 58fe2f10 | bellard | gb(s, 0x66);
|
1141 | 58fe2f10 | bellard | if (!s->aflag)
|
1142 | 58fe2f10 | bellard | gb(s, 0x67);
|
1143 | 58fe2f10 | bellard | if (prefixes & PREFIX_REPZ)
|
1144 | 58fe2f10 | bellard | gb(s, 0xf3);
|
1145 | 58fe2f10 | bellard | else if (prefixes & PREFIX_REPNZ) |
1146 | 58fe2f10 | bellard | gb(s, 0xf2);
|
1147 | 58fe2f10 | bellard | { |
1148 | 58fe2f10 | bellard | int len, i;
|
1149 | 58fe2f10 | bellard | len = s->pc - pc_start_insn; |
1150 | 58fe2f10 | bellard | for(i = 0; i < len; i++) { |
1151 | 58fe2f10 | bellard | *s->gen_code_ptr++ = ldub_code(pc_start_insn + i); |
1152 | 58fe2f10 | bellard | } |
1153 | 58fe2f10 | bellard | } |
1154 | 58fe2f10 | bellard | no_copy:
|
1155 | 58fe2f10 | bellard | return 0; |
1156 | 58fe2f10 | bellard | illegal_op:
|
1157 | 58fe2f10 | bellard | unsupported_op:
|
1158 | 58fe2f10 | bellard | /* fall back to slower code gen necessary */
|
1159 | 58fe2f10 | bellard | s->pc = pc_start; |
1160 | 58fe2f10 | bellard | return -1; |
1161 | 58fe2f10 | bellard | } |
1162 | 58fe2f10 | bellard | |
1163 | 58fe2f10 | bellard | #define GEN_CODE_MAX_SIZE 8192 |
1164 | 58fe2f10 | bellard | #define GEN_CODE_MAX_INSN_SIZE 512 |
1165 | 58fe2f10 | bellard | |
1166 | 58fe2f10 | bellard | static inline int gen_intermediate_code_internal(CPUState *env, |
1167 | 58fe2f10 | bellard | TranslationBlock *tb, |
1168 | 58fe2f10 | bellard | uint8_t *gen_code_ptr, |
1169 | 58fe2f10 | bellard | int *gen_code_size_ptr,
|
1170 | 58fe2f10 | bellard | int search_pc,
|
1171 | 58fe2f10 | bellard | uint8_t *tc_ptr) |
1172 | 58fe2f10 | bellard | { |
1173 | 58fe2f10 | bellard | DisasContext dc1, *dc = &dc1; |
1174 | 58fe2f10 | bellard | uint8_t *pc_insn, *pc_start, *gen_code_end; |
1175 | 58fe2f10 | bellard | int flags, ret;
|
1176 | 58fe2f10 | bellard | uint8_t *cs_base; |
1177 | 58fe2f10 | bellard | |
1178 | 58fe2f10 | bellard | if (env->nb_breakpoints > 0 || |
1179 | 58fe2f10 | bellard | env->singlestep_enabled) |
1180 | 58fe2f10 | bellard | return -1; |
1181 | 58fe2f10 | bellard | flags = tb->flags; |
1182 | 58fe2f10 | bellard | if (flags & (HF_TF_MASK | HF_ADDSEG_MASK |
|
1183 | 58fe2f10 | bellard | HF_SOFTMMU_MASK | HF_INHIBIT_IRQ_MASK)) |
1184 | 58fe2f10 | bellard | return -1; |
1185 | 58fe2f10 | bellard | if (!(flags & HF_SS32_MASK))
|
1186 | 58fe2f10 | bellard | return -1; |
1187 | 58fe2f10 | bellard | gen_code_end = gen_code_ptr + |
1188 | 58fe2f10 | bellard | GEN_CODE_MAX_SIZE - GEN_CODE_MAX_INSN_SIZE; |
1189 | 58fe2f10 | bellard | dc->gen_code_ptr = gen_code_ptr; |
1190 | 58fe2f10 | bellard | dc->gen_code_start = gen_code_ptr; |
1191 | 58fe2f10 | bellard | |
1192 | 58fe2f10 | bellard | /* generate intermediate code */
|
1193 | 58fe2f10 | bellard | pc_start = (uint8_t *)tb->pc; |
1194 | 58fe2f10 | bellard | cs_base = (uint8_t *)tb->cs_base; |
1195 | 58fe2f10 | bellard | dc->pc = pc_start; |
1196 | 58fe2f10 | bellard | dc->cs_base = cs_base; |
1197 | 58fe2f10 | bellard | dc->pe = (flags >> HF_PE_SHIFT) & 1;
|
1198 | 58fe2f10 | bellard | dc->code32 = (flags >> HF_CS32_SHIFT) & 1;
|
1199 | 58fe2f10 | bellard | dc->f_st = 0;
|
1200 | 58fe2f10 | bellard | dc->vm86 = (flags >> VM_SHIFT) & 1;
|
1201 | 58fe2f10 | bellard | dc->cpl = (flags >> HF_CPL_SHIFT) & 3;
|
1202 | 58fe2f10 | bellard | dc->iopl = (flags >> IOPL_SHIFT) & 3;
|
1203 | 58fe2f10 | bellard | dc->tb = tb; |
1204 | 42c3c0cc | bellard | dc->flags = flags; |
1205 | 42c3c0cc | bellard | |
1206 | 58fe2f10 | bellard | dc->is_jmp = 0;
|
1207 | 58fe2f10 | bellard | |
1208 | 58fe2f10 | bellard | for(;;) {
|
1209 | 58fe2f10 | bellard | pc_insn = dc->pc; |
1210 | 58fe2f10 | bellard | ret = disas_insn(dc); |
1211 | 58fe2f10 | bellard | if (ret < 0) { |
1212 | 58fe2f10 | bellard | /* unsupported insn */
|
1213 | 58fe2f10 | bellard | if (dc->pc == pc_start) {
|
1214 | 58fe2f10 | bellard | /* if first instruction, signal that no copying was done */
|
1215 | 58fe2f10 | bellard | return -1; |
1216 | 58fe2f10 | bellard | } else {
|
1217 | 58fe2f10 | bellard | gen_jmp(dc, dc->pc - dc->cs_base); |
1218 | 58fe2f10 | bellard | dc->is_jmp = 1;
|
1219 | 58fe2f10 | bellard | } |
1220 | 58fe2f10 | bellard | } |
1221 | 58fe2f10 | bellard | if (search_pc) {
|
1222 | 58fe2f10 | bellard | /* search pc mode */
|
1223 | 58fe2f10 | bellard | if (tc_ptr < dc->gen_code_ptr) {
|
1224 | 58fe2f10 | bellard | env->eip = pc_insn - cs_base; |
1225 | 58fe2f10 | bellard | return 0; |
1226 | 58fe2f10 | bellard | } |
1227 | 58fe2f10 | bellard | } |
1228 | 58fe2f10 | bellard | /* stop translation if indicated */
|
1229 | 58fe2f10 | bellard | if (dc->is_jmp)
|
1230 | 58fe2f10 | bellard | break;
|
1231 | 58fe2f10 | bellard | /* if too long translation, stop generation */
|
1232 | 58fe2f10 | bellard | if (dc->gen_code_ptr >= gen_code_end ||
|
1233 | 58fe2f10 | bellard | (dc->pc - pc_start) >= (TARGET_PAGE_SIZE - 32)) {
|
1234 | 58fe2f10 | bellard | gen_jmp(dc, dc->pc - dc->cs_base); |
1235 | 58fe2f10 | bellard | break;
|
1236 | 58fe2f10 | bellard | } |
1237 | 58fe2f10 | bellard | } |
1238 | 58fe2f10 | bellard | |
1239 | 58fe2f10 | bellard | #ifdef DEBUG_DISAS
|
1240 | 58fe2f10 | bellard | if (loglevel) {
|
1241 | 58fe2f10 | bellard | fprintf(logfile, "----------------\n");
|
1242 | 42c3c0cc | bellard | fprintf(logfile, "IN: COPY: %s fpu=%d\n",
|
1243 | 42c3c0cc | bellard | lookup_symbol(pc_start), |
1244 | 42c3c0cc | bellard | tb->cflags & CF_TB_FP_USED ? 1 : 0); |
1245 | 58fe2f10 | bellard | disas(logfile, pc_start, dc->pc - pc_start, 0, !dc->code32);
|
1246 | 58fe2f10 | bellard | fprintf(logfile, "\n");
|
1247 | 58fe2f10 | bellard | } |
1248 | 58fe2f10 | bellard | #endif
|
1249 | 58fe2f10 | bellard | |
1250 | 58fe2f10 | bellard | if (!search_pc) {
|
1251 | 58fe2f10 | bellard | *gen_code_size_ptr = dc->gen_code_ptr - dc->gen_code_start; |
1252 | 58fe2f10 | bellard | tb->size = dc->pc - pc_start; |
1253 | 42c3c0cc | bellard | tb->cflags |= CF_CODE_COPY; |
1254 | 58fe2f10 | bellard | return 0; |
1255 | 58fe2f10 | bellard | } else {
|
1256 | 58fe2f10 | bellard | return -1; |
1257 | 58fe2f10 | bellard | } |
1258 | 58fe2f10 | bellard | } |
1259 | 58fe2f10 | bellard | |
1260 | 58fe2f10 | bellard | /* generate code by just copying data. Return -1 if cannot generate
|
1261 | 58fe2f10 | bellard | any code. Return 0 if code was generated */
|
1262 | 58fe2f10 | bellard | int cpu_gen_code_copy(CPUState *env, TranslationBlock *tb,
|
1263 | 58fe2f10 | bellard | int max_code_size, int *gen_code_size_ptr) |
1264 | 58fe2f10 | bellard | { |
1265 | 58fe2f10 | bellard | /* generate machine code */
|
1266 | 58fe2f10 | bellard | tb->tb_next_offset[0] = 0xffff; |
1267 | 58fe2f10 | bellard | tb->tb_next_offset[1] = 0xffff; |
1268 | 58fe2f10 | bellard | #ifdef USE_DIRECT_JUMP
|
1269 | 58fe2f10 | bellard | /* the following two entries are optional (only used for string ops) */
|
1270 | 58fe2f10 | bellard | tb->tb_jmp_offset[2] = 0xffff; |
1271 | 58fe2f10 | bellard | tb->tb_jmp_offset[3] = 0xffff; |
1272 | 58fe2f10 | bellard | #endif
|
1273 | 58fe2f10 | bellard | return gen_intermediate_code_internal(env, tb,
|
1274 | 58fe2f10 | bellard | tb->tc_ptr, gen_code_size_ptr, |
1275 | 58fe2f10 | bellard | 0, NULL); |
1276 | 58fe2f10 | bellard | } |
1277 | 58fe2f10 | bellard | |
1278 | 58fe2f10 | bellard | static uint8_t dummy_gen_code_buf[GEN_CODE_MAX_SIZE];
|
1279 | 58fe2f10 | bellard | |
1280 | 58fe2f10 | bellard | int cpu_restore_state_copy(TranslationBlock *tb,
|
1281 | 58fe2f10 | bellard | CPUState *env, unsigned long searched_pc, |
1282 | 58fe2f10 | bellard | void *puc)
|
1283 | 58fe2f10 | bellard | { |
1284 | 58fe2f10 | bellard | struct ucontext *uc = puc;
|
1285 | 58fe2f10 | bellard | int ret, eflags;
|
1286 | 58fe2f10 | bellard | |
1287 | 58fe2f10 | bellard | /* find opc index corresponding to search_pc */
|
1288 | 58fe2f10 | bellard | if (searched_pc < (unsigned long)tb->tc_ptr) |
1289 | 58fe2f10 | bellard | return -1; |
1290 | 58fe2f10 | bellard | searched_pc = searched_pc - (long)tb->tc_ptr + (long)dummy_gen_code_buf; |
1291 | 58fe2f10 | bellard | ret = gen_intermediate_code_internal(env, tb, |
1292 | 58fe2f10 | bellard | dummy_gen_code_buf, NULL,
|
1293 | 58fe2f10 | bellard | 1, (uint8_t *)searched_pc);
|
1294 | 58fe2f10 | bellard | if (ret < 0) |
1295 | 58fe2f10 | bellard | return ret;
|
1296 | 58fe2f10 | bellard | /* restore all the CPU state from the CPU context from the
|
1297 | 42c3c0cc | bellard | signal. The FPU context stays in the host CPU. */
|
1298 | 58fe2f10 | bellard | |
1299 | 58fe2f10 | bellard | env->regs[R_EAX] = uc->uc_mcontext.gregs[REG_EAX]; |
1300 | 58fe2f10 | bellard | env->regs[R_ECX] = uc->uc_mcontext.gregs[REG_ECX]; |
1301 | 58fe2f10 | bellard | env->regs[R_EDX] = uc->uc_mcontext.gregs[REG_EDX]; |
1302 | 58fe2f10 | bellard | env->regs[R_EBX] = uc->uc_mcontext.gregs[REG_EBX]; |
1303 | 58fe2f10 | bellard | env->regs[R_ESP] = uc->uc_mcontext.gregs[REG_ESP]; |
1304 | 58fe2f10 | bellard | env->regs[R_EBP] = uc->uc_mcontext.gregs[REG_EBP]; |
1305 | 58fe2f10 | bellard | env->regs[R_ESI] = uc->uc_mcontext.gregs[REG_ESI]; |
1306 | 58fe2f10 | bellard | env->regs[R_EDI] = uc->uc_mcontext.gregs[REG_EDI]; |
1307 | 58fe2f10 | bellard | eflags = uc->uc_mcontext.gregs[REG_EFL]; |
1308 | 58fe2f10 | bellard | env->df = 1 - (2 * ((eflags >> 10) & 1)); |
1309 | 58fe2f10 | bellard | env->cc_src = eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
1310 | 58fe2f10 | bellard | env->cc_op = CC_OP_EFLAGS; |
1311 | 58fe2f10 | bellard | return 0; |
1312 | 58fe2f10 | bellard | } |
1313 | 42c3c0cc | bellard | |
1314 | 42c3c0cc | bellard | #endif /* USE_CODE_COPY */ |