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.
25 extern ULONG PageDirectoryStart
;
26 extern ULONG PageDirectoryEnd
;
28 ROS_LOADER_PARAMETER_BLOCK LoaderBlock
;
29 char reactos_kernel_cmdline
[255]; // Command line passed to kernel
30 LOADER_MODULE reactos_modules
[64]; // Array to hold boot module info loaded for the kernel
31 char reactos_module_strings
[64][256]; // Array to hold module names
32 unsigned long reactos_memory_map_descriptor_size
;
33 memory_map_t reactos_memory_map
[32]; // Memory map
37 extern ULONG_PTR KernelBase
, KernelEntryPoint
;
39 extern BOOLEAN
FrLdrLoadDriver(PCHAR szFileName
, INT nPos
);
45 static FrLdrLoadKernel(IN PCHAR szFileName
,
52 PIMAGE_NT_HEADERS NtHeader
;
54 /* Extract Kernel filename without path */
55 szShortName
= strrchr(szFileName
, '\\');
58 /* No path, leave it alone */
59 szShortName
= szFileName
;
64 szShortName
= szShortName
+ 1;
68 FilePointer
= FsOpenFile(szFileName
);
71 /* Return failure on the short name */
72 strcpy(szBuffer
, szShortName
);
73 strcat(szBuffer
, " not found.");
74 UiMessageBox(szBuffer
);
78 /* Update the status bar with the current file */
79 strcpy(szBuffer
, "Reading ");
80 strcat(szBuffer
, szShortName
);
81 UiDrawStatusText(szBuffer
);
83 /* Do the actual loading */
84 LoadBase
= FrLdrMapImage(FilePointer
, szShortName
, 1);
86 /* Get the NT header, kernel base and kernel entry */
87 NtHeader
= RtlImageNtHeader(LoadBase
);
88 KernelBase
= NtHeader
->OptionalHeader
.ImageBase
;
89 KernelEntryPoint
= KernelBase
+ NtHeader
->OptionalHeader
.AddressOfEntryPoint
;
90 LoaderBlock
.KernelBase
= KernelBase
;
92 /* Update Processbar and return success */
97 LoadDriver(PCSTR szSourcePath
, PCSTR szFileName
)
99 return FrLdrLoadDriver((PCHAR
)szFileName
, 0);
104 LoadNlsFile(PCSTR szSourcePath
, PCSTR szFileName
, PCSTR szModuleName
)
106 CHAR szFullName
[256];
113 if (szSourcePath
[0] != '\\')
115 strcpy(szFullName
, "\\");
116 strcat(szFullName
, szSourcePath
);
120 strcpy(szFullName
, szSourcePath
);
123 if (szFullName
[strlen(szFullName
)] != '\\')
125 strcat(szFullName
, "\\");
128 if (szFileName
[0] != '\\')
130 strcat(szFullName
, szFileName
);
134 strcat(szFullName
, szFileName
+ 1);
137 szShortName
= strrchr(szFileName
, '\\');
138 if (szShortName
== NULL
)
139 szShortName
= szFileName
;
141 szShortName
= szShortName
+ 1;
144 FilePointer
= FsOpenFile(szFullName
);
145 if (FilePointer
== NULL
)
147 printf("Could not find %s\n", szFileName
);
152 * Update the status bar with the current file
155 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
156 UiDrawStatusText(szBuffer
);
158 printf("Reading %s\n", szShortName
);
161 /* Load the driver */
162 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
171 const char *SourcePath
;
172 const char *LoadOptions
= "", *DbgLoadOptions
= "";
173 char szKernelName
[256];
177 INFCONTEXT InfContext
;
179 /* Setup multiboot information structure */
180 LoaderBlock
.CommandLine
= reactos_kernel_cmdline
;
181 LoaderBlock
.PageDirectoryStart
= (ULONG
)&PageDirectoryStart
;
182 LoaderBlock
.PageDirectoryEnd
= (ULONG
)&PageDirectoryEnd
;
183 LoaderBlock
.ModsCount
= 0;
184 LoaderBlock
.ModsAddr
= reactos_modules
;
185 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)reactos_memory_map
, 32) * sizeof(memory_map_t
);
186 if (LoaderBlock
.MmapLength
)
190 LoaderBlock
.MmapAddr
= (unsigned long)&reactos_memory_map
;
191 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
192 for (i
=0; i
<(LoaderBlock
.MmapLength
/sizeof(memory_map_t
)); i
++)
194 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
195 0 == reactos_memory_map
[i
].base_addr_low
)
197 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
198 if (640 < LoaderBlock
.MemLower
)
200 LoaderBlock
.MemLower
= 640;
203 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
204 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
205 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
207 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
214 UiDrawStatusText("");
217 extern BOOLEAN FrLdrBootType
;
218 FrLdrBootType
= TRUE
;
220 /* Initialize registry */
221 RegInitializeRegistry();
223 /* Detect hardware */
225 UiDrawStatusText("Detecting hardware...");
227 printf("Detecting hardware...\n\n");
231 UiDrawStatusText("");
234 /* set boot device */
235 MachDiskGetBootDevice(&LoaderBlock
.BootDevice
);
237 /* Open boot drive */
238 if (!FsOpenBootVolume())
241 UiMessageBox("Failed to open boot drive.");
243 printf("Failed to open boot drive.");
248 /* Open 'txtsetup.sif' */
249 if (!InfOpenFile (&InfHandle
,
250 MachDiskBootingFromFloppy() ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif",
253 printf("Failed to open 'txtsetup.sif'\n");
258 /* Get load options */
259 if (InfFindFirstLine (InfHandle
,
264 if (!InfGetDataField (&InfContext
, 1, &DbgLoadOptions
))
268 if (!strlen(DbgLoadOptions
) && !InfFindFirstLine (InfHandle
,
273 printf("Failed to find 'SetupData/OsLoadOptions'\n");
277 if (!InfGetDataField (&InfContext
,
281 printf("Failed to get load options\n");
285 printf("LoadOptions: '%s'\n", LoadOptions
);
288 if (MachDiskBootingFromFloppy())
290 /* Boot from floppy disk */
295 /* Boot from cdrom */
296 SourcePath
= "\\reactos";
299 /* Set kernel command line */
300 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
301 strcat(strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
302 LoadOptions
), DbgLoadOptions
);
304 strcpy(SystemRoot
, SourcePath
);
305 strcat(SystemRoot
, "\\");
307 /* Setup the boot path and kernel path */
308 strcpy(szBootPath
, SourcePath
);
309 strcpy(szKernelName
, szBootPath
);
310 strcat(szKernelName
, "\\ntoskrnl.exe");
312 /* Setup the HAL path */
313 strcpy(szHalName
, szBootPath
);
314 strcat(szHalName
, "\\hal.dll");
316 /* Load the kernel */
317 if (!FrLdrLoadKernel(szKernelName
, 5)) return;
319 /* Export the hardware hive */
320 Base
= FrLdrCreateModule ("HARDWARE");
321 RegExportBinaryHive (L
"\\Registry\\Machine\\HARDWARE", (PVOID
)Base
, &Size
);
322 FrLdrCloseModule (Base
, Size
);
325 printf("Base: %x\n", Base
);
326 printf("Size: %u\n", Size
);
327 printf("*** System stopped ***\n");
331 /* Insert boot disk 2 */
332 if (MachDiskBootingFromFloppy())
335 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
337 printf("\n\n Please insert \"ReactOS Boot Disk 2\" and press ENTER\n");
341 /* Open boot drive */
342 if (!FsOpenBootVolume())
345 UiMessageBox("Failed to open boot drive.");
347 printf("Failed to open boot drive.");
352 /* FIXME: check volume label or disk marker file */
356 /* Get ANSI codepage file */
357 if (!InfFindFirstLine (InfHandle
,
362 printf("Failed to find 'NLS/AnsiCodepage'\n");
366 if (!InfGetDataField (&InfContext
,
370 printf("Failed to get load options\n");
374 /* Load ANSI codepage file */
375 if (!LoadNlsFile(SourcePath
, LoadOptions
, "ansi.nls"))
378 UiMessageBox("Failed to load the ANSI codepage file.");
380 printf("Failed to load the ANSI codepage file.");
385 /* Get OEM codepage file */
386 if (!InfFindFirstLine (InfHandle
,
391 printf("Failed to find 'NLS/AnsiCodepage'\n");
395 if (!InfGetDataField (&InfContext
,
399 printf("Failed to get load options\n");
403 /* Load OEM codepage file */
404 if (!LoadNlsFile(SourcePath
, LoadOptions
, "oem.nls"))
407 UiMessageBox("Failed to load the OEM codepage file.");
409 printf("Failed to load the OEM codepage file.");
414 /* Get Unicode Casemap file */
415 if (!InfFindFirstLine (InfHandle
,
420 printf("Failed to find 'NLS/AnsiCodepage'\n");
424 if (!InfGetDataField (&InfContext
,
428 printf("Failed to get load options\n");
432 /* Load Unicode casemap file */
433 if (!LoadNlsFile(SourcePath
, LoadOptions
, "casemap.nls"))
436 UiMessageBox("Failed to load the Unicode casemap file.");
438 printf("Failed to load the Unicode casemap file.");
445 if (!LoadDriver(SourcePath
, "acpi.sys"))
450 /* Load isapnp.sys */
451 if (!LoadDriver(SourcePath
, "isapnp.sys"))
457 if (!LoadDriver(SourcePath
, "pci.sys"))
461 /* Load scsiport.sys */
462 if (!LoadDriver(SourcePath
, "scsiport.sys"))
465 /* Load atapi.sys (depends on hardware detection) */
466 if (!LoadDriver(SourcePath
, "atapi.sys"))
469 /* Load buslogic.sys (depends on hardware detection) */
470 if (!LoadDriver(SourcePath
, "buslogic.sys"))
473 /* Load class2.sys */
474 if (!LoadDriver(SourcePath
, "class2.sys"))
478 if (!LoadDriver(SourcePath
, "cdrom.sys"))
482 if (!LoadDriver(SourcePath
, "cdfs.sys"))
486 if (!LoadDriver(SourcePath
, "disk.sys"))
489 /* Load floppy.sys */
490 if (!LoadDriver(SourcePath
, "floppy.sys"))
493 /* Load vfatfs.sys (could be loaded by the setup prog!) */
494 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
498 /* Load keyboard driver */
499 if (!LoadDriver(SourcePath
, "i8042prt.sys"))
501 if (!LoadDriver(SourcePath
, "kbdclass.sys"))
504 /* Load screen driver */
505 if (!LoadDriver(SourcePath
, "blue.sys"))
509 UiUnInitialize("Booting ReactOS...");
512 /* Now boot the kernel */
513 DiskStopFloppyMotor();
514 MachVideoPrepareForReactOS(TRUE
);
515 FrLdrStartup(0x2badb002);