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"
33 #include "wine/winuser16.h"
35 #include "wine/debug.h"
36 #include "kernel_private.h"
37 #include "kernel16_private.h"
38 #include "wine/exception.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(int);
41 WINE_DECLARE_DEBUG_CHANNEL(io
);
43 /* macros to set parts of a DWORD */
44 #define SET_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD(val))
45 #define SET_LOBYTE(dw,val) ((dw) = ((dw) & 0xffffff00) | LOBYTE(val))
46 #define ADD_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
47 #define ISV86(context) ((context)->EFlags & 0x00020000)
49 static inline void add_stack( CONTEXT86
*context
, int offset
)
51 if (ISV86(context
) || !IS_SELECTOR_32BIT(context
->SegSs
))
52 ADD_LOWORD( context
->Esp
, offset
);
54 context
->Esp
+= offset
;
57 static inline void *make_ptr( CONTEXT86
*context
, DWORD seg
, DWORD off
, int long_addr
)
59 if (ISV86(context
)) return (void *)((seg
<< 4) + LOWORD(off
));
60 if (wine_ldt_is_system(seg
)) return (void *)off
;
61 if (!long_addr
) off
= LOWORD(off
);
62 return (char *) MapSL( MAKESEGPTR( seg
, 0 ) ) + off
;
65 static inline void *get_stack( CONTEXT86
*context
)
67 if (ISV86(context
)) return (void *)((context
->SegSs
<< 4) + LOWORD(context
->Esp
));
68 return wine_ldt_get_ptr( context
->SegSs
, context
->Esp
);
79 static LDT_ENTRY idt
[256];
81 static inline struct idtr
get_idtr(void)
84 #if defined(__i386__) && defined(__GNUC__)
85 __asm__( "sidtl %0" : "=m" (ret
) );
87 ret
.base
= (BYTE
*)idt
;
88 ret
.limit
= sizeof(idt
) - 1;
94 /***********************************************************************
95 * INSTR_ReplaceSelector
97 * Try to replace an invalid selector by a valid one.
98 * The only selector where it is allowed to do "mov ax,40;mov es,ax"
99 * is the so called 'bimodal' selector 0x40, which points to the BIOS
100 * data segment. Used by (at least) Borland products (and programs compiled
101 * using Borland products).
103 * See Undocumented Windows, Chapter 5, __0040.
105 static BOOL
INSTR_ReplaceSelector( CONTEXT86
*context
, WORD
*sel
)
109 static WORD sys_timer
= 0;
112 if (!winedos
.BiosTick
) load_winedos();
113 if (winedos
.BiosTick
)
114 sys_timer
= CreateSystemTimer( 55, winedos
.BiosTick
);
116 *sel
= DOSMEM_BiosDataSeg
;
119 return FALSE
; /* Can't replace selector, crashdump */
123 /* store an operand into a register */
124 static void store_reg( CONTEXT86
*context
, BYTE regmodrm
, const BYTE
*addr
, int long_op
)
126 switch((regmodrm
>> 3) & 7)
129 if (long_op
) context
->Eax
= *(const DWORD
*)addr
;
130 else SET_LOWORD(context
->Eax
, *(const WORD
*)addr
);
133 if (long_op
) context
->Ecx
= *(const DWORD
*)addr
;
134 else SET_LOWORD(context
->Ecx
, *(const WORD
*)addr
);
137 if (long_op
) context
->Edx
= *(const DWORD
*)addr
;
138 else SET_LOWORD(context
->Edx
, *(const WORD
*)addr
);
141 if (long_op
) context
->Ebx
= *(const DWORD
*)addr
;
142 else SET_LOWORD(context
->Ebx
, *(const WORD
*)addr
);
145 if (long_op
) context
->Esp
= *(const DWORD
*)addr
;
146 else SET_LOWORD(context
->Esp
, *(const WORD
*)addr
);
149 if (long_op
) context
->Ebp
= *(const DWORD
*)addr
;
150 else SET_LOWORD(context
->Ebp
, *(const WORD
*)addr
);
153 if (long_op
) context
->Esi
= *(const DWORD
*)addr
;
154 else SET_LOWORD(context
->Esi
, *(const WORD
*)addr
);
157 if (long_op
) context
->Edi
= *(const DWORD
*)addr
;
158 else SET_LOWORD(context
->Edi
, *(const WORD
*)addr
);
163 /***********************************************************************
164 * INSTR_GetOperandAddr
166 * Return the address of an instruction operand (from the mod/rm byte).
168 static BYTE
*INSTR_GetOperandAddr( CONTEXT86
*context
, BYTE
*instr
,
169 int long_addr
, int segprefix
, int *len
)
171 int mod
, rm
, base
= 0, index
= 0, ss
= 0, seg
= 0, off
;
174 #define GET_VAL(val,type) \
175 { *val = *(type *)instr; instr += sizeof(type); *len += sizeof(type); }
178 GET_VAL( &mod
, BYTE
);
186 case 0: return (BYTE
*)&context
->Eax
;
187 case 1: return (BYTE
*)&context
->Ecx
;
188 case 2: return (BYTE
*)&context
->Edx
;
189 case 3: return (BYTE
*)&context
->Ebx
;
190 case 4: return (BYTE
*)&context
->Esp
;
191 case 5: return (BYTE
*)&context
->Ebp
;
192 case 6: return (BYTE
*)&context
->Esi
;
193 case 7: return (BYTE
*)&context
->Edi
;
202 GET_VAL( &sib
, BYTE
);
207 case 0: index
= context
->Eax
; break;
208 case 1: index
= context
->Ecx
; break;
209 case 2: index
= context
->Edx
; break;
210 case 3: index
= context
->Ebx
; break;
211 case 4: index
= 0; break;
212 case 5: index
= context
->Ebp
; break;
213 case 6: index
= context
->Esi
; break;
214 case 7: index
= context
->Edi
; break;
220 case 0: base
= context
->Eax
; seg
= context
->SegDs
; break;
221 case 1: base
= context
->Ecx
; seg
= context
->SegDs
; break;
222 case 2: base
= context
->Edx
; seg
= context
->SegDs
; break;
223 case 3: base
= context
->Ebx
; seg
= context
->SegDs
; break;
224 case 4: base
= context
->Esp
; seg
= context
->SegSs
; break;
225 case 5: base
= context
->Ebp
; seg
= context
->SegSs
; break;
226 case 6: base
= context
->Esi
; seg
= context
->SegDs
; break;
227 case 7: base
= context
->Edi
; seg
= context
->SegDs
; break;
232 if (rm
== 5) /* special case: ds:(disp32) */
234 GET_VAL( &base
, DWORD
);
235 seg
= context
->SegDs
;
239 case 1: /* 8-bit disp */
240 GET_VAL( &off
, BYTE
);
241 base
+= (signed char)off
;
244 case 2: /* 32-bit disp */
245 GET_VAL( &off
, DWORD
);
246 base
+= (signed long)off
;
250 else /* short address */
254 case 0: /* ds:(bx,si) */
255 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Esi
);
256 seg
= context
->SegDs
;
258 case 1: /* ds:(bx,di) */
259 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Edi
);
260 seg
= context
->SegDs
;
262 case 2: /* ss:(bp,si) */
263 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Esi
);
264 seg
= context
->SegSs
;
266 case 3: /* ss:(bp,di) */
267 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Edi
);
268 seg
= context
->SegSs
;
270 case 4: /* ds:(si) */
271 base
= LOWORD(context
->Esi
);
272 seg
= context
->SegDs
;
274 case 5: /* ds:(di) */
275 base
= LOWORD(context
->Edi
);
276 seg
= context
->SegDs
;
278 case 6: /* ss:(bp) */
279 base
= LOWORD(context
->Ebp
);
280 seg
= context
->SegSs
;
282 case 7: /* ds:(bx) */
283 base
= LOWORD(context
->Ebx
);
284 seg
= context
->SegDs
;
291 if (rm
== 6) /* special case: ds:(disp16) */
293 GET_VAL( &base
, WORD
);
294 seg
= context
->SegDs
;
298 case 1: /* 8-bit disp */
299 GET_VAL( &off
, BYTE
);
300 base
+= (signed char)off
;
303 case 2: /* 16-bit disp */
304 GET_VAL( &off
, WORD
);
305 base
+= (signed short)off
;
310 if (segprefix
!= -1) seg
= segprefix
;
312 /* Make sure the segment and offset are valid */
313 if (wine_ldt_is_system(seg
)) return (BYTE
*)(base
+ (index
<< ss
));
314 if ((seg
& 7) != 7) return NULL
;
315 wine_ldt_get_entry( seg
, &entry
);
316 if (wine_ldt_is_empty( &entry
)) return NULL
;
317 if (wine_ldt_get_limit(&entry
) < (base
+ (index
<< ss
))) return NULL
;
318 return (BYTE
*)wine_ldt_get_base(&entry
) + base
+ (index
<< ss
);
323 /***********************************************************************
326 * Emulate the LDS (and LES,LFS,etc.) instruction.
328 static BOOL
INSTR_EmulateLDS( CONTEXT86
*context
, BYTE
*instr
, int long_op
,
329 int long_addr
, int segprefix
, int *len
)
332 BYTE
*regmodrm
= instr
+ 1 + (*instr
== 0x0f);
333 BYTE
*addr
= INSTR_GetOperandAddr( context
, regmodrm
,
334 long_addr
, segprefix
, len
);
336 return FALSE
; /* Unable to emulate it */
337 seg
= *(WORD
*)(addr
+ (long_op
? 4 : 2));
339 if (!INSTR_ReplaceSelector( context
, &seg
))
340 return FALSE
; /* Unable to emulate it */
342 /* Now store the offset in the correct register */
344 store_reg( context
, *regmodrm
, addr
, long_op
);
346 /* Store the correct segment in the segment register */
350 case 0xc4: context
->SegEs
= seg
; break; /* les */
351 case 0xc5: context
->SegDs
= seg
; break; /* lds */
352 case 0x0f: switch(instr
[1])
354 case 0xb2: context
->SegSs
= seg
; break; /* lss */
355 case 0xb4: context
->SegFs
= seg
; break; /* lfs */
356 case 0xb5: context
->SegGs
= seg
; break; /* lgs */
361 /* Add the opcode size to the total length */
363 *len
+= 1 + (*instr
== 0x0f);
367 /***********************************************************************
370 * input on an I/O port
372 static DWORD
INSTR_inport( WORD port
, int size
, CONTEXT86
*context
)
376 if (!winedos
.inport
) load_winedos();
377 if (winedos
.inport
) res
= winedos
.inport( port
, size
);
384 TRACE_(io
)( "0x%x < %02x @ %04x:%04x\n", port
, LOBYTE(res
),
385 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
388 TRACE_(io
)( "0x%x < %04x @ %04x:%04x\n", port
, LOWORD(res
),
389 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
392 TRACE_(io
)( "0x%x < %08x @ %04x:%04x\n", port
, res
,
393 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
401 /***********************************************************************
404 * output on an I/O port
406 static void INSTR_outport( WORD port
, int size
, DWORD val
, CONTEXT86
*context
)
408 if (!winedos
.outport
) load_winedos();
409 if (winedos
.outport
) winedos
.outport( port
, size
, val
);
416 TRACE_(io
)("0x%x > %02x @ %04x:%04x\n", port
, LOBYTE(val
),
417 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
420 TRACE_(io
)("0x%x > %04x @ %04x:%04x\n", port
, LOWORD(val
),
421 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
424 TRACE_(io
)("0x%x > %08x @ %04x:%04x\n", port
, val
,
425 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
432 /***********************************************************************
433 * __wine_emulate_instruction
435 * Emulate a privileged instruction.
436 * Returns exception continuation status.
438 DWORD
__wine_emulate_instruction( EXCEPTION_RECORD
*rec
, CONTEXT86
*context
)
440 int prefix
, segprefix
, prefixlen
, len
, repX
, long_op
, long_addr
;
443 long_op
= long_addr
= (!ISV86(context
) && IS_SELECTOR_32BIT(context
->SegCs
));
444 instr
= make_ptr( context
, context
->SegCs
, context
->Eip
, TRUE
);
445 if (!instr
) return ExceptionContinueSearch
;
447 /* First handle any possible prefix */
449 segprefix
= -1; /* no prefix */
458 segprefix
= context
->SegCs
;
461 segprefix
= context
->SegSs
;
464 segprefix
= context
->SegDs
;
467 segprefix
= context
->SegEs
;
470 segprefix
= context
->SegFs
;
473 segprefix
= context
->SegGs
;
476 long_op
= !long_op
; /* opcode size prefix */
479 long_addr
= !long_addr
; /* addr size prefix */
481 case 0xf0: /* lock */
483 case 0xf2: /* repne */
486 case 0xf3: /* repe */
490 prefix
= 0; /* no more prefixes */
500 /* Now look at the actual instruction */
504 case 0x07: /* pop es */
505 case 0x17: /* pop ss */
506 case 0x1f: /* pop ds */
508 WORD seg
= *(WORD
*)get_stack( context
);
509 if (INSTR_ReplaceSelector( context
, &seg
))
513 case 0x07: context
->SegEs
= seg
; break;
514 case 0x17: context
->SegSs
= seg
; break;
515 case 0x1f: context
->SegDs
= seg
; break;
517 add_stack(context
, long_op
? 4 : 2);
518 context
->Eip
+= prefixlen
+ 1;
519 return ExceptionContinueExecution
;
522 break; /* Unable to emulate it */
524 case 0x0f: /* extended instruction */
527 case 0x22: /* mov eax, crX */
531 ERR("mov eax,cr0 at 0x%08x, EAX=0x%08x\n",
532 context
->Eip
,context
->Eax
);
533 context
->Eip
+= prefixlen
+3;
534 return ExceptionContinueExecution
;
536 break; /*fallthrough to bad instruction handling */
538 break; /*fallthrough to bad instruction handling */
539 case 0x20: /* mov crX, eax */
542 case 0xe0: /* mov cr4, eax */
543 /* CR4 register . See linux/arch/i386/mm/init.c, X86_CR4_ defs
544 * bit 0: VME Virtual Mode Exception ?
545 * bit 1: PVI Protected mode Virtual Interrupt
546 * bit 2: TSD Timestamp disable
547 * bit 3: DE Debugging extensions
548 * bit 4: PSE Page size extensions
549 * bit 5: PAE Physical address extension
550 * bit 6: MCE Machine check enable
551 * bit 7: PGE Enable global pages
552 * bit 8: PCE Enable performance counters at IPL3
554 ERR("mov cr4,eax at 0x%08x\n",context
->Eip
);
556 context
->Eip
+= prefixlen
+3;
557 return ExceptionContinueExecution
;
558 case 0xc0: /* mov cr0, eax */
559 ERR("mov cr0,eax at 0x%08x\n",context
->Eip
);
560 context
->Eax
= 0x10; /* FIXME: set more bits ? */
561 context
->Eip
+= prefixlen
+3;
562 return ExceptionContinueExecution
;
563 default: /* fallthrough to illegal instruction */
566 /* fallthrough to illegal instruction */
568 case 0x21: /* mov drX, eax */
571 case 0xc8: /* mov dr1, eax */
572 TRACE("mov dr1,eax at 0x%08x\n",context
->Eip
);
573 context
->Eax
= context
->Dr1
;
574 context
->Eip
+= prefixlen
+3;
575 return ExceptionContinueExecution
;
576 case 0xf8: /* mov dr7, eax */
577 TRACE("mov dr7,eax at 0x%08x\n",context
->Eip
);
578 context
->Eax
= 0x400;
579 context
->Eip
+= prefixlen
+3;
580 return ExceptionContinueExecution
;
582 ERR("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
583 /* fallthrough to illegal instruction */
585 case 0x23: /* mov eax drX */
588 case 0xc8: /* mov eax, dr1 */
589 context
->Dr1
= context
->Eax
;
590 context
->Eip
+= prefixlen
+3;
591 return ExceptionContinueExecution
;
593 ERR("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
594 /* fallthrough to illegal instruction */
596 case 0xa1: /* pop fs */
598 WORD seg
= *(WORD
*)get_stack( context
);
599 if (INSTR_ReplaceSelector( context
, &seg
))
601 context
->SegFs
= seg
;
602 add_stack(context
, long_op
? 4 : 2);
603 context
->Eip
+= prefixlen
+ 2;
604 return ExceptionContinueExecution
;
608 case 0xa9: /* pop gs */
610 WORD seg
= *(WORD
*)get_stack( context
);
611 if (INSTR_ReplaceSelector( context
, &seg
))
613 context
->SegGs
= seg
;
614 add_stack(context
, long_op
? 4 : 2);
615 context
->Eip
+= prefixlen
+ 2;
616 return ExceptionContinueExecution
;
620 case 0xb2: /* lss addr,reg */
621 case 0xb4: /* lfs addr,reg */
622 case 0xb5: /* lgs addr,reg */
623 if (INSTR_EmulateLDS( context
, instr
, long_op
,
624 long_addr
, segprefix
, &len
))
626 context
->Eip
+= prefixlen
+ len
;
627 return ExceptionContinueExecution
;
631 break; /* Unable to emulate it */
633 case 0x6c: /* insb */
634 case 0x6d: /* insw/d */
635 case 0x6e: /* outsb */
636 case 0x6f: /* outsw/d */
638 int typ
= *instr
; /* Just in case it's overwritten. */
639 int outp
= (typ
>= 0x6e);
640 unsigned long count
= repX
?
641 (long_addr
? context
->Ecx
: LOWORD(context
->Ecx
)) : 1;
642 int opsize
= (typ
& 1) ? (long_op
? 4 : 2) : 1;
643 int step
= (context
->EFlags
& 0x400) ? -opsize
: +opsize
;
644 int seg
= outp
? context
->SegDs
: context
->SegEs
; /* FIXME: is this right? */
647 /* FIXME: Check segment is readable. */
650 /* FIXME: Check segment is writable. */
655 if (long_addr
) context
->Ecx
= 0;
656 else SET_LOWORD(context
->Ecx
,0);
662 WORD dx
= LOWORD(context
->Edx
);
665 data
= make_ptr( context
, seg
, context
->Esi
, long_addr
);
666 if (long_addr
) context
->Esi
+= step
;
667 else ADD_LOWORD(context
->Esi
,step
);
671 data
= make_ptr( context
, seg
, context
->Edi
, long_addr
);
672 if (long_addr
) context
->Edi
+= step
;
673 else ADD_LOWORD(context
->Edi
,step
);
679 *(BYTE
*)data
= INSTR_inport( dx
, 1, context
);
683 *(DWORD
*)data
= INSTR_inport( dx
, 4, context
);
685 *(WORD
*)data
= INSTR_inport( dx
, 2, context
);
688 INSTR_outport( dx
, 1, *(BYTE
*)data
, context
);
692 INSTR_outport( dx
, 4, *(DWORD
*)data
, context
);
694 INSTR_outport( dx
, 2, *(WORD
*)data
, context
);
698 context
->Eip
+= prefixlen
+ 1;
700 return ExceptionContinueExecution
;
702 case 0x8b: /* mov Ev, Gv */
704 BYTE
*addr
= INSTR_GetOperandAddr(context
, instr
+ 1, long_addr
,
706 struct idtr idtr
= get_idtr();
707 unsigned int offset
= addr
- idtr
.base
;
709 if (offset
<= idtr
.limit
+ 1 - (long_op
? 4 : 2))
711 idt
[1].LimitLow
= 0x100; /* FIXME */
712 idt
[2].LimitLow
= 0x11E; /* FIXME */
713 idt
[3].LimitLow
= 0x500; /* FIXME */
714 store_reg( context
, instr
[1], (BYTE
*)idt
+ offset
, long_op
);
715 context
->Eip
+= prefixlen
+ len
+ 1;
716 return ExceptionContinueExecution
;
719 break; /* Unable to emulate it */
721 case 0x8e: /* mov XX,segment_reg */
724 BYTE
*addr
= INSTR_GetOperandAddr(context
, instr
+ 1,
725 long_addr
, segprefix
, &len
);
727 break; /* Unable to emulate it */
729 if (!INSTR_ReplaceSelector( context
, &seg
))
730 break; /* Unable to emulate it */
732 switch((instr
[1] >> 3) & 7)
735 context
->SegEs
= seg
;
736 context
->Eip
+= prefixlen
+ len
+ 1;
737 return ExceptionContinueExecution
;
741 context
->SegSs
= seg
;
742 context
->Eip
+= prefixlen
+ len
+ 1;
743 return ExceptionContinueExecution
;
745 context
->SegDs
= seg
;
746 context
->Eip
+= prefixlen
+ len
+ 1;
747 return ExceptionContinueExecution
;
749 context
->SegFs
= seg
;
750 context
->Eip
+= prefixlen
+ len
+ 1;
751 return ExceptionContinueExecution
;
753 context
->SegGs
= seg
;
754 context
->Eip
+= prefixlen
+ len
+ 1;
755 return ExceptionContinueExecution
;
761 break; /* Unable to emulate it */
763 case 0xc4: /* les addr,reg */
764 case 0xc5: /* lds addr,reg */
765 if (INSTR_EmulateLDS( context
, instr
, long_op
,
766 long_addr
, segprefix
, &len
))
768 context
->Eip
+= prefixlen
+ len
;
769 return ExceptionContinueExecution
;
771 break; /* Unable to emulate it */
773 case 0xcd: /* int <XX> */
774 if (!winedos
.EmulateInterruptPM
) load_winedos();
775 if (winedos
.EmulateInterruptPM
)
777 context
->Eip
+= prefixlen
+ 2;
778 if (winedos
.EmulateInterruptPM( context
, instr
[1] )) return ExceptionContinueExecution
;
779 context
->Eip
-= prefixlen
+ 2; /* restore eip */
781 break; /* Unable to emulate it */
783 case 0xcf: /* iret */
784 if (wine_ldt_is_system(context
->SegCs
)) break; /* don't emulate it in 32-bit code */
787 DWORD
*stack
= get_stack( context
);
788 context
->Eip
= *stack
++;
789 context
->SegCs
= *stack
++;
790 context
->EFlags
= *stack
;
791 add_stack(context
, 3*sizeof(DWORD
)); /* Pop the return address and flags */
795 WORD
*stack
= get_stack( context
);
796 context
->Eip
= *stack
++;
797 context
->SegCs
= *stack
++;
798 SET_LOWORD(context
->EFlags
,*stack
);
799 add_stack(context
, 3*sizeof(WORD
)); /* Pop the return address and flags */
801 return ExceptionContinueExecution
;
803 case 0xe4: /* inb al,XX */
804 SET_LOBYTE(context
->Eax
,INSTR_inport( instr
[1], 1, context
));
805 context
->Eip
+= prefixlen
+ 2;
806 return ExceptionContinueExecution
;
808 case 0xe5: /* in (e)ax,XX */
810 context
->Eax
= INSTR_inport( instr
[1], 4, context
);
812 SET_LOWORD(context
->Eax
, INSTR_inport( instr
[1], 2, context
));
813 context
->Eip
+= prefixlen
+ 2;
814 return ExceptionContinueExecution
;
816 case 0xe6: /* outb XX,al */
817 INSTR_outport( instr
[1], 1, LOBYTE(context
->Eax
), context
);
818 context
->Eip
+= prefixlen
+ 2;
819 return ExceptionContinueExecution
;
821 case 0xe7: /* out XX,(e)ax */
823 INSTR_outport( instr
[1], 4, context
->Eax
, context
);
825 INSTR_outport( instr
[1], 2, LOWORD(context
->Eax
), context
);
826 context
->Eip
+= prefixlen
+ 2;
827 return ExceptionContinueExecution
;
829 case 0xec: /* inb al,dx */
830 SET_LOBYTE(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 1, context
) );
831 context
->Eip
+= prefixlen
+ 1;
832 return ExceptionContinueExecution
;
834 case 0xed: /* in (e)ax,dx */
836 context
->Eax
= INSTR_inport( LOWORD(context
->Edx
), 4, context
);
838 SET_LOWORD(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 2, context
));
839 context
->Eip
+= prefixlen
+ 1;
840 return ExceptionContinueExecution
;
842 case 0xee: /* outb dx,al */
843 INSTR_outport( LOWORD(context
->Edx
), 1, LOBYTE(context
->Eax
), context
);
844 context
->Eip
+= prefixlen
+ 1;
845 return ExceptionContinueExecution
;
847 case 0xef: /* out dx,(e)ax */
849 INSTR_outport( LOWORD(context
->Edx
), 4, context
->Eax
, context
);
851 INSTR_outport( LOWORD(context
->Edx
), 2, LOWORD(context
->Eax
), context
);
852 context
->Eip
+= prefixlen
+ 1;
853 return ExceptionContinueExecution
;
856 get_vm86_teb_info()->dpmi_vif
= 0;
857 context
->Eip
+= prefixlen
+ 1;
858 return ExceptionContinueExecution
;
861 get_vm86_teb_info()->dpmi_vif
= 1;
862 context
->Eip
+= prefixlen
+ 1;
863 if (get_vm86_teb_info()->vm86_pending
)
865 get_vm86_teb_info()->vm86_pending
= 0;
866 rec
->ExceptionCode
= EXCEPTION_VM86_STI
;
867 break; /* Handle the pending event. */
869 return ExceptionContinueExecution
;
871 return ExceptionContinueSearch
; /* Unable to emulate it */
875 /***********************************************************************
876 * INSTR_vectored_handler
878 * Vectored exception handler used to emulate protected instructions
881 LONG CALLBACK
INSTR_vectored_handler( EXCEPTION_POINTERS
*ptrs
)
883 EXCEPTION_RECORD
*record
= ptrs
->ExceptionRecord
;
884 CONTEXT86
*context
= ptrs
->ContextRecord
;
886 if (wine_ldt_is_system(context
->SegCs
) &&
887 (record
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
||
888 record
->ExceptionCode
== EXCEPTION_PRIV_INSTRUCTION
))
890 if (__wine_emulate_instruction( record
, context
) == ExceptionContinueExecution
)
891 return EXCEPTION_CONTINUE_EXECUTION
;
893 return EXCEPTION_CONTINUE_SEARCH
;
897 /***********************************************************************
898 * INSTR_CallBuiltinHandler
900 static void INSTR_CallBuiltinHandler( CONTEXT86
*context
, BYTE intnum
)
902 if (!winedos
.CallBuiltinHandler
) load_winedos();
903 if (winedos
.CallBuiltinHandler
) winedos
.CallBuiltinHandler( context
, intnum
);
907 /***********************************************************************
908 * DOS3Call (KERNEL.102)
910 void WINAPI
DOS3Call( CONTEXT86
*context
)
912 INSTR_CallBuiltinHandler( context
, 0x21 );
916 /***********************************************************************
917 * NetBIOSCall (KERNEL.103)
919 void WINAPI
NetBIOSCall16( CONTEXT86
*context
)
921 INSTR_CallBuiltinHandler( context
, 0x5c );
925 /***********************************************************************
926 * GetSetKernelDOSProc (KERNEL.311)
928 FARPROC16 WINAPI
GetSetKernelDOSProc16( FARPROC16 DosProc
)
930 FIXME("(DosProc=%p): stub\n", DosProc
);
934 #endif /* __i386__ */