EDN logo


Design Ideas: May 9, 1996

Assembly code reads IDE-drive parameters

John Foster,
Advanced Control Systems, Norcross, GA


Many older disk drives and most current models that interface with the ATA or IDE standard have readable configuration tables. These tables contain the manufacturer's identification data and data-organization parameters that you may need to configure your PC to properly access the drive. The ability to directly read this table eliminates the need to peruse data sheets, books, or even Web pages to obtain the drive's configuration parameters. So, if a situation occurs, such as losing the clock RAM data, installing new drives or reactivating existing ones becomes easier.

Because you must read the data with 16-bit I/O accesses, standard DOS Debug commands or program-I/O accesses may not work. However, you can use a small assembly-language code fragment to read the data from the IDE controller after manually requesting the drive-configuration table. To enter the code and issue IDE commands, you use the DOS Debug utility. If the hard-disk drive is not working, you must prepare a bootable, floppy disk containing Debug on another machine. Warning: If you're using a hard-disk drive, do not run Debug from a DOS window in Windows. Exit Windows to DOS before running Debug.

At the DOS prompt, enter these commands:

debug	
e 100	
1e_7_b9_0_1_ba_f0_1_bf_0_2_ed_88_c3_88_e0_88_dc_ab_e2_f6_eb_e8

(Note: The underline characters represent spacebar characters.)

The result should resemble the array in Figure 1. You then verify with the Unassemble command: u 100. The 13 instructions should match:

-u 100	
1D12:0100 1E 		PUSH DS	
1D12:0101 07 		POP ES	
1D12:0102 B90001	MOV CX,0100	
1D12:0105 BAF001	MOV DX,01F0	
1D12:0108 BF0002 	MOV DI,0200	
1D12:010B FC 		CLD	
1D12:010C ED 		IN AX,DX	
1D12:010D 88C3 		MOV BL,AL	
1D12:010F 88E0 		MOV AL,AH	
1D12:0111 88DC 		MOV AH,BL	
1D12:0113 AB 		STOSW	
1D12:0114 E2F6 		LOOP 010C	
1D12:0116 EBE8 		JMP 0100

You then select the drive with the command o 1f6,1. If you have two IDE drives and want to select the second one, the command is o 1f6,11. Finally, you load the command Identify Drive: o 1f7,ec to request configuration information. Then, verify that the configuration data is available with i 1f7. The answer should be 58. Other results, such as 51, indicate that your commands are unsupported, and you cannot obtain the configuration.

Assuming that you receive the valid answer, you can read the data by entering two commands, g,116 and g,100. Enter these commands exactly, because any error may lock the computer and cause other side effects. After entering the second command, you should obtain a response resembling the array in Figure 2. The drive data is in memory, starting at 200H. To display the data, enter the commands d 200 and d. The results should resemble the array in Figure 3.

The textual data areas should be legible strings visible on the right. The binary values are the hex data in the middle and are 16-bit (four hex digits) integers. The first seven such values, derived from Figure 3, give the following information about the drive organization:

1 flags (045C)	
2 cylinder count (02D3)	
3 reserved (0000)	
4 head count (000D)	
5 bytes per track (6600)	
6 bytes per sector (0200)	
7 sectors per track (0033).

Once you obtain these values, you can exit the Debug program with the command q. You can combine the values to give the drive capacity in bytes. First, convert the values from hexadecimal to decimal numbers. In this case, the cylinder count is 02D3=723, the head count is 000D=13, and the number of sectors per track is 0033=51. You multiply the product of these figures by 512 to obtain the drive capacity: 723 X 13 X 51 X 512=245,426,688 bytes, or 246 Mbytes. You can use the above parameters to set up the drive in the computer's BIOS setup logic. (DI #1861)


| EDN Access | feedback | subscribe to EDN! |
| design features | out in front | design ideas | departments | products | columnist |


Copyright © 1996 EDN Magazine. EDN is a registered trademark of Reed Properties Inc, used under license.