Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmiscboot.c
Go to the documentation of this file.
00001 /* 00002 * FreeLoader 00003 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 00020 #include <freeldr.h> 00021 00022 VOID LoadAndBootBootSector(PCSTR OperatingSystemName) 00023 { 00024 PFILE FilePointer; 00025 CHAR SettingName[80]; 00026 ULONG SectionId; 00027 CHAR FileName[260]; 00028 ULONG BytesRead; 00029 00030 // Find all the message box settings and run them 00031 UiShowMessageBoxesInSection(OperatingSystemName); 00032 00033 // Try to open the operating system section in the .ini file 00034 if (!IniOpenSection(OperatingSystemName, &SectionId)) 00035 { 00036 sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName); 00037 UiMessageBox(SettingName); 00038 return; 00039 } 00040 00041 if (!IniReadSettingByName(SectionId, "BootSectorFile", FileName, sizeof(FileName))) 00042 { 00043 UiMessageBox("Boot sector file not specified for selected OS!"); 00044 return; 00045 } 00046 00047 FilePointer = FsOpenFile(FileName); 00048 if (!FilePointer) 00049 { 00050 strcat(FileName, " not found."); 00051 UiMessageBox(FileName); 00052 return; 00053 } 00054 00055 // Read boot sector 00056 if (!FsReadFile(FilePointer, 512, &BytesRead, (void*)0x7c00) || (BytesRead != 512)) 00057 { 00058 UiMessageBox("Unable to read boot sector."); 00059 return; 00060 } 00061 00062 // Check for validity 00063 if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55) 00064 { 00065 UiMessageBox("Invalid boot sector magic (0xaa55)"); 00066 return; 00067 } 00068 00069 UiUnInitialize("Booting..."); 00070 // Don't stop the floppy drive motor when we 00071 // are just booting a bootsector, or drive, or partition. 00072 // If we were to stop the floppy motor then 00073 // the BIOS wouldn't be informed and if the 00074 // next read is to a floppy then the BIOS will 00075 // still think the motor is on and this will 00076 // result in a read error. 00077 //DiskStopFloppyMotor(); 00078 //DisableA20(); 00079 ChainLoadBiosBootSectorCode(); 00080 } 00081 00082 VOID LoadAndBootPartition(PCSTR OperatingSystemName) 00083 { 00084 CHAR SettingName[80]; 00085 CHAR SettingValue[80]; 00086 ULONG SectionId; 00087 PARTITION_TABLE_ENTRY PartitionTableEntry; 00088 UCHAR DriveNumber; 00089 ULONG PartitionNumber; 00090 00091 // Find all the message box settings and run them 00092 UiShowMessageBoxesInSection(OperatingSystemName); 00093 00094 // Try to open the operating system section in the .ini file 00095 if (!IniOpenSection(OperatingSystemName, &SectionId)) 00096 { 00097 sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName); 00098 UiMessageBox(SettingName); 00099 return; 00100 } 00101 00102 // Read the boot drive 00103 if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, sizeof(SettingValue))) 00104 { 00105 UiMessageBox("Boot drive not specified for selected OS!"); 00106 return; 00107 } 00108 00109 DriveNumber = DriveMapGetBiosDriveNumber(SettingValue); 00110 00111 // Read the boot partition 00112 if (!IniReadSettingByName(SectionId, "BootPartition", SettingValue, sizeof(SettingValue))) 00113 { 00114 UiMessageBox("Boot partition not specified for selected OS!"); 00115 return; 00116 } 00117 00118 PartitionNumber = atoi(SettingValue); 00119 00120 // Get the partition table entry 00121 if (!DiskGetPartitionEntry(DriveNumber, PartitionNumber, &PartitionTableEntry)) 00122 { 00123 return; 00124 } 00125 00126 // Now try to read the partition boot sector 00127 // If this fails then abort 00128 if (!MachDiskReadLogicalSectors(DriveNumber, PartitionTableEntry.SectorCountBeforePartition, 1, (PVOID)0x7C00)) 00129 { 00130 UiMessageBox("Unable to read partition's boot sector."); 00131 return; 00132 } 00133 00134 // Check for validity 00135 if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55) 00136 { 00137 UiMessageBox("Invalid boot sector magic (0xaa55)"); 00138 return; 00139 } 00140 00141 UiUnInitialize("Booting..."); 00142 // Don't stop the floppy drive motor when we 00143 // are just booting a bootsector, or drive, or partition. 00144 // If we were to stop the floppy motor then 00145 // the BIOS wouldn't be informed and if the 00146 // next read is to a floppy then the BIOS will 00147 // still think the motor is on and this will 00148 // result in a read error. 00149 //DiskStopFloppyMotor(); 00150 //DisableA20(); 00151 ChainLoadBiosBootSectorCode(); 00152 } 00153 00154 VOID LoadAndBootDrive(PCSTR OperatingSystemName) 00155 { 00156 CHAR SettingName[80]; 00157 CHAR SettingValue[80]; 00158 ULONG SectionId; 00159 UCHAR DriveNumber; 00160 00161 // Find all the message box settings and run them 00162 UiShowMessageBoxesInSection(OperatingSystemName); 00163 00164 // Try to open the operating system section in the .ini file 00165 if (!IniOpenSection(OperatingSystemName, &SectionId)) 00166 { 00167 sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName); 00168 UiMessageBox(SettingName); 00169 return; 00170 } 00171 00172 if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, sizeof(SettingValue))) 00173 { 00174 UiMessageBox("Boot drive not specified for selected OS!"); 00175 return; 00176 } 00177 00178 DriveNumber = DriveMapGetBiosDriveNumber(SettingValue); 00179 00180 // Now try to read the boot sector (or mbr) 00181 // If this fails then abort 00182 if (!MachDiskReadLogicalSectors(DriveNumber, 0, 1, (PVOID)0x7C00)) 00183 { 00184 UiMessageBox("Unable to read boot sector"); 00185 return; 00186 } 00187 00188 // Check for validity 00189 if (*((USHORT*)(0x7c00 + 0x1fe)) != 0xaa55) 00190 { 00191 UiMessageBox("Invalid boot sector magic (0xaa55)"); 00192 return; 00193 } 00194 00195 UiUnInitialize("Booting..."); 00196 // Don't stop the floppy drive motor when we 00197 // are just booting a bootsector, or drive, or partition. 00198 // If we were to stop the floppy motor then 00199 // the BIOS wouldn't be informed and if the 00200 // next read is to a floppy then the BIOS will 00201 // still think the motor is on and this will 00202 // result in a read error. 00203 //DiskStopFloppyMotor(); 00204 //DisableA20(); 00205 ChainLoadBiosBootSectorCode(); 00206 } Generated on Sun May 27 2012 04:19:08 for ReactOS by
1.7.6.1
|