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( CONTEXT
*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( CONTEXT
*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( CONTEXT
*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( CONTEXT
*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_word( CONTEXT
*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 /* store an operand into a byte register */
156 static void store_reg_byte( CONTEXT
*context
, BYTE regmodrm
, const BYTE
*addr
)
158 switch((regmodrm
>> 3) & 7)
160 case 0: context
->Eax
= (context
->Eax
& 0xffffff00) | *addr
; break;
161 case 1: context
->Ecx
= (context
->Ecx
& 0xffffff00) | *addr
; break;
162 case 2: context
->Edx
= (context
->Edx
& 0xffffff00) | *addr
; break;
163 case 3: context
->Ebx
= (context
->Ebx
& 0xffffff00) | *addr
; break;
164 case 4: context
->Eax
= (context
->Eax
& 0xffff00ff) | (*addr
<< 8); break;
165 case 5: context
->Ecx
= (context
->Ecx
& 0xffff00ff) | (*addr
<< 8); break;
166 case 6: context
->Edx
= (context
->Edx
& 0xffff00ff) | (*addr
<< 8); break;
167 case 7: context
->Ebx
= (context
->Ebx
& 0xffff00ff) | (*addr
<< 8); break;
171 /***********************************************************************
172 * INSTR_GetOperandAddr
174 * Return the address of an instruction operand (from the mod/rm byte).
176 static BYTE
*INSTR_GetOperandAddr( CONTEXT
*context
, BYTE
*instr
,
177 int long_addr
, int segprefix
, int *len
)
179 int mod
, rm
, base
= 0, index
= 0, ss
= 0, seg
= 0, off
;
182 #define GET_VAL(val,type) \
183 { *val = *(type *)instr; instr += sizeof(type); *len += sizeof(type); }
186 GET_VAL( &mod
, BYTE
);
194 case 0: return (BYTE
*)&context
->Eax
;
195 case 1: return (BYTE
*)&context
->Ecx
;
196 case 2: return (BYTE
*)&context
->Edx
;
197 case 3: return (BYTE
*)&context
->Ebx
;
198 case 4: return (BYTE
*)&context
->Esp
;
199 case 5: return (BYTE
*)&context
->Ebp
;
200 case 6: return (BYTE
*)&context
->Esi
;
201 case 7: return (BYTE
*)&context
->Edi
;
210 GET_VAL( &sib
, BYTE
);
213 switch((sib
>> 3) & 7)
215 case 0: index
= context
->Eax
; break;
216 case 1: index
= context
->Ecx
; break;
217 case 2: index
= context
->Edx
; break;
218 case 3: index
= context
->Ebx
; break;
219 case 4: index
= 0; break;
220 case 5: index
= context
->Ebp
; break;
221 case 6: index
= context
->Esi
; break;
222 case 7: index
= context
->Edi
; break;
228 case 0: base
= context
->Eax
; seg
= context
->SegDs
; break;
229 case 1: base
= context
->Ecx
; seg
= context
->SegDs
; break;
230 case 2: base
= context
->Edx
; seg
= context
->SegDs
; break;
231 case 3: base
= context
->Ebx
; seg
= context
->SegDs
; break;
232 case 4: base
= context
->Esp
; seg
= context
->SegSs
; break;
233 case 5: base
= context
->Ebp
; seg
= context
->SegSs
; break;
234 case 6: base
= context
->Esi
; seg
= context
->SegDs
; break;
235 case 7: base
= context
->Edi
; seg
= context
->SegDs
; break;
240 if (rm
== 5) /* special case: ds:(disp32) */
242 GET_VAL( &base
, DWORD
);
243 seg
= context
->SegDs
;
247 case 1: /* 8-bit disp */
248 GET_VAL( &off
, BYTE
);
249 base
+= (signed char)off
;
252 case 2: /* 32-bit disp */
253 GET_VAL( &off
, DWORD
);
254 base
+= (signed long)off
;
258 else /* short address */
262 case 0: /* ds:(bx,si) */
263 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Esi
);
264 seg
= context
->SegDs
;
266 case 1: /* ds:(bx,di) */
267 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Edi
);
268 seg
= context
->SegDs
;
270 case 2: /* ss:(bp,si) */
271 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Esi
);
272 seg
= context
->SegSs
;
274 case 3: /* ss:(bp,di) */
275 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Edi
);
276 seg
= context
->SegSs
;
278 case 4: /* ds:(si) */
279 base
= LOWORD(context
->Esi
);
280 seg
= context
->SegDs
;
282 case 5: /* ds:(di) */
283 base
= LOWORD(context
->Edi
);
284 seg
= context
->SegDs
;
286 case 6: /* ss:(bp) */
287 base
= LOWORD(context
->Ebp
);
288 seg
= context
->SegSs
;
290 case 7: /* ds:(bx) */
291 base
= LOWORD(context
->Ebx
);
292 seg
= context
->SegDs
;
299 if (rm
== 6) /* special case: ds:(disp16) */
301 GET_VAL( &base
, WORD
);
302 seg
= context
->SegDs
;
306 case 1: /* 8-bit disp */
307 GET_VAL( &off
, BYTE
);
308 base
+= (signed char)off
;
311 case 2: /* 16-bit disp */
312 GET_VAL( &off
, WORD
);
313 base
+= (signed short)off
;
318 if (segprefix
!= -1) seg
= segprefix
;
320 /* Make sure the segment and offset are valid */
321 if (wine_ldt_is_system(seg
)) return (BYTE
*)(base
+ (index
<< ss
));
322 if ((seg
& 7) != 7) return NULL
;
323 wine_ldt_get_entry( seg
, &entry
);
324 if (wine_ldt_is_empty( &entry
)) return NULL
;
325 if (wine_ldt_get_limit(&entry
) < (base
+ (index
<< ss
))) return NULL
;
326 return (BYTE
*)wine_ldt_get_base(&entry
) + base
+ (index
<< ss
);
331 /***********************************************************************
334 * Emulate the LDS (and LES,LFS,etc.) instruction.
336 static BOOL
INSTR_EmulateLDS( CONTEXT
*context
, BYTE
*instr
, int long_op
,
337 int long_addr
, int segprefix
, int *len
)
340 BYTE
*regmodrm
= instr
+ 1 + (*instr
== 0x0f);
341 BYTE
*addr
= INSTR_GetOperandAddr( context
, regmodrm
,
342 long_addr
, segprefix
, len
);
344 return FALSE
; /* Unable to emulate it */
345 seg
= *(WORD
*)(addr
+ (long_op
? 4 : 2));
347 if (!INSTR_ReplaceSelector( context
, &seg
))
348 return FALSE
; /* Unable to emulate it */
350 /* Now store the offset in the correct register */
352 store_reg_word( context
, *regmodrm
, addr
, long_op
);
354 /* Store the correct segment in the segment register */
358 case 0xc4: context
->SegEs
= seg
; break; /* les */
359 case 0xc5: context
->SegDs
= seg
; break; /* lds */
360 case 0x0f: switch(instr
[1])
362 case 0xb2: context
->SegSs
= seg
; break; /* lss */
363 case 0xb4: context
->SegFs
= seg
; break; /* lfs */
364 case 0xb5: context
->SegGs
= seg
; break; /* lgs */
369 /* Add the opcode size to the total length */
371 *len
+= 1 + (*instr
== 0x0f);
375 /***********************************************************************
378 * input on an I/O port
380 static DWORD
INSTR_inport( WORD port
, int size
, CONTEXT
*context
)
382 DWORD res
= DOSVM_inport( port
, size
);
389 TRACE_(io
)( "0x%x < %02x @ %04x:%04x\n", port
, LOBYTE(res
),
390 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
393 TRACE_(io
)( "0x%x < %04x @ %04x:%04x\n", port
, LOWORD(res
),
394 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
397 TRACE_(io
)( "0x%x < %08x @ %04x:%04x\n", port
, res
,
398 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
406 /***********************************************************************
409 * output on an I/O port
411 static void INSTR_outport( WORD port
, int size
, DWORD val
, CONTEXT
*context
)
413 DOSVM_outport( port
, size
, val
);
420 TRACE_(io
)("0x%x > %02x @ %04x:%04x\n", port
, LOBYTE(val
),
421 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
424 TRACE_(io
)("0x%x > %04x @ %04x:%04x\n", port
, LOWORD(val
),
425 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
428 TRACE_(io
)("0x%x > %08x @ %04x:%04x\n", port
, val
,
429 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
436 /***********************************************************************
437 * __wine_emulate_instruction
439 * Emulate a privileged instruction.
440 * Returns exception continuation status.
442 DWORD
__wine_emulate_instruction( EXCEPTION_RECORD
*rec
, CONTEXT
*context
)
444 int prefix
, segprefix
, prefixlen
, len
, repX
, long_op
, long_addr
;
447 long_op
= long_addr
= (!ISV86(context
) && IS_SELECTOR_32BIT(context
->SegCs
));
448 instr
= make_ptr( context
, context
->SegCs
, context
->Eip
, TRUE
);
449 if (!instr
) return ExceptionContinueSearch
;
451 /* First handle any possible prefix */
453 segprefix
= -1; /* no prefix */
462 segprefix
= context
->SegCs
;
465 segprefix
= context
->SegSs
;
468 segprefix
= context
->SegDs
;
471 segprefix
= context
->SegEs
;
474 segprefix
= context
->SegFs
;
477 segprefix
= context
->SegGs
;
480 long_op
= !long_op
; /* opcode size prefix */
483 long_addr
= !long_addr
; /* addr size prefix */
485 case 0xf0: /* lock */
487 case 0xf2: /* repne */
490 case 0xf3: /* repe */
494 prefix
= 0; /* no more prefixes */
504 /* Now look at the actual instruction */
508 case 0x07: /* pop es */
509 case 0x17: /* pop ss */
510 case 0x1f: /* pop ds */
512 WORD seg
= *(WORD
*)get_stack( context
);
513 if (INSTR_ReplaceSelector( context
, &seg
))
517 case 0x07: context
->SegEs
= seg
; break;
518 case 0x17: context
->SegSs
= seg
; break;
519 case 0x1f: context
->SegDs
= seg
; break;
521 add_stack(context
, long_op
? 4 : 2);
522 context
->Eip
+= prefixlen
+ 1;
523 return ExceptionContinueExecution
;
526 break; /* Unable to emulate it */
528 case 0x0f: /* extended instruction */
531 case 0x22: /* mov %eax, %crX */
535 FIXME("mov %%eax, %%cr0 at 0x%08x, EAX=0x%08x\n",
536 context
->Eip
,context
->Eax
);
537 context
->Eip
+= prefixlen
+3;
538 return ExceptionContinueExecution
;
540 break; /* Fallthrough to bad instruction handling */
542 break; /* Fallthrough to bad instruction handling */
543 case 0x20: /* mov %crX, %eax */
546 case 0xe0: /* mov %cr4, %eax */
547 /* CR4 register: See linux/arch/i386/mm/init.c, X86_CR4_ defs
548 * bit 0: VME Virtual Mode Exception ?
549 * bit 1: PVI Protected mode Virtual Interrupt
550 * bit 2: TSD Timestamp disable
551 * bit 3: DE Debugging extensions
552 * bit 4: PSE Page size extensions
553 * bit 5: PAE Physical address extension
554 * bit 6: MCE Machine check enable
555 * bit 7: PGE Enable global pages
556 * bit 8: PCE Enable performance counters at IPL3
558 FIXME("mov %%cr4, %%eax at 0x%08x\n",context
->Eip
);
560 context
->Eip
+= prefixlen
+3;
561 return ExceptionContinueExecution
;
562 case 0xc0: /* mov %cr0, %eax */
563 FIXME("mov %%cr0, %%eax at 0x%08x\n",context
->Eip
);
564 context
->Eax
= 0x10; /* FIXME: set more bits ? */
565 context
->Eip
+= prefixlen
+3;
566 return ExceptionContinueExecution
;
567 default: /* Fallthrough to illegal instruction */
570 /* Fallthrough to illegal instruction */
572 case 0x21: /* mov %drX, %eax */
575 case 0xc8: /* mov %dr1, %eax */
576 TRACE("mov %%dr1, %%eax at 0x%08x\n",context
->Eip
);
577 context
->Eax
= context
->Dr1
;
578 context
->Eip
+= prefixlen
+3;
579 return ExceptionContinueExecution
;
580 case 0xf8: /* mov %dr7, %eax */
581 TRACE("mov %%dr7, %%eax at 0x%08x\n",context
->Eip
);
582 context
->Eax
= 0x400;
583 context
->Eip
+= prefixlen
+3;
584 return ExceptionContinueExecution
;
586 FIXME("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
587 /* fallthrough to illegal instruction */
589 case 0x23: /* mov %eax, %drX */
592 case 0xc8: /* mov %eax, %dr1 */
593 context
->Dr1
= context
->Eax
;
594 context
->Eip
+= prefixlen
+3;
595 return ExceptionContinueExecution
;
597 FIXME("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
598 /* fallthrough to illegal instruction */
600 case 0xa1: /* pop fs */
602 WORD seg
= *(WORD
*)get_stack( context
);
603 if (INSTR_ReplaceSelector( context
, &seg
))
605 context
->SegFs
= seg
;
606 add_stack(context
, long_op
? 4 : 2);
607 context
->Eip
+= prefixlen
+ 2;
608 return ExceptionContinueExecution
;
612 case 0xa9: /* pop gs */
614 WORD seg
= *(WORD
*)get_stack( context
);
615 if (INSTR_ReplaceSelector( context
, &seg
))
617 context
->SegGs
= seg
;
618 add_stack(context
, long_op
? 4 : 2);
619 context
->Eip
+= prefixlen
+ 2;
620 return ExceptionContinueExecution
;
624 case 0xb2: /* lss addr,reg */
625 case 0xb4: /* lfs addr,reg */
626 case 0xb5: /* lgs addr,reg */
627 if (INSTR_EmulateLDS( context
, instr
, long_op
,
628 long_addr
, segprefix
, &len
))
630 context
->Eip
+= prefixlen
+ len
;
631 return ExceptionContinueExecution
;
635 break; /* Unable to emulate it */
637 case 0x6c: /* insb */
638 case 0x6d: /* insw/d */
639 case 0x6e: /* outsb */
640 case 0x6f: /* outsw/d */
642 int typ
= *instr
; /* Just in case it's overwritten. */
643 int outp
= (typ
>= 0x6e);
644 unsigned long count
= repX
?
645 (long_addr
? context
->Ecx
: LOWORD(context
->Ecx
)) : 1;
646 int opsize
= (typ
& 1) ? (long_op
? 4 : 2) : 1;
647 int step
= (context
->EFlags
& 0x400) ? -opsize
: +opsize
;
648 int seg
= outp
? context
->SegDs
: context
->SegEs
; /* FIXME: is this right? */
652 /* FIXME: Check segment is readable. */
656 /* FIXME: Check segment is writable. */
661 if (long_addr
) context
->Ecx
= 0;
662 else SET_LOWORD(context
->Ecx
,0);
668 WORD dx
= LOWORD(context
->Edx
);
671 data
= make_ptr( context
, seg
, context
->Esi
, long_addr
);
672 if (long_addr
) context
->Esi
+= step
;
673 else ADD_LOWORD(context
->Esi
,step
);
677 data
= make_ptr( context
, seg
, context
->Edi
, long_addr
);
678 if (long_addr
) context
->Edi
+= step
;
679 else ADD_LOWORD(context
->Edi
,step
);
685 *(BYTE
*)data
= INSTR_inport( dx
, 1, context
);
689 *(DWORD
*)data
= INSTR_inport( dx
, 4, context
);
691 *(WORD
*)data
= INSTR_inport( dx
, 2, context
);
694 INSTR_outport( dx
, 1, *(BYTE
*)data
, context
);
698 INSTR_outport( dx
, 4, *(DWORD
*)data
, context
);
700 INSTR_outport( dx
, 2, *(WORD
*)data
, context
);
704 context
->Eip
+= prefixlen
+ 1;
706 return ExceptionContinueExecution
;
708 case 0x8a: /* mov Eb, Gb */
709 case 0x8b: /* mov Ev, Gv */
711 BYTE
*data
= INSTR_GetOperandAddr(context
, instr
+ 1, long_addr
,
713 unsigned int data_size
= (*instr
== 0x8b) ? (long_op
? 4 : 2) : 1;
714 struct idtr idtr
= get_idtr();
715 unsigned int offset
= data
- idtr
.base
;
717 if (offset
<= idtr
.limit
+ 1 - data_size
)
719 idt
[1].LimitLow
= 0x100; /* FIXME */
720 idt
[2].LimitLow
= 0x11E; /* FIXME */
721 idt
[3].LimitLow
= 0x500; /* FIXME */
725 case 0x8a: store_reg_byte( context
, instr
[1], (BYTE
*)idt
+ offset
); break;
726 case 0x8b: store_reg_word( context
, instr
[1], (BYTE
*)idt
+ offset
, long_op
); break;
728 context
->Eip
+= prefixlen
+ len
+ 1;
729 return ExceptionContinueExecution
;
732 break; /* Unable to emulate it */
734 case 0x8e: /* mov XX,segment_reg */
737 BYTE
*addr
= INSTR_GetOperandAddr(context
, instr
+ 1,
738 long_addr
, segprefix
, &len
);
740 break; /* Unable to emulate it */
742 if (!INSTR_ReplaceSelector( context
, &seg
))
743 break; /* Unable to emulate it */
745 switch((instr
[1] >> 3) & 7)
748 context
->SegEs
= seg
;
749 context
->Eip
+= prefixlen
+ len
+ 1;
750 return ExceptionContinueExecution
;
754 context
->SegSs
= seg
;
755 context
->Eip
+= prefixlen
+ len
+ 1;
756 return ExceptionContinueExecution
;
758 context
->SegDs
= seg
;
759 context
->Eip
+= prefixlen
+ len
+ 1;
760 return ExceptionContinueExecution
;
762 context
->SegFs
= seg
;
763 context
->Eip
+= prefixlen
+ len
+ 1;
764 return ExceptionContinueExecution
;
766 context
->SegGs
= seg
;
767 context
->Eip
+= prefixlen
+ len
+ 1;
768 return ExceptionContinueExecution
;
774 break; /* Unable to emulate it */
776 case 0xc4: /* les addr,reg */
777 case 0xc5: /* lds addr,reg */
778 if (INSTR_EmulateLDS( context
, instr
, long_op
,
779 long_addr
, segprefix
, &len
))
781 context
->Eip
+= prefixlen
+ len
;
782 return ExceptionContinueExecution
;
784 break; /* Unable to emulate it */
786 case 0xcd: /* int <XX> */
787 context
->Eip
+= prefixlen
+ 2;
788 if (DOSVM_EmulateInterruptPM( context
, instr
[1] )) return ExceptionContinueExecution
;
789 context
->Eip
-= prefixlen
+ 2; /* restore eip */
790 break; /* Unable to emulate it */
792 case 0xcf: /* iret */
793 if (wine_ldt_is_system(context
->SegCs
)) break; /* don't emulate it in 32-bit code */
796 DWORD
*stack
= get_stack( context
);
797 context
->Eip
= *stack
++;
798 context
->SegCs
= *stack
++;
799 context
->EFlags
= *stack
;
800 add_stack(context
, 3*sizeof(DWORD
)); /* Pop the return address and flags */
804 WORD
*stack
= get_stack( context
);
805 context
->Eip
= *stack
++;
806 context
->SegCs
= *stack
++;
807 SET_LOWORD(context
->EFlags
,*stack
);
808 add_stack(context
, 3*sizeof(WORD
)); /* Pop the return address and flags */
810 return ExceptionContinueExecution
;
812 case 0xe4: /* inb al,XX */
813 SET_LOBYTE(context
->Eax
,INSTR_inport( instr
[1], 1, context
));
814 context
->Eip
+= prefixlen
+ 2;
815 return ExceptionContinueExecution
;
817 case 0xe5: /* in (e)ax,XX */
819 context
->Eax
= INSTR_inport( instr
[1], 4, context
);
821 SET_LOWORD(context
->Eax
, INSTR_inport( instr
[1], 2, context
));
822 context
->Eip
+= prefixlen
+ 2;
823 return ExceptionContinueExecution
;
825 case 0xe6: /* outb XX,al */
826 INSTR_outport( instr
[1], 1, LOBYTE(context
->Eax
), context
);
827 context
->Eip
+= prefixlen
+ 2;
828 return ExceptionContinueExecution
;
830 case 0xe7: /* out XX,(e)ax */
832 INSTR_outport( instr
[1], 4, context
->Eax
, context
);
834 INSTR_outport( instr
[1], 2, LOWORD(context
->Eax
), context
);
835 context
->Eip
+= prefixlen
+ 2;
836 return ExceptionContinueExecution
;
838 case 0xec: /* inb al,dx */
839 SET_LOBYTE(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 1, context
) );
840 context
->Eip
+= prefixlen
+ 1;
841 return ExceptionContinueExecution
;
843 case 0xed: /* in (e)ax,dx */
845 context
->Eax
= INSTR_inport( LOWORD(context
->Edx
), 4, context
);
847 SET_LOWORD(context
->Eax
, INSTR_inport( LOWORD(context
->Edx
), 2, context
));
848 context
->Eip
+= prefixlen
+ 1;
849 return ExceptionContinueExecution
;
851 case 0xee: /* outb dx,al */
852 INSTR_outport( LOWORD(context
->Edx
), 1, LOBYTE(context
->Eax
), context
);
853 context
->Eip
+= prefixlen
+ 1;
854 return ExceptionContinueExecution
;
856 case 0xef: /* out dx,(e)ax */
858 INSTR_outport( LOWORD(context
->Edx
), 4, context
->Eax
, context
);
860 INSTR_outport( LOWORD(context
->Edx
), 2, LOWORD(context
->Eax
), context
);
861 context
->Eip
+= prefixlen
+ 1;
862 return ExceptionContinueExecution
;
865 get_vm86_teb_info()->dpmi_vif
= 0;
866 context
->Eip
+= prefixlen
+ 1;
867 return ExceptionContinueExecution
;
870 get_vm86_teb_info()->dpmi_vif
= 1;
871 context
->Eip
+= prefixlen
+ 1;
872 if (get_vm86_teb_info()->vm86_pending
)
874 get_vm86_teb_info()->vm86_pending
= 0;
875 rec
->ExceptionCode
= EXCEPTION_VM86_STI
;
876 break; /* Handle the pending event. */
878 return ExceptionContinueExecution
;
880 return ExceptionContinueSearch
; /* Unable to emulate it */
884 /***********************************************************************
885 * INSTR_vectored_handler
887 * Vectored exception handler used to emulate protected instructions
890 LONG CALLBACK
INSTR_vectored_handler( EXCEPTION_POINTERS
*ptrs
)
892 EXCEPTION_RECORD
*record
= ptrs
->ExceptionRecord
;
893 CONTEXT
*context
= ptrs
->ContextRecord
;
895 if (wine_ldt_is_system(context
->SegCs
) &&
896 (record
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
||
897 record
->ExceptionCode
== EXCEPTION_PRIV_INSTRUCTION
))
899 if (__wine_emulate_instruction( record
, context
) == ExceptionContinueExecution
)
900 return EXCEPTION_CONTINUE_EXECUTION
;
902 return EXCEPTION_CONTINUE_SEARCH
;
906 /***********************************************************************
907 * DOS3Call (KERNEL.102)
909 void WINAPI
DOS3Call( CONTEXT
*context
)
911 __wine_call_int_handler( context
, 0x21 );
915 /***********************************************************************
916 * NetBIOSCall (KERNEL.103)
918 void WINAPI
NetBIOSCall16( CONTEXT
*context
)
920 __wine_call_int_handler( context
, 0x5c );
924 /***********************************************************************
925 * GetSetKernelDOSProc (KERNEL.311)
927 FARPROC16 WINAPI
GetSetKernelDOSProc16( FARPROC16 DosProc
)
929 FIXME("(DosProc=%p): stub\n", DosProc
);