Author: aandrejevic Date: Sat Aug 31 19:18:12 2013 New Revision: 59929
URL: http://svn.reactos.org/svn/reactos?rev=59929&view=rev Log: [SOFT386] Fix the "persistant prefix" bug. Fix the conditional jump bug. Implement Soft386ExecuteAt. [NTVDM] Add Soft386 support to ntvdm.
Modified: branches/ntvdm/include/reactos/libs/soft386/soft386.h branches/ntvdm/lib/soft386/opcodes.c branches/ntvdm/lib/soft386/soft386.c branches/ntvdm/subsystems/ntvdm/emulator.c branches/ntvdm/subsystems/ntvdm/ntvdm.h
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] Sat Aug 31 19:18:12 2013 @@ -332,6 +332,10 @@ NTAPI Soft386Interrupt(PSOFT386_STATE State, UCHAR Number);
+VOID +NTAPI +Soft386ExecuteAt(PSOFT386_STATE State, USHORT Segment, ULONG Offset); + #endif // _SOFT386_H_
/* EOF */
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] Sat Aug 31 19:18:12 2013 @@ -726,7 +726,7 @@ } }
- if ((Opcode & 0xF0) & 1) + if (Opcode & 1) { /* Invert the result */ Jump = !Jump;
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] Sat Aug 31 19:18:12 2013 @@ -57,6 +57,12 @@ { /* This is not a valid opcode */ Soft386Exception(State, SOFT386_EXCEPTION_UD); + } + + if (Soft386OpcodeHandlers[Opcode] != Soft386OpcodePrefix) + { + /* A non-prefix opcode has been executed, reset the prefix flags */ + State->PrefixFlags = 0; } } while ((Command == SOFT386_CONTINUE) @@ -246,4 +252,19 @@ UNIMPLEMENTED; }
+VOID +NTAPI +Soft386ExecuteAt(PSOFT386_STATE State, USHORT Segment, ULONG Offset) +{ + /* Load the new CS */ + if (!Soft386LoadSegment(State, SOFT386_REG_CS, Segment)) + { + /* An exception occurred, let the handler execute instead */ + return; + } + + /* Set the new IP */ + State->InstPtr.Long = Offset; +} + /* EOF */
Modified: branches/ntvdm/subsystems/ntvdm/emulator.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/emulator.... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/emulator.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/emulator.c [iso-8859-1] Sat Aug 31 19:18:12 2013 @@ -30,8 +30,6 @@ static BOOLEAN A20Line = FALSE;
/* PRIVATE FUNCTIONS **********************************************************/ - -#ifndef NEW_EMULATOR
static VOID EmulatorReadMemory(PVOID Context, UINT Address, LPBYTE Buffer, INT Size) { @@ -230,6 +228,8 @@ } }
+#ifndef NEW_EMULATOR + static VOID EmulatorBop(WORD Code) { WORD StackSegment, StackPointer, CodeSegment, InstructionPointer; @@ -407,7 +407,14 @@ /* Connect the emulated FPU to the emulated CPU */ softx87_connect_to_CPU(&EmulatorContext, &FpuEmulatorContext); #else - // TODO: NOT IMPLEMENTED + /* Set the callbacks */ + EmulatorContext.MemReadCallback = (SOFT386_MEM_READ_PROC)EmulatorReadMemory; + EmulatorContext.MemWriteCallback = (SOFT386_MEM_WRITE_PROC)EmulatorWriteMemory; + EmulatorContext.IoReadCallback = (SOFT386_IO_READ_PROC)EmulatorReadIo; + EmulatorContext.IoWriteCallback = (SOFT386_IO_WRITE_PROC)EmulatorWriteIo; + + /* Reset the CPU */ + Soft386Reset(&EmulatorContext); #endif
/* Enable interrupts */ @@ -426,13 +433,15 @@ #endif }
+// FIXME: This function assumes 16-bit mode!!! VOID EmulatorExecute(WORD Segment, WORD Offset) { #ifndef NEW_EMULATOR /* Call the softx86 API */ softx86_set_instruction_ptr(&EmulatorContext, Segment, Offset); #else - // TODO: NOT IMPLEMENTED + /* Tell Soft386 to move the instruction pointer */ + Soft386ExecuteAt(&EmulatorContext, Segment, Offset); #endif }
@@ -572,7 +581,11 @@ EmulatorInterrupt(EMULATOR_EXCEPTION_INVALID_OPCODE); } #else - // TODO: NOT IMPLEMENTED + /* Dump the state for debugging purposes */ + Soft386DumpState(&EmulatorContext); + + /* Execute the next instruction */ + Soft386StepInto(&EmulatorContext); #endif }
Modified: branches/ntvdm/subsystems/ntvdm/ntvdm.h URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/ntvdm.h?r... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/ntvdm.h [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/ntvdm.h [iso-8859-1] Sat Aug 31 19:18:12 2013 @@ -27,6 +27,9 @@ #define FAR_POINTER(x) ((ULONG_PTR)BaseAddress + TO_LINEAR(HIWORD(x), LOWORD(x))) #define STEPS_PER_CYCLE 256
+// Uncomment the following to use the new Soft386 CPU emulator (EXPERIMENTAL) +// #define NEW_EMULATOR + /* FUNCTIONS ******************************************************************/
extern LPVOID BaseAddress;