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
;
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");
252 /* Get load options */
253 if (!InfFindFirstLine (InfHandle
,
258 printf("Failed to find 'SetupData/OsLoadOptions'\n");
262 if (!InfGetDataField (&InfContext
,
266 printf("Failed to get load options\n");
270 printf("LoadOptions: '%s'\n", LoadOptions
);
273 if (MachDiskBootingFromFloppy())
275 /* Boot from floppy disk */
280 /* Boot from cdrom */
281 SourcePath
= "\\reactos";
284 /* Set kernel command line */
285 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
286 strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
289 strcpy(SystemRoot
, SourcePath
);
290 strcat(SystemRoot
, "\\");
292 /* Setup the boot path and kernel path */
293 strcpy(szBootPath
, SourcePath
);
294 strcpy(szKernelName
, szBootPath
);
295 strcat(szKernelName
, "\\ntoskrnl.exe");
297 /* Setup the HAL path */
298 strcpy(szHalName
, szBootPath
);
299 strcat(szHalName
, "\\hal.dll");
301 /* Load the kernel */
302 if (!FrLdrLoadKernel(szKernelName
, 5)) return;
304 /* Export the hardware hive */
305 Base
= FrLdrCreateModule ("HARDWARE");
306 RegExportBinaryHive (L
"\\Registry\\Machine\\HARDWARE", (PVOID
)Base
, &Size
);
307 FrLdrCloseModule (Base
, Size
);
310 printf("Base: %x\n", Base
);
311 printf("Size: %u\n", Size
);
312 printf("*** System stopped ***\n");
316 /* Insert boot disk 2 */
317 if (MachDiskBootingFromFloppy())
320 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
322 printf("\n\n Please insert \"ReactOS Boot Disk 2\" and press ENTER\n");
326 /* Open boot drive */
327 if (!FsOpenBootVolume())
330 UiMessageBox("Failed to open boot drive.");
332 printf("Failed to open boot drive.");
337 /* FIXME: check volume label or disk marker file */
341 /* Get ANSI codepage file */
342 if (!InfFindFirstLine (InfHandle
,
347 printf("Failed to find 'NLS/AnsiCodepage'\n");
351 if (!InfGetDataField (&InfContext
,
355 printf("Failed to get load options\n");
359 /* Load ANSI codepage file */
360 if (!LoadNlsFile(SourcePath
, LoadOptions
, "ansi.nls"))
363 UiMessageBox("Failed to load the ANSI codepage file.");
365 printf("Failed to load the ANSI codepage file.");
370 /* Get OEM codepage file */
371 if (!InfFindFirstLine (InfHandle
,
376 printf("Failed to find 'NLS/AnsiCodepage'\n");
380 if (!InfGetDataField (&InfContext
,
384 printf("Failed to get load options\n");
388 /* Load OEM codepage file */
389 if (!LoadNlsFile(SourcePath
, LoadOptions
, "oem.nls"))
392 UiMessageBox("Failed to load the OEM codepage file.");
394 printf("Failed to load the OEM codepage file.");
399 /* Get Unicode Casemap file */
400 if (!InfFindFirstLine (InfHandle
,
405 printf("Failed to find 'NLS/AnsiCodepage'\n");
409 if (!InfGetDataField (&InfContext
,
413 printf("Failed to get load options\n");
417 /* Load Unicode casemap file */
418 if (!LoadNlsFile(SourcePath
, LoadOptions
, "casemap.nls"))
421 UiMessageBox("Failed to load the Unicode casemap file.");
423 printf("Failed to load the Unicode casemap file.");
430 if (!LoadDriver(SourcePath
, "acpi.sys"))
435 /* Load isapnp.sys */
436 if (!LoadDriver(SourcePath
, "isapnp.sys"))
442 if (!LoadDriver(SourcePath
, "pci.sys"))
446 /* Load scsiport.sys */
447 if (!LoadDriver(SourcePath
, "scsiport.sys"))
450 /* Load atapi.sys (depends on hardware detection) */
451 if (!LoadDriver(SourcePath
, "atapi.sys"))
454 /* Load buslogic.sys (depends on hardware detection) */
455 if (!LoadDriver(SourcePath
, "buslogic.sys"))
458 /* Load class2.sys */
459 if (!LoadDriver(SourcePath
, "class2.sys"))
463 if (!LoadDriver(SourcePath
, "cdrom.sys"))
467 if (!LoadDriver(SourcePath
, "cdfs.sys"))
471 if (!LoadDriver(SourcePath
, "disk.sys"))
474 /* Load floppy.sys */
475 if (!LoadDriver(SourcePath
, "floppy.sys"))
478 /* Load vfatfs.sys (could be loaded by the setup prog!) */
479 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
483 /* Load keyboard driver */
485 if (!LoadDriver(SourcePath
, "keyboard.sys"))
488 if (!LoadDriver(SourcePath
, "i8042prt.sys"))
490 if (!LoadDriver(SourcePath
, "kbdclass.sys"))
493 /* Load screen driver */
494 if (!LoadDriver(SourcePath
, "blue.sys"))
498 UiUnInitialize("Booting ReactOS...");
501 /* Now boot the kernel */
502 DiskStopFloppyMotor();
503 MachVideoPrepareForReactOS(TRUE
);
504 FrLdrStartup(0x2badb002);