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 FilePointer
= FsOpenFile(FileName
);
50 strcat(FileName
, " not found.");
51 UiMessageBox(FileName
);
56 if (!FsReadFile(FilePointer
, 512, &BytesRead
, (void*)0x7c00) || (BytesRead
!= 512))
58 UiMessageBox("Unable to read boot sector.");
63 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
65 UiMessageBox("Invalid boot sector magic (0xaa55)");
69 UiUnInitialize("Booting...");
70 // Don't stop the floppy drive motor when we
71 // are just booting a bootsector, or drive, or partition.
72 // If we were to stop the floppy motor then
73 // the BIOS wouldn't be informed and if the
74 // next read is to a floppy then the BIOS will
75 // still think the motor is on and this will
76 // result in a read error.
77 //DiskStopFloppyMotor();
79 ChainLoadBiosBootSectorCode();
82 VOID
LoadAndBootPartition(PCSTR OperatingSystemName
)
85 CHAR SettingValue
[80];
87 PARTITION_TABLE_ENTRY PartitionTableEntry
;
89 ULONG PartitionNumber
;
91 // Find all the message box settings and run them
92 UiShowMessageBoxesInSection(OperatingSystemName
);
94 // Try to open the operating system section in the .ini file
95 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
97 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
98 UiMessageBox(SettingName
);
102 // Read the boot drive
103 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, sizeof(SettingValue
)))
105 UiMessageBox("Boot drive not specified for selected OS!");
109 DriveNumber
= DriveMapGetBiosDriveNumber(SettingValue
);
111 // Read the boot partition
112 if (!IniReadSettingByName(SectionId
, "BootPartition", SettingValue
, sizeof(SettingValue
)))
114 UiMessageBox("Boot partition not specified for selected OS!");
118 PartitionNumber
= atoi(SettingValue
);
120 // Get the partition table entry
121 if (!DiskGetPartitionEntry(DriveNumber
, PartitionNumber
, &PartitionTableEntry
))
126 // Now try to read the partition boot sector
127 // 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...");
142 // Don't stop the floppy drive motor when we
143 // are just booting a bootsector, or drive, or partition.
144 // If we were to stop the floppy motor then
145 // the BIOS wouldn't be informed and if the
146 // next read is to a floppy then the BIOS will
147 // still think the motor is on and this will
148 // result in a read error.
149 //DiskStopFloppyMotor();
151 ChainLoadBiosBootSectorCode();
154 VOID
LoadAndBootDrive(PCSTR OperatingSystemName
)
156 CHAR SettingName
[80];
157 CHAR SettingValue
[80];
161 // Find all the message box settings and run them
162 UiShowMessageBoxesInSection(OperatingSystemName
);
164 // Try to open the operating system section in the .ini file
165 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
167 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
168 UiMessageBox(SettingName
);
172 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, sizeof(SettingValue
)))
174 UiMessageBox("Boot drive not specified for selected OS!");
178 DriveNumber
= DriveMapGetBiosDriveNumber(SettingValue
);
180 // Now try to read the boot sector (or mbr)
181 // 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...");
196 // Don't stop the floppy drive motor when we
197 // are just booting a bootsector, or drive, or partition.
198 // If we were to stop the floppy motor then
199 // the BIOS wouldn't be informed and if the
200 // next read is to a floppy then the BIOS will
201 // still think the motor is on and this will
202 // result in a read error.
203 //DiskStopFloppyMotor();
205 ChainLoadBiosBootSectorCode();