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 const char *sourcePaths
[] = {
174 "", /* Only for floppy boot */
177 #elif defined(_M_MPPC)
179 #elif defined(_M_MRX000)
184 char szKernelName
[256];
188 INFCONTEXT InfContext
;
190 /* Setup multiboot information structure */
191 LoaderBlock
.CommandLine
= reactos_kernel_cmdline
;
192 LoaderBlock
.PageDirectoryStart
= (ULONG
)&PageDirectoryStart
;
193 LoaderBlock
.PageDirectoryEnd
= (ULONG
)&PageDirectoryEnd
;
194 LoaderBlock
.ModsCount
= 0;
195 LoaderBlock
.ModsAddr
= reactos_modules
;
196 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)reactos_memory_map
, 32) * sizeof(memory_map_t
);
197 if (LoaderBlock
.MmapLength
)
201 LoaderBlock
.MmapAddr
= (unsigned long)&reactos_memory_map
;
202 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
203 for (i
=0; i
<(LoaderBlock
.MmapLength
/sizeof(memory_map_t
)); i
++)
205 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
206 0 == reactos_memory_map
[i
].base_addr_low
)
208 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
209 if (640 < LoaderBlock
.MemLower
)
211 LoaderBlock
.MemLower
= 640;
214 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
215 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
216 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
218 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
225 UiDrawStatusText("");
228 extern BOOLEAN FrLdrBootType
;
229 FrLdrBootType
= TRUE
;
231 /* Initialize registry */
232 RegInitializeRegistry();
234 /* Detect hardware */
236 UiDrawStatusText("Detecting hardware...");
238 printf("Detecting hardware...\n\n");
242 UiDrawStatusText("");
245 /* set boot device */
246 MachDiskGetBootDevice(&LoaderBlock
.BootDevice
);
248 /* Open boot drive */
249 if (!FsOpenBootVolume())
252 UiMessageBox("Failed to open boot drive.");
254 printf("Failed to open boot drive.");
259 /* Open 'txtsetup.sif' */
260 for (i
= MachDiskBootingFromFloppy() ? 0 : 1; ; i
++)
262 SourcePath
= sourcePaths
[i
];
265 printf("Failed to open 'txtsetup.sif'\n");
268 strcpy(szKernelName
, SourcePath
);
269 strcat(szKernelName
, "\\txtsetup.sif");
270 if (InfOpenFile (&InfHandle
, szKernelName
, &ErrorLine
))
277 /* Get load options */
278 if (InfFindFirstLine (InfHandle
,
283 if (!InfGetDataField (&InfContext
, 1, &DbgLoadOptions
))
287 if (!strlen(DbgLoadOptions
) && !InfFindFirstLine (InfHandle
,
292 printf("Failed to find 'SetupData/OsLoadOptions'\n");
296 if (!InfGetDataField (&InfContext
,
300 printf("Failed to get load options\n");
304 printf("LoadOptions: '%s'\n", LoadOptions
);
307 /* Set kernel command line */
308 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
309 strcat(strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
310 LoadOptions
), DbgLoadOptions
);
312 strcpy(SystemRoot
, SourcePath
);
313 strcat(SystemRoot
, "\\");
315 /* Setup the boot path and kernel path */
316 strcpy(szBootPath
, SourcePath
);
317 strcpy(szKernelName
, szBootPath
);
318 strcat(szKernelName
, "\\ntoskrnl.exe");
320 /* Setup the HAL path */
321 strcpy(szHalName
, szBootPath
);
322 strcat(szHalName
, "\\hal.dll");
324 /* Load the kernel */
325 if (!FrLdrLoadKernel(szKernelName
, 5)) return;
327 /* Export the hardware hive */
328 Base
= FrLdrCreateModule ("HARDWARE");
329 RegExportBinaryHive (L
"\\Registry\\Machine\\HARDWARE", (PVOID
)Base
, &Size
);
330 FrLdrCloseModule (Base
, Size
);
333 printf("Base: %x\n", Base
);
334 printf("Size: %u\n", Size
);
335 printf("*** System stopped ***\n");
339 /* Insert boot disk 2 */
340 if (MachDiskBootingFromFloppy())
343 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
345 printf("\n\n Please insert \"ReactOS Boot Disk 2\" and press ENTER\n");
349 /* Open boot drive */
350 if (!FsOpenBootVolume())
353 UiMessageBox("Failed to open boot drive.");
355 printf("Failed to open boot drive.");
360 /* FIXME: check volume label or disk marker file */
364 /* Get ANSI codepage file */
365 if (!InfFindFirstLine (InfHandle
,
370 printf("Failed to find 'NLS/AnsiCodepage'\n");
374 if (!InfGetDataField (&InfContext
,
378 printf("Failed to get load options\n");
382 /* Load ANSI codepage file */
383 if (!LoadNlsFile(SourcePath
, LoadOptions
, "ansi.nls"))
386 UiMessageBox("Failed to load the ANSI codepage file.");
388 printf("Failed to load the ANSI codepage file.");
393 /* Get OEM codepage file */
394 if (!InfFindFirstLine (InfHandle
,
399 printf("Failed to find 'NLS/AnsiCodepage'\n");
403 if (!InfGetDataField (&InfContext
,
407 printf("Failed to get load options\n");
411 /* Load OEM codepage file */
412 if (!LoadNlsFile(SourcePath
, LoadOptions
, "oem.nls"))
415 UiMessageBox("Failed to load the OEM codepage file.");
417 printf("Failed to load the OEM codepage file.");
422 /* Get Unicode Casemap file */
423 if (!InfFindFirstLine (InfHandle
,
428 printf("Failed to find 'NLS/AnsiCodepage'\n");
432 if (!InfGetDataField (&InfContext
,
436 printf("Failed to get load options\n");
440 /* Load Unicode casemap file */
441 if (!LoadNlsFile(SourcePath
, LoadOptions
, "casemap.nls"))
444 UiMessageBox("Failed to load the Unicode casemap file.");
446 printf("Failed to load the Unicode casemap file.");
453 if (!LoadDriver(SourcePath
, "acpi.sys"))
458 /* Load isapnp.sys */
459 if (!LoadDriver(SourcePath
, "isapnp.sys"))
465 if (!LoadDriver(SourcePath
, "pci.sys"))
469 /* Load scsiport.sys */
470 if (!LoadDriver(SourcePath
, "scsiport.sys"))
473 /* Load atapi.sys (depends on hardware detection) */
474 if (!LoadDriver(SourcePath
, "atapi.sys"))
477 /* Load buslogic.sys (depends on hardware detection) */
478 if (!LoadDriver(SourcePath
, "buslogic.sys"))
481 /* Load class2.sys */
482 if (!LoadDriver(SourcePath
, "class2.sys"))
486 if (!LoadDriver(SourcePath
, "cdrom.sys"))
490 if (!LoadDriver(SourcePath
, "cdfs.sys"))
494 if (!LoadDriver(SourcePath
, "disk.sys"))
497 /* Load floppy.sys */
498 if (!LoadDriver(SourcePath
, "floppy.sys"))
501 /* Load vfatfs.sys (could be loaded by the setup prog!) */
502 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
506 /* Load keyboard driver */
507 if (!LoadDriver(SourcePath
, "i8042prt.sys"))
509 if (!LoadDriver(SourcePath
, "kbdclass.sys"))
512 /* Load screen driver */
513 if (!LoadDriver(SourcePath
, "blue.sys"))
517 UiUnInitialize("Booting ReactOS...");
520 /* Now boot the kernel */
521 DiskStopFloppyMotor();
522 MachVideoPrepareForReactOS(TRUE
);
523 FrLdrStartup(0x2badb002);