[NTVDM]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Mon, 19 May 2014 01:12:25 +0000 (01:12 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Mon, 19 May 2014 01:12:25 +0000 (01:12 +0000)
Since the BIOS registers the whole range of possible interrupts, we register their stubs in an array-form so that the BIOS always registers INT n at the same place. We save 561 bytes of memory.

svn path=/trunk/; revision=63366

reactos/subsystems/ntvdm/bios/bios32/bios32.c
reactos/subsystems/ntvdm/bios/bios32/bios32p.h
reactos/subsystems/ntvdm/bop.c
reactos/subsystems/ntvdm/callback.c
reactos/subsystems/ntvdm/callback.h

index fc27282..045e58c 100644 (file)
@@ -301,18 +301,14 @@ static VOID BiosHwSetup(VOID)
 static VOID InitializeBiosInt32(VOID)
 {
     USHORT i;
-    // USHORT Offset = 0;
 
     /* Initialize the callback context */
     InitializeContext(&BiosContext, BIOS_SEGMENT, 0x0000);
 
-    /* Register the BIOS 32-bit Interrupts */
+    /* Register the default BIOS 32-bit Interrupts */
     for (i = 0x00; i <= 0xFF; i++)
     {
-        // Offset += RegisterInt32(MAKELONG(Offset, BIOS_SEGMENT), i, NULL, NULL);
-        BiosContext.NextOffset += RegisterInt32(MAKELONG(BiosContext.NextOffset,
-                                                         BiosContext.Segment),
-                                                i, NULL, NULL);
+        RegisterBiosInt32(i, NULL);
     }
 
     /* Initialize the exception vector interrupts to a default Exception handler */
index 604fda3..d74e04e 100644 (file)
 /* FUNCTIONS ******************************************************************/
 
 extern CALLBACK16 BiosContext;
-#define RegisterBiosInt32(IntNumber, IntHandler) \
+#define RegisterBiosInt32(IntNumber, IntHandler)    \
 do { \
-    BiosContext.NextOffset += RegisterInt32(MAKELONG(BiosContext.NextOffset,  \
-                                                     BiosContext.Segment),    \
-                                            (IntNumber), (IntHandler), NULL); \
+    RegisterInt32(BiosContext.TrampolineFarPtr +    \
+                  BiosContext.TrampolineSize   +    \
+                  (IntNumber) * Int16To32StubSize,  \
+                  (IntNumber), (IntHandler), NULL); \
 } while(0);
 
 VOID EnableHwIRQ(UCHAR hwirq, EMULATOR_INT32_PROC func);
index 4070042..88a41dd 100644 (file)
@@ -19,7 +19,7 @@
 /*
  * This is the list of registered BOP handlers.
  */
-EMULATOR_BOP_PROC BopProc[EMULATOR_MAX_BOP_NUM] = { NULL };
+static EMULATOR_BOP_PROC BopProc[EMULATOR_MAX_BOP_NUM] = { NULL };
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 
index 7566a94..d1ecaf3 100644 (file)
@@ -22,7 +22,7 @@
 /*
  * This is the list of registered 32-bit Interrupt handlers.
  */
-EMULATOR_INT32_PROC Int32Proc[EMULATOR_MAX_INT32_NUM] = { NULL };
+static EMULATOR_INT32_PROC Int32Proc[EMULATOR_MAX_INT32_NUM] = { NULL };
 
 /* BOP Identifiers */
 #define BOP_CONTROL             0xFF    // Control BOP Handler
@@ -50,7 +50,7 @@ do {                                 \
 //
 
 /* 16-bit generic interrupt code for calling a 32-bit interrupt handler */
-BYTE Int16To32[] =
+static BYTE Int16To32[] =
 {
     0xFA,               // cli
 
@@ -76,6 +76,7 @@ BYTE Int16To32[] =
     0x44, 0x44,         // inc sp, inc sp
     0xCF,               // iret
 };
+const ULONG Int16To32StubSize = sizeof(Int16To32);
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 
@@ -85,9 +86,10 @@ InitializeContext(IN PCALLBACK16 Context,
                   IN USHORT      Offset)
 {
     Context->TrampolineFarPtr = MAKELONG(Offset, Segment);
+    Context->TrampolineSize   = max(CALL16_TRAMPOLINE_SIZE,
+                                     INT16_TRAMPOLINE_SIZE);
     Context->Segment          = Segment;
-    Context->NextOffset       = Offset + max(CALL16_TRAMPOLINE_SIZE,
-                                              INT16_TRAMPOLINE_SIZE);
+    Context->NextOffset       = Offset + Context->TrampolineSize;
 }
 
 VOID
index c29ef9c..264e67f 100644 (file)
 /* 32-bit Interrupt Identifiers */
 #define EMULATOR_MAX_INT32_NUM  0xFF + 1
 
-#define INT_HANDLER_OFFSET 0x1000
-#define COMMON_STUB_OFFSET 0x2000
-
-
 typedef struct _CALLBACK16
 {
     ULONG  TrampolineFarPtr; // Where the trampoline zone is placed
+    ULONG  TrampolineSize;   // Size of the trampoline zone
     USHORT Segment;
     USHORT NextOffset;
 } CALLBACK16, *PCALLBACK16;
 
+extern const ULONG Int16To32StubSize;
 
 /* FUNCTIONS ******************************************************************/