VOID DoOptionsMenu(VOID) { ULONG SelectedMenuItem; if (!UiDisplayMenu(OptionsMenuList, OptionsMenuItemCount, 0, -1, &SelectedMenuItem, TRUE, NULL)) { // The user pressed ESC return; } // Clear the backdrop UiDrawBackdrop(); switch (SelectedMenuItem) { case SAFE_MODE: SafeMode = TRUE; BootLogging = TRUE; break; case SAFE_MODE_WITH_NETWORKING: SafeModeWithNetworking = TRUE; BootLogging = TRUE; break; case SAFE_MODE_WITH_COMMAND_PROMPT: SafeModeWithCommandPrompt = TRUE; BootLogging = TRUE; break; //case SEPARATOR1: // break; case ENABLE_BOOT_LOGGING: BootLogging = TRUE; break; case ENABLE_VGA_MODE: VgaMode = TRUE; break; case LAST_KNOWN_GOOD_CONFIGURATION: LastKnownGoodConfiguration = TRUE; break; case DIRECTORY_SERVICES_RESTORE_MODE: DirectoryServicesRepairMode = TRUE; break; case DEBUGGING_MODE: DebuggingMode = TRUE; break; case BOOT_NORMALLY: break; //case SEPARATOR2: // break; #ifdef HAS_OPTION_MENU_CUSTOM_BOOT case CUSTOM_BOOT: OptionMenuCustomBoot(); break; #endif #ifdef HAS_OPTION_MENU_REBOOT case REBOOT: OptionMenuReboot(); break; #endif } }
VOID UiUnInitialize(PCSTR BootText) { UiDrawBackdrop(); UiDrawStatusText("Booting..."); UiInfoBox(BootText); UiVtbl.UnInitialize(); }
static BOOLEAN LoadModule( PLOADER_PARAMETER_BLOCK LoaderBlock, PCCH Path, PCCH File, TYPE_OF_MEMORY MemoryType, PLDR_DATA_TABLE_ENTRY *Dte, BOOLEAN IsKdTransportDll, ULONG Percentage) { BOOLEAN Status; CHAR FullFileName[MAX_PATH]; CHAR ProgressString[256]; PVOID BaseAdress = NULL; UiDrawBackdrop(); sprintf(ProgressString, "Loading %s...", File); UiDrawProgressBarCenter(Percentage, 100, ProgressString); strcpy(FullFileName, Path); strcat(FullFileName, "SYSTEM32\\"); strcat(FullFileName, File); Status = WinLdrLoadImage(FullFileName, MemoryType, &BaseAdress); if (!Status) { TRACE("Loading %s failed\n", File); return FALSE; } TRACE("%s loaded successfully at %p\n", File, BaseAdress); strcpy(FullFileName, "WINDOWS\\SYSTEM32\\"); strcat(FullFileName, File); /* * Cheat about the base DLL name if we are loading * the Kernel Debugger Transport DLL, to make the * PE loader happy. */ Status = WinLdrAllocateDataTableEntry(&LoaderBlock->LoadOrderListHead, (IsKdTransportDll ? "KDCOM.DLL" : File), FullFileName, BaseAdress, Dte); return Status; }
VOID TuiDrawMenu(PUI_MENU_INFO MenuInfo) { ULONG i; // // Draw the backdrop // UiDrawBackdrop(); // // Update the status bar // UiVtbl.DrawStatusText("Use \x18 and \x19 to select, then press ENTER."); // // Draw the menu box // TuiDrawMenuBox(MenuInfo); // // Draw each line of the menu // for (i = 0; i < MenuInfo->MenuItemCount; i++) { TuiDrawMenuItem(MenuInfo, i); } /* Display the boot options if needed */ if (MenuInfo->ShowBootOptions) { DisplayBootTimeOptions(); } VideoCopyOffScreenBufferToVRAM(); }
VOID DoOptionsMenu(VOID) { ULONG SelectedMenuItem; CHAR DebugChannelString[100]; if (!UiDisplayMenu("Select an option:", "", TRUE, OptionsMenuList, OptionsMenuItemCount, 11, // Use "Start ReactOS normally" as default; see the switch below. -1, &SelectedMenuItem, TRUE, NULL)) { /* The user pressed ESC */ return; } /* Clear the backdrop */ UiDrawBackdrop(); switch (SelectedMenuItem) { case 0: // Safe Mode BootOptionChoice = SAFE_MODE; BootLogging = TRUE; break; case 1: // Safe Mode with Networking BootOptionChoice = SAFE_MODE_WITH_NETWORKING; BootLogging = TRUE; break; case 2: // Safe Mode with Command Prompt BootOptionChoice = SAFE_MODE_WITH_COMMAND_PROMPT; BootLogging = TRUE; break; // case 3: // Separator // break; case 4: // Enable Boot Logging BootLogging = TRUE; break; case 5: // Enable VGA Mode VgaMode = TRUE; break; case 6: // Last Known Good Configuration BootOptionChoice = LAST_KNOWN_GOOD_CONFIGURATION; break; case 7: // Directory Services Restore Mode BootOptionChoice = DIRECTORY_SERVICES_RESTORE_MODE; break; case 8: // Debugging Mode DebuggingMode = TRUE; break; case 9: // FreeLdr debugging DebugChannelString[0] = 0; if (UiEditBox(FrldrDbgMsg, DebugChannelString, sizeof(DebugChannelString) / sizeof(DebugChannelString[0]))) { DbgParseDebugChannels(DebugChannelString); } break; // case 10: // Separator // break; case 11: // Start ReactOS normally // Reset all the parameters to their default values. BootOptionChoice = NO_OPTION; BootLogging = FALSE; VgaMode = FALSE; DebuggingMode = FALSE; break; #ifdef HAS_OPTION_MENU_CUSTOM_BOOT case 12: // Custom Boot OptionMenuCustomBoot(); break; #endif #ifdef HAS_OPTION_MENU_REBOOT case 13: // Reboot OptionMenuReboot(); break; #endif } }
VOID LoadAndBootWindowsCommon( USHORT OperatingSystemVersion, PLOADER_PARAMETER_BLOCK LoaderBlock, LPCSTR BootOptions, LPCSTR BootPath, BOOLEAN Setup) { PLOADER_PARAMETER_BLOCK LoaderBlockVA; BOOLEAN Status; PLDR_DATA_TABLE_ENTRY KernelDTE; KERNEL_ENTRY_POINT KiSystemStartup; LPCSTR SystemRoot; TRACE("LoadAndBootWindowsCommon()\n"); /* 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 */ Status = LoadWindowsCore(OperatingSystemVersion, LoaderBlock, BootOptions, BootPath, &KernelDTE); if (!Status) { UiMessageBox("Error loading NTOS core."); return; } /* Load boot drivers */ UiDrawBackdrop(); UiDrawProgressBarCenter(100, 100, "Loading boot drivers..."); Status = WinLdrLoadBootDrivers(LoaderBlock, BootPath); TRACE("Boot drivers loaded with status %d\n", Status); /* 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); /* 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 //FIXME: If I substitute this debugging checkpoint, GCC will "optimize away" the code below //while (1) {}; /*asm(".intel_syntax noprefix\n"); asm("test1:\n"); asm("jmp test1\n"); asm(".att_syntax\n");*/ /* Pass control */ (*KiSystemStartup)(LoaderBlockVA); }
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 RunLoader(VOID) { ULONG_PTR SectionId; ULONG OperatingSystemCount; OperatingSystemItem* OperatingSystemList; PCSTR* OperatingSystemDisplayNames; ULONG DefaultOperatingSystem; LONG TimeOut; ULONG SelectedOperatingSystem; ULONG i; if (!MachInitializeBootDevices()) { UiMessageBoxCritical("Error when detecting hardware."); return; } #ifdef _M_IX86 /* Load additional SCSI driver (if any) */ if (LoadBootDeviceDriver() != ESUCCESS) { UiMessageBoxCritical("Unable to load additional boot device drivers."); } #endif if (!IniFileInitialize()) { UiMessageBoxCritical("Error initializing .ini file."); return; } /* Debugger main initialization */ DebugInit(TRUE); if (!IniOpenSection("FreeLoader", &SectionId)) { UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini."); return; } TimeOut = GetTimeOut(); /* UI main initialization */ if (!UiInitialize(TRUE)) { UiMessageBoxCritical("Unable to initialize UI."); return; } OperatingSystemList = InitOperatingSystemList(&OperatingSystemCount); if (!OperatingSystemList) { UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot."); goto Reboot; } if (OperatingSystemCount == 0) { UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot."); goto Reboot; } DefaultOperatingSystem = GetDefaultOperatingSystem(OperatingSystemList, OperatingSystemCount); /* Create list of display names */ OperatingSystemDisplayNames = FrLdrTempAlloc(sizeof(PCSTR) * OperatingSystemCount, 'mNSO'); if (!OperatingSystemDisplayNames) goto Reboot; for (i = 0; i < OperatingSystemCount; i++) { OperatingSystemDisplayNames[i] = OperatingSystemList[i].LoadIdentifier; } /* Find all the message box settings and run them */ UiShowMessageBoxesInSection("FreeLoader"); for (;;) { /* Redraw the backdrop */ UiDrawBackdrop(); /* Show the operating system list menu */ if (!UiDisplayMenu("Please select the operating system to start:", "For troubleshooting and advanced startup options for " "ReactOS, press F8.", TRUE, OperatingSystemDisplayNames, OperatingSystemCount, DefaultOperatingSystem, TimeOut, &SelectedOperatingSystem, FALSE, MainBootMenuKeyPressFilter)) { UiMessageBox("Press ENTER to reboot."); goto Reboot; } TimeOut = -1; /* Load the chosen operating system */ LoadOperatingSystem(&OperatingSystemList[SelectedOperatingSystem]); } Reboot: UiUnInitialize("Rebooting..."); return; }
VOID MiniTuiDrawMenu(PUI_MENU_INFO MenuInfo) { ULONG i; // // Draw the backdrop // UiDrawBackdrop(); // // No GUI status bar text, just minimal text. Show the menu header. // UiVtbl.DrawText(0, MenuInfo->Top - 2, MenuInfo->MenuHeader, ATTR(UiMenuFgColor, UiMenuBgColor)); // // Now tell the user how to choose // UiVtbl.DrawText(0, MenuInfo->Bottom + 1, "Use \x18 and \x19 to move the highlight to your choice.", ATTR(UiMenuFgColor, UiMenuBgColor)); UiVtbl.DrawText(0, MenuInfo->Bottom + 2, "Press ENTER to choose.", ATTR(UiMenuFgColor, UiMenuBgColor)); // // And show the menu footer // UiVtbl.DrawText(0, UiScreenHeight - 4, MenuInfo->MenuFooter, ATTR(UiMenuFgColor, UiMenuBgColor)); // // Draw the menu box // TuiDrawMenuBox(MenuInfo); // // Draw each line of the menu // for (i = 0; i < MenuInfo->MenuItemCount; i++) { TuiDrawMenuItem(MenuInfo, i); } // // Display the boot options if needed // if (MenuInfo->ShowBootOptions) { DisplayBootTimeOptions(); } VideoCopyOffScreenBufferToVRAM(); }
VOID LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem, IN USHORT OperatingSystemVersion) { ULONG_PTR SectionId; PCSTR SectionName = OperatingSystem->SystemPartition; CHAR SettingsValue[80]; BOOLEAN HasSection; CHAR BootOptions2[256]; PCHAR File; CHAR FileName[512]; CHAR BootPath[512]; LPCSTR LoadOptions; LPSTR BootOptions; BOOLEAN BootFromFloppy; ULONG i, ErrorLine; HINF InfHandle; INFCONTEXT InfContext; PLOADER_PARAMETER_BLOCK LoaderBlock; PSETUP_LOADER_BLOCK SetupBlock; LPCSTR SystemPath; 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 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))) { MachDiskGetBootPath(BootPath, sizeof(BootPath)); } /* Append a backslash */ if ((strlen(BootPath)==0) || BootPath[strlen(BootPath)] != '\\') strcat(BootPath, "\\"); /* Read booting options */ if (!HasSection || !IniReadSettingByName(SectionId, "Options", BootOptions2, sizeof(BootOptions2))) { /* Get options after the title */ PCSTR p = SettingsValue; while (*p == ' ' || *p == '"') p++; while (*p != '\0' && *p != '"') p++; strcpy(BootOptions2, p); TRACE("BootOptions: '%s'\n", BootOptions2); } /* Check if a ramdisk file was given */ File = strstr(BootOptions2, "/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); } TRACE("BootPath: '%s'\n", BootPath); /* And check if we booted from floppy */ BootFromFloppy = strstr(BootPath, "fdisk") != NULL; /* Open 'txtsetup.sif' from any of source paths */ File = BootPath + strlen(BootPath); for (i = BootFromFloppy ? 0 : 1; ; i++) { SystemPath = SourcePaths[i]; if (!SystemPath) { ERR("Failed to open txtsetup.sif\n"); return; } sprintf(File, "%stxtsetup.sif", SystemPath); if (InfOpenFile (&InfHandle, BootPath, &ErrorLine)) { sprintf(File, "%s", SystemPath); break; } } TRACE("BootPath: '%s', SystemPath: '%s'\n", BootPath, SystemPath); /* Get Load options - debug and non-debug */ if (!InfFindFirstLine(InfHandle, "SetupData", "OsLoadOptions", &InfContext)) { ERR("Failed to find 'SetupData/OsLoadOptions'\n"); return; } if (!InfGetDataField(&InfContext, 1, &LoadOptions)) { ERR("Failed to get load options\n"); return; } #if DBG /* Get debug load options and use them */ if (InfFindFirstLine(InfHandle, "SetupData", "DbgOsLoadOptions", &InfContext)) { LPCSTR DbgLoadOptions; if (InfGetDataField(&InfContext, 1, &DbgLoadOptions)) LoadOptions = DbgLoadOptions; } #endif /* Copy loadoptions (original string will be freed) */ BootOptions = FrLdrTempAlloc(strlen(LoadOptions) + 1, TAG_BOOT_OPTIONS); strcpy(BootOptions, LoadOptions); TRACE("BootOptions: '%s'\n", BootOptions); UiDrawStatusText("Setup is loading..."); /* Allocate and minimalistic-initialize LPB */ AllocateAndInitLPB(&LoaderBlock); /* Allocate and initialize setup loader block */ SetupBlock = &WinLdrSystemBlock->SetupBlock; LoaderBlock->SetupLdrBlock = SetupBlock; /* Set textmode setup flag */ SetupBlock->Flags = SETUPLDR_TEXT_MODE; /* Load NLS data, they are in system32 */ strcpy(FileName, BootPath); strcat(FileName, "system32\\"); SetupLdrLoadNlsData(LoaderBlock, InfHandle, FileName); /* Get a list of boot drivers */ SetupLdrScanBootDrivers(&LoaderBlock->BootDriverListHead, InfHandle, BootPath); /* Close the inf file */ InfCloseFile(InfHandle); /* Load ReactOS */ LoadAndBootWindowsCommon(_WIN32_WINNT_WS03, LoaderBlock, BootOptions, BootPath, TRUE); }
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 Success; 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); } /* * Check whether BootPath is a full path * and if not, create a full boot path. * * See FsOpenFile for the technique used. */ if (strrchr(BootPath, ')') == NULL) { /* Temporarily save the boot path */ strcpy(FileName, BootPath); /* This is not a full path. Use the current (i.e. boot) device. */ MachDiskGetBootPath(BootPath, sizeof(BootPath)); /* Append a path separator if needed */ if (FileName[0] != '\\' && FileName[0] != '/') strcat(BootPath, "\\"); /* Append the remaining path */ strcat(BootPath, FileName); } /* Append a backslash if needed */ if ((strlen(BootPath) == 0) || BootPath[strlen(BootPath) - 1] != '\\') 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 */ if (!RamDiskLoadVirtualFile(FileName)) { UiMessageBox("Failed to load RAM disk file %s", FileName); return; } } /* Let user know we started loading */ //UiDrawStatusText("Loading..."); TRACE("BootPath: '%s'\n", BootPath); /* Allocate and minimalistic-initialize LPB */ AllocateAndInitLPB(&LoaderBlock); /* Load Hive */ UiDrawBackdrop(); UiDrawProgressBarCenter(15, 100, "Loading system hive..."); Success = WinLdrInitSystemHive(LoaderBlock, BootPath); TRACE("SYSTEM hive %s\n", (Success ? "loaded" : "not loaded")); /* Load NLS data, OEM font, and prepare boot drivers list */ Success = WinLdrScanSystemHive(LoaderBlock, BootPath); TRACE("SYSTEM hive %s\n", (Success ? "scanned" : "not scanned")); /* Finish loading */ LoadAndBootWindowsCommon(OperatingSystemVersion, LoaderBlock, BootOptions, BootPath, FALSE); }
VOID LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem, IN USHORT OperatingSystemVersion) { ULONG_PTR SectionId; PCSTR SectionName = OperatingSystem->SystemPartition; CHAR SettingsValue[80]; BOOLEAN HasSection; CHAR BootOptions2[256]; PCHAR File; CHAR FileName[512]; CHAR BootPath[512]; LPCSTR LoadOptions; LPSTR BootOptions; BOOLEAN BootFromFloppy; ULONG i, ErrorLine; HINF InfHandle; INFCONTEXT InfContext; PLOADER_PARAMETER_BLOCK LoaderBlock; PSETUP_LOADER_BLOCK SetupBlock; LPCSTR SystemPath; 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 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 ReactOS Setup..."); /* Read the system path is set in the .ini file */ if (!HasSection || !IniReadSettingByName(SectionId, "SystemPath", BootPath, sizeof(BootPath))) { /* * IMPROVE: I don't want to call MachDiskGetBootPath here as a * default choice because I can call it after (see few lines below). * Also doing the strcpy call as it is done in winldr.c is not * really what we want. Instead I reset BootPath here so that * we can build the full path using the general code from below. */ // MachDiskGetBootPath(BootPath, sizeof(BootPath)); // strcpy(BootPath, SectionName); BootPath[0] = '\0'; } /* * Check whether BootPath is a full path * and if not, create a full boot path. * * See FsOpenFile for the technique used. */ if (strrchr(BootPath, ')') == NULL) { /* Temporarily save the boot path */ strcpy(FileName, BootPath); /* This is not a full path. Use the current (i.e. boot) device. */ MachDiskGetBootPath(BootPath, sizeof(BootPath)); /* Append a path separator if needed */ if (FileName[0] != '\\' && FileName[0] != '/') strcat(BootPath, "\\"); /* Append the remaining path */ strcat(BootPath, FileName); } /* Append a backslash if needed */ if ((strlen(BootPath) == 0) || BootPath[strlen(BootPath) - 1] != '\\') strcat(BootPath, "\\"); /* Read booting options */ if (!HasSection || !IniReadSettingByName(SectionId, "Options", BootOptions2, sizeof(BootOptions2))) { /* Get options after the title */ PCSTR p = SettingsValue; while (*p == ' ' || *p == '"') p++; while (*p != '\0' && *p != '"') p++; strcpy(BootOptions2, p); TRACE("BootOptions: '%s'\n", BootOptions2); } /* Check if a ramdisk file was given */ File = strstr(BootOptions2, "/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 */ if (!RamDiskLoadVirtualFile(FileName)) { UiMessageBox("Failed to load RAM disk file %s", FileName); return; } } TRACE("BootPath: '%s'\n", BootPath); /* And check if we booted from floppy */ BootFromFloppy = strstr(BootPath, "fdisk") != NULL; /* Open 'txtsetup.sif' from any of source paths */ File = BootPath + strlen(BootPath); for (i = BootFromFloppy ? 0 : 1; ; i++) { SystemPath = SourcePaths[i]; if (!SystemPath) { UiMessageBox("Failed to open txtsetup.sif"); return; } strcpy(File, SystemPath); strcpy(FileName, BootPath); strcat(FileName, "txtsetup.sif"); if (InfOpenFile(&InfHandle, FileName, &ErrorLine)) { break; } } TRACE("BootPath: '%s', SystemPath: '%s'\n", BootPath, SystemPath); /* Get Load options - debug and non-debug */ if (!InfFindFirstLine(InfHandle, "SetupData", "OsLoadOptions", &InfContext)) { ERR("Failed to find 'SetupData/OsLoadOptions'\n"); return; } if (!InfGetDataField(&InfContext, 1, &LoadOptions)) { ERR("Failed to get load options\n"); return; } #if DBG /* Get debug load options and use them */ if (InfFindFirstLine(InfHandle, "SetupData", "DbgOsLoadOptions", &InfContext)) { LPCSTR DbgLoadOptions; if (InfGetDataField(&InfContext, 1, &DbgLoadOptions)) LoadOptions = DbgLoadOptions; } #endif /* Copy loadoptions (original string will be freed) */ BootOptions = FrLdrTempAlloc(strlen(LoadOptions) + 1, TAG_BOOT_OPTIONS); strcpy(BootOptions, LoadOptions); TRACE("BootOptions: '%s'\n", BootOptions); UiDrawStatusText("Setup is loading..."); /* Allocate and minimalistic-initialize LPB */ AllocateAndInitLPB(&LoaderBlock); /* Allocate and initialize setup loader block */ SetupBlock = &WinLdrSystemBlock->SetupBlock; LoaderBlock->SetupLdrBlock = SetupBlock; /* Set textmode setup flag */ SetupBlock->Flags = SETUPLDR_TEXT_MODE; /* Load NLS data, they are in system32 */ strcpy(FileName, BootPath); strcat(FileName, "system32\\"); SetupLdrLoadNlsData(LoaderBlock, InfHandle, FileName); /* Get a list of boot drivers */ SetupLdrScanBootDrivers(&LoaderBlock->BootDriverListHead, InfHandle, BootPath); /* Close the inf file */ InfCloseFile(InfHandle); /* Load ReactOS Setup */ LoadAndBootWindowsCommon(_WIN32_WINNT_WS03, LoaderBlock, BootOptions, BootPath, TRUE); }