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(PCHAR OperatingSystemName
)
40 // Find all the message box settings and run them
41 UiShowMessageBoxesInSection(OperatingSystemName
);
43 // Try to open the operating system section in the .ini file
44 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
46 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
47 UiMessageBox(SettingName
);
51 if (!IniReadSettingByName(SectionId
, "BootSectorFile", FileName
, 260))
53 UiMessageBox("Boot sector file not specified for selected OS!");
57 if (!FsOpenSystemVolume(FileName
, FileName
, NULL
))
59 UiMessageBox("Failed to open boot drive.");
63 FilePointer
= FsOpenFile(FileName
);
64 if (FilePointer
== NULL
)
66 strcat(FileName
, " not found.");
67 UiMessageBox(FileName
);
72 if (!FsReadFile(FilePointer
, 512, &BytesRead
, (void*)0x7c00) || (BytesRead
!= 512))
78 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
80 UiMessageBox("Invalid boot sector magic (0xaa55)");
84 UiUnInitialize("Booting...");
85 // Don't stop the floppy drive motor when we
86 // are just booting a bootsector, or drive, or partition.
87 // If we were to stop the floppy motor then
88 // the BIOS wouldn't be informed and if the
89 // next read is to a floppy then the BIOS will
90 // still think the motor is on and this will
91 // result in a read error.
92 //DiskStopFloppyMotor();
94 ChainLoadBiosBootSectorCode();
97 VOID
LoadAndBootPartition(PCHAR OperatingSystemName
)
100 CHAR SettingValue
[80];
102 PARTITION_TABLE_ENTRY PartitionTableEntry
;
104 ULONG PartitionNumber
;
106 // Find all the message box settings and run them
107 UiShowMessageBoxesInSection(OperatingSystemName
);
109 // Try to open the operating system section in the .ini file
110 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
112 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
113 UiMessageBox(SettingName
);
117 // Read the boot drive
118 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, 80))
120 UiMessageBox("Boot drive not specified for selected OS!");
124 DriveNumber
= DriveMapGetBiosDriveNumber(SettingValue
);
126 // Read the boot partition
127 if (!IniReadSettingByName(SectionId
, "BootPartition", SettingValue
, 80))
129 UiMessageBox("Boot partition not specified for selected OS!");
133 PartitionNumber
= atoi(SettingValue
);
135 // Get the partition table entry
136 if (!DiskGetPartitionEntry(DriveNumber
, PartitionNumber
, &PartitionTableEntry
))
141 // Now try to read the partition boot sector
142 // If this fails then abort
143 if (!MachDiskReadLogicalSectors(DriveNumber
, PartitionTableEntry
.SectorCountBeforePartition
, 1, (PVOID
)0x7C00))
148 // Check for validity
149 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
151 UiMessageBox("Invalid boot sector magic (0xaa55)");
155 UiUnInitialize("Booting...");
156 // Don't stop the floppy drive motor when we
157 // are just booting a bootsector, or drive, or partition.
158 // If we were to stop the floppy motor then
159 // the BIOS wouldn't be informed and if the
160 // next read is to a floppy then the BIOS will
161 // still think the motor is on and this will
162 // result in a read error.
163 //DiskStopFloppyMotor();
165 ChainLoadBiosBootSectorCode();
168 VOID
LoadAndBootDrive(PCHAR OperatingSystemName
)
170 CHAR SettingName
[80];
171 CHAR SettingValue
[80];
175 // Find all the message box settings and run them
176 UiShowMessageBoxesInSection(OperatingSystemName
);
178 // Try to open the operating system section in the .ini file
179 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
181 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
182 UiMessageBox(SettingName
);
186 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, 80))
188 UiMessageBox("Boot drive not specified for selected OS!");
192 DriveNumber
= DriveMapGetBiosDriveNumber(SettingValue
);
194 // Now try to read the boot sector (or mbr)
195 // If this fails then abort
196 if (!MachDiskReadLogicalSectors(DriveNumber
, 0, 1, (PVOID
)0x7C00))
201 // Check for validity
202 if (*((USHORT
*)(0x7c00 + 0x1fe)) != 0xaa55)
204 UiMessageBox("Invalid boot sector magic (0xaa55)");
208 UiUnInitialize("Booting...");
209 // Don't stop the floppy drive motor when we
210 // are just booting a bootsector, or drive, or partition.
211 // If we were to stop the floppy motor then
212 // the BIOS wouldn't be informed and if the
213 // next read is to a floppy then the BIOS will
214 // still think the motor is on and this will
215 // result in a read error.
216 //DiskStopFloppyMotor();
218 ChainLoadBiosBootSectorCode();