Skip to content

Commit

Permalink
only print messages once, not each time processing partitions; use LB…
Browse files Browse the repository at this point in the history
…A if forceLBA enabled in additional cases where LBA support not detected
  • Loading branch information
PerditionC committed Dec 18, 2023
1 parent 4b0162c commit 7b0633b
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions kernel/initdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ void DosDefinePartition(struct DriveParamS *driveParam,
}

/* Get the parameters of the hard disk */
STATIC int LBA_Get_Drive_Parameters(int drive, struct DriveParamS *driveParam)
STATIC int LBA_Get_Drive_Parameters(int drive, struct DriveParamS *driveParam, int firstPass)
{
iregs regs;
struct _bios_LBA_disk_parameterS lba_bios_parameters;
Expand Down Expand Up @@ -663,12 +663,13 @@ STATIC int LBA_Get_Drive_Parameters(int drive, struct DriveParamS *driveParam)
if DAP cannot be used, don't use
LBA
*/
if ((regs.c.x & 1) == 0)
if (((regs.c.x & 1) == 0) && !ExtLBAForce)
{
goto StandardBios;
}

/* drive supports LBA addressing */
if (firstPass && (InitKernelConfig.Verbose >= 1)) printf("Checking for LBA support in BIOS\n");

/* version 1.0, 2.0 have different verify */
if (regs.a.x < 0x2100)
Expand All @@ -695,15 +696,22 @@ STATIC int LBA_Get_Drive_Parameters(int drive, struct DriveParamS *driveParam)
lba_bios_parameters.sectors > 0xffff ||
lba_bios_parameters.totalSectHigh != 0)
{
printf("Drive is too large to handle, using only 1st 8 GB\n"
" drive %02x heads %lu sectors %lu , total=0x%lx-%08lx\n",
if (firstPass)
{
printf("Drive is too large to handle, ");
if (ExtLBAForce)
printf("limited to 2TB");
else
printf("using CHS, limited to 8GB");
printf("\nDrive %02x, heads=%lu, sectors=%lu, total=0x%lx-%08lx\n",
drive,
(ULONG) lba_bios_parameters.heads,
(ULONG) lba_bios_parameters.sectors,
(ULONG) lba_bios_parameters.totalSect,
(ULONG) lba_bios_parameters.totalSectHigh);
}

goto StandardBios;
if (!ExtLBAForce) goto StandardBios;
}

driveParam->total_sectors = lba_bios_parameters.totalSect;
Expand All @@ -719,6 +727,7 @@ STATIC int LBA_Get_Drive_Parameters(int drive, struct DriveParamS *driveParam)
}

StandardBios: /* old way to get parameters */
if (firstPass && (InitKernelConfig.Verbose >= 1)) printf("Retrieving CHS values for drive\n");

regs.a.b.h = 0x08;
regs.d.b.l = drive;
Expand All @@ -742,7 +751,7 @@ STATIC int LBA_Get_Drive_Parameters(int drive, struct DriveParamS *driveParam)
if (driveParam->chs.Sector == 0) {
/* happens e.g. with Bochs 1.x if no harddisk defined */
driveParam->chs.Sector = 63; /* avoid division by zero...! */
if (InitKernelConfig.Verbose >= 0) printf("BIOS reported 0 sectors/track, assuming 63!\n");
if (firstPass && (InitKernelConfig.Verbose >= 0)) printf("BIOS reported 0 sectors/track, assuming 63!\n");
}

if (!(driveParam->descflags & DF_LBA))
Expand Down Expand Up @@ -988,6 +997,7 @@ int Read1LBASector(struct DriveParamS *driveParam, unsigned drive,

for (num_retries = 0; num_retries < N_RETRY; num_retries++)
{
if (InitKernelConfig.Verbose >= 1) printf("retry# %i\n", num_retries);
regs.d.b.l = drive | 0x80;
LBA_to_CHS(&chs, LBA_address, driveParam);
/* Some old "security" software (PROT) traps int13 and assumes non
Expand All @@ -999,6 +1009,7 @@ int Read1LBASector(struct DriveParamS *driveParam, unsigned drive,
if ((driveParam->descflags & DF_LBA) &&
(InitKernelConfig.ForceLBA || ExtLBAForce || chs.Cylinder > 1023))
{
if (InitKernelConfig.Verbose >= 1) printf("LBA mode\n");
dap.number_of_blocks = 1;
dap.buffer_address = buffer;
dap.block_address_high = 0; /* clear high part */
Expand All @@ -1011,6 +1022,7 @@ int Read1LBASector(struct DriveParamS *driveParam, unsigned drive,
}
else
{ /* transfer data, using old bios functions */
if (InitKernelConfig.Verbose >= 1) printf("CHS mode\n");
/* avoid overflow at end of track */

if (chs.Cylinder > 1023)
Expand Down Expand Up @@ -1039,6 +1051,7 @@ int Read1LBASector(struct DriveParamS *driveParam, unsigned drive,
/* Load the Partition Tables and get information on all drives */
int ProcessDisk(int scanType, unsigned drive, int PartitionsToIgnore)
{
/* note: error messages are only printed on first call, where (scanType==SCAN_PRIMARYBOOT) */

struct PartTableEntry PTable[4];
ULONG RelSectorOffset;
Expand All @@ -1053,7 +1066,7 @@ int ProcessDisk(int scanType, unsigned drive, int PartitionsToIgnore)
/* Get the hard drive parameters and ensure that the drive exists. */
/* If there was an error accessing the drive, skip that drive. */

if (!LBA_Get_Drive_Parameters(drive, &driveParam))
if (!LBA_Get_Drive_Parameters(drive, &driveParam,(scanType==SCAN_PRIMARYBOOT)))
{
printf("can't get drive parameters for drive %02x\n", drive);
return PartitionsToIgnore;
Expand Down Expand Up @@ -1087,7 +1100,7 @@ int ProcessDisk(int scanType, unsigned drive, int PartitionsToIgnore)
if (++strangeHardwareLoop < 3)
goto strange_restart;

printf("illegal partition table - drive %02x sector %lu\n", drive,
if (scanType==SCAN_PRIMARYBOOT) printf("illegal partition table - drive %02x sector %lu\n", drive,
RelSectorOffset);
return PartitionsToIgnore;
}
Expand Down Expand Up @@ -1328,7 +1341,7 @@ void ReadAllPartitionTables(void)

if (InitKernelConfig.DLASortByDriveNo == 0)
{
/* printf("Drive Letter Assignment - DOS order\n"); */
if (InitKernelConfig.Verbose >= 1) printf("Drive Letter Assignment - DOS order\n");

/* Process primary partition table 1 partition only */
for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++)
Expand Down Expand Up @@ -1357,13 +1370,13 @@ void ReadAllPartitionTables(void)
{
UBYTE bootdrv = peekb(0,0x5e0);

/* printf("Drive Letter Assignment - sorted by drive\n"); */
if (InitKernelConfig.Verbose >= 1) printf("Drive Letter Assignment - sorted by drive\n");

/* Process primary partition table 1 partition only */
for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++)
{
struct DriveParamS driveParam;
if (LBA_Get_Drive_Parameters(HardDrive, &driveParam) &&
if (LBA_Get_Drive_Parameters(HardDrive, &driveParam, 0) &&
driveParam.driveno == bootdrv)
{
foundPartitions[HardDrive] =
Expand Down Expand Up @@ -1391,12 +1404,24 @@ void ReadAllPartitionTables(void)
ProcessDisk(SCAN_PRIMARY2, HardDrive, foundPartitions[HardDrive]);
}
}

if (InitKernelConfig.Verbose >= 0)
{
unsigned foundPartitionsCount = 0;
/* Tell user if no valid partitions found on any hard drive */
for (HardDrive = 0; HardDrive < nHardDisk; HardDrive++)
{
foundPartitionsCount += foundPartitions[HardDrive];
}
/* printf("Found %i partitions\n", foundPartitionsCount); */
if (!foundPartitionsCount) printf("No supported partitions found.\n");
}
}

/* disk initialization: returns number of units */
COUNT dsk_init()
{
if (InitKernelConfig.Verbose >= 0) printf(" - InitDisk");
if (InitKernelConfig.Verbose >= 0) printf("\nInitDisk\n");

#if defined(DEBUG) && !defined(DOSEMU)
{
Expand Down

0 comments on commit 7b0633b

Please sign in to comment.