4 * Copyright 1998 Ove Kåven
6 * This code hasn't been completely cleaned up yet.
16 #include <sys/types.h>
31 static void DOSVM_Dump( LPDOSTASK lpDosTask
)
37 switch (VM86_TYPE(lpDosTask
->fn
)) {
39 printf("Trapped signal\n"); break;
41 printf("Trapped unhandled GPF\n"); break;
43 printf("Trapped INT %02x\n",VM86_ARG(lpDosTask
->fn
)); break;
45 printf("Trapped STI\n"); break;
47 printf("Trapped due to pending PIC request\n"); break;
49 printf("Trapped debug request\n"); break;
51 #define REGS lpDosTask->VM86.regs
52 fprintf(stderr
,"AX=%04lX CX=%04lX DX=%04lX BX=%04lX\n",REGS
.eax
,REGS
.ebx
,REGS
.ecx
,REGS
.edx
);
53 fprintf(stderr
,"SI=%04lX DI=%04lX SP=%04lX BP=%04lX\n",REGS
.esi
,REGS
.edi
,REGS
.esp
,REGS
.ebp
);
54 fprintf(stderr
,"CS=%04X DS=%04X ES=%04X SS=%04X\n",REGS
.cs
,REGS
.ds
,REGS
.es
,REGS
.ss
);
55 fprintf(stderr
,"EIP=%04lX EFLAGS=%08lX\n",REGS
.eip
,REGS
.eflags
);
57 iofs
=((DWORD
)REGS
.cs
<<4)+REGS
.eip
;
59 inst
=(BYTE
*)lpDosTask
->img
+iofs
;
61 for (x
=0; x
<8; x
++) printf(" %02x",inst
[x
]);
67 static int DOSVM_Int(int vect
, PCONTEXT context
)
69 /* moved to INT_RealModeInterrupt in msdos/interrupts.c */
70 INT_RealModeInterrupt(vect
,context
);
74 #define CV CP(eax,Eax); CP(ecx,Ecx); CP(edx,Edx); CP(ebx,Ebx); \
75 CP(esi,Esi); CP(edi,Edi); CP(esp,Esp); CP(ebp,Ebp); \
76 CP(cs,SegCs); CP(ds,SegDs); CP(es,SegEs); \
77 CP(ss,SegSs); CP(fs,SegFs); CP(gs,SegGs); \
78 CP(eip,Eip); CP(eflags,EFlags)
80 int DOSVM_Process( LPDOSTASK lpDosTask
)
85 #define CP(x,y) context.y = lpDosTask->VM86.regs.x
88 (void*)V86BASE(&context
)=lpDosTask
->img
;
90 switch (VM86_TYPE(lpDosTask
->fn
)) {
92 printf("Trapped signal\n");
94 case VM86_UNKNOWN
: /* unhandled GPF */
95 DOSVM_Dump(lpDosTask
);
96 ctx_debug(SIGSEGV
,&context
);
99 TRACE(int,"DOS EXE calls INT %02x with AX=%04lx\n",VM86_ARG(lpDosTask
->fn
),context
.Eax
);
100 ret
=DOSVM_Int(VM86_ARG(lpDosTask
->fn
),&context
); break;
104 printf("Trapped due to pending PIC request\n"); break;
106 ctx_debug(SIGTRAP
,&context
);
109 DOSVM_Dump(lpDosTask
);
112 lpDosTask
->fn
=VM86_ENTER
;
113 #define CP(x,y) lpDosTask->VM86.regs.x = context.y
119 int DOSVM_Enter( PCONTEXT context
)
121 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
122 NE_MODULE
*pModule
= NE_GetPtr( pTask
->hModule
);
126 GlobalUnlock16( GetCurrentTask() );
128 ERR(module
,"No task is currently active!\n");
131 if (!pModule
->lpDosTask
) {
132 /* no VM86 (dosmod) task is currently running, start one */
133 if ((lpDosTask
= calloc(1, sizeof(DOSTASK
))) == NULL
)
135 lpDosTask
->hModule
=pModule
->self
;
136 stat
=MZ_InitMemory(lpDosTask
,pModule
);
137 if (stat
>=32) stat
=MZ_InitTask(lpDosTask
);
142 pModule
->lpDosTask
= lpDosTask
;
143 pModule
->dos_image
= lpDosTask
->img
;
144 /* Note: we're leaving it running after this, in case we need it again,
145 as this minimizes the overhead of starting it up every time...
146 it will be killed automatically when the current task terminates */
147 } else lpDosTask
=pModule
->lpDosTask
;
150 #define CP(x,y) lpDosTask->VM86.regs.x = context->y
156 while ((stat
= MZ_RunModule(lpDosTask
)) >= 0)
157 if (stat
> 0 && DOSVM_Process(lpDosTask
) < 0)
161 #define CP(x,y) context->y = lpDosTask->VM86.regs.x
168 #else /* !MZ_SUPPORTED */
170 int DOSVM_Enter( PCONTEXT context
)
172 ERR(module
,"DOS realmode not supported on this architecture!\n");