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.
24 #include <ndk/ldrtypes.h>
27 DBG_DEFAULT_CHANNEL(WINDOWS
);
29 //FIXME: Do a better way to retrieve Arc disk information
30 extern ULONG reactos_disk_count
;
31 extern ARC_DISK_SIGNATURE reactos_arc_disk_info
[];
33 extern ULONG LoaderPagesSpanned
;
34 extern BOOLEAN AcpiPresent
;
36 extern HEADLESS_LOADER_BLOCK LoaderRedirectionInformation
;
37 extern BOOLEAN WinLdrTerminalConnected
;
38 extern void WinLdrSetupEms(IN PCHAR BootOptions
);
40 PLOADER_SYSTEM_BLOCK WinLdrSystemBlock
;
43 VOID
DumpMemoryAllocMap(VOID
);
47 AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK
*OutLoaderBlock
)
49 PLOADER_PARAMETER_BLOCK LoaderBlock
;
51 /* Allocate and zero-init the LPB */
52 WinLdrSystemBlock
= MmAllocateMemoryWithType(sizeof(LOADER_SYSTEM_BLOCK
),
54 if (WinLdrSystemBlock
== NULL
)
56 UiMessageBox("Failed to allocate memory for system block!");
60 RtlZeroMemory(WinLdrSystemBlock
, sizeof(LOADER_SYSTEM_BLOCK
));
62 LoaderBlock
= &WinLdrSystemBlock
->LoaderBlock
;
63 LoaderBlock
->NlsData
= &WinLdrSystemBlock
->NlsDataBlock
;
65 /* Init three critical lists, used right away */
66 InitializeListHead(&LoaderBlock
->LoadOrderListHead
);
67 InitializeListHead(&LoaderBlock
->MemoryDescriptorListHead
);
68 InitializeListHead(&LoaderBlock
->BootDriverListHead
);
70 *OutLoaderBlock
= LoaderBlock
;
75 WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock
,
81 /* Examples of correct options and paths */
82 //CHAR Options[] = "/DEBUGPORT=COM1 /BAUDRATE=115200";
83 //CHAR Options[] = "/NODEBUG";
84 //CHAR SystemRoot[] = "\\WINNT\\";
85 //CHAR ArcBoot[] = "multi(0)disk(0)rdisk(0)partition(1)";
87 LPSTR LoadOptions
, NewLoadOptions
;
88 CHAR HalPath
[] = "\\";
92 ULONG_PTR PathSeparator
;
93 PLOADER_PARAMETER_EXTENSION Extension
;
95 /* Construct SystemRoot and ArcBoot from SystemPath */
96 PathSeparator
= strstr(BootPath
, "\\") - BootPath
;
97 strncpy(ArcBoot
, BootPath
, PathSeparator
);
98 ArcBoot
[PathSeparator
] = 0;
100 TRACE("ArcBoot: %s\n", ArcBoot
);
101 TRACE("SystemRoot: %s\n", SystemRoot
);
102 TRACE("Options: %s\n", Options
);
104 /* Fill Arc BootDevice */
105 LoaderBlock
->ArcBootDeviceName
= WinLdrSystemBlock
->ArcBootDeviceName
;
106 strncpy(LoaderBlock
->ArcBootDeviceName
, ArcBoot
, MAX_PATH
);
107 LoaderBlock
->ArcBootDeviceName
= PaToVa(LoaderBlock
->ArcBootDeviceName
);
109 /* Fill Arc HalDevice, it matches ArcBoot path */
110 LoaderBlock
->ArcHalDeviceName
= WinLdrSystemBlock
->ArcBootDeviceName
;
111 LoaderBlock
->ArcHalDeviceName
= PaToVa(LoaderBlock
->ArcHalDeviceName
);
113 /* Fill SystemRoot */
114 LoaderBlock
->NtBootPathName
= WinLdrSystemBlock
->NtBootPathName
;
115 strncpy(LoaderBlock
->NtBootPathName
, SystemRoot
, MAX_PATH
);
116 LoaderBlock
->NtBootPathName
= PaToVa(LoaderBlock
->NtBootPathName
);
118 /* Fill NtHalPathName */
119 LoaderBlock
->NtHalPathName
= WinLdrSystemBlock
->NtHalPathName
;
120 strncpy(LoaderBlock
->NtHalPathName
, HalPath
, MAX_PATH
);
121 LoaderBlock
->NtHalPathName
= PaToVa(LoaderBlock
->NtHalPathName
);
123 /* Fill LoadOptions and strip the '/' commutator symbol in front of each option */
124 NewLoadOptions
= LoadOptions
= LoaderBlock
->LoadOptions
= WinLdrSystemBlock
->LoadOptions
;
125 strncpy(LoaderBlock
->LoadOptions
, Options
, MAX_OPTIONS_LENGTH
);
129 while (*LoadOptions
== '/')
132 *NewLoadOptions
++ = *LoadOptions
;
133 } while (*LoadOptions
++);
135 LoaderBlock
->LoadOptions
= PaToVa(LoaderBlock
->LoadOptions
);
138 LoaderBlock
->ArcDiskInformation
= &WinLdrSystemBlock
->ArcDiskInformation
;
139 InitializeListHead(&LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
);
141 /* Convert ARC disk information from freeldr to a correct format */
142 for (i
= 0; i
< reactos_disk_count
; i
++)
144 PARC_DISK_SIGNATURE_EX ArcDiskSig
;
146 /* Allocate the ARC structure */
147 ArcDiskSig
= FrLdrHeapAlloc(sizeof(ARC_DISK_SIGNATURE_EX
), 'giSD');
149 /* Copy the data over */
150 ArcDiskSig
->DiskSignature
.Signature
= reactos_arc_disk_info
[i
].Signature
;
151 ArcDiskSig
->DiskSignature
.CheckSum
= reactos_arc_disk_info
[i
].CheckSum
;
153 /* Copy the ARC Name */
154 strncpy(ArcDiskSig
->ArcName
, reactos_arc_disk_info
[i
].ArcName
, MAX_PATH
);
155 ArcDiskSig
->DiskSignature
.ArcName
= PaToVa(ArcDiskSig
->ArcName
);
157 /* Mark partition table as valid */
158 ArcDiskSig
->DiskSignature
.ValidPartitionTable
= TRUE
;
160 /* Insert into the list */
161 InsertTailList(&LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
,
162 &ArcDiskSig
->DiskSignature
.ListEntry
);
165 /* Convert all list's to Virtual address */
167 /* Convert the ArcDisks list to virtual address */
168 List_PaToVa(&LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
);
169 LoaderBlock
->ArcDiskInformation
= PaToVa(LoaderBlock
->ArcDiskInformation
);
171 /* Convert configuration entries to VA */
172 ConvertConfigToVA(LoaderBlock
->ConfigurationRoot
);
173 LoaderBlock
->ConfigurationRoot
= PaToVa(LoaderBlock
->ConfigurationRoot
);
175 /* Convert all DTE into virtual addresses */
176 List_PaToVa(&LoaderBlock
->LoadOrderListHead
);
178 /* this one will be converted right before switching to
179 virtual paging mode */
180 //List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
182 /* Convert list of boot drivers */
183 List_PaToVa(&LoaderBlock
->BootDriverListHead
);
185 /* Initialize Extension now */
186 Extension
= &WinLdrSystemBlock
->Extension
;
187 Extension
->Size
= sizeof(LOADER_PARAMETER_EXTENSION
);
188 Extension
->MajorVersion
= (VersionToBoot
& 0xFF00) >> 8;
189 Extension
->MinorVersion
= VersionToBoot
& 0xFF;
190 Extension
->Profile
.Status
= 2;
192 /* Check if ACPI is present */
195 /* See KiRosFrldrLpbToNtLpb for details */
196 Extension
->AcpiTable
= (PVOID
)1;
200 /* Set headless block pointer */
201 if (WinLdrTerminalConnected
)
203 Extension
->HeadlessLoaderBlock
= &WinLdrSystemBlock
->HeadlessLoaderBlock
;
204 RtlCopyMemory(Extension
->HeadlessLoaderBlock
,
205 &LoaderRedirectionInformation
,
206 sizeof(HEADLESS_LOADER_BLOCK
));
207 Extension
->HeadlessLoaderBlock
= PaToVa(Extension
->HeadlessLoaderBlock
);
210 /* Load drivers database */
211 strcpy(MiscFiles
, BootPath
);
212 strcat(MiscFiles
, "AppPatch\\drvmain.sdb");
213 Extension
->DrvDBImage
= PaToVa(WinLdrLoadModule(MiscFiles
,
214 &Extension
->DrvDBSize
,
215 LoaderRegistryData
));
217 /* Convert extension and setup block pointers */
218 LoaderBlock
->Extension
= PaToVa(Extension
);
220 if (LoaderBlock
->SetupLdrBlock
)
221 LoaderBlock
->SetupLdrBlock
= PaToVa(LoaderBlock
->SetupLdrBlock
);
223 TRACE("WinLdrInitializePhase1() completed\n");
227 WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead
,
229 PUNICODE_STRING FilePath
,
231 PLDR_DATA_TABLE_ENTRY
*DriverDTE
)
234 CHAR DriverPath
[1024];
238 PVOID DriverBase
= NULL
;
240 // Separate the path to file name and directory path
241 _snprintf(DriverPath
, sizeof(DriverPath
), "%wZ", FilePath
);
242 DriverNamePos
= strrchr(DriverPath
, '\\');
243 if (DriverNamePos
!= NULL
)
246 strcpy(DllName
, DriverNamePos
+1);
248 // Cut out the name from the path
249 *(DriverNamePos
+1) = 0;
253 // There is no directory in the path
254 strcpy(DllName
, DriverPath
);
258 TRACE("DriverPath: %s, DllName: %s, LPB\n", DriverPath
, DllName
);
260 // Check if driver is already loaded
261 Status
= WinLdrCheckForLoadedDll(LoadOrderListHead
, DllName
, DriverDTE
);
264 // We've got the pointer to its DTE, just return success
268 // It's not loaded, we have to load it
269 _snprintf(FullPath
, sizeof(FullPath
), "%s%wZ", BootPath
, FilePath
);
270 Status
= WinLdrLoadImage(FullPath
, LoaderBootDriver
, &DriverBase
);
274 // Allocate a DTE for it
275 Status
= WinLdrAllocateDataTableEntry(LoadOrderListHead
, DllName
, DllName
, DriverBase
, DriverDTE
);
278 ERR("WinLdrAllocateDataTableEntry() failed\n");
282 // Modify any flags, if needed
283 (*DriverDTE
)->Flags
|= Flags
;
285 // Look for any dependencies it may have, and load them too
286 sprintf(FullPath
,"%s%s", BootPath
, DriverPath
);
287 Status
= WinLdrScanImportDescriptorTable(LoadOrderListHead
, FullPath
, *DriverDTE
);
290 ERR("WinLdrScanImportDescriptorTable() failed for %s\n", FullPath
);
298 WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock
,
302 PBOOT_DRIVER_LIST_ENTRY BootDriver
;
305 // Walk through the boot drivers list
306 NextBd
= LoaderBlock
->BootDriverListHead
.Flink
;
308 while (NextBd
!= &LoaderBlock
->BootDriverListHead
)
310 BootDriver
= CONTAINING_RECORD(NextBd
, BOOT_DRIVER_LIST_ENTRY
, Link
);
312 TRACE("BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver
->FilePath
,
313 BootDriver
->LdrEntry
, &BootDriver
->RegistryPath
);
315 // Paths are relative (FIXME: Are they always relative?)
318 Status
= WinLdrLoadDeviceDriver(&LoaderBlock
->LoadOrderListHead
,
320 &BootDriver
->FilePath
,
322 &BootDriver
->LdrEntry
);
324 // If loading failed - cry loudly
325 //FIXME: Maybe remove it from the list and try to continue?
328 UiMessageBox("Can't load boot driver!");
332 // Convert the RegistryPath and DTE addresses to VA since we are not going to use it anymore
333 BootDriver
->RegistryPath
.Buffer
= PaToVa(BootDriver
->RegistryPath
.Buffer
);
334 BootDriver
->FilePath
.Buffer
= PaToVa(BootDriver
->FilePath
.Buffer
);
335 BootDriver
->LdrEntry
= PaToVa(BootDriver
->LdrEntry
);
337 NextBd
= BootDriver
->Link
.Flink
;
344 WinLdrLoadModule(PCSTR ModuleName
,
346 TYPE_OF_MEMORY MemoryType
)
350 FILEINFORMATION FileInfo
;
355 //CHAR ProgressString[256];
357 /* Inform user we are loading files */
358 //sprintf(ProgressString, "Loading %s...", FileName);
359 //UiDrawProgressBarCenter(1, 100, ProgressString);
361 TRACE("Loading module %s\n", ModuleName
);
364 /* Open the image file */
365 Status
= ArcOpen((PCHAR
)ModuleName
, OpenReadOnly
, &FileId
);
366 if (Status
!= ESUCCESS
)
368 /* In case of errors, we just return, without complaining to the user */
372 /* Get this file's size */
373 Status
= ArcGetFileInformation(FileId
, &FileInfo
);
374 if (Status
!= ESUCCESS
)
379 FileSize
= FileInfo
.EndingAddress
.LowPart
;
382 /* Allocate memory */
383 PhysicalBase
= MmAllocateMemoryWithType(FileSize
, MemoryType
);
384 if (PhysicalBase
== NULL
)
390 /* Load whole file */
391 Status
= ArcRead(FileId
, PhysicalBase
, FileSize
, &BytesRead
);
393 if (Status
!= ESUCCESS
)
398 TRACE("Loaded %s at 0x%x with size 0x%x\n", ModuleName
, PhysicalBase
, FileSize
);
404 WinLdrDetectVersion()
411 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server",
413 if (rc
!= ERROR_SUCCESS
)
415 // Key doesn't exist; assume NT 4.0
416 return _WIN32_WINNT_NT4
;
419 // We may here want to read the value of ProductVersion
420 return _WIN32_WINNT_WS03
;
426 PLOADER_PARAMETER_BLOCK LoaderBlock
,
429 TYPE_OF_MEMORY MemoryType
,
430 PLDR_DATA_TABLE_ENTRY
*Dte
,
431 BOOLEAN IsKdTransportDll
,
435 CHAR FullFileName
[MAX_PATH
];
436 CHAR ProgressString
[256];
437 PVOID BaseAdress
= NULL
;
440 sprintf(ProgressString
, "Loading %s...", File
);
441 UiDrawProgressBarCenter(Percentage
, 100, ProgressString
);
443 strcpy(FullFileName
, Path
);
444 strcat(FullFileName
, "SYSTEM32\\");
445 strcat(FullFileName
, File
);
447 Status
= WinLdrLoadImage(FullFileName
, MemoryType
, &BaseAdress
);
450 TRACE("Loading %s failed\n", File
);
453 TRACE("%s loaded successfully at %p\n", File
, BaseAdress
);
455 strcpy(FullFileName
, "WINDOWS\\SYSTEM32\\");
456 strcat(FullFileName
, File
);
458 * Cheat about the base DLL name if we are loading
459 * the Kernel Debugger Transport DLL, to make the
462 Status
= WinLdrAllocateDataTableEntry(&LoaderBlock
->LoadOrderListHead
,
463 (IsKdTransportDll
? "KDCOM.DLL" : File
),
473 LoadWindowsCore(IN USHORT OperatingSystemVersion
,
474 IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock
,
475 IN LPCSTR BootOptions
,
477 IN OUT PLDR_DATA_TABLE_ENTRY
* KernelDTE
)
480 CHAR DirPath
[MAX_PATH
];
481 CHAR KdTransportDllName
[MAX_PATH
];
482 PLDR_DATA_TABLE_ENTRY HalDTE
, KdComDTE
= NULL
;
484 if (!KernelDTE
) return FALSE
;
486 /* Load the Kernel */
487 LoadModule(LoaderBlock
, BootPath
, "NTOSKRNL.EXE", LoaderSystemCode
, KernelDTE
, FALSE
, 30);
490 LoadModule(LoaderBlock
, BootPath
, "HAL.DLL", LoaderHalCode
, &HalDTE
, FALSE
, 45);
492 /* Load the Kernel Debugger Transport DLL */
493 if (OperatingSystemVersion
> _WIN32_WINNT_WIN2K
)
496 * According to http://www.nynaeve.net/?p=173 :
497 * "[...] Another enhancement that could be done Microsoft-side would be
498 * a better interface for replacing KD transport modules. Right now, due
499 * to the fact that ntoskrnl is static linked to KDCOM.DLL, the OS loader
500 * has a hardcoded hack that interprets the KD type in the OS loader options,
501 * loads one of the (hardcoded filenames) "kdcom.dll", "kd1394.dll", or
502 * "kdusb2.dll" modules, and inserts them into the loaded module list under
503 * the name "kdcom.dll". [...]"
507 * This loop replaces a dumb call to strstr(..., "DEBUGPORT=").
508 * Indeed I want it to be case-insensitive to allow "debugport="
509 * or "DeBuGpOrT=" or... , and I don't want it to match malformed
510 * command-line options, such as:
512 * "...foo DEBUGPORT=xxx bar..."
513 * "...foo/DEBUGPORT=xxx bar..."
514 * "...foo/DEBUGPORT=bar..."
516 * i.e. the "DEBUGPORT=" switch must start with a slash and be separated
517 * from the rest by whitespace, unless it begins the command-line, e.g.:
519 * "/DEBUGPORT=COM1 foo...bar..."
520 * "...foo /DEBUGPORT=USB bar..."
522 * "...foo /DEBUGPORT= bar..."
523 * (in that case, we default the port to COM).
527 /* Skip possible initial whitespace */
528 BootOptions
+= strspn(BootOptions
, " \t");
530 /* Check whether a new commutator starts and it is the DEBUGPORT one */
531 if (*BootOptions
!= '/' || _strnicmp(++BootOptions
, "DEBUGPORT=", 10) != 0)
533 /* Search for another whitespace */
534 BootOptions
= strpbrk(BootOptions
, " \t");
539 /* We found the DEBUGPORT commutator. Move to the port name. */
548 * We have found the DEBUGPORT commutator. Parse the port name.
549 * Format: /DEBUGPORT=COM1 or /DEBUGPORT=FILE:\Device\HarddiskX\PartitionY\debug.log or /DEBUGPORT=FOO
550 * If we only have /DEBUGPORT= (i.e. without any port name), defaults it to "COM".
552 strcpy(KdTransportDllName
, "KD");
553 if (_strnicmp(BootOptions
, "COM", 3) == 0 && '0' <= BootOptions
[3] && BootOptions
[3] <= '9')
555 strncat(KdTransportDllName
, BootOptions
, 3);
559 size_t i
= strcspn(BootOptions
, " \t:"); /* Skip valid separators: whitespace or colon */
561 strcat(KdTransportDllName
, "COM");
563 strncat(KdTransportDllName
, BootOptions
, i
);
565 strcat(KdTransportDllName
, ".DLL");
566 _strupr(KdTransportDllName
);
569 * Load the transport DLL. Specify it to LoadModule so that it can
570 * change the base DLL name of the loaded transport DLL to the default
571 * "KDCOM.DLL" name, to make the PE loader happy.
573 LoadModule(LoaderBlock
, BootPath
, KdTransportDllName
, LoaderSystemCode
, &KdComDTE
, TRUE
, 60);
577 /* Load all referenced DLLs for Kernel, HAL and Kernel Debugger Transport DLL */
578 strcpy(DirPath
, BootPath
);
579 strcat(DirPath
, "system32\\");
580 Status
= WinLdrScanImportDescriptorTable(&LoaderBlock
->LoadOrderListHead
, DirPath
, *KernelDTE
);
581 Status
&= WinLdrScanImportDescriptorTable(&LoaderBlock
->LoadOrderListHead
, DirPath
, HalDTE
);
584 Status
&= WinLdrScanImportDescriptorTable(&LoaderBlock
->LoadOrderListHead
, DirPath
, KdComDTE
);
591 LoadAndBootWindows(IN OperatingSystemItem
* OperatingSystem
,
592 IN USHORT OperatingSystemVersion
)
595 PCSTR SectionName
= OperatingSystem
->SystemPartition
;
596 CHAR SettingsValue
[80];
598 CHAR BootPath
[MAX_PATH
];
599 CHAR FileName
[MAX_PATH
];
600 CHAR BootOptions
[256];
603 PLOADER_PARAMETER_BLOCK LoaderBlock
;
605 // Get OS setting value
606 SettingsValue
[0] = ANSI_NULL
;
607 IniOpenSection("Operating Systems", &SectionId
);
608 IniReadSettingByName(SectionId
, SectionName
, SettingsValue
, sizeof(SettingsValue
));
610 // Open the operating system section
611 // specified in the .ini file
612 HasSection
= IniOpenSection(SectionName
, &SectionId
);
615 UiDrawProgressBarCenter(1, 100, "Loading NT...");
617 /* Read the system path is set in the .ini file */
619 !IniReadSettingByName(SectionId
, "SystemPath", BootPath
, sizeof(BootPath
)))
621 strcpy(BootPath
, SectionName
);
624 /* Special case for LiveCD */
625 if (!_strnicmp(BootPath
, "LiveCD", strlen("LiveCD")))
627 strcpy(FileName
, BootPath
+ strlen("LiveCD"));
628 MachDiskGetBootPath(BootPath
, sizeof(BootPath
));
629 strcat(BootPath
, FileName
);
632 /* Append a backslash */
633 if ((strlen(BootPath
)==0) || BootPath
[strlen(BootPath
)] != '\\')
634 strcat(BootPath
, "\\");
636 /* Read booting options */
637 if (!HasSection
|| !IniReadSettingByName(SectionId
, "Options", BootOptions
, sizeof(BootOptions
)))
639 /* Get options after the title */
640 PCSTR p
= SettingsValue
;
641 while (*p
== ' ' || *p
== '"')
643 while (*p
!= '\0' && *p
!= '"')
645 strcpy(BootOptions
, p
);
646 TRACE("BootOptions: '%s'\n", BootOptions
);
649 /* Append boot-time options */
650 AppendBootTimeOptions(BootOptions
);
652 /* Check if a ramdisk file was given */
653 File
= strstr(BootOptions
, "/RDPATH=");
656 /* Copy the file name and everything else after it */
657 strcpy(FileName
, File
+ 8);
660 *strstr(FileName
, " ") = ANSI_NULL
;
662 /* Load the ramdisk */
663 RamDiskLoadVirtualFile(FileName
);
666 /* Let user know we started loading */
667 //UiDrawStatusText("Loading...");
669 TRACE("BootPath: '%s'\n", BootPath
);
671 /* Allocate and minimalistic-initialize LPB */
672 AllocateAndInitLPB(&LoaderBlock
);
676 UiDrawProgressBarCenter(15, 100, "Loading system hive...");
677 Status
= WinLdrInitSystemHive(LoaderBlock
, BootPath
);
678 TRACE("SYSTEM hive %s\n", (Status
? "loaded" : "not loaded"));
680 /* Load NLS data, OEM font, and prepare boot drivers list */
681 Status
= WinLdrScanSystemHive(LoaderBlock
, BootPath
);
682 TRACE("SYSTEM hive %s\n", (Status
? "scanned" : "not scanned"));
685 LoadAndBootWindowsCommon(OperatingSystemVersion
,
693 LoadAndBootWindowsCommon(
694 USHORT OperatingSystemVersion
,
695 PLOADER_PARAMETER_BLOCK LoaderBlock
,
700 PLOADER_PARAMETER_BLOCK LoaderBlockVA
;
702 PLDR_DATA_TABLE_ENTRY KernelDTE
;
703 KERNEL_ENTRY_POINT KiSystemStartup
;
705 TRACE("LoadAndBootWindowsCommon()\n");
708 /* Setup redirection support */
709 WinLdrSetupEms((PCHAR
)BootOptions
);
712 /* Convert BootPath to SystemRoot */
713 SystemRoot
= strstr(BootPath
, "\\");
715 /* Detect hardware */
716 LoaderBlock
->ConfigurationRoot
= MachHwDetect();
718 if (OperatingSystemVersion
== 0)
719 OperatingSystemVersion
= WinLdrDetectVersion();
721 /* Load the operating system core: the Kernel, the HAL and the Kernel Debugger Transport DLL */
722 Status
= LoadWindowsCore(OperatingSystemVersion
,
729 UiMessageBox("Error loading NTOS core.");
733 /* Load boot drivers */
735 UiDrawProgressBarCenter(100, 100, "Loading boot drivers...");
736 Status
= WinLdrLoadBootDrivers(LoaderBlock
, BootPath
);
737 TRACE("Boot drivers loaded with status %d\n", Status
);
739 /* Initialize Phase 1 - no drivers loading anymore */
740 WinLdrInitializePhase1(LoaderBlock
,
744 OperatingSystemVersion
);
746 /* Save entry-point pointer and Loader block VAs */
747 KiSystemStartup
= (KERNEL_ENTRY_POINT
)KernelDTE
->EntryPoint
;
748 LoaderBlockVA
= PaToVa(LoaderBlock
);
750 /* "Stop all motors", change videomode */
751 MachPrepareForReactOS(Setup
);
753 /* Cleanup ini file */
757 //DumpMemoryAllocMap();
759 /* Do the machine specific initialization */
760 WinLdrSetupMachineDependent(LoaderBlock
);
762 /* Map pages and create memory descriptors */
763 WinLdrSetupMemoryLayout(LoaderBlock
);
765 /* Set processor context */
766 WinLdrSetProcessorContext();
768 /* Save final value of LoaderPagesSpanned */
769 LoaderBlock
->Extension
->LoaderPagesSpanned
= LoaderPagesSpanned
;
771 TRACE("Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
772 KiSystemStartup
, LoaderBlockVA
);
774 // Zero KI_USER_SHARED_DATA page
775 memset((PVOID
)KI_USER_SHARED_DATA
, 0, MM_PAGE_SIZE
);
777 WinLdrpDumpMemoryDescriptors(LoaderBlockVA
);
778 WinLdrpDumpBootDriver(LoaderBlockVA
);
780 WinLdrpDumpArcDisks(LoaderBlockVA
);
783 //FIXME: If I substitute this debugging checkpoint, GCC will "optimize away" the code below
785 /*asm(".intel_syntax noprefix\n");
788 asm(".att_syntax\n");*/
791 (*KiSystemStartup
)(LoaderBlockVA
);
795 WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock
)
798 PMEMORY_ALLOCATION_DESCRIPTOR MemoryDescriptor
;
800 NextMd
= LoaderBlock
->MemoryDescriptorListHead
.Flink
;
802 while (NextMd
!= &LoaderBlock
->MemoryDescriptorListHead
)
804 MemoryDescriptor
= CONTAINING_RECORD(NextMd
, MEMORY_ALLOCATION_DESCRIPTOR
, ListEntry
);
806 TRACE("BP %08X PC %04X MT %d\n", MemoryDescriptor
->BasePage
,
807 MemoryDescriptor
->PageCount
, MemoryDescriptor
->MemoryType
);
809 NextMd
= MemoryDescriptor
->ListEntry
.Flink
;
814 WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock
)
817 PBOOT_DRIVER_LIST_ENTRY BootDriver
;
819 NextBd
= LoaderBlock
->BootDriverListHead
.Flink
;
821 while (NextBd
!= &LoaderBlock
->BootDriverListHead
)
823 BootDriver
= CONTAINING_RECORD(NextBd
, BOOT_DRIVER_LIST_ENTRY
, Link
);
825 TRACE("BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver
->FilePath
,
826 BootDriver
->LdrEntry
, &BootDriver
->RegistryPath
);
828 NextBd
= BootDriver
->Link
.Flink
;
833 WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock
)
836 PARC_DISK_SIGNATURE ArcDisk
;
838 NextBd
= LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
.Flink
;
840 while (NextBd
!= &LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
)
842 ArcDisk
= CONTAINING_RECORD(NextBd
, ARC_DISK_SIGNATURE
, ListEntry
);
844 TRACE("ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
845 ArcDisk
->ArcName
, ArcDisk
->CheckSum
, ArcDisk
->Signature
);
847 NextBd
= ArcDisk
->ListEntry
.Flink
;