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>
28 void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock
,
33 //FIXME: Do a better way to retrieve Arc disk information
34 extern ULONG reactos_disk_count
;
35 extern ARC_DISK_SIGNATURE reactos_arc_disk_info
[];
36 extern char reactos_arc_strings
[32][256];
38 extern BOOLEAN UseRealHeap
;
39 extern ULONG LoaderPagesSpanned
;
40 extern BOOLEAN AcpiPresent
;
42 extern HEADLESS_LOADER_BLOCK LoaderRedirectionInformation
;
43 extern BOOLEAN WinLdrTerminalConnected
;
44 extern void WinLdrSetupEms(IN PCHAR BootOptions
);
47 WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock
,
49 OUT PLDR_DATA_TABLE_ENTRY
*LoadedEntry
);
52 VOID
DumpMemoryAllocMap(VOID
);
53 VOID
WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock
);
54 VOID
WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock
);
55 VOID
WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock
);
60 AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK
*OutLoaderBlock
)
62 PLOADER_PARAMETER_BLOCK LoaderBlock
;
64 /* Allocate and zero-init the LPB */
65 LoaderBlock
= MmHeapAlloc(sizeof(LOADER_PARAMETER_BLOCK
));
66 RtlZeroMemory(LoaderBlock
, sizeof(LOADER_PARAMETER_BLOCK
));
68 /* Init three critical lists, used right away */
69 InitializeListHead(&LoaderBlock
->LoadOrderListHead
);
70 InitializeListHead(&LoaderBlock
->MemoryDescriptorListHead
);
71 InitializeListHead(&LoaderBlock
->BootDriverListHead
);
73 /* Alloc space for NLS (it will be converted to VA in WinLdrLoadNLS) */
74 LoaderBlock
->NlsData
= MmHeapAlloc(sizeof(NLS_DATA_BLOCK
));
75 if (LoaderBlock
->NlsData
== NULL
)
77 UiMessageBox("Failed to allocate memory for NLS table data!");
80 RtlZeroMemory(LoaderBlock
->NlsData
, sizeof(NLS_DATA_BLOCK
));
82 *OutLoaderBlock
= LoaderBlock
;
87 WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock
,
93 /* Examples of correct options and paths */
94 //CHAR Options[] = "/DEBUGPORT=COM1 /BAUDRATE=115200";
95 //CHAR Options[] = "/NODEBUG";
96 //CHAR SystemRoot[] = "\\WINNT\\";
97 //CHAR ArcBoot[] = "multi(0)disk(0)rdisk(0)partition(1)";
99 CHAR HalPath
[] = "\\";
102 ULONG i
, PathSeparator
;
103 PLOADER_PARAMETER_EXTENSION Extension
;
105 /* Construct SystemRoot and ArcBoot from SystemPath */
106 PathSeparator
= strstr(BootPath
, "\\") - BootPath
;
107 strncpy(ArcBoot
, BootPath
, PathSeparator
);
108 ArcBoot
[PathSeparator
] = 0;
110 DPRINTM(DPRINT_WINDOWS
, "ArcBoot: %s\n", ArcBoot
);
111 DPRINTM(DPRINT_WINDOWS
, "SystemRoot: %s\n", SystemRoot
);
112 DPRINTM(DPRINT_WINDOWS
, "Options: %s\n", Options
);
114 /* Fill Arc BootDevice */
115 LoaderBlock
->ArcBootDeviceName
= MmHeapAlloc(strlen(ArcBoot
)+1);
116 strcpy(LoaderBlock
->ArcBootDeviceName
, ArcBoot
);
117 LoaderBlock
->ArcBootDeviceName
= PaToVa(LoaderBlock
->ArcBootDeviceName
);
119 /* Fill Arc HalDevice, it matches ArcBoot path */
120 LoaderBlock
->ArcHalDeviceName
= MmHeapAlloc(strlen(ArcBoot
)+1);
121 strcpy(LoaderBlock
->ArcHalDeviceName
, ArcBoot
);
122 LoaderBlock
->ArcHalDeviceName
= PaToVa(LoaderBlock
->ArcHalDeviceName
);
124 /* Fill SystemRoot */
125 LoaderBlock
->NtBootPathName
= MmHeapAlloc(strlen(SystemRoot
)+1);
126 strcpy(LoaderBlock
->NtBootPathName
, SystemRoot
);
127 LoaderBlock
->NtBootPathName
= PaToVa(LoaderBlock
->NtBootPathName
);
129 /* Fill NtHalPathName */
130 LoaderBlock
->NtHalPathName
= MmHeapAlloc(strlen(HalPath
)+1);
131 strcpy(LoaderBlock
->NtHalPathName
, HalPath
);
132 LoaderBlock
->NtHalPathName
= PaToVa(LoaderBlock
->NtHalPathName
);
134 /* Fill load options */
135 LoaderBlock
->LoadOptions
= MmHeapAlloc(strlen(Options
)+1);
136 strcpy(LoaderBlock
->LoadOptions
, Options
);
137 LoaderBlock
->LoadOptions
= PaToVa(LoaderBlock
->LoadOptions
);
140 LoaderBlock
->ArcDiskInformation
= (PARC_DISK_INFORMATION
)MmHeapAlloc(sizeof(ARC_DISK_INFORMATION
));
141 InitializeListHead(&LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
);
143 /* Convert ARC disk information from freeldr to a correct format */
144 for (i
= 0; i
< reactos_disk_count
; i
++)
146 PARC_DISK_SIGNATURE ArcDiskInfo
;
148 /* Get the ARC structure */
149 ArcDiskInfo
= (PARC_DISK_SIGNATURE
)MmHeapAlloc(sizeof(ARC_DISK_SIGNATURE
));
150 RtlZeroMemory(ArcDiskInfo
, sizeof(ARC_DISK_SIGNATURE
));
152 /* Copy the data over */
153 ArcDiskInfo
->Signature
= reactos_arc_disk_info
[i
].Signature
;
154 ArcDiskInfo
->CheckSum
= reactos_arc_disk_info
[i
].CheckSum
;
156 /* Copy the ARC Name */
157 ArcDiskInfo
->ArcName
= (PCHAR
)MmHeapAlloc(sizeof(CHAR
)*256);
158 strcpy(ArcDiskInfo
->ArcName
, reactos_arc_disk_info
[i
].ArcName
);
159 ArcDiskInfo
->ArcName
= (PCHAR
)PaToVa(ArcDiskInfo
->ArcName
);
161 /* Mark partition table as valid */
162 ArcDiskInfo
->ValidPartitionTable
= TRUE
;
164 /* Insert into the list */
165 InsertTailList(&LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
,
166 &ArcDiskInfo
->ListEntry
);
169 /* Convert all list's to Virtual address */
171 /* Convert the ArcDisks list to virtual address */
172 List_PaToVa(&LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
);
173 LoaderBlock
->ArcDiskInformation
= PaToVa(LoaderBlock
->ArcDiskInformation
);
175 /* Convert configuration entries to VA */
176 ConvertConfigToVA(LoaderBlock
->ConfigurationRoot
);
177 LoaderBlock
->ConfigurationRoot
= PaToVa(LoaderBlock
->ConfigurationRoot
);
179 /* Convert all DTE into virtual addresses */
180 List_PaToVa(&LoaderBlock
->LoadOrderListHead
);
182 /* this one will be converted right before switching to
183 virtual paging mode */
184 //List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
186 /* Convert list of boot drivers */
187 List_PaToVa(&LoaderBlock
->BootDriverListHead
);
189 /* Initialize Extension now */
190 Extension
= MmHeapAlloc(sizeof(LOADER_PARAMETER_EXTENSION
));
191 if (Extension
== NULL
)
193 UiMessageBox("Failed to allocate LPB Extension!");
196 RtlZeroMemory(Extension
, sizeof(LOADER_PARAMETER_EXTENSION
));
198 /* Fill LPB extension */
199 Extension
->Size
= sizeof(LOADER_PARAMETER_EXTENSION
);
200 Extension
->MajorVersion
= (VersionToBoot
& 0xFF00) >> 8;
201 Extension
->MinorVersion
= VersionToBoot
& 0xFF;
202 Extension
->Profile
.Status
= 2;
204 /* Check if ACPI is present */
207 /* See KiRosFrldrLpbToNtLpb for details */
208 Extension
->AcpiTable
= (PVOID
)1;
212 /* Set headless block pointer */
213 if (WinLdrTerminalConnected
)
215 Extension
->HeadlessLoaderBlock
= MmHeapAlloc(sizeof(HEADLESS_LOADER_BLOCK
));
216 if (Extension
->HeadlessLoaderBlock
== NULL
)
218 UiMessageBox("Failed to allocate HLB Extension!");
223 Extension
->HeadlessLoaderBlock
,
224 &LoaderRedirectionInformation
,
225 sizeof(HEADLESS_LOADER_BLOCK
));
226 Extension
->HeadlessLoaderBlock
= PaToVa(Extension
->HeadlessLoaderBlock
);
229 /* Load drivers database */
230 strcpy(MiscFiles
, BootPath
);
231 strcat(MiscFiles
, "AppPatch\\drvmain.sdb");
232 Extension
->DrvDBImage
= PaToVa(WinLdrLoadModule(MiscFiles
,
233 &Extension
->DrvDBSize
, LoaderRegistryData
));
235 /* Convert extension and setup block pointers */
236 LoaderBlock
->Extension
= PaToVa(Extension
);
238 if (LoaderBlock
->SetupLdrBlock
)
239 LoaderBlock
->SetupLdrBlock
= PaToVa(LoaderBlock
->SetupLdrBlock
);
244 WinLdrLoadDeviceDriver(PLOADER_PARAMETER_BLOCK LoaderBlock
,
246 PUNICODE_STRING FilePath
,
248 PLDR_DATA_TABLE_ENTRY
*DriverDTE
)
251 CHAR DriverPath
[1024];
257 // Separate the path to file name and directory path
258 _snprintf(DriverPath
, sizeof(DriverPath
), "%wZ", FilePath
);
259 DriverNamePos
= strrchr(DriverPath
, '\\');
260 if (DriverNamePos
!= NULL
)
263 strcpy(DllName
, DriverNamePos
+1);
265 // Cut out the name from the path
266 *(DriverNamePos
+1) = 0;
270 // There is no directory in the path
271 strcpy(DllName
, DriverPath
);
275 DPRINTM(DPRINT_WINDOWS
, "DriverPath: %s, DllName: %s, LPB %p\n", DriverPath
, DllName
, LoaderBlock
);
278 // Check if driver is already loaded
279 Status
= WinLdrCheckForLoadedDll(LoaderBlock
, DllName
, DriverDTE
);
282 // We've got the pointer to its DTE, just return success
286 // It's not loaded, we have to load it
287 _snprintf(FullPath
, sizeof(FullPath
), "%s%wZ", BootPath
, FilePath
);
288 Status
= WinLdrLoadImage(FullPath
, LoaderBootDriver
, &DriverBase
);
292 // Allocate a DTE for it
293 Status
= WinLdrAllocateDataTableEntry(LoaderBlock
, DllName
, DllName
, DriverBase
, DriverDTE
);
296 DPRINTM(DPRINT_WINDOWS
, "WinLdrAllocateDataTableEntry() failed\n");
300 // Modify any flags, if needed
301 (*DriverDTE
)->Flags
|= Flags
;
303 // Look for any dependencies it may have, and load them too
304 sprintf(FullPath
,"%s%s", BootPath
, DriverPath
);
305 Status
= WinLdrScanImportDescriptorTable(LoaderBlock
, FullPath
, *DriverDTE
);
308 DPRINTM(DPRINT_WINDOWS
, "WinLdrScanImportDescriptorTable() failed for %s\n",
317 WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock
,
321 PBOOT_DRIVER_LIST_ENTRY BootDriver
;
324 // Walk through the boot drivers list
325 NextBd
= LoaderBlock
->BootDriverListHead
.Flink
;
327 while (NextBd
!= &LoaderBlock
->BootDriverListHead
)
329 BootDriver
= CONTAINING_RECORD(NextBd
, BOOT_DRIVER_LIST_ENTRY
, Link
);
331 DPRINTM(DPRINT_WINDOWS
, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver
->FilePath
,
332 BootDriver
->LdrEntry
, &BootDriver
->RegistryPath
);
334 // Paths are relative (FIXME: Are they always relative?)
337 Status
= WinLdrLoadDeviceDriver(LoaderBlock
, BootPath
, &BootDriver
->FilePath
,
338 0, &BootDriver
->LdrEntry
);
340 // If loading failed - cry loudly
341 //FIXME: Maybe remove it from the list and try to continue?
344 UiMessageBox("Can't load boot driver!");
348 // Convert the RegistryPath and DTE addresses to VA since we are not going to use it anymore
349 BootDriver
->RegistryPath
.Buffer
= PaToVa(BootDriver
->RegistryPath
.Buffer
);
350 BootDriver
->FilePath
.Buffer
= PaToVa(BootDriver
->FilePath
.Buffer
);
351 BootDriver
->LdrEntry
= PaToVa(BootDriver
->LdrEntry
);
353 NextBd
= BootDriver
->Link
.Flink
;
359 PVOID
WinLdrLoadModule(PCSTR ModuleName
, ULONG
*Size
,
360 TYPE_OF_MEMORY MemoryType
)
364 FILEINFORMATION FileInfo
;
369 //CHAR ProgressString[256];
371 /* Inform user we are loading files */
372 //sprintf(ProgressString, "Loading %s...", FileName);
373 //UiDrawProgressBarCenter(1, 100, ProgressString);
375 DPRINTM(DPRINT_WINDOWS
, "Loading module %s\n", ModuleName
);
378 /* Open the image file */
379 Status
= ArcOpen((PCHAR
)ModuleName
, OpenReadOnly
, &FileId
);
380 if (Status
!= ESUCCESS
)
382 /* In case of errors, we just return, without complaining to the user */
386 /* Get this file's size */
387 Status
= ArcGetFileInformation(FileId
, &FileInfo
);
388 if (Status
!= ESUCCESS
)
393 FileSize
= FileInfo
.EndingAddress
.LowPart
;
396 /* Allocate memory */
397 PhysicalBase
= MmAllocateMemoryWithType(FileSize
, MemoryType
);
398 if (PhysicalBase
== NULL
)
404 /* Load whole file */
405 Status
= ArcRead(FileId
, PhysicalBase
, FileSize
, &BytesRead
);
407 if (Status
!= ESUCCESS
)
412 DPRINTM(DPRINT_WINDOWS
, "Loaded %s at 0x%x with size 0x%x\n", ModuleName
, PhysicalBase
, FileSize
);
419 WinLdrDetectVersion()
426 L
"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server",
428 if (rc
!= ERROR_SUCCESS
)
430 // Key doesn't exist; assume NT 4.0
431 return _WIN32_WINNT_NT4
;
434 // We may here want to read the value of ProductVersion
435 return _WIN32_WINNT_WS03
;
440 LoadAndBootWindows(PCSTR OperatingSystemName
,
442 USHORT OperatingSystemVersion
)
445 char FullPath
[MAX_PATH
], SystemRoot
[MAX_PATH
], BootPath
[MAX_PATH
];
446 CHAR FileName
[MAX_PATH
];
447 CHAR BootOptions
[256];
450 PVOID NtosBase
= NULL
, HalBase
= NULL
, KdComBase
= NULL
;
453 PLOADER_PARAMETER_BLOCK LoaderBlock
, LoaderBlockVA
;
454 KERNEL_ENTRY_POINT KiSystemStartup
;
455 PLDR_DATA_TABLE_ENTRY KernelDTE
, HalDTE
, KdComDTE
= NULL
;
461 CHAR ProgressString
[256];
463 // Open the operating system section
464 // specified in the .ini file
465 HasSection
= IniOpenSection(OperatingSystemName
, &SectionId
);
468 UiDrawStatusText("Detecting Hardware...");
469 sprintf(ProgressString
, "Loading NT...");
470 UiDrawProgressBarCenter(1, 100, ProgressString
);
472 /* Read the system path is set in the .ini file */
473 if (!HasSection
|| !IniReadSettingByName(SectionId
, "SystemPath", FullPath
, sizeof(FullPath
)))
475 strcpy(FullPath
, OperatingSystemName
);
478 /* Special case for LiveCD */
479 if (!_strnicmp(FullPath
, "LiveCD", strlen("LiveCD")))
481 strcpy(BootPath
, FullPath
+ strlen("LiveCD"));
482 MachDiskGetBootPath(FullPath
, sizeof(FullPath
));
483 strcat(FullPath
, BootPath
);
486 /* Convert FullPath to SystemRoot */
487 PathSeparator
= strstr(FullPath
, "\\");
488 strcpy(SystemRoot
, PathSeparator
);
489 strcat(SystemRoot
, "\\");
491 /* Read booting options */
492 if (!HasSection
|| !IniReadSettingByName(SectionId
, "Options", BootOptions
, sizeof(BootOptions
)))
494 /* Get options after the title */
495 const CHAR
*p
= SettingsValue
;
496 while (*p
== ' ' || *p
== '"')
498 while (*p
!= '\0' && *p
!= '"')
500 strcpy(BootOptions
, p
);
501 DPRINTM(DPRINT_WINDOWS
,"BootOptions: '%s'\n", BootOptions
);
504 /* Append boot-time options */
505 AppendBootTimeOptions(BootOptions
);
508 // Check if a ramdisk file was given
510 File
= strstr(BootOptions
, "/RDPATH=");
514 // Copy the file name and everything else after it
516 strcpy(FileName
, File
+ 8);
521 *strstr(FileName
, " ") = ANSI_NULL
;
526 RamDiskLoadVirtualFile(FileName
);
529 /* Let user know we started loading */
530 //UiDrawStatusText("Loading...");
532 /* append a backslash */
533 strcpy(BootPath
, FullPath
);
534 if ((strlen(BootPath
)==0) ||
535 BootPath
[strlen(BootPath
)] != '\\')
536 strcat(BootPath
, "\\");
538 DPRINTM(DPRINT_WINDOWS
,"BootPath: '%s'\n", BootPath
);
540 /* Allocate and minimalistic-initialize LPB */
541 AllocateAndInitLPB(&LoaderBlock
);
544 /* Setup redirection support */
545 WinLdrSetupEms(BootOptions
);
547 /* Detect hardware */
549 LoaderBlock
->ConfigurationRoot
= MachHwDetect();
551 sprintf(ProgressString
, "Loading system hive...");
553 UiDrawProgressBarCenter(15, 100, ProgressString
);
556 Status
= WinLdrInitSystemHive(LoaderBlock
, BootPath
);
557 DPRINTM(DPRINT_WINDOWS
, "SYSTEM hive loaded with status %d\n", Status
);
559 if (OperatingSystemVersion
== 0)
560 OperatingSystemVersion
= WinLdrDetectVersion();
563 strcpy(FileName
, BootPath
);
564 strcat(FileName
, "SYSTEM32\\NTOSKRNL.EXE");
565 sprintf(ProgressString
, "Loading %s...", strchr(FileName
, '\\') + 1);
567 UiDrawProgressBarCenter(30, 100, ProgressString
);
568 Status
= WinLdrLoadImage(FileName
, LoaderSystemCode
, &NtosBase
);
569 DPRINTM(DPRINT_WINDOWS
, "Ntos loaded with status %d at %p\n", Status
, NtosBase
);
572 strcpy(FileName
, BootPath
);
573 strcat(FileName
, "SYSTEM32\\HAL.DLL");
574 sprintf(ProgressString
, "Loading %s...", strchr(FileName
, '\\') + 1);
576 UiDrawProgressBarCenter(45, 100, ProgressString
);
577 Status
= WinLdrLoadImage(FileName
, LoaderHalCode
, &HalBase
);
578 DPRINTM(DPRINT_WINDOWS
, "HAL loaded with status %d at %p\n", Status
, HalBase
);
580 /* Load kernel-debugger support dll */
581 if (OperatingSystemVersion
> _WIN32_WINNT_WIN2K
)
583 strcpy(FileName
, BootPath
);
584 strcat(FileName
, "SYSTEM32\\KDCOM.DLL");
585 sprintf(ProgressString
, "Loading %s...", strchr(FileName
, '\\') + 1);
587 UiDrawProgressBarCenter(60, 100, ProgressString
);
588 Status
= WinLdrLoadImage(FileName
, LoaderBootDriver
, &KdComBase
);
589 DPRINTM(DPRINT_WINDOWS
, "KdCom loaded with status %d at %p\n", Status
, KdComBase
);
592 /* Allocate data table entries for above-loaded modules */
593 WinLdrAllocateDataTableEntry(LoaderBlock
, "ntoskrnl.exe",
594 "WINDOWS\\SYSTEM32\\NTOSKRNL.EXE", NtosBase
, &KernelDTE
);
595 WinLdrAllocateDataTableEntry(LoaderBlock
, "hal.dll",
596 "WINDOWS\\SYSTEM32\\HAL.DLL", HalBase
, &HalDTE
);
597 if (OperatingSystemVersion
> _WIN32_WINNT_WIN2K
)
599 WinLdrAllocateDataTableEntry(LoaderBlock
, "kdcom.dll",
600 "WINDOWS\\SYSTEM32\\KDCOM.DLL", KdComBase
, &KdComDTE
);
603 /* Load all referenced DLLs for kernel, HAL and kdcom.dll */
604 strcpy(FileName
, BootPath
);
605 strcat(FileName
, "SYSTEM32\\");
606 WinLdrScanImportDescriptorTable(LoaderBlock
, FileName
, KernelDTE
);
607 WinLdrScanImportDescriptorTable(LoaderBlock
, FileName
, HalDTE
);
609 WinLdrScanImportDescriptorTable(LoaderBlock
, FileName
, KdComDTE
);
611 sprintf(ProgressString
, "Loading NLS and OEM fonts...");
613 UiDrawProgressBarCenter(80, 100, ProgressString
);
614 /* Load NLS data, OEM font, and prepare boot drivers list */
615 Status
= WinLdrScanSystemHive(LoaderBlock
, BootPath
);
616 DPRINTM(DPRINT_WINDOWS
, "SYSTEM hive scanned with status %d\n", Status
);
618 /* Load boot drivers */
619 sprintf(ProgressString
, "Loading boot drivers...");
621 UiDrawProgressBarCenter(100, 100, ProgressString
);
622 Status
= WinLdrLoadBootDrivers(LoaderBlock
, BootPath
);
623 DPRINTM(DPRINT_WINDOWS
, "Boot drivers loaded with status %d\n", Status
);
625 /* Alloc PCR, TSS, do magic things with the GDT/IDT */
626 WinLdrSetupForNt(LoaderBlock
, &GdtIdt
, &PcrBasePage
, &TssBasePage
);
628 /* Initialize Phase 1 - no drivers loading anymore */
629 WinLdrInitializePhase1(LoaderBlock
, BootOptions
, SystemRoot
, BootPath
, OperatingSystemVersion
);
631 /* Save entry-point pointer and Loader block VAs */
632 KiSystemStartup
= (KERNEL_ENTRY_POINT
)KernelDTE
->EntryPoint
;
633 LoaderBlockVA
= PaToVa(LoaderBlock
);
635 /* "Stop all motors", change videomode */
636 if (OperatingSystemVersion
< _WIN32_WINNT_WIN2K
)
637 MachPrepareForReactOS(TRUE
);
639 MachPrepareForReactOS(FALSE
);
642 //DumpMemoryAllocMap();
644 /* Turn on paging mode of CPU*/
645 WinLdrTurnOnPaging(LoaderBlock
, PcrBasePage
, TssBasePage
, GdtIdt
);
647 /* Save final value of LoaderPagesSpanned */
648 LoaderBlockVA
->Extension
->LoaderPagesSpanned
= LoaderPagesSpanned
;
650 DPRINTM(DPRINT_WINDOWS
, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
651 KiSystemStartup
, LoaderBlockVA
);
653 WinLdrpDumpMemoryDescriptors(LoaderBlockVA
);
654 WinLdrpDumpBootDriver(LoaderBlockVA
);
655 WinLdrpDumpArcDisks(LoaderBlockVA
);
657 //FIXME: If I substitute this debugging checkpoint, GCC will "optimize away" the code below
659 /*asm(".intel_syntax noprefix\n");
662 asm(".att_syntax\n");*/
665 (*KiSystemStartup
)(LoaderBlockVA
);
671 WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock
)
674 PMEMORY_ALLOCATION_DESCRIPTOR MemoryDescriptor
;
676 NextMd
= LoaderBlock
->MemoryDescriptorListHead
.Flink
;
678 while (NextMd
!= &LoaderBlock
->MemoryDescriptorListHead
)
680 MemoryDescriptor
= CONTAINING_RECORD(NextMd
, MEMORY_ALLOCATION_DESCRIPTOR
, ListEntry
);
682 DPRINTM(DPRINT_WINDOWS
, "BP %08X PC %04X MT %d\n", MemoryDescriptor
->BasePage
,
683 MemoryDescriptor
->PageCount
, MemoryDescriptor
->MemoryType
);
685 NextMd
= MemoryDescriptor
->ListEntry
.Flink
;
690 WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock
)
693 PBOOT_DRIVER_LIST_ENTRY BootDriver
;
695 NextBd
= LoaderBlock
->BootDriverListHead
.Flink
;
697 while (NextBd
!= &LoaderBlock
->BootDriverListHead
)
699 BootDriver
= CONTAINING_RECORD(NextBd
, BOOT_DRIVER_LIST_ENTRY
, Link
);
701 DPRINTM(DPRINT_WINDOWS
, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver
->FilePath
,
702 BootDriver
->LdrEntry
, &BootDriver
->RegistryPath
);
704 NextBd
= BootDriver
->Link
.Flink
;
709 WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock
)
712 PARC_DISK_SIGNATURE ArcDisk
;
714 NextBd
= LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
.Flink
;
716 while (NextBd
!= &LoaderBlock
->ArcDiskInformation
->DiskSignatureListHead
)
718 ArcDisk
= CONTAINING_RECORD(NextBd
, ARC_DISK_SIGNATURE
, ListEntry
);
720 DPRINTM(DPRINT_WINDOWS
, "ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
721 ArcDisk
->ArcName
, ArcDisk
->CheckSum
, ArcDisk
->Signature
);
723 NextBd
= ArcDisk
->ListEntry
.Flink
;