4 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <multiboot.h>
36 LOADER_PARAMETER_BLOCK LoaderBlock
;
37 char reactos_kernel_cmdline
[255]; // Command line passed to kernel
38 LOADER_MODULE reactos_modules
[64]; // Array to hold boot module info loaded for the kernel
39 char reactos_module_strings
[64][256]; // Array to hold module names
40 unsigned long reactos_memory_map_descriptor_size
;
41 memory_map_t reactos_memory_map
[32]; // Memory map
47 LoadKernel(PCHAR szSourcePath
, PCHAR szFileName
)
56 if (szSourcePath
[0] != '\\')
58 strcpy(szFullName
, "\\");
59 strcat(szFullName
, szSourcePath
);
63 strcpy(szFullName
, szSourcePath
);
66 if (szFullName
[strlen(szFullName
)] != '\\')
68 strcat(szFullName
, "\\");
71 if (szFileName
[0] != '\\')
73 strcat(szFullName
, szFileName
);
77 strcat(szFullName
, szFileName
+ 1);
80 szShortName
= strrchr(szFileName
, '\\');
81 if (szShortName
== NULL
)
82 szShortName
= szFileName
;
84 szShortName
= szShortName
+ 1;
86 FilePointer
= FsOpenFile(szFullName
);
87 if (FilePointer
== NULL
)
89 printf("Could not find %s\n", szShortName
);
94 * Update the status bar with the current file
97 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
98 UiDrawStatusText(szBuffer
);
100 printf("Reading %s\n", szShortName
);
106 FrLdrMapKernel(FilePointer
);
113 LoadDriver(PCHAR szSourcePath
, PCHAR szFileName
)
115 CHAR szFullName
[256];
122 if (szSourcePath
[0] != '\\')
124 strcpy(szFullName
, "\\");
125 strcat(szFullName
, szSourcePath
);
129 strcpy(szFullName
, szSourcePath
);
132 if (szFullName
[strlen(szFullName
)] != '\\')
134 strcat(szFullName
, "\\");
137 if (szFileName
[0] != '\\')
139 strcat(szFullName
, szFileName
);
143 strcat(szFullName
, szFileName
+ 1);
146 szShortName
= strrchr(szFileName
, '\\');
147 if (szShortName
== NULL
)
148 szShortName
= szFileName
;
150 szShortName
= szShortName
+ 1;
153 FilePointer
= FsOpenFile(szFullName
);
154 if (FilePointer
== NULL
)
156 printf("Could not find %s\n", szFileName
);
161 * Update the status bar with the current file
164 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
165 UiDrawStatusText(szBuffer
);
167 printf("Reading %s\n", szShortName
);
170 /* Load the driver */
171 FrLdrLoadModule(FilePointer
, szFileName
, NULL
);
178 LoadNlsFile(PCHAR szSourcePath
, PCHAR szFileName
, PCHAR szModuleName
)
180 CHAR szFullName
[256];
187 if (szSourcePath
[0] != '\\')
189 strcpy(szFullName
, "\\");
190 strcat(szFullName
, szSourcePath
);
194 strcpy(szFullName
, szSourcePath
);
197 if (szFullName
[strlen(szFullName
)] != '\\')
199 strcat(szFullName
, "\\");
202 if (szFileName
[0] != '\\')
204 strcat(szFullName
, szFileName
);
208 strcat(szFullName
, szFileName
+ 1);
211 szShortName
= strrchr(szFileName
, '\\');
212 if (szShortName
== NULL
)
213 szShortName
= szFileName
;
215 szShortName
= szShortName
+ 1;
218 FilePointer
= FsOpenFile(szFullName
);
219 if (FilePointer
== NULL
)
221 printf("Could not find %s\n", szFileName
);
226 * Update the status bar with the current file
229 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
230 UiDrawStatusText(szBuffer
);
232 printf("Reading %s\n", szShortName
);
235 /* Load the driver */
236 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
241 BOOL
SetupUiInitialize(VOID
);
253 INFCONTEXT InfContext
;
255 extern ULONG PageDirectoryStart
;
256 extern ULONG PageDirectoryEnd
;
258 /* Setup multiboot information structure */
259 LoaderBlock
.Flags
= MB_FLAGS_BOOT_DEVICE
| MB_FLAGS_COMMAND_LINE
| MB_FLAGS_MODULE_INFO
;
260 LoaderBlock
.PageDirectoryStart
= (ULONG
)&PageDirectoryStart
;
261 LoaderBlock
.PageDirectoryEnd
= (ULONG
)&PageDirectoryEnd
;
262 LoaderBlock
.BootDevice
= 0xffffffff;
263 LoaderBlock
.CommandLine
= (unsigned long)reactos_kernel_cmdline
;
264 LoaderBlock
.ModsCount
= 0;
265 LoaderBlock
.ModsAddr
= (unsigned long)reactos_modules
;
266 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)(PVOID
)&reactos_memory_map
, 32) * sizeof(memory_map_t
);
267 if (LoaderBlock
.MmapLength
)
269 LoaderBlock
.MmapAddr
= (unsigned long)&reactos_memory_map
;
270 LoaderBlock
.Flags
|= MB_FLAGS_MEM_INFO
| MB_FLAGS_MMAP_INFO
;
271 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
272 for (i
= 0; i
< (LoaderBlock
.MmapLength
/ sizeof(memory_map_t
)); i
++)
274 if (MEMTYPE_USABLE
== reactos_memory_map
[i
].type
&&
275 0 == reactos_memory_map
[i
].base_addr_low
)
277 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
278 if (640 < LoaderBlock
.MemLower
)
280 LoaderBlock
.MemLower
= 640;
283 if (MEMTYPE_USABLE
== reactos_memory_map
[i
].type
&&
284 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
285 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
287 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
290 printf("start: %x\t size: %x\t type %d\n",
291 reactos_memory_map
[i
].base_addr_low
,
292 reactos_memory_map
[i
].length_low
,
293 reactos_memory_map
[i
].type
);
298 printf("low_mem = %d\n", LoaderBlock
.MemLower
);
299 printf("high_mem = %d\n", LoaderBlock
.MemHigher
);
305 UiDrawStatusText("");
308 /* Initialize registry */
309 RegInitializeRegistry();
311 /* Detect hardware */
313 UiDrawStatusText("Detecting hardware...");
315 printf("Detecting hardware...\n\n");
319 UiDrawStatusText("");
322 /* set boot device */
323 MachDiskGetBootDevice(&LoaderBlock
.BootDevice
);
325 /* Open boot drive */
326 if (!FsOpenBootVolume())
329 UiMessageBox("Failed to open boot drive.");
331 printf("Failed to open boot drive.");
336 /* Open 'txtsetup.sif' */
337 if (!InfOpenFile (&InfHandle
,
338 MachDiskBootingFromFloppy() ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif",
341 printf("Failed to open 'txtsetup.sif'\n");
345 /* Get load options */
346 if (!InfFindFirstLine (InfHandle
,
351 printf("Failed to find 'SetupData/OsLoadOptions'\n");
355 if (!InfGetDataField (&InfContext
,
359 printf("Failed to get load options\n");
363 printf("LoadOptions: '%s'\n", LoadOptions
);
366 if (MachDiskBootingFromFloppy())
368 /* Boot from floppy disk */
373 /* Boot from cdrom */
374 SourcePath
= "\\reactos";
377 /* Set kernel command line */
378 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
379 strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
382 /* Load ntoskrnl.exe */
383 if (!LoadKernel(SourcePath
, "ntoskrnl.exe"))
388 if (!LoadDriver(SourcePath
, "hal.dll"))
392 /* Export the hardware hive */
393 Base
= FrLdrCreateModule ("HARDWARE");
394 RegExportBinaryHive ("\\Registry\\Machine\\HARDWARE", (PVOID
)Base
, &Size
);
395 FrLdrCloseModule (Base
, Size
);
398 printf("Base: %x\n", Base
);
399 printf("Size: %u\n", Size
);
400 printf("*** System stopped ***\n");
404 /* Insert boot disk 2 */
405 if (MachDiskBootingFromFloppy())
408 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
410 printf("\n\n Please insert \"ReactOS Boot Disk 2\" and press ENTER\n");
414 /* Open boot drive */
415 if (!FsOpenBootVolume())
418 UiMessageBox("Failed to open boot drive.");
420 printf("Failed to open boot drive.");
425 /* FIXME: check volume label or disk marker file */
429 /* Get ANSI codepage file */
430 if (!InfFindFirstLine (InfHandle
,
435 printf("Failed to find 'NLS/AnsiCodepage'\n");
439 if (!InfGetDataField (&InfContext
,
443 printf("Failed to get load options\n");
447 /* Load ANSI codepage file */
448 if (!LoadNlsFile(SourcePath
, LoadOptions
, "ansi.nls"))
451 UiMessageBox("Failed to load the ANSI codepage file.");
453 printf("Failed to load the ANSI codepage file.");
458 /* Get OEM codepage file */
459 if (!InfFindFirstLine (InfHandle
,
464 printf("Failed to find 'NLS/AnsiCodepage'\n");
468 if (!InfGetDataField (&InfContext
,
472 printf("Failed to get load options\n");
476 /* Load OEM codepage file */
477 if (!LoadNlsFile(SourcePath
, LoadOptions
, "oem.nls"))
480 UiMessageBox("Failed to load the OEM codepage file.");
482 printf("Failed to load the OEM codepage file.");
487 /* Get Unicode Casemap file */
488 if (!InfFindFirstLine (InfHandle
,
493 printf("Failed to find 'NLS/AnsiCodepage'\n");
497 if (!InfGetDataField (&InfContext
,
501 printf("Failed to get load options\n");
505 /* Load Unicode casemap file */
506 if (!LoadNlsFile(SourcePath
, LoadOptions
, "casemap.nls"))
509 UiMessageBox("Failed to load the Unicode casemap file.");
511 printf("Failed to load the Unicode casemap file.");
518 if (!LoadDriver(SourcePath
, "acpi.sys"))
523 /* Load isapnp.sys */
524 if (!LoadDriver(SourcePath
, "isapnp.sys"))
530 if (!LoadDriver(SourcePath
, "pci.sys"))
534 /* Load scsiport.sys */
535 if (!LoadDriver(SourcePath
, "scsiport.sys"))
538 /* Load atapi.sys (depends on hardware detection) */
539 if (!LoadDriver(SourcePath
, "atapi.sys"))
542 /* Load class2.sys */
543 if (!LoadDriver(SourcePath
, "class2.sys"))
547 if (!LoadDriver(SourcePath
, "cdrom.sys"))
551 if (!LoadDriver(SourcePath
, "cdfs.sys"))
555 if (!LoadDriver(SourcePath
, "disk.sys"))
558 /* Load floppy.sys */
559 if (!LoadDriver(SourcePath
, "floppy.sys"))
562 /* Load vfatfs.sys (could be loaded by the setup prog!) */
563 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
567 /* Load keyboard driver */
569 if (!LoadDriver(SourcePath
, "keyboard.sys"))
572 if (!LoadDriver(SourcePath
, "i8042prt.sys"))
574 if (!LoadDriver(SourcePath
, "kbdclass.sys"))
577 /* Load screen driver */
578 if (!LoadDriver(SourcePath
, "blue.sys"))
582 UiUnInitialize("Booting ReactOS...");
585 /* Now boot the kernel */
586 DiskStopFloppyMotor();
587 MachVideoPrepareForReactOS();
588 FrLdrStartup(0x2badb002);