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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 VOID
DumpMemoryAllocMap(VOID
);
28 VOID
WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock
);
31 LoadAndBootWindows(PCSTR OperatingSystemName
, WORD OperatingSystemVersion
)
34 CHAR SystemPath
[1024], SearchPath
[1024];
37 PVOID NtosBase
= NULL
, HalBase
= NULL
;
41 PLOADER_PARAMETER_BLOCK LoaderBlock
=NULL
, LoaderBlockVA
;
42 PLDR_DATA_TABLE_ENTRY KernelDTE
, HalDTE
;
43 KERNEL_ENTRY_POINT KiSystemStartup
;
49 //sprintf(MsgBuffer,"Booting Microsoft(R) Windows(R) OS version '%04x' is not implemented yet", OperatingSystemVersion);
50 //UiMessageBox(MsgBuffer);
53 // Open the operating system section
54 // specified in the .ini file
56 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
58 sprintf(MsgBuffer
,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName
);
59 UiMessageBox(MsgBuffer
);
64 * Make sure the system path is set in the .ini file
66 if (!IniReadSettingByName(SectionId
, "SystemPath", SystemPath
, sizeof(SystemPath
)))
68 UiMessageBox("System path not specified for selected operating system.");
72 if (!MachDiskNormalizeSystemPath(SystemPath
,
75 UiMessageBox("Invalid system path");
79 UiDrawStatusText("Loading...");
82 * Try to open system drive
84 BootDevice
= 0xffffffff;
85 if (!FsOpenSystemVolume(SystemPath
, BootPath
, &BootDevice
))
87 UiMessageBox("Failed to open boot drive.");
91 /* append a backslash */
92 if ((strlen(BootPath
)==0) ||
93 BootPath
[strlen(BootPath
)] != '\\')
94 strcat(BootPath
, "\\");
96 DbgPrint((DPRINT_WINDOWS
,"SystemRoot: '%s'\n", BootPath
));
98 /* Allocate and minimalistic-initialize LPB */
99 //AllocateAndInitLPB(&LoaderBlock);
102 strcpy(FileName
, BootPath
);
103 strcat(FileName
, "SYSTEM32\\NTOSKRNL.EXE");
104 Status
= WinLdrLoadImage(FileName
, &NtosBase
);
105 DbgPrint((DPRINT_WINDOWS
, "Ntos loaded with status %d\n", Status
));
108 strcpy(FileName
, BootPath
);
109 strcat(FileName
, "SYSTEM32\\HAL.DLL");
110 Status
= WinLdrLoadImage(FileName
, &HalBase
);
111 DbgPrint((DPRINT_WINDOWS
, "HAL loaded with status %d\n", Status
));
113 WinLdrAllocateDataTableEntry(LoaderBlock
, "ntoskrnl.exe",
114 "WINNT\\SYSTEM32\\NTOSKRNL.EXE", NtosBase
, &KernelDTE
);
115 WinLdrAllocateDataTableEntry(LoaderBlock
, "hal.dll",
116 "WINNT\\SYSTEM32\\HAL.EXE", HalBase
, &HalDTE
);
118 /* Load all referenced DLLs for kernel and HAL */
119 strcpy(SearchPath
, BootPath
);
120 strcat(SearchPath
, "SYSTEM32\\");
121 WinLdrScanImportDescriptorTable(LoaderBlock
, SearchPath
, KernelDTE
);
122 WinLdrScanImportDescriptorTable(LoaderBlock
, SearchPath
, HalDTE
);
124 /* Initialize Phase 1 - before NLS */
125 //WinLdrInitializePhase1(LoaderBlock);
127 /* Load SYSTEM hive and its LOG file */
128 strcpy(SearchPath
, BootPath
);
129 strcat(SearchPath
, "SYSTEM32\\CONFIG\\");
130 //Status = WinLdrLoadSystemHive(LoaderBlock, SearchPath, "SYSTEM");
131 DbgPrint((DPRINT_WINDOWS
, "SYSTEM hive loaded with status %d\n", Status
));
134 strcpy(SearchPath
, BootPath
);
135 strcat(SearchPath
, "SYSTEM32\\");
136 //Status = WinLdrLoadNLSData(LoaderBlock, SearchPath,
137 // "c_1252.nls", "c_437.nls", "l_intl.nls");
138 DbgPrint((DPRINT_WINDOWS
, "NLS data loaded with status %d\n", Status
));
140 /* Load OEM HAL font */
142 /* Load boot drivers */
144 /* Alloc PCR, TSS, do magic things with the GDT/IDT */
145 //WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage);
147 /* Save entry-point pointer (VA) */
148 KiSystemStartup
= (KERNEL_ENTRY_POINT
)KernelDTE
->EntryPoint
;
149 LoaderBlockVA
= PaToVa(LoaderBlock
);
152 //DumpMemoryAllocMap();
154 /* Turn on paging mode of CPU*/
155 WinLdrTurnOnPaging(LoaderBlock
, PcrBasePage
, TssBasePage
, GdtIdt
);
157 DbgPrint((DPRINT_WINDOWS
, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
158 KiSystemStartup
, LoaderBlockVA
));
160 WinLdrpDumpMemoryDescriptors(LoaderBlockVA
);
170 ULONG *trrr = (ULONG *)(512*1024*1024);
178 (KiSystemStartup
)(LoaderBlockVA
);
184 WinLdrpDumpMemoryDescriptors(PLOADER_PARAMETER_BLOCK LoaderBlock
)
187 PMEMORY_ALLOCATION_DESCRIPTOR MemoryDescriptor
;
189 NextMd
= LoaderBlock
->MemoryDescriptorListHead
.Flink
;
191 while (NextMd
!= &LoaderBlock
->MemoryDescriptorListHead
)
193 MemoryDescriptor
= CONTAINING_RECORD(NextMd
, MEMORY_ALLOCATION_DESCRIPTOR
, ListEntry
);
196 DbgPrint((DPRINT_WINDOWS
, "BP %08X PC %04X MT %d\n", MemoryDescriptor
->BasePage
,
197 MemoryDescriptor
->PageCount
, MemoryDescriptor
->MemoryType
));
199 NextMd
= MemoryDescriptor
->ListEntry
.Flink
;