[NTVDM]: Add a write-protect ROM helper and use it when possible external ROMs are...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 18 Jul 2015 23:46:22 +0000 (23:46 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 18 Jul 2015 23:46:22 +0000 (23:46 +0000)
svn path=/trunk/; revision=68419

reactos/subsystems/mvdm/ntvdm/bios/bios.c
reactos/subsystems/mvdm/ntvdm/bios/rom.c
reactos/subsystems/mvdm/ntvdm/bios/rom.h

index 24bdc17..ccf4aa2 100644 (file)
@@ -12,7 +12,6 @@
 
 #include "ntvdm.h"
 #include "emulator.h"
-#include "memory.h"
 #include "cpu/callback.h"
 #include "cpu/bop.h"
 
@@ -42,12 +41,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 ***********************************************************/
 
 VOID WINAPI BiosEquipmentService(LPWORD Stack)
@@ -82,11 +75,6 @@ BiosInitialize(IN LPCSTR BiosFileName)
     // 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')
     {
         PVOID BiosLocation = NULL;
@@ -138,6 +126,9 @@ BiosInitialize(IN LPCSTR BiosFileName)
     }
     else
     {
+        WriteProtectRom((PVOID)ROM_AREA_START,
+                        ROM_AREA_END - ROM_AREA_START + 1);
+
         Success = Bios32Loaded = Bios32Initialize();
     }
 
index 78f282f..f3ff579 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "ntvdm.h"
 #include "emulator.h"
+#include "memory.h"
 #include "cpu/callback.h"
 #include "rom.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,
             OUT PULONG RomSize OPTIONAL)
@@ -96,7 +103,7 @@ InitRomRange(IN PCALLBACK16 Context,
              IN ULONG End,
              IN ULONG Increment)
 {
-    ULONG Address, AddressBoot;
+    ULONG Address, EntryPoint;
     ULONG RomSize;
     UCHAR Checksum;
 
@@ -120,20 +127,20 @@ InitRomRange(IN PCALLBACK16 Context,
             Checksum = ComputeChecksum(Address, RomSize);
             if (Checksum == 0x00)
             {
-                AddressBoot = Address + 3;
-                DPRINT1("Going to run @ address 0x%p\n", AddressBoot);
+                EntryPoint = Address + 3;
+                DPRINT1("Going to run @ address 0x%p\n", EntryPoint);
 
-                AddressBoot = MAKELONG((AddressBoot & 0xFFFF), (AddressBoot & 0xF0000) >> 4);
+                EntryPoint = MAKELONG((EntryPoint & 0xFFFF), (EntryPoint & 0xF0000) >> 4);
                 // setDS((Address & 0xF0000) >> 4);
                 setDS((Address & 0xFF000) >> 4);
-                RunCallback16(Context, AddressBoot);
-                // Call16((AddressBoot & 0xF0000) >> 4, (AddressBoot & 0xFFFF));
+                RunCallback16(Context, EntryPoint);
+                // Call16((EntryPoint & 0xF0000) >> 4, (EntryPoint & 0xFFFF));
 
-                DPRINT1("Rom @ address 0x%p initialized\n", Address);
+                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);
             }
         }
     }
@@ -141,6 +148,14 @@ InitRomRange(IN PCALLBACK16 Context,
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 
+BOOLEAN
+WriteProtectRom(IN PVOID RomLocation,
+                IN ULONG RomSize)
+{
+    return MemInstallFastMemoryHook(RomLocation, RomSize,
+                                    NULL, ShadowRomWrite);
+}
+
 BOOLEAN
 LoadBios(IN  PCSTR  BiosFileName,
          OUT PVOID* BiosLocation OPTIONAL,
@@ -171,9 +186,14 @@ LoadBios(IN  PCSTR  BiosFileName,
     /* 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 @@ LoadRom(IN  PCSTR  RomFileName,
     /* 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;
     }
 
index 0bda3de..5c74b54 100644 (file)
 
 /* FUNCTIONS ******************************************************************/
 
+BOOLEAN
+WriteProtectRom(IN PVOID RomLocation,
+                IN ULONG RomSize);
+
 BOOLEAN
 LoadBios(IN  PCSTR  BiosFileName,
          OUT PVOID* BiosLocation OPTIONAL,