Reworked the boot sector & boot drive code

You can again use FreeLoader to dual boot between two drives or a boot sector file

svn path=/trunk/; revision=2547
This commit is contained in:
Brian Palmer 2002-01-24 00:59:16 +00:00
parent 5a6adb4f13
commit 148e40a24e
5 changed files with 84 additions and 156 deletions

View file

@ -102,32 +102,49 @@ VOID BootMain(VOID)
for (;;) for (;;)
{ {
// Show the operating system list menu
if (!DisplayMenu(OperatingSystemDisplayNames, OperatingSystemCount, DefaultOperatingSystem, TimeOut, &SelectedOperatingSystem)) if (!DisplayMenu(OperatingSystemDisplayNames, OperatingSystemCount, DefaultOperatingSystem, TimeOut, &SelectedOperatingSystem))
{ {
MessageBox("Press ENTER to reboot.\n"); MessageBox("Press ENTER to reboot.\n");
return; goto reboot;
} }
LoadAndBootReactOS(OperatingSystemSectionNames[SelectedOperatingSystem]); // Try to open the operating system section in the .ini file
if (!OpenSection(OperatingSystemSectionNames[SelectedOperatingSystem], &SectionId))
/*switch (OSList[nOSToBoot].nOSType) {
sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemSectionNames[SelectedOperatingSystem]);
MessageBox(SettingName);
continue;
}
// Try to read the boot type
if (!ReadSectionSettingByName(SectionId, "BootType", SettingValue, 80))
{
sprintf(SettingName, "BootType= line not found in section [%s] in freeldr.ini.\n", OperatingSystemSectionNames[SelectedOperatingSystem]);
MessageBox(SettingName);
continue;
}
if (stricmp(SettingValue, "ReactOS") == 0)
{
LoadAndBootReactOS(OperatingSystemSectionNames[SelectedOperatingSystem]);
}
else if (stricmp(SettingValue, "Linux") == 0)
{ {
case OSTYPE_REACTOS:
LoadAndBootReactOS(OSList[nOSToBoot].name);
break;
case OSTYPE_LINUX:
MessageBox("Cannot boot this OS type yet!"); MessageBox("Cannot boot this OS type yet!");
break; }
case OSTYPE_BOOTSECTOR: else if (stricmp(SettingValue, "BootSector") == 0)
LoadAndBootBootSector(nOSToBoot); {
break; LoadAndBootBootSector(OperatingSystemSectionNames[SelectedOperatingSystem]);
case OSTYPE_PARTITION: }
LoadAndBootPartition(nOSToBoot); else if (stricmp(SettingValue, "Partition") == 0)
break; {
case OSTYPE_DRIVE: LoadAndBootPartition(OperatingSystemSectionNames[SelectedOperatingSystem]);
LoadAndBootDrive(nOSToBoot); }
break; else if (stricmp(SettingValue, "Drive") == 0)
}*/ {
LoadAndBootDrive(OperatingSystemSectionNames[SelectedOperatingSystem]);
}
} }

View file

@ -25,39 +25,43 @@
#include "fs.h" #include "fs.h"
#include "ui.h" #include "ui.h"
#include "parseini.h" #include "parseini.h"
#include "disk.h"
void LoadAndBootBootSector(int nOSToBoot) VOID LoadAndBootBootSector(PUCHAR OperatingSystemName)
{ {
FILE* FilePointer; PFILE FilePointer;
char name[260]; UCHAR SettingName[80];
char value[260]; UCHAR SettingValue[80];
char szFileName[1024]; ULONG SectionId;
int i; UCHAR FileName[260];
ULONG BytesRead; ULONG BytesRead;
// Find all the message box settings and run them // Find all the message box settings and run them
/*for (i=1; i<=GetNumSectionItems(OSList[nOSToBoot].name); i++) ShowMessageBoxesInSection(OperatingSystemName);
// Try to open the operating system section in the .ini file
if (!OpenSection(OperatingSystemName, &SectionId))
{ {
ReadSectionSettingByNumber(OSList[nOSToBoot].name, i, name, value); sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
if (stricmp(name, "MessageBox") == 0) MessageBox(SettingName);
MessageBox(value); return;
if (stricmp(name, "MessageLine") == 0)
MessageLine(value);
} }
if (!ReadSectionSettingByName(OSList[nOSToBoot].name, "BootDrive", value)) if (!ReadSectionSettingByName(SectionId, "BootDrive", SettingValue, 80))
{ {
MessageBox("Boot drive not specified for selected OS!"); MessageBox("Boot drive not specified for selected OS!");
return; return;
} }
BootDrive = atoi(value); BootDrive = atoi(SettingValue);
BootPartition = 0; BootPartition = 0;
if (ReadSectionSettingByName(OSList[nOSToBoot].name, "BootPartition", value)) if (ReadSectionSettingByName(SectionId, "BootPartition", SettingValue, 80))
BootPartition = atoi(value); {
BootPartition = atoi(SettingValue);
}
if (!ReadSectionSettingByName(OSList[nOSToBoot].name, "BootSector", value)) if (!ReadSectionSettingByName(SectionId, "BootSectorFile", FileName, 260))
{ {
MessageBox("Boot sector file not specified for selected OS!"); MessageBox("Boot sector file not specified for selected OS!");
return; return;
@ -69,20 +73,18 @@ void LoadAndBootBootSector(int nOSToBoot)
return; return;
} }
strcpy(szFileName, value); FilePointer = OpenFile(FileName);
FilePointer = OpenFile(szFileName);
if (FilePointer == NULL) if (FilePointer == NULL)
{ {
strcat(value, " not found."); strcat(FileName, " not found.");
MessageBox(value); MessageBox(FileName);
return; return;
} }
// Read boot sector // Read boot sector
if (!ReadFile(FilePointer, 512, &BytesRead, (void*)0x7c00) || (BytesRead != 512)) if (!ReadFile(FilePointer, 512, &BytesRead, (void*)0x7c00) || (BytesRead != 512))
{ {
MessageBox("Disk Read Error"); DiskError("Disk read error.");
return; return;
} }
@ -93,15 +95,13 @@ void LoadAndBootBootSector(int nOSToBoot)
return; return;
} }
RestoreScreen(ScreenBuffer); clrscr();
showcursor(); showcursor();
gotoxy(CursorXPos, CursorYPos);
stop_floppy(); stop_floppy();
JumpToBootCode();*/ JumpToBootCode();
} }
void LoadAndBootPartition(int nOSToBoot) VOID LoadAndBootPartition(PUCHAR OperatingSystemName)
{ {
char name[260]; char name[260];
char value[260]; char value[260];
@ -187,33 +187,34 @@ void LoadAndBootPartition(int nOSToBoot)
JumpToBootCode();*/ JumpToBootCode();*/
} }
void LoadAndBootDrive(int nOSToBoot) VOID LoadAndBootDrive(PUCHAR OperatingSystemName)
{ {
char name[260]; UCHAR SettingName[80];
char value[260]; UCHAR SettingValue[80];
int i; ULONG SectionId;
// Find all the message box settings and run them // Find all the message box settings and run them
/*for (i=1; i<=GetNumSectionItems(OSList[nOSToBoot].name); i++) ShowMessageBoxesInSection(OperatingSystemName);
// Try to open the operating system section in the .ini file
if (!OpenSection(OperatingSystemName, &SectionId))
{ {
ReadSectionSettingByNumber(OSList[nOSToBoot].name, i, name, value); sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
if (stricmp(name, "MessageBox") == 0) MessageBox(SettingName);
MessageBox(value); return;
if (stricmp(name, "MessageLine") == 0)
MessageLine(value);
} }
if (!ReadSectionSettingByName(OSList[nOSToBoot].name, "BootDrive", value)) if (!ReadSectionSettingByName(SectionId, "BootDrive", SettingValue, 80))
{ {
MessageBox("Boot drive not specified for selected OS!"); MessageBox("Boot drive not specified for selected OS!");
return; return;
} }
BootDrive = atoi(value); BootDrive = atoi(SettingValue);
if (!biosdisk(_DISK_READ, BootDrive, 0, 0, 1, 1, (void*)0x7c00)) if (!BiosInt13Read(BootDrive, 0, 0, 1, 1, (PVOID)0x7C00))
{ {
MessageBox("Disk Read Error"); DiskError("Disk read error.");
return; return;
} }
@ -224,10 +225,8 @@ void LoadAndBootDrive(int nOSToBoot)
return; return;
} }
RestoreScreen(ScreenBuffer); clrscr();
showcursor(); showcursor();
gotoxy(CursorXPos, CursorYPos);
stop_floppy(); stop_floppy();
JumpToBootCode();*/ JumpToBootCode();
} }

View file

@ -22,8 +22,8 @@
void JumpToBootCode(void); // Implemented in boot.S void JumpToBootCode(void); // Implemented in boot.S
void LoadAndBootBootSector(int nOSToBoot); VOID LoadAndBootBootSector(PUCHAR OperatingSystemName);
void LoadAndBootPartition(int nOSToBoot); VOID LoadAndBootPartition(PUCHAR OperatingSystemName);
void LoadAndBootDrive(int nOSToBoot); VOID LoadAndBootDrive(PUCHAR OperatingSystemName);
#endif // defined __BOOT_H #endif // defined __BOOT_H

View file

@ -431,90 +431,3 @@ BOOL IsValidSetting(char *setting, char *value)
return FALSE; return FALSE;
} }
/*void SetSetting(char *setting, char *value)
{
char v[260];
if(stricmp(setting, "TitleText") == 0)
strcpy(szTitleBoxTitleText, value);
else if(stricmp(setting, "StatusBarColor") == 0)
cStatusBarBgColor = TextToColor(value);
else if(stricmp(setting, "StatusBarTextColor") == 0)
cStatusBarFgColor = TextToColor(value);
else if(stricmp(setting, "BackdropTextColor") == 0)
cBackdropFgColor = TextToColor(value);
else if(stricmp(setting, "BackdropColor") == 0)
cBackdropBgColor = TextToColor(value);
else if(stricmp(setting, "BackdropFillStyle") == 0)
cBackdropFillStyle = TextToFillStyle(value);
else if(stricmp(setting, "TitleBoxTextColor") == 0)
cTitleBoxFgColor = TextToColor(value);
else if(stricmp(setting, "TitleBoxColor") == 0)
cTitleBoxBgColor = TextToColor(value);
else if(stricmp(setting, "MessageBoxTextColor") == 0)
cMessageBoxFgColor = TextToColor(value);
else if(stricmp(setting, "MessageBoxColor") == 0)
cMessageBoxBgColor = TextToColor(value);
else if(stricmp(setting, "MenuTextColor") == 0)
cMenuFgColor = TextToColor(value);
else if(stricmp(setting, "MenuColor") == 0)
cMenuBgColor = TextToColor(value);
else if(stricmp(setting, "TextColor") == 0)
cTextColor = TextToColor(value);
else if(stricmp(setting, "SelectedTextColor") == 0)
cSelectedTextColor = TextToColor(value);
else if(stricmp(setting, "SelectedColor") == 0)
cSelectedTextBgColor = TextToColor(value);
else if(stricmp(setting, "OS") == 0)
{
if(nNumOS >= 16)
{
printf("Error: you can only boot to at most 16 different operating systems.\n");
printf("Press any key to continue\n");
getch();
return;
}
if(!GetNumSectionItems(value))
{
printf("Error: OS \"%s\" listed.\n", value);
printf("It does not have it's own [section], or it is empty.\n");
printf("Press any key to continue\n");
getch();
return;
}
strcpy(OSList[nNumOS].name, value);
if (!ReadSectionSettingByName(value, "BootType", v))
{
printf("Unknown BootType for OS \"%s\"\n", value);
printf("Press any key to continue\n");
getch();
return;
}
if (stricmp(v, "ReactOS") == 0)
OSList[nNumOS].nOSType = OSTYPE_REACTOS;
else if (stricmp(v, "Linux") == 0)
OSList[nNumOS].nOSType = OSTYPE_LINUX;
else if (stricmp(v, "BootSector") == 0)
OSList[nNumOS].nOSType = OSTYPE_BOOTSECTOR;
else if (stricmp(v, "Partition") == 0)
OSList[nNumOS].nOSType = OSTYPE_PARTITION;
else if (stricmp(v, "Drive") == 0)
OSList[nNumOS].nOSType = OSTYPE_DRIVE;
else
{
printf("Unknown BootType for OS \"%s\"\n", value);
printf("Press any key to continue\n");
getch();
return;
}
nNumOS++;
}
else if(stricmp(setting, "TimeOut") == 0)
nTimeOut = atoi(value);
}*/

View file

@ -36,7 +36,6 @@ ULONG GetNumSectionItems(ULONG SectionId);
BOOL ReadSectionSettingByNumber(ULONG SectionId, ULONG SettingNumber, PUCHAR SettingName, ULONG NameSize, PUCHAR SettingValue, ULONG ValueSize); BOOL ReadSectionSettingByNumber(ULONG SectionId, ULONG SettingNumber, PUCHAR SettingName, ULONG NameSize, PUCHAR SettingValue, ULONG ValueSize);
BOOL ReadSectionSettingByName(ULONG SectionId, PUCHAR SettingName, PUCHAR Buffer, ULONG BufferSize); BOOL ReadSectionSettingByName(ULONG SectionId, PUCHAR SettingName, PUCHAR Buffer, ULONG BufferSize);
BOOL IsValidSetting(char *setting, char *value); BOOL IsValidSetting(char *setting, char *value);
void SetSetting(char *setting, char *value);
#endif // defined __PARSEINI_H #endif // defined __PARSEINI_H