Summary of the actual mode and protection mode

Source: Internet
Author: User

I have been reading this item during this time. Today I will summarize it:

To understand the real and protection modes, let's talk about the history of intel X86 CPU development.

 

Starting from 8086, 8086 is a 16-bit CPU (why is it a 16-bit address line? No, because 8086 is a 20-bit address line, which generally refers to the width of the "arithmetic logic unit" ALU In the processor. The data section in the system bus, known as the "Data Bus", usually has the same width as ALU ). 8086 is a 20-bit address line that can address 2 to the power of 20, that is, 1 m address space. The ALU of 8086 is only 16 bits in width. How can we address 1 m space ?? Intel implements the following:

Physical address = segment value x 16 + offset (both segment value and offset are 16 bits)

I believe that everyone has studied in college, but at that time I believe that many people are just like me...

 

In this way, the memory is divided into several 64 K segments (why is it 64 K? I am stupid when I look at it for a long time and I don't know why. I only know it after drawing it, for example, can the red Address 64 K memory address at the power of 16 through the offset)

 

19 18 17 16 15 14 13 12 11 10 9 8 6 5 4 3 2 1 0

| --------------------------- Segment address ----------------------------- |

| ---------------------------- Offset ----------------------- |

 

 

I 've talked a lot about the real mode and the protection mode? In fact, the above addressing method is "real mode". By changing the value of the segment register, we can freely access any unit in the memory without any restrictions, you cannot restrict memory access, so you cannot protect the system. Therefore, it is impossible to construct an operating system in the modern sense in the real mode.

 

 

To address this defect of 8086, 80386 stands out (in fact, there is still a 80286 transition in the middle, which is not mentioned here), 80386 is a 32-bit address line, and the addressing capability reaches 4G. ALU is also 32-bit. Is the addressing method of the actual mode discarded above? Actually, it does not support the previous real mode, but also the protection mode. Its protection mode is implemented as follows: it still uses seg: offset to represent it, except that this value is not the actual physical address, but an index, this index points to a table item in a data structure. The table item defines the starting address, boundaries, attributes, and other content of the segment in detail. This is gdt (or LDT ), that is, "descriptor"

 

Gdt contains 8 bytes. Why do we call this mode as the protection mode? This is because these 8 bytes are not long-winded here. Simply put, a bunch of protection attributes are defined in it, for example, the descriptor's privileged level DPL is in the range of 0-3. Generally, 0 is the highest level, system level, and 3 is the lowest level, which can be used to protect the system, for example, privileged commands that have a major impact on the system cannot be used at the user level.

 

I am talking a little rough here, but I just set up my impression on the real mode and protection mode.

Let's take a look. When an Access Memory Command sends out a memory address, the CPU sums up the address that should actually be placed on the data bus:

1) determine the register segment to use based on the nature of the instruction. For example, the address placed in the transfer instruction is in the code segment, and the address in the data segment is in the data segment.

2) Find the corresponding "descriptor" based on the content of the segment register ";

3) obtain the base address from the descriptor

4) use the address issued in the instruction as a displacement to check whether the IP address is out of the boundary compared with the boundary in the descriptor;

5) Determine whether the authorization is unauthorized based on the nature of the instruction and the access permission in the descriptor;

6) use the address issued in the instruction as the displacement and add it to the base address to obtain the actual "physical address"

 

These things can be realized without reading them once or twice. I did not really understand these things, if you really need to understand it, you still need to write a program that converts the real mode to the protection mode. We recommend that you read the book "write your own operating system" to teach you to enter the protection mode step by step.

 

 

 

 

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.