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