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 ROS_LOADER_PARAMETER_BLOCK LoaderBlock
;
26 char reactos_kernel_cmdline
[255]; // Command line passed to kernel
27 LOADER_MODULE reactos_modules
[64]; // Array to hold boot module info loaded for the kernel
28 char reactos_module_strings
[64][256]; // Array to hold module names
29 unsigned long reactos_memory_map_descriptor_size
;
30 memory_map_t reactos_memory_map
[32]; // Memory map
34 extern ULONG_PTR KernelBase
, KernelEntry
;
36 extern BOOLEAN
FrLdrLoadDriver(PCHAR szFileName
, INT nPos
);
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
)
96 return FrLdrLoadDriver((PCHAR
)szFileName
, 0);
101 LoadNlsFile(PCSTR szSourcePath
, PCSTR szFileName
, PCSTR szModuleName
)
103 CHAR szFullName
[256];
110 if (szSourcePath
[0] != '\\')
112 strcpy(szFullName
, "\\");
113 strcat(szFullName
, szSourcePath
);
117 strcpy(szFullName
, szSourcePath
);
120 if (szFullName
[strlen(szFullName
)] != '\\')
122 strcat(szFullName
, "\\");
125 if (szFileName
[0] != '\\')
127 strcat(szFullName
, szFileName
);
131 strcat(szFullName
, szFileName
+ 1);
134 szShortName
= strrchr(szFileName
, '\\');
135 if (szShortName
== NULL
)
136 szShortName
= szFileName
;
138 szShortName
= szShortName
+ 1;
141 FilePointer
= FsOpenFile(szFullName
);
142 if (FilePointer
== NULL
)
144 printf("Could not find %s\n", szFileName
);
149 * Update the status bar with the current file
152 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
153 UiDrawStatusText(szBuffer
);
155 printf("Reading %s\n", szShortName
);
158 /* Load the driver */
159 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
168 const char *SourcePath
;
169 const char *LoadOptions
= "", *DbgLoadOptions
= "";
170 char szKernelName
[256];
174 INFCONTEXT InfContext
;
176 /* Setup multiboot information structure */
177 LoaderBlock
.CommandLine
= reactos_kernel_cmdline
;
178 LoaderBlock
.ModsCount
= 0;
179 LoaderBlock
.ModsAddr
= reactos_modules
;
180 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)reactos_memory_map
, 32) * sizeof(memory_map_t
);
181 if (LoaderBlock
.MmapLength
)
185 LoaderBlock
.MmapAddr
= (unsigned long)&reactos_memory_map
;
186 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
187 for (i
=0; i
<(LoaderBlock
.MmapLength
/sizeof(memory_map_t
)); i
++)
189 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
190 0 == reactos_memory_map
[i
].base_addr_low
)
192 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
193 if (640 < LoaderBlock
.MemLower
)
195 LoaderBlock
.MemLower
= 640;
198 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
199 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
200 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
202 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
209 UiDrawStatusText("");
212 extern BOOLEAN FrLdrBootType
;
213 FrLdrBootType
= TRUE
;
215 /* Initialize registry */
216 RegInitializeRegistry();
218 /* Detect hardware */
220 UiDrawStatusText("Detecting hardware...");
222 printf("Detecting hardware...\n\n");
226 UiDrawStatusText("");
229 /* set boot device */
230 MachDiskGetBootDevice(&LoaderBlock
.BootDevice
);
232 /* Open boot drive */
233 if (!FsOpenBootVolume())
236 UiMessageBox("Failed to open boot drive.");
238 printf("Failed to open boot drive.");
243 /* Open 'txtsetup.sif' */
244 if (!InfOpenFile (&InfHandle
,
245 MachDiskBootingFromFloppy() ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif",
248 printf("Failed to open 'txtsetup.sif'\n");
253 /* Get load options */
254 if (InfFindFirstLine (InfHandle
,
259 if (!InfGetDataField (&InfContext
, 1, &DbgLoadOptions
))
263 if (!strlen(DbgLoadOptions
) && !InfFindFirstLine (InfHandle
,
268 printf("Failed to find 'SetupData/OsLoadOptions'\n");
272 if (!InfGetDataField (&InfContext
,
276 printf("Failed to get load options\n");
280 printf("LoadOptions: '%s'\n", LoadOptions
);
283 if (MachDiskBootingFromFloppy())
285 /* Boot from floppy disk */
290 /* Boot from cdrom */
291 SourcePath
= "\\reactos";
294 /* Set kernel command line */
295 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
296 strcat(strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
297 LoadOptions
), DbgLoadOptions
);
299 strcpy(SystemRoot
, SourcePath
);
300 strcat(SystemRoot
, "\\");
302 /* Setup the boot path and kernel path */
303 strcpy(szBootPath
, SourcePath
);
304 strcpy(szKernelName
, szBootPath
);
305 strcat(szKernelName
, "\\ntoskrnl.exe");
307 /* Setup the HAL path */
308 strcpy(szHalName
, szBootPath
);
309 strcat(szHalName
, "\\hal.dll");
311 /* Load the kernel */
312 if (!FrLdrLoadKernel(szKernelName
, 5)) return;
314 /* Export the hardware hive */
315 Base
= FrLdrCreateModule ("HARDWARE");
316 RegExportBinaryHive (L
"\\Registry\\Machine\\HARDWARE", (PVOID
)Base
, &Size
);
317 FrLdrCloseModule (Base
, Size
);
320 printf("Base: %x\n", Base
);
321 printf("Size: %u\n", Size
);
322 printf("*** System stopped ***\n");
326 /* Insert boot disk 2 */
327 if (MachDiskBootingFromFloppy())
330 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
332 printf("\n\n Please insert \"ReactOS Boot Disk 2\" and press ENTER\n");
336 /* Open boot drive */
337 if (!FsOpenBootVolume())
340 UiMessageBox("Failed to open boot drive.");
342 printf("Failed to open boot drive.");
347 /* FIXME: check volume label or disk marker file */
351 /* Get ANSI codepage file */
352 if (!InfFindFirstLine (InfHandle
,
357 printf("Failed to find 'NLS/AnsiCodepage'\n");
361 if (!InfGetDataField (&InfContext
,
365 printf("Failed to get load options\n");
369 /* Load ANSI codepage file */
370 if (!LoadNlsFile(SourcePath
, LoadOptions
, "ansi.nls"))
373 UiMessageBox("Failed to load the ANSI codepage file.");
375 printf("Failed to load the ANSI codepage file.");
380 /* Get OEM codepage file */
381 if (!InfFindFirstLine (InfHandle
,
386 printf("Failed to find 'NLS/AnsiCodepage'\n");
390 if (!InfGetDataField (&InfContext
,
394 printf("Failed to get load options\n");
398 /* Load OEM codepage file */
399 if (!LoadNlsFile(SourcePath
, LoadOptions
, "oem.nls"))
402 UiMessageBox("Failed to load the OEM codepage file.");
404 printf("Failed to load the OEM codepage file.");
409 /* Get Unicode Casemap file */
410 if (!InfFindFirstLine (InfHandle
,
415 printf("Failed to find 'NLS/AnsiCodepage'\n");
419 if (!InfGetDataField (&InfContext
,
423 printf("Failed to get load options\n");
427 /* Load Unicode casemap file */
428 if (!LoadNlsFile(SourcePath
, LoadOptions
, "casemap.nls"))
431 UiMessageBox("Failed to load the Unicode casemap file.");
433 printf("Failed to load the Unicode casemap file.");
440 if (!LoadDriver(SourcePath
, "acpi.sys"))
445 /* Load isapnp.sys */
446 if (!LoadDriver(SourcePath
, "isapnp.sys"))
452 if (!LoadDriver(SourcePath
, "pci.sys"))
456 /* Load scsiport.sys */
457 if (!LoadDriver(SourcePath
, "scsiport.sys"))
460 /* Load atapi.sys (depends on hardware detection) */
461 if (!LoadDriver(SourcePath
, "atapi.sys"))
464 /* Load buslogic.sys (depends on hardware detection) */
465 if (!LoadDriver(SourcePath
, "buslogic.sys"))
468 /* Load class2.sys */
469 if (!LoadDriver(SourcePath
, "class2.sys"))
473 if (!LoadDriver(SourcePath
, "cdrom.sys"))
477 if (!LoadDriver(SourcePath
, "cdfs.sys"))
481 if (!LoadDriver(SourcePath
, "disk.sys"))
484 /* Load floppy.sys */
485 if (!LoadDriver(SourcePath
, "floppy.sys"))
488 /* Load vfatfs.sys (could be loaded by the setup prog!) */
489 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
493 /* Load keyboard driver */
494 if (!LoadDriver(SourcePath
, "i8042prt.sys"))
496 if (!LoadDriver(SourcePath
, "kbdclass.sys"))
499 /* Load screen driver */
500 if (!LoadDriver(SourcePath
, "blue.sys"))
504 UiUnInitialize("Booting ReactOS...");
507 /* Now boot the kernel */
508 DiskStopFloppyMotor();
509 MachVideoPrepareForReactOS(TRUE
);
510 FrLdrStartup(0x2badb002);