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.
23 ROS_LOADER_PARAMETER_BLOCK LoaderBlock
;
24 char reactos_kernel_cmdline
[255]; // Command line passed to kernel
25 LOADER_MODULE reactos_modules
[64]; // Array to hold boot module info loaded for the kernel
26 char reactos_module_strings
[64][256]; // Array to hold module names
27 unsigned long reactos_memory_map_descriptor_size
;
28 memory_map_t reactos_memory_map
[32]; // Memory map
44 static FrLdrLoadKernel(IN PCHAR szFileName
,
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 FrLdrMapImage(FilePointer
, szShortName
, 1);
83 /* Update Processbar and return success */
88 LoadDriver(PCSTR szSourcePath
, PCSTR szFileName
)
97 if (szSourcePath
[0] != '\\')
99 strcpy(szFullName
, "\\");
100 strcat(szFullName
, szSourcePath
);
104 strcpy(szFullName
, szSourcePath
);
107 if (szFullName
[strlen(szFullName
)] != '\\')
109 strcat(szFullName
, "\\");
112 if (szFileName
[0] != '\\')
114 strcat(szFullName
, szFileName
);
118 strcat(szFullName
, szFileName
+ 1);
121 szShortName
= strrchr(szFileName
, '\\');
122 if (szShortName
== NULL
)
123 szShortName
= szFileName
;
125 szShortName
= szShortName
+ 1;
128 FilePointer
= FsOpenFile(szFullName
);
129 if (FilePointer
== NULL
)
131 printf("Could not find %s\n", szFileName
);
136 * Update the status bar with the current file
139 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
140 UiDrawStatusText(szBuffer
);
142 printf("Reading %s\n", szShortName
);
145 /* Load the driver */
146 FrLdrMapImage(FilePointer
, (LPSTR
)szFileName
, 2);
153 LoadNlsFile(PCSTR szSourcePath
, PCSTR szFileName
, PCSTR szModuleName
)
155 CHAR szFullName
[256];
162 if (szSourcePath
[0] != '\\')
164 strcpy(szFullName
, "\\");
165 strcat(szFullName
, szSourcePath
);
169 strcpy(szFullName
, szSourcePath
);
172 if (szFullName
[strlen(szFullName
)] != '\\')
174 strcat(szFullName
, "\\");
177 if (szFileName
[0] != '\\')
179 strcat(szFullName
, szFileName
);
183 strcat(szFullName
, szFileName
+ 1);
186 szShortName
= strrchr(szFileName
, '\\');
187 if (szShortName
== NULL
)
188 szShortName
= szFileName
;
190 szShortName
= szShortName
+ 1;
193 FilePointer
= FsOpenFile(szFullName
);
194 if (FilePointer
== NULL
)
196 printf("Could not find %s\n", szFileName
);
201 * Update the status bar with the current file
204 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
205 UiDrawStatusText(szBuffer
);
207 printf("Reading %s\n", szShortName
);
210 /* Load the driver */
211 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
220 const char *SourcePath
;
221 const char *LoadOptions
;
222 char szKernelName
[256];
226 INFCONTEXT InfContext
;
228 /* Setup multiboot information structure */
229 LoaderBlock
.CommandLine
= reactos_kernel_cmdline
;
230 LoaderBlock
.ModsCount
= 0;
231 LoaderBlock
.ModsAddr
= reactos_modules
;
232 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)(PVOID
)&reactos_memory_map
, 32) * sizeof(memory_map_t
);
233 if (LoaderBlock
.MmapLength
)
237 LoaderBlock
.MmapAddr
= (unsigned long)&reactos_memory_map
;
238 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
239 for (i
=0; i
<(LoaderBlock
.MmapLength
/sizeof(memory_map_t
)); i
++)
241 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
242 0 == reactos_memory_map
[i
].base_addr_low
)
244 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
245 if (640 < LoaderBlock
.MemLower
)
247 LoaderBlock
.MemLower
= 640;
250 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
251 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
252 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
254 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
261 UiDrawStatusText("");
264 extern BOOLEAN FrLdrBootType
;
265 FrLdrBootType
= TRUE
;
267 /* Initialize registry */
268 RegInitializeRegistry();
270 /* Detect hardware */
272 UiDrawStatusText("Detecting hardware...");
274 printf("Detecting hardware...\n\n");
278 UiDrawStatusText("");
281 /* set boot device */
282 MachDiskGetBootDevice(&LoaderBlock
.BootDevice
);
284 /* Open boot drive */
285 if (!FsOpenBootVolume())
288 UiMessageBox("Failed to open boot drive.");
290 printf("Failed to open boot drive.");
295 /* Open 'txtsetup.sif' */
296 if (!InfOpenFile (&InfHandle
,
297 MachDiskBootingFromFloppy() ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif",
300 printf("Failed to open 'txtsetup.sif'\n");
304 /* Get load options */
305 if (!InfFindFirstLine (InfHandle
,
310 printf("Failed to find 'SetupData/OsLoadOptions'\n");
314 if (!InfGetDataField (&InfContext
,
318 printf("Failed to get load options\n");
322 printf("LoadOptions: '%s'\n", LoadOptions
);
325 if (MachDiskBootingFromFloppy())
327 /* Boot from floppy disk */
332 /* Boot from cdrom */
333 SourcePath
= "\\reactos";
336 /* Set kernel command line */
337 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
338 strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
341 /* Setup the boot path and kernel path */
342 strcpy(szBootPath
, SourcePath
);
343 strcpy(szKernelName
, szBootPath
);
344 strcat(szKernelName
, "\\ntoskrnl.exe");
346 /* Setup the HAL path */
347 strcpy(szHalName
, szBootPath
);
348 strcat(szHalName
, "\\hal.dll");
350 /* Load the kernel */
351 if (!FrLdrLoadKernel(szKernelName
, 5)) return;
353 /* Export the hardware hive */
354 Base
= FrLdrCreateModule ("HARDWARE");
355 RegExportBinaryHive (L
"\\Registry\\Machine\\HARDWARE", (PVOID
)Base
, &Size
);
356 FrLdrCloseModule (Base
, Size
);
359 printf("Base: %x\n", Base
);
360 printf("Size: %u\n", Size
);
361 printf("*** System stopped ***\n");
365 /* Insert boot disk 2 */
366 if (MachDiskBootingFromFloppy())
369 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
371 printf("\n\n Please insert \"ReactOS Boot Disk 2\" and press ENTER\n");
375 /* Open boot drive */
376 if (!FsOpenBootVolume())
379 UiMessageBox("Failed to open boot drive.");
381 printf("Failed to open boot drive.");
386 /* FIXME: check volume label or disk marker file */
390 /* Get ANSI codepage file */
391 if (!InfFindFirstLine (InfHandle
,
396 printf("Failed to find 'NLS/AnsiCodepage'\n");
400 if (!InfGetDataField (&InfContext
,
404 printf("Failed to get load options\n");
408 /* Load ANSI codepage file */
409 if (!LoadNlsFile(SourcePath
, LoadOptions
, "ansi.nls"))
412 UiMessageBox("Failed to load the ANSI codepage file.");
414 printf("Failed to load the ANSI codepage file.");
419 /* Get OEM codepage file */
420 if (!InfFindFirstLine (InfHandle
,
425 printf("Failed to find 'NLS/AnsiCodepage'\n");
429 if (!InfGetDataField (&InfContext
,
433 printf("Failed to get load options\n");
437 /* Load OEM codepage file */
438 if (!LoadNlsFile(SourcePath
, LoadOptions
, "oem.nls"))
441 UiMessageBox("Failed to load the OEM codepage file.");
443 printf("Failed to load the OEM codepage file.");
448 /* Get Unicode Casemap file */
449 if (!InfFindFirstLine (InfHandle
,
454 printf("Failed to find 'NLS/AnsiCodepage'\n");
458 if (!InfGetDataField (&InfContext
,
462 printf("Failed to get load options\n");
466 /* Load Unicode casemap file */
467 if (!LoadNlsFile(SourcePath
, LoadOptions
, "casemap.nls"))
470 UiMessageBox("Failed to load the Unicode casemap file.");
472 printf("Failed to load the Unicode casemap file.");
479 if (!LoadDriver(SourcePath
, "acpi.sys"))
484 /* Load isapnp.sys */
485 if (!LoadDriver(SourcePath
, "isapnp.sys"))
491 if (!LoadDriver(SourcePath
, "pci.sys"))
495 /* Load scsiport.sys */
496 if (!LoadDriver(SourcePath
, "scsiport.sys"))
499 /* Load atapi.sys (depends on hardware detection) */
500 if (!LoadDriver(SourcePath
, "atapi.sys"))
503 /* Load buslogic.sys (depends on hardware detection) */
504 if (!LoadDriver(SourcePath
, "buslogic.sys"))
507 /* Load class2.sys */
508 if (!LoadDriver(SourcePath
, "class2.sys"))
512 if (!LoadDriver(SourcePath
, "cdrom.sys"))
516 if (!LoadDriver(SourcePath
, "cdfs.sys"))
520 if (!LoadDriver(SourcePath
, "disk.sys"))
523 /* Load floppy.sys */
524 if (!LoadDriver(SourcePath
, "floppy.sys"))
527 /* Load vfatfs.sys (could be loaded by the setup prog!) */
528 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
532 /* Load keyboard driver */
534 if (!LoadDriver(SourcePath
, "keyboard.sys"))
537 if (!LoadDriver(SourcePath
, "i8042prt.sys"))
539 if (!LoadDriver(SourcePath
, "kbdclass.sys"))
542 /* Load screen driver */
543 if (!LoadDriver(SourcePath
, "blue.sys"))
547 UiUnInitialize("Booting ReactOS...");
550 /* Now boot the kernel */
551 DiskStopFloppyMotor();
552 MachVideoPrepareForReactOS(TRUE
);
553 FrLdrStartup(0x2badb002);