c1b6fa3906e7be07f31901fba245a7f16285c9a1
[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 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.
20 */
21
22 #include <freeldr.h>
23
24 #include <ndk/ldrtypes.h>
25 #include <debug.h>
26
27 DBG_DEFAULT_CHANNEL(WINDOWS);
28
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[];
32
33 extern BOOLEAN UseRealHeap;
34 extern ULONG LoaderPagesSpanned;
35 extern BOOLEAN AcpiPresent;
36
37 extern HEADLESS_LOADER_BLOCK LoaderRedirectionInformation;
38 extern BOOLEAN WinLdrTerminalConnected;
39 extern void WinLdrSetupEms(IN PCHAR BootOptions);
40
41 PLOADER_SYSTEM_BLOCK WinLdrSystemBlock;
42
43 // debug stuff
44 VOID DumpMemoryAllocMap(VOID);
45
46 // Init "phase 0"
47 VOID
48 AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock)
49 {
50 PLOADER_PARAMETER_BLOCK LoaderBlock;
51
52 /* Allocate and zero-init the LPB */
53 WinLdrSystemBlock = MmAllocateMemoryWithType(sizeof(LOADER_SYSTEM_BLOCK),
54 LoaderSystemBlock);
55 if (WinLdrSystemBlock == NULL)
56 {
57 UiMessageBox("Failed to allocate memory for system block!");
58 return;
59 }
60
61 RtlZeroMemory(WinLdrSystemBlock, sizeof(LOADER_SYSTEM_BLOCK));
62
63 LoaderBlock = &WinLdrSystemBlock->LoaderBlock;
64 LoaderBlock->NlsData = &WinLdrSystemBlock->NlsDataBlock;
65
66 /* Init three critical lists, used right away */
67 InitializeListHead(&LoaderBlock->LoadOrderListHead);
68 InitializeListHead(&LoaderBlock->MemoryDescriptorListHead);
69 InitializeListHead(&LoaderBlock->BootDriverListHead);
70
71 *OutLoaderBlock = LoaderBlock;
72 }
73
74 // Init "phase 1"
75 VOID
76 WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
77 LPCSTR Options,
78 LPCSTR SystemRoot,
79 LPCSTR BootPath,
80 USHORT VersionToBoot)
81 {
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)";
87
88 LPSTR LoadOptions, NewLoadOptions;
89 CHAR HalPath[] = "\\";
90 CHAR ArcBoot[256];
91 CHAR MiscFiles[256];
92 ULONG i;
93 ULONG_PTR PathSeparator;
94 PLOADER_PARAMETER_EXTENSION Extension;
95
96 /* Construct SystemRoot and ArcBoot from SystemPath */
97 PathSeparator = strstr(BootPath, "\\") - BootPath;
98 strncpy(ArcBoot, BootPath, PathSeparator);
99 ArcBoot[PathSeparator] = 0;
100
101 TRACE("ArcBoot: %s\n", ArcBoot);
102 TRACE("SystemRoot: %s\n", SystemRoot);
103 TRACE("Options: %s\n", Options);
104
105 /* Fill Arc BootDevice */
106 LoaderBlock->ArcBootDeviceName = WinLdrSystemBlock->ArcBootDeviceName;
107 strncpy(LoaderBlock->ArcBootDeviceName, ArcBoot, MAX_PATH);
108 LoaderBlock->ArcBootDeviceName = PaToVa(LoaderBlock->ArcBootDeviceName);
109
110 /* Fill Arc HalDevice, it matches ArcBoot path */
111 LoaderBlock->ArcHalDeviceName = WinLdrSystemBlock->ArcBootDeviceName;
112 LoaderBlock->ArcHalDeviceName = PaToVa(LoaderBlock->ArcHalDeviceName);
113
114 /* Fill SystemRoot */
115 LoaderBlock->NtBootPathName = WinLdrSystemBlock->NtBootPathName;
116 strncpy(LoaderBlock->NtBootPathName, SystemRoot, MAX_PATH);
117 LoaderBlock->NtBootPathName = PaToVa(LoaderBlock->NtBootPathName);
118
119 /* Fill NtHalPathName */
120 LoaderBlock->NtHalPathName = WinLdrSystemBlock->NtHalPathName;
121 strncpy(LoaderBlock->NtHalPathName, HalPath, MAX_PATH);
122 LoaderBlock->NtHalPathName = PaToVa(LoaderBlock->NtHalPathName);
123
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);
127
128 do
129 {
130 while (*LoadOptions == '/')
131 ++LoadOptions;
132
133 *NewLoadOptions++ = *LoadOptions;
134 } while (*LoadOptions++);
135
136 LoaderBlock->LoadOptions = PaToVa(LoaderBlock->LoadOptions);
137
138 /* Arc devices */
139 LoaderBlock->ArcDiskInformation = &WinLdrSystemBlock->ArcDiskInformation;
140 InitializeListHead(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead);
141
142 /* Convert ARC disk information from freeldr to a correct format */
143 for (i = 0; i < reactos_disk_count; i++)
144 {
145 PARC_DISK_SIGNATURE_EX ArcDiskSig;
146
147 /* Allocate the ARC structure */
148 ArcDiskSig = HeapAllocate(FrLdrDefaultHeap,
149 sizeof(ARC_DISK_SIGNATURE_EX),
150 'giSD');
151
152 /* Copy the data over */
153 ArcDiskSig->DiskSignature.Signature = reactos_arc_disk_info[i].Signature;
154 ArcDiskSig->DiskSignature.CheckSum = reactos_arc_disk_info[i].CheckSum;
155
156 /* Copy the ARC Name */
157 strncpy(ArcDiskSig->ArcName, reactos_arc_disk_info[i].ArcName, MAX_PATH);
158 ArcDiskSig->DiskSignature.ArcName = PaToVa(ArcDiskSig->ArcName);
159
160 /* Mark partition table as valid */
161 ArcDiskSig->DiskSignature.ValidPartitionTable = TRUE;
162
163 /* Insert into the list */
164 InsertTailList(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead,
165 &ArcDiskSig->DiskSignature.ListEntry);
166 }
167
168 /* Convert all list's to Virtual address */
169
170 /* Convert the ArcDisks list to virtual address */
171 List_PaToVa(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead);
172 LoaderBlock->ArcDiskInformation = PaToVa(LoaderBlock->ArcDiskInformation);
173
174 /* Convert configuration entries to VA */
175 ConvertConfigToVA(LoaderBlock->ConfigurationRoot);
176 LoaderBlock->ConfigurationRoot = PaToVa(LoaderBlock->ConfigurationRoot);
177
178 /* Convert all DTE into virtual addresses */
179 List_PaToVa(&LoaderBlock->LoadOrderListHead);
180
181 /* this one will be converted right before switching to
182 virtual paging mode */
183 //List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
184
185 /* Convert list of boot drivers */
186 List_PaToVa(&LoaderBlock->BootDriverListHead);
187
188 /* Initialize Extension now */
189 Extension = &WinLdrSystemBlock->Extension;
190 Extension->Size = sizeof(LOADER_PARAMETER_EXTENSION);
191 Extension->MajorVersion = (VersionToBoot & 0xFF00) >> 8;
192 Extension->MinorVersion = VersionToBoot & 0xFF;
193 Extension->Profile.Status = 2;
194
195 /* Check if ACPI is present */
196 if (AcpiPresent)
197 {
198 /* See KiRosFrldrLpbToNtLpb for details */
199 Extension->AcpiTable = (PVOID)1;
200 }
201
202 #ifdef _M_IX86
203 /* Set headless block pointer */
204 if (WinLdrTerminalConnected)
205 {
206 Extension->HeadlessLoaderBlock = &WinLdrSystemBlock->HeadlessLoaderBlock;
207 RtlCopyMemory(Extension->HeadlessLoaderBlock,
208 &LoaderRedirectionInformation,
209 sizeof(HEADLESS_LOADER_BLOCK));
210 Extension->HeadlessLoaderBlock = PaToVa(Extension->HeadlessLoaderBlock);
211 }
212 #endif
213 /* Load drivers database */
214 strcpy(MiscFiles, BootPath);
215 strcat(MiscFiles, "AppPatch\\drvmain.sdb");
216 Extension->DrvDBImage = PaToVa(WinLdrLoadModule(MiscFiles,
217 &Extension->DrvDBSize,
218 LoaderRegistryData));
219
220 /* Convert extension and setup block pointers */
221 LoaderBlock->Extension = PaToVa(Extension);
222
223 if (LoaderBlock->SetupLdrBlock)
224 LoaderBlock->SetupLdrBlock = PaToVa(LoaderBlock->SetupLdrBlock);
225
226 TRACE("WinLdrInitializePhase1() completed\n");
227 }
228
229 static BOOLEAN
230 WinLdrLoadDeviceDriver(PLIST_ENTRY LoadOrderListHead,
231 LPSTR BootPath,
232 PUNICODE_STRING FilePath,
233 ULONG Flags,
234 PLDR_DATA_TABLE_ENTRY *DriverDTE)
235 {
236 CHAR FullPath[1024];
237 CHAR DriverPath[1024];
238 CHAR DllName[1024];
239 PCHAR DriverNamePos;
240 BOOLEAN Status;
241 PVOID DriverBase;
242
243 // Separate the path to file name and directory path
244 _snprintf(DriverPath, sizeof(DriverPath), "%wZ", FilePath);
245 DriverNamePos = strrchr(DriverPath, '\\');
246 if (DriverNamePos != NULL)
247 {
248 // Copy the name
249 strcpy(DllName, DriverNamePos+1);
250
251 // Cut out the name from the path
252 *(DriverNamePos+1) = 0;
253 }
254 else
255 {
256 // There is no directory in the path
257 strcpy(DllName, DriverPath);
258 DriverPath[0] = 0;
259 }
260
261 TRACE("DriverPath: %s, DllName: %s, LPB\n", DriverPath, DllName);
262
263
264 // Check if driver is already loaded
265 Status = WinLdrCheckForLoadedDll(LoadOrderListHead, DllName, DriverDTE);
266 if (Status)
267 {
268 // We've got the pointer to its DTE, just return success
269 return TRUE;
270 }
271
272 // It's not loaded, we have to load it
273 _snprintf(FullPath, sizeof(FullPath), "%s%wZ", BootPath, FilePath);
274 Status = WinLdrLoadImage(FullPath, LoaderBootDriver, &DriverBase);
275 if (!Status)
276 return FALSE;
277
278 // Allocate a DTE for it
279 Status = WinLdrAllocateDataTableEntry(LoadOrderListHead, DllName, DllName, DriverBase, DriverDTE);
280 if (!Status)
281 {
282 ERR("WinLdrAllocateDataTableEntry() failed\n");
283 return FALSE;
284 }
285
286 // Modify any flags, if needed
287 (*DriverDTE)->Flags |= Flags;
288
289 // Look for any dependencies it may have, and load them too
290 sprintf(FullPath,"%s%s", BootPath, DriverPath);
291 Status = WinLdrScanImportDescriptorTable(LoadOrderListHead, FullPath, *DriverDTE);
292 if (!Status)
293 {
294 ERR("WinLdrScanImportDescriptorTable() failed for %s\n", FullPath);
295 return FALSE;
296 }
297
298 return TRUE;
299 }
300
301 BOOLEAN
302 WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock,
303 LPSTR BootPath)
304 {
305 PLIST_ENTRY NextBd;
306 PBOOT_DRIVER_LIST_ENTRY BootDriver;
307 BOOLEAN Status;
308
309 // Walk through the boot drivers list
310 NextBd = LoaderBlock->BootDriverListHead.Flink;
311
312 while (NextBd != &LoaderBlock->BootDriverListHead)
313 {
314 BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, Link);
315
316 TRACE("BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
317 BootDriver->LdrEntry, &BootDriver->RegistryPath);
318
319 // Paths are relative (FIXME: Are they always relative?)
320
321 // Load it
322 Status = WinLdrLoadDeviceDriver(&LoaderBlock->LoadOrderListHead, BootPath, &BootDriver->FilePath,
323 0, &BootDriver->LdrEntry);
324
325 // If loading failed - cry loudly
326 //FIXME: Maybe remove it from the list and try to continue?
327 if (!Status)
328 {
329 UiMessageBox("Can't load boot driver!");
330 return FALSE;
331 }
332
333 // Convert the RegistryPath and DTE addresses to VA since we are not going to use it anymore
334 BootDriver->RegistryPath.Buffer = PaToVa(BootDriver->RegistryPath.Buffer);
335 BootDriver->FilePath.Buffer = PaToVa(BootDriver->FilePath.Buffer);
336 BootDriver->LdrEntry = PaToVa(BootDriver->LdrEntry);
337
338 NextBd = BootDriver->Link.Flink;
339 }
340
341 return TRUE;
342 }
343
344 PVOID WinLdrLoadModule(PCSTR ModuleName, ULONG *Size,
345 TYPE_OF_MEMORY MemoryType)
346 {
347 ULONG FileId;
348 PVOID PhysicalBase;
349 FILEINFORMATION FileInfo;
350 ULONG FileSize;
351 ULONG Status;
352 ULONG BytesRead;
353
354 //CHAR ProgressString[256];
355
356 /* Inform user we are loading files */
357 //sprintf(ProgressString, "Loading %s...", FileName);
358 //UiDrawProgressBarCenter(1, 100, ProgressString);
359
360 TRACE("Loading module %s\n", ModuleName);
361 *Size = 0;
362
363 /* Open the image file */
364 Status = ArcOpen((PCHAR)ModuleName, OpenReadOnly, &FileId);
365 if (Status != ESUCCESS)
366 {
367 /* In case of errors, we just return, without complaining to the user */
368 return NULL;
369 }
370
371 /* Get this file's size */
372 Status = ArcGetFileInformation(FileId, &FileInfo);
373 if (Status != ESUCCESS)
374 {
375 ArcClose(FileId);
376 return NULL;
377 }
378 FileSize = FileInfo.EndingAddress.LowPart;
379 *Size = FileSize;
380
381 /* Allocate memory */
382 PhysicalBase = MmAllocateMemoryWithType(FileSize, MemoryType);
383 if (PhysicalBase == NULL)
384 {
385 ArcClose(FileId);
386 return NULL;
387 }
388
389 /* Load whole file */
390 Status = ArcRead(FileId, PhysicalBase, FileSize, &BytesRead);
391 ArcClose(FileId);
392 if (Status != ESUCCESS)
393 {
394 return NULL;
395 }
396
397 TRACE("Loaded %s at 0x%x with size 0x%x\n", ModuleName, PhysicalBase, FileSize);
398
399 return PhysicalBase;
400 }
401
402
403 USHORT
404 WinLdrDetectVersion()
405 {
406 LONG rc;
407 FRLDRHKEY hKey;
408
409 rc = RegOpenKey(
410 NULL,
411 L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server",
412 &hKey);
413 if (rc != ERROR_SUCCESS)
414 {
415 // Key doesn't exist; assume NT 4.0
416 return _WIN32_WINNT_NT4;
417 }
418
419 // We may here want to read the value of ProductVersion
420 return _WIN32_WINNT_WS03;
421 }
422
423 static
424 PVOID
425 LoadModule(
426 PLOADER_PARAMETER_BLOCK LoaderBlock,
427 PCCH Path,
428 PCCH File,
429 TYPE_OF_MEMORY MemoryType,
430 PLDR_DATA_TABLE_ENTRY *Dte,
431 ULONG Percentage)
432 {
433 CHAR FullFileName[MAX_PATH];
434 CHAR ProgressString[256];
435 NTSTATUS Status;
436 PVOID BaseAdress;
437
438 UiDrawBackdrop();
439 sprintf(ProgressString, "Loading %s...", File);
440 UiDrawProgressBarCenter(Percentage, 100, ProgressString);
441
442 strcpy(FullFileName, Path);
443 strcat(FullFileName, "SYSTEM32\\");
444 strcat(FullFileName, File);
445
446 Status = WinLdrLoadImage(FullFileName, MemoryType, &BaseAdress);
447 TRACE("%s loaded with status %d at %p\n",
448 File, Status, BaseAdress);
449
450 strcpy(FullFileName, "WINDOWS\\SYSTEM32\\");
451 strcat(FullFileName, File);
452 WinLdrAllocateDataTableEntry(&LoaderBlock->LoadOrderListHead, File,
453 FullFileName, BaseAdress, Dte);
454
455 return BaseAdress;
456 }
457
458 VOID
459 LoadAndBootWindows(IN OperatingSystemItem* OperatingSystem,
460 IN USHORT OperatingSystemVersion)
461 {
462 ULONG_PTR SectionId;
463 PCSTR SectionName = OperatingSystem->SystemPartition;
464 CHAR SettingsValue[80];
465 BOOLEAN HasSection;
466 CHAR BootPath[MAX_PATH];
467 CHAR FileName[MAX_PATH];
468 CHAR BootOptions[256];
469 PCHAR File;
470 BOOLEAN Status;
471 PLOADER_PARAMETER_BLOCK LoaderBlock;
472
473 // Get OS setting value
474 SettingsValue[0] = ANSI_NULL;
475 IniOpenSection("Operating Systems", &SectionId);
476 IniReadSettingByName(SectionId, SectionName, SettingsValue, sizeof(SettingsValue));
477
478 // Open the operating system section
479 // specified in the .ini file
480 HasSection = IniOpenSection(SectionName, &SectionId);
481
482 UiDrawBackdrop();
483 UiDrawProgressBarCenter(1, 100, "Loading NT...");
484
485 /* Read the system path is set in the .ini file */
486 if (!HasSection ||
487 !IniReadSettingByName(SectionId, "SystemPath", BootPath, sizeof(BootPath)))
488 {
489 strcpy(BootPath, SectionName);
490 }
491
492 /* Special case for LiveCD */
493 if (!_strnicmp(BootPath, "LiveCD", strlen("LiveCD")))
494 {
495 strcpy(FileName, BootPath + strlen("LiveCD"));
496 MachDiskGetBootPath(BootPath, sizeof(BootPath));
497 strcat(BootPath, FileName);
498 }
499
500 /* append a backslash */
501 if ((strlen(BootPath)==0) || BootPath[strlen(BootPath)] != '\\')
502 strcat(BootPath, "\\");
503
504 /* Read booting options */
505 if (!HasSection || !IniReadSettingByName(SectionId, "Options", BootOptions, sizeof(BootOptions)))
506 {
507 /* Get options after the title */
508 PCSTR p = SettingsValue;
509 while (*p == ' ' || *p == '"')
510 p++;
511 while (*p != '\0' && *p != '"')
512 p++;
513 strcpy(BootOptions, p);
514 TRACE("BootOptions: '%s'\n", BootOptions);
515 }
516
517 /* Append boot-time options */
518 AppendBootTimeOptions(BootOptions);
519
520 /* Check if a ramdisk file was given */
521 File = strstr(BootOptions, "/RDPATH=");
522 if (File)
523 {
524 /* Copy the file name and everything else after it */
525 strcpy(FileName, File + 8);
526
527 /* Null-terminate */
528 *strstr(FileName, " ") = ANSI_NULL;
529
530 /* Load the ramdisk */
531 RamDiskLoadVirtualFile(FileName);
532 }
533
534 /* Let user know we started loading */
535 //UiDrawStatusText("Loading...");
536
537 TRACE("BootPath: '%s'\n", BootPath);
538
539 /* Allocate and minimalistic-initialize LPB */
540 AllocateAndInitLPB(&LoaderBlock);
541
542 #ifdef _M_IX86
543 /* Setup redirection support */
544 WinLdrSetupEms(BootOptions);
545 #endif
546
547 /* Load Hive */
548 UiDrawBackdrop();
549 UiDrawProgressBarCenter(15, 100, "Loading system hive...");
550 Status = WinLdrInitSystemHive(LoaderBlock, BootPath);
551 TRACE("SYSTEM hive loaded with status %d\n", Status);
552
553 /* Load NLS data, OEM font, and prepare boot drivers list */
554 Status = WinLdrScanSystemHive(LoaderBlock, BootPath);
555 TRACE("SYSTEM hive scanned with status %d\n", Status);
556
557
558 LoadAndBootWindowsCommon(OperatingSystemVersion,
559 LoaderBlock,
560 BootOptions,
561 BootPath,
562 0);
563 }
564
565 VOID
566 LoadAndBootWindowsCommon(
567 USHORT OperatingSystemVersion,
568 PLOADER_PARAMETER_BLOCK LoaderBlock,
569 LPCSTR BootOptions,
570 LPCSTR BootPath,
571 BOOLEAN Setup)
572 {
573 PLOADER_PARAMETER_BLOCK LoaderBlockVA;
574 BOOLEAN Status;
575 CHAR FileName[MAX_PATH];
576 PLDR_DATA_TABLE_ENTRY KernelDTE, HalDTE, KdComDTE = NULL;
577 KERNEL_ENTRY_POINT KiSystemStartup;
578 LPCSTR SystemRoot;
579 TRACE("LoadAndBootWindowsCommon()\n");
580
581 /* Convert BootPath to SystemRoot */
582 SystemRoot = strstr(BootPath, "\\");
583
584 /* Detect hardware */
585 UseRealHeap = TRUE;
586 LoaderBlock->ConfigurationRoot = MachHwDetect();
587
588 if (OperatingSystemVersion == 0)
589 OperatingSystemVersion = WinLdrDetectVersion();
590
591 /* Load kernel */
592 LoadModule(LoaderBlock, BootPath, "NTOSKRNL.EXE", LoaderSystemCode, &KernelDTE, 30);
593
594 /* Load HAL */
595 LoadModule(LoaderBlock, BootPath, "HAL.DLL", LoaderHalCode, &HalDTE, 45);
596
597 /* Load kernel-debugger support dll */
598 if (OperatingSystemVersion > _WIN32_WINNT_WIN2K)
599 {
600 LoadModule(LoaderBlock, BootPath, "KDCOM.DLL", LoaderSystemCode, &KdComDTE, 60);
601 }
602
603 /* Load all referenced DLLs for kernel, HAL and kdcom.dll */
604 strcpy(FileName, BootPath);
605 strcat(FileName, "system32\\");
606 Status = WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FileName, KernelDTE);
607 Status &= WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FileName, HalDTE);
608 if (KdComDTE)
609 Status &= WinLdrScanImportDescriptorTable(&LoaderBlock->LoadOrderListHead, FileName, KdComDTE);
610
611 if (!Status)
612 {
613 UiMessageBox("Error loading imported dll.");
614 return;
615 }
616
617 /* Load boot drivers */
618 UiDrawBackdrop();
619 UiDrawProgressBarCenter(100, 100, "Loading boot drivers...");
620 Status = WinLdrLoadBootDrivers(LoaderBlock, (PCHAR)BootPath);
621 TRACE("Boot drivers loaded with status %d\n", Status);
622
623 /* Initialize Phase 1 - no drivers loading anymore */
624 WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemRoot, BootPath, OperatingSystemVersion);
625
626 /* Save entry-point pointer and Loader block VAs */
627 KiSystemStartup = (KERNEL_ENTRY_POINT)KernelDTE->EntryPoint;
628 LoaderBlockVA = PaToVa(LoaderBlock);
629
630 /* "Stop all motors", change videomode */
631 MachPrepareForReactOS(Setup);
632
633 /* Debugging... */
634 //DumpMemoryAllocMap();
635
636 /* Do the machine specific initialization */
637 WinLdrSetupMachineDependent(LoaderBlock);
638
639 /* Map pages and create memory descriptors */
640 WinLdrSetupMemoryLayout(LoaderBlock);
641
642 /* Set processor context */
643 WinLdrSetProcessorContext();
644
645 /* Save final value of LoaderPagesSpanned */
646 LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;
647
648 TRACE("Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
649 KiSystemStartup, LoaderBlockVA);
650
651 // Zero KI_USER_SHARED_DATA page
652 memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE);
653
654 WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
655 WinLdrpDumpBootDriver(LoaderBlockVA);
656 #ifndef _M_AMD64
657 WinLdrpDumpArcDisks(LoaderBlockVA);
658 #endif
659
660 //FIXME: If I substitute this debugging checkpoint, GCC will "optimize away" the code below
661 //while (1) {};
662 /*asm(".intel_syntax noprefix\n");
663 asm("test1:\n");
664 asm("jmp test1\n");
665 asm(".att_syntax\n");*/
666
667 /* Pass control */
668 (*KiSystemStartup)(LoaderBlockVA);
669 }
670
671 VOID
672 WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock)
673 {
674 PLIST_ENTRY NextMd;
675 PMEMORY_ALLOCATION_DESCRIPTOR MemoryDescriptor;
676
677 NextMd = LoaderBlock->MemoryDescriptorListHead.Flink;
678
679 while (NextMd != &LoaderBlock->MemoryDescriptorListHead)
680 {
681 MemoryDescriptor = CONTAINING_RECORD(NextMd, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry);
682
683 TRACE("BP %08X PC %04X MT %d\n", MemoryDescriptor->BasePage,
684 MemoryDescriptor->PageCount, MemoryDescriptor->MemoryType);
685
686 NextMd = MemoryDescriptor->ListEntry.Flink;
687 }
688 }
689
690 VOID
691 WinLdrpDumpBootDriver(PLOADER_PARAMETER_BLOCK LoaderBlock)
692 {
693 PLIST_ENTRY NextBd;
694 PBOOT_DRIVER_LIST_ENTRY BootDriver;
695
696 NextBd = LoaderBlock->BootDriverListHead.Flink;
697
698 while (NextBd != &LoaderBlock->BootDriverListHead)
699 {
700 BootDriver = CONTAINING_RECORD(NextBd, BOOT_DRIVER_LIST_ENTRY, Link);
701
702 TRACE("BootDriver %wZ DTE %08X RegPath: %wZ\n", &BootDriver->FilePath,
703 BootDriver->LdrEntry, &BootDriver->RegistryPath);
704
705 NextBd = BootDriver->Link.Flink;
706 }
707 }
708
709 VOID
710 WinLdrpDumpArcDisks(PLOADER_PARAMETER_BLOCK LoaderBlock)
711 {
712 PLIST_ENTRY NextBd;
713 PARC_DISK_SIGNATURE ArcDisk;
714
715 NextBd = LoaderBlock->ArcDiskInformation->DiskSignatureListHead.Flink;
716
717 while (NextBd != &LoaderBlock->ArcDiskInformation->DiskSignatureListHead)
718 {
719 ArcDisk = CONTAINING_RECORD(NextBd, ARC_DISK_SIGNATURE, ListEntry);
720
721 TRACE("ArcDisk %s checksum: 0x%X, signature: 0x%X\n",
722 ArcDisk->ArcName, ArcDisk->CheckSum, ArcDisk->Signature);
723
724 NextBd = ArcDisk->ListEntry.Flink;
725 }
726 }
727
728