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
28 #include "wine/winuser16.h"
30 #include "wine/debug.h"
31 #include "kernel16_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(int);
35 WINE_DECLARE_DEBUG_CHANNEL(io
);
37 /* macros to set parts of a DWORD */
38 #define SET_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD(val))
39 #define SET_LOBYTE(dw,val) ((dw) = ((dw) & 0xffffff00) | LOBYTE(val))
40 #define ADD_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
42 static inline void add_stack( CONTEXT
*context
, int offset
)
44 if (!IS_SELECTOR_32BIT(context
->SegSs
))
45 ADD_LOWORD( context
->Esp
, offset
);
47 context
->Esp
+= offset
;
50 static inline void *make_ptr( CONTEXT
*context
, DWORD seg
, DWORD off
, int long_addr
)
52 if (ldt_is_system(seg
)) return (void *)off
;
53 if (!long_addr
) off
= LOWORD(off
);
54 return (char *) MapSL( MAKESEGPTR( seg
, 0 ) ) + off
;
57 static inline void *get_stack( CONTEXT
*context
)
59 return ldt_get_ptr( context
->SegSs
, context
->Esp
);
70 static LDT_ENTRY idt
[256];
72 static inline struct idtr
get_idtr(void)
75 #if defined(__i386__) && defined(__GNUC__)
76 __asm__( "sidtl %0" : "=m" (ret
) );
78 ret
.base
= (BYTE
*)idt
;
79 ret
.limit
= sizeof(idt
) - 1;
85 /***********************************************************************
86 * INSTR_ReplaceSelector
88 * Try to replace an invalid selector by a valid one.
89 * The only selector where it is allowed to do "mov ax,40;mov es,ax"
90 * is the so called 'bimodal' selector 0x40, which points to the BIOS
91 * data segment. Used by (at least) Borland products (and programs compiled
92 * using Borland products).
94 * See Undocumented Windows, Chapter 5, __0040.
96 static BOOL
INSTR_ReplaceSelector( CONTEXT
*context
, WORD
*sel
)
100 DOSVM_start_bios_timer();
101 *sel
= DOSMEM_BiosDataSeg
;
104 return FALSE
; /* Can't replace selector, crashdump */
108 /* store an operand into a register */
109 static void store_reg_word( CONTEXT
*context
, BYTE regmodrm
, const BYTE
*addr
, int long_op
)
111 switch((regmodrm
>> 3) & 7)
114 if (long_op
) context
->Eax
= *(const DWORD
*)addr
;
115 else SET_LOWORD(context
->Eax
, *(const WORD
*)addr
);
118 if (long_op
) context
->Ecx
= *(const DWORD
*)addr
;
119 else SET_LOWORD(context
->Ecx
, *(const WORD
*)addr
);
122 if (long_op
) context
->Edx
= *(const DWORD
*)addr
;
123 else SET_LOWORD(context
->Edx
, *(const WORD
*)addr
);
126 if (long_op
) context
->Ebx
= *(const DWORD
*)addr
;
127 else SET_LOWORD(context
->Ebx
, *(const WORD
*)addr
);
130 if (long_op
) context
->Esp
= *(const DWORD
*)addr
;
131 else SET_LOWORD(context
->Esp
, *(const WORD
*)addr
);
134 if (long_op
) context
->Ebp
= *(const DWORD
*)addr
;
135 else SET_LOWORD(context
->Ebp
, *(const WORD
*)addr
);
138 if (long_op
) context
->Esi
= *(const DWORD
*)addr
;
139 else SET_LOWORD(context
->Esi
, *(const WORD
*)addr
);
142 if (long_op
) context
->Edi
= *(const DWORD
*)addr
;
143 else SET_LOWORD(context
->Edi
, *(const WORD
*)addr
);
148 /* store an operand into a byte register */
149 static void store_reg_byte( CONTEXT
*context
, BYTE regmodrm
, const BYTE
*addr
)
151 switch((regmodrm
>> 3) & 7)
153 case 0: context
->Eax
= (context
->Eax
& 0xffffff00) | *addr
; break;
154 case 1: context
->Ecx
= (context
->Ecx
& 0xffffff00) | *addr
; break;
155 case 2: context
->Edx
= (context
->Edx
& 0xffffff00) | *addr
; break;
156 case 3: context
->Ebx
= (context
->Ebx
& 0xffffff00) | *addr
; break;
157 case 4: context
->Eax
= (context
->Eax
& 0xffff00ff) | (*addr
<< 8); break;
158 case 5: context
->Ecx
= (context
->Ecx
& 0xffff00ff) | (*addr
<< 8); break;
159 case 6: context
->Edx
= (context
->Edx
& 0xffff00ff) | (*addr
<< 8); break;
160 case 7: context
->Ebx
= (context
->Ebx
& 0xffff00ff) | (*addr
<< 8); break;
164 /***********************************************************************
165 * INSTR_GetOperandAddr
167 * Return the address of an instruction operand (from the mod/rm byte).
169 static BYTE
*INSTR_GetOperandAddr( CONTEXT
*context
, BYTE
*instr
,
170 int long_addr
, int segprefix
, int *len
)
172 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
);
205 switch((sib
>> 3) & 7)
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 (ldt_is_system(seg
)) return (BYTE
*)(base
+ (index
<< ss
));
314 if ((seg
& 7) != 7) return NULL
;
315 if (!ldt_is_valid( seg
)) return NULL
;
316 if (ldt_get_limit( seg
) < (base
+ (index
<< ss
))) return NULL
;
317 return (BYTE
*)ldt_get_base( seg
) + base
+ (index
<< ss
);
322 /***********************************************************************
325 * Emulate the LDS (and LES,LFS,etc.) instruction.
327 static BOOL
INSTR_EmulateLDS( CONTEXT
*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_word( 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
, CONTEXT
*context
)
373 DWORD res
= DOSVM_inport( port
, size
);
380 TRACE_(io
)( "0x%x < %02x @ %04x:%04x\n", port
, LOBYTE(res
),
381 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
384 TRACE_(io
)( "0x%x < %04x @ %04x:%04x\n", port
, LOWORD(res
),
385 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
388 TRACE_(io
)( "0x%x < %08lx @ %04x:%04x\n", port
, res
,
389 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
397 /***********************************************************************
400 * output on an I/O port
402 static void INSTR_outport( WORD port
, int size
, DWORD val
, CONTEXT
*context
)
404 DOSVM_outport( port
, size
, val
);
411 TRACE_(io
)("0x%x > %02x @ %04x:%04x\n", port
, LOBYTE(val
),
412 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
415 TRACE_(io
)("0x%x > %04x @ %04x:%04x\n", port
, LOWORD(val
),
416 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
419 TRACE_(io
)("0x%x > %08lx @ %04x:%04x\n", port
, val
,
420 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
427 /***********************************************************************
428 * __wine_emulate_instruction
430 * Emulate a privileged instruction.
431 * Returns exception continuation status.
433 DWORD
__wine_emulate_instruction( EXCEPTION_RECORD
*rec
, CONTEXT
*context
)
435 int prefix
, segprefix
, prefixlen
, len
, repX
, long_op
, long_addr
;
438 long_op
= long_addr
= IS_SELECTOR_32BIT(context
->SegCs
);
439 instr
= make_ptr( context
, context
->SegCs
, context
->Eip
, TRUE
);
440 if (!instr
) return ExceptionContinueSearch
;
442 /* First handle any possible prefix */
444 segprefix
= -1; /* no prefix */
453 segprefix
= context
->SegCs
;
456 segprefix
= context
->SegSs
;
459 segprefix
= context
->SegDs
;
462 segprefix
= context
->SegEs
;
465 segprefix
= context
->SegFs
;
468 segprefix
= context
->SegGs
;
471 long_op
= !long_op
; /* opcode size prefix */
474 long_addr
= !long_addr
; /* addr size prefix */
476 case 0xf0: /* lock */
478 case 0xf2: /* repne */
481 case 0xf3: /* repe */
485 prefix
= 0; /* no more prefixes */
495 /* Now look at the actual instruction */
499 case 0x07: /* pop es */
500 case 0x17: /* pop ss */
501 case 0x1f: /* pop ds */
503 WORD seg
= *(WORD
*)get_stack( context
);
504 if (INSTR_ReplaceSelector( context
, &seg
))
508 case 0x07: context
->SegEs
= seg
; break;
509 case 0x17: context
->SegSs
= seg
; break;
510 case 0x1f: context
->SegDs
= seg
; break;
512 add_stack(context
, long_op
? 4 : 2);
513 context
->Eip
+= prefixlen
+ 1;
514 return ExceptionContinueExecution
;
517 break; /* Unable to emulate it */
519 case 0x0f: /* extended instruction */
522 case 0x22: /* mov %eax, %crX */
526 FIXME("mov %%eax, %%cr0 at 0x%08lx, EAX=0x%08lx\n",
527 context
->Eip
,context
->Eax
);
528 context
->Eip
+= prefixlen
+3;
529 return ExceptionContinueExecution
;
531 break; /* Fallthrough to bad instruction handling */
533 break; /* Fallthrough to bad instruction handling */
534 case 0x20: /* mov %crX, %eax */
537 case 0xe0: /* mov %cr4, %eax */
538 /* CR4 register: See linux/arch/i386/mm/init.c, X86_CR4_ defs
539 * bit 0: VME Virtual Mode Exception ?
540 * bit 1: PVI Protected mode Virtual Interrupt
541 * bit 2: TSD Timestamp disable
542 * bit 3: DE Debugging extensions
543 * bit 4: PSE Page size extensions
544 * bit 5: PAE Physical address extension
545 * bit 6: MCE Machine check enable
546 * bit 7: PGE Enable global pages
547 * bit 8: PCE Enable performance counters at IPL3
549 FIXME("mov %%cr4, %%eax at 0x%08lx\n",context
->Eip
);
551 context
->Eip
+= prefixlen
+3;
552 return ExceptionContinueExecution
;
553 case 0xc0: /* mov %cr0, %eax */
554 FIXME("mov %%cr0, %%eax at 0x%08lx\n",context
->Eip
);
555 context
->Eax
= 0x10; /* FIXME: set more bits ? */
556 context
->Eip
+= prefixlen
+3;
557 return ExceptionContinueExecution
;
558 default: /* Fallthrough to illegal instruction */
561 /* Fallthrough to illegal instruction */
563 case 0x21: /* mov %drX, %eax */
566 case 0xc8: /* mov %dr1, %eax */
567 TRACE("mov %%dr1, %%eax at 0x%08lx\n",context
->Eip
);
568 context
->Eax
= context
->Dr1
;
569 context
->Eip
+= prefixlen
+3;
570 return ExceptionContinueExecution
;
571 case 0xf8: /* mov %dr7, %eax */
572 TRACE("mov %%dr7, %%eax at 0x%08lx\n",context
->Eip
);
573 context
->Eax
= 0x400;
574 context
->Eip
+= prefixlen
+3;
575 return ExceptionContinueExecution
;
577 FIXME("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
578 /* fallthrough to illegal instruction */
580 case 0x23: /* mov %eax, %drX */
583 case 0xc8: /* mov %eax, %dr1 */
584 context
->Dr1
= context
->Eax
;
585 context
->Eip
+= prefixlen
+3;
586 return ExceptionContinueExecution
;
588 FIXME("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
589 /* fallthrough to illegal instruction */
591 case 0xa1: /* pop fs */
593 WORD seg
= *(WORD
*)get_stack( context
);
594 if (INSTR_ReplaceSelector( context
, &seg
))
596 context
->SegFs
= seg
;
597 add_stack(context
, long_op
? 4 : 2);
598 context
->Eip
+= prefixlen
+ 2;
599 return ExceptionContinueExecution
;
603 case 0xa9: /* pop gs */
605 WORD seg
= *(WORD
*)get_stack( context
);
606 if (INSTR_ReplaceSelector( context
, &seg
))
608 context
->SegGs
= seg
;
609 add_stack(context
, long_op
? 4 : 2);
610 context
->Eip
+= prefixlen
+ 2;
611 return ExceptionContinueExecution
;
615 case 0xb2: /* lss addr,reg */
616 case 0xb4: /* lfs addr,reg */
617 case 0xb5: /* lgs addr,reg */
618 if (INSTR_EmulateLDS( context
, instr
, long_op
,
619 long_addr
, segprefix
, &len
))
621 context
->Eip
+= prefixlen
+ len
;
622 return ExceptionContinueExecution
;
626 break; /* Unable to emulate it */
628 case 0x6c: /* insb */
629 case 0x6d: /* insw/d */
630 case 0x6e: /* outsb */
631 case 0x6f: /* outsw/d */
633 int typ
= *instr
; /* Just in case it's overwritten. */
634 int outp
= (typ
>= 0x6e);
635 unsigned long count
= repX
?
636 (long_addr
? context
->Ecx
: LOWORD(context
->Ecx
)) : 1;
637 int opsize
= (typ
& 1) ? (long_op
? 4 : 2) : 1;
638 int step
= (context
->EFlags
& 0x400) ? -opsize
: +opsize
;
643 /* Check if there is a segment prefix override and honour it */
644 seg
= segprefix
== -1 ? context
->SegDs
: segprefix
;
645 /* FIXME: Check segment is readable. */
649 seg
= context
->SegEs
;
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 0x8a: /* mov Eb, Gb */
703 case 0x8b: /* mov Ev, Gv */
705 BYTE
*data
= INSTR_GetOperandAddr(context
, instr
+ 1, long_addr
,
707 unsigned int data_size
= (*instr
== 0x8b) ? (long_op
? 4 : 2) : 1;
708 struct idtr idtr
= get_idtr();
709 unsigned int offset
= data
- idtr
.base
;
711 if (offset
<= idtr
.limit
+ 1 - data_size
)
713 idt
[1].LimitLow
= 0x100; /* FIXME */
714 idt
[2].LimitLow
= 0x11E; /* FIXME */
715 idt
[3].LimitLow
= 0x500; /* FIXME */
719 case 0x8a: store_reg_byte( context
, instr
[1], (BYTE
*)idt
+ offset
); break;
720 case 0x8b: store_reg_word( context
, instr
[1], (BYTE
*)idt
+ offset
, long_op
); break;
722 context
->Eip
+= prefixlen
+ len
+ 1;
723 return ExceptionContinueExecution
;
726 break; /* Unable to emulate it */
728 case 0x8e: /* mov XX,segment_reg */
731 BYTE
*addr
= INSTR_GetOperandAddr(context
, instr
+ 1,
732 long_addr
, segprefix
, &len
);
734 break; /* Unable to emulate it */
736 if (!INSTR_ReplaceSelector( context
, &seg
))
737 break; /* Unable to emulate it */
739 switch((instr
[1] >> 3) & 7)
742 context
->SegEs
= seg
;
743 context
->Eip
+= prefixlen
+ len
+ 1;
744 return ExceptionContinueExecution
;
748 context
->SegSs
= seg
;
749 context
->Eip
+= prefixlen
+ len
+ 1;
750 return ExceptionContinueExecution
;
752 context
->SegDs
= seg
;
753 context
->Eip
+= prefixlen
+ len
+ 1;
754 return ExceptionContinueExecution
;
756 context
->SegFs
= seg
;
757 context
->Eip
+= prefixlen
+ len
+ 1;
758 return ExceptionContinueExecution
;
760 context
->SegGs
= seg
;
761 context
->Eip
+= prefixlen
+ len
+ 1;
762 return ExceptionContinueExecution
;
768 break; /* Unable to emulate it */
770 case 0xc4: /* les addr,reg */
771 case 0xc5: /* lds addr,reg */
772 if (INSTR_EmulateLDS( context
, instr
, long_op
,
773 long_addr
, segprefix
, &len
))
775 context
->Eip
+= prefixlen
+ len
;
776 return ExceptionContinueExecution
;
778 break; /* Unable to emulate it */
780 case 0xcd: /* int <XX> */
781 context
->Eip
+= prefixlen
+ 2;
782 if (DOSVM_EmulateInterruptPM( context
, instr
[1] )) return ExceptionContinueExecution
;
783 context
->Eip
-= prefixlen
+ 2; /* restore eip */
784 break; /* Unable to emulate it */
786 case 0xcf: /* iret */
787 if (ldt_is_system(context
->SegCs
)) break; /* don't emulate it in 32-bit code */
790 DWORD
*stack
= get_stack( context
);
791 context
->Eip
= *stack
++;
792 context
->SegCs
= *stack
++;
793 context
->EFlags
= *stack
;
794 add_stack(context
, 3*sizeof(DWORD
)); /* Pop the return address and flags */
798 WORD
*stack
= get_stack( context
);
799 context
->Eip
= *stack
++;
800 context
->SegCs
= *stack
++;
801 SET_LOWORD(context
->EFlags
,*stack
);
802 add_stack(context
, 3*sizeof(WORD
)); /* Pop the return address and flags */
804 return ExceptionContinueExecution
;
806 case 0xe4: /* inb al,XX */
807 SET_LOBYTE(context
->Eax
,INSTR_inport( instr
[1], 1, context
));
808 context
->Eip
+= prefixlen
+ 2;
809 return ExceptionContinueExecution
;
811 case 0xe5: /* in (e)ax,XX */
813 context
->Eax
= INSTR_inport( instr
[1], 4, context
);
815 SET_LOWORD(context
->Eax
, INSTR_inport( instr
[1], 2, context
));
816 context
->Eip
+= prefixlen
+ 2;
817 return ExceptionContinueExecution
;
819 case 0xe6: /* outb XX,al */
820 INSTR_outport( instr
[1], 1, LOBYTE(context
->Eax
), context
);
821 context
->Eip
+= prefixlen
+ 2;
822 return ExceptionContinueExecution
;
824 case 0xe7: /* out XX,(e)ax */
826 INSTR_outport( instr
[1], 4, context
->Eax
, context
);
828 INSTR_outport( instr
[1], 2, LOWORD(context
->Eax
), context
);
829 context
->Eip
+= prefixlen
+ 2;
830 return ExceptionContinueExecution
;
832 case 0xec: /* inb al,dx */
833 SET_LOBYTE(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 1, context
) );
834 context
->Eip
+= prefixlen
+ 1;
835 return ExceptionContinueExecution
;
837 case 0xed: /* in (e)ax,dx */
839 context
->Eax
= INSTR_inport( LOWORD(context
->Edx
), 4, context
);
841 SET_LOWORD(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 2, context
));
842 context
->Eip
+= prefixlen
+ 1;
843 return ExceptionContinueExecution
;
845 case 0xee: /* outb dx,al */
846 INSTR_outport( LOWORD(context
->Edx
), 1, LOBYTE(context
->Eax
), context
);
847 context
->Eip
+= prefixlen
+ 1;
848 return ExceptionContinueExecution
;
850 case 0xef: /* out dx,(e)ax */
852 INSTR_outport( LOWORD(context
->Edx
), 4, context
->Eax
, context
);
854 INSTR_outport( LOWORD(context
->Edx
), 2, LOWORD(context
->Eax
), context
);
855 context
->Eip
+= prefixlen
+ 1;
856 return ExceptionContinueExecution
;
859 context
->Eip
+= prefixlen
+ 1;
860 return ExceptionContinueExecution
;
863 context
->Eip
+= prefixlen
+ 1;
864 return ExceptionContinueExecution
;
866 return ExceptionContinueSearch
; /* Unable to emulate it */
870 /***********************************************************************
871 * INSTR_vectored_handler
873 * Vectored exception handler used to emulate protected instructions
876 LONG CALLBACK
INSTR_vectored_handler( EXCEPTION_POINTERS
*ptrs
)
878 EXCEPTION_RECORD
*record
= ptrs
->ExceptionRecord
;
879 CONTEXT
*context
= ptrs
->ContextRecord
;
881 if (ldt_is_system(context
->SegCs
) &&
882 (record
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
||
883 record
->ExceptionCode
== EXCEPTION_PRIV_INSTRUCTION
))
885 if (__wine_emulate_instruction( record
, context
) == ExceptionContinueExecution
)
886 return EXCEPTION_CONTINUE_EXECUTION
;
888 return EXCEPTION_CONTINUE_SEARCH
;
892 /***********************************************************************
893 * DOS3Call (KERNEL.102)
895 void WINAPI
DOS3Call( CONTEXT
*context
)
897 __wine_call_int_handler16( 0x21, context
);
901 /***********************************************************************
902 * NetBIOSCall (KERNEL.103)
904 void WINAPI
NetBIOSCall16( CONTEXT
*context
)
906 __wine_call_int_handler16( 0x5c, context
);
910 /***********************************************************************
911 * GetSetKernelDOSProc (KERNEL.311)
913 FARPROC16 WINAPI
GetSetKernelDOSProc16( FARPROC16 DosProc
)
915 FIXME("(DosProc=%p): stub\n", DosProc
);