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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
31 #include "wine/winuser16.h"
33 #include "wine/debug.h"
34 #include "kernel16_private.h"
36 #include "wine/exception.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(int);
39 WINE_DECLARE_DEBUG_CHANNEL(io
);
41 /* macros to set parts of a DWORD */
42 #define SET_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD(val))
43 #define SET_LOBYTE(dw,val) ((dw) = ((dw) & 0xffffff00) | LOBYTE(val))
44 #define ADD_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
45 #define ISV86(context) ((context)->EFlags & 0x00020000)
47 static inline void add_stack( CONTEXT86
*context
, int offset
)
49 if (ISV86(context
) || !IS_SELECTOR_32BIT(context
->SegSs
))
50 ADD_LOWORD( context
->Esp
, offset
);
52 context
->Esp
+= offset
;
55 static inline void *make_ptr( CONTEXT86
*context
, DWORD seg
, DWORD off
, int long_addr
)
57 if (ISV86(context
)) return (void *)((seg
<< 4) + LOWORD(off
));
58 if (wine_ldt_is_system(seg
)) return (void *)off
;
59 if (!long_addr
) off
= LOWORD(off
);
60 return (char *) MapSL( MAKESEGPTR( seg
, 0 ) ) + off
;
63 static inline void *get_stack( CONTEXT86
*context
)
65 if (ISV86(context
)) return (void *)((context
->SegSs
<< 4) + LOWORD(context
->Esp
));
66 return wine_ldt_get_ptr( context
->SegSs
, context
->Esp
);
77 static LDT_ENTRY idt
[256];
79 static inline struct idtr
get_idtr(void)
82 #if defined(__i386__) && defined(__GNUC__)
83 __asm__( "sidtl %0" : "=m" (ret
) );
85 ret
.base
= (BYTE
*)idt
;
86 ret
.limit
= sizeof(idt
) - 1;
92 /***********************************************************************
93 * INSTR_ReplaceSelector
95 * Try to replace an invalid selector by a valid one.
96 * The only selector where it is allowed to do "mov ax,40;mov es,ax"
97 * is the so called 'bimodal' selector 0x40, which points to the BIOS
98 * data segment. Used by (at least) Borland products (and programs compiled
99 * using Borland products).
101 * See Undocumented Windows, Chapter 5, __0040.
103 static BOOL
INSTR_ReplaceSelector( CONTEXT86
*context
, WORD
*sel
)
107 *sel
= DOSMEM_BiosDataSeg
;
110 return FALSE
; /* Can't replace selector, crashdump */
114 /* store an operand into a register */
115 static void store_reg( CONTEXT86
*context
, BYTE regmodrm
, const BYTE
*addr
, int long_op
)
117 switch((regmodrm
>> 3) & 7)
120 if (long_op
) context
->Eax
= *(const DWORD
*)addr
;
121 else SET_LOWORD(context
->Eax
, *(const WORD
*)addr
);
124 if (long_op
) context
->Ecx
= *(const DWORD
*)addr
;
125 else SET_LOWORD(context
->Ecx
, *(const WORD
*)addr
);
128 if (long_op
) context
->Edx
= *(const DWORD
*)addr
;
129 else SET_LOWORD(context
->Edx
, *(const WORD
*)addr
);
132 if (long_op
) context
->Ebx
= *(const DWORD
*)addr
;
133 else SET_LOWORD(context
->Ebx
, *(const WORD
*)addr
);
136 if (long_op
) context
->Esp
= *(const DWORD
*)addr
;
137 else SET_LOWORD(context
->Esp
, *(const WORD
*)addr
);
140 if (long_op
) context
->Ebp
= *(const DWORD
*)addr
;
141 else SET_LOWORD(context
->Ebp
, *(const WORD
*)addr
);
144 if (long_op
) context
->Esi
= *(const DWORD
*)addr
;
145 else SET_LOWORD(context
->Esi
, *(const WORD
*)addr
);
148 if (long_op
) context
->Edi
= *(const DWORD
*)addr
;
149 else SET_LOWORD(context
->Edi
, *(const WORD
*)addr
);
154 /***********************************************************************
155 * INSTR_GetOperandAddr
157 * Return the address of an instruction operand (from the mod/rm byte).
159 static BYTE
*INSTR_GetOperandAddr( CONTEXT86
*context
, BYTE
*instr
,
160 int long_addr
, int segprefix
, int *len
)
162 int mod
, rm
, base
= 0, index
= 0, ss
= 0, seg
= 0, off
;
165 #define GET_VAL(val,type) \
166 { *val = *(type *)instr; instr += sizeof(type); *len += sizeof(type); }
169 GET_VAL( &mod
, BYTE
);
177 case 0: return (BYTE
*)&context
->Eax
;
178 case 1: return (BYTE
*)&context
->Ecx
;
179 case 2: return (BYTE
*)&context
->Edx
;
180 case 3: return (BYTE
*)&context
->Ebx
;
181 case 4: return (BYTE
*)&context
->Esp
;
182 case 5: return (BYTE
*)&context
->Ebp
;
183 case 6: return (BYTE
*)&context
->Esi
;
184 case 7: return (BYTE
*)&context
->Edi
;
193 GET_VAL( &sib
, BYTE
);
198 case 0: index
= context
->Eax
; break;
199 case 1: index
= context
->Ecx
; break;
200 case 2: index
= context
->Edx
; break;
201 case 3: index
= context
->Ebx
; break;
202 case 4: index
= 0; break;
203 case 5: index
= context
->Ebp
; break;
204 case 6: index
= context
->Esi
; break;
205 case 7: index
= context
->Edi
; break;
211 case 0: base
= context
->Eax
; seg
= context
->SegDs
; break;
212 case 1: base
= context
->Ecx
; seg
= context
->SegDs
; break;
213 case 2: base
= context
->Edx
; seg
= context
->SegDs
; break;
214 case 3: base
= context
->Ebx
; seg
= context
->SegDs
; break;
215 case 4: base
= context
->Esp
; seg
= context
->SegSs
; break;
216 case 5: base
= context
->Ebp
; seg
= context
->SegSs
; break;
217 case 6: base
= context
->Esi
; seg
= context
->SegDs
; break;
218 case 7: base
= context
->Edi
; seg
= context
->SegDs
; break;
223 if (rm
== 5) /* special case: ds:(disp32) */
225 GET_VAL( &base
, DWORD
);
226 seg
= context
->SegDs
;
230 case 1: /* 8-bit disp */
231 GET_VAL( &off
, BYTE
);
232 base
+= (signed char)off
;
235 case 2: /* 32-bit disp */
236 GET_VAL( &off
, DWORD
);
237 base
+= (signed long)off
;
241 else /* short address */
245 case 0: /* ds:(bx,si) */
246 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Esi
);
247 seg
= context
->SegDs
;
249 case 1: /* ds:(bx,di) */
250 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Edi
);
251 seg
= context
->SegDs
;
253 case 2: /* ss:(bp,si) */
254 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Esi
);
255 seg
= context
->SegSs
;
257 case 3: /* ss:(bp,di) */
258 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Edi
);
259 seg
= context
->SegSs
;
261 case 4: /* ds:(si) */
262 base
= LOWORD(context
->Esi
);
263 seg
= context
->SegDs
;
265 case 5: /* ds:(di) */
266 base
= LOWORD(context
->Edi
);
267 seg
= context
->SegDs
;
269 case 6: /* ss:(bp) */
270 base
= LOWORD(context
->Ebp
);
271 seg
= context
->SegSs
;
273 case 7: /* ds:(bx) */
274 base
= LOWORD(context
->Ebx
);
275 seg
= context
->SegDs
;
282 if (rm
== 6) /* special case: ds:(disp16) */
284 GET_VAL( &base
, WORD
);
285 seg
= context
->SegDs
;
289 case 1: /* 8-bit disp */
290 GET_VAL( &off
, BYTE
);
291 base
+= (signed char)off
;
294 case 2: /* 16-bit disp */
295 GET_VAL( &off
, WORD
);
296 base
+= (signed short)off
;
301 if (segprefix
!= -1) seg
= segprefix
;
303 /* Make sure the segment and offset are valid */
304 if (wine_ldt_is_system(seg
)) return (BYTE
*)(base
+ (index
<< ss
));
305 if ((seg
& 7) != 7) return NULL
;
306 wine_ldt_get_entry( seg
, &entry
);
307 if (wine_ldt_is_empty( &entry
)) return NULL
;
308 if (wine_ldt_get_limit(&entry
) < (base
+ (index
<< ss
))) return NULL
;
309 return (BYTE
*)wine_ldt_get_base(&entry
) + base
+ (index
<< ss
);
314 /***********************************************************************
317 * Emulate the LDS (and LES,LFS,etc.) instruction.
319 static BOOL
INSTR_EmulateLDS( CONTEXT86
*context
, BYTE
*instr
, int long_op
,
320 int long_addr
, int segprefix
, int *len
)
323 BYTE
*regmodrm
= instr
+ 1 + (*instr
== 0x0f);
324 BYTE
*addr
= INSTR_GetOperandAddr( context
, regmodrm
,
325 long_addr
, segprefix
, len
);
327 return FALSE
; /* Unable to emulate it */
328 seg
= *(WORD
*)(addr
+ (long_op
? 4 : 2));
330 if (!INSTR_ReplaceSelector( context
, &seg
))
331 return FALSE
; /* Unable to emulate it */
333 /* Now store the offset in the correct register */
335 store_reg( context
, *regmodrm
, addr
, long_op
);
337 /* Store the correct segment in the segment register */
341 case 0xc4: context
->SegEs
= seg
; break; /* les */
342 case 0xc5: context
->SegDs
= seg
; break; /* lds */
343 case 0x0f: switch(instr
[1])
345 case 0xb2: context
->SegSs
= seg
; break; /* lss */
346 case 0xb4: context
->SegFs
= seg
; break; /* lfs */
347 case 0xb5: context
->SegGs
= seg
; break; /* lgs */
352 /* Add the opcode size to the total length */
354 *len
+= 1 + (*instr
== 0x0f);
358 /***********************************************************************
361 * input on an I/O port
363 static DWORD
INSTR_inport( WORD port
, int size
, CONTEXT86
*context
)
365 DWORD res
= DOSVM_inport( port
, size
);
372 TRACE_(io
)( "0x%x < %02x @ %04x:%04x\n", port
, LOBYTE(res
),
373 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
376 TRACE_(io
)( "0x%x < %04x @ %04x:%04x\n", port
, LOWORD(res
),
377 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
380 TRACE_(io
)( "0x%x < %08x @ %04x:%04x\n", port
, res
,
381 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
389 /***********************************************************************
392 * output on an I/O port
394 static void INSTR_outport( WORD port
, int size
, DWORD val
, CONTEXT86
*context
)
396 DOSVM_outport( port
, size
, val
);
403 TRACE_(io
)("0x%x > %02x @ %04x:%04x\n", port
, LOBYTE(val
),
404 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
407 TRACE_(io
)("0x%x > %04x @ %04x:%04x\n", port
, LOWORD(val
),
408 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
411 TRACE_(io
)("0x%x > %08x @ %04x:%04x\n", port
, val
,
412 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
419 /***********************************************************************
420 * __wine_emulate_instruction
422 * Emulate a privileged instruction.
423 * Returns exception continuation status.
425 DWORD
__wine_emulate_instruction( EXCEPTION_RECORD
*rec
, CONTEXT86
*context
)
427 int prefix
, segprefix
, prefixlen
, len
, repX
, long_op
, long_addr
;
430 long_op
= long_addr
= (!ISV86(context
) && IS_SELECTOR_32BIT(context
->SegCs
));
431 instr
= make_ptr( context
, context
->SegCs
, context
->Eip
, TRUE
);
432 if (!instr
) return ExceptionContinueSearch
;
434 /* First handle any possible prefix */
436 segprefix
= -1; /* no prefix */
445 segprefix
= context
->SegCs
;
448 segprefix
= context
->SegSs
;
451 segprefix
= context
->SegDs
;
454 segprefix
= context
->SegEs
;
457 segprefix
= context
->SegFs
;
460 segprefix
= context
->SegGs
;
463 long_op
= !long_op
; /* opcode size prefix */
466 long_addr
= !long_addr
; /* addr size prefix */
468 case 0xf0: /* lock */
470 case 0xf2: /* repne */
473 case 0xf3: /* repe */
477 prefix
= 0; /* no more prefixes */
487 /* Now look at the actual instruction */
491 case 0x07: /* pop es */
492 case 0x17: /* pop ss */
493 case 0x1f: /* pop ds */
495 WORD seg
= *(WORD
*)get_stack( context
);
496 if (INSTR_ReplaceSelector( context
, &seg
))
500 case 0x07: context
->SegEs
= seg
; break;
501 case 0x17: context
->SegSs
= seg
; break;
502 case 0x1f: context
->SegDs
= seg
; break;
504 add_stack(context
, long_op
? 4 : 2);
505 context
->Eip
+= prefixlen
+ 1;
506 return ExceptionContinueExecution
;
509 break; /* Unable to emulate it */
511 case 0x0f: /* extended instruction */
514 case 0x22: /* mov eax, crX */
518 ERR("mov eax,cr0 at 0x%08x, EAX=0x%08x\n",
519 context
->Eip
,context
->Eax
);
520 context
->Eip
+= prefixlen
+3;
521 return ExceptionContinueExecution
;
523 break; /*fallthrough to bad instruction handling */
525 break; /*fallthrough to bad instruction handling */
526 case 0x20: /* mov crX, eax */
529 case 0xe0: /* mov cr4, eax */
530 /* CR4 register . See linux/arch/i386/mm/init.c, X86_CR4_ defs
531 * bit 0: VME Virtual Mode Exception ?
532 * bit 1: PVI Protected mode Virtual Interrupt
533 * bit 2: TSD Timestamp disable
534 * bit 3: DE Debugging extensions
535 * bit 4: PSE Page size extensions
536 * bit 5: PAE Physical address extension
537 * bit 6: MCE Machine check enable
538 * bit 7: PGE Enable global pages
539 * bit 8: PCE Enable performance counters at IPL3
541 ERR("mov cr4,eax at 0x%08x\n",context
->Eip
);
543 context
->Eip
+= prefixlen
+3;
544 return ExceptionContinueExecution
;
545 case 0xc0: /* mov cr0, eax */
546 ERR("mov cr0,eax at 0x%08x\n",context
->Eip
);
547 context
->Eax
= 0x10; /* FIXME: set more bits ? */
548 context
->Eip
+= prefixlen
+3;
549 return ExceptionContinueExecution
;
550 default: /* fallthrough to illegal instruction */
553 /* fallthrough to illegal instruction */
555 case 0x21: /* mov drX, eax */
558 case 0xc8: /* mov dr1, eax */
559 TRACE("mov dr1,eax at 0x%08x\n",context
->Eip
);
560 context
->Eax
= context
->Dr1
;
561 context
->Eip
+= prefixlen
+3;
562 return ExceptionContinueExecution
;
563 case 0xf8: /* mov dr7, eax */
564 TRACE("mov dr7,eax at 0x%08x\n",context
->Eip
);
565 context
->Eax
= 0x400;
566 context
->Eip
+= prefixlen
+3;
567 return ExceptionContinueExecution
;
569 ERR("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
570 /* fallthrough to illegal instruction */
572 case 0x23: /* mov eax drX */
575 case 0xc8: /* mov eax, dr1 */
576 context
->Dr1
= context
->Eax
;
577 context
->Eip
+= prefixlen
+3;
578 return ExceptionContinueExecution
;
580 ERR("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
581 /* fallthrough to illegal instruction */
583 case 0xa1: /* pop fs */
585 WORD seg
= *(WORD
*)get_stack( context
);
586 if (INSTR_ReplaceSelector( context
, &seg
))
588 context
->SegFs
= seg
;
589 add_stack(context
, long_op
? 4 : 2);
590 context
->Eip
+= prefixlen
+ 2;
591 return ExceptionContinueExecution
;
595 case 0xa9: /* pop gs */
597 WORD seg
= *(WORD
*)get_stack( context
);
598 if (INSTR_ReplaceSelector( context
, &seg
))
600 context
->SegGs
= seg
;
601 add_stack(context
, long_op
? 4 : 2);
602 context
->Eip
+= prefixlen
+ 2;
603 return ExceptionContinueExecution
;
607 case 0xb2: /* lss addr,reg */
608 case 0xb4: /* lfs addr,reg */
609 case 0xb5: /* lgs addr,reg */
610 if (INSTR_EmulateLDS( context
, instr
, long_op
,
611 long_addr
, segprefix
, &len
))
613 context
->Eip
+= prefixlen
+ len
;
614 return ExceptionContinueExecution
;
618 break; /* Unable to emulate it */
620 case 0x6c: /* insb */
621 case 0x6d: /* insw/d */
622 case 0x6e: /* outsb */
623 case 0x6f: /* outsw/d */
625 int typ
= *instr
; /* Just in case it's overwritten. */
626 int outp
= (typ
>= 0x6e);
627 unsigned long count
= repX
?
628 (long_addr
? context
->Ecx
: LOWORD(context
->Ecx
)) : 1;
629 int opsize
= (typ
& 1) ? (long_op
? 4 : 2) : 1;
630 int step
= (context
->EFlags
& 0x400) ? -opsize
: +opsize
;
631 int seg
= outp
? context
->SegDs
: context
->SegEs
; /* FIXME: is this right? */
634 /* FIXME: Check segment is readable. */
637 /* FIXME: Check segment is writable. */
642 if (long_addr
) context
->Ecx
= 0;
643 else SET_LOWORD(context
->Ecx
,0);
649 WORD dx
= LOWORD(context
->Edx
);
652 data
= make_ptr( context
, seg
, context
->Esi
, long_addr
);
653 if (long_addr
) context
->Esi
+= step
;
654 else ADD_LOWORD(context
->Esi
,step
);
658 data
= make_ptr( context
, seg
, context
->Edi
, long_addr
);
659 if (long_addr
) context
->Edi
+= step
;
660 else ADD_LOWORD(context
->Edi
,step
);
666 *(BYTE
*)data
= INSTR_inport( dx
, 1, context
);
670 *(DWORD
*)data
= INSTR_inport( dx
, 4, context
);
672 *(WORD
*)data
= INSTR_inport( dx
, 2, context
);
675 INSTR_outport( dx
, 1, *(BYTE
*)data
, context
);
679 INSTR_outport( dx
, 4, *(DWORD
*)data
, context
);
681 INSTR_outport( dx
, 2, *(WORD
*)data
, context
);
685 context
->Eip
+= prefixlen
+ 1;
687 return ExceptionContinueExecution
;
689 case 0x8b: /* mov Ev, Gv */
691 BYTE
*addr
= INSTR_GetOperandAddr(context
, instr
+ 1, long_addr
,
693 struct idtr idtr
= get_idtr();
694 unsigned int offset
= addr
- idtr
.base
;
696 if (offset
<= idtr
.limit
+ 1 - (long_op
? 4 : 2))
698 idt
[1].LimitLow
= 0x100; /* FIXME */
699 idt
[2].LimitLow
= 0x11E; /* FIXME */
700 idt
[3].LimitLow
= 0x500; /* FIXME */
701 store_reg( context
, instr
[1], (BYTE
*)idt
+ offset
, long_op
);
702 context
->Eip
+= prefixlen
+ len
+ 1;
703 return ExceptionContinueExecution
;
706 break; /* Unable to emulate it */
708 case 0x8e: /* mov XX,segment_reg */
711 BYTE
*addr
= INSTR_GetOperandAddr(context
, instr
+ 1,
712 long_addr
, segprefix
, &len
);
714 break; /* Unable to emulate it */
716 if (!INSTR_ReplaceSelector( context
, &seg
))
717 break; /* Unable to emulate it */
719 switch((instr
[1] >> 3) & 7)
722 context
->SegEs
= seg
;
723 context
->Eip
+= prefixlen
+ len
+ 1;
724 return ExceptionContinueExecution
;
728 context
->SegSs
= seg
;
729 context
->Eip
+= prefixlen
+ len
+ 1;
730 return ExceptionContinueExecution
;
732 context
->SegDs
= seg
;
733 context
->Eip
+= prefixlen
+ len
+ 1;
734 return ExceptionContinueExecution
;
736 context
->SegFs
= seg
;
737 context
->Eip
+= prefixlen
+ len
+ 1;
738 return ExceptionContinueExecution
;
740 context
->SegGs
= seg
;
741 context
->Eip
+= prefixlen
+ len
+ 1;
742 return ExceptionContinueExecution
;
748 break; /* Unable to emulate it */
750 case 0xc4: /* les addr,reg */
751 case 0xc5: /* lds addr,reg */
752 if (INSTR_EmulateLDS( context
, instr
, long_op
,
753 long_addr
, segprefix
, &len
))
755 context
->Eip
+= prefixlen
+ len
;
756 return ExceptionContinueExecution
;
758 break; /* Unable to emulate it */
760 case 0xcd: /* int <XX> */
761 context
->Eip
+= prefixlen
+ 2;
762 if (DOSVM_EmulateInterruptPM( context
, instr
[1] )) return ExceptionContinueExecution
;
763 context
->Eip
-= prefixlen
+ 2; /* restore eip */
764 break; /* Unable to emulate it */
766 case 0xcf: /* iret */
767 if (wine_ldt_is_system(context
->SegCs
)) break; /* don't emulate it in 32-bit code */
770 DWORD
*stack
= get_stack( context
);
771 context
->Eip
= *stack
++;
772 context
->SegCs
= *stack
++;
773 context
->EFlags
= *stack
;
774 add_stack(context
, 3*sizeof(DWORD
)); /* Pop the return address and flags */
778 WORD
*stack
= get_stack( context
);
779 context
->Eip
= *stack
++;
780 context
->SegCs
= *stack
++;
781 SET_LOWORD(context
->EFlags
,*stack
);
782 add_stack(context
, 3*sizeof(WORD
)); /* Pop the return address and flags */
784 return ExceptionContinueExecution
;
786 case 0xe4: /* inb al,XX */
787 SET_LOBYTE(context
->Eax
,INSTR_inport( instr
[1], 1, context
));
788 context
->Eip
+= prefixlen
+ 2;
789 return ExceptionContinueExecution
;
791 case 0xe5: /* in (e)ax,XX */
793 context
->Eax
= INSTR_inport( instr
[1], 4, context
);
795 SET_LOWORD(context
->Eax
, INSTR_inport( instr
[1], 2, context
));
796 context
->Eip
+= prefixlen
+ 2;
797 return ExceptionContinueExecution
;
799 case 0xe6: /* outb XX,al */
800 INSTR_outport( instr
[1], 1, LOBYTE(context
->Eax
), context
);
801 context
->Eip
+= prefixlen
+ 2;
802 return ExceptionContinueExecution
;
804 case 0xe7: /* out XX,(e)ax */
806 INSTR_outport( instr
[1], 4, context
->Eax
, context
);
808 INSTR_outport( instr
[1], 2, LOWORD(context
->Eax
), context
);
809 context
->Eip
+= prefixlen
+ 2;
810 return ExceptionContinueExecution
;
812 case 0xec: /* inb al,dx */
813 SET_LOBYTE(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 1, context
) );
814 context
->Eip
+= prefixlen
+ 1;
815 return ExceptionContinueExecution
;
817 case 0xed: /* in (e)ax,dx */
819 context
->Eax
= INSTR_inport( LOWORD(context
->Edx
), 4, context
);
821 SET_LOWORD(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 2, context
));
822 context
->Eip
+= prefixlen
+ 1;
823 return ExceptionContinueExecution
;
825 case 0xee: /* outb dx,al */
826 INSTR_outport( LOWORD(context
->Edx
), 1, LOBYTE(context
->Eax
), context
);
827 context
->Eip
+= prefixlen
+ 1;
828 return ExceptionContinueExecution
;
830 case 0xef: /* out dx,(e)ax */
832 INSTR_outport( LOWORD(context
->Edx
), 4, context
->Eax
, context
);
834 INSTR_outport( LOWORD(context
->Edx
), 2, LOWORD(context
->Eax
), context
);
835 context
->Eip
+= prefixlen
+ 1;
836 return ExceptionContinueExecution
;
839 get_vm86_teb_info()->dpmi_vif
= 0;
840 context
->Eip
+= prefixlen
+ 1;
841 return ExceptionContinueExecution
;
844 get_vm86_teb_info()->dpmi_vif
= 1;
845 context
->Eip
+= prefixlen
+ 1;
846 if (get_vm86_teb_info()->vm86_pending
)
848 get_vm86_teb_info()->vm86_pending
= 0;
849 rec
->ExceptionCode
= EXCEPTION_VM86_STI
;
850 break; /* Handle the pending event. */
852 return ExceptionContinueExecution
;
854 return ExceptionContinueSearch
; /* Unable to emulate it */
858 /***********************************************************************
859 * INSTR_vectored_handler
861 * Vectored exception handler used to emulate protected instructions
864 LONG CALLBACK
INSTR_vectored_handler( EXCEPTION_POINTERS
*ptrs
)
866 EXCEPTION_RECORD
*record
= ptrs
->ExceptionRecord
;
867 CONTEXT86
*context
= ptrs
->ContextRecord
;
869 if (wine_ldt_is_system(context
->SegCs
) &&
870 (record
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
||
871 record
->ExceptionCode
== EXCEPTION_PRIV_INSTRUCTION
))
873 if (__wine_emulate_instruction( record
, context
) == ExceptionContinueExecution
)
874 return EXCEPTION_CONTINUE_EXECUTION
;
876 return EXCEPTION_CONTINUE_SEARCH
;
880 /***********************************************************************
881 * DOS3Call (KERNEL.102)
883 void WINAPI
DOS3Call( CONTEXT86
*context
)
885 __wine_call_int_handler( context
, 0x21 );
889 /***********************************************************************
890 * NetBIOSCall (KERNEL.103)
892 void WINAPI
NetBIOSCall16( CONTEXT86
*context
)
894 __wine_call_int_handler( context
, 0x5c );
898 /***********************************************************************
899 * GetSetKernelDOSProc (KERNEL.311)
901 FARPROC16 WINAPI
GetSetKernelDOSProc16( FARPROC16 DosProc
)
903 FIXME("(DosProc=%p): stub\n", DosProc
);