VOID LoadAndBootWindows(IN OperatingSystemItem* OperatingSystem, IN USHORT OperatingSystemVersion) { ULONG_PTR SectionId; PCSTR SectionName = OperatingSystem->SystemPartition; CHAR SettingsValue[80]; BOOLEAN HasSection; CHAR BootPath[MAX_PATH]; CHAR FileName[MAX_PATH]; CHAR BootOptions[256]; PCHAR File; BOOLEAN Status; PLOADER_PARAMETER_BLOCK LoaderBlock; // Get OS setting value SettingsValue[0] = ANSI_NULL; IniOpenSection("Operating Systems", &SectionId); IniReadSettingByName(SectionId, SectionName, SettingsValue, sizeof(SettingsValue)); // Open the operating system section // specified in the .ini file HasSection = IniOpenSection(SectionName, &SectionId); UiDrawBackdrop(); UiDrawProgressBarCenter(1, 100, "Loading NT..."); /* Read the system path is set in the .ini file */ if (!HasSection || !IniReadSettingByName(SectionId, "SystemPath", BootPath, sizeof(BootPath))) { strcpy(BootPath, SectionName); } /* Special case for LiveCD */ if (!_strnicmp(BootPath, "LiveCD", strlen("LiveCD"))) { strcpy(FileName, BootPath + strlen("LiveCD")); MachDiskGetBootPath(BootPath, sizeof(BootPath)); strcat(BootPath, FileName); } /* Append a backslash */ if ((strlen(BootPath)==0) || BootPath[strlen(BootPath)] != '\\') strcat(BootPath, "\\"); /* Read booting options */ if (!HasSection || !IniReadSettingByName(SectionId, "Options", BootOptions, sizeof(BootOptions))) { /* Get options after the title */ PCSTR p = SettingsValue; while (*p == ' ' || *p == '"') p++; while (*p != '\0' && *p != '"') p++; strcpy(BootOptions, p); TRACE("BootOptions: '%s'\n", BootOptions); } /* Append boot-time options */ AppendBootTimeOptions(BootOptions); /* Check if a ramdisk file was given */ File = strstr(BootOptions, "/RDPATH="); if (File) { /* Copy the file name and everything else after it */ strcpy(FileName, File + 8); /* Null-terminate */ *strstr(FileName, " ") = ANSI_NULL; /* Load the ramdisk */ RamDiskLoadVirtualFile(FileName); } /* Let user know we started loading */ //UiDrawStatusText("Loading..."); TRACE("BootPath: '%s'\n", BootPath); /* Allocate and minimalistic-initialize LPB */ AllocateAndInitLPB(&LoaderBlock); #ifdef _M_IX86 /* Setup redirection support */ WinLdrSetupEms(BootOptions); #endif /* Load Hive */ UiDrawBackdrop(); UiDrawProgressBarCenter(15, 100, "Loading system hive..."); Status = WinLdrInitSystemHive(LoaderBlock, BootPath); TRACE("SYSTEM hive %s\n", (Status ? "loaded" : "not loaded")); /* Load NLS data, OEM font, and prepare boot drivers list */ Status = WinLdrScanSystemHive(LoaderBlock, BootPath); TRACE("SYSTEM hive %s\n", (Status ? "scanned" : "not scanned")); /* Finish loading */ LoadAndBootWindowsCommon(OperatingSystemVersion, LoaderBlock, BootOptions, BootPath, 0); }
VOID LoadAndBootWindowsCommon( USHORT OperatingSystemVersion, PLOADER_PARAMETER_BLOCK LoaderBlock, LPCSTR BootOptions, LPCSTR BootPath, BOOLEAN Setup) { PLOADER_PARAMETER_BLOCK LoaderBlockVA; BOOLEAN Success; PLDR_DATA_TABLE_ENTRY KernelDTE; KERNEL_ENTRY_POINT KiSystemStartup; LPCSTR SystemRoot; TRACE("LoadAndBootWindowsCommon()\n"); #ifdef _M_IX86 /* Setup redirection support */ WinLdrSetupEms((PCHAR)BootOptions); #endif /* Convert BootPath to SystemRoot */ SystemRoot = strstr(BootPath, "\\"); /* Detect hardware */ LoaderBlock->ConfigurationRoot = MachHwDetect(); if (OperatingSystemVersion == 0) OperatingSystemVersion = WinLdrDetectVersion(); /* Load the operating system core: the Kernel, the HAL and the Kernel Debugger Transport DLL */ Success = LoadWindowsCore(OperatingSystemVersion, LoaderBlock, BootOptions, BootPath, &KernelDTE); if (!Success) { UiMessageBox("Error loading NTOS core."); return; } /* Load boot drivers */ UiDrawBackdrop(); UiDrawProgressBarCenter(100, 100, "Loading boot drivers..."); Success = WinLdrLoadBootDrivers(LoaderBlock, BootPath); TRACE("Boot drivers loading %s\n", Success ? "successful" : "failed"); /* Initialize Phase 1 - no drivers loading anymore */ WinLdrInitializePhase1(LoaderBlock, BootOptions, SystemRoot, BootPath, OperatingSystemVersion); /* Save entry-point pointer and Loader block VAs */ KiSystemStartup = (KERNEL_ENTRY_POINT)KernelDTE->EntryPoint; LoaderBlockVA = PaToVa(LoaderBlock); /* "Stop all motors", change videomode */ MachPrepareForReactOS(Setup); /* Cleanup ini file */ IniCleanup(); /* Debugging... */ //DumpMemoryAllocMap(); /* Do the machine specific initialization */ WinLdrSetupMachineDependent(LoaderBlock); /* Map pages and create memory descriptors */ WinLdrSetupMemoryLayout(LoaderBlock); /* Set processor context */ WinLdrSetProcessorContext(); /* Save final value of LoaderPagesSpanned */ LoaderBlock->Extension->LoaderPagesSpanned = LoaderPagesSpanned; TRACE("Hello from paged mode, KiSystemStartup %p, LoaderBlockVA %p!\n", KiSystemStartup, LoaderBlockVA); // Zero KI_USER_SHARED_DATA page memset((PVOID)KI_USER_SHARED_DATA, 0, MM_PAGE_SIZE); WinLdrpDumpMemoryDescriptors(LoaderBlockVA); WinLdrpDumpBootDriver(LoaderBlockVA); #ifndef _M_AMD64 WinLdrpDumpArcDisks(LoaderBlockVA); #endif /* Pass control */ (*KiSystemStartup)(LoaderBlockVA); }