From de36490031fc50d59ea0c93c10305ad0aa07c850 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Mon, 19 May 2014 01:12:25 +0000 Subject: [PATCH] [NTVDM] 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 | 8 ++------ reactos/subsystems/ntvdm/bios/bios32/bios32p.h | 9 +++++---- reactos/subsystems/ntvdm/bop.c | 2 +- reactos/subsystems/ntvdm/callback.c | 10 ++++++---- reactos/subsystems/ntvdm/callback.h | 6 ++---- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/reactos/subsystems/ntvdm/bios/bios32/bios32.c b/reactos/subsystems/ntvdm/bios/bios32/bios32.c index fc272826242..045e58c82bb 100644 --- a/reactos/subsystems/ntvdm/bios/bios32/bios32.c +++ b/reactos/subsystems/ntvdm/bios/bios32/bios32.c @@ -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 */ diff --git a/reactos/subsystems/ntvdm/bios/bios32/bios32p.h b/reactos/subsystems/ntvdm/bios/bios32/bios32p.h index 604fda30cc7..d74e04e7d4d 100644 --- a/reactos/subsystems/ntvdm/bios/bios32/bios32p.h +++ b/reactos/subsystems/ntvdm/bios/bios32/bios32p.h @@ -30,11 +30,12 @@ /* 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); diff --git a/reactos/subsystems/ntvdm/bop.c b/reactos/subsystems/ntvdm/bop.c index 407004290b7..88a41dde9ef 100644 --- a/reactos/subsystems/ntvdm/bop.c +++ b/reactos/subsystems/ntvdm/bop.c @@ -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 ***********************************************************/ diff --git a/reactos/subsystems/ntvdm/callback.c b/reactos/subsystems/ntvdm/callback.c index 7566a9437a7..d1ecaf3f436 100644 --- a/reactos/subsystems/ntvdm/callback.c +++ b/reactos/subsystems/ntvdm/callback.c @@ -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 diff --git a/reactos/subsystems/ntvdm/callback.h b/reactos/subsystems/ntvdm/callback.h index c29ef9cb687..264e67fe6d0 100644 --- a/reactos/subsystems/ntvdm/callback.h +++ b/reactos/subsystems/ntvdm/callback.h @@ -15,17 +15,15 @@ /* 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 ******************************************************************/ -- 2.17.1