[FREELDR] Other enhancements.

- Add optional arguments BootDrive and BootPartition to
  ChainLoadBiosBootSectorCode() so as not to modify explicitly the
  FrldrBootDrive and FrldrBootPartition variables, that should remain
  purely internal.

- Implement ChainLoadBiosBootSectorCode() for x64.

- Get rid of the machine-specific DiskGetBootPath(), and instead do its
  job only once in the machine-specific InitializeBootDevices() (or in
  MachInit() for PPC).
  Cache the result of this operation into the globally-accessible
  FrldrBootPath buffer. This avoids the unneeded calls to (Mach)DiskGetBootPath()
  we used to do before.
  Also remove the separate distinction between the PC and XBOX versions
  of this functionality.

- Move the PC-specific DiskIsDriveRemovable() and DiskGetBootPath()
  as well as the disk-IO-error functionality, back into the
  corresponding PC-arch files.

- Simplify IniFileInitialize(), getting rid of IniOpenIniFile().
This commit is contained in:
Hermès Bélusca-Maïto 2019-09-13 02:14:22 +02:00
parent b16ca9cd65
commit 4843c1a954
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
25 changed files with 310 additions and 347 deletions

View file

@ -73,10 +73,48 @@ Reboot:
/* 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
@ -135,23 +173,6 @@ CallRealMode_return:
/////////////////////////////////////////
/* 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:
@ -165,4 +186,16 @@ __ltr:
ret
/* 64-bit stack pointer */
stack64:
.quad STACKADDR
PUBLIC FrldrBootDrive
FrldrBootDrive:
.byte 0
PUBLIC FrldrBootPartition
FrldrBootPartition:
.long 0
END

View file

@ -95,19 +95,6 @@ ArmPrepareForReactOS(VOID)
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)
{
@ -152,7 +139,12 @@ BOOLEAN
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];
@ -239,6 +231,5 @@ MachInit(IN PCCH CommandLine)
MachVtbl.GetMemoryMap = ArmMemGetMemoryMap;
MachVtbl.InitializeBootDevices = ArmInitializeBootDevices;
MachVtbl.HwDetect = ArmHwDetect;
MachVtbl.DiskGetBootPath = ArmDiskGetBootPath;
MachVtbl.HwIdle = ArmHwIdle;
}

View file

@ -62,7 +62,6 @@ PUBLIC ContinueAddress
ContinueAddress:
.long _FrldrStartup
_FrldrStartup:
/* Store BootDrive and BootPartition */
@ -100,6 +99,47 @@ stop:
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);
*
@ -139,27 +179,6 @@ _PxeCallApi:
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 */

View file

@ -53,7 +53,6 @@ static ARC_STATUS
DiskClose(ULONG FileId)
{
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
FrLdrTempFree(Context, TAG_HW_DISK_CONTEXT);
return ESUCCESS;
}
@ -361,18 +360,85 @@ EnumerateHarddisks(OUT PBOOLEAN BootDriveReported)
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) ||
@ -407,9 +473,9 @@ PcInitializeBootDevices(VOID)
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);
}

View file

@ -1428,7 +1428,6 @@ PcMachInit(const char *CmdLine)
MachVtbl.GetMemoryMap = PcMemGetMemoryMap;
MachVtbl.GetExtendedBIOSData = PcGetExtendedBIOSData;
MachVtbl.GetFloppyCount = PcGetFloppyCount;
MachVtbl.DiskGetBootPath = PcDiskGetBootPath;
MachVtbl.DiskReadLogicalSectors = PcDiskReadLogicalSectors;
MachVtbl.DiskGetDriveGeometry = PcDiskGetDriveGeometry;
MachVtbl.DiskGetCacheableBlockCount = PcDiskGetCacheableBlockCount;

View file

@ -284,7 +284,6 @@ XboxMachInit(const char *CmdLine)
MachVtbl.GetMemoryMap = XboxMemGetMemoryMap;
MachVtbl.GetExtendedBIOSData = XboxGetExtendedBIOSData;
MachVtbl.GetFloppyCount = XboxGetFloppyCount;
MachVtbl.DiskGetBootPath = DiskGetBootPath;
MachVtbl.DiskReadLogicalSectors = XboxDiskReadLogicalSectors;
MachVtbl.DiskGetDriveGeometry = XboxDiskGetDriveGeometry;
MachVtbl.DiskGetCacheableBlockCount = XboxDiskGetCacheableBlockCount;

View file

@ -73,6 +73,65 @@ typedef struct
#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)
@ -157,7 +216,10 @@ static BOOLEAN PcDiskReadLogicalSectorsLBA(UCHAR DriveNumber, ULONGLONG SectorNu
}
/* 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;
}
@ -271,7 +333,10 @@ static BOOLEAN PcDiskReadLogicalSectorsCHS(UCHAR DriveNumber, ULONGLONG SectorNu
/* 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;
}
@ -563,7 +628,7 @@ PcDiskGetCacheableBlockCount(UCHAR DriveNumber)
}
/* 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;
}
@ -573,33 +638,4 @@ PcDiskGetCacheableBlockCount(UCHAR DriveNumber)
}
}
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 */

View file

@ -32,7 +32,7 @@ static int chosen_package, stdin_handle, stdout_handle, part_handle = -1;
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;
@ -247,11 +247,6 @@ ULONG PpcGetMemoryMap( PBIOS_MEMORY_MAP BiosMemoryMap,
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;
@ -441,7 +436,6 @@ void PpcDefaultMachVtbl()
MachVtbl.GetMemoryMap = PpcGetMemoryMap;
MachVtbl.DiskGetBootPath = PpcDiskGetBootPath;
MachVtbl.DiskReadLogicalSectors = PpcDiskReadLogicalSectors;
MachVtbl.DiskGetDriveGeometry = PpcDiskGetDriveGeometry;
MachVtbl.DiskGetCacheableBlockCount = PpcDiskGetCacheableBlockCount;
@ -493,7 +487,7 @@ void MachInit(const char *CmdLine) {
char *sep;
BootPart[0] = 0;
BootPath[0] = 0;
FrldrBootPath[0] = 0;
printf( "Determining boot device: [%s]\n", CmdLine );
@ -511,18 +505,18 @@ void MachInit(const char *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;
}
}
@ -551,7 +545,10 @@ void BootNewLinuxKernel() {
ofw_exit();
}
void ChainLoadBiosBootSectorCode() {
VOID __cdecl ChainLoadBiosBootSectorCode(
IN UCHAR BootDrive OPTIONAL,
IN ULONG BootPartition OPTIONAL)
{
ofw_exit();
}

View file

@ -30,7 +30,7 @@
/* 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

View file

@ -273,7 +273,7 @@ InRealMode:
/* 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

View file

@ -105,7 +105,7 @@ inrmode:
/* Do the callback, specified by bx */
shl bx, 1
call word ptr ds:callback_table[bx]
call word ptr ds:CallbackTable[bx]
/*
@ -140,7 +140,7 @@ pm_entrypoint:
.long 0 // receives address of PE entry point
nop
callback_table:
CallbackTable:
.word Int386
.word Reboot
.word ChainLoadBiosBootSectorCode

View file

@ -87,7 +87,6 @@ BuildArgvForOsLoader(
PCHAR* Argv;
PCHAR* Args;
PCHAR SettingName, SettingValue;
CHAR BootPath[MAX_PATH];
*pArgc = 0;
@ -97,9 +96,6 @@ BuildArgvForOsLoader(
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);
@ -113,7 +109,7 @@ BuildArgvForOsLoader(
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)
{
@ -139,7 +135,7 @@ BuildArgvForOsLoader(
/* i == 1: SystemPartition */
{
strcpy(SettingName, "SystemPartition=");
strcat(SettingName, BootPath);
strcat(SettingName, FrldrBootPath);
*Args++ = SettingName;
SettingName += (strlen(SettingName) + 1);

View file

@ -17,136 +17,4 @@
* 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

View file

@ -24,7 +24,7 @@
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
@ -84,12 +84,7 @@ DiskReadBootRecord(
}
/* Check the partition table magic value */
if (BootRecord->MasterBootRecordMagic != 0xaa55)
{
return FALSE;
}
return TRUE;
return (BootRecord->MasterBootRecordMagic == 0xaa55);
}
static BOOLEAN
@ -503,10 +498,10 @@ IoReadPartitionTable(
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;
@ -518,11 +513,11 @@ IoReadPartitionTable(
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 */

View file

@ -169,7 +169,6 @@ SpiSendSynchronousSrb(
static ARC_STATUS DiskClose(ULONG FileId)
{
DISKCONTEXT* Context = FsGetDeviceSpecific(FileId);
ExFreePool(Context);
return ESUCCESS;
}
@ -1612,7 +1611,7 @@ LoadBootDeviceDriver(VOID)
InitializeListHead(&ModuleListHead);
/* Create full ntbootdd.sys path */
MachDiskGetBootPath(NtBootDdPath, sizeof(NtBootDdPath));
strcpy(NtBootDdPath, FrldrBootPath);
strcat(NtBootDdPath, "\\NTBOOTDD.SYS");
/* Load file */

View file

@ -24,6 +24,10 @@
#include <debug.h>
DBG_DEFAULT_CHANNEL(WARNING);
/* GLOBALS ********************************************************************/
CCHAR FrldrBootPath[MAX_PATH] = "";
/* FUNCTIONS ******************************************************************/
VOID __cdecl BootMain(IN PCCH CmdLine)

View file

@ -51,10 +51,17 @@ VOID PcPrepareForReactOS(VOID);
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);

View file

@ -160,9 +160,12 @@ int __cdecl Int386(int ivec, REGS* in, REGS* out);
// 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__ */

View file

@ -30,9 +30,9 @@ typedef struct _GEOMETRY
} GEOMETRY, *PGEOMETRY;
//
// Extended disk geometry (Int13 / ah=48h)
//
/*
* Extended disk geometry (Int13 / ah=48h)
*/
#include <pshpack1.h>
typedef struct _EXTENDED_GEOMETRY
{
@ -47,9 +47,9 @@ 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,
@ -66,9 +66,9 @@ typedef struct _PARTITION_TABLE_ENTRY
} 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 */
@ -80,9 +80,9 @@ typedef struct _MASTER_BOOT_RECORD
} 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
@ -117,28 +117,15 @@ typedef struct _MASTER_BOOT_RECORD
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

View file

@ -64,7 +64,6 @@ typedef struct tagMACHVTBL
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);
@ -124,8 +123,6 @@ VOID MachInit(const char *CmdLine);
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) \

View file

@ -1115,7 +1115,6 @@ ARC_STATUS BtrFsClose(ULONG FileId)
TRACE("BtrFsClose %lu\n", FileId);
FrLdrTempFree(phandle, TAG_BTRFS_FILE);
return ESUCCESS;
}

View file

@ -1194,9 +1194,7 @@ BOOLEAN Ext2CopyTripleIndirectBlockPointers(PEXT2_VOLUME_INFO Volume, ULONG* Blo
ARC_STATUS Ext2Close(ULONG FileId)
{
PEXT2_FILE_INFO FileHandle = FsGetDeviceSpecific(FileId);
FrLdrTempFree(FileHandle, TAG_EXT_FILE);
return ESUCCESS;
}

View file

@ -243,9 +243,7 @@ static ARC_STATUS IsoLookupFile(PCSTR FileName, ULONG DeviceId, PISO_FILE_INFO I
ARC_STATUS IsoClose(ULONG FileId)
{
PISO_FILE_INFO FileHandle = FsGetDeviceSpecific(FileId);
FrLdrTempFree(FileHandle, TAG_ISO_FILE);
return ESUCCESS;
}

View file

@ -22,20 +22,6 @@
#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;
@ -44,12 +30,11 @@ BOOLEAN IniFileInitialize(VOID)
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);
@ -57,9 +42,7 @@ BOOLEAN IniFileInitialize(VOID)
return FALSE;
}
//
// Get the file size
//
/* Get the file size */
Status = ArcGetFileInformation(FileId, &FileInformation);
if (Status != ESUCCESS || FileInformation.EndingAddress.HighPart != 0)
{
@ -69,9 +52,7 @@ BOOLEAN IniFileInitialize(VOID)
}
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)
{
@ -80,9 +61,7 @@ BOOLEAN IniFileInitialize(VOID)
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)
{
@ -93,14 +72,10 @@ BOOLEAN IniFileInitialize(VOID)
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);

View file

@ -128,9 +128,8 @@ LoadAndBootBootSector(
* 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;
}
@ -215,10 +214,8 @@ LoadAndBootPartitionOrDrive(
* result in a read error.
*/
// DiskStopFloppyMotor();
FrldrBootDrive = DriveNumber;
FrldrBootPartition = PartitionNumber;
ChainLoadBiosBootSectorCode();
Reboot(); /* Must not return! */
ChainLoadBiosBootSectorCode(DriveNumber, PartitionNumber);
/* Must not return! */
return ESUCCESS;
}