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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 extern ULONG PageDirectoryStart
;
27 extern ULONG PageDirectoryEnd
;
29 ROS_LOADER_PARAMETER_BLOCK LoaderBlock
;
30 char reactos_kernel_cmdline
[255]; // Command line passed to kernel
31 LOADER_MODULE reactos_modules
[64]; // Array to hold boot module info loaded for the kernel
32 char reactos_module_strings
[64][256]; // Array to hold module names
33 // Make this a single struct to guarantee that these elements are nearby in
35 reactos_mem_data_t reactos_mem_data
;
36 ARC_DISK_SIGNATURE reactos_arc_disk_info
[32]; // ARC Disk Information
37 char reactos_arc_strings
[32][256];
38 unsigned long reactos_disk_count
= 0;
39 char reactos_arc_hardware_data
[HW_MAX_ARC_HEAP_SIZE
] = {0};
44 static CHAR szLoadingMsg
[] = "ReactOS is loading files...";
45 BOOLEAN FrLdrBootType
;
47 ROS_KERNEL_ENTRY_POINT KernelEntryPoint
;
50 FrLdrLoadDriver(PCHAR szFileName
,
54 CHAR value
[256], *FinalSlash
;
57 if (!_stricmp(szFileName
, "hal.dll"))
59 /* Use the boot.ini name instead */
60 szFileName
= szHalName
;
63 FinalSlash
= strrchr(szFileName
, '\\');
65 szFileName
= FinalSlash
+ 1;
68 FilePointer
= FsOpenFile(szFileName
);
70 /* Try under the system root in the main dir and drivers */
73 strcpy(value
, SystemRoot
);
74 if(value
[strlen(value
)-1] != '\\')
76 strcat(value
, szFileName
);
77 FilePointer
= FsOpenFile(value
);
82 strcpy(value
, SystemRoot
);
83 if(value
[strlen(value
)-1] != '\\')
85 strcat(value
, "SYSTEM32\\");
86 strcat(value
, szFileName
);
87 FilePointer
= FsOpenFile(value
);
92 strcpy(value
, SystemRoot
);
93 if(value
[strlen(value
)-1] != '\\')
95 strcat(value
, "SYSTEM32\\DRIVERS\\");
96 strcat(value
, szFileName
);
97 FilePointer
= FsOpenFile(value
);
100 /* Make sure we did */
103 /* Fail if file wasn't opened */
104 strcpy(value
, szFileName
);
105 strcat(value
, " not found.");
109 /* Update the status bar with the current file */
110 strcpy(value
, "Reading ");
111 p
= strrchr(szFileName
, '\\');
114 strcat(value
, szFileName
);
118 strcat(value
, p
+ 1);
121 UiDrawStatusText(value
);
123 /* Load the driver */
124 FrLdrReadAndMapImage(FilePointer
, szFileName
, 0);
126 /* Update status and return */
127 UiDrawProgressBarCenter(nPos
, 100, szLoadingMsg
);
133 FrLdrLoadImage(IN PCHAR szFileName
,
139 CHAR szBuffer
[256], szFullPath
[256];
142 /* Extract filename without path */
143 szShortName
= strrchr(szFileName
, '\\');
146 /* No path, leave it alone */
147 szShortName
= szFileName
;
149 /* Which means we need to build a path now */
150 strcpy(szBuffer
, szFileName
);
151 strcpy(szFullPath
, szBootPath
);
154 strcat(szFullPath
, "SYSTEM32\\DRIVERS\\");
158 strcat(szFullPath
, "\\");
160 strcat(szFullPath
, szBuffer
);
161 szFileName
= szFullPath
;
166 szShortName
= szShortName
+ 1;
170 FilePointer
= FsOpenFile(szFileName
);
173 /* Return failure on the short name */
174 strcpy(szBuffer
, szShortName
);
175 strcat(szBuffer
, " not found.");
176 UiMessageBox(szBuffer
);
180 /* Update the status bar with the current file */
181 strcpy(szBuffer
, "Reading ");
182 strcat(szBuffer
, szShortName
);
183 UiDrawStatusText(szBuffer
);
185 /* Do the actual loading */
186 LoadBase
= FrLdrReadAndMapImage(FilePointer
, szShortName
, ImageType
);
188 /* Update Processbar and return success */
189 if (!FrLdrBootType
) UiDrawProgressBarCenter(nPos
, 100, szLoadingMsg
);
194 FrLdrLoadNlsFile(PCSTR szFileName
,
201 /* Open the Driver */
202 FilePointer
= FsOpenFile(szFileName
);
204 /* Make sure we did */
207 /* Fail if file wasn't opened */
208 strcpy(value
, szFileName
);
209 strcat(value
, " not found.");
214 /* Update the status bar with the current file */
215 strcpy(value
, "Reading ");
216 p
= strrchr(szFileName
, '\\');
219 strcat(value
, szFileName
);
223 strcat(value
, p
+ 1);
225 UiDrawStatusText(value
);
227 /* Load the driver */
228 FrLdrLoadModule(FilePointer
, szModuleName
, NULL
);
233 FrLdrLoadNlsFiles(PCHAR szSystemRoot
,
236 LONG rc
= ERROR_SUCCESS
;
238 WCHAR szIdBuffer
[80];
239 WCHAR szNameBuffer
[80];
240 CHAR szFileName
[256];
243 /* open the codepage key */
244 rc
= RegOpenKey(NULL
,
245 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage",
247 if (rc
!= ERROR_SUCCESS
) {
249 strcpy(szErrorOut
, "Couldn't open CodePage registry key");
253 /* get ANSI codepage */
254 BufferSize
= sizeof(szIdBuffer
);
255 rc
= RegQueryValue(hKey
, L
"ACP", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
256 if (rc
!= ERROR_SUCCESS
) {
258 strcpy(szErrorOut
, "Couldn't get ACP NLS setting");
262 BufferSize
= sizeof(szNameBuffer
);
263 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)szNameBuffer
, &BufferSize
);
264 if (rc
!= ERROR_SUCCESS
) {
266 //strcpy(szErrorOut, "ACP NLS Setting exists, but isn't readable");
270 wcscpy(szNameBuffer
, L
"c_1252.nls");
273 /* load ANSI codepage table */
274 sprintf(szFileName
,"%ssystem32\\%S", szSystemRoot
, szNameBuffer
);
275 DPRINTM(DPRINT_REACTOS
, "ANSI file: %s\n", szFileName
);
276 if (!FrLdrLoadNlsFile(szFileName
, "ansi.nls")) {
278 strcpy(szErrorOut
, "Couldn't load ansi.nls");
282 /* get OEM codepage */
283 BufferSize
= sizeof(szIdBuffer
);
284 rc
= RegQueryValue(hKey
, L
"OEMCP", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
285 if (rc
!= ERROR_SUCCESS
) {
287 strcpy(szErrorOut
, "Couldn't get OEMCP NLS setting");
291 BufferSize
= sizeof(szNameBuffer
);
292 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)szNameBuffer
, &BufferSize
);
293 if (rc
!= ERROR_SUCCESS
) {
295 //strcpy(szErrorOut, "OEMCP NLS setting exists, but isn't readable");
299 wcscpy(szNameBuffer
, L
"c_437.nls");
302 /* load OEM codepage table */
303 sprintf(szFileName
, "%ssystem32\\%S", szSystemRoot
, szNameBuffer
);
304 DPRINTM(DPRINT_REACTOS
, "Oem file: %s\n", szFileName
);
305 if (!FrLdrLoadNlsFile(szFileName
, "oem.nls")) {
307 strcpy(szErrorOut
, "Couldn't load oem.nls");
311 /* open the language key */
312 rc
= RegOpenKey(NULL
,
313 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language",
315 if (rc
!= ERROR_SUCCESS
) {
317 strcpy(szErrorOut
, "Couldn't open Language registry key");
321 /* get the Unicode case table */
322 BufferSize
= sizeof(szIdBuffer
);
323 rc
= RegQueryValue(hKey
, L
"Default", NULL
, (PUCHAR
)szIdBuffer
, &BufferSize
);
324 if (rc
!= ERROR_SUCCESS
) {
326 strcpy(szErrorOut
, "Couldn't get Language Default setting");
330 BufferSize
= sizeof(szNameBuffer
);
331 rc
= RegQueryValue(hKey
, szIdBuffer
, NULL
, (PUCHAR
)szNameBuffer
, &BufferSize
);
332 if (rc
!= ERROR_SUCCESS
) {
334 sprintf(szErrorOut
, "Language Default setting exists, but isn't readable (%S)", szIdBuffer
);
338 /* load Unicode case table */
339 sprintf(szFileName
, "%ssystem32\\%S", szSystemRoot
, szNameBuffer
);
340 DPRINTM(DPRINT_REACTOS
, "Casemap file: %s\n", szFileName
);
341 if (!FrLdrLoadNlsFile(szFileName
, "casemap.nls")) {
343 strcpy(szErrorOut
, "casemap.nls");
351 FrLdrLoadBootDrivers(PCHAR szSystemRoot
,
355 FRLDRHKEY hGroupKey
, hOrderKey
, hServiceKey
, hDriverKey
;
356 WCHAR GroupNameBuffer
[512];
357 WCHAR ServiceName
[256];
358 ULONG OrderList
[128];
368 WCHAR DriverGroup
[256];
369 ULONG DriverGroupSize
;
372 WCHAR TempImagePath
[256];
374 /* get 'service group order' key */
375 rc
= RegOpenKey(NULL
,
376 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\ServiceGroupOrder",
378 if (rc
!= ERROR_SUCCESS
) {
380 DPRINTM(DPRINT_REACTOS
, "Failed to open the 'ServiceGroupOrder' key (rc %d)\n", (int)rc
);
384 /* get 'group order list' key */
385 rc
= RegOpenKey(NULL
,
386 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\GroupOrderList",
388 if (rc
!= ERROR_SUCCESS
) {
390 DPRINTM(DPRINT_REACTOS
, "Failed to open the 'GroupOrderList' key (rc %d)\n", (int)rc
);
394 /* enumerate drivers */
395 rc
= RegOpenKey(NULL
,
396 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services",
398 if (rc
!= ERROR_SUCCESS
) {
400 DPRINTM(DPRINT_REACTOS
, "Failed to open the 'Services' key (rc %d)\n", (int)rc
);
404 /* Get the Name Group */
405 BufferSize
= sizeof(GroupNameBuffer
);
406 rc
= RegQueryValue(hGroupKey
, L
"List", NULL
, (PUCHAR
)GroupNameBuffer
, &BufferSize
);
407 DPRINTM(DPRINT_REACTOS
, "RegQueryValue(): rc %d\n", (int)rc
);
408 if (rc
!= ERROR_SUCCESS
) return;
409 DPRINTM(DPRINT_REACTOS
, "BufferSize: %d \n", (int)BufferSize
);
410 DPRINTM(DPRINT_REACTOS
, "GroupNameBuffer: '%S' \n", GroupNameBuffer
);
412 /* Loop through each group */
413 GroupName
= GroupNameBuffer
;
415 DPRINTM(DPRINT_REACTOS
, "Driver group: '%S'\n", GroupName
);
417 /* Query the Order */
418 BufferSize
= sizeof(OrderList
);
419 rc
= RegQueryValue(hOrderKey
, GroupName
, NULL
, (PUCHAR
)OrderList
, &BufferSize
);
420 if (rc
!= ERROR_SUCCESS
) OrderList
[0] = 0;
422 /* enumerate all drivers */
423 for (TagIndex
= 1; TagIndex
<= SWAPD(OrderList
[0]); TagIndex
++) {
429 /* Get the Driver's Name */
430 ValueSize
= sizeof(ServiceName
);
431 rc
= RegEnumKey(hServiceKey
, Index
, ServiceName
, &ValueSize
);
432 DPRINTM(DPRINT_REACTOS
, "RegEnumKey(): rc %d\n", (int)rc
);
434 /* Makre sure it's valid, and check if we're done */
435 if (rc
== ERROR_NO_MORE_ITEMS
) break;
436 if (rc
!= ERROR_SUCCESS
) return;
437 DPRINTM(DPRINT_REACTOS
, "Service %d: '%S'\n", (int)Index
, ServiceName
);
439 /* open driver Key */
440 rc
= RegOpenKey(hServiceKey
, ServiceName
, &hDriverKey
);
441 if (rc
== ERROR_SUCCESS
)
443 /* Read the Start Value */
444 ValueSize
= sizeof(ULONG
);
445 rc
= RegQueryValue(hDriverKey
, L
"Start", &ValueType
, (PUCHAR
)&StartValue
, &ValueSize
);
446 if (rc
!= ERROR_SUCCESS
) StartValue
= (ULONG
)-1;
447 DPRINTM(DPRINT_REACTOS
, " Start: %x \n", (int)StartValue
);
450 ValueSize
= sizeof(ULONG
);
451 rc
= RegQueryValue(hDriverKey
, L
"Tag", &ValueType
, (PUCHAR
)&TagValue
, &ValueSize
);
452 if (rc
!= ERROR_SUCCESS
) TagValue
= (ULONG
)-1;
453 DPRINTM(DPRINT_REACTOS
, " Tag: %x \n", (int)TagValue
);
455 /* Read the driver's group */
456 DriverGroupSize
= sizeof(DriverGroup
);
457 rc
= RegQueryValue(hDriverKey
, L
"Group", NULL
, (PUCHAR
)DriverGroup
, &DriverGroupSize
);
458 DPRINTM(DPRINT_REACTOS
, " Group: '%S' \n", DriverGroup
);
460 /* Make sure it should be started */
461 if ((StartValue
== 0) &&
462 (TagValue
== OrderList
[TagIndex
]) &&
463 (_wcsicmp(DriverGroup
, GroupName
) == 0)) {
465 /* Get the Driver's Location */
466 ValueSize
= sizeof(TempImagePath
);
467 rc
= RegQueryValue(hDriverKey
, L
"ImagePath", NULL
, (PUCHAR
)TempImagePath
, &ValueSize
);
469 /* Write the whole path if it suceeded, else prepare to fail */
470 if (rc
!= ERROR_SUCCESS
) {
471 DPRINTM(DPRINT_REACTOS
, " ImagePath: not found\n");
472 sprintf(ImagePath
, "%s\\system32\\drivers\\%S.sys", szSystemRoot
, ServiceName
);
473 } else if (TempImagePath
[0] != L
'\\') {
474 sprintf(ImagePath
, "%s%S", szSystemRoot
, TempImagePath
);
476 sprintf(ImagePath
, "%S", TempImagePath
);
477 DPRINTM(DPRINT_REACTOS
, " ImagePath: '%s'\n", ImagePath
);
480 DPRINTM(DPRINT_REACTOS
, " Loading driver: '%s'\n", ImagePath
);
482 /* Update the position if needed */
483 if (nPos
< 100) nPos
+= 5;
485 FrLdrLoadImage(ImagePath
, nPos
, 2);
489 DPRINTM(DPRINT_REACTOS
, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current Tag %d, current group '%S')\n",
490 ServiceName
, StartValue
, TagValue
, DriverGroup
, OrderList
[TagIndex
], GroupName
);
501 /* Get the Driver's Name */
502 ValueSize
= sizeof(ServiceName
);
503 rc
= RegEnumKey(hServiceKey
, Index
, ServiceName
, &ValueSize
);
505 DPRINTM(DPRINT_REACTOS
, "RegEnumKey(): rc %d\n", (int)rc
);
506 if (rc
== ERROR_NO_MORE_ITEMS
) break;
507 if (rc
!= ERROR_SUCCESS
) return;
508 DPRINTM(DPRINT_REACTOS
, "Service %d: '%S'\n", (int)Index
, ServiceName
);
510 /* open driver Key */
511 rc
= RegOpenKey(hServiceKey
, ServiceName
, &hDriverKey
);
512 if (rc
== ERROR_SUCCESS
)
514 /* Read the Start Value */
515 ValueSize
= sizeof(ULONG
);
516 rc
= RegQueryValue(hDriverKey
, L
"Start", &ValueType
, (PUCHAR
)&StartValue
, &ValueSize
);
517 if (rc
!= ERROR_SUCCESS
) StartValue
= (ULONG
)-1;
518 DPRINTM(DPRINT_REACTOS
, " Start: %x \n", (int)StartValue
);
521 ValueSize
= sizeof(ULONG
);
522 rc
= RegQueryValue(hDriverKey
, L
"Tag", &ValueType
, (PUCHAR
)&TagValue
, &ValueSize
);
523 if (rc
!= ERROR_SUCCESS
) TagValue
= (ULONG
)-1;
524 DPRINTM(DPRINT_REACTOS
, " Tag: %x \n", (int)TagValue
);
526 /* Read the driver's group */
527 DriverGroupSize
= sizeof(DriverGroup
);
528 rc
= RegQueryValue(hDriverKey
, L
"Group", NULL
, (PUCHAR
)DriverGroup
, &DriverGroupSize
);
529 DPRINTM(DPRINT_REACTOS
, " Group: '%S' \n", DriverGroup
);
531 for (TagIndex
= 1; TagIndex
<= OrderList
[0]; TagIndex
++) {
532 if (TagValue
== OrderList
[TagIndex
]) break;
535 if ((StartValue
== 0) &&
536 (TagIndex
> OrderList
[0]) &&
537 (_wcsicmp(DriverGroup
, GroupName
) == 0)) {
539 ValueSize
= sizeof(TempImagePath
);
540 rc
= RegQueryValue(hDriverKey
, L
"ImagePath", NULL
, (PUCHAR
)TempImagePath
, &ValueSize
);
541 if (rc
!= ERROR_SUCCESS
) {
542 DPRINTM(DPRINT_REACTOS
, " ImagePath: not found\n");
543 sprintf(ImagePath
, "%ssystem32\\drivers\\%S.sys", szSystemRoot
, ServiceName
);
544 } else if (TempImagePath
[0] != L
'\\') {
545 sprintf(ImagePath
, "%s%S", szSystemRoot
, TempImagePath
);
547 sprintf(ImagePath
, "%S", TempImagePath
);
548 DPRINTM(DPRINT_REACTOS
, " ImagePath: '%s'\n", ImagePath
);
550 DPRINTM(DPRINT_REACTOS
, " Loading driver: '%s'\n", ImagePath
);
552 if (nPos
< 100) nPos
+= 5;
554 FrLdrLoadImage(ImagePath
, nPos
, 2);
558 DPRINTM(DPRINT_REACTOS
, " Skipping driver '%S' with Start %d, Tag %d and Group '%S' (Current group '%S')\n",
559 ServiceName
, StartValue
, TagValue
, DriverGroup
, GroupName
);
566 /* Move to the next group name */
567 GroupName
= GroupName
+ wcslen(GroupName
) + 1;
572 LoadAndBootReactOS(PCSTR OperatingSystemName
)
577 CHAR SystemPath
[255];
579 CHAR szKernelName
[255];
580 CHAR szFileName
[255];
583 PIMAGE_NT_HEADERS NtHeader
;
594 // Open the operating system section
595 // specified in the .ini file
597 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
599 sprintf(MsgBuffer
,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName
);
600 UiMessageBox(MsgBuffer
);
605 // Read the command line
607 if (IniReadSettingByName(SectionId
, "Options", value
, sizeof(value
)))
610 // Append boot-time options
612 AppendBootTimeOptions(value
);
615 // Check if a ramdisk file was given
618 File
= strstr(value
, "/RDIMAGEPATH=");
622 // Copy the file name and everything else after it
624 strcpy(szFileName
, File
+ 13);
629 *strstr(szFileName
, " ") = ANSI_NULL
;
634 RamDiskLoadVirtualFile(szFileName
);
639 * Setup multiboot information structure
641 UiDrawProgressBarCenter(1, 100, szLoadingMsg
);
642 UiDrawStatusText("Detecting Hardware...");
643 LoaderBlock
.CommandLine
= reactos_kernel_cmdline
;
644 LoaderBlock
.PageDirectoryStart
= (ULONG_PTR
)&PageDirectoryStart
;
645 LoaderBlock
.PageDirectoryEnd
= (ULONG_PTR
)&PageDirectoryEnd
;
646 LoaderBlock
.ModsCount
= 0;
647 LoaderBlock
.ModsAddr
= reactos_modules
;
648 LoaderBlock
.DrivesAddr
= reactos_arc_disk_info
;
649 LoaderBlock
.RdAddr
= (ULONG_PTR
)gRamDiskBase
;
650 LoaderBlock
.RdLength
= gRamDiskSize
;
651 LoaderBlock
.MmapLength
= (SIZE_T
)MachVtbl
.GetMemoryMap((PBIOS_MEMORY_MAP
)reactos_memory_map
, 32) * sizeof(memory_map_t
);
652 if (LoaderBlock
.MmapLength
)
655 LoaderBlock
.Flags
|= MB_FLAGS_MEM_INFO
| MB_FLAGS_MMAP_INFO
;
656 LoaderBlock
.MmapAddr
= (ULONG_PTR
)&reactos_memory_map
;
657 reactos_memory_map_descriptor_size
= sizeof(memory_map_t
); // GetBiosMemoryMap uses a fixed value of 24
658 for (i
=0; i
<(LoaderBlock
.MmapLength
/sizeof(memory_map_t
)); i
++)
662 /* Also swap from long long to high/low
663 * We also have unusable memory that will be available to kernel
664 * land. Mark it here.
666 if (BiosMemoryAcpiReclaim
== reactos_memory_map
[i
].type
)
668 reactos_memory_map
[i
].type
= BiosMemoryUsable
;
671 tmp
= reactos_memory_map
[i
].base_addr_low
;
672 reactos_memory_map
[i
].base_addr_low
= reactos_memory_map
[i
].base_addr_high
;
673 reactos_memory_map
[i
].base_addr_high
= tmp
;
674 tmp
= reactos_memory_map
[i
].length_low
;
675 reactos_memory_map
[i
].length_low
= reactos_memory_map
[i
].length_high
;
676 reactos_memory_map
[i
].length_high
= tmp
;
679 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
680 0 == reactos_memory_map
[i
].base_addr_low
)
682 LoaderBlock
.MemLower
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024;
683 if (640 < LoaderBlock
.MemLower
)
685 LoaderBlock
.MemLower
= 640;
688 if (BiosMemoryUsable
== reactos_memory_map
[i
].type
&&
689 reactos_memory_map
[i
].base_addr_low
<= 1024 * 1024 &&
690 1024 * 1024 <= reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
)
692 LoaderBlock
.MemHigher
= (reactos_memory_map
[i
].base_addr_low
+ reactos_memory_map
[i
].length_low
) / 1024 - 1024;
698 * Initialize the registry
700 RegInitializeRegistry();
703 * Make sure the system path is set in the .ini file
705 if (!IniReadSettingByName(SectionId
, "SystemPath", SystemPath
, sizeof(SystemPath
)))
707 UiMessageBox("System path not specified for selected operating system.");
712 * Special case for Live CD.
714 if (!_strnicmp(SystemPath
, "LiveCD", strlen("LiveCD")))
716 /* Use everything following the "LiveCD" string as the path */
717 strcpy(LivePath
, SystemPath
+ strlen("LiveCD"));
719 MachDiskGetBootPath(SystemPath
, sizeof(SystemPath
));
720 strcat(SystemPath
, LivePath
);
721 strcat(strcpy(reactos_kernel_cmdline
, SystemPath
),
726 /* copy system path into kernel command line */
727 strcpy(reactos_kernel_cmdline
, SystemPath
);
731 * Read the optional kernel parameters (if any)
733 if (IniReadSettingByName(SectionId
, "Options", value
, sizeof(value
)))
735 strcat(reactos_kernel_cmdline
, " ");
736 strcat(reactos_kernel_cmdline
, value
);
742 LoaderBlock
.ArchExtra
= (ULONG_PTR
)MachHwDetect();
743 UiDrawProgressBarCenter(5, 100, szLoadingMsg
);
745 LoaderBlock
.DrivesCount
= reactos_disk_count
;
747 UiDrawStatusText("Loading...");
750 if (strchr(SystemPath
, '\\') != NULL
)
751 strcpy(szBootPath
, strchr(SystemPath
, '\\'));
753 szBootPath
[0] = '\0';
755 /* append a backslash */
756 if ((strlen(szBootPath
)==0) ||
757 szBootPath
[strlen(szBootPath
)] != '\\')
758 strcat(szBootPath
, "\\");
760 DPRINTM(DPRINT_REACTOS
,"SystemRoot: '%s'\n", szBootPath
);
761 strcpy(SystemRoot
, szBootPath
);
764 * Find the kernel image name
765 * and try to load the kernel off the disk
767 if(IniReadSettingByName(SectionId
, "Kernel", value
, sizeof(value
)))
772 if (value
[0] == '\\')
774 strcpy(szKernelName
, value
);
778 strcpy(szKernelName
, szBootPath
);
779 strcat(szKernelName
, "SYSTEM32\\");
780 strcat(szKernelName
, value
);
785 strcpy(value
, "NTOSKRNL.EXE");
786 strcpy(szKernelName
, szBootPath
);
787 strcat(szKernelName
, "SYSTEM32\\");
788 strcat(szKernelName
, value
);
792 * Find the HAL image name
793 * and try to load the kernel off the disk
795 if(IniReadSettingByName(SectionId
, "Hal", value
, sizeof(value
)))
800 if (value
[0] == '\\')
802 strcpy(szHalName
, value
);
806 strcpy(szHalName
, szBootPath
);
807 strcat(szHalName
, "SYSTEM32\\");
808 strcat(szHalName
, value
);
813 strcpy(value
, "HAL.DLL");
814 strcpy(szHalName
, szBootPath
);
815 strcat(szHalName
, "SYSTEM32\\");
816 strcat(szHalName
, value
);
819 /* Load the kernel */
820 LoadBase
= FrLdrLoadImage(szKernelName
, 5, 1);
821 if (!LoadBase
) return;
823 /* Get the NT header, kernel base and kernel entry */
824 NtHeader
= RtlImageNtHeader(LoadBase
);
825 KernelBase
= SWAPD(NtHeader
->OptionalHeader
.ImageBase
);
826 KernelEntryPoint
= (ROS_KERNEL_ENTRY_POINT
)(KernelBase
+ SWAPD(NtHeader
->OptionalHeader
.AddressOfEntryPoint
));
827 LoaderBlock
.KernelBase
= KernelBase
;
830 * Load the System hive from disk
832 strcpy(szFileName
, szBootPath
);
833 strcat(szFileName
, "SYSTEM32\\CONFIG\\SYSTEM");
835 DPRINTM(DPRINT_REACTOS
, "SystemHive: '%s'", szFileName
);
837 FilePointer
= FsOpenFile(szFileName
);
840 UiMessageBox("Could not find the System hive!");
845 * Update the status bar with the current file
847 strcpy(name
, "Reading ");
849 while (strlen(name
) < 80)
851 UiDrawStatusText(name
);
854 * Load the System hive
856 Base
= FrLdrLoadModule(FilePointer
, szFileName
, &Size
);
857 if (Base
== 0 || Size
== 0)
859 UiMessageBox("Could not load the System hive!\n");
862 DPRINTM(DPRINT_REACTOS
, "SystemHive loaded at 0x%x size %u\n", (unsigned)Base
, (unsigned)Size
);
865 * Import the loaded system hive
867 RegImportBinaryHive((PCHAR
)Base
, Size
);
870 * Initialize the 'CurrentControlSet' link
872 RegInitCurrentControlSet(FALSE
);
874 UiDrawProgressBarCenter(15, 100, szLoadingMsg
);
876 UiDrawProgressBarCenter(20, 100, szLoadingMsg
);
881 if (!FrLdrLoadNlsFiles(szBootPath
, MsgBuffer
))
883 UiMessageBox(MsgBuffer
);
886 UiDrawProgressBarCenter(30, 100, szLoadingMsg
);
891 FrLdrLoadBootDrivers(szBootPath
, 40);
892 UiDrawProgressBarCenter(100, 100, szLoadingMsg
);
893 //UiUnInitialize("Booting ReactOS...");
896 // Perform architecture-specific pre-boot configuration
898 MachPrepareForReactOS(FALSE
);
901 // Setup paging and jump to kernel
903 FrLdrStartup(0x2badb002);