Spelling fixes.
[wine.git] / memory / instr.c
blob098d61ae42b100800d7fa546a47520959418d161
1 /*
2 * Emulation of priviledged instructions
4 * Copyright 1995 Alexandre Julliard
5 */
7 #include "windef.h"
8 #include "wingdi.h"
9 #include "wine/winuser16.h"
10 #include "ldt.h"
11 #include "global.h"
12 #include "module.h"
13 #include "dosexe.h"
14 #include "miscemu.h"
15 #include "selectors.h"
16 #include "debugtools.h"
18 DEFAULT_DEBUG_CHANNEL(int);
19 DECLARE_DEBUG_CHANNEL(io);
21 #ifdef __i386__
23 #define IS_SEL_32(context,seg) \
24 (ISV86(context) ? FALSE : IS_SELECTOR_32BIT(seg))
26 #define STACK_reg(context) \
27 (IS_SEL_32(context,SS_reg(context)) ? ESP_reg(context) : (DWORD)LOWORD(ESP_reg(context)))
29 #define ADD_STACK_reg(context,offset) \
30 do { if (IS_SEL_32(context,SS_reg(context))) ESP_reg(context) += (offset); \
31 else ADD_LOWORD(ESP_reg(context),(offset)); } while(0)
33 #define MAKE_PTR(seg,off) \
34 (IS_SELECTOR_SYSTEM(seg) ? (void *)(off) : PTR_SEG_OFF_TO_LIN(seg,off))
36 #define MK_PTR(context,seg,off) \
37 (ISV86(context) ? DOSMEM_MapRealToLinear(MAKELONG(off,seg)) \
38 : MAKE_PTR(seg,off))
40 #define STACK_PTR(context) \
41 (ISV86(context) ? \
42 DOSMEM_MapRealToLinear(MAKELONG(LOWORD(ESP_reg(context)),SS_reg(context))) : \
43 (IS_SELECTOR_SYSTEM(SS_reg(context)) ? (void *)ESP_reg(context) : \
44 (PTR_SEG_OFF_TO_LIN(SS_reg(context),STACK_reg(context)))))
46 /***********************************************************************
47 * INSTR_ReplaceSelector
49 * Try to replace an invalid selector by a valid one.
50 * The only selector where it is allowed to do "mov ax,40;mov es,ax"
51 * is the so called 'bimodal' selector 0x40, which points to the BIOS
52 * data segment. Used by (at least) Borland products (and programs compiled
53 * using Borland products).
55 * See Undocumented Windows, Chapter 5, __0040.
57 static BOOL INSTR_ReplaceSelector( CONTEXT86 *context, WORD *sel )
59 extern char Call16_Start, Call16_End;
61 if (IS_SELECTOR_SYSTEM(CS_reg(context)))
62 if ( (char *)EIP_reg(context) >= &Call16_Start
63 && (char *)EIP_reg(context) < &Call16_End )
65 /* Saved selector may have become invalid when the relay code */
66 /* tries to restore it. We simply clear it. */
67 *sel = 0;
68 return TRUE;
71 if (*sel == 0x40)
73 static WORD sys_timer = 0;
74 if (!sys_timer)
75 sys_timer = CreateSystemTimer( 55, DOSMEM_Tick );
76 *sel = DOSMEM_BiosDataSeg;
77 return TRUE;
79 if (!IS_SELECTOR_SYSTEM(*sel) && !IS_SELECTOR_FREE(*sel))
80 ERR("Got protection fault on valid selector, maybe your kernel is too old?\n" );
81 return FALSE; /* Can't replace selector, crashdump */
85 /***********************************************************************
86 * INSTR_GetOperandAddr
88 * Return the address of an instruction operand (from the mod/rm byte).
90 static BYTE *INSTR_GetOperandAddr( CONTEXT86 *context, BYTE *instr,
91 int long_addr, int segprefix, int *len )
93 int mod, rm, base, index = 0, ss = 0, seg = 0, off;
95 #define GET_VAL(val,type) \
96 { *val = *(type *)instr; instr += sizeof(type); *len += sizeof(type); }
98 *len = 0;
99 GET_VAL( &mod, BYTE );
100 rm = mod & 7;
101 mod >>= 6;
103 if (mod == 3)
105 switch(rm)
107 case 0: return (BYTE *)&EAX_reg(context);
108 case 1: return (BYTE *)&ECX_reg(context);
109 case 2: return (BYTE *)&EDX_reg(context);
110 case 3: return (BYTE *)&EBX_reg(context);
111 case 4: return (BYTE *)&ESP_reg(context);
112 case 5: return (BYTE *)&EBP_reg(context);
113 case 6: return (BYTE *)&ESI_reg(context);
114 case 7: return (BYTE *)&EDI_reg(context);
118 if (long_addr)
120 if (rm == 4)
122 BYTE sib;
123 GET_VAL( &sib, BYTE );
124 rm = sib & 7;
125 ss = sib >> 6;
126 switch(sib >> 3)
128 case 0: index = EAX_reg(context); break;
129 case 1: index = ECX_reg(context); break;
130 case 2: index = EDX_reg(context); break;
131 case 3: index = EBX_reg(context); break;
132 case 4: index = 0; break;
133 case 5: index = EBP_reg(context); break;
134 case 6: index = ESI_reg(context); break;
135 case 7: index = EDI_reg(context); break;
139 switch(rm)
141 case 0: base = EAX_reg(context); seg = DS_reg(context); break;
142 case 1: base = ECX_reg(context); seg = DS_reg(context); break;
143 case 2: base = EDX_reg(context); seg = DS_reg(context); break;
144 case 3: base = EBX_reg(context); seg = DS_reg(context); break;
145 case 4: base = ESP_reg(context); seg = SS_reg(context); break;
146 case 5: base = EBP_reg(context); seg = SS_reg(context); break;
147 case 6: base = ESI_reg(context); seg = DS_reg(context); break;
148 case 7: base = EDI_reg(context); seg = DS_reg(context); break;
150 switch (mod)
152 case 0:
153 if (rm == 5) /* special case: ds:(disp32) */
155 GET_VAL( &base, DWORD );
156 seg = DS_reg(context);
158 break;
160 case 1: /* 8-bit disp */
161 GET_VAL( &off, BYTE );
162 base += (signed char)off;
163 break;
165 case 2: /* 32-bit disp */
166 GET_VAL( &off, DWORD );
167 base += (signed long)off;
168 break;
171 else /* short address */
173 switch(rm)
175 case 0: /* ds:(bx,si) */
176 base = LOWORD(EBX_reg(context)) + LOWORD(ESI_reg(context));
177 seg = DS_reg(context);
178 break;
179 case 1: /* ds:(bx,di) */
180 base = LOWORD(EBX_reg(context)) + LOWORD(EDI_reg(context));
181 seg = DS_reg(context);
182 break;
183 case 2: /* ss:(bp,si) */
184 base = LOWORD(EBP_reg(context)) + LOWORD(ESI_reg(context));
185 seg = SS_reg(context);
186 break;
187 case 3: /* ss:(bp,di) */
188 base = LOWORD(EBP_reg(context)) + LOWORD(EDI_reg(context));
189 seg = SS_reg(context);
190 break;
191 case 4: /* ds:(si) */
192 base = LOWORD(ESI_reg(context));
193 seg = DS_reg(context);
194 break;
195 case 5: /* ds:(di) */
196 base = LOWORD(EDI_reg(context));
197 seg = DS_reg(context);
198 break;
199 case 6: /* ss:(bp) */
200 base = LOWORD(EBP_reg(context));
201 seg = SS_reg(context);
202 break;
203 case 7: /* ds:(bx) */
204 base = LOWORD(EBX_reg(context));
205 seg = DS_reg(context);
206 break;
209 switch(mod)
211 case 0:
212 if (rm == 6) /* special case: ds:(disp16) */
214 GET_VAL( &base, WORD );
215 seg = DS_reg(context);
217 break;
219 case 1: /* 8-bit disp */
220 GET_VAL( &off, BYTE );
221 base += (signed char)off;
222 break;
224 case 2: /* 16-bit disp */
225 GET_VAL( &off, WORD );
226 base += (signed short)off;
227 break;
229 base &= 0xffff;
231 if (segprefix != -1) seg = segprefix;
233 /* Make sure the segment and offset are valid */
234 if (IS_SELECTOR_SYSTEM(seg)) return (BYTE *)(base + (index << ss));
235 if (((seg & 7) != 7) || IS_SELECTOR_FREE(seg)) return NULL;
236 if (GET_SEL_LIMIT(seg) < (base + (index << ss))) return NULL;
237 return (BYTE *)PTR_SEG_OFF_TO_LIN( seg, (base + (index << ss)) );
238 #undef GET_VAL
242 /***********************************************************************
243 * INSTR_EmulateLDS
245 * Emulate the LDS (and LES,LFS,etc.) instruction.
247 static BOOL INSTR_EmulateLDS( CONTEXT86 *context, BYTE *instr, int long_op,
248 int long_addr, int segprefix, int *len )
250 WORD seg;
251 BYTE *regmodrm = instr + 1 + (*instr == 0x0f);
252 BYTE *addr = INSTR_GetOperandAddr( context, regmodrm,
253 long_addr, segprefix, len );
254 if (!addr)
255 return FALSE; /* Unable to emulate it */
256 seg = *(WORD *)(addr + (long_op ? 4 : 2));
258 if (!INSTR_ReplaceSelector( context, &seg ))
259 return FALSE; /* Unable to emulate it */
261 /* Now store the offset in the correct register */
263 switch((*regmodrm >> 3) & 7)
265 case 0:
266 if (long_op) EAX_reg(context) = *(DWORD *)addr;
267 else SET_LOWORD(EAX_reg(context),*(WORD *)addr);
268 break;
269 case 1:
270 if (long_op) ECX_reg(context) = *(DWORD *)addr;
271 else SET_LOWORD(ECX_reg(context),*(WORD *)addr);
272 break;
273 case 2:
274 if (long_op) EDX_reg(context) = *(DWORD *)addr;
275 else SET_LOWORD(EDX_reg(context),*(WORD *)addr);
276 break;
277 case 3:
278 if (long_op) EBX_reg(context) = *(DWORD *)addr;
279 else SET_LOWORD(EBX_reg(context),*(WORD *)addr);
280 break;
281 case 4:
282 if (long_op) ESP_reg(context) = *(DWORD *)addr;
283 else SET_LOWORD(ESP_reg(context),*(WORD *)addr);
284 break;
285 case 5:
286 if (long_op) EBP_reg(context) = *(DWORD *)addr;
287 else SET_LOWORD(EBP_reg(context),*(WORD *)addr);
288 break;
289 case 6:
290 if (long_op) ESI_reg(context) = *(DWORD *)addr;
291 else SET_LOWORD(ESI_reg(context),*(WORD *)addr);
292 break;
293 case 7:
294 if (long_op) EDI_reg(context) = *(DWORD *)addr;
295 else SET_LOWORD(EDI_reg(context),*(WORD *)addr);
296 break;
299 /* Store the correct segment in the segment register */
301 switch(*instr)
303 case 0xc4: ES_reg(context) = seg; break; /* les */
304 case 0xc5: DS_reg(context) = seg; break; /* lds */
305 case 0x0f: switch(instr[1])
307 case 0xb2: SS_reg(context) = seg; break; /* lss */
308 case 0xb4: FS_reg(context) = seg; break; /* lfs */
309 case 0xb5: GS_reg(context) = seg; break; /* lgs */
311 break;
314 /* Add the opcode size to the total length */
316 *len += 1 + (*instr == 0x0f);
317 return TRUE;
320 /***********************************************************************
321 * INSTR_inport
323 * input on a I/O port
325 static DWORD INSTR_inport( WORD port, int size, CONTEXT86 *context )
327 DWORD res = IO_inport( port, size );
328 if (TRACE_ON(io))
330 switch(size)
332 case 1:
333 DPRINTF( "0x%x < %02x @ %04x:%04x\n", port, LOBYTE(res),
334 (WORD)CS_reg(context), LOWORD(EIP_reg(context)));
335 break;
336 case 2:
337 DPRINTF( "0x%x < %04x @ %04x:%04x\n", port, LOWORD(res),
338 (WORD)CS_reg(context), LOWORD(EIP_reg(context)));
339 break;
340 case 4:
341 DPRINTF( "0x%x < %08lx @ %04x:%04x\n", port, res,
342 (WORD)CS_reg(context), LOWORD(EIP_reg(context)));
343 break;
346 return res;
350 /***********************************************************************
351 * INSTR_outport
353 * output on a I/O port
355 static void INSTR_outport( WORD port, int size, DWORD val, CONTEXT86 *context )
357 IO_outport( port, size, val );
358 if (TRACE_ON(io))
360 switch(size)
362 case 1:
363 DPRINTF("0x%x > %02x @ %04x:%04x\n", port, LOBYTE(val),
364 (WORD)CS_reg(context), LOWORD(EIP_reg(context)));
365 break;
366 case 2:
367 DPRINTF("0x%x > %04x @ %04x:%04x\n", port, LOWORD(val),
368 (WORD)CS_reg(context), LOWORD(EIP_reg(context)));
369 break;
370 case 4:
371 DPRINTF("0x%x > %08lx @ %04x:%04x\n", port, val,
372 (WORD)CS_reg(context), LOWORD(EIP_reg(context)));
373 break;
379 /***********************************************************************
380 * INSTR_EmulateInstruction
382 * Emulate a priviledged instruction. Returns TRUE if emulation successful.
384 BOOL INSTR_EmulateInstruction( CONTEXT86 *context )
386 int prefix, segprefix, prefixlen, len, repX, long_op, long_addr;
387 SEGPTR gpHandler;
388 BYTE *instr;
390 long_op = long_addr = IS_SEL_32(context,CS_reg(context));
391 instr = (BYTE *)MK_PTR(context,CS_reg(context),EIP_reg(context));
392 if (!instr) return FALSE;
394 /* First handle any possible prefix */
396 segprefix = -1; /* no prefix */
397 prefix = 1;
398 repX = 0;
399 prefixlen = 0;
400 while(prefix)
402 switch(*instr)
404 case 0x2e:
405 segprefix = CS_reg(context);
406 break;
407 case 0x36:
408 segprefix = SS_reg(context);
409 break;
410 case 0x3e:
411 segprefix = DS_reg(context);
412 break;
413 case 0x26:
414 segprefix = ES_reg(context);
415 break;
416 case 0x64:
417 segprefix = FS_reg(context);
418 break;
419 case 0x65:
420 segprefix = GS_reg(context);
421 break;
422 case 0x66:
423 long_op = !long_op; /* opcode size prefix */
424 break;
425 case 0x67:
426 long_addr = !long_addr; /* addr size prefix */
427 break;
428 case 0xf0: /* lock */
429 break;
430 case 0xf2: /* repne */
431 repX = 1;
432 break;
433 case 0xf3: /* repe */
434 repX = 2;
435 break;
436 default:
437 prefix = 0; /* no more prefixes */
438 break;
440 if (prefix)
442 instr++;
443 prefixlen++;
447 /* Now look at the actual instruction */
449 switch(*instr)
451 case 0x07: /* pop es */
452 case 0x17: /* pop ss */
453 case 0x1f: /* pop ds */
455 WORD seg = *(WORD *)STACK_PTR( context );
456 if (INSTR_ReplaceSelector( context, &seg ))
458 switch(*instr)
460 case 0x07: ES_reg(context) = seg; break;
461 case 0x17: SS_reg(context) = seg; break;
462 case 0x1f: DS_reg(context) = seg; break;
464 ADD_STACK_reg(context, long_op ? 4 : 2);
465 EIP_reg(context) += prefixlen + 1;
466 return TRUE;
469 break; /* Unable to emulate it */
471 case 0x0f: /* extended instruction */
472 switch(instr[1])
474 case 0x22: /* mov eax, crX */
475 switch (instr[2]) {
476 case 0xc0:
477 ERR("mov eax,cr0 at 0x%08lx, EAX=0x%08lx\n",
478 EIP_reg(context),EAX_reg(context) );
479 EIP_reg(context) += prefixlen+3;
480 return TRUE;
481 default:
482 break; /*fallthrough to bad instruction handling */
484 break; /*fallthrough to bad instruction handling */
485 case 0x20: /* mov crX, eax */
486 switch (instr[2]) {
487 case 0xe0: /* mov cr4, eax */
488 /* CR4 register . See linux/arch/i386/mm/init.c, X86_CR4_ defs
489 * bit 0: VME Virtual Mode Exception ?
490 * bit 1: PVI Protected mode Virtual Interrupt
491 * bit 2: TSD Timestamp disable
492 * bit 3: DE Debugging extensions
493 * bit 4: PSE Page size extensions
494 * bit 5: PAE Physical address extension
495 * bit 6: MCE Machine check enable
496 * bit 7: PGE Enable global pages
497 * bit 8: PCE Enable performance counters at IPL3
499 ERR("mov cr4,eax at 0x%08lx\n",EIP_reg(context));
500 EAX_reg(context) = 0;
501 EIP_reg(context) += prefixlen+3;
502 return TRUE;
503 case 0xc0: /* mov cr0, eax */
504 ERR("mov cr0,eax at 0x%08lx\n",EIP_reg(context));
505 EAX_reg(context) = 0x10; /* FIXME: set more bits ? */
506 EIP_reg(context) += prefixlen+3;
507 return TRUE;
508 default: /* fallthrough to illegal instruction */
509 break;
511 /* fallthrough to illegal instruction */
512 break;
513 case 0xa1: /* pop fs */
515 WORD seg = *(WORD *)STACK_PTR( context );
516 if (INSTR_ReplaceSelector( context, &seg ))
518 FS_reg(context) = seg;
519 ADD_STACK_reg(context, long_op ? 4 : 2);
520 EIP_reg(context) += prefixlen + 2;
521 return TRUE;
524 break;
525 case 0xa9: /* pop gs */
527 WORD seg = *(WORD *)STACK_PTR( context );
528 if (INSTR_ReplaceSelector( context, &seg ))
530 GS_reg(context) = seg;
531 ADD_STACK_reg(context, long_op ? 4 : 2);
532 EIP_reg(context) += prefixlen + 2;
533 return TRUE;
536 break;
537 case 0xb2: /* lss addr,reg */
538 case 0xb4: /* lfs addr,reg */
539 case 0xb5: /* lgs addr,reg */
540 if (INSTR_EmulateLDS( context, instr, long_op,
541 long_addr, segprefix, &len ))
543 EIP_reg(context) += prefixlen + len;
544 return TRUE;
546 break;
548 break; /* Unable to emulate it */
550 case 0x6c: /* insb */
551 case 0x6d: /* insw/d */
552 case 0x6e: /* outsb */
553 case 0x6f: /* outsw/d */
555 int typ = *instr; /* Just in case it's overwritten. */
556 int outp = (typ >= 0x6e);
557 unsigned long count = repX ?
558 (long_addr ? ECX_reg(context) : LOWORD(ECX_reg(context))) : 1;
559 int opsize = (typ & 1) ? (long_op ? 4 : 2) : 1;
560 int step = (EFL_reg(context) & 0x400) ? -opsize : +opsize;
561 int seg = outp ? DS_reg(context) : ES_reg(context); /* FIXME: is this right? */
563 if (outp)
564 /* FIXME: Check segment readable. */
565 (void)0;
566 else
567 /* FIXME: Check segment writeable. */
568 (void)0;
570 if (repX)
572 if (long_addr) ECX_reg(context) = 0;
573 else SET_LOWORD(ECX_reg(context),0);
576 while (count-- > 0)
578 void *data;
579 WORD dx = LOWORD(EDX_reg(context));
580 if (outp)
582 data = MK_PTR(context, seg,
583 long_addr ? ESI_reg(context) : LOWORD(ESI_reg(context)));
584 if (long_addr) ESI_reg(context) += step;
585 else ADD_LOWORD(ESI_reg(context),step);
587 else
589 data = MK_PTR(context, seg,
590 long_addr ? EDI_reg(context) : LOWORD(EDI_reg(context)));
591 if (long_addr) EDI_reg(context) += step;
592 else ADD_LOWORD(EDI_reg(context),step);
595 switch (typ)
597 case 0x6c:
598 *(BYTE *)data = INSTR_inport( dx, 1, context );
599 break;
600 case 0x6d:
601 if (long_op)
602 *(DWORD *)data = INSTR_inport( dx, 4, context );
603 else
604 *(WORD *)data = INSTR_inport( dx, 2, context );
605 break;
606 case 0x6e:
607 INSTR_outport( dx, 1, *(BYTE *)data, context );
608 break;
609 case 0x6f:
610 if (long_op)
611 INSTR_outport( dx, 4, *(DWORD *)data, context );
612 else
613 INSTR_outport( dx, 2, *(WORD *)data, context );
614 break;
617 EIP_reg(context) += prefixlen + 1;
619 return TRUE;
621 case 0x8e: /* mov XX,segment_reg */
623 WORD seg;
624 BYTE *addr = INSTR_GetOperandAddr(context, instr + 1,
625 long_addr, segprefix, &len );
626 if (!addr)
627 break; /* Unable to emulate it */
628 seg = *(WORD *)addr;
629 if (!INSTR_ReplaceSelector( context, &seg ))
630 break; /* Unable to emulate it */
632 switch((instr[1] >> 3) & 7)
634 case 0:
635 ES_reg(context) = seg;
636 EIP_reg(context) += prefixlen + len + 1;
637 return TRUE;
638 case 1: /* cs */
639 break;
640 case 2:
641 SS_reg(context) = seg;
642 EIP_reg(context) += prefixlen + len + 1;
643 return TRUE;
644 case 3:
645 DS_reg(context) = seg;
646 EIP_reg(context) += prefixlen + len + 1;
647 return TRUE;
648 case 4:
649 FS_reg(context) = seg;
650 EIP_reg(context) += prefixlen + len + 1;
651 return TRUE;
652 case 5:
653 GS_reg(context) = seg;
654 EIP_reg(context) += prefixlen + len + 1;
655 return TRUE;
656 case 6: /* unused */
657 case 7: /* unused */
658 break;
661 break; /* Unable to emulate it */
663 case 0xc4: /* les addr,reg */
664 case 0xc5: /* lds addr,reg */
665 if (INSTR_EmulateLDS( context, instr, long_op,
666 long_addr, segprefix, &len ))
668 EIP_reg(context) += prefixlen + len;
669 return TRUE;
671 break; /* Unable to emulate it */
673 case 0xcd: /* int <XX> */
674 if (long_op)
676 ERR("int xx from 32-bit code is not supported.\n");
677 break; /* Unable to emulate it */
679 else
681 FARPROC16 addr = INT_GetPMHandler( instr[1] );
682 WORD *stack = (WORD *)STACK_PTR( context );
683 if (!addr)
685 FIXME("no handler for interrupt %02x, ignoring it\n", instr[1]);
686 EIP_reg(context) += prefixlen + 2;
687 return TRUE;
689 /* Push the flags and return address on the stack */
690 *(--stack) = LOWORD(EFL_reg(context));
691 *(--stack) = CS_reg(context);
692 *(--stack) = LOWORD(EIP_reg(context)) + prefixlen + 2;
693 ADD_STACK_reg(context, -3 * sizeof(WORD));
694 /* Jump to the interrupt handler */
695 CS_reg(context) = HIWORD(addr);
696 EIP_reg(context) = LOWORD(addr);
698 return TRUE;
700 case 0xcf: /* iret */
701 if (long_op)
703 DWORD *stack = (DWORD *)STACK_PTR( context );
704 EIP_reg(context) = *stack++;
705 CS_reg(context) = *stack++;
706 EFL_reg(context) = *stack;
707 ADD_STACK_reg(context, 3*sizeof(DWORD)); /* Pop the return address and flags */
709 else
711 WORD *stack = (WORD *)STACK_PTR( context );
712 EIP_reg(context) = *stack++;
713 CS_reg(context) = *stack++;
714 SET_LOWORD(EFL_reg(context),*stack);
715 ADD_STACK_reg(context, 3*sizeof(WORD)); /* Pop the return address and flags */
717 return TRUE;
719 case 0xe4: /* inb al,XX */
720 SET_LOBYTE(EAX_reg(context),INSTR_inport( instr[1], 1, context ));
721 EIP_reg(context) += prefixlen + 2;
722 return TRUE;
724 case 0xe5: /* in (e)ax,XX */
725 if (long_op)
726 EAX_reg(context) = INSTR_inport( instr[1], 4, context );
727 else
728 SET_LOWORD(EAX_reg(context), INSTR_inport( instr[1], 2, context ));
729 EIP_reg(context) += prefixlen + 2;
730 return TRUE;
732 case 0xe6: /* outb XX,al */
733 INSTR_outport( instr[1], 1, LOBYTE(EAX_reg(context)), context );
734 EIP_reg(context) += prefixlen + 2;
735 return TRUE;
737 case 0xe7: /* out XX,(e)ax */
738 if (long_op)
739 INSTR_outport( instr[1], 4, EAX_reg(context), context );
740 else
741 INSTR_outport( instr[1], 2, LOWORD(EAX_reg(context)), context );
742 EIP_reg(context) += prefixlen + 2;
743 return TRUE;
745 case 0xec: /* inb al,dx */
746 SET_LOBYTE(EAX_reg(context), INSTR_inport( LOWORD(EDX_reg(context)), 1, context ) );
747 EIP_reg(context) += prefixlen + 1;
748 return TRUE;
750 case 0xed: /* in (e)ax,dx */
751 if (long_op)
752 EAX_reg(context) = INSTR_inport( LOWORD(EDX_reg(context)), 4, context );
753 else
754 SET_LOWORD(EAX_reg(context), INSTR_inport( LOWORD(EDX_reg(context)), 2, context ));
755 EIP_reg(context) += prefixlen + 1;
756 return TRUE;
758 case 0xee: /* outb dx,al */
759 INSTR_outport( LOWORD(EDX_reg(context)), 1, LOBYTE(EAX_reg(context)), context );
760 EIP_reg(context) += prefixlen + 1;
761 return TRUE;
763 case 0xef: /* out dx,(e)ax */
764 if (long_op)
765 INSTR_outport( LOWORD(EDX_reg(context)), 4, EAX_reg(context), context );
766 else
767 INSTR_outport( LOWORD(EDX_reg(context)), 2, LOWORD(EAX_reg(context)), context );
768 EIP_reg(context) += prefixlen + 1;
769 return TRUE;
771 case 0xfa: /* cli, ignored */
772 EIP_reg(context) += prefixlen + 1;
773 return TRUE;
775 case 0xfb: /* sti, ignored */
776 EIP_reg(context) += prefixlen + 1;
777 return TRUE;
781 /* Check for Win16 __GP handler */
782 gpHandler = HasGPHandler16( PTR_SEG_OFF_TO_SEGPTR( CS_reg(context),
783 EIP_reg(context) ) );
784 if (gpHandler)
786 WORD *stack = (WORD *)STACK_PTR( context );
787 *--stack = CS_reg(context);
788 *--stack = EIP_reg(context);
789 ADD_STACK_reg(context, -2*sizeof(WORD));
791 CS_reg(context) = SELECTOROF( gpHandler );
792 EIP_reg(context) = OFFSETOF( gpHandler );
793 return TRUE;
795 return FALSE; /* Unable to emulate it */
798 #endif /* __i386__ */