4 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
5 * Copyright (C) 2006 Aleksey Bragin <aleksey@reactos.org>
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.
25 #include <ndk/ldrtypes.h>
28 DBG_DEFAULT_CHANNEL(WINDOWS
);
30 // FIXME: Find a better way to retrieve ARC disk information
31 extern ULONG reactos_disk_count
;
32 extern ARC_DISK_SIGNATURE_EX reactos_arc_disk_info
[];
34 extern ULONG LoaderPagesSpanned
;
35 extern BOOLEAN AcpiPresent
;
37 extern HEADLESS_LOADER_BLOCK LoaderRedirectionInformation
;
38 extern BOOLEAN WinLdrTerminalConnected
;
39 extern void WinLdrSetupEms(IN PCHAR BootOptions
);
41 PLOADER_SYSTEM_BLOCK WinLdrSystemBlock
;
44 VOID
DumpMemoryAllocMap(VOID
);
48 AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK
*OutLoaderBlock
)
50 PLOADER_PARAMETER_BLOCK LoaderBlock
;
52 /* Allocate and zero-init the LPB */
53 WinLdrSystemBlock
= MmAllocateMemoryWithType(sizeof(LOADER_SYSTEM_BLOCK
),
55 if (WinLdrSystemBlock
== NULL
)
57 UiMessageBox("Failed to allocate memory for system block!");
61 RtlZeroMemory(WinLdrSystemBlock
, sizeof(LOADER_SYSTEM_BLOCK
));
63 LoaderBlock
= &WinLdrSystemBlock
->LoaderBlock
;
64 LoaderBlock
->NlsData
= &WinLdrSystemBlock
->NlsDataBlock
;
66 /* Init three critical lists, used right away */
67 InitializeListHead(&LoaderBlock
->LoadOrderListHead
);
68 InitializeListHead(&LoaderBlock
->MemoryDescriptorListHead
);
69 InitializeListHead(&LoaderBlock
->BootDriverListHead
);
71 *OutLoaderBlock
= LoaderBlock
;
76 WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock
,
82 /* Examples of correct options and paths */
83 //CHAR Options[] = "/DEBUGPORT=COM1 /BAUDRATE=115200";
84 //CHAR Options[] = "/NODEBUG";
85 //CHAR SystemRoot[] = "\\WINNT\\";
86 //CHAR ArcBoot[] = "multi(0)disk(0)rdisk(0)partition(1)";
88 LPSTR LoadOptions
, NewLoadOptions
;
89 CHAR HalPath
[] = "\\";
93 ULONG_PTR PathSeparator
;
94 PLOADER_PARAMETER_EXTENSION Extension
;
96 /* Construct SystemRoot and ArcBoot from SystemPath */
97 PathSeparator
= strstr(BootPath
, "\\") - BootPath
;
98 strncpy(ArcBoot
, BootPath
, PathSeparator
);
99 ArcBoot
[PathSeparator
] = ANSI_NULL
;
101 TRACE("ArcBoot: %s\n", ArcBoot
);
102 TRACE("SystemRoot: %s\n", SystemRoot
);
103 TRACE("Options: %s\n", Options
);
105 /* Fill Arc BootDevice */
106 LoaderBlock
->ArcBootDeviceName
= WinLdrSystemBlock
->ArcBootDeviceName
;
107 strncpy(LoaderBlock
->ArcBootDeviceName
, ArcBoot
, MAX_PATH
);
108 LoaderBlock
->ArcBootDeviceName
= PaToVa(LoaderBlock
->ArcBootDeviceName
);
110 /* Fill Arc HalDevice, it matches ArcBoot path */
111 LoaderBlock
->ArcHalDeviceName
= WinLdrSystemBlock
->ArcBootDeviceName
;
112 LoaderBlock
->ArcHalDeviceName
= PaToVa(LoaderBlock
->ArcHalDeviceName
);
114 /* Fill SystemRoot */
115 LoaderBlock
->NtBootPathName
= WinLdrSystemBlock
->NtBootPathName
;
116 strncpy(LoaderBlock
->NtBootPathName
, SystemRoot
, MAX_PATH
);
117 LoaderBlock
->NtBootPathName
= PaToVa(LoaderBlock
->NtBootPathName
);
119 /* Fill NtHalPathName */
120 LoaderBlock
->NtHalPathName
= WinLdrSystemBlock
->NtHalPathName
;
121 strncpy(LoaderBlock
->NtHalPathName
, HalPath
, MAX_PATH
);
122 LoaderBlock
->NtHalPathName
= PaToVa(LoaderBlock
->NtHalPathName
);
124 /* Fill LoadOptions and strip the '/' commutator symbol in front of each option */
125 NewLoadOptions
= LoadOptions
= LoaderBlock
->LoadOptions
= WinLdrSystemBlock
->LoadOptions
;
126 strncpy(LoaderBlock
->LoadOptions
, Options
, MAX_OPTIONS_LENGTH
);
130 while (*LoadOptions
== '/')
133 *NewLoadOptions
++ = *LoadOptions
;
134 } while (*LoadOptions
++);
136 LoaderBlock
->LoadOptions
= PaToVa(LoaderBlock
->LoadOptions
);
139 LoaderBlock
->ArcDiskInformation
= &WinLdrSystemBlock
->ArcDiskInformation
;
140 InitializeListHead(&LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
);
142 /* Convert ARC disk information from freeldr to a correct format */
143 for (i
= 0; i
< reactos_disk_count
; i
++)
145 PARC_DISK_SIGNATURE_EX ArcDiskSig
;
147 /* Allocate the ARC structure */
148 ArcDiskSig
= FrLdrHeapAlloc(sizeof(ARC_DISK_SIGNATURE_EX
), 'giSD');
150 /* Copy the data over */
151 RtlCopyMemory(ArcDiskSig
, &reactos_arc_disk_info
[i
], sizeof(ARC_DISK_SIGNATURE_EX
));
153 /* Set the ARC Name pointer and mark the partition table as valid */
154 ArcDiskSig
->DiskSignature
.ArcName
= PaToVa(ArcDiskSig
->ArcName
);
155 ArcDiskSig
->DiskSignature
.ValidPartitionTable
= TRUE
;
157 /* Insert into the list */
158 InsertTailList(&LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
,
159 &ArcDiskSig
->DiskSignature
.ListEntry
);
162 /* Convert all list's to Virtual address */
164 /* Convert the ArcDisks list to virtual address */
165 List_PaToVa(&LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
);
166 LoaderBlock
->ArcDiskInformation
= PaToVa(LoaderBlock
->ArcDiskInformation
);
168 /* Convert configuration entries to VA */
169 ConvertConfigToVA(LoaderBlock
->ConfigurationRoot
);
170 LoaderBlock
->ConfigurationRoot
= PaToVa(LoaderBlock
->ConfigurationRoot
);
172 /* Convert all DTE into virtual addresses */
173 List_PaToVa(&LoaderBlock
->LoadOrderListHead
);
175 /* This one will be converted right before switching to virtual paging mode */
176 //List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
178 /* Convert list of boot drivers */
179 List_PaToVa(&LoaderBlock
->BootDriverListHead
);
181 /* Initialize Extension now */
182 Extension
= &WinLdrSystemBlock
->Extension
;
183 Extension
->Size
= sizeof(LOADER_PARAMETER_EXTENSION
);
184 Extension
->MajorVersion
= (VersionToBoot
& 0xFF00) >> 8;
185 Extension
->MinorVersion
= VersionToBoot
& 0xFF;
186 Extension
->Profile
.Status
= 2;
188 /* Check if FreeLdr detected a ACPI table */
191 /* Set the pointer to something for compatibility */
192 Extension
->AcpiTable
= (PVOID
)1;
193 // FIXME: Extension->AcpiTableSize;
197 /* Set headless block pointer */
198 if (WinLdrTerminalConnected
)
200 Extension
->HeadlessLoaderBlock
= &WinLdrSystemBlock
->HeadlessLoaderBlock
;
201 RtlCopyMemory(Extension
->HeadlessLoaderBlock
,
202 &LoaderRedirectionInformation
,
203 sizeof(HEADLESS_LOADER_BLOCK
));
204 Extension
->HeadlessLoaderBlock
= PaToVa(Extension
->HeadlessLoaderBlock
);
207 /* Load drivers database */
208 strcpy(MiscFiles
, BootPath
);
209 strcat(MiscFiles
, "AppPatch\\drvmain.sdb");
210 Extension
->DrvDBImage
= PaToVa(WinLdrLoadModule(MiscFiles
,
211 &Extension
->DrvDBSize
,
212 LoaderRegistryData
));
214 /* Convert extension and setup block pointers */
215 LoaderBlock
->Extension
= PaToVa(Extension
);
217 if (LoaderBlock
->SetupLdrBlock
)
218 LoaderBlock
->SetupLdrBlock
= PaToVa(LoaderBlock
->SetupLdrBlock
);
220 TRACE("WinLdrInitializePhase1() completed\n");
224 WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead
,
226 PUNICODE_STRING FilePath
,
228 PLDR_DATA_TABLE_ENTRY
*DriverDTE
)
231 CHAR DriverPath
[1024];
235 PVOID DriverBase
= NULL
;
237 // Separate the path to file name and directory path
238 _snprintf(DriverPath
, sizeof(DriverPath
), "%wZ", FilePath
);
239 DriverNamePos
= strrchr(DriverPath
, '\\');
240 if (DriverNamePos
!= NULL
)
243 strcpy(DllName
, DriverNamePos
+1);
245 // Cut out the name from the path
246 *(DriverNamePos
+1) = 0;
250 // There is no directory in the path
251 strcpy(DllName
, DriverPath
);
252 DriverPath
[0] = ANSI_NULL
;
255 TRACE("DriverPath: %s, DllName: %s, LPB\n", DriverPath
, DllName
);
257 // Check if driver is already loaded
258 Success
= WinLdrCheckForLoadedDll(LoadOrderListHead
, DllName
, DriverDTE
);
261 // We've got the pointer to its DTE, just return success
265 // It's not loaded, we have to load it
266 _snprintf(FullPath
, sizeof(FullPath
), "%s%wZ", BootPath
, FilePath
);
267 Success
= WinLdrLoadImage(FullPath
, LoaderBootDriver
, &DriverBase
);
271 // Allocate a DTE for it
272 Success
= WinLdrAllocateDataTableEntry(LoadOrderListHead
, DllName
, DllName
, DriverBase
, DriverDTE
);
275 ERR("WinLdrAllocateDataTableEntry() failed\n");
279 // Modify any flags, if needed
280 (*DriverDTE
)->Flags
|= Flags
;
282 // Look for any dependencies it may have, and load them too
283 sprintf(FullPath
,"%s%s", BootPath
, DriverPath
);
284 Success
= WinLdrScanImportDescriptorTable(LoadOrderListHead
, FullPath
, *DriverDTE
);
287 ERR("WinLdrScanImportDescriptorTable() failed for %s\n", FullPath
);
295 WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock
,
299 PBOOT_DRIVER_LIST_ENTRY BootDriver
;
303 // Walk through the boot drivers list
304 NextBd
= LoaderBlock
->BootDriverListHead
.Flink
;
306 while (NextBd
!= &LoaderBlock
->BootDriverListHead
)
308 BootDriver
= CONTAINING_RECORD(NextBd
, BOOT_DRIVER_LIST_ENTRY
, Link
);
310 TRACE("BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver
->FilePath
,
311 BootDriver
->LdrEntry
, &BootDriver
->RegistryPath
);
313 // Paths are relative (FIXME: Are they always relative?)
316 Success
= WinLdrLoadDeviceDriver(&LoaderBlock
->LoadOrderListHead
,
318 &BootDriver
->FilePath
,
320 &BootDriver
->LdrEntry
);
324 // Convert the RegistryPath and DTE addresses to VA since we are not going to use it anymore
325 BootDriver
->RegistryPath
.Buffer
= PaToVa(BootDriver
->RegistryPath
.Buffer
);
326 BootDriver
->FilePath
.Buffer
= PaToVa(BootDriver
->FilePath
.Buffer
);
327 BootDriver
->LdrEntry
= PaToVa(BootDriver
->LdrEntry
);
331 // Loading failed - cry loudly
332 ERR("Can't load boot driver '%wZ'!\n", &BootDriver
->FilePath
);
333 UiMessageBox("Can't load boot driver '%wZ'!", &BootDriver
->FilePath
);
336 // Remove it from the list and try to continue
337 RemoveEntryList(NextBd
);
340 NextBd
= BootDriver
->Link
.Flink
;
347 WinLdrLoadModule(PCSTR ModuleName
,
349 TYPE_OF_MEMORY MemoryType
)
353 FILEINFORMATION FileInfo
;
358 //CHAR ProgressString[256];
360 /* Inform user we are loading files */
361 //sprintf(ProgressString, "Loading %s...", FileName);
362 //UiDrawProgressBarCenter(1, 100, ProgressString);
364 TRACE("Loading module %s\n", ModuleName
);
367 /* Open the image file */
368 Status
= ArcOpen((PCHAR
)ModuleName
, OpenReadOnly
, &FileId
);
369 if (Status
!= ESUCCESS
)
371 /* In case of errors, we just return, without complaining to the user */
375 /* Get this file's size */
376 Status
= ArcGetFileInformation(FileId
, &FileInfo
);
377 if (Status
!= ESUCCESS
)
382 FileSize
= FileInfo
.EndingAddress
.LowPart
;
385 /* Allocate memory */
386 PhysicalBase
= MmAllocateMemoryWithType(FileSize
, MemoryType
);
387 if (PhysicalBase
== NULL
)
393 /* Load whole file */
394 Status
= ArcRead(FileId
, PhysicalBase
, FileSize
, &BytesRead
);
396 if (Status
!= ESUCCESS
)
401 TRACE("Loaded %s at 0x%x with size 0x%x\n", ModuleName
, PhysicalBase
, FileSize
);
407 WinLdrDetectVersion(VOID
)
414 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server",
416 if (rc
!= ERROR_SUCCESS
)
418 // Key doesn't exist; assume NT 4.0
419 return _WIN32_WINNT_NT4
;
422 // We may here want to read the value of ProductVersion
423 return _WIN32_WINNT_WS03
;
429 IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock
,
432 IN PCCH ImportName
, // BaseDllName
433 IN TYPE_OF_MEMORY MemoryType
,
434 OUT PLDR_DATA_TABLE_ENTRY
*Dte
,
438 CHAR FullFileName
[MAX_PATH
];
439 CHAR ProgressString
[256];
440 PVOID BaseAddress
= NULL
;
443 sprintf(ProgressString
, "Loading %s...", File
);
444 UiDrawProgressBarCenter(Percentage
, 100, ProgressString
);
446 strcpy(FullFileName
, Path
);
447 strcat(FullFileName
, File
);
449 Success
= WinLdrLoadImage(FullFileName
, MemoryType
, &BaseAddress
);
452 TRACE("Loading %s failed\n", File
);
455 TRACE("%s loaded successfully at %p\n", File
, BaseAddress
);
458 * Cheat about the base DLL name if we are loading
459 * the Kernel Debugger Transport DLL, to make the
462 Success
= WinLdrAllocateDataTableEntry(&LoaderBlock
->LoadOrderListHead
,
473 LoadWindowsCore(IN USHORT OperatingSystemVersion
,
474 IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock
,
475 IN PCSTR BootOptions
,
477 IN OUT PLDR_DATA_TABLE_ENTRY
* KernelDTE
)
481 CHAR DirPath
[MAX_PATH
];
482 CHAR KernelFileName
[MAX_PATH
];
483 CHAR HalFileName
[MAX_PATH
];
484 CHAR KdTransportDllName
[MAX_PATH
];
485 PLDR_DATA_TABLE_ENTRY HalDTE
, KdComDTE
= NULL
;
487 if (!KernelDTE
) return FALSE
;
489 /* Initialize SystemRoot\System32 path */
490 strcpy(DirPath
, BootPath
);
491 strcat(DirPath
, "SYSTEM32\\");
494 // TODO: Parse also the separate INI values "Kernel=" and "Hal="
497 /* Default KERNEL and HAL file names */
498 strcpy(KernelFileName
, "NTOSKRNL.EXE");
499 strcpy(HalFileName
, "HAL.DLL");
501 /* Find any /KERNEL= or /HAL= switch in the boot options */
502 Options
= BootOptions
;
505 /* Skip possible initial whitespace */
506 Options
+= strspn(Options
, " \t");
508 /* Check whether a new commutator starts and it is either KERNEL or HAL */
509 if (*Options
!= '/' || (++Options
,
510 !(_strnicmp(Options
, "KERNEL=", 7) == 0 ||
511 _strnicmp(Options
, "HAL=", 4) == 0)) )
513 /* Search for another whitespace */
514 Options
= strpbrk(Options
, " \t");
519 size_t i
= strcspn(Options
, " \t"); /* Skip whitespace */
522 /* Use the default values */
526 /* We have found either KERNEL or HAL commutator */
527 if (_strnicmp(Options
, "KERNEL=", 7) == 0)
529 Options
+= 7; i
-= 7;
530 strncpy(KernelFileName
, Options
, i
);
531 KernelFileName
[i
] = ANSI_NULL
;
532 _strupr(KernelFileName
);
534 else if (_strnicmp(Options
, "HAL=", 4) == 0)
536 Options
+= 4; i
-= 4;
537 strncpy(HalFileName
, Options
, i
);
538 HalFileName
[i
] = ANSI_NULL
;
539 _strupr(HalFileName
);
544 TRACE("Kernel file = '%s' ; HAL file = '%s'\n", KernelFileName
, HalFileName
);
546 /* Load the Kernel */
547 LoadModule(LoaderBlock
, DirPath
, KernelFileName
, "NTOSKRNL.EXE", LoaderSystemCode
, KernelDTE
, 30);
550 LoadModule(LoaderBlock
, DirPath
, HalFileName
, "HAL.DLL", LoaderHalCode
, &HalDTE
, 45);
552 /* Load the Kernel Debugger Transport DLL */
553 if (OperatingSystemVersion
> _WIN32_WINNT_WIN2K
)
556 * According to http://www.nynaeve.net/?p=173 :
557 * "[...] Another enhancement that could be done Microsoft-side would be
558 * a better interface for replacing KD transport modules. Right now, due
559 * to the fact that ntoskrnl is static linked to KDCOM.DLL, the OS loader
560 * has a hardcoded hack that interprets the KD type in the OS loader options,
561 * loads one of the (hardcoded filenames) "kdcom.dll", "kd1394.dll", or
562 * "kdusb2.dll" modules, and inserts them into the loaded module list under
563 * the name "kdcom.dll". [...]"
567 * This loop replaces a dumb call to strstr(..., "DEBUGPORT=").
568 * Indeed I want it to be case-insensitive to allow "debugport="
569 * or "DeBuGpOrT=" or... , and I don't want it to match malformed
570 * command-line options, such as:
572 * "...foo DEBUGPORT=xxx bar..."
573 * "...foo/DEBUGPORT=xxx bar..."
574 * "...foo/DEBUGPORT=bar..."
576 * i.e. the "DEBUGPORT=" switch must start with a slash and be separated
577 * from the rest by whitespace, unless it begins the command-line, e.g.:
579 * "/DEBUGPORT=COM1 foo...bar..."
580 * "...foo /DEBUGPORT=USB bar..."
582 * "...foo /DEBUGPORT= bar..."
583 * (in that case, we default the port to COM).
585 Options
= BootOptions
;
588 /* Skip possible initial whitespace */
589 Options
+= strspn(Options
, " \t");
591 /* Check whether a new commutator starts and it is the DEBUGPORT one */
592 if (*Options
!= '/' || _strnicmp(++Options
, "DEBUGPORT=", 10) != 0)
594 /* Search for another whitespace */
595 Options
= strpbrk(Options
, " \t");
600 /* We found the DEBUGPORT commutator. Move to the port name. */
609 * We have found the DEBUGPORT commutator. Parse the port name.
610 * Format: /DEBUGPORT=COM1 or /DEBUGPORT=FILE:\Device\HarddiskX\PartitionY\debug.log or /DEBUGPORT=FOO
611 * If we only have /DEBUGPORT= (i.e. without any port name), defaults it to "COM".
613 strcpy(KdTransportDllName
, "KD");
614 if (_strnicmp(Options
, "COM", 3) == 0 && '0' <= Options
[3] && Options
[3] <= '9')
616 strncat(KdTransportDllName
, Options
, 3);
620 size_t i
= strcspn(Options
, " \t:"); /* Skip valid separators: whitespace or colon */
622 strcat(KdTransportDllName
, "COM");
624 strncat(KdTransportDllName
, Options
, i
);
626 strcat(KdTransportDllName
, ".DLL");
627 _strupr(KdTransportDllName
);
630 * Load the transport DLL. Override the base DLL name of the
631 * loaded transport DLL to the default "KDCOM.DLL" name.
633 LoadModule(LoaderBlock
, DirPath
, KdTransportDllName
, "KDCOM.DLL", LoaderSystemCode
, &KdComDTE
, 60);
637 /* Load all referenced DLLs for Kernel, HAL and Kernel Debugger Transport DLL */
638 Success
= WinLdrScanImportDescriptorTable(&LoaderBlock
->LoadOrderListHead
, DirPath
, *KernelDTE
);
639 Success
&= WinLdrScanImportDescriptorTable(&LoaderBlock
->LoadOrderListHead
, DirPath
, HalDTE
);
642 Success
&= WinLdrScanImportDescriptorTable(&LoaderBlock
->LoadOrderListHead
, DirPath
, KdComDTE
);
649 LoadAndBootWindows(IN OperatingSystemItem
* OperatingSystem
,
650 IN USHORT OperatingSystemVersion
)
653 PCSTR SectionName
= OperatingSystem
->SystemPartition
;
654 CHAR SettingsValue
[80];
656 CHAR BootPath
[MAX_PATH
];
657 CHAR FileName
[MAX_PATH
];
658 CHAR BootOptions
[256];
661 PLOADER_PARAMETER_BLOCK LoaderBlock
;
663 /* Get OS setting value */
664 SettingsValue
[0] = ANSI_NULL
;
665 IniOpenSection("Operating Systems", &SectionId
);
666 IniReadSettingByName(SectionId
, SectionName
, SettingsValue
, sizeof(SettingsValue
));
668 /* Open the operating system section specified in the .ini file */
669 HasSection
= IniOpenSection(SectionName
, &SectionId
);
672 UiDrawProgressBarCenter(1, 100, "Loading NT...");
674 /* Read the system path is set in the .ini file */
676 !IniReadSettingByName(SectionId
, "SystemPath", BootPath
, sizeof(BootPath
)))
678 strcpy(BootPath
, SectionName
);
682 * Check whether BootPath is a full path
683 * and if not, create a full boot path.
685 * See FsOpenFile for the technique used.
687 if (strrchr(BootPath
, ')') == NULL
)
689 /* Temporarily save the boot path */
690 strcpy(FileName
, BootPath
);
692 /* This is not a full path. Use the current (i.e. boot) device. */
693 MachDiskGetBootPath(BootPath
, sizeof(BootPath
));
695 /* Append a path separator if needed */
696 if (FileName
[0] != '\\' && FileName
[0] != '/')
697 strcat(BootPath
, "\\");
699 /* Append the remaining path */
700 strcat(BootPath
, FileName
);
703 /* Append a backslash if needed */
704 if ((BootPath
[0] == 0) || BootPath
[strlen(BootPath
) - 1] != '\\')
705 strcat(BootPath
, "\\");
707 /* Read booting options */
708 if (!HasSection
|| !IniReadSettingByName(SectionId
, "Options", BootOptions
, sizeof(BootOptions
)))
710 /* Get options after the title */
711 PCSTR p
= SettingsValue
;
712 while (*p
== ' ' || *p
== '"')
714 while (*p
!= '\0' && *p
!= '"')
716 strcpy(BootOptions
, p
);
717 TRACE("BootOptions: '%s'\n", BootOptions
);
720 /* Append boot-time options */
721 AppendBootTimeOptions(BootOptions
);
723 /* Check if a ramdisk file was given */
724 File
= strstr(BootOptions
, "/RDPATH=");
727 /* Copy the file name and everything else after it */
728 strcpy(FileName
, File
+ 8);
731 *strstr(FileName
, " ") = ANSI_NULL
;
733 /* Load the ramdisk */
734 if (!RamDiskLoadVirtualFile(FileName
))
736 UiMessageBox("Failed to load RAM disk file %s", FileName
);
741 /* Let user know we started loading */
742 //UiDrawStatusText("Loading...");
744 TRACE("BootPath: '%s'\n", BootPath
);
746 /* Allocate and minimalist-initialize LPB */
747 AllocateAndInitLPB(&LoaderBlock
);
749 /* Load the system hive */
751 UiDrawProgressBarCenter(15, 100, "Loading system hive...");
752 Success
= WinLdrInitSystemHive(LoaderBlock
, BootPath
);
753 TRACE("SYSTEM hive %s\n", (Success
? "loaded" : "not loaded"));
754 /* Bail out if failure */
758 /* Load NLS data, OEM font, and prepare boot drivers list */
759 Success
= WinLdrScanSystemHive(LoaderBlock
, BootPath
);
760 TRACE("SYSTEM hive %s\n", (Success
? "scanned" : "not scanned"));
761 /* Bail out if failure */
766 LoadAndBootWindowsCommon(OperatingSystemVersion
,
774 LoadAndBootWindowsCommon(
775 USHORT OperatingSystemVersion
,
776 PLOADER_PARAMETER_BLOCK LoaderBlock
,
781 PLOADER_PARAMETER_BLOCK LoaderBlockVA
;
783 PLDR_DATA_TABLE_ENTRY KernelDTE
;
784 KERNEL_ENTRY_POINT KiSystemStartup
;
786 TRACE("LoadAndBootWindowsCommon()\n");
789 /* Setup redirection support */
790 WinLdrSetupEms((PCHAR
)BootOptions
);
793 /* Convert BootPath to SystemRoot */
794 SystemRoot
= strstr(BootPath
, "\\");
796 /* Detect hardware */
798 UiDrawProgressBarCenter(20, 100, "Detecting hardware...");
799 LoaderBlock
->ConfigurationRoot
= MachHwDetect();
801 if (OperatingSystemVersion
== 0)
802 OperatingSystemVersion
= WinLdrDetectVersion();
804 /* Load the operating system core: the Kernel, the HAL and the Kernel Debugger Transport DLL */
805 Success
= LoadWindowsCore(OperatingSystemVersion
,
812 UiMessageBox("Error loading NTOS core.");
816 /* Load boot drivers */
818 UiDrawProgressBarCenter(100, 100, "Loading boot drivers...");
819 Success
= WinLdrLoadBootDrivers(LoaderBlock
, BootPath
);
820 TRACE("Boot drivers loading %s\n", Success
? "successful" : "failed");
822 /* Initialize Phase 1 - no drivers loading anymore */
823 WinLdrInitializePhase1(LoaderBlock
,
827 OperatingSystemVersion
);
829 /* Save entry-point pointer and Loader block VAs */
830 KiSystemStartup
= (KERNEL_ENTRY_POINT
)KernelDTE
->EntryPoint
;
831 LoaderBlockVA
= PaToVa(LoaderBlock
);
833 /* "Stop all motors", change videomode */
834 MachPrepareForReactOS(Setup
);
836 /* Cleanup ini file */
840 //DumpMemoryAllocMap();
842 /* Do the machine specific initialization */
843 WinLdrSetupMachineDependent(LoaderBlock
);
845 /* Map pages and create memory descriptors */
846 WinLdrSetupMemoryLayout(LoaderBlock
);
848 /* Set processor context */
849 WinLdrSetProcessorContext();
851 /* Save final value of LoaderPagesSpanned */
852 LoaderBlock
->Extension
->LoaderPagesSpanned
= LoaderPagesSpanned
;
854 TRACE("Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
855 KiSystemStartup
, LoaderBlockVA
);
857 // Zero KI_USER_SHARED_DATA page
858 memset((PVOID
)KI_USER_SHARED_DATA
, 0, MM_PAGE_SIZE
);
860 WinLdrpDumpMemoryDescriptors(LoaderBlockVA
);
861 WinLdrpDumpBootDriver(LoaderBlockVA
);
863 WinLdrpDumpArcDisks(LoaderBlockVA
);
867 (*KiSystemStartup
)(LoaderBlockVA
);
871 WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock
)
874 PMEMORY_ALLOCATION_DESCRIPTOR MemoryDescriptor
;
876 NextMd
= LoaderBlock
->MemoryDescriptorListHead
.Flink
;
878 while (NextMd
!= &LoaderBlock
->MemoryDescriptorListHead
)
880 MemoryDescriptor
= CONTAINING_RECORD(NextMd
, MEMORY_ALLOCATION_DESCRIPTOR
, ListEntry
);
882 TRACE("BP %08X PC %04X MT %d\n", MemoryDescriptor
->BasePage
,
883 MemoryDescriptor
->PageCount
, MemoryDescriptor
->MemoryType
);
885 NextMd
= MemoryDescriptor
->ListEntry
.Flink
;
890 WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock
)
893 PBOOT_DRIVER_LIST_ENTRY BootDriver
;
895 NextBd
= LoaderBlock
->BootDriverListHead
.Flink
;
897 while (NextBd
!= &LoaderBlock
->BootDriverListHead
)
899 BootDriver
= CONTAINING_RECORD(NextBd
, BOOT_DRIVER_LIST_ENTRY
, Link
);
901 TRACE("BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver
->FilePath
,
902 BootDriver
->LdrEntry
, &BootDriver
->RegistryPath
);
904 NextBd
= BootDriver
->Link
.Flink
;
909 WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock
)
912 PARC_DISK_SIGNATURE ArcDisk
;
914 NextBd
= LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
.Flink
;
916 while (NextBd
!= &LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
)
918 ArcDisk
= CONTAINING_RECORD(NextBd
, ARC_DISK_SIGNATURE
, ListEntry
);
920 TRACE("ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
921 ArcDisk
->ArcName
, ArcDisk
->CheckSum
, ArcDisk
->Signature
);
923 NextBd
= ArcDisk
->ListEntry
.Flink
;