[NTVDM]
[reactos.git] / subsystems / ntvdm / int32.c
index 8e03933..5372097 100644 (file)
@@ -128,18 +128,18 @@ VOID WINAPI Int32Dispatch(LPWORD Stack)
 
 VOID WINAPI InitializeInt32(WORD BiosSegment)
 {
-    USHORT i;
-    WORD Offset = 0;
-
     LPDWORD IntVecTable = (LPDWORD)BaseAddress;
-    LPBYTE BiosCode = (LPBYTE)SEG_OFF_TO_PTR(BiosSegment, 0);
+    LPBYTE  BiosCode    = (LPBYTE)SEG_OFF_TO_PTR(BiosSegment, 0);
+    USHORT i;
+    WORD BopSeqOffset, Offset = 0;
 
     /* Generate ISR stubs and fill the IVT */
     for (i = 0x00; i <= 0xFF; i++)
     {
+        Offset = INT_HANDLER_OFFSET + (i << 4);
         IntVecTable[i] = MAKELONG(Offset, BiosSegment);
 
-        BiosCode[Offset++] = 0xFB; // sti
+        BiosCode[Offset++] = 0xFA; // cli
 
         BiosCode[Offset++] = 0x6A; // push i
         BiosCode[Offset++] = (UCHAR)i;
@@ -147,30 +147,41 @@ VOID WINAPI InitializeInt32(WORD BiosSegment)
         BiosCode[Offset++] = 0x6A; // push 0
         BiosCode[Offset++] = 0x00;
 
+        BopSeqOffset = COMMON_STUB_OFFSET - (Offset + 3);
+
+        BiosCode[Offset++] = 0xE9; // jmp near BOP_SEQ
+        BiosCode[Offset++] = LOBYTE(BopSeqOffset);
+        BiosCode[Offset++] = HIBYTE(BopSeqOffset);
+    }
+
+    /* Write the common stub code */
+    Offset = COMMON_STUB_OFFSET;
+
 // BOP_SEQ:
-        BiosCode[Offset++] = 0xF8; // clc
+    BiosCode[Offset++] = 0xF8; // clc
 
-        BiosCode[Offset++] = LOBYTE(EMULATOR_BOP);  // BOP sequence
-        BiosCode[Offset++] = HIBYTE(EMULATOR_BOP);
-        BiosCode[Offset++] = EMULATOR_CTRL_BOP;     // Control BOP
-        BiosCode[Offset++] = CTRL_BOP_INT32;        // 32-bit Interrupt dispatcher
+    BiosCode[Offset++] = LOBYTE(EMULATOR_BOP);  // BOP sequence
+    BiosCode[Offset++] = HIBYTE(EMULATOR_BOP);
+    BiosCode[Offset++] = EMULATOR_CTRL_BOP;     // Control BOP
+    BiosCode[Offset++] = CTRL_BOP_INT32;        // 32-bit Interrupt dispatcher
 
-        BiosCode[Offset++] = 0x73; // jnc EXIT (offset +3)
-        BiosCode[Offset++] = 0x03;
+    BiosCode[Offset++] = 0x73; // jnc EXIT (offset +4)
+    BiosCode[Offset++] = 0x04;
 
-        // HACK: The following instruction should be HLT!
-        BiosCode[Offset++] = 0x90; // nop
+    BiosCode[Offset++] = 0xFB; // sti
 
-        BiosCode[Offset++] = 0xEB; // jmp BOP_SEQ (offset -10)
-        BiosCode[Offset++] = 0xF6;
+    // HACK: The following instruction should be HLT!
+    BiosCode[Offset++] = 0x90; // nop
+
+    BiosCode[Offset++] = 0xEB; // jmp BOP_SEQ (offset -11)
+    BiosCode[Offset++] = 0xF5;
 
 // EXIT:
-        BiosCode[Offset++] = 0x83; // add sp, 4
-        BiosCode[Offset++] = 0xC4;
-        BiosCode[Offset++] = 0x04;
+    BiosCode[Offset++] = 0x83; // add sp, 4
+    BiosCode[Offset++] = 0xC4;
+    BiosCode[Offset++] = 0x04;
 
-        BiosCode[Offset++] = 0xCF; // iret
-    }
+    BiosCode[Offset++] = 0xCF; // iret
 }
 
 VOID WINAPI RegisterInt32(BYTE IntNumber, EMULATOR_INT32_PROC IntHandler)