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.
22 #include <reactos/rossym.h>
29 #include <multiboot.h>
37 LOADER_PARAMETER_BLOCK LoaderBlock
;
38 char reactos_kernel_cmdline
[255]; // Command line passed to kernel
39 LOADER_MODULE reactos_modules
[64]; // Array to hold boot module info loaded for the kernel
40 char reactos_module_strings
[64][256]; // Array to hold module names
41 unsigned long reactos_memory_map_descriptor_size
;
42 memory_map_t reactos_memory_map
[32]; // Memory map
47 FreeldrReadFile(PVOID FileContext
, PVOID Buffer
, ULONG Size
)
51 return FsReadFile((PFILE
) FileContext
, (ULONG
) Size
, &BytesRead
, Buffer
)
56 FreeldrSeekFile(PVOID FileContext
, ULONG_PTR Position
)
58 FsSetFilePointer((PFILE
) FileContext
, (ULONG
) Position
);
63 LoadKernel(PCSTR szSourcePath
, PCSTR szFileName
)
72 if (szSourcePath
[0] != '\\')
74 strcpy(szFullName
, "\\");
75 strcat(szFullName
, szSourcePath
);
79 strcpy(szFullName
, szSourcePath
);
82 if (szFullName
[strlen(szFullName
)] != '\\')
84 strcat(szFullName
, "\\");
87 if (szFileName
[0] != '\\')
89 strcat(szFullName
, szFileName
);
93 strcat(szFullName
, szFileName
+ 1);
96 szShortName
= strrchr(szFileName
, '\\');
97 if (szShortName
== NULL
)
98 szShortName
= szFileName
;
100 szShortName
= szShortName
+ 1;
102 FilePointer
= FsOpenFile(szFullName
);
103 if (FilePointer
== NULL
)
105 printf("Could not find %s\n", szShortName
);
110 * Update the status bar with the current file
113 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
114 UiDrawStatusText(szBuffer
);
116 printf("Reading %s\n", szShortName
);
122 FrLdrMapKernel(FilePointer
);
128 LoadKernelSymbols(PCSTR szSourcePath
, PCSTR szFileName
)
130 static ROSSYM_CALLBACKS FreeldrCallbacks
=
137 CHAR szFullName
[256];
139 PROSSYM_INFO RosSymInfo
;
143 if (szSourcePath
[0] != '\\')
145 strcpy(szFullName
, "\\");
146 strcat(szFullName
, szSourcePath
);
150 strcpy(szFullName
, szSourcePath
);
153 if (szFullName
[strlen(szFullName
)] != '\\')
155 strcat(szFullName
, "\\");
158 if (szFileName
[0] != '\\')
160 strcat(szFullName
, szFileName
);
164 strcat(szFullName
, szFileName
+ 1);
167 RosSymInit(&FreeldrCallbacks
);
169 FilePointer
= FsOpenFile(szFullName
);
170 if (FilePointer
&& RosSymCreateFromFile(FilePointer
, &RosSymInfo
))
172 Base
= FrLdrCreateModule("NTOSKRNL.SYM");
173 Size
= RosSymGetRawDataLength(RosSymInfo
);
174 RosSymGetRawData(RosSymInfo
, (PVOID
)Base
);
175 FrLdrCloseModule(Base
, Size
);
176 RosSymDelete(RosSymInfo
);
183 LoadDriver(PCSTR szSourcePath
, PCSTR szFileName
)
185 CHAR szFullName
[256];
192 if (szSourcePath
[0] != '\\')
194 strcpy(szFullName
, "\\");
195 strcat(szFullName
, szSourcePath
);
199 strcpy(szFullName
, szSourcePath
);
202 if (szFullName
[strlen(szFullName
)] != '\\')
204 strcat(szFullName
, "\\");
207 if (szFileName
[0] != '\\')
209 strcat(szFullName
, szFileName
);
213 strcat(szFullName
, szFileName
+ 1);
216 szShortName
= strrchr(szFileName
, '\\');
217 if (szShortName
== NULL
)
218 szShortName
= szFileName
;
220 szShortName
= szShortName
+ 1;
223 FilePointer
= FsOpenFile(szFullName
);
224 if (FilePointer
== NULL
)
226 printf("Could not find %s\n", szFileName
);
231 * Update the status bar with the current file
234 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
235 UiDrawStatusText(szBuffer
);
237 printf("Reading %s\n", szShortName
);
240 /* Load the driver */
241 FrLdrLoadModule(FilePointer
, szFileName
, NULL
);
248 LoadNlsFile(PCSTR szSourcePath
, PCSTR szFileName
, PCSTR szModuleName
)
250 CHAR szFullName
[256];
257 if (szSourcePath
[0] != '\\')
259 strcpy(szFullName
, "\\");
260 strcat(szFullName
, szSourcePath
);
264 strcpy(szFullName
, szSourcePath
);
267 if (szFullName
[strlen(szFullName
)] != '\\')
269 strcat(szFullName
, "\\");
272 if (szFileName
[0] != '\\')
274 strcat(szFullName
, szFileName
);
278 strcat(szFullName
, szFileName
+ 1);
281 szShortName
= strrchr(szFileName
, '\\');
282 if (szShortName
== NULL
)
283 szShortName
= szFileName
;
285 szShortName
= szShortName
+ 1;
288 FilePointer
= FsOpenFile(szFullName
);
289 if (FilePointer
== NULL
)
291 printf("Could not find %s\n", szFileName
);
296 * Update the status bar with the current file
299 sprintf(szBuffer
, "Setup is loading files (%s)", szShortName
);
300 UiDrawStatusText(szBuffer
);
302 printf("Reading %s\n", szShortName
);
305 /* Load the driver */
306 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
315 const char *SourcePath
;
316 const char *LoadOptions
;
321 INFCONTEXT InfContext
;
323 extern ULONG PageDirectoryStart
;
324 extern ULONG PageDirectoryEnd
;
326 /* Setup multiboot information structure */
327 LoaderBlock
.Flags
= MB_FLAGS_BOOT_DEVICE
| MB_FLAGS_COMMAND_LINE
| MB_FLAGS_MODULE_INFO
;
328 LoaderBlock
.PageDirectoryStart
= (ULONG
)&PageDirectoryStart
;
329 LoaderBlock
.PageDirectoryEnd
= (ULONG
)&PageDirectoryEnd
;
330 LoaderBlock
.BootDevice
= 0xffffffff;
331 LoaderBlock
.CommandLine
= (unsigned long)reactos_kernel_cmdline
;
332 LoaderBlock
.ModsCount
= 0;
333 LoaderBlock
.ModsAddr
= (unsigned long)reactos_modules
;
334 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)(PVOID
)&reactos_memory_map
, 32) * sizeof(memory_map_t
);
335 if (LoaderBlock
.MmapLength
)
337 LoaderBlock
.MmapAddr
= (unsigned long)&reactos_memory_map
;
338 LoaderBlock
.Flags
|= MB_FLAGS_MEM_INFO
| MB_FLAGS_MMAP_INFO
;
339 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
340 for (i
= 0; i
< (LoaderBlock
.MmapLength
/ sizeof(memory_map_t
)); i
++)
342 if (MEMTYPE_USABLE
== reactos_memory_map
[i
].type
&&
343 0 == reactos_memory_map
[i
].base_addr_low
)
345 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
346 if (640 < LoaderBlock
.MemLower
)
348 LoaderBlock
.MemLower
= 640;
351 if (MEMTYPE_USABLE
== reactos_memory_map
[i
].type
&&
352 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
353 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
355 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
358 printf("start: %x\t size: %x\t type %d\n",
359 reactos_memory_map
[i
].base_addr_low
,
360 reactos_memory_map
[i
].length_low
,
361 reactos_memory_map
[i
].type
);
366 printf("low_mem = %d\n", LoaderBlock
.MemLower
);
367 printf("high_mem = %d\n", LoaderBlock
.MemHigher
);
373 UiDrawStatusText("");
376 /* Initialize registry */
377 RegInitializeRegistry();
379 /* Detect hardware */
381 UiDrawStatusText("Detecting hardware...");
383 printf("Detecting hardware...\n\n");
387 UiDrawStatusText("");
390 /* set boot device */
391 MachDiskGetBootDevice(&LoaderBlock
.BootDevice
);
393 /* Open boot drive */
394 if (!FsOpenBootVolume())
397 UiMessageBox("Failed to open boot drive.");
399 printf("Failed to open boot drive.");
404 /* Open 'txtsetup.sif' */
405 if (!InfOpenFile (&InfHandle
,
406 MachDiskBootingFromFloppy() ? "\\txtsetup.sif" : "\\reactos\\txtsetup.sif",
409 printf("Failed to open 'txtsetup.sif'\n");
413 /* Get load options */
414 if (!InfFindFirstLine (InfHandle
,
419 printf("Failed to find 'SetupData/OsLoadOptions'\n");
423 if (!InfGetDataField (&InfContext
,
427 printf("Failed to get load options\n");
431 printf("LoadOptions: '%s'\n", LoadOptions
);
434 if (MachDiskBootingFromFloppy())
436 /* Boot from floppy disk */
441 /* Boot from cdrom */
442 SourcePath
= "\\reactos";
445 /* Set kernel command line */
446 MachDiskGetBootPath(reactos_kernel_cmdline
, sizeof(reactos_kernel_cmdline
));
447 strcat(strcat(strcat(reactos_kernel_cmdline
, SourcePath
), " "),
450 /* Load ntoskrnl.exe */
451 if (!LoadKernel(SourcePath
, "ntoskrnl.exe"))
456 if (!LoadDriver(SourcePath
, "hal.dll"))
459 /* Create ntoskrnl.sym */
460 LoadKernelSymbols(SourcePath
, "ntoskrnl.exe");
462 /* Export the hardware hive */
463 Base
= FrLdrCreateModule ("HARDWARE");
464 RegExportBinaryHive ("\\Registry\\Machine\\HARDWARE", (PVOID
)Base
, &Size
);
465 FrLdrCloseModule (Base
, Size
);
468 printf("Base: %x\n", Base
);
469 printf("Size: %u\n", Size
);
470 printf("*** System stopped ***\n");
474 /* Insert boot disk 2 */
475 if (MachDiskBootingFromFloppy())
478 UiMessageBox("Please insert \"ReactOS Boot Disk 2\" and press ENTER");
480 printf("\n\n Please insert \"ReactOS Boot Disk 2\" and press ENTER\n");
484 /* Open boot drive */
485 if (!FsOpenBootVolume())
488 UiMessageBox("Failed to open boot drive.");
490 printf("Failed to open boot drive.");
495 /* FIXME: check volume label or disk marker file */
499 /* Get ANSI codepage file */
500 if (!InfFindFirstLine (InfHandle
,
505 printf("Failed to find 'NLS/AnsiCodepage'\n");
509 if (!InfGetDataField (&InfContext
,
513 printf("Failed to get load options\n");
517 /* Load ANSI codepage file */
518 if (!LoadNlsFile(SourcePath
, LoadOptions
, "ansi.nls"))
521 UiMessageBox("Failed to load the ANSI codepage file.");
523 printf("Failed to load the ANSI codepage file.");
528 /* Get OEM codepage file */
529 if (!InfFindFirstLine (InfHandle
,
534 printf("Failed to find 'NLS/AnsiCodepage'\n");
538 if (!InfGetDataField (&InfContext
,
542 printf("Failed to get load options\n");
546 /* Load OEM codepage file */
547 if (!LoadNlsFile(SourcePath
, LoadOptions
, "oem.nls"))
550 UiMessageBox("Failed to load the OEM codepage file.");
552 printf("Failed to load the OEM codepage file.");
557 /* Get Unicode Casemap file */
558 if (!InfFindFirstLine (InfHandle
,
563 printf("Failed to find 'NLS/AnsiCodepage'\n");
567 if (!InfGetDataField (&InfContext
,
571 printf("Failed to get load options\n");
575 /* Load Unicode casemap file */
576 if (!LoadNlsFile(SourcePath
, LoadOptions
, "casemap.nls"))
579 UiMessageBox("Failed to load the Unicode casemap file.");
581 printf("Failed to load the Unicode casemap file.");
588 if (!LoadDriver(SourcePath
, "acpi.sys"))
593 /* Load isapnp.sys */
594 if (!LoadDriver(SourcePath
, "isapnp.sys"))
600 if (!LoadDriver(SourcePath
, "pci.sys"))
604 /* Load scsiport.sys */
605 if (!LoadDriver(SourcePath
, "scsiport.sys"))
608 /* Load atapi.sys (depends on hardware detection) */
609 if (!LoadDriver(SourcePath
, "atapi.sys"))
612 /* Load buslogic.sys (depends on hardware detection) */
613 if (!LoadDriver(SourcePath
, "buslogic.sys"))
616 /* Load class2.sys */
617 if (!LoadDriver(SourcePath
, "class2.sys"))
621 if (!LoadDriver(SourcePath
, "cdrom.sys"))
625 if (!LoadDriver(SourcePath
, "cdfs.sys"))
629 if (!LoadDriver(SourcePath
, "disk.sys"))
632 /* Load floppy.sys */
633 if (!LoadDriver(SourcePath
, "floppy.sys"))
636 /* Load vfatfs.sys (could be loaded by the setup prog!) */
637 if (!LoadDriver(SourcePath
, "vfatfs.sys"))
641 /* Load keyboard driver */
643 if (!LoadDriver(SourcePath
, "keyboard.sys"))
646 if (!LoadDriver(SourcePath
, "i8042prt.sys"))
648 if (!LoadDriver(SourcePath
, "kbdclass.sys"))
651 /* Load screen driver */
652 if (!LoadDriver(SourcePath
, "blue.sys"))
656 UiUnInitialize("Booting ReactOS...");
659 /* Now boot the kernel */
660 DiskStopFloppyMotor();
661 MachVideoPrepareForReactOS();
662 FrLdrStartup(0x2badb002);