From cb45ae15fa9b529044d18178ef3214b484bc5ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Thu, 27 Feb 2014 03:05:42 +0000 Subject: [PATCH] [NTVDM] - Add BOP 0x12 "BiosGetMemorySize" (same number as the corresponding INTerrupt). Needed by ntio.sys when initializing (see next commit). - Use ASCII names for bios image and dos kernel files names. - Use the file helper functions committed before for implementing ROM image file loading. svn path=/branches/ntvdm/; revision=62342 --- subsystems/ntvdm/bios/bios.c | 20 +++-- subsystems/ntvdm/bios/bios.h | 11 ++- subsystems/ntvdm/bios/bios32/bios32.c | 9 +- subsystems/ntvdm/bios/rom.c | 122 ++++++++++++-------------- subsystems/ntvdm/bios/rom.h | 17 ++-- 5 files changed, 92 insertions(+), 87 deletions(-) diff --git a/subsystems/ntvdm/bios/bios.c b/subsystems/ntvdm/bios/bios.c index 46d7c6055a1..87d3d031c2a 100644 --- a/subsystems/ntvdm/bios/bios.c +++ b/subsystems/ntvdm/bios/bios.c @@ -12,10 +12,10 @@ #include "emulator.h" #include "callback.h" +#include "bop.h" #include "bios.h" -#include "bop.h" #include "rom.h" /* PRIVATE VARIABLES **********************************************************/ @@ -34,12 +34,12 @@ static CALLBACK16 __BiosContext; static VOID WINAPI BiosInitBop(LPWORD Stack) { /* Load the second part of the Windows NTVDM BIOS image */ - LPCWSTR BiosFileName = L"bios1.rom"; + LPCSTR BiosFileName = "bios1.rom"; PVOID BiosLocation = (PVOID)TO_LINEAR(BIOS_SEGMENT, 0x0000); DWORD BiosSize = 0; BOOLEAN Success; - DPRINT1("You are loading Windows NTVDM BIOS!"); + DPRINT1("You are loading Windows NTVDM BIOS!\n"); /* Initialize a private callback context */ InitializeContext(&__BiosContext, BIOS_SEGMENT, 0x0000); @@ -71,13 +71,13 @@ static VOID WINAPI BiosInitBop(LPWORD Stack) /* Initialize IVT and hardware */ /* Load VGA BIOS */ - // Success = LoadRom(L"v7vga.rom", (PVOID)0xC0000, &BiosSize); + // Success = LoadRom("v7vga.rom", (PVOID)0xC0000, &BiosSize); // DPRINT1("VGA BIOS loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError()); ///////////// MUST BE DONE AFTER IVT INITIALIZATION !! ///////////////////// /* Load some ROMs */ - Success = LoadRom(L"boot.bin", (PVOID)0xE0000, &BiosSize); + Success = LoadRom("boot.bin", (PVOID)0xE0000, &BiosSize); DPRINT1("Test ROM loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError()); SearchAndInitRoms(&__BiosContext); @@ -85,9 +85,10 @@ static VOID WINAPI BiosInitBop(LPWORD Stack) /* PUBLIC FUNCTIONS ***********************************************************/ -BOOLEAN BiosInitialize(IN LPCWSTR BiosFileName, - IN HANDLE ConsoleInput, - IN HANDLE ConsoleOutput) +BOOLEAN +BiosInitialize(IN LPCSTR BiosFileName, + IN HANDLE ConsoleInput, + IN HANDLE ConsoleOutput) { /* Register the BIOS support BOPs */ RegisterBop(BOP_BIOSINIT, BiosInitBop); @@ -148,7 +149,8 @@ BOOLEAN BiosInitialize(IN LPCWSTR BiosFileName, } } -VOID BiosCleanup(VOID) +VOID +BiosCleanup(VOID) { if (Bios32Loaded) Bios32Cleanup(); } diff --git a/subsystems/ntvdm/bios/bios.h b/subsystems/ntvdm/bios/bios.h index e71d899ecff..147a2aff4de 100644 --- a/subsystems/ntvdm/bios/bios.h +++ b/subsystems/ntvdm/bios/bios.h @@ -105,10 +105,13 @@ C_ASSERT(sizeof(BIOS_DATA_AREA) == 0x133); extern PBIOS_DATA_AREA Bda; -BOOLEAN BiosInitialize(IN LPCWSTR BiosFileName, - IN HANDLE ConsoleInput, - IN HANDLE ConsoleOutput); -VOID BiosCleanup(VOID); +BOOLEAN +BiosInitialize(IN LPCSTR BiosFileName, + IN HANDLE ConsoleInput, + IN HANDLE ConsoleOutput); + +VOID +BiosCleanup(VOID); #endif // _BIOS_H_ diff --git a/subsystems/ntvdm/bios/bios32/bios32.c b/subsystems/ntvdm/bios/bios32/bios32.c index d5a84c89d3c..d1922ab7f83 100644 --- a/subsystems/ntvdm/bios/bios32/bios32.c +++ b/subsystems/ntvdm/bios/bios32/bios32.c @@ -12,6 +12,7 @@ #include "emulator.h" #include "callback.h" +#include "bop.h" #include "../rom.h" #include "../bios.h" @@ -27,6 +28,9 @@ CALLBACK16 BiosContext; PBIOS_DATA_AREA Bda; +/* BOP Identifiers */ +#define BOP_GETMEMSIZE 0x12 + /* PRIVATE FUNCTIONS **********************************************************/ static VOID WINAPI BiosException(LPWORD Stack) @@ -347,6 +351,9 @@ static VOID InitializeBiosInt32(VOID) ((PULONG)BaseAddress)[0x46] = (ULONG)NULL; ((PULONG)BaseAddress)[0x48] = (ULONG)NULL; ((PULONG)BaseAddress)[0x49] = (ULONG)NULL; + + /* Register the BIOS support BOPs */ + RegisterBop(BOP_GETMEMSIZE, BiosGetMemorySize); } /* PUBLIC FUNCTIONS ***********************************************************/ @@ -408,7 +415,7 @@ BOOLEAN Bios32Initialize(IN HANDLE ConsoleInput, ///////////// MUST BE DONE AFTER IVT INITIALIZATION !! ///////////////////// /* Load some ROMs */ - Success = LoadRom(L"boot.bin", (PVOID)0xE0000, NULL); + Success = LoadRom("boot.bin", (PVOID)0xE0000, NULL); DPRINT1("Test ROM loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError()); SearchAndInitRoms(&BiosContext); diff --git a/subsystems/ntvdm/bios/rom.c b/subsystems/ntvdm/bios/rom.c index fd11408a293..e4dbc6bf5f6 100644 --- a/subsystems/ntvdm/bios/rom.c +++ b/subsystems/ntvdm/bios/rom.c @@ -12,65 +12,48 @@ #include "emulator.h" #include "callback.h" +#include "utils.h" #include "rom.h" /* PRIVATE FUNCTIONS **********************************************************/ static HANDLE -OpenRomFile(IN LPCWSTR RomFileName, - OUT PDWORD RomSize OPTIONAL) +OpenRomFile(IN PCSTR RomFileName, + OUT PULONG RomSize OPTIONAL) { HANDLE hRomFile; - DWORD dwRomSize; + ULONG ulRomSize = 0; /* Open the ROM image file */ - SetLastError(0); // For debugging purposes - hRomFile = CreateFileW(RomFileName, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); - DPRINT1("ROM opening %s ; GetLastError() = %u\n", hRomFile != INVALID_HANDLE_VALUE ? "succeeded" : "failed", GetLastError()); + hRomFile = FileOpen(RomFileName, &ulRomSize); - /* We failed, bail out */ - if (hRomFile == INVALID_HANDLE_VALUE) return NULL; - - /* OK, we have a handle to the ROM image file */ + /* If we failed, bail out */ + if (hRomFile == NULL) return NULL; /* - * Retrieve the size of the file. - * * The size of the ROM image file is at most 256kB. For instance, * the SeaBIOS image, which includes also expansion ROMs inside it, * covers the range C000:0000 to F000:FFFF . - * - * We therefore can use GetFileSize. */ - dwRomSize = GetFileSize(hRomFile, NULL); - if ( (dwRomSize == INVALID_FILE_SIZE && GetLastError() != ERROR_SUCCESS) || - (dwRomSize > 0x40000) ) + if (ulRomSize > 0x40000) { /* We failed, bail out */ - DPRINT1("Error when retrieving ROM size, or size too large (%d)\n", dwRomSize); - - /* Close the ROM image file */ - CloseHandle(hRomFile); - + DPRINT1("ROM image size 0x%lx too large, expected at most 0x40000 (256kB)", ulRomSize); + FileClose(hRomFile); return NULL; } /* Success, return file handle and size if needed */ - if (RomSize) *RomSize = dwRomSize; + if (RomSize) *RomSize = ulRomSize; return hRomFile; } -static BOOL -LoadRomFileByHandle(IN HANDLE RomFileHandle, - IN PVOID RomLocation, - IN ULONG RomSize) +static BOOLEAN +LoadRomFileByHandle(IN HANDLE RomFileHandle, + IN PVOID RomLocation, + IN ULONG RomSize, + OUT PULONG BytesRead) { /* * The size of the ROM image file is at most 256kB. For instance, @@ -79,17 +62,15 @@ LoadRomFileByHandle(IN HANDLE RomFileHandle, */ if (RomSize > 0x40000) { - DPRINT1("Wrong ROM image size 0x%lx, expected at most 0x40000 (256kB)", RomSize); + DPRINT1("ROM image size 0x%lx too large, expected at most 0x40000 (256kB)", RomSize); return FALSE; } /* Attempt to load the ROM image file into memory */ - SetLastError(0); // For debugging purposes - return ReadFile(RomFileHandle, - REAL_TO_PHYS(RomLocation), - RomSize, - &RomSize, - NULL); + return FileLoadByHandle(RomFileHandle, + REAL_TO_PHYS(RomLocation), + RomSize, + BytesRead); } static UCHAR @@ -159,73 +140,82 @@ InitRomRange(IN PCALLBACK16 Context, /* PUBLIC FUNCTIONS ***********************************************************/ -BOOLEAN LoadBios(IN LPCWSTR BiosFileName, - OUT PVOID* BiosLocation OPTIONAL, - OUT PDWORD BiosSize OPTIONAL) +BOOLEAN +LoadBios(IN PCSTR BiosFileName, + OUT PVOID* BiosLocation OPTIONAL, + OUT PULONG BiosSize OPTIONAL) { - BOOL Success; - HANDLE hBiosFile; - DWORD dwBiosSize = 0; - PVOID pBiosLocation; + BOOLEAN Success; + HANDLE hBiosFile; + ULONG ulBiosSize = 0; + PVOID pBiosLocation; /* Open the BIOS image file */ - hBiosFile = OpenRomFile(BiosFileName, &dwBiosSize); + hBiosFile = OpenRomFile(BiosFileName, &ulBiosSize); /* If we failed, bail out */ if (hBiosFile == NULL) return FALSE; /* BIOS location needs to be aligned on 32-bit boundary */ - // (PVOID)((ULONG_PTR)BaseAddress + ROM_AREA_END + 1 - dwBiosSize) - pBiosLocation = MEM_ALIGN_DOWN(TO_LINEAR(0xF000, 0xFFFF) + 1 - dwBiosSize, sizeof(ULONG)); + // (PVOID)((ULONG_PTR)BaseAddress + ROM_AREA_END + 1 - ulBiosSize) + pBiosLocation = MEM_ALIGN_DOWN(TO_LINEAR(0xF000, 0xFFFF) + 1 - ulBiosSize, sizeof(ULONG)); /* Attempt to load the BIOS image file into memory */ - Success = LoadRomFileByHandle(hBiosFile, pBiosLocation, dwBiosSize); + Success = LoadRomFileByHandle(hBiosFile, + pBiosLocation, + ulBiosSize, + &ulBiosSize); DPRINT1("BIOS loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError()); /* Close the BIOS image file */ - CloseHandle(hBiosFile); + FileClose(hBiosFile); /* In case of success, return BIOS location and size if needed */ if (Success) { if (BiosLocation) *BiosLocation = pBiosLocation; - if (BiosSize) *BiosSize = dwBiosSize; + if (BiosSize) *BiosSize = ulBiosSize; } - return (BOOLEAN)Success; + return Success; } -BOOLEAN LoadRom(IN LPCWSTR RomFileName, - IN PVOID RomLocation, - OUT PDWORD RomSize OPTIONAL) +BOOLEAN +LoadRom(IN PCSTR RomFileName, + IN PVOID RomLocation, + OUT PULONG RomSize OPTIONAL) { - BOOL Success; - HANDLE hRomFile; - DWORD dwRomSize = 0; + BOOLEAN Success; + HANDLE hRomFile; + ULONG ulRomSize = 0; /* Open the ROM image file */ - hRomFile = OpenRomFile(RomFileName, &dwRomSize); + hRomFile = OpenRomFile(RomFileName, &ulRomSize); /* If we failed, bail out */ if (hRomFile == NULL) return FALSE; /* Attempt to load the ROM image file into memory */ - Success = LoadRomFileByHandle(hRomFile, RomLocation, dwRomSize); + Success = LoadRomFileByHandle(hRomFile, + RomLocation, + ulRomSize, + &ulRomSize); DPRINT1("ROM loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError()); /* Close the ROM image file and return */ - CloseHandle(hRomFile); + FileClose(hRomFile); /* In case of success, return ROM size if needed */ if (Success) { - if (RomSize) *RomSize = dwRomSize; + if (RomSize) *RomSize = ulRomSize; } - return (BOOLEAN)Success; + return Success; } -VOID SearchAndInitRoms(IN PCALLBACK16 Context) +VOID +SearchAndInitRoms(IN PCALLBACK16 Context) { /* Adapters ROMs -- Start: C8000, End: E0000, 2kB blocks */ InitRomRange(Context, 0xC8000, 0xE0000, 0x0800); diff --git a/subsystems/ntvdm/bios/rom.h b/subsystems/ntvdm/bios/rom.h index 694f87fd1b9..01f95e85dc8 100644 --- a/subsystems/ntvdm/bios/rom.h +++ b/subsystems/ntvdm/bios/rom.h @@ -22,15 +22,18 @@ /* FUNCTIONS ******************************************************************/ -BOOLEAN LoadBios(IN LPCWSTR BiosFileName, - OUT PVOID* BiosLocation OPTIONAL, - OUT PDWORD BiosSize OPTIONAL); +BOOLEAN +LoadBios(IN PCSTR BiosFileName, + OUT PVOID* BiosLocation OPTIONAL, + OUT PULONG BiosSize OPTIONAL); -BOOLEAN LoadRom(IN LPCWSTR RomFileName, - IN PVOID RomLocation, - OUT PDWORD RomSize OPTIONAL); +BOOLEAN +LoadRom(IN PCSTR RomFileName, + IN PVOID RomLocation, + OUT PULONG RomSize OPTIONAL); -VOID SearchAndInitRoms(IN PCALLBACK16 Context); +VOID +SearchAndInitRoms(IN PCALLBACK16 Context); #endif // _ROM_H_