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.
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 if (!FsOpenSystemVolume(FileName
, FileName
, NULL
))
55 UiMessageBox("Failed to open boot drive.");
59 FilePointer
= FsOpenFile(FileName
);
60 if (FilePointer
== NULL
)
62 strcat(FileName
, " not found.");
63 UiMessageBox(FileName
);
68 if (!FsReadFile(FilePointer
, 512, &BytesRead
, (void*)0x7c00) || (BytesRead
!= 512))
74 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
76 UiMessageBox("Invalid boot sector magic (0xaa55)");
80 UiUnInitialize("Booting...");
81 // Don't stop the floppy drive motor when we
82 // are just booting a bootsector, or drive, or partition.
83 // If we were to stop the floppy motor then
84 // the BIOS wouldn't be informed and if the
85 // next read is to a floppy then the BIOS will
86 // still think the motor is on and this will
87 // result in a read error.
88 //DiskStopFloppyMotor();
90 ChainLoadBiosBootSectorCode();
93 VOID
LoadAndBootPartition(PCSTR OperatingSystemName
)
96 CHAR SettingValue
[80];
98 PARTITION_TABLE_ENTRY PartitionTableEntry
;
100 ULONG PartitionNumber
;
102 // Find all the message box settings and run them
103 UiShowMessageBoxesInSection(OperatingSystemName
);
105 // Try to open the operating system section in the .ini file
106 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
108 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
109 UiMessageBox(SettingName
);
113 // Read the boot drive
114 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, sizeof(SettingValue
)))
116 UiMessageBox("Boot drive not specified for selected OS!");
120 DriveNumber
= DriveMapGetBiosDriveNumber(SettingValue
);
122 // Read the boot partition
123 if (!IniReadSettingByName(SectionId
, "BootPartition", SettingValue
, sizeof(SettingValue
)))
125 UiMessageBox("Boot partition not specified for selected OS!");
129 PartitionNumber
= atoi(SettingValue
);
131 // Get the partition table entry
132 if (!DiskGetPartitionEntry(DriveNumber
, PartitionNumber
, &PartitionTableEntry
))
137 // Now try to read the partition boot sector
138 // If this fails then abort
139 if (!MachDiskReadLogicalSectors(DriveNumber
, PartitionTableEntry
.SectorCountBeforePartition
, 1, (PVOID
)0x7C00))
144 // Check for validity
145 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
147 UiMessageBox("Invalid boot sector magic (0xaa55)");
151 UiUnInitialize("Booting...");
152 // Don't stop the floppy drive motor when we
153 // are just booting a bootsector, or drive, or partition.
154 // If we were to stop the floppy motor then
155 // the BIOS wouldn't be informed and if the
156 // next read is to a floppy then the BIOS will
157 // still think the motor is on and this will
158 // result in a read error.
159 //DiskStopFloppyMotor();
161 ChainLoadBiosBootSectorCode();
164 VOID
LoadAndBootDrive(PCSTR OperatingSystemName
)
166 CHAR SettingName
[80];
167 CHAR SettingValue
[80];
171 // Find all the message box settings and run them
172 UiShowMessageBoxesInSection(OperatingSystemName
);
174 // Try to open the operating system section in the .ini file
175 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
177 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
178 UiMessageBox(SettingName
);
182 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, sizeof(SettingValue
)))
184 UiMessageBox("Boot drive not specified for selected OS!");
188 DriveNumber
= DriveMapGetBiosDriveNumber(SettingValue
);
190 // Now try to read the boot sector (or mbr)
191 // If this fails then abort
192 if (!MachDiskReadLogicalSectors(DriveNumber
, 0, 1, (PVOID
)0x7C00))
197 // Check for validity
198 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
200 UiMessageBox("Invalid boot sector magic (0xaa55)");
204 UiUnInitialize("Booting...");
205 // Don't stop the floppy drive motor when we
206 // are just booting a bootsector, or drive, or partition.
207 // If we were to stop the floppy motor then
208 // the BIOS wouldn't be informed and if the
209 // next read is to a floppy then the BIOS will
210 // still think the motor is on and this will
211 // result in a read error.
212 //DiskStopFloppyMotor();
214 ChainLoadBiosBootSectorCode();