/* Set the function ID */
mov bx, FNID_Reboot
- /* Switch to real mode (We don't return) */
+ /* Switch to real mode (we don't return) */
jmp SwitchToReal
+/*
+ * VOID __cdecl ChainLoadBiosBootSectorCode(
+ * IN UCHAR BootDrive OPTIONAL,
+ * IN ULONG BootPartition OPTIONAL);
+ *
+ * RETURNS: Nothing
+ */
+PUBLIC ChainLoadBiosBootSectorCode
+ChainLoadBiosBootSectorCode:
+ /* Set the boot drive */
+ mov dl, [esp + 4]
+ test dl, dl
+ jnz set_part
+ mov dl, byte ptr [FrldrBootDrive]
+
+ /* Set the boot partition */
+set_part:
+ mov eax, [esp + 8]
+ test eax, eax
+ jnz continue
+ mov eax, dword ptr [FrldrBootPartition]
+continue:
+ /* Store the 1-byte truncated partition number in DH */
+ mov dh, al
+
+ /* Set the function ID */
+ mov bx, FNID_ChainLoadBiosBootSectorCode
+
+ /* Switch to real mode (we don't return) */
+ jmp SwitchToReal
+
+
+PUBLIC PxeCallApi
+PxeCallApi:
+ xor eax, eax
+ ret
+
+
/* Internal function for realmode calls
* bx must be set to the ID of the realmode function to call. */
PUBLIC CallRealMode
/////////////////////////////////////////
- /* 64-bit stack pointer */
-stack64:
- .quad STACKADDR
-
-PUBLIC FrldrBootDrive
-FrldrBootDrive:
- .byte 0
-
-PUBLIC FrldrBootPartition
-FrldrBootPartition:
- .long 0
-
-PUBLIC PxeCallApi
-PxeCallApi:
- xor eax, eax
- ret
-
//void __lgdt(void *Source);
PUBLIC __lgdt
__lgdt:
ret
+ /* 64-bit stack pointer */
+stack64:
+ .quad STACKADDR
+
+PUBLIC FrldrBootDrive
+FrldrBootDrive:
+ .byte 0
+
+PUBLIC FrldrBootPartition
+FrldrBootPartition:
+ .long 0
+
END
return;
}
-BOOLEAN
-ArmDiskGetBootPath(OUT PCHAR BootPath, IN ULONG Size)
-{
- PCCH Path = "ramdisk(0)";
-
- /* Make sure enough space exists */
- if (Size < sizeof(Path)) return FALSE;
-
- /* On ARM platforms, the loader is always in RAM */
- strcpy(BootPath, Path);
- return TRUE;
-}
-
PCONFIGURATION_COMPONENT_DATA
ArmHwDetect(VOID)
{
ArmInitializeBootDevices(VOID)
{
/* Emulate old behavior */
- return (ArmHwDetect() != NULL);
+ if (ArmHwDetect() == NULL)
+ return FALSE;
+
+ /* On ARM platforms, the loader is always in RAM */
+ strcpy(FrldrBootPath, "ramdisk(0)");
+ return TRUE;
}
FREELDR_MEMORY_DESCRIPTOR ArmMemoryMap[32];
MachVtbl.GetMemoryMap = ArmMemGetMemoryMap;
MachVtbl.InitializeBootDevices = ArmInitializeBootDevices;
MachVtbl.HwDetect = ArmHwDetect;
- MachVtbl.DiskGetBootPath = ArmDiskGetBootPath;
MachVtbl.HwIdle = ArmHwIdle;
}
ContinueAddress:
.long _FrldrStartup
-
_FrldrStartup:
/* Store BootDrive and BootPartition */
nop
+PUBLIC _Reboot
+_Reboot:
+ /* Set the function ID */
+ mov bx, FNID_Reboot
+
+ /* Switch to real mode (we don't return) */
+ jmp SwitchToReal
+
+
+/*
+ * VOID __cdecl ChainLoadBiosBootSectorCode(
+ * IN UCHAR BootDrive OPTIONAL,
+ * IN ULONG BootPartition OPTIONAL);
+ *
+ * RETURNS: Nothing
+ */
+PUBLIC _ChainLoadBiosBootSectorCode
+_ChainLoadBiosBootSectorCode:
+ /* Set the boot drive */
+ mov dl, [esp + 4]
+ test dl, dl
+ jnz set_part
+ mov dl, byte ptr ds:[_FrldrBootDrive]
+
+ /* Set the boot partition */
+set_part:
+ mov eax, [esp + 8]
+ test eax, eax
+ jnz continue
+ mov eax, dword ptr ds:[_FrldrBootPartition]
+continue:
+ /* Store the 1-byte truncated partition number in DH */
+ mov dh, al
+
+ /* Set the function ID */
+ mov bx, FNID_ChainLoadBiosBootSectorCode
+
+ /* Switch to real mode (we don't return) */
+ jmp SwitchToReal
+
+
/*
* U16 PxeCallApi(U16 Segment, U16 Offset, U16 Service, VOID *Parameter);
*
ret
-PUBLIC _Reboot
-_Reboot:
- /* Set the function ID */
- mov bx, FNID_Reboot
-
- /* Switch to real mode (we don't return) */
- jmp SwitchToReal
-
-
-PUBLIC _ChainLoadBiosBootSectorCode
-_ChainLoadBiosBootSectorCode:
- /* Set the boot drive */
- mov dl, byte ptr ds:[_FrldrBootDrive]
-
- /* Set the function ID */
- mov bx, FNID_ChainLoadBiosBootSectorCode
-
- /* Switch to real mode (we don't return) */
- jmp SwitchToReal
-
-
PUBLIC i386CallRealMode
i386CallRealMode:
/* Set continue address and switch to real mode */
DiskClose(ULONG FileId)
{
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
-
FrLdrTempFree(Context, TAG_HW_DISK_CONTEXT);
return ESUCCESS;
}
return DiskCount;
}
+static BOOLEAN
+DiskIsDriveRemovable(UCHAR DriveNumber)
+{
+ /*
+ * Hard disks use drive numbers >= 0x80 . So if the drive number
+ * indicates a hard disk then return FALSE.
+ * 0x49 is our magic ramdisk drive, so return FALSE for that too.
+ */
+ if ((DriveNumber >= 0x80) || (DriveNumber == 0x49))
+ return FALSE;
+
+ /* The drive is a floppy diskette so return TRUE */
+ return TRUE;
+}
+
+static BOOLEAN
+DiskGetBootPath(BOOLEAN IsPxe)
+{
+ if (*FrldrBootPath)
+ return TRUE;
+
+ // FIXME! FIXME! Do this in some drive recognition procedure!!!!
+ if (IsPxe)
+ {
+ RtlStringCbCopyA(FrldrBootPath, sizeof(FrldrBootPath), "net(0)");
+ }
+ else
+ /* 0x49 is our magic ramdisk drive, so try to detect it first */
+ if (FrldrBootDrive == 0x49)
+ {
+ /* This is the ramdisk. See ArmInitializeBootDevices() too... */
+ // RtlStringCbPrintfA(FrldrBootPath, sizeof(FrldrBootPath), "ramdisk(%u)", 0);
+ RtlStringCbCopyA(FrldrBootPath, sizeof(FrldrBootPath), "ramdisk(0)");
+ }
+ else if (FrldrBootDrive < 0x80)
+ {
+ /* This is a floppy */
+ RtlStringCbPrintfA(FrldrBootPath, sizeof(FrldrBootPath),
+ "multi(0)disk(0)fdisk(%u)", FrldrBootDrive);
+ }
+ else if (FrldrBootPartition == 0xFF)
+ {
+ /* Boot Partition 0xFF is the magic value that indicates booting from CD-ROM (see isoboot.S) */
+ RtlStringCbPrintfA(FrldrBootPath, sizeof(FrldrBootPath),
+ "multi(0)disk(0)cdrom(%u)", FrldrBootDrive - 0x80);
+ }
+ else
+ {
+ ULONG BootPartition;
+ PARTITION_TABLE_ENTRY PartitionEntry;
+
+ /* This is a hard disk */
+ if (!DiskGetBootPartitionEntry(FrldrBootDrive, &PartitionEntry, &BootPartition))
+ {
+ ERR("Failed to get boot partition entry\n");
+ return FALSE;
+ }
+
+ FrldrBootPartition = BootPartition;
+
+ RtlStringCbPrintfA(FrldrBootPath, sizeof(FrldrBootPath),
+ "multi(0)disk(0)rdisk(%u)partition(%lu)",
+ FrldrBootDrive - 0x80, FrldrBootPartition);
+ }
+
+ return TRUE;
+}
+
BOOLEAN
PcInitializeBootDevices(VOID)
{
UCHAR DiskCount;
BOOLEAN BootDriveReported = FALSE;
ULONG i;
- CHAR BootPath[MAX_PATH];
DiskCount = EnumerateHarddisks(&BootDriveReported);
- /* Get the drive we're booting from */
- MachDiskGetBootPath(BootPath, sizeof(BootPath));
+ /* Initialize FrldrBootPath, the boot path we're booting from (the "SystemPartition") */
+ DiskGetBootPath(PxeInit());
/* Add it, if it's a floppy or cdrom */
if ((FrldrBootDrive >= 0x80 && !BootDriveReported) ||
TRACE("Checksum: %x\n", Checksum);
/* Fill out the ARC disk block */
- AddReactOSArcDiskInfo(BootPath, Signature, Checksum, TRUE);
+ AddReactOSArcDiskInfo(FrldrBootPath, Signature, Checksum, TRUE);
- FsRegisterDevice(BootPath, &DiskVtbl);
+ FsRegisterDevice(FrldrBootPath, &DiskVtbl);
DiskCount++; // This is not accounted for in the number of pre-enumerated BIOS drives!
TRACE("Additional boot drive detected: 0x%02X\n", (int)FrldrBootDrive);
}
MachVtbl.GetMemoryMap = PcMemGetMemoryMap;
MachVtbl.GetExtendedBIOSData = PcGetExtendedBIOSData;
MachVtbl.GetFloppyCount = PcGetFloppyCount;
- MachVtbl.DiskGetBootPath = PcDiskGetBootPath;
MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors;
MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry;
MachVtbl.DiskGetCacheableBlockCount = PcDiskGetCacheableBlockCount;
MachVtbl.GetMemoryMap = XboxMemGetMemoryMap;
MachVtbl.GetExtendedBIOSData = XboxGetExtendedBIOSData;
MachVtbl.GetFloppyCount = XboxGetFloppyCount;
- MachVtbl.DiskGetBootPath = DiskGetBootPath;
MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors;
MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry;
MachVtbl.DiskGetCacheableBlockCount = XboxDiskGetCacheableBlockCount;
#include <poppack.h>
+/* DISK IO ERROR SUPPORT *****************************************************/
+
+static BOOLEAN bReportError = TRUE;
+
+VOID DiskReportError(BOOLEAN bError)
+{
+ bReportError = bError;
+}
+
+static PCSTR DiskGetErrorCodeString(ULONG ErrorCode)
+{
+ switch (ErrorCode)
+ {
+ case 0x00: return "no error";
+ case 0x01: return "bad command passed to driver";
+ case 0x02: return "address mark not found or bad sector";
+ case 0x03: return "diskette write protect error";
+ case 0x04: return "sector not found";
+ case 0x05: return "fixed disk reset failed";
+ case 0x06: return "diskette changed or removed";
+ case 0x07: return "bad fixed disk parameter table";
+ case 0x08: return "DMA overrun";
+ case 0x09: return "DMA access across 64k boundary";
+ case 0x0A: return "bad fixed disk sector flag";
+ case 0x0B: return "bad fixed disk cylinder";
+ case 0x0C: return "unsupported track/invalid media";
+ case 0x0D: return "invalid number of sectors on fixed disk format";
+ case 0x0E: return "fixed disk controlled data address mark detected";
+ case 0x0F: return "fixed disk DMA arbitration level out of range";
+ case 0x10: return "ECC/CRC error on disk read";
+ case 0x11: return "recoverable fixed disk data error, data fixed by ECC";
+ case 0x20: return "controller error (NEC for floppies)";
+ case 0x40: return "seek failure";
+ case 0x80: return "time out, drive not ready";
+ case 0xAA: return "fixed disk drive not ready";
+ case 0xBB: return "fixed disk undefined error";
+ case 0xCC: return "fixed disk write fault on selected drive";
+ case 0xE0: return "fixed disk status error/Error reg = 0";
+ case 0xFF: return "sense operation failed";
+
+ default: return "unknown error code";
+ }
+}
+
+static VOID DiskError(PCSTR ErrorString, ULONG ErrorCode)
+{
+ CHAR ErrorCodeString[200];
+
+ if (bReportError == FALSE)
+ return;
+
+ sprintf(ErrorCodeString, "%s\n\nError Code: 0x%lx\nError: %s",
+ ErrorString, ErrorCode, DiskGetErrorCodeString(ErrorCode));
+
+ TRACE("%s\n", ErrorCodeString);
+
+ UiMessageBox(ErrorCodeString);
+}
+
/* FUNCTIONS *****************************************************************/
BOOLEAN DiskResetController(UCHAR DriveNumber)
}
/* If we get here then the read failed */
- ERR("Disk Read Failed in LBA mode: %x (DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d)\n", RegsOut.b.ah, DriveNumber, SectorNumber, SectorCount);
+ DiskError("Disk Read Failed in LBA mode", RegsOut.b.ah);
+ ERR("Disk Read Failed in LBA mode: %x (%s) (DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d)\n",
+ RegsOut.b.ah, DiskGetErrorCodeString(RegsOut.b.ah),
+ DriveNumber, SectorNumber, SectorCount);
return FALSE;
}
/* If we retried 3 times then fail */
if (RetryCount >= 3)
{
- ERR("Disk Read Failed in CHS mode, after retrying 3 times: %x\n", RegsOut.b.ah);
+ DiskError("Disk Read Failed in CHS mode, after retrying 3 times", RegsOut.b.ah);
+ ERR("Disk Read Failed in CHS mode, after retrying 3 times: %x (%s) (DriveNumber: 0x%x SectorNumber: %I64d SectorCount: %d)\n",
+ RegsOut.b.ah, DiskGetErrorCodeString(RegsOut.b.ah),
+ DriveNumber, SectorNumber, SectorCount);
return FALSE;
}
}
/* Get the disk geometry. If this fails then we will
* just return 1 sector to be safe. */
- else if (! PcDiskGetDriveGeometry(DriveNumber, &Geometry))
+ else if (!PcDiskGetDriveGeometry(DriveNumber, &Geometry))
{
return 1;
}
}
}
-BOOLEAN
-PcDiskGetBootPath(OUT PCHAR BootPath, IN ULONG Size)
-{
- // FIXME: Keep it there, or put it in DiskGetBootPath?
- // Or, abstract the notion of network booting to make
- // sense for other platforms than the PC (and this idea
- // already exists), then we would need to check whether
- // we were booting from network (and: PC --> PXE, etc...)
- // and if so, set the correct ARC path. But then this new
- // logic could be moved back to DiskGetBootPath...
-
- if (*FrldrBootPath)
- {
- /* Copy back the buffer */
- if (Size < strlen(FrldrBootPath) + 1)
- return FALSE;
- strncpy(BootPath, FrldrBootPath, Size);
- return TRUE;
- }
-
- // FIXME! FIXME! Do this in some drive recognition procedure!!!!
- if (PxeInit())
- {
- strcpy(BootPath, "net(0)");
- return TRUE;
- }
- return DiskGetBootPath(BootPath, Size);
-}
-
/* EOF */
int mmu_handle = 0;
int claimed[4];
BOOLEAN AcpiPresent = FALSE;
-char BootPath[0x100] = { 0 }, BootPart[0x100] = { 0 }, CmdLine[0x100] = { "bootprep" };
+CHAR FrldrBootPath[MAX_PATH] = "", BootPart[MAX_PATH] = "", CmdLine[MAX_PATH] = "bootprep";
jmp_buf jmp;
volatile char *video_mem = 0;
return slots;
}
-BOOLEAN PpcDiskGetBootPath(PCHAR OutBootPath, ULONG Size) {
- strncpy( OutBootPath, BootPath, Size );
- return TRUE;
-}
-
BOOLEAN PpcDiskReadLogicalSectors( ULONG DriveNumber, ULONGLONG SectorNumber,
ULONG SectorCount, PVOID Buffer ) {
int rlen = 0;
MachVtbl.GetMemoryMap = PpcGetMemoryMap;
- MachVtbl.DiskGetBootPath = PpcDiskGetBootPath;
MachVtbl.DiskReadLogicalSectors = PpcDiskReadLogicalSectors;
MachVtbl.DiskGetDriveGeometry = PpcDiskGetDriveGeometry;
MachVtbl.DiskGetCacheableBlockCount = PpcDiskGetCacheableBlockCount;
char *sep;
BootPart[0] = 0;
- BootPath[0] = 0;
+ FrldrBootPath[0] = 0;
printf( "Determining boot device: [%s]\n", CmdLine );
if( strlen(BootPart) == 0 ) {
if (ofproxy)
len = ofw_getprop(chosen_package, "bootpath",
- BootPath, sizeof(BootPath));
+ FrldrBootPath, sizeof(FrldrBootPath));
else
len = 0;
if( len < 0 ) len = 0;
- BootPath[len] = 0;
- printf( "Boot Path: %s\n", BootPath );
+ FrldrBootPath[len] = 0;
+ printf( "Boot Path: %s\n", FrldrBootPath );
- sep = strrchr(BootPath, ',');
+ sep = strrchr(FrldrBootPath, ',');
- strcpy(BootPart, BootPath);
+ strcpy(BootPart, FrldrBootPath);
if( sep ) {
- BootPart[sep - BootPath] = 0;
+ BootPart[sep - FrldrBootPath] = 0;
}
}
ofw_exit();
}
-void ChainLoadBiosBootSectorCode() {
+VOID __cdecl ChainLoadBiosBootSectorCode(
+ IN UCHAR BootDrive OPTIONAL,
+ IN ULONG BootPartition OPTIONAL)
+{
ofw_exit();
}
/* We'll check this to see if we're in OFW land */
extern of_proxy ofproxy;
-PVOID KernelMemory = 0;
+PVOID KernelMemory = NULL;
/* Bits to shift to convert a Virtual Address into an Offset in the Page Table */
#define PFN_SHIFT 12
/* Restore real mode stack */
mov sp, word ptr ds:[stack16]
- // sti /* These are ok now */
+ // sti /* These are ok now */
/* Do the callback, specified by bx */
shl bx, 1
/* Do the callback, specified by bx */
shl bx, 1
- call word ptr ds:callback_table[bx]
+ call word ptr ds:CallbackTable[bx]
/*
.long 0 // receives address of PE entry point
nop
-callback_table:
+CallbackTable:
.word Int386
.word Reboot
.word ChainLoadBiosBootSectorCode
PCHAR* Argv;
PCHAR* Args;
PCHAR SettingName, SettingValue;
- CHAR BootPath[MAX_PATH];
*pArgc = 0;
if (LoadIdentifier && !*LoadIdentifier)
LoadIdentifier = NULL;
- /* Get the boot path we're booting from (the "SystemPartition") */
- MachDiskGetBootPath(BootPath, sizeof(BootPath));
-
/* Count the number of operating systems in the section */
Count = IniGetNumSectionItems(SectionId);
Size = 0;
/* i == 0: Program name */
/* i == 1: SystemPartition : from where FreeLdr has been started */
- Size += (strlen("SystemPartition=") + strlen(BootPath) + 1) * sizeof(CHAR);
+ Size += (strlen("SystemPartition=") + strlen(FrldrBootPath) + 1) * sizeof(CHAR);
/* i == 2: LoadIdentifier : ASCII string that may be used to associate an identifier with a set of load parameters */
if (LoadIdentifier)
{
/* i == 1: SystemPartition */
{
strcpy(SettingName, "SystemPartition=");
- strcat(SettingName, BootPath);
+ strcat(SettingName, FrldrBootPath);
*Args++ = SettingName;
SettingName += (strlen(SettingName) + 1);
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef _M_ARM
#include <freeldr.h>
-
-#include <debug.h>
-DBG_DEFAULT_CHANNEL(DISK);
-
-CHAR FrldrBootPath[MAX_PATH] = "";
-
-static BOOLEAN bReportError = TRUE;
-
-/* FUNCTIONS *****************************************************************/
-
-VOID DiskReportError(BOOLEAN bError)
-{
- bReportError = bError;
-}
-
-VOID DiskError(PCSTR ErrorString, ULONG ErrorCode)
-{
- CHAR ErrorCodeString[200];
-
- if (bReportError == FALSE)
- return;
-
- sprintf(ErrorCodeString, "%s\n\nError Code: 0x%lx\nError: %s",
- ErrorString, ErrorCode, DiskGetErrorCodeString(ErrorCode));
-
- TRACE("%s\n", ErrorCodeString);
-
- UiMessageBox(ErrorCodeString);
-}
-
-PCSTR DiskGetErrorCodeString(ULONG ErrorCode)
-{
- switch (ErrorCode)
- {
- case 0x00: return "no error";
- case 0x01: return "bad command passed to driver";
- case 0x02: return "address mark not found or bad sector";
- case 0x03: return "diskette write protect error";
- case 0x04: return "sector not found";
- case 0x05: return "fixed disk reset failed";
- case 0x06: return "diskette changed or removed";
- case 0x07: return "bad fixed disk parameter table";
- case 0x08: return "DMA overrun";
- case 0x09: return "DMA access across 64k boundary";
- case 0x0A: return "bad fixed disk sector flag";
- case 0x0B: return "bad fixed disk cylinder";
- case 0x0C: return "unsupported track/invalid media";
- case 0x0D: return "invalid number of sectors on fixed disk format";
- case 0x0E: return "fixed disk controlled data address mark detected";
- case 0x0F: return "fixed disk DMA arbitration level out of range";
- case 0x10: return "ECC/CRC error on disk read";
- case 0x11: return "recoverable fixed disk data error, data fixed by ECC";
- case 0x20: return "controller error (NEC for floppies)";
- case 0x40: return "seek failure";
- case 0x80: return "time out, drive not ready";
- case 0xAA: return "fixed disk drive not ready";
- case 0xBB: return "fixed disk undefined error";
- case 0xCC: return "fixed disk write fault on selected drive";
- case 0xE0: return "fixed disk status error/Error reg = 0";
- case 0xFF: return "sense operation failed";
-
- default: return "unknown error code";
- }
-}
-
-BOOLEAN DiskIsDriveRemovable(UCHAR DriveNumber)
-{
- /*
- * Hard disks use drive numbers >= 0x80 . So if the drive number
- * indicates a hard disk then return FALSE.
- * 0x49 is our magic ramdisk drive, so return FALSE for that too.
- */
- if ((DriveNumber >= 0x80) || (DriveNumber == 0x49))
- return FALSE;
-
- /* The drive is a floppy diskette so return TRUE */
- return TRUE;
-}
-
-BOOLEAN DiskGetBootPath(OUT PCHAR BootPath, IN ULONG Size)
-{
- if (*FrldrBootPath)
- goto Done;
-
- if (Size)
- BootPath[0] = ANSI_NULL;
-
- /* 0x49 is our magic ramdisk drive, so try to detect it first */
- if (FrldrBootDrive == 0x49)
- {
- /* This is the ramdisk. See ArmDiskGetBootPath too... */
- // sprintf(FrldrBootPath, "ramdisk(%u)", 0);
- strcpy(FrldrBootPath, "ramdisk(0)");
- }
- else if (FrldrBootDrive < 0x80)
- {
- /* This is a floppy */
- sprintf(FrldrBootPath, "multi(0)disk(0)fdisk(%u)", FrldrBootDrive);
- }
- else if (FrldrBootPartition == 0xFF)
- {
- /* Boot Partition 0xFF is the magic value that indicates booting from CD-ROM (see isoboot.S) */
- sprintf(FrldrBootPath, "multi(0)disk(0)cdrom(%u)", FrldrBootDrive - 0x80);
- }
- else
- {
- ULONG BootPartition;
- PARTITION_TABLE_ENTRY PartitionEntry;
-
- /* This is a hard disk */
- if (!DiskGetBootPartitionEntry(FrldrBootDrive, &PartitionEntry, &BootPartition))
- {
- ERR("Failed to get boot partition entry\n");
- return FALSE;
- }
-
- FrldrBootPartition = BootPartition;
-
- sprintf(FrldrBootPath, "multi(0)disk(0)rdisk(%u)partition(%lu)",
- FrldrBootDrive - 0x80, FrldrBootPartition);
- }
-
-Done:
- /* Copy back the buffer */
- if (Size < strlen(FrldrBootPath) + 1)
- return FALSE;
- strncpy(BootPath, FrldrBootPath, Size);
- return TRUE;
-}
-
-#endif
DBG_DEFAULT_CHANNEL(DISK);
#define MaxDriveNumber 0xFF
-PARTITION_STYLE DiskPartitionType[MaxDriveNumber + 1];
+static PARTITION_STYLE DiskPartitionType[MaxDriveNumber + 1];
/* BRFR signature at disk offset 0x600 */
#define XBOX_SIGNATURE_SECTOR 3
}
/* Check the partition table magic value */
- if (BootRecord->MasterBootRecordMagic != 0xaa55)
- {
- return FALSE;
- }
-
- return TRUE;
+ return (BootRecord->MasterBootRecordMagic == 0xaa55);
}
static BOOLEAN
IN BOOLEAN ReturnRecognizedPartitions,
OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer)
{
+ NTSTATUS Status;
PMASTER_BOOT_RECORD MasterBootRecord;
PDRIVE_LAYOUT_INFORMATION Partitions;
ULONG NbPartitions, i, Size;
- NTSTATUS ret;
*PartitionBuffer = NULL;
return STATUS_NO_MEMORY;
/* Read disk MBR */
- ret = IopReadBootRecord(DeviceObject, 0, SectorSize, MasterBootRecord);
- if (!NT_SUCCESS(ret))
+ Status = IopReadBootRecord(DeviceObject, 0, SectorSize, MasterBootRecord);
+ if (!NT_SUCCESS(Status))
{
ExFreePool(MasterBootRecord);
- return ret;
+ return Status;
}
/* Check validity of boot record */
static ARC_STATUS DiskClose(ULONG FileId)
{
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
-
ExFreePool(Context);
return ESUCCESS;
}
InitializeListHead(&ModuleListHead);
/* Create full ntbootdd.sys path */
- MachDiskGetBootPath(NtBootDdPath, sizeof(NtBootDdPath));
+ strcpy(NtBootDdPath, FrldrBootPath);
strcat(NtBootDdPath, "\\NTBOOTDD.SYS");
/* Load file */
#include <debug.h>
DBG_DEFAULT_CHANNEL(WARNING);
+/* GLOBALS ********************************************************************/
+
+CCHAR FrldrBootPath[MAX_PATH] = "";
+
/* FUNCTIONS ******************************************************************/
VOID __cdecl BootMain(IN PCCH CmdLine)
PFREELDR_MEMORY_DESCRIPTOR PcMemGetMemoryMap(ULONG *MemoryMapSize);
BOOLEAN PcFindPciBios(PPCI_REGISTRY_INFO BusData);
+/*
+ * Disk Variables and Functions
+ */
+/* Platform-specific boot drive and partition numbers */
+extern UCHAR FrldrBootDrive;
+extern ULONG FrldrBootPartition;
+
+VOID DiskReportError(BOOLEAN bError);
BOOLEAN DiskResetController(UCHAR DriveNumber);
BOOLEAN DiskGetExtendedDriveParameters(UCHAR DriveNumber, PVOID Buffer, USHORT BufferSize);
-BOOLEAN PcDiskGetBootPath(OUT PCHAR BootPath, IN ULONG Size);
BOOLEAN PcDiskReadLogicalSectors(UCHAR DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer);
BOOLEAN PcDiskGetDriveGeometry(UCHAR DriveNumber, PGEOMETRY DriveGeometry);
ULONG PcDiskGetCacheableBlockCount(UCHAR DriveNumber);
// If CF is set then the call failed (usually)
#define INT386_SUCCESS(regs) ((regs.x.eflags & EFLAGS_CF) == 0)
-VOID __cdecl ChainLoadBiosBootSectorCode(VOID); // Implemented in boot.S
-VOID __cdecl Reboot(VOID); // Implemented in boot.S
-VOID DetectHardware(VOID); // Implemented in hardware.c
+VOID __cdecl ChainLoadBiosBootSectorCode( // Implemented in boot.S
+ IN UCHAR BootDrive OPTIONAL,
+ IN ULONG BootPartition OPTIONAL);
+
+VOID __cdecl Reboot(VOID); // Implemented in boot.S
+VOID DetectHardware(VOID); // Implemented in hardware.c
#endif /* ! __ASM__ */
} GEOMETRY, *PGEOMETRY;
-//
-// Extended disk geometry (Int13 / ah=48h)
-//
+/*
+ * Extended disk geometry (Int13 / ah=48h)
+ */
#include <pshpack1.h>
typedef struct _EXTENDED_GEOMETRY
{
} EXTENDED_GEOMETRY, *PEXTENDED_GEOMETRY;
-//
-// Define the structure of a partition table entry
-//
+/*
+ * Define the structure of a partition table entry
+ */
typedef struct _PARTITION_TABLE_ENTRY
{
UCHAR BootIndicator; // 0x00 - non-bootable partition,
} PARTITION_TABLE_ENTRY, *PPARTITION_TABLE_ENTRY;
-//
-// Define the structure of the master boot record
-//
+/*
+ * Define the structure of the master boot record
+ */
typedef struct _MASTER_BOOT_RECORD
{
UCHAR MasterBootRecordCodeAndData[0x1b8]; /* 0x000 */
} MASTER_BOOT_RECORD, *PMASTER_BOOT_RECORD;
#include <poppack.h>
-//
-// Partition type defines (of PSDK)
-//
+/*
+ * Partition type defines (of PSDK)
+ */
#define PARTITION_ENTRY_UNUSED 0x00 // Entry unused
#define PARTITION_FAT_12 0x01 // 12-bit FAT entries
#define PARTITION_XENIX_1 0x02 // Xenix
VOID DiskStopFloppyMotor(VOID);
#endif // defined __i386__ || defined(_M_AMD64)
-///////////////////////////////////////////////////////////////////////////////////////
-//
-// FreeLoader Disk Functions
-//
-///////////////////////////////////////////////////////////////////////////////////////
-VOID DiskReportError(BOOLEAN bError);
-VOID DiskError(PCSTR ErrorString, ULONG ErrorCode);
-PCSTR DiskGetErrorCodeString(ULONG ErrorCode);
-BOOLEAN DiskIsDriveRemovable(UCHAR DriveNumber);
-
-BOOLEAN DiskGetBootPath(OUT PCHAR BootPath, IN ULONG Size);
-/* Platform-specific boot drive and partition numbers */
-extern UCHAR FrldrBootDrive;
-extern ULONG FrldrBootPartition;
-/* ARC path of the boot drive and partition */
-extern CHAR FrldrBootPath[MAX_PATH];
-
-/* Buffer for disk reads */
+/* Buffer for disk reads (hwdisk.c) */
extern PVOID DiskReadBuffer;
extern SIZE_T DiskReadBufferSize;
+/* ARC path of the boot drive and partition */
+extern CCHAR FrldrBootPath[MAX_PATH];
+
+
///////////////////////////////////////////////////////////////////////////////////////
//
// Fixed Disk Partition Management Functions
VOID (*GetExtendedBIOSData)(PULONG ExtendedBIOSDataArea, PULONG ExtendedBIOSDataSize);
UCHAR (*GetFloppyCount)(VOID);
- BOOLEAN (*DiskGetBootPath)(PCHAR BootPath, ULONG Size);
BOOLEAN (*DiskReadLogicalSectors)(UCHAR DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer);
BOOLEAN (*DiskGetDriveGeometry)(UCHAR DriveNumber, PGEOMETRY DriveGeometry);
ULONG (*DiskGetCacheableBlockCount)(UCHAR DriveNumber);
MachVtbl.GetExtendedBIOSData((ExtendedBIOSDataArea), (ExtendedBIOSDataSize))
#define MachGetFloppyCount() \
MachVtbl.GetFloppyCount()
-#define MachDiskGetBootPath(Path, Size) \
- MachVtbl.DiskGetBootPath((Path), (Size))
#define MachDiskReadLogicalSectors(Drive, Start, Count, Buf) \
MachVtbl.DiskReadLogicalSectors((Drive), (Start), (Count), (Buf))
#define MachDiskGetDriveGeometry(Drive, Geom) \
TRACE("BtrFsClose %lu\n", FileId);
FrLdrTempFree(phandle, TAG_BTRFS_FILE);
-
return ESUCCESS;
}
ARC_STATUS Ext2Close(ULONG FileId)
{
PEXT2_FILE_INFO FileHandle = FsGetDeviceSpecific(FileId);
-
FrLdrTempFree(FileHandle, TAG_EXT_FILE);
-
return ESUCCESS;
}
ARC_STATUS IsoClose(ULONG FileId)
{
PISO_FILE_INFO FileHandle = FsGetDeviceSpecific(FileId);
-
FrLdrTempFree(FileHandle, TAG_ISO_FILE);
-
return ESUCCESS;
}
#include <debug.h>
DBG_DEFAULT_CHANNEL(INIFILE);
-static ARC_STATUS IniOpenIniFile(ULONG* FileId)
-{
- CHAR FreeldrPath[MAX_PATH];
-
- //
- // Create full freeldr.ini path
- //
- MachDiskGetBootPath(FreeldrPath, sizeof(FreeldrPath));
- strcat(FreeldrPath, "\\freeldr.ini");
-
- // Try to open freeldr.ini
- return ArcOpen(FreeldrPath, OpenReadOnly, FileId);
-}
-
BOOLEAN IniFileInitialize(VOID)
{
FILEINFORMATION FileInformation;
ULONG FreeLoaderIniFileSize, Count;
ARC_STATUS Status;
BOOLEAN Success;
+
TRACE("IniFileInitialize()\n");
- //
- // Open freeldr.ini
- //
- Status = IniOpenIniFile(&FileId);
+ /* Try to open freeldr.ini */
+ Status = FsOpenFile("freeldr.ini", FrldrBootPath, OpenReadOnly, &FileId);
if (Status != ESUCCESS)
{
ERR("Error while opening freeldr.ini, Status: %d\n", Status);
return FALSE;
}
- //
- // Get the file size
- //
+ /* Get the file size */
Status = ArcGetFileInformation(FileId, &FileInformation);
if (Status != ESUCCESS || FileInformation.EndingAddress.HighPart != 0)
{
}
FreeLoaderIniFileSize = FileInformation.EndingAddress.LowPart;
- //
- // Allocate memory to cache the whole freeldr.ini
- //
+ /* Allocate memory to cache the whole freeldr.ini */
FreeLoaderIniFileData = FrLdrTempAlloc(FreeLoaderIniFileSize, TAG_INI_FILE);
if (!FreeLoaderIniFileData)
{
return FALSE;
}
- //
- // Read freeldr.ini off the disk
- //
+ /* Load freeldr.ini from the disk */
Status = ArcRead(FileId, FreeLoaderIniFileData, FreeLoaderIniFileSize, &Count);
if (Status != ESUCCESS || Count != FreeLoaderIniFileSize)
{
return FALSE;
}
- //
- // Parse the .ini file data
- //
+ /* Parse the .ini file data */
Success = IniParseFile(FreeLoaderIniFileData, FreeLoaderIniFileSize);
- //
- // Do some cleanup, and return
- //
+ /* Do some cleanup, and return */
ArcClose(FileId);
FrLdrTempFree(FreeLoaderIniFileData, TAG_INI_FILE);
* result in a read error.
*/
// DiskStopFloppyMotor();
- /* NOTE: Don't touch FrldrBootDrive */
- ChainLoadBiosBootSectorCode();
- Reboot(); /* Must not return! */
+ ChainLoadBiosBootSectorCode(0 /*DriveNumber*/, 0 /*PartitionNumber*/);
+ /* Must not return! */
return ESUCCESS;
}
* result in a read error.
*/
// DiskStopFloppyMotor();
- FrldrBootDrive = DriveNumber;
- FrldrBootPartition = PartitionNumber;
- ChainLoadBiosBootSectorCode();
- Reboot(); /* Must not return! */
+ ChainLoadBiosBootSectorCode(DriveNumber, PartitionNumber);
+ /* Must not return! */
return ESUCCESS;
}