* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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>
-#ifdef __i386__
-VOID LoadAndBootBootSector(PCSTR OperatingSystemName)
+/* FUNCTIONS ******************************************************************/
+
+ARC_STATUS
+LoadAndBootBootSector(
+ IN ULONG Argc,
+ IN PCHAR Argv[],
+ IN PCHAR Envp[])
{
- PFILE FilePointer;
- CHAR SettingName[80];
- ULONG SectionId;
- CHAR FileName[260];
- ULONG BytesRead;
-
- // Find all the message box settings and run them
- UiShowMessageBoxesInSection(OperatingSystemName);
-
- // Try to open the operating system section in the .ini file
- if (!IniOpenSection(OperatingSystemName, &SectionId))
- {
- sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
- UiMessageBox(SettingName);
- return;
- }
-
- if (!IniReadSettingByName(SectionId, "BootSectorFile", FileName, sizeof(FileName)))
- {
- UiMessageBox("Boot sector file not specified for selected OS!");
- return;
- }
-
- if (!MachDiskNormalizeSystemPath(FileName, sizeof(FileName)))
- {
- UiMessageBox("Invalid path to boot sector file");
- return;
- }
-
- if (!FsOpenSystemVolume(FileName, FileName, NULL))
- {
- UiMessageBox("Failed to open boot drive.");
- return;
- }
-
- FilePointer = FsOpenFile(FileName);
- if (FilePointer == NULL)
- {
- strcat(FileName, " not found.");
- UiMessageBox(FileName);
- return;
- }
-
- // Read boot sector
- if (!FsReadFile(FilePointer, 512, &BytesRead, (void*)0x7c00) || (BytesRead != 512))
- {
- return;
- }
-
- // Check for validity
- if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55)
- {
- UiMessageBox("Invalid boot sector magic (0xaa55)");
- return;
- }
-
- 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();
- ChainLoadBiosBootSectorCode();
+ PCSTR FileName;
+ ULONG FileId;
+ 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;
+ }
+
+ FileId = FsOpenFile(FileName);
+ if (!FileId)
+ {
+ UiMessageBox("%s not found.", FileName);
+ return ENOENT;
+ }
+
+ /* Read boot sector */
+ if (ArcRead(FileId, (void*)0x7c00, 512, &BytesRead) != ESUCCESS ||
+ (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;
}
-VOID LoadAndBootPartition(PCSTR OperatingSystemName)
+ARC_STATUS
+LoadAndBootPartition(
+ IN ULONG Argc,
+ IN PCHAR Argv[],
+ IN PCHAR Envp[])
{
- CHAR SettingName[80];
- CHAR SettingValue[80];
- ULONG SectionId;
- PARTITION_TABLE_ENTRY PartitionTableEntry;
- ULONG DriveNumber;
- ULONG PartitionNumber;
-
- // Find all the message box settings and run them
- UiShowMessageBoxesInSection(OperatingSystemName);
-
- // Try to open the operating system section in the .ini file
- if (!IniOpenSection(OperatingSystemName, &SectionId))
- {
- sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
- UiMessageBox(SettingName);
- return;
- }
-
- // Read the boot drive
- if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, sizeof(SettingValue)))
- {
- UiMessageBox("Boot drive not specified for selected OS!");
- return;
- }
-
- DriveNumber = DriveMapGetBiosDriveNumber(SettingValue);
-
- // Read the boot partition
- if (!IniReadSettingByName(SectionId, "BootPartition", SettingValue, sizeof(SettingValue)))
- {
- UiMessageBox("Boot partition not specified for selected OS!");
- return;
- }
-
- PartitionNumber = atoi(SettingValue);
-
- // Get the partition table entry
- if (!DiskGetPartitionEntry(DriveNumber, PartitionNumber, &PartitionTableEntry))
- {
- return;
- }
-
- // Now try to read the partition boot sector
- // If this fails then abort
- if (!MachDiskReadLogicalSectors(DriveNumber, PartitionTableEntry.SectorCountBeforePartition, 1, (PVOID)0x7C00))
- {
- return;
- }
-
- // Check for validity
- if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55)
- {
- UiMessageBox("Invalid boot sector magic (0xaa55)");
- return;
- }
-
- 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();
- ChainLoadBiosBootSectorCode();
+ 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;
}
-VOID LoadAndBootDrive(PCSTR OperatingSystemName)
+ARC_STATUS
+LoadAndBootDrive(
+ IN ULONG Argc,
+ IN PCHAR Argv[],
+ IN PCHAR Envp[])
{
- CHAR SettingName[80];
- CHAR SettingValue[80];
- ULONG SectionId;
- ULONG DriveNumber;
-
- // Find all the message box settings and run them
- UiShowMessageBoxesInSection(OperatingSystemName);
-
- // Try to open the operating system section in the .ini file
- if (!IniOpenSection(OperatingSystemName, &SectionId))
- {
- sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
- UiMessageBox(SettingName);
- return;
- }
-
- if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, sizeof(SettingValue)))
- {
- UiMessageBox("Boot drive not specified for selected OS!");
- return;
- }
-
- DriveNumber = DriveMapGetBiosDriveNumber(SettingValue);
-
- // Now try to read the boot sector (or mbr)
- // If this fails then abort
- if (!MachDiskReadLogicalSectors(DriveNumber, 0, 1, (PVOID)0x7C00))
- {
- return;
- }
-
- // Check for validity
- if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55)
- {
- UiMessageBox("Invalid boot sector magic (0xaa55)");
- return;
- }
-
- 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();
- ChainLoadBiosBootSectorCode();
+ 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 /* __i386__ */
+
+#endif // _M_IX86