mirror of
https://github.com/reactos/reactos.git
synced 2024-06-25 23:41:35 +00:00
![Hermès Bélusca-Maïto](/assets/img/avatar_default.png)
CORE-9023 - During loading and initialization of the list of operating systems available in freeldr.ini, convert any legacy operating system entry encountered -- they are like those in NTLDR's boot.ini file, i.e.: ArcOsLoadPartition="LoadIdentifier" /List /of /Options into a new operating system INI entry, like those used by default in FreeLoader. This allows us to avoid treating this corner-case later in different parts of the code. Also, the "BootType" value is now determined there, only once. - Convert the OS loaders entry-points to ARC-compatible ones, following the "Advanced RISC Computing Specification, Version 1.2" specification https://www.netbsd.org/docs/Hardware/Machines/ARC/riscspec.pdf - Introduce helpers for retrieving options values from the argument vector in a simple way. - Simplify LoadOperatingSystem(), since now the "BootType" value has been determined once while loading the list of OSes (see above) and is well-defined there. Use the BuildArgvForOsLoader() helper to build the ARC-compatible argument vector from the corresponding INI settings for the selected operating system entry, and use it when calling the corresponding OS loader. - In the OS loaders, since we can now directly read the settings from the argument vector (instead of using INI settings), we can avoid using a bunch of fixed-size string buffers, and avoid potentially failing IniOpenSection() calls as well. - Simplify code in the Linux loader (and the RemoveQuotes() function). - Add UiShowMessageBoxesInArgv() that acts on the "MessageBox=" settings passed through the argument vector (equivalent to UiShowMessageBoxesInSection() ). - Use string-safe functions where needed (copy/concatenation/printf on fixed-size buffers).
214 lines
5.9 KiB
C
214 lines
5.9 KiB
C
/*
|
|
* FreeLoader
|
|
* Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*/
|
|
|
|
#ifdef _M_IX86
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
#include <freeldr.h>
|
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
ARC_STATUS
|
|
LoadAndBootBootSector(
|
|
IN ULONG Argc,
|
|
IN PCHAR Argv[],
|
|
IN PCHAR Envp[])
|
|
{
|
|
PCSTR FileName;
|
|
PFILE FilePointer;
|
|
ULONG BytesRead;
|
|
|
|
/* Find all the message box settings and run them */
|
|
UiShowMessageBoxesInArgv(Argc, Argv);
|
|
|
|
/* Read the file name */
|
|
FileName = GetArgumentValue(Argc, Argv, "BootSectorFile");
|
|
if (!FileName)
|
|
{
|
|
UiMessageBox("Boot sector file not specified for selected OS!");
|
|
return EINVAL;
|
|
}
|
|
|
|
FilePointer = FsOpenFile(FileName);
|
|
if (!FilePointer)
|
|
{
|
|
UiMessageBox("%s not found.", FileName);
|
|
return ENOENT;
|
|
}
|
|
|
|
/* Read boot sector */
|
|
if (!FsReadFile(FilePointer, 512, &BytesRead, (void*)0x7c00) || (BytesRead != 512))
|
|
{
|
|
UiMessageBox("Unable to read boot sector.");
|
|
return EIO;
|
|
}
|
|
|
|
/* Check for validity */
|
|
if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55)
|
|
{
|
|
UiMessageBox("Invalid boot sector magic (0xaa55)");
|
|
return ENOEXEC;
|
|
}
|
|
|
|
UiUnInitialize("Booting...");
|
|
IniCleanup();
|
|
|
|
/*
|
|
* 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();
|
|
return ESUCCESS;
|
|
}
|
|
|
|
ARC_STATUS
|
|
LoadAndBootPartition(
|
|
IN ULONG Argc,
|
|
IN PCHAR Argv[],
|
|
IN PCHAR Envp[])
|
|
{
|
|
PCSTR ArgValue;
|
|
PARTITION_TABLE_ENTRY PartitionTableEntry;
|
|
UCHAR DriveNumber;
|
|
ULONG PartitionNumber;
|
|
|
|
/* Find all the message box settings and run them */
|
|
UiShowMessageBoxesInArgv(Argc, Argv);
|
|
|
|
/* Read the boot drive */
|
|
ArgValue = GetArgumentValue(Argc, Argv, "BootDrive");
|
|
if (!ArgValue)
|
|
{
|
|
UiMessageBox("Boot drive not specified for selected OS!");
|
|
return EINVAL;
|
|
}
|
|
DriveNumber = DriveMapGetBiosDriveNumber(ArgValue);
|
|
|
|
/* Read the boot partition */
|
|
ArgValue = GetArgumentValue(Argc, Argv, "BootPartition");
|
|
if (!ArgValue)
|
|
{
|
|
UiMessageBox("Boot partition not specified for selected OS!");
|
|
return EINVAL;
|
|
}
|
|
PartitionNumber = atoi(ArgValue);
|
|
|
|
/* Get the partition table entry */
|
|
if (!DiskGetPartitionEntry(DriveNumber, PartitionNumber, &PartitionTableEntry))
|
|
{
|
|
return ENOENT;
|
|
}
|
|
|
|
/* 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 EIO;
|
|
}
|
|
|
|
/* Check for validity */
|
|
if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55)
|
|
{
|
|
UiMessageBox("Invalid boot sector magic (0xaa55)");
|
|
return ENOEXEC;
|
|
}
|
|
|
|
UiUnInitialize("Booting...");
|
|
IniCleanup();
|
|
|
|
/*
|
|
* 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();
|
|
return ESUCCESS;
|
|
}
|
|
|
|
ARC_STATUS
|
|
LoadAndBootDrive(
|
|
IN ULONG Argc,
|
|
IN PCHAR Argv[],
|
|
IN PCHAR Envp[])
|
|
{
|
|
PCSTR ArgValue;
|
|
UCHAR DriveNumber;
|
|
|
|
/* Find all the message box settings and run them */
|
|
UiShowMessageBoxesInArgv(Argc, Argv);
|
|
|
|
/* Read the boot drive */
|
|
ArgValue = GetArgumentValue(Argc, Argv, "BootDrive");
|
|
if (!ArgValue)
|
|
{
|
|
UiMessageBox("Boot drive not specified for selected OS!");
|
|
return EINVAL;
|
|
}
|
|
DriveNumber = DriveMapGetBiosDriveNumber(ArgValue);
|
|
|
|
/* 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 EIO;
|
|
}
|
|
|
|
/* Check for validity */
|
|
if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55)
|
|
{
|
|
UiMessageBox("Invalid boot sector magic (0xaa55)");
|
|
return ENOEXEC;
|
|
}
|
|
|
|
UiUnInitialize("Booting...");
|
|
IniCleanup();
|
|
|
|
/*
|
|
* 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();
|
|
return ESUCCESS;
|
|
}
|
|
|
|
#endif // _M_IX86
|