ReactOS 0.4.16-dev-297-gc569aee
rom.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ROM_AREA_START   0xE0000
 
#define ROM_AREA_END   0xFFFFF
 
#define OPTION_ROM_SIGNATURE   0xAA55
 

Functions

BOOLEAN WriteProtectRom (IN PVOID RomLocation, IN ULONG RomSize)
 
BOOLEAN WriteUnProtectRom (IN PVOID RomLocation, IN ULONG RomSize)
 
UCHAR CalcRomChecksum (IN ULONG RomLocation, IN ULONG RomSize)
 
BOOLEAN LoadBios (IN PCSTR BiosFileName, OUT PVOID *BiosLocation OPTIONAL, OUT PULONG BiosSize OPTIONAL)
 
BOOLEAN LoadRom (IN PCSTR RomFileName, IN PVOID RomLocation, OUT PULONG RomSize OPTIONAL)
 
VOID SearchAndInitRoms (IN PCALLBACK16 Context)
 

Macro Definition Documentation

◆ OPTION_ROM_SIGNATURE

#define OPTION_ROM_SIGNATURE   0xAA55

Definition at line 17 of file rom.h.

◆ ROM_AREA_END

#define ROM_AREA_END   0xFFFFF

Definition at line 15 of file rom.h.

◆ ROM_AREA_START

#define ROM_AREA_START   0xE0000

Definition at line 14 of file rom.h.

Function Documentation

◆ CalcRomChecksum()

UCHAR CalcRomChecksum ( IN ULONG  RomLocation,
IN ULONG  RomSize 
)

Definition at line 153 of file rom.c.

155{
156 ULONG RomLastAddress = RomLocation + RomSize;
157 UCHAR Sum = 0x00; // Using a UCHAR guarantees that we wrap at 0xFF i.e. we do a sum modulo 0x100.
158
159 while (RomLocation < RomLastAddress)
160 {
161 Sum += *(PUCHAR)REAL_TO_PHYS(RomLocation);
162 ++RomLocation;
163 }
164
165 return Sum;
166}
#define REAL_TO_PHYS(ptr)
Definition: emulator.h:37
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by InitRomRange(), and VidBiosInitialize().

◆ LoadBios()

BOOLEAN LoadBios ( IN PCSTR  BiosFileName,
OUT PVOID *BiosLocation  OPTIONAL,
OUT PULONG BiosSize  OPTIONAL 
)

Definition at line 169 of file rom.c.

172{
174 HANDLE hBiosFile;
175 ULONG ulBiosSize = 0;
176 PVOID pBiosLocation;
177
178 /* Open the BIOS image file */
179 hBiosFile = OpenRomFile(BiosFileName, &ulBiosSize);
180
181 /* If we failed, bail out */
182 if (hBiosFile == NULL) return FALSE;
183
184 /* BIOS location needs to be aligned on 32-bit boundary */
185 // (PVOID)((ULONG_PTR)BaseAddress + ROM_AREA_END + 1 - ulBiosSize)
186 pBiosLocation = MEM_ALIGN_DOWN(TO_LINEAR(0xF000, 0xFFFF) + 1 - ulBiosSize, sizeof(ULONG));
187
188 /* Attempt to load the BIOS image file into memory */
189 Success = LoadRomFileByHandle(hBiosFile,
190 pBiosLocation,
191 ulBiosSize,
192 &ulBiosSize);
193 DPRINT1("BIOS loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError());
194
195 /* Close the BIOS image file */
196 FileClose(hBiosFile);
197
198 /*
199 * In case of success, write-protect the BIOS location
200 * and return the BIOS location and its size if needed.
201 */
202 if (Success)
203 {
204 WriteProtectRom(pBiosLocation, ulBiosSize);
205
206 if (BiosLocation) *BiosLocation = pBiosLocation;
207 if (BiosSize) *BiosSize = ulBiosSize;
208 }
209
210 return Success;
211}
unsigned char BOOLEAN
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define TO_LINEAR(seg, off)
Definition: emulator.h:26
#define MEM_ALIGN_DOWN(ptr, align)
Definition: emulator.h:23
@ Success
Definition: eventcreate.c:712
static HANDLE OpenRomFile(IN PCSTR RomFileName, OUT PULONG RomSize OPTIONAL)
Definition: rom.c:32
BOOLEAN WriteProtectRom(IN PVOID RomLocation, IN ULONG RomSize)
Definition: rom.c:138
static BOOLEAN LoadRomFileByHandle(IN HANDLE RomFileHandle, IN PVOID RomLocation, IN ULONG RomSize, OUT PULONG BytesRead)
Definition: rom.c:63
VOID FileClose(IN HANDLE FileHandle)
Definition: utils.c:21
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by BiosInitialize().

◆ LoadRom()

BOOLEAN LoadRom ( IN PCSTR  RomFileName,
IN PVOID  RomLocation,
OUT PULONG RomSize  OPTIONAL 
)

Definition at line 214 of file rom.c.

217{
219 HANDLE hRomFile;
220 ULONG ulRomSize = 0;
221
222 /* Open the ROM image file */
223 hRomFile = OpenRomFile(RomFileName, &ulRomSize);
224
225 /* If we failed, bail out */
226 if (hRomFile == NULL) return FALSE;
227
228 /* Attempt to load the ROM image file into memory */
229 Success = LoadRomFileByHandle(hRomFile,
230 RomLocation,
231 ulRomSize,
232 &ulRomSize);
233 DPRINT1("ROM loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError());
234
235 /* Close the ROM image file and return */
236 FileClose(hRomFile);
237
238 /*
239 * In case of success, write-protect the ROM location
240 * and return the ROM size if needed.
241 */
242 if (Success)
243 {
244 WriteProtectRom(RomLocation, ulRomSize);
245 if (RomSize) *RomSize = ulRomSize;
246 }
247
248 return Success;
249}

Referenced by BiosInitialize().

◆ SearchAndInitRoms()

VOID SearchAndInitRoms ( IN PCALLBACK16  Context)

Definition at line 252 of file rom.c.

253{
254 /* Video ROMs -- Start: C0000, End: C8000, 2kB blocks */
255 InitRomRange(Context, 0xC0000, 0xC8000, 0x0800);
256
257 /* Adapters ROMs -- Start: C8000, End: E0000, 2kB blocks */
258 InitRomRange(Context, 0xC8000, 0xE0000, 0x0800);
259
260 /* Expansion ROM -- Start: E0000, End: F0000, 64kB block */
261 InitRomRange(Context, 0xE0000, 0xEFFFF, 0x10000);
262}
static VOID InitRomRange(IN PCALLBACK16 Context, IN ULONG Start, IN ULONG End, IN ULONG Increment)
Definition: rom.c:87

Referenced by Bios32Post().

◆ WriteProtectRom()

BOOLEAN WriteProtectRom ( IN PVOID  RomLocation,
IN ULONG  RomSize 
)

Definition at line 138 of file rom.c.

140{
141 return MemInstallFastMemoryHook(RomLocation, RomSize,
143}
static BOOLEAN FASTCALL ShadowRomWrite(ULONG Address, PVOID Buffer, ULONG Size)
Definition: rom.c:25
BOOL MemInstallFastMemoryHook(PVOID Address, ULONG Size, PMEMORY_READ_HANDLER ReadHandler, PMEMORY_WRITE_HANDLER WriteHandler)
Definition: memory.c:299

Referenced by Bios32Initialize(), LoadBios(), LoadRom(), and VidBiosInitialize().

◆ WriteUnProtectRom()

BOOLEAN WriteUnProtectRom ( IN PVOID  RomLocation,
IN ULONG  RomSize 
)

Definition at line 146 of file rom.c.

148{
149 return MemRemoveFastMemoryHook(RomLocation, RomSize);
150}
BOOL MemRemoveFastMemoryHook(PVOID Address, ULONG Size)
Definition: memory.c:353