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.
27 ROS_LOADER_PARAMETER_BLOCK LoaderBlock
;
28 char reactos_kernel_cmdline
[255]; // Command line passed to kernel
29 LOADER_MODULE reactos_modules
[64]; // Array to hold boot module info loaded for the kernel
30 char reactos_module_strings
[64][256]; // Array to hold module names
31 unsigned long reactos_memory_map_descriptor_size
;
32 memory_map_t reactos_memory_map
[32]; // Memory map
35 extern ULONG_PTR KernelBase
, KernelEntry
;
42 static FrLdrLoadKernel(IN PCHAR szFileName
,
49 PIMAGE_NT_HEADERS NtHeader
;
51 /* Extract Kernel filename without path */
52 szShortName
= strrchr(szFileName
, '\\');
55 /* No path, leave it alone */
56 szShortName
= szFileName
;
61 szShortName
= szShortName
+ 1;
65 FilePointer
= FsOpenFile(szFileName
);
68 /* Return failure on the short name */
69 strcpy(szBuffer
, szShortName
);
70 strcat(szBuffer
, " not found.");
71 UiMessageBox(szBuffer
);
75 /* Update the status bar with the current file */
76 strcpy(szBuffer
, "Reading ");
77 strcat(szBuffer
, szShortName
);
78 UiDrawStatusText(szBuffer
);
80 /* Do the actual loading */
81 LoadBase
= FrLdrMapImage(FilePointer
, szShortName
, 1);
83 /* Get the NT header, kernel base and kernel entry */
84 NtHeader
= RtlImageNtHeader(LoadBase
);
85 KernelBase
= NtHeader
->OptionalHeader
.ImageBase
;
86 KernelEntry
= RaToPa(NtHeader
->OptionalHeader
.AddressOfEntryPoint
);
87 LoaderBlock
.KernelBase
= KernelBase
;
89 /* Update Processbar and return success */
94 LoadDriver(PCSTR szSourcePath
, PCSTR szFileName
)
103 if (szSourcePath
[0] != '\\')
105 strcpy(szFullName
, "\\");
106 strcat(szFullName
, szSourcePath
);
110 strcpy(szFullName
, szSourcePath
);
113 if (szFullName
[strlen(szFullName
)] != '\\')
115 strcat(szFullName
, "\\");
118 if (szFileName
[0] != '\\')
120 strcat(szFullName
, szFileName
);
124 strcat(szFullName
, szFileName
+ 1);
127 szShortName
= strrchr(szFileName
, '\\');
128 if (szShortName
== NULL
)
129 szShortName
= szFileName
;
131 szShortName
= szShortName
+ 1;
134 FilePointer
= FsOpenFile(szFullName
);
135 if (FilePointer
== NULL
)
137 printf("Could not find %s\n", szFileName
);
142 * Update the status bar with the current file
145 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
146 UiDrawStatusText(szBuffer
);
148 printf("Reading %s\n", szShortName
);
151 /* Load the driver */
152 FrLdrMapImage(FilePointer
, (LPSTR
)szFileName
, 2);
159 LoadNlsFile(PCSTR szSourcePath
, PCSTR szFileName
, PCSTR szModuleName
)
161 CHAR szFullName
[256];
168 if (szSourcePath
[0] != '\\')
170 strcpy(szFullName
, "\\");
171 strcat(szFullName
, szSourcePath
);
175 strcpy(szFullName
, szSourcePath
);
178 if (szFullName
[strlen(szFullName
)] != '\\')
180 strcat(szFullName
, "\\");
183 if (szFileName
[0] != '\\')
185 strcat(szFullName
, szFileName
);
189 strcat(szFullName
, szFileName
+ 1);
192 szShortName
= strrchr(szFileName
, '\\');
193 if (szShortName
== NULL
)
194 szShortName
= szFileName
;
196 szShortName
= szShortName
+ 1;
199 FilePointer
= FsOpenFile(szFullName
);
200 if (FilePointer
== NULL
)
202 printf("Could not find %s\n", szFileName
);
207 * Update the status bar with the current file
210 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
211 UiDrawStatusText(szBuffer
);
213 printf("Reading %s\n", szShortName
);
216 /* Load the driver */
217 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
226 const char *SourcePath
;
227 const char *LoadOptions
;
228 char szKernelName
[256];
232 INFCONTEXT InfContext
;
234 /* Setup multiboot information structure */
235 LoaderBlock
.CommandLine
= reactos_kernel_cmdline
;
236 LoaderBlock
.ModsCount
= 0;
237 LoaderBlock
.ModsAddr
= reactos_modules
;
238 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)(PVOID
)&reactos_memory_map
, 32) * sizeof(memory_map_t
);
239 if (LoaderBlock
.MmapLength
)
243 LoaderBlock
.MmapAddr
= (unsigned long)&reactos_memory_map
;
244 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
245 for (i
=0; i
<(LoaderBlock
.MmapLength
/sizeof(memory_map_t
)); i
++)
247 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
248 0 == reactos_memory_map
[i
].base_addr_low
)
250 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
251 if (640 < LoaderBlock
.MemLower
)
253 LoaderBlock
.MemLower
= 640;
256 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
257 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
258 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
260 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
267 UiDrawStatusText("");
270 extern BOOLEAN FrLdrBootType
;
271 FrLdrBootType
= TRUE
;
273 /* Initialize registry */
274 RegInitializeRegistry();
276 /* Detect hardware */
278 UiDrawStatusText("Detecting hardware...");
280 printf("Detecting hardware...\n\n");
284 UiDrawStatusText("");
287 /* set boot device */
288 MachDiskGetBootDevice(&LoaderBlock
.BootDevice
);
290 /* Open boot drive */
291 if (!FsOpenBootVolume())
294 UiMessageBox("Failed to open boot drive.");
296 printf("Failed to open boot drive.");
301 /* Open 'txtsetup.sif' */
302 if (!InfOpenFile (&InfHandle
,
303 MachDiskBootingFromFloppy() ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif",
306 printf("Failed to open 'txtsetup.sif'\n");
310 /* Get load options */
311 if (!InfFindFirstLine (InfHandle
,
316 printf("Failed to find 'SetupData/OsLoadOptions'\n");
320 if (!InfGetDataField (&InfContext
,
324 printf("Failed to get load options\n");
328 printf("LoadOptions: '%s'\n", LoadOptions
);
331 if (MachDiskBootingFromFloppy())
333 /* Boot from floppy disk */
338 /* Boot from cdrom */
339 SourcePath
= "\\reactos";
342 /* Set kernel command line */
343 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
344 strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
347 /* Setup the boot path and kernel path */
348 strcpy(szBootPath
, SourcePath
);
349 strcpy(szKernelName
, szBootPath
);
350 strcat(szKernelName
, "\\ntoskrnl.exe");
352 /* Setup the HAL path */
353 strcpy(szHalName
, szBootPath
);
354 strcat(szHalName
, "\\hal.dll");
356 /* Load the kernel */
357 if (!FrLdrLoadKernel(szKernelName
, 5)) return;
359 /* Export the hardware hive */
360 Base
= FrLdrCreateModule ("HARDWARE");
361 RegExportBinaryHive (L
"\\Registry\\Machine\\HARDWARE", (PVOID
)Base
, &Size
);
362 FrLdrCloseModule (Base
, Size
);
365 printf("Base: %x\n", Base
);
366 printf("Size: %u\n", Size
);
367 printf("*** System stopped ***\n");
371 /* Insert boot disk 2 */
372 if (MachDiskBootingFromFloppy())
375 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
377 printf("\n\n Please insert \"ReactOS Boot Disk 2\" and press ENTER\n");
381 /* Open boot drive */
382 if (!FsOpenBootVolume())
385 UiMessageBox("Failed to open boot drive.");
387 printf("Failed to open boot drive.");
392 /* FIXME: check volume label or disk marker file */
396 /* Get ANSI codepage file */
397 if (!InfFindFirstLine (InfHandle
,
402 printf("Failed to find 'NLS/AnsiCodepage'\n");
406 if (!InfGetDataField (&InfContext
,
410 printf("Failed to get load options\n");
414 /* Load ANSI codepage file */
415 if (!LoadNlsFile(SourcePath
, LoadOptions
, "ansi.nls"))
418 UiMessageBox("Failed to load the ANSI codepage file.");
420 printf("Failed to load the ANSI codepage file.");
425 /* Get OEM codepage file */
426 if (!InfFindFirstLine (InfHandle
,
431 printf("Failed to find 'NLS/AnsiCodepage'\n");
435 if (!InfGetDataField (&InfContext
,
439 printf("Failed to get load options\n");
443 /* Load OEM codepage file */
444 if (!LoadNlsFile(SourcePath
, LoadOptions
, "oem.nls"))
447 UiMessageBox("Failed to load the OEM codepage file.");
449 printf("Failed to load the OEM codepage file.");
454 /* Get Unicode Casemap file */
455 if (!InfFindFirstLine (InfHandle
,
460 printf("Failed to find 'NLS/AnsiCodepage'\n");
464 if (!InfGetDataField (&InfContext
,
468 printf("Failed to get load options\n");
472 /* Load Unicode casemap file */
473 if (!LoadNlsFile(SourcePath
, LoadOptions
, "casemap.nls"))
476 UiMessageBox("Failed to load the Unicode casemap file.");
478 printf("Failed to load the Unicode casemap file.");
485 if (!LoadDriver(SourcePath
, "acpi.sys"))
490 /* Load isapnp.sys */
491 if (!LoadDriver(SourcePath
, "isapnp.sys"))
497 if (!LoadDriver(SourcePath
, "pci.sys"))
501 /* Load scsiport.sys */
502 if (!LoadDriver(SourcePath
, "scsiport.sys"))
505 /* Load atapi.sys (depends on hardware detection) */
506 if (!LoadDriver(SourcePath
, "atapi.sys"))
509 /* Load buslogic.sys (depends on hardware detection) */
510 if (!LoadDriver(SourcePath
, "buslogic.sys"))
513 /* Load class2.sys */
514 if (!LoadDriver(SourcePath
, "class2.sys"))
518 if (!LoadDriver(SourcePath
, "cdrom.sys"))
522 if (!LoadDriver(SourcePath
, "cdfs.sys"))
526 if (!LoadDriver(SourcePath
, "disk.sys"))
529 /* Load floppy.sys */
530 if (!LoadDriver(SourcePath
, "floppy.sys"))
533 /* Load vfatfs.sys (could be loaded by the setup prog!) */
534 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
538 /* Load keyboard driver */
540 if (!LoadDriver(SourcePath
, "keyboard.sys"))
543 if (!LoadDriver(SourcePath
, "i8042prt.sys"))
545 if (!LoadDriver(SourcePath
, "kbdclass.sys"))
548 /* Load screen driver */
549 if (!LoadDriver(SourcePath
, "blue.sys"))
553 UiUnInitialize("Booting ReactOS...");
556 /* Now boot the kernel */
557 DiskStopFloppyMotor();
558 MachVideoPrepareForReactOS(TRUE
);
559 FrLdrStartup(0x2badb002);