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.
30 VOID
LoadAndBootBootSector(PUCHAR OperatingSystemName
)
33 UCHAR SettingName
[80];
34 UCHAR SettingValue
[80];
39 // Find all the message box settings and run them
40 ShowMessageBoxesInSection(OperatingSystemName
);
42 // Try to open the operating system section in the .ini file
43 if (!OpenSection(OperatingSystemName
, &SectionId
))
45 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
46 MessageBox(SettingName
);
50 if (!ReadSectionSettingByName(SectionId
, "BootDrive", SettingValue
, 80))
52 MessageBox("Boot drive not specified for selected OS!");
56 BootDrive
= atoi(SettingValue
);
59 if (ReadSectionSettingByName(SectionId
, "BootPartition", SettingValue
, 80))
61 BootPartition
= atoi(SettingValue
);
64 if (!ReadSectionSettingByName(SectionId
, "BootSectorFile", FileName
, 260))
66 MessageBox("Boot sector file not specified for selected OS!");
70 if (!OpenDiskDrive(BootDrive
, BootPartition
))
72 MessageBox("Failed to open boot drive.");
76 FilePointer
= OpenFile(FileName
);
77 if (FilePointer
== NULL
)
79 strcat(FileName
, " not found.");
85 if (!ReadFile(FilePointer
, 512, &BytesRead
, (void*)0x7c00) || (BytesRead
!= 512))
87 DiskError("Disk read error.");
92 if (*((WORD
*)(0x7c00 + 0x1fe)) != 0xaa55)
94 MessageBox("Invalid boot sector magic (0xaa55)");
104 VOID
LoadAndBootPartition(PUCHAR OperatingSystemName
)
108 int head
, sector
, cylinder
;
112 // Find all the message box settings and run them
113 /*for (i=1; i<=GetNumSectionItems(OSList[nOSToBoot].name); i++)
115 ReadSectionSettingByNumber(OSList[nOSToBoot].name, i, name, value);
116 if (stricmp(name, "MessageBox") == 0)
118 if (stricmp(name, "MessageLine") == 0)
122 if (!ReadSectionSettingByName(OSList[nOSToBoot].name, "BootDrive", value))
124 MessageBox("Boot drive not specified for selected OS!");
128 BootDrive = atoi(value);
130 if (!ReadSectionSettingByName(OSList[nOSToBoot].name, "BootPartition", value))
132 MessageBox("Boot partition not specified for selected OS!");
136 BootPartition = atoi(value);
138 if (!BiosInt13Read(BootDrive, 0, 0, 1, 1, DISKREADBUFFER))
140 MessageBox("Disk Read Error");
144 // Check for validity
145 if (*((WORD*)(DISKREADBUFFER + 0x1fe)) != 0xaa55)
147 MessageBox("Invalid partition table magic (0xaa55)");
151 offset = 0x1BE + ((BootPartition-1) * 0x10);
153 // Check for valid partition
154 if (SectorBuffer[offset + 4] == 0)
156 MessageBox("Invalid boot partition");
160 head = SectorBuffer[offset + 1];
161 sector = (SectorBuffer[offset + 2] & 0x3F);
162 cylinder = SectorBuffer[offset + 3];
163 if (SectorBuffer[offset + 2] & 0x80)
165 if (SectorBuffer[offset + 2] & 0x40)
168 // Read partition boot sector
169 if (!biosdisk(_DISK_READ, BootDrive, head, cylinder, sector, 1, (void*)0x7c00))
171 MessageBox("Disk Read Error");
175 // Check for validity
176 if (*((WORD*)(0x7c00 + 0x1fe)) != 0xaa55)
178 MessageBox("Invalid boot sector magic (0xaa55)");
182 RestoreScreen(ScreenBuffer);
184 gotoxy(CursorXPos, CursorYPos);
190 VOID
LoadAndBootDrive(PUCHAR OperatingSystemName
)
192 UCHAR SettingName
[80];
193 UCHAR SettingValue
[80];
196 // Find all the message box settings and run them
197 ShowMessageBoxesInSection(OperatingSystemName
);
199 // Try to open the operating system section in the .ini file
200 if (!OpenSection(OperatingSystemName
, &SectionId
))
202 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName
);
203 MessageBox(SettingName
);
207 if (!ReadSectionSettingByName(SectionId
, "BootDrive", SettingValue
, 80))
209 MessageBox("Boot drive not specified for selected OS!");
213 BootDrive
= atoi(SettingValue
);
215 if (!BiosInt13Read(BootDrive
, 0, 0, 1, 1, (PVOID
)0x7C00))
217 DiskError("Disk read error.");
221 // Check for validity
222 if (*((WORD
*)(0x7c00 + 0x1fe)) != 0xaa55)
224 MessageBox("Invalid boot sector magic (0xaa55)");