3 * Copyright (C) 1998-2002 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.
31 VOID
LoadAndBootBootSector(PUCHAR OperatingSystemName
)
34 UCHAR SettingName
[80];
35 UCHAR SettingValue
[80];
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
, "BootDrive", SettingValue
, 80))
53 UiMessageBox("Boot drive not specified for selected OS!");
57 BootDrive
= atoi(SettingValue
);
60 if (IniReadSettingByName(SectionId
, "BootPartition", SettingValue
, 80))
62 BootPartition
= atoi(SettingValue
);
65 if (!IniReadSettingByName(SectionId
, "BootSectorFile", FileName
, 260))
67 UiMessageBox("Boot sector file not specified for selected OS!");
71 if (!OpenDiskDrive(BootDrive
, BootPartition
))
73 UiMessageBox("Failed to open boot drive.");
77 FilePointer
= OpenFile(FileName
);
78 if (FilePointer
== NULL
)
80 strcat(FileName
, " not found.");
81 UiMessageBox(FileName
);
86 if (!ReadFile(FilePointer
, 512, &BytesRead
, (void*)0x7c00) || (BytesRead
!= 512))
92 if (*((U16
*)(0x7c00 + 0x1fe)) != 0xaa55)
94 UiMessageBox("Invalid boot sector magic (0xaa55)");
99 VideoShowTextCursor();
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.
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
= atoi(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 (!DiskReadLogicalSectors(BootDrive
, PartitionTableEntry
.SectorCountBeforePartition
, 1, (PVOID
)0x7C00))
161 // Check for validity
162 if (*((U16
*)(0x7c00 + 0x1fe)) != 0xaa55)
164 UiMessageBox("Invalid boot sector magic (0xaa55)");
169 VideoShowTextCursor();
170 // Don't stop the floppy drive motor when we
171 // are just booting a bootsector, or drive, or partition.
172 // If we were to stop the floppy motor then
173 // the BIOS wouldn't be informed and if the
174 // next read is to a floppy then the BIOS will
175 // still think the motor is on and this will
176 // result in a read error.
179 ChainLoadBiosBootSectorCode();
182 VOID
LoadAndBootDrive(PUCHAR OperatingSystemName
)
184 UCHAR SettingName
[80];
185 UCHAR SettingValue
[80];
188 // Find all the message box settings and run them
189 UiShowMessageBoxesInSection(OperatingSystemName
);
191 // Try to open the operating system section in the .ini file
192 if (!IniOpenSection(OperatingSystemName
, &SectionId
))
194 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
195 UiMessageBox(SettingName
);
199 if (!IniReadSettingByName(SectionId
, "BootDrive", SettingValue
, 80))
201 UiMessageBox("Boot drive not specified for selected OS!");
205 BootDrive
= atoi(SettingValue
);
207 // Now try to read the boot sector (or mbr)
208 // If this fails then abort
209 if (!DiskReadLogicalSectors(BootDrive
, 0, 1, (PVOID
)0x7C00))
214 // Check for validity
215 if (*((U16
*)(0x7c00 + 0x1fe)) != 0xaa55)
217 UiMessageBox("Invalid boot sector magic (0xaa55)");
222 VideoShowTextCursor();
223 // Don't stop the floppy drive motor when we
224 // are just booting a bootsector, or drive, or partition.
225 // If we were to stop the floppy motor then
226 // the BIOS wouldn't be informed and if the
227 // next read is to a floppy then the BIOS will
228 // still think the motor is on and this will
229 // result in a read error.
232 ChainLoadBiosBootSectorCode();