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
34 static CHAR szLoadingMsg
[] = "Loading ReactOS...";
38 FrLdrLoadKernel(PCHAR szFileName
,
45 /* Extract Kernel filename without path */
46 szShortName
= strrchr(szFileName
, '\\');
47 if (szShortName
== NULL
) {
49 /* No path, leave it alone */
50 szShortName
= szFileName
;
55 szShortName
= szShortName
+ 1;
59 FilePointer
= FsOpenFile(szFileName
);
61 /* Make sure it worked */
62 if (FilePointer
== NULL
) {
64 /* Return failure on the short name */
65 strcpy(szBuffer
, szShortName
);
66 strcat(szBuffer
, " not found.");
67 UiMessageBox(szBuffer
);
71 /* Update the status bar with the current file */
72 strcpy(szBuffer
, "Reading ");
73 strcat(szBuffer
, szShortName
);
74 UiDrawStatusText(szBuffer
);
76 /* Do the actual loading */
77 FrLdrMapKernel(FilePointer
);
79 /* Update Processbar and return success */
80 UiDrawProgressBarCenter(nPos
, 100, szLoadingMsg
);
85 FreeldrFreeMem(PVOID Area
)
91 FreeldrAllocMem(ULONG_PTR Size
)
93 return MmAllocateMemory((ULONG
) Size
);
97 FreeldrReadFile(PVOID FileContext
, PVOID Buffer
, ULONG Size
)
101 return FsReadFile((PFILE
) FileContext
, (ULONG
) Size
, &BytesRead
, Buffer
)
102 && Size
== BytesRead
;
106 FreeldrSeekFile(PVOID FileContext
, ULONG_PTR Position
)
108 FsSetFilePointer((PFILE
) FileContext
, (ULONG
) Position
);
113 LoadKernelSymbols(PCHAR szKernelName
, int nPos
)
115 static ROSSYM_CALLBACKS FreeldrCallbacks
=
123 PROSSYM_INFO RosSymInfo
;
127 RosSymInit(&FreeldrCallbacks
);
129 FilePointer
= FsOpenFile(szKernelName
);
130 if (FilePointer
== NULL
)
134 if (! RosSymCreateFromFile(FilePointer
, &RosSymInfo
))
138 Base
= FrLdrCreateModule("NTOSKRNL.SYM");
139 Size
= RosSymGetRawDataLength(RosSymInfo
);
140 RosSymGetRawData(RosSymInfo
, (PVOID
)Base
);
141 FrLdrCloseModule(Base
, Size
);
142 RosSymDelete(RosSymInfo
);
147 FrLdrLoadNlsFile(PCSTR szFileName
,
154 /* Open the Driver */
155 FilePointer
= FsOpenFile(szFileName
);
157 /* Make sure we did */
158 if (FilePointer
== NULL
) {
160 /* Fail if file wasn't opened */
161 strcpy(value
, szFileName
);
162 strcat(value
, " not found.");
167 /* Update the status bar with the current file */
168 strcpy(value
, "Reading ");
169 p
= strrchr(szFileName
, '\\');
172 strcat(value
, szFileName
);
176 strcat(value
, p
+ 1);
178 UiDrawStatusText(value
);
180 /* Load the driver */
181 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
186 FrLdrLoadNlsFiles(PCHAR szSystemRoot
,
189 LONG rc
= ERROR_SUCCESS
;
191 WCHAR szIdBuffer
[80];
192 WCHAR szNameBuffer
[80];
193 CHAR szFileName
[256];
196 /* open the codepage key */
197 rc
= RegOpenKey(NULL
,
198 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage",
200 if (rc
!= ERROR_SUCCESS
) {
202 strcpy(szErrorOut
, "Couldn't open CodePage registry key");
206 /* get ANSI codepage */
207 BufferSize
= sizeof(szIdBuffer
);
208 rc
= RegQueryValue(hKey
, L
"ACP", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
209 if (rc
!= ERROR_SUCCESS
) {
211 strcpy(szErrorOut
, "Couldn't get ACP NLS setting");
215 BufferSize
= sizeof(szNameBuffer
);
216 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)szNameBuffer
, &BufferSize
);
217 if (rc
!= ERROR_SUCCESS
) {
219 strcpy(szErrorOut
, "ACP NLS Setting exists, but isn't readable");
223 /* load ANSI codepage table */
224 sprintf(szFileName
,"%ssystem32\\%S", szSystemRoot
, szNameBuffer
);
225 DbgPrint((DPRINT_REACTOS
, "ANSI file: %s\n", szFileName
));
226 if (!FrLdrLoadNlsFile(szFileName
, "ansi.nls")) {
228 strcpy(szErrorOut
, "Couldn't load ansi.nls");
232 /* get OEM codepage */
233 BufferSize
= sizeof(szIdBuffer
);
234 rc
= RegQueryValue(hKey
, L
"OEMCP", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
235 if (rc
!= ERROR_SUCCESS
) {
237 strcpy(szErrorOut
, "Couldn't get OEMCP NLS setting");
241 BufferSize
= sizeof(szNameBuffer
);
242 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)szNameBuffer
, &BufferSize
);
243 if (rc
!= ERROR_SUCCESS
) {
245 strcpy(szErrorOut
, "OEMCP NLS setting exists, but isn't readable");
249 /* load OEM codepage table */
250 sprintf(szFileName
, "%ssystem32\\%S", szSystemRoot
, szNameBuffer
);
251 DbgPrint((DPRINT_REACTOS
, "Oem file: %s\n", szFileName
));
252 if (!FrLdrLoadNlsFile(szFileName
, "oem.nls")) {
254 strcpy(szErrorOut
, "Couldn't load oem.nls");
258 /* open the language key */
259 rc
= RegOpenKey(NULL
,
260 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
262 if (rc
!= ERROR_SUCCESS
) {
264 strcpy(szErrorOut
, "Couldn't open Language registry key");
268 /* get the Unicode case table */
269 BufferSize
= sizeof(szIdBuffer
);
270 rc
= RegQueryValue(hKey
, L
"Default", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
271 if (rc
!= ERROR_SUCCESS
) {
273 strcpy(szErrorOut
, "Couldn't get Language Default setting");
277 BufferSize
= sizeof(szNameBuffer
);
278 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)szNameBuffer
, &BufferSize
);
279 if (rc
!= ERROR_SUCCESS
) {
281 strcpy(szErrorOut
, "Language Default setting exists, but isn't readable");
285 /* load Unicode case table */
286 sprintf(szFileName
, "%ssystem32\\%S", szSystemRoot
, szNameBuffer
);
287 DbgPrint((DPRINT_REACTOS
, "Casemap file: %s\n", szFileName
));
288 if (!FrLdrLoadNlsFile(szFileName
, "casemap.nls")) {
290 strcpy(szErrorOut
, "casemap.nls");
298 FrLdrLoadDriver(PCHAR szFileName
,
305 /* Open the Driver */
306 FilePointer
= FsOpenFile(szFileName
);
308 /* Make sure we did */
309 if (FilePointer
== NULL
) {
311 /* Fail if file wasn't opened */
312 strcpy(value
, szFileName
);
313 strcat(value
, " not found.");
318 /* Update the status bar with the current file */
319 strcpy(value
, "Reading ");
320 p
= strrchr(szFileName
, '\\');
323 strcat(value
, szFileName
);
327 strcat(value
, p
+ 1);
330 UiDrawStatusText(value
);
332 /* Load the driver */
333 FrLdrLoadModule(FilePointer
, szFileName
, NULL
);
335 /* Update status and return */
336 UiDrawProgressBarCenter(nPos
, 100, szLoadingMsg
);
341 FrLdrLoadBootDrivers(PCHAR szSystemRoot
,
345 FRLDRHKEY hGroupKey
, hOrderKey
, hServiceKey
, hDriverKey
;
346 WCHAR GroupNameBuffer
[512];
347 WCHAR ServiceName
[256];
348 ULONG OrderList
[128];
358 WCHAR DriverGroup
[256];
359 ULONG DriverGroupSize
;
362 WCHAR TempImagePath
[256];
364 /* get 'service group order' key */
365 rc
= RegOpenKey(NULL
,
366 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder",
368 if (rc
!= ERROR_SUCCESS
) {
370 DbgPrint((DPRINT_REACTOS
, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc
));
374 /* get 'group order list' key */
375 rc
= RegOpenKey(NULL
,
376 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\GroupOrderList",
378 if (rc
!= ERROR_SUCCESS
) {
380 DbgPrint((DPRINT_REACTOS
, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc
));
384 /* enumerate drivers */
385 rc
= RegOpenKey(NULL
,
386 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services",
388 if (rc
!= ERROR_SUCCESS
) {
390 DbgPrint((DPRINT_REACTOS
, "Failed to open the 'Services' key (rc %d)\n", (int)rc
));
394 /* Get the Name Group */
395 BufferSize
= sizeof(GroupNameBuffer
);
396 rc
= RegQueryValue(hGroupKey
, L
"List", NULL
, (PUCHAR
)GroupNameBuffer
, &BufferSize
);
397 DbgPrint((DPRINT_REACTOS
, "RegQueryValue(): rc %d\n", (int)rc
));
398 if (rc
!= ERROR_SUCCESS
) return;
399 DbgPrint((DPRINT_REACTOS
, "BufferSize: %d \n", (int)BufferSize
));
400 DbgPrint((DPRINT_REACTOS
, "GroupNameBuffer: '%S' \n", GroupNameBuffer
));
402 /* Loop through each group */
403 GroupName
= GroupNameBuffer
;
405 DbgPrint((DPRINT_REACTOS
, "Driver group: '%S'\n", GroupName
));
407 /* Query the Order */
408 BufferSize
= sizeof(OrderList
);
409 rc
= RegQueryValue(hOrderKey
, GroupName
, NULL
, (PUCHAR
)OrderList
, &BufferSize
);
410 if (rc
!= ERROR_SUCCESS
) OrderList
[0] = 0;
412 /* enumerate all drivers */
413 for (TagIndex
= 1; TagIndex
<= OrderList
[0]; TagIndex
++) {
419 /* Get the Driver's Name */
420 ValueSize
= sizeof(ServiceName
);
421 rc
= RegEnumKey(hServiceKey
, Index
, ServiceName
, &ValueSize
);
422 DbgPrint((DPRINT_REACTOS
, "RegEnumKey(): rc %d\n", (int)rc
));
424 /* Makre sure it's valid, and check if we're done */
425 if (rc
== ERROR_NO_MORE_ITEMS
) break;
426 if (rc
!= ERROR_SUCCESS
) return;
427 DbgPrint((DPRINT_REACTOS
, "Service %d: '%S'\n", (int)Index
, ServiceName
));
429 /* open driver Key */
430 rc
= RegOpenKey(hServiceKey
, ServiceName
, &hDriverKey
);
431 if (rc
== ERROR_SUCCESS
)
433 /* Read the Start Value */
434 ValueSize
= sizeof(ULONG
);
435 rc
= RegQueryValue(hDriverKey
, L
"Start", &ValueType
, (PUCHAR
)&StartValue
, &ValueSize
);
436 if (rc
!= ERROR_SUCCESS
) StartValue
= (ULONG
)-1;
437 DbgPrint((DPRINT_REACTOS
, " Start: %x \n", (int)StartValue
));
440 ValueSize
= sizeof(ULONG
);
441 rc
= RegQueryValue(hDriverKey
, L
"Tag", &ValueType
, (PUCHAR
)&TagValue
, &ValueSize
);
442 if (rc
!= ERROR_SUCCESS
) TagValue
= (ULONG
)-1;
443 DbgPrint((DPRINT_REACTOS
, " Tag: %x \n", (int)TagValue
));
445 /* Read the driver's group */
446 DriverGroupSize
= sizeof(DriverGroup
);
447 rc
= RegQueryValue(hDriverKey
, L
"Group", NULL
, (PUCHAR
)DriverGroup
, &DriverGroupSize
);
448 DbgPrint((DPRINT_REACTOS
, " Group: '%S' \n", DriverGroup
));
450 /* Make sure it should be started */
451 if ((StartValue
== 0) &&
452 (TagValue
== OrderList
[TagIndex
]) &&
453 (_wcsicmp(DriverGroup
, GroupName
) == 0)) {
455 /* Get the Driver's Location */
456 ValueSize
= sizeof(TempImagePath
);
457 rc
= RegQueryValue(hDriverKey
, L
"ImagePath", NULL
, (PUCHAR
)TempImagePath
, &ValueSize
);
459 /* Write the whole path if it suceeded, else prepare to fail */
460 if (rc
!= ERROR_SUCCESS
) {
461 DbgPrint((DPRINT_REACTOS
, " ImagePath: not found\n"));
462 sprintf(ImagePath
, "%s\\system32\\drivers\\%S.sys", szSystemRoot
, ServiceName
);
463 } else if (TempImagePath
[0] != L
'\\') {
464 sprintf(ImagePath
, "%s%S", szSystemRoot
, TempImagePath
);
466 sprintf(ImagePath
, "%S", TempImagePath
);
467 DbgPrint((DPRINT_REACTOS
, " ImagePath: '%s'\n", ImagePath
));
470 DbgPrint((DPRINT_REACTOS
, " Loading driver: '%s'\n", ImagePath
));
472 /* Update the position if needed */
473 if (nPos
< 100) nPos
+= 5;
475 FrLdrLoadDriver(ImagePath
, nPos
);
479 DbgPrint((DPRINT_REACTOS
, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n",
480 ServiceName
, StartValue
, TagValue
, DriverGroup
, OrderList
[TagIndex
], GroupName
));
491 /* Get the Driver's Name */
492 ValueSize
= sizeof(ServiceName
);
493 rc
= RegEnumKey(hServiceKey
, Index
, ServiceName
, &ValueSize
);
495 DbgPrint((DPRINT_REACTOS
, "RegEnumKey(): rc %d\n", (int)rc
));
496 if (rc
== ERROR_NO_MORE_ITEMS
) break;
497 if (rc
!= ERROR_SUCCESS
) return;
498 DbgPrint((DPRINT_REACTOS
, "Service %d: '%S'\n", (int)Index
, ServiceName
));
500 /* open driver Key */
501 rc
= RegOpenKey(hServiceKey
, ServiceName
, &hDriverKey
);
502 if (rc
== ERROR_SUCCESS
)
504 /* Read the Start Value */
505 ValueSize
= sizeof(ULONG
);
506 rc
= RegQueryValue(hDriverKey
, L
"Start", &ValueType
, (PUCHAR
)&StartValue
, &ValueSize
);
507 if (rc
!= ERROR_SUCCESS
) StartValue
= (ULONG
)-1;
508 DbgPrint((DPRINT_REACTOS
, " Start: %x \n", (int)StartValue
));
511 ValueSize
= sizeof(ULONG
);
512 rc
= RegQueryValue(hDriverKey
, L
"Tag", &ValueType
, (PUCHAR
)&TagValue
, &ValueSize
);
513 if (rc
!= ERROR_SUCCESS
) TagValue
= (ULONG
)-1;
514 DbgPrint((DPRINT_REACTOS
, " Tag: %x \n", (int)TagValue
));
516 /* Read the driver's group */
517 DriverGroupSize
= sizeof(DriverGroup
);
518 rc
= RegQueryValue(hDriverKey
, L
"Group", NULL
, (PUCHAR
)DriverGroup
, &DriverGroupSize
);
519 DbgPrint((DPRINT_REACTOS
, " Group: '%S' \n", DriverGroup
));
521 for (TagIndex
= 1; TagIndex
<= OrderList
[0]; TagIndex
++) {
522 if (TagValue
== OrderList
[TagIndex
]) break;
525 if ((StartValue
== 0) &&
526 (TagIndex
> OrderList
[0]) &&
527 (_wcsicmp(DriverGroup
, GroupName
) == 0)) {
529 ValueSize
= sizeof(TempImagePath
);
530 rc
= RegQueryValue(hDriverKey
, L
"ImagePath", NULL
, (PUCHAR
)TempImagePath
, &ValueSize
);
531 if (rc
!= ERROR_SUCCESS
) {
532 DbgPrint((DPRINT_REACTOS
, " ImagePath: not found\n"));
533 sprintf(ImagePath
, "%ssystem32\\drivers\\%S.sys", szSystemRoot
, ServiceName
);
534 } else if (TempImagePath
[0] != L
'\\') {
535 sprintf(ImagePath
, "%s%S", szSystemRoot
, TempImagePath
);
537 sprintf(ImagePath
, "%S", TempImagePath
);
538 DbgPrint((DPRINT_REACTOS
, " ImagePath: '%s'\n", ImagePath
));
540 DbgPrint((DPRINT_REACTOS
, " Loading driver: '%s'\n", ImagePath
));
542 if (nPos
< 100) nPos
+= 5;
544 FrLdrLoadDriver(ImagePath
, nPos
);
548 DbgPrint((DPRINT_REACTOS
, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n",
549 ServiceName
, StartValue
, TagValue
, DriverGroup
, GroupName
));
556 /* Move to the next group name */
557 GroupName
= GroupName
+ wcslen(GroupName
) + 1;
562 LoadAndBootReactOS(PCSTR OperatingSystemName
)
567 CHAR SystemPath
[1024];
568 CHAR szKernelName
[1024];
569 CHAR szHalName
[1024];
570 CHAR szFileName
[1024];
571 CHAR szBootPath
[256];
579 extern ULONG PageDirectoryStart
;
580 extern ULONG PageDirectoryEnd
;
581 extern BOOLEAN AcpiPresent
;
584 // Open the operating system section
585 // specified in the .ini file
587 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
589 sprintf(MsgBuffer
,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName
);
590 UiMessageBox(MsgBuffer
);
595 UiDrawStatusText("Detecting Hardware...");
596 UiDrawProgressBarCenter(1, 100, szLoadingMsg
);
599 * Setup multiboot information structure
601 LoaderBlock
.Flags
= MB_FLAGS_BOOT_DEVICE
| MB_FLAGS_COMMAND_LINE
| MB_FLAGS_MODULE_INFO
;
602 LoaderBlock
.PageDirectoryStart
= (ULONG
)&PageDirectoryStart
;
603 LoaderBlock
.PageDirectoryEnd
= (ULONG
)&PageDirectoryEnd
;
604 LoaderBlock
.BootDevice
= 0xffffffff;
605 LoaderBlock
.CommandLine
= (unsigned long)reactos_kernel_cmdline
;
606 LoaderBlock
.ModsCount
= 0;
607 LoaderBlock
.ModsAddr
= (unsigned long)reactos_modules
;
608 LoaderBlock
.MmapLength
= (unsigned long)MachGetMemoryMap((PBIOS_MEMORY_MAP
)(PVOID
)&reactos_memory_map
, 32) * sizeof(memory_map_t
);
609 if (LoaderBlock
.MmapLength
)
611 LoaderBlock
.MmapAddr
= (unsigned long)&reactos_memory_map
;
612 LoaderBlock
.Flags
|= MB_FLAGS_MEM_INFO
| MB_FLAGS_MMAP_INFO
;
613 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
614 DbgPrint((DPRINT_REACTOS
, "memory map length: %d\n", LoaderBlock
.MmapLength
));
615 DbgPrint((DPRINT_REACTOS
, "dumping memory map:\n"));
616 for (i
=0; i
<(LoaderBlock
.MmapLength
/sizeof(memory_map_t
)); i
++)
618 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
619 0 == reactos_memory_map
[i
].base_addr_low
)
621 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
622 if (640 < LoaderBlock
.MemLower
)
624 LoaderBlock
.MemLower
= 640;
627 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
628 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
629 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
631 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
633 DbgPrint((DPRINT_REACTOS
, "start: %x\t size: %x\t type %d\n",
634 reactos_memory_map
[i
].base_addr_low
,
635 reactos_memory_map
[i
].length_low
,
636 reactos_memory_map
[i
].type
));
639 DbgPrint((DPRINT_REACTOS
, "low_mem = %d\n", LoaderBlock
.MemLower
));
640 DbgPrint((DPRINT_REACTOS
, "high_mem = %d\n", LoaderBlock
.MemHigher
));
643 * Initialize the registry
645 RegInitializeRegistry();
648 * Make sure the system path is set in the .ini file
650 if (!IniReadSettingByName(SectionId
, "SystemPath", SystemPath
, sizeof(SystemPath
)))
652 UiMessageBox("System path not specified for selected operating system.");
657 * Special case for Live CD.
659 if (!_stricmp(SystemPath
, "LiveCD"))
662 MachDiskGetBootPath(SystemPath
, sizeof(SystemPath
));
663 strcat(SystemPath
, "\\reactos");
664 strcat(strcpy(reactos_kernel_cmdline
, SystemPath
),
669 if (! MachDiskNormalizeSystemPath(SystemPath
,
672 UiMessageBox("Invalid system path");
675 /* copy system path into kernel command line */
676 strcpy(reactos_kernel_cmdline
, SystemPath
);
680 * Read the optional kernel parameters (if any)
682 if (IniReadSettingByName(SectionId
, "Options", value
, 1024))
684 strcat(reactos_kernel_cmdline
, " ");
685 strcat(reactos_kernel_cmdline
, value
);
692 UiDrawProgressBarCenter(5, 100, szLoadingMsg
);
694 if (AcpiPresent
) LoaderBlock
.Flags
|= MB_FLAGS_ACPI_TABLE
;
696 UiDrawStatusText("Loading...");
699 * Try to open system drive
701 if (!FsOpenSystemVolume(SystemPath
, szBootPath
, &LoaderBlock
.BootDevice
))
703 UiMessageBox("Failed to open boot drive.");
707 /* append a backslash */
708 if ((strlen(szBootPath
)==0) ||
709 szBootPath
[strlen(szBootPath
)] != '\\')
710 strcat(szBootPath
, "\\");
712 DbgPrint((DPRINT_REACTOS
,"SystemRoot: '%s'\n", szBootPath
));
715 * Find the kernel image name
716 * and try to load the kernel off the disk
718 if(IniReadSettingByName(SectionId
, "Kernel", value
, 1024))
723 if (value
[0] == '\\')
725 strcpy(szKernelName
, value
);
729 strcpy(szKernelName
, szBootPath
);
730 strcat(szKernelName
, "SYSTEM32\\");
731 strcat(szKernelName
, value
);
736 strcpy(value
, "NTOSKRNL.EXE");
737 strcpy(szKernelName
, szBootPath
);
738 strcat(szKernelName
, "SYSTEM32\\");
739 strcat(szKernelName
, value
);
742 if (!FrLdrLoadKernel(szKernelName
, 5)) return;
745 * Find the HAL image name
746 * and try to load the kernel off the disk
748 if(IniReadSettingByName(SectionId
, "Hal", value
, 1024))
753 if (value
[0] == '\\')
755 strcpy(szHalName
, value
);
759 strcpy(szHalName
, szBootPath
);
760 strcat(szHalName
, "SYSTEM32\\");
761 strcat(szHalName
, value
);
766 strcpy(value
, "HAL.DLL");
767 strcpy(szHalName
, szBootPath
);
768 strcat(szHalName
, "SYSTEM32\\");
769 strcat(szHalName
, value
);
772 if (!FrLdrLoadDriver(szHalName
, 10))
777 strcpy(value
, "INBV.DLL");
778 strcpy(szHalName
, szBootPath
);
779 strcat(szHalName
, "SYSTEM32\\");
780 strcat(szHalName
, value
);
782 if (!FrLdrLoadDriver(szHalName
, 10))
786 * Load the System hive from disk
788 strcpy(szFileName
, szBootPath
);
789 strcat(szFileName
, "SYSTEM32\\CONFIG\\SYSTEM");
791 DbgPrint((DPRINT_REACTOS
, "SystemHive: '%s'", szFileName
));
793 FilePointer
= FsOpenFile(szFileName
);
794 if (FilePointer
== NULL
)
796 UiMessageBox("Could not find the System hive!");
801 * Update the status bar with the current file
803 strcpy(name
, "Reading ");
805 while (strlen(name
) < 80)
807 UiDrawStatusText(name
);
810 * Load the System hive
812 Base
= FrLdrLoadModule(FilePointer
, szFileName
, &Size
);
813 if (Base
== 0 || Size
== 0)
815 UiMessageBox("Could not load the System hive!\n");
818 DbgPrint((DPRINT_REACTOS
, "SystemHive loaded at 0x%x size %u", (unsigned)Base
, (unsigned)Size
));
821 * Import the loaded system hive
823 RegImportBinaryHive((PCHAR
)Base
, Size
);
826 * Initialize the 'CurrentControlSet' link
828 RegInitCurrentControlSet(FALSE
);
830 UiDrawProgressBarCenter(15, 100, szLoadingMsg
);
833 * Export the hardware hive
835 Base
= FrLdrCreateModule ("HARDWARE");
836 RegExportBinaryHive (L
"\\Registry\\Machine\\HARDWARE", (PCHAR
)Base
, &Size
);
837 FrLdrCloseModule (Base
, Size
);
839 UiDrawProgressBarCenter(20, 100, szLoadingMsg
);
844 if (!FrLdrLoadNlsFiles(szBootPath
, MsgBuffer
))
846 UiMessageBox(MsgBuffer
);
849 UiDrawProgressBarCenter(30, 100, szLoadingMsg
);
852 * Load kernel symbols
854 LoadKernelSymbols(szKernelName
, 30);
855 UiDrawProgressBarCenter(40, 100, szLoadingMsg
);
860 FrLdrLoadBootDrivers(szBootPath
, 40);
861 UiUnInitialize("Booting ReactOS...");
864 * Now boot the kernel
866 DiskStopFloppyMotor();
867 MachVideoPrepareForReactOS();
868 FrLdrStartup(0x2badb002);
873 DbgPrint(const char *Format
, ...)
879 va_start(ap
, Format
);
881 /* Construct a string */
882 Length
= _vsnprintf(Buffer
, 512, Format
, ap
);
884 /* Check if we went past the buffer */
887 /* Terminate it if we went over-board */
888 Buffer
[sizeof(Buffer
) - 1] = '\n';
891 Length
= sizeof(Buffer
);
894 /* Show it as a message box */
895 UiMessageBox(Buffer
);
897 /* Cleanup and exit */