Protection mode knowledge (3)

zhaozj2021-02-16  55

The descriptor has already mentioned that the descriptor is a structure that describes 8 bytes of the size, address, and various states, which can define it when programming. As shown in FIG. 2, according to the descriptor Different, the descriptor can be divided into three types of memory segment descriptors, system segment descriptors, and door descriptors, and the door descriptor can also be divided into four categories of call doors, task doors, interrupt gates, and traps. The descriptive role and its meaning will be described below: 1. The memory segment descriptor memory segment descriptor is the code segment and data segment in the program, which also includes a stack segment, in the protection mode, should be put The stack segment is understood as a special data segment. When analyzing the memory segment descriptor, it should be divided into 4 domains: the first domain is the 0th to 1 byte of the descriptor, the word is the lower 16 bits of the segment line, the segment line is the size of the description segment. Bit, high 4 bits in the low 4 bits of the sixth byte; the second field is the 2nd to 4th bytes of the descriptor, these three bytes are 24 bits of segment baseline; the third domain is The 5th, 6th bytes of the descriptor are stored in some attributes of the segment; the fourth domain is the last byte, which is stored in the number of segment bases. Next, each bit of the property word is described: as shown in FIG. 2 illustrates whether the segment depicted by the P bit means that the segment depicting the descriptor is in memory, P = 0 represents the descriptor The segment described is not in memory. DPLs are privileged levels described in the descriptor, and only the valid privileged EPL is greater than or equal to DPL. The DT bit must be 1 to distinguish between system segment descriptors. TYPE field: Bit 0 indicates whether the segment being described is accessed, and the bit is 0 indicates that it is not accessed, and 1 means that the segment has been previously accessed. The definition of bit 1 is the type of the segment described in the descriptor. When the described code segment is described, it is read if the described code segment is read, and is read, 0 is not read; when the data segment is described, the bit indicates whether the data segment is described. Write, write to write, and do not write for 0. The definition of bit 2 is also the type of segment described in the descriptor. When the code segment is described, the bit indicates whether the described code segment is one to the code segment, indicating that the code segment is one to the code segment, indicating that the code segment is not one to the code segment, ie a normal code segment. . When the described data segment is described, the bit indicates the expansion direction of the segment, indicating that the segment is expanded to the lower address, and is 0 indicates that the segment is expanded to the high address. Bit 3 indicates the segment type described, 1 means the described segment is a code segment, which is possible to execute, 0 indicating the described segment is a data segment, is not performed. As mentioned earlier, in the protection mode, the stack segment should be understood as a special data segment, and the stack segment is also included in 0. The G bit represents the count unit of the segment boundary, which indicates that the segment boundary is limited to byte, indicating in 4k. This calculates that the 20-bit segment boundary can describe segments of size 64k or 4G, and D bits illustrate the segment described by the descriptor is a 32-bit environment or a 16-bit environment. This determines the number of operands used in the instruction and the default size of the address. It is a 32-bit address and a 32-bit operand, which is a 32-bit segment; it is 0, it is a 16-bit address and 16-bit operand, ie 16-bit segment. But you can still use the operand and address size prefix to change this default setting. This bit determines whether the system uses IP or EIP, using SP or ESP, Second, the system segment descriptor system segment descriptor is to describe two special segments, which are partial descriptor table LDT segments and task status segments TSS. As can be seen from FIG. 2, the difference between the system segment descriptor and the memory segment descriptor is only in the DT bit, and the DT = 1 is a memory segment descriptor, and the DT = 0 is a system segment descriptor, and the two descriptors rely on this bit. Distinguish. However, the TYPE field of the system segment descriptor and the TYPE of the memory segment descriptor is completely different. Description: TYPE field: 0, 1 two definitions depend on bit 2. When 2 is 1, it is illustrated whether the door descriptor is 0, and the non-door descriptor is explained.

When 2 is 1, 0, 1 determines the type of the door descriptor because two digits can have 4 states, so it is exactly 4 descriptors, and 0 is 0, it is 1, it is task. The door, 2 times, is interrupted door, 3 times is a trap door; when 2 is 0, the low two 0 digits, 1 bit is 0 when 0 is 0, which is 1 time is the available 286 TSS, At 2, the LDT is LDT, 3, is a busy 286 TSS. When bit 4 is 0, if other bits are 0 or lower than 2 or 3 times, it is not defined, otherwise the bit prompt is 386 or 286 descriptor, and the segment base address and segment limit are arranged in two The reason for separating the domain is also related to this, please readers think about it! Third, the door descriptor can see that the door descriptor is distinguished by the TYPE field and the system segment descriptor, but the gate descriptor is not structured from the system segment descriptor in FIG. One, in fact, this is the key to distinguishing between them. The low 4 bits of the fourth byte of the door descriptor are double-word count fields. This field is to copy the parameters in the outer stack to the number in the inner stack when a privileged transformation occurs. Unit. See "Protective Level Check" in Protection Mode for privileged transformation. (To be continued)

转载请注明原文地址:https://www.9cbs.com/read-28088.html

New Post(0)