章节 – 9
处理大硬盘
处理大型硬盘
在上一章中,我们讨论了 BIOS-Disk 功能和使用中断来访问硬盘的物理介质。我们在那里使用了 INT 13H 函数来访问硬盘。
INT 13H 接口支持许多不同的命令,例如读、写、格式化和验证等,可以给 BIOS,然后将它们传递到硬盘。由于 DOS 已经使用了很长时间,INT13H 多年来一直是标准。
INT 13H 分配 24 位用于指定驱动器的几何形状,并要求调用程序知道硬盘的具体参数,并为例程提供准确的磁头、柱面和扇区地址以允许磁盘访问。
BIOS 使用在 BIOS 设置程序中设置的硬盘几何结构。由 INT 13H 接口分配的 24 位用于驱动器几何规格的划分如下:
- 10 位为柱面编号。因此,气缸总数的上限可能为 1,024 个气缸。
- 8 位为头号。因此,总正面数的上限为 256。
- 6 位扇区号。因此,扇区总数最多可达 63 个。
因此,这种方法支持的最大扇区可能高达 1024 * 256 * 63 = 16515072。
这意味着 INT13H 接口可以支持最多包含大约 1650 万个扇区的磁盘,每扇区 512 字节导致最大为 8.46 GB。这正是我要解释的。因此,通过使用所有这些函数或 INT 13H,我们最多只能访问 8.46 GB 的磁盘。
这就是为什么近年来这种旧接口的局限性导致它被放弃,转而采用一种新的硬盘寻址方式,本章接下来将介绍。
首先,让我告诉你一个故事!
11年前,在我上七年级的时候,在学校里,我听说了容量为42MB的硬盘,可能是IBM的WDA-L42。那时我和我的朋友们真的很难想象这么大容量的硬盘。
INT 13H 方法论是从今天开始大约二十年前开发的。您现在可以理解,即使在那个时代的梦想中,8 GB 的硬盘也要大得多。但是今天,如果我们向任何个人计算机用户谈论 8 GB 硬盘,他可能不喜欢使用它,说它的存储容量小。
这就是 INT 13H 接口在现代系统中最终无法发挥作用的原因。 INT 13H 使用 24 位来分配磁盘几何结构,不幸的是无法扩展现有的 INT 13H BIOS 接口,因为如果这样做,许多旧硬件和软件将停止工作,您可以理解今天的计算机市场数以百万计的旧软件和硬件产品停止工作,永远无法承受如此大的变化。
牢记这一条件,INT 13H 已被称为 INT 13H 扩展的更新接口取代。然而 INT 13H 仍可被 DOS 和其他一些较旧的操作系统使用并用于其他兼容性目的。
新的 INT 13H 接口使用 64 位而不是 24 位进行寻址,并允许最大硬盘大小为 9.4 * 1021 字节,实际上是 9.4 万亿字节或 9400000000000 千兆字节。我希望现在我们可以放松一段时间,直到这个限制被打破。
接下来介绍了中断 13H 扩展的一些重要功能。您可以像使用 INT 13H 的功能一样在编程中使用这些功能。这也是这些函数被称为 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:
该函数用于获取固定磁盘的制造头。读取的第一个扇区包含带有缺陷条目数和缺陷图开头的制造标头;其余扇区包含缺陷图的其余部分。制造标头格式(缺陷映射记录格式)可在 IBM 70MB、115MB 固定磁盘驱动器技术参考中找到。
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:
此函数用于获取指向 SCSI 磁盘信息块的指针。这也设置了一个不可重置的标志,以防止显示某些控制器消息。
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:
该函数用于获取空闲控制器 Ram。 ES:BX 指向控制器上空闲 RAM 的第一个字节,可用于其他用途。 ES 包含控制器所在的段。控制器的两个内存映射 I/O 端口位于偏移 1C00H 和 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:
该函数用于获取命令完成状态。如果函数成功,则清除进位标志,如果不成功,则设置进位标志。
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:
该函数用于获取设备状态。如果函数成功,则清除进位标志,如果不成功,则设置进位标志。
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:
此函数用于获取磁盘的设备配置。如果函数成功,进位标志清零,AH 寄存器为 01H,否则进位标志置位,AH 寄存器返回状态。下表显示了 ESDI 驱动器配置状态块的格式:
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:
该函数用于获取适配器配置。如果函数成功进位标志清零,AH 为 01H,如果不成功进位标志置位,AH 返回状态。
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:
此函数用于获取 POS 信息。如果函数成功进位标志清零,AH 为 01H,如果不成功进位标志置位,AH 返回状态。
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:
此函数将 RBA(相对块地址)转换为 ABA(绝对块地址)。如果功能成功,进位标志清零,AH 寄存器为 01H,否则进位标志置位,AH 返回状态。
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:
该函数用于获取当前的媒体格式。 Compaq/ATAPI 软盘介质类型的值已在下表中给出:
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:
该函数用于使用 Multiple Block Mode 读取多个磁盘扇区,它仅在传输一组扇区结束后而不是在每个扇区之后产生中断。
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:
该函数用于使用多块模式写入多个磁盘扇区,该模式仅在传输一组扇区结束后而不是在每个扇区之后产生中断。
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:
此功能启用和/或禁用所有驱动器的缓存。如果函数成功,则 AX 寄存器为 0000H,否则返回状态。
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:
该函数用于设置控制器特性寄存器。如果函数成功,进位标志被清除,如果不成功进位标志被设置并且 AH 寄存器返回状态
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:
此功能用于设置多路传输模式。如果要禁用多传输模式,请将扇区数设置为 0。块大小的最大值(例如 2、4、6、8 和 16 等)取决于固定磁盘驱动器类型。
该值存储在由 POST(开机自检)创建的硬盘驱动器参数表的字节 15H 中。地址 0040H:0074H 处的字节设置为操作状态。 PS/1 硬盘功能编号的值已在下表中列出:
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:
此函数用于设置扇区。如果函数成功,则 AX 寄存器为 0000H,否则 AX 返回状态。
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:
此功能用于识别驱动器。地址 0040h:0074h 处的字节设置为操作状态。 IBM 正式将此功能归类为可选功能。下表给出了通用驱动器配置的位字段:
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)
|
ATA(AT Attachment)规范中给出的驱动器信息块格式的描述已在下表中给出:
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:
此函数用于设置刷新间隔。如果函数成功,AH 为 0000H,否则 AH 返回状态。
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 返回状态从 0001H 到 00FFH 用于被另一个 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:
如果安装,AX 寄存器为 0000H,BX 返回非零值。
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:
调用函数,AL = 00H 禁用,AL = 01H 启用。
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:
该函数用于设置缓冲区大小。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。
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:
如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。使用 AL = 00H 来禁用和 AL = 01H 来启用驱动器访问声音的调用函数
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:
此函数启用或禁用所有驱动器的延迟写入。使用 AH=38H 更改单个驱动器。使用 AL = 00H 禁用,使用 01H 启用。
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:
此功能启用或禁用所有驱动器的预读。使用 AL = 00H 禁用,使用 AL = 01H 启用。使用 AH=37H 更改单个驱动器。
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:
此函数用于设置刷新计数。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。
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:
如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。
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:
此函数用于获取由 AL 指定的有关系统的不同类型的信息。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。 AX = 8000H 表示无效的信息说明符。要指定给 AL 的信息编号已在下表中列出:
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:
该函数用于为应用程序保留内存。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。
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:
此函数用于启用特定驱动器的缓存。例如,为 A: 调用具有 AL = 00H 的函数,依此类推。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。
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:
此函数用于禁用特定驱动器的缓存。例如,为 A: 调用具有 AL = 00H 的函数,依此类推。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。
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:
该函数用于调用由 AL 指定的扇区的锁定/解锁函数。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。下表给出了用 AL 调用的不同函数号:
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:
该函数用于设置锁池大小。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。
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:
此函数用于设置跟踪缓冲区大小。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。该函数通常用 INT 13H 的函数 24H 调用,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:
此函数用于设置特定驱动器的缓冲读取。如果 AL = 00H,则状态启用,否则禁用。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。
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:
此函数用于为特定驱动器设置缓冲写入。如果 AL = 00H,则状态启用,否则禁用。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。
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:
此函数用于设置特定驱动器的读取缓冲区大小,例如 A: 的 DL = 00H 等等。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。
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:
此函数用于设置特定驱动器的写入缓冲区大小,例如 A: 的 DL = 00H 等等。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。
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:
此功能用于启用/禁用特定驱动器的气缸冲洗,例如 A: 的 DL = 00H 等等。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。如果 AL 寄存器设置为 01H,则状态为启用,否则禁用。
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:
此功能用于设置单部门奖金。如果函数成功则 AX 为 0000H,如果不成功则 AX 返回状态。
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:
此函数用于设置奖励阈值。如果函数成功则AX为0000H,如果不成功则AX返回状态
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:
此函数检查是否安装并支持 IBM/MS INT 13H 扩展。下表给出了主要版本的扩展值:
Value
|
Major Version of Extension
|
01H
|
1.x
|
20H
|
2.0 / EDD-1.0
|
21H
|
2.1 / EDD-1.1
|
30H
|
EDD-3.0
|
下表给出了 IBM/MS INT 13H 扩展 API 支持位图的位字段:
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:
该函数是磁盘读取功能的扩展。如果函数成功,进位标志清零,AH 寄存器为 00H,否则进位标志置位,AH 返回错误码。磁盘地址包的块计数字段设置为成功传输的块数。磁盘地址包的格式如下:
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:
该功能是对磁盘写入功能的扩展。如果函数成功进位标志清零,AH 寄存器为 00H,否则进位标志置位,AH 返回错误码。磁盘地址包的块计数字段设置为成功的块数。下表给出了不同版本的写标志信息:
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:
该功能是验证扇区功能的扩展。如果函数成功,进位标志清零,AH 寄存器为 00H,否则进位标志置位,AH 返回错误码。磁盘地址包的块计数字段设置为成功的块数
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:
此功能用于锁定/解锁驱动器。任何编号为 80H 或更高的可移动驱动器都需要支持此功能。一个驱动器上最多可以放置 255 个锁,并且在所有锁都被移除之前,媒体不会被物理解锁。
如果函数成功,进位标志清零,AH寄存器为00H,否则进位标志置位,AH返回错误码。
驱动器的不同锁定/解锁操作的操作编号已在下表中给出:
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:
此功能是弹出媒体。如果函数成功进位标志清零,AH 寄存器为 00H,否则进位标志置位,AH 返回错误码。
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:
该函数是对 seek 函数的扩展。如果函数成功进位标志清零,AH 寄存器为 00H,否则进位标志置位,AH 返回错误码。磁盘地址包的块计数字段设置为成功的块数。
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:
该函数用于获取驱动器参数。如果函数成功,进位标志清零,AH 寄存器为 00H,DS:SI 为 Filled 缓冲区,否则设置进位标志,AH 返回错误代码。
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:
该功能是媒体更换功能的扩展。如果函数成功,进位标志清零,AH寄存器为00H,否则进位标志置位,AH返回错误码。
这个函数和函数AH = 16H of INT 13H的主要区别在于我们可以指定任何驱动器号,其中函数16H只允许驱动器号00H到7FH的软盘。
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:
此函数用于启动磁盘仿真。如果函数成功,进位标志清零,否则进位标志置位,AX寄存器返回状态码,驱动器不会进入仿真模式。
可引导光盘规格包的格式如下表所示:
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)
|
可引导 CD-ROM 引导媒体类型的位字段已在下表中给出:
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:
此函数用于终止磁盘仿真。如果要终止所有仿真,请使用 DL = 7FH 调用该函数。如果函数成功,进位标志清零,否则进位标志置位,AX 寄存器返回状态码,驱动器保持仿真模式。
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:
该函数用于获取状态。如果函数成功,则清除进位标志,否则设置进位标志并 AX 寄存器返回状态码
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:
该函数用于启动磁盘仿真和引导系统。如果函数成功,则不返回任何其他内容,进位标志被设置并且 AX 寄存器返回状态码。
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:
该函数用于返回引导目录。如果函数成功,则清零进位标志,否则设置进位标志并 AX 寄存器返回状态码。 “获取引导目录”的可引导光盘格式命令包已在下表中给出:
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:
该函数用于设置硬件配置。 AL 调用此函数的函数编号如下表所示:
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 和 PIO 模式是互斥的,因此选择 DMA 会禁用指定设备或该控制器上所有设备的 PIO,选择 PIO 会禁用 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:
该函数用于发送数据包命令。如果函数成功,进位标志清零,AH 寄存器为 00H,否则进位标志置位,AH 返回错误码。 Enhanced Disk Drive Spec v3.0 命令包的格式如下表所示:
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:
此功能用于发送查询。 ST01/ST02 BIOS 不返回函数的任何成功或失败指示,因此必须假定所有命令都已成功。
ST01/ST02 BIOS 总是在之前的 BIOS 驱动器之后映射其驱动器,而不会更改 0040H:0075H 处的 BIOS 驱动器计数。此命令与 SCSI 查询命令相同
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:
该函数用于设置 DTQ(Device Type Qualifier)。该函数不返回任何内容。 DTQ 字节的位字段如下表所示:
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:
函数用于返回驱动器的标识。
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:
该功能用于停放磁盘的磁头。它用于旧硬盘,但现代硬盘不需要任何外部程序来停放磁头。
子功能 00H 停放磁头(SCSI 停止命令)和子功能 01H 取消停放磁盘的磁头(SCSI 启动命令)。
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:
为 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:
这些功能已被正式列为“保留”。
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:
该函数用于获取常驻代码段。 AX 返回驻留代码段。
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:
该函数用于刷新缓存。
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:
函数用于禁用缓存。
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:
该函数用于启用缓存。
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:
该功能用于设置 1024 – 气缸标志。除 AH=EEH 和 AH=EFH 外,所有 INT 13H 调用都会清除该标志。磁盘管理器也支持这些调用。该函数相当于调用函数 AH=EFH 且 CX=0400H 为支持该调用的软件调用。
HyperDisk v4.01 及更高版本和 PC-Cache v5.5 及更高版本也支持此功能,以允许使用 SWBIOS 访问超过 1024 个柱面的驱动器缓存。
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:
该函数用于设置圆柱偏移。对于支持该调用的软件,函数AH=EEH 等价于CX=0400H 调用该函数。除了 AH=EEH 和 AH=EFH 之外,所有调用的 INT 13H 都将柱面偏移重置为 0。
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:
该功能用于安装检查。如果函数成功进位标志被清除并且DX返回配置字,否则进位标志被设置。
如果其他 SWBIOS 扩展可用,则设置第 15 位。磁盘管理器也支持这些调用。
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:
此函数用于获取扩展的 Cylinder 计数。 INT 13H 的函数 AH = 08H 将返回截断为 1024 的柱面计数。没有此扩展的 BIOS 将返回计数模数 1024。磁盘管理器也支持这些调用
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:
此功能用于设置 Turbo 模式。下表给出了用 BL 调用函数的子函数编号:
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
|
如何在 C 编程中使用 INT 13H 扩展
我们可以使用前面章节中使用的相同 C 函数(int86()、int86x() 等)调用 INT 13H 的扩展函数。让我们通过一个例子来学习它。
以下示例重点介绍了三个功能(检查扩展是否存在、扩展读取和扩展写入)。不过本章我们不会使用扩展写函数。
如果 INT 13H 存在扩展,程序首先检查是否支持扩展,它读取磁盘的绝对扇区 0(即 MBR)。程序的编码按以下方式进行:
/* 使用 INT 13 BIOS 扩展程序访问超过 8.46 GB 的扇区 */
#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()
{
/* 它将以与 read_sectors 函数相同的方式编写,除了函数编号在此函数中为 0x43。我们将在下一章讨论扩展写入函数。
在使用此功能之前,请检查并确认您将要做什么。你应该对你将要做什么有正确的了解。在缺乏知识或粗心的情况下使用此功能可能会破坏您的数据。 */
}
/// 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]);
}
}
对程序编码的评论
typedef 将标识符分配给数据类型,以便 typedef unsigned char Byte;为数据类型 char 分配标识符 Byte。类似地,标识符 Word 被分配给 int,而 DWord 被分配给 long。
disk_packet 结构被加载到 DS:SI 并执行命令(例如扩展读取、扩展写入或验证等)。参见前面给出的 IBM/MS INT 13H Extensions(Function 41H to Function 49H)的功能。
check_ext_present() 函数检查扩展是否可用/支持。该函数使用 BX=55AAH (inregs.x.bx=0x55AA;) 调用,如果支持扩展,则 BX 寄存器设置为 AA55H。 (参见前面给出的函数 41H)
函数read_sectors用于读取磁盘的绝对扇区,由disk_pack.lba1指定。在这个程序中,我们给定了 disk_pack.lba1=0,因此我们将读取绝对扇区 0(参见下面的注释),从而读取磁盘的 MBR。
write_sector 函数也与 read_sectors 函数相同,并且将以相同的方式写入,但具有不同的 Function 选项。我们将在接下来的章节中使用它。
注意:
我们通过以下两种方式读取磁盘扇区:
- 相对扇区读(或写)
- 绝对扇区读取(或写入)
在相对扇区读取中,我们根据磁盘的 CHS(柱面、磁头和扇区)几何形状读取磁盘扇区。在相对扇区读取中,磁盘的 MBR(磁盘的第一个扇区)位于 Cylinder 0、head 0 和 Sector 1。
在磁盘扇区的绝对读取中,我们不需要在我们的程序中指定柱面或磁头编号。绝对扇区从绝对扇区 0 开始计算。
因此,如果我们要读取磁盘的 MBR(磁盘的第一个扇区),我们将读取绝对扇区 0。BIOS 的工作是将绝对扇区号转换为其对应的 Cylinder,Head和扇区号。
与绝对扇区读(或写)一样,在整个磁盘读或写等操作中,我们只需要计算循环内的绝对扇区,而在相对扇区读(或写)的情况下,我们需要一次运行三个循环来计算 CHS,因此绝对扇区读/写比相对扇区读/写快得多。
例如, 如果我们有一个 16 个磁头(边)、12 个圆柱体和 63 个扇区的硬盘,下面给出的表格显示了两种读取方法的过程和差异,从而显示了绝对扇区的方法可能会使我们的耗时程序(例如整个磁盘读取/写入或整个磁盘擦除程序等)运行得更快:
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
|
任何磁盘MBR分析工具显示的MBR分区表信息如下:
以上信息中,两个分区起始的相对扇区号分别为63和11277630,不包括分区,按磁盘可用扇区数计算。