winealsa: Remove AudioSessionManager.
[wine.git] / dlls / krnl386.exe16 / instr.c
blobb21a00d5ccf0508501986502de97874ba066dc1e
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"
34 WINE_DEFAULT_DEBUG_CHANNEL(int);
35 WINE_DECLARE_DEBUG_CHANNEL(io);
37 /* macros to set parts of a DWORD */
38 #define SET_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD(val))
39 #define SET_LOBYTE(dw,val) ((dw) = ((dw) & 0xffffff00) | LOBYTE(val))
40 #define ADD_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
42 static inline void add_stack( CONTEXT *context, int offset )
44 if (!IS_SELECTOR_32BIT(context->SegSs))
45 ADD_LOWORD( context->Esp, offset );
46 else
47 context->Esp += offset;
50 static inline void *make_ptr( CONTEXT *context, DWORD seg, DWORD off, int long_addr )
52 if (ldt_is_system(seg)) return (void *)off;
53 if (!long_addr) off = LOWORD(off);
54 return (char *) MapSL( MAKESEGPTR( seg, 0 ) ) + off;
57 static inline void *get_stack( CONTEXT *context )
59 return ldt_get_ptr( context->SegSs, context->Esp );
62 #include "pshpack1.h"
63 struct idtr
65 WORD limit;
66 BYTE *base;
68 #include "poppack.h"
70 static LDT_ENTRY idt[256];
72 static inline struct idtr get_idtr(void)
74 struct idtr ret;
75 #if defined(__i386__) && defined(__GNUC__)
76 __asm__( "sidtl %0" : "=m" (ret) );
77 #else
78 ret.base = (BYTE *)idt;
79 ret.limit = sizeof(idt) - 1;
80 #endif
81 return ret;
85 /***********************************************************************
86 * INSTR_ReplaceSelector
88 * Try to replace an invalid selector by a valid one.
89 * The only selector where it is allowed to do "mov ax,40;mov es,ax"
90 * is the so called 'bimodal' selector 0x40, which points to the BIOS
91 * data segment. Used by (at least) Borland products (and programs compiled
92 * using Borland products).
94 * See Undocumented Windows, Chapter 5, __0040.
96 static BOOL INSTR_ReplaceSelector( CONTEXT *context, WORD *sel )
98 if (*sel == 0x40)
100 DOSVM_start_bios_timer();
101 *sel = DOSMEM_BiosDataSeg;
102 return TRUE;
104 return FALSE; /* Can't replace selector, crashdump */
108 /* store an operand into a register */
109 static void store_reg_word( CONTEXT *context, BYTE regmodrm, const BYTE *addr, int long_op )
111 switch((regmodrm >> 3) & 7)
113 case 0:
114 if (long_op) context->Eax = *(const DWORD *)addr;
115 else SET_LOWORD(context->Eax, *(const WORD *)addr);
116 break;
117 case 1:
118 if (long_op) context->Ecx = *(const DWORD *)addr;
119 else SET_LOWORD(context->Ecx, *(const WORD *)addr);
120 break;
121 case 2:
122 if (long_op) context->Edx = *(const DWORD *)addr;
123 else SET_LOWORD(context->Edx, *(const WORD *)addr);
124 break;
125 case 3:
126 if (long_op) context->Ebx = *(const DWORD *)addr;
127 else SET_LOWORD(context->Ebx, *(const WORD *)addr);
128 break;
129 case 4:
130 if (long_op) context->Esp = *(const DWORD *)addr;
131 else SET_LOWORD(context->Esp, *(const WORD *)addr);
132 break;
133 case 5:
134 if (long_op) context->Ebp = *(const DWORD *)addr;
135 else SET_LOWORD(context->Ebp, *(const WORD *)addr);
136 break;
137 case 6:
138 if (long_op) context->Esi = *(const DWORD *)addr;
139 else SET_LOWORD(context->Esi, *(const WORD *)addr);
140 break;
141 case 7:
142 if (long_op) context->Edi = *(const DWORD *)addr;
143 else SET_LOWORD(context->Edi, *(const WORD *)addr);
144 break;
148 /* store an operand into a byte register */
149 static void store_reg_byte( CONTEXT *context, BYTE regmodrm, const BYTE *addr )
151 switch((regmodrm >> 3) & 7)
153 case 0: context->Eax = (context->Eax & 0xffffff00) | *addr; break;
154 case 1: context->Ecx = (context->Ecx & 0xffffff00) | *addr; break;
155 case 2: context->Edx = (context->Edx & 0xffffff00) | *addr; break;
156 case 3: context->Ebx = (context->Ebx & 0xffffff00) | *addr; break;
157 case 4: context->Eax = (context->Eax & 0xffff00ff) | (*addr << 8); break;
158 case 5: context->Ecx = (context->Ecx & 0xffff00ff) | (*addr << 8); break;
159 case 6: context->Edx = (context->Edx & 0xffff00ff) | (*addr << 8); break;
160 case 7: context->Ebx = (context->Ebx & 0xffff00ff) | (*addr << 8); break;
164 /***********************************************************************
165 * INSTR_GetOperandAddr
167 * Return the address of an instruction operand (from the mod/rm byte).
169 static BYTE *INSTR_GetOperandAddr( CONTEXT *context, BYTE *instr,
170 int long_addr, int segprefix, int *len )
172 int mod, rm, base = 0, index = 0, ss = 0, seg = 0, off;
174 #define GET_VAL(val,type) \
175 { *val = *(type *)instr; instr += sizeof(type); *len += sizeof(type); }
177 *len = 0;
178 GET_VAL( &mod, BYTE );
179 rm = mod & 7;
180 mod >>= 6;
182 if (mod == 3)
184 switch(rm)
186 case 0: return (BYTE *)&context->Eax;
187 case 1: return (BYTE *)&context->Ecx;
188 case 2: return (BYTE *)&context->Edx;
189 case 3: return (BYTE *)&context->Ebx;
190 case 4: return (BYTE *)&context->Esp;
191 case 5: return (BYTE *)&context->Ebp;
192 case 6: return (BYTE *)&context->Esi;
193 case 7: return (BYTE *)&context->Edi;
197 if (long_addr)
199 if (rm == 4)
201 BYTE sib;
202 GET_VAL( &sib, BYTE );
203 rm = sib & 7;
204 ss = sib >> 6;
205 switch((sib >> 3) & 7)
207 case 0: index = context->Eax; break;
208 case 1: index = context->Ecx; break;
209 case 2: index = context->Edx; break;
210 case 3: index = context->Ebx; break;
211 case 4: index = 0; break;
212 case 5: index = context->Ebp; break;
213 case 6: index = context->Esi; break;
214 case 7: index = context->Edi; break;
218 switch(rm)
220 case 0: base = context->Eax; seg = context->SegDs; break;
221 case 1: base = context->Ecx; seg = context->SegDs; break;
222 case 2: base = context->Edx; seg = context->SegDs; break;
223 case 3: base = context->Ebx; seg = context->SegDs; break;
224 case 4: base = context->Esp; seg = context->SegSs; break;
225 case 5: base = context->Ebp; seg = context->SegSs; break;
226 case 6: base = context->Esi; seg = context->SegDs; break;
227 case 7: base = context->Edi; seg = context->SegDs; break;
229 switch (mod)
231 case 0:
232 if (rm == 5) /* special case: ds:(disp32) */
234 GET_VAL( &base, DWORD );
235 seg = context->SegDs;
237 break;
239 case 1: /* 8-bit disp */
240 GET_VAL( &off, BYTE );
241 base += (signed char)off;
242 break;
244 case 2: /* 32-bit disp */
245 GET_VAL( &off, DWORD );
246 base += (signed long)off;
247 break;
250 else /* short address */
252 switch(rm)
254 case 0: /* ds:(bx,si) */
255 base = LOWORD(context->Ebx) + LOWORD(context->Esi);
256 seg = context->SegDs;
257 break;
258 case 1: /* ds:(bx,di) */
259 base = LOWORD(context->Ebx) + LOWORD(context->Edi);
260 seg = context->SegDs;
261 break;
262 case 2: /* ss:(bp,si) */
263 base = LOWORD(context->Ebp) + LOWORD(context->Esi);
264 seg = context->SegSs;
265 break;
266 case 3: /* ss:(bp,di) */
267 base = LOWORD(context->Ebp) + LOWORD(context->Edi);
268 seg = context->SegSs;
269 break;
270 case 4: /* ds:(si) */
271 base = LOWORD(context->Esi);
272 seg = context->SegDs;
273 break;
274 case 5: /* ds:(di) */
275 base = LOWORD(context->Edi);
276 seg = context->SegDs;
277 break;
278 case 6: /* ss:(bp) */
279 base = LOWORD(context->Ebp);
280 seg = context->SegSs;
281 break;
282 case 7: /* ds:(bx) */
283 base = LOWORD(context->Ebx);
284 seg = context->SegDs;
285 break;
288 switch(mod)
290 case 0:
291 if (rm == 6) /* special case: ds:(disp16) */
293 GET_VAL( &base, WORD );
294 seg = context->SegDs;
296 break;
298 case 1: /* 8-bit disp */
299 GET_VAL( &off, BYTE );
300 base += (signed char)off;
301 break;
303 case 2: /* 16-bit disp */
304 GET_VAL( &off, WORD );
305 base += (signed short)off;
306 break;
308 base &= 0xffff;
310 if (segprefix != -1) seg = segprefix;
312 /* Make sure the segment and offset are valid */
313 if (ldt_is_system(seg)) return (BYTE *)(base + (index << ss));
314 if ((seg & 7) != 7) return NULL;
315 if (!ldt_is_valid( seg )) return NULL;
316 if (ldt_get_limit( seg ) < (base + (index << ss))) return NULL;
317 return (BYTE *)ldt_get_base( seg ) + base + (index << ss);
318 #undef GET_VAL
322 /***********************************************************************
323 * INSTR_EmulateLDS
325 * Emulate the LDS (and LES,LFS,etc.) instruction.
327 static BOOL INSTR_EmulateLDS( CONTEXT *context, BYTE *instr, int long_op,
328 int long_addr, int segprefix, int *len )
330 WORD seg;
331 BYTE *regmodrm = instr + 1 + (*instr == 0x0f);
332 BYTE *addr = INSTR_GetOperandAddr( context, regmodrm,
333 long_addr, segprefix, len );
334 if (!addr)
335 return FALSE; /* Unable to emulate it */
336 seg = *(WORD *)(addr + (long_op ? 4 : 2));
338 if (!INSTR_ReplaceSelector( context, &seg ))
339 return FALSE; /* Unable to emulate it */
341 /* Now store the offset in the correct register */
343 store_reg_word( context, *regmodrm, addr, long_op );
345 /* Store the correct segment in the segment register */
347 switch(*instr)
349 case 0xc4: context->SegEs = seg; break; /* les */
350 case 0xc5: context->SegDs = seg; break; /* lds */
351 case 0x0f: switch(instr[1])
353 case 0xb2: context->SegSs = seg; break; /* lss */
354 case 0xb4: context->SegFs = seg; break; /* lfs */
355 case 0xb5: context->SegGs = seg; break; /* lgs */
357 break;
360 /* Add the opcode size to the total length */
362 *len += 1 + (*instr == 0x0f);
363 return TRUE;
366 /***********************************************************************
367 * INSTR_inport
369 * input on an I/O port
371 static DWORD INSTR_inport( WORD port, int size, CONTEXT *context )
373 DWORD res = DOSVM_inport( port, size );
375 if (TRACE_ON(io))
377 switch(size)
379 case 1:
380 TRACE_(io)( "0x%x < %02x @ %04x:%04x\n", port, LOBYTE(res),
381 (WORD)context->SegCs, LOWORD(context->Eip));
382 break;
383 case 2:
384 TRACE_(io)( "0x%x < %04x @ %04x:%04x\n", port, LOWORD(res),
385 (WORD)context->SegCs, LOWORD(context->Eip));
386 break;
387 case 4:
388 TRACE_(io)( "0x%x < %08lx @ %04x:%04x\n", port, res,
389 (WORD)context->SegCs, LOWORD(context->Eip));
390 break;
393 return res;
397 /***********************************************************************
398 * INSTR_outport
400 * output on an I/O port
402 static void INSTR_outport( WORD port, int size, DWORD val, CONTEXT *context )
404 DOSVM_outport( port, size, val );
406 if (TRACE_ON(io))
408 switch(size)
410 case 1:
411 TRACE_(io)("0x%x > %02x @ %04x:%04x\n", port, LOBYTE(val),
412 (WORD)context->SegCs, LOWORD(context->Eip));
413 break;
414 case 2:
415 TRACE_(io)("0x%x > %04x @ %04x:%04x\n", port, LOWORD(val),
416 (WORD)context->SegCs, LOWORD(context->Eip));
417 break;
418 case 4:
419 TRACE_(io)("0x%x > %08lx @ %04x:%04x\n", port, val,
420 (WORD)context->SegCs, LOWORD(context->Eip));
421 break;
427 /***********************************************************************
428 * __wine_emulate_instruction
430 * Emulate a privileged instruction.
431 * Returns exception continuation status.
433 DWORD __wine_emulate_instruction( EXCEPTION_RECORD *rec, CONTEXT *context )
435 int prefix, segprefix, prefixlen, len, repX, long_op, long_addr;
436 BYTE *instr;
438 long_op = long_addr = IS_SELECTOR_32BIT(context->SegCs);
439 instr = make_ptr( context, context->SegCs, context->Eip, TRUE );
440 if (!instr) return ExceptionContinueSearch;
442 /* First handle any possible prefix */
444 segprefix = -1; /* no prefix */
445 prefix = 1;
446 repX = 0;
447 prefixlen = 0;
448 while(prefix)
450 switch(*instr)
452 case 0x2e:
453 segprefix = context->SegCs;
454 break;
455 case 0x36:
456 segprefix = context->SegSs;
457 break;
458 case 0x3e:
459 segprefix = context->SegDs;
460 break;
461 case 0x26:
462 segprefix = context->SegEs;
463 break;
464 case 0x64:
465 segprefix = context->SegFs;
466 break;
467 case 0x65:
468 segprefix = context->SegGs;
469 break;
470 case 0x66:
471 long_op = !long_op; /* opcode size prefix */
472 break;
473 case 0x67:
474 long_addr = !long_addr; /* addr size prefix */
475 break;
476 case 0xf0: /* lock */
477 break;
478 case 0xf2: /* repne */
479 repX = 1;
480 break;
481 case 0xf3: /* repe */
482 repX = 2;
483 break;
484 default:
485 prefix = 0; /* no more prefixes */
486 break;
488 if (prefix)
490 instr++;
491 prefixlen++;
495 /* Now look at the actual instruction */
497 switch(*instr)
499 case 0x07: /* pop es */
500 case 0x17: /* pop ss */
501 case 0x1f: /* pop ds */
503 WORD seg = *(WORD *)get_stack( context );
504 if (INSTR_ReplaceSelector( context, &seg ))
506 switch(*instr)
508 case 0x07: context->SegEs = seg; break;
509 case 0x17: context->SegSs = seg; break;
510 case 0x1f: context->SegDs = seg; break;
512 add_stack(context, long_op ? 4 : 2);
513 context->Eip += prefixlen + 1;
514 return ExceptionContinueExecution;
517 break; /* Unable to emulate it */
519 case 0x0f: /* extended instruction */
520 switch(instr[1])
522 case 0x22: /* mov %eax, %crX */
523 switch (instr[2])
525 case 0xc0:
526 FIXME("mov %%eax, %%cr0 at 0x%08lx, EAX=0x%08lx\n",
527 context->Eip,context->Eax );
528 context->Eip += prefixlen+3;
529 return ExceptionContinueExecution;
530 default:
531 break; /* Fallthrough to bad instruction handling */
533 break; /* Fallthrough to bad instruction handling */
534 case 0x20: /* mov %crX, %eax */
535 switch (instr[2])
537 case 0xe0: /* mov %cr4, %eax */
538 /* CR4 register: See linux/arch/i386/mm/init.c, X86_CR4_ defs
539 * bit 0: VME Virtual Mode Exception ?
540 * bit 1: PVI Protected mode Virtual Interrupt
541 * bit 2: TSD Timestamp disable
542 * bit 3: DE Debugging extensions
543 * bit 4: PSE Page size extensions
544 * bit 5: PAE Physical address extension
545 * bit 6: MCE Machine check enable
546 * bit 7: PGE Enable global pages
547 * bit 8: PCE Enable performance counters at IPL3
549 FIXME("mov %%cr4, %%eax at 0x%08lx\n",context->Eip);
550 context->Eax = 0;
551 context->Eip += prefixlen+3;
552 return ExceptionContinueExecution;
553 case 0xc0: /* mov %cr0, %eax */
554 FIXME("mov %%cr0, %%eax at 0x%08lx\n",context->Eip);
555 context->Eax = 0x10; /* FIXME: set more bits ? */
556 context->Eip += prefixlen+3;
557 return ExceptionContinueExecution;
558 default: /* Fallthrough to illegal instruction */
559 break;
561 /* Fallthrough to illegal instruction */
562 break;
563 case 0x21: /* mov %drX, %eax */
564 switch (instr[2])
566 case 0xc8: /* mov %dr1, %eax */
567 TRACE("mov %%dr1, %%eax at 0x%08lx\n",context->Eip);
568 context->Eax = context->Dr1;
569 context->Eip += prefixlen+3;
570 return ExceptionContinueExecution;
571 case 0xf8: /* mov %dr7, %eax */
572 TRACE("mov %%dr7, %%eax at 0x%08lx\n",context->Eip);
573 context->Eax = 0x400;
574 context->Eip += prefixlen+3;
575 return ExceptionContinueExecution;
577 FIXME("Unsupported DR register, eip+2 is %02x\n", instr[2]);
578 /* fallthrough to illegal instruction */
579 break;
580 case 0x23: /* mov %eax, %drX */
581 switch (instr[2])
583 case 0xc8: /* mov %eax, %dr1 */
584 context->Dr1 = context->Eax;
585 context->Eip += prefixlen+3;
586 return ExceptionContinueExecution;
588 FIXME("Unsupported DR register, eip+2 is %02x\n", instr[2]);
589 /* fallthrough to illegal instruction */
590 break;
591 case 0xa1: /* pop fs */
593 WORD seg = *(WORD *)get_stack( context );
594 if (INSTR_ReplaceSelector( context, &seg ))
596 context->SegFs = seg;
597 add_stack(context, long_op ? 4 : 2);
598 context->Eip += prefixlen + 2;
599 return ExceptionContinueExecution;
602 break;
603 case 0xa9: /* pop gs */
605 WORD seg = *(WORD *)get_stack( context );
606 if (INSTR_ReplaceSelector( context, &seg ))
608 context->SegGs = seg;
609 add_stack(context, long_op ? 4 : 2);
610 context->Eip += prefixlen + 2;
611 return ExceptionContinueExecution;
614 break;
615 case 0xb2: /* lss addr,reg */
616 case 0xb4: /* lfs addr,reg */
617 case 0xb5: /* lgs addr,reg */
618 if (INSTR_EmulateLDS( context, instr, long_op,
619 long_addr, segprefix, &len ))
621 context->Eip += prefixlen + len;
622 return ExceptionContinueExecution;
624 break;
626 break; /* Unable to emulate it */
628 case 0x6c: /* insb */
629 case 0x6d: /* insw/d */
630 case 0x6e: /* outsb */
631 case 0x6f: /* outsw/d */
633 int typ = *instr; /* Just in case it's overwritten. */
634 int outp = (typ >= 0x6e);
635 unsigned long count = repX ?
636 (long_addr ? context->Ecx : LOWORD(context->Ecx)) : 1;
637 int opsize = (typ & 1) ? (long_op ? 4 : 2) : 1;
638 int step = (context->EFlags & 0x400) ? -opsize : +opsize;
639 int seg;
641 if (outp)
643 /* Check if there is a segment prefix override and honour it */
644 seg = segprefix == -1 ? context->SegDs : segprefix;
645 /* FIXME: Check segment is readable. */
647 else
649 seg = context->SegEs;
650 /* FIXME: Check segment is writable. */
653 if (repX)
655 if (long_addr) context->Ecx = 0;
656 else SET_LOWORD(context->Ecx,0);
659 while (count-- > 0)
661 void *data;
662 WORD dx = LOWORD(context->Edx);
663 if (outp)
665 data = make_ptr( context, seg, context->Esi, long_addr );
666 if (long_addr) context->Esi += step;
667 else ADD_LOWORD(context->Esi,step);
669 else
671 data = make_ptr( context, seg, context->Edi, long_addr );
672 if (long_addr) context->Edi += step;
673 else ADD_LOWORD(context->Edi,step);
676 switch (typ)
678 case 0x6c:
679 *(BYTE *)data = INSTR_inport( dx, 1, context );
680 break;
681 case 0x6d:
682 if (long_op)
683 *(DWORD *)data = INSTR_inport( dx, 4, context );
684 else
685 *(WORD *)data = INSTR_inport( dx, 2, context );
686 break;
687 case 0x6e:
688 INSTR_outport( dx, 1, *(BYTE *)data, context );
689 break;
690 case 0x6f:
691 if (long_op)
692 INSTR_outport( dx, 4, *(DWORD *)data, context );
693 else
694 INSTR_outport( dx, 2, *(WORD *)data, context );
695 break;
698 context->Eip += prefixlen + 1;
700 return ExceptionContinueExecution;
702 case 0x8a: /* mov Eb, Gb */
703 case 0x8b: /* mov Ev, Gv */
705 BYTE *data = INSTR_GetOperandAddr(context, instr + 1, long_addr,
706 segprefix, &len);
707 unsigned int data_size = (*instr == 0x8b) ? (long_op ? 4 : 2) : 1;
708 struct idtr idtr = get_idtr();
709 unsigned int offset = data - idtr.base;
711 if (offset <= idtr.limit + 1 - data_size)
713 idt[1].LimitLow = 0x100; /* FIXME */
714 idt[2].LimitLow = 0x11E; /* FIXME */
715 idt[3].LimitLow = 0x500; /* FIXME */
717 switch (*instr)
719 case 0x8a: store_reg_byte( context, instr[1], (BYTE *)idt + offset ); break;
720 case 0x8b: store_reg_word( context, instr[1], (BYTE *)idt + offset, long_op ); break;
722 context->Eip += prefixlen + len + 1;
723 return ExceptionContinueExecution;
726 break; /* Unable to emulate it */
728 case 0x8e: /* mov XX,segment_reg */
730 WORD seg;
731 BYTE *addr = INSTR_GetOperandAddr(context, instr + 1,
732 long_addr, segprefix, &len );
733 if (!addr)
734 break; /* Unable to emulate it */
735 seg = *(WORD *)addr;
736 if (!INSTR_ReplaceSelector( context, &seg ))
737 break; /* Unable to emulate it */
739 switch((instr[1] >> 3) & 7)
741 case 0:
742 context->SegEs = seg;
743 context->Eip += prefixlen + len + 1;
744 return ExceptionContinueExecution;
745 case 1: /* cs */
746 break;
747 case 2:
748 context->SegSs = seg;
749 context->Eip += prefixlen + len + 1;
750 return ExceptionContinueExecution;
751 case 3:
752 context->SegDs = seg;
753 context->Eip += prefixlen + len + 1;
754 return ExceptionContinueExecution;
755 case 4:
756 context->SegFs = seg;
757 context->Eip += prefixlen + len + 1;
758 return ExceptionContinueExecution;
759 case 5:
760 context->SegGs = seg;
761 context->Eip += prefixlen + len + 1;
762 return ExceptionContinueExecution;
763 case 6: /* unused */
764 case 7: /* unused */
765 break;
768 break; /* Unable to emulate it */
770 case 0xc4: /* les addr,reg */
771 case 0xc5: /* lds addr,reg */
772 if (INSTR_EmulateLDS( context, instr, long_op,
773 long_addr, segprefix, &len ))
775 context->Eip += prefixlen + len;
776 return ExceptionContinueExecution;
778 break; /* Unable to emulate it */
780 case 0xcd: /* int <XX> */
781 context->Eip += prefixlen + 2;
782 if (DOSVM_EmulateInterruptPM( context, instr[1] )) return ExceptionContinueExecution;
783 context->Eip -= prefixlen + 2; /* restore eip */
784 break; /* Unable to emulate it */
786 case 0xcf: /* iret */
787 if (ldt_is_system(context->SegCs)) break; /* don't emulate it in 32-bit code */
788 if (long_op)
790 DWORD *stack = get_stack( context );
791 context->Eip = *stack++;
792 context->SegCs = *stack++;
793 context->EFlags = *stack;
794 add_stack(context, 3*sizeof(DWORD)); /* Pop the return address and flags */
796 else
798 WORD *stack = get_stack( context );
799 context->Eip = *stack++;
800 context->SegCs = *stack++;
801 SET_LOWORD(context->EFlags,*stack);
802 add_stack(context, 3*sizeof(WORD)); /* Pop the return address and flags */
804 return ExceptionContinueExecution;
806 case 0xe4: /* inb al,XX */
807 SET_LOBYTE(context->Eax,INSTR_inport( instr[1], 1, context ));
808 context->Eip += prefixlen + 2;
809 return ExceptionContinueExecution;
811 case 0xe5: /* in (e)ax,XX */
812 if (long_op)
813 context->Eax = INSTR_inport( instr[1], 4, context );
814 else
815 SET_LOWORD(context->Eax, INSTR_inport( instr[1], 2, context ));
816 context->Eip += prefixlen + 2;
817 return ExceptionContinueExecution;
819 case 0xe6: /* outb XX,al */
820 INSTR_outport( instr[1], 1, LOBYTE(context->Eax), context );
821 context->Eip += prefixlen + 2;
822 return ExceptionContinueExecution;
824 case 0xe7: /* out XX,(e)ax */
825 if (long_op)
826 INSTR_outport( instr[1], 4, context->Eax, context );
827 else
828 INSTR_outport( instr[1], 2, LOWORD(context->Eax), context );
829 context->Eip += prefixlen + 2;
830 return ExceptionContinueExecution;
832 case 0xec: /* inb al,dx */
833 SET_LOBYTE(context->Eax, INSTR_inport( LOWORD(context->Edx), 1, context ) );
834 context->Eip += prefixlen + 1;
835 return ExceptionContinueExecution;
837 case 0xed: /* in (e)ax,dx */
838 if (long_op)
839 context->Eax = INSTR_inport( LOWORD(context->Edx), 4, context );
840 else
841 SET_LOWORD(context->Eax, INSTR_inport( LOWORD(context->Edx), 2, context ));
842 context->Eip += prefixlen + 1;
843 return ExceptionContinueExecution;
845 case 0xee: /* outb dx,al */
846 INSTR_outport( LOWORD(context->Edx), 1, LOBYTE(context->Eax), context );
847 context->Eip += prefixlen + 1;
848 return ExceptionContinueExecution;
850 case 0xef: /* out dx,(e)ax */
851 if (long_op)
852 INSTR_outport( LOWORD(context->Edx), 4, context->Eax, context );
853 else
854 INSTR_outport( LOWORD(context->Edx), 2, LOWORD(context->Eax), context );
855 context->Eip += prefixlen + 1;
856 return ExceptionContinueExecution;
858 case 0xfa: /* cli */
859 context->Eip += prefixlen + 1;
860 return ExceptionContinueExecution;
862 case 0xfb: /* sti */
863 context->Eip += prefixlen + 1;
864 return ExceptionContinueExecution;
866 return ExceptionContinueSearch; /* Unable to emulate it */
870 /***********************************************************************
871 * INSTR_vectored_handler
873 * Vectored exception handler used to emulate protected instructions
874 * from 32-bit code.
876 LONG CALLBACK INSTR_vectored_handler( EXCEPTION_POINTERS *ptrs )
878 EXCEPTION_RECORD *record = ptrs->ExceptionRecord;
879 CONTEXT *context = ptrs->ContextRecord;
881 if (ldt_is_system(context->SegCs) &&
882 (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION ||
883 record->ExceptionCode == EXCEPTION_PRIV_INSTRUCTION))
885 if (__wine_emulate_instruction( record, context ) == ExceptionContinueExecution)
886 return EXCEPTION_CONTINUE_EXECUTION;
888 return EXCEPTION_CONTINUE_SEARCH;
892 /***********************************************************************
893 * DOS3Call (KERNEL.102)
895 void WINAPI DOS3Call( CONTEXT *context )
897 __wine_call_int_handler16( 0x21, context );
901 /***********************************************************************
902 * NetBIOSCall (KERNEL.103)
904 void WINAPI NetBIOSCall16( CONTEXT *context )
906 __wine_call_int_handler16( 0x5c, context );
910 /***********************************************************************
911 * GetSetKernelDOSProc (KERNEL.311)
913 FARPROC16 WINAPI GetSetKernelDOSProc16( FARPROC16 DosProc )
915 FIXME("(DosProc=%p): stub\n", DosProc);
916 return NULL;