Supriya Ghosh (Editor)

INT 13H

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

INT 13h is shorthand for BIOS interrupt call 13hex, the 20th interrupt vector in an x86-based computer system. The BIOS typically sets up a real mode interrupt handler at this vector that provides sector-based hard disk and floppy disk read and write services using cylinder-head-sector (CHS) addressing.

Contents

INT is an x86 instruction that triggers a software interrupt, and 13hex is the interrupt number (as a hexadecimal value) being called.

Modern computers come with both BIOS int 0x13 and UEFI functionality that provides the same services and more. Typically, UEFI drivers generally use LBA-addressing instead of CHS.

Overview

Under real mode operating systems, such as MS-DOS, calling INT 13h would jump into the computer's ROM-BIOS code for low-level disk services, which would carry out physical sector-based disk read or write operations for the program. In MS-DOS, it serves as the low-level interface for the built-in block device drivers for hard disks and floppy disks. This allows INT 25h and INT 26h to provide absolute disk read/write functions for logical sectors to the FAT file system driver in the DOS kernel, which handles file-related requests through MS-DOS API (INT 21h) functions.

Under protected mode operating systems, such as Microsoft Windows NT derivatives (e.g. NT4, 2000, XP, and Server 2003) and Linux with dosemu, the OS intercepts the call and passes it to the operating system's native disk I/O mechanism. Windows 9x and Windows for Workgroups 3.11 also bypass BIOS routines when using 32-bit File Access.

The original BIOS real-mode INT 13h interface supports drives of sizes up to about 504 MB using what is commonly referred to as physical CHS addressing. This limit originates from the hardware interface of the IBM PC/XT disk hardware. The BIOS used the cylinder-head-sector (CHS) address given in the INT 13h call, and transferred it directly to the hardware interface.

This interface was later extended to support addressing of up to exactly 8064 MB using what is commonly referred to as logical CHS addressing. This limit originates from a combination of the register value based calling convention used in the INT 13h interface, and the goal of maintaining backward compatibility. There were originally a number of BIOSes that offered incompatible versions of this interface, but eventually the computer industry standardized on the interface developed in the Microid Research ("MR BIOS") in 1989. This limit uses 1024 cylinders, 256 heads, 63 sectors, and 512 byte blocks, allowing exactly 7.875 GiB of addressing (1024 * 256 * 63 * 512 bytes).

To support even larger addressing modes, an interface known as INT 13h Extensions was introduced by Western Digital and Phoenix Technologies as part of BIOS Enhanced Disk Drive Services (EDD). It uses 64-bit logical block addressing (LBA) which allows addressing up to 8 ZiB (the drive can also support 28-bit or 48-bit LBA which allows up to 128 GiB or 128 PiB respectively, assuming a 512-byte sector/block size). This is a packet interface, because it uses a pointer to a packet of information rather than the register based calling convention of the original INT 13h interface. This packet is a data structure that contains an interface version, data size, and LBAs.

"[Most] versions of MS-DOS, (including MS-DOS 7, and Windows 95) have a bug which prevents booting hard disks with 256 heads (register value 0xFF), so many modern BIOSes provide mappings with at most 255 (FEh) heads", thus reducing the total addressable space to exactly 8032.5 MiB (approx 7.844 GiB). Some cache drivers flush their buffers when detecting that MS-DOS is bypassed by directly issuing INT 13h from applications. A dummy read can be used as one of several methods to force cache flushing for unknown caches (e.g. before rebooting). AMI BIOSes from around 1990-1991 trash word unaligned buffers. Some MS-DOS and TSR programs clobber interrupt enabling and registers so PC DOS and MS-DOS install their own filters to prevent this.

AWARD AT BIOS and AMI 386sx BIOS have been extended to handle more than 1024 cylinders by placing bits 10 and 11 of the cylinder number into bits 6 and 7 of DH

Function Table

If the second column is empty then the function may be used both for floppy and hard disk.

  • FD: for floppy disk only.
  • HD: for hard disk only.
  • PS/2: for hard disk on PS/2 system only.
  • EXT: part of the Int 13h Extensions which were written in the 1990s to support hard drives with more than 8 GB.
  • INT 13h AH=00h: Reset Disk Drive

    Parameters:

    Results:

    INT 13h AH=01h: Get Status of Last Drive Operation

    Parameters:

    Bit 7=0 for floppy drive, bit 7=1 for fixed drive

    Results:

    INT 13h AH=02h: Read Sectors From Drive

    Parameters:

    Results:

    Remarks:
    Register CX contains both the cylinder number (10 bits, possible values are 0 to 1023) and the sector number (6 bits, possible values are 1 to 63). Cylinder and Sector bits are numbered below:

    CX = ---CH--- ---CL--- cylinder : 76543210 98 sector : 543210

    Examples of translation:

    CX := ( ( cylinder and 255 ) shl 8 ) or ( ( cylinder and 768 ) shr 2 ) or sector; cylinder := ( (CX and 0xFF00) shr 8 ) or ( (CX and 0xC0) shl 2) sector := CX and 63;

    Addressing of Buffer should guarantee that the complete buffer is inside the given segment, i.e. ( BX + size_of_buffer ) <= 10000h. Otherwise the interrupt may fail with some BIOS or hardware versions.
    Example: Assume you want to read 16 sectors (= 2000h bytes) and your buffer starts at memory address 4FF00h. Utilizing memory segmentation, there are different ways to calculate the register values, e.g.:

    ES = segment = 4F00h BX = offset = 0F00h sum = memory address = 4FF00h would be a good choice because 0F00h + 2000h = 2F00h <= 10000h ES = segment = 4000h BX = offset = FF00h sum = memory address = 4FF00h would not be a good choice because FF00h + 2000h = 11F00h > 10000h

    Function 02h of interrupt 13h may only read sectors of the first 16,450,560 sectors of your hard drive, to read sectors beyond the 8 GB limit you should use function 42h of Int 13h Extensions. Another alternate may be DOS interrupt 25h which reads sectors within a partition.

    INT 13h AH=03h: Write Sectors To Drive

    Parameters:

    Results:

    INT 13h AH=04h: Verify Sectors From Drive

    Parameters:

    Results:

    INT 13h AH=05h: Format Track

    Parameters:

    4-byte address field (applies to PC/XT 286,AT, PS/1 and PS/2)

    Results:

    INT 13h AH=06h: Format Track Set Bad Sector Flags

    Parameters:

    Results:

    INT 13h AH=07h: Format Drive Starting at Track

    Parameters:

    Results:

    INT 13h AH=08h: Read Drive Parameters

    Parameters:


    Results:

    Remarks:
    Logical values of function 08h may/should differ from physical CHS values of function 48h.
    Result register CX contains both cylinders and sector/track values, see remark of function 02h.

    INT 13h AH=09h: Init Drive Pair Characteristics

    Parameters:

    Results:

    INT 13h AH=0Ah: Read Long Sectors From Drive

    The only difference between this function and function 02h (see above) is that function 0Ah reads 516 bytes per sector instead of only 512. The last 4 bytes contains the Error Correction Code (ECC), a checksum of sector data.

    INT 13h AH=41h: Check Extensions Present

    Parameters:

    Results:

    INT 13h AH=42h: Extended Read Sectors From Drive

    Parameters:

    Results:

    INT 13h AH=43h: Extended Write Sectors to Drive

    Parameters:

    Results:

    INT 13h AH=48h: Extended Read Drive Parameters

    Parameters:


    Results:

    Remark: Physical CHS values of function 48h may/should differ from logical values of function 08h.

    References

    INT 13H Wikipedia