Don't return from overlapped ReadFile on EAGAIN and other non-fatal
[wine/gsoc_dplay.git] / dlls / winedos / dosvm.c
blobf8338b9c2b055f1acc419ea4e6a4f270ba01d45d
1 /*
2 * DOS Virtual Machine
4 * Copyright 1998 Ove Kåven
6 * This code hasn't been completely cleaned up yet.
7 */
9 #include "config.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <errno.h>
15 #include <fcntl.h>
16 #include <signal.h>
17 #include <unistd.h>
18 #include <sys/time.h>
19 #include <sys/types.h>
21 #include "wine/winbase16.h"
22 #include "wine/exception.h"
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winnt.h"
28 #include "wincon.h"
30 #include "msdos.h"
31 #include "file.h"
32 #include "miscemu.h"
33 #include "dosexe.h"
34 #include "../../loader/dos/dosmod.h"
35 #include "stackframe.h"
36 #include "debugtools.h"
38 DEFAULT_DEBUG_CHANNEL(int);
39 DECLARE_DEBUG_CHANNEL(module);
40 DECLARE_DEBUG_CHANNEL(relay);
42 WORD DOSVM_psp = 0;
43 WORD DOSVM_retval = 0;
45 #ifdef MZ_SUPPORTED
47 #ifdef HAVE_SYS_VM86_H
48 # include <sys/vm86.h>
49 #endif
50 #ifdef HAVE_SYS_MMAN_H
51 # include <sys/mman.h>
52 #endif
54 #define IF_CLR(ctx) ((ctx)->EFlags &= ~VIF_MASK)
55 #define IF_SET(ctx) ((ctx)->EFlags |= VIF_MASK)
56 #define IF_ENABLED(ctx) ((ctx)->EFlags & VIF_MASK)
57 #define SET_PEND(ctx) ((ctx)->EFlags |= VIP_MASK)
58 #define CLR_PEND(ctx) ((ctx)->EFlags &= ~VIP_MASK)
59 #define IS_PEND(ctx) ((ctx)->EFlags & VIP_MASK)
61 #undef TRY_PICRETURN
63 typedef struct _DOSEVENT {
64 int irq,priority;
65 DOSRELAY relay;
66 void *data;
67 struct _DOSEVENT *next;
68 } DOSEVENT, *LPDOSEVENT;
70 static struct _DOSEVENT *pending_event, *current_event;
71 static int sig_sent, entered;
72 static CONTEXT86 *current_context;
74 /* from module.c */
75 extern int read_pipe, write_pipe;
76 extern HANDLE hReadPipe;
77 extern pid_t dosmod_pid;
79 static void do_exception( int signal, CONTEXT86 *context )
81 EXCEPTION_RECORD rec;
82 if ((signal == SIGTRAP) || (signal == SIGHUP))
84 rec.ExceptionCode = EXCEPTION_BREAKPOINT;
85 rec.ExceptionFlags = EXCEPTION_CONTINUABLE;
87 else
89 rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION; /* generic error */
90 rec.ExceptionFlags = EH_NONCONTINUABLE;
92 rec.ExceptionRecord = NULL;
93 rec.ExceptionAddress = (LPVOID)context->Eip;
94 rec.NumberParameters = 0;
95 EXC_RtlRaiseException( &rec, context );
98 static void DOSVM_Dump( int fn, int sig, struct vm86plus_struct*VM86 )
100 BYTE*inst;
101 int x;
103 switch (VM86_TYPE(fn)) {
104 case VM86_SIGNAL:
105 printf("Trapped signal %d\n",sig); break;
106 case VM86_UNKNOWN:
107 printf("Trapped unhandled GPF\n"); break;
108 case VM86_INTx:
109 printf("Trapped INT %02x\n",VM86_ARG(fn)); break;
110 case VM86_STI:
111 printf("Trapped STI\n"); break;
112 case VM86_PICRETURN:
113 printf("Trapped due to pending PIC request\n"); break;
114 case VM86_TRAP:
115 printf("Trapped debug request\n"); break;
116 default:
117 printf("Trapped unknown VM86 type %d arg %d\n",VM86_TYPE(fn),VM86_ARG(fn)); break;
119 #define REGS VM86->regs
120 fprintf(stderr,"AX=%04lX CX=%04lX DX=%04lX BX=%04lX\n",REGS.eax,REGS.ecx,REGS.edx,REGS.ebx);
121 fprintf(stderr,"SI=%04lX DI=%04lX SP=%04lX BP=%04lX\n",REGS.esi,REGS.edi,REGS.esp,REGS.ebp);
122 fprintf(stderr,"CS=%04X DS=%04X ES=%04X SS=%04X\n",REGS.cs,REGS.ds,REGS.es,REGS.ss);
123 fprintf(stderr,"IP=%04lX EFLAGS=%08lX\n",REGS.eip,REGS.eflags);
125 inst = PTR_REAL_TO_LIN( REGS.cs, REGS.eip );
126 #undef REGS
127 printf("Opcodes:");
128 for (x=0; x<8; x++) printf(" %02x",inst[x]);
129 printf("\n");
132 static int DOSVM_SimulateInt( int vect, CONTEXT86 *context, BOOL inwine )
134 FARPROC16 handler=DOSVM_GetRMHandler(vect);
136 /* check for our real-mode hooks */
137 if (vect==0x31) {
138 if (context->SegCs==DOSMEM_wrap_seg) {
139 /* exit from real-mode wrapper */
140 return -1;
142 /* we could probably move some other dodgy stuff here too from dpmi.c */
144 /* check if the call is from our fake BIOS interrupt stubs */
145 if ((context->SegCs==0xf000) && !inwine) {
146 if (vect != (context->Eip/4)) {
147 TRACE("something fishy going on here (interrupt stub is %02lx)\n", context->Eip/4);
149 TRACE("builtin interrupt %02x has been branched to\n", vect);
150 DOSVM_RealModeInterrupt(vect, context);
152 /* check if the call goes to an unhooked interrupt */
153 else if (SELECTOROF(handler)==0xf000) {
154 /* if so, call it directly */
155 TRACE("builtin interrupt %02x has been invoked (through vector %02x)\n", OFFSETOF(handler)/4, vect);
156 DOSVM_RealModeInterrupt(OFFSETOF(handler)/4, context);
158 /* the interrupt is hooked, simulate interrupt in DOS space */
159 else {
160 WORD*stack= PTR_REAL_TO_LIN( context->SegSs, context->Esp );
161 WORD flag=LOWORD(context->EFlags);
163 if (IF_ENABLED(context)) flag|=IF_MASK;
164 else flag&=~IF_MASK;
166 *(--stack)=flag;
167 *(--stack)=context->SegCs;
168 *(--stack)=LOWORD(context->Eip);
169 context->Esp-=6;
170 context->SegCs=SELECTOROF(handler);
171 context->Eip=OFFSETOF(handler);
172 IF_CLR(context);
174 return 0;
177 #define SHOULD_PEND(x) \
178 (x && ((!current_event) || (x->priority < current_event->priority)))
180 static void DOSVM_SendQueuedEvent(CONTEXT86 *context)
182 LPDOSEVENT event = pending_event;
184 if (SHOULD_PEND(event)) {
185 /* remove from "pending" list */
186 pending_event = event->next;
187 /* process event */
188 if (event->irq>=0) {
189 /* it's an IRQ, move it to "current" list */
190 event->next = current_event;
191 current_event = event;
192 TRACE("dispatching IRQ %d\n",event->irq);
193 /* note that if DOSVM_SimulateInt calls an internal interrupt directly,
194 * current_event might be cleared (and event freed) in this very call! */
195 DOSVM_SimulateInt((event->irq<8)?(event->irq+8):(event->irq-8+0x70),context,TRUE);
196 } else {
197 /* callback event */
198 TRACE("dispatching callback event\n");
199 (*event->relay)(context,event->data);
200 free(event);
203 if (!SHOULD_PEND(pending_event)) {
204 TRACE("clearing Pending flag\n");
205 CLR_PEND(context);
209 static void DOSVM_SendQueuedEvents(CONTEXT86 *context)
211 /* we will send all queued events as long as interrupts are enabled,
212 * but IRQ events will disable interrupts again */
213 while (IS_PEND(context) && IF_ENABLED(context))
214 DOSVM_SendQueuedEvent(context);
217 /***********************************************************************
218 * QueueEvent (WINEDOS.@)
220 void WINAPI DOSVM_QueueEvent( INT irq, INT priority, DOSRELAY relay, LPVOID data)
222 LPDOSEVENT event, cur, prev;
224 if (entered) {
225 event = malloc(sizeof(DOSEVENT));
226 if (!event) {
227 ERR("out of memory allocating event entry\n");
228 return;
230 event->irq = irq; event->priority = priority;
231 event->relay = relay; event->data = data;
233 /* insert event into linked list, in order *after*
234 * all earlier events of higher or equal priority */
235 cur = pending_event; prev = NULL;
236 while (cur && cur->priority<=priority) {
237 prev = cur;
238 cur = cur->next;
240 event->next = cur;
241 if (prev) prev->next = event;
242 else pending_event = event;
244 /* get dosmod's attention to the new event, if necessary */
245 if (!sig_sent) {
246 TRACE("new event queued, signalling dosmod\n");
247 kill(dosmod_pid,SIGUSR2);
248 sig_sent++;
249 } else {
250 TRACE("new event queued\n");
252 } else {
253 /* DOS subsystem not running */
254 /* (this probably means that we're running a win16 app
255 * which uses DPMI to thunk down to DOS services) */
256 if (irq<0) {
257 /* callback event, perform it with dummy context */
258 CONTEXT86 context;
259 memset(&context,0,sizeof(context));
260 (*relay)(&context,data);
261 } else {
262 ERR("IRQ without DOS task: should not happen");
267 #define CV do { CP(eax,Eax); CP(ecx,Ecx); CP(edx,Edx); CP(ebx,Ebx); \
268 CP(esi,Esi); CP(edi,Edi); CP(esp,Esp); CP(ebp,Ebp); \
269 CP(cs,SegCs); CP(ds,SegDs); CP(es,SegEs); \
270 CP(ss,SegSs); CP(fs,SegFs); CP(gs,SegGs); \
271 CP(eip,Eip); CP(eflags,EFlags); } while(0)
273 static int DOSVM_Process( int fn, int sig, struct vm86plus_struct*VM86 )
275 CONTEXT86 context, *old_context;
276 int ret=0;
278 #define CP(x,y) context.y = VM86->regs.x
280 #undef CP
281 if (VM86_TYPE(fn)==VM86_UNKNOWN) {
282 ret=INSTR_EmulateInstruction(&context);
283 #define CP(x,y) VM86->regs.x = context.y
285 #undef CP
286 if (ret) return 0;
287 ret=0;
289 #ifdef TRY_PICRETURN
290 if (VM86->vm86plus.force_return_for_pic) {
291 SET_PEND(&context);
293 #else
294 /* linux doesn't preserve pending flag on return */
295 if (SHOULD_PEND(pending_event)) {
296 SET_PEND(&context);
298 #endif
300 old_context = current_context;
301 current_context = &context;
303 switch (VM86_TYPE(fn)) {
304 case VM86_SIGNAL:
305 TRACE("DOS module caught signal %d\n",sig);
306 if ((sig==SIGALRM) || (sig==SIGUSR2)) {
307 if (sig==SIGALRM) {
308 sig_sent++;
309 DOSVM_QueueEvent(0,DOS_PRIORITY_REALTIME,NULL,NULL);
311 if (pending_event) {
312 TRACE("setting Pending flag, interrupts are currently %s\n",
313 IF_ENABLED(&context) ? "enabled" : "disabled");
314 SET_PEND(&context);
315 DOSVM_SendQueuedEvents(&context);
316 } else {
317 TRACE("no events are pending, clearing Pending flag\n");
318 CLR_PEND(&context);
320 sig_sent--;
322 else if ((sig==SIGHUP) || (sig==SIGILL) || (sig==SIGSEGV)) {
323 do_exception( sig, &context );
324 } else {
325 DOSVM_Dump(fn,sig,VM86);
326 ret=-1;
328 break;
329 case VM86_UNKNOWN: /* unhandled GPF */
330 DOSVM_Dump(fn,sig,VM86);
331 do_exception( SIGSEGV, &context );
332 break;
333 case VM86_INTx:
334 if (TRACE_ON(relay))
335 DPRINTF("Call DOS int 0x%02x (EAX=%08lx) ret=%04lx:%04lx\n",VM86_ARG(fn),context.Eax,context.SegCs,context.Eip);
336 ret=DOSVM_SimulateInt(VM86_ARG(fn),&context,FALSE);
337 if (TRACE_ON(relay))
338 DPRINTF("Ret DOS int 0x%02x (EAX=%08lx) ret=%04lx:%04lx\n",VM86_ARG(fn),context.Eax,context.SegCs,context.Eip);
339 break;
340 case VM86_STI:
341 IF_SET(&context);
342 /* case VM86_PICRETURN: */
343 TRACE("DOS task enabled interrupts %s events pending, sending events\n", IS_PEND(&context)?"with":"without");
344 DOSVM_SendQueuedEvents(&context);
345 break;
346 case VM86_TRAP:
347 do_exception( SIGTRAP, &context );
348 break;
349 default:
350 DOSVM_Dump(fn,sig,VM86);
351 ret=-1;
354 current_context = old_context;
356 #define CP(x,y) VM86->regs.x = context.y
358 #undef CP
359 #ifdef TRY_PICRETURN
360 VM86->vm86plus.force_return_for_pic = IS_PEND(&context) ? 1 : 0;
361 CLR_PEND(&context);
362 #endif
363 return ret;
366 static void DOSVM_ProcessConsole(void)
368 INPUT_RECORD msg;
369 DWORD res;
370 BYTE scan;
372 if (ReadConsoleInputA(GetStdHandle(STD_INPUT_HANDLE),&msg,1,&res)) {
373 switch (msg.EventType) {
374 case KEY_EVENT:
375 scan = msg.Event.KeyEvent.wVirtualScanCode;
376 if (!msg.Event.KeyEvent.bKeyDown) scan |= 0x80;
378 /* check whether extended bit is set,
379 * and if so, queue the extension prefix */
380 if (msg.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY) {
381 DOSVM_Int09SendScan(0xE0,0);
383 DOSVM_Int09SendScan(scan,msg.Event.KeyEvent.uChar.AsciiChar);
384 break;
385 default:
386 FIXME("unhandled console event: %d\n", msg.EventType);
391 static void DOSVM_ProcessMessage(MSG *msg)
393 BYTE scan = 0;
395 TRACE("got message %04x, wparam=%08x, lparam=%08lx\n",msg->message,msg->wParam,msg->lParam);
396 if ((msg->message>=WM_MOUSEFIRST)&&
397 (msg->message<=WM_MOUSELAST)) {
398 DOSVM_Int33Message(msg->message,msg->wParam,msg->lParam);
399 } else {
400 switch (msg->message) {
401 case WM_KEYUP:
402 scan = 0x80;
403 case WM_KEYDOWN:
404 scan |= (msg->lParam >> 16) & 0x7f;
406 /* check whether extended bit is set,
407 * and if so, queue the extension prefix */
408 if (msg->lParam & 0x1000000) {
409 /* FIXME: some keys (function keys) have
410 * extended bit set even when they shouldn't,
411 * should check for them */
412 DOSVM_Int09SendScan(0xE0,0);
414 DOSVM_Int09SendScan(scan,0);
415 break;
420 /***********************************************************************
421 * Wait (WINEDOS.@)
423 void WINAPI DOSVM_Wait( INT read_pipe, HANDLE hObject )
425 MSG msg;
426 DWORD waitret;
427 HANDLE objs[2];
428 int objc;
429 BOOL got_msg = FALSE;
431 objs[0]=GetStdHandle(STD_INPUT_HANDLE);
432 objs[1]=hObject;
433 objc=hObject?2:1;
434 do {
435 /* check for messages (waste time before the response check below) */
436 if (PeekMessageA)
438 while (PeekMessageA(&msg,0,0,0,PM_REMOVE|PM_NOYIELD)) {
439 /* got a message */
440 DOSVM_ProcessMessage(&msg);
441 /* we don't need a TranslateMessage here */
442 DispatchMessageA(&msg);
443 got_msg = TRUE;
446 chk_console_input:
447 if (!got_msg) {
448 /* check for console input */
449 INPUT_RECORD msg;
450 DWORD num;
451 if (PeekConsoleInputA(objs[0],&msg,1,&num) && num) {
452 DOSVM_ProcessConsole();
453 got_msg = TRUE;
456 if (read_pipe == -1) {
457 /* dispatch pending events */
458 if (SHOULD_PEND(pending_event)) {
459 CONTEXT86 context = *current_context;
460 IF_SET(&context);
461 SET_PEND(&context);
462 DOSVM_SendQueuedEvents(&context);
464 if (got_msg) break;
465 } else {
466 fd_set readfds;
467 struct timeval timeout={0,0};
468 /* quick check for response from dosmod
469 * (faster than doing the full blocking wait, if data already available) */
470 FD_ZERO(&readfds); FD_SET(read_pipe,&readfds);
471 if (select(read_pipe+1,&readfds,NULL,NULL,&timeout)>0)
472 break;
474 /* nothing yet, block while waiting for something to do */
475 if (MsgWaitForMultipleObjects)
476 waitret = MsgWaitForMultipleObjects(objc,objs,FALSE,INFINITE,QS_ALLINPUT);
477 else
478 waitret = WaitForMultipleObjects(objc,objs,FALSE,INFINITE);
480 if (waitret==(DWORD)-1) {
481 ERR_(module)("dosvm wait error=%ld\n",GetLastError());
483 if ((read_pipe != -1) && hObject) {
484 if (waitret==(WAIT_OBJECT_0+1)) break;
486 if (waitret==WAIT_OBJECT_0)
487 goto chk_console_input;
488 } while (TRUE);
491 /***********************************************************************
492 * Enter (WINEDOS.@)
494 INT WINAPI DOSVM_Enter( CONTEXT86 *context )
496 struct vm86plus_struct VM86;
497 int stat,len,sig;
499 memset(&VM86, 0, sizeof(VM86));
500 #define CP(x,y) VM86.regs.x = context->y
502 #undef CP
503 if (VM86.regs.eflags & IF_MASK)
504 VM86.regs.eflags |= VIF_MASK;
506 /* main exchange loop */
507 entered++;
508 do {
509 TRACE_(module)("thread is: %lx\n",GetCurrentThreadId());
510 stat = VM86_ENTER;
511 errno = 0;
512 /* transmit VM86 structure to dosmod task */
513 if (write(write_pipe,&stat,sizeof(stat))!=sizeof(stat)) {
514 ERR_(module)("dosmod sync lost, errno=%d, fd=%d, pid=%d\n",errno,write_pipe,getpid());
515 return -1;
517 if (write(write_pipe,&VM86,sizeof(VM86))!=sizeof(VM86)) {
518 ERR_(module)("dosmod sync lost, errno=%d\n",errno);
519 return -1;
521 /* wait for response, doing other things in the meantime */
522 DOSVM_Wait(read_pipe, hReadPipe);
523 /* read response */
524 while (1) {
525 if ((len=read(read_pipe,&stat,sizeof(stat)))==sizeof(stat)) break;
526 if (((errno==EINTR)||(errno==EAGAIN))&&(len<=0)) {
527 WARN_(module)("rereading dosmod return code due to errno=%d, result=%d\n",errno,len);
528 continue;
530 ERR_(module)("dosmod sync lost reading return code, errno=%d, result=%d\n",errno,len);
531 return -1;
533 TRACE_(module)("dosmod return code=%d\n",stat);
534 if (stat==DOSMOD_LEFTIDLE) {
535 continue;
537 while (1) {
538 if ((len=read(read_pipe,&VM86,sizeof(VM86)))==sizeof(VM86)) break;
539 if (((errno==EINTR)||(errno==EAGAIN))&&(len<=0)) {
540 WARN_(module)("rereading dosmod VM86 structure due to errno=%d, result=%d\n",errno,len);
541 continue;
543 ERR_(module)("dosmod sync lost reading VM86 structure, errno=%d, result=%d\n",errno,len);
544 return -1;
546 if ((stat&0xff)==DOSMOD_SIGNAL) {
547 while (1) {
548 if ((len=read(read_pipe,&sig,sizeof(sig)))==sizeof(sig)) break;
549 if (((errno==EINTR)||(errno==EAGAIN))&&(len<=0)) {
550 WARN_(module)("rereading dosmod signal due to errno=%d, result=%d\n",errno,len);
551 continue;
553 ERR_(module)("dosmod sync lost reading signal, errno=%d, result=%d\n",errno,len);
554 return -1;
555 } while (0);
556 } else sig=0;
557 /* got response */
558 } while (DOSVM_Process(stat,sig,&VM86)>=0);
559 entered--;
561 #define CP(x,y) context->y = VM86.regs.x
563 #undef CP
564 return 0;
567 /***********************************************************************
568 * OutPIC (WINEDOS.@)
570 void WINAPI DOSVM_PIC_ioport_out( WORD port, BYTE val)
572 LPDOSEVENT event;
574 if ((port==0x20) && (val==0x20)) {
575 if (current_event) {
576 /* EOI (End Of Interrupt) */
577 TRACE("received EOI for current IRQ, clearing\n");
578 event = current_event;
579 current_event = event->next;
580 if (event->relay)
581 (*event->relay)(NULL,event->data);
582 free(event);
584 if (pending_event &&
585 !sig_sent) {
586 /* another event is pending, which we should probably
587 * be able to process now, so tell dosmod about it */
588 TRACE("another event pending, signalling dosmod\n");
589 kill(dosmod_pid,SIGUSR2);
590 sig_sent++;
592 } else {
593 WARN("EOI without active IRQ\n");
595 } else {
596 FIXME("unrecognized PIC command %02x\n",val);
600 /***********************************************************************
601 * SetTimer (WINEDOS.@)
603 void WINAPI DOSVM_SetTimer( UINT ticks )
605 int stat=DOSMOD_SET_TIMER;
606 struct timeval tim;
608 if (write_pipe != -1) {
609 /* the PC clocks ticks at 1193180 Hz */
610 tim.tv_sec=0;
611 tim.tv_usec=MulDiv(ticks,1000000,1193180);
612 /* sanity check */
613 if (!tim.tv_usec) tim.tv_usec=1;
615 if (write(write_pipe,&stat,sizeof(stat))!=sizeof(stat)) {
616 ERR_(module)("dosmod sync lost, errno=%d\n",errno);
617 return;
619 if (write(write_pipe,&tim,sizeof(tim))!=sizeof(tim)) {
620 ERR_(module)("dosmod sync lost, errno=%d\n",errno);
621 return;
623 /* there's no return */
627 /***********************************************************************
628 * GetTimer (WINEDOS.@)
630 UINT WINAPI DOSVM_GetTimer( void )
632 int stat=DOSMOD_GET_TIMER;
633 struct timeval tim;
635 if (write_pipe != -1) {
636 if (write(write_pipe,&stat,sizeof(stat))!=sizeof(stat)) {
637 ERR_(module)("dosmod sync lost, errno=%d\n",errno);
638 return 0;
640 /* read response */
641 while (1) {
642 if (read(read_pipe,&tim,sizeof(tim))==sizeof(tim)) break;
643 if ((errno==EINTR)||(errno==EAGAIN)) continue;
644 ERR_(module)("dosmod sync lost, errno=%d\n",errno);
645 return 0;
647 return MulDiv(tim.tv_usec,1193180,1000000);
649 return 0;
652 #else /* !MZ_SUPPORTED */
654 /***********************************************************************
655 * Enter (WINEDOS.@)
657 INT WINAPI DOSVM_Enter( CONTEXT86 *context )
659 ERR_(module)("DOS realmode not supported on this architecture!\n");
660 return -1;
663 /***********************************************************************
664 * Wait (WINEDOS.@)
666 void WINAPI DOSVM_Wait( INT read_pipe, HANDLE hObject) {}
668 /***********************************************************************
669 * OutPIC (WINEDOS.@)
671 void WINAPI DOSVM_PIC_ioport_out( WORD port, BYTE val) {}
673 /***********************************************************************
674 * SetTimer (WINEDOS.@)
676 void WINAPI DOSVM_SetTimer( UINT ticks ) {}
678 /***********************************************************************
679 * GetTimer (WINEDOS.@)
681 UINT WINAPI DOSVM_GetTimer( void ) { return 0; }
683 /***********************************************************************
684 * QueueEvent (WINEDOS.@)
686 void WINAPI DOSVM_QueueEvent( INT irq, INT priority, DOSRELAY relay, LPVOID data)
688 if (irq<0) {
689 /* callback event, perform it with dummy context */
690 CONTEXT86 context;
691 memset(&context,0,sizeof(context));
692 (*relay)(&context,data);
693 } else {
694 ERR("IRQ without DOS task: should not happen");
698 #endif
700 /**********************************************************************
701 * DOSVM_GetRMHandler
703 * Return the real mode interrupt vector for a given interrupt.
705 FARPROC16 DOSVM_GetRMHandler( BYTE intnum )
707 return ((FARPROC16*)DOSMEM_SystemBase())[intnum];
711 /**********************************************************************
712 * DOSVM_SetRMHandler
714 * Set the real mode interrupt handler for a given interrupt.
716 void DOSVM_SetRMHandler( BYTE intnum, FARPROC16 handler )
718 TRACE("Set real mode interrupt vector %02x <- %04x:%04x\n",
719 intnum, HIWORD(handler), LOWORD(handler) );
720 ((FARPROC16*)DOSMEM_SystemBase())[intnum] = handler;
724 static const INTPROC real_mode_handlers[] =
726 /* 00 */ 0, 0, 0, 0, 0, 0, 0, 0,
727 /* 08 */ 0, DOSVM_Int09Handler, 0, 0, 0, 0, 0, 0,
728 /* 10 */ DOSVM_Int10Handler, INT_Int11Handler, INT_Int12Handler, INT_Int13Handler,
729 0, INT_Int15Handler, DOSVM_Int16Handler, DOSVM_Int17Handler,
730 /* 18 */ 0, 0, INT_Int1aHandler, 0, 0, 0, 0, 0,
731 /* 20 */ DOSVM_Int20Handler, DOSVM_Int21Handler, 0, 0, 0, INT_Int25Handler, 0, 0,
732 /* 28 */ 0, DOSVM_Int29Handler, INT_Int2aHandler, 0, 0, 0, 0, INT_Int2fHandler,
733 /* 30 */ 0, DOSVM_Int31Handler, 0, DOSVM_Int33Handler
737 /**********************************************************************
738 * DOSVM_RealModeInterrupt
740 * Handle real mode interrupts
742 void DOSVM_RealModeInterrupt( BYTE intnum, CONTEXT86 *context )
744 if (intnum < sizeof(real_mode_handlers)/sizeof(INTPROC) && real_mode_handlers[intnum])
745 (*real_mode_handlers[intnum])(context);
746 else
748 FIXME("Unknown Interrupt in DOS mode: 0x%x\n", intnum);
749 FIXME(" eax=%08lx ebx=%08lx ecx=%08lx edx=%08lx\n",
750 context->Eax, context->Ebx, context->Ecx, context->Edx);
751 FIXME(" esi=%08lx edi=%08lx ds=%04lx es=%04lx\n",
752 context->Esi, context->Edi, context->SegDs, context->SegEs );
757 /**********************************************************************
758 * DOSVM_Init
760 BOOL WINAPI DOSVM_Init( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
762 TRACE_(module)("(0x%08x,%ld,%p)\n", hinstDLL, fdwReason, lpvReserved);
764 if (fdwReason == DLL_PROCESS_ATTACH)
766 /* initialize the memory */
767 TRACE("Initializing DOS memory structures\n");
768 DOSMEM_Init( TRUE );
769 DOSDEV_InstallDOSDevices();
771 return TRUE;