Implementation of an operating system: protection mode and real-mode jump and segment descriptor high-speed buffer register

Source: Internet
Author: User

It is still the third chapter. It looks so slow. In fact, it is very easy to jump from the real mode to the protection mode. The main note is that the jump command

 

Jmp dword selectorcode32: 0
// But not
JMP selectorcode32: 0

This is because the 16-bit code is compiled. If the offset of the target address is not 0, it is a large value, such

 

jmp SelectorCode32:0x12345678  

After compilation, the offset will be truncated, with only 0x5678 left.

 

Therefore, this special jump requires special processing. In Linux kernel (at&t assembly is used in Linux, rather than the common ibnmpc assembly), this jump is achieved by directly writing binary code using DB commands, NASM obviously provides a better solution, that is, adding a DWORD. Originally, the DWORD should be added before the offset, but NASM can be added before the whole address, as we did before, this is also the advantage of NASM. In short, a program can contain multiple different bit segments, 32-bit or 16-bit, and they can also jump to each other, but 32-bit segments use 32-bit registers, the 16-bit code segment uses a 16-bit register. To use a 32-bit register in a 16-bit segment, the DWORD displayed must be the same as the forced type conversion in advanced languages.

 

However, switching from the protection mode to the back-to-reality mode is not so easy to understand, at least I think so, because before preparing to end the protection mode to return to the actual mode, you need to load a suitable descriptor to select Sub-to the relevant segment register, so that the corresponding segment descriptor high-speed buffer register
(See the following explanation) contains the appropriate segment boundaries and attributes (the correct segment boundary here is obviously 64 K, that is, 0 ffffh, and the attribute should be da_drw, that is, 90 h can read and write data segments), and can only be returned from 16-bit code segments. This is because the attribute in the CS high-speed buffer register does not meet the requirements of the real mode when a 32-bit code segment is returned (the real mode cannot change the segment attribute ).

 

In real mode, the segment register contains the segment value. When a physical address is formed for access to the memory, the processor references a specific segment register and times its value by 16 to form a 20-bit segment base address. In protection mode
Memory contains segment Selection Sub-, as described above, in order to access the memory to form a linear address, the processor needs to use the base address and other information in the descriptor specified by the sub-selection. To avoid the need to access
Obtain the corresponding segment descriptor from the descriptor table. From 80286 onwards, each segment register is equipped with a high-speed buffer register, which is called the segment descriptor high-speed buffer register.
Or descriptor projection register, for programmers
It is invisible. When a Selection Sub-is loaded into a segment register, the processor automatically extracts the corresponding descriptor from the descriptor table and saves the information in the descriptor to the corresponding high-speed buffer register. After that
During this segment of access, the processor uses the descriptor information in the corresponding high-speed buffer register, instead of getting the descriptor from the descriptor table.

The newly added normal descriptor with a segment limit of 64 K and the attribute da_drw is suitable for loading the corresponding selectornormal to DS, es, and SS before returning the actual mode.

 

 

Bytes ------------------------------------------------------------------------------------------------------

 

Repost my blog article solemnly states: the famous author of a technical website can be reprinted, and a commercial website can be reprinted only with my consent; otherwise, the website will be held accountable --

Pang123hui blog:

Blog Park http://www.cnblogs.com/pang123hui/


Csdnhttp: // blog.csdn.net/pang123hui/



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.