- Fix warning in winldr.c
[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
26 //#define NDEBUG
27 #include <debug.h>
28
29 VOID DumpMemoryAllocMap(VOID);
30 VOID WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock);
31
32 BOOLEAN
33 WinLdrLoadNLSData(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
34 IN LPCSTR DirectoryPath,
35 IN LPCSTR AnsiFileName,
36 IN LPCSTR OemFileName,
37 IN LPCSTR LanguageFileName)
38 {
39 CHAR FileName[255];
40 PFILE AnsiFileHandle;
41 PFILE OemFileHandle;
42 PFILE LanguageFileHandle;
43 ULONG AnsiFileSize, OemFileSize, LanguageFileSize;
44 ULONG TotalSize;
45 ULONG_PTR NlsDataBase;
46 PVOID NlsVirtual;
47 BOOLEAN Status, AnsiEqualsOem = FALSE;
48
49 /* There may be a case, when OEM and ANSI page coincide */
50 if (!strcmp(AnsiFileName, OemFileName))
51 AnsiEqualsOem = TRUE;
52
53 /* Open file with ANSI and store its size */
54 //Print(L"Loading %s...\n", Filename);
55 strcpy(FileName, DirectoryPath);
56 strcat(FileName, AnsiFileName);
57 AnsiFileHandle = FsOpenFile(FileName);
58
59 if (AnsiFileHandle == NULL)
60 goto Failure;
61
62 AnsiFileSize = FsGetFileSize(AnsiFileHandle);
63 DbgPrint((DPRINT_WINDOWS, "AnsiFileSize: %d\n", AnsiFileSize));
64 FsCloseFile(AnsiFileHandle);
65
66 /* Open OEM file and store its length */
67 if (AnsiEqualsOem)
68 {
69 OemFileSize = 0;
70 }
71 else
72 {
73 //Print(L"Loading %s...\n", Filename);
74 strcpy(FileName, DirectoryPath);
75 strcat(FileName, OemFileName);
76 OemFileHandle = FsOpenFile(FileName);
77
78 if (OemFileHandle == NULL)
79 goto Failure;
80
81 OemFileSize = FsGetFileSize(OemFileHandle);
82 FsCloseFile(OemFileHandle);
83 }
84 DbgPrint((DPRINT_WINDOWS, "OemFileSize: %d\n", OemFileSize));
85
86 /* And finally open the language codepage file and store its length */
87 //Print(L"Loading %s...\n", Filename);
88 strcpy(FileName, DirectoryPath);
89 strcat(FileName, LanguageFileName);
90 LanguageFileHandle = FsOpenFile(FileName);
91
92 if (LanguageFileHandle == NULL)
93 goto Failure;
94
95 LanguageFileSize = FsGetFileSize(LanguageFileHandle);
96 FsCloseFile(LanguageFileHandle);
97 DbgPrint((DPRINT_WINDOWS, "LanguageFileSize: %d\n", LanguageFileSize));
98
99 /* Sum up all three length, having in mind that every one of them
100 must start at a page boundary => thus round up each file to a page */
101 TotalSize = MM_SIZE_TO_PAGES(AnsiFileSize) +
102 MM_SIZE_TO_PAGES(OemFileSize) +
103 MM_SIZE_TO_PAGES(LanguageFileSize);
104
105 NlsDataBase = (ULONG_PTR)MmAllocateMemory(TotalSize*MM_PAGE_SIZE);
106
107 if (NlsDataBase == 0)
108 goto Failure;
109
110 NlsVirtual = (PVOID)(KSEG0_BASE | NlsDataBase);
111 LoaderBlock->NlsData->AnsiCodePageData = NlsVirtual;
112 LoaderBlock->NlsData->OemCodePageData = (PVOID)((PUCHAR)NlsVirtual +
113 (MM_SIZE_TO_PAGES(AnsiFileSize) << MM_PAGE_SHIFT));
114 LoaderBlock->NlsData->UnicodeCodePageData = (PVOID)((PUCHAR)NlsVirtual +
115 (MM_SIZE_TO_PAGES(AnsiFileSize) << MM_PAGE_SHIFT) +
116 (MM_SIZE_TO_PAGES(OemFileSize) << MM_PAGE_SHIFT));
117
118 /* Ansi and OEM data are the same - just set pointers to the same area */
119 if (AnsiEqualsOem)
120 LoaderBlock->NlsData->OemCodePageData = LoaderBlock->NlsData->AnsiCodePageData;
121
122
123 /* Now actually read the data into memory, starting with Ansi file */
124 strcpy(FileName, DirectoryPath);
125 strcat(FileName, AnsiFileName);
126 AnsiFileHandle = FsOpenFile(FileName);
127
128 if (AnsiFileHandle == NULL)
129 goto Failure;
130
131 Status = FsReadFile(AnsiFileHandle, AnsiFileSize, NULL, VaToPa(LoaderBlock->NlsData->AnsiCodePageData));
132
133 if (!Status)
134 goto Failure;
135
136 FsCloseFile(AnsiFileHandle);
137
138 /* OEM now, if it doesn't equal Ansi of course */
139 if (!AnsiEqualsOem)
140 {
141 strcpy(FileName, DirectoryPath);
142 strcat(FileName, OemFileName);
143 OemFileHandle = FsOpenFile(FileName);
144
145 if (OemFileHandle == NULL)
146 goto Failure;
147
148 Status = FsReadFile(OemFileHandle, OemFileSize, NULL, VaToPa(LoaderBlock->NlsData->OemCodePageData));
149
150 if (!Status)
151 goto Failure;
152
153 FsCloseFile(AnsiFileHandle);
154 }
155
156 /* finally the language file */
157 strcpy(FileName, DirectoryPath);
158 strcat(FileName, LanguageFileName);
159 LanguageFileHandle = FsOpenFile(FileName);
160
161 if (LanguageFileHandle == NULL)
162 goto Failure;
163
164 Status = FsReadFile(LanguageFileHandle, LanguageFileSize, NULL, VaToPa(LoaderBlock->NlsData->UnicodeCodePageData));
165
166 if (!Status)
167 goto Failure;
168
169 FsCloseFile(LanguageFileHandle);
170
171 //
172 // THIS IS HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACK
173 // Should go to WinLdrLoadOemHalFont(), when it will be implemented
174 //
175 LoaderBlock->OemFontFile = VaToPa(LoaderBlock->NlsData->UnicodeCodePageData);
176
177 /* Convert NlsTables address to VA */
178 LoaderBlock->NlsData = PaToVa(LoaderBlock->NlsData);
179
180 return TRUE;
181
182 Failure:
183 //UiMessageBox("Error reading NLS file %s\n", Filename);
184 UiMessageBox("Error reading NLS file!");
185 return FALSE;
186 }
187
188 BOOLEAN
189 WinLdrLoadSystemHive(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock,
190 IN LPCSTR DirectoryPath,
191 IN LPCSTR HiveName)
192 {
193 PFILE FileHandle;
194 CHAR FullHiveName[256];
195 BOOLEAN Status;
196 ULONG HiveFileSize;
197 ULONG_PTR HiveDataPhysical;
198 PVOID HiveDataVirtual;
199
200 /* Concatenate path and filename to get the full name */
201 strcpy(FullHiveName, DirectoryPath);
202 strcat(FullHiveName, HiveName);
203 //Print(L"Loading %s...\n", FullHiveName);
204 FileHandle = FsOpenFile(FullHiveName);
205
206 if (FileHandle == NULL)
207 {
208 UiMessageBox("Opening hive file failed!");
209 return FALSE;
210 }
211
212 /* Get the file length */
213 HiveFileSize = FsGetFileSize(FileHandle);
214
215 if (HiveFileSize == 0)
216 {
217 FsCloseFile(FileHandle);
218 UiMessageBox("Hive file has 0 size!");
219 return FALSE;
220 }
221
222 /* Round up the size to page boundary and alloc memory */
223 HiveDataPhysical = (ULONG_PTR)MmAllocateMemory(
224 MM_SIZE_TO_PAGES(HiveFileSize + MM_PAGE_SIZE - 1) << MM_PAGE_SHIFT);
225
226 if (HiveDataPhysical == 0)
227 {
228 FsCloseFile(FileHandle);
229 UiMessageBox("Unable to alloc memory for a hive!");
230 return FALSE;
231 }
232
233 /* Convert address to virtual */
234 HiveDataVirtual = (PVOID)(KSEG0_BASE | HiveDataPhysical);
235
236 /* Fill LoaderBlock's entries */
237 LoaderBlock->RegistryLength = HiveFileSize;
238 LoaderBlock->RegistryBase = HiveDataVirtual;
239
240 /* Finally read from file to the memory */
241 Status = FsReadFile(FileHandle, HiveFileSize, NULL, (PVOID)HiveDataPhysical);
242 FsCloseFile(FileHandle);
243 if (!Status)
244 {
245 UiMessageBox("Unable to read from hive file!");
246 return FALSE;
247 }
248
249 return TRUE;
250 }
251
252 void InitializeHWConfig(IN OUT PLOADER_PARAMETER_BLOCK LoaderBlock)
253 {
254 PCONFIGURATION_COMPONENT_DATA ConfigurationRoot;
255 PCONFIGURATION_COMPONENT Component;
256 PCONFIGURATION_COMPONENT_DATA /*CurrentEntry,*/ PreviousEntry, AdapterEntry;
257 BOOLEAN IsNextEntryChild;
258
259 DbgPrint((DPRINT_WINDOWS, "InitializeHWConfig()\n"));
260
261 LoaderBlock->ConfigurationRoot = MmAllocateMemory(sizeof(CONFIGURATION_COMPONENT_DATA));
262 RtlZeroMemory(LoaderBlock->ConfigurationRoot, sizeof(CONFIGURATION_COMPONENT_DATA));
263
264 /* Fill root == SystemClass */
265 ConfigurationRoot = LoaderBlock->ConfigurationRoot;
266 Component = &LoaderBlock->ConfigurationRoot->ComponentEntry;
267
268 Component->Class = SystemClass;
269 Component->Type = MaximumType;
270 Component->Version = 0; // FIXME: ?
271 Component->Key = 0;
272 Component->AffinityMask = 0;
273
274 IsNextEntryChild = TRUE;
275 PreviousEntry = ConfigurationRoot;
276
277 /* Enumerate all PCI buses */
278 AdapterEntry = ConfigurationRoot;
279
280 /* TODO: Disk Geometry */
281 /* TODO: Keyboard */
282
283 /* TODO: Serial port */
284
285 //Config->ConfigurationData = alloc(sizeof(CONFIGURATION_COMPONENT_DATA), EfiLoaderData);
286
287 /* Convert everything to VA */
288 ConvertConfigToVA(LoaderBlock->ConfigurationRoot);
289 LoaderBlock->ConfigurationRoot = PaToVa(LoaderBlock->ConfigurationRoot);
290 }
291
292
293 // Init "phase 0"
294 VOID
295 AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock)
296 {
297 PLOADER_PARAMETER_BLOCK LoaderBlock;
298
299 /* Allocate and zero-init the LPB */
300 LoaderBlock = MmAllocateMemory(sizeof(LOADER_PARAMETER_BLOCK));
301 RtlZeroMemory(LoaderBlock, sizeof(LOADER_PARAMETER_BLOCK));
302
303 /* Init three critical lists, used right away */
304 InitializeListHead(&LoaderBlock->LoadOrderListHead);
305 InitializeListHead(&LoaderBlock->MemoryDescriptorListHead);
306 InitializeListHead(&LoaderBlock->BootDriverListHead);
307
308
309 *OutLoaderBlock = LoaderBlock;
310 }
311
312 // Init "phase 1"
313 VOID
314 WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock)
315 {
316 //CHAR Options[] = "/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200";
317 CHAR Options[] = "/NODEBUG";
318 CHAR SystemRoot[] = "\\WINNT";
319 CHAR HalPath[] = "\\";
320 CHAR ArcBoot[] = "multi(0)";
321 CHAR ArcHal[] = "multi(0)";
322
323 PLOADER_PARAMETER_EXTENSION Extension;
324
325 LoaderBlock->u.I386.CommonDataArea = NULL; // Force No ABIOS support
326
327 /* Fill Arc BootDevice */
328 LoaderBlock->ArcBootDeviceName = MmAllocateMemory(strlen(ArcBoot)+1);
329 strcpy(LoaderBlock->ArcBootDeviceName, ArcBoot);
330 LoaderBlock->ArcBootDeviceName = PaToVa(LoaderBlock->ArcBootDeviceName);
331
332 /* Fill Arc HalDevice */
333 LoaderBlock->ArcHalDeviceName = MmAllocateMemory(strlen(ArcHal)+1);
334 strcpy(LoaderBlock->ArcHalDeviceName, ArcHal);
335 LoaderBlock->ArcHalDeviceName = PaToVa(LoaderBlock->ArcHalDeviceName);
336
337 /* Fill SystemRoot */
338 LoaderBlock->NtBootPathName = MmAllocateMemory(strlen(SystemRoot)+1);
339 strcpy(LoaderBlock->NtBootPathName, SystemRoot);
340 LoaderBlock->NtBootPathName = PaToVa(LoaderBlock->NtBootPathName);
341
342 /* Fill NtHalPathName */
343 LoaderBlock->NtHalPathName = MmAllocateMemory(strlen(HalPath)+1);
344 strcpy(LoaderBlock->NtHalPathName, HalPath);
345 LoaderBlock->NtHalPathName = PaToVa(LoaderBlock->NtHalPathName);
346
347 /* Fill load options */
348 LoaderBlock->LoadOptions = MmAllocateMemory(strlen(Options)+1);
349 strcpy(LoaderBlock->LoadOptions, Options);
350 LoaderBlock->LoadOptions = PaToVa(LoaderBlock->LoadOptions);
351
352 /* Arc devices */
353 LoaderBlock->ArcDiskInformation = (PARC_DISK_INFORMATION)MmAllocateMemory(sizeof(ARC_DISK_INFORMATION));
354 InitializeListHead(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead);
355 List_PaToVa(&LoaderBlock->ArcDiskInformation->DiskSignatureListHead);
356 LoaderBlock->ArcDiskInformation = PaToVa(LoaderBlock->ArcDiskInformation);
357
358 /* Alloc space for NLS (it will be converted to VA in WinLdrLoadNLS) */
359 LoaderBlock->NlsData = MmAllocateMemory(sizeof(NLS_DATA_BLOCK));
360 if (LoaderBlock->NlsData == NULL)
361 {
362 UiMessageBox("Failed to allocate memory for NLS table data!");
363 return;
364 }
365 RtlZeroMemory(LoaderBlock->NlsData, sizeof(NLS_DATA_BLOCK));
366
367 /* Create configuration entries */
368 InitializeHWConfig(LoaderBlock);
369
370 /* Convert all DTE into virtual addresses */
371 //TODO: !!!
372
373 /* Convert all list's to Virtual address */
374 List_PaToVa(&LoaderBlock->LoadOrderListHead);
375
376 /* this one will be converted right before switching to
377 virtual paging mode */
378 //List_PaToVa(&LoaderBlock->MemoryDescriptorListHead);
379
380 List_PaToVa(&LoaderBlock->BootDriverListHead);
381
382 /* Initialize Extension now */
383 Extension = MmAllocateMemory(sizeof(LOADER_PARAMETER_EXTENSION));
384 if (Extension == NULL)
385 {
386 UiMessageBox("Failed to allocate LPB Extension!");
387 return;
388 }
389 RtlZeroMemory(Extension, sizeof(LOADER_PARAMETER_EXTENSION));
390
391 Extension->Size = sizeof(LOADER_PARAMETER_EXTENSION);
392 Extension->MajorVersion = 4;
393 Extension->MinorVersion = 0;
394
395
396 LoaderBlock->Extension = PaToVa(Extension);
397 }
398
399 // Last step before going virtual
400 void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock,
401 PVOID *GdtIdt,
402 ULONG *PcrBasePage,
403 ULONG *TssBasePage)
404 {
405 ULONG TssSize;
406 ULONG TssPages;
407 ULONG_PTR Pcr = 0;
408 ULONG_PTR Tss = 0;
409 ULONG BlockSize, NumPages;
410
411 LoaderBlock->u.I386.CommonDataArea = NULL;//CommonDataArea;
412 //LoaderBlock->u.I386.MachineType = MachineType; //FIXME: MachineType?
413
414 /* Allocate 2 pages for PCR */
415 Pcr = (ULONG_PTR)MmAllocateMemory(2 * MM_PAGE_SIZE);
416 *PcrBasePage = Pcr >> MM_PAGE_SHIFT;
417
418 if (Pcr == 0)
419 {
420 UiMessageBox("Can't allocate PCR\n");
421 return;
422 }
423
424 /* Allocate TSS */
425 TssSize = (sizeof(KTSS) + MM_PAGE_SIZE) & ~(MM_PAGE_SIZE - 1);
426 TssPages = TssSize / MM_PAGE_SIZE;
427
428 Tss = (ULONG_PTR)MmAllocateMemory(TssSize);
429
430 *TssBasePage = Tss >> MM_PAGE_SHIFT;
431
432 /* Allocate space for new GDT + IDT */
433 BlockSize = NUM_GDT*sizeof(KGDTENTRY) + NUM_IDT*sizeof(KIDTENTRY);//FIXME: Use GDT/IDT limits here?
434 NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT;
435 *GdtIdt = (PKGDTENTRY)MmAllocateMemory(NumPages * MM_PAGE_SIZE);
436
437 if (*GdtIdt == NULL)
438 {
439 UiMessageBox("Can't allocate pages for GDT+IDT!\n");
440 return;
441 }
442
443 /* Zero newly prepared GDT+IDT */
444 RtlZeroMemory(*GdtIdt, NumPages << MM_PAGE_SHIFT);
445 }
446
447 VOID
448 LoadAndBootWindows(PCSTR OperatingSystemName, WORD OperatingSystemVersion)
449 {
450 CHAR MsgBuffer[256];
451 CHAR SystemPath[1024], SearchPath[1024];
452 CHAR FileName[1024];
453 CHAR BootPath[256];
454 PVOID NtosBase = NULL, HalBase = NULL;
455 BOOLEAN Status;
456 ULONG SectionId;
457 ULONG BootDevice;
458 PLOADER_PARAMETER_BLOCK LoaderBlock, LoaderBlockVA;
459 KERNEL_ENTRY_POINT KiSystemStartup;
460 PLDR_DATA_TABLE_ENTRY KernelDTE, HalDTE;
461 // Mm-related things
462 PVOID GdtIdt;
463 ULONG PcrBasePage=0;
464 ULONG TssBasePage=0;
465
466
467
468 //sprintf(MsgBuffer,"Booting Microsoft(R) Windows(R) OS version '%04x' is not implemented yet", OperatingSystemVersion);
469 //UiMessageBox(MsgBuffer);
470
471 //
472 // Open the operating system section
473 // specified in the .ini file
474 //
475 if (!IniOpenSection(OperatingSystemName, &SectionId))
476 {
477 sprintf(MsgBuffer,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName);
478 UiMessageBox(MsgBuffer);
479 return;
480 }
481
482 /*
483 * Make sure the system path is set in the .ini file
484 */
485 if (!IniReadSettingByName(SectionId, "SystemPath", SystemPath, sizeof(SystemPath)))
486 {
487 UiMessageBox("System path not specified for selected operating system.");
488 return;
489 }
490
491 if (!MachDiskNormalizeSystemPath(SystemPath,
492 sizeof(SystemPath)))
493 {
494 UiMessageBox("Invalid system path");
495 return;
496 }
497
498 UiDrawStatusText("Loading...");
499
500 /*
501 * Try to open system drive
502 */
503 BootDevice = 0xffffffff;
504 if (!FsOpenSystemVolume(SystemPath, BootPath, &BootDevice))
505 {
506 UiMessageBox("Failed to open boot drive.");
507 return;
508 }
509
510 /* append a backslash */
511 if ((strlen(BootPath)==0) ||
512 BootPath[strlen(BootPath)] != '\\')
513 strcat(BootPath, "\\");
514
515 DbgPrint((DPRINT_WINDOWS,"SystemRoot: '%s'\n", BootPath));
516
517 /* Allocate and minimalistic-initialize LPB */
518 AllocateAndInitLPB(&LoaderBlock);
519
520 // Load kernel
521 strcpy(FileName, BootPath);
522 strcat(FileName, "SYSTEM32\\NTOSKRNL.EXE");
523 Status = WinLdrLoadImage(FileName, &NtosBase);
524 DbgPrint((DPRINT_WINDOWS, "Ntos loaded with status %d\n", Status));
525
526 // Load HAL
527 strcpy(FileName, BootPath);
528 strcat(FileName, "SYSTEM32\\HAL.DLL");
529 Status = WinLdrLoadImage(FileName, &HalBase);
530 DbgPrint((DPRINT_WINDOWS, "HAL loaded with status %d\n", Status));
531
532 WinLdrAllocateDataTableEntry(LoaderBlock, "ntoskrnl.exe",
533 "WINNT\\SYSTEM32\\NTOSKRNL.EXE", NtosBase, &KernelDTE);
534 WinLdrAllocateDataTableEntry(LoaderBlock, "hal.dll",
535 "WINNT\\SYSTEM32\\HAL.EXE", HalBase, &HalDTE);
536
537 /* Load all referenced DLLs for kernel and HAL */
538 strcpy(SearchPath, BootPath);
539 strcat(SearchPath, "SYSTEM32\\");
540 WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, KernelDTE);
541 WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, HalDTE);
542
543 /* Initialize Phase 1 - before NLS */
544 WinLdrInitializePhase1(LoaderBlock);
545
546 /* Load SYSTEM hive and its LOG file */
547 strcpy(SearchPath, BootPath);
548 strcat(SearchPath, "SYSTEM32\\CONFIG\\");
549 Status = WinLdrLoadSystemHive(LoaderBlock, SearchPath, "SYSTEM");
550 DbgPrint((DPRINT_WINDOWS, "SYSTEM hive loaded with status %d\n", Status));
551
552 /* Load NLS data */
553 strcpy(SearchPath, BootPath);
554 strcat(SearchPath, "SYSTEM32\\");
555 Status = WinLdrLoadNLSData(LoaderBlock, SearchPath,
556 "c_1252.nls", "c_437.nls", "l_intl.nls");
557 DbgPrint((DPRINT_WINDOWS, "NLS data loaded with status %d\n", Status));
558
559 /* Load OEM HAL font */
560
561 /* Load boot drivers */
562
563 /* Alloc PCR, TSS, do magic things with the GDT/IDT */
564 WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage);
565
566 /* Save entry-point pointer (VA) */
567 KiSystemStartup = (KERNEL_ENTRY_POINT)KernelDTE->EntryPoint;
568
569 LoaderBlockVA = PaToVa(LoaderBlock);
570
571 /* Debugging... */
572 //DumpMemoryAllocMap();
573
574 /* Turn on paging mode of CPU*/
575 WinLdrTurnOnPaging(LoaderBlock, PcrBasePage, TssBasePage, GdtIdt);
576
577 DbgPrint((DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
578 KiSystemStartup, LoaderBlockVA));
579
580 WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
581
582 // temp: offset C9000
583
584 //FIXME: If I substitute this debugging checkpoint, GCC will "optimize away" the code below
585 //while (1) {};
586 asm(".intel_syntax noprefix\n");
587 asm("test1:\n");
588 asm("jmp test1\n");
589 asm(".att_syntax\n");
590
591
592 (*KiSystemStartup)(LoaderBlockVA);
593
594 return;
595 }
596
597 VOID
598 WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock)
599 {
600 PLIST_ENTRY NextMd;
601 PMEMORY_ALLOCATION_DESCRIPTOR MemoryDescriptor;
602
603 NextMd = LoaderBlock->MemoryDescriptorListHead.Flink;
604
605 while (NextMd != &LoaderBlock->MemoryDescriptorListHead)
606 {
607 MemoryDescriptor = CONTAINING_RECORD(NextMd, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry);
608
609
610 DbgPrint((DPRINT_WINDOWS, "BP %08X PC %04X MT %d\n", MemoryDescriptor->BasePage,
611 MemoryDescriptor->PageCount, MemoryDescriptor->MemoryType));
612
613 NextMd = MemoryDescriptor->ListEntry.Flink;
614 }
615 }