[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

@ -163,7 +163,7 @@ i386PrintExceptionText(ULONG TrapIndex, PKTRAP_FRAME TrapFrame, PKSPECIAL_REGIST
TrapFrame->SegSs, Special->Ldtr, Special->Idtr.Limit);
InstructionPointer = (PUCHAR)TrapFrame->Rip;
#endif
PrintText("\nInstructionstream: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x \n",
PrintText("\nInstruction stream: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x \n",
InstructionPointer[0], InstructionPointer[1],
InstructionPointer[2], InstructionPointer[3],
InstructionPointer[4], InstructionPointer[5],
@ -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)
@ -106,19 +111,17 @@ VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem)
ULONG GetDefaultOperatingSystem(OperatingSystemItem* OperatingSystemList, ULONG OperatingSystemCount)
{
CHAR DefaultOSText[80];
PCSTR DefaultOSName;
ULONG_PTR SectionId;
ULONG DefaultOS = 0;
ULONG Idx;
CHAR DefaultOSText[80];
PCSTR DefaultOSName;
ULONG_PTR SectionId;
ULONG DefaultOS = 0;
ULONG Idx;
if (!IniOpenSection("FreeLoader", &SectionId))
{
return 0;
}
DefaultOSName = CmdLineGetDefaultOS();
if (NULL == DefaultOSName)
if (DefaultOSName == NULL)
{
if (IniReadSettingByName(SectionId, "DefaultOS", DefaultOSText, sizeof(DefaultOSText)))
{
@ -126,9 +129,9 @@ ULONG GetDefaultOperatingSystem(OperatingSystemItem* OperatingSystemList, ULONG
}
}
if (NULL != DefaultOSName)
if (DefaultOSName != NULL)
{
for (Idx=0; Idx<OperatingSystemCount; Idx++)
for (Idx = 0; Idx<OperatingSystemCount; Idx++)
{
if (_stricmp(DefaultOSName, OperatingSystemList[Idx].SystemPartition) == 0)
{
@ -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,42 +170,41 @@ 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;
}
VOID RunLoader(VOID)
{
ULONG_PTR SectionId;
ULONG OperatingSystemCount;
OperatingSystemItem* OperatingSystemList;
PCSTR* OperatingSystemDisplayNames;
ULONG DefaultOperatingSystem;
LONG TimeOut;
ULONG SelectedOperatingSystem;
ULONG i;
ULONG_PTR SectionId;
ULONG OperatingSystemCount;
OperatingSystemItem* OperatingSystemList;
PCSTR* OperatingSystemDisplayNames;
ULONG DefaultOperatingSystem;
LONG TimeOut;
ULONG SelectedOperatingSystem;
ULONG i;
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,32 +17,37 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <freeldr.h>
#ifdef _M_IX86
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.";
const CHAR BootSectorFilePrompt[] = "Enter the boot sector file path.\n\nExamples:\n\\BOOTSECT.DOS\n/boot/bootsect.dos";
const CHAR LinuxKernelPrompt[] = "Enter the Linux kernel image path.\n\nExamples:\n/vmlinuz\n/boot/vmlinuz-2.4.18";
const CHAR LinuxInitrdPrompt[] = "Enter the initrd image path.\n\nExamples:\n/initrd.gz\n/boot/root.img.gz\n\nLeave blank for no initial ram disk.";
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";
/* INCLUDES *******************************************************************/
const CHAR CustomBootPrompt[] = "Press ENTER to boot your custom boot setup.";
#include <freeldr.h>
/* 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.";
const CHAR BootSectorFilePrompt[] = "Enter the boot sector file path.\n\nExamples:\n\\BOOTSECT.DOS\n/boot/bootsect.dos";
const CHAR LinuxKernelPrompt[] = "Enter the Linux kernel image path.\n\nExamples:\n/vmlinuz\n/boot/vmlinuz-2.4.18";
const CHAR LinuxInitrdPrompt[] = "Enter the initrd image path.\n\nExamples:\n/initrd.gz\n/boot/root.img.gz\n\nLeave blank for no initial ram disk.";
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[] = {
PCSTR CustomBootMenuList[] = {
"Disk",
"Partition",
"Boot Sector File",
"ReactOS",
"Linux"
};
ULONG CustomBootMenuCount = sizeof(CustomBootMenuList) / sizeof(CustomBootMenuList[0]);
ULONG SelectedMenuItem;
ULONG CustomBootMenuCount = sizeof(CustomBootMenuList) / sizeof(CustomBootMenuList[0]);
ULONG SelectedMenuItem;
if (!UiDisplayMenu("Please choose a boot method:", "",
FALSE,
@ -59,61 +64,53 @@ VOID OptionMenuCustomBoot(VOID)
switch (SelectedMenuItem)
{
case 0: // Disk
OptionMenuCustomBootDisk();
break;
case 1: // Partition
OptionMenuCustomBootPartition();
break;
case 2: // Boot Sector File
OptionMenuCustomBootBootSectorFile();
break;
case 3: // ReactOS
OptionMenuCustomBootReactOS();
break;
case 4: // Linux
OptionMenuCustomBootLinux();
break;
case 0: // Disk
OptionMenuCustomBootDisk();
break;
case 1: // Partition
OptionMenuCustomBootPartition();
break;
case 2: // Boot Sector File
OptionMenuCustomBootBootSectorFile();
break;
case 3: // ReactOS
OptionMenuCustomBootReactOS();
break;
case 4: // Linux
OptionMenuCustomBootLinux();
break;
}
}
VOID OptionMenuCustomBootDisk(VOID)
{
ULONG_PTR SectionId;
CHAR SectionName[100];
CHAR BootDriveString[20];
TIMEINFO* TimeInfo;
OperatingSystemItem OperatingSystem;
ULONG_PTR SectionId;
CHAR SectionName[100];
CHAR BootDriveString[20];
TIMEINFO* TimeInfo;
OperatingSystemItem OperatingSystem;
RtlZeroMemory(SectionName, sizeof(SectionName));
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);
@ -127,54 +124,42 @@ VOID OptionMenuCustomBootDisk(VOID)
VOID OptionMenuCustomBootPartition(VOID)
{
ULONG_PTR SectionId;
CHAR SectionName[100];
CHAR BootDriveString[20];
CHAR BootPartitionString[20];
TIMEINFO* TimeInfo;
OperatingSystemItem OperatingSystem;
ULONG_PTR SectionId;
CHAR SectionName[100];
CHAR BootDriveString[20];
CHAR BootPartitionString[20];
TIMEINFO* TimeInfo;
OperatingSystemItem OperatingSystem;
RtlZeroMemory(SectionName, sizeof(SectionName));
RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
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);
@ -188,13 +173,13 @@ VOID OptionMenuCustomBootPartition(VOID)
VOID OptionMenuCustomBootBootSectorFile(VOID)
{
ULONG_PTR SectionId;
CHAR SectionName[100];
CHAR BootDriveString[20];
CHAR BootPartitionString[20];
CHAR BootSectorFileString[200];
TIMEINFO* TimeInfo;
OperatingSystemItem OperatingSystem;
ULONG_PTR SectionId;
CHAR SectionName[100];
CHAR BootDriveString[20];
CHAR BootPartitionString[20];
CHAR BootSectorFileString[200];
TIMEINFO* TimeInfo;
OperatingSystemItem OperatingSystem;
RtlZeroMemory(SectionName, sizeof(SectionName));
RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
@ -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);
@ -262,15 +231,15 @@ VOID OptionMenuCustomBootBootSectorFile(VOID)
VOID OptionMenuCustomBootReactOS(VOID)
{
ULONG_PTR SectionId;
CHAR SectionName[100];
CHAR BootDriveString[20];
CHAR BootPartitionString[20];
CHAR ReactOSSystemPath[200];
CHAR ReactOSARCPath[200];
CHAR ReactOSOptions[200];
TIMEINFO* TimeInfo;
OperatingSystemItem OperatingSystem;
ULONG_PTR SectionId;
CHAR SectionName[100];
CHAR BootDriveString[20];
CHAR BootPartitionString[20];
CHAR ReactOSSystemPath[200];
CHAR ReactOSARCPath[200];
CHAR ReactOSOptions[200];
TIMEINFO* TimeInfo;
OperatingSystemItem OperatingSystem;
RtlZeroMemory(SectionName, sizeof(SectionName));
RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
@ -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);
@ -341,15 +294,15 @@ VOID OptionMenuCustomBootReactOS(VOID)
VOID OptionMenuCustomBootLinux(VOID)
{
ULONG_PTR SectionId;
CHAR SectionName[100];
CHAR BootDriveString[20];
CHAR BootPartitionString[20];
CHAR LinuxKernelString[200];
CHAR LinuxInitrdString[200];
CHAR LinuxCommandLineString[200];
TIMEINFO* TimeInfo;
OperatingSystemItem OperatingSystem;
ULONG_PTR SectionId;
CHAR SectionName[100];
CHAR BootDriveString[20];
CHAR BootPartitionString[20];
CHAR LinuxKernelString[200];
CHAR LinuxInitrdString[200];
CHAR LinuxCommandLineString[200];
TIMEINFO* TimeInfo;
OperatingSystemItem OperatingSystem;
RtlZeroMemory(SectionName, sizeof(SectionName));
RtlZeroMemory(BootDriveString, sizeof(BootDriveString));
@ -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

@ -23,12 +23,12 @@
#if DBG && !defined(_M_ARM)
//#define DEBUG_ALL
//#define DEBUG_WARN
//#define DEBUG_ERR
//#define DEBUG_INIFILE
//#define DEBUG_REACTOS
//#define DEBUG_CUSTOM
// #define DEBUG_ALL
// #define DEBUG_WARN
// #define DEBUG_ERR
// #define DEBUG_INIFILE
// #define DEBUG_REACTOS
// #define DEBUG_CUSTOM
#define DEBUG_NONE
#define DBG_DEFAULT_LEVELS (ERR_LEVEL|FIXME_LEVEL)
@ -44,23 +44,22 @@
#define BOCHS_OUTPUT_PORT 0xe9
static UCHAR DbgChannels[DBG_CHANNELS_COUNT];
ULONG DebugPort = RS232;
//ULONG DebugPort = SCREEN;
//ULONG DebugPort = BOCHS;
//ULONG DebugPort = SCREEN|BOCHS;
ULONG DebugPort = RS232;
// ULONG DebugPort = SCREEN;
// ULONG DebugPort = BOCHS;
// ULONG DebugPort = SCREEN|BOCHS;
#ifdef _WINKD_
/* COM1 is the WinDbg port */
ULONG ComPort = COM2;
ULONG ComPort = COM2;
#else
ULONG ComPort = COM1;
ULONG ComPort = COM1;
#endif
//ULONG BaudRate = 19200;
ULONG BaudRate = 115200;
// ULONG BaudRate = 19200;
ULONG BaudRate = 115200;
BOOLEAN DebugStartOfLine = TRUE;
BOOLEAN DebugStartOfLine = TRUE;
VOID DebugInit(VOID)
{
@ -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++)
{
@ -267,40 +253,40 @@ DebugDumpBuffer(ULONG Mask, PVOID Buffer, ULONG Length)
}
static BOOLEAN
DbgAddDebugChannel( CHAR* channel, CHAR* level, CHAR op)
DbgAddDebugChannel(CHAR* channel, CHAR* level, CHAR op)
{
int iLevel, iChannel;
if(channel == NULL || *channel == L'\0' ||strlen(channel) == 0 )
if (channel == NULL || *channel == L'\0' || strlen(channel) == 0 )
return FALSE;
if(level == NULL || *level == L'\0' ||strlen(level) == 0 )
if (level == NULL || *level == L'\0' || strlen(level) == 0 )
iLevel = MAX_LEVEL;
else if(strcmp(level, "err") == 0)
else if (strcmp(level, "err") == 0)
iLevel = ERR_LEVEL;
else if(strcmp(level, "fixme") == 0)
else if (strcmp(level, "fixme") == 0)
iLevel = FIXME_LEVEL;
else if(strcmp(level, "warn") == 0)
else if (strcmp(level, "warn") == 0)
iLevel = WARN_LEVEL;
else if (strcmp(level, "trace") == 0)
iLevel = TRACE_LEVEL;
else
return FALSE;
if(strcmp(channel, "memory") == 0) iChannel = DPRINT_MEMORY;
else if(strcmp(channel, "filesystem") == 0) iChannel = DPRINT_FILESYSTEM;
else if(strcmp(channel, "inifile") == 0) iChannel = DPRINT_INIFILE;
else if(strcmp(channel, "ui") == 0) iChannel = DPRINT_UI;
else if(strcmp(channel, "disk") == 0) iChannel = DPRINT_DISK;
else if(strcmp(channel, "cache") == 0) iChannel = DPRINT_CACHE;
else if(strcmp(channel, "registry") == 0) iChannel = DPRINT_REGISTRY;
else if(strcmp(channel, "linux") == 0) iChannel = DPRINT_LINUX;
else if(strcmp(channel, "hwdetect") == 0) iChannel = DPRINT_HWDETECT;
else if(strcmp(channel, "windows") == 0) iChannel = DPRINT_WINDOWS;
else if(strcmp(channel, "peloader") == 0) iChannel = DPRINT_PELOADER;
else if(strcmp(channel, "scsiport") == 0) iChannel = DPRINT_SCSIPORT;
else if(strcmp(channel, "heap") == 0) iChannel = DPRINT_HEAP;
else if(strcmp(channel, "all") == 0)
if (strcmp(channel, "memory" ) == 0) iChannel = DPRINT_MEMORY;
else if (strcmp(channel, "filesystem") == 0) iChannel = DPRINT_FILESYSTEM;
else if (strcmp(channel, "inifile" ) == 0) iChannel = DPRINT_INIFILE;
else if (strcmp(channel, "ui" ) == 0) iChannel = DPRINT_UI;
else if (strcmp(channel, "disk" ) == 0) iChannel = DPRINT_DISK;
else if (strcmp(channel, "cache" ) == 0) iChannel = DPRINT_CACHE;
else if (strcmp(channel, "registry" ) == 0) iChannel = DPRINT_REGISTRY;
else if (strcmp(channel, "linux" ) == 0) iChannel = DPRINT_LINUX;
else if (strcmp(channel, "hwdetect" ) == 0) iChannel = DPRINT_HWDETECT;
else if (strcmp(channel, "windows" ) == 0) iChannel = DPRINT_WINDOWS;
else if (strcmp(channel, "peloader" ) == 0) iChannel = DPRINT_PELOADER;
else if (strcmp(channel, "scsiport" ) == 0) iChannel = DPRINT_SCSIPORT;
else if (strcmp(channel, "heap" ) == 0) iChannel = DPRINT_HEAP;
else if (strcmp(channel, "all" ) == 0)
{
int i;
@ -316,7 +302,7 @@ DbgAddDebugChannel( CHAR* channel, CHAR* level, CHAR op)
}
else return FALSE;
if(op==L'+')
if (op == L'+')
DbgChannels[iChannel] |= iLevel;
else
DbgChannels[iChannel] &= ~iLevel;
@ -333,25 +319,25 @@ DbgParseDebugChannels(PCHAR Value)
do
{
separator = strchr(str, L',');
if(separator != NULL)
*separator = L'\0';
separator = strchr(str, ',');
if (separator != NULL)
*separator = '\0';
c = strchr(str, L'+');
if(c == NULL)
c = strchr(str, L'-');
c = strchr(str, '+');
if (c == NULL)
c = strchr(str, '-');
if(c != NULL)
if (c != NULL)
{
op = *c;
*c = L'\0';
*c = '\0';
c++;
DbgAddDebugChannel(c, str, op);
}
str = separator + 1;
} while(separator != NULL);
} while (separator != NULL);
}
#else
@ -394,7 +380,7 @@ MsgBoxPrint(const char *Format, ...)
return 0;
}
//DECLSPEC_NORETURN
// DECLSPEC_NORETURN
VOID
NTAPI
KeBugCheckEx(
@ -406,8 +392,8 @@ KeBugCheckEx(
{
char Buffer[70];
sprintf(Buffer, "*** STOP: 0x%08lX (0x%08lX, 0x%08lX, 0x%08lX, 0x%08lX)",
BugCheckCode, BugCheckParameter1, BugCheckParameter2,
BugCheckParameter3, BugCheckParameter4);
BugCheckCode, BugCheckParameter1, BugCheckParameter2,
BugCheckParameter3, BugCheckParameter4);
UiMessageBoxCritical(Buffer);
assert(FALSE);
for (;;);
@ -420,23 +406,23 @@ RtlAssert(IN PVOID FailedAssertion,
IN ULONG LineNumber,
IN PCHAR Message OPTIONAL)
{
if (Message)
{
DbgPrint("Assertion \'%s\' failed at %s line %u: %s\n",
(PCHAR)FailedAssertion,
(PCHAR)FileName,
LineNumber,
Message);
}
else
{
DbgPrint("Assertion \'%s\' failed at %s line %u\n",
(PCHAR)FailedAssertion,
(PCHAR)FileName,
LineNumber);
}
if (Message)
{
DbgPrint("Assertion \'%s\' failed at %s line %u: %s\n",
(PCHAR)FailedAssertion,
(PCHAR)FileName,
LineNumber,
Message);
}
else
{
DbgPrint("Assertion \'%s\' failed at %s line %u\n",
(PCHAR)FailedAssertion,
(PCHAR)FileName,
LineNumber);
}
DbgBreakPoint();
DbgBreakPoint();
}
char *BugCodeStrings[] =
@ -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();
@ -73,7 +73,7 @@ int __cdecl wctomb(char *mbchar, wchar_t wchar)
return 1;
}
int __cdecl mbtowc (wchar_t *wchar, const char *mbchar, size_t count)
int __cdecl mbtowc(wchar_t *wchar, const char *mbchar, size_t count)
{
*wchar = (wchar_t)*mbchar;
return 1;

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

@ -20,16 +20,16 @@
#ifndef __DEBUG_H
#define __DEBUG_H
#define DPRINT_NONE 0 // No debug print
#define DPRINT_WARNING 1 // debugger messages and other misc stuff
#define DPRINT_MEMORY 2 // memory management messages
#define DPRINT_FILESYSTEM 3 // file system messages
#define DPRINT_INIFILE 4 // .ini file messages
#define DPRINT_UI 5 // user interface messages
#define DPRINT_DISK 6 // disk messages
#define DPRINT_CACHE 7 // cache messages
#define DPRINT_REGISTRY 8 // registry messages
#define DPRINT_REACTOS 9 // ReactOS messages
#define DPRINT_NONE 0 // No debug print
#define DPRINT_WARNING 1 // debugger messages and other misc stuff
#define DPRINT_MEMORY 2 // memory management messages
#define DPRINT_FILESYSTEM 3 // file system messages
#define DPRINT_INIFILE 4 // .ini file messages
#define DPRINT_UI 5 // user interface messages
#define DPRINT_DISK 6 // disk messages
#define DPRINT_CACHE 7 // cache messages
#define DPRINT_REGISTRY 8 // registry messages
#define DPRINT_REACTOS 9 // ReactOS messages
#define DPRINT_LINUX 10 // Linux messages
#define DPRINT_HWDETECT 11 // hardware detection messages
#define DPRINT_WINDOWS 12 // messages from Windows loader

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,55 +19,55 @@
#ifndef _M_ARM
#ifdef _M_IX86
/* INCLUDES *******************************************************************/
#include <freeldr.h>
#include <debug.h>
#ifdef _M_IX86
#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;
BOOLEAN NewStyleLinuxKernel = FALSE;
ULONG LinuxKernelSize = 0;
ULONG LinuxInitrdSize = 0;
CHAR LinuxKernelName[260];
CHAR LinuxInitrdName[260];
BOOLEAN LinuxHasInitrd = FALSE;
CHAR LinuxCommandLine[260] = "";
ULONG LinuxCommandLineSize = 0;
PVOID LinuxKernelLoadAddress = NULL;
PVOID LinuxInitrdLoadAddress = NULL;
CHAR LinuxBootDescription[80];
CHAR LinuxBootPath[260] = "";
/* GLOBALS ********************************************************************/
#define LINUX_READ_CHUNK_SIZE 0x20000 // Read 128k at a time
PLINUX_BOOTSECTOR LinuxBootSector = NULL;
PLINUX_SETUPSECTOR LinuxSetupSector = NULL;
ULONG SetupSectorSize = 0;
BOOLEAN NewStyleLinuxKernel = FALSE;
ULONG LinuxKernelSize = 0;
ULONG LinuxInitrdSize = 0;
CHAR LinuxKernelName[260];
CHAR LinuxInitrdName[260];
BOOLEAN LinuxHasInitrd = FALSE;
CHAR LinuxCommandLine[260] = "";
ULONG LinuxCommandLineSize = 0;
PVOID LinuxKernelLoadAddress = NULL;
PVOID LinuxInitrdLoadAddress = NULL;
CHAR LinuxBootDescription[80];
CHAR LinuxBootPath[260] = "";
/* FUNCTIONS ******************************************************************/
BOOLEAN RemoveQuotes(PCHAR QuotedString)
{
CHAR TempString[200];
CHAR TempString[200];
PCHAR p;
PSTR Start;
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);
@ -78,33 +78,27 @@ VOID
LoadAndBootLinux(IN OperatingSystemItem* OperatingSystem,
IN USHORT OperatingSystemVersion)
{
PCSTR SectionName = OperatingSystem->SystemPartition;
PCSTR Description = OperatingSystem->LoadIdentifier;
PFILE LinuxKernel = 0;
PFILE LinuxInitrdFile = 0;
CHAR TempString[260];
PCSTR SectionName = OperatingSystem->SystemPartition;
PCSTR Description = OperatingSystem->LoadIdentifier;
PFILE LinuxKernel = 0;
PFILE LinuxInitrdFile = 0;
CHAR TempString[260];
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;
@ -243,13 +211,13 @@ LinuxBootFailed:
BOOLEAN LinuxParseIniSection(PCSTR SectionName)
{
ULONG_PTR SectionId;
CHAR SettingName[260];
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)");
@ -325,48 +289,36 @@ BOOLEAN LinuxReadBootSector(PFILE LinuxKernelFile)
BOOLEAN LinuxReadSetupSector(PFILE LinuxKernelFile)
{
UCHAR TempLinuxSetupSector[512];
UCHAR TempLinuxSetupSector[512];
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);
@ -391,14 +343,14 @@ BOOLEAN LinuxReadSetupSector(PFILE LinuxKernelFile)
BOOLEAN LinuxReadKernel(PFILE LinuxKernelFile)
{
ULONG BytesLoaded;
CHAR StatusText[260];
PVOID LoadAddress;
ULONG BytesLoaded;
CHAR StatusText[260];
PVOID LoadAddress;
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,25 +17,29 @@
* 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,
IN USHORT OperatingSystemVersion)
{
ULONG_PTR SectionId;
PCSTR SectionName = OperatingSystem->SystemPartition;
CHAR FileName[260];
PFILE FilePointer;
ULONG BytesRead;
CHAR SettingName[80];
ULONG_PTR SectionId;
PCSTR SectionName = OperatingSystem->SystemPartition;
CHAR FileName[260];
PFILE FilePointer;
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,15 +76,18 @@ 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.
//DiskStopFloppyMotor();
//DisableA20();
/*
* 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();
}
@ -88,18 +95,18 @@ VOID
LoadAndBootPartition(IN OperatingSystemItem* OperatingSystem,
IN USHORT OperatingSystemVersion)
{
ULONG_PTR SectionId;
PCSTR SectionName = OperatingSystem->SystemPartition;
CHAR SettingName[80];
CHAR SettingValue[80];
PARTITION_TABLE_ENTRY PartitionTableEntry;
UCHAR DriveNumber;
ULONG PartitionNumber;
ULONG_PTR SectionId;
PCSTR SectionName = OperatingSystem->SystemPartition;
CHAR SettingName[80];
CHAR SettingValue[80];
PARTITION_TABLE_ENTRY PartitionTableEntry;
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,15 +153,18 @@ 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.
//DiskStopFloppyMotor();
//DisableA20();
/*
* 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;
ChainLoadBiosBootSectorCode();
}
@ -164,16 +173,16 @@ VOID
LoadAndBootDrive(IN OperatingSystemItem* OperatingSystem,
IN USHORT OperatingSystemVersion)
{
ULONG_PTR SectionId;
PCSTR SectionName = OperatingSystem->SystemPartition;
CHAR SettingName[80];
CHAR SettingValue[80];
UCHAR DriveNumber;
ULONG_PTR SectionId;
PCSTR SectionName = OperatingSystem->SystemPartition;
CHAR SettingName[80];
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,15 +213,18 @@ 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.
//DiskStopFloppyMotor();
//DisableA20();
/*
* 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;
ChainLoadBiosBootSectorCode();
}