[ros-diffs] [fireball] 40028: - Implement first part of setupldr: * Constructing boot / system paths * Opening boot device * Getting options string * Loading kernel, hal and kdcom.dll, and their dependencies
fireball at svn.reactos.org
fireball at svn.reactos.org
Sun Mar 15 11:46:42 CET 2009
Author: fireball
Date: Sun Mar 15 13:46:41 2009
New Revision: 40028
URL: http://svn.reactos.org/svn/reactos?rev=40028&view=rev
Log:
- Implement first part of setupldr:
* Constructing boot / system paths
* Opening boot device
* Getting options string
* Loading kernel, hal and kdcom.dll, and their dependencies
Modified:
trunk/reactos/boot/freeldr/freeldr/windows/setupldr2.c
Modified: trunk/reactos/boot/freeldr/freeldr/windows/setupldr2.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windows/setupldr2.c?rev=40028&r1=40027&r2=40028&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/setupldr2.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/setupldr2.c [iso-8859-1] Sun Mar 15 13:46:41 2009
@@ -23,7 +23,205 @@
#include <ndk/ldrtypes.h>
#include <debug.h>
+// TODO: Move to .h
+VOID AllocateAndInitLPB(PLOADER_PARAMETER_BLOCK *OutLoaderBlock);
+BOOLEAN WinLdrLoadBootDrivers(PLOADER_PARAMETER_BLOCK LoaderBlock, LPSTR BootPath);
+void WinLdrSetupForNt(PLOADER_PARAMETER_BLOCK LoaderBlock,
+ PVOID *GdtIdt,
+ ULONG *PcrBasePage,
+ ULONG *TssBasePage);
+VOID
+WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock,
+ PCHAR Options,
+ PCHAR SystemPath,
+ PCHAR BootPath,
+ USHORT VersionToBoot);
+
+
+
+//FIXME: Do a better way to retrieve Arc disk information
+extern ULONG reactos_disk_count;
+extern ARC_DISK_SIGNATURE reactos_arc_disk_info[];
+extern char reactos_arc_strings[32][256];
+
+extern BOOLEAN UseRealHeap;
+extern ULONG LoaderPagesSpanned;
+
VOID LoadReactOSSetup2(VOID)
{
+ CHAR SystemPath[512], SearchPath[512];
+ CHAR FileName[512];
+ CHAR BootPath[512];
+ LPCSTR BootOptions;
+ PVOID NtosBase = NULL, HalBase = NULL, KdComBase = NULL;
+ BOOLEAN Status;
+ ULONG BootDevice;
+ ULONG i, ErrorLine;
+ HINF InfHandle;
+ INFCONTEXT InfContext;
+ PLOADER_PARAMETER_BLOCK LoaderBlock, LoaderBlockVA;
+ KERNEL_ENTRY_POINT KiSystemStartup;
+ PLDR_DATA_TABLE_ENTRY KernelDTE, HalDTE, KdComDTE = NULL;
+ // Mm-related things
+ PVOID GdtIdt;
+ ULONG PcrBasePage=0;
+ ULONG TssBasePage=0;
+ LPCSTR SourcePath;
+ LPCSTR SourcePaths[] =
+ {
+ "", /* Only for floppy boot */
+#if defined(_M_IX86)
+ "\\I386",
+#elif defined(_M_MPPC)
+ "\\PPC",
+#elif defined(_M_MRX000)
+ "\\MIPS",
+#endif
+ "\\reactos",
+ NULL
+ };
+
+ /* Get boot device number */
+ MachDiskGetBootDevice(&BootDevice);
+
+ /* Open 'txtsetup.sif' from any of source paths */
+ for (i = MachDiskBootingFromFloppy() ? 0 : 1; ; i++)
+ {
+ SourcePath = SourcePaths[i];
+ if (!SourcePath)
+ {
+ printf("Failed to open 'txtsetup.sif'\n");
+ return;
+ }
+ sprintf(FileName,"%s\\txtsetup.sif", SourcePath);
+ if (InfOpenFile (&InfHandle, FileName, &ErrorLine))
+ break;
+ }
+
+ /* If we didn't find it anywhere, then just use root */
+ if (!*SourcePath)
+ SourcePath = "\\";
+
+ /* Load options */
+ if (!InfFindFirstLine(InfHandle,
+ "SetupData",
+ "OsLoadOptions",
+ &InfContext))
+ {
+ printf("Failed to find 'SetupData/OsLoadOptions'\n");
+ return;
+ }
+
+ if (!InfGetDataField (&InfContext, 1, &BootOptions))
+ {
+ printf("Failed to get load options\n");
+ return;
+ }
+
+ /* Save source path */
+ strcpy(BootPath, SourcePath);
+
+ SetupUiInitialize();
+ UiDrawStatusText("");
+ UiDrawStatusText("Detecting Hardware...");
+
+ /* Let user know we started loading */
+ UiDrawStatusText("Loading...");
+
+ /* Try to open system drive */
+ FsOpenBootVolume();
+
+ /* Append a backslash to the bootpath if needed */
+ if ((strlen(BootPath)==0) || BootPath[strlen(BootPath)] != '\\')
+ {
+ strcat(BootPath, "\\");
+ }
+
+ /* Construct the system path */
+ MachDiskGetBootPath(SystemPath, sizeof(SystemPath));
+ strcat(SystemPath, SourcePath);
+
+ DPRINTM(DPRINT_WINDOWS,"SystemRoot: '%s', SystemPath: '%s'\n", BootPath, SystemPath);
+
+ /* Allocate and minimalistic-initialize LPB */
+ AllocateAndInitLPB(&LoaderBlock);
+
+ /* Detect hardware */
+ UseRealHeap = TRUE;
+ LoaderBlock->ConfigurationRoot = MachHwDetect();
+
+ /* Load kernel */
+ strcpy(FileName, BootPath);
+ strcat(FileName, "NTOSKRNL.EXE");
+ Status = WinLdrLoadImage(FileName, LoaderSystemCode, &NtosBase);
+ DPRINTM(DPRINT_WINDOWS, "Ntos loaded with status %d at %p\n", Status, NtosBase);
+
+ /* Load HAL */
+ strcpy(FileName, BootPath);
+ strcat(FileName, "HAL.DLL");
+ Status = WinLdrLoadImage(FileName, LoaderHalCode, &HalBase);
+ DPRINTM(DPRINT_WINDOWS, "HAL loaded with status %d at %p\n", Status, HalBase);
+
+ /* Load kernel-debugger support dll */
+ strcpy(FileName, BootPath);
+ strcat(FileName, "KDCOM.DLL");
+ Status = WinLdrLoadImage(FileName, LoaderBootDriver, &KdComBase);
+ DPRINTM(DPRINT_WINDOWS, "KdCom loaded with status %d at %p\n", Status, KdComBase);
+
+ /* Allocate data table entries for above-loaded modules */
+ WinLdrAllocateDataTableEntry(LoaderBlock, "ntoskrnl.exe",
+ "NTOSKRNL.EXE", NtosBase, &KernelDTE);
+ WinLdrAllocateDataTableEntry(LoaderBlock, "hal.dll",
+ "HAL.DLL", HalBase, &HalDTE);
+ WinLdrAllocateDataTableEntry(LoaderBlock, "kdcom.dll",
+ "KDCOM.DLL", KdComBase, &KdComDTE);
+
+ /* Load all referenced DLLs for kernel, HAL and kdcom.dll */
+ strcpy(SearchPath, BootPath);
+ WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, KernelDTE);
+ WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, HalDTE);
+ if (KdComDTE)
+ WinLdrScanImportDescriptorTable(LoaderBlock, SearchPath, KdComDTE);
+
+ /* Load Hive, and then NLS data, OEM font, and prepare boot drivers list */
+ //Status = WinLdrLoadAndScanSystemHive(LoaderBlock, BootPath);
+ DPRINTM(DPRINT_WINDOWS, "SYSTEM hive loaded and scanned with status %d\n", Status);
+
+ /* Load boot drivers */
+ //Status = WinLdrLoadBootDrivers(LoaderBlock, BootPath);
+ DPRINTM(DPRINT_WINDOWS, "Boot drivers loaded with status %d\n", Status);
+
+ /* Alloc PCR, TSS, do magic things with the GDT/IDT */
+ WinLdrSetupForNt(LoaderBlock, &GdtIdt, &PcrBasePage, &TssBasePage);
+
+ /* Initialize Phase 1 - no drivers loading anymore */
+ WinLdrInitializePhase1(LoaderBlock, (PCHAR)BootOptions, SystemPath, BootPath, _WIN32_WINNT_WS03);
+
+ /* Save entry-point pointer and Loader block VAs */
+ KiSystemStartup = (KERNEL_ENTRY_POINT)KernelDTE->EntryPoint;
+ LoaderBlockVA = PaToVa(LoaderBlock);
+
+ /* "Stop all motors", change videomode */
+ MachPrepareForReactOS(FALSE);
+
+ /* Debugging... */
+ //DumpMemoryAllocMap();
+
+ /* Turn on paging mode of CPU*/
+ WinLdrTurnOnPaging(LoaderBlock, PcrBasePage, TssBasePage, GdtIdt);
+
+ /* Save final value of LoaderPagesSpanned */
+ LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned;
+
+ DPRINTM(DPRINT_WINDOWS, "Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n",
+ KiSystemStartup, LoaderBlockVA);
+
+ //WinLdrpDumpMemoryDescriptors(LoaderBlockVA);
+ //WinLdrpDumpBootDriver(LoaderBlockVA);
+ //WinLdrpDumpArcDisks(LoaderBlockVA);
+
+ /* Pass control */
+ (*KiSystemStartup)(LoaderBlockVA);
+
+ return;
}
-
More information about the Ros-diffs
mailing list