Hard Disk parameter table

Source: Internet
Author: User
1> what is a hard disk parameter table?
The position of the interrupt vector in the interrupt vector table set by BIOS in PC (4*0x41 =
0x0000: 0x0104) is not the address of the interrupted program, but the basic parameter table of the first hard disk.
For 100% compatible bios, the first address of the hard disk parameter table array is 0xf000: 0e401.
The entry address of the basic parameter table of the second hard disk is stored at the int 0x46 interrupt vector position.
The data table size is 16 bytes.
2> what is A20?
In section 8086/8088, there are only 20 address buses, so the accessible address is 2 ^ 20 = 1 m,
In 8086/8088, the 16-bit address mode can indicate that the address range is 0-64 K, so in 8086/
8088 can access 1 MB of memory, Intel adopts the segmented mode: 16 bit Segment Base Address: 16 bit offset.
The absolute address calculation method is as follows: shifts the 16-bit base address 4-bit or 16-bit offset = 20-bit.
However, this method causes a new problem. Through the above segmentation mode, the maximum memory can be expressed:
Ffffh: ffffh = ffff0h + ffffh = 10 ffefh = 1 m + 64k-16bytes (1 m excess part is
But 8086/8088 only has 20-bit address lines. If you access the 100000 H-
10 ffefh memory, there must be 21st IP lines. So when the programmer gives more than 1 m
(100000h-10ffefh ).
The calculation starts from 0. That is to say, when the system calculates the actual address, the model is calculated based on 1 m.
This technology is called wrap-around.
By 80286, the address bus of the system has grown to 24, so that the memory that can be accessed can reach
2 ^ 24 = 16m. Intel's goal in designing 80286 is to show the behavior of the system in real mode.
It should be exactly the same as 8086/8088, that is, in the real mode, 80286 and subsequent systems
Columns should be fully compatible with 8086/8088, but in the end, the 80286 chip has a bug: If the programmer
Access the memory between 100000h-10ffefh, the system will actually access this memory, instead
The sample starts from 0 again.
To solve the problem above, IBM uses some of the remaining output lines on the keyboard controller to manage 21st
The root address line (starting from 0 to 20th) is called the A20 gate. If the A20 gate is opened
When the programmer gives an address between 100000h-10ffefh, the system will actually access this memory Zone
If the A20 gate is disabled, when the programmer gives an address between 100000h-10ffefh,
The system still uses the 8086/8088 method. The default A20 gate for most ibm pc compatible hosts is
Forbidden. Because there was no better way to solve this problem at the time, IBM used keyboard control.
In the 80286 and later series PCs, even if the A20 gate is opened
In this mode, the maximum memory that can be accessed is 10 ffefh, even though their address bus can
The access capability is greatly higher than this limit. In order to access the memory above 10 ffefh
Inbound protection mode.
A20, in fact, is a special processing for 20-bit (starting from 0) (that is, for 21st
Address Line Processing). If A20 gate is disabled, for 80286, its address is 24bit, and its address table
Show as efffff; for the 32-bit chip with an extremely high latency of 80386, its address is expressed as ffefffff.
This indicates that if the A20 gate is disabled, the 20-bit indicates that when the CPU is used for address access
The value is always 0. If the A20 gate is opened, the 20-bit value is valid,
The value can be either 0 or 1.
Therefore, in protection mode, if the A20 gate is disabled, the available memory can only be an odd number.
1 M Segment, that is, 1 m, 3 M, 5 m ..., That is, 00000-fffff, 200000-2fffff, 300000-3fffff ....
If the A20 gate is enabled, the memory that can be accessed is continuous.
3> how to enable A20 address line
Most PCs use a keyboard controller (8042 chip) to process the A20 gate. Theoretically
The A20 gate method is to set 2nd-bit of the 8042 chip output port (64 h), but in fact, when
When you write to the 8042 chip output port, there may be other numbers in the keyboard buffer.
Data has not been processed, so you must first process the data.
The process is as follows:
1. Interruption prohibited;
2. Wait until the 8042 input buffer is empty;
3. Send a command to prohibit keyboard operation to 8042 input buffer;
4. Wait until the 8042 input buffer is empty;
5. Send the 8042 output PORT command;
6. Wait until 8042 output buffer has data;
7. Read the 8042 output buffer and save the obtained bytes;
8. Wait until the 8042 input buffer is empty;
9. Send the write 8042 output PORT command to 8042 input buffer;
10. Wait until 8042 input buffer is empty;
11. Write the 8042 position 1 (or 2) of the byte obtained from the 2nd output port to 8042
Input buffer;
12. Wait until the 8042 input buffer is empty;
13. Send a keyboard operation command to 8042 input buffer;
14. Open the interrupt.
4> how to check whether the A20 address line is enabled
As we have mentioned earlier, if the A20 gate is opened, the programmer can
Direct access to 100000h ~ 10ffefh memory, if A20 gate is disabled, then in real mode,
If the programmer accesses H ~ Memory between 10 ffefh is automatically converted to 0 h ~ by hardware ~ 0 ffefh
So we can use this difference to check whether the A20 gate is opened.
5> Cr0 register
The Cr0 register is one of the four control registers of the processor. The structure is as follows:
+ ---- + -------------------------- + ---- +
| PG | reserved | et | ts | em | MP | PE |
+ ---- + -------------------------- + ---- +
31 30 5 4 3 2 1 0
Bit 0: PE if this bit is set, the protection mode is run; otherwise, the actual mode is run.
Bit 1: MP controls wait commands
Bit 2: Em indicates whether the coprocessor function can be simulated
Bit 3: ts for task Conversion
Bit 4: et indicates the type of the current coprocessor (80287 or 80387)
Bit 31: PG indicates whether the processor uses the paging Mechanism
6> Descriptor Table
The addressing mode of memory in the protection mode is different from that in the real mode.
The 16-bit address of the device is shifted to four places left, And the offset is added to form a 20-bit address.
Addressing 4 GB space, because there are 32 and address lines, SO 2 ^ 32 = 4 GB. In this mode, it is a pass segment
The index value of the Register is searched in the Descriptor Table (gdt in the Global Descriptor Table or LDT in the Local Descriptor Table ).
To the corresponding table, and then get the base address of the segment saved in the table item, the base address of the segment and the offset are added.
Obtain the linear address. If the system does not adopt the paging processing mode, the linear address corresponds to the actual
The physical address. The paging processing mode is put in the memory management document for detailed description.
Segment register format:
+ -------------------------------- + ------ + ----- +
| Index | Ti | RPL |
+ -------------------------------- + ------ + ----- +
15 32 1 0
RPL: Priority Level 0-4 Linux only uses 0 core State 3 user State
Ti: 0 uses the Global Descriptor Table (gdt), 1 uses the Local Descriptor Table (LDT)

The Descriptor Table is stored in the GDTR or ldtr register, which occupies 6 bytes in total
Small. 0-15 bits are table restrictions, and 16-47 bits are the base addresses of tables. The table limit indicates the table size, and the base address is the table size.
Location in the linear address of the descriptor table.
The structure of the global descriptive symbol table is the same as that of the local descriptive symbol table, as shown below:
+ --------------------------------- + ---------- +
| Base address | limit |
+ --------------------------------- + ---------- +
47 1615 0
The Descriptor Table item is the content stored in the descriptor table. Intel sets the first item of the table item
It is null. The structure of the. Descriptor Table item used since 2nd table items is defined as follows:
63 5655 5251 4847 4039 3231 1615 87 0
+ --------- + ---- + ------- + ----- + --------- + ------------- + ----------------- +
| B31-B24 | L19-L16 | B23-F8 | base address B15-B0 | segment ceiling L15-l0 |
+ --------- + ---- + ------- + ----- + --------- + ------------- + ----------------- +

+ ------ +
| G | D/B | o | AV |
+ ------ +
55 52
G: = 1 segment length in 4 K Bytes = 0 Segment Length in bytes
D/B: = 1 indicates 32-bit access to this segment. = 0 indicates 16-bit access.
O: Always 0
AV: can be used by software, and the CPU ignores this bit.

+ ----- + ---------- + ----- + ------- + ------ +
| P | DPL | S | E | ED/c | r/w | A |
+ ----- + ---------- + ----- + ------- + ------ +
47 44 43 40
A: = 1 already accessed = 0 has not been accessed
R/W: --- +
Ed/C: --- | ---- + ---> + ---- E = 0 Data Segment
E: --- + |
| + ---- ED = 0 stretch up (Data Segment) Ed = 1 stretch down (stack segment)
|
| + ---- W = 0 cannot be written W = 1 can be written
|
+ ---> + ---- E = 1 code segment
|
+ ---- C = 0 ignore privileged level C = not ignore privileged level
|
+ ---- R = 0 cannot read r = 1 readable
S = 0 indicates the system segment used for System Management = 1 indicates the general code segment or data segment
DPL: privileged
P = 1 this segment is in memory = 0 is not in memory

1st Floor

Basic hard disk parameter table
In the interrupt vector table, the interrupt vector location of int 0x41 (4*0x41 = 0x0000: 0x0104) is not the place where the interrupt program is stored.
Address is the basic parameter table of the first hard disk. For 100% compatible bios, the first address of the hard disk parameter table array is stored here
F000h: e401h. The entry address of the basic parameter table of the second hard disk is stored in the int 0x46 interrupt vector.
Table hard disk basic parameter information table

Displacement description
0x00-Number of cylinders
0x02 bytes
0x03 words start to reduce the write current of the cylindrical surface (pc xt only, other 0)
0x05 words pre-compensated cylindrical number before writing (multiplied by 4)
0x07 maximum ECC burst length (for XT only, 0 for others)
0x08 bytes control byte (step-by-step selection)
Bit 0 unused
Bit 1 reserved (0) (disable IRQ)
Bit 2 can be reset
Bits 3. If the number of magnetic heads is greater than 8, 1 is set.
Four unused bits (0)
(5) If there is a producer's bad zone graph at the number of cylinders + 1, set it to 1.
Bit 6 disable ECC retry
Bit 7 prohibit access and try again.
0x09 bytes standard timeout value (used only by XT, and 0 for others)
0x0a bytes formatting timeout value (only used by XT, and 0 for others)
0x0b bytes drive time-out value (XT only, 0 for others)
0x0c head (STOP) Cylinder Number
0x0e bytes per track sector
0x0f bytes are retained.
Hard Disk device number naming method
The master device Number of the hard disk is 3. The main device numbers of other devices are:
1-memory, 2-disk, 3-hard disk, 4-ttyx, 5-tty, 6-parallel port, 7-non-Named Pipe
Since one hard disk can have 1-4 partitions, the hard disk is also partitioned according to the device number of different times. Therefore
The logical device number of a hard disk is composed of the following methods:
Device No. = master device no. * 256 + sub-device No.
That is, dev_no = (Major <8) + minor
The following table lists all the logical device numbers of the two hard disks.
Table logical device numbers of Hard Disks
Description of the device file corresponding to the logical device number
0x300/dev/hd0 represents the entire 1st Hard Disks
0x301/dev/hd1 indicates 1st partitions of 1st hard disks.
0x302/dev/hd2 indicates 1st partitions of 2nd hard disks.
0x303/dev/hd3 indicates 1st partitions of 3rd hard disks.
0x304/dev/hd4 indicates 1st partitions of 4th hard disks.
0x305/dev/hd5 represents the entire 2nd hard disks.
0x306/dev/hd6 indicates 2nd partitions of 1st hard disks.
0x307/dev/hd7 indicates 2nd partitions of 2nd hard disks.
0x308/dev/hd8 indicates 2nd partitions of 3rd hard disks.
0x309/dev/hd9 indicates 2nd partitions of 4th hard disks.

0x300 and 0x305 do not correspond to any partition, but represent the entire hard disk.
Linux Kernel version 0.95 does not use this cumbersome naming method, but uses the same naming method as it is now.
5.4.3.5 Hard Disk Partition Table
To share hard disk resources among multiple operating systems, the hard disk can be logically divided into 1-4 partitions. Fan area number between each partition
Is adjacent. A partitioned table consists of four table items. Each table item consists of 16 bytes. It corresponds to the information of a partition and stores the partition size.
And start and end of the cylinder number, track number and fan area number, as shown in the following table. The partition table is stored in the hard disk's 0-core, 0-header, 1st-sector 0x1be -- 0x1fd
.
Table Hard Disk Partition Table Structure
Location name size description
0x00 boot_ind byte boot flag. Only one of the four partitions is bootable.
0x00-do not boot the operating system from this partition; 0x80-boot from this partition
System.
The START head number of the 0x01 head byte partition.
0x02 sector byte partition start fan area number (bit 0-5) and start cylindrical number height 2 bits (bit 6-7 ).
0x03 cyl: the start Cylinder Number of the byte partition is 8 bits.
0x04 sys_ind byte partition type byte. 0x0b-dos; 0x80-old minix; 0x83-linux...
0x05 end_head end head number of the byte partition.
0x06 end_sector Byte end fan ID (0-5) and end cylindrical number (6-7 ).
0x07 end_cyl the number of the ending cylinder in the byte is 8 bits.
0x08 -- 0x0b start_sect long-character partition start physical fan area number.
0x0c -- 0x0f nr_sects number of sectors occupied by long-character partitions.
__

After the BIOS completes execution, place the hard disk parameter somewhere, and its entry address is specified by the interrupt vector No. 0x41.

The address of the interrupt vector 0x41 is 4*0x41 (four bytes per vector)
Use bochs to view [XP/11x0x104]
0x00000104 <bogus + 0>: 0x9fc0003d 0xf000ff53 0xc0002544
0xf000ff53

Visible portal address: 0x9fc0003d

The first byte of the entry address is the offset (0x003d), and the last two byte is the segment address (0x9fc0). Therefore, the physical address is 9fc00 + 003d = 0x9fc3d.

View the hard disk parameter table [XP/11x 0x9fc3d]
0x0009fc3d <bogus + 0>: 0x00040132 0x00ffff00 0x000000c0
Zero X 00110132

Bytes 0132 are the number of cylinders, that is, 0x3201 (not 0 x 2nd), bytes are the number of Magnetic Heads 0x04, and the last and second bytes are the number of non-magnetic sectors, 0x11

A hard disk can be regarded as a cylindrical disk. The three parameters are as follows:
Head, which side?
Cylindrical circle
Slice, the arc in the ring

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.