Debian Codegraph @

src/cpu/core_full/load.h

raw symbols SCIP
1 switch (inst.code.load) {
2 /* General loading */
3 case L_POPwRM:
4 inst_op1_w = Pop_16();
5 goto case_L_MODRM;
6 case L_POPdRM:
7 inst_op1_d = Pop_32();
8 goto case_L_MODRM;
9 case L_MODRM_NVM:
10 if ((reg_flags & FLAG_VM) || !cpu.pmode) goto illegalopcode;
11 goto case_L_MODRM;
12 case_L_MODRM:
13 case L_MODRM:
14 inst.rm=Fetchb();
15 inst.rm_index=(inst.rm >> 3) & 7;
16 inst.rm_eai=inst.rm&07;
17 inst.rm_mod=inst.rm>>6;
18 /* Decode address of mod/rm if needed */
19 if (inst.rm<0xc0) {
20 if (!(inst.prefix & PREFIX_ADDR))
21 #include "ea_lookup.h"
22 }
23 l_MODRMswitch:
24 switch (inst.code.extra) {
25 /* Byte */
26 case M_Ib:
27 inst_op1_d=Fetchb();
28 break;
29 case M_Ebx:
30 if (inst.rm<0xc0) inst_op1_ds=(Bit8s)LoadMb(inst.rm_eaa);
31 else inst_op1_ds=(Bit8s)reg_8(inst.rm_eai);
32 break;
33 case M_EbIb:
34 inst_op2_d=Fetchb();
35 case M_Eb:
36 if (inst.rm<0xc0) inst_op1_d=LoadMb(inst.rm_eaa);
37 else inst_op1_d=reg_8(inst.rm_eai);
38 break;
39 case M_EbGb:
40 if (inst.rm<0xc0) inst_op1_d=LoadMb(inst.rm_eaa);
41 else inst_op1_d=reg_8(inst.rm_eai);
42 inst_op2_d=reg_8(inst.rm_index);
43 break;
44 case M_GbEb:
45 if (inst.rm<0xc0) inst_op2_d=LoadMb(inst.rm_eaa);
46 else inst_op2_d=reg_8(inst.rm_eai);
47 case M_Gb:
48 inst_op1_d=reg_8(inst.rm_index);;
49 break;
50 /* Word */
51 case M_Iw:
52 inst_op1_d=Fetchw();
53 break;
54 case M_EwxGwx:
55 inst_op2_ds=(Bit16s)reg_16(inst.rm_index);
56 goto l_M_Ewx;
57 case M_EwxIbx:
58 inst_op2_ds=Fetchbs();
59 goto l_M_Ewx;
60 case M_EwxIwx:
61 inst_op2_ds=Fetchws();
62 l_M_Ewx:
63 case M_Ewx:
64 if (inst.rm<0xc0) inst_op1_ds=(Bit16s)LoadMw(inst.rm_eaa);
65 else inst_op1_ds=(Bit16s)reg_16(inst.rm_eai);
66 break;
67 case M_EwIb:
68 inst_op2_d=Fetchb();
69 goto l_M_Ew;
70 case M_EwIbx:
71 inst_op2_ds=Fetchbs();
72 goto l_M_Ew;
73 case M_EwIw:
74 inst_op2_d=Fetchw();
75 goto l_M_Ew;
76 case M_EwGwCL:
77 inst_imm_d=reg_cl;
78 goto l_M_EwGw;
79 case M_EwGwIb:
80 inst_imm_d=Fetchb();
81 goto l_M_EwGw;
82 case M_EwGwt:
83 inst_op2_d=reg_16(inst.rm_index);
84 inst.rm_eaa+=((Bit16s)inst_op2_d >> 4) * 2;
85 goto l_M_Ew;
86 l_M_EwGw:
87 case M_EwGw:
88 inst_op2_d=reg_16(inst.rm_index);
89 l_M_Ew:
90 case M_Ew:
91 if (inst.rm<0xc0) inst_op1_d=LoadMw(inst.rm_eaa);
92 else inst_op1_d=reg_16(inst.rm_eai);
93 break;
94 case M_GwEw:
95 if (inst.rm<0xc0) inst_op2_d=LoadMw(inst.rm_eaa);
96 else inst_op2_d=reg_16(inst.rm_eai);
97 case M_Gw:
98 inst_op1_d=reg_16(inst.rm_index);;
99 break;
100 /* DWord */
101 case M_Id:
102 inst_op1_d=Fetchd();
103 break;
104 case M_EdxGdx:
105 inst_op2_ds=(Bit32s)reg_32(inst.rm_index);
106 case M_Edx:
107 if (inst.rm<0xc0) inst_op1_d=(Bit32s)LoadMd(inst.rm_eaa);
108 else inst_op1_d=(Bit32s)reg_32(inst.rm_eai);
109 break;
110 case M_EdIb:
111 inst_op2_d=Fetchb();
112 goto l_M_Ed;
113 case M_EdIbx:
114 inst_op2_ds=Fetchbs();
115 goto l_M_Ed;
116 case M_EdId:
117 inst_op2_d=Fetchd();
118 goto l_M_Ed;
119 case M_EdGdCL:
120 inst_imm_d=reg_cl;
121 goto l_M_EdGd;
122 case M_EdGdt:
123 inst_op2_d=reg_32(inst.rm_index);
124 inst.rm_eaa+=((Bit32s)inst_op2_d >> 5) * 4;
125 goto l_M_Ed;
126 case M_EdGdIb:
127 inst_imm_d=Fetchb();
128 goto l_M_EdGd;
129 l_M_EdGd:
130 case M_EdGd:
131 inst_op2_d=reg_32(inst.rm_index);
132 l_M_Ed:
133 case M_Ed:
134 if (inst.rm<0xc0) inst_op1_d=LoadMd(inst.rm_eaa);
135 else inst_op1_d=reg_32(inst.rm_eai);
136 break;
137 case M_GdEd:
138 if (inst.rm<0xc0) inst_op2_d=LoadMd(inst.rm_eaa);
139 else inst_op2_d=reg_32(inst.rm_eai);
140 case M_Gd:
141 inst_op1_d=reg_32(inst.rm_index);
142 break;
143 /* Others */
144
145 case M_SEG:
146 //TODO Check for limit
147 inst_op1_d=SegValue((SegNames)inst.rm_index);
148 break;
149 case M_Efw:
150 if (inst.rm>=0xc0) goto illegalopcode;
151 inst_op1_d=LoadMw(inst.rm_eaa);
152 inst_op2_d=LoadMw(inst.rm_eaa+2);
153 break;
154 case M_Efd:
155 if (inst.rm>=0xc0) goto illegalopcode;
156 inst_op1_d=LoadMd(inst.rm_eaa);
157 inst_op2_d=LoadMw(inst.rm_eaa+4);
158 break;
159 case M_EA:
160 inst_op1_d=inst.rm_off;
161 break;
162 case M_POPw:
163 inst_op1_d = Pop_16();
164 break;
165 case M_POPd:
166 inst_op1_d = Pop_32();
167 break;
168 case M_GRP:
169 inst.code=Groups[inst.code.op][inst.rm_index];
170 goto l_MODRMswitch;
171 case M_GRP_Ib:
172 inst_op2_d=Fetchb();
173 inst.code=Groups[inst.code.op][inst.rm_index];
174 goto l_MODRMswitch;
175 case M_GRP_CL:
176 inst_op2_d=reg_cl;
177 inst.code=Groups[inst.code.op][inst.rm_index];
178 goto l_MODRMswitch;
179 case M_GRP_1:
180 inst_op2_d=1;
181 inst.code=Groups[inst.code.op][inst.rm_index];
182 goto l_MODRMswitch;
183 case 0:
184 break;
185 default:
186 LOG(LOG_CPU,LOG_ERROR)("MODRM:Unhandled load %d entry %x",inst.code.extra,inst.entry);
187 break;
188 }
189 break;
190 case L_POPw:
191 inst_op1_d = Pop_16();
192 break;
193 case L_POPd:
194 inst_op1_d = Pop_32();
195 break;
196 case L_POPfw:
197 inst_op1_d = Pop_16();
198 inst_op2_d = Pop_16();
199 break;
200 case L_POPfd:
201 inst_op1_d = Pop_32();
202 inst_op2_d = Pop_16();
203 break;
204 case L_Ib:
205 inst_op1_d=Fetchb();
206 break;
207 case L_Ibx:
208 inst_op1_ds=Fetchbs();
209 break;
210 case L_Iw:
211 inst_op1_d=Fetchw();
212 break;
213 case L_Iwx:
214 inst_op1_ds=Fetchws();
215 break;
216 case L_Idx:
217 case L_Id:
218 inst_op1_d=Fetchd();
219 break;
220 case L_Ifw:
221 inst_op1_d=Fetchw();
222 inst_op2_d=Fetchw();
223 break;
224 case L_Ifd:
225 inst_op1_d=Fetchd();
226 inst_op2_d=Fetchw();
227 break;
228 /* Direct load of registers */
229 case L_REGbIb:
230 inst_op2_d=Fetchb();
231 case L_REGb:
232 inst_op1_d=reg_8(inst.code.extra);
233 break;
234 case L_REGwIw:
235 inst_op2_d=Fetchw();
236 case L_REGw:
237 inst_op1_d=reg_16(inst.code.extra);
238 break;
239 case L_REGdId:
240 inst_op2_d=Fetchd();
241 case L_REGd:
242 inst_op1_d=reg_32(inst.code.extra);
243 break;
244 case L_SEG:
245 inst_op1_d=SegValue((SegNames)inst.code.extra);
246 break;
247 /* Depending on addressize */
248 case L_OP:
249 if (inst.prefix & PREFIX_ADDR) {
250 inst.rm_eaa=Fetchd();
251 } else {
252 inst.rm_eaa=Fetchw();
253 }
254 if (inst.prefix & PREFIX_SEG) {
255 inst.rm_eaa+=inst.seg.base;
256 } else {
257 inst.rm_eaa+=SegBase(ds);
258 }
259 break;
260 /* Special cases */
261 case L_DOUBLE:
262 inst.entry|=0x100;
263 goto restartopcode;
264 case L_PRESEG:
265 inst.prefix|=PREFIX_SEG;
266 inst.seg.base=SegBase((SegNames)inst.code.extra);
267 goto restartopcode;
268 case L_PREREPNE:
269 inst.prefix|=PREFIX_REP;
270 inst.repz=false;
271 goto restartopcode;
272 case L_PREREP:
273 inst.prefix|=PREFIX_REP;
274 inst.repz=true;
275 goto restartopcode;
276 case L_PREOP:
277 inst.entry=(cpu.code.big ^1) * 0x200;
278 goto restartopcode;
279 case L_PREADD:
280 inst.prefix=(inst.prefix & ~1) | (cpu.code.big ^ 1);
281 goto restartopcode;
282 case L_VAL:
283 inst_op1_d=inst.code.extra;
284 break;
285 case L_INTO:
286 if (!get_OF()) goto nextopcode;
287 inst_op1_d=4;
288 break;
289 case D_IRETw:
290 CPU_IRET(false,GetIP());
291 if (GETFLAG(IF) && PIC_IRQCheck) {
292 return CBRET_NONE;
293 }
294 continue;
295 case D_IRETd:
296 CPU_IRET(true,GetIP());
297 if (GETFLAG(IF) && PIC_IRQCheck)
298 return CBRET_NONE;
299 continue;
300 case D_RETFwIw:
301 {
302 Bitu words=Fetchw();
303 FillFlags();
304 CPU_RET(false,words,GetIP());
305 continue;
306 }
307 case D_RETFw:
308 FillFlags();
309 CPU_RET(false,0,GetIP());
310 continue;
311 case D_RETFdIw:
312 {
313 Bitu words=Fetchw();
314 FillFlags();
315 CPU_RET(true,words,GetIP());
316 continue;
317 }
318 case D_RETFd:
319 FillFlags();
320 CPU_RET(true,0,GetIP());
321 continue;
322 /* Direct operations */
323 case L_STRING:
324 #include "string.h"
325 goto nextopcode;
326 case D_PUSHAw:
327 {
328 Bit16u old_sp=reg_sp;
329 Push_16(reg_ax);Push_16(reg_cx);Push_16(reg_dx);Push_16(reg_bx);
330 Push_16(old_sp);Push_16(reg_bp);Push_16(reg_si);Push_16(reg_di);
331 }
332 goto nextopcode;
333 case D_PUSHAd:
334 {
335 Bit32u old_esp=reg_esp;
336 Push_32(reg_eax);Push_32(reg_ecx);Push_32(reg_edx);Push_32(reg_ebx);
337 Push_32(old_esp);Push_32(reg_ebp);Push_32(reg_esi);Push_32(reg_edi);
338 }
339 goto nextopcode;
340 case D_POPAw:
341 reg_di=Pop_16();reg_si=Pop_16();reg_bp=Pop_16();Pop_16();//Don't save SP
342 reg_bx=Pop_16();reg_dx=Pop_16();reg_cx=Pop_16();reg_ax=Pop_16();
343 goto nextopcode;
344 case D_POPAd:
345 reg_edi=Pop_32();reg_esi=Pop_32();reg_ebp=Pop_32();Pop_32();//Don't save ESP
346 reg_ebx=Pop_32();reg_edx=Pop_32();reg_ecx=Pop_32();reg_eax=Pop_32();
347 goto nextopcode;
348 case D_POPSEGw:
349 if (CPU_PopSeg((SegNames)inst.code.extra,false)) RunException();
350 goto nextopcode;
351 case D_POPSEGd:
352 if (CPU_PopSeg((SegNames)inst.code.extra,true)) RunException();
353 goto nextopcode;
354 case D_SETALC:
355 reg_al = get_CF() ? 0xFF : 0;
356 goto nextopcode;
357 case D_XLAT:
358 if (inst.prefix & PREFIX_SEG) {
359 if (inst.prefix & PREFIX_ADDR) {
360 reg_al=LoadMb(inst.seg.base+(Bit32u)(reg_ebx+reg_al));
361 } else {
362 reg_al=LoadMb(inst.seg.base+(Bit16u)(reg_bx+reg_al));
363 }
364 } else {
365 if (inst.prefix & PREFIX_ADDR) {
366 reg_al=LoadMb(SegBase(ds)+(Bit32u)(reg_ebx+reg_al));
367 } else {
368 reg_al=LoadMb(SegBase(ds)+(Bit16u)(reg_bx+reg_al));
369 }
370 }
371 goto nextopcode;
372 case D_CBW:
373 reg_ax=(Bit8s)reg_al;
374 goto nextopcode;
375 case D_CWDE:
376 reg_eax=(Bit16s)reg_ax;
377 goto nextopcode;
378 case D_CWD:
379 if (reg_ax & 0x8000) reg_dx=0xffff;
380 else reg_dx=0;
381 goto nextopcode;
382 case D_CDQ:
383 if (reg_eax & 0x80000000) reg_edx=0xffffffff;
384 else reg_edx=0;
385 goto nextopcode;
386 case D_CLI:
387 if (CPU_CLI()) RunException();
388 goto nextopcode;
389 case D_STI:
390 if (CPU_STI()) RunException();
391 goto nextopcode;
392 case D_STC:
393 FillFlags();SETFLAGBIT(CF,true);
394 goto nextopcode;
395 case D_CLC:
396 FillFlags();SETFLAGBIT(CF,false);
397 goto nextopcode;
398 case D_CMC:
399 FillFlags();
400 SETFLAGBIT(CF,!(reg_flags & FLAG_CF));
401 goto nextopcode;
402 case D_CLD:
403 SETFLAGBIT(DF,false);
404 cpu.direction=1;
405 goto nextopcode;
406 case D_STD:
407 SETFLAGBIT(DF,true);
408 cpu.direction=-1;
409 goto nextopcode;
410 case D_PUSHF:
411 if (CPU_PUSHF(inst.code.extra)) RunException();
412 goto nextopcode;
413 case D_POPF:
414 if (CPU_POPF(inst.code.extra)) RunException();
415 if (GETFLAG(IF) && PIC_IRQCheck) {
416 SaveIP();
417 return CBRET_NONE;
418 }
419 goto nextopcode;
420 case D_SAHF:
421 SETFLAGSb(reg_ah);
422 goto nextopcode;
423 case D_LAHF:
424 FillFlags();
425 reg_ah=reg_flags&0xff;
426 goto nextopcode;
427 case D_WAIT:
428 case D_NOP:
429 goto nextopcode;
430 case D_LOCK: /* FIXME: according to intel, LOCK should raise an exception if it's not followed by one of a small set of instructions;
431 probably doesn't matter for our purposes as it is a pentium prefix anyhow */
432 LOG(LOG_CPU,LOG_NORMAL)("CPU:LOCK");
433 goto nextopcode;
434 case D_ENTERw:
435 {
436 Bitu bytes=Fetchw();
437 Bitu level=Fetchb();
438 CPU_ENTER(false,bytes,level);
439 goto nextopcode;
440 }
441 case D_ENTERd:
442 {
443 Bitu bytes=Fetchw();
444 Bitu level=Fetchb();
445 CPU_ENTER(true,bytes,level);
446 goto nextopcode;
447 }
448 case D_LEAVEw:
449 reg_esp&=cpu.stack.notmask;
450 reg_esp|=(reg_ebp&cpu.stack.mask);
451 reg_bp=Pop_16();
452 goto nextopcode;
453 case D_LEAVEd:
454 reg_esp&=cpu.stack.notmask;
455 reg_esp|=(reg_ebp&cpu.stack.mask);
456 reg_ebp=Pop_32();
457 goto nextopcode;
458 case D_DAA:
459 DAA();
460 goto nextopcode;
461 case D_DAS:
462 DAS();
463 goto nextopcode;
464 case D_AAA:
465 AAA();
466 goto nextopcode;
467 case D_AAS:
468 AAS();
469 goto nextopcode;
470 case D_CPUID:
471 if (!CPU_CPUID()) goto illegalopcode;
472 goto nextopcode;
473 case D_HLT:
474 if (cpu.pmode && cpu.cpl) EXCEPTION(EXCEPTION_GP);
475 FillFlags();
476 CPU_HLT(GetIP());
477 return CBRET_NONE;
478 case D_CLTS:
479 if (cpu.pmode && cpu.cpl) goto illegalopcode;
480 cpu.cr0&=(~CR0_TASKSWITCH);
481 goto nextopcode;
482 case D_ICEBP:
483 CPU_SW_Interrupt_NoIOPLCheck(1,GetIP());
484 continue;
485 default:
486 LOG(LOG_CPU,LOG_ERROR)("LOAD:Unhandled code %d opcode %X",inst.code.load,inst.entry);
487 goto illegalopcode;
488 }
489