Search code examples
assemblydosx86-16diskbios

Is INT13H (non extended) capable of accessing drives with more than 16 heads per cylinder?


I know that you need the INT 13H extended functions to access drives over 8GB in size. This question refers to standard INT 13H, function 02H.

I also know the old 504MB hard drive limit was a result of: 1024 cylinders x 16 heads x 63 sectors x 512 bytes = 528,482,304 bytes.

But was this hard drive limitation caused by Int 13h itself? Is there any particular reason the head number was limited to 16 when there is an entire byte of space (dh) for the head number? Obviously later on the standard was changed to allow head numbers up to 255 (which caused the 8GB limit)

The reason i'm asking is because i'm having trouble reading a sector that lies quite a ways into a hard disk. It lies over 3 gigabytes into the disk.

Its exact C/H/S offset is: Cylinder 485, Head 147, sector 47

And the code i'm using to attempt to read it is as follows:

mov bx, ds
mov es, bx        ;es takes ds
lea bx, secBuff   ;bx takes the offset of secBuff, a 512 byte buffer
mov ah, 2         ;function 2, read sectors
mov dl, 80h       ;source drive set to master drive
mov ch, 0e5h      ;lower 8 bits of cylinder number
mov dh, 93h       ;head number
mov cl, 6fh       ;upper 2 bits of cylinder number, 6 bit sector number
int 13h           ;read the sector into ds:secBuff

I know for a fact that the boot sector of the second partition lies at this C/H/S, i've quadruple checked using a disk editing program, but instead of loading the boot sector into secBuff, it just gets filled with zeros.

INT 13H returns an error code into AH after execution. The code it returns is 00h, which means that as far as it's concerned, the load was successful.

Can INT 13H handle head numbers greater than 16, or is it simply unable to access sectors that lie beyond the first 504MB, or maybe even 2GB of the drive?


Solution

  • (This post answers the question as asked. I haven't checked to see if absurdly long comment thread added any pertinent information that should have been incorporated into the question.)

    Whether the INT 13h CHS BIOS functions are capable of addressing sectors located on heads numbered 16 or higher depends on the BIOS. The oldest BIOS implementations don't provide any translation of CHS values, passing the cylinder, head and sector numbers directly through the drive interface unmodified. These BIOS implementations don't support drives with more than 16 heads because the standard IBM PC AT controller, the WD-1003, only supported 16 heads. Since the IDE CHS interface is backwards compatible with the WD-1003, this limit also applies to any IDE drive that (only) supports CHS addressing.

    Newer BIOSes will do some sort of translation, but what translation used hasn't been consistent. Modern BIOSes will convert the CHS values passed through the INT 13h into an LBA address using the emulated geometry reported by the BIOS and (if the drive doesn't support LBA addressing) back into CHS values using the geometry reported by the drive. However other translation schemes have been used (eg. using the upper two bits of the head value to extend the cylinder value.) Also even when the now standard CHS/LBA/CHS translation used, different BIOS implementations can use different emulated geometries for the same drive.

    If your BIOS doesn't use the modern CHS/LBA/CHS translation then you'll need to figure out what translation it does use. If your BIOS does use it and you've moved the drive between computers (or even potentially between controllers on the same PC) that use different emulated geometries then any CHS values stored in on the drive (eg. in the partition table, or FAT BPB) are no longer valid and you'll have to either ignore them or figure out how translate them. LBA values stored on the disk won't normally cause a problem as these remain the same regardless of emulated geometry.

    There's a comprehensive document titled How It Works -- CHS Translation by Hale Landis that describes how older BIOSes perform CHS translation in more detail than I've given above. In particular it describes 10 different BIOS types that may help identify what translation scheme your computer might be using. Note that this document is pretty old, so much of what it talks about actual operating systems doing is out of date.