Extended INT13h Call Details (fix)

Source: Internet
Author: User
Tags constant relative reserved
Extended INT13h Call Details (fix)
Introduction to the first part

I. Drive STRUCTURE INTRODUCTION

1. Hard Drive parameter explanation

So far, the hard drive parameters that people often say are still old CHS (cylinder/
Head/sector) parameter. So why use these parameters, and what are their meanings?
What are their range of values?
A long time ago, when the capacity of hard disk was very small, people used the same knot as floppy disk
Production of hard drives. That is, each track of a hard disk disc has the same number of sectors. Resulting
Produced the so-called 3D parameters (Disk Geometry). Number of heads (Heads), number of cylinders
(cylinders), number of sectors (sectors), and the corresponding addressing method.

which

The number of heads (Heads) indicates that the drive has a total of several heads, that is, several platters, the largest
is 255 (stored with 8 bits);
The number of cylinders (cylinders) indicates that there are several tracks on each platter of the hard disk, up to a maximum of 1023
(with 10 bits storage);
The number of sectors (sectors) indicates that there are several sectors on each track, up to a maximum of 63 (with 6
BITS storage).
Each sector is typically 512 bytes, which in theory is not necessary, but it does not seem to take
The value of the other.

So the maximum disk capacity is:

255 * 1023 * * 512/1048576 = 8024 MB (1M = 1048576 Bytes)
or hard disk manufacturers commonly used units:
255 * 1023 * * 512/1000000 = 8414 MB (1M = 1000000 Bytes)

In the CHS addressing method, the head, cylinder, and sector values range from 0 to Heads-1, respectively,
0 to Cylinders-1, 1 to sectors (note is starting from 1).

2. Introduction to basic INT 13H invocation

BIOS Int 13H Call is BIOS provided disk basic Input output interrupt call, it can
Complete disk (including hard disk and floppy disk) reset, read/write, check, location, diagnosis, formatting and other functions.
It uses the CHS addressing method, so the maximum knowledge access to about 8 GB of hard disk (in this article
If no special instructions are given, they are in 1M = 1048576 bytes.

3. Introduction to modern hard disk structure

In older hard drives, the record density of the heretics is much lower due to the equal number of sectors per track
Unes, so it wastes a lot of disk space (as with a floppy disk). In order to solve this problem, a
Step to increase the capacity of the hard disk, people use equal density structure to produce hard disk. In other words, the sector of the outer ring track
More than the inner ring track. With this structure, the hard drive no longer has the actual 3D parameters, and the addressing method is changed
For linear addressing, that is, sector-based addressing.
In order to be compatible with old software that uses 3D addressing (such as software that uses the BIOS INT13h interface), the hard
The disk controller internally installs an address * * *, which is responsible for the old 3D parameters into a new linear
Parameters. This is why the 3D parameters of a hard drive can now be selected for a variety of reasons (different working modes
corresponding to different 3D parameters, such as LBA, LARGE, NORMAL).

4. Introduction to Extended Int 13H

Although the modern hard drive has already adopted linear addressing, but due to the basic Int 13H constraints, so that
Programs that use the BIOS Int 13H interface, such as DOS, can only access hard disk space within 8 G.
To break this limit, several companies such as Microsoft have developed an extended Int 13H standard
(Extended INT13h), which uses a linear addressing method to access the hard drive, thus breaking the 8 G limit,
It also adds support for removable media, such as active hard drives.

Two. Boot Sector structure Introduction

1. The composition of Boot Sector

Boot Sector is the first sector of the hard disk, which is made up of the MBR (Master Boot Record),
The DPT (Disk Partition Table) and Boot Record IDs are composed of three parts.

The MBR, also known as the Master boot record, occupies the first 446 bytes of boot Sector (0 to 0X1BD),
Holds the system Master Boot program (it is responsible for loading and running the system boot from the active partition).
The DPT is the primary partition table that consumes 64 bytes (0x1be to 0X1FD), which records the basic partition of the disk
Information. The primary partition table is divided into four partition entries, each of which is 16 bytes, each of which records the information of each primary partition.
(so you can have up to four primary partitions).
The boot Record ID, which is the boot-zone token, consumes two bytes (0X1FE and 0x1ff) for a legitimate
The boot area, which is equal to 0xaa55, is a sign that the guide zone is legitimate.
The specific structure of the Boot Sector is shown in the following figure (see NightOwl's article):





2. Introduction to partitioned Table structure
A partitioned table consists of four partition items, each of which is structured as follows:
BYTE state: Partition status, 0 = not activated, 0x80 = active (Note this)
BYTE Starthead: Partition starting magnetic Number one
WORD STARTSC: Partition start sector and cylinder number, lower 6 bits of bottom byte are sector codes,
The height 2 bits is the array,10 bit of the cylinder number, and the high byte is the lower 8 bits of the cylinder number.
BYTE type: partition type, such as 0x0B = FAT32, 0x83 = Linux, etc.
00 indicates that this item is not used
BYTE Endhead: Partition over magnetic number one
WORD ENDSC: Partition end sector and cylinder number, defined as previous
DWORD Relative: Partition relative sector address in linear addressing mode
(Absolute address for basic partition)
DWORD Sectors: Partition size (total number of sectors)

Note: Under the Dos/windows system, basic partitions must be divided by cylinder
(sectors * Heads sectors), such as for the CHS-764/255/63 hard disk, the partition's
The minimum size is 255 * 512/1048576 = 7.844 MB.

3. Introduction to Extended partitions

Because the primary partition table can only be divided into four partitions, which cannot meet the requirements, an extension is designed
The partition format. Basically, the extended partition information is stored in a linked list, but there are some special
Other places.
First, there is a basic extended partition entry in the primary partition table, and all the extended partitions belong to it.
This means that all other extended partition spaces must be included in this basic extended partition. For
For Dos/windows, the extended partition is of type 0x05 or 0x0f (>8GB).
All extended partitions except the base extended partition are cascaded in the form of a linked list, after
A data entry for an extended partition is recorded in the partition table of the previous extended partition, but two extended partitions
The space does not overlap.
An extended partition is similar to a full hard disk and must be further partitioned before it can be used. But each expansion
Only one other partition can exist in the exhibition partition. This partition is the logical disk in the Dos/windows environment.
Therefore, the partition table for each extended partition (also stored in the first sector of the extended partition) is up to
There can be only two partition data items (including data items for the next extended partition).
The schematic diagram of the extended partition and the logical disk is as follows:





Three. Introduction to the system startup process

The system boot process consists of a few steps (take the hard disk boot as an example):

1. Boot:-)
2. BIOS power-on self test
Memory address is 0ffff:0000
3. Place the first sector of the hard drive (0 header 0 Channel 1 sectors, which is boot Sector)
Read into memory at address 0000:7c00.
4. Check if (WORD) 0000:7dfe is equal to 0xaa55, if not equal to
Then go to try other boot media, if no other boot media is displayed
"No ROM BASIC" then crashes.
5. Jump to 0000:7c00 to execute the program in the MBR.
6. The MBR first copies itself to 0000:0600, and then resumes execution.
7. Search for the partition marked active in the primary partition table. If no activity is found
Partition or there is more than one active partition, the turn stops.
8. Read the first sector of the active partition into the memory address 0000:7c00.
Array. Checks if (WORD) 0000:7dfe is equal to 0xaa55, if not equal

Display "Missing Operating System" and then stop, or try
Floppy boot.
10. Jump to 0000:7C00 to continue execution of a specific system startup program.
11. Start the system ...

The 2,3,4,5 step in the above steps is done by the BIOS boot program. 6,7,8,array,10
Step is completed by the bootstrapper in the MBR.

General multi-system boot program (e.g. Smartfdisk, Bootstar, pqboot, etc.)
is to replace the standard master boot record with its own boot program, running the system launcher
Let the user select the partition to start before.
And some system comes with the multi-system boot program (such as Lilo, NT Loader, etc.)
You can place your own bootstrapper in the first sector of the partition where the system is located, in the Linux
is Superblock (in fact, the superblock is two sectors).

Note: The standard MBR is used in each of the above steps, and the boot of other multi-system boot programs
The process differs from this.


Part II Technical data

Chapter One extended INT13h technical data

I. INTRODUCTION
The purpose of the extended INT13h interface is designed to extend the functionality of the BIOS so that it supports
More than 1024 cylinders of hard disk, as well as removable media, such as the locking, unlocking and eject functions.

Two. Data structure

1. Data type Conventions
BYTE 1-byte integer (8-bit)
WORD 2-byte integer (16-bit)
DWORD 4-byte integer (32-bit)
QWORD 8-byte integer (64-bit)

2. Disk address packet Packet (DAP)
DAP is based on absolute sector addresses, so using DAP, the INT13h can easily exceed
The more 1024 the cylinder limit, because it does not need the concept of CHS at all.
The structure of DAP is as follows:

struct Diskaddresspacket
{
BYTE PacketSize; Packet size:
(fixed value, constant equals 16, or 10H, refers to the storage space occupied by this structure)
BYTE Reserved; ==0
WORD Blockcount; Number of data blocks to transfer (in sectors)
DWORD bufferaddr; Transport buffer Address (Segment:offset)
QWORD Blocknum; Disk Start Absolute block address
};

PacketSize preserves the size of the DAP structure so that it can be expanded in the future. In
The currently used version of the extended INT13h is PacketSize constant equals 16. If it is less than
16, extension INT13h will return an error code (AH=01, cf=1).
Blockcount is the total number of data blocks that need to be transmitted for input, and for output
Is the number of data blocks actually transferred. Blockcount = 0 means that no data blocks are transmitted.
BUFFERADDR is the 32-bit address (segment address: offset) of the transmit data buffer. Data
The buffer must be within normal memory (1M).
Blocknum represents the absolute block address (in sectors) from the beginning of the disk.
independent of partition. The first block address is 0. In general, the relationship between Blocknum and the CHS address
Is:
Blocknum =
(Cylinder * numberofheads + head) * sectorspertrack + sector-1;

where cylinder, head, sector is the CHS address, numberofheads is the disk
Number of heads, Sectorspertrack is the number of sectors per track of the disk.
That is, the blocknum is the sequential count of the cylinder along the sector, the track. This Shun
Sequence is virtual by the disk controller, the actual order of the disk surface data blocks may differ from this
(such as the interval factor set to increase disk speed will disrupt the order of the sectors).

3. Drive parameter data packet drives Parameters Packet
Drive parameter packet is in the get drive parameter sub-function call of the extended INT13h
The data package used. The format is as follows:


struct Driveparameterspacket
{
WORD infosize; Packet size:
(fixed value, equal to 26, or 1AH, refers to the storage space occupied by this structure)
WORD Flags; Information flags
DWORD cylinders; Number of disk cylinders
DWORD Heads; Number of disk heads
DWORD Sectorspertrack; Number of sectors per track
QWORD sectors; Total number of disk sectors
WORD sectorsize; Sector size (in bytes)
};
Information flags are used to return additional information about the disk, each of which is defined as follows:

0-bit:
0 = DMA Boundary error may occur
1 = DMA boundary error will be handled transparently
If this position is 1, the BIOS will automatically handle the DMA boundary error, which means
Error code 0ArrayH will never appear.

1-bit:
0 = no CHS information provided
1 = CHS information is legal
If the traditional CHS geometry information for a block device is not appropriate, the bit will be set to 0.

2-bit:
0 = drive is not removable
1 = Drive Removable

3-bit: Indicates whether the drive supports write-time validation.

4-bit:
0 = drive does not have media replacement detection line
1 = drive with media replacement detection line


5-bit:
0 = drive is not locked
1 = drive can be locked
To access a removable drive with a drive letter greater than 0x80, the bit must be set to 1
(Some devices with a drive letter of 0 to 0x7F also need to be placed)

6-bit:
0 = CHS value is the value of the current storage medium (for removable media only), if
There is a storage medium in the drive and the CHS value is returned.
1 = The CHS value is the maximum value supported by the drive (there is no media in the drive at this time).

7-15 bits: Reserved, must be set to 0.

Three. Interface Specification

1. Register conventions
The following register conventions are generally used in extended INT13h calls:

DS:SI ==> disk address packet (packet)
DL ==> Drive Letter
Ah ==> function code/return code

In a basic INT13h call, the drive letter between 0-0x7f represents a removable drive
The drive letter between 0x80-0xff represents a fixed drive. But in the extended INT13h call
0x80-0xff also includes some new removable drives, such as active hard drives.
These drives support advanced locking, unlocking and other functions.
The error code returned by Ah, in addition to the standard INT13h calling the basic error code specified, adds
The following error code:

The media in the b0h drive is not locked

The media in the b1h drive is locked

B2H Media is removable

B3H Media is being used

b4h Lock Count Overflow

b5h legitimate pop-up request failed

2. Introduction to the API subset
Two major API subsets are specified in the extended INT13h call of version 1.x.

The first subset provides the functionality necessary to access a large hard drive, including checking the extension in13h
Presence (41H), extended Read (42H), extended write (43H), checksum sector (44H),
Expand positioning (47h) and obtain drive parameters (48h).
The second subset provides support for software-controlled drive locking and ejection, including checking the extension
INT13h is present (41H), lock/Unlock drive (45h), eject Drive (46h),
Get the drive parameters (48h), get the extended drive change status (4ARRAYH), int 15h.
If you use a feature that is not supported in the calling specification, the BIOS returns an error code, AH = 01h,
CF = 1.

3. API explanation

1) Verify that the extension function is present
Entrance:
AH = 41h
BX = 55AAh
DL = Drive Letter

Return:
CF = 0
AH = Major version number of the extension feature
AL = Internal Use
BX = aa55h
CX = API subset supports bitmaps
CF = 1
AH = error code 01h, Invalid command

This call verifies that there is an extension function for a particular drive. If the carry marker is 1
This drive does not support extended functionality. If the carry flag is 0 and BX = aa55h, then
There is an extension feature. At this point, the 0-bit CX indicates whether the first subset is supported, and 1-bit indicates whether
Supports a second subset.
For the 1.x version of the extended INT13h, the major version number is AH = 1. AL is the sub-version number,
However, this is limited to internal BIOS use, and any software must not check the value of AL.

2) Extended Read
Entrance:
AH = 42h
DL = Drive Letter
DS:DI = Disk address packet (Packet)

Return:
CF = 0, AH = 0 Successful
CF = 1, AH = error code

This call reads the data on the disk into memory. If an error occurs, the Blockcount of DAP
Xiangzhong records the number of data blocks actually read before the error.

3) Extended Write
Entrance:
AH = 43h
AL
0 bit = 0 Turn write check off
1 Turn on write verification
1-7-bit reserved, set 0
DL = Drive Letter
DS:DI = Disk address packet (DAP)
Return:
CF = 0, AH = 0 Successful
CF = 1, AH = error code

This call writes the data in memory to disk. If the Write check option is turned on, but the BIOS
Not supported, the error code is returned AH = 01h, CF = 1. function 48h can detect if the BIOS
Supports write verification.
If an error occurs, the Blockcount key for DAP records the number of actual writes before the error
According to the number of blocks.

4) Check Sector
Entrance:
AH = 44h
DL = Drive Letter
DS:DI = Disk address packet (Packet)

Return:
CF = 0, AH = 0 Successful
CF = 1, AH = error code


This call verifies the disk data, but does not read the data into memory. If an error occurs, the DAP's
The number of data blocks that were actually checked before the error was recorded in the Blockcount key.

5) lock/unlock Drive
Entrance:
AH = 45h
AL
= 0 Lock Drive
= 1 Drive Unlocked
= 02 return lock/Unlock status
= 03H-FFH-Reserved
DL = Drive Letter

Return:
CF = 0, AH = 0 Successful
CF = 1, AH = error code

This call is used to indent the media in the specified drive.
All removable drives with a label greater than or equal to 0x80 must support this feature. If
Use this feature call on a fixed drive that supports a subset of removable drive control functions
will return successfully.
The drive must support a maximum of 255 locks and cannot be physically removed until all locks are unlocked
Unlock the drive. Unlock an unlocked drive and the error code ah= B0H will be returned. If you lock a
A drive that has been locked 255 times will return an error code AH = b4h.
It is legal to lock a drive with no media.

6) Eject the media in the removable drive
Entrance:
AH = 46h
AL = 0 Reserved
DL = Drive Letter

Return:
CF = 0, AH = 0 Successful
CF = 1, AH = error code

This call is used to eject the media in the specified removable drive.
All removable drives with a label greater than or equal to 0x80 must support this feature. If
Use this feature call on a fixed drive that supports a subset of removable drive control functions
The error code is returned AH = B2H (the media is not removable). If you attempt to eject a locked media
The error code will be returned AH = b1h (the media is locked).
If you attempt to eject a drive that does not have media, the error code is returned AH = 31h (drive
Media is not in the medium).
If you attempt to eject media from a removable drive that is not locked, INT13h calls int15h
(AH = 52h) to check whether the popup request can be executed. Returns an error code if the popup request is rejected (same as
int15h). If the pop-up request is accepted, but there are other errors, the error code, AH = b5h, is returned.

7) Extended positioning
Entrance:
AH = 47h
DL = Drive Letter
DS:DI = Disk address packet (Packet)

Return:
CF = 0, AH = 0 Successful
CF = 1, AH = error code

This call locates the head to the specified sector.

8) Get Drive parameters
Entrance:
AH = 48h
DL = Drive Letter
Ds:di = return Data buffer address

Return:
CF = 0, AH = 0 Successful
Ds:di Drive parameter packet address (see previous article)
CF = 1, AH = error code

This call returns the parameters for the specified drive.

Array) Get extended drive media replacement detection line status
Entrance:
AH = 4Arrayh
DL = Drive Letter

Return:
CF = 0, AH = 0 media not replaced
CF = 1, AH = 06h media may have been replaced

This call returns the media replacement status for the specified drive.
This call is identical to the INT13h AH = 16h sub-function call, except that any drive is allowed
Label. If you use this feature on a fixed drive that supports a subset of removable media features, you can always
Returns CF = 0, AH = 0.
Simply lock the removable media and unlock it to activate the detection line without having to actually replace the media.


Int 15h removable media eject support
Entrance:
AH = 52h
DL = Drive Letter
Return:
CF = 0, AH = 0 pop-up request may be executed
CF = 1, AH = error code b1h or b3h popup request cannot be executed

This call is used internally by the INT13h ah=46h pop-up media feature call.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.