diff --git a/include/reactos/libs/soft386/soft386.h b/include/reactos/libs/soft386/soft386.h index 0f699c687d9..00e68e90cd7 100644 --- a/include/reactos/libs/soft386/soft386.h +++ b/include/reactos/libs/soft386/soft386.h @@ -332,6 +332,10 @@ VOID NTAPI Soft386Interrupt(PSOFT386_STATE State, UCHAR Number); +VOID +NTAPI +Soft386ExecuteAt(PSOFT386_STATE State, USHORT Segment, ULONG Offset); + #endif // _SOFT386_H_ /* EOF */ diff --git a/lib/soft386/opcodes.c b/lib/soft386/opcodes.c index 5ab29377c10..51ed74e4d4d 100644 --- a/lib/soft386/opcodes.c +++ b/lib/soft386/opcodes.c @@ -726,7 +726,7 @@ Soft386OpcodeShortConditionalJmp(PSOFT386_STATE State, UCHAR Opcode) } } - if ((Opcode & 0xF0) & 1) + if (Opcode & 1) { /* Invert the result */ Jump = !Jump; diff --git a/lib/soft386/soft386.c b/lib/soft386/soft386.c index f6283ac3aa8..22732fdf340 100644 --- a/lib/soft386/soft386.c +++ b/lib/soft386/soft386.c @@ -58,6 +58,12 @@ Soft386ExecutionControl(PSOFT386_STATE State, INT Command) /* 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) || (Command == SOFT386_STEP_OVER && ProcedureCallCount > 0) @@ -246,4 +252,19 @@ Soft386Interrupt(PSOFT386_STATE State, UCHAR Number) 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 */ diff --git a/subsystems/ntvdm/emulator.c b/subsystems/ntvdm/emulator.c index 33441a356b4..c41d1c646ac 100644 --- a/subsystems/ntvdm/emulator.c +++ b/subsystems/ntvdm/emulator.c @@ -31,8 +31,6 @@ static BOOLEAN A20Line = FALSE; /* PRIVATE FUNCTIONS **********************************************************/ -#ifndef NEW_EMULATOR - static VOID EmulatorReadMemory(PVOID Context, UINT Address, LPBYTE Buffer, INT Size) { UNREFERENCED_PARAMETER(Context); @@ -230,6 +228,8 @@ static VOID EmulatorWriteIo(PVOID Context, UINT Address, LPBYTE Buffer, INT Size } } +#ifndef NEW_EMULATOR + static VOID EmulatorBop(WORD Code) { WORD StackSegment, StackPointer, CodeSegment, InstructionPointer; @@ -407,7 +407,14 @@ BOOLEAN EmulatorInitialize() /* 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 @@ VOID EmulatorSetStack(WORD Segment, DWORD Offset) #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 @@ VOID EmulatorStep(VOID) EmulatorInterrupt(EMULATOR_EXCEPTION_INVALID_OPCODE); } #else - // TODO: NOT IMPLEMENTED + /* Dump the state for debugging purposes */ + Soft386DumpState(&EmulatorContext); + + /* Execute the next instruction */ + Soft386StepInto(&EmulatorContext); #endif } diff --git a/subsystems/ntvdm/ntvdm.h b/subsystems/ntvdm/ntvdm.h index f34354824b8..371604d9f35 100644 --- a/subsystems/ntvdm/ntvdm.h +++ b/subsystems/ntvdm/ntvdm.h @@ -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;