From ae24fd4e410dc8ec4f02752aa8f417eae7d405dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 12 Oct 2014 17:23:20 +0000 Subject: [PATCH] [NTVDM] - Move the stack frame indices to where they belong (this is the stack layout when an interrupt is called). - In the bootstrap interrupt, modify the CS:IP stored in the stack instead of the current CS:IP of the CPU, so that we can clean up everything and the interrupt return correctly, instead of breaking everything... (some apps wouldn't start with the original code^^). This is an addendum/fix to revision 64521. svn path=/trunk/; revision=64701 --- reactos/subsystems/ntvdm/bios/bios32/bios32.c | 15 ++++++++++++--- reactos/subsystems/ntvdm/cpu/callback.h | 10 ---------- reactos/subsystems/ntvdm/int32.h | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/reactos/subsystems/ntvdm/bios/bios32/bios32.c b/reactos/subsystems/ntvdm/bios/bios32/bios32.c index eb6f385daf5..4a14b6e2499 100644 --- a/reactos/subsystems/ntvdm/bios/bios32/bios32.c +++ b/reactos/subsystems/ntvdm/bios/bios32/bios32.c @@ -295,9 +295,18 @@ static VOID WINAPI BiosBootstrapLoader(LPWORD Stack) /* Load DOS */ DosBootsectorInitialize(); - /* Position CPU to 0000:7C00 to boot the OS */ - setCS(0x0000); - setIP(0x7C00); + + /* + * Position CPU to 0000:7C00 to boot the OS. + * + * Since we are called via the INT32 mechanism, we need to correctly set + * CS:IP, not by changing the current one (otherwise the interrupt could + * not be clean up and return properly), but by changing the CS:IP in the + * stack, so that when the interrupt returns, the modified CS:IP is popped + * off the stack and the CPU is correctly repositioned. + */ + Stack[STACK_CS] = 0x0000; + Stack[STACK_IP] = 0x7C00; DPRINT1("<-- BiosBootstrapLoader\n"); } diff --git a/reactos/subsystems/ntvdm/cpu/callback.h b/reactos/subsystems/ntvdm/cpu/callback.h index 265669f3611..8813d3b6273 100644 --- a/reactos/subsystems/ntvdm/cpu/callback.h +++ b/reactos/subsystems/ntvdm/cpu/callback.h @@ -29,16 +29,6 @@ typedef struct _CALLBACK16 USHORT NextOffset; } CALLBACK16, *PCALLBACK16; -// -// WARNING WARNING!! -// If you're changing the indices here, you then need to -// also fix the BOP code in callback.c !!!!!!!!!!!!!!!!! -// -#define STACK_INT_NUM 0 -#define STACK_IP 1 -#define STACK_CS 2 -#define STACK_FLAGS 3 - /* FUNCTIONS ******************************************************************/ VOID diff --git a/reactos/subsystems/ntvdm/int32.h b/reactos/subsystems/ntvdm/int32.h index d9dc9f8c774..552d9107a36 100644 --- a/reactos/subsystems/ntvdm/int32.h +++ b/reactos/subsystems/ntvdm/int32.h @@ -19,6 +19,21 @@ /* 32-bit Interrupt Identifiers */ #define EMULATOR_MAX_INT32_NUM 0xFF + 1 + +// +// WARNING WARNING!! +// If you're changing the stack indices here, you then need +// to also fix the Int16To32 handler code in int32.c !! +// + +// Custom variable pushed onto the stack for INT32 interrupts +#define STACK_INT_NUM 0 + +// This is the standard stack layout for an interrupt +#define STACK_IP 1 +#define STACK_CS 2 +#define STACK_FLAGS 3 + extern const ULONG Int16To32StubSize; /* FUNCTIONS ******************************************************************/