2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
5 * PURPOSE: VDM BIOS Support Library
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
9 /* INCLUDES *******************************************************************/
18 #include "bios32/bios32.h"
23 #include "hardware/cmos.h"
25 /* DEFINES ********************************************************************/
28 #define BOP_BIOSINIT 0x00 // Windows NTVDM (SoftPC) BIOS calls BOP 0x00
29 // to let the virtual machine initialize itself
30 // the IVT and its hardware.
31 #define BOP_EQUIPLIST 0x11
32 #define BOP_GETMEMSIZE 0x12
34 /* PRIVATE VARIABLES **********************************************************/
36 static BOOLEAN Bios32Loaded
= FALSE
;
38 static CALLBACK16 __BiosContext
;
40 PBIOS_CONFIG_TABLE Bct
;
42 /* PRIVATE FUNCTIONS **********************************************************/
44 static VOID WINAPI
BiosInitBop(LPWORD Stack
)
48 /* Load the second part of the Windows NTVDM BIOS image */
49 LPCSTR BiosFileName
= "bios1.rom";
50 PVOID BiosLocation
= (PVOID
)TO_LINEAR(BIOS_SEGMENT
, 0x0000);
53 /* Disable interrupts */
56 DisplayMessage(L
"You are loading Windows NTVDM BIOS!\n");
58 /* Initialize a private callback context */
59 InitializeContext(&__BiosContext
, BIOS_SEGMENT
, 0x0000);
61 Success
= LoadRom(BiosFileName
, BiosLocation
, &BiosSize
);
62 DPRINT1("BIOS loading %s ; GetLastError() = %u\n", Success
? "succeeded" : "failed", GetLastError());
71 // 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"
72 // L"3 last bytes at 0x%p: 0x%02x 0x%02x 0x%02x",
74 // *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 0),
75 // *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 1),
76 // *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 2),
77 // *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 3),
78 // *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 4),
79 // *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 5),
80 // *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 6),
81 // *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 7),
82 // *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 8),
83 // *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + 9),
85 // (PVOID)((ULONG_PTR)BiosLocation + BiosSize - 2),
86 // *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + BiosSize - 2),
87 // *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + BiosSize - 1),
88 // *(PCHAR)((ULONG_PTR)REAL_TO_PHYS(BiosLocation) + BiosSize - 0));
90 /* Initialize IVT and hardware */
92 /* Initialize the Keyboard and Video BIOS */
93 if (!KbdBiosInitialize() || !VidBiosInitialize())
101 // Success = LoadRom("v7vga.rom", (PVOID)0xC0000, &BiosSize);
102 // DPRINT1("VGA BIOS loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError());
104 /* Enable interrupts */
107 ///////////// MUST BE DONE AFTER IVT INITIALIZATION !! /////////////////////
110 // Success = LoadRom("boot.bin", (PVOID)0xE0000, &BiosSize);
111 // DPRINT1("Test ROM loading %s ; GetLastError() = %u\n", Success ? "succeeded" : "failed", GetLastError());
113 SearchAndInitRoms(&__BiosContext
);
116 /* PUBLIC FUNCTIONS ***********************************************************/
118 VOID WINAPI
BiosEquipmentService(LPWORD Stack
)
120 /* Return the equipment list */
121 setAX(Bda
->EquipmentList
);
124 VOID WINAPI
BiosGetMemorySize(LPWORD Stack
)
126 /* Return the conventional memory size in kB, typically 640 kB */
127 setAX(Bda
->MemorySize
);
131 BiosInitialize(IN LPCSTR BiosFileName
)
133 BOOLEAN Success
= FALSE
;
135 /* Disable interrupts */
138 /* Initialize the BDA and the BCT pointers */
139 Bda
= (PBIOS_DATA_AREA
)SEG_OFF_TO_PTR(BDA_SEGMENT
, 0x0000);
140 // The BCT is found at F000:E6F5 for 100% compatible BIOSes.
141 Bct
= (PBIOS_CONFIG_TABLE
)SEG_OFF_TO_PTR(BIOS_SEGMENT
, 0xE6F5);
143 /* Register the BIOS support BOPs */
144 RegisterBop(BOP_BIOSINIT
, BiosInitBop
);
145 RegisterBop(BOP_EQUIPLIST
, BiosEquipmentService
);
146 RegisterBop(BOP_GETMEMSIZE
, BiosGetMemorySize
);
150 PVOID BiosLocation
= NULL
;
153 Success
= LoadBios(BiosFileName
, &BiosLocation
, &BiosSize
);
154 DPRINT1("BIOS loading %s ; GetLastError() = %u\n", Success
? "succeeded" : "failed", GetLastError());
156 if (!Success
) return FALSE
;
158 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"
159 L
"3 last bytes at 0x%p: 0x%02x 0x%02x 0x%02x",
161 *(PCHAR
)((ULONG_PTR
)REAL_TO_PHYS(BiosLocation
) + 0),
162 *(PCHAR
)((ULONG_PTR
)REAL_TO_PHYS(BiosLocation
) + 1),
163 *(PCHAR
)((ULONG_PTR
)REAL_TO_PHYS(BiosLocation
) + 2),
164 *(PCHAR
)((ULONG_PTR
)REAL_TO_PHYS(BiosLocation
) + 3),
165 *(PCHAR
)((ULONG_PTR
)REAL_TO_PHYS(BiosLocation
) + 4),
166 *(PCHAR
)((ULONG_PTR
)REAL_TO_PHYS(BiosLocation
) + 5),
167 *(PCHAR
)((ULONG_PTR
)REAL_TO_PHYS(BiosLocation
) + 6),
168 *(PCHAR
)((ULONG_PTR
)REAL_TO_PHYS(BiosLocation
) + 7),
169 *(PCHAR
)((ULONG_PTR
)REAL_TO_PHYS(BiosLocation
) + 8),
170 *(PCHAR
)((ULONG_PTR
)REAL_TO_PHYS(BiosLocation
) + 9),
172 (PVOID
)((ULONG_PTR
)BiosLocation
+ BiosSize
- 2),
173 *(PCHAR
)((ULONG_PTR
)REAL_TO_PHYS(BiosLocation
) + BiosSize
- 2),
174 *(PCHAR
)((ULONG_PTR
)REAL_TO_PHYS(BiosLocation
) + BiosSize
- 1),
175 *(PCHAR
)((ULONG_PTR
)REAL_TO_PHYS(BiosLocation
) + BiosSize
- 0));
177 DisplayMessage(L
"POST at 0x%p: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
178 TO_LINEAR(getCS(), getIP()),
179 *(PCHAR
)((ULONG_PTR
)SEG_OFF_TO_PTR(getCS(), getIP()) + 0),
180 *(PCHAR
)((ULONG_PTR
)SEG_OFF_TO_PTR(getCS(), getIP()) + 1),
181 *(PCHAR
)((ULONG_PTR
)SEG_OFF_TO_PTR(getCS(), getIP()) + 2),
182 *(PCHAR
)((ULONG_PTR
)SEG_OFF_TO_PTR(getCS(), getIP()) + 3),
183 *(PCHAR
)((ULONG_PTR
)SEG_OFF_TO_PTR(getCS(), getIP()) + 4));
188 * The CPU is already in reset-mode so that
189 * CS:IP points to F000:FFF0 as required.
191 DisplayMessage(L
"CS=0x%p ; IP=0x%p", getCS(), getIP());
199 Success
= Bios32Loaded
= Bios32Initialize();
202 /* Enable interrupts */
211 if (Bios32Loaded
) Bios32Cleanup();