4 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
5 * Copyright (C) 2005 Alex Ionescu <alex@relsoft.net>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 ROS_LOADER_PARAMETER_BLOCK LoaderBlock
;
28 char reactos_kernel_cmdline
[255]; // Command line passed to kernel
29 LOADER_MODULE reactos_modules
[64]; // Array to hold boot module info loaded for the kernel
30 char reactos_module_strings
[64][256]; // Array to hold module names
31 unsigned long reactos_memory_map_descriptor_size
;
32 memory_map_t reactos_memory_map
[32]; // Memory map
33 ARC_DISK_SIGNATURE reactos_arc_disk_info
[32]; // ARC Disk Information
34 char reactos_arc_strings
[32][256];
35 unsigned long reactos_disk_count
= 0;
38 static CHAR szLoadingMsg
[] = "Loading ReactOS...";
39 BOOLEAN FrLdrBootType
;
43 FrLdrLoadKernel(PCHAR szFileName
,
50 /* Extract Kernel filename without path */
51 szShortName
= strrchr(szFileName
, '\\');
52 if (szShortName
== NULL
) {
54 /* No path, leave it alone */
55 szShortName
= szFileName
;
60 szShortName
= szShortName
+ 1;
64 FilePointer
= FsOpenFile(szFileName
);
66 /* Make sure it worked */
67 if (FilePointer
== NULL
) {
69 /* Return failure on the short name */
70 strcpy(szBuffer
, szShortName
);
71 strcat(szBuffer
, " not found.");
72 UiMessageBox(szBuffer
);
76 /* Update the status bar with the current file */
77 strcpy(szBuffer
, "Reading ");
78 strcat(szBuffer
, szShortName
);
79 UiDrawStatusText(szBuffer
);
81 /* Do the actual loading */
82 FrLdrMapKernel(FilePointer
);
84 /* Update Processbar and return success */
85 UiDrawProgressBarCenter(nPos
, 100, szLoadingMsg
);
98 FrLdrLoadImage(IN PCHAR szFileName
,
103 CHAR szBuffer
[256], szFullPath
[256];
105 /* Check if this the HAL being loaded */
106 if (!_stricmp(szFileName
, "hal.dll"))
108 /* Use the boot.ini name instead */
109 szFileName
= szHalName
;
112 /* Extract filename without path */
113 szShortName
= strrchr(szFileName
, '\\');
116 /* No path, leave it alone */
117 szShortName
= szFileName
;
119 /* Which means we need to build a path now */
120 strcpy(szBuffer
, szFileName
);
121 strcpy(szFullPath
, szBootPath
);
124 strcat(szFullPath
, "SYSTEM32\\DRIVERS\\");
128 strcat(szFullPath
, "\\");
130 strcat(szFullPath
, szBuffer
);
131 szFileName
= szFullPath
;
136 szShortName
= szShortName
+ 1;
140 FilePointer
= FsOpenFile(szFileName
);
143 /* Return failure on the short name */
144 strcpy(szBuffer
, szShortName
);
145 strcat(szBuffer
, " not found.");
146 UiMessageBox(szBuffer
);
150 /* Update the status bar with the current file */
151 strcpy(szBuffer
, "Reading ");
152 strcat(szBuffer
, szShortName
);
153 UiDrawStatusText(szBuffer
);
155 /* Do the actual loading */
156 FrLdrMapImage(FilePointer
, szShortName
);
158 /* Update Processbar and return success */
159 if (!FrLdrBootType
) UiDrawProgressBarCenter(nPos
, 100, szLoadingMsg
);
164 FreeldrFreeMem(PVOID Area
)
170 FreeldrAllocMem(ULONG_PTR Size
)
172 return MmAllocateMemory((ULONG
) Size
);
176 FreeldrReadFile(PVOID FileContext
, PVOID Buffer
, ULONG Size
)
180 return FsReadFile((PFILE
) FileContext
, (ULONG
) Size
, &BytesRead
, Buffer
)
181 && Size
== BytesRead
;
185 FreeldrSeekFile(PVOID FileContext
, ULONG_PTR Position
)
187 FsSetFilePointer((PFILE
) FileContext
, (ULONG
) Position
);
192 LoadKernelSymbols(PCHAR szKernelName
, int nPos
)
194 static ROSSYM_CALLBACKS FreeldrCallbacks
=
202 PROSSYM_INFO RosSymInfo
;
207 RosSymInit(&FreeldrCallbacks
);
209 FilePointer
= FsOpenFile(szKernelName
);
210 if (FilePointer
== NULL
)
214 if (! RosSymCreateFromFile(FilePointer
, &RosSymInfo
))
218 Base
= FrLdrCreateModule("NTOSKRNL.SYM");
219 Size
= RosSymGetRawDataLength(RosSymInfo
);
220 RosSymGetRawData(RosSymInfo
, (PVOID
)Base
);
221 FrLdrCloseModule(Base
, Size
);
222 RosSymDelete(RosSymInfo
);
227 FrLdrLoadNlsFile(PCSTR szFileName
,
234 /* Open the Driver */
235 FilePointer
= FsOpenFile(szFileName
);
237 /* Make sure we did */
238 if (FilePointer
== NULL
) {
240 /* Fail if file wasn't opened */
241 strcpy(value
, szFileName
);
242 strcat(value
, " not found.");
247 /* Update the status bar with the current file */
248 strcpy(value
, "Reading ");
249 p
= strrchr(szFileName
, '\\');
252 strcat(value
, szFileName
);
256 strcat(value
, p
+ 1);
258 UiDrawStatusText(value
);
260 /* Load the driver */
261 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
266 FrLdrLoadNlsFiles(PCHAR szSystemRoot
,
269 LONG rc
= ERROR_SUCCESS
;
271 WCHAR szIdBuffer
[80];
272 WCHAR szNameBuffer
[80];
273 CHAR szFileName
[256];
276 /* open the codepage key */
277 rc
= RegOpenKey(NULL
,
278 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage",
280 if (rc
!= ERROR_SUCCESS
) {
282 strcpy(szErrorOut
, "Couldn't open CodePage registry key");
286 /* get ANSI codepage */
287 BufferSize
= sizeof(szIdBuffer
);
288 rc
= RegQueryValue(hKey
, L
"ACP", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
289 if (rc
!= ERROR_SUCCESS
) {
291 strcpy(szErrorOut
, "Couldn't get ACP NLS setting");
295 BufferSize
= sizeof(szNameBuffer
);
296 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)szNameBuffer
, &BufferSize
);
297 if (rc
!= ERROR_SUCCESS
) {
299 strcpy(szErrorOut
, "ACP NLS Setting exists, but isn't readable");
303 /* load ANSI codepage table */
304 sprintf(szFileName
,"%ssystem32\\%S", szSystemRoot
, szNameBuffer
);
305 DbgPrint((DPRINT_REACTOS
, "ANSI file: %s\n", szFileName
));
306 if (!FrLdrLoadNlsFile(szFileName
, "ansi.nls")) {
308 strcpy(szErrorOut
, "Couldn't load ansi.nls");
312 /* get OEM codepage */
313 BufferSize
= sizeof(szIdBuffer
);
314 rc
= RegQueryValue(hKey
, L
"OEMCP", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
315 if (rc
!= ERROR_SUCCESS
) {
317 strcpy(szErrorOut
, "Couldn't get OEMCP NLS setting");
321 BufferSize
= sizeof(szNameBuffer
);
322 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)szNameBuffer
, &BufferSize
);
323 if (rc
!= ERROR_SUCCESS
) {
325 strcpy(szErrorOut
, "OEMCP NLS setting exists, but isn't readable");
329 /* load OEM codepage table */
330 sprintf(szFileName
, "%ssystem32\\%S", szSystemRoot
, szNameBuffer
);
331 DbgPrint((DPRINT_REACTOS
, "Oem file: %s\n", szFileName
));
332 if (!FrLdrLoadNlsFile(szFileName
, "oem.nls")) {
334 strcpy(szErrorOut
, "Couldn't load oem.nls");
338 /* open the language key */
339 rc
= RegOpenKey(NULL
,
340 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
342 if (rc
!= ERROR_SUCCESS
) {
344 strcpy(szErrorOut
, "Couldn't open Language registry key");
348 /* get the Unicode case table */
349 BufferSize
= sizeof(szIdBuffer
);
350 rc
= RegQueryValue(hKey
, L
"Default", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
351 if (rc
!= ERROR_SUCCESS
) {
353 strcpy(szErrorOut
, "Couldn't get Language Default setting");
357 BufferSize
= sizeof(szNameBuffer
);
358 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)szNameBuffer
, &BufferSize
);
359 if (rc
!= ERROR_SUCCESS
) {
361 strcpy(szErrorOut
, "Language Default setting exists, but isn't readable");
365 /* load Unicode case table */
366 sprintf(szFileName
, "%ssystem32\\%S", szSystemRoot
, szNameBuffer
);
367 DbgPrint((DPRINT_REACTOS
, "Casemap file: %s\n", szFileName
));
368 if (!FrLdrLoadNlsFile(szFileName
, "casemap.nls")) {
370 strcpy(szErrorOut
, "casemap.nls");
378 FrLdrLoadDriver(PCHAR szFileName
,
385 /* Open the Driver */
386 FilePointer
= FsOpenFile(szFileName
);
388 /* Make sure we did */
389 if (FilePointer
== NULL
) {
391 /* Fail if file wasn't opened */
392 strcpy(value
, szFileName
);
393 strcat(value
, " not found.");
398 /* Update the status bar with the current file */
399 strcpy(value
, "Reading ");
400 p
= strrchr(szFileName
, '\\');
403 strcat(value
, szFileName
);
407 strcat(value
, p
+ 1);
410 UiDrawStatusText(value
);
412 /* Load the driver */
413 FrLdrLoadModule(FilePointer
, szFileName
, NULL
);
415 /* Update status and return */
416 UiDrawProgressBarCenter(nPos
, 100, szLoadingMsg
);
421 FrLdrLoadBootDrivers(PCHAR szSystemRoot
,
425 FRLDRHKEY hGroupKey
, hOrderKey
, hServiceKey
, hDriverKey
;
426 WCHAR GroupNameBuffer
[512];
427 WCHAR ServiceName
[256];
428 ULONG OrderList
[128];
438 WCHAR DriverGroup
[256];
439 ULONG DriverGroupSize
;
442 WCHAR TempImagePath
[256];
444 /* get 'service group order' key */
445 rc
= RegOpenKey(NULL
,
446 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder",
448 if (rc
!= ERROR_SUCCESS
) {
450 DbgPrint((DPRINT_REACTOS
, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc
));
454 /* get 'group order list' key */
455 rc
= RegOpenKey(NULL
,
456 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\GroupOrderList",
458 if (rc
!= ERROR_SUCCESS
) {
460 DbgPrint((DPRINT_REACTOS
, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc
));
464 /* enumerate drivers */
465 rc
= RegOpenKey(NULL
,
466 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services",
468 if (rc
!= ERROR_SUCCESS
) {
470 DbgPrint((DPRINT_REACTOS
, "Failed to open the 'Services' key (rc %d)\n", (int)rc
));
474 /* Get the Name Group */
475 BufferSize
= sizeof(GroupNameBuffer
);
476 rc
= RegQueryValue(hGroupKey
, L
"List", NULL
, (PUCHAR
)GroupNameBuffer
, &BufferSize
);
477 DbgPrint((DPRINT_REACTOS
, "RegQueryValue(): rc %d\n", (int)rc
));
478 if (rc
!= ERROR_SUCCESS
) return;
479 DbgPrint((DPRINT_REACTOS
, "BufferSize: %d \n", (int)BufferSize
));
480 DbgPrint((DPRINT_REACTOS
, "GroupNameBuffer: '%S' \n", GroupNameBuffer
));
482 /* Loop through each group */
483 GroupName
= GroupNameBuffer
;
485 DbgPrint((DPRINT_REACTOS
, "Driver group: '%S'\n", GroupName
));
487 /* Query the Order */
488 BufferSize
= sizeof(OrderList
);
489 rc
= RegQueryValue(hOrderKey
, GroupName
, NULL
, (PUCHAR
)OrderList
, &BufferSize
);
490 if (rc
!= ERROR_SUCCESS
) OrderList
[0] = 0;
492 /* enumerate all drivers */
493 for (TagIndex
= 1; TagIndex
<= OrderList
[0]; TagIndex
++) {
499 /* Get the Driver's Name */
500 ValueSize
= sizeof(ServiceName
);
501 rc
= RegEnumKey(hServiceKey
, Index
, ServiceName
, &ValueSize
);
502 DbgPrint((DPRINT_REACTOS
, "RegEnumKey(): rc %d\n", (int)rc
));
504 /* Makre sure it's valid, and check if we're done */
505 if (rc
== ERROR_NO_MORE_ITEMS
) break;
506 if (rc
!= ERROR_SUCCESS
) return;
507 DbgPrint((DPRINT_REACTOS
, "Service %d: '%S'\n", (int)Index
, ServiceName
));
509 /* open driver Key */
510 rc
= RegOpenKey(hServiceKey
, ServiceName
, &hDriverKey
);
511 if (rc
== ERROR_SUCCESS
)
513 /* Read the Start Value */
514 ValueSize
= sizeof(ULONG
);
515 rc
= RegQueryValue(hDriverKey
, L
"Start", &ValueType
, (PUCHAR
)&StartValue
, &ValueSize
);
516 if (rc
!= ERROR_SUCCESS
) StartValue
= (ULONG
)-1;
517 DbgPrint((DPRINT_REACTOS
, " Start: %x \n", (int)StartValue
));
520 ValueSize
= sizeof(ULONG
);
521 rc
= RegQueryValue(hDriverKey
, L
"Tag", &ValueType
, (PUCHAR
)&TagValue
, &ValueSize
);
522 if (rc
!= ERROR_SUCCESS
) TagValue
= (ULONG
)-1;
523 DbgPrint((DPRINT_REACTOS
, " Tag: %x \n", (int)TagValue
));
525 /* Read the driver's group */
526 DriverGroupSize
= sizeof(DriverGroup
);
527 rc
= RegQueryValue(hDriverKey
, L
"Group", NULL
, (PUCHAR
)DriverGroup
, &DriverGroupSize
);
528 DbgPrint((DPRINT_REACTOS
, " Group: '%S' \n", DriverGroup
));
530 /* Make sure it should be started */
531 if ((StartValue
== 0) &&
532 (TagValue
== OrderList
[TagIndex
]) &&
533 (_wcsicmp(DriverGroup
, GroupName
) == 0)) {
535 /* Get the Driver's Location */
536 ValueSize
= sizeof(TempImagePath
);
537 rc
= RegQueryValue(hDriverKey
, L
"ImagePath", NULL
, (PUCHAR
)TempImagePath
, &ValueSize
);
539 /* Write the whole path if it suceeded, else prepare to fail */
540 if (rc
!= ERROR_SUCCESS
) {
541 DbgPrint((DPRINT_REACTOS
, " ImagePath: not found\n"));
542 sprintf(ImagePath
, "%s\\system32\\drivers\\%S.sys", szSystemRoot
, ServiceName
);
543 } else if (TempImagePath
[0] != L
'\\') {
544 sprintf(ImagePath
, "%s%S", szSystemRoot
, TempImagePath
);
546 sprintf(ImagePath
, "%S", TempImagePath
);
547 DbgPrint((DPRINT_REACTOS
, " ImagePath: '%s'\n", ImagePath
));
550 DbgPrint((DPRINT_REACTOS
, " Loading driver: '%s'\n", ImagePath
));
552 /* Update the position if needed */
553 if (nPos
< 100) nPos
+= 5;
555 FrLdrLoadDriver(ImagePath
, nPos
);
559 DbgPrint((DPRINT_REACTOS
, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n",
560 ServiceName
, StartValue
, TagValue
, DriverGroup
, OrderList
[TagIndex
], GroupName
));
571 /* Get the Driver's Name */
572 ValueSize
= sizeof(ServiceName
);
573 rc
= RegEnumKey(hServiceKey
, Index
, ServiceName
, &ValueSize
);
575 DbgPrint((DPRINT_REACTOS
, "RegEnumKey(): rc %d\n", (int)rc
));
576 if (rc
== ERROR_NO_MORE_ITEMS
) break;
577 if (rc
!= ERROR_SUCCESS
) return;
578 DbgPrint((DPRINT_REACTOS
, "Service %d: '%S'\n", (int)Index
, ServiceName
));
580 /* open driver Key */
581 rc
= RegOpenKey(hServiceKey
, ServiceName
, &hDriverKey
);
582 if (rc
== ERROR_SUCCESS
)
584 /* Read the Start Value */
585 ValueSize
= sizeof(ULONG
);
586 rc
= RegQueryValue(hDriverKey
, L
"Start", &ValueType
, (PUCHAR
)&StartValue
, &ValueSize
);
587 if (rc
!= ERROR_SUCCESS
) StartValue
= (ULONG
)-1;
588 DbgPrint((DPRINT_REACTOS
, " Start: %x \n", (int)StartValue
));
591 ValueSize
= sizeof(ULONG
);
592 rc
= RegQueryValue(hDriverKey
, L
"Tag", &ValueType
, (PUCHAR
)&TagValue
, &ValueSize
);
593 if (rc
!= ERROR_SUCCESS
) TagValue
= (ULONG
)-1;
594 DbgPrint((DPRINT_REACTOS
, " Tag: %x \n", (int)TagValue
));
596 /* Read the driver's group */
597 DriverGroupSize
= sizeof(DriverGroup
);
598 rc
= RegQueryValue(hDriverKey
, L
"Group", NULL
, (PUCHAR
)DriverGroup
, &DriverGroupSize
);
599 DbgPrint((DPRINT_REACTOS
, " Group: '%S' \n", DriverGroup
));
601 for (TagIndex
= 1; TagIndex
<= OrderList
[0]; TagIndex
++) {
602 if (TagValue
== OrderList
[TagIndex
]) break;
605 if ((StartValue
== 0) &&
606 (TagIndex
> OrderList
[0]) &&
607 (_wcsicmp(DriverGroup
, GroupName
) == 0)) {
609 ValueSize
= sizeof(TempImagePath
);
610 rc
= RegQueryValue(hDriverKey
, L
"ImagePath", NULL
, (PUCHAR
)TempImagePath
, &ValueSize
);
611 if (rc
!= ERROR_SUCCESS
) {
612 DbgPrint((DPRINT_REACTOS
, " ImagePath: not found\n"));
613 sprintf(ImagePath
, "%ssystem32\\drivers\\%S.sys", szSystemRoot
, ServiceName
);
614 } else if (TempImagePath
[0] != L
'\\') {
615 sprintf(ImagePath
, "%s%S", szSystemRoot
, TempImagePath
);
617 sprintf(ImagePath
, "%S", TempImagePath
);
618 DbgPrint((DPRINT_REACTOS
, " ImagePath: '%s'\n", ImagePath
));
620 DbgPrint((DPRINT_REACTOS
, " Loading driver: '%s'\n", ImagePath
));
622 if (nPos
< 100) nPos
+= 5;
624 FrLdrLoadDriver(ImagePath
, nPos
);
628 DbgPrint((DPRINT_REACTOS
, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n",
629 ServiceName
, StartValue
, TagValue
, DriverGroup
, GroupName
));
636 /* Move to the next group name */
637 GroupName
= GroupName
+ wcslen(GroupName
) + 1;
642 LoadAndBootReactOS(PCSTR OperatingSystemName
)
647 CHAR SystemPath
[255];
648 CHAR szKernelName
[255];
649 CHAR szFileName
[255];
657 extern ULONG PageDirectoryStart
;
658 extern ULONG PageDirectoryEnd
;
659 extern BOOLEAN AcpiPresent
;
662 // Open the operating system section
663 // specified in the .ini file
665 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
667 sprintf(MsgBuffer
,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName
);
668 UiMessageBox(MsgBuffer
);
673 UiDrawStatusText("Detecting Hardware...");
674 UiDrawProgressBarCenter(1, 100, szLoadingMsg
);
677 * Setup multiboot information structure
679 LoaderBlock
.Flags
= MB_FLAGS_BOOT_DEVICE
| MB_FLAGS_COMMAND_LINE
| MB_FLAGS_MODULE_INFO
;
680 LoaderBlock
.PageDirectoryStart
= (ULONG
)&PageDirectoryStart
;
681 LoaderBlock
.PageDirectoryEnd
= (ULONG
)&PageDirectoryEnd
;
682 LoaderBlock
.BootDevice
= 0xffffffff;
683 LoaderBlock
.CommandLine
= reactos_kernel_cmdline
;
684 LoaderBlock
.ModsCount
= 0;
685 LoaderBlock
.ModsAddr
= reactos_modules
;
686 LoaderBlock
.DrivesAddr
= reactos_arc_disk_info
;
687 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)(PVOID
)&reactos_memory_map
, 32) * sizeof(memory_map_t
);
688 if (LoaderBlock
.MmapLength
)
690 LoaderBlock
.MmapAddr
= (unsigned long)&reactos_memory_map
;
691 LoaderBlock
.Flags
|= MB_FLAGS_MEM_INFO
| MB_FLAGS_MMAP_INFO
;
692 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
693 DbgPrint((DPRINT_REACTOS
, "memory map length: %d\n", LoaderBlock
.MmapLength
));
694 DbgPrint((DPRINT_REACTOS
, "dumping memory map:\n"));
695 for (i
=0; i
<(LoaderBlock
.MmapLength
/sizeof(memory_map_t
)); i
++)
697 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
698 0 == reactos_memory_map
[i
].base_addr_low
)
700 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
701 if (640 < LoaderBlock
.MemLower
)
703 LoaderBlock
.MemLower
= 640;
706 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
707 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
708 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
710 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
712 DbgPrint((DPRINT_REACTOS
, "start: %x\t size: %x\t type %d\n",
713 reactos_memory_map
[i
].base_addr_low
,
714 reactos_memory_map
[i
].length_low
,
715 reactos_memory_map
[i
].type
));
718 DbgPrint((DPRINT_REACTOS
, "low_mem = %d\n", LoaderBlock
.MemLower
));
719 DbgPrint((DPRINT_REACTOS
, "high_mem = %d\n", LoaderBlock
.MemHigher
));
722 * Initialize the registry
724 RegInitializeRegistry();
727 * Make sure the system path is set in the .ini file
729 if (!IniReadSettingByName(SectionId
, "SystemPath", SystemPath
, sizeof(SystemPath
)))
731 UiMessageBox("System path not specified for selected operating system.");
736 * Special case for Live CD.
738 if (!_stricmp(SystemPath
, "LiveCD"))
741 MachDiskGetBootPath(SystemPath
, sizeof(SystemPath
));
742 strcat(SystemPath
, "\\reactos");
743 strcat(strcpy(reactos_kernel_cmdline
, SystemPath
),
748 if (! MachDiskNormalizeSystemPath(SystemPath
,
751 UiMessageBox("Invalid system path");
754 /* copy system path into kernel command line */
755 strcpy(reactos_kernel_cmdline
, SystemPath
);
759 * Read the optional kernel parameters (if any)
761 if (IniReadSettingByName(SectionId
, "Options", value
, sizeof(value
)))
763 strcat(reactos_kernel_cmdline
, " ");
764 strcat(reactos_kernel_cmdline
, value
);
771 UiDrawProgressBarCenter(5, 100, szLoadingMsg
);
773 if (AcpiPresent
) LoaderBlock
.Flags
|= MB_FLAGS_ACPI_TABLE
;
774 LoaderBlock
.DrivesCount
= reactos_disk_count
;
776 UiDrawStatusText("Loading...");
779 * Try to open system drive
781 if (!FsOpenSystemVolume(SystemPath
, szBootPath
, &LoaderBlock
.BootDevice
))
783 UiMessageBox("Failed to open boot drive.");
787 /* append a backslash */
788 if ((strlen(szBootPath
)==0) ||
789 szBootPath
[strlen(szBootPath
)] != '\\')
790 strcat(szBootPath
, "\\");
792 DbgPrint((DPRINT_REACTOS
,"SystemRoot: '%s'\n", szBootPath
));
795 * Find the kernel image name
796 * and try to load the kernel off the disk
798 if(IniReadSettingByName(SectionId
, "Kernel", value
, sizeof(value
)))
803 if (value
[0] == '\\')
805 strcpy(szKernelName
, value
);
809 strcpy(szKernelName
, szBootPath
);
810 strcat(szKernelName
, "SYSTEM32\\");
811 strcat(szKernelName
, value
);
816 strcpy(value
, "NTOSKRNL.EXE");
817 strcpy(szKernelName
, szBootPath
);
818 strcat(szKernelName
, "SYSTEM32\\");
819 strcat(szKernelName
, value
);
823 * Find the HAL image name
824 * and try to load the kernel off the disk
826 if(IniReadSettingByName(SectionId
, "Hal", value
, sizeof(value
)))
831 if (value
[0] == '\\')
833 strcpy(szHalName
, value
);
837 strcpy(szHalName
, szBootPath
);
838 strcat(szHalName
, "SYSTEM32\\");
839 strcat(szHalName
, value
);
844 strcpy(value
, "HAL.DLL");
845 strcpy(szHalName
, szBootPath
);
846 strcat(szHalName
, "SYSTEM32\\");
847 strcat(szHalName
, value
);
850 /* Load the kernel */
851 if (!FrLdrLoadKernel(szKernelName
, 5)) return;
854 * Load the System hive from disk
856 strcpy(szFileName
, szBootPath
);
857 strcat(szFileName
, "SYSTEM32\\CONFIG\\SYSTEM");
859 DbgPrint((DPRINT_REACTOS
, "SystemHive: '%s'", szFileName
));
861 FilePointer
= FsOpenFile(szFileName
);
862 if (FilePointer
== NULL
)
864 UiMessageBox("Could not find the System hive!");
869 * Update the status bar with the current file
871 strcpy(name
, "Reading ");
873 while (strlen(name
) < 80)
875 UiDrawStatusText(name
);
878 * Load the System hive
880 Base
= FrLdrLoadModule(FilePointer
, szFileName
, &Size
);
881 if (Base
== 0 || Size
== 0)
883 UiMessageBox("Could not load the System hive!\n");
886 DbgPrint((DPRINT_REACTOS
, "SystemHive loaded at 0x%x size %u", (unsigned)Base
, (unsigned)Size
));
889 * Import the loaded system hive
891 RegImportBinaryHive((PCHAR
)Base
, Size
);
894 * Initialize the 'CurrentControlSet' link
896 RegInitCurrentControlSet(FALSE
);
898 UiDrawProgressBarCenter(15, 100, szLoadingMsg
);
901 * Export the hardware hive
903 Base
= FrLdrCreateModule ("HARDWARE");
904 RegExportBinaryHive (L
"\\Registry\\Machine\\HARDWARE", (PCHAR
)Base
, &Size
);
905 FrLdrCloseModule (Base
, Size
);
907 UiDrawProgressBarCenter(20, 100, szLoadingMsg
);
912 if (!FrLdrLoadNlsFiles(szBootPath
, MsgBuffer
))
914 UiMessageBox(MsgBuffer
);
917 UiDrawProgressBarCenter(30, 100, szLoadingMsg
);
920 * Load kernel symbols
922 LoadKernelSymbols(szKernelName
, 30);
923 UiDrawProgressBarCenter(40, 100, szLoadingMsg
);
928 FrLdrLoadBootDrivers(szBootPath
, 40);
929 //UiUnInitialize("Booting ReactOS...");
932 * Now boot the kernel
934 DiskStopFloppyMotor();
935 //MachVideoPrepareForReactOS();
936 FrLdrStartup(0x2badb002);
941 DbgPrint(const char *Format
, ...)
947 va_start(ap
, Format
);
949 /* Construct a string */
950 Length
= _vsnprintf(Buffer
, 512, Format
, ap
);
952 /* Check if we went past the buffer */
955 /* Terminate it if we went over-board */
956 Buffer
[sizeof(Buffer
) - 1] = '\n';
959 Length
= sizeof(Buffer
);
962 /* Show it as a message box */
963 UiMessageBox(Buffer
);
965 /* Cleanup and exit */