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 FileId
= FsOpenFile(FileName
);
52 UiMessageBox("%s not found.", FileName
);
56 /* Read boot sector */
57 if (ArcRead(FileId
, (void*)0x7c00, 512, &BytesRead
) != ESUCCESS
||
60 UiMessageBox("Unable to read boot sector.");
64 /* Check for validity */
65 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
67 UiMessageBox("Invalid boot sector magic (0xaa55)");
71 UiUnInitialize("Booting...");
75 * Don't stop the floppy drive motor when we
76 * are just booting a bootsector, or drive, or partition.
77 * If we were to stop the floppy motor then
78 * the BIOS wouldn't be informed and if the
79 * next read is to a floppy then the BIOS will
80 * still think the motor is on and this will
81 * result in a read error.
83 // DiskStopFloppyMotor();
85 ChainLoadBiosBootSectorCode();
96 PARTITION_TABLE_ENTRY PartitionTableEntry
;
98 ULONG PartitionNumber
;
100 /* Find all the message box settings and run them */
101 UiShowMessageBoxesInArgv(Argc
, Argv
);
103 /* Read the boot drive */
104 ArgValue
= GetArgumentValue(Argc
, Argv
, "BootDrive");
107 UiMessageBox("Boot drive not specified for selected OS!");
110 DriveNumber
= DriveMapGetBiosDriveNumber(ArgValue
);
112 /* Read the boot partition */
113 ArgValue
= GetArgumentValue(Argc
, Argv
, "BootPartition");
116 UiMessageBox("Boot partition not specified for selected OS!");
119 PartitionNumber
= atoi(ArgValue
);
121 /* Get the partition table entry */
122 if (!DiskGetPartitionEntry(DriveNumber
, PartitionNumber
, &PartitionTableEntry
))
127 /* Now try to read the partition boot sector. If this fails then abort. */
128 if (!MachDiskReadLogicalSectors(DriveNumber
, PartitionTableEntry
.SectorCountBeforePartition
, 1, (PVOID
)0x7C00))
130 UiMessageBox("Unable to read partition's boot sector.");
134 /* Check for validity */
135 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
137 UiMessageBox("Invalid boot sector magic (0xaa55)");
141 UiUnInitialize("Booting...");
145 * Don't stop the floppy drive motor when we
146 * are just booting a bootsector, or drive, or partition.
147 * If we were to stop the floppy motor then
148 * the BIOS wouldn't be informed and if the
149 * next read is to a floppy then the BIOS will
150 * still think the motor is on and this will
151 * result in a read error.
153 // DiskStopFloppyMotor();
155 FrldrBootDrive
= DriveNumber
;
156 ChainLoadBiosBootSectorCode();
169 /* Find all the message box settings and run them */
170 UiShowMessageBoxesInArgv(Argc
, Argv
);
172 /* Read the boot drive */
173 ArgValue
= GetArgumentValue(Argc
, Argv
, "BootDrive");
176 UiMessageBox("Boot drive not specified for selected OS!");
179 DriveNumber
= DriveMapGetBiosDriveNumber(ArgValue
);
181 /* Now try to read the boot sector (or mbr). If this fails then abort. */
182 if (!MachDiskReadLogicalSectors(DriveNumber
, 0, 1, (PVOID
)0x7C00))
184 UiMessageBox("Unable to read boot sector");
188 /* Check for validity */
189 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
191 UiMessageBox("Invalid boot sector magic (0xaa55)");
195 UiUnInitialize("Booting...");
199 * Don't stop the floppy drive motor when we
200 * are just booting a bootsector, or drive, or partition.
201 * If we were to stop the floppy motor then
202 * the BIOS wouldn't be informed and if the
203 * next read is to a floppy then the BIOS will
204 * still think the motor is on and this will
205 * result in a read error.
207 // DiskStopFloppyMotor();
209 FrldrBootDrive
= DriveNumber
;
210 ChainLoadBiosBootSectorCode();