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(IN OperatingSystemItem
* OperatingSystem
,
30 IN USHORT OperatingSystemVersion
)
33 PCSTR SectionName
= OperatingSystem
->SystemPartition
;
38 /* Find all the message box settings and run them */
39 UiShowMessageBoxesInSection(SectionName
);
41 /* Try to open the operating system section in the .ini file */
42 if (!IniOpenSection(SectionName
, &SectionId
))
44 UiMessageBox("Section [%s] not found in freeldr.ini.", SectionName
);
48 if (!IniReadSettingByName(SectionId
, "BootSectorFile", FileName
, sizeof(FileName
)))
50 UiMessageBox("Boot sector file not specified for selected OS!");
54 FilePointer
= FsOpenFile(FileName
);
57 UiMessageBox("%s not found.", FileName
);
61 /* Read boot sector */
62 if (!FsReadFile(FilePointer
, 512, &BytesRead
, (void*)0x7c00) || (BytesRead
!= 512))
64 UiMessageBox("Unable to read boot sector.");
68 /* Check for validity */
69 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
71 UiMessageBox("Invalid boot sector magic (0xaa55)");
75 UiUnInitialize("Booting...");
78 * Don't stop the floppy drive motor when we
79 * are just booting a bootsector, or drive, or partition.
80 * If we were to stop the floppy motor then
81 * the BIOS wouldn't be informed and if the
82 * next read is to a floppy then the BIOS will
83 * still think the motor is on and this will
84 * result in a read error.
86 // DiskStopFloppyMotor();
88 ChainLoadBiosBootSectorCode();
92 LoadAndBootPartition(IN OperatingSystemItem
* OperatingSystem
,
93 IN USHORT OperatingSystemVersion
)
96 PCSTR SectionName
= OperatingSystem
->SystemPartition
;
97 CHAR SettingValue
[80];
98 PARTITION_TABLE_ENTRY PartitionTableEntry
;
100 ULONG PartitionNumber
;
102 /* Find all the message box settings and run them */
103 UiShowMessageBoxesInSection(SectionName
);
105 /* Try to open the operating system section in the .ini file */
106 if (!IniOpenSection(SectionName
, &SectionId
))
108 UiMessageBox("Section [%s] not found in freeldr.ini.", SectionName
);
112 /* Read the boot drive */
113 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, sizeof(SettingValue
)))
115 UiMessageBox("Boot drive not specified for selected OS!");
119 DriveNumber
= DriveMapGetBiosDriveNumber(SettingValue
);
121 /* Read the boot partition */
122 if (!IniReadSettingByName(SectionId
, "BootPartition", SettingValue
, sizeof(SettingValue
)))
124 UiMessageBox("Boot partition not specified for selected OS!");
128 PartitionNumber
= atoi(SettingValue
);
130 /* Get the partition table entry */
131 if (!DiskGetPartitionEntry(DriveNumber
, PartitionNumber
, &PartitionTableEntry
))
136 /* Now try to read the partition boot sector. If this fails then abort. */
137 if (!MachDiskReadLogicalSectors(DriveNumber
, PartitionTableEntry
.SectorCountBeforePartition
, 1, (PVOID
)0x7C00))
139 UiMessageBox("Unable to read partition's boot sector.");
143 /* Check for validity */
144 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
146 UiMessageBox("Invalid boot sector magic (0xaa55)");
150 UiUnInitialize("Booting...");
153 * Don't stop the floppy drive motor when we
154 * are just booting a bootsector, or drive, or partition.
155 * If we were to stop the floppy motor then
156 * the BIOS wouldn't be informed and if the
157 * next read is to a floppy then the BIOS will
158 * still think the motor is on and this will
159 * result in a read error.
161 // DiskStopFloppyMotor();
163 FrldrBootDrive
= DriveNumber
;
164 ChainLoadBiosBootSectorCode();
168 LoadAndBootDrive(IN OperatingSystemItem
* OperatingSystem
,
169 IN USHORT OperatingSystemVersion
)
172 PCSTR SectionName
= OperatingSystem
->SystemPartition
;
173 CHAR SettingValue
[80];
176 /* Find all the message box settings and run them */
177 UiShowMessageBoxesInSection(SectionName
);
179 /* Try to open the operating system section in the .ini file */
180 if (!IniOpenSection(SectionName
, &SectionId
))
182 UiMessageBox("Section [%s] not found in freeldr.ini.", SectionName
);
186 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, sizeof(SettingValue
)))
188 UiMessageBox("Boot drive not specified for selected OS!");
192 DriveNumber
= DriveMapGetBiosDriveNumber(SettingValue
);
194 /* Now try to read the boot sector (or mbr). If this fails then abort. */
195 if (!MachDiskReadLogicalSectors(DriveNumber
, 0, 1, (PVOID
)0x7C00))
197 UiMessageBox("Unable to read boot sector");
201 /* Check for validity */
202 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
204 UiMessageBox("Invalid boot sector magic (0xaa55)");
208 UiUnInitialize("Booting...");
211 * Don't stop the floppy drive motor when we
212 * are just booting a bootsector, or drive, or partition.
213 * If we were to stop the floppy motor then
214 * the BIOS wouldn't be informed and if the
215 * next read is to a floppy then the BIOS will
216 * still think the motor is on and this will
217 * result in a read error.
219 // DiskStopFloppyMotor();
221 FrldrBootDrive
= DriveNumber
;
222 ChainLoadBiosBootSectorCode();