Skip to content

Commit

Permalink
Merge branch 'boot/freeldr-split' of https://github.com/tkreuzer/reactos
Browse files Browse the repository at this point in the history
 into xbox
  • Loading branch information
binarymaster committed Jan 20, 2025
2 parents 4623570 + 9b5c887 commit ef8776a
Show file tree
Hide file tree
Showing 48 changed files with 662 additions and 225 deletions.
15 changes: 13 additions & 2 deletions base/setup/lib/bootsup.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,6 @@ InstallMbrBootCodeToDisk(
InstallMbrBootCode);
}


static
NTSTATUS
InstallBootloaderFiles(
Expand All @@ -895,7 +894,19 @@ InstallBootloaderFiles(
CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\freeldr.sys");
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"freeldr.sys");

DPRINT1("Copy: %S ==> %S\n", SrcPath, DstPath);
DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath);
Status = SetupCopyFile(SrcPath, DstPath, FALSE);
if (!NT_SUCCESS(Status))
{
DPRINT1("SetupCopyFile() failed (Status 0x%08lx)\n", Status);
return Status;
}

/* Copy rosload to the system partition, always overwriting the older version */
CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\rosload.exe");
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, L"rosload.exe");

DPRINT("Copy: %S ==> %S\n", SrcPath, DstPath);
Status = SetupCopyFile(SrcPath, DstPath, FALSE);
if (!NT_SUCCESS(Status))
{
Expand Down
2 changes: 1 addition & 1 deletion base/setup/lib/utils/bldrsup.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ NtLdrEnumerateBootEntries(
// Question 2: What if many config files are possible?
NTOS_BOOT_LOADER_FILES NtosBootLoaders[] =
{
{FreeLdr, L"freeldr.sys\0", L"freeldr.ini",
{FreeLdr, L"freeldr.sys\0" L"rosload.exe\0", L"freeldr.ini",
OpenIniBootLoaderStore, CloseIniBootLoaderStore, (PENUM_BOOT_STORE_ENTRIES)FreeLdrEnumerateBootEntries},
{NtLdr , L"ntldr\0" L"osloader.exe\0", L"boot.ini",
OpenIniBootLoaderStore, CloseIniBootLoaderStore, (PENUM_BOOT_STORE_ENTRIES)NtLdrEnumerateBootEntries },
Expand Down
23 changes: 5 additions & 18 deletions boot/freeldr/freeldr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ list(APPEND FREELDR_BOOTLIB_SOURCE

list(APPEND FREELDR_BOOTMGR_SOURCE
include/freeldr.h
custom.c
# linuxboot.c
miscboot.c
options.c
oslist.c
settings.c
ui/directui.c
# ui/gui.c
Expand All @@ -88,10 +83,7 @@ if(ARCH STREQUAL "i386")
# arch/i386/linux.S

list(APPEND FREELDR_ARC_SOURCE
arch/i386/i386bug.c
arch/i386/halstub.c
arch/i386/ntoskrnl.c
disk/scsiport.c)
arch/i386/i386bug.c)

list(APPEND FREELDR_NTLDR_SOURCE
ntldr/arch/i386/winldr.c
Expand All @@ -118,23 +110,18 @@ else()
endif()

list(APPEND FREELDR_BASE_SOURCE
bootmgr.c # This file is compiled with custom definitions
freeldr.c
ntldr/setupldr.c ## Strangely enough this file is needed in GCC builds
## even if ${FREELDR_NTLDR_SOURCE} is not added,
## otherwise we get linking errors with Rtl**Bitmap** APIs.
## Do not happen on MSVC builds however...
ntldr/inffile.c
ntldr/ntldropts.c
ntldr/ntldropts.c # Should be in rosload, but is currently needed by machpc.c, etc.
lib/rtl/libsupp.c)

if(ARCH STREQUAL "i386")
if(ARCH STREQUAL "i386" OR ARCH STREQUAL "amd64")
# Must be included together with disk/scsiport.c
list(APPEND FREELDR_BASE_SOURCE
${CMAKE_CURRENT_BINARY_DIR}/freeldr_pe.def)
${CMAKE_CURRENT_BINARY_DIR}/freeldr.def)
endif()

include(pcat.cmake)
include(rosload.cmake)
if(NOT ARCH STREQUAL "i386" OR NOT (SARCH STREQUAL "pc98" OR SARCH STREQUAL "xbox"))
include(uefi.cmake)
endif()
21 changes: 21 additions & 0 deletions boot/freeldr/freeldr/arch/arcemul.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,25 @@ ArcGetRelativeTime(VOID)
return ret;
}

PCONFIGURATION_COMPONENT_DATA
MachHwDetect(_In_opt_ PCSTR Options)
{
return MachVtbl.HwDetect(Options);
}

VOID MachPrepareForReactOS(VOID)
{
MachVtbl.PrepareForReactOS();
}

VOID MachGetExtendedBIOSData(PULONG ExtendedBIOSDataArea, PULONG ExtendedBIOSDataSize)
{
MachVtbl.GetExtendedBIOSData(ExtendedBIOSDataArea, ExtendedBIOSDataSize);
}

VOID MachVideoGetFontsFromFirmware(PULONG RomFontPointers)
{
MachVtbl.VideoGetFontsFromFirmware(RomFontPointers);
}

/* EOF */
15 changes: 15 additions & 0 deletions boot/freeldr/freeldr/arch/archwsup.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,18 @@ FldrCreateComponentKey(
/* Return the child */
*ComponentKey = ComponentData;
}

ULONG ArcGetDiskCount(VOID)
{
return reactos_disk_count;
}

PARC_DISK_SIGNATURE_EX ArcGetDiskInfo(ULONG Index)
{
if (Index >= reactos_disk_count)
{
return NULL;
}

return &reactos_arc_disk_info[Index];
}
5 changes: 5 additions & 0 deletions boot/freeldr/freeldr/arch/i386/hwacpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ DBG_DEFAULT_CHANNEL(HWDETECT);

BOOLEAN AcpiPresent = FALSE;

BOOLEAN IsAcpiPresent(VOID)
{
return AcpiPresent;
}

static PRSDP_DESCRIPTOR
FindAcpiBios(VOID)
{
Expand Down
5 changes: 5 additions & 0 deletions boot/freeldr/freeldr/arch/uefi/uefihw.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ BOOLEAN AcpiPresent = FALSE;

/* FUNCTIONS *****************************************************************/

BOOLEAN IsAcpiPresent(VOID)
{
return AcpiPresent;
}

static
PRSDP_DESCRIPTOR
FindAcpiBios(VOID)
Expand Down
27 changes: 11 additions & 16 deletions boot/freeldr/freeldr/bootmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ WarnDeprecated(
CHAR msgString[300];

/* If the user didn't cancel the timeout, don't display the warning */
if (BootMgrInfo.TimeOut >= 0)
if (GetBootMgrInfo()->TimeOut >= 0)
return;

va_start(ap, MsgFmt);
Expand Down Expand Up @@ -183,6 +183,7 @@ BuildArgvForOsLoader(
PCHAR* Argv;
PCHAR* Args;
PCHAR SettingName, SettingValue;
PCCHAR BootPath = FrLdrGetBootPath();

*pArgc = 0;

Expand All @@ -208,7 +209,7 @@ BuildArgvForOsLoader(
/* i == 0: Program name */
// TODO: Provide one in the future...
/* i == 1: SystemPartition : from where FreeLdr has been started */
Size += (strlen("SystemPartition=") + strlen(FrLdrBootPath) + 1) * sizeof(CHAR);
Size += (strlen("SystemPartition=") + strlen(BootPath) + 1) * sizeof(CHAR);
/* i == 2: LoadIdentifier : ASCII string that may be used
* to associate an identifier with a set of load parameters */
if (LoadIdentifier)
Expand Down Expand Up @@ -236,7 +237,7 @@ BuildArgvForOsLoader(
/* i == 1: SystemPartition */
{
strcpy(SettingName, "SystemPartition=");
strcat(SettingName, FrLdrBootPath);
strcat(SettingName, BootPath);

*Args++ = SettingName;
SettingName += (strlen(SettingName) + 1);
Expand Down Expand Up @@ -333,12 +334,13 @@ MainBootMenuKeyPressFilter(
IN PVOID Context OPTIONAL)
{
/* Any key-press cancels the global timeout */
BootMgrInfo.TimeOut = -1;
GetBootMgrInfo()->TimeOut = -1;

switch (KeyPress)
{
case KEY_F8:
DoOptionsMenu(&((OperatingSystemItem*)Context)[SelectedMenuItem]);
DisplayBootTimeOptions();
return TRUE;

#ifdef HAS_OPTION_MENU_EDIT_CMDLINE
Expand All @@ -362,12 +364,6 @@ VOID RunLoader(VOID)
ULONG SelectedOperatingSystem;
ULONG i;

if (!MachInitializeBootDevices())
{
UiMessageBoxCritical("Error when detecting hardware.");
return;
}

#ifdef _M_IX86
#ifndef UEFIBOOT
/* Load additional SCSI driver (if any) */
Expand All @@ -394,7 +390,7 @@ VOID RunLoader(VOID)
#endif

/* Debugger main initialization */
DebugInit(BootMgrInfo.DebugString);
DebugInit(GetBootMgrInfo()->DebugString);

/* UI main initialization */
if (!UiInitialize(TRUE))
Expand Down Expand Up @@ -427,7 +423,7 @@ VOID RunLoader(VOID)
}

/* Find all the message box settings and run them */
UiShowMessageBoxesInSection(BootMgrInfo.FrLdrSection);
UiShowMessageBoxesInSection(GetBootMgrInfo()->FrLdrSection);

for (;;)
{
Expand All @@ -438,11 +434,10 @@ VOID RunLoader(VOID)
if (!UiDisplayMenu("Please select the operating system to start:",
"For troubleshooting and advanced startup options for "
"ReactOS, press F8.",
TRUE,
OperatingSystemDisplayNames,
OperatingSystemCount,
DefaultOperatingSystem,
BootMgrInfo.TimeOut,
GetBootMgrInfo()->TimeOut,
&SelectedOperatingSystem,
FALSE,
MainBootMenuKeyPressFilter,
Expand All @@ -455,12 +450,12 @@ VOID RunLoader(VOID)
/* Load the chosen operating system */
LoadOperatingSystem(&OperatingSystemList[SelectedOperatingSystem]);

BootMgrInfo.TimeOut = -1;
GetBootMgrInfo()->TimeOut = -1;

/* If we get there, the OS loader failed. As it may have
* messed up the display, re-initialize the UI. */
#ifndef _M_ARM
UiVtbl.UnInitialize();
UiUnInitialize("");
#endif
UiInitialize(TRUE);
}
Expand Down
1 change: 0 additions & 1 deletion boot/freeldr/freeldr/custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ VOID OptionMenuCustomBoot(VOID)
OperatingSystemItem OperatingSystem;

if (!UiDisplayMenu("Please choose a boot method:", NULL,
FALSE,
CustomBootMenuList,
RTL_NUMBER_OF(CustomBootMenuList),
0, -1,
Expand Down
2 changes: 1 addition & 1 deletion boot/freeldr/freeldr/disk/scsiport.c
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ LoadBootDeviceDriver(VOID)
#endif

/* Create full ntbootdd.sys path */
strcpy(NtBootDdPath, FrLdrBootPath);
strcpy(NtBootDdPath, FrLdrGetBootPath());
strcat(NtBootDdPath, "\\NTBOOTDD.SYS");

/* Load ntbootdd.sys */
Expand Down
83 changes: 82 additions & 1 deletion boot/freeldr/freeldr/freeldr.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,62 @@ CCHAR FrLdrBootPath[MAX_PATH] = "";

/* FUNCTIONS ******************************************************************/

static
BOOLEAN
LoadRosload(
_In_ PCSTR RosloadPath,
_Out_ PVOID* ImageBase,
_Out_ PLDR_DATA_TABLE_ENTRY* DataTableEntry)
{
CHAR FullPath[MAX_PATH];
BOOLEAN Success;

/* Create full rosload.exe path */
strcpy(FullPath, FrLdrBootPath);
strcat(FullPath, "\\");
strcat(FullPath, RosloadPath);

TRACE("Loading second stage loader '%s'\n", FullPath);

/* Load rosload.exe as a bootloader image. The base name is "scsiport.sys",
because it exports ScsiPort* functions for ntbootdd.sys */
Success = PeLdrLoadBootImage(FullPath,
"scsiport.sys",
ImageBase,
DataTableEntry);
if (!Success)
{
WARN("Failed to load second stage loader '%s'\n", FullPath);
return FALSE;
}

return TRUE;
}

static
ULONG
LaunchSecondStageLoader(VOID)
{
PLDR_DATA_TABLE_ENTRY RosloadDTE;
PVOID ImageBase;
LONG (*EntryPoint)(VOID);

/* Load the second stage loader */
if (!LoadRosload("rosload.exe", &ImageBase, &RosloadDTE))
{
/* Try in loader directory */
if (!LoadRosload("loader\\rosload.exe", &ImageBase, &RosloadDTE))
{
return ENOENT;
}
}

/* Call the entrypoint */
printf("Launching rosload.exe...\n");
EntryPoint = VaToPa(RosloadDTE->EntryPoint);
return (*EntryPoint)();
}

VOID __cdecl BootMain(IN PCCH CmdLine)
{
/* Load the default settings from the command-line */
Expand Down Expand Up @@ -71,7 +127,17 @@ VOID __cdecl BootMain(IN PCCH CmdLine)
goto Quit;
}

RunLoader();
if (!MachInitializeBootDevices())
{
UiMessageBoxCritical("Error when detecting hardware.");
goto Quit;
}

/* Launch second stage loader */
if (LaunchSecondStageLoader() != ESUCCESS)
{
UiMessageBoxCritical("Unable to load second stage loader.");
}

Quit:
/* If we reach this point, something went wrong before, therefore reboot */
Expand Down Expand Up @@ -124,3 +190,18 @@ double log10(double x)
__debugbreak();
return 0.0;
}

PCCHAR FrLdrGetBootPath(VOID)
{
return FrLdrBootPath;
}

UCHAR FrldrGetBootDrive(VOID)
{
return FrldrBootDrive;
}

ULONG FrldrGetBootPartition(VOID)
{
return FrldrBootPartition;
}
Loading

0 comments on commit ef8776a

Please sign in to comment.