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)))
46 static inline void add_stack( CONTEXT
*context
, int offset
)
48 if (!IS_SELECTOR_32BIT(context
->SegSs
))
49 ADD_LOWORD( context
->Esp
, offset
);
51 context
->Esp
+= offset
;
54 static inline void *make_ptr( CONTEXT
*context
, DWORD seg
, DWORD off
, int long_addr
)
56 if (wine_ldt_is_system(seg
)) return (void *)off
;
57 if (!long_addr
) off
= LOWORD(off
);
58 return (char *) MapSL( MAKESEGPTR( seg
, 0 ) ) + off
;
61 static inline void *get_stack( CONTEXT
*context
)
63 return wine_ldt_get_ptr( context
->SegSs
, context
->Esp
);
74 static LDT_ENTRY idt
[256];
76 static inline struct idtr
get_idtr(void)
79 #if defined(__i386__) && defined(__GNUC__)
80 __asm__( "sidtl %0" : "=m" (ret
) );
82 ret
.base
= (BYTE
*)idt
;
83 ret
.limit
= sizeof(idt
) - 1;
89 /***********************************************************************
90 * INSTR_ReplaceSelector
92 * Try to replace an invalid selector by a valid one.
93 * The only selector where it is allowed to do "mov ax,40;mov es,ax"
94 * is the so called 'bimodal' selector 0x40, which points to the BIOS
95 * data segment. Used by (at least) Borland products (and programs compiled
96 * using Borland products).
98 * See Undocumented Windows, Chapter 5, __0040.
100 static BOOL
INSTR_ReplaceSelector( CONTEXT
*context
, WORD
*sel
)
104 DOSVM_start_bios_timer();
105 *sel
= DOSMEM_BiosDataSeg
;
108 return FALSE
; /* Can't replace selector, crashdump */
112 /* store an operand into a register */
113 static void store_reg_word( CONTEXT
*context
, BYTE regmodrm
, const BYTE
*addr
, int long_op
)
115 switch((regmodrm
>> 3) & 7)
118 if (long_op
) context
->Eax
= *(const DWORD
*)addr
;
119 else SET_LOWORD(context
->Eax
, *(const WORD
*)addr
);
122 if (long_op
) context
->Ecx
= *(const DWORD
*)addr
;
123 else SET_LOWORD(context
->Ecx
, *(const WORD
*)addr
);
126 if (long_op
) context
->Edx
= *(const DWORD
*)addr
;
127 else SET_LOWORD(context
->Edx
, *(const WORD
*)addr
);
130 if (long_op
) context
->Ebx
= *(const DWORD
*)addr
;
131 else SET_LOWORD(context
->Ebx
, *(const WORD
*)addr
);
134 if (long_op
) context
->Esp
= *(const DWORD
*)addr
;
135 else SET_LOWORD(context
->Esp
, *(const WORD
*)addr
);
138 if (long_op
) context
->Ebp
= *(const DWORD
*)addr
;
139 else SET_LOWORD(context
->Ebp
, *(const WORD
*)addr
);
142 if (long_op
) context
->Esi
= *(const DWORD
*)addr
;
143 else SET_LOWORD(context
->Esi
, *(const WORD
*)addr
);
146 if (long_op
) context
->Edi
= *(const DWORD
*)addr
;
147 else SET_LOWORD(context
->Edi
, *(const WORD
*)addr
);
152 /* store an operand into a byte register */
153 static void store_reg_byte( CONTEXT
*context
, BYTE regmodrm
, const BYTE
*addr
)
155 switch((regmodrm
>> 3) & 7)
157 case 0: context
->Eax
= (context
->Eax
& 0xffffff00) | *addr
; break;
158 case 1: context
->Ecx
= (context
->Ecx
& 0xffffff00) | *addr
; break;
159 case 2: context
->Edx
= (context
->Edx
& 0xffffff00) | *addr
; break;
160 case 3: context
->Ebx
= (context
->Ebx
& 0xffffff00) | *addr
; break;
161 case 4: context
->Eax
= (context
->Eax
& 0xffff00ff) | (*addr
<< 8); break;
162 case 5: context
->Ecx
= (context
->Ecx
& 0xffff00ff) | (*addr
<< 8); break;
163 case 6: context
->Edx
= (context
->Edx
& 0xffff00ff) | (*addr
<< 8); break;
164 case 7: context
->Ebx
= (context
->Ebx
& 0xffff00ff) | (*addr
<< 8); break;
168 /***********************************************************************
169 * INSTR_GetOperandAddr
171 * Return the address of an instruction operand (from the mod/rm byte).
173 static BYTE
*INSTR_GetOperandAddr( CONTEXT
*context
, BYTE
*instr
,
174 int long_addr
, int segprefix
, int *len
)
176 int mod
, rm
, base
= 0, index
= 0, ss
= 0, seg
= 0, off
;
179 #define GET_VAL(val,type) \
180 { *val = *(type *)instr; instr += sizeof(type); *len += sizeof(type); }
183 GET_VAL( &mod
, BYTE
);
191 case 0: return (BYTE
*)&context
->Eax
;
192 case 1: return (BYTE
*)&context
->Ecx
;
193 case 2: return (BYTE
*)&context
->Edx
;
194 case 3: return (BYTE
*)&context
->Ebx
;
195 case 4: return (BYTE
*)&context
->Esp
;
196 case 5: return (BYTE
*)&context
->Ebp
;
197 case 6: return (BYTE
*)&context
->Esi
;
198 case 7: return (BYTE
*)&context
->Edi
;
207 GET_VAL( &sib
, BYTE
);
210 switch((sib
>> 3) & 7)
212 case 0: index
= context
->Eax
; break;
213 case 1: index
= context
->Ecx
; break;
214 case 2: index
= context
->Edx
; break;
215 case 3: index
= context
->Ebx
; break;
216 case 4: index
= 0; break;
217 case 5: index
= context
->Ebp
; break;
218 case 6: index
= context
->Esi
; break;
219 case 7: index
= context
->Edi
; break;
225 case 0: base
= context
->Eax
; seg
= context
->SegDs
; break;
226 case 1: base
= context
->Ecx
; seg
= context
->SegDs
; break;
227 case 2: base
= context
->Edx
; seg
= context
->SegDs
; break;
228 case 3: base
= context
->Ebx
; seg
= context
->SegDs
; break;
229 case 4: base
= context
->Esp
; seg
= context
->SegSs
; break;
230 case 5: base
= context
->Ebp
; seg
= context
->SegSs
; break;
231 case 6: base
= context
->Esi
; seg
= context
->SegDs
; break;
232 case 7: base
= context
->Edi
; seg
= context
->SegDs
; break;
237 if (rm
== 5) /* special case: ds:(disp32) */
239 GET_VAL( &base
, DWORD
);
240 seg
= context
->SegDs
;
244 case 1: /* 8-bit disp */
245 GET_VAL( &off
, BYTE
);
246 base
+= (signed char)off
;
249 case 2: /* 32-bit disp */
250 GET_VAL( &off
, DWORD
);
251 base
+= (signed long)off
;
255 else /* short address */
259 case 0: /* ds:(bx,si) */
260 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Esi
);
261 seg
= context
->SegDs
;
263 case 1: /* ds:(bx,di) */
264 base
= LOWORD(context
->Ebx
) + LOWORD(context
->Edi
);
265 seg
= context
->SegDs
;
267 case 2: /* ss:(bp,si) */
268 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Esi
);
269 seg
= context
->SegSs
;
271 case 3: /* ss:(bp,di) */
272 base
= LOWORD(context
->Ebp
) + LOWORD(context
->Edi
);
273 seg
= context
->SegSs
;
275 case 4: /* ds:(si) */
276 base
= LOWORD(context
->Esi
);
277 seg
= context
->SegDs
;
279 case 5: /* ds:(di) */
280 base
= LOWORD(context
->Edi
);
281 seg
= context
->SegDs
;
283 case 6: /* ss:(bp) */
284 base
= LOWORD(context
->Ebp
);
285 seg
= context
->SegSs
;
287 case 7: /* ds:(bx) */
288 base
= LOWORD(context
->Ebx
);
289 seg
= context
->SegDs
;
296 if (rm
== 6) /* special case: ds:(disp16) */
298 GET_VAL( &base
, WORD
);
299 seg
= context
->SegDs
;
303 case 1: /* 8-bit disp */
304 GET_VAL( &off
, BYTE
);
305 base
+= (signed char)off
;
308 case 2: /* 16-bit disp */
309 GET_VAL( &off
, WORD
);
310 base
+= (signed short)off
;
315 if (segprefix
!= -1) seg
= segprefix
;
317 /* Make sure the segment and offset are valid */
318 if (wine_ldt_is_system(seg
)) return (BYTE
*)(base
+ (index
<< ss
));
319 if ((seg
& 7) != 7) return NULL
;
320 wine_ldt_get_entry( seg
, &entry
);
321 if (wine_ldt_is_empty( &entry
)) return NULL
;
322 if (wine_ldt_get_limit(&entry
) < (base
+ (index
<< ss
))) return NULL
;
323 return (BYTE
*)wine_ldt_get_base(&entry
) + base
+ (index
<< ss
);
328 /***********************************************************************
331 * Emulate the LDS (and LES,LFS,etc.) instruction.
333 static BOOL
INSTR_EmulateLDS( CONTEXT
*context
, BYTE
*instr
, int long_op
,
334 int long_addr
, int segprefix
, int *len
)
337 BYTE
*regmodrm
= instr
+ 1 + (*instr
== 0x0f);
338 BYTE
*addr
= INSTR_GetOperandAddr( context
, regmodrm
,
339 long_addr
, segprefix
, len
);
341 return FALSE
; /* Unable to emulate it */
342 seg
= *(WORD
*)(addr
+ (long_op
? 4 : 2));
344 if (!INSTR_ReplaceSelector( context
, &seg
))
345 return FALSE
; /* Unable to emulate it */
347 /* Now store the offset in the correct register */
349 store_reg_word( context
, *regmodrm
, addr
, long_op
);
351 /* Store the correct segment in the segment register */
355 case 0xc4: context
->SegEs
= seg
; break; /* les */
356 case 0xc5: context
->SegDs
= seg
; break; /* lds */
357 case 0x0f: switch(instr
[1])
359 case 0xb2: context
->SegSs
= seg
; break; /* lss */
360 case 0xb4: context
->SegFs
= seg
; break; /* lfs */
361 case 0xb5: context
->SegGs
= seg
; break; /* lgs */
366 /* Add the opcode size to the total length */
368 *len
+= 1 + (*instr
== 0x0f);
372 /***********************************************************************
375 * input on an I/O port
377 static DWORD
INSTR_inport( WORD port
, int size
, CONTEXT
*context
)
379 DWORD res
= DOSVM_inport( port
, size
);
386 TRACE_(io
)( "0x%x < %02x @ %04x:%04x\n", port
, LOBYTE(res
),
387 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
390 TRACE_(io
)( "0x%x < %04x @ %04x:%04x\n", port
, LOWORD(res
),
391 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
394 TRACE_(io
)( "0x%x < %08x @ %04x:%04x\n", port
, res
,
395 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
403 /***********************************************************************
406 * output on an I/O port
408 static void INSTR_outport( WORD port
, int size
, DWORD val
, CONTEXT
*context
)
410 DOSVM_outport( port
, size
, val
);
417 TRACE_(io
)("0x%x > %02x @ %04x:%04x\n", port
, LOBYTE(val
),
418 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
421 TRACE_(io
)("0x%x > %04x @ %04x:%04x\n", port
, LOWORD(val
),
422 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
425 TRACE_(io
)("0x%x > %08x @ %04x:%04x\n", port
, val
,
426 (WORD
)context
->SegCs
, LOWORD(context
->Eip
));
433 /***********************************************************************
434 * __wine_emulate_instruction
436 * Emulate a privileged instruction.
437 * Returns exception continuation status.
439 DWORD
__wine_emulate_instruction( EXCEPTION_RECORD
*rec
, CONTEXT
*context
)
441 int prefix
, segprefix
, prefixlen
, len
, repX
, long_op
, long_addr
;
444 long_op
= long_addr
= IS_SELECTOR_32BIT(context
->SegCs
);
445 instr
= make_ptr( context
, context
->SegCs
, context
->Eip
, TRUE
);
446 if (!instr
) return ExceptionContinueSearch
;
448 /* First handle any possible prefix */
450 segprefix
= -1; /* no prefix */
459 segprefix
= context
->SegCs
;
462 segprefix
= context
->SegSs
;
465 segprefix
= context
->SegDs
;
468 segprefix
= context
->SegEs
;
471 segprefix
= context
->SegFs
;
474 segprefix
= context
->SegGs
;
477 long_op
= !long_op
; /* opcode size prefix */
480 long_addr
= !long_addr
; /* addr size prefix */
482 case 0xf0: /* lock */
484 case 0xf2: /* repne */
487 case 0xf3: /* repe */
491 prefix
= 0; /* no more prefixes */
501 /* Now look at the actual instruction */
505 case 0x07: /* pop es */
506 case 0x17: /* pop ss */
507 case 0x1f: /* pop ds */
509 WORD seg
= *(WORD
*)get_stack( context
);
510 if (INSTR_ReplaceSelector( context
, &seg
))
514 case 0x07: context
->SegEs
= seg
; break;
515 case 0x17: context
->SegSs
= seg
; break;
516 case 0x1f: context
->SegDs
= seg
; break;
518 add_stack(context
, long_op
? 4 : 2);
519 context
->Eip
+= prefixlen
+ 1;
520 return ExceptionContinueExecution
;
523 break; /* Unable to emulate it */
525 case 0x0f: /* extended instruction */
528 case 0x22: /* mov %eax, %crX */
532 FIXME("mov %%eax, %%cr0 at 0x%08x, EAX=0x%08x\n",
533 context
->Eip
,context
->Eax
);
534 context
->Eip
+= prefixlen
+3;
535 return ExceptionContinueExecution
;
537 break; /* Fallthrough to bad instruction handling */
539 break; /* Fallthrough to bad instruction handling */
540 case 0x20: /* mov %crX, %eax */
543 case 0xe0: /* mov %cr4, %eax */
544 /* CR4 register: See linux/arch/i386/mm/init.c, X86_CR4_ defs
545 * bit 0: VME Virtual Mode Exception ?
546 * bit 1: PVI Protected mode Virtual Interrupt
547 * bit 2: TSD Timestamp disable
548 * bit 3: DE Debugging extensions
549 * bit 4: PSE Page size extensions
550 * bit 5: PAE Physical address extension
551 * bit 6: MCE Machine check enable
552 * bit 7: PGE Enable global pages
553 * bit 8: PCE Enable performance counters at IPL3
555 FIXME("mov %%cr4, %%eax at 0x%08x\n",context
->Eip
);
557 context
->Eip
+= prefixlen
+3;
558 return ExceptionContinueExecution
;
559 case 0xc0: /* mov %cr0, %eax */
560 FIXME("mov %%cr0, %%eax at 0x%08x\n",context
->Eip
);
561 context
->Eax
= 0x10; /* FIXME: set more bits ? */
562 context
->Eip
+= prefixlen
+3;
563 return ExceptionContinueExecution
;
564 default: /* Fallthrough to illegal instruction */
567 /* Fallthrough to illegal instruction */
569 case 0x21: /* mov %drX, %eax */
572 case 0xc8: /* mov %dr1, %eax */
573 TRACE("mov %%dr1, %%eax at 0x%08x\n",context
->Eip
);
574 context
->Eax
= context
->Dr1
;
575 context
->Eip
+= prefixlen
+3;
576 return ExceptionContinueExecution
;
577 case 0xf8: /* mov %dr7, %eax */
578 TRACE("mov %%dr7, %%eax at 0x%08x\n",context
->Eip
);
579 context
->Eax
= 0x400;
580 context
->Eip
+= prefixlen
+3;
581 return ExceptionContinueExecution
;
583 FIXME("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
584 /* fallthrough to illegal instruction */
586 case 0x23: /* mov %eax, %drX */
589 case 0xc8: /* mov %eax, %dr1 */
590 context
->Dr1
= context
->Eax
;
591 context
->Eip
+= prefixlen
+3;
592 return ExceptionContinueExecution
;
594 FIXME("Unsupported DR register, eip+2 is %02x\n", instr
[2]);
595 /* fallthrough to illegal instruction */
597 case 0xa1: /* pop fs */
599 WORD seg
= *(WORD
*)get_stack( context
);
600 if (INSTR_ReplaceSelector( context
, &seg
))
602 context
->SegFs
= seg
;
603 add_stack(context
, long_op
? 4 : 2);
604 context
->Eip
+= prefixlen
+ 2;
605 return ExceptionContinueExecution
;
609 case 0xa9: /* pop gs */
611 WORD seg
= *(WORD
*)get_stack( context
);
612 if (INSTR_ReplaceSelector( context
, &seg
))
614 context
->SegGs
= seg
;
615 add_stack(context
, long_op
? 4 : 2);
616 context
->Eip
+= prefixlen
+ 2;
617 return ExceptionContinueExecution
;
621 case 0xb2: /* lss addr,reg */
622 case 0xb4: /* lfs addr,reg */
623 case 0xb5: /* lgs addr,reg */
624 if (INSTR_EmulateLDS( context
, instr
, long_op
,
625 long_addr
, segprefix
, &len
))
627 context
->Eip
+= prefixlen
+ len
;
628 return ExceptionContinueExecution
;
632 break; /* Unable to emulate it */
634 case 0x6c: /* insb */
635 case 0x6d: /* insw/d */
636 case 0x6e: /* outsb */
637 case 0x6f: /* outsw/d */
639 int typ
= *instr
; /* Just in case it's overwritten. */
640 int outp
= (typ
>= 0x6e);
641 unsigned long count
= repX
?
642 (long_addr
? context
->Ecx
: LOWORD(context
->Ecx
)) : 1;
643 int opsize
= (typ
& 1) ? (long_op
? 4 : 2) : 1;
644 int step
= (context
->EFlags
& 0x400) ? -opsize
: +opsize
;
649 /* Check if there is a segment prefix override and honour it */
650 seg
= segprefix
== -1 ? context
->SegDs
: segprefix
;
651 /* FIXME: Check segment is readable. */
655 seg
= context
->SegEs
;
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 context
->Eip
+= prefixlen
+ 1;
866 return ExceptionContinueExecution
;
869 context
->Eip
+= prefixlen
+ 1;
870 return ExceptionContinueExecution
;
872 return ExceptionContinueSearch
; /* Unable to emulate it */
876 /***********************************************************************
877 * INSTR_vectored_handler
879 * Vectored exception handler used to emulate protected instructions
882 LONG CALLBACK
INSTR_vectored_handler( EXCEPTION_POINTERS
*ptrs
)
884 EXCEPTION_RECORD
*record
= ptrs
->ExceptionRecord
;
885 CONTEXT
*context
= ptrs
->ContextRecord
;
887 if (wine_ldt_is_system(context
->SegCs
) &&
888 (record
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
||
889 record
->ExceptionCode
== EXCEPTION_PRIV_INSTRUCTION
))
891 if (__wine_emulate_instruction( record
, context
) == ExceptionContinueExecution
)
892 return EXCEPTION_CONTINUE_EXECUTION
;
894 return EXCEPTION_CONTINUE_SEARCH
;
898 /***********************************************************************
899 * DOS3Call (KERNEL.102)
901 void WINAPI
DOS3Call( CONTEXT
*context
)
903 __wine_call_int_handler( context
, 0x21 );
907 /***********************************************************************
908 * NetBIOSCall (KERNEL.103)
910 void WINAPI
NetBIOSCall16( CONTEXT
*context
)
912 __wine_call_int_handler( context
, 0x5c );
916 /***********************************************************************
917 * GetSetKernelDOSProc (KERNEL.311)
919 FARPROC16 WINAPI
GetSetKernelDOSProc16( FARPROC16 DosProc
)
921 FIXME("(DosProc=%p): stub\n", DosProc
);