From c063145e96ad665e9124798b3326d3b0b27ab75d Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Fri, 12 Jun 2015 03:30:40 +0000 Subject: [PATCH] [FAST486][NTVDM] Use FASTCALL instead of NTAPI. Merge EmulatorReadMemory with MemRead and EmulatorWriteMemory with MemWrite. svn path=/trunk/; revision=68109 --- .../include/reactos/libs/fast486/fast486.h | 14 +-- reactos/lib/fast486/debug.c | 101 ++++++++--------- reactos/lib/fast486/fast486.c | 103 ++---------------- reactos/subsystems/mvdm/ntvdm/bios/vidbios.c | 1 + reactos/subsystems/mvdm/ntvdm/cpu/bop.c | 2 +- reactos/subsystems/mvdm/ntvdm/cpu/bop.h | 2 +- .../mvdm/ntvdm/dos/dos32krnl/dosfiles.c | 11 +- .../mvdm/ntvdm/dos/dos32krnl/himem.c | 1 + .../mvdm/ntvdm/dos/dos32krnl/memory.h | 6 +- reactos/subsystems/mvdm/ntvdm/dos/mouse32.c | 1 + reactos/subsystems/mvdm/ntvdm/emulator.c | 55 +--------- reactos/subsystems/mvdm/ntvdm/emulator.h | 24 +--- reactos/subsystems/mvdm/ntvdm/hardware/dma.c | 8 +- reactos/subsystems/mvdm/ntvdm/hardware/ps2.c | 1 + reactos/subsystems/mvdm/ntvdm/io.c | 4 +- reactos/subsystems/mvdm/ntvdm/io.h | 4 +- reactos/subsystems/mvdm/ntvdm/memory.c | 56 ++++++++-- reactos/subsystems/mvdm/ntvdm/memory.h | 11 +- 18 files changed, 149 insertions(+), 256 deletions(-) diff --git a/reactos/include/reactos/libs/fast486/fast486.h b/reactos/include/reactos/libs/fast486/fast486.h index 9280f488786..923f828dabf 100644 --- a/reactos/include/reactos/libs/fast486/fast486.h +++ b/reactos/include/reactos/libs/fast486/fast486.h @@ -182,7 +182,7 @@ typedef enum _FAST486_EXCEPTIONS typedef VOID -(NTAPI *FAST486_MEM_READ_PROC) +(FASTCALL *FAST486_MEM_READ_PROC) ( PFAST486_STATE State, ULONG Address, @@ -192,7 +192,7 @@ VOID typedef VOID -(NTAPI *FAST486_MEM_WRITE_PROC) +(FASTCALL *FAST486_MEM_WRITE_PROC) ( PFAST486_STATE State, ULONG Address, @@ -202,7 +202,7 @@ VOID typedef VOID -(NTAPI *FAST486_IO_READ_PROC) +(FASTCALL *FAST486_IO_READ_PROC) ( PFAST486_STATE State, USHORT Port, @@ -213,7 +213,7 @@ VOID typedef VOID -(NTAPI *FAST486_IO_WRITE_PROC) +(FASTCALL *FAST486_IO_WRITE_PROC) ( PFAST486_STATE State, USHORT Port, @@ -224,7 +224,7 @@ VOID typedef VOID -(NTAPI *FAST486_BOP_PROC) +(FASTCALL *FAST486_BOP_PROC) ( PFAST486_STATE State, UCHAR BopCode @@ -232,14 +232,14 @@ VOID typedef UCHAR -(NTAPI *FAST486_INT_ACK_PROC) +(FASTCALL *FAST486_INT_ACK_PROC) ( PFAST486_STATE State ); typedef VOID -(NTAPI *FAST486_FPU_PROC) +(FASTCALL *FAST486_FPU_PROC) ( PFAST486_STATE State ); diff --git a/reactos/lib/fast486/debug.c b/reactos/lib/fast486/debug.c index af362f1328f..a4a935a2e7d 100644 --- a/reactos/lib/fast486/debug.c +++ b/reactos/lib/fast486/debug.c @@ -43,91 +43,82 @@ typedef enum /* PRIVATE FUNCTIONS **********************************************************/ -#if 0 -static inline VOID -NTAPI +FORCEINLINE +VOID +FASTCALL Fast486ExecutionControl(PFAST486_STATE State, FAST486_EXEC_CMD Command) { UCHAR Opcode; FAST486_OPCODE_HANDLER_PROC CurrentHandler; INT ProcedureCallCount = 0; + BOOLEAN Trap; /* Main execution loop */ do { -NextInst: - /* Check if this is a new instruction */ - if (State->PrefixFlags == 0) State->SavedInstPtr = State->InstPtr; + Trap = State->Flags.Tf; - /* Perform an instruction fetch */ - if (!Fast486FetchByte(State, &Opcode)) + if (!State->Halted) { - /* Exception occurred */ +NextInst: + /* Check if this is a new instruction */ + if (State->PrefixFlags == 0) + { + State->SavedInstPtr = State->InstPtr; + State->SavedStackPtr = State->GeneralRegs[FAST486_REG_ESP]; + } + + /* Perform an instruction fetch */ + if (!Fast486FetchByte(State, &Opcode)) + { + /* Exception occurred */ + State->PrefixFlags = 0; + continue; + } + + // TODO: Check for CALL/RET to update ProcedureCallCount. + + /* Call the opcode handler */ + CurrentHandler = Fast486OpcodeHandlers[Opcode]; + CurrentHandler(State, Opcode); + + /* If this is a prefix, go to the next instruction immediately */ + if (CurrentHandler == Fast486OpcodePrefix) goto NextInst; + + /* A non-prefix opcode has been executed, reset the prefix flags */ State->PrefixFlags = 0; - continue; } - // TODO: Check for CALL/RET to update ProcedureCallCount. - - /* Call the opcode handler */ - CurrentHandler = Fast486OpcodeHandlers[Opcode]; - CurrentHandler(State, Opcode); - - /* If this is a prefix, go to the next instruction immediately */ - if (CurrentHandler == Fast486OpcodePrefix) goto NextInst; - - /* A non-prefix opcode has been executed, reset the prefix flags */ - State->PrefixFlags = 0; - /* * Check if there is an interrupt to execute, or a hardware interrupt signal * while interrupts are enabled. */ - if (State->Flags.Tf) + if (State->DoNotInterrupt) { - /* Perform the interrupt */ - Fast486PerformInterrupt(State, 0x01); - - /* - * Flags and TF are pushed on stack so we can reset TF now, - * to not break into the INT 0x01 handler. - * After the INT 0x01 handler returns, the flags and therefore - * TF are popped back off the stack and restored, so TF will be - * automatically reset to its previous state. - */ - State->Flags.Tf = FALSE; + /* Clear the interrupt delay flag */ + State->DoNotInterrupt = FALSE; } - else if (State->IntStatus == FAST486_INT_EXECUTE) + else if (Trap && !State->Halted) { /* Perform the interrupt */ - Fast486PerformInterrupt(State, State->PendingIntNum); + Fast486PerformInterrupt(State, FAST486_EXCEPTION_DB); + } + else if (State->Flags.If && State->IntSignaled) + { + /* No longer halted */ + State->Halted = FALSE; + + /* Acknowledge the interrupt and perform it */ + Fast486PerformInterrupt(State, State->IntAckCallback(State)); /* Clear the interrupt status */ - State->IntStatus = FAST486_INT_NONE; - } - else if (State->Flags.If && (State->IntStatus == FAST486_INT_SIGNAL)) - { - /* Acknowledge the interrupt to get the number */ - State->PendingIntNum = State->IntAckCallback(State); - - /* Set the interrupt status to execute on the next instruction */ - State->IntStatus = FAST486_INT_EXECUTE; - } - else if (State->IntStatus == FAST486_INT_DELAYED) - { - /* Restore the old state */ - State->IntStatus = FAST486_INT_EXECUTE; + State->IntSignaled = FALSE; } } while ((Command == FAST486_CONTINUE) || (Command == FAST486_STEP_OVER && ProcedureCallCount > 0) || (Command == FAST486_STEP_OUT && ProcedureCallCount >= 0)); } -#else -VOID -NTAPI -Fast486ExecutionControl(PFAST486_STATE State, FAST486_EXEC_CMD Command); -#endif /* PUBLIC FUNCTIONS ***********************************************************/ diff --git a/reactos/lib/fast486/fast486.c b/reactos/lib/fast486/fast486.c index e2ff4562b21..8505bccbfb6 100644 --- a/reactos/lib/fast486/fast486.c +++ b/reactos/lib/fast486/fast486.c @@ -31,98 +31,10 @@ #include "opcodes.h" #include "fpu.h" -/* DEFINES ********************************************************************/ - -typedef enum -{ - FAST486_STEP_INTO, - FAST486_STEP_OVER, - FAST486_STEP_OUT, - FAST486_CONTINUE -} FAST486_EXEC_CMD; - -/* PRIVATE FUNCTIONS **********************************************************/ - -VOID -NTAPI -Fast486ExecutionControl(PFAST486_STATE State, FAST486_EXEC_CMD Command) -{ - UCHAR Opcode; - FAST486_OPCODE_HANDLER_PROC CurrentHandler; - INT ProcedureCallCount = 0; - BOOLEAN Trap; - - /* Main execution loop */ - do - { - Trap = State->Flags.Tf; - - if (!State->Halted) - { -NextInst: - /* Check if this is a new instruction */ - if (State->PrefixFlags == 0) - { - State->SavedInstPtr = State->InstPtr; - State->SavedStackPtr = State->GeneralRegs[FAST486_REG_ESP]; - } - - /* Perform an instruction fetch */ - if (!Fast486FetchByte(State, &Opcode)) - { - /* Exception occurred */ - State->PrefixFlags = 0; - continue; - } - - // TODO: Check for CALL/RET to update ProcedureCallCount. - - /* Call the opcode handler */ - CurrentHandler = Fast486OpcodeHandlers[Opcode]; - CurrentHandler(State, Opcode); - - /* If this is a prefix, go to the next instruction immediately */ - if (CurrentHandler == Fast486OpcodePrefix) goto NextInst; - - /* A non-prefix opcode has been executed, reset the prefix flags */ - State->PrefixFlags = 0; - } - - /* - * Check if there is an interrupt to execute, or a hardware interrupt signal - * while interrupts are enabled. - */ - if (State->DoNotInterrupt) - { - /* Clear the interrupt delay flag */ - State->DoNotInterrupt = FALSE; - } - else if (Trap && !State->Halted) - { - /* Perform the interrupt */ - Fast486PerformInterrupt(State, FAST486_EXCEPTION_DB); - } - else if (State->Flags.If && State->IntSignaled) - { - /* No longer halted */ - State->Halted = FALSE; - - /* Acknowledge the interrupt and perform it */ - Fast486PerformInterrupt(State, State->IntAckCallback(State)); - - /* Clear the interrupt status */ - State->IntSignaled = FALSE; - } - } - while ((Command == FAST486_CONTINUE) || - (Command == FAST486_STEP_OVER && ProcedureCallCount > 0) || - (Command == FAST486_STEP_OUT && ProcedureCallCount >= 0)); -} - /* DEFAULT CALLBACKS **********************************************************/ static VOID -NTAPI +FASTCALL Fast486MemReadCallback(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size) { UNREFERENCED_PARAMETER(State); @@ -130,7 +42,7 @@ Fast486MemReadCallback(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG } static VOID -NTAPI +FASTCALL Fast486MemWriteCallback(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size) { UNREFERENCED_PARAMETER(State); @@ -138,7 +50,7 @@ Fast486MemWriteCallback(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG } static VOID -NTAPI +FASTCALL Fast486IoReadCallback(PFAST486_STATE State, USHORT Port, PVOID Buffer, ULONG DataCount, UCHAR DataSize) { UNREFERENCED_PARAMETER(State); @@ -149,7 +61,7 @@ Fast486IoReadCallback(PFAST486_STATE State, USHORT Port, PVOID Buffer, ULONG Dat } static VOID -NTAPI +FASTCALL Fast486IoWriteCallback(PFAST486_STATE State, USHORT Port, PVOID Buffer, ULONG DataCount, UCHAR DataSize) { UNREFERENCED_PARAMETER(State); @@ -160,7 +72,7 @@ Fast486IoWriteCallback(PFAST486_STATE State, USHORT Port, PVOID Buffer, ULONG Da } static VOID -NTAPI +FASTCALL Fast486BopCallback(PFAST486_STATE State, UCHAR BopCode) { UNREFERENCED_PARAMETER(State); @@ -168,7 +80,7 @@ Fast486BopCallback(PFAST486_STATE State, UCHAR BopCode) } static UCHAR -NTAPI +FASTCALL Fast486IntAckCallback(PFAST486_STATE State) { UNREFERENCED_PARAMETER(State); @@ -177,7 +89,8 @@ Fast486IntAckCallback(PFAST486_STATE State) return 0x01; } -static VOID NTAPI +static VOID +FASTCALL Fast486FpuCallback(PFAST486_STATE State) { UNREFERENCED_PARAMETER(State); diff --git a/reactos/subsystems/mvdm/ntvdm/bios/vidbios.c b/reactos/subsystems/mvdm/ntvdm/bios/vidbios.c index 4b923a4e5eb..a03029d7df5 100644 --- a/reactos/subsystems/mvdm/ntvdm/bios/vidbios.c +++ b/reactos/subsystems/mvdm/ntvdm/bios/vidbios.c @@ -15,6 +15,7 @@ #include "emulator.h" #include "cpu/cpu.h" #include "cpu/bop.h" +#include "memory.h" #include "bios.h" // #include "vidbios.h" diff --git a/reactos/subsystems/mvdm/ntvdm/cpu/bop.c b/reactos/subsystems/mvdm/ntvdm/cpu/bop.c index 3cc411e1dab..b66e88f830f 100644 --- a/reactos/subsystems/mvdm/ntvdm/cpu/bop.c +++ b/reactos/subsystems/mvdm/ntvdm/cpu/bop.c @@ -29,7 +29,7 @@ VOID RegisterBop(BYTE BopCode, EMULATOR_BOP_PROC BopHandler) BopProc[BopCode] = BopHandler; } -VOID WINAPI EmulatorBiosOperation(PFAST486_STATE State, UCHAR BopCode) +VOID FASTCALL EmulatorBiosOperation(PFAST486_STATE State, UCHAR BopCode) { WORD StackSegment, StackPointer; LPWORD Stack; diff --git a/reactos/subsystems/mvdm/ntvdm/cpu/bop.h b/reactos/subsystems/mvdm/ntvdm/cpu/bop.h index a936d1f25cb..a8240b82fbf 100644 --- a/reactos/subsystems/mvdm/ntvdm/cpu/bop.h +++ b/reactos/subsystems/mvdm/ntvdm/cpu/bop.h @@ -21,7 +21,7 @@ typedef VOID (WINAPI *EMULATOR_BOP_PROC)(LPWORD Stack); VOID RegisterBop(BYTE BopCode, EMULATOR_BOP_PROC BopHandler); -VOID WINAPI EmulatorBiosOperation(PFAST486_STATE State, UCHAR BopCode); +VOID FASTCALL EmulatorBiosOperation(PFAST486_STATE State, UCHAR BopCode); #endif // _BOP_H_ diff --git a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.c b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.c index 30644b56ab6..a2740769335 100644 --- a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.c +++ b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/dosfiles.c @@ -704,7 +704,10 @@ WORD DosReadFile(WORD FileHandle, if (ReadFile(Descriptor->Win32Handle, LocalBuffer, Count, &BytesRead32, NULL)) { /* Write to the memory */ - MemWrite(TO_LINEAR(HIWORD(Buffer), LOWORD(Buffer)), LocalBuffer, LOWORD(BytesRead32)); + EmulatorWriteMemory(&EmulatorContext, + TO_LINEAR(HIWORD(Buffer), LOWORD(Buffer)), + LocalBuffer, + LOWORD(BytesRead32)); /* Update the position */ Descriptor->Position += BytesRead32; @@ -756,7 +759,11 @@ WORD DosWriteFile(WORD FileHandle, ASSERT(LocalBuffer != NULL); /* Read from the memory */ - MemRead(TO_LINEAR(HIWORD(Buffer), LOWORD(Buffer)), LocalBuffer, Count); + EmulatorReadMemory(&EmulatorContext, + TO_LINEAR(HIWORD(Buffer), + LOWORD(Buffer)), + LocalBuffer, + Count); /* Write the file */ if (WriteFile(Descriptor->Win32Handle, LocalBuffer, Count, &BytesWritten32, NULL)) diff --git a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/himem.c b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/himem.c index 259f90e58b3..96bd5c779aa 100644 --- a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/himem.c +++ b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/himem.c @@ -13,6 +13,7 @@ #include "ntvdm.h" #include "emulator.h" #include "cpu/bop.h" +#include "../../memory.h" #include "io.h" #include "hardware/ps2.h" diff --git a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/memory.h b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/memory.h index 3d537bebbe9..e9ed2dc70f5 100644 --- a/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/memory.h +++ b/reactos/subsystems/mvdm/ntvdm/dos/dos32krnl/memory.h @@ -6,8 +6,8 @@ * PROGRAMMERS: Aleksandar Andrejevic */ -#ifndef _MEMORY_H_ -#define _MEMORY_H_ +#ifndef _DOS_MEMORY_H_ +#define _DOS_MEMORY_H_ /* TYPEDEFS *******************************************************************/ @@ -45,6 +45,6 @@ BOOLEAN DosLinkUmb(VOID); BOOLEAN DosUnlinkUmb(VOID); VOID DosChangeMemoryOwner(WORD Segment, WORD NewOwner); -#endif // _MEMORY_H_ +#endif // _DOS_MEMORY_H_ /* EOF */ diff --git a/reactos/subsystems/mvdm/ntvdm/dos/mouse32.c b/reactos/subsystems/mvdm/ntvdm/dos/mouse32.c index d2f2a31262c..0a116f753ac 100644 --- a/reactos/subsystems/mvdm/ntvdm/dos/mouse32.c +++ b/reactos/subsystems/mvdm/ntvdm/dos/mouse32.c @@ -24,6 +24,7 @@ #include "bios/bios.h" #include "bios/bios32/bios32p.h" +#include "memory.h" #include "io.h" #include "dos32krnl/dos.h" diff --git a/reactos/subsystems/mvdm/ntvdm/emulator.c b/reactos/subsystems/mvdm/ntvdm/emulator.c index e3a9fa5deef..933162c2949 100644 --- a/reactos/subsystems/mvdm/ntvdm/emulator.c +++ b/reactos/subsystems/mvdm/ntvdm/emulator.c @@ -42,8 +42,6 @@ LPVOID BaseAddress = NULL; BOOLEAN VdmRunning = TRUE; -static BOOLEAN A20Line = FALSE; - static HANDLE InputThread = NULL; LPCWSTR ExceptionName[] = @@ -63,46 +61,7 @@ LPCWSTR ExceptionName[] = /* PRIVATE FUNCTIONS **********************************************************/ -VOID WINAPI EmulatorReadMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size) -{ - UNREFERENCED_PARAMETER(State); - - /* Mirror 0x000FFFF0 at 0xFFFFFFF0 */ - if (Address >= 0xFFFFFFF0) Address -= 0xFFF00000; - - /* If the A20 line is disabled, mask bit 20 */ - if (!A20Line) Address &= ~(1 << 20); - - if ((Address + Size - 1) >= MAX_ADDRESS) - { - ULONG ExtraStart = (Address < MAX_ADDRESS) ? MAX_ADDRESS - Address : 0; - - /* Fill the memory that was above the limit with 0xFF */ - RtlFillMemory((PVOID)((ULONG_PTR)Buffer + ExtraStart), Size - ExtraStart, 0xFF); - - if (Address < MAX_ADDRESS) Size = MAX_ADDRESS - Address; - else return; - } - - /* Read while calling fast memory hooks */ - MemRead(Address, Buffer, Size); -} - -VOID WINAPI EmulatorWriteMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size) -{ - UNREFERENCED_PARAMETER(State); - - /* If the A20 line is disabled, mask bit 20 */ - if (!A20Line) Address &= ~(1 << 20); - - if (Address >= MAX_ADDRESS) return; - Size = min(Size, MAX_ADDRESS - Address); - - /* Write while calling fast memory hooks */ - MemWrite(Address, Buffer, Size); -} - -UCHAR WINAPI EmulatorIntAcknowledge(PFAST486_STATE State) +UCHAR FASTCALL EmulatorIntAcknowledge(PFAST486_STATE State) { UNREFERENCED_PARAMETER(State); @@ -110,7 +69,7 @@ UCHAR WINAPI EmulatorIntAcknowledge(PFAST486_STATE State) return PicGetInterrupt(); } -VOID WINAPI EmulatorFpu(PFAST486_STATE State) +VOID FASTCALL EmulatorFpu(PFAST486_STATE State) { /* The FPU is wired to IRQ 13 */ PicInterruptRequest(13); @@ -164,16 +123,6 @@ VOID EmulatorInterruptSignal(VOID) Fast486InterruptSignal(&EmulatorContext); } -VOID EmulatorSetA20(BOOLEAN Enabled) -{ - A20Line = Enabled; -} - -BOOLEAN EmulatorGetA20(VOID) -{ - return A20Line; -} - static VOID WINAPI EmulatorDebugBreakBop(LPWORD Stack) { DPRINT1("NTVDM: BOP_DEBUGGER\n"); diff --git a/reactos/subsystems/mvdm/ntvdm/emulator.h b/reactos/subsystems/mvdm/ntvdm/emulator.h index 0b032d7ff48..b904345503e 100644 --- a/reactos/subsystems/mvdm/ntvdm/emulator.h +++ b/reactos/subsystems/mvdm/ntvdm/emulator.h @@ -90,7 +90,7 @@ enum EMULATOR_EXCEPTION_PAGE_FAULT }; -// extern FAST486_STATE EmulatorContext; +extern FAST486_STATE EmulatorContext; extern LPVOID BaseAddress; extern BOOLEAN VdmRunning; @@ -98,28 +98,12 @@ extern BOOLEAN VdmRunning; VOID DumpMemory(BOOLEAN TextFormat); -VOID WINAPI EmulatorReadMemory -( - PFAST486_STATE State, - ULONG Address, - PVOID Buffer, - ULONG Size -); - -VOID WINAPI EmulatorWriteMemory -( - PFAST486_STATE State, - ULONG Address, - PVOID Buffer, - ULONG Size -); - -UCHAR WINAPI EmulatorIntAcknowledge +UCHAR FASTCALL EmulatorIntAcknowledge ( PFAST486_STATE State ); -VOID WINAPI EmulatorFpu +VOID FASTCALL EmulatorFpu ( PFAST486_STATE State ); @@ -129,8 +113,6 @@ VOID EmulatorException(BYTE ExceptionNumber, LPWORD Stack); VOID EmulatorTerminate(VOID); VOID EmulatorInterruptSignal(VOID); -VOID EmulatorSetA20(BOOLEAN Enabled); -BOOLEAN EmulatorGetA20(VOID); BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput); VOID EmulatorCleanup(VOID); diff --git a/reactos/subsystems/mvdm/ntvdm/hardware/dma.c b/reactos/subsystems/mvdm/ntvdm/hardware/dma.c index a268982478d..ae63da78f3f 100644 --- a/reactos/subsystems/mvdm/ntvdm/hardware/dma.c +++ b/reactos/subsystems/mvdm/ntvdm/hardware/dma.c @@ -477,13 +477,13 @@ DWORD DmaRequest(IN WORD iChannel, if (Increment) { - MemWrite(CurrAddress, dmabuf, length); + EmulatorWriteMemory(&EmulatorContext, CurrAddress, dmabuf, length); } else { for (i = 0; i < length; i++) { - MemWrite(CurrAddress - i, dmabuf + i, sizeof(BYTE)); + EmulatorWriteMemory(&EmulatorContext, CurrAddress - i, dmabuf + i, sizeof(BYTE)); } } @@ -498,13 +498,13 @@ DWORD DmaRequest(IN WORD iChannel, if (Increment) { - MemRead(CurrAddress, dmabuf, length); + EmulatorReadMemory(&EmulatorContext, CurrAddress, dmabuf, length); } else { for (i = 0; i < length; i++) { - MemRead(CurrAddress - i, dmabuf + i, sizeof(BYTE)); + EmulatorReadMemory(&EmulatorContext, CurrAddress - i, dmabuf + i, sizeof(BYTE)); } } diff --git a/reactos/subsystems/mvdm/ntvdm/hardware/ps2.c b/reactos/subsystems/mvdm/ntvdm/hardware/ps2.c index df00ac56a84..b52f20fb1e6 100644 --- a/reactos/subsystems/mvdm/ntvdm/hardware/ps2.c +++ b/reactos/subsystems/mvdm/ntvdm/hardware/ps2.c @@ -15,6 +15,7 @@ #include "emulator.h" #include "ps2.h" +#include "memory.h" #include "io.h" #include "pic.h" #include "clock.h" diff --git a/reactos/subsystems/mvdm/ntvdm/io.c b/reactos/subsystems/mvdm/ntvdm/io.c index 775fe939fd0..714d2b429b4 100644 --- a/reactos/subsystems/mvdm/ntvdm/io.c +++ b/reactos/subsystems/mvdm/ntvdm/io.c @@ -343,7 +343,7 @@ VOID UnregisterIoPort(USHORT Port) RtlZeroMemory(&IoPortProc[Port], sizeof(IoPortProc[Port])); } -VOID WINAPI +VOID FASTCALL EmulatorReadIo(PFAST486_STATE State, USHORT Port, PVOID Buffer, @@ -418,7 +418,7 @@ EmulatorReadIo(PFAST486_STATE State, } } -VOID WINAPI +VOID FASTCALL EmulatorWriteIo(PFAST486_STATE State, USHORT Port, PVOID Buffer, diff --git a/reactos/subsystems/mvdm/ntvdm/io.h b/reactos/subsystems/mvdm/ntvdm/io.h index 33f85557cf6..f7a36f24375 100644 --- a/reactos/subsystems/mvdm/ntvdm/io.h +++ b/reactos/subsystems/mvdm/ntvdm/io.h @@ -85,7 +85,7 @@ VOID RegisterIoPort(USHORT Port, VOID UnregisterIoPort(USHORT Port); -VOID WINAPI EmulatorReadIo +VOID FASTCALL EmulatorReadIo ( PFAST486_STATE State, USHORT Port, @@ -94,7 +94,7 @@ VOID WINAPI EmulatorReadIo UCHAR DataSize ); -VOID WINAPI EmulatorWriteIo +VOID FASTCALL EmulatorWriteIo ( PFAST486_STATE State, USHORT Port, diff --git a/reactos/subsystems/mvdm/ntvdm/memory.c b/reactos/subsystems/mvdm/ntvdm/memory.c index 42da010e9a3..49a14eb144a 100644 --- a/reactos/subsystems/mvdm/ntvdm/memory.c +++ b/reactos/subsystems/mvdm/ntvdm/memory.c @@ -36,6 +36,7 @@ typedef struct _MEM_HOOK static LIST_ENTRY HookList; static PMEM_HOOK PageTable[TOTAL_PAGES] = { NULL }; +static BOOLEAN A20Line = FALSE; /* PRIVATE FUNCTIONS **********************************************************/ @@ -137,12 +138,32 @@ WritePage(PMEM_HOOK Hook, ULONG Address, PVOID Buffer, ULONG Size) /* PUBLIC FUNCTIONS ***********************************************************/ -VOID -MemRead(ULONG Address, PVOID Buffer, ULONG Size) +VOID FASTCALL EmulatorReadMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size) { ULONG i, Offset, Length; - ULONG FirstPage = Address >> 12; - ULONG LastPage = (Address + Size - 1) >> 12; + ULONG FirstPage, LastPage; + + UNREFERENCED_PARAMETER(State); + + /* Mirror 0x000FFFF0 at 0xFFFFFFF0 */ + if (Address >= 0xFFFFFFF0) Address -= 0xFFF00000; + + /* If the A20 line is disabled, mask bit 20 */ + if (!A20Line) Address &= ~(1 << 20); + + if ((Address + Size - 1) >= MAX_ADDRESS) + { + ULONG ExtraStart = (Address < MAX_ADDRESS) ? MAX_ADDRESS - Address : 0; + + /* Fill the memory that was above the limit with 0xFF */ + RtlFillMemory((PVOID)((ULONG_PTR)Buffer + ExtraStart), Size - ExtraStart, 0xFF); + + if (Address < MAX_ADDRESS) Size = MAX_ADDRESS - Address; + else return; + } + + FirstPage = Address >> 12; + LastPage = (Address + Size - 1) >> 12; if (FirstPage == LastPage) { @@ -161,12 +182,21 @@ MemRead(ULONG Address, PVOID Buffer, ULONG Size) } } -VOID -MemWrite(ULONG Address, PVOID Buffer, ULONG Size) +VOID FASTCALL EmulatorWriteMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size) { ULONG i, Offset, Length; - ULONG FirstPage = Address >> 12; - ULONG LastPage = (Address + Size - 1) >> 12; + ULONG FirstPage, LastPage; + + UNREFERENCED_PARAMETER(State); + + /* If the A20 line is disabled, mask bit 20 */ + if (!A20Line) Address &= ~(1 << 20); + + if (Address >= MAX_ADDRESS) return; + Size = min(Size, MAX_ADDRESS - Address); + + FirstPage = Address >> 12; + LastPage = (Address + Size - 1) >> 12; if (FirstPage == LastPage) { @@ -185,6 +215,16 @@ MemWrite(ULONG Address, PVOID Buffer, ULONG Size) } } +VOID EmulatorSetA20(BOOLEAN Enabled) +{ + A20Line = Enabled; +} + +BOOLEAN EmulatorGetA20(VOID) +{ + return A20Line; +} + VOID MemExceptionHandler(ULONG FaultAddress, BOOLEAN Writing) { diff --git a/reactos/subsystems/mvdm/ntvdm/memory.h b/reactos/subsystems/mvdm/ntvdm/memory.h index e41a9d16b60..d3a352096ae 100644 --- a/reactos/subsystems/mvdm/ntvdm/memory.h +++ b/reactos/subsystems/mvdm/ntvdm/memory.h @@ -36,21 +36,28 @@ VOID MemCleanup(VOID); VOID MemExceptionHandler(ULONG FaultAddress, BOOLEAN Writing); VOID -MemRead +FASTCALL +EmulatorReadMemory ( + PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size ); VOID -MemWrite +FASTCALL +EmulatorWriteMemory ( + PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size ); +VOID EmulatorSetA20(BOOLEAN Enabled); +BOOLEAN EmulatorGetA20(VOID); + BOOL MemInstallFastMemoryHook (