2 * Emulation of privileged instructions
4 * Copyright 1995 Alexandre Julliard
5 * Copyright 2005 Ivan Leo Puoti
6 * Copyright 2005 Laurent Pinchart
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/port.h"
31 #include "wine/winuser16.h"
34 #include "wine/debug.h"
35 #include "kernel_private.h"
36 #include "kernel16_private.h"
37 #include "wine/exception.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(int);
40 WINE_DECLARE_DEBUG_CHANNEL(io
);
42 /* macros to set parts of a DWORD */
43 #define SET_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD(val))
44 #define SET_LOBYTE(dw,val) ((dw) = ((dw) & 0xffffff00) | LOBYTE(val))
45 #define ADD_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
46 #define ISV86(context) ((context)->EFlags & 0x00020000)
48 inline static void add_stack( CONTEXT86
*context
, int offset
)
50 if (ISV86(context
) || !IS_SELECTOR_32BIT(context
->SegSs
))
51 ADD_LOWORD( context
->Esp
, offset
);
53 context
->Esp
+= offset
;
56 inline static void *make_ptr( CONTEXT86
*context
, DWORD seg
, DWORD off
, int long_addr
)
58 if (ISV86(context
)) return (void *)((seg
<< 4) + LOWORD(off
));
59 if (wine_ldt_is_system(seg
)) return (void *)off
;
60 if (!long_addr
) off
= LOWORD(off
);
61 return (char *) MapSL( MAKESEGPTR( seg
, 0 ) ) + off
;
64 inline static void *get_stack( CONTEXT86
*context
)
66 if (ISV86(context
)) return (void *)((context
->SegSs
<< 4) + LOWORD(context
->Esp
));
67 return wine_ldt_get_ptr( context
->SegSs
, context
->Esp
);
78 static LDT_ENTRY idt
[256];
80 inline static struct idtr
get_idtr(void)
83 #if defined(__i386__) && defined(__GNUC__)
84 __asm__( "sidtl %0" : "=m" (ret
) );
86 ret
.base
= (BYTE
*)idt
;
87 ret
.limit
= sizeof(idt
) - 1;
93 /***********************************************************************
94 * INSTR_ReplaceSelector
96 * Try to replace an invalid selector by a valid one.
97 * The only selector where it is allowed to do "mov ax,40;mov es,ax"
98 * is the so called 'bimodal' selector 0x40, which points to the BIOS
99 * data segment. Used by (at least) Borland products (and programs compiled
100 * using Borland products).
102 * See Undocumented Windows, Chapter 5, __0040.
104 static BOOL
INSTR_ReplaceSelector( CONTEXT86
*context
, WORD
*sel
)
108 static WORD sys_timer
= 0;
111 if (!winedos
.BiosTick
) load_winedos();
112 if (winedos
.BiosTick
)
113 sys_timer
= CreateSystemTimer( 55, winedos
.BiosTick
);
115 *sel
= DOSMEM_BiosDataSeg
;
118 return FALSE
; /* Can't replace selector, crashdump */
122 /* store an operand into a register */
123 static void store_reg( CONTEXT86
*context
, BYTE regmodrm
, const BYTE
*addr
, int long_op
)
125 switch((regmodrm
>> 3) & 7)
128 if (long_op
) context
->Eax
= *(DWORD
*)addr
;
129 else SET_LOWORD(context
->Eax
,*(WORD
*)addr
);
132 if (long_op
) context
->Ecx
= *(DWORD
*)addr
;
133 else SET_LOWORD(context
->Ecx
,*(WORD
*)addr
);
136 if (long_op
) context
->Edx
= *(DWORD
*)addr
;
137 else SET_LOWORD(context
->Edx
,*(WORD
*)addr
);
140 if (long_op
) context
->Ebx
= *(DWORD
*)addr
;
141 else SET_LOWORD(context
->Ebx
,*(WORD
*)addr
);
144 if (long_op
) context
->Esp
= *(DWORD
*)addr
;
145 else SET_LOWORD(context
->Esp
,*(WORD
*)addr
);
148 if (long_op
) context
->Ebp
= *(DWORD
*)addr
;
149 else SET_LOWORD(context
->Ebp
,*(WORD
*)addr
);
152 if (long_op
) context
->Esi
= *(DWORD
*)addr
;
153 else SET_LOWORD(context
->Esi
,*(WORD
*)addr
);
156 if (long_op
) context
->Edi
= *(DWORD
*)addr
;
157 else SET_LOWORD(context
->Edi
,*(WORD
*)addr
);
162 /***********************************************************************
163 * INSTR_GetOperandAddr
165 * Return the address of an instruction operand (from the mod/rm byte).
167 static BYTE
*INSTR_GetOperandAddr( CONTEXT86
*context
, BYTE
*instr
,
168 int long_addr
, int segprefix
, int *len
)
170 int mod
, rm
, base
= 0, index
= 0, ss
= 0, seg
= 0, off
;
173 #define GET_VAL(val,type) \
174 { *val = *(type *)instr; instr += sizeof(type); *len += sizeof(type); }
177 GET_VAL( &mod
, BYTE
);
185 case 0: return (BYTE
*)&context
->Eax
;
186 case 1: return (BYTE
*)&context
->Ecx
;
187 case 2: return (BYTE
*)&context
->Edx
;
188 case 3: return (BYTE
*)&context
->Ebx
;
189 case 4: return (BYTE
*)&context
->Esp
;
190 case 5: return (BYTE
*)&context
->Ebp
;
191 case 6: return (BYTE
*)&context
->Esi
;
192 case 7: return (BYTE
*)&context
->Edi
;
201 GET_VAL( &sib
, BYTE
);
206 case 0: index
= context
->Eax
; break;
207 case 1: index
= context
->Ecx
; break;
208 case 2: index
= context
->Edx
; break;
209 case 3: index
= context
->Ebx
; break;
210 case 4: index
= 0; break;
211 case 5: index
= context
->Ebp
; break;
212 case 6: index
= context
->Esi
; break;
213 case 7: index
= context
->Edi
; break;
219 case 0: base
= context
->Eax
; seg
= context
->SegDs
; break;
220 case 1: base
= context
->Ecx
; seg
= context
->SegDs
; break;
221 case 2: base
= context
->Edx
; seg
= context
->SegDs
; break;
222 case 3: base
= context
->Ebx
; seg
= context
->SegDs
; break;
223 case 4: base
= context
->Esp
; seg
= context
->SegSs
; break;
224 case 5: base
= context
->Ebp
; seg
= context
->SegSs
; break;
225 case 6: base
= context
->Esi
; seg
= context
->SegDs
; break;
226 case 7: base
= context
->Edi
; seg
= context
->SegDs
; break;
231 if (rm
== 5) /* special case: ds:(disp32) */
233 GET_VAL( &base
, DWORD
);
234 seg
= context
->SegDs
;
238 case 1: /* 8-bit disp */
239 GET_VAL( &off
, BYTE
);
240 base
+= (signed char)off
;
243 case 2: /* 32-bit disp */
244 GET_VAL( &off
, DWORD
);
245 base
+= (signed long)off
;
249 else /* short address */
253 case 0: /* ds:(bx,si) */
254 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Esi
);
255 seg
= context
->SegDs
;
257 case 1: /* ds:(bx,di) */
258 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Edi
);
259 seg
= context
->SegDs
;
261 case 2: /* ss:(bp,si) */
262 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Esi
);
263 seg
= context
->SegSs
;
265 case 3: /* ss:(bp,di) */
266 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Edi
);
267 seg
= context
->SegSs
;
269 case 4: /* ds:(si) */
270 base
= LOWORD(context
->Esi
);
271 seg
= context
->SegDs
;
273 case 5: /* ds:(di) */
274 base
= LOWORD(context
->Edi
);
275 seg
= context
->SegDs
;
277 case 6: /* ss:(bp) */
278 base
= LOWORD(context
->Ebp
);
279 seg
= context
->SegSs
;
281 case 7: /* ds:(bx) */
282 base
= LOWORD(context
->Ebx
);
283 seg
= context
->SegDs
;
290 if (rm
== 6) /* special case: ds:(disp16) */
292 GET_VAL( &base
, WORD
);
293 seg
= context
->SegDs
;
297 case 1: /* 8-bit disp */
298 GET_VAL( &off
, BYTE
);
299 base
+= (signed char)off
;
302 case 2: /* 16-bit disp */
303 GET_VAL( &off
, WORD
);
304 base
+= (signed short)off
;
309 if (segprefix
!= -1) seg
= segprefix
;
311 /* Make sure the segment and offset are valid */
312 if (wine_ldt_is_system(seg
)) return (BYTE
*)(base
+ (index
<< ss
));
313 if ((seg
& 7) != 7) return NULL
;
314 wine_ldt_get_entry( seg
, &entry
);
315 if (wine_ldt_is_empty( &entry
)) return NULL
;
316 if (wine_ldt_get_limit(&entry
) < (base
+ (index
<< ss
))) return NULL
;
317 return (BYTE
*)wine_ldt_get_base(&entry
) + base
+ (index
<< ss
);
322 /***********************************************************************
325 * Emulate the LDS (and LES,LFS,etc.) instruction.
327 static BOOL
INSTR_EmulateLDS( CONTEXT86
*context
, BYTE
*instr
, int long_op
,
328 int long_addr
, int segprefix
, int *len
)
331 BYTE
*regmodrm
= instr
+ 1 + (*instr
== 0x0f);
332 BYTE
*addr
= INSTR_GetOperandAddr( context
, regmodrm
,
333 long_addr
, segprefix
, len
);
335 return FALSE
; /* Unable to emulate it */
336 seg
= *(WORD
*)(addr
+ (long_op
? 4 : 2));
338 if (!INSTR_ReplaceSelector( context
, &seg
))
339 return FALSE
; /* Unable to emulate it */
341 /* Now store the offset in the correct register */
343 store_reg( context
, *regmodrm
, addr
, long_op
);
345 /* Store the correct segment in the segment register */
349 case 0xc4: context
->SegEs
= seg
; break; /* les */
350 case 0xc5: context
->SegDs
= seg
; break; /* lds */
351 case 0x0f: switch(instr
[1])
353 case 0xb2: context
->SegSs
= seg
; break; /* lss */
354 case 0xb4: context
->SegFs
= seg
; break; /* lfs */
355 case 0xb5: context
->SegGs
= seg
; break; /* lgs */
360 /* Add the opcode size to the total length */
362 *len
+= 1 + (*instr
== 0x0f);
366 /***********************************************************************
369 * input on an I/O port
371 static DWORD
INSTR_inport( WORD port
, int size
, CONTEXT86
*context
)
375 if (!winedos
.inport
) load_winedos();
376 if (winedos
.inport
) res
= winedos
.inport( port
, size
);
383 TRACE_(io
)( "0x%x < %02x @ %04x:%04x\n", port
, LOBYTE(res
),
384 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
387 TRACE_(io
)( "0x%x < %04x @ %04x:%04x\n", port
, LOWORD(res
),
388 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
391 TRACE_(io
)( "0x%x < %08lx @ %04x:%04x\n", port
, res
,
392 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
400 /***********************************************************************
403 * output on an I/O port
405 static void INSTR_outport( WORD port
, int size
, DWORD val
, CONTEXT86
*context
)
407 if (!winedos
.outport
) load_winedos();
408 if (winedos
.outport
) winedos
.outport( port
, size
, val
);
415 TRACE_(io
)("0x%x > %02x @ %04x:%04x\n", port
, LOBYTE(val
),
416 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
419 TRACE_(io
)("0x%x > %04x @ %04x:%04x\n", port
, LOWORD(val
),
420 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
423 TRACE_(io
)("0x%x > %08lx @ %04x:%04x\n", port
, val
,
424 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
431 /***********************************************************************
432 * INSTR_EmulateInstruction
434 * Emulate a privileged instruction.
435 * Returns exception continuation status.
437 DWORD
INSTR_EmulateInstruction( EXCEPTION_RECORD
*rec
, CONTEXT86
*context
)
439 int prefix
, segprefix
, prefixlen
, len
, repX
, long_op
, long_addr
;
442 long_op
= long_addr
= (!ISV86(context
) && IS_SELECTOR_32BIT(context
->SegCs
));
443 instr
= make_ptr( context
, context
->SegCs
, context
->Eip
, TRUE
);
444 if (!instr
) return ExceptionContinueSearch
;
446 /* First handle any possible prefix */
448 segprefix
= -1; /* no prefix */
457 segprefix
= context
->SegCs
;
460 segprefix
= context
->SegSs
;
463 segprefix
= context
->SegDs
;
466 segprefix
= context
->SegEs
;
469 segprefix
= context
->SegFs
;
472 segprefix
= context
->SegGs
;
475 long_op
= !long_op
; /* opcode size prefix */
478 long_addr
= !long_addr
; /* addr size prefix */
480 case 0xf0: /* lock */
482 case 0xf2: /* repne */
485 case 0xf3: /* repe */
489 prefix
= 0; /* no more prefixes */
499 /* Now look at the actual instruction */
503 case 0x07: /* pop es */
504 case 0x17: /* pop ss */
505 case 0x1f: /* pop ds */
507 WORD seg
= *(WORD
*)get_stack( context
);
508 if (INSTR_ReplaceSelector( context
, &seg
))
512 case 0x07: context
->SegEs
= seg
; break;
513 case 0x17: context
->SegSs
= seg
; break;
514 case 0x1f: context
->SegDs
= seg
; break;
516 add_stack(context
, long_op
? 4 : 2);
517 context
->Eip
+= prefixlen
+ 1;
518 return ExceptionContinueExecution
;
521 break; /* Unable to emulate it */
523 case 0x0f: /* extended instruction */
526 case 0x22: /* mov eax, crX */
530 ERR("mov eax,cr0 at 0x%08lx, EAX=0x%08lx\n",
531 context
->Eip
,context
->Eax
);
532 context
->Eip
+= prefixlen
+3;
533 return ExceptionContinueExecution
;
535 break; /*fallthrough to bad instruction handling */
537 break; /*fallthrough to bad instruction handling */
538 case 0x20: /* mov crX, eax */
541 case 0xe0: /* mov cr4, eax */
542 /* CR4 register . See linux/arch/i386/mm/init.c, X86_CR4_ defs
543 * bit 0: VME Virtual Mode Exception ?
544 * bit 1: PVI Protected mode Virtual Interrupt
545 * bit 2: TSD Timestamp disable
546 * bit 3: DE Debugging extensions
547 * bit 4: PSE Page size extensions
548 * bit 5: PAE Physical address extension
549 * bit 6: MCE Machine check enable
550 * bit 7: PGE Enable global pages
551 * bit 8: PCE Enable performance counters at IPL3
553 ERR("mov cr4,eax at 0x%08lx\n",context
->Eip
);
555 context
->Eip
+= prefixlen
+3;
556 return ExceptionContinueExecution
;
557 case 0xc0: /* mov cr0, eax */
558 ERR("mov cr0,eax at 0x%08lx\n",context
->Eip
);
559 context
->Eax
= 0x10; /* FIXME: set more bits ? */
560 context
->Eip
+= prefixlen
+3;
561 return ExceptionContinueExecution
;
562 default: /* fallthrough to illegal instruction */
565 /* fallthrough to illegal instruction */
567 case 0x21: /* mov drX, eax */
570 case 0xc8: /* mov dr1, eax */
571 context
->ContextFlags
= CONTEXT_DEBUG_REGISTERS
;
572 NtGetContextThread( GetCurrentThread(), context
);
573 TRACE("mov dr1,eax at 0x%08lx\n",context
->Eip
);
574 context
->Eax
= context
->Dr1
;
575 context
->Eip
+= prefixlen
+3;
576 return ExceptionContinueExecution
;
577 case 0xf8: /* mov dr7, eax */
578 TRACE("mov dr7,eax at 0x%08lx\n",context
->Eip
);
579 context
->Eax
= 0x400;
580 context
->Eip
+= prefixlen
+3;
581 return ExceptionContinueExecution
;
583 ERR("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
584 /* fallthrough to illegal instruction */
586 case 0x23: /* mov eax drX */
589 case 0xc8: /* mov eax, dr1 */
590 context
->ContextFlags
= CONTEXT_DEBUG_REGISTERS
;
591 NtGetContextThread( GetCurrentThread(), context
);
592 context
->Dr1
= context
->Eax
;
593 context
->Eip
+= prefixlen
+3;
594 context
->ContextFlags
= CONTEXT_DEBUG_REGISTERS
;
595 NtSetContextThread( GetCurrentThread(), context
);
596 return ExceptionContinueExecution
;
598 ERR("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
599 /* fallthrough to illegal instruction */
601 case 0xa1: /* pop fs */
603 WORD seg
= *(WORD
*)get_stack( context
);
604 if (INSTR_ReplaceSelector( context
, &seg
))
606 context
->SegFs
= seg
;
607 add_stack(context
, long_op
? 4 : 2);
608 context
->Eip
+= prefixlen
+ 2;
609 return ExceptionContinueExecution
;
613 case 0xa9: /* pop gs */
615 WORD seg
= *(WORD
*)get_stack( context
);
616 if (INSTR_ReplaceSelector( context
, &seg
))
618 context
->SegGs
= seg
;
619 add_stack(context
, long_op
? 4 : 2);
620 context
->Eip
+= prefixlen
+ 2;
621 return ExceptionContinueExecution
;
625 case 0xb2: /* lss addr,reg */
626 case 0xb4: /* lfs addr,reg */
627 case 0xb5: /* lgs addr,reg */
628 if (INSTR_EmulateLDS( context
, instr
, long_op
,
629 long_addr
, segprefix
, &len
))
631 context
->Eip
+= prefixlen
+ len
;
632 return ExceptionContinueExecution
;
636 break; /* Unable to emulate it */
638 case 0x6c: /* insb */
639 case 0x6d: /* insw/d */
640 case 0x6e: /* outsb */
641 case 0x6f: /* outsw/d */
643 int typ
= *instr
; /* Just in case it's overwritten. */
644 int outp
= (typ
>= 0x6e);
645 unsigned long count
= repX
?
646 (long_addr
? context
->Ecx
: LOWORD(context
->Ecx
)) : 1;
647 int opsize
= (typ
& 1) ? (long_op
? 4 : 2) : 1;
648 int step
= (context
->EFlags
& 0x400) ? -opsize
: +opsize
;
649 int seg
= outp
? context
->SegDs
: context
->SegEs
; /* FIXME: is this right? */
652 /* FIXME: Check segment readable. */
655 /* FIXME: Check segment writeable. */
660 if (long_addr
) context
->Ecx
= 0;
661 else SET_LOWORD(context
->Ecx
,0);
667 WORD dx
= LOWORD(context
->Edx
);
670 data
= make_ptr( context
, seg
, context
->Esi
, long_addr
);
671 if (long_addr
) context
->Esi
+= step
;
672 else ADD_LOWORD(context
->Esi
,step
);
676 data
= make_ptr( context
, seg
, context
->Edi
, long_addr
);
677 if (long_addr
) context
->Edi
+= step
;
678 else ADD_LOWORD(context
->Edi
,step
);
684 *(BYTE
*)data
= INSTR_inport( dx
, 1, context
);
688 *(DWORD
*)data
= INSTR_inport( dx
, 4, context
);
690 *(WORD
*)data
= INSTR_inport( dx
, 2, context
);
693 INSTR_outport( dx
, 1, *(BYTE
*)data
, context
);
697 INSTR_outport( dx
, 4, *(DWORD
*)data
, context
);
699 INSTR_outport( dx
, 2, *(WORD
*)data
, context
);
703 context
->Eip
+= prefixlen
+ 1;
705 return ExceptionContinueExecution
;
707 case 0x8b: /* mov Ev, Gv */
709 BYTE
*addr
= INSTR_GetOperandAddr(context
, instr
+ 1, long_addr
,
711 struct idtr idtr
= get_idtr();
712 unsigned int offset
= addr
- idtr
.base
;
714 if (offset
<= idtr
.limit
+ 1 - (long_op
? 4 : 2))
716 idt
[1].LimitLow
= 0x100; /* FIXME */
717 idt
[2].LimitLow
= 0x11E; /* FIXME */
718 idt
[3].LimitLow
= 0x500; /* FIXME */
719 store_reg( context
, instr
[1], (BYTE
*)&idt
+ offset
, long_op
);
720 context
->Eip
+= prefixlen
+ len
+ 1;
721 return ExceptionContinueExecution
;
724 break; /* Unable to emulate it */
726 case 0x8e: /* mov XX,segment_reg */
729 BYTE
*addr
= INSTR_GetOperandAddr(context
, instr
+ 1,
730 long_addr
, segprefix
, &len
);
732 break; /* Unable to emulate it */
734 if (!INSTR_ReplaceSelector( context
, &seg
))
735 break; /* Unable to emulate it */
737 switch((instr
[1] >> 3) & 7)
740 context
->SegEs
= seg
;
741 context
->Eip
+= prefixlen
+ len
+ 1;
742 return ExceptionContinueExecution
;
746 context
->SegSs
= seg
;
747 context
->Eip
+= prefixlen
+ len
+ 1;
748 return ExceptionContinueExecution
;
750 context
->SegDs
= seg
;
751 context
->Eip
+= prefixlen
+ len
+ 1;
752 return ExceptionContinueExecution
;
754 context
->SegFs
= seg
;
755 context
->Eip
+= prefixlen
+ len
+ 1;
756 return ExceptionContinueExecution
;
758 context
->SegGs
= seg
;
759 context
->Eip
+= prefixlen
+ len
+ 1;
760 return ExceptionContinueExecution
;
766 break; /* Unable to emulate it */
768 case 0xc4: /* les addr,reg */
769 case 0xc5: /* lds addr,reg */
770 if (INSTR_EmulateLDS( context
, instr
, long_op
,
771 long_addr
, segprefix
, &len
))
773 context
->Eip
+= prefixlen
+ len
;
774 return ExceptionContinueExecution
;
776 break; /* Unable to emulate it */
778 case 0xcd: /* int <XX> */
779 if (wine_ldt_is_system(context
->SegCs
)) break; /* don't emulate it in 32-bit code */
780 if (!winedos
.EmulateInterruptPM
) load_winedos();
781 if (winedos
.EmulateInterruptPM
)
783 context
->Eip
+= prefixlen
+ 2;
784 winedos
.EmulateInterruptPM( context
, instr
[1] );
785 return ExceptionContinueExecution
;
787 break; /* Unable to emulate it */
789 case 0xcf: /* iret */
790 if (wine_ldt_is_system(context
->SegCs
)) break; /* don't emulate it in 32-bit code */
793 DWORD
*stack
= get_stack( context
);
794 context
->Eip
= *stack
++;
795 context
->SegCs
= *stack
++;
796 context
->EFlags
= *stack
;
797 add_stack(context
, 3*sizeof(DWORD
)); /* Pop the return address and flags */
801 WORD
*stack
= get_stack( context
);
802 context
->Eip
= *stack
++;
803 context
->SegCs
= *stack
++;
804 SET_LOWORD(context
->EFlags
,*stack
);
805 add_stack(context
, 3*sizeof(WORD
)); /* Pop the return address and flags */
807 return ExceptionContinueExecution
;
809 case 0xe4: /* inb al,XX */
810 SET_LOBYTE(context
->Eax
,INSTR_inport( instr
[1], 1, context
));
811 context
->Eip
+= prefixlen
+ 2;
812 return ExceptionContinueExecution
;
814 case 0xe5: /* in (e)ax,XX */
816 context
->Eax
= INSTR_inport( instr
[1], 4, context
);
818 SET_LOWORD(context
->Eax
, INSTR_inport( instr
[1], 2, context
));
819 context
->Eip
+= prefixlen
+ 2;
820 return ExceptionContinueExecution
;
822 case 0xe6: /* outb XX,al */
823 INSTR_outport( instr
[1], 1, LOBYTE(context
->Eax
), context
);
824 context
->Eip
+= prefixlen
+ 2;
825 return ExceptionContinueExecution
;
827 case 0xe7: /* out XX,(e)ax */
829 INSTR_outport( instr
[1], 4, context
->Eax
, context
);
831 INSTR_outport( instr
[1], 2, LOWORD(context
->Eax
), context
);
832 context
->Eip
+= prefixlen
+ 2;
833 return ExceptionContinueExecution
;
835 case 0xec: /* inb al,dx */
836 SET_LOBYTE(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 1, context
) );
837 context
->Eip
+= prefixlen
+ 1;
838 return ExceptionContinueExecution
;
840 case 0xed: /* in (e)ax,dx */
842 context
->Eax
= INSTR_inport( LOWORD(context
->Edx
), 4, context
);
844 SET_LOWORD(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 2, context
));
845 context
->Eip
+= prefixlen
+ 1;
846 return ExceptionContinueExecution
;
848 case 0xee: /* outb dx,al */
849 INSTR_outport( LOWORD(context
->Edx
), 1, LOBYTE(context
->Eax
), context
);
850 context
->Eip
+= prefixlen
+ 1;
851 return ExceptionContinueExecution
;
853 case 0xef: /* out dx,(e)ax */
855 INSTR_outport( LOWORD(context
->Edx
), 4, context
->Eax
, context
);
857 INSTR_outport( LOWORD(context
->Edx
), 2, LOWORD(context
->Eax
), context
);
858 context
->Eip
+= prefixlen
+ 1;
859 return ExceptionContinueExecution
;
862 NtCurrentTeb()->dpmi_vif
= 0;
863 context
->Eip
+= prefixlen
+ 1;
864 return ExceptionContinueExecution
;
867 NtCurrentTeb()->dpmi_vif
= 1;
868 context
->Eip
+= prefixlen
+ 1;
869 if (NtCurrentTeb()->vm86_pending
)
871 NtCurrentTeb()->vm86_pending
= 0;
872 rec
->ExceptionCode
= EXCEPTION_VM86_STI
;
873 break; /* Handle the pending event. */
875 return ExceptionContinueExecution
;
877 return ExceptionContinueSearch
; /* Unable to emulate it */
881 /***********************************************************************
882 * INSTR_vectored_handler
884 * Vectored exception handler used to emulate protected instructions
887 LONG CALLBACK
INSTR_vectored_handler( EXCEPTION_POINTERS
*ptrs
)
889 EXCEPTION_RECORD
*record
= ptrs
->ExceptionRecord
;
890 CONTEXT86
*context
= ptrs
->ContextRecord
;
892 if (wine_ldt_is_system(context
->SegCs
) &&
893 (record
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
||
894 record
->ExceptionCode
== EXCEPTION_PRIV_INSTRUCTION
))
896 if (INSTR_EmulateInstruction( record
, context
) == ExceptionContinueExecution
)
897 return EXCEPTION_CONTINUE_EXECUTION
;
899 return EXCEPTION_CONTINUE_SEARCH
;
903 /***********************************************************************
904 * INSTR_CallBuiltinHandler
906 void INSTR_CallBuiltinHandler( CONTEXT86
*context
, BYTE intnum
)
908 if (!winedos
.CallBuiltinHandler
) load_winedos();
909 if (winedos
.CallBuiltinHandler
) winedos
.CallBuiltinHandler( context
, intnum
);
913 /***********************************************************************
914 * DOS3Call (KERNEL.102)
916 void WINAPI
DOS3Call( CONTEXT86
*context
)
918 INSTR_CallBuiltinHandler( context
, 0x21 );
922 /***********************************************************************
923 * NetBIOSCall (KERNEL.103)
925 void WINAPI
NetBIOSCall16( CONTEXT86
*context
)
927 INSTR_CallBuiltinHandler( context
, 0x5c );
931 /***********************************************************************
932 * GetSetKernelDOSProc (KERNEL.311)
934 FARPROC16 WINAPI
GetSetKernelDOSProc16( FARPROC16 DosProc
)
936 FIXME("(DosProc=%p): stub\n", DosProc
);