Reading the parameters (BIOS) of hardware disk IDE/AT


To decode all their information
(Article written by Jean-François DUVIVIER published in LANGUAGE & SYSTEMS - INFOPC N°92 - May 1993)

 

The hard disk controllers for PC knew their first “Cultural revolution” with the arrival of the IBM/AT in 1984. This machine included a ST506 controller with encoding MFM Modified frequency Modulation (Western Digital origin) and a BIOS controlling the hard drive integrated out of standard in Bios of IBM AT.
For reasons of compatibility, all the following models and all the compatible ones incorporated the same type of Bios. Consequently, all the charts controllers of all the manufacturers and all technologies (ST506/MFM ST506/RLL and ESDD) function use the same registers and the same commands.

The first test of IDE hard disk goes back to 1986. It is the work of Imprimis (repurchased since by Seagate) which at the request of Compaq and with the assistance of Western Digital, incorporates a controller card PC compatible /AT on the hard drive. The marriage controller/disc makes it possible to reduce the component count and, especially to eliminate a chart in the machine. The idea gradually will make its way, Conner showing a precursor in the marketing of 3,5 inches IDE hard disk.

However the differences in interfaces as well as the incompatibilities of the discs between them slow down the diffusion of IDE hard disks.

The companies implied in the IDE create then in October 1988, a work group called the CAM (Common Access Method Commitee) to standardize the IDE under the name of ATA/AT Attachment, the document of description of the IDE is elaborated during the following months.

After several revisions, it becomes a proposal for a standard near the Years. The benefit of this standardization are felt since 1990 and lead same the manufacturers of discs to stop all their developments in technology ST506/MFM, ST506/RLL and ESDI. Only the SCSI, intelligent and powerful interface give access to discs of very great capacity and will remain with tidal wave IDE.

available commands:

A IDE hard disk reacts to commands which are addressed to it by 3 types :

Those which must obligatorily be implemented by the disc. It correspond in fact to the commands recognized by the first card controller used on the first IBM/AT

The BIOS of the machines containing 80286 processor (and superior) use them to fulfill all the functions of the interruption standard 1Bh.

Those which are specific to each manufacturer of hard drive, and which neither are documented, nor even diffused. They can be commands used for the tests during the manufacture of the hard disk, but also commands allowing a “fine” configuration of the internal plugs of the disc or a modification of the firmware (of which a part can be in PROM and another stored on the disc itself in an invisible place for the user, thus allowing a kind of remote loading.

Those which are optional and whose implementation is let with goodwill manufacturers of discs. They are however very clearly defined; so that they present the same codes and functionalities on all the discs. Mainly three big families there are found.

The first gathers commands making it possible to modify the consumption of the disc (Idle, Sleep, Standby) thanks to the gradual extinction of certain parts (electronics, motors…). The majority of the discs incorporated in the memo pads use these functionalities to prolong the autonomy of the batteries.

Second gathers commands authorizing reading or writing of several sectors at the same time (more powerful operation since only one command is sent to the disc for a group of consecutive sectors instead of a command for each sector), as well as the commands allowing the reading and the writing of a sector by using a channel DMA. However, as Bios do not use these commands because of sacro-holy “compatibility”, the majority of the discs do not implement them.

The drive command “Identify”

The last family includes only one command called “Identify drive”, which makes it possible to recover certain information on the hard disk. Although optional, this command in fact is always implemented and makes it possible “to read” a sector of 512 bytes whose format is given hereafter. Information is gathered by words of 16 bits (256 on the whole). Some of them only will interest the user:
The model of the disc. This information generally turns over the mark and the code allotted by the manufacturer of the disc. It thus makes it possible to identify very quickly and without opening the machine the model of the hard drive installed.

The serial number of the disc. In practice, certain discs do not present this information because the manufacturer did not envisage to register a variable table. The serial number is indeed the only difference being able to exist between two of the same discs model.

The version of the firmware, i.e. software implemented on the disc. Although it is much less prone to modification and correction that Bios of a machine, for example, the firmware of a disc can be the object of modifications, especially at the beginning of its marketing.

Characteristics of the disc, represented in the traditional form of the cylinders, heads and sectors per track. In general, the returned parameters are “logical”, i.e. they define the way in which one can reach the disc and not his real physical characteristics. Transcribing between logical and physical parameters was necessary to the beginning (in 1988-1989) in order to present 17 sectors by tracks, value which was traditional for discs MFM, and which certain software required.
This reason lost of its importance now, but transcribing is always necessary because of the original limitations of Bios which prohibit to define more than 1024 cylinders, whereas progress in the magnetic density made it possible to exceed this limit on a disc 3,5 inches. Moreover, Bios does not integrate either the possibility of using a disc presenting a number of variable sectors according to the tracks (one can indeed put more sector on the tracks (one can indeed put more sectors on the tracks external of the plate than those located more at the center). This technique, called ZBR (Zone Bit Recording), is very largely practised to increase the capacities of a disc. Certain discs, rare it is true, can indicate their truths “physical” parameters before transcribing. It was in particular the case of some Conner discs. One generally realizes some by a number of cylinders higher than 1024. In the case of the Quantum LPS105 which was used to us as test (see figure 1), one can affirm that the returned parameters are logical for two reasons.

On the one hand the low number of 17 sectors per track does not reflect the longitudinal densities that the manufacturers are able to reach today. As example technology RLL going back to 1987 already made it possible to obtain 26 sectors per track. In addition the number of heads (16) would suppose 8 plates which it is undoubtedly impossible to make hold in a 2,5 cm high disc. In fact, the LPS105 has two plates, therefore of 4 heads, with 1219 cylinders and a number of sector per track equal to 35 (inside), 42 (in the medium) or (outside 49).
The rate of transfer interns with the disc: The values suggested are in fact of the thresholds (5 and 10 megabits a second) and three bits of the word of configuration are used to indicate the performances of the disc compared to these thresholds. Of course, these rates of transfer are not those which one will find under DOS with a utility such as Coretest, but there exists a direct relationship: a disc having a better rate of transfer interns will be also more powerful under DOS.
The size and the type of the plug intern with the disc: The majority of the modern discs are equipped with a plug report allowing of the operations of “look-ahead” (anticipated reading of the sectors which follows that one has just read) as well as traditional mask (the repeated reading of the same sector will not cause any more a “physical” access to the disc starting from the second operation, since the data are already present in the plug of the disc). The size is important because it makes it possible to carry out a more important mask or to read a whole track ahead. The type of mask can take four different values: (0: plug not specified), 1 (plug monosector and mono-access), 2 (plug multi sector towards the disc and the computer) and 3 (identical to 2, with in addition to the possibilities of mask in reading). The higher the figure representing the type is, the more the plug is powerful.
Other information is also available, the such number of bytes ECC (error-correcting codes) or the possibilities of multisecteurs transfer or DMA.
The writing of the utility HDID which posts some of these parameters was carried out in mixed language (MSC and assembler). The part out of C allows the interpretation and the posting of the data while the assembler is adapted more to manage the dialogue with the disc. The interface between the two languages is done by means of a GetID function which admits in parameter a pointer towards the plug of 512 bytes, and whose composition is copied on table 1. The use of a structure allows an access simplified to each one of its elements. The call to the GetID function must transmit the address of this structure by means of the operator &. It should be noted that the three character strings ASCII returned by the disc must be reprocessed because the bytes two to two are reversed (low byte and high byte of each word). It is the goal of the function swab. It is also necessary to add the 0 to it which serves as terminating of chain in language C, because it he is not reproduced on the data returned by the disc.
Side assembler, the GetID function is defined like PUBLIC and preceded by the character _ (underscore), which is the convention for the functions C. In order to reach easily the parameters of a function C, it is of use to define a structure (Sgetid here) which will include/understand the BP register of course “pushé” at the beginning programs it to be used as pointer of pile, but also the return address to C (only one word since one work in small mode), then all the parameters of this function in the order of their appearance. The registers of segment must be safeguarded if they are modified during the execution of the routine assembler.
Seen PC, the hard drive presents eight registers (see table) located 1F0h at 1F7h. Some present different functions in reading and writing. HDID uses only three of them: the register of data (to read the parameters returned by the disc), the register Disc/Head to define the reached disc (00h for the first disc, 10:00 for the second) and the register Statute/Command to send the command. In reading, the Statute makes it possible to manage the state of the disc and to control the errors. The significance of the various bits is given hereafter

The sending of a command initially requires to authorize the IRQ 14 used by the disc to mean that it is ready to transfer the parameters. It is then necessary to make sure that the disc is ready to accept a command by testing the statute, then to charge the corresponding registers. When the disc has to carry out the command, it generates an interruption IRQ14 automatically treated by the BIOS which updates variable certain in its data field located in the segment 40h. It is enough to test one of these values to know if the IRQ14 were generated. In the affirmative, it is the signal of the availability of the parameters which can then be read starting from the register of data.
The program must take care well, at the time of all its operations, to maintain up to date the variables of Bios (in particular the copy of Status in 40h: 74h) in order not to disturb the later operation of the machine. The program C is compiled in small mode with MSC 6.0. The program assembler is assembled with a MASM 6.0. Following syntaxes were used:
Masm /MX hdida, hdida;
Cl hdid. C hdida.obj
Among the improvements which could be brought to version 1.00 of HDID, appear the parameter setting of the disc (0 or 1), the complete dump of the 512 bytes in hexadecimal form or the finer interpretation of the parameters coded in binary format.

Here you will find the source in C and ASM 8086 compiled with MASM 6.0 and Borland TurboC 6.0

Important Note: The program compiled ace so doesn' twork (errors in the article by reprinting the source and I still boat make this program working, so If you edge help you are welcome!)

C source hdid.c

ASM source hdida.asm

 

Other Resources here:

hdid.c

hdid.pas

hdid1.htm



Back to the Welcome page

Updated: July 24, 2010

matthieu.benoit@free.fr