Chapter – 9
Handling Large Hard Disks
Handling Large Hard Disks
In the previous chapter, we discussed the BIOS-Disk functions and the use of interrupts to access the physical media of the hard disks. We used INT 13H functions there to access the hard disks.
The INT 13H interface supports many different commands such as reading, writing, formatting and verifying etc. that can be given to the BIOS, which then passes them on to the hard disk. As it has been used by DOS for a long time, INT13H has been the standard for many years.
The INT 13H allocates 24 bits for the specification of the geometry of the drive and requires the invoking program to know the specific parameters of the hard disk, and provide exact head, cylinder and sector addressing to the routines to allow disk access.
The BIOS uses the geometry for the hard disk as it is set up in the BIOS setup program. The 24 bits, allocated by the INT 13H interface for the specification of the drive geometry are broken up as follows:
- 10 bits for the cylinder number. Thus the maximum limit of total cylinders may be up to 1,024 cylinders.
- 8 bits for the head number. Thus the maximum limit of total heads is up to 256.
- 6 bits for the sector number. Thus a maximum total of sectors may be up to 63 sectors.
Thus the maximum sectors supported by this approach may be up to, 1024 * 256 * 63 = 16515072.
This means that the INT13H interface can support disks containing up to approximately 16.5 million sectors, which at 512 bytes per sector leads a maximum of 8.46 GB. That is exactly I want to explain. Thus by using all these functions or INT 13H, we can access the disks up to 8.46 GB only.
That is why, in recent years that the limitations of this old interface have caused it to be abandoned in favor of a new way of addressing hard disks, as described next in this chapter.
First of all, let me tell you a Story!
Eleven years ago, when I was in seventh standard, in my school, I heard about the hard disk with the capacity of 42 MB, perhaps it was WDA-L42 of IBM. It was really difficult for me and my friends to imagine such a big capacity of hard disk, that time.
The INT 13H methodology was developed about twenty years ago from today. You can now understand that an 8 GB hard disk was much bigger to fit even in dreams in that age. But today, if we talk about an 8 GB hard disk to any personal computer users, he may not like to use it saying it small in storage capacity.
This is the reason that INT 13H interface has finally come to the end of its usefulness in modern systems. INT 13H used 24 bits to allocate the disk geometry and unfortunately it was not possible to expand the existing INT 13H BIOS interface because if it was done, a lot of older hardware and software would stop working, and you can understand that the today’s computer market can never bear such a big change with millions of older software and hardware products to stop working.
Keeping this condition in mind, INT 13H has been replaced with a newer interface called INT 13H extensions. However INT 13H still may be used by DOS and some other older operating systems and for other compatibility purposes.
The new INT 13H interface uses 64 bits instead of 24 bits for addressing and allows a maximum hard drive size of 9.4 * 1021 bytes which is in fact 9.4 trillion gigabytes or 9400000000000 Gigabytes. I hope now we are relaxed for some time until this limit is broken.
Some Important functions of the Extension for Interrupt 13H has been described next. You can use these function in programming in the same way as you were using the functions of INT 13H. This is also a reason that these functions are called the extensions of INT 13H.
INT 13H Extensions:
INT 13H (0x13)
Function 1BH (0x1B or 27) --> Get Manufacturing Header (ESDI Fixed Disk)
Call with: AH = 1BH
AL = number of sector(s) to read
DL = drive
ES: BX = buffer for manufacturing header
(defect list)
Returns: If function successful
Carry flag = clear
AH = 00H
If function unsuccessful
Carry flag = set
AH = status
Comments:
This function is used to get the manufacturing header of the fixed disk. The first sector read contains the manufacturing header with the number of defect entries and the beginning of the defect map; the remaining sectors contain the remainder of the defect map. Manufacturing header format (Defect Map Record format) can be found in IBM 70MB, 115MB Fixed Disk Drives Technical Reference.
INT 13H (0x13)
Function 1BH (0x1B or 27) --> Get Pointer to SCSI Disk Information Block (Future Domain SCSI Controller)
Call with: AH = 1BH
DL = hard drive ID
Returns: If function successful
Carry flag = clear
AH = 01H
If function unsuccessful
Carry flag = set
AH = status
ES:BX = SCSI disk information block
Comments:
This function is used to get the pointer to SCSI Disk Information Block. This also sets a non-resettable flag which prevents some controller messages from being displayed.
INT 13H (0x13)
Function 1CH (0x1C or 28) --> Get Pointer to Free Controller Ram (Future Domain SCSI Controller)
Call with: AH = 1CH
DL = hard drive ID for any valid SCSI
hard disk
Returns: If function successful
Carry flag = clear
AH = 01H
If function unsuccessful
Carry flag = set
AH = status
ES:BX = first byte of free RAM on controller
Comments:
This function is used to get the free controller Ram. ES:BX points to the first byte of free RAM on the controller, available for other uses. ES contains the segment at which the controller resides. The two memory-mapped I/O ports of the controller are at offsets 1C00H and 1E00H.
INT 13H (0x13)
Function 1C08H (0x1C08) --> Get Command Completion Status (ESDI Fixed Disk)
Call with: AX = 1C08H
DL = drive
ES:BX = buffer for Command Complete
Status Block
Return: If function successful
Carry flag = clear
AH = 01H
If function unsuccessful
Carry flag = set
AH = status
Comments:
This Function is used to get the Command Completion Status. If the function is successful the carry flag is clear and if unsuccessful carry flag is set.
INT 13H (0x13)
Function 1C09H (0x1C09) --> Get Device Status (ESDI Fixed Disk)
Call with: AX = 1C09H
DL = drive
ES:BX = buffer for Device Status Block
Return: If function successful
Carry flag = clear
AH = 01H
If function unsuccessful
Carry flag = set
AH = status
Comments:
This Function is used to get the Device Status. If the function is successful the carry flag is clear and if unsuccessful carry flag is set.
INT 13H (0x13)
Function 1C0AH (0x1C0A) --> Get Device Configuration (ESDI Fixed Disk)
Call with: AX = 1C0AH
DL = drive
ES:BX = buffer for Drive Configuration Status
Block
Return: If function successful
Carry flag = clear
AH = 01H
If function unsuccessful
Carry flag = set
AH = status
Comments:
This Function is used to get the Device Configuration for the disk. If the function is successful, carry flag is clear and AH register is 01H else Carry flag is set and AH register Returns the Status. The following table shows the Format of ESDI Drive Configuration Status Block:
Offset
|
Size
|
Description
|
00H
|
Byte
|
09H
|
01H
|
Byte
|
number of words in block (06H)
|
02H
|
Byte
|
flags
|
03H
|
Byte
|
number of spare sectors per cylinder
|
04H
|
Double Word
|
total number of usable sectors
|
08H
|
Word
|
total number of cylinders
|
0AH
|
Byte
|
tracks per cylinder
|
0BH
|
Byte
|
sectors per track
|
INT 13H (0x13)
Function 1C0BH (0x1C0B) --> Get Adapter Configuration (ESDI Fixed Disk)
Call with: AX = 1C0BH
ES:BX = buffer for Controller Configuration
Status Block
Return: If function successful
Carry flag = clear
AH = 01H
If function unsuccessful
Carry flag = set
AH = status
Comments:
This Function is used to get the Adapter Configuration. If the function is successful the carry flag is clear and AH is 01H, if unsuccessful carry flag is set and AH returns the status.
INT 13H (0x13)
Function 1C0CH (0x1C0C) --> Get POS Information (ESDI Fixed Disk)
Call with: AX = 1C0CH
ES:BX = buffer for POS Information Status
Block
Return: If function successful
Carry flag = clear
AH = 01H
If function unsuccessful
Carry flag = set
AH = status
Comments:
This Function is used to get the POS Information. If the function is successful the carry flag is clear and AH is 01H, if unsuccessful carry flag is set and AH returns the status.
INT 13H (0x13)
Function 1C0EH (0x1C0E) --> Translate RBA to ABA (ESDI Fixed Disk)
Call with: AX = 1C0EH
CH = low 8 bits of cylinder number
CL = sector number (high two bits of
cylinder number in bits 6 and 7)
DH = head number
DL = drive number
ES:BX = ABA (Absolute Block Address)
number
Return: If function successful
Carry flag = clear
AH = 01H
If function unsuccessful
Carry flag = set
AH = status
Comments:
This Function translates the RBA (Relative Block Address) to ABA (Absolute Block Address). If the function is successful carry flag is clear and AH register is 01H, else Carry Flag is set and AH returns the status.
INT 13H (0x13)
Function 20H (0x20 or 32) --> Get Current Media Format (Compaq ATAPI Removable Media Device)
Call with: AH = 20H
DL = drive number
Return: If Function Successful,
Carry Flag = clear
AL = media type
AH = 00H
If Function Unsuccessful,
CF = set
AH = error code
Comments:
This Function is used to get the current media format. Values for Compaq/ATAPI diskette media type have been given in the following table:
Value
|
Media
|
03H
|
720K (1M unformatted)
|
04H
|
1.44M (2M unformatted)
|
06H
|
2.88M (4M unformatted)
|
0CH
|
360K
|
0DH
|
1.2M
|
0EH
|
Toshiba 3mode
|
0FH
|
NEC 3mode (1024 bytes per sectors)
|
10H
|
ATAPI Removable Media Device
|
INT 13H (0x13)
Function 21H (0x21 or 33) --> Read Multiple Disk Sectors (PS and PS/2, Hard Disks)
Call with: AH = 21H
AL = number of sectors to Read
CH = low byte of 12-bit cylinder number
CL = starting sector (bits 0 to 5) and bits 8
and 9 of cylinder (bits 6 and 7)
DH = head number (bits 0 to 5) and bits 10
and 11 of cylinder (bits 6 and 7)
DL = drive number
ES:BX = Data buffer to be read
Return: If Function Successful,
Carry flag = clear
ES:BX = Filled Data Buffer
If Function Unsuccessful,
Carry flag = set
AH = status
Comments:
The Function is used to read the multiple Disk sectors Using Multiple Block Mode, which generates an interrupt only after the end of transferring a group of sectors rather than after each sector.
INT 13H (0x13)
Function 22H (0x22 or 34) --> Write Multiple Disk Sectors (PS and PS/2, Hard Disks)
Call with: AH = 22H
AL = number of sectors to be written
CH = low byte of 12-bit cylinder number
CL = starting sector (bits 0 to 5) and bits 8
and 9 of cylinder (bits 6 and 7)
DH = head number (bits 0 to 5) and bits 10
and 11 of cylinder (bits 6 and 7)
DL = drive number
ES:BX = buffer containing data to be written
Return: If function Successful,
Carry Flag = clear
AH = 01H
If function Unsuccessful,
Carry Flag = Set
AH = Status
Comments:
The Function is used to write the multiple Disk sectors using Multiple Block Mode, which generates an interrupt only after the end of transferring a group of sectors rather than after each sector.
INT 13H (0x13)
Function 22H (0x22 or 34) --> Enable/Disable Cache (QuickCache II v4.20)
Call with: AH = 22H
AL = new state (00H, if disabled and 01H,
if enabled)
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = status
Comments:
This Function Enables and/or disables caching of all drives. If the function is successful the AX register is 0000H else returns the status.
INT 13H (0x13)
Function 23H (0x23 or 35) --> Set Controller Features Register (PS and PS/2, Hard Disk)
Call with: AH = 23H
AL = feature number
DL = drive number
Return: If Function Successful,
Carry Flag = Clear
If Function Unsuccessful,
Carry Flag = Set
AH = Status
Comments:
This Function is used to set the controller feature register. If the function is successful the carry flag is clear and if unsuccessful carry flag is set and AH register returns the status
INT 13H (0x13)
Function 24H (0x24 or 36) --> Set Multiple – Transfer Mode (Hard Disk, PS and PS/2)
Call with: AH = 24H
AL = number of sectors per block
DL = drive number
Return: If Function Successful,
Carry Flag = Clear
If Function Unsuccessful,
Carry Flag = Set
AH = Status
Comments:
This Function is used to set Multiple – Transfer Mode. If you want to disable the Multiple – Transfer Mode, set the number of sectors to 0. The maximum value for the block size (Such as 2,4,6,8 and 16 etc.) depends on the fixed disk drive type.
The value is stored in byte 15H of the fixed disk drive parameter table that is created by POST (Power On Self-Test). The byte at address 0040H:0074H is set to status of operation. The Values for PS/1 hard disk feature number have been listed in the following table:
Value
|
Description
|
01H
|
Select 8-bit data transfers instead of 16-bit
|
02H
|
Enable write cache
|
22H
|
Write Same, user-specified area
|
33H
|
Disable retries
|
44H
|
Set number of ECC bytes for read long/write long
|
54H
|
Set cache segments
|
55H
|
Disable look ahead
|
66H
|
Disable reverting to power-on defaults
|
77H
|
Disable error correction
|
81H
|
Select 16-bit data transfers (default)
|
82H
|
Disable write cache
|
88H
|
Enable error correction (default)
|
99H
|
Enable retries (default)
|
AAH
|
Enable look ahead
|
BBH
|
Set ECC length for read long/write long to four bytes
|
CCH
|
Enable reverting to power-on defaults
|
DDH
|
Write Same, entire disk
|
INT 13H (0x13)
Function 24H (0x24 or 36) --> Set Sectors (QuickCache II v4.20)
Call with: AX = 24H
BX = New number of sector buffers in
cache
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to set the Sectors. If the function is successful AX register is 0000H else AX returns the Status.
INT 13H (0x13)
Function 25H (0x25 or 37) --> Identify Drive (Hard Disk, PS and PS/2)
Call with: AH = 25H
DL = Drive number
ES:BX = Buffer of 512 bytes for reply packet
Return: If Function Successful,
Carry Flag = Clear
Buffer filled with drive information block
If Function Unsuccessful,
Carry Flag = Set
AH = Status
Comments:
This Function is used to identify the Drive. The byte at address 0040h:0074h is set to the status of the operation. IBM officially classifies this function as optional. The Bit fields for general drive configuration have been given in the following table:
Bit(s)
|
Description
|
0
|
Reserved (0)
|
1
|
Hard sectored
|
2
|
Soft sectored
|
3
|
Not MFM encoded
|
4
|
Head switch time greater than 15msec
|
5
|
Spindle motor control option implemented
|
6
|
Fixed drive
|
7
|
Removable cartridge drive
|
8
|
Disk transfer rate is less than or equal to 5Mbs
|
9
|
Disk transfer rate is greater than 5Mbs but less than or equal to 10Mbs
|
10
|
Disk transfer rate is greater than 10Mbs
|
11
|
Rotational speed tolerance is greater than 0.5%
|
12
|
Data strobe offset option available
|
13
|
Track offset option available
|
14
|
Format speed tolerance gap required
|
15
|
Reserved for non-magnetic drives (0)
|
The description of Format of Drive information block as given in the ATA (AT Attachment) Specification has been given in the next table:
Offset
|
Size
|
Description
|
00H
|
WORD
|
General drive configuration
|
02H
|
WORD
|
Number of cylinders
|
04H
|
WORD
|
Reserved
|
06H
|
WORD
|
Number of heads
|
08H
|
WORD
|
Number of unformatted bytes per track
|
0AH
|
WORD
|
Number of unformatted bytes per sector
|
0CH
|
WORD
|
Number of sectors per track
|
0EH
|
6 BYTES
|
Vendor unique
|
14H
|
20 BYTES
|
Serial number in ASCII, (0000H=not specified)
|
28H
|
WORD
|
Buffer type
|
2AH
|
WORD
|
Buffer size in 512 byte increments (0000H=not specified)
|
2CH
|
WORD
|
Number of ECC bytes passed on Read/Write Long commands 0000H = not specified
|
2EH
|
8 BYTES
|
Firmware revision in ASCII, 0000H=not specified
|
36H
|
40 BYTES
|
Model number in ASCII, 0000H=not specified
|
5EH
|
WORD
|
Bits 15-8 Vendor Unique, bits 7-0, (if 00H = Read/Write Multiple commands not Implemented, else xxH = Maximum number of sectors that can be transferred per interrupt on Read and Write Multiple Commands)
|
60H
|
WORD
|
0000H = Cannot perform Doubleword I/O,
0001H = Can perform Doubleword I/O.
|
62H
|
WORD
|
Bit 15-9 (0=reserved),
bit 8 (1=DMA Supported),
Bit 7-0 Vendor Unique.
|
64H
|
WORD
|
Reserved
|
66H
|
WORD
|
Bits 15-8 PIO data transfer cycle timing mode, Bits 7-0 Vendor Unique
|
68H
|
WORD
|
Bits 15-8 DMA data transfer cycle timing mode, Bits 7-0 Vendor Unique
|
6AH
|
WORD
|
Bits 15-1 reserved,
bit 0 (1=the fields reported in translation mode are valid,
0=the fields reported in translation mode may be valid)
|
6CH
|
WORD
|
Number of current cylinders
|
6EH
|
WORD
|
Number of current heads
|
70H
|
WORD
|
Number of current sectors per track
|
72H
|
DWORD
|
Current capacity in sectors
|
76H
|
>WORD
|
Reserved
|
78H
|
136 BYTES
|
Not defined
|
100H
|
64 BYTES
|
Vendor unique
|
140H
|
96 BYTES
|
Reserved
|
INT 13H (0x13)
Function 25H (0x25 or 37) --> Set Flush Interval (QuickCache II v4.20)
Call with: AH = 25H
BX = Interval of Flush
Return: If Function Successful,
AH = 0000H
If Function Unsuccessful,
AH = status
Comments:
This Function is used to set the Flush Interval. If the function is successful the AH is 0000H else AH returns the status.
INT 13H (0x13)
Function 26H (0x26 or 38) --> QuickCache II v4.20 Uninstall
Call with: AH = 26H
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = status
Comments:
AX returns status from 0001H to 00FFH for interrupt vector which was hooked by another TSR
INT 13H (0x13)
Function 27H (0x27 or 39) --> Installation Check (QuickCache II v4.20)
Call with: AH = 27H
BX = 0000H
Return: BH = Major Version
BL = Binary Minor Version
If installed,
AX = 0000H
BX = Non-zero
Comments:
If installed, AX Register is 0000H and BX returns Non-zero value.
INT 13H (0x13)
Function 28H (0x28 or 40) --> Set Automatic Dismount (QuickCache II v4.20)
Call with: AH = 28H
AL = New State
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
Call function with AL = 00H to Disable and with AL = 01H to Enable.
INT 13H (0x13)
Function 29H (0x29 or 41) --> No Operation (QuickCache II v4.20)
Call with: AH = 29H
Return: AX = 0000H
INT 13H (0x13)
Function 2AH (0x2A or 42) --> Set Buffer Size (QuickCache II v4.20)
Call with: AH = 2AH
AL = Buffer Size
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to set the buffer size. If the function is successful the AX is 0000H, if unsuccessful AX returns the status.
INT 13H (0x13)
Function 2BH (0x2B or 43) --> Drive Access Sounds (QuickCache II v4.20)
Call with: AH = 2BH
AL = new state (00h disabled, 01h
enabled)
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
If the function is successful the AX is 0000H, if unsuccessful AX returns the status. Call function with AL = 00H to Disable and AL = 01H to Enable Drive Access Sounds
INT 13H (0x13)
Function 2CH (0x2C or 44) --> Set Buffered Write (QuickCache II v4.20)
Call with: AH = 2CH
AL = new state
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This function enables or disables delayed writes for all drives. Use AH=38H to change a single drive. Use AL = 00H to Disable and 01H to Enable.
INT 13H (0x13)
Function 2DH (0x2D or 45) --> Set Buffered Read (QuickCache II v4.20)
Call with: AH = 2Dh
AL = new state (00h disabled, 01h
enabled)
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This function enables or disables read-ahead for all drives. Use AL = 00H to Disable and AL = 01H to Enable. Use AH=37H to change a single drive.
INT 13H (0x13)
Function 2EH (0x2E or 46) --> Set Flush Count (QuickCache II v4.20)
Call with: AH = 2EH
BX = Flush count
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to set the Flush Count. If the function is successful the AX is 0000H, if unsuccessful AX returns the status.
INT 13H (0x13)
Function 2FH (0x2F or 47) --> Force Immediate Incremental Flush (QuickCache II v4.20)
Call with: AH = 2FH
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
If the function is successful the AX is 0000H, if unsuccessful AX returns the status.
INT 13H (0x13)
Function 30H (0x30 or 48) --> Get Information (QuickCache II v4.20)
Call with: AH = 30H
AL = Information Number (See Table in
Comments)
DS:DX = buffer for info
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to get the different type of information about system, specified by AL. If the function is successful the AX is 0000H, if unsuccessful AX returns the status. AX = 8000H indicates the invalid Information specifier. Information numbers to be specified to AL, have been listed in the following table:
Value
|
Description
|
00H
|
System information
|
01H
|
Drive information
|
02H
|
Access frequency (Array of 30 words)
|
03H
|
Drive Index (Array of 32 bytes indicating BIOS drive for DOS drive)
|
INT 13H (0x13)
Function 31H (0x31 or 49) --> Reserve Memory (QuickCache II v4.20)
Call with: AH = 31H
BX = Number of paragraphs of
conventional memory to reserve for
Applications.
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to reserve the memory for applications. If the function is successful the AX is 0000H, if unsuccessful AX returns the status.
INT 13H (0x13)
Function 32H (0x32 or 50) --> Enable Caching For Specific Drive(QuickCache II v4.20)
Call with: AH = 32H
AL = drive number
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to enable caching for specific drive. For example, call Function with AL = 00H for A: and so on. If the function is successful the AX is 0000H, if unsuccessful AX returns the status.
INT 13H (0x13)
Function 33H (0x33 or 51) --> Disable Caching For Specific Drive (QuickCache II v4.20)
Call with: AH = 33H
AL = drive number
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to disable caching for specific drive. For example, call Function with AL = 00H for A: and so on. If the function is successful the AX is 0000H, if unsuccessful AX returns the status.
INT 13H (0x13)
Function 34H (0x34 or 52) --> Lock/Unlock Sector(s) (QuickCache II v4.20)
Call with: AH = 34H
AL = Locking/Unlocking function number
(See the Table Given in Comments)
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to call lock/unlock functions of sectors, specified by AL. If the function is successful the AX is 0000H, if unsuccessful AX returns the status. The different function numbers to be called with AL have been given in the following table:
Value
|
Function
|
00H
|
End sector locking/unlocking
|
01H
|
Lock all accessed sectors into cache
|
02H
|
Unlock all accessed sectors and discard from cache
|
INT 13H (0x13)
Function 35H (0x35 or 53) --> Set Lock Pool Size (QuickCache II v4.20)
Call with: AH = 35H
BX = Number of sectors in lock pool
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to set lock pool size. If the function is successful the AX is 0000H, if unsuccessful AX returns the status.
INT 13H (0x13)
Function 36H (0x36 or 54) --> Set Trace Buffer Size
Call with: AH = 36H
AL = New size of trace buffer
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to set the Trace Buffer Size. If the function is successful the AX is 0000H, if unsuccessful AX returns the status. This Function is usually called with Function 24H of INT 13H with AL=05H.
INT 13H (0x13)
Function 37H (0x37 or 55) --> Set Buffered Reads For Specific Drive (QuickCache II v4.20)
Call with: AH = 37H
AL = New state
DL = Drive number
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to set buffered reads for specific Drive. If AL = 00H the State is enable, else disable. If the function is successful the AX is 0000H, if unsuccessful AX returns the status.
INT 13H (0x13)
Function 38H (0x38 or 56) --> Set Buffered Writes for Specific Drive (QuickCache II v4.20)
Call with: AH = 38H
AL = New state
DL = Drive number
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to set buffered writes for specific Drive. If AL = 00H the State is enable, else disable. If the function is successful the AX is 0000H, if unsuccessful AX returns the status.
INT 13H (0x13)
Function 39H (0x39 or 57) --> Set Read Buffer Size for Specific Drive (QuickCache II v4.20)
Call with: AH = 39H
AL = New size of read buffer
DL = Drive number
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to set the Read Buffer size for Specific Drive such as DL = 00H for A: and so on. If the function is successful the AX is 0000H, if unsuccessful AX returns the status.
INT 13H (0x13)
Function 3AH (0x3A or 58) --> Set Write Buffer Size for Specific Drive (QuickCache II v4.20)
Call with: AH = 3AH
AL = New size of Write buffer
DL = Drive number
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to set the write Buffer size for Specific Drive such as DL = 00H for A: and so on. If the function is successful the AX is 0000H, if unsuccessful AX returns the status.
INT 13H (0x13)
Function 3DH (0x3D or 61) --> Enable/Disable Cylinder Flush for Drive (QuickCache II v4.20)
Call with: AH = 3DH
AL = New state
DL = drive number
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to Enable/Disable Cylinder flush for Specific Drive such as DL = 00H for A: and so on. If the function is successful the AX is 0000H, if unsuccessful AX returns the status. If AL register is set to 01H, state is enable, else disable.
INT 13H (0x13)
Function 3EH (0x3E or 62) --> Set Single-Sector Bonus (QuickCache II v4.20)
Call with: AH = 3EH
AL = New value for bonus
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to set the Single-Sector Bonus. If the function is successful the AX is 0000H, if unsuccessful AX returns the status.
INT 13H (0x13)
Function 3FH (0x3F or 63) --> Set Bonus Thrashold (QuickCache II v4.20)
Call with: AH = 3FH
AL = New value for bonus threshold
Return: If Function Successful,
AX = 0000H
If Function Unsuccessful,
AX = Status
Comments:
This Function is used to set the Bonus Threshold. If the function is successful the AX is 0000H, if unsuccessful AX returns the status
INT 13H (0x13)
Function 41H (0x41 or 65) --> Installation Check (IBM/MS INT 13H Extensions)
Call with: AH = 41H
BX = 55AAH
DL = Drive number (80H-FFH)
Return: If Extensions Supported and Function Successful,
Carry Flag = Clear
BX = AA55H
AH = Major version of extensions (See the
table in Comments)
AL = Internal use
CX = API subset support bitmap (See the
Table in Comments)
DH = Extension version (v2.0 and later)
If Extension not Supported or Function Unsuccessful,
Carry Flag = set
AH = 01H (Function Invalid)
Comments:
This function checks whether the IBM/MS INT 13H Extensions are installed and supported. Values for major versions of extensions have been given in the following table:
Value
|
Major Version of Extension
|
01H
|
1.x
|
20H
|
2.0 / EDD-1.0
|
21H
|
2.1 / EDD-1.1
|
30H
|
EDD-3.0
|
The Bit fields for IBM/MS INT 13H Extensions API support bitmap have been given in the following table:
Bit(s)
|
Description
|
0
|
Extended disk access functions (AH=42H, 43H, 44H, 47h and 48H) supported.
|
1
|
Removable drive controller functions (AH=45H, 46H, 48H, 49H, and INT15/AH =52H) supported.
|
2
|
Enhanced disk drive (EDD) functions (AH=48H and AH=4EH) supported. Extended drive parameter table is valid.
|
3-15
|
Reserved (0)
|
INT 13H (0x13)
Function 42H (0x42 or 66) --> Extended Read (IBM/MS INT 13H Extensions)
Call with: AH = 42H
DL = Drive number
DS:SI = Disk address packet (See the table in
comments)
Return: If Function Successful,
Carry Flag = Clear
AH = 00H
If Function Unsuccessful,
Carry Flag = Set
AH = error code
Comments:
This function is the extension for disk read function. If the function is successful carry flag is clear and AH register is 00H, else Carry flag is set and AH returns the error code. The block count field of disk address packet is set to number of blocks successfully transferred. The Format of disk address packet has been given below:
Offset
|
Size
|
Description
|
00H
|
BYTE
|
Size of Packet (10H)
|
01H
|
BYTE
|
Reserved (0)
|
02H
|
WORD
|
Number of blocks to transfer
|
04H
|
DWORD
|
Transfer buffer
|
08H
|
QWORD
|
Starting absolute block number (LBA)
|
INT 13H (0x13)
Function 43H (0x43 or 67) --> Extended Write (IBM/MS INT 13H Extensions)
Call with: AH = 43H
AL = write flags (See the table in
comments)
DL = drive number.
DS:SI = disk address packet
Return: If Function Successful,
Carry Flag = clear
AH = 00H
If Function Unsuccessful,
Carry Flag = set
AH = error code
Comments:
This function is the extension for disk write function. If the function is successful carry flag is clear and AH register is 00H, else Carry flag is set and AH returns the error code. The block count field of disk address packet is set to number of blocks successfully. The information of write flags for different versions has been given in the following table:
Version 1.0 and 2.0
|
Version 2.1 and later
|
Value
|
Description
|
Value
|
Description
|
Bit 0
|
Verify Write
|
00H and 01H
|
Write without Verify
|
Bits 1 to 7
|
Reserved (0)
|
02H
|
Write with verify
|
INT 13H (0x13)
Function 44H (0x44 or 68) --> Verify Sectors (IBM/MS INT 13H Extensions)
Call with: AH = 44H
DL = drive number
DS:SI = disk address packet
Return: If Function Successful,
Carry Flag = Clear
AH = 00H
If Function Unsuccessful,
Carry Flag = Set
AH = error code
Comments:
This function is the extension for Verify Sectors function. If the function is successful carry flag is clear and AH register is 00H, else Carry flag is set and AH returns the error code. The block count field of disk address packet is set to number of blocks successfully
INT 13H (0x13)
Function 45H (0x45 or 69) --> Lock/Unlock Drive (IBM/MS INT 13H Extensions)
Call with: AH = 45H
AL = Operation Number (See the Table in
comments)
DL = Drive number
Return: If Function Successful,
Carry Flag = Clear
AH = 00H
AL = Lock State (00H = Unlocked)
If Function Unsuccessful,
Carry Flag = Set
AH = Error code
Comments:
This function is used to Lock/Unlock the drive. This function is required to be supported for any removable drives numbered 80H or higher. Up to 255 locks may be placed on a drive, and the media will not be physically unlocked until all locks have been removed.
If the function is successful carry flag is clear and AH register is 00H, else Carry flag is set and AH returns the error code.
Operation numbers for different Lock/Unlock operation of the drive have been given in the following table:
Value
|
Function
|
00H
|
Lock media in drive
|
01H
|
Unlock media
|
02H
|
Check lock status
|
INT 13H (0x13)
Function 46H (0x46 or 70) --> Eject Media (IBM/MS INT 13H Extensions)
Call with: AH = 46H
AL = 00H (reserved)
DL = Drive number
Return: If Function Successful,
Carry Flag = Clear
AH = 00H
If Function Unsuccessful,
Carry Flag = Set
AH = error code
Comments:
This function is to eject media. If the function is successful carry flag is clear and AH register is 00H, else Carry flag is set and AH returns the error code.
INT 13H (0x13)
Function 47H (0x47 or 71) --> Extended Seek (IBM/MS INT 13H Extensions)
Call with: AH = 47H
DL = Drive number
DS:SI = Disk address packet
Return: If Function Successful,
Carry Flag = Clear
AH = 00H
If Function Unsuccessful,
Carry Flag = Set
AH = error code
Comments:
This function is the extension for seek function. If the function is successful carry flag is clear and AH register is 00H, else Carry flag is set and AH returns the error code. The block count field of disk address packet is set to number of blocks successfully.
INT 13H (0x13)
Function 48H (0x48 or 72) --> Get Drive Parameters (IBM/MS INT 13H Extensions)
Call with: AH = 48H
DL = Drive (80H-FFH)
DS:SI = Buffer for drive parameters
Return: If Function Successful,
Carry Flag = Clear
AH = 00H
DS:SI = Buffer filled
If Function Unsuccessful,
Carry Flag = Set
AH = Error code
Comments:
This function is used to get the drive parameters. If the function is successful carry flag is clear and AH register is 00H with DS:SI of Filled buffer, else Carry flag is set and AH returns the error code.
INT 13H (0x13)
Function 49H (0x49 or 73) --> Extended Media Change (IBM/MS INT 13H Extensions)
Call with: AH = 49H
DL = Drive number (any drive number, see
Comments)
Return: If media has not been changed,
Carry Flag = Clear
AH = 00H
If media may have been changed,
Carry Flag = Set
AH = 06H (Error code for media change)
Comments:
This function is the extension for media change function. If the function is successful carry flag is clear and AH register is 00H, else Carry flag is set and AH returns the error code.
The main difference in this function and function AH = 16H of INT 13H is that we may specify any drive number, where Function 16H allows only drive number 00H to 7FH of floppy disks.
INT 13H (0x13)
Function 4AH (0x4A or 74) --> Initiate disk Emulation (Bootable CD-ROM)
Call with: AH = 4AH
AL = 00H
DS:SI = Specification packet (see the Table in comments)
Return: If Function Successful,
Carry Flag = Clear
If Function unsuccessful,
Carry Flag = Set
AX = Status Code
Comments:
This Function is used to initiate the disk emulation. If the function is successful carry flag is clear, else carry flag is set and AX register returns status code and drive will not be in emulation mode.
The Format of Bootable CD-ROM Specification Packet has been given in the following table:
Offset
|
Size
|
Description
|
00H
|
BYTE
|
Size of packet in bytes (13H)
|
01H
|
BYTE
|
Boot media type
|
02H
|
BYTE
|
Drive Number
Drive Number
|
Drive Description
|
00H
|
Floppy image
|
80H
|
Bootable hard disk
|
81H to FFH
|
Non bootable or no Emulation
|
|
03H
|
BYTE
|
CD-ROM controller number
|
04H
|
DWORD
|
Logical Block Address of disk image to Emu
|
08H
|
WORD
|
Device Specification
Value
|
Description
|
(IDE) Bit 0
|
Drive is slave instead of master
|
(SCSI) Bits 0 to 7
|
LUN (Logical Unit Number) and PUN (Physical Unit Number)
|
Bits 8 to 15
|
Bus Number
|
|
0AH
|
WORD
|
Segment of 3Kb buffer for caching CD-ROM reads
|
0CH
|
WORD
|
Load segment for initial boot image (if 0000H, load at segment 07C0H)
|
0EH
|
WORD
|
Number of 512-byte virtual sectors to load (only valid for Function 4CH of INT 13H)
|
10H
|
BYTE
|
Low byte of cylinder count (for Function 08H of INT 13H)
|
11H
|
BYTE
|
Sector count, high bits of cylinder count (for Function 08H of INT 13H)
|
12H
|
BYTE
|
Head count (for Function 08H of INT 13H)
|
The Bit fields for Bootable CD-ROM boot media type have been given in the following table:
Bit(s)
|
Description
|
3-0
|
Media type
Value
|
Description
|
0000
|
No emulation.
|
0001
|
1.2M diskette.
|
0010
|
1.44M diskette.
|
0011
|
2.88M diskette.
|
0100
|
Hard disk (drive C:)
|
Other
|
Reserved
|
|
5-4
|
Reserved (0)
|
6
|
Image contains ATAPI driver
|
7
|
Image contains SCSI driver(s)
|
INT 13H (0x13)
Function 4B00H (0x4B00) --> Terminate Disk Emulation (Bootable CD-ROM)
Call with: AX = 4B00H
DL = Drive number (or 7FH to terminate
all emulations)
DS:SI = Empty specification packet
Return: If Function Successful,
Carry Flag = Clear
If Function Unsuccessful,
Carry Flag = Set
AX = Status code
DS:SI = Specification packet filled
Comments:
This Function is used to terminate the disk emulation. If you want to terminate all emulations, call the function with DL = 7FH. If the Function is successful, the carry flag is clear, else carry flag is set and AX register returns status code and the drive remains in emulation mode.
INT 13H (0x13)
Function 4B01H (0x4B01) --> Get Status (Bootable CD-ROM)
Call with: AX = 4B01H
DL = Drive number
DS:SI = Empty specification packet
Return: If Function Successful,
Carry Flag = Clear
If Function Unsuccessful,
Carry Flag = Set
AX = Status code
DS:SI = Specification packet filled
Comments:
The Function is used to get the status. If the Function is successful, the carry flag is clear, else carry flag is set and AX register returns status code
INT 13H (0x13)
Function 4CH (0x4C or 76) --> Initiate Disk Emulation and Boot (Bootable CD-ROM)
Call with: AH = 4CH
AL = 00H
DS:SI = Specification packet
Return: If Function Successful,
Nothing
If Function Unsuccessful,
Carry Flag = Set
AX = Status code
Comments:
This Function is used to Initiate the disk Emulation and boot the system. If the function is successful, returns nothing else the carry flag is set and AX register returns the status code.
INT 13H (0x13)
Function 4D00H (0x4D00) --> Return Boot Catalog (Bootable CD-ROM)
Call with: AX = 4D00H
DS:SI = Command packet (See the Table in
comments)
Return: If Function Successful,
Carry Flag = Clear
If Function Unsuccessful,
Carry Flag = Set
AX = Status code
Comments:
This function is used to return the boot catalog. If the Function is successful, the carry flag is clear, else carry flag is set and AX register returns status code. The Format of Bootable CD-ROM of "Get Boot Catalog" command packet has been given in the following table:
Offset
|
Size
|
Description
|
00H
|
BYTE
|
Size of packet in bytes (08H)
|
01H
|
BYTE
|
Number of sectors of boot catalog to read
|
02H
|
DWORD
|
Buffer for boot catalog
|
06H
|
WORD
|
First sector in boot catalog to transfer
|
INT 13H (0x13)
Function 4EH (0x4E or 78) --> Set Hardware Configuration (IBM/MS INT 13H Extensions v2.1)
Call with: AH = 4EH
AL = Function Number ( See the Table in comments)
DL = Drive number
Return: If Function Successful,
Carry Flag = Clear
AH = 00H
If Function Unsuccessful,
Carry Flag = Set
AH = error code
AL = Status
Comments:
This Function is used to set the hardware configuration. The function numbers for AL to call this Function have been given in the following table:
Value
|
Description
|
00H
|
Enable prefetch
|
01H
|
Disable prefetch
|
02H
|
Set maximum PIO transfer mode
|
03H
|
Set PIO mode 0
|
04H
|
Set default PIO transfer mode
|
05H
|
Enable INT 13H DMA maximum mode
|
06H
|
Disable INT 13H DMA
|
DMA and PIO modes are mutually exclusive therefore selecting DMA disables PIO for either the specified device or all devices on that controller and selecting PIO disables DMA
INT 13H (0x13)
Function 5001H (0x5001) --> Send Packet Command (Enhanced Disk Drive Spec v3.0)
Call with: AX = 5001H
DL = Drive number
ES:BX = Command packet (See the Table in
comments)
Return: If Function Successful,
Carry Flag = Clear
AH = 00H
If Function Unsuccessful,
Carry Flag = Set
AH = error code
Comments:
This function is used to send the packet commands. If the function is successful carry flag is clear and AH register is 00H, else Carry flag is set and AH returns the error code. The Format of Enhanced Disk Drive Spec v3.0 command packet has been given in the following table:
Offset
|
Size
|
Description
|
00H
|
WORD
|
Signature B055H
|
02H
|
BYTE
|
Length of packet in bytes
|
03H
|
BYTE
|
Reserved (0)
|
04H
|
N BYTEs
|
Formatted packet data
|
INT 13H (0x13)
Function 5501H (0x5501) --> Inquiry (Seagate ST01/ST02)
Call with: AX = 5501H
DH = Number of bytes to transfer
DL = Drive Number
ES:BX = Buffer for results
Return
ES:BX buffer, filled with the Inquiry results.
Comments:
This function is used to send inquiry. The ST01/ST02 BIOS does not return any success or failure indication for the function therefore all the commands must be assumed to have been successful.
The ST01/ST02 BIOS always maps its drives after the previous BIOS drives without changing the BIOS drive count at 0040H:0075H. This command is identical to the SCSI Inquiry command
INT 13H (0x13)
Function 5502H (0x5502) --> Reserved (Seagate ST01/ST02)
INT 13H (0x13)
Function 5503H (0x5503) --> Set DTQ (Device Type Qualifier) (Seagate ST01/ST02)
Call with: AX = 5503H
DH = DTQ byte (See the table in
comments)
DL = Drive Number
Return: Nothing
Comments:
This function is used to set the DTQ (Device Type Qualifier). The Function returns nothing. The Bit fields for DTQ byte have been shown in the following table:
Bit(s)
|
Description
|
0
|
Seagate installation software present
|
1
|
Selected drive has been installed
|
2
|
Host Adapter checks parity on the selected drive
|
3
|
Selected drive is ST225N
|
4
|
Selected drive is paired ST225N/NP
|
5
|
Reserved
|
6
|
SCSI drive attached
|
7
|
Reserved
|
INT 13H (0x13)
Function 5504H (0x5504) --> Return Identification (Seagate ST01/ST02)
Call with: AX = 5504H
DL = Drive Number
Return:
AX = 4321H
BL = selected drive number (00H, 01H)
BH = number of drives attached to Host
Adapter
Comments:
Function is used to return the identification of the drive(s).
INT 13H (0x13)
Function 5505H (0x5505) --> Park Heads (Seagate ST01/ST02)
Call with: AX = 5505H
DL = Drive Number
DH = Sub function (see the comments)
Return:
Nothing
Comments:
The function is used to park the heads of the disk. It was used in the old hard disk disks however the modern hard disks do not need any external program to park their heads.
The Sub function 00H parks the heads (SCSI Stop command) and Sub function 01H un-park the heads (SCSI Start command) of the disk.
INT 13H (0x13)
Function 5506H (0x5506) --> SCSI Bus Parity (Seagate ST01/ST02)
Call with: AX = 5506H
DL = Drive Number
DH = Sub function Number (See
Comments)
Return:
AL = Status (00H parity checking
disabled, 01H parity checking enabled)
Comments:
Call the function with the following sub function number for DH:
Value
|
Description
|
00H
|
Disable parity check
|
01H
|
Enable parity check
|
02H
|
Return current parity setting
|
INT 13H (0x13)
Function 5507H (0x5507) To Function 550DH (0x550D) --> Reserved Functions (Seagate ST01/ST02)
Call with: AX = 5507H to AX = 550DH
Comments:
These Functions have been officially listed as "Reserved"
INT 13H (0x13)
Function A0H (0xA0 or 160) --> Get Resident Code Segment (Super PC-Kwik v3.20 and Later)
Call with: AH = A0H
SI = 4358H
Return:
AX = Segment of Resident Code
Comments:
This function is used to get the resident code segment. AX returns the segment of resident code.
INT 13H (0x13)
Function A1H (0xA1 or 161) --> Flush Cache (Super PC-Kwik v3.20 and Later)
Call with: AH = A1H
SI = 4358H
Return:
Carry Flag = Clear
AH = 00H (v5.10)
Comments:
The Function is used to flush the cache.
INT 13H (0x13)
Function A3H (0xA3 or 163) --> Disable Cache (Super PC- Kwik v3.20 and Later)
Call with: AH = A3H
SI = 4358H
Return:
Carry Flag = Clear
Comments:
Function is used to disable the cache.
INT 13H (0x13)
Function A4H (0xA4 or 164) --> Enable Cache (Super PC-Kwik v3.20 and Later)
Call with: AH = A4H
SI = 4358H
Return:
Carry Flag = Clear
Comments:
This function is used to enable cache.
INT 13H (0x13)
Function EEH (0xEE or 238) --> Set 1024-Cylinder Flag (SWBIOS)
Call with: AH = EEH
DL = Drive Number
Return:
Carry Flag = Clear
AH = 00H
Comments:
The Function is used to Set 1024 – Cylinder flag. The flag is cleared by all INT 13H calls except AH=EEH and AH=EFH. Disk Manager also supports these calls. This function is equivalent to calling Function AH=EFH with CX=0400H for the software which supports that call.
This function is also supported by HyperDisk v4.01 and later, and PC-Cache v5.5 and later, in order to allow caching of drives using SWBIOS to access more than 1024 cylinders.
INT 13H (0x13)
Function EFH (0xEF or 239) --> Set Cylinder Offset (Ontrack Drive Rocket)
Call with: AH = EFH
CX = Cylinder offset for next INT 13H call
DL = Drive Number
Return:
Carry Flag = Clear
AH = 00H
Comments:
The Function is used to set Cylinder offset. For software which supports this call, the Function AH=EEH is equivalent to calling this function with CX=0400H. The cylinder offset is reset to 0 by all INT 13H called except AH=EEH and AH=EFH.
INT 13H (0x13)
Function F9H (0xF9 or 249) --> Installation Check (SWBIOS)
Call with: AH = F9H
DL = Drive Number
Return: If Function Successful,
Carry Flag = Clear
DX = Configuration Word (see comments)
If Function Unsuccessful,
Carry Flag = Set
Comments:
This Function is used for installation Check. If the Function is successful carry flag is clear and DX returns the configuration word, else carry flag is set.
Bit 15 is set if other SWBIOS extensions are available. Disk Manager also supports these calls.
INT 13H (0x13)
Function FEH (0xFE or 254) --> Get Extended Cylinder Count (SWBIOS)
Call with: AH = FEH
DL = Drive Number
Return:
Carry Flag = Clear
DX = Number of Cylinders beyond 1024
on drive
Comments:
This function is used to get the extended Cylinder count. The function AH = 08H of INT 13H will return a cylinder count truncated to 1024. BIOS without this extension would return count modul 1024. Disk Manager also supports these calls
INT 13H (0x13)
Function FFH (0xFF or 255) --> Officially Private Function (IBM SurePath BIOS)
INT 13H (0x13)
Function FFFFH (0xFFFF) --> Set Turbo Mode (UNIQUE UX Turbo Utility)
Call with: AX = FFFFH
BH = AAH
BL = Sub Function Number (See the table
in Comments)
Return: If installed,
AX = 1234H
Comments:
This function is used to set the Turbo Mode. The Sub function numbers to call the function with BL have been given in the following table:
Value
|
Description
|
00H
|
Installation check
|
01H
|
Turn on Turbo mode
|
02H
|
Turn off Turbo mode
|
03H
|
Set Turbo mode according to hardware switch
|
04H
|
Set disk access to Turbo mode
|
05H
|
Set disk access to Normal mode
|
How to use INT 13H Extensions in C Programming
We can call the Extension Functions of INT 13H with the same C functions (int86(), int86x() etc.) , which we were using in the earlier chapters. Let us learn it by an example.
The following example gives the focus to the three functions (Check Extensions present, extended read and extended write). However we are not going to use extended write function in this chapter.
The program first checks if extensions are supported or not if the extensions are present for INT 13H, It reads the absolute sector 0 (thus MBR) of the disk. The coding of the program proceeds in the following manner:
/* Program to access sectors beyond 8.46 GB using INT 13 BIOS extensions */
#include<stdio.h>
#include<dos.h>
/* Assigns the identifier to the data type */
typedef unsigned char Byte;
typedef unsigned int Word;
typedef unsigned long DWord;
/* disk_packet structure is loaded in DS:SI and command executed */
struct disk_packet
{
Byte size_pack; // Size of packet must be 16 or 16+
Byte reserved1; // Reserved
Byte no_of_blocks;// Number of blocks for transfer
Byte reserved2; // Reserved
/* Address in Segment:Offset format */
Word offset; //offset address
Word segment; //segment address
/* To Support the Disk Even of Capacity of 1152921504.607 GB */
DWord lba1;
DWord lba2;
}
disk_pack;
/* Function to check if the Extensions are supported */
void check_ext_present()
{
union REGS inregs, outregs; /* Input Registers and
Output */
inregs.h.ah=0x41; /* Function to Check
Extension Present */
inregs.x.bx=0x55AA;
inregs.h.dl=0x80; /* Drive No for first Hard Disk */
int86(0x13,&inregs,&outregs); /*Call interrupt */
if(outregs.x.cflag)
{
/* Extension Not Supported */
printf("\nBios extension not supported");
exit(1);
}
if(outregs.x.bx==0xAA55)
if(outregs.x.cx & 0x1)
/* Extension Present */
printf("\nExtended I/O supported");
}
/* Function to read the Sector */
void read_sectors(void *buffer)
{
union REGS inregs, outregs; /* Input and Output
Registers */
struct SREGS segregs; // Segment Registers
disk_pack.size_pack=16; // Set size to 16
disk_pack.no_of_blocks=1; // One block
disk_pack.reserved1=0; // Reserved Word
disk_pack.reserved2=0; // Reserved Word
disk_pack.segment=FP_SEG(buffer);// Segment of buffer
disk_pack.offset=FP_OFF(buffer); // Offset of buffer
/* request for MBR of hard disk 1 */
/* Read Absolute sector 0 */
disk_pack.lba1=0; /* LBA address, Contains first
32 bits */
/* We normally require( drives < 2.1 T.B) to set
only this */
disk_pack.lba2=0; // Last 32 bit address
inregs.h.ah=0x42; // Function to read
inregs.h.dl=0x80; // Drive Number for First Hard Disk inregs.x.si = FP_OFF(&disk_pack); /*Make DS:SI point
to disk_pack */
segregs.ds = FP_SEG(&disk_pack);
/* Call Interrupt */
int86x(0x13,&inregs,&outregs,&segregs);
if(outregs.x.cflag)
printf("\n\nError %d\n",outregs.h.ah);
else
printf("\n\nI hope Everything is all Right");
}
//// Write Sector Function \\\\
void write_sector()
{
/* It will be written in the same way as read_sectors function, except Function Number, which will be 0x43 in this function. We’ll discuss extended write function in next chapters.
Before Using this Function please check and verify what are you going to do. You should have the proper knowledge of what you are going to do. Use of this function in lack of knowledge or carelessly may destroy your data. */
}
/// Main Function \\\\
void main()
{
int i=0;
/* buffer to hold MBR */
Byte mbr[512];
clrscr();
/* check for BIOS extension present */
check_ext_present();
/* read sector */
read_sectors(&mbr);
printf("\n\n Data of MBR \n");
printf("▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀\n\n\n");
while(i++<512)
{
/* display the MBR buffer */
printf("%c",mbr[i]);
}
}
Comments on Coding of the program
typedef Assigns the identifier to the data type such that typedef unsigned char Byte; assigns identifier Byte for the data type char. Similarly identifier Word is assigned to int and DWord is assigned to long.
The disk_packet structure is loaded in DS:SI and the command (such as extended read, extended write or verify etc.) is executed. See the functions of IBM/MS INT 13H Extensions (Function 41H to Function 49H) given before.
The check_ext_present() function checks if the extensions are available/supported or not. The function is called with BX=55AAH (inregs.x.bx=0x55AA;) and if extensions are supported the BX register is set to AA55H. (See Function 41H given before)
The Function read_sectors is used to read the absolute sector of the disk, specified by disk_pack.lba1. In this program we have given disk_pack.lba1=0, thus we are going to read the absolute sector 0 (See the Note Below) thus going to read the MBR of the disk.
The write_sector function is also same as the read_sectors function and will be written in the same way but with the different Function options. We shall use it in the next chapters.
Note:
We read the disk sectors in the following two ways:
- Relative Sector Read (or Write)
- Absolute Sector Read (or Write)
In Relative Sector Read we read the disk sectors in accordance with CHS (Cylinder, Head and Sector) geometry of the disk. In relative sector read the MBR of the disk (First Sector of the disk) is on Cylinder 0, head 0 and Sector 1.
In the Absolute reading of the disk sectors, we need not to specify the Cylinder or Head numbers in our program. The absolute sectors are counted from absolute sector 0.
Thus if we are going to read the MBR of the disk (First sector of the disk), we are going to read absolute sector 0. It is the work of BIOS to convert the absolute sector number to its corresponding Cylinder, Head and Sector number.
As in absolute sector reading (or writing), we have to calculate only the absolute sectors within the loop in the operations such as entire disk reading or writing, whereas in case of relative sector reading (or writing), we need to run three loops at a time for calculating CHS therefore absolute sector reading/writing is much faster than relative sector reading/writing.
For example, if we have any hard disk with the 16 heads (sides), 12 Cylinders and with 63 sectors, the table given next, shows the procedure and difference of both the reading methods and thus shows how absolute sector approach may make our time taking programs (such as entire disk reading/ writing or entire disk wiping programs etc.) to run much faster:
Relative Sectors Reading
|
Absolute Sector reading
|
Cylinder =0, Head =0, Sector = 1
|
Absolute Sector = 0
|
Cylinder =0, Head =0, Sector = 2
|
Absolute Sector = 1
|
Cylinder =0, Head =0, Sector = 3
|
Absolute Sector = 2
|
.
.
.
.
|
.
.
.
.
|
Cylinder =0, Head =0, Sector = 62
|
Absolute Sector = 61
|
Cylinder =0, Head =0, Sector = 63
|
Absolute Sector = 62
|
Cylinder =0, Head =1, Sector = 1
|
Absolute Sector = 63
|
Cylinder =0, Head =1, Sector = 2
|
Absolute Sector = 64
|
Cylinder =0, Head =1, Sector = 3
|
Absolute Sector = 65
|
Cylinder =0, Head =1, Sector = 4
|
Absolute Sector = 66
|
.
.
.
.
|
.
.
.
.
|
Cylinder =0, Head =1, Sector = 63
|
Absolute Sector = 125
|
Cylinder =0, Head =2, Sector = 1
|
Absolute Sector = 126
|
Cylinder =0, Head =2, Sector = 2
|
Absolute Sector = 127
|
Cylinder =0, Head =2, Sector = 3
|
Absolute Sector = 128
|
.
.
.
.
|
.
.
.
.
|
Cylinder =0, Head =15, Sector = 63
|
Absolute Sector = 1007
|
Cylinder =1, Head =0, Sector = 1
|
Absolute Sector = 1008
|
Cylinder =1, Head =0, Sector = 2
|
Absolute Sector = 1009
|
Cylinder =1, Head =0, Sector = 3
|
Absolute Sector = 1010
|
.
.
.
.
|
.
.
.
.
|
Cylinder =1, Head =0, Sector = 63
|
Absolute Sector = 1070
|
Cylinder =1, Head =1, Sector = 1
|
Absolute Sector = 1071
|
Cylinder =1, Head =1, Sector = 2
|
Absolute Sector = 1072
|
Cylinder =1, Head =1, Sector = 3
|
Absolute Sector = 1073
|
.
.
.
.
|
.
.
.
.
|
Cylinder =1, Head =15, Sector = 63
|
Absolute Sector = 2015
|
Cylinder =2, Head =0, Sector = 1
|
Absolute Sector = 2016
|
Cylinder =2, Head =0, Sector = 2
|
Absolute Sector = 2017
|
Cylinder =2, Head =0, Sector = 3
|
Absolute Sector = 2018
|
.
.
.
.
|
.
.
.
.
|
Cylinder =11, Head =15, Sector = 60
|
Absolute Sector = 12092
|
Cylinder =11, Head =15, Sector = 61
|
Absolute Sector = 12093
|
Cylinder =11, Head =15, Sector = 62
|
Absolute Sector = 12094
|
Cylinder =11, Head =15, Sector = 63
|
Absolute Sector = 12095
|
The information of partition table of MBR, which is displayed by any disk MBR analyzing tool, has been given below:
In the above information, the relative sector numbers for the starting of both partitions are 63 and 11277630 respectively, which are free from partitions and counted according to the number of sectors, available in disk.
Page Modified on: 13/01/2022