From f1a3c93e0769e61af252017bba0fcb14dfdea55a Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Tue, 28 Oct 2014 00:33:03 +0000 Subject: [PATCH] [FAST486][NTVDM] Get rid of Fast486Interrupt, since it's not used anywhere. Also we can now remove workarounds for all of the bugs that it caused. Implement the "single-instruction interrupt delay" for instructions that load the stack segment only. svn path=/trunk/; revision=65061 --- .../include/reactos/libs/fast486/fast486.h | 16 +------- reactos/lib/fast486/fast486.c | 40 +++++-------------- reactos/lib/fast486/opcodes.c | 29 ++++++++++---- reactos/subsystems/ntvdm/emulator.c | 6 --- reactos/subsystems/ntvdm/emulator.h | 1 - reactos/subsystems/ntvdm/ntvdm.c | 6 +-- 6 files changed, 38 insertions(+), 60 deletions(-) diff --git a/reactos/include/reactos/libs/fast486/fast486.h b/reactos/include/reactos/libs/fast486/fast486.h index 2a933e51a49..379ad081afa 100644 --- a/reactos/include/reactos/libs/fast486/fast486.h +++ b/reactos/include/reactos/libs/fast486/fast486.h @@ -169,14 +169,6 @@ typedef enum _FAST486_EXCEPTIONS FAST486_EXCEPTION_MC = 0x12 } FAST486_EXCEPTIONS, *PFAST486_EXCEPTIONS; -typedef enum _FAST486_INT_STATUS -{ - FAST486_INT_NONE = 0, - FAST486_INT_EXECUTE = 1, - FAST486_INT_SIGNAL = 2, - FAST486_INT_DELAYED = 3 -} FAST486_INT_STATUS, *PFAST486_INT_STATUS; - typedef VOID (NTAPI *FAST486_MEM_READ_PROC) @@ -495,8 +487,8 @@ struct _FAST486_STATE ULONG PrefixFlags; FAST486_SEG_REGS SegmentOverride; BOOLEAN Halted; - FAST486_INT_STATUS IntStatus; - UCHAR PendingIntNum; + BOOLEAN IntSignaled; + BOOLEAN DoNotInterrupt; PULONG Tlb; #ifndef FAST486_NO_PREFETCH BOOLEAN PrefetchValid; @@ -548,10 +540,6 @@ VOID NTAPI Fast486DumpState(PFAST486_STATE State); -VOID -NTAPI -Fast486Interrupt(PFAST486_STATE State, UCHAR Number); - VOID NTAPI Fast486InterruptSignal(PFAST486_STATE State); diff --git a/reactos/lib/fast486/fast486.c b/reactos/lib/fast486/fast486.c index 12a37685869..bc9748d5791 100644 --- a/reactos/lib/fast486/fast486.c +++ b/reactos/lib/fast486/fast486.c @@ -85,7 +85,12 @@ NextInst: * Check if there is an interrupt to execute, or a hardware interrupt signal * while interrupts are enabled. */ - if (State->Flags.Tf && !State->Halted) + if (State->DoNotInterrupt) + { + /* Clear the interrupt delay flag */ + State->DoNotInterrupt = FALSE; + } + else if (State->Flags.Tf && !State->Halted) { /* Perform the interrupt */ Fast486PerformInterrupt(State, 0x01); @@ -99,29 +104,16 @@ NextInst: */ State->Flags.Tf = FALSE; } - else if (State->IntStatus == FAST486_INT_EXECUTE) + else if (State->Flags.If && State->IntSignaled) { /* No longer halted */ State->Halted = FALSE; - /* Perform the interrupt */ - Fast486PerformInterrupt(State, State->PendingIntNum); + /* Acknowledge the interrupt and perform it */ + Fast486PerformInterrupt(State, State->IntAckCallback(State)); /* Clear the interrupt status */ - State->IntStatus = FAST486_INT_NONE; - } - else if (State->Flags.If && (State->IntStatus == FAST486_INT_SIGNAL)) - { - /* Acknowledge the interrupt to get the number */ - State->PendingIntNum = State->IntAckCallback(State); - - /* Set the interrupt status to execute on the next instruction */ - State->IntStatus = FAST486_INT_EXECUTE; - } - else if (State->IntStatus == FAST486_INT_DELAYED) - { - /* Restore the old state */ - State->IntStatus = FAST486_INT_EXECUTE; + State->IntSignaled = FALSE; } } while ((Command == FAST486_CONTINUE) || @@ -284,21 +276,11 @@ Fast486Reset(PFAST486_STATE State) State->Tlb = Tlb; } -VOID -NTAPI -Fast486Interrupt(PFAST486_STATE State, UCHAR Number) -{ - /* Set the interrupt status and the number */ - State->IntStatus = FAST486_INT_EXECUTE; - State->PendingIntNum = Number; -} - VOID NTAPI Fast486InterruptSignal(PFAST486_STATE State) { - /* Set the interrupt status */ - State->IntStatus = FAST486_INT_SIGNAL; + State->IntSignaled = TRUE; } VOID diff --git a/reactos/lib/fast486/opcodes.c b/reactos/lib/fast486/opcodes.c index 9337988fd34..29c10d85246 100644 --- a/reactos/lib/fast486/opcodes.c +++ b/reactos/lib/fast486/opcodes.c @@ -2635,7 +2635,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopSs) } /* Call the internal API */ - Fast486LoadSegment(State, FAST486_REG_SS, LOWORD(NewSelector)); + if (Fast486LoadSegment(State, FAST486_REG_SS, LOWORD(NewSelector))) + { + /* Inhibit all interrupts until the next instruction */ + State->DoNotInterrupt = TRUE; + } } FAST486_OPCODE_HANDLER(Fast486OpcodeSbbByteModrm) @@ -3953,7 +3957,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovLoadSeg) return; } - Fast486LoadSegment(State, ModRegRm.Register, LOWORD(Selector)); + if (!Fast486LoadSegment(State, ModRegRm.Register, LOWORD(Selector))) + { + /* Exception occurred */ + return; + } } else { @@ -3965,7 +3973,17 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovLoadSeg) return; } - Fast486LoadSegment(State, ModRegRm.Register, Selector); + if (Fast486LoadSegment(State, ModRegRm.Register, Selector)) + { + /* Exception occurred */ + return; + } + } + + if ((INT)ModRegRm.Register == FAST486_REG_SS) + { + /* Inhibit all interrupts until the next instruction */ + State->DoNotInterrupt = TRUE; } } @@ -4261,10 +4279,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLdsLes) * changes the CS:IP, the interrupt handler won't execute and the * stack pointer will never be restored. */ - if (State->IntStatus == FAST486_INT_EXECUTE) - { - State->IntStatus = FAST486_INT_DELAYED; - } + State->DoNotInterrupt = TRUE; return; } diff --git a/reactos/subsystems/ntvdm/emulator.c b/reactos/subsystems/ntvdm/emulator.c index b8a43b6aeae..d2e95e27e15 100644 --- a/reactos/subsystems/ntvdm/emulator.c +++ b/reactos/subsystems/ntvdm/emulator.c @@ -250,12 +250,6 @@ VOID EmulatorTerminate(VOID) VdmRunning = FALSE; } -VOID EmulatorInterrupt(BYTE Number) -{ - /* Call the Fast486 API */ - Fast486Interrupt(&EmulatorContext, Number); -} - VOID EmulatorInterruptSignal(VOID) { /* Call the Fast486 API */ diff --git a/reactos/subsystems/ntvdm/emulator.h b/reactos/subsystems/ntvdm/emulator.h index 4b4928e3313..3c209ccedf2 100644 --- a/reactos/subsystems/ntvdm/emulator.h +++ b/reactos/subsystems/ntvdm/emulator.h @@ -96,7 +96,6 @@ VOID EmulatorException(BYTE ExceptionNumber, LPWORD Stack); VOID EmulatorTerminate(VOID); -VOID EmulatorInterrupt(BYTE Number); VOID EmulatorInterruptSignal(VOID); VOID EmulatorSetA20(BOOLEAN Enabled); diff --git a/reactos/subsystems/ntvdm/ntvdm.c b/reactos/subsystems/ntvdm/ntvdm.c index ab75aff6530..8a194e16ce3 100644 --- a/reactos/subsystems/ntvdm/ntvdm.c +++ b/reactos/subsystems/ntvdm/ntvdm.c @@ -204,9 +204,9 @@ ConsoleCtrlHandler(DWORD ControlType) case CTRL_C_EVENT: case CTRL_BREAK_EVENT: { - /* Call INT 23h */ - DPRINT1("Ctrl-C/Break: Call INT 23h\n"); - EmulatorInterrupt(0x23); + /* HACK: Stop the VDM */ + EmulatorTerminate(); + break; } case CTRL_LAST_CLOSE_EVENT: