3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 /* INCLUDES *******************************************************************/
26 /* FUNCTIONS ******************************************************************/
29 LoadAndBootBootSector(
38 /* Find all the message box settings and run them */
39 UiShowMessageBoxesInArgv(Argc
, Argv
);
41 /* Read the file name */
42 FileName
= GetArgumentValue(Argc
, Argv
, "BootSectorFile");
45 UiMessageBox("Boot sector file not specified for selected OS!");
49 FilePointer
= FsOpenFile(FileName
);
52 UiMessageBox("%s not found.", FileName
);
56 /* Read boot sector */
57 if (!FsReadFile(FilePointer
, 512, &BytesRead
, (void*)0x7c00) || (BytesRead
!= 512))
59 UiMessageBox("Unable to read boot sector.");
63 /* Check for validity */
64 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
66 UiMessageBox("Invalid boot sector magic (0xaa55)");
70 UiUnInitialize("Booting...");
74 * Don't stop the floppy drive motor when we
75 * are just booting a bootsector, or drive, or partition.
76 * If we were to stop the floppy motor then
77 * the BIOS wouldn't be informed and if the
78 * next read is to a floppy then the BIOS will
79 * still think the motor is on and this will
80 * result in a read error.
82 // DiskStopFloppyMotor();
84 ChainLoadBiosBootSectorCode();
95 PARTITION_TABLE_ENTRY PartitionTableEntry
;
97 ULONG PartitionNumber
;
99 /* Find all the message box settings and run them */
100 UiShowMessageBoxesInArgv(Argc
, Argv
);
102 /* Read the boot drive */
103 ArgValue
= GetArgumentValue(Argc
, Argv
, "BootDrive");
106 UiMessageBox("Boot drive not specified for selected OS!");
109 DriveNumber
= DriveMapGetBiosDriveNumber(ArgValue
);
111 /* Read the boot partition */
112 ArgValue
= GetArgumentValue(Argc
, Argv
, "BootPartition");
115 UiMessageBox("Boot partition not specified for selected OS!");
118 PartitionNumber
= atoi(ArgValue
);
120 /* Get the partition table entry */
121 if (!DiskGetPartitionEntry(DriveNumber
, PartitionNumber
, &PartitionTableEntry
))
126 /* Now try to read the partition boot sector. If this fails then abort. */
127 if (!MachDiskReadLogicalSectors(DriveNumber
, PartitionTableEntry
.SectorCountBeforePartition
, 1, (PVOID
)0x7C00))
129 UiMessageBox("Unable to read partition's boot sector.");
133 /* Check for validity */
134 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
136 UiMessageBox("Invalid boot sector magic (0xaa55)");
140 UiUnInitialize("Booting...");
144 * Don't stop the floppy drive motor when we
145 * are just booting a bootsector, or drive, or partition.
146 * If we were to stop the floppy motor then
147 * the BIOS wouldn't be informed and if the
148 * next read is to a floppy then the BIOS will
149 * still think the motor is on and this will
150 * result in a read error.
152 // DiskStopFloppyMotor();
154 FrldrBootDrive
= DriveNumber
;
155 ChainLoadBiosBootSectorCode();
168 /* Find all the message box settings and run them */
169 UiShowMessageBoxesInArgv(Argc
, Argv
);
171 /* Read the boot drive */
172 ArgValue
= GetArgumentValue(Argc
, Argv
, "BootDrive");
175 UiMessageBox("Boot drive not specified for selected OS!");
178 DriveNumber
= DriveMapGetBiosDriveNumber(ArgValue
);
180 /* Now try to read the boot sector (or mbr). If this fails then abort. */
181 if (!MachDiskReadLogicalSectors(DriveNumber
, 0, 1, (PVOID
)0x7C00))
183 UiMessageBox("Unable to read boot sector");
187 /* Check for validity */
188 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
190 UiMessageBox("Invalid boot sector magic (0xaa55)");
194 UiUnInitialize("Booting...");
198 * Don't stop the floppy drive motor when we
199 * are just booting a bootsector, or drive, or partition.
200 * If we were to stop the floppy motor then
201 * the BIOS wouldn't be informed and if the
202 * next read is to a floppy then the BIOS will
203 * still think the motor is on and this will
204 * result in a read error.
206 // DiskStopFloppyMotor();
208 FrldrBootDrive
= DriveNumber
;
209 ChainLoadBiosBootSectorCode();