2013-06-17 00:00:36 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: GPL - See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Virtual DOS Machine
|
|
|
|
* FILE: bios.c
|
2014-02-17 22:20:03 +00:00
|
|
|
* PURPOSE: VDM BIOS Support Library
|
|
|
|
* PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
|
2013-06-17 00:00:36 +00:00
|
|
|
*/
|
|
|
|
|
2013-06-26 22:58:41 +00:00
|
|
|
/* INCLUDES *******************************************************************/
|
2013-06-17 00:00:36 +00:00
|
|
|
|
2013-07-22 13:51:26 +00:00
|
|
|
#define NDEBUG
|
|
|
|
|
2014-02-17 22:50:41 +00:00
|
|
|
#include "emulator.h"
|
2014-02-26 01:16:56 +00:00
|
|
|
#include "callback.h"
|
2014-02-27 03:05:42 +00:00
|
|
|
#include "bop.h"
|
2014-02-26 01:16:56 +00:00
|
|
|
|
2013-11-09 22:15:40 +00:00
|
|
|
#include "bios.h"
|
2013-11-09 23:01:11 +00:00
|
|
|
|
2014-02-26 01:16:56 +00:00
|
|
|
#include "rom.h"
|
|
|
|
|
2013-06-26 22:58:41 +00:00
|
|
|
/* PRIVATE VARIABLES **********************************************************/
|
|
|
|
|
2014-02-17 22:20:03 +00:00
|
|
|
static BOOLEAN Bios32Loaded = FALSE;
|
2013-07-15 01:37:38 +00:00
|
|
|
|
2014-02-26 01:16:56 +00:00
|
|
|
static CALLBACK16 __BiosContext;
|
|
|
|
|
|
|
|
/* BOP Identifiers */
|
|
|
|
#define BOP_BIOSINIT 0x00 // Windows NTVDM (SoftPC) BIOS calls BOP 0x00
|
|
|
|
// to let the virtual machine initialize itself
|
|
|
|
// the IVT and its hardware.
|
|
|
|
|
2013-08-05 23:20:25 +00:00
|
|
|
/* PRIVATE FUNCTIONS **********************************************************/
|
2013-06-26 22:58:41 +00:00
|
|
|
|
2014-02-26 01:16:56 +00:00
|
|
|
static VOID WINAPI BiosInitBop(LPWORD Stack)
|
|
|
|
{
|
|
|
|
/* Load the second part of the Windows NTVDM BIOS image */
|
2014-02-27 03:05:42 +00:00
|
|
|
LPCSTR BiosFileName = "bios1.rom";
|
2014-02-26 01:16:56 +00:00
|
|
|
PVOID BiosLocation = (PVOID)TO_LINEAR(BIOS_SEGMENT, 0x0000);
|
|
|
|
DWORD BiosSize = 0;
|
|
|
|
BOOLEAN Success;
|
|
|
|
|
2014-02-27 03:05:42 +00:00
|
|
|
DPRINT1("You are loading Windows NTVDM BIOS!\n");
|
2014-02-26 01:16:56 +00:00
|
|
|
|
|
|
|
/* Initialize a private callback context */
|
|
|
|
InitializeContext(&__BiosContext, BIOS_SEGMENT, 0x0000);
|
|
|
|
|
|
|
|
Success = LoadRom(BiosFileName, BiosLocation, &BiosSize);
|
|
|
|
DPRINT1("BIOS loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError());
|
|
|
|
|
|
|
|
if (Success == FALSE) return;
|
|
|
|
|
|
|
|
// DisplayMessage(L"First bytes at 0x%p: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n"
|
|
|
|
// L"3 last bytes at 0x%p: 0x%02x 0x%02x 0x%02x",
|
|
|
|
// BiosLocation,
|
|
|
|
// *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 0),
|
|
|
|
// *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 1),
|
|
|
|
// *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 2),
|
|
|
|
// *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 3),
|
|
|
|
// *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 4),
|
|
|
|
// *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 5),
|
|
|
|
// *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 6),
|
|
|
|
// *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 7),
|
|
|
|
// *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 8),
|
|
|
|
// *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 9),
|
|
|
|
|
|
|
|
// (PVOID)((ULONG_PTR)BiosLocation + BiosSize - 2),
|
|
|
|
// *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + BiosSize - 2),
|
|
|
|
// *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + BiosSize - 1),
|
|
|
|
// *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + BiosSize - 0));
|
|
|
|
|
|
|
|
/* Initialize IVT and hardware */
|
|
|
|
|
|
|
|
/* Load VGA BIOS */
|
2014-02-27 03:05:42 +00:00
|
|
|
// Success = LoadRom("v7vga.rom", (PVOID)0xC0000, &BiosSize);
|
2014-02-26 01:16:56 +00:00
|
|
|
// DPRINT1("VGA BIOS loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError());
|
|
|
|
|
|
|
|
///////////// MUST BE DONE AFTER IVT INITIALIZATION !! /////////////////////
|
|
|
|
|
|
|
|
/* Load some ROMs */
|
2014-02-27 03:05:42 +00:00
|
|
|
Success = LoadRom("boot.bin", (PVOID)0xE0000, &BiosSize);
|
2014-02-26 01:16:56 +00:00
|
|
|
DPRINT1("Test ROM loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError());
|
|
|
|
|
|
|
|
SearchAndInitRoms(&__BiosContext);
|
|
|
|
}
|
|
|
|
|
2014-01-25 00:21:51 +00:00
|
|
|
/* PUBLIC FUNCTIONS ***********************************************************/
|
2013-07-05 01:31:50 +00:00
|
|
|
|
2014-02-27 03:05:42 +00:00
|
|
|
BOOLEAN
|
2014-03-02 01:45:57 +00:00
|
|
|
BiosInitialize(IN LPCSTR BiosFileName)
|
2013-06-21 00:47:07 +00:00
|
|
|
{
|
2014-02-26 01:16:56 +00:00
|
|
|
/* Register the BIOS support BOPs */
|
|
|
|
RegisterBop(BOP_BIOSINIT, BiosInitBop);
|
|
|
|
|
2014-02-17 22:50:41 +00:00
|
|
|
if (BiosFileName)
|
|
|
|
{
|
2014-02-26 01:16:56 +00:00
|
|
|
PVOID BiosLocation = NULL;
|
|
|
|
DWORD BiosSize = 0;
|
|
|
|
BOOLEAN Success = LoadBios(BiosFileName, &BiosLocation, &BiosSize);
|
2014-02-23 20:40:09 +00:00
|
|
|
|
2014-02-17 22:50:41 +00:00
|
|
|
DPRINT1("BIOS loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError());
|
|
|
|
|
2014-02-26 01:16:56 +00:00
|
|
|
if (Success == FALSE) return FALSE;
|
2014-02-17 22:50:41 +00:00
|
|
|
|
|
|
|
DisplayMessage(L"First bytes at 0x%p: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n"
|
|
|
|
L"3 last bytes at 0x%p: 0x%02x 0x%02x 0x%02x",
|
2014-02-23 20:40:09 +00:00
|
|
|
BiosLocation,
|
|
|
|
*(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 0),
|
|
|
|
*(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 1),
|
|
|
|
*(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 2),
|
|
|
|
*(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 3),
|
|
|
|
*(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 4),
|
|
|
|
*(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 5),
|
|
|
|
*(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 6),
|
|
|
|
*(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 7),
|
|
|
|
*(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 8),
|
|
|
|
*(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 9),
|
|
|
|
|
2014-02-26 01:16:56 +00:00
|
|
|
(PVOID)((ULONG_PTR)BiosLocation + BiosSize - 2),
|
|
|
|
*(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + BiosSize - 2),
|
|
|
|
*(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + BiosSize - 1),
|
|
|
|
*(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + BiosSize - 0));
|
2014-02-17 22:50:41 +00:00
|
|
|
|
|
|
|
DisplayMessage(L"POST at 0x%p: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
|
|
|
|
TO_LINEAR(getCS(), getIP()),
|
|
|
|
*(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(getCS(), getIP()) + 0),
|
|
|
|
*(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(getCS(), getIP()) + 1),
|
|
|
|
*(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(getCS(), getIP()) + 2),
|
|
|
|
*(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(getCS(), getIP()) + 3),
|
|
|
|
*(PCHAR)((ULONG_PTR)SEG_OFF_TO_PTR(getCS(), getIP()) + 4));
|
|
|
|
|
|
|
|
/* Boot it up */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The CPU is already in reset-mode so that
|
|
|
|
* CS:IP points to F000:FFF0 as required.
|
|
|
|
*/
|
|
|
|
DisplayMessage(L"CS=0x%p ; IP=0x%p", getCS(), getIP());
|
|
|
|
// setCS(0xF000);
|
|
|
|
// setIP(0xFFF0);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-02 01:45:57 +00:00
|
|
|
Bios32Loaded = Bios32Initialize();
|
2014-02-17 22:50:41 +00:00
|
|
|
return Bios32Loaded;
|
|
|
|
}
|
2014-01-25 00:21:51 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 03:05:42 +00:00
|
|
|
VOID
|
|
|
|
BiosCleanup(VOID)
|
2014-01-25 00:21:51 +00:00
|
|
|
{
|
2014-02-17 22:20:03 +00:00
|
|
|
if (Bios32Loaded) Bios32Cleanup();
|
2013-06-21 00:47:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-17 00:00:36 +00:00
|
|
|
/* EOF */
|