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 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
33 FreeldrReadFile(PVOID FileContext
, PVOID Buffer
, ULONG Size
)
37 return FsReadFile((PFILE
) FileContext
, (ULONG
) Size
, &BytesRead
, Buffer
)
42 FreeldrSeekFile(PVOID FileContext
, ULONG_PTR Position
)
44 FsSetFilePointer((PFILE
) FileContext
, (ULONG
) Position
);
49 LoadKernel(PCSTR szSourcePath
, PCSTR szFileName
)
58 if (szSourcePath
[0] != '\\')
60 strcpy(szFullName
, "\\");
61 strcat(szFullName
, szSourcePath
);
65 strcpy(szFullName
, szSourcePath
);
68 if (szFullName
[strlen(szFullName
)] != '\\')
70 strcat(szFullName
, "\\");
73 if (szFileName
[0] != '\\')
75 strcat(szFullName
, szFileName
);
79 strcat(szFullName
, szFileName
+ 1);
82 szShortName
= strrchr(szFileName
, '\\');
83 if (szShortName
== NULL
)
84 szShortName
= szFileName
;
86 szShortName
= szShortName
+ 1;
88 FilePointer
= FsOpenFile(szFullName
);
89 if (FilePointer
== NULL
)
91 printf("Could not find %s\n", szShortName
);
96 * Update the status bar with the current file
99 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
100 UiDrawStatusText(szBuffer
);
102 printf("Reading %s\n", szShortName
);
108 FrLdrMapKernel(FilePointer
);
114 LoadKernelSymbols(PCSTR szSourcePath
, PCSTR szFileName
)
116 static ROSSYM_CALLBACKS FreeldrCallbacks
=
123 CHAR szFullName
[256];
125 PROSSYM_INFO RosSymInfo
;
129 if (szSourcePath
[0] != '\\')
131 strcpy(szFullName
, "\\");
132 strcat(szFullName
, szSourcePath
);
136 strcpy(szFullName
, szSourcePath
);
139 if (szFullName
[strlen(szFullName
)] != '\\')
141 strcat(szFullName
, "\\");
144 if (szFileName
[0] != '\\')
146 strcat(szFullName
, szFileName
);
150 strcat(szFullName
, szFileName
+ 1);
153 RosSymInit(&FreeldrCallbacks
);
155 FilePointer
= FsOpenFile(szFullName
);
156 if (FilePointer
&& RosSymCreateFromFile(FilePointer
, &RosSymInfo
))
158 Base
= FrLdrCreateModule("NTOSKRNL.SYM");
159 Size
= RosSymGetRawDataLength(RosSymInfo
);
160 RosSymGetRawData(RosSymInfo
, (PVOID
)Base
);
161 FrLdrCloseModule(Base
, Size
);
162 RosSymDelete(RosSymInfo
);
169 LoadDriver(PCSTR szSourcePath
, PCSTR szFileName
)
171 CHAR szFullName
[256];
178 if (szSourcePath
[0] != '\\')
180 strcpy(szFullName
, "\\");
181 strcat(szFullName
, szSourcePath
);
185 strcpy(szFullName
, szSourcePath
);
188 if (szFullName
[strlen(szFullName
)] != '\\')
190 strcat(szFullName
, "\\");
193 if (szFileName
[0] != '\\')
195 strcat(szFullName
, szFileName
);
199 strcat(szFullName
, szFileName
+ 1);
202 szShortName
= strrchr(szFileName
, '\\');
203 if (szShortName
== NULL
)
204 szShortName
= szFileName
;
206 szShortName
= szShortName
+ 1;
209 FilePointer
= FsOpenFile(szFullName
);
210 if (FilePointer
== NULL
)
212 printf("Could not find %s\n", szFileName
);
217 * Update the status bar with the current file
220 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
221 UiDrawStatusText(szBuffer
);
223 printf("Reading %s\n", szShortName
);
226 /* Load the driver */
227 FrLdrLoadModule(FilePointer
, szFileName
, NULL
);
234 LoadNlsFile(PCSTR szSourcePath
, PCSTR szFileName
, PCSTR szModuleName
)
236 CHAR szFullName
[256];
243 if (szSourcePath
[0] != '\\')
245 strcpy(szFullName
, "\\");
246 strcat(szFullName
, szSourcePath
);
250 strcpy(szFullName
, szSourcePath
);
253 if (szFullName
[strlen(szFullName
)] != '\\')
255 strcat(szFullName
, "\\");
258 if (szFileName
[0] != '\\')
260 strcat(szFullName
, szFileName
);
264 strcat(szFullName
, szFileName
+ 1);
267 szShortName
= strrchr(szFileName
, '\\');
268 if (szShortName
== NULL
)
269 szShortName
= szFileName
;
271 szShortName
= szShortName
+ 1;
274 FilePointer
= FsOpenFile(szFullName
);
275 if (FilePointer
== NULL
)
277 printf("Could not find %s\n", szFileName
);
282 * Update the status bar with the current file
285 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
286 UiDrawStatusText(szBuffer
);
288 printf("Reading %s\n", szShortName
);
291 /* Load the driver */
292 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
301 const char *SourcePath
;
302 const char *LoadOptions
;
307 INFCONTEXT InfContext
;
309 extern ULONG PageDirectoryStart
;
310 extern ULONG PageDirectoryEnd
;
312 /* Setup multiboot information structure */
313 LoaderBlock
.Flags
= MB_FLAGS_BOOT_DEVICE
| MB_FLAGS_COMMAND_LINE
| MB_FLAGS_MODULE_INFO
;
314 LoaderBlock
.PageDirectoryStart
= (ULONG
)&PageDirectoryStart
;
315 LoaderBlock
.PageDirectoryEnd
= (ULONG
)&PageDirectoryEnd
;
316 LoaderBlock
.BootDevice
= 0xffffffff;
317 LoaderBlock
.CommandLine
= (unsigned long)reactos_kernel_cmdline
;
318 LoaderBlock
.ModsCount
= 0;
319 LoaderBlock
.ModsAddr
= (unsigned long)reactos_modules
;
320 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)(PVOID
)&reactos_memory_map
, 32) * sizeof(memory_map_t
);
321 if (LoaderBlock
.MmapLength
)
323 LoaderBlock
.MmapAddr
= (unsigned long)&reactos_memory_map
;
324 LoaderBlock
.Flags
|= MB_FLAGS_MEM_INFO
| MB_FLAGS_MMAP_INFO
;
325 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
326 for (i
= 0; i
< (LoaderBlock
.MmapLength
/ sizeof(memory_map_t
)); i
++)
328 if (MEMTYPE_USABLE
== reactos_memory_map
[i
].type
&&
329 0 == reactos_memory_map
[i
].base_addr_low
)
331 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
332 if (640 < LoaderBlock
.MemLower
)
334 LoaderBlock
.MemLower
= 640;
337 if (MEMTYPE_USABLE
== reactos_memory_map
[i
].type
&&
338 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
339 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
341 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
344 printf("start: %x\t size: %x\t type %d\n",
345 reactos_memory_map
[i
].base_addr_low
,
346 reactos_memory_map
[i
].length_low
,
347 reactos_memory_map
[i
].type
);
352 printf("low_mem = %d\n", LoaderBlock
.MemLower
);
353 printf("high_mem = %d\n", LoaderBlock
.MemHigher
);
359 UiDrawStatusText("");
362 /* Initialize registry */
363 RegInitializeRegistry();
365 /* Detect hardware */
367 UiDrawStatusText("Detecting hardware...");
369 printf("Detecting hardware...\n\n");
373 UiDrawStatusText("");
376 /* set boot device */
377 MachDiskGetBootDevice(&LoaderBlock
.BootDevice
);
379 /* Open boot drive */
380 if (!FsOpenBootVolume())
383 UiMessageBox("Failed to open boot drive.");
385 printf("Failed to open boot drive.");
390 /* Open 'txtsetup.sif' */
391 if (!InfOpenFile (&InfHandle
,
392 MachDiskBootingFromFloppy() ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif",
395 printf("Failed to open 'txtsetup.sif'\n");
399 /* Get load options */
400 if (!InfFindFirstLine (InfHandle
,
405 printf("Failed to find 'SetupData/OsLoadOptions'\n");
409 if (!InfGetDataField (&InfContext
,
413 printf("Failed to get load options\n");
417 printf("LoadOptions: '%s'\n", LoadOptions
);
420 if (MachDiskBootingFromFloppy())
422 /* Boot from floppy disk */
427 /* Boot from cdrom */
428 SourcePath
= "\\reactos";
431 /* Set kernel command line */
432 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
433 strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
436 /* Load ntoskrnl.exe */
437 if (!LoadKernel(SourcePath
, "ntoskrnl.exe"))
442 if (!LoadDriver(SourcePath
, "hal.dll"))
445 /* Create ntoskrnl.sym */
446 LoadKernelSymbols(SourcePath
, "ntoskrnl.exe");
448 /* Export the hardware hive */
449 Base
= FrLdrCreateModule ("HARDWARE");
450 RegExportBinaryHive (L
"\\Registry\\Machine\\HARDWARE", (PVOID
)Base
, &Size
);
451 FrLdrCloseModule (Base
, Size
);
454 printf("Base: %x\n", Base
);
455 printf("Size: %u\n", Size
);
456 printf("*** System stopped ***\n");
460 /* Insert boot disk 2 */
461 if (MachDiskBootingFromFloppy())
464 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
466 printf("\n\n Please insert \"ReactOS Boot Disk 2\" and press ENTER\n");
470 /* Open boot drive */
471 if (!FsOpenBootVolume())
474 UiMessageBox("Failed to open boot drive.");
476 printf("Failed to open boot drive.");
481 /* FIXME: check volume label or disk marker file */
485 /* Get ANSI codepage file */
486 if (!InfFindFirstLine (InfHandle
,
491 printf("Failed to find 'NLS/AnsiCodepage'\n");
495 if (!InfGetDataField (&InfContext
,
499 printf("Failed to get load options\n");
503 /* Load ANSI codepage file */
504 if (!LoadNlsFile(SourcePath
, LoadOptions
, "ansi.nls"))
507 UiMessageBox("Failed to load the ANSI codepage file.");
509 printf("Failed to load the ANSI codepage file.");
514 /* Get OEM codepage file */
515 if (!InfFindFirstLine (InfHandle
,
520 printf("Failed to find 'NLS/AnsiCodepage'\n");
524 if (!InfGetDataField (&InfContext
,
528 printf("Failed to get load options\n");
532 /* Load OEM codepage file */
533 if (!LoadNlsFile(SourcePath
, LoadOptions
, "oem.nls"))
536 UiMessageBox("Failed to load the OEM codepage file.");
538 printf("Failed to load the OEM codepage file.");
543 /* Get Unicode Casemap file */
544 if (!InfFindFirstLine (InfHandle
,
549 printf("Failed to find 'NLS/AnsiCodepage'\n");
553 if (!InfGetDataField (&InfContext
,
557 printf("Failed to get load options\n");
561 /* Load Unicode casemap file */
562 if (!LoadNlsFile(SourcePath
, LoadOptions
, "casemap.nls"))
565 UiMessageBox("Failed to load the Unicode casemap file.");
567 printf("Failed to load the Unicode casemap file.");
574 if (!LoadDriver(SourcePath
, "acpi.sys"))
579 /* Load isapnp.sys */
580 if (!LoadDriver(SourcePath
, "isapnp.sys"))
586 if (!LoadDriver(SourcePath
, "pci.sys"))
590 /* Load scsiport.sys */
591 if (!LoadDriver(SourcePath
, "scsiport.sys"))
594 /* Load atapi.sys (depends on hardware detection) */
595 if (!LoadDriver(SourcePath
, "atapi.sys"))
598 /* Load buslogic.sys (depends on hardware detection) */
599 if (!LoadDriver(SourcePath
, "buslogic.sys"))
602 * Load aic78u2.sys (depends on hardware detection)
604 if (!LoadDriver(SourcePath
, "aic78u2.sys"))
608 * Load trm390w.sys (depends on hardware detection)
610 if (!LoadDriver(SourcePath
, "trm390w.sys"))
614 * Load hpt3xx.sys (depends on hardware detection)
616 if (!LoadDriver(SourcePath
, "hpt3xx.sys"))
620 * Load inia100.sys (depends on hardware detection)
622 if (!LoadDriver(SourcePath
, "inia100.sys"))
626 /* Load class2.sys */
627 if (!LoadDriver(SourcePath
, "class2.sys"))
631 if (!LoadDriver(SourcePath
, "cdrom.sys"))
635 if (!LoadDriver(SourcePath
, "cdfs.sys"))
639 if (!LoadDriver(SourcePath
, "disk.sys"))
642 /* Load floppy.sys */
643 if (!LoadDriver(SourcePath
, "floppy.sys"))
646 /* Load vfatfs.sys (could be loaded by the setup prog!) */
647 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
651 /* Load keyboard driver */
653 if (!LoadDriver(SourcePath
, "keyboard.sys"))
656 if (!LoadDriver(SourcePath
, "i8042prt.sys"))
658 if (!LoadDriver(SourcePath
, "kbdclass.sys"))
661 /* Load screen driver */
662 if (!LoadDriver(SourcePath
, "blue.sys"))
666 UiUnInitialize("Booting ReactOS...");
669 /* Now boot the kernel */
670 DiskStopFloppyMotor();
671 MachVideoPrepareForReactOS();
672 FrLdrStartup(0x2badb002);