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"
33 #include "wine/exception.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(int);
36 WINE_DECLARE_DEBUG_CHANNEL(io
);
38 /* macros to set parts of a DWORD */
39 #define SET_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD(val))
40 #define SET_LOBYTE(dw,val) ((dw) = ((dw) & 0xffffff00) | LOBYTE(val))
41 #define ADD_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
43 static inline void add_stack( CONTEXT
*context
, int offset
)
45 if (!IS_SELECTOR_32BIT(context
->SegSs
))
46 ADD_LOWORD( context
->Esp
, offset
);
48 context
->Esp
+= offset
;
51 static inline void *make_ptr( CONTEXT
*context
, DWORD seg
, DWORD off
, int long_addr
)
53 if (ldt_is_system(seg
)) return (void *)off
;
54 if (!long_addr
) off
= LOWORD(off
);
55 return (char *) MapSL( MAKESEGPTR( seg
, 0 ) ) + off
;
58 static inline void *get_stack( CONTEXT
*context
)
60 return ldt_get_ptr( context
->SegSs
, context
->Esp
);
71 static LDT_ENTRY idt
[256];
73 static inline struct idtr
get_idtr(void)
76 #if defined(__i386__) && defined(__GNUC__)
77 __asm__( "sidtl %0" : "=m" (ret
) );
79 ret
.base
= (BYTE
*)idt
;
80 ret
.limit
= sizeof(idt
) - 1;
86 /***********************************************************************
87 * INSTR_ReplaceSelector
89 * Try to replace an invalid selector by a valid one.
90 * The only selector where it is allowed to do "mov ax,40;mov es,ax"
91 * is the so called 'bimodal' selector 0x40, which points to the BIOS
92 * data segment. Used by (at least) Borland products (and programs compiled
93 * using Borland products).
95 * See Undocumented Windows, Chapter 5, __0040.
97 static BOOL
INSTR_ReplaceSelector( CONTEXT
*context
, WORD
*sel
)
101 DOSVM_start_bios_timer();
102 *sel
= DOSMEM_BiosDataSeg
;
105 return FALSE
; /* Can't replace selector, crashdump */
109 /* store an operand into a register */
110 static void store_reg_word( CONTEXT
*context
, BYTE regmodrm
, const BYTE
*addr
, int long_op
)
112 switch((regmodrm
>> 3) & 7)
115 if (long_op
) context
->Eax
= *(const DWORD
*)addr
;
116 else SET_LOWORD(context
->Eax
, *(const WORD
*)addr
);
119 if (long_op
) context
->Ecx
= *(const DWORD
*)addr
;
120 else SET_LOWORD(context
->Ecx
, *(const WORD
*)addr
);
123 if (long_op
) context
->Edx
= *(const DWORD
*)addr
;
124 else SET_LOWORD(context
->Edx
, *(const WORD
*)addr
);
127 if (long_op
) context
->Ebx
= *(const DWORD
*)addr
;
128 else SET_LOWORD(context
->Ebx
, *(const WORD
*)addr
);
131 if (long_op
) context
->Esp
= *(const DWORD
*)addr
;
132 else SET_LOWORD(context
->Esp
, *(const WORD
*)addr
);
135 if (long_op
) context
->Ebp
= *(const DWORD
*)addr
;
136 else SET_LOWORD(context
->Ebp
, *(const WORD
*)addr
);
139 if (long_op
) context
->Esi
= *(const DWORD
*)addr
;
140 else SET_LOWORD(context
->Esi
, *(const WORD
*)addr
);
143 if (long_op
) context
->Edi
= *(const DWORD
*)addr
;
144 else SET_LOWORD(context
->Edi
, *(const WORD
*)addr
);
149 /* store an operand into a byte register */
150 static void store_reg_byte( CONTEXT
*context
, BYTE regmodrm
, const BYTE
*addr
)
152 switch((regmodrm
>> 3) & 7)
154 case 0: context
->Eax
= (context
->Eax
& 0xffffff00) | *addr
; break;
155 case 1: context
->Ecx
= (context
->Ecx
& 0xffffff00) | *addr
; break;
156 case 2: context
->Edx
= (context
->Edx
& 0xffffff00) | *addr
; break;
157 case 3: context
->Ebx
= (context
->Ebx
& 0xffffff00) | *addr
; break;
158 case 4: context
->Eax
= (context
->Eax
& 0xffff00ff) | (*addr
<< 8); break;
159 case 5: context
->Ecx
= (context
->Ecx
& 0xffff00ff) | (*addr
<< 8); break;
160 case 6: context
->Edx
= (context
->Edx
& 0xffff00ff) | (*addr
<< 8); break;
161 case 7: context
->Ebx
= (context
->Ebx
& 0xffff00ff) | (*addr
<< 8); break;
165 /***********************************************************************
166 * INSTR_GetOperandAddr
168 * Return the address of an instruction operand (from the mod/rm byte).
170 static BYTE
*INSTR_GetOperandAddr( CONTEXT
*context
, BYTE
*instr
,
171 int long_addr
, int segprefix
, int *len
)
173 int mod
, rm
, base
= 0, index
= 0, ss
= 0, seg
= 0, off
;
175 #define GET_VAL(val,type) \
176 { *val = *(type *)instr; instr += sizeof(type); *len += sizeof(type); }
179 GET_VAL( &mod
, BYTE
);
187 case 0: return (BYTE
*)&context
->Eax
;
188 case 1: return (BYTE
*)&context
->Ecx
;
189 case 2: return (BYTE
*)&context
->Edx
;
190 case 3: return (BYTE
*)&context
->Ebx
;
191 case 4: return (BYTE
*)&context
->Esp
;
192 case 5: return (BYTE
*)&context
->Ebp
;
193 case 6: return (BYTE
*)&context
->Esi
;
194 case 7: return (BYTE
*)&context
->Edi
;
203 GET_VAL( &sib
, BYTE
);
206 switch((sib
>> 3) & 7)
208 case 0: index
= context
->Eax
; break;
209 case 1: index
= context
->Ecx
; break;
210 case 2: index
= context
->Edx
; break;
211 case 3: index
= context
->Ebx
; break;
212 case 4: index
= 0; break;
213 case 5: index
= context
->Ebp
; break;
214 case 6: index
= context
->Esi
; break;
215 case 7: index
= context
->Edi
; break;
221 case 0: base
= context
->Eax
; seg
= context
->SegDs
; break;
222 case 1: base
= context
->Ecx
; seg
= context
->SegDs
; break;
223 case 2: base
= context
->Edx
; seg
= context
->SegDs
; break;
224 case 3: base
= context
->Ebx
; seg
= context
->SegDs
; break;
225 case 4: base
= context
->Esp
; seg
= context
->SegSs
; break;
226 case 5: base
= context
->Ebp
; seg
= context
->SegSs
; break;
227 case 6: base
= context
->Esi
; seg
= context
->SegDs
; break;
228 case 7: base
= context
->Edi
; seg
= context
->SegDs
; break;
233 if (rm
== 5) /* special case: ds:(disp32) */
235 GET_VAL( &base
, DWORD
);
236 seg
= context
->SegDs
;
240 case 1: /* 8-bit disp */
241 GET_VAL( &off
, BYTE
);
242 base
+= (signed char)off
;
245 case 2: /* 32-bit disp */
246 GET_VAL( &off
, DWORD
);
247 base
+= (signed long)off
;
251 else /* short address */
255 case 0: /* ds:(bx,si) */
256 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Esi
);
257 seg
= context
->SegDs
;
259 case 1: /* ds:(bx,di) */
260 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Edi
);
261 seg
= context
->SegDs
;
263 case 2: /* ss:(bp,si) */
264 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Esi
);
265 seg
= context
->SegSs
;
267 case 3: /* ss:(bp,di) */
268 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Edi
);
269 seg
= context
->SegSs
;
271 case 4: /* ds:(si) */
272 base
= LOWORD(context
->Esi
);
273 seg
= context
->SegDs
;
275 case 5: /* ds:(di) */
276 base
= LOWORD(context
->Edi
);
277 seg
= context
->SegDs
;
279 case 6: /* ss:(bp) */
280 base
= LOWORD(context
->Ebp
);
281 seg
= context
->SegSs
;
283 case 7: /* ds:(bx) */
284 base
= LOWORD(context
->Ebx
);
285 seg
= context
->SegDs
;
292 if (rm
== 6) /* special case: ds:(disp16) */
294 GET_VAL( &base
, WORD
);
295 seg
= context
->SegDs
;
299 case 1: /* 8-bit disp */
300 GET_VAL( &off
, BYTE
);
301 base
+= (signed char)off
;
304 case 2: /* 16-bit disp */
305 GET_VAL( &off
, WORD
);
306 base
+= (signed short)off
;
311 if (segprefix
!= -1) seg
= segprefix
;
313 /* Make sure the segment and offset are valid */
314 if (ldt_is_system(seg
)) return (BYTE
*)(base
+ (index
<< ss
));
315 if ((seg
& 7) != 7) return NULL
;
316 if (!ldt_is_valid( seg
)) return NULL
;
317 if (ldt_get_limit( seg
) < (base
+ (index
<< ss
))) return NULL
;
318 return (BYTE
*)ldt_get_base( seg
) + base
+ (index
<< ss
);
323 /***********************************************************************
326 * Emulate the LDS (and LES,LFS,etc.) instruction.
328 static BOOL
INSTR_EmulateLDS( CONTEXT
*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_word( 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
, CONTEXT
*context
)
374 DWORD res
= DOSVM_inport( port
, size
);
381 TRACE_(io
)( "0x%x < %02x @ %04x:%04x\n", port
, LOBYTE(res
),
382 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
385 TRACE_(io
)( "0x%x < %04x @ %04x:%04x\n", port
, LOWORD(res
),
386 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
389 TRACE_(io
)( "0x%x < %08x @ %04x:%04x\n", port
, res
,
390 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
398 /***********************************************************************
401 * output on an I/O port
403 static void INSTR_outport( WORD port
, int size
, DWORD val
, CONTEXT
*context
)
405 DOSVM_outport( port
, size
, val
);
412 TRACE_(io
)("0x%x > %02x @ %04x:%04x\n", port
, LOBYTE(val
),
413 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
416 TRACE_(io
)("0x%x > %04x @ %04x:%04x\n", port
, LOWORD(val
),
417 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
420 TRACE_(io
)("0x%x > %08x @ %04x:%04x\n", port
, val
,
421 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
428 /***********************************************************************
429 * __wine_emulate_instruction
431 * Emulate a privileged instruction.
432 * Returns exception continuation status.
434 DWORD
__wine_emulate_instruction( EXCEPTION_RECORD
*rec
, CONTEXT
*context
)
436 int prefix
, segprefix
, prefixlen
, len
, repX
, long_op
, long_addr
;
439 long_op
= long_addr
= IS_SELECTOR_32BIT(context
->SegCs
);
440 instr
= make_ptr( context
, context
->SegCs
, context
->Eip
, TRUE
);
441 if (!instr
) return ExceptionContinueSearch
;
443 /* First handle any possible prefix */
445 segprefix
= -1; /* no prefix */
454 segprefix
= context
->SegCs
;
457 segprefix
= context
->SegSs
;
460 segprefix
= context
->SegDs
;
463 segprefix
= context
->SegEs
;
466 segprefix
= context
->SegFs
;
469 segprefix
= context
->SegGs
;
472 long_op
= !long_op
; /* opcode size prefix */
475 long_addr
= !long_addr
; /* addr size prefix */
477 case 0xf0: /* lock */
479 case 0xf2: /* repne */
482 case 0xf3: /* repe */
486 prefix
= 0; /* no more prefixes */
496 /* Now look at the actual instruction */
500 case 0x07: /* pop es */
501 case 0x17: /* pop ss */
502 case 0x1f: /* pop ds */
504 WORD seg
= *(WORD
*)get_stack( context
);
505 if (INSTR_ReplaceSelector( context
, &seg
))
509 case 0x07: context
->SegEs
= seg
; break;
510 case 0x17: context
->SegSs
= seg
; break;
511 case 0x1f: context
->SegDs
= seg
; break;
513 add_stack(context
, long_op
? 4 : 2);
514 context
->Eip
+= prefixlen
+ 1;
515 return ExceptionContinueExecution
;
518 break; /* Unable to emulate it */
520 case 0x0f: /* extended instruction */
523 case 0x22: /* mov %eax, %crX */
527 FIXME("mov %%eax, %%cr0 at 0x%08x, EAX=0x%08x\n",
528 context
->Eip
,context
->Eax
);
529 context
->Eip
+= prefixlen
+3;
530 return ExceptionContinueExecution
;
532 break; /* Fallthrough to bad instruction handling */
534 break; /* Fallthrough to bad instruction handling */
535 case 0x20: /* mov %crX, %eax */
538 case 0xe0: /* mov %cr4, %eax */
539 /* CR4 register: See linux/arch/i386/mm/init.c, X86_CR4_ defs
540 * bit 0: VME Virtual Mode Exception ?
541 * bit 1: PVI Protected mode Virtual Interrupt
542 * bit 2: TSD Timestamp disable
543 * bit 3: DE Debugging extensions
544 * bit 4: PSE Page size extensions
545 * bit 5: PAE Physical address extension
546 * bit 6: MCE Machine check enable
547 * bit 7: PGE Enable global pages
548 * bit 8: PCE Enable performance counters at IPL3
550 FIXME("mov %%cr4, %%eax at 0x%08x\n",context
->Eip
);
552 context
->Eip
+= prefixlen
+3;
553 return ExceptionContinueExecution
;
554 case 0xc0: /* mov %cr0, %eax */
555 FIXME("mov %%cr0, %%eax at 0x%08x\n",context
->Eip
);
556 context
->Eax
= 0x10; /* FIXME: set more bits ? */
557 context
->Eip
+= prefixlen
+3;
558 return ExceptionContinueExecution
;
559 default: /* Fallthrough to illegal instruction */
562 /* Fallthrough to illegal instruction */
564 case 0x21: /* mov %drX, %eax */
567 case 0xc8: /* mov %dr1, %eax */
568 TRACE("mov %%dr1, %%eax at 0x%08x\n",context
->Eip
);
569 context
->Eax
= context
->Dr1
;
570 context
->Eip
+= prefixlen
+3;
571 return ExceptionContinueExecution
;
572 case 0xf8: /* mov %dr7, %eax */
573 TRACE("mov %%dr7, %%eax at 0x%08x\n",context
->Eip
);
574 context
->Eax
= 0x400;
575 context
->Eip
+= prefixlen
+3;
576 return ExceptionContinueExecution
;
578 FIXME("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
579 /* fallthrough to illegal instruction */
581 case 0x23: /* mov %eax, %drX */
584 case 0xc8: /* mov %eax, %dr1 */
585 context
->Dr1
= context
->Eax
;
586 context
->Eip
+= prefixlen
+3;
587 return ExceptionContinueExecution
;
589 FIXME("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
590 /* fallthrough to illegal instruction */
592 case 0xa1: /* pop fs */
594 WORD seg
= *(WORD
*)get_stack( context
);
595 if (INSTR_ReplaceSelector( context
, &seg
))
597 context
->SegFs
= seg
;
598 add_stack(context
, long_op
? 4 : 2);
599 context
->Eip
+= prefixlen
+ 2;
600 return ExceptionContinueExecution
;
604 case 0xa9: /* pop gs */
606 WORD seg
= *(WORD
*)get_stack( context
);
607 if (INSTR_ReplaceSelector( context
, &seg
))
609 context
->SegGs
= seg
;
610 add_stack(context
, long_op
? 4 : 2);
611 context
->Eip
+= prefixlen
+ 2;
612 return ExceptionContinueExecution
;
616 case 0xb2: /* lss addr,reg */
617 case 0xb4: /* lfs addr,reg */
618 case 0xb5: /* lgs addr,reg */
619 if (INSTR_EmulateLDS( context
, instr
, long_op
,
620 long_addr
, segprefix
, &len
))
622 context
->Eip
+= prefixlen
+ len
;
623 return ExceptionContinueExecution
;
627 break; /* Unable to emulate it */
629 case 0x6c: /* insb */
630 case 0x6d: /* insw/d */
631 case 0x6e: /* outsb */
632 case 0x6f: /* outsw/d */
634 int typ
= *instr
; /* Just in case it's overwritten. */
635 int outp
= (typ
>= 0x6e);
636 unsigned long count
= repX
?
637 (long_addr
? context
->Ecx
: LOWORD(context
->Ecx
)) : 1;
638 int opsize
= (typ
& 1) ? (long_op
? 4 : 2) : 1;
639 int step
= (context
->EFlags
& 0x400) ? -opsize
: +opsize
;
644 /* Check if there is a segment prefix override and honour it */
645 seg
= segprefix
== -1 ? context
->SegDs
: segprefix
;
646 /* FIXME: Check segment is readable. */
650 seg
= context
->SegEs
;
651 /* FIXME: Check segment is writable. */
656 if (long_addr
) context
->Ecx
= 0;
657 else SET_LOWORD(context
->Ecx
,0);
663 WORD dx
= LOWORD(context
->Edx
);
666 data
= make_ptr( context
, seg
, context
->Esi
, long_addr
);
667 if (long_addr
) context
->Esi
+= step
;
668 else ADD_LOWORD(context
->Esi
,step
);
672 data
= make_ptr( context
, seg
, context
->Edi
, long_addr
);
673 if (long_addr
) context
->Edi
+= step
;
674 else ADD_LOWORD(context
->Edi
,step
);
680 *(BYTE
*)data
= INSTR_inport( dx
, 1, context
);
684 *(DWORD
*)data
= INSTR_inport( dx
, 4, context
);
686 *(WORD
*)data
= INSTR_inport( dx
, 2, context
);
689 INSTR_outport( dx
, 1, *(BYTE
*)data
, context
);
693 INSTR_outport( dx
, 4, *(DWORD
*)data
, context
);
695 INSTR_outport( dx
, 2, *(WORD
*)data
, context
);
699 context
->Eip
+= prefixlen
+ 1;
701 return ExceptionContinueExecution
;
703 case 0x8a: /* mov Eb, Gb */
704 case 0x8b: /* mov Ev, Gv */
706 BYTE
*data
= INSTR_GetOperandAddr(context
, instr
+ 1, long_addr
,
708 unsigned int data_size
= (*instr
== 0x8b) ? (long_op
? 4 : 2) : 1;
709 struct idtr idtr
= get_idtr();
710 unsigned int offset
= data
- idtr
.base
;
712 if (offset
<= idtr
.limit
+ 1 - data_size
)
714 idt
[1].LimitLow
= 0x100; /* FIXME */
715 idt
[2].LimitLow
= 0x11E; /* FIXME */
716 idt
[3].LimitLow
= 0x500; /* FIXME */
720 case 0x8a: store_reg_byte( context
, instr
[1], (BYTE
*)idt
+ offset
); break;
721 case 0x8b: store_reg_word( context
, instr
[1], (BYTE
*)idt
+ offset
, long_op
); break;
723 context
->Eip
+= prefixlen
+ len
+ 1;
724 return ExceptionContinueExecution
;
727 break; /* Unable to emulate it */
729 case 0x8e: /* mov XX,segment_reg */
732 BYTE
*addr
= INSTR_GetOperandAddr(context
, instr
+ 1,
733 long_addr
, segprefix
, &len
);
735 break; /* Unable to emulate it */
737 if (!INSTR_ReplaceSelector( context
, &seg
))
738 break; /* Unable to emulate it */
740 switch((instr
[1] >> 3) & 7)
743 context
->SegEs
= seg
;
744 context
->Eip
+= prefixlen
+ len
+ 1;
745 return ExceptionContinueExecution
;
749 context
->SegSs
= seg
;
750 context
->Eip
+= prefixlen
+ len
+ 1;
751 return ExceptionContinueExecution
;
753 context
->SegDs
= seg
;
754 context
->Eip
+= prefixlen
+ len
+ 1;
755 return ExceptionContinueExecution
;
757 context
->SegFs
= seg
;
758 context
->Eip
+= prefixlen
+ len
+ 1;
759 return ExceptionContinueExecution
;
761 context
->SegGs
= seg
;
762 context
->Eip
+= prefixlen
+ len
+ 1;
763 return ExceptionContinueExecution
;
769 break; /* Unable to emulate it */
771 case 0xc4: /* les addr,reg */
772 case 0xc5: /* lds addr,reg */
773 if (INSTR_EmulateLDS( context
, instr
, long_op
,
774 long_addr
, segprefix
, &len
))
776 context
->Eip
+= prefixlen
+ len
;
777 return ExceptionContinueExecution
;
779 break; /* Unable to emulate it */
781 case 0xcd: /* int <XX> */
782 context
->Eip
+= prefixlen
+ 2;
783 if (DOSVM_EmulateInterruptPM( context
, instr
[1] )) return ExceptionContinueExecution
;
784 context
->Eip
-= prefixlen
+ 2; /* restore eip */
785 break; /* Unable to emulate it */
787 case 0xcf: /* iret */
788 if (ldt_is_system(context
->SegCs
)) break; /* don't emulate it in 32-bit code */
791 DWORD
*stack
= get_stack( context
);
792 context
->Eip
= *stack
++;
793 context
->SegCs
= *stack
++;
794 context
->EFlags
= *stack
;
795 add_stack(context
, 3*sizeof(DWORD
)); /* Pop the return address and flags */
799 WORD
*stack
= get_stack( context
);
800 context
->Eip
= *stack
++;
801 context
->SegCs
= *stack
++;
802 SET_LOWORD(context
->EFlags
,*stack
);
803 add_stack(context
, 3*sizeof(WORD
)); /* Pop the return address and flags */
805 return ExceptionContinueExecution
;
807 case 0xe4: /* inb al,XX */
808 SET_LOBYTE(context
->Eax
,INSTR_inport( instr
[1], 1, context
));
809 context
->Eip
+= prefixlen
+ 2;
810 return ExceptionContinueExecution
;
812 case 0xe5: /* in (e)ax,XX */
814 context
->Eax
= INSTR_inport( instr
[1], 4, context
);
816 SET_LOWORD(context
->Eax
, INSTR_inport( instr
[1], 2, context
));
817 context
->Eip
+= prefixlen
+ 2;
818 return ExceptionContinueExecution
;
820 case 0xe6: /* outb XX,al */
821 INSTR_outport( instr
[1], 1, LOBYTE(context
->Eax
), context
);
822 context
->Eip
+= prefixlen
+ 2;
823 return ExceptionContinueExecution
;
825 case 0xe7: /* out XX,(e)ax */
827 INSTR_outport( instr
[1], 4, context
->Eax
, context
);
829 INSTR_outport( instr
[1], 2, LOWORD(context
->Eax
), context
);
830 context
->Eip
+= prefixlen
+ 2;
831 return ExceptionContinueExecution
;
833 case 0xec: /* inb al,dx */
834 SET_LOBYTE(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 1, context
) );
835 context
->Eip
+= prefixlen
+ 1;
836 return ExceptionContinueExecution
;
838 case 0xed: /* in (e)ax,dx */
840 context
->Eax
= INSTR_inport( LOWORD(context
->Edx
), 4, context
);
842 SET_LOWORD(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 2, context
));
843 context
->Eip
+= prefixlen
+ 1;
844 return ExceptionContinueExecution
;
846 case 0xee: /* outb dx,al */
847 INSTR_outport( LOWORD(context
->Edx
), 1, LOBYTE(context
->Eax
), context
);
848 context
->Eip
+= prefixlen
+ 1;
849 return ExceptionContinueExecution
;
851 case 0xef: /* out dx,(e)ax */
853 INSTR_outport( LOWORD(context
->Edx
), 4, context
->Eax
, context
);
855 INSTR_outport( LOWORD(context
->Edx
), 2, LOWORD(context
->Eax
), context
);
856 context
->Eip
+= prefixlen
+ 1;
857 return ExceptionContinueExecution
;
860 context
->Eip
+= prefixlen
+ 1;
861 return ExceptionContinueExecution
;
864 context
->Eip
+= prefixlen
+ 1;
865 return ExceptionContinueExecution
;
867 return ExceptionContinueSearch
; /* Unable to emulate it */
871 /***********************************************************************
872 * INSTR_vectored_handler
874 * Vectored exception handler used to emulate protected instructions
877 LONG CALLBACK
INSTR_vectored_handler( EXCEPTION_POINTERS
*ptrs
)
879 EXCEPTION_RECORD
*record
= ptrs
->ExceptionRecord
;
880 CONTEXT
*context
= ptrs
->ContextRecord
;
882 if (ldt_is_system(context
->SegCs
) &&
883 (record
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
||
884 record
->ExceptionCode
== EXCEPTION_PRIV_INSTRUCTION
))
886 if (__wine_emulate_instruction( record
, context
) == ExceptionContinueExecution
)
887 return EXCEPTION_CONTINUE_EXECUTION
;
889 return EXCEPTION_CONTINUE_SEARCH
;
893 /***********************************************************************
894 * DOS3Call (KERNEL.102)
896 void WINAPI
DOS3Call( CONTEXT
*context
)
898 __wine_call_int_handler( context
, 0x21 );
902 /***********************************************************************
903 * NetBIOSCall (KERNEL.103)
905 void WINAPI
NetBIOSCall16( CONTEXT
*context
)
907 __wine_call_int_handler( context
, 0x5c );
911 /***********************************************************************
912 * GetSetKernelDOSProc (KERNEL.311)
914 FARPROC16 WINAPI
GetSetKernelDOSProc16( FARPROC16 DosProc
)
916 FIXME("(DosProc=%p): stub\n", DosProc
);