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 "kernel_private.h"
35 #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( CONTEXT86 *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( CONTEXT86 *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( CONTEXT86 *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( CONTEXT86 *context, WORD *sel )
107 static WORD sys_timer = 0;
110 if (!winedos.BiosTick) load_winedos();
111 if (winedos.BiosTick)
112 sys_timer = CreateSystemTimer( 55, winedos.BiosTick );
114 *sel = DOSMEM_BiosDataSeg;
117 return FALSE; /* Can't replace selector, crashdump */
121 /* store an operand into a register */
122 static void store_reg( CONTEXT86 *context, BYTE regmodrm, const BYTE *addr, int long_op )
124 switch((regmodrm >> 3) & 7)
127 if (long_op) context->Eax = *(const DWORD *)addr;
128 else SET_LOWORD(context->Eax, *(const WORD *)addr);
131 if (long_op) context->Ecx = *(const DWORD *)addr;
132 else SET_LOWORD(context->Ecx, *(const WORD *)addr);
135 if (long_op) context->Edx = *(const DWORD *)addr;
136 else SET_LOWORD(context->Edx, *(const WORD *)addr);
139 if (long_op) context->Ebx = *(const DWORD *)addr;
140 else SET_LOWORD(context->Ebx, *(const WORD *)addr);
143 if (long_op) context->Esp = *(const DWORD *)addr;
144 else SET_LOWORD(context->Esp, *(const WORD *)addr);
147 if (long_op) context->Ebp = *(const DWORD *)addr;
148 else SET_LOWORD(context->Ebp, *(const WORD *)addr);
151 if (long_op) context->Esi = *(const DWORD *)addr;
152 else SET_LOWORD(context->Esi, *(const WORD *)addr);
155 if (long_op) context->Edi = *(const DWORD *)addr;
156 else SET_LOWORD(context->Edi, *(const WORD *)addr);
161 /***********************************************************************
162 * INSTR_GetOperandAddr
164 * Return the address of an instruction operand (from the mod/rm byte).
166 static BYTE *INSTR_GetOperandAddr( CONTEXT86 *context, BYTE *instr,
167 int long_addr, int segprefix, int *len )
169 int mod, rm, base = 0, index = 0, ss = 0, seg = 0, off;
172 #define GET_VAL(val,type) \
173 { *val = *(type *)instr; instr += sizeof(type); *len += sizeof(type); }
176 GET_VAL( &mod, BYTE );
184 case 0: return (BYTE *)&context->Eax;
185 case 1: return (BYTE *)&context->Ecx;
186 case 2: return (BYTE *)&context->Edx;
187 case 3: return (BYTE *)&context->Ebx;
188 case 4: return (BYTE *)&context->Esp;
189 case 5: return (BYTE *)&context->Ebp;
190 case 6: return (BYTE *)&context->Esi;
191 case 7: return (BYTE *)&context->Edi;
200 GET_VAL( &sib, BYTE );
205 case 0: index = context->Eax; break;
206 case 1: index = context->Ecx; break;
207 case 2: index = context->Edx; break;
208 case 3: index = context->Ebx; break;
209 case 4: index = 0; break;
210 case 5: index = context->Ebp; break;
211 case 6: index = context->Esi; break;
212 case 7: index = context->Edi; break;
218 case 0: base = context->Eax; seg = context->SegDs; break;
219 case 1: base = context->Ecx; seg = context->SegDs; break;
220 case 2: base = context->Edx; seg = context->SegDs; break;
221 case 3: base = context->Ebx; seg = context->SegDs; break;
222 case 4: base = context->Esp; seg = context->SegSs; break;
223 case 5: base = context->Ebp; seg = context->SegSs; break;
224 case 6: base = context->Esi; seg = context->SegDs; break;
225 case 7: base = context->Edi; seg = context->SegDs; break;
230 if (rm == 5) /* special case: ds:(disp32) */
232 GET_VAL( &base, DWORD );
233 seg = context->SegDs;
237 case 1: /* 8-bit disp */
238 GET_VAL( &off, BYTE );
239 base += (signed char)off;
242 case 2: /* 32-bit disp */
243 GET_VAL( &off, DWORD );
244 base += (signed long)off;
248 else /* short address */
252 case 0: /* ds:(bx,si) */
253 base = LOWORD(context->Ebx) + LOWORD(context->Esi);
254 seg = context->SegDs;
256 case 1: /* ds:(bx,di) */
257 base = LOWORD(context->Ebx) + LOWORD(context->Edi);
258 seg = context->SegDs;
260 case 2: /* ss:(bp,si) */
261 base = LOWORD(context->Ebp) + LOWORD(context->Esi);
262 seg = context->SegSs;
264 case 3: /* ss:(bp,di) */
265 base = LOWORD(context->Ebp) + LOWORD(context->Edi);
266 seg = context->SegSs;
268 case 4: /* ds:(si) */
269 base = LOWORD(context->Esi);
270 seg = context->SegDs;
272 case 5: /* ds:(di) */
273 base = LOWORD(context->Edi);
274 seg = context->SegDs;
276 case 6: /* ss:(bp) */
277 base = LOWORD(context->Ebp);
278 seg = context->SegSs;
280 case 7: /* ds:(bx) */
281 base = LOWORD(context->Ebx);
282 seg = context->SegDs;
289 if (rm == 6) /* special case: ds:(disp16) */
291 GET_VAL( &base, WORD );
292 seg = context->SegDs;
296 case 1: /* 8-bit disp */
297 GET_VAL( &off, BYTE );
298 base += (signed char)off;
301 case 2: /* 16-bit disp */
302 GET_VAL( &off, WORD );
303 base += (signed short)off;
308 if (segprefix != -1) seg = segprefix;
310 /* Make sure the segment and offset are valid */
311 if (wine_ldt_is_system(seg)) return (BYTE *)(base + (index << ss));
312 if ((seg & 7) != 7) return NULL;
313 wine_ldt_get_entry( seg, &entry );
314 if (wine_ldt_is_empty( &entry )) return NULL;
315 if (wine_ldt_get_limit(&entry) < (base + (index << ss))) return NULL;
316 return (BYTE *)wine_ldt_get_base(&entry) + base + (index << ss);
321 /***********************************************************************
324 * Emulate the LDS (and LES,LFS,etc.) instruction.
326 static BOOL INSTR_EmulateLDS( CONTEXT86 *context, BYTE *instr, int long_op,
327 int long_addr, int segprefix, int *len )
330 BYTE *regmodrm = instr + 1 + (*instr == 0x0f);
331 BYTE *addr = INSTR_GetOperandAddr( context, regmodrm,
332 long_addr, segprefix, len );
334 return FALSE; /* Unable to emulate it */
335 seg = *(WORD *)(addr + (long_op ? 4 : 2));
337 if (!INSTR_ReplaceSelector( context, &seg ))
338 return FALSE; /* Unable to emulate it */
340 /* Now store the offset in the correct register */
342 store_reg( context, *regmodrm, addr, long_op );
344 /* Store the correct segment in the segment register */
348 case 0xc4: context->SegEs = seg; break; /* les */
349 case 0xc5: context->SegDs = seg; break; /* lds */
350 case 0x0f: switch(instr[1])
352 case 0xb2: context->SegSs = seg; break; /* lss */
353 case 0xb4: context->SegFs = seg; break; /* lfs */
354 case 0xb5: context->SegGs = seg; break; /* lgs */
359 /* Add the opcode size to the total length */
361 *len += 1 + (*instr == 0x0f);
365 /***********************************************************************
368 * input on an I/O port
370 static DWORD INSTR_inport( WORD port, int size, CONTEXT86 *context )
374 if (!winedos.inport) load_winedos();
375 if (winedos.inport) res = winedos.inport( port, size );
382 TRACE_(io)( "0x%x < %02x @ %04x:%04x\n", port, LOBYTE(res),
383 (WORD)context->SegCs, LOWORD(context->Eip));
386 TRACE_(io)( "0x%x < %04x @ %04x:%04x\n", port, LOWORD(res),
387 (WORD)context->SegCs, LOWORD(context->Eip));
390 TRACE_(io)( "0x%x < %08x @ %04x:%04x\n", port, res,
391 (WORD)context->SegCs, LOWORD(context->Eip));
399 /***********************************************************************
402 * output on an I/O port
404 static void INSTR_outport( WORD port, int size, DWORD val, CONTEXT86 *context )
406 if (!winedos.outport) load_winedos();
407 if (winedos.outport) winedos.outport( port, size, val );
414 TRACE_(io)("0x%x > %02x @ %04x:%04x\n", port, LOBYTE(val),
415 (WORD)context->SegCs, LOWORD(context->Eip));
418 TRACE_(io)("0x%x > %04x @ %04x:%04x\n", port, LOWORD(val),
419 (WORD)context->SegCs, LOWORD(context->Eip));
422 TRACE_(io)("0x%x > %08x @ %04x:%04x\n", port, val,
423 (WORD)context->SegCs, LOWORD(context->Eip));
430 /***********************************************************************
431 * __wine_emulate_instruction
433 * Emulate a privileged instruction.
434 * Returns exception continuation status.
436 DWORD __wine_emulate_instruction( EXCEPTION_RECORD *rec, CONTEXT86 *context )
438 int prefix, segprefix, prefixlen, len, repX, long_op, long_addr;
441 long_op = long_addr = (!ISV86(context) && IS_SELECTOR_32BIT(context->SegCs));
442 instr = make_ptr( context, context->SegCs, context->Eip, TRUE );
443 if (!instr) return ExceptionContinueSearch;
445 /* First handle any possible prefix */
447 segprefix = -1; /* no prefix */
456 segprefix = context->SegCs;
459 segprefix = context->SegSs;
462 segprefix = context->SegDs;
465 segprefix = context->SegEs;
468 segprefix = context->SegFs;
471 segprefix = context->SegGs;
474 long_op = !long_op; /* opcode size prefix */
477 long_addr = !long_addr; /* addr size prefix */
479 case 0xf0: /* lock */
481 case 0xf2: /* repne */
484 case 0xf3: /* repe */
488 prefix = 0; /* no more prefixes */
498 /* Now look at the actual instruction */
502 case 0x07: /* pop es */
503 case 0x17: /* pop ss */
504 case 0x1f: /* pop ds */
506 WORD seg = *(WORD *)get_stack( context );
507 if (INSTR_ReplaceSelector( context, &seg ))
511 case 0x07: context->SegEs = seg; break;
512 case 0x17: context->SegSs = seg; break;
513 case 0x1f: context->SegDs = seg; break;
515 add_stack(context, long_op ? 4 : 2);
516 context->Eip += prefixlen + 1;
517 return ExceptionContinueExecution;
520 break; /* Unable to emulate it */
522 case 0x0f: /* extended instruction */
525 case 0x22: /* mov eax, crX */
529 ERR("mov eax,cr0 at 0x%08x, EAX=0x%08x\n",
530 context->Eip,context->Eax );
531 context->Eip += prefixlen+3;
532 return ExceptionContinueExecution;
534 break; /*fallthrough to bad instruction handling */
536 break; /*fallthrough to bad instruction handling */
537 case 0x20: /* mov crX, eax */
540 case 0xe0: /* mov cr4, eax */
541 /* CR4 register . See linux/arch/i386/mm/init.c, X86_CR4_ defs
542 * bit 0: VME Virtual Mode Exception ?
543 * bit 1: PVI Protected mode Virtual Interrupt
544 * bit 2: TSD Timestamp disable
545 * bit 3: DE Debugging extensions
546 * bit 4: PSE Page size extensions
547 * bit 5: PAE Physical address extension
548 * bit 6: MCE Machine check enable
549 * bit 7: PGE Enable global pages
550 * bit 8: PCE Enable performance counters at IPL3
552 ERR("mov cr4,eax at 0x%08x\n",context->Eip);
554 context->Eip += prefixlen+3;
555 return ExceptionContinueExecution;
556 case 0xc0: /* mov cr0, eax */
557 ERR("mov cr0,eax at 0x%08x\n",context->Eip);
558 context->Eax = 0x10; /* FIXME: set more bits ? */
559 context->Eip += prefixlen+3;
560 return ExceptionContinueExecution;
561 default: /* fallthrough to illegal instruction */
564 /* fallthrough to illegal instruction */
566 case 0x21: /* mov drX, eax */
569 case 0xc8: /* mov dr1, eax */
570 TRACE("mov dr1,eax at 0x%08x\n",context->Eip);
571 context->Eax = context->Dr1;
572 context->Eip += prefixlen+3;
573 return ExceptionContinueExecution;
574 case 0xf8: /* mov dr7, eax */
575 TRACE("mov dr7,eax at 0x%08x\n",context->Eip);
576 context->Eax = 0x400;
577 context->Eip += prefixlen+3;
578 return ExceptionContinueExecution;
580 ERR("Unsupported DR register, eip+2 is %02x\n", instr[2]);
581 /* fallthrough to illegal instruction */
583 case 0x23: /* mov eax drX */
586 case 0xc8: /* mov eax, dr1 */
587 context->Dr1 = context->Eax;
588 context->Eip += prefixlen+3;
589 return ExceptionContinueExecution;
591 ERR("Unsupported DR register, eip+2 is %02x\n", instr[2]);
592 /* fallthrough to illegal instruction */
594 case 0xa1: /* pop fs */
596 WORD seg = *(WORD *)get_stack( context );
597 if (INSTR_ReplaceSelector( context, &seg ))
599 context->SegFs = seg;
600 add_stack(context, long_op ? 4 : 2);
601 context->Eip += prefixlen + 2;
602 return ExceptionContinueExecution;
606 case 0xa9: /* pop gs */
608 WORD seg = *(WORD *)get_stack( context );
609 if (INSTR_ReplaceSelector( context, &seg ))
611 context->SegGs = seg;
612 add_stack(context, long_op ? 4 : 2);
613 context->Eip += prefixlen + 2;
614 return ExceptionContinueExecution;
618 case 0xb2: /* lss addr,reg */
619 case 0xb4: /* lfs addr,reg */
620 case 0xb5: /* lgs addr,reg */
621 if (INSTR_EmulateLDS( context, instr, long_op,
622 long_addr, segprefix, &len ))
624 context->Eip += prefixlen + len;
625 return ExceptionContinueExecution;
629 break; /* Unable to emulate it */
631 case 0x6c: /* insb */
632 case 0x6d: /* insw/d */
633 case 0x6e: /* outsb */
634 case 0x6f: /* outsw/d */
636 int typ = *instr; /* Just in case it's overwritten. */
637 int outp = (typ >= 0x6e);
638 unsigned long count = repX ?
639 (long_addr ? context->Ecx : LOWORD(context->Ecx)) : 1;
640 int opsize = (typ & 1) ? (long_op ? 4 : 2) : 1;
641 int step = (context->EFlags & 0x400) ? -opsize : +opsize;
642 int seg = outp ? context->SegDs : context->SegEs; /* FIXME: is this right? */
645 /* FIXME: Check segment is readable. */
648 /* FIXME: Check segment is writable. */
653 if (long_addr) context->Ecx = 0;
654 else SET_LOWORD(context->Ecx,0);
660 WORD dx = LOWORD(context->Edx);
663 data = make_ptr( context, seg, context->Esi, long_addr );
664 if (long_addr) context->Esi += step;
665 else ADD_LOWORD(context->Esi,step);
669 data = make_ptr( context, seg, context->Edi, long_addr );
670 if (long_addr) context->Edi += step;
671 else ADD_LOWORD(context->Edi,step);
677 *(BYTE *)data = INSTR_inport( dx, 1, context );
681 *(DWORD *)data = INSTR_inport( dx, 4, context );
683 *(WORD *)data = INSTR_inport( dx, 2, context );
686 INSTR_outport( dx, 1, *(BYTE *)data, context );
690 INSTR_outport( dx, 4, *(DWORD *)data, context );
692 INSTR_outport( dx, 2, *(WORD *)data, context );
696 context->Eip += prefixlen + 1;
698 return ExceptionContinueExecution;
700 case 0x8b: /* mov Ev, Gv */
702 BYTE *addr = INSTR_GetOperandAddr(context, instr + 1, long_addr,
704 struct idtr idtr = get_idtr();
705 unsigned int offset = addr - idtr.base;
707 if (offset <= idtr.limit + 1 - (long_op ? 4 : 2))
709 idt[1].LimitLow = 0x100; /* FIXME */
710 idt[2].LimitLow = 0x11E; /* FIXME */
711 idt[3].LimitLow = 0x500; /* FIXME */
712 store_reg( context, instr[1], (BYTE *)idt + offset, long_op );
713 context->Eip += prefixlen + len + 1;
714 return ExceptionContinueExecution;
717 break; /* Unable to emulate it */
719 case 0x8e: /* mov XX,segment_reg */
722 BYTE *addr = INSTR_GetOperandAddr(context, instr + 1,
723 long_addr, segprefix, &len );
725 break; /* Unable to emulate it */
727 if (!INSTR_ReplaceSelector( context, &seg ))
728 break; /* Unable to emulate it */
730 switch((instr[1] >> 3) & 7)
733 context->SegEs = seg;
734 context->Eip += prefixlen + len + 1;
735 return ExceptionContinueExecution;
739 context->SegSs = seg;
740 context->Eip += prefixlen + len + 1;
741 return ExceptionContinueExecution;
743 context->SegDs = seg;
744 context->Eip += prefixlen + len + 1;
745 return ExceptionContinueExecution;
747 context->SegFs = seg;
748 context->Eip += prefixlen + len + 1;
749 return ExceptionContinueExecution;
751 context->SegGs = seg;
752 context->Eip += prefixlen + len + 1;
753 return ExceptionContinueExecution;
759 break; /* Unable to emulate it */
761 case 0xc4: /* les addr,reg */
762 case 0xc5: /* lds addr,reg */
763 if (INSTR_EmulateLDS( context, instr, long_op,
764 long_addr, segprefix, &len ))
766 context->Eip += prefixlen + len;
767 return ExceptionContinueExecution;
769 break; /* Unable to emulate it */
771 case 0xcd: /* int <XX> */
772 if (!winedos.EmulateInterruptPM) load_winedos();
773 if (winedos.EmulateInterruptPM)
775 context->Eip += prefixlen + 2;
776 if (winedos.EmulateInterruptPM( context, instr[1] )) return ExceptionContinueExecution;
777 context->Eip -= prefixlen + 2; /* restore eip */
779 break; /* Unable to emulate it */
781 case 0xcf: /* iret */
782 if (wine_ldt_is_system(context->SegCs)) break; /* don't emulate it in 32-bit code */
785 DWORD *stack = get_stack( context );
786 context->Eip = *stack++;
787 context->SegCs = *stack++;
788 context->EFlags = *stack;
789 add_stack(context, 3*sizeof(DWORD)); /* Pop the return address and flags */
793 WORD *stack = get_stack( context );
794 context->Eip = *stack++;
795 context->SegCs = *stack++;
796 SET_LOWORD(context->EFlags,*stack);
797 add_stack(context, 3*sizeof(WORD)); /* Pop the return address and flags */
799 return ExceptionContinueExecution;
801 case 0xe4: /* inb al,XX */
802 SET_LOBYTE(context->Eax,INSTR_inport( instr[1], 1, context ));
803 context->Eip += prefixlen + 2;
804 return ExceptionContinueExecution;
806 case 0xe5: /* in (e)ax,XX */
808 context->Eax = INSTR_inport( instr[1], 4, context );
810 SET_LOWORD(context->Eax, INSTR_inport( instr[1], 2, context ));
811 context->Eip += prefixlen + 2;
812 return ExceptionContinueExecution;
814 case 0xe6: /* outb XX,al */
815 INSTR_outport( instr[1], 1, LOBYTE(context->Eax), context );
816 context->Eip += prefixlen + 2;
817 return ExceptionContinueExecution;
819 case 0xe7: /* out XX,(e)ax */
821 INSTR_outport( instr[1], 4, context->Eax, context );
823 INSTR_outport( instr[1], 2, LOWORD(context->Eax), context );
824 context->Eip += prefixlen + 2;
825 return ExceptionContinueExecution;
827 case 0xec: /* inb al,dx */
828 SET_LOBYTE(context->Eax, INSTR_inport( LOWORD(context->Edx), 1, context ) );
829 context->Eip += prefixlen + 1;
830 return ExceptionContinueExecution;
832 case 0xed: /* in (e)ax,dx */
834 context->Eax = INSTR_inport( LOWORD(context->Edx), 4, context );
836 SET_LOWORD(context->Eax, INSTR_inport( LOWORD(context->Edx), 2, context ));
837 context->Eip += prefixlen + 1;
838 return ExceptionContinueExecution;
840 case 0xee: /* outb dx,al */
841 INSTR_outport( LOWORD(context->Edx), 1, LOBYTE(context->Eax), context );
842 context->Eip += prefixlen + 1;
843 return ExceptionContinueExecution;
845 case 0xef: /* out dx,(e)ax */
847 INSTR_outport( LOWORD(context->Edx), 4, context->Eax, context );
849 INSTR_outport( LOWORD(context->Edx), 2, LOWORD(context->Eax), context );
850 context->Eip += prefixlen + 1;
851 return ExceptionContinueExecution;
854 get_vm86_teb_info()->dpmi_vif = 0;
855 context->Eip += prefixlen + 1;
856 return ExceptionContinueExecution;
859 get_vm86_teb_info()->dpmi_vif = 1;
860 context->Eip += prefixlen + 1;
861 if (get_vm86_teb_info()->vm86_pending)
863 get_vm86_teb_info()->vm86_pending = 0;
864 rec->ExceptionCode = EXCEPTION_VM86_STI;
865 break; /* Handle the pending event. */
867 return ExceptionContinueExecution;
869 return ExceptionContinueSearch; /* Unable to emulate it */
873 /***********************************************************************
874 * INSTR_vectored_handler
876 * Vectored exception handler used to emulate protected instructions
879 LONG CALLBACK INSTR_vectored_handler( EXCEPTION_POINTERS *ptrs )
881 EXCEPTION_RECORD *record = ptrs->ExceptionRecord;
882 CONTEXT86 *context = ptrs->ContextRecord;
884 if (wine_ldt_is_system(context->SegCs) &&
885 (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION ||
886 record->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION))
888 if (__wine_emulate_instruction( record, context ) == ExceptionContinueExecution)
889 return EXCEPTION_CONTINUE_EXECUTION;
891 return EXCEPTION_CONTINUE_SEARCH;
895 /***********************************************************************
896 * INSTR_CallBuiltinHandler
898 void INSTR_CallBuiltinHandler( CONTEXT86 *context, BYTE intnum )
900 if (!winedos.CallBuiltinHandler) load_winedos();
901 if (winedos.CallBuiltinHandler) winedos.CallBuiltinHandler( context, intnum );
905 /***********************************************************************
906 * DOS3Call (KERNEL.102)
908 void WINAPI DOS3Call( CONTEXT86 *context )
910 INSTR_CallBuiltinHandler( context, 0x21 );
914 /***********************************************************************
915 * NetBIOSCall (KERNEL.103)
917 void WINAPI NetBIOSCall16( CONTEXT86 *context )
919 INSTR_CallBuiltinHandler( context, 0x5c );
923 /***********************************************************************
924 * GetSetKernelDOSProc (KERNEL.311)
926 FARPROC16 WINAPI GetSetKernelDOSProc16( FARPROC16 DosProc )
928 FIXME("(DosProc=%p): stub\n", DosProc);