[FREELDR]

- Fix date format in CHANGELOG (that uses that #$@! of US format)
- Diverse code style changes (whitespace, extra braces, C++ to C-style comments, ...)

svn path=/trunk/; revision=66144
This commit is contained in:
Hermès Bélusca-Maïto 2015-02-01 20:22:13 +00:00
parent 2682e03820
commit fd896be2a7
13 changed files with 419 additions and 562 deletions

View file

@ -1,4 +1,4 @@
Changes in v3.0+ (05/01/2015) (hbelusca)
Changes in v3.0+ (01/05/2015) (hbelusca)
- Remove support for special value "LiveCD" of SystemPath option
for loading ReactOS since now we treat non-ARC SystemPath as

View file

@ -240,4 +240,3 @@ FrLdrBugCheck(ULONG BugCode)
{
FrLdrBugCheckEx(BugCode, 0, 0);
}

View file

@ -17,9 +17,14 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* INCLUDES *******************************************************************/
#include <freeldr.h>
ARC_DISK_SIGNATURE reactos_arc_disk_info[32]; // ARC Disk Information
/* GLOBALS ********************************************************************/
// ARC Disk Information
ARC_DISK_SIGNATURE reactos_arc_disk_info[32];
ULONG reactos_disk_count = 0;
CHAR reactos_arc_strings[32][256];
@ -48,10 +53,10 @@ struct
{"WindowsNT40" , _WIN32_WINNT_NT4 , LoadAndBootWindows },
#endif
{"Windows2003" , _WIN32_WINNT_WS03, LoadAndBootWindows },
// {"Not found" , 0 , NULL }
};
/* FUNCTIONS ******************************************************************/
VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem)
{
ULONG_PTR SectionId;
@ -59,10 +64,10 @@ VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem)
CHAR BootType[80];
ULONG i;
// Try to open the operating system section in the .ini file
/* Try to open the operating system section in the .ini file */
if (IniOpenSection(SectionName, &SectionId))
{
// Try to read the boot type
/* Try to read the boot type */
IniReadSettingByName(SectionId, "BootType", BootType, sizeof(BootType));
}
else
@ -72,7 +77,7 @@ VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem)
if (BootType[0] == ANSI_NULL && SectionName[0] != ANSI_NULL)
{
// Try to infere the boot type value
/* Try to infere the boot type value */
#ifdef _M_IX86
ULONG FileId;
if (ArcOpen((PSTR)SectionName, OpenReadOnly, &FileId) == ESUCCESS)
@ -87,12 +92,12 @@ VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem)
}
}
// Install the drive mapper according to this section drive mappings
/* Install the drive mapper according to this section drive mappings */
#if defined(_M_IX86) && !defined(_MSC_VER)
DriveMapMapDrivesInSection(SectionName);
#endif
// Loop through the OS loading method table and find a suitable OS to boot
/* Loop through the OS loading method table and find a suitable OS to boot */
for (i = 0; i < sizeof(OSLoadingMethods) / sizeof(OSLoadingMethods[0]); ++i)
{
if (_stricmp(BootType, OSLoadingMethods[i].BootType) == 0)
@ -113,12 +118,10 @@ ULONG GetDefaultOperatingSystem(OperatingSystemItem* OperatingSystemList, ULONG
ULONG Idx;
if (!IniOpenSection("FreeLoader", &SectionId))
{
return 0;
}
DefaultOSName = CmdLineGetDefaultOS();
if (NULL == DefaultOSName)
if (DefaultOSName == NULL)
{
if (IniReadSettingByName(SectionId, "DefaultOS", DefaultOSText, sizeof(DefaultOSText)))
{
@ -126,7 +129,7 @@ ULONG GetDefaultOperatingSystem(OperatingSystemItem* OperatingSystemList, ULONG
}
}
if (NULL != DefaultOSName)
if (DefaultOSName != NULL)
{
for (Idx = 0; Idx<OperatingSystemCount; Idx++)
{
@ -148,24 +151,16 @@ LONG GetTimeOut(VOID)
ULONG_PTR SectionId;
TimeOut = CmdLineGetTimeOut();
if (0 <= TimeOut)
{
if (TimeOut >= 0)
return TimeOut;
}
if (!IniOpenSection("FreeLoader", &SectionId))
{
return -1;
}
if (IniReadSettingByName(SectionId, "TimeOut", TimeOutText, sizeof(TimeOutText)))
{
TimeOut = atoi(TimeOutText);
}
else
{
TimeOut = -1;
}
return TimeOut;
}
@ -175,11 +170,10 @@ BOOLEAN MainBootMenuKeyPressFilter(ULONG KeyPress)
if (KeyPress == KEY_F8)
{
DoOptionsMenu();
return TRUE;
}
// We didn't handle the key
/* We didn't handle the key */
return FALSE;
}
@ -196,21 +190,21 @@ VOID RunLoader(VOID)
if (!MachInitializeBootDevices())
{
UiMessageBoxCritical("Error when detecting hardware");
UiMessageBoxCritical("Error when detecting hardware.");
return;
}
#ifdef _M_IX86
// Load additional SCSI driver (if any)
/* Load additional SCSI driver (if any) */
if (LoadBootDeviceDriver() != ESUCCESS)
{
UiMessageBoxCritical("Unable to load additional boot device driver");
UiMessageBoxCritical("Unable to load additional boot device drivers.");
}
#endif
if (!IniFileInitialize())
{
UiMessageBoxCritical("Error initializing .ini file");
UiMessageBoxCritical("Error initializing .ini file.");
return;
}
@ -219,6 +213,7 @@ VOID RunLoader(VOID)
UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
return;
}
TimeOut = GetTimeOut();
if (!UiInitialize(TRUE))
@ -231,41 +226,36 @@ VOID RunLoader(VOID)
if (!OperatingSystemList)
{
UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
goto reboot;
goto Reboot;
}
if (OperatingSystemCount == 0)
{
UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
goto reboot;
goto Reboot;
}
DefaultOperatingSystem = GetDefaultOperatingSystem(OperatingSystemList, OperatingSystemCount);
//
// Create list of display names
//
/* Create list of display names */
OperatingSystemDisplayNames = FrLdrTempAlloc(sizeof(PCSTR) * OperatingSystemCount, 'mNSO');
if (!OperatingSystemDisplayNames)
{
goto reboot;
}
goto Reboot;
for (i = 0; i < OperatingSystemCount; i++)
{
OperatingSystemDisplayNames[i] = OperatingSystemList[i].LoadIdentifier;
}
//
// Find all the message box settings and run them
//
/* Find all the message box settings and run them */
UiShowMessageBoxesInSection("FreeLoader");
for (;;)
{
// Redraw the backdrop
/* Redraw the backdrop */
UiDrawBackdrop();
// Show the operating system list menu
/* 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.",
@ -279,16 +269,16 @@ VOID RunLoader(VOID)
MainBootMenuKeyPressFilter))
{
UiMessageBox("Press ENTER to reboot.");
goto reboot;
goto Reboot;
}
TimeOut = -1;
// Load the chosen operating system
/* Load the chosen operating system */
LoadOperatingSystem(&OperatingSystemList[SelectedOperatingSystem]);
}
reboot:
Reboot:
UiUnInitialize("Rebooting...");
return;
}

View file

@ -12,6 +12,12 @@
/* GLOBALS ********************************************************************/
typedef struct tagCMDLINEINFO
{
const char *DefaultOperatingSystem;
LONG TimeOut;
} CMDLINEINFO, *PCMDLINEINFO;
CCHAR DefaultOs[256];
CMDLINEINFO CmdLineInfo;
@ -23,43 +29,34 @@ CmdLineParse(IN PCHAR CmdLine)
PCHAR End, Setting;
ULONG_PTR Length, Offset = 0;
//
// Set defaults
//
/* Set defaults */
CmdLineInfo.DefaultOperatingSystem = NULL;
CmdLineInfo.TimeOut = -1;
//
// Get timeout
//
/* Get timeout */
Setting = strstr(CmdLine, "timeout=");
if (Setting) CmdLineInfo.TimeOut = atoi(Setting +
sizeof("timeout=") +
sizeof(ANSI_NULL));
//
// Get default OS
//
/* Get default OS */
Setting = strstr(CmdLine, "defaultos=");
if (Setting)
{
//
// Check if there's more command-line parameters following
//
/* Check if there's more command-line parameters following */
Setting += sizeof("defaultos=") + sizeof(ANSI_NULL);
End = strstr(Setting, " ");
if (End) Length = End - Setting; else Length = sizeof(DefaultOs);
if (End)
Length = End - Setting;
else
Length = sizeof(DefaultOs);
//
// Copy the default OS
//
/* Copy the default OS */
strncpy(DefaultOs, Setting, Length);
CmdLineInfo.DefaultOperatingSystem = DefaultOs;
}
//
// Get ramdisk base address
//
/* Get ramdisk base address */
Setting = strstr(CmdLine, "rdbase=");
if (Setting) gRamDiskBase = (PVOID)(ULONG_PTR)strtoull(Setting +
sizeof("rdbase=") -
@ -67,9 +64,7 @@ CmdLineParse(IN PCHAR CmdLine)
NULL,
0);
//
// Get ramdisk size
//
/* Get ramdisk size */
Setting = strstr(CmdLine, "rdsize=");
if (Setting) gRamDiskSize = strtoul(Setting +
sizeof("rdsize=") -
@ -77,9 +72,7 @@ CmdLineParse(IN PCHAR CmdLine)
NULL,
0);
//
// Get ramdisk offset
//
/* Get ramdisk offset */
Setting = strstr(CmdLine, "rdoffset=");
if (Setting) Offset = strtoul(Setting +
sizeof("rdoffset=") -
@ -87,9 +80,7 @@ CmdLineParse(IN PCHAR CmdLine)
NULL,
0);
//
// Fix it up
//
/* Fix it up */
gRamDiskBase = (PVOID)((ULONG_PTR)gRamDiskBase + Offset);
}

View file

@ -17,9 +17,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef _M_IX86
/* INCLUDES *******************************************************************/
#include <freeldr.h>
#ifdef _M_IX86
/* GLOBALS ********************************************************************/
const CHAR BootDrivePrompt[] = "Enter the boot drive.\n\nExamples:\nfd0 - first floppy drive\nhd0 - first hard drive\nhd1 - second hard drive\ncd0 - first CD-ROM drive.\n\nBIOS drive numbers may also be used:\n0 - first floppy drive\n0x80 - first hard drive\n0x81 - second hard drive";
const CHAR BootPartitionPrompt[] = "Enter the boot partition.\n\nEnter 0 for the active (bootable) partition.";
@ -29,9 +33,10 @@ const CHAR LinuxInitrdPrompt[] = "Enter the initrd image path.\n\nExamples:\
const CHAR LinuxCommandLinePrompt[] = "Enter the Linux kernel command line.\n\nExamples:\nroot=/dev/hda1\nroot=/dev/fd0 read-only\nroot=/dev/sdb1 init=/sbin/init";
const CHAR ReactOSSystemPathPrompt[] = "Enter the path to your ReactOS system directory.\n\nExamples:\n\\REACTOS\n\\ROS";
const CHAR ReactOSOptionsPrompt[] = "Enter the options you want passed to the kernel.\n\nExamples:\n/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200\n/FASTDETECT /SOS /NOGUIBOOT\n/BASEVIDEO /MAXMEM=64\n/KERNEL=NTKRNLMP.EXE /HAL=HALMPS.DLL";
const CHAR CustomBootPrompt[] = "Press ENTER to boot your custom boot setup.";
/* FUNCTIONS ******************************************************************/
VOID OptionMenuCustomBoot(VOID)
{
PCSTR CustomBootMenuList[] = {
@ -89,31 +94,23 @@ VOID OptionMenuCustomBootDisk(VOID)
RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
{
return;
}
// Generate a unique section name
/* Generate a unique section name */
TimeInfo = ArcGetTime();
sprintf(SectionName, "CustomBootDisk%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
// Add the section
/* Add the section */
if (!IniAddSection(SectionName, &SectionId))
{
return;
}
// Add the BootType
/* Add the BootType */
if (!IniAddSettingValueToSection(SectionId, "BootType", "Drive"))
{
return;
}
// Add the BootDrive
/* Add the BootDrive */
if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
{
return;
}
UiMessageBox(CustomBootPrompt);
@ -139,42 +136,30 @@ VOID OptionMenuCustomBootPartition(VOID)
RtlZeroMemory(BootPartitionString, sizeof(BootPartitionString));
if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
{
return;
}
if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
{
return;
}
// Generate a unique section name
/* Generate a unique section name */
TimeInfo = ArcGetTime();
sprintf(SectionName, "CustomBootPartition%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
// Add the section
/* Add the section */
if (!IniAddSection(SectionName, &SectionId))
{
return;
}
// Add the BootType
/* Add the BootType */
if (!IniAddSettingValueToSection(SectionId, "BootType", "Partition"))
{
return;
}
// Add the BootDrive
/* Add the BootDrive */
if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
{
return;
}
// Add the BootPartition
/* Add the BootPartition */
if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
{
return;
}
UiMessageBox(CustomBootPrompt);
@ -202,53 +187,37 @@ VOID OptionMenuCustomBootBootSectorFile(VOID)
RtlZeroMemory(BootSectorFileString, sizeof(BootSectorFileString));
if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
{
return;
}
if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
{
return;
}
if (!UiEditBox(BootSectorFilePrompt, BootSectorFileString, 200))
{
return;
}
// Generate a unique section name
/* Generate a unique section name */
TimeInfo = ArcGetTime();
sprintf(SectionName, "CustomBootSectorFile%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
// Add the section
/* Add the section */
if (!IniAddSection(SectionName, &SectionId))
{
return;
}
// Add the BootType
/* Add the BootType */
if (!IniAddSettingValueToSection(SectionId, "BootType", "BootSector"))
{
return;
}
// Add the BootDrive
/* Add the BootDrive */
if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
{
return;
}
// Add the BootPartition
/* Add the BootPartition */
if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
{
return;
}
// Add the BootSectorFile
/* Add the BootSectorFile */
if (!IniAddSettingValueToSection(SectionId, "BootSectorFile", BootSectorFileString))
{
return;
}
UiMessageBox(CustomBootPrompt);
@ -279,55 +248,39 @@ VOID OptionMenuCustomBootReactOS(VOID)
RtlZeroMemory(ReactOSOptions, sizeof(ReactOSOptions));
if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
{
return;
}
if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
{
return;
}
if (!UiEditBox(ReactOSSystemPathPrompt, ReactOSSystemPath, 200))
{
return;
}
if (!UiEditBox(ReactOSOptionsPrompt, ReactOSOptions, 200))
{
return;
}
// Generate a unique section name
/* Generate a unique section name */
TimeInfo = ArcGetTime();
sprintf(SectionName, "CustomReactOS%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
// Add the section
/* Add the section */
if (!IniAddSection(SectionName, &SectionId))
{
return;
}
// Add the BootType
/* Add the BootType */
if (!IniAddSettingValueToSection(SectionId, "BootType", "Windows2003"))
{
return;
}
// Construct the ReactOS ARC system path
/* Construct the ReactOS ARC system path */
ConstructArcPath(ReactOSARCPath, ReactOSSystemPath, DriveMapGetBiosDriveNumber(BootDriveString), atoi(BootPartitionString));
// Add the system path
/* Add the system path */
if (!IniAddSettingValueToSection(SectionId, "SystemPath", ReactOSARCPath))
{
return;
}
// Add the CommandLine
/* Add the CommandLine */
if (!IniAddSettingValueToSection(SectionId, "Options", ReactOSOptions))
{
return;
}
UiMessageBox(CustomBootPrompt);
@ -359,78 +312,54 @@ VOID OptionMenuCustomBootLinux(VOID)
RtlZeroMemory(LinuxCommandLineString, sizeof(LinuxCommandLineString));
if (!UiEditBox(BootDrivePrompt, BootDriveString, 20))
{
return;
}
if (!UiEditBox(BootPartitionPrompt, BootPartitionString, 20))
{
return;
}
if (!UiEditBox(LinuxKernelPrompt, LinuxKernelString, 200))
{
return;
}
if (!UiEditBox(LinuxInitrdPrompt, LinuxInitrdString, 200))
{
return;
}
if (!UiEditBox(LinuxCommandLinePrompt, LinuxCommandLineString, 200))
{
return;
}
// Generate a unique section name
/* Generate a unique section name */
TimeInfo = ArcGetTime();
sprintf(SectionName, "CustomLinux%u%u%u%u%u%u", TimeInfo->Year, TimeInfo->Day, TimeInfo->Month, TimeInfo->Hour, TimeInfo->Minute, TimeInfo->Second);
// Add the section
/* Add the section */
if (!IniAddSection(SectionName, &SectionId))
{
return;
}
// Add the BootType
/* Add the BootType */
if (!IniAddSettingValueToSection(SectionId, "BootType", "Linux"))
{
return;
}
// Add the BootDrive
/* Add the BootDrive */
if (!IniAddSettingValueToSection(SectionId, "BootDrive", BootDriveString))
{
return;
}
// Add the BootPartition
/* Add the BootPartition */
if (!IniAddSettingValueToSection(SectionId, "BootPartition", BootPartitionString))
{
return;
}
// Add the Kernel
/* Add the Kernel */
if (!IniAddSettingValueToSection(SectionId, "Kernel", LinuxKernelString))
{
return;
}
// Add the Initrd
/* Add the Initrd */
if (strlen(LinuxInitrdString) > 0)
{
if (!IniAddSettingValueToSection(SectionId, "Initrd", LinuxInitrdString))
{
return;
}
}
// Add the CommandLine
/* Add the CommandLine */
if (!IniAddSettingValueToSection(SectionId, "CommandLine", LinuxCommandLineString))
{
return;
}
UiMessageBox(CustomBootPrompt);

View file

@ -44,7 +44,6 @@
#define BOCHS_OUTPUT_PORT 0xe9
static UCHAR DbgChannels[DBG_CHANNELS_COUNT];
ULONG DebugPort = RS232;
@ -93,16 +92,13 @@ VOID DebugInit(VOID)
VOID DebugPrintChar(UCHAR Character)
{
if (Character == '\n')
{
DebugStartOfLine = TRUE;
}
if (DebugPort & RS232)
{
if (Character == '\n')
{
Rs232PortPutByte('\r');
}
Rs232PortPutByte(Character);
}
if (DebugPort & BOCHS)
@ -152,13 +148,13 @@ DbgPrint2(ULONG Mask, ULONG Level, const char *File, ULONG Line, char *Format, .
char Buffer[2096];
char *ptr = Buffer;
// Mask out unwanted debug messages
/* Mask out unwanted debug messages */
if (!(DbgChannels[Mask] & Level) && !(Level & DBG_DEFAULT_LEVELS ))
{
return;
}
// Print the header if we have started a new line
/* Print the header if we have started a new line */
if (DebugStartOfLine)
{
DbgPrint("(%s:%lu) ", File, Line);
@ -199,11 +195,9 @@ DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length)
ULONG Idx;
ULONG Idx2;
// Mask out unwanted debug messages
/* Mask out unwanted debug messages */
if (!(DbgChannels[Mask] & TRACE_LEVEL))
{
return;
}
DebugStartOfLine = FALSE; // We don't want line headers
DbgPrint("Dumping buffer at %p with length of %lu bytes:\n", Buffer, Length);
@ -213,21 +207,13 @@ DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length)
DebugStartOfLine = FALSE; // We don't want line headers
if (Idx < 0x0010)
{
DbgPrint("000%x:\t", Idx);
}
else if (Idx < 0x0100)
{
DbgPrint("00%x:\t", Idx);
}
else if (Idx < 0x1000)
{
DbgPrint("0%x:\t", Idx);
}
else
{
DbgPrint("%x:\t", Idx);
}
for (Idx2=0; Idx2<16; Idx2++,Idx++)
{
@ -333,18 +319,18 @@ DbgParseDebugChannels(PCHAR Value)
do
{
separator = strchr(str, L',');
separator = strchr(str, ',');
if (separator != NULL)
*separator = L'\0';
*separator = '\0';
c = strchr(str, L'+');
c = strchr(str, '+');
if (c == NULL)
c = strchr(str, L'-');
c = strchr(str, '-');
if (c != NULL)
{
op = *c;
*c = L'\0';
*c = '\0';
c++;
DbgAddDebugChannel(c, str, op);
@ -448,4 +434,3 @@ char *BugCodeStrings[] =
};
ULONG_PTR BugCheckInfo[5];

View file

@ -17,20 +17,19 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* INCLUDES *******************************************************************/
#include <freeldr.h>
#include <debug.h>
DBG_DEFAULT_CHANNEL(WARNING);
VOID NTAPI HalpInitializePciStubs(VOID);
VOID NTAPI HalpInitBusHandler(VOID);
/* FUNCTIONS ******************************************************************/
VOID BootMain(LPSTR CmdLine)
{
CmdLineParse(CmdLine);
MachInit(CmdLine);
FsInit();
DebugInit();
@ -43,22 +42,23 @@ VOID BootMain(LPSTR CmdLine)
if (!UiInitialize(FALSE))
{
UiMessageBoxCritical("Unable to initialize UI.\n");
goto quit;
goto Quit;
}
if (!MmInitializeMemoryManager())
{
UiMessageBoxCritical("Unable to initialize memory manager");
goto quit;
goto Quit;
}
#ifdef _M_IX86
HalpInitializePciStubs();
HalpInitBusHandler();
#endif
RunLoader();
quit:
Quit:
/* If we reach this point, something went wrong before, therefore reboot */
DiskStopFloppyMotor();
Reboot();

View file

@ -19,12 +19,6 @@
#pragma once
typedef struct tagCMDLINEINFO
{
const char *DefaultOperatingSystem;
LONG TimeOut;
} CMDLINEINFO, *PCMDLINEINFO;
VOID CmdLineParse(IN PCHAR CmdLine);
PCCH CmdLineGetDefaultOS(VOID);

View file

@ -29,7 +29,7 @@
#define ROUND_UP(n, align) \
ROUND_DOWN(((ULONG)n) + (align) - 1, (align))
/* public headers */
/* Public headers */
#ifdef __REACTOS__
#define NTOSAPI
#define printf TuiPrintf
@ -54,7 +54,7 @@
#include <ntsup.h>
#endif
/* internal headers */
/* Internal headers */
// #include <arcemul.h>
#include <bytesex.h>
#include <cache.h>
@ -62,6 +62,7 @@
#include <comm.h>
#include <disk.h>
#include <fs.h>
#include <hal.h>
#include <inffile.h>
#include <inifile.h>
#include <keycodes.h>
@ -81,20 +82,20 @@
#include <video.h>
#include <winldr.h>
/* file system headers */
/* File system headers */
#include <fs/ext2.h>
#include <fs/fat.h>
#include <fs/ntfs.h>
#include <fs/iso.h>
#include <fs/pxe.h>
/* ui support */
/* UI support */
#include <ui/gui.h>
#include <ui/minitui.h>
#include <ui/noui.h>
#include <ui/tui.h>
/* arch specific includes */
/* Arch specific includes */
#if defined(_M_IX86) || defined(_M_AMD64)
#include <arch/pc/hardware.h>
#include <arch/pc/pcbios.h>

View file

@ -0,0 +1,9 @@
#pragma once
#ifdef _M_IX86
VOID NTAPI HalpInitializePciStubs(VOID);
VOID NTAPI HalpInitBusHandler(VOID);
#endif

View file

@ -19,15 +19,19 @@
#ifndef _M_ARM
#ifdef _M_IX86
/* INCLUDES *******************************************************************/
#include <freeldr.h>
#include <debug.h>
#ifdef _M_IX86
DBG_DEFAULT_CHANNEL(LINUX);
/* GLOBALS ********************************************************************/
#define LINUX_READ_CHUNK_SIZE 0x20000 // Read 128k at a time
DBG_DEFAULT_CHANNEL(LINUX);
PLINUX_BOOTSECTOR LinuxBootSector = NULL;
PLINUX_SETUPSECTOR LinuxSetupSector = NULL;
ULONG SetupSectorSize = 0;
@ -44,30 +48,26 @@ PVOID LinuxInitrdLoadAddress = NULL;
CHAR LinuxBootDescription[80];
CHAR LinuxBootPath[260] = "";
/* FUNCTIONS ******************************************************************/
BOOLEAN RemoveQuotes(PCHAR QuotedString)
{
CHAR TempString[200];
PCHAR p;
PSTR Start;
//
// Skip spaces up to "
//
/* Skip spaces up to " */
p = QuotedString;
while (*p == ' ' || *p == '"')
p++;
Start = p;
//
// Go up to next "
//
/* Go up to next " */
while (*p != '"' && *p != ANSI_NULL)
p++;
*p = ANSI_NULL;
//
// Copy result
//
/* Copy result */
strcpy(TempString, Start);
strcpy(QuotedString, TempString);
@ -87,24 +87,18 @@ LoadAndBootLinux(IN OperatingSystemItem* OperatingSystem,
UiDrawBackdrop();
if (Description)
{
sprintf(LinuxBootDescription, "Loading %s...", Description);
}
else
{
strcpy(LinuxBootDescription, "Loading Linux...");
}
UiDrawStatusText(LinuxBootDescription);
UiDrawProgressBarCenter(0, 100, LinuxBootDescription);
// Parse the .ini file section
/* Parse the .ini file section */
if (!LinuxParseIniSection(SectionName))
{
goto LinuxBootFailed;
}
// Open the kernel
/* Open the kernel */
LinuxKernel = FsOpenFile(LinuxKernelName);
if (!LinuxKernel)
{
@ -113,7 +107,7 @@ LoadAndBootLinux(IN OperatingSystemItem* OperatingSystem,
goto LinuxBootFailed;
}
// Open the initrd file image (if necessary)
/* Open the initrd file image (if necessary) */
if (LinuxHasInitrd)
{
LinuxInitrdFile = FsOpenFile(LinuxInitrdName);
@ -125,44 +119,34 @@ LoadAndBootLinux(IN OperatingSystemItem* OperatingSystem,
}
}
// Read the boot sector
/* Read the boot sector */
if (!LinuxReadBootSector(LinuxKernel))
{
goto LinuxBootFailed;
}
// Read the setup sector
/* Read the setup sector */
if (!LinuxReadSetupSector(LinuxKernel))
{
goto LinuxBootFailed;
}
// Calc kernel size
/* Calc kernel size */
LinuxKernelSize = FsGetFileSize(LinuxKernel) - (512 + SetupSectorSize);
// Get the file size
/* Get the file size */
LinuxInitrdSize = FsGetFileSize(LinuxInitrdFile);
// Read the kernel
/* Read the kernel */
if (!LinuxReadKernel(LinuxKernel))
{
goto LinuxBootFailed;
}
// Read the initrd (if necessary)
/* Read the initrd (if necessary) */
if (LinuxHasInitrd)
{
if (!LinuxReadInitrd(LinuxInitrdFile))
{
goto LinuxBootFailed;
}
}
// If the default root device is set to FLOPPY (0000h), change to /dev/fd0 (0200h)
if (LinuxBootSector->RootDevice == 0x0000)
{
LinuxBootSector->RootDevice = 0x0200;
}
if (LinuxSetupSector->Version >= 0x0202)
{
@ -175,13 +159,9 @@ LoadAndBootLinux(IN OperatingSystemItem* OperatingSystem,
}
if (NewStyleLinuxKernel)
{
LinuxSetupSector->TypeOfLoader = LINUX_LOADER_TYPE_FREELOADER;
}
else
{
LinuxSetupSector->LoadFlags = 0;
}
RtlCopyMemory((PVOID)0x90000, LinuxBootSector, 512);
RtlCopyMemory((PVOID)0x90200, LinuxSetupSector, SetupSectorSize);
@ -192,42 +172,30 @@ LoadAndBootLinux(IN OperatingSystemItem* OperatingSystem,
DiskStopFloppyMotor();
if (LinuxSetupSector->LoadFlags & LINUX_FLAG_LOAD_HIGH)
{
BootNewLinuxKernel();
}
else
{
BootOldLinuxKernel(LinuxKernelSize);
}
LinuxBootFailed:
if (LinuxKernel)
{
FsCloseFile(LinuxKernel);
}
if (LinuxInitrdFile)
{
FsCloseFile(LinuxInitrdFile);
}
if (LinuxBootSector != NULL)
{
MmFreeMemory(LinuxBootSector);
}
if (LinuxSetupSector != NULL)
{
MmFreeMemory(LinuxSetupSector);
}
if (LinuxKernelLoadAddress != NULL)
{
MmFreeMemory(LinuxKernelLoadAddress);
}
if (LinuxInitrdLoadAddress != NULL)
{
MmFreeMemory(LinuxInitrdLoadAddress);
}
LinuxBootSector = NULL;
LinuxSetupSector = NULL;
@ -246,10 +214,10 @@ BOOLEAN LinuxParseIniSection(PCSTR SectionName)
ULONG_PTR SectionId;
CHAR SettingName[260];
// Find all the message box settings and run them
/* Find all the message box settings and run them */
UiShowMessageBoxesInSection(SectionName);
// Try to open the operating system section in the .ini file
/* Try to open the operating system section in the .ini file */
if (!IniOpenSection(SectionName, &SectionId))
{
sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", SectionName);
@ -263,20 +231,20 @@ BOOLEAN LinuxParseIniSection(PCSTR SectionName)
return FALSE;
}
// Get the kernel name
/* Get the kernel name */
if (!IniReadSettingByName(SectionId, "Kernel", LinuxKernelName, sizeof(LinuxKernelName)))
{
UiMessageBox("Linux kernel filename not specified for selected OS!");
return FALSE;
}
// Get the initrd name
/* Get the initrd name */
if (IniReadSettingByName(SectionId, "Initrd", LinuxInitrdName, sizeof(LinuxInitrdName)))
{
LinuxHasInitrd = TRUE;
}
// Get the command line
/* Get the command line */
if (IniReadSettingByName(SectionId, "CommandLine", LinuxCommandLine, sizeof(LinuxCommandLine)))
{
RemoveQuotes(LinuxCommandLine);
@ -288,21 +256,17 @@ BOOLEAN LinuxParseIniSection(PCSTR SectionName)
BOOLEAN LinuxReadBootSector(PFILE LinuxKernelFile)
{
// Allocate memory for boot sector
/* Allocate memory for boot sector */
LinuxBootSector = MmAllocateMemoryWithType(512, LoaderSystemCode);
if (LinuxBootSector == NULL)
{
return FALSE;
}
// Read linux boot sector
/* Read linux boot sector */
FsSetFilePointer(LinuxKernelFile, 0);
if (!FsReadFile(LinuxKernelFile, 512, NULL, LinuxBootSector))
{
return FALSE;
}
// Check for validity
/* Check for validity */
if (LinuxBootSector->BootFlag != LINUX_BOOT_SECTOR_MAGIC)
{
UiMessageBox("Invalid boot sector magic (0xaa55)");
@ -329,44 +293,32 @@ BOOLEAN LinuxReadSetupSector(PFILE LinuxKernelFile)
LinuxSetupSector = (PLINUX_SETUPSECTOR)TempLinuxSetupSector;
// Read first linux setup sector
/* Read first linux setup sector */
FsSetFilePointer(LinuxKernelFile, 512);
if (!FsReadFile(LinuxKernelFile, 512, NULL, TempLinuxSetupSector))
{
return FALSE;
}
// Check the kernel version
/* Check the kernel version */
if (!LinuxCheckKernelVersion())
{
return FALSE;
}
if (NewStyleLinuxKernel)
{
SetupSectorSize = 512 * LinuxBootSector->SetupSectors;
}
else
{
SetupSectorSize = 4 * 512; // Always 4 setup sectors
}
SetupSectorSize = 512 * 4; // Always 4 setup sectors
// Allocate memory for setup sectors
/* Allocate memory for setup sectors */
LinuxSetupSector = MmAllocateMemoryWithType(SetupSectorSize, LoaderSystemCode);
if (LinuxSetupSector == NULL)
{
return FALSE;
}
// Copy over first setup sector
/* Copy over first setup sector */
RtlCopyMemory(LinuxSetupSector, TempLinuxSetupSector, 512);
// Read in the rest of the linux setup sectors
/* Read in the rest of the linux setup sectors */
FsSetFilePointer(LinuxKernelFile, 1024);
if (!FsReadFile(LinuxKernelFile, SetupSectorSize - 512, NULL, (PVOID)((ULONG_PTR)LinuxSetupSector + 512)))
{
return FALSE;
}
// DbgDumpBuffer(DPRINT_LINUX, LinuxSetupSector, SetupSectorSize);
@ -398,7 +350,7 @@ BOOLEAN LinuxReadKernel(PFILE LinuxKernelFile)
sprintf(StatusText, "Loading %s", LinuxKernelName);
UiDrawStatusText(StatusText);
// Allocate memory for Linux kernel
/* Allocate memory for Linux kernel */
LinuxKernelLoadAddress = MmAllocateMemoryAtAddress(LinuxKernelSize, (PVOID)LINUX_KERNEL_LOAD_ADDRESS, LoaderSystemCode);
if (LinuxKernelLoadAddress != (PVOID)LINUX_KERNEL_LOAD_ADDRESS)
{
@ -407,14 +359,12 @@ BOOLEAN LinuxReadKernel(PFILE LinuxKernelFile)
LoadAddress = LinuxKernelLoadAddress;
// Read linux kernel to 0x100000 (1mb)
/* Read linux kernel to 0x100000 (1mb) */
FsSetFilePointer(LinuxKernelFile, 512 + SetupSectorSize);
for (BytesLoaded=0; BytesLoaded<LinuxKernelSize; )
{
if (!FsReadFile(LinuxKernelFile, LINUX_READ_CHUNK_SIZE, NULL, LoadAddress))
{
return FALSE;
}
BytesLoaded += LINUX_READ_CHUNK_SIZE;
LoadAddress = (PVOID)((ULONG_PTR)LoadAddress + LINUX_READ_CHUNK_SIZE);
@ -427,25 +377,25 @@ BOOLEAN LinuxReadKernel(PFILE LinuxKernelFile)
BOOLEAN LinuxCheckKernelVersion(VOID)
{
// Just assume old kernel until we find otherwise
/* Just assume old kernel until we find otherwise */
NewStyleLinuxKernel = FALSE;
// Check for new style setup header
/* Check for new style setup header */
if (LinuxSetupSector->SetupHeaderSignature != LINUX_SETUP_HEADER_ID)
{
NewStyleLinuxKernel = FALSE;
}
// Check for version below 2.0
/* Check for version below 2.0 */
else if (LinuxSetupSector->Version < 0x0200)
{
NewStyleLinuxKernel = FALSE;
}
// Check for version 2.0
/* Check for version 2.0 */
else if (LinuxSetupSector->Version == 0x0200)
{
NewStyleLinuxKernel = TRUE;
}
// Check for version 2.01+
/* Check for version 2.01+ */
else if (LinuxSetupSector->Version >= 0x0201)
{
NewStyleLinuxKernel = TRUE;
@ -487,7 +437,7 @@ BOOLEAN LinuxReadInitrd(PFILE LinuxInitrdFile)
return FALSE;
}
// Set the information in the setup struct
/* Set the information in the setup struct */
LinuxSetupSector->RamdiskAddress = (ULONG)LinuxInitrdLoadAddress;
LinuxSetupSector->RamdiskSize = LinuxInitrdSize;
@ -499,13 +449,11 @@ BOOLEAN LinuxReadInitrd(PFILE LinuxInitrdFile)
TRACE("InitrdAddressMax: 0x%x\n", LinuxSetupSector->InitrdAddressMax);
}
// Read in the ramdisk
/* Read in the ramdisk */
for (BytesLoaded=0; BytesLoaded<LinuxInitrdSize; )
{
if (!FsReadFile(LinuxInitrdFile, LINUX_READ_CHUNK_SIZE, NULL, (PVOID)LinuxInitrdLoadAddress))
{
return FALSE;
}
BytesLoaded += LINUX_READ_CHUNK_SIZE;
LinuxInitrdLoadAddress = (PVOID)((ULONG_PTR)LinuxInitrdLoadAddress + LINUX_READ_CHUNK_SIZE);

View file

@ -17,9 +17,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef _M_IX86
/* INCLUDES *******************************************************************/
#include <freeldr.h>
#ifdef _M_IX86
/* FUNCTIONS ******************************************************************/
VOID
LoadAndBootBootSector(IN OperatingSystemItem* OperatingSystem,
@ -32,10 +36,10 @@ LoadAndBootBootSector(IN OperatingSystemItem* OperatingSystem,
ULONG BytesRead;
CHAR SettingName[80];
// Find all the message box settings and run them
/* Find all the message box settings and run them */
UiShowMessageBoxesInSection(SectionName);
// Try to open the operating system section in the .ini file
/* Try to open the operating system section in the .ini file */
if (!IniOpenSection(SectionName, &SectionId))
{
sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", SectionName);
@ -57,14 +61,14 @@ LoadAndBootBootSector(IN OperatingSystemItem* OperatingSystem,
return;
}
// Read boot sector
/* Read boot sector */
if (!FsReadFile(FilePointer, 512, &BytesRead, (void*)0x7c00) || (BytesRead != 512))
{
UiMessageBox("Unable to read boot sector.");
return;
}
// Check for validity
/* Check for validity */
if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55)
{
UiMessageBox("Invalid boot sector magic (0xaa55)");
@ -72,13 +76,16 @@ LoadAndBootBootSector(IN OperatingSystemItem* OperatingSystem,
}
UiUnInitialize("Booting...");
// Don't stop the floppy drive motor when we
// are just booting a bootsector, or drive, or partition.
// If we were to stop the floppy motor then
// the BIOS wouldn't be informed and if the
// next read is to a floppy then the BIOS will
// still think the motor is on and this will
// result in a read error.
/*
* Don't stop the floppy drive motor when we
* are just booting a bootsector, or drive, or partition.
* If we were to stop the floppy motor then
* the BIOS wouldn't be informed and if the
* next read is to a floppy then the BIOS will
* still think the motor is on and this will
* result in a read error.
*/
// DiskStopFloppyMotor();
// DisableA20();
ChainLoadBiosBootSectorCode();
@ -96,10 +103,10 @@ LoadAndBootPartition(IN OperatingSystemItem* OperatingSystem,
UCHAR DriveNumber;
ULONG PartitionNumber;
// Find all the message box settings and run them
/* Find all the message box settings and run them */
UiShowMessageBoxesInSection(SectionName);
// Try to open the operating system section in the .ini file
/* Try to open the operating system section in the .ini file */
if (!IniOpenSection(SectionName, &SectionId))
{
sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", SectionName);
@ -107,7 +114,7 @@ LoadAndBootPartition(IN OperatingSystemItem* OperatingSystem,
return;
}
// Read the boot drive
/* Read the boot drive */
if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, sizeof(SettingValue)))
{
UiMessageBox("Boot drive not specified for selected OS!");
@ -116,7 +123,7 @@ LoadAndBootPartition(IN OperatingSystemItem* OperatingSystem,
DriveNumber = DriveMapGetBiosDriveNumber(SettingValue);
// Read the boot partition
/* Read the boot partition */
if (!IniReadSettingByName(SectionId, "BootPartition", SettingValue, sizeof(SettingValue)))
{
UiMessageBox("Boot partition not specified for selected OS!");
@ -125,21 +132,20 @@ LoadAndBootPartition(IN OperatingSystemItem* OperatingSystem,
PartitionNumber = atoi(SettingValue);
// Get the partition table entry
/* Get the partition table entry */
if (!DiskGetPartitionEntry(DriveNumber, PartitionNumber, &PartitionTableEntry))
{
return;
}
// Now try to read the partition boot sector
// If this fails then abort
/* Now try to read the partition boot sector. If this fails then abort. */
if (!MachDiskReadLogicalSectors(DriveNumber, PartitionTableEntry.SectorCountBeforePartition, 1, (PVOID)0x7C00))
{
UiMessageBox("Unable to read partition's boot sector.");
return;
}
// Check for validity
/* Check for validity */
if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55)
{
UiMessageBox("Invalid boot sector magic (0xaa55)");
@ -147,13 +153,16 @@ LoadAndBootPartition(IN OperatingSystemItem* OperatingSystem,
}
UiUnInitialize("Booting...");
// Don't stop the floppy drive motor when we
// are just booting a bootsector, or drive, or partition.
// If we were to stop the floppy motor then
// the BIOS wouldn't be informed and if the
// next read is to a floppy then the BIOS will
// still think the motor is on and this will
// result in a read error.
/*
* Don't stop the floppy drive motor when we
* are just booting a bootsector, or drive, or partition.
* If we were to stop the floppy motor then
* the BIOS wouldn't be informed and if the
* next read is to a floppy then the BIOS will
* still think the motor is on and this will
* result in a read error.
*/
// DiskStopFloppyMotor();
// DisableA20();
FrldrBootDrive = DriveNumber;
@ -170,10 +179,10 @@ LoadAndBootDrive(IN OperatingSystemItem* OperatingSystem,
CHAR SettingValue[80];
UCHAR DriveNumber;
// Find all the message box settings and run them
/* Find all the message box settings and run them */
UiShowMessageBoxesInSection(SectionName);
// Try to open the operating system section in the .ini file
/* Try to open the operating system section in the .ini file */
if (!IniOpenSection(SectionName, &SectionId))
{
sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", SectionName);
@ -189,15 +198,14 @@ LoadAndBootDrive(IN OperatingSystemItem* OperatingSystem,
DriveNumber = DriveMapGetBiosDriveNumber(SettingValue);
// Now try to read the boot sector (or mbr)
// If this fails then abort
/* Now try to read the boot sector (or mbr). If this fails then abort. */
if (!MachDiskReadLogicalSectors(DriveNumber, 0, 1, (PVOID)0x7C00))
{
UiMessageBox("Unable to read boot sector");
return;
}
// Check for validity
/* Check for validity */
if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55)
{
UiMessageBox("Invalid boot sector magic (0xaa55)");
@ -205,13 +213,16 @@ LoadAndBootDrive(IN OperatingSystemItem* OperatingSystem,
}
UiUnInitialize("Booting...");
// Don't stop the floppy drive motor when we
// are just booting a bootsector, or drive, or partition.
// If we were to stop the floppy motor then
// the BIOS wouldn't be informed and if the
// next read is to a floppy then the BIOS will
// still think the motor is on and this will
// result in a read error.
/*
* Don't stop the floppy drive motor when we
* are just booting a bootsector, or drive, or partition.
* If we were to stop the floppy motor then
* the BIOS wouldn't be informed and if the
* next read is to a floppy then the BIOS will
* still think the motor is on and this will
* result in a read error.
*/
// DiskStopFloppyMotor();
// DisableA20();
FrldrBootDrive = DriveNumber;