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 DOSVM_start_bios_timer();
108 *sel
= DOSMEM_BiosDataSeg
;
111 return FALSE
; /* Can't replace selector, crashdump */
115 /* store an operand into a register */
116 static void store_reg( CONTEXT86
*context
, BYTE regmodrm
, const BYTE
*addr
, int long_op
)
118 switch((regmodrm
>> 3) & 7)
121 if (long_op
) context
->Eax
= *(const DWORD
*)addr
;
122 else SET_LOWORD(context
->Eax
, *(const WORD
*)addr
);
125 if (long_op
) context
->Ecx
= *(const DWORD
*)addr
;
126 else SET_LOWORD(context
->Ecx
, *(const WORD
*)addr
);
129 if (long_op
) context
->Edx
= *(const DWORD
*)addr
;
130 else SET_LOWORD(context
->Edx
, *(const WORD
*)addr
);
133 if (long_op
) context
->Ebx
= *(const DWORD
*)addr
;
134 else SET_LOWORD(context
->Ebx
, *(const WORD
*)addr
);
137 if (long_op
) context
->Esp
= *(const DWORD
*)addr
;
138 else SET_LOWORD(context
->Esp
, *(const WORD
*)addr
);
141 if (long_op
) context
->Ebp
= *(const DWORD
*)addr
;
142 else SET_LOWORD(context
->Ebp
, *(const WORD
*)addr
);
145 if (long_op
) context
->Esi
= *(const DWORD
*)addr
;
146 else SET_LOWORD(context
->Esi
, *(const WORD
*)addr
);
149 if (long_op
) context
->Edi
= *(const DWORD
*)addr
;
150 else SET_LOWORD(context
->Edi
, *(const WORD
*)addr
);
155 /***********************************************************************
156 * INSTR_GetOperandAddr
158 * Return the address of an instruction operand (from the mod/rm byte).
160 static BYTE
*INSTR_GetOperandAddr( CONTEXT86
*context
, BYTE
*instr
,
161 int long_addr
, int segprefix
, int *len
)
163 int mod
, rm
, base
= 0, index
= 0, ss
= 0, seg
= 0, off
;
166 #define GET_VAL(val,type) \
167 { *val = *(type *)instr; instr += sizeof(type); *len += sizeof(type); }
170 GET_VAL( &mod
, BYTE
);
178 case 0: return (BYTE
*)&context
->Eax
;
179 case 1: return (BYTE
*)&context
->Ecx
;
180 case 2: return (BYTE
*)&context
->Edx
;
181 case 3: return (BYTE
*)&context
->Ebx
;
182 case 4: return (BYTE
*)&context
->Esp
;
183 case 5: return (BYTE
*)&context
->Ebp
;
184 case 6: return (BYTE
*)&context
->Esi
;
185 case 7: return (BYTE
*)&context
->Edi
;
194 GET_VAL( &sib
, BYTE
);
199 case 0: index
= context
->Eax
; break;
200 case 1: index
= context
->Ecx
; break;
201 case 2: index
= context
->Edx
; break;
202 case 3: index
= context
->Ebx
; break;
203 case 4: index
= 0; break;
204 case 5: index
= context
->Ebp
; break;
205 case 6: index
= context
->Esi
; break;
206 case 7: index
= context
->Edi
; break;
212 case 0: base
= context
->Eax
; seg
= context
->SegDs
; break;
213 case 1: base
= context
->Ecx
; seg
= context
->SegDs
; break;
214 case 2: base
= context
->Edx
; seg
= context
->SegDs
; break;
215 case 3: base
= context
->Ebx
; seg
= context
->SegDs
; break;
216 case 4: base
= context
->Esp
; seg
= context
->SegSs
; break;
217 case 5: base
= context
->Ebp
; seg
= context
->SegSs
; break;
218 case 6: base
= context
->Esi
; seg
= context
->SegDs
; break;
219 case 7: base
= context
->Edi
; seg
= context
->SegDs
; break;
224 if (rm
== 5) /* special case: ds:(disp32) */
226 GET_VAL( &base
, DWORD
);
227 seg
= context
->SegDs
;
231 case 1: /* 8-bit disp */
232 GET_VAL( &off
, BYTE
);
233 base
+= (signed char)off
;
236 case 2: /* 32-bit disp */
237 GET_VAL( &off
, DWORD
);
238 base
+= (signed long)off
;
242 else /* short address */
246 case 0: /* ds:(bx,si) */
247 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Esi
);
248 seg
= context
->SegDs
;
250 case 1: /* ds:(bx,di) */
251 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Edi
);
252 seg
= context
->SegDs
;
254 case 2: /* ss:(bp,si) */
255 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Esi
);
256 seg
= context
->SegSs
;
258 case 3: /* ss:(bp,di) */
259 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Edi
);
260 seg
= context
->SegSs
;
262 case 4: /* ds:(si) */
263 base
= LOWORD(context
->Esi
);
264 seg
= context
->SegDs
;
266 case 5: /* ds:(di) */
267 base
= LOWORD(context
->Edi
);
268 seg
= context
->SegDs
;
270 case 6: /* ss:(bp) */
271 base
= LOWORD(context
->Ebp
);
272 seg
= context
->SegSs
;
274 case 7: /* ds:(bx) */
275 base
= LOWORD(context
->Ebx
);
276 seg
= context
->SegDs
;
283 if (rm
== 6) /* special case: ds:(disp16) */
285 GET_VAL( &base
, WORD
);
286 seg
= context
->SegDs
;
290 case 1: /* 8-bit disp */
291 GET_VAL( &off
, BYTE
);
292 base
+= (signed char)off
;
295 case 2: /* 16-bit disp */
296 GET_VAL( &off
, WORD
);
297 base
+= (signed short)off
;
302 if (segprefix
!= -1) seg
= segprefix
;
304 /* Make sure the segment and offset are valid */
305 if (wine_ldt_is_system(seg
)) return (BYTE
*)(base
+ (index
<< ss
));
306 if ((seg
& 7) != 7) return NULL
;
307 wine_ldt_get_entry( seg
, &entry
);
308 if (wine_ldt_is_empty( &entry
)) return NULL
;
309 if (wine_ldt_get_limit(&entry
) < (base
+ (index
<< ss
))) return NULL
;
310 return (BYTE
*)wine_ldt_get_base(&entry
) + base
+ (index
<< ss
);
315 /***********************************************************************
318 * Emulate the LDS (and LES,LFS,etc.) instruction.
320 static BOOL
INSTR_EmulateLDS( CONTEXT86
*context
, BYTE
*instr
, int long_op
,
321 int long_addr
, int segprefix
, int *len
)
324 BYTE
*regmodrm
= instr
+ 1 + (*instr
== 0x0f);
325 BYTE
*addr
= INSTR_GetOperandAddr( context
, regmodrm
,
326 long_addr
, segprefix
, len
);
328 return FALSE
; /* Unable to emulate it */
329 seg
= *(WORD
*)(addr
+ (long_op
? 4 : 2));
331 if (!INSTR_ReplaceSelector( context
, &seg
))
332 return FALSE
; /* Unable to emulate it */
334 /* Now store the offset in the correct register */
336 store_reg( context
, *regmodrm
, addr
, long_op
);
338 /* Store the correct segment in the segment register */
342 case 0xc4: context
->SegEs
= seg
; break; /* les */
343 case 0xc5: context
->SegDs
= seg
; break; /* lds */
344 case 0x0f: switch(instr
[1])
346 case 0xb2: context
->SegSs
= seg
; break; /* lss */
347 case 0xb4: context
->SegFs
= seg
; break; /* lfs */
348 case 0xb5: context
->SegGs
= seg
; break; /* lgs */
353 /* Add the opcode size to the total length */
355 *len
+= 1 + (*instr
== 0x0f);
359 /***********************************************************************
362 * input on an I/O port
364 static DWORD
INSTR_inport( WORD port
, int size
, CONTEXT86
*context
)
366 DWORD res
= DOSVM_inport( port
, size
);
373 TRACE_(io
)( "0x%x < %02x @ %04x:%04x\n", port
, LOBYTE(res
),
374 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
377 TRACE_(io
)( "0x%x < %04x @ %04x:%04x\n", port
, LOWORD(res
),
378 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
381 TRACE_(io
)( "0x%x < %08x @ %04x:%04x\n", port
, res
,
382 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
390 /***********************************************************************
393 * output on an I/O port
395 static void INSTR_outport( WORD port
, int size
, DWORD val
, CONTEXT86
*context
)
397 DOSVM_outport( port
, size
, val
);
404 TRACE_(io
)("0x%x > %02x @ %04x:%04x\n", port
, LOBYTE(val
),
405 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
408 TRACE_(io
)("0x%x > %04x @ %04x:%04x\n", port
, LOWORD(val
),
409 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
412 TRACE_(io
)("0x%x > %08x @ %04x:%04x\n", port
, val
,
413 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
420 /***********************************************************************
421 * __wine_emulate_instruction
423 * Emulate a privileged instruction.
424 * Returns exception continuation status.
426 DWORD
__wine_emulate_instruction( EXCEPTION_RECORD
*rec
, CONTEXT86
*context
)
428 int prefix
, segprefix
, prefixlen
, len
, repX
, long_op
, long_addr
;
431 long_op
= long_addr
= (!ISV86(context
) && IS_SELECTOR_32BIT(context
->SegCs
));
432 instr
= make_ptr( context
, context
->SegCs
, context
->Eip
, TRUE
);
433 if (!instr
) return ExceptionContinueSearch
;
435 /* First handle any possible prefix */
437 segprefix
= -1; /* no prefix */
446 segprefix
= context
->SegCs
;
449 segprefix
= context
->SegSs
;
452 segprefix
= context
->SegDs
;
455 segprefix
= context
->SegEs
;
458 segprefix
= context
->SegFs
;
461 segprefix
= context
->SegGs
;
464 long_op
= !long_op
; /* opcode size prefix */
467 long_addr
= !long_addr
; /* addr size prefix */
469 case 0xf0: /* lock */
471 case 0xf2: /* repne */
474 case 0xf3: /* repe */
478 prefix
= 0; /* no more prefixes */
488 /* Now look at the actual instruction */
492 case 0x07: /* pop es */
493 case 0x17: /* pop ss */
494 case 0x1f: /* pop ds */
496 WORD seg
= *(WORD
*)get_stack( context
);
497 if (INSTR_ReplaceSelector( context
, &seg
))
501 case 0x07: context
->SegEs
= seg
; break;
502 case 0x17: context
->SegSs
= seg
; break;
503 case 0x1f: context
->SegDs
= seg
; break;
505 add_stack(context
, long_op
? 4 : 2);
506 context
->Eip
+= prefixlen
+ 1;
507 return ExceptionContinueExecution
;
510 break; /* Unable to emulate it */
512 case 0x0f: /* extended instruction */
515 case 0x22: /* mov eax, crX */
519 ERR("mov eax,cr0 at 0x%08x, EAX=0x%08x\n",
520 context
->Eip
,context
->Eax
);
521 context
->Eip
+= prefixlen
+3;
522 return ExceptionContinueExecution
;
524 break; /*fallthrough to bad instruction handling */
526 break; /*fallthrough to bad instruction handling */
527 case 0x20: /* mov crX, eax */
530 case 0xe0: /* mov cr4, eax */
531 /* CR4 register . See linux/arch/i386/mm/init.c, X86_CR4_ defs
532 * bit 0: VME Virtual Mode Exception ?
533 * bit 1: PVI Protected mode Virtual Interrupt
534 * bit 2: TSD Timestamp disable
535 * bit 3: DE Debugging extensions
536 * bit 4: PSE Page size extensions
537 * bit 5: PAE Physical address extension
538 * bit 6: MCE Machine check enable
539 * bit 7: PGE Enable global pages
540 * bit 8: PCE Enable performance counters at IPL3
542 ERR("mov cr4,eax at 0x%08x\n",context
->Eip
);
544 context
->Eip
+= prefixlen
+3;
545 return ExceptionContinueExecution
;
546 case 0xc0: /* mov cr0, eax */
547 ERR("mov cr0,eax at 0x%08x\n",context
->Eip
);
548 context
->Eax
= 0x10; /* FIXME: set more bits ? */
549 context
->Eip
+= prefixlen
+3;
550 return ExceptionContinueExecution
;
551 default: /* fallthrough to illegal instruction */
554 /* fallthrough to illegal instruction */
556 case 0x21: /* mov drX, eax */
559 case 0xc8: /* mov dr1, eax */
560 TRACE("mov dr1,eax at 0x%08x\n",context
->Eip
);
561 context
->Eax
= context
->Dr1
;
562 context
->Eip
+= prefixlen
+3;
563 return ExceptionContinueExecution
;
564 case 0xf8: /* mov dr7, eax */
565 TRACE("mov dr7,eax at 0x%08x\n",context
->Eip
);
566 context
->Eax
= 0x400;
567 context
->Eip
+= prefixlen
+3;
568 return ExceptionContinueExecution
;
570 ERR("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
571 /* fallthrough to illegal instruction */
573 case 0x23: /* mov eax drX */
576 case 0xc8: /* mov eax, dr1 */
577 context
->Dr1
= context
->Eax
;
578 context
->Eip
+= prefixlen
+3;
579 return ExceptionContinueExecution
;
581 ERR("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
582 /* fallthrough to illegal instruction */
584 case 0xa1: /* pop fs */
586 WORD seg
= *(WORD
*)get_stack( context
);
587 if (INSTR_ReplaceSelector( context
, &seg
))
589 context
->SegFs
= seg
;
590 add_stack(context
, long_op
? 4 : 2);
591 context
->Eip
+= prefixlen
+ 2;
592 return ExceptionContinueExecution
;
596 case 0xa9: /* pop gs */
598 WORD seg
= *(WORD
*)get_stack( context
);
599 if (INSTR_ReplaceSelector( context
, &seg
))
601 context
->SegGs
= seg
;
602 add_stack(context
, long_op
? 4 : 2);
603 context
->Eip
+= prefixlen
+ 2;
604 return ExceptionContinueExecution
;
608 case 0xb2: /* lss addr,reg */
609 case 0xb4: /* lfs addr,reg */
610 case 0xb5: /* lgs addr,reg */
611 if (INSTR_EmulateLDS( context
, instr
, long_op
,
612 long_addr
, segprefix
, &len
))
614 context
->Eip
+= prefixlen
+ len
;
615 return ExceptionContinueExecution
;
619 break; /* Unable to emulate it */
621 case 0x6c: /* insb */
622 case 0x6d: /* insw/d */
623 case 0x6e: /* outsb */
624 case 0x6f: /* outsw/d */
626 int typ
= *instr
; /* Just in case it's overwritten. */
627 int outp
= (typ
>= 0x6e);
628 unsigned long count
= repX
?
629 (long_addr
? context
->Ecx
: LOWORD(context
->Ecx
)) : 1;
630 int opsize
= (typ
& 1) ? (long_op
? 4 : 2) : 1;
631 int step
= (context
->EFlags
& 0x400) ? -opsize
: +opsize
;
632 int seg
= outp
? context
->SegDs
: context
->SegEs
; /* FIXME: is this right? */
635 /* FIXME: Check segment is readable. */
638 /* FIXME: Check segment is writable. */
643 if (long_addr
) context
->Ecx
= 0;
644 else SET_LOWORD(context
->Ecx
,0);
650 WORD dx
= LOWORD(context
->Edx
);
653 data
= make_ptr( context
, seg
, context
->Esi
, long_addr
);
654 if (long_addr
) context
->Esi
+= step
;
655 else ADD_LOWORD(context
->Esi
,step
);
659 data
= make_ptr( context
, seg
, context
->Edi
, long_addr
);
660 if (long_addr
) context
->Edi
+= step
;
661 else ADD_LOWORD(context
->Edi
,step
);
667 *(BYTE
*)data
= INSTR_inport( dx
, 1, context
);
671 *(DWORD
*)data
= INSTR_inport( dx
, 4, context
);
673 *(WORD
*)data
= INSTR_inport( dx
, 2, context
);
676 INSTR_outport( dx
, 1, *(BYTE
*)data
, context
);
680 INSTR_outport( dx
, 4, *(DWORD
*)data
, context
);
682 INSTR_outport( dx
, 2, *(WORD
*)data
, context
);
686 context
->Eip
+= prefixlen
+ 1;
688 return ExceptionContinueExecution
;
690 case 0x8b: /* mov Ev, Gv */
692 BYTE
*addr
= INSTR_GetOperandAddr(context
, instr
+ 1, long_addr
,
694 struct idtr idtr
= get_idtr();
695 unsigned int offset
= addr
- idtr
.base
;
697 if (offset
<= idtr
.limit
+ 1 - (long_op
? 4 : 2))
699 idt
[1].LimitLow
= 0x100; /* FIXME */
700 idt
[2].LimitLow
= 0x11E; /* FIXME */
701 idt
[3].LimitLow
= 0x500; /* FIXME */
702 store_reg( context
, instr
[1], (BYTE
*)idt
+ offset
, long_op
);
703 context
->Eip
+= prefixlen
+ len
+ 1;
704 return ExceptionContinueExecution
;
707 break; /* Unable to emulate it */
709 case 0x8e: /* mov XX,segment_reg */
712 BYTE
*addr
= INSTR_GetOperandAddr(context
, instr
+ 1,
713 long_addr
, segprefix
, &len
);
715 break; /* Unable to emulate it */
717 if (!INSTR_ReplaceSelector( context
, &seg
))
718 break; /* Unable to emulate it */
720 switch((instr
[1] >> 3) & 7)
723 context
->SegEs
= seg
;
724 context
->Eip
+= prefixlen
+ len
+ 1;
725 return ExceptionContinueExecution
;
729 context
->SegSs
= seg
;
730 context
->Eip
+= prefixlen
+ len
+ 1;
731 return ExceptionContinueExecution
;
733 context
->SegDs
= seg
;
734 context
->Eip
+= prefixlen
+ len
+ 1;
735 return ExceptionContinueExecution
;
737 context
->SegFs
= seg
;
738 context
->Eip
+= prefixlen
+ len
+ 1;
739 return ExceptionContinueExecution
;
741 context
->SegGs
= seg
;
742 context
->Eip
+= prefixlen
+ len
+ 1;
743 return ExceptionContinueExecution
;
749 break; /* Unable to emulate it */
751 case 0xc4: /* les addr,reg */
752 case 0xc5: /* lds addr,reg */
753 if (INSTR_EmulateLDS( context
, instr
, long_op
,
754 long_addr
, segprefix
, &len
))
756 context
->Eip
+= prefixlen
+ len
;
757 return ExceptionContinueExecution
;
759 break; /* Unable to emulate it */
761 case 0xcd: /* int <XX> */
762 context
->Eip
+= prefixlen
+ 2;
763 if (DOSVM_EmulateInterruptPM( context
, instr
[1] )) return ExceptionContinueExecution
;
764 context
->Eip
-= prefixlen
+ 2; /* restore eip */
765 break; /* Unable to emulate it */
767 case 0xcf: /* iret */
768 if (wine_ldt_is_system(context
->SegCs
)) break; /* don't emulate it in 32-bit code */
771 DWORD
*stack
= get_stack( context
);
772 context
->Eip
= *stack
++;
773 context
->SegCs
= *stack
++;
774 context
->EFlags
= *stack
;
775 add_stack(context
, 3*sizeof(DWORD
)); /* Pop the return address and flags */
779 WORD
*stack
= get_stack( context
);
780 context
->Eip
= *stack
++;
781 context
->SegCs
= *stack
++;
782 SET_LOWORD(context
->EFlags
,*stack
);
783 add_stack(context
, 3*sizeof(WORD
)); /* Pop the return address and flags */
785 return ExceptionContinueExecution
;
787 case 0xe4: /* inb al,XX */
788 SET_LOBYTE(context
->Eax
,INSTR_inport( instr
[1], 1, context
));
789 context
->Eip
+= prefixlen
+ 2;
790 return ExceptionContinueExecution
;
792 case 0xe5: /* in (e)ax,XX */
794 context
->Eax
= INSTR_inport( instr
[1], 4, context
);
796 SET_LOWORD(context
->Eax
, INSTR_inport( instr
[1], 2, context
));
797 context
->Eip
+= prefixlen
+ 2;
798 return ExceptionContinueExecution
;
800 case 0xe6: /* outb XX,al */
801 INSTR_outport( instr
[1], 1, LOBYTE(context
->Eax
), context
);
802 context
->Eip
+= prefixlen
+ 2;
803 return ExceptionContinueExecution
;
805 case 0xe7: /* out XX,(e)ax */
807 INSTR_outport( instr
[1], 4, context
->Eax
, context
);
809 INSTR_outport( instr
[1], 2, LOWORD(context
->Eax
), context
);
810 context
->Eip
+= prefixlen
+ 2;
811 return ExceptionContinueExecution
;
813 case 0xec: /* inb al,dx */
814 SET_LOBYTE(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 1, context
) );
815 context
->Eip
+= prefixlen
+ 1;
816 return ExceptionContinueExecution
;
818 case 0xed: /* in (e)ax,dx */
820 context
->Eax
= INSTR_inport( LOWORD(context
->Edx
), 4, context
);
822 SET_LOWORD(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 2, context
));
823 context
->Eip
+= prefixlen
+ 1;
824 return ExceptionContinueExecution
;
826 case 0xee: /* outb dx,al */
827 INSTR_outport( LOWORD(context
->Edx
), 1, LOBYTE(context
->Eax
), context
);
828 context
->Eip
+= prefixlen
+ 1;
829 return ExceptionContinueExecution
;
831 case 0xef: /* out dx,(e)ax */
833 INSTR_outport( LOWORD(context
->Edx
), 4, context
->Eax
, context
);
835 INSTR_outport( LOWORD(context
->Edx
), 2, LOWORD(context
->Eax
), context
);
836 context
->Eip
+= prefixlen
+ 1;
837 return ExceptionContinueExecution
;
840 get_vm86_teb_info()->dpmi_vif
= 0;
841 context
->Eip
+= prefixlen
+ 1;
842 return ExceptionContinueExecution
;
845 get_vm86_teb_info()->dpmi_vif
= 1;
846 context
->Eip
+= prefixlen
+ 1;
847 if (get_vm86_teb_info()->vm86_pending
)
849 get_vm86_teb_info()->vm86_pending
= 0;
850 rec
->ExceptionCode
= EXCEPTION_VM86_STI
;
851 break; /* Handle the pending event. */
853 return ExceptionContinueExecution
;
855 return ExceptionContinueSearch
; /* Unable to emulate it */
859 /***********************************************************************
860 * INSTR_vectored_handler
862 * Vectored exception handler used to emulate protected instructions
865 LONG CALLBACK
INSTR_vectored_handler( EXCEPTION_POINTERS
*ptrs
)
867 EXCEPTION_RECORD
*record
= ptrs
->ExceptionRecord
;
868 CONTEXT86
*context
= ptrs
->ContextRecord
;
870 if (wine_ldt_is_system(context
->SegCs
) &&
871 (record
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
||
872 record
->ExceptionCode
== EXCEPTION_PRIV_INSTRUCTION
))
874 if (__wine_emulate_instruction( record
, context
) == ExceptionContinueExecution
)
875 return EXCEPTION_CONTINUE_EXECUTION
;
877 return EXCEPTION_CONTINUE_SEARCH
;
881 /***********************************************************************
882 * DOS3Call (KERNEL.102)
884 void WINAPI
DOS3Call( CONTEXT86
*context
)
886 __wine_call_int_handler( context
, 0x21 );
890 /***********************************************************************
891 * NetBIOSCall (KERNEL.103)
893 void WINAPI
NetBIOSCall16( CONTEXT86
*context
)
895 __wine_call_int_handler( context
, 0x5c );
899 /***********************************************************************
900 * GetSetKernelDOSProc (KERNEL.311)
902 FARPROC16 WINAPI
GetSetKernelDOSProc16( FARPROC16 DosProc
)
904 FIXME("(DosProc=%p): stub\n", DosProc
);