Added IDT emulation.
[wine/testsucceed.git] / dlls / kernel / instr.c
blobbcce920867df3e36512e1c5ae3ddd4498175d385
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "config.h"
24 #include "wine/port.h"
26 #include <stdarg.h>
28 #include "ntstatus.h"
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "wine/winuser16.h"
33 #include "excpt.h"
34 #include "thread.h"
35 #include "wine/debug.h"
36 #include "kernel_private.h"
37 #include "kernel16_private.h"
38 #include "wine/exception.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(int);
41 WINE_DECLARE_DEBUG_CHANNEL(io);
43 /* macros to set parts of a DWORD */
44 #define SET_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD(val))
45 #define SET_LOBYTE(dw,val) ((dw) = ((dw) & 0xffffff00) | LOBYTE(val))
46 #define ADD_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val)))
47 #define ISV86(context) ((context)->EFlags & 0x00020000)
49 inline static void add_stack( CONTEXT86 *context, int offset )
51 if (ISV86(context) || !IS_SELECTOR_32BIT(context->SegSs))
52 ADD_LOWORD( context->Esp, offset );
53 else
54 context->Esp += offset;
57 inline static void *make_ptr( CONTEXT86 *context, DWORD seg, DWORD off, int long_addr )
59 if (ISV86(context)) return (void *)((seg << 4) + LOWORD(off));
60 if (wine_ldt_is_system(seg)) return (void *)off;
61 if (!long_addr) off = LOWORD(off);
62 return (char *) MapSL( MAKESEGPTR( seg, 0 ) ) + off;
65 inline static void *get_stack( CONTEXT86 *context )
67 if (ISV86(context)) return (void *)((context->SegSs << 4) + LOWORD(context->Esp));
68 return wine_ldt_get_ptr( context->SegSs, context->Esp );
71 #include "pshpack1.h"
72 struct idtr
74 WORD limit;
75 BYTE *base;
77 #include "poppack.h"
79 static LDT_ENTRY idt[256];
81 inline static struct idtr get_idtr(void)
83 struct idtr ret;
84 #if defined(__i386__) && defined(__GNUC__)
85 __asm__( "sidtl %0" : "=m" (ret) );
86 #else
87 ret.base = (BYTE *)idt;
88 ret.limit = sizeof(idt) - 1;
89 #endif
90 return ret;
94 /***********************************************************************
95 * INSTR_ReplaceSelector
97 * Try to replace an invalid selector by a valid one.
98 * The only selector where it is allowed to do "mov ax,40;mov es,ax"
99 * is the so called 'bimodal' selector 0x40, which points to the BIOS
100 * data segment. Used by (at least) Borland products (and programs compiled
101 * using Borland products).
103 * See Undocumented Windows, Chapter 5, __0040.
105 static BOOL INSTR_ReplaceSelector( CONTEXT86 *context, WORD *sel )
107 if (*sel == 0x40)
109 static WORD sys_timer = 0;
110 if (!sys_timer)
112 if (!winedos.BiosTick) load_winedos();
113 if (winedos.BiosTick)
114 sys_timer = CreateSystemTimer( 55, winedos.BiosTick );
116 *sel = DOSMEM_BiosDataSeg;
117 return TRUE;
119 return FALSE; /* Can't replace selector, crashdump */
123 /* store an operand into a register */
124 static void store_reg( CONTEXT86 *context, BYTE regmodrm, const BYTE *addr, int long_op )
126 switch((regmodrm >> 3) & 7)
128 case 0:
129 if (long_op) context->Eax = *(DWORD *)addr;
130 else SET_LOWORD(context->Eax,*(WORD *)addr);
131 break;
132 case 1:
133 if (long_op) context->Ecx = *(DWORD *)addr;
134 else SET_LOWORD(context->Ecx,*(WORD *)addr);
135 break;
136 case 2:
137 if (long_op) context->Edx = *(DWORD *)addr;
138 else SET_LOWORD(context->Edx,*(WORD *)addr);
139 break;
140 case 3:
141 if (long_op) context->Ebx = *(DWORD *)addr;
142 else SET_LOWORD(context->Ebx,*(WORD *)addr);
143 break;
144 case 4:
145 if (long_op) context->Esp = *(DWORD *)addr;
146 else SET_LOWORD(context->Esp,*(WORD *)addr);
147 break;
148 case 5:
149 if (long_op) context->Ebp = *(DWORD *)addr;
150 else SET_LOWORD(context->Ebp,*(WORD *)addr);
151 break;
152 case 6:
153 if (long_op) context->Esi = *(DWORD *)addr;
154 else SET_LOWORD(context->Esi,*(WORD *)addr);
155 break;
156 case 7:
157 if (long_op) context->Edi = *(DWORD *)addr;
158 else SET_LOWORD(context->Edi,*(WORD *)addr);
159 break;
163 /***********************************************************************
164 * INSTR_GetOperandAddr
166 * Return the address of an instruction operand (from the mod/rm byte).
168 static BYTE *INSTR_GetOperandAddr( CONTEXT86 *context, BYTE *instr,
169 int long_addr, int segprefix, int *len )
171 int mod, rm, base = 0, index = 0, ss = 0, seg = 0, off;
172 LDT_ENTRY entry;
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)
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 (wine_ldt_is_system(seg)) return (BYTE *)(base + (index << ss));
314 if ((seg & 7) != 7) return NULL;
315 wine_ldt_get_entry( seg, &entry );
316 if (wine_ldt_is_empty( &entry )) return NULL;
317 if (wine_ldt_get_limit(&entry) < (base + (index << ss))) return NULL;
318 return (BYTE *)wine_ldt_get_base(&entry) + 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( CONTEXT86 *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( 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, CONTEXT86 *context )
374 DWORD res = ~0U;
376 if (!winedos.inport) load_winedos();
377 if (winedos.inport) res = winedos.inport( port, size );
379 if (TRACE_ON(io))
381 switch(size)
383 case 1:
384 DPRINTF( "0x%x < %02x @ %04x:%04x\n", port, LOBYTE(res),
385 (WORD)context->SegCs, LOWORD(context->Eip));
386 break;
387 case 2:
388 DPRINTF( "0x%x < %04x @ %04x:%04x\n", port, LOWORD(res),
389 (WORD)context->SegCs, LOWORD(context->Eip));
390 break;
391 case 4:
392 DPRINTF( "0x%x < %08lx @ %04x:%04x\n", port, res,
393 (WORD)context->SegCs, LOWORD(context->Eip));
394 break;
397 return res;
401 /***********************************************************************
402 * INSTR_outport
404 * output on an I/O port
406 static void INSTR_outport( WORD port, int size, DWORD val, CONTEXT86 *context )
408 if (!winedos.outport) load_winedos();
409 if (winedos.outport) winedos.outport( port, size, val );
411 if (TRACE_ON(io))
413 switch(size)
415 case 1:
416 DPRINTF("0x%x > %02x @ %04x:%04x\n", port, LOBYTE(val),
417 (WORD)context->SegCs, LOWORD(context->Eip));
418 break;
419 case 2:
420 DPRINTF("0x%x > %04x @ %04x:%04x\n", port, LOWORD(val),
421 (WORD)context->SegCs, LOWORD(context->Eip));
422 break;
423 case 4:
424 DPRINTF("0x%x > %08lx @ %04x:%04x\n", port, val,
425 (WORD)context->SegCs, LOWORD(context->Eip));
426 break;
432 /***********************************************************************
433 * INSTR_EmulateInstruction
435 * Emulate a privileged instruction.
436 * Returns exception continuation status.
438 DWORD INSTR_EmulateInstruction( EXCEPTION_RECORD *rec, CONTEXT86 *context )
440 int prefix, segprefix, prefixlen, len, repX, long_op, long_addr;
441 BYTE *instr;
443 long_op = long_addr = (!ISV86(context) && IS_SELECTOR_32BIT(context->SegCs));
444 instr = make_ptr( context, context->SegCs, context->Eip, TRUE );
445 if (!instr) return ExceptionContinueSearch;
447 /* First handle any possible prefix */
449 segprefix = -1; /* no prefix */
450 prefix = 1;
451 repX = 0;
452 prefixlen = 0;
453 while(prefix)
455 switch(*instr)
457 case 0x2e:
458 segprefix = context->SegCs;
459 break;
460 case 0x36:
461 segprefix = context->SegSs;
462 break;
463 case 0x3e:
464 segprefix = context->SegDs;
465 break;
466 case 0x26:
467 segprefix = context->SegEs;
468 break;
469 case 0x64:
470 segprefix = context->SegFs;
471 break;
472 case 0x65:
473 segprefix = context->SegGs;
474 break;
475 case 0x66:
476 long_op = !long_op; /* opcode size prefix */
477 break;
478 case 0x67:
479 long_addr = !long_addr; /* addr size prefix */
480 break;
481 case 0xf0: /* lock */
482 break;
483 case 0xf2: /* repne */
484 repX = 1;
485 break;
486 case 0xf3: /* repe */
487 repX = 2;
488 break;
489 default:
490 prefix = 0; /* no more prefixes */
491 break;
493 if (prefix)
495 instr++;
496 prefixlen++;
500 /* Now look at the actual instruction */
502 switch(*instr)
504 case 0x07: /* pop es */
505 case 0x17: /* pop ss */
506 case 0x1f: /* pop ds */
508 WORD seg = *(WORD *)get_stack( context );
509 if (INSTR_ReplaceSelector( context, &seg ))
511 switch(*instr)
513 case 0x07: context->SegEs = seg; break;
514 case 0x17: context->SegSs = seg; break;
515 case 0x1f: context->SegDs = seg; break;
517 add_stack(context, long_op ? 4 : 2);
518 context->Eip += prefixlen + 1;
519 return ExceptionContinueExecution;
522 break; /* Unable to emulate it */
524 case 0x0f: /* extended instruction */
525 switch(instr[1])
527 case 0x22: /* mov eax, crX */
528 switch (instr[2])
530 case 0xc0:
531 ERR("mov eax,cr0 at 0x%08lx, EAX=0x%08lx\n",
532 context->Eip,context->Eax );
533 context->Eip += prefixlen+3;
534 return ExceptionContinueExecution;
535 default:
536 break; /*fallthrough to bad instruction handling */
538 break; /*fallthrough to bad instruction handling */
539 case 0x20: /* mov crX, eax */
540 switch (instr[2])
542 case 0xe0: /* mov cr4, eax */
543 /* CR4 register . See linux/arch/i386/mm/init.c, X86_CR4_ defs
544 * bit 0: VME Virtual Mode Exception ?
545 * bit 1: PVI Protected mode Virtual Interrupt
546 * bit 2: TSD Timestamp disable
547 * bit 3: DE Debugging extensions
548 * bit 4: PSE Page size extensions
549 * bit 5: PAE Physical address extension
550 * bit 6: MCE Machine check enable
551 * bit 7: PGE Enable global pages
552 * bit 8: PCE Enable performance counters at IPL3
554 ERR("mov cr4,eax at 0x%08lx\n",context->Eip);
555 context->Eax = 0;
556 context->Eip += prefixlen+3;
557 return ExceptionContinueExecution;
558 case 0xc0: /* mov cr0, eax */
559 ERR("mov cr0,eax at 0x%08lx\n",context->Eip);
560 context->Eax = 0x10; /* FIXME: set more bits ? */
561 context->Eip += prefixlen+3;
562 return ExceptionContinueExecution;
563 default: /* fallthrough to illegal instruction */
564 break;
566 /* fallthrough to illegal instruction */
567 break;
568 case 0x21: /* mov drX, eax */
569 switch (instr[2])
571 case 0xc8: /* mov dr1, eax */
572 context->ContextFlags = CONTEXT_DEBUG_REGISTERS;
573 NtGetContextThread( GetCurrentThread(), context );
574 TRACE("mov dr1,eax at 0x%08lx\n",context->Eip);
575 context->Eax = context->Dr1;
576 context->Eip += prefixlen+3;
577 return ExceptionContinueExecution;
578 case 0xf8: /* mov dr7, eax */
579 TRACE("mov dr7,eax at 0x%08lx\n",context->Eip);
580 context->Eax = 0x400;
581 context->Eip += prefixlen+3;
582 return ExceptionContinueExecution;
584 ERR("Unsupported DR register, eip+2 is %02x\n", instr[2]);
585 /* fallthrough to illegal instruction */
586 break;
587 case 0x23: /* mov eax drX */
588 switch (instr[2])
590 case 0xc8: /* mov eax, dr1 */
591 context->ContextFlags = CONTEXT_DEBUG_REGISTERS;
592 NtGetContextThread( GetCurrentThread(), context );
593 context->Dr1 = context->Eax;
594 context->Eip += prefixlen+3;
595 context->ContextFlags = CONTEXT_DEBUG_REGISTERS;
596 NtSetContextThread( GetCurrentThread(), context );
597 return ExceptionContinueExecution;
599 ERR("Unsupported DR register, eip+2 is %02x\n", instr[2]);
600 /* fallthrough to illegal instruction */
601 break;
602 case 0xa1: /* pop fs */
604 WORD seg = *(WORD *)get_stack( context );
605 if (INSTR_ReplaceSelector( context, &seg ))
607 context->SegFs = seg;
608 add_stack(context, long_op ? 4 : 2);
609 context->Eip += prefixlen + 2;
610 return ExceptionContinueExecution;
613 break;
614 case 0xa9: /* pop gs */
616 WORD seg = *(WORD *)get_stack( context );
617 if (INSTR_ReplaceSelector( context, &seg ))
619 context->SegGs = seg;
620 add_stack(context, long_op ? 4 : 2);
621 context->Eip += prefixlen + 2;
622 return ExceptionContinueExecution;
625 break;
626 case 0xb2: /* lss addr,reg */
627 case 0xb4: /* lfs addr,reg */
628 case 0xb5: /* lgs addr,reg */
629 if (INSTR_EmulateLDS( context, instr, long_op,
630 long_addr, segprefix, &len ))
632 context->Eip += prefixlen + len;
633 return ExceptionContinueExecution;
635 break;
637 break; /* Unable to emulate it */
639 case 0x6c: /* insb */
640 case 0x6d: /* insw/d */
641 case 0x6e: /* outsb */
642 case 0x6f: /* outsw/d */
644 int typ = *instr; /* Just in case it's overwritten. */
645 int outp = (typ >= 0x6e);
646 unsigned long count = repX ?
647 (long_addr ? context->Ecx : LOWORD(context->Ecx)) : 1;
648 int opsize = (typ & 1) ? (long_op ? 4 : 2) : 1;
649 int step = (context->EFlags & 0x400) ? -opsize : +opsize;
650 int seg = outp ? context->SegDs : context->SegEs; /* FIXME: is this right? */
652 if (outp)
653 /* FIXME: Check segment readable. */
654 (void)0;
655 else
656 /* FIXME: Check segment writeable. */
657 (void)0;
659 if (repX)
661 if (long_addr) context->Ecx = 0;
662 else SET_LOWORD(context->Ecx,0);
665 while (count-- > 0)
667 void *data;
668 WORD dx = LOWORD(context->Edx);
669 if (outp)
671 data = make_ptr( context, seg, context->Esi, long_addr );
672 if (long_addr) context->Esi += step;
673 else ADD_LOWORD(context->Esi,step);
675 else
677 data = make_ptr( context, seg, context->Edi, long_addr );
678 if (long_addr) context->Edi += step;
679 else ADD_LOWORD(context->Edi,step);
682 switch (typ)
684 case 0x6c:
685 *(BYTE *)data = INSTR_inport( dx, 1, context );
686 break;
687 case 0x6d:
688 if (long_op)
689 *(DWORD *)data = INSTR_inport( dx, 4, context );
690 else
691 *(WORD *)data = INSTR_inport( dx, 2, context );
692 break;
693 case 0x6e:
694 INSTR_outport( dx, 1, *(BYTE *)data, context );
695 break;
696 case 0x6f:
697 if (long_op)
698 INSTR_outport( dx, 4, *(DWORD *)data, context );
699 else
700 INSTR_outport( dx, 2, *(WORD *)data, context );
701 break;
704 context->Eip += prefixlen + 1;
706 return ExceptionContinueExecution;
708 case 0x8b: /* mov Ev, Gv */
710 BYTE *addr = INSTR_GetOperandAddr(context, instr + 1, long_addr,
711 segprefix, &len);
712 struct idtr idtr = get_idtr();
713 unsigned int offset = addr - idtr.base;
715 if (offset <= idtr.limit + 1 - (long_op ? 4 : 2))
717 idt[1].LimitLow = 0x100; /* FIXME */
718 idt[3].LimitLow = 0x500; /* FIXME */
719 store_reg( context, instr[1], (BYTE *)&idt + offset, long_op );
720 context->Eip += prefixlen + len + 1;
721 return ExceptionContinueExecution;
724 break; /* Unable to emulate it */
726 case 0x8e: /* mov XX,segment_reg */
728 WORD seg;
729 BYTE *addr = INSTR_GetOperandAddr(context, instr + 1,
730 long_addr, segprefix, &len );
731 if (!addr)
732 break; /* Unable to emulate it */
733 seg = *(WORD *)addr;
734 if (!INSTR_ReplaceSelector( context, &seg ))
735 break; /* Unable to emulate it */
737 switch((instr[1] >> 3) & 7)
739 case 0:
740 context->SegEs = seg;
741 context->Eip += prefixlen + len + 1;
742 return ExceptionContinueExecution;
743 case 1: /* cs */
744 break;
745 case 2:
746 context->SegSs = seg;
747 context->Eip += prefixlen + len + 1;
748 return ExceptionContinueExecution;
749 case 3:
750 context->SegDs = seg;
751 context->Eip += prefixlen + len + 1;
752 return ExceptionContinueExecution;
753 case 4:
754 context->SegFs = seg;
755 context->Eip += prefixlen + len + 1;
756 return ExceptionContinueExecution;
757 case 5:
758 context->SegGs = seg;
759 context->Eip += prefixlen + len + 1;
760 return ExceptionContinueExecution;
761 case 6: /* unused */
762 case 7: /* unused */
763 break;
766 break; /* Unable to emulate it */
768 case 0xc4: /* les addr,reg */
769 case 0xc5: /* lds addr,reg */
770 if (INSTR_EmulateLDS( context, instr, long_op,
771 long_addr, segprefix, &len ))
773 context->Eip += prefixlen + len;
774 return ExceptionContinueExecution;
776 break; /* Unable to emulate it */
778 case 0xcd: /* int <XX> */
779 if (wine_ldt_is_system(context->SegCs)) break; /* don't emulate it in 32-bit code */
780 if (!winedos.EmulateInterruptPM) load_winedos();
781 if (winedos.EmulateInterruptPM)
783 context->Eip += prefixlen + 2;
784 winedos.EmulateInterruptPM( context, instr[1] );
785 return ExceptionContinueExecution;
787 break; /* Unable to emulate it */
789 case 0xcf: /* iret */
790 if (wine_ldt_is_system(context->SegCs)) break; /* don't emulate it in 32-bit code */
791 if (long_op)
793 DWORD *stack = get_stack( context );
794 context->Eip = *stack++;
795 context->SegCs = *stack++;
796 context->EFlags = *stack;
797 add_stack(context, 3*sizeof(DWORD)); /* Pop the return address and flags */
799 else
801 WORD *stack = get_stack( context );
802 context->Eip = *stack++;
803 context->SegCs = *stack++;
804 SET_LOWORD(context->EFlags,*stack);
805 add_stack(context, 3*sizeof(WORD)); /* Pop the return address and flags */
807 return ExceptionContinueExecution;
809 case 0xe4: /* inb al,XX */
810 SET_LOBYTE(context->Eax,INSTR_inport( instr[1], 1, context ));
811 context->Eip += prefixlen + 2;
812 return ExceptionContinueExecution;
814 case 0xe5: /* in (e)ax,XX */
815 if (long_op)
816 context->Eax = INSTR_inport( instr[1], 4, context );
817 else
818 SET_LOWORD(context->Eax, INSTR_inport( instr[1], 2, context ));
819 context->Eip += prefixlen + 2;
820 return ExceptionContinueExecution;
822 case 0xe6: /* outb XX,al */
823 INSTR_outport( instr[1], 1, LOBYTE(context->Eax), context );
824 context->Eip += prefixlen + 2;
825 return ExceptionContinueExecution;
827 case 0xe7: /* out XX,(e)ax */
828 if (long_op)
829 INSTR_outport( instr[1], 4, context->Eax, context );
830 else
831 INSTR_outport( instr[1], 2, LOWORD(context->Eax), context );
832 context->Eip += prefixlen + 2;
833 return ExceptionContinueExecution;
835 case 0xec: /* inb al,dx */
836 SET_LOBYTE(context->Eax, INSTR_inport( LOWORD(context->Edx), 1, context ) );
837 context->Eip += prefixlen + 1;
838 return ExceptionContinueExecution;
840 case 0xed: /* in (e)ax,dx */
841 if (long_op)
842 context->Eax = INSTR_inport( LOWORD(context->Edx), 4, context );
843 else
844 SET_LOWORD(context->Eax, INSTR_inport( LOWORD(context->Edx), 2, context ));
845 context->Eip += prefixlen + 1;
846 return ExceptionContinueExecution;
848 case 0xee: /* outb dx,al */
849 INSTR_outport( LOWORD(context->Edx), 1, LOBYTE(context->Eax), context );
850 context->Eip += prefixlen + 1;
851 return ExceptionContinueExecution;
853 case 0xef: /* out dx,(e)ax */
854 if (long_op)
855 INSTR_outport( LOWORD(context->Edx), 4, context->Eax, context );
856 else
857 INSTR_outport( LOWORD(context->Edx), 2, LOWORD(context->Eax), context );
858 context->Eip += prefixlen + 1;
859 return ExceptionContinueExecution;
861 case 0xfa: /* cli */
862 NtCurrentTeb()->dpmi_vif = 0;
863 context->Eip += prefixlen + 1;
864 return ExceptionContinueExecution;
866 case 0xfb: /* sti */
867 NtCurrentTeb()->dpmi_vif = 1;
868 context->Eip += prefixlen + 1;
869 if (NtCurrentTeb()->vm86_pending)
871 NtCurrentTeb()->vm86_pending = 0;
872 rec->ExceptionCode = EXCEPTION_VM86_STI;
873 break; /* Handle the pending event. */
875 return ExceptionContinueExecution;
877 return ExceptionContinueSearch; /* Unable to emulate it */
881 /***********************************************************************
882 * INSTR_CallBuiltinHandler
884 void INSTR_CallBuiltinHandler( CONTEXT86 *context, BYTE intnum )
886 if (!winedos.CallBuiltinHandler) load_winedos();
887 if (winedos.CallBuiltinHandler) winedos.CallBuiltinHandler( context, intnum );
891 /***********************************************************************
892 * DOS3Call (KERNEL.102)
894 void WINAPI DOS3Call( CONTEXT86 *context )
896 INSTR_CallBuiltinHandler( context, 0x21 );
900 /***********************************************************************
901 * NetBIOSCall (KERNEL.103)
903 void WINAPI NetBIOSCall16( CONTEXT86 *context )
905 INSTR_CallBuiltinHandler( context, 0x5c );
909 /***********************************************************************
910 * GetSetKernelDOSProc (KERNEL.311)
912 FARPROC16 WINAPI GetSetKernelDOSProc16( FARPROC16 DosProc )
914 FIXME("(DosProc=0x%08x): stub\n", (UINT)DosProc);
915 return NULL;