INT 13
Encyclopedia
INT 13H or INT 19 is shorthand for BIOS interrupt call
BIOS interrupt call
BIOS interrupt calls are a facility that DOS programs and some other software, such as boot loaders, use to invoke the facilities of the Basic Input/Output System...

 13hex
Hexadecimal
In mathematics and computer science, hexadecimal is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen...

, the 20th interrupt vector
Interrupt vector
An interrupt vector is the memory address of an interrupt handler, or an index into an array called an interrupt vector table that contains the memory addresses of interrupt handlers...

 in an x86-based computer system. The BIOS
BIOS
In IBM PC compatible computers, the basic input/output system , also known as the System BIOS or ROM BIOS , is a de facto standard defining a firmware interface....

 typically sets up a real mode
Real mode
Real mode, also called real address mode, is an operating mode of 80286 and later x86-compatible CPUs. Real mode is characterized by a 20 bit segmented memory address space and unlimited direct software access to all memory, I/O addresses and peripheral hardware...

 interrupt handler
Interrupt handler
An interrupt handler, also known as an interrupt service routine , is a callback subroutine in microcontroller firmware, operating system or device driver whose execution is triggered by the reception of an interrupt...

 at this vector that provides sector-based hard disk and floppy disk read and write services using cylinder-head-sector
Cylinder-head-sector
Cylinder-head-sector, also known as CHS, was an early method for giving addresses to each physical block of data on a hard disk drive. In the case of floppy drives, for which the same exact diskette medium can be truly low-level formatted to different capacities, this is still true.Though CHS...

 (CHS) addressing.

INT
INT (x86 instruction)
INT is an assembly language instruction for x86 processors that generates a software interrupt. It takes the interrupt number formatted as a byte value.When written in assembly language, the instruction is written like this:...

 is an x86 instruction that triggers a software interrupt, and 13hex vector passed to the instruction (interrupts start at zero, and are labeled with hexadecimal
Hexadecimal
In mathematics and computer science, hexadecimal is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen...

 values).

Overview

Under real mode
Real mode
Real mode, also called real address mode, is an operating mode of 80286 and later x86-compatible CPUs. Real mode is characterized by a 20 bit segmented memory address space and unlimited direct software access to all memory, I/O addresses and peripheral hardware...

 operating systems, such as MS-DOS
MS-DOS
MS-DOS is an operating system for x86-based personal computers. It was the most commonly used member of the DOS family of operating systems, and was the main operating system for IBM PC compatible personal computers during the 1980s to the mid 1990s, until it was gradually superseded by operating...

, calling INT 0x13 would jump into the computer's BIOS code for low level disk services, which would carry out sector-based disk read or write operations for the program. In MS-DOS it serves as a foundation for higher-level MS-DOS API
MS-DOS API
The MS-DOS API is an API used originally in MS-DOS/PC-DOS, and later by other DOS systems. Most calls to the DOS API invoke software interrupt 21h . By calling INT 21h with a subfunction number in the AH processor register and other parameters in other registers, one invokes various DOS services...

 (INT 21h) functions which deal with file system
File system
A file system is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device which contain it. A file system organizes data in an efficient manner and is tuned to the...

 access.

Under protected mode
Protected mode
In computing, protected mode, also called protected virtual address mode, is an operational mode of x86-compatible central processing units...

 operating systems, such as Microsoft Windows NT derivatives (e.g. NT4, 2000, XP, and Server 2003) and Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...

 with dosemu
DOSEMU
DOSEMU, alternatively rendered dosemu, is a compatibility layer software package that enables MS-DOS systems, DOS clones such as FreeDOS, and DOS software to run under Linux on x86-based PCs ....

, the OS intercepts the call and passes it to the operating system's native disk I/O mechanism. Windows 9x
Windows 9x
Windows 9x is a generic term referring to a series of Microsoft Windows computer operating systems produced since 1995, which were based on the original and later modified Windows 95 kernel...

 and Windows for Workgroups 3.11 also bypass BIOS routines when using 32-bit File Access
32-bit File Access
32-bit file access refers to the higher performance, protected mode disk caching method introduced in Windows for Workgroups 3.11, which replaced SmartDrive . It bypassed MS-DOS and directly accessed the disk, either via the BIOS or 32-bit disk access...

.

The original BIOS real-mode INT 0x13 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 x86 disk hardware. The BIOS used the cylinder-head-sector
Cylinder-head-sector
Cylinder-head-sector, also known as CHS, was an early method for giving addresses to each physical block of data on a hard disk drive. In the case of floppy drives, for which the same exact diskette medium can be truly low-level formatted to different capacities, this is still true.Though CHS...

 (CHS) address given in the INT 0x13 call, and transmitted 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 0x13 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, giving roughly 7.875 GB of addressing (1024 * 256 * 63 * 512).

To support even larger addressing modes, an interface known as 'INT13h Extensions was introduced by Western Digital
Western Digital
Western Digital Corporation is one of the largest computer hard disk drive manufacturers in the world. It has a long history in the electronics industry as an integrated circuit maker and a storage products company. Western Digital was founded on April 23, 1970 by Alvin B...

 and Phoenix Technologies
Phoenix Technologies
Phoenix Technologies Ltd designs, develops and supports core system software for personal computers and other computing devices. Phoenix's products — commonly referred to as BIOS or firmware — support and enable the compatibility, connectivity, security and management of the various components and...

 as part of BIOS Enhanced Disk Drive Services (EDD) standard. It uses 64-bit logical block addressing
Logical block addressing
Logical block addressing is a common scheme used for specifying the location of blocks of data stored on computer storage devices, generally secondary storage systems such as hard disks....

 (LBA) which allows addressing up to 8 ZiB
Zebibyte
The zebibyte is a standards-based binary multiple of the byte, a unit of digital information storage. The zebibyte unit symbol is ZiB.1 zebibyte = 270 bytes = = 1,024 exbibytes...

 (the drive can also support 28-bit or 48-bit LBA which allows up to 128 GiB
Gibibyte
The gibibyte is a standards-based binary multiple of the byte, a unit of digital information storage. The gibibyte unit symbol is GiB....

 or 128 PiB
Pebibyte
The pebibyte is a standards-based binary multiple of the byte, a unit of digital information storage. The pebibyte unit symbol is 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 13 interface. This packet is a data structure that contains an interface version, data size, and LBAs.

All versions of MS-DOS
MS-DOS
MS-DOS is an operating system for x86-based personal computers. It was the most commonly used member of the DOS family of operating systems, and was the main operating system for IBM PC compatible personal computers during the 1980s to the mid 1990s, until it was gradually superseded by operating...

, including MS-DOS 7, and Windows 95
Windows 95
Windows 95 is a consumer-oriented graphical user interface-based operating system. It was released on August 24, 1995 by Microsoft, and was a significant progression from the company's previous Windows products...

 contain a bug that prevents booting hard disks with 256 heads (register value 0xFF), so many modern BIOS maps the drives to have at most 255 heads. Also some cache drivers will flush their buffers when detecting that MS-DOS is bypassed by applications that directly issues INT 13h requests.
AMI BIOSes from around 1990-1991 trash word unaligned buffers. Some MS-DOS and TSR
Terminate and Stay Resident
Terminate and Stay Resident is a computer system call in DOS computer operating systems that returns control to the system as if the program has quit, but keeps the program in memory...

 programs clobber interrupt enabling and registers so PC-DOS
PC-DOS
IBM PC DOS is a DOS system for the IBM Personal Computer and compatibles, manufactured and sold by IBM from the 1980s to the 2000s....

 and MS-DOS
MS-DOS
MS-DOS is an operating system for x86-based personal computers. It was the most commonly used member of the DOS family of operating systems, and was the main operating system for IBM PC compatible personal computers during the 1980s to the mid 1990s, until it was gradually superseded by operating...

 install their own filters to prevent this.

Drive Table

DL = 00h 1st floppy disk ( "drive A:" )
DL = 01h 2nd floppy disk ( "drive B:" )
DL = 80h 1st hard disk
DL = 81h 2nd hard disk

Function Table

AH = 00h   Reset Disk Drives
AH = 01h   Get Status of Last Drive Operation
AH = 02h   Read Sectors From Drive
AH = 03h   Write Sectors To Drive
AH = 04h   Verify Sectors
AH = 05h   Format Track
AH = 06h   Format Track Set Bad Sector Flags
AH = 07h   Format Drive starting at Track
AH = 08h   Read Drive Parameters
AH = 09h HD Initialize Disk Controller
AH = 0Ah HD Read Long Sectors From Drive
AH = 0Bh HD Write Long Sectors To Drive
AH = 0Ch HD Move Drive Head To Cylinder
AH = 0Dh HD Reset Disk Drives
AH = 0Eh PS/2 Controller Read Test
AH = 0Fh PS/2 Controller Write Test
AH = 10h HD Test Whether Drive Is Ready
AH = 11h HD Recalibrate Drive
AH = 12h PS/2 Controller RAM Test
AH = 13h PS/2 Drive Test
AH = 14h HD Controller Diagnostic
AH = 15h   Read Drive Type
AH = 16h FD Detect Media Change
AH = 17h FD Set Media Type For Format ( used by DOS versions <= 3.1 )
AH = 18h FD Set Media Type For Format ( used by DOS versions >= 3.2 )
AH = 19h   Park Heads
AH = 41h EXT Test Whether Extensions Are Available
AH = 42h EXT Read Sectors From Drive
AH = 43h EXT Write Sectors To Drive
AH = 44h EXT Verify Sectors
AH = 45h EXT Lock/Unlock Drive
AH = 46h EXT Eject Drive
AH = 47h EXT Move Drive Head To Sector
AH = 48h EXT Read Drive Parameters
AH = 49h EXT Detect Media Change


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
    Gigabyte
    The gigabyte is a multiple of the unit byte for digital information storage. The prefix giga means 109 in the International System of Units , therefore 1 gigabyte is...

    .

INT 13h AH=00h: Reset Disk Drive

Parameters:
AH 00h
DL Drive


Results:
CF Set on error


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

Parameters:
AH 01h
DL Drive$

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

Results:
AL Return Code
00h Success
01h Invalid Command
02h Cannot Find Address Mark
03h Attempted Write On Write Protected Disk
04h Sector Not Found
05h Reset Failed
06h Disk change line 'active'
07h Drive parameter activity failed
08h DMA overrun
09h Attempt to DMA over 64kb boundary
0Ah Bad sector detected
0Bh Bad cylinder (track) detected
0Ch Media type not found
0Dh Invalid number of sectors
0Eh Control data address mark detected
0Fh DMA out of range
10h CRC/ECC data error
11h ECC corrected data error
20h Controller failure
40h Seek failure
80h Drive timed out, assumed not ready
AAh Drive not ready
BBh Undefined error
CCh Write fault
E0h Status error
FFh Sense operation failed
CF Set On Error, Clear If No Error

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

Parameters:
AH 02h
AL Sectors To Read Count
CH Track
CL Sector
DH Head
DL Drive
ES:BX Buffer Address Pointer

Results:
CF Set On Error, Clear If No Error
AH Return Code
AL Actual Sectors Read Count

Remarks:

Register CX contains both the cylinder number (10 bit
Bit
A bit is the basic unit of information in computing and telecommunications; it is the amount of information stored by a digital device or other physical system that exists in one of two possible distinct states...

s, possible values are 0 to 1023)
and the sector number (6 bits, possible values are 1 to 63):
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 byte
Byte
The byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...

s) 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:
AH 03h
AL Sectors To Write Count
CH Track
CL Sector
DH Head
DL Drive
ES:BX Buffer Address Pointer

Results:
CF Set On Error, Clear If No Error
AH Return Code
AL Actual Sectors Written Count

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

Parameters:
AH 04h
AL Sectors To Verify Count
CH Track
CL Sector
DH Head
DL Drive
ES:BX Buffer Address Pointer

Results:
CF Set On Error, Clear If No Error
AH Return Code
AL Actual Sectors Verified Count

INT 13h AH=05h: Format Track

Parameters:
AH 05h
AL Sectors To Format Count
CH Track
CL Sector
DH Head
DL Drive
ES:BX Buffer Address Pointer$


$4-byte address field (applies to PC/XT 286,AT, PS/1 and PS/2)
Byte Meaning Allowable Values
1 Track
2 Head
3 Sector
4 Bytes/Sector 0=128, 1-256, 2-512, 3-1024


Results:
CF Set On Error, Clear If No Error
AH Return Code

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

Parameters:
AH 06h
AL Interleave
CH Track
CL Sector
DH Head
DL Drive

Results:
CF Set On Error, Clear If No Error
AH Return Code

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

Parameters:
AH 07h
AL Interleave
CH Track
CL Sector
DH Head
DL Drive

Results:
CF Set On Error, Clear If No Error
AH Return Code

INT 13h AH=08h: Read Drive Parameters

Parameters:
Registers
AH 08h = function number for read_drive_parameters
DL drive index (e.g. 1st HDD = 80h)
ES:DI set to 0000h:0000h to workaround some buggy BIOS



Results:
CF Set On Error, Clear If No Error
AH Return Code
DL number of hard disk drives
DH logical last index of heads = number_of - 1 (because index starts with 0)
CX [7:6] [15:8] logical last index of cylinders = number_of - 1 (because index starts )

[5:0] logical last index of sectors per track = number_of (because index starts with 1)
BL drive type (only AT/PS2 floppies)
ES:DI pointer to drive parameter table (only for floppies)

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:
AH 09h
DL Drive

Results:
CF Set On Error, Clear If No Error
AH Return Code

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:
Registers
AH 41h = function number for extensions check
DL drive index (e.g. 1st HDD = 80h)
BX 55AAh


Results:
CF Set On Not Present, Clear If Present
AH Error Code or Major Version Number
BX AA55h
CX Interface support bitmask:

1 - Device Access using the packet structure

2 - Drive Locking and Ejecting

4 - Enhanced Disk Drive Support (EDD)

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

Parameters:
Registers
AH 42h = function number for extended read
DL drive index (e.g. 1st HDD = 80h)
DS:SI segment:offset pointer to the DAP, see below

DAP : Disk Address Packet
offset range size description
00h 1 byte size of DAP = 16 = 10h
01h 1 byte unused, should be zero
02h..03h 2 bytes number of sectors to be read, (some Phoenix BIOSes are limited to a maximum of 127 sectors)
04h..07h 4 bytes segment:offset pointer to the memory buffer to which sectors will be transferred (note that x86 is little-endian: if declaring the segment and offset separately, the offset must be declared before the segment)
08h..0Fh 8 bytes absolute number of the start of the sectors to be read (1st sector of drive has number 0)


Results:
CF Set On Error, Clear If No Error
AH Return Code

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

Parameters:
Registers
AH 48h = function number for extended_read_drive_parameters
DL drive index (e.g. 1st HDD = 80h)
DS:SI segment:offset pointer to Result Buffer, see below

Result Buffer
offset range size description
00h..01h 2 bytes size of Result Buffer = 30 = 1Eh
02h..03h 2 bytes information flags
04h..07h 4 bytes physical number of cylinders = last index + 1 (because index starts with 0)
08h..0Bh 4 bytes physical number of heads = last index + 1 (because index starts with 0)
0Ch..0Fh 4 bytes physical number of sectors per track = last index (because index starts with 1)
10h..17h 8 bytes absolute number of sectors = last index + 1 (because index starts with 0)
18h..19h 2 bytes bytes per sector
1Ah..1Dh 4 bytes optional pointer to Enhanced Disk Drive (EDD) configuration parameters
which may be used for subsequent interrupt 13h Extension calls (if supported)



Results:
CF Set On Error, Clear If No Error
AH Return Code


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

See also

  • INT 10H
  • BIOS interrupt call
    BIOS interrupt call
    BIOS interrupt calls are a facility that DOS programs and some other software, such as boot loaders, use to invoke the facilities of the Basic Input/Output System...

  • Cylinder-head-sector
    Cylinder-head-sector
    Cylinder-head-sector, also known as CHS, was an early method for giving addresses to each physical block of data on a hard disk drive. In the case of floppy drives, for which the same exact diskette medium can be truly low-level formatted to different capacities, this is still true.Though CHS...

  • INT (x86 instruction)
    INT (x86 instruction)
    INT is an assembly language instruction for x86 processors that generates a software interrupt. It takes the interrupt number formatted as a byte value.When written in assembly language, the instruction is written like this:...

  • DPMI (DOS Protected Mode Interface)

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK