76622ee940d73e098064eb9be8af70d4f6b378d0
[reactos.git] / reactos / boot / freeldr / freeldr / windows / winldr.c
1 /*
2 * FreeLoader
3 *
4 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
5 * Copyright (C) 2006 Aleksey Bragin <aleksey@reactos.org>
6 *
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.
11 *
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.
16 *
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.
20 */
21
22 #include <freeldr.h>
23
24 #include <ndk/ldrtypes.h>
25 #include <debug.h>
26
27 // TODO: Move to .h
28 void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock,
29 PVOID *GdtIdt,
30 ULONG *PcrBasePage,
31 ULONG *TssBasePage);
32
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];
37
38 extern BOOLEAN UseRealHeap;
39 extern ULONG LoaderPagesSpanned;
40
41 BOOLEAN
42 WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock,
43 IN PCH DllName,
44 OUT PLDR_DATA_TABLE_ENTRY *LoadedEntry);
45
46 // debug stuff
47 VOID DumpMemoryAllocMap(VOID);
48 VOID WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock);
49 VOID WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock);
50 VOID WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock);
51
52
53 // Init "phase 0"
54 VOID
55 AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock)
56 {
57 PLOADER_PARAMETER_BLOCK LoaderBlock;
58
59 /* Allocate and zero-init the LPB */
60 LoaderBlock = MmHeapAlloc(sizeof(LOADER_PARAMETER_BLOCK));
61 RtlZeroMemory(LoaderBlock, sizeof(LOADER_PARAMETER_BLOCK));
62
63 /* Init three critical lists, used right away */
64 InitializeListHead(&LoaderBlock->LoadOrderListHead);
65 InitializeListHead(&LoaderBlock->MemoryDescriptorListHead);
66 InitializeListHead(&LoaderBlock->BootDriverListHead);
67
68 /* Alloc space for NLS (it will be converted to VA in WinLdrLoadNLS) */
69 LoaderBlock->NlsData = MmHeapAlloc(sizeof(NLS_DATA_BLOCK));
70 if (LoaderBlock->NlsData == NULL)
71 {
72 UiMessageBox("Failed to allocate memory for NLS table data!");
73 return;
74 }
75 RtlZeroMemory(LoaderBlock->NlsData, sizeof(NLS_DATA_BLOCK));
76
77 *OutLoaderBlock = LoaderBlock;
78 }
79
80 // Init "phase 1"
81 VOID
82 WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
83 PCHAR Options,
84 PCHAR SystemRoot,
85 PCHAR BootPath,
86 USHORT VersionToBoot)
87 {
88 /* Examples of correct options and paths */
89 //CHAR Options[] = "/DEBUGPORT=COM1 /BAUDRATE=115200";
90 //CHAR Options[] = "/NODEBUG";
91 //CHAR SystemRoot[] = "\\WINNT\\";
92 //CHAR ArcBoot[] = "multi(0)disk(0)rdisk(0)partition(1)";
93
94 CHAR HalPath[] = "\\";
95 CHAR ArcBoot[256];
96 CHAR MiscFiles[256];
97 ULONG i, PathSeparator;
98 PLOADER_PARAMETER_EXTENSION Extension;
99
100 /* Construct SystemRoot and ArcBoot from SystemPath */
101 PathSeparator = strstr(BootPath, "\\") - BootPath;
102 strncpy(ArcBoot, BootPath, PathSeparator);
103 ArcBoot[PathSeparator] = 0;
104
105 DPRINTM(DPRINT_WINDOWS, "ArcBoot: %s\n", ArcBoot);
106 DPRINTM(DPRINT_WINDOWS, "SystemRoot: %s\n", SystemRoot);
107 DPRINTM(DPRINT_WINDOWS, "Options: %s\n", Options);
108
109 /* Fill Arc BootDevice */
110 LoaderBlock->ArcBootDeviceName = MmHeapAlloc(strlen(ArcBoot)+1);
111 strcpy(LoaderBlock->ArcBootDeviceName, ArcBoot);
112 LoaderBlock->ArcBootDeviceName = PaToVa(LoaderBlock->ArcBootDeviceName);
113
114 /* Fill Arc HalDevice, it matches ArcBoot path */
115 LoaderBlock->ArcHalDeviceName = MmHeapAlloc(strlen(ArcBoot)+1);
116 strcpy(LoaderBlock->ArcHalDeviceName, ArcBoot);
117 LoaderBlock->ArcHalDeviceName = PaToVa(LoaderBlock->ArcHalDeviceName);
118
119 /* Fill SystemRoot */
120 LoaderBlock->NtBootPathName = MmHeapAlloc(strlen(SystemRoot)+1);
121 strcpy(LoaderBlock->NtBootPathName, SystemRoot);
122 LoaderBlock->NtBootPathName = PaToVa(LoaderBlock->NtBootPathName);
123
124 /* Fill NtHalPathName */
125 LoaderBlock->NtHalPathName = MmHeapAlloc(strlen(HalPath)+1);
126 strcpy(LoaderBlock->NtHalPathName, HalPath);
127 LoaderBlock->NtHalPathName = PaToVa(LoaderBlock->NtHalPathName);
128
129 /* Fill load options */
130 LoaderBlock->LoadOptions = MmHeapAlloc(strlen(Options)+1);
131 strcpy(LoaderBlock->LoadOptions, Options);
132 LoaderBlock->LoadOptions = PaToVa(LoaderBlock->LoadOptions);
133
134 /* Arc devices */
135 LoaderBlock->ArcDiskInformation = (PARC_DISK_INFORMATION)MmHeapAlloc(sizeof(ARC_DISK_INFORMATION));
136 InitializeListHead(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead);
137
138 /* Convert ARC disk information from freeldr to a correct format */
139 for (i = 0; i < reactos_disk_count; i++)
140 {
141 PARC_DISK_SIGNATURE ArcDiskInfo;
142
143 /* Get the ARC structure */
144 ArcDiskInfo = (PARC_DISK_SIGNATURE)MmHeapAlloc(sizeof(ARC_DISK_SIGNATURE));
145 RtlZeroMemory(ArcDiskInfo, sizeof(ARC_DISK_SIGNATURE));
146
147 /* Copy the data over */
148 ArcDiskInfo->Signature = reactos_arc_disk_info[i].Signature;
149 ArcDiskInfo->CheckSum = reactos_arc_disk_info[i].CheckSum;
150
151 /* Copy the ARC Name */
152 ArcDiskInfo->ArcName = (PCHAR)MmHeapAlloc(sizeof(CHAR)*256);
153 strcpy(ArcDiskInfo->ArcName, reactos_arc_disk_info[i].ArcName);
154 ArcDiskInfo->ArcName = (PCHAR)PaToVa(ArcDiskInfo->ArcName);
155
156 /* Mark partition table as valid */
157 ArcDiskInfo->ValidPartitionTable = TRUE;
158
159 /* Insert into the list */
160 InsertTailList(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead,
161 &ArcDiskInfo->ListEntry);
162 }
163
164 /* Convert all list's to Virtual address */
165
166 /* Convert the ArcDisks list to virtual address */
167 List_PaToVa(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead);
168 LoaderBlock->ArcDiskInformation = PaToVa(LoaderBlock->ArcDiskInformation);
169
170 /* Convert configuration entries to VA */
171 ConvertConfigToVA(LoaderBlock->ConfigurationRoot);
172 LoaderBlock->ConfigurationRoot = PaToVa(LoaderBlock->ConfigurationRoot);
173
174 /* Convert all DTE into virtual addresses */
175 List_PaToVa(&LoaderBlock->LoadOrderListHead);
176
177 /* this one will be converted right before switching to
178 virtual paging mode */
179 //List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
180
181 /* Convert list of boot drivers */
182 List_PaToVa(&LoaderBlock->BootDriverListHead);
183
184 /* Initialize Extension now */
185 Extension = MmHeapAlloc(sizeof(LOADER_PARAMETER_EXTENSION));
186 if (Extension == NULL)
187 {
188 UiMessageBox("Failed to allocate LPB Extension!");
189 return;
190 }
191 RtlZeroMemory(Extension, sizeof(LOADER_PARAMETER_EXTENSION));
192
193 /* Fill LPB extension */
194 Extension->Size = sizeof(LOADER_PARAMETER_EXTENSION);
195 Extension->MajorVersion = (VersionToBoot & 0xFF00) >> 8;
196 Extension->MinorVersion = VersionToBoot & 0xFF;
197 Extension->Profile.Status = 2;
198
199 /* Load drivers database */
200 strcpy(MiscFiles, BootPath);
201 strcat(MiscFiles, "AppPatch\\drvmain.sdb");
202 Extension->DrvDBImage = PaToVa(WinLdrLoadModule(MiscFiles,
203 &Extension->DrvDBSize, LoaderRegistryData));
204
205 /* Convert extension and setup block pointers */
206 LoaderBlock->Extension = PaToVa(Extension);
207
208 if (LoaderBlock->SetupLdrBlock)
209 LoaderBlock->SetupLdrBlock = PaToVa(LoaderBlock->SetupLdrBlock);
210 }
211
212 BOOLEAN
213 WinLdrLoadDeviceDriver(PLOADER_PARAMETER_BLOCK LoaderBlock,
214 LPSTR BootPath,
215 PUNICODE_STRING FilePath,
216 ULONG Flags,
217 PLDR_DATA_TABLE_ENTRY *DriverDTE)
218 {
219 CHAR FullPath[1024];
220 CHAR DriverPath[1024];
221 CHAR DllName[1024];
222 PCHAR DriverNamePos;
223 BOOLEAN Status;
224 PVOID DriverBase;
225
226 // Separate the path to file name and directory path
227 sprintf(DriverPath, "%S", FilePath->Buffer);
228 DriverNamePos = strrchr(DriverPath, '\\');
229 if (DriverNamePos != NULL)
230 {
231 // Copy the name
232 strcpy(DllName, DriverNamePos+1);
233
234 // Cut out the name from the path
235 *(DriverNamePos+1) = 0;
236 }
237 else
238 {
239 // There is no directory in the path
240 strcpy(DllName, DriverPath);
241 DriverPath[0] = 0;
242 }
243
244 DPRINTM(DPRINT_WINDOWS, "DriverPath: %s, DllName: %s, LPB %p\n", DriverPath, DllName, LoaderBlock);
245
246
247 // Check if driver is already loaded
248 Status = WinLdrCheckForLoadedDll(LoaderBlock, DllName, DriverDTE);
249 if (Status)
250 {
251 // We've got the pointer to its DTE, just return success
252 return TRUE;
253 }
254
255 // It's not loaded, we have to load it
256 sprintf(FullPath,"%s%S", BootPath, FilePath->Buffer);
257 Status = WinLdrLoadImage(FullPath, LoaderBootDriver, &DriverBase);
258 if (!Status)
259 return FALSE;
260
261 // Allocate a DTE for it
262 Status = WinLdrAllocateDataTableEntry(LoaderBlock, DllName, DllName, DriverBase, DriverDTE);
263 if (!Status)
264 {
265 DPRINTM(DPRINT_WINDOWS, "WinLdrAllocateDataTableEntry() failed\n");
266 return FALSE;
267 }
268
269 // Modify any flags, if needed
270 (*DriverDTE)->Flags |= Flags;
271
272 // Look for any dependencies it may have, and load them too
273 sprintf(FullPath,"%s%s", BootPath, DriverPath);
274 Status = WinLdrScanImportDescriptorTable(LoaderBlock, FullPath, *DriverDTE);
275 if (!Status)
276 {
277 DPRINTM(DPRINT_WINDOWS, "WinLdrScanImportDescriptorTable() failed for %s\n",
278 FullPath);
279 return FALSE;
280 }
281
282 return TRUE;
283 }
284
285 BOOLEAN
286 WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock,
287 LPSTR BootPath)
288 {
289 PLIST_ENTRY NextBd;
290 PBOOT_DRIVER_LIST_ENTRY BootDriver;
291 BOOLEAN Status;
292
293 // Walk through the boot drivers list
294 NextBd = LoaderBlock->BootDriverListHead.Flink;
295
296 while (NextBd != &LoaderBlock->BootDriverListHead)
297 {
298 BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, Link);
299
300 DPRINTM(DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
301 BootDriver->LdrEntry, &BootDriver->RegistryPath);
302
303 // Paths are relative (FIXME: Are they always relative?)
304
305 // Load it
306 Status = WinLdrLoadDeviceDriver(LoaderBlock, BootPath, &BootDriver->FilePath,
307 0, &BootDriver->LdrEntry);
308
309 // If loading failed - cry loudly
310 //FIXME: Maybe remove it from the list and try to continue?
311 if (!Status)
312 {
313 UiMessageBox("Can't load boot driver!");
314 return FALSE;
315 }
316
317 // Convert the RegistryPath and DTE addresses to VA since we are not going to use it anymore
318 BootDriver->RegistryPath.Buffer = PaToVa(BootDriver->RegistryPath.Buffer);
319 BootDriver->LdrEntry = PaToVa(BootDriver->LdrEntry);
320
321 NextBd = BootDriver->Link.Flink;
322 }
323
324 return TRUE;
325 }
326
327 PVOID WinLdrLoadModule(PCSTR ModuleName, ULONG *Size,
328 TYPE_OF_MEMORY MemoryType)
329 {
330 ULONG FileId;
331 PVOID PhysicalBase;
332 FILEINFORMATION FileInfo;
333 ULONG FileSize;
334 ULONG Status;
335 ULONG BytesRead;
336
337 //CHAR ProgressString[256];
338
339 /* Inform user we are loading files */
340 //sprintf(ProgressString, "Loading %s...", FileName);
341 //UiDrawProgressBarCenter(1, 100, ProgressString);
342
343 DPRINTM(DPRINT_WINDOWS, "Loading module %s\n", ModuleName);
344 *Size = 0;
345
346 /* Open the image file */
347 Status = ArcOpen((PCHAR)ModuleName, OpenReadOnly, &FileId);
348 if (Status != ESUCCESS)
349 {
350 /* In case of errors, we just return, without complaining to the user */
351 return NULL;
352 }
353
354 /* Get this file's size */
355 Status = ArcGetFileInformation(FileId, &FileInfo);
356 if (Status != ESUCCESS)
357 {
358 ArcClose(FileId);
359 return NULL;
360 }
361 FileSize = FileInfo.EndingAddress.LowPart;
362 *Size = FileSize;
363
364 /* Allocate memory */
365 PhysicalBase = MmAllocateMemoryWithType(FileSize, MemoryType);
366 if (PhysicalBase == NULL)
367 {
368 ArcClose(FileId);
369 return NULL;
370 }
371
372 /* Load whole file */
373 Status = ArcRead(FileId, PhysicalBase, FileSize, &BytesRead);
374 ArcClose(FileId);
375 if (Status != ESUCCESS)
376 {
377 return NULL;
378 }
379
380 DPRINTM(DPRINT_WINDOWS, "Loaded %s at 0x%x with size 0x%x\n", ModuleName, PhysicalBase, FileSize);
381
382 return PhysicalBase;
383 }
384
385
386 VOID
387 LoadAndBootWindows(PCSTR OperatingSystemName, USHORT OperatingSystemVersion)
388 {
389 CHAR MsgBuffer[256];
390 CHAR FullPath[MAX_PATH], SystemRoot[MAX_PATH], BootPath[MAX_PATH];
391 CHAR FileName[MAX_PATH];
392 CHAR BootOptions[256];
393 PCHAR File;
394 PCHAR PathSeparator;
395 PVOID NtosBase = NULL, HalBase = NULL, KdComBase = NULL;
396 BOOLEAN Status;
397 ULONG SectionId;
398 PLOADER_PARAMETER_BLOCK LoaderBlock, LoaderBlockVA;
399 KERNEL_ENTRY_POINT KiSystemStartup;
400 PLDR_DATA_TABLE_ENTRY KernelDTE, HalDTE, KdComDTE = NULL;
401 // Mm-related things
402 PVOID GdtIdt;
403 ULONG PcrBasePage=0;
404 ULONG TssBasePage=0;
405
406 //sprintf(MsgBuffer,"Booting Microsoft(R) Windows(R) OS version '%04x' is not implemented yet", OperatingSystemVersion);
407 //UiMessageBox(MsgBuffer);
408
409 // Open the operating system section
410 // specified in the .ini file
411 if (!IniOpenSection(OperatingSystemName, &SectionId))
412 {
413 sprintf(MsgBuffer,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName);
414 UiMessageBox(MsgBuffer);
415 return;
416 }
417
418 UiDrawBackdrop();
419 UiDrawStatusText("Detecting Hardware...");
420 UiDrawProgressBarCenter(1, 100, "Loading Windows...");
421
422 /* Make sure the system path is set in the .ini file */
423 if (!IniReadSettingByName(SectionId, "SystemPath", FullPath, sizeof(FullPath)))
424 {
425 UiMessageBox("System path not specified for selected operating system.");
426 return;
427 }
428
429 /* Special case for LiveCD */
430 if (!_strnicmp(FullPath, "LiveCD", strlen("LiveCD")))
431 {
432 strcpy(BootPath, FullPath + strlen("LiveCD"));
433 MachDiskGetBootPath(FullPath, sizeof(FullPath));
434 strcat(FullPath, BootPath);
435 }
436
437 /* Convert FullPath to SystemRoot */
438 PathSeparator = strstr(FullPath, "\\");
439 strcpy(SystemRoot, PathSeparator);
440 strcat(SystemRoot, "\\");
441
442 /* Read booting options */
443 if (!IniReadSettingByName(SectionId, "Options", BootOptions, sizeof(BootOptions)))
444 {
445 /* Nothing read, make the string empty */
446 strcpy(BootOptions, "");
447 }
448
449 //
450 // Check if a ramdisk file was given
451 //
452 File = strstr(BootOptions, "/RDPATH=");
453 if (File)
454 {
455 //
456 // Copy the file name and everything else after it
457 //
458 strcpy(FileName, File + 8);
459
460 //
461 // Null-terminate
462 //
463 *strstr(FileName, " ") = ANSI_NULL;
464
465 //
466 // Load the ramdisk
467 //
468 RamDiskLoadVirtualFile(FileName);
469 }
470
471 /* Let user know we started loading */
472 UiDrawStatusText("Loading...");
473
474 /* append a backslash */
475 strcpy(BootPath, FullPath);
476 if ((strlen(BootPath)==0) ||
477 BootPath[strlen(BootPath)] != '\\')
478 strcat(BootPath, "\\");
479
480 DPRINTM(DPRINT_WINDOWS,"BootPath: '%s'\n", BootPath);
481
482 /* Allocate and minimalistic-initialize LPB */
483 AllocateAndInitLPB(&LoaderBlock);
484
485 /* Detect hardware */
486 UseRealHeap = TRUE;
487 LoaderBlock->ConfigurationRoot = MachHwDetect();
488
489 /* Load kernel */
490 strcpy(FileName, BootPath);
491 strcat(FileName, "SYSTEM32\\NTOSKRNL.EXE");
492 Status = WinLdrLoadImage(FileName, LoaderSystemCode, &NtosBase);
493 DPRINTM(DPRINT_WINDOWS, "Ntos loaded with status %d at %p\n", Status, NtosBase);
494
495 /* Load HAL */
496 strcpy(FileName, BootPath);
497 strcat(FileName, "SYSTEM32\\HAL.DLL");
498 Status = WinLdrLoadImage(FileName, LoaderHalCode, &HalBase);
499 DPRINTM(DPRINT_WINDOWS, "HAL loaded with status %d at %p\n", Status, HalBase);
500
501 /* Load kernel-debugger support dll */
502 if (OperatingSystemVersion > _WIN32_WINNT_WIN2K)
503 {
504 strcpy(FileName, BootPath);
505 strcat(FileName, "SYSTEM32\\KDCOM.DLL");
506 Status = WinLdrLoadImage(FileName, LoaderBootDriver, &KdComBase);
507 DPRINTM(DPRINT_WINDOWS, "KdCom loaded with status %d at %p\n", Status, KdComBase);
508 }
509
510 /* Allocate data table entries for above-loaded modules */
511 WinLdrAllocateDataTableEntry(LoaderBlock, "ntoskrnl.exe",
512 "WINDOWS\\SYSTEM32\\NTOSKRNL.EXE", NtosBase, &KernelDTE);
513 WinLdrAllocateDataTableEntry(LoaderBlock, "hal.dll",
514 "WINDOWS\\SYSTEM32\\HAL.DLL", HalBase, &HalDTE);
515 if (OperatingSystemVersion > _WIN32_WINNT_WIN2K)
516 {
517 WinLdrAllocateDataTableEntry(LoaderBlock, "kdcom.dll",
518 "WINDOWS\\SYSTEM32\\KDCOM.DLL", KdComBase, &KdComDTE);
519 }
520
521 /* Load all referenced DLLs for kernel, HAL and kdcom.dll */
522 strcpy(FileName, BootPath);
523 strcat(FileName, "SYSTEM32\\");
524 WinLdrScanImportDescriptorTable(LoaderBlock, FileName, KernelDTE);
525 WinLdrScanImportDescriptorTable(LoaderBlock, FileName, HalDTE);
526 if (KdComDTE)
527 WinLdrScanImportDescriptorTable(LoaderBlock, FileName, KdComDTE);
528
529 /* Load Hive, and then NLS data, OEM font, and prepare boot drivers list */
530 Status = WinLdrLoadAndScanSystemHive(LoaderBlock, BootPath);
531 DPRINTM(DPRINT_WINDOWS, "SYSTEM hive loaded and scanned with status %d\n", Status);
532
533 /* Load boot drivers */
534 Status = WinLdrLoadBootDrivers(LoaderBlock, BootPath);
535 DPRINTM(DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status);
536
537 /* Alloc PCR, TSS, do magic things with the GDT/IDT */
538 WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage);
539
540 /* Initialize Phase 1 - no drivers loading anymore */
541 WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemRoot, BootPath, OperatingSystemVersion);
542
543 /* Save entry-point pointer and Loader block VAs */
544 KiSystemStartup = (KERNEL_ENTRY_POINT)KernelDTE->EntryPoint;
545 LoaderBlockVA = PaToVa(LoaderBlock);
546
547 /* "Stop all motors", change videomode */
548 if (OperatingSystemVersion < _WIN32_WINNT_WIN2K)
549 MachPrepareForReactOS(TRUE);
550 else
551 MachPrepareForReactOS(FALSE);
552
553 /* Debugging... */
554 //DumpMemoryAllocMap();
555
556 /* Turn on paging mode of CPU*/
557 WinLdrTurnOnPaging(LoaderBlock, PcrBasePage, TssBasePage, GdtIdt);
558
559 /* Save final value of LoaderPagesSpanned */
560 LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;
561
562 DPRINTM(DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
563 KiSystemStartup, LoaderBlockVA);
564
565 WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
566 WinLdrpDumpBootDriver(LoaderBlockVA);
567 WinLdrpDumpArcDisks(LoaderBlockVA);
568
569 //FIXME: If I substitute this debugging checkpoint, GCC will "optimize away" the code below
570 //while (1) {};
571 /*asm(".intel_syntax noprefix\n");
572 asm("test1:\n");
573 asm("jmp test1\n");
574 asm(".att_syntax\n");*/
575
576 /* Pass control */
577 (*KiSystemStartup)(LoaderBlockVA);
578
579 return;
580 }
581
582 VOID
583 WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock)
584 {
585 PLIST_ENTRY NextMd;
586 PMEMORY_ALLOCATION_DESCRIPTOR MemoryDescriptor;
587
588 NextMd = LoaderBlock->MemoryDescriptorListHead.Flink;
589
590 while (NextMd != &LoaderBlock->MemoryDescriptorListHead)
591 {
592 MemoryDescriptor = CONTAINING_RECORD(NextMd, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry);
593
594 DPRINTM(DPRINT_WINDOWS, "BP %08X PC %04X MT %d\n", MemoryDescriptor->BasePage,
595 MemoryDescriptor->PageCount, MemoryDescriptor->MemoryType);
596
597 NextMd = MemoryDescriptor->ListEntry.Flink;
598 }
599 }
600
601 VOID
602 WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock)
603 {
604 PLIST_ENTRY NextBd;
605 PBOOT_DRIVER_LIST_ENTRY BootDriver;
606
607 NextBd = LoaderBlock->BootDriverListHead.Flink;
608
609 while (NextBd != &LoaderBlock->BootDriverListHead)
610 {
611 BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, Link);
612
613 DPRINTM(DPRINT_WINDOWS, "BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
614 BootDriver->LdrEntry, &BootDriver->RegistryPath);
615
616 NextBd = BootDriver->Link.Flink;
617 }
618 }
619
620 VOID
621 WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock)
622 {
623 PLIST_ENTRY NextBd;
624 PARC_DISK_SIGNATURE ArcDisk;
625
626 NextBd = LoaderBlock->ArcDiskInformation->DiskSignatureListHead.Flink;
627
628 while (NextBd != &LoaderBlock->ArcDiskInformation->DiskSignatureListHead)
629 {
630 ArcDisk = CONTAINING_RECORD(NextBd, ARC_DISK_SIGNATURE, ListEntry);
631
632 DPRINTM(DPRINT_WINDOWS, "ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
633 ArcDisk->ArcName, ArcDisk->CheckSum, ArcDisk->Signature);
634
635 NextBd = ArcDisk->ListEntry.Flink;
636 }
637 }
638
639