|
(追記) (追記ここまで) LBA to CHS TranslationCHS translation is needed only for disk drives between 528MB and 8GB. Below 528MB CHS addresses do not require translation. Above 8GB CHS addressing is not supported by ATA hard disk drives or by system BIOS software. Most systems are finally making the switch to using LBA addressing on all capacity drives. IntroductionThis is very technical. Please read carefully. There is lots of information here that can sound confusing the first time you read it. Why is an understanding of how a BIOS works so important? The basic reason is that the information returned by INT 13H AH=08H is used by FDISK, it is used in the partition table entries within a partition record (like the Master Boot Record) that are created by FDISK, and it is used by the small boot program that FDISK places into the Master Boot Record. The information returned by INT 13H AH=08H is in cylinder/head/sector (CHS) format, it is not in LBA format. The boot processing done by your computer's BIOS (INT 19H and INT 13H) is all CHS based. Read this so that you are not confused by all the false information going around that says "LBA solves the>528MB problem". Read this so that you understand the possible data integrity problem that a WD EIDE type BIOS creates. Any BIOS that has a "LBA mode" in the BIOS setup could be a WD EIDE BIOS. Be very careful and NEVER chage the "LBA mode" setting after you have partitioned and installed your software.
Definitions
Today we have CHS translating BIOS types that can use one CHS at the INT 13H interface and a different CHS at the device interface. These two types of CHS will be called the logical CHS or L-CHS and the physical CHS or P-CHS in this document. L-CHS is the CHS used at the INT 13H interface and P-CHS is the CHS used at the device interface. The L-CHS used at the INT 13 interface allows up to 256 heads, up to 1024 cylinders and up to 63 sectors. This allows support of up to 8GB drives. This scheme started with either ESDI or SCSI adapters many years ago. The P-CHS used at the device interface allows up to 16 heads up to 65535 cylinders, and up to 63 sectors. This allows access to 2^28 sectors (136GB) on an ATA device. When a P-CHS is used at the INT 13H interface it is limited to 1024 cylinders, 16 heads and 63 sectors. This is where the old 528MB limit originated. ATA devices may also support LBA at the device interface. LBA allows access to approximately 2^28 sectors (137GB) on an ATA device. A SCSI host adapter can convert a L-CHS directly to an LBA used in the SCSI read/write commands. On a PC today, SCSI is also limited to 8GB when CHS addressing is used at the INT 13H interface.
Background and AssumptionsFirst, please note that this is written with the OS implementor in mind and that I am talking about the possible BIOS types as seen by an OS during its hardware configuration search. It is very important that you not be confused by all the misinformation going around these days. All OS's that want to be co-resident with another OS (and that is all of the PC based OS's that I know of) MUST use INT 13H to determine the capacity of a hard disk. And that capacity information MUST be determined in L-CHS mode. Why is this? Because: 1) FDISK and the partition tables are really L-CHS based, and 2) MS/PC DOS uses INT 13H AH=02H and AH=03H to read and write the disk and these BIOS calls are L-CHS based. The boot processing done by the BIOS is all L-CHS based. During the boot processing, all of the disk read accesses are done in L-CHS mode via INT 13H and this includes loading the first of the OS's kernel code or boot manager's code. Second, because there can be multiple BIOS types in any one system, each drive may be under the control of a different type of BIOS. For example, drive 80H (the first hard drive) could be controlled by the original system BIOS, drive 81H (the second drive) could be controlled by a option ROM BIOS and drive 82H (the third drive) could be controlled by a software driver. Also, be aware that each drive could be a different type, for example, drive 80H could be an MFM drive, drive 81H could be an ATA drive, drive 82H could be a SCSI drive. Third, not all OS's understand or use BIOS drive numbers greater than 81H. Even if there is INT 13H support for drives 82H or greater, the OS may not use that support. Fourth, the BIOS INT 13H configuration calls are:
Note: The INT 13H AH=4xH calls duplicate the older AH=0xH calls but use a different parameter passing structure. This new structure allows support of drives with up to 2^64 sectors (really BIG drives). While at the INT 13H interface the AH=4xH calls are LBA based, these calls do NOT require that the drive support LBA addressing.
CHS Translation AlgorithmsAs you read this, do not forget that all of the boot processing done by the system BIOS via INT 19H and INT 13H use only the INT 13H AH=0xH calls and that all of this processing is done in CHS mode. First, lets review all the different ways a BIOS can be called to perform read/write operations and the conversions that a BIOS must support.
INT 13H (L-CHS == P-CHS) ATA AH=0xH --------------------------------> device (L-CHS) (P-CHS) INT 13H L-CHS ATA AH=0xH --+--> to --+----------------> device (L-CHS) | P-CHS | (P-CHS) | | | | P-CHS | +--> to --+ | LBA | | | | L-CHS | ATA +--> to -----------------+---> device LBA (LBA) INT 13H ATA AH=4xH --+-----------------------------> device (LBA) | (LBA) | | LBA +--> to ---------------+ P-CHS | | INT 13H L-CHS | ATA AH=0xH --+--> to --+------------+---> device (L-CHS) | P-CHS | (P-CHS) | | | | P-CHS | +--> to --+ | LBA | | | | L-CHS | ATA +--> to -----------------+---> device LBA (LBA) You would think there is only one L-CHS to P-CHS translation algorithm, only one L-CHS to LBA translation algorithm and only one P-CHS to LBA translation algorithm. But this is not so. Why? Because there is no document that standardizes such an algorithm. You can not rely on all BIOS's and OS's to do these translations the same way. The following explains what is widely accepted as the "correct" algorithms. An ATA disk must implement both CHS and LBA addressing and must at any given time support only one P-CHS at the device interface. And, the drive must maintain a strick relationship between the sector addressing in CHS mode and LBA mode. Quoting the ATA-2 document: LBA = ( (cylinder * heads_per_cylinder + heads ) * sectors_per_track ) + sector - 1 This algorithm can be reversed such that an LBA can be converted to a CHS: cylinder = LBA / (heads_per_cylinder * sectors_per_track) temp = LBA % (heads_per_cylinder * sectors_per_track) head = temp / sectors_per_track sector = temp % sectors_per_track + 1 |