Author: hbelusca
Date: Sat Jul 18 23:46:22 2015
New Revision: 68419
URL:
http://svn.reactos.org/svn/reactos?rev=68419&view=rev
Log:
[NTVDM]: Add a write-protect ROM helper and use it when possible external ROMs are
loaded.
Modified:
trunk/reactos/subsystems/mvdm/ntvdm/bios/bios.c
trunk/reactos/subsystems/mvdm/ntvdm/bios/rom.c
trunk/reactos/subsystems/mvdm/ntvdm/bios/rom.h
Modified: trunk/reactos/subsystems/mvdm/ntvdm/bios/bios.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/bios…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/bios/bios.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/bios/bios.c [iso-8859-1] Sat Jul 18 23:46:22 2015
@@ -12,7 +12,6 @@
#include "ntvdm.h"
#include "emulator.h"
-#include "memory.h"
#include "cpu/callback.h"
#include "cpu/bop.h"
@@ -41,12 +40,6 @@
PBIOS_CONFIG_TABLE Bct;
/* PRIVATE FUNCTIONS **********************************************************/
-
-static BOOLEAN FASTCALL BiosRomWrite(ULONG Address, PVOID Buffer, ULONG Size)
-{
- /* Prevent writing to ROM */
- return FALSE;
-}
/* PUBLIC FUNCTIONS ***********************************************************/
@@ -81,11 +74,6 @@
// /* Register the BIOS support BOPs */
// RegisterBop(BOP_EQUIPLIST , BiosEquipmentService);
// RegisterBop(BOP_GETMEMSIZE, BiosGetMemorySize);
-
- MemInstallFastMemoryHook((PVOID)ROM_AREA_START,
- ROM_AREA_END - ROM_AREA_START + 1,
- NULL,
- BiosRomWrite);
if (BiosFileName && BiosFileName[0] != '\0')
{
@@ -138,6 +126,9 @@
}
else
{
+ WriteProtectRom((PVOID)ROM_AREA_START,
+ ROM_AREA_END - ROM_AREA_START + 1);
+
Success = Bios32Loaded = Bios32Initialize();
}
Modified: trunk/reactos/subsystems/mvdm/ntvdm/bios/rom.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/bios…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/bios/rom.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/bios/rom.c [iso-8859-1] Sat Jul 18 23:46:22 2015
@@ -12,12 +12,19 @@
#include "ntvdm.h"
#include "emulator.h"
+#include "memory.h"
#include "cpu/callback.h"
#include "rom.h"
#include "utils.h"
/* PRIVATE FUNCTIONS **********************************************************/
+
+static BOOLEAN FASTCALL ShadowRomWrite(ULONG Address, PVOID Buffer, ULONG Size)
+{
+ /* Prevent writing to ROM */
+ return FALSE;
+}
static HANDLE
OpenRomFile(IN PCSTR RomFileName,
@@ -96,7 +103,7 @@
IN ULONG End,
IN ULONG Increment)
{
- ULONG Address, AddressBoot;
+ ULONG Address, EntryPoint;
ULONG RomSize;
UCHAR Checksum;
@@ -120,26 +127,34 @@
Checksum = ComputeChecksum(Address, RomSize);
if (Checksum == 0x00)
{
- AddressBoot = Address + 3;
- DPRINT1("Going to run @ address 0x%p\n", AddressBoot);
-
- AddressBoot = MAKELONG((AddressBoot & 0xFFFF), (AddressBoot &
0xF0000) >> 4);
+ EntryPoint = Address + 3;
+ DPRINT1("Going to run @ address 0x%p\n", EntryPoint);
+
+ EntryPoint = MAKELONG((EntryPoint & 0xFFFF), (EntryPoint &
0xF0000) >> 4);
// setDS((Address & 0xF0000) >> 4);
setDS((Address & 0xFF000) >> 4);
- RunCallback16(Context, AddressBoot);
- // Call16((AddressBoot & 0xF0000) >> 4, (AddressBoot &
0xFFFF));
-
- DPRINT1("Rom @ address 0x%p initialized\n", Address);
+ RunCallback16(Context, EntryPoint);
+ // Call16((EntryPoint & 0xF0000) >> 4, (EntryPoint &
0xFFFF));
+
+ DPRINT1("ROM @ address 0x%p initialized\n", Address);
}
else
{
- DPRINT1("Rom @ address 0x%p has invalid checksum of 0x%02x\n",
Address, Checksum);
+ DPRINT1("ROM @ address 0x%p has invalid checksum of 0x%02x\n",
Address, Checksum);
}
}
}
}
/* PUBLIC FUNCTIONS ***********************************************************/
+
+BOOLEAN
+WriteProtectRom(IN PVOID RomLocation,
+ IN ULONG RomSize)
+{
+ return MemInstallFastMemoryHook(RomLocation, RomSize,
+ NULL, ShadowRomWrite);
+}
BOOLEAN
LoadBios(IN PCSTR BiosFileName,
@@ -171,9 +186,14 @@
/* Close the BIOS image file */
FileClose(hBiosFile);
- /* In case of success, return BIOS location and size if needed */
+ /*
+ * In case of success, write-protect the BIOS location
+ * and return the BIOS location and its size if needed.
+ */
if (Success)
{
+ WriteProtectRom(pBiosLocation, ulBiosSize);
+
if (BiosLocation) *BiosLocation = pBiosLocation;
if (BiosSize) *BiosSize = ulBiosSize;
}
@@ -206,9 +226,13 @@
/* Close the ROM image file and return */
FileClose(hRomFile);
- /* In case of success, return ROM size if needed */
+ /*
+ * In case of success, write-protect the ROM location
+ * and return the ROM size if needed.
+ */
if (Success)
{
+ WriteProtectRom(RomLocation, ulRomSize);
if (RomSize) *RomSize = ulRomSize;
}
Modified: trunk/reactos/subsystems/mvdm/ntvdm/bios/rom.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/bios…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/bios/rom.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/bios/rom.h [iso-8859-1] Sat Jul 18 23:46:22 2015
@@ -19,6 +19,10 @@
/* FUNCTIONS ******************************************************************/
BOOLEAN
+WriteProtectRom(IN PVOID RomLocation,
+ IN ULONG RomSize);
+
+BOOLEAN
LoadBios(IN PCSTR BiosFileName,
OUT PVOID* BiosLocation OPTIONAL,
OUT PULONG BiosSize OPTIONAL);