diff --git a/reactos/lib/fast486/common.c b/reactos/lib/fast486/common.c index 147a5c01fc0..52f2fc75ca8 100644 --- a/reactos/lib/fast486/common.c +++ b/reactos/lib/fast486/common.c @@ -294,8 +294,9 @@ Fast486InterruptInternal(PFAST486_STATE State, State->PrefixFlags |= FAST486_PREFIX_OPSIZE; } - /* Check if the interrupt handler is more privileged */ - if (Fast486GetCurrentPrivLevel(State) > GET_SEGMENT_RPL(SegmentSelector)) + /* Check if the interrupt handler is more privileged or if we're in V86 mode */ + if ((Fast486GetCurrentPrivLevel(State) > GET_SEGMENT_RPL(SegmentSelector)) + || State->Flags.Vm) { /* Read the TSS */ if (!Fast486ReadLinearMemory(State, @@ -310,6 +311,24 @@ Fast486InterruptInternal(PFAST486_STATE State, /* Switch to the new privilege level */ State->Cpl = GET_SEGMENT_RPL(SegmentSelector); + if (State->Flags.Vm) + { + /* Clear the VM flag */ + State->Flags.Vm = FALSE; + + /* Push GS, FS, DS and ES */ + if (!Fast486StackPush(State, State->SegmentRegs[FAST486_REG_GS].Selector)) goto Cleanup; + if (!Fast486StackPush(State, State->SegmentRegs[FAST486_REG_FS].Selector)) goto Cleanup; + if (!Fast486StackPush(State, State->SegmentRegs[FAST486_REG_DS].Selector)) goto Cleanup; + if (!Fast486StackPush(State, State->SegmentRegs[FAST486_REG_ES].Selector)) goto Cleanup; + + /* Now load them with NULL selectors, since they are useless in protected mode */ + if (!Fast486LoadSegment(State, FAST486_REG_GS, 0)) goto Cleanup; + if (!Fast486LoadSegment(State, FAST486_REG_FS, 0)) goto Cleanup; + if (!Fast486LoadSegment(State, FAST486_REG_DS, 0)) goto Cleanup; + if (!Fast486LoadSegment(State, FAST486_REG_ES, 0)) goto Cleanup; + } + /* Check the new (higher) privilege level */ switch (State->Cpl) { diff --git a/reactos/lib/fast486/opcodes.c b/reactos/lib/fast486/opcodes.c index 238f2b50e73..90cdc61df5f 100644 --- a/reactos/lib/fast486/opcodes.c +++ b/reactos/lib/fast486/opcodes.c @@ -754,7 +754,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeClearInt) if (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE) { /* Check IOPL */ - if (State->Flags.Iopl >= State->SegmentRegs[FAST486_REG_CS].Dpl) + if (State->Flags.Iopl >= Fast486GetCurrentPrivLevel(State)) { /* Clear the interrupt flag */ State->Flags.If = FALSE; @@ -789,7 +789,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSetInt) if (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE) { /* Check IOPL */ - if (State->Flags.Iopl >= State->SegmentRegs[FAST486_REG_CS].Dpl) + if (State->Flags.Iopl >= Fast486GetCurrentPrivLevel(State)) { /* Set the interrupt flag */ State->Flags.If = TRUE; @@ -4548,6 +4548,14 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeInt) { UCHAR IntNum; + /* Check for V86 mode */ + if (State->Flags.Vm && (State->Flags.Iopl != 3)) + { + /* Call the V86 monitor */ + Fast486Exception(State, FAST486_EXCEPTION_GP); + return; + } + switch (Opcode) { case 0xCC: // INT 3