Author: aandrejevic Date: Thu Aug 29 22:07:53 2013 New Revision: 59890
URL: http://svn.reactos.org/svn/reactos?rev=59890&view=rev Log: [SOFT386] Add checks for illegal prefixes. Implement HLT and PAUSE.
Modified: branches/ntvdm/include/reactos/libs/soft386/soft386.h branches/ntvdm/lib/soft386/opcodes.c branches/ntvdm/lib/soft386/soft386.c
Modified: branches/ntvdm/include/reactos/libs/soft386/soft386.h URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/include/reactos/libs/soft3... ============================================================================== --- branches/ntvdm/include/reactos/libs/soft386/soft386.h [iso-8859-1] (original) +++ branches/ntvdm/include/reactos/libs/soft386/soft386.h [iso-8859-1] Thu Aug 29 22:07:53 2013 @@ -148,6 +148,13 @@ ULONG Port, PVOID Buffer, ULONG Size +); + +typedef +VOID +(NTAPI *SOFT386_IDLE_PROC) +( + PSOFT386_STATE State );
typedef union _SOFT386_REG @@ -280,6 +287,7 @@ SOFT386_MEM_WRITE_PROC MemWriteCallback; SOFT386_IO_READ_PROC IoReadCallback; SOFT386_IO_WRITE_PROC IoWriteCallback; + SOFT386_IDLE_PROC IdleCallback; SOFT386_REG GeneralRegs[SOFT386_NUM_GEN_REGS]; SOFT386_SEG_REG SegmentRegs[SOFT386_NUM_SEG_REGS]; SOFT386_REG InstPtr; @@ -291,6 +299,7 @@ ULONG ExceptionCount; ULONG PrefixFlags; INT SegmentOverride; + BOOLEAN HardwareInt; };
/* FUNCTIONS ******************************************************************/
Modified: branches/ntvdm/lib/soft386/opcodes.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/lib/soft386/opcodes.c?rev=... ============================================================================== --- branches/ntvdm/lib/soft386/opcodes.c [iso-8859-1] (original) +++ branches/ntvdm/lib/soft386/opcodes.c [iso-8859-1] Thu Aug 29 22:07:53 2013 @@ -600,7 +600,8 @@
if (State->PrefixFlags & SOFT386_PREFIX_REP) { - // TODO: Handle PAUSE instruction. + /* Idle cycle */ + State->IdleCallback(State); }
return TRUE; @@ -748,6 +749,13 @@ /* Make sure this is the right instruction */ ASSERT(Opcode == 0xF8);
+ /* No prefixes allowed */ + if (State->PrefixFlags) + { + Soft386Exception(State, SOFT386_EXCEPTION_UD); + return FALSE; + } + /* Clear CF and return success */ State->Flags.Cf = FALSE; return TRUE; @@ -760,6 +768,13 @@ /* Make sure this is the right instruction */ ASSERT(Opcode == 0xF9);
+ /* No prefixes allowed */ + if (State->PrefixFlags) + { + Soft386Exception(State, SOFT386_EXCEPTION_UD); + return FALSE; + } + /* Set CF and return success*/ State->Flags.Cf = TRUE; return TRUE; @@ -771,6 +786,13 @@ { /* Make sure this is the right instruction */ ASSERT(Opcode == 0xFA); + + /* No prefixes allowed */ + if (State->PrefixFlags) + { + Soft386Exception(State, SOFT386_EXCEPTION_UD); + return FALSE; + }
/* Check for protected mode */ if (State->ControlRegisters[SOFT386_REG_CR0] & SOFT386_CR0_PE) @@ -805,6 +827,13 @@ /* Make sure this is the right instruction */ ASSERT(Opcode == 0xFB);
+ /* No prefixes allowed */ + if (State->PrefixFlags) + { + Soft386Exception(State, SOFT386_EXCEPTION_UD); + return FALSE; + } + /* Check for protected mode */ if (State->ControlRegisters[SOFT386_REG_CR0] & SOFT386_CR0_PE) { @@ -838,6 +867,13 @@ /* Make sure this is the right instruction */ ASSERT(Opcode == 0xFC);
+ /* No prefixes allowed */ + if (State->PrefixFlags) + { + Soft386Exception(State, SOFT386_EXCEPTION_UD); + return FALSE; + } + /* Clear DF and return success */ State->Flags.Df = FALSE; return TRUE; @@ -850,7 +886,42 @@ /* Make sure this is the right instruction */ ASSERT(Opcode == 0xFD);
+ /* No prefixes allowed */ + if (State->PrefixFlags) + { + Soft386Exception(State, SOFT386_EXCEPTION_UD); + return FALSE; + } + /* Set DF and return success*/ State->Flags.Df = TRUE; return TRUE; } + +BOOLEAN +FASTCALL +Soft386OpcodeHalt(PSOFT386_STATE State, UCHAR Opcode) +{ + /* Make sure this is the right instruction */ + ASSERT(Opcode == 0xF4); + + /* No prefixes allowed */ + if (State->PrefixFlags) + { + Soft386Exception(State, SOFT386_EXCEPTION_UD); + return FALSE; + } + + /* Privileged instructions can only be executed under CPL = 0 */ + if (State->SegmentRegs[SOFT386_REG_CS].Dpl != 0) + { + Soft386Exception(State, SOFT386_EXCEPTION_GP); + return FALSE; + } + + /* Halt */ + while (!State->HardwareInt) State->IdleCallback(State); + + /* Return success */ + return TRUE; +}
Modified: branches/ntvdm/lib/soft386/soft386.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/lib/soft386/soft386.c?rev=... ============================================================================== --- branches/ntvdm/lib/soft386/soft386.c [iso-8859-1] (original) +++ branches/ntvdm/lib/soft386/soft386.c [iso-8859-1] Thu Aug 29 22:07:53 2013 @@ -201,6 +201,7 @@ SOFT386_MEM_WRITE_PROC MemWriteCallback = State->MemWriteCallback; SOFT386_IO_READ_PROC IoReadCallback = State->IoReadCallback; SOFT386_IO_WRITE_PROC IoWriteCallback = State->IoWriteCallback; + SOFT386_IDLE_PROC IdleCallback = State->IdleCallback;
/* Clear the entire structure */ RtlZeroMemory(State, sizeof(*State)); @@ -234,6 +235,7 @@ State->MemWriteCallback = MemWriteCallback; State->IoReadCallback = IoReadCallback; State->IoWriteCallback = IoWriteCallback; + State->IdleCallback = IdleCallback; }
VOID