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 VOID
LoadAndBootBootSector(PCSTR OperatingSystemName
)
30 // Find all the message box settings and run them
31 UiShowMessageBoxesInSection(OperatingSystemName
);
33 // Try to open the operating system section in the .ini file
34 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
36 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
37 UiMessageBox(SettingName
);
41 if (!IniReadSettingByName(SectionId
, "BootSectorFile", FileName
, sizeof(FileName
)))
43 UiMessageBox("Boot sector file not specified for selected OS!");
47 if (!MachDiskNormalizeSystemPath(FileName
, sizeof(FileName
)))
49 UiMessageBox("Invalid path to boot sector file");
53 FilePointer
= FsOpenFile(FileName
);
56 strcat(FileName
, " not found.");
57 UiMessageBox(FileName
);
62 if (!FsReadFile(FilePointer
, 512, &BytesRead
, (void*)0x7c00) || (BytesRead
!= 512))
64 UiMessageBox("Unable to read boot sector.");
69 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
71 UiMessageBox("Invalid boot sector magic (0xaa55)");
75 UiUnInitialize("Booting...");
76 // Don't stop the floppy drive motor when we
77 // are just booting a bootsector, or drive, or partition.
78 // If we were to stop the floppy motor then
79 // the BIOS wouldn't be informed and if the
80 // next read is to a floppy then the BIOS will
81 // still think the motor is on and this will
82 // result in a read error.
83 //DiskStopFloppyMotor();
85 ChainLoadBiosBootSectorCode();
88 VOID
LoadAndBootPartition(PCSTR OperatingSystemName
)
91 CHAR SettingValue
[80];
93 PARTITION_TABLE_ENTRY PartitionTableEntry
;
95 ULONG PartitionNumber
;
97 // Find all the message box settings and run them
98 UiShowMessageBoxesInSection(OperatingSystemName
);
100 // Try to open the operating system section in the .ini file
101 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
103 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
104 UiMessageBox(SettingName
);
108 // Read the boot drive
109 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, sizeof(SettingValue
)))
111 UiMessageBox("Boot drive not specified for selected OS!");
115 DriveNumber
= DriveMapGetBiosDriveNumber(SettingValue
);
117 // Read the boot partition
118 if (!IniReadSettingByName(SectionId
, "BootPartition", SettingValue
, sizeof(SettingValue
)))
120 UiMessageBox("Boot partition not specified for selected OS!");
124 PartitionNumber
= atoi(SettingValue
);
126 // Get the partition table entry
127 if (!DiskGetPartitionEntry(DriveNumber
, PartitionNumber
, &PartitionTableEntry
))
132 // Now try to read the partition boot sector
133 // If this fails then abort
134 if (!MachDiskReadLogicalSectors(DriveNumber
, PartitionTableEntry
.SectorCountBeforePartition
, 1, (PVOID
)0x7C00))
136 UiMessageBox("Unable to read partition's boot sector.");
140 // Check for validity
141 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
143 UiMessageBox("Invalid boot sector magic (0xaa55)");
147 UiUnInitialize("Booting...");
148 // Don't stop the floppy drive motor when we
149 // are just booting a bootsector, or drive, or partition.
150 // If we were to stop the floppy motor then
151 // the BIOS wouldn't be informed and if the
152 // next read is to a floppy then the BIOS will
153 // still think the motor is on and this will
154 // result in a read error.
155 //DiskStopFloppyMotor();
157 ChainLoadBiosBootSectorCode();
160 VOID
LoadAndBootDrive(PCSTR OperatingSystemName
)
162 CHAR SettingName
[80];
163 CHAR SettingValue
[80];
167 // Find all the message box settings and run them
168 UiShowMessageBoxesInSection(OperatingSystemName
);
170 // Try to open the operating system section in the .ini file
171 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
173 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
174 UiMessageBox(SettingName
);
178 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, sizeof(SettingValue
)))
180 UiMessageBox("Boot drive not specified for selected OS!");
184 DriveNumber
= DriveMapGetBiosDriveNumber(SettingValue
);
186 // Now try to read the boot sector (or mbr)
187 // If this fails then abort
188 if (!MachDiskReadLogicalSectors(DriveNumber
, 0, 1, (PVOID
)0x7C00))
190 UiMessageBox("Unable to read boot sector");
194 // Check for validity
195 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
197 UiMessageBox("Invalid boot sector magic (0xaa55)");
201 UiUnInitialize("Booting...");
202 // Don't stop the floppy drive motor when we
203 // are just booting a bootsector, or drive, or partition.
204 // If we were to stop the floppy motor then
205 // the BIOS wouldn't be informed and if the
206 // next read is to a floppy then the BIOS will
207 // still think the motor is on and this will
208 // result in a read error.
209 //DiskStopFloppyMotor();
211 ChainLoadBiosBootSectorCode();