From: Aleksandar Andrejevic Date: Fri, 18 Oct 2013 22:50:00 +0000 (+0000) Subject: [SOFT386] X-Git-Tag: backups/0.3.17@66124~1365^2~366 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=0e8be812b029702f73006f7d778312741147ea91 [SOFT386] Implement the hardware interrupt system. Modify Soft386Interrupt to assume hardware interrupts, because software interrupts from outside the emulator may cause race conditions. svn path=/branches/ntvdm/; revision=60696 --- diff --git a/include/reactos/libs/soft386/soft386.h b/include/reactos/libs/soft386/soft386.h index e87810dd66a..4e9bd0bc94d 100644 --- a/include/reactos/libs/soft386/soft386.h +++ b/include/reactos/libs/soft386/soft386.h @@ -342,6 +342,7 @@ struct _SOFT386_STATE ULONG PrefixFlags; SOFT386_SEG_REGS SegmentOverride; BOOLEAN HardwareInt; + UCHAR PendingIntNum; }; /* FUNCTIONS ******************************************************************/ @@ -372,7 +373,7 @@ Soft386Reset(PSOFT386_STATE State); VOID NTAPI -Soft386Interrupt(PSOFT386_STATE State, UCHAR Number, BOOLEAN Hardware); +Soft386Interrupt(PSOFT386_STATE State, UCHAR Number); VOID NTAPI diff --git a/lib/soft386/soft386.c b/lib/soft386/soft386.c index 060ac2cea5d..feca57917d7 100644 --- a/lib/soft386/soft386.c +++ b/lib/soft386/soft386.c @@ -56,8 +56,30 @@ Soft386ExecutionControl(PSOFT386_STATE State, INT Command) /* Main execution loop */ do { - /* If this is a new instruction, save the IP */ - if (State->PrefixFlags == 0) State->SavedInstPtr = State->InstPtr; + /* Check if this is a new instruction */ + if (State->PrefixFlags == 0) + { + State->SavedInstPtr = State->InstPtr; + + /* Check if interrupts are enabled and there is an interrupt pending */ + if (State->Flags.If && State->HardwareInt) + { + SOFT386_IDT_ENTRY IdtEntry; + + /* Get the interrupt vector */ + if (Soft386GetIntVector(State, State->PendingIntNum, &IdtEntry)) + { + /* Perform the interrupt */ + Soft386InterruptInternal(State, + IdtEntry.Selector, + MAKELONG(IdtEntry.Offset, IdtEntry.OffsetHigh), + IdtEntry.Type); + } + + /* Clear the interrupt pending flag */ + State->HardwareInt = FALSE; + } + } /* Perform an instruction fetch */ if (!Soft386FetchByte(State, &Opcode)) continue; @@ -273,27 +295,11 @@ Soft386Reset(PSOFT386_STATE State) VOID NTAPI -Soft386Interrupt(PSOFT386_STATE State, UCHAR Number, BOOLEAN Hardware) +Soft386Interrupt(PSOFT386_STATE State, UCHAR Number) { - SOFT386_IDT_ENTRY IdtEntry; - - if (Hardware) - { - /* Set the hardware interrupt flag */ - State->HardwareInt = TRUE; - } - - if (!Soft386GetIntVector(State, Number, &IdtEntry)) - { - /* An exception occurred, let the handler execute */ - return; - } - - /* Perform the interrupt */ - Soft386InterruptInternal(State, - IdtEntry.Selector, - MAKELONG(IdtEntry.Offset, IdtEntry.OffsetHigh), - IdtEntry.Type); + /* Set the hardware interrupt flag */ + State->HardwareInt = TRUE; + State->PendingIntNum = Number; } VOID diff --git a/subsystems/ntvdm/emulator.c b/subsystems/ntvdm/emulator.c index a9814e15038..1c99b574047 100644 --- a/subsystems/ntvdm/emulator.c +++ b/subsystems/ntvdm/emulator.c @@ -473,7 +473,7 @@ VOID EmulatorInterrupt(BYTE Number) softx86_make_simple_interrupt_call(&EmulatorContext, &Segment, &Offset); #else /* Call the Soft386 API */ - Soft386Interrupt(&EmulatorContext, Number, FALSE); + Soft386Interrupt(&EmulatorContext, Number); #endif } @@ -484,7 +484,7 @@ VOID EmulatorExternalInterrupt(BYTE Number) softx86_ext_hw_signal(&EmulatorContext, Number); #else /* Call the Soft386 API */ - Soft386Interrupt(&EmulatorContext, Number, TRUE); + Soft386Interrupt(&EmulatorContext, Number); #endif }