hidclass.sys: Support parsing of explicit usage page.
[wine.git] / dlls / krnl386.exe16 / instr.c
blobff7f866f9e01a8bb61d56e9f04b63f7b7856f5ae
1 /*
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
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winternl.h"
28 #include "wine/winuser16.h"
29 #include "excpt.h"
30 #include "wine/debug.h"
31 #include "kernel16_private.h"
32 #include "dosexe.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 );
47 else
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 );
63 #include "pshpack1.h"
64 struct idtr
66 WORD limit;
67 BYTE *base;
69 #include "poppack.h"
71 static LDT_ENTRY idt[256];
73 static inline struct idtr get_idtr(void)
75 struct idtr ret;
76 #if defined(__i386__) && defined(__GNUC__)
77 __asm__( "sidtl %0" : "=m" (ret) );
78 #else
79 ret.base = (BYTE *)idt;
80 ret.limit = sizeof(idt) - 1;
81 #endif
82 return ret;
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 )
99 if (*sel == 0x40)
101 DOSVM_start_bios_timer();
102 *sel = DOSMEM_BiosDataSeg;
103 return TRUE;
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)
114 case 0:
115 if (long_op) context->Eax = *(const DWORD *)addr;
116 else SET_LOWORD(context->Eax, *(const WORD *)addr);
117 break;
118 case 1:
119 if (long_op) context->Ecx = *(const DWORD *)addr;
120 else SET_LOWORD(context->Ecx, *(const WORD *)addr);
121 break;
122 case 2:
123 if (long_op) context->Edx = *(const DWORD *)addr;
124 else SET_LOWORD(context->Edx, *(const WORD *)addr);
125 break;
126 case 3:
127 if (long_op) context->Ebx = *(const DWORD *)addr;
128 else SET_LOWORD(context->Ebx, *(const WORD *)addr);
129 break;
130 case 4:
131 if (long_op) context->Esp = *(const DWORD *)addr;
132 else SET_LOWORD(context->Esp, *(const WORD *)addr);
133 break;
134 case 5:
135 if (long_op) context->Ebp = *(const DWORD *)addr;
136 else SET_LOWORD(context->Ebp, *(const WORD *)addr);
137 break;
138 case 6:
139 if (long_op) context->Esi = *(const DWORD *)addr;
140 else SET_LOWORD(context->Esi, *(const WORD *)addr);
141 break;
142 case 7:
143 if (long_op) context->Edi = *(const DWORD *)addr;
144 else SET_LOWORD(context->Edi, *(const WORD *)addr);
145 break;
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); }
178 *len = 0;
179 GET_VAL( &mod, BYTE );
180 rm = mod & 7;
181 mod >>= 6;
183 if (mod == 3)
185 switch(rm)
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;
198 if (long_addr)
200 if (rm == 4)
202 BYTE sib;
203 GET_VAL( &sib, BYTE );
204 rm = sib & 7;
205 ss = sib >> 6;
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;
219 switch(rm)
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;
230 switch (mod)
232 case 0:
233 if (rm == 5) /* special case: ds:(disp32) */
235 GET_VAL( &base, DWORD );
236 seg = context->SegDs;
238 break;
240 case 1: /* 8-bit disp */
241 GET_VAL( &off, BYTE );
242 base += (signed char)off;
243 break;
245 case 2: /* 32-bit disp */
246 GET_VAL( &off, DWORD );
247 base += (signed long)off;
248 break;
251 else /* short address */
253 switch(rm)
255 case 0: /* ds:(bx,si) */
256 base = LOWORD(context->Ebx) + LOWORD(context->Esi);
257 seg = context->SegDs;
258 break;
259 case 1: /* ds:(bx,di) */
260 base = LOWORD(context->Ebx) + LOWORD(context->Edi);
261 seg = context->SegDs;
262 break;
263 case 2: /* ss:(bp,si) */
264 base = LOWORD(context->Ebp) + LOWORD(context->Esi);
265 seg = context->SegSs;
266 break;
267 case 3: /* ss:(bp,di) */
268 base = LOWORD(context->Ebp) + LOWORD(context->Edi);
269 seg = context->SegSs;
270 break;
271 case 4: /* ds:(si) */
272 base = LOWORD(context->Esi);
273 seg = context->SegDs;
274 break;
275 case 5: /* ds:(di) */
276 base = LOWORD(context->Edi);
277 seg = context->SegDs;
278 break;
279 case 6: /* ss:(bp) */
280 base = LOWORD(context->Ebp);
281 seg = context->SegSs;
282 break;
283 case 7: /* ds:(bx) */
284 base = LOWORD(context->Ebx);
285 seg = context->SegDs;
286 break;
289 switch(mod)
291 case 0:
292 if (rm == 6) /* special case: ds:(disp16) */
294 GET_VAL( &base, WORD );
295 seg = context->SegDs;
297 break;
299 case 1: /* 8-bit disp */
300 GET_VAL( &off, BYTE );
301 base += (signed char)off;
302 break;
304 case 2: /* 16-bit disp */
305 GET_VAL( &off, WORD );
306 base += (signed short)off;
307 break;
309 base &= 0xffff;
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);
319 #undef GET_VAL
323 /***********************************************************************
324 * INSTR_EmulateLDS
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 )
331 WORD seg;
332 BYTE *regmodrm = instr + 1 + (*instr == 0x0f);
333 BYTE *addr = INSTR_GetOperandAddr( context, regmodrm,
334 long_addr, segprefix, len );
335 if (!addr)
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 */
348 switch(*instr)
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 */
358 break;
361 /* Add the opcode size to the total length */
363 *len += 1 + (*instr == 0x0f);
364 return TRUE;
367 /***********************************************************************
368 * INSTR_inport
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 );
376 if (TRACE_ON(io))
378 switch(size)
380 case 1:
381 TRACE_(io)( "0x%x < %02x @ %04x:%04x\n", port, LOBYTE(res),
382 (WORD)context->SegCs, LOWORD(context->Eip));
383 break;
384 case 2:
385 TRACE_(io)( "0x%x < %04x @ %04x:%04x\n", port, LOWORD(res),
386 (WORD)context->SegCs, LOWORD(context->Eip));
387 break;
388 case 4:
389 TRACE_(io)( "0x%x < %08x @ %04x:%04x\n", port, res,
390 (WORD)context->SegCs, LOWORD(context->Eip));
391 break;
394 return res;
398 /***********************************************************************
399 * INSTR_outport
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 );
407 if (TRACE_ON(io))
409 switch(size)
411 case 1:
412 TRACE_(io)("0x%x > %02x @ %04x:%04x\n", port, LOBYTE(val),
413 (WORD)context->SegCs, LOWORD(context->Eip));
414 break;
415 case 2:
416 TRACE_(io)("0x%x > %04x @ %04x:%04x\n", port, LOWORD(val),
417 (WORD)context->SegCs, LOWORD(context->Eip));
418 break;
419 case 4:
420 TRACE_(io)("0x%x > %08x @ %04x:%04x\n", port, val,
421 (WORD)context->SegCs, LOWORD(context->Eip));
422 break;
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;
437 BYTE *instr;
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 */
446 prefix = 1;
447 repX = 0;
448 prefixlen = 0;
449 while(prefix)
451 switch(*instr)
453 case 0x2e:
454 segprefix = context->SegCs;
455 break;
456 case 0x36:
457 segprefix = context->SegSs;
458 break;
459 case 0x3e:
460 segprefix = context->SegDs;
461 break;
462 case 0x26:
463 segprefix = context->SegEs;
464 break;
465 case 0x64:
466 segprefix = context->SegFs;
467 break;
468 case 0x65:
469 segprefix = context->SegGs;
470 break;
471 case 0x66:
472 long_op = !long_op; /* opcode size prefix */
473 break;
474 case 0x67:
475 long_addr = !long_addr; /* addr size prefix */
476 break;
477 case 0xf0: /* lock */
478 break;
479 case 0xf2: /* repne */
480 repX = 1;
481 break;
482 case 0xf3: /* repe */
483 repX = 2;
484 break;
485 default:
486 prefix = 0; /* no more prefixes */
487 break;
489 if (prefix)
491 instr++;
492 prefixlen++;
496 /* Now look at the actual instruction */
498 switch(*instr)
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 ))
507 switch(*instr)
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 */
521 switch(instr[1])
523 case 0x22: /* mov %eax, %crX */
524 switch (instr[2])
526 case 0xc0:
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;
531 default:
532 break; /* Fallthrough to bad instruction handling */
534 break; /* Fallthrough to bad instruction handling */
535 case 0x20: /* mov %crX, %eax */
536 switch (instr[2])
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);
551 context->Eax = 0;
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 */
560 break;
562 /* Fallthrough to illegal instruction */
563 break;
564 case 0x21: /* mov %drX, %eax */
565 switch (instr[2])
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 */
580 break;
581 case 0x23: /* mov %eax, %drX */
582 switch (instr[2])
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 */
591 break;
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;
603 break;
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;
615 break;
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;
625 break;
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;
640 int seg;
642 if (outp)
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. */
648 else
650 seg = context->SegEs;
651 /* FIXME: Check segment is writable. */
654 if (repX)
656 if (long_addr) context->Ecx = 0;
657 else SET_LOWORD(context->Ecx,0);
660 while (count-- > 0)
662 void *data;
663 WORD dx = LOWORD(context->Edx);
664 if (outp)
666 data = make_ptr( context, seg, context->Esi, long_addr );
667 if (long_addr) context->Esi += step;
668 else ADD_LOWORD(context->Esi,step);
670 else
672 data = make_ptr( context, seg, context->Edi, long_addr );
673 if (long_addr) context->Edi += step;
674 else ADD_LOWORD(context->Edi,step);
677 switch (typ)
679 case 0x6c:
680 *(BYTE *)data = INSTR_inport( dx, 1, context );
681 break;
682 case 0x6d:
683 if (long_op)
684 *(DWORD *)data = INSTR_inport( dx, 4, context );
685 else
686 *(WORD *)data = INSTR_inport( dx, 2, context );
687 break;
688 case 0x6e:
689 INSTR_outport( dx, 1, *(BYTE *)data, context );
690 break;
691 case 0x6f:
692 if (long_op)
693 INSTR_outport( dx, 4, *(DWORD *)data, context );
694 else
695 INSTR_outport( dx, 2, *(WORD *)data, context );
696 break;
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,
707 segprefix, &len);
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 */
718 switch (*instr)
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 */
731 WORD seg;
732 BYTE *addr = INSTR_GetOperandAddr(context, instr + 1,
733 long_addr, segprefix, &len );
734 if (!addr)
735 break; /* Unable to emulate it */
736 seg = *(WORD *)addr;
737 if (!INSTR_ReplaceSelector( context, &seg ))
738 break; /* Unable to emulate it */
740 switch((instr[1] >> 3) & 7)
742 case 0:
743 context->SegEs = seg;
744 context->Eip += prefixlen + len + 1;
745 return ExceptionContinueExecution;
746 case 1: /* cs */
747 break;
748 case 2:
749 context->SegSs = seg;
750 context->Eip += prefixlen + len + 1;
751 return ExceptionContinueExecution;
752 case 3:
753 context->SegDs = seg;
754 context->Eip += prefixlen + len + 1;
755 return ExceptionContinueExecution;
756 case 4:
757 context->SegFs = seg;
758 context->Eip += prefixlen + len + 1;
759 return ExceptionContinueExecution;
760 case 5:
761 context->SegGs = seg;
762 context->Eip += prefixlen + len + 1;
763 return ExceptionContinueExecution;
764 case 6: /* unused */
765 case 7: /* unused */
766 break;
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 */
789 if (long_op)
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 */
797 else
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 */
813 if (long_op)
814 context->Eax = INSTR_inport( instr[1], 4, context );
815 else
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 */
826 if (long_op)
827 INSTR_outport( instr[1], 4, context->Eax, context );
828 else
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 */
839 if (long_op)
840 context->Eax = INSTR_inport( LOWORD(context->Edx), 4, context );
841 else
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 */
852 if (long_op)
853 INSTR_outport( LOWORD(context->Edx), 4, context->Eax, context );
854 else
855 INSTR_outport( LOWORD(context->Edx), 2, LOWORD(context->Eax), context );
856 context->Eip += prefixlen + 1;
857 return ExceptionContinueExecution;
859 case 0xfa: /* cli */
860 context->Eip += prefixlen + 1;
861 return ExceptionContinueExecution;
863 case 0xfb: /* sti */
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
875 * from 32-bit code.
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);
917 return NULL;