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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 VOID
LoadAndBootBootSector(PUCHAR OperatingSystemName
)
35 UCHAR SettingName
[80];
36 UCHAR SettingValue
[80];
41 // Find all the message box settings and run them
42 UiShowMessageBoxesInSection(OperatingSystemName
);
44 // Try to open the operating system section in the .ini file
45 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
47 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
48 UiMessageBox(SettingName
);
52 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, 80))
54 UiMessageBox("Boot drive not specified for selected OS!");
58 BootDrive
= DriveMapGetBiosDriveNumber(SettingValue
);
61 if (IniReadSettingByName(SectionId
, "BootPartition", SettingValue
, 80))
63 BootPartition
= atoi(SettingValue
);
66 if (!IniReadSettingByName(SectionId
, "BootSectorFile", FileName
, 260))
68 UiMessageBox("Boot sector file not specified for selected OS!");
72 if (!FsOpenVolume(BootDrive
, BootPartition
))
74 UiMessageBox("Failed to open boot drive.");
78 FilePointer
= FsOpenFile(FileName
);
79 if (FilePointer
== NULL
)
81 strcat(FileName
, " not found.");
82 UiMessageBox(FileName
);
87 if (!FsReadFile(FilePointer
, 512, &BytesRead
, (void*)0x7c00) || (BytesRead
!= 512))
93 if (*((U16
*)(0x7c00 + 0x1fe)) != 0xaa55)
95 UiMessageBox("Invalid boot sector magic (0xaa55)");
99 UiUnInitialize("Booting...");
100 // Don't stop the floppy drive motor when we
101 // are just booting a bootsector, or drive, or partition.
102 // If we were to stop the floppy motor then
103 // the BIOS wouldn't be informed and if the
104 // next read is to a floppy then the BIOS will
105 // still think the motor is on and this will
106 // result in a read error.
107 //DiskStopFloppyMotor();
109 ChainLoadBiosBootSectorCode();
112 VOID
LoadAndBootPartition(PUCHAR OperatingSystemName
)
114 UCHAR SettingName
[80];
115 UCHAR SettingValue
[80];
117 PARTITION_TABLE_ENTRY PartitionTableEntry
;
119 // Find all the message box settings and run them
120 UiShowMessageBoxesInSection(OperatingSystemName
);
122 // Try to open the operating system section in the .ini file
123 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
125 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
126 UiMessageBox(SettingName
);
130 // Read the boot drive
131 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, 80))
133 UiMessageBox("Boot drive not specified for selected OS!");
137 BootDrive
= DriveMapGetBiosDriveNumber(SettingValue
);
139 // Read the boot partition
140 if (!IniReadSettingByName(SectionId
, "BootPartition", SettingValue
, 80))
142 UiMessageBox("Boot partition not specified for selected OS!");
146 BootPartition
= atoi(SettingValue
);
148 // Get the partition table entry
149 if (!DiskGetPartitionEntry(BootDrive
, BootPartition
, &PartitionTableEntry
))
154 // Now try to read the partition boot sector
155 // If this fails then abort
156 if (!MachDiskReadLogicalSectors(BootDrive
, PartitionTableEntry
.SectorCountBeforePartition
, 1, (PVOID
)0x7C00))
161 // Check for validity
162 if (*((U16
*)(0x7c00 + 0x1fe)) != 0xaa55)
164 UiMessageBox("Invalid boot sector magic (0xaa55)");
168 UiUnInitialize("Booting...");
169 // Don't stop the floppy drive motor when we
170 // are just booting a bootsector, or drive, or partition.
171 // If we were to stop the floppy motor then
172 // the BIOS wouldn't be informed and if the
173 // next read is to a floppy then the BIOS will
174 // still think the motor is on and this will
175 // result in a read error.
176 //DiskStopFloppyMotor();
178 ChainLoadBiosBootSectorCode();
181 VOID
LoadAndBootDrive(PUCHAR OperatingSystemName
)
183 UCHAR SettingName
[80];
184 UCHAR SettingValue
[80];
187 // Find all the message box settings and run them
188 UiShowMessageBoxesInSection(OperatingSystemName
);
190 // Try to open the operating system section in the .ini file
191 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
193 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
194 UiMessageBox(SettingName
);
198 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, 80))
200 UiMessageBox("Boot drive not specified for selected OS!");
204 BootDrive
= DriveMapGetBiosDriveNumber(SettingValue
);
206 // Now try to read the boot sector (or mbr)
207 // If this fails then abort
208 if (!MachDiskReadLogicalSectors(BootDrive
, 0, 1, (PVOID
)0x7C00))
213 // Check for validity
214 if (*((U16
*)(0x7c00 + 0x1fe)) != 0xaa55)
216 UiMessageBox("Invalid boot sector magic (0xaa55)");
220 UiUnInitialize("Booting...");
221 // Don't stop the floppy drive motor when we
222 // are just booting a bootsector, or drive, or partition.
223 // If we were to stop the floppy motor then
224 // the BIOS wouldn't be informed and if the
225 // next read is to a floppy then the BIOS will
226 // still think the motor is on and this will
227 // result in a read error.
228 //DiskStopFloppyMotor();
230 ChainLoadBiosBootSectorCode();