NOTICE (18 Dec 99): See the file README.TXT! How It Works -- CHS Translation Plus BIOS Types, LBA and Other Good Stuff Part 1 of 2 Version 4b -- 24 Jun 99 by Hale Landis NOTE: A "!" at the left margin of the first line of a paragraph indicates that some change was made in that paragraph. Introduction (READ THIS!) ------------------------- This 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. History ------- Changes between this version and the preceeding version are marked by "!" at left margin of the first line of a changed or new paragraph. Version 4 -- BIOS Types 8 and 10 updated. Version 3 -- New BIOS types found and added to this list. More detailed information is listed for each BIOS type. A section describing CHS translation was added. Version 2 -- A rewrite of version 1 adding BIOS types not included in version 1. Version 1 -- First attempt to classify the BIOS types and describe what each does or does not do. Definitions ----------- * 528MB - The maximun drive capacity that is supported by 1024 cylinders, 16 heads and 63 sectors (1024x16x63x512). This is the limit for CHS addressing in the original IBM PC/XT and IBM PC/AT INT 13H BIOS. * 8GB - The maximum drive capacity that can be supported by 1024 cylinders, 256 heads and 63 sectors (1024x256x63x512). This is the limit for the BIOS INT 13H AH=0xH calls. * ATA - AT Attachment -- The real name of what is widely known as IDE. * CE Cylinder - Customer Engineering cylinder. This is the last cylinder in P-CHS mode. IBM has always reserved this cylinder for use of disk diagnostic programs. Many BIOS do not account for it correctly. It is of questionable value these days and probably should be considered obsolete. However, since there is no industry wide agreement, beware. There is no CE Cylinder reserved in the L-CHS address. Also beware of diagnostic programs that don't realize they are operating in L-CHS mode and think that the last L-CHS cylinder is the CE Cylinder. * CHS - Cylinder/Head/Sector. This is the traditional way to address sectors on a disk. There are at least two types of CHS addressing: the CHS that is used at the INT 13H interface and the CHS that is used at the ATA device interface. In the MFM/RLL/ESDI and early ATA days the CHS used at the INT 13H interface was the same as the CHS used at the device interface. 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. * EDPT - Enhanced fixed Disk Parameter Table -- This table returns additional information for BIOS drive numbers 80H and 81H. The EDPT for BIOS drive 80H is pointed to by INT 41H. The EDPT for BIOS drive 81H is pointed to by INT 46H. The EDPT is a fixed disk parameter table with an AxH signature byte. This table format returns two sets of CHS information. One set is the L-CHS and is probably the same as returned by INT 13H AH=08H. The other set is the P-CHS used at the drive interface. This type of table allows drives with >1024 cylinders or drives >528MB to be supported. The translated CHS will have <=1024 cylinders and (probably) >16 heads. The CHS used at the drive interface will have >1024 cylinders and <=16 heads. It is unclear how the IBM defined CE cylinder is accounted for in such a table. Compaq probably gets the credit for the original definition of this type of table. * FDPT - Fixed Disk Parameter Table - This table returns additional information for BIOS drive numbers 80H and 81H. The FDPT for BIOS drive 80H is pointed to by INT 41H. The FDPT for BIOS drive 81H is pointed to by INT 46H. A FDPT does not have a AxH signature byte. This table format returns a single set of CHS information. The L-CHS information returned by this table is probably the same as the P-CHS and is also probably the same as the L-CHS returned by INT 13H AH=08H. However, not all BIOS properly account for the IBM defined CE cylinder and this can cause a one or two cylinder difference between the number of cylinders returned in the AH=08H data and the FDPT data. IBM gets the credit for the original definition of this type of table. * LBA - Logical Block Address. Another way of addressing sectors that uses a simple numbering scheme starting with zero as the address of the first sector on a device. The ATA standard requires that cylinder 0, head 0, sector 1 address the same sector as addressed by LBA 0. LBA addressing can be used at the ATA interface if the ATA device supports it. LBA addressing is also used at the INT 13H interface by the AH=4xH read/write calls. * L-CHS -- Logical CHS. The CHS used at the INT 13H interface by the AH=0xH calls. See CHS above. * MBR - Master Boot Record (also known as a partition table) - The sector located at cylinder 0 head 0 sector 1 (or LBA 0). This sector is created by an "FDISK" utility program. The MBR may be the only partition table sector or the MBR can be the first of multiple partition table sectors that form a linked list. A partition table entry can describe the starting and ending sector addresses of a partition (also known as a logical volume or a logical drive) in both L-CHS and LBA form. Partition table entries use the L-CHS returned by INT 13H AH=08H. Older FDISK programs may not compute valid LBA values. * OS - Operating System. * P-CHS -- Physical CHS. The CHS used at the ATA device interface. This CHS is also used at the INT 13H interface by older BIOS's that do not support >1024 cylinders or >528MB. See CHS above. Background and Assumptions -------------------------- First, 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: * AH=08H, Get Drive Parameters -- This call is restricted to drives up to 528MB without CHS translation and to drives up to 8GB with CHS translation. For older BIOS with no support for >1024 cylinders or >528MB, this call returns the same CHS as is used at the ATA interface (the P-CHS). For newer BIOS's that do support >1024 cylinders or >528MB, this call returns a translated CHS (the L-CHS). The CHS returned by this call is used by FDISK to build partition records. * AH=41H, Get BIOS Extensions Support -- This call is used to determine if the IBM/Microsoft Extensions or if the Phoenix Enhanced INT 13H calls are supported for the BIOS drive number. * AH=48H, Extended Get Drive Parameters -- This call is used to determine the CHS geometries, LBA information and other data about the BIOS drive number. * the FDPT or EDPT -- While not actually a call, but instead a data area, the FDPT or EDPT can return additional information about a drive. * other tables -- The IBM/Microsoft extensions provide a pointer to a drive parameter table via INT 13H AH=48H. The Phoenix enhancement provides a pointer to a drive parameter table extension via INT 13H AH=48H. These tables are NOT the same as the FDPT or EDPT. 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 Algorithms -------------------------- NOTE: Before you send me email about this, read this entire section. Thanks! As you read this, don't 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. * An old BIOS (like BIOS type 1 below) does no CHS translation and does not use LBA. It only supports the AH=0xH calls: INT 13H (L-CHS == P-CHS) ATA AH=0xH --------------------------------> device (L-CHS) (P-CHS) * A newer BIOS may support CHS translation and it may support LBA at the ATA interface: 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) * A really new BIOS may also support the AH=4xH in addtion to the older AH\0xH calls. This BIOS must support all possible combinations of CHS and LBA at both the INT 13H and ATA interfaces: 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 where heads_per_cylinder and sectors_per_track are the current translation mode values. This algorithm can also be used by a BIOS or an OS to convert a L-CHS to an LBA as we'll see below. 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 While most OS's compute disk addresses in an LBA scheme, an OS like DOS must convert that LBA to a CHS in order to call INT 13H. Technically an INT 13H should follow this process when converting an L-CHS to a P-CHS: 1) convert the L-CHS to an LBA, 2) convert the LBA to a P-CHS, If an LBA is required at the ATA interface, then this third step is needed: 3) convert the P-CHS to an LBA. All of these conversions are done by normal arithmetic. However, while this is the technically correct way to do things, certain short cuts can be taken. It is possible to convert an L-CHS directly to a P-CHS using bit a bit shifting algorithm. This combines steps 1 and 2. And, if the ATA device being used supports LBA, steps 2 and 3 are not needed. The LBA value produced in step 1 is the same as the LBA value produced in step 3. AN EXAMPLE Lets look at an example. Lets say that the L-CHS is 1000 cylinders 10 heads and 50 sectors, the P-CHS is 2000 cylinders, 5 heads and 50 sectors. Lets say we want to access the sector at L-CHS 2,4,3. * step 1 converts the L-CHS to an LBA, lba = 1202 = ( ( 2 * 10 + 4 ) * 50 ) + 3 - 1 * step 2 converts the LBA to the P-CHS, cylinder = 4 = ( 1202 / ( 5 * 50 ) temp = 202 = ( 1202 % ( 5 * 50 ) ) head = 4 = ( 202 / 50 ) sector = 3 = ( 202 % 50 ) + 1 * step 3 converts the P-CHS to an LBA, lba = 1202 = ( ( 4 * 5 + 4 ) * 50 ) + 3 - 1 Most BIOS (or OS) software is not going to do all of this to convert an address. Most will use some other algorithm. There are many such algorithms. BIT SHIFTING INSTEAD If the L-CHS is produced from the P-CHS by 1) dividing the P-CHS cylinders by N, and 2) multiplying the P-CHS heads by N, where N is 2, 4, 8, ..., then this bit shifting algorithm can be used and N becomes a bit shift value. This is the most common way to make the P-CHS geometry of a >528MB drive fit the INT 13H L-CHS rules. Plus this algorithm maintains the same sector ordering as the more complex algorithm above. Note the following: Lcylinder = L-CHS cylinder being accessed Lhead = L-CHS head being accessed Lsector = L-CHS sector being accessed Pcylinder = the P-CHS cylinder being accessed Phead = the P-CHS head being accessed Psector = P-CHS sector being accessed NPH = is the number of heads in the P-CHS N = 2, 4, 8, ..., the bit shift value The algorithm, which can be implemented using bit shifting instead of multiply and divide operations is: Pcylinder = ( Lcylinder * N ) + ( Lhead / NPH ); Phead = ( Lhead % NPH ); Psector = Lsector; A BIT SHIFTING EXAMPLE Lets apply this to our example above (L-CHS = 1000,10,50 and P-CHS = 2000, 5, 50) and access the same sector at at L-CHS 2,4,3. Pcylinder = 4 = ( 2 * 2 ) + ( 4 / 5 ) Phead = 4 = ( 4 % 5 ) Psector = 3 = 3 As you can see, this produces the same P-CHS as the more complex method above. SO WHAT IS THE PROBLEM? The basic problem is that there is no requirement that a CHS translating BIOS followed these rules. There are many other algorithms that can be implemented to perform a similar function. Today, there are at least two popular implementions: the Phoenix implementation (described above) and the non-Phoenix implementations. SO WHY IS THIS A PROBLEM IF IT IS HIDDEN INSIDE THE BIOS? Because a protected mode OS that does not want to use INT 13H must implement the same CHS translation algorithm. If it doesn't, your data gets scrambled. WHY USE CHS AT ALL? In the perfect world of tomorrow, maybe only LBA will be used. But today we are faced with the following problems: * Some drives >528MB don't implement LBA. * Some drives are optimized for CHS and may have lower performance when given commands in LBA mode. Don't forget that LBA is something new for the ATA disk designers who have worked very hard for many years to optimize CHS address handling. And not all drive designs require the use of LBA internally. * The L-CHS to LBA conversion is more complex and slower than the bit shifting L-CHS to P-CHS conversion. * DOS, FDISK and the MBR are still CHS based -- they use the CHS returned by INT 13H AH=08H. Any OS that can be installed on the same disk with DOS must understand CHS addressing. * The BIOS boot processing and loading of the first OS kernel code is done in CHS mode -- the CHS returned by INT 13H AH=08H is used. * Microsoft has said that their OS's will not use any disk capacity that can not also be accessed by INT 13H AH=0xH. These are difficult problems to overcome in today's industry environment. The result: chaos. DANGER TO YOUR DATA! See the description of BIOS Type 7 below to understand why a WD EIDE BIOS is so dangerous to your data. ! AN INTERESTING TABLE The following table was created and used by T13 when discussing the various CHS and LBA problems in x86 PC BIOS. You may find it interesting. In many rows, both the drive's CHS and the resulting INT 13 translated CHS are shown. Any CHS with more than 16 heads is a translated CHS. ----------------------------------------------------------------- Number of Approx CHS Sectors Bytes Note ------------- ----------- ------- ------------------------- 1024 16 63 1,032,192 528.4MB Max w/o CHS translation. 8192 16 63 8,257,536 4.228GB This is the 15/16 head 1024 128 63 8,257,536 4,228GB boundary (see note 3). 16383 15 63 15,481,935 7.926GB Bit-shifting 1023 240 63 15,467,760 7.919GB BIOS max. 16384 15 63 15,482,880 7.927GB What a 1024 240 63 15,482,880 7.927GB nice fit. 1024 255 63 16,450,560 8.423GB LBA assisted BIOS max. 16383 16 63 16,514,064 8,455GB ID word 1, 3, 6 limit (per ATA annex). 16384 16 63 16,515,072 8.456GB Another nice fit but 1024 256 63 16,515,072 8.456GB we can't use it. 32768 16 63 33,030,144 16.91GB Valid drive CHS but no valid BIOS translation 65536 16 63 66,060,288 33.82GB Valid drive CHS but no valid BIOS translation. 65535 16 255 267,382,800 136.9GB CHS max drive size in ID words. 65536 16 255 267,386,880 136.9GB CHS max drive size addressable. 28-bit lba 268,435,456 137.4GB LBA max drive size. ----------------------------------------------------------------- Notes: 1) A drive really can't have 65536 cylinders, numbered 0 to 65535 (or FFFFH). The max number of cylinders is 65535, numbered 0 to 65534 (or FFFEH). This is because the maximum value in ID words 1 and 54 is 65535 (or FFFFH). But beware that a media access command could attempt to access cylinder number 65535 (or FFFFH). 2) LBA is able to address about 0.5GB more than CHS because there is no sector number 0 in CHS. 3) A drive that reports 16 heads in ID word 3 and more than 8192 cylinders in ID word 1 will cause a bit-shifting BIOS to use a CHS translation with 256 heads. Some operating systems save only the lower 8-bits of this value resulting in zero heads. Many bit-shitting BIOS will IDP such a drive to 15 heads, so that the translated CHS is 240 heads, in order to avoid this problem. /end of part 1 of 2 -- continued in part 2 of 2/