Real mode, protection mode, and virtual 8086 Mode

Source: Internet
Author: User

1. Three operating modes of 386 processors
Generally, 80x86 (80386 and later generations of CPUs) can run in three modes: real mode, protection mode, and virtual 8086 mode. Real mode is the operating environment of the ancient MS-DOS. Win95 and later operating systems only use two modes: protection mode and virtual 8086 mode. The security mode is a diagnostic mode for windows. In this mode, the system only loads the most basic necessary modules and drivers for troubleshooting and solving problems. The following are the differences between the three modes:
The real mode is the mode when the CPU is started. This mode is equivalent to a super-fast 8086. It cannot use multiple threads, achieve permission classification, or access more than 20 address lines, that is to say, only 1 MB of memory can be accessed.
After the operating system takes over the CPU, the CPU enters the protection mode. At this time, it can exert all the power of 80x86, including permission classification, memory paging, and other functions. In the protected mode, all 32 address lines are valid and can address up to 4 GB of physical address space; extended memory segment management mechanism and optional memory paging management mechanism, it not only provides hardware support for Memory sharing and protection, but also provides hardware support for implementing virtual memory. It supports multiple tasks to quickly switch tasks and protect the task environment; the four privileged levels and comprehensive privileged inspection mechanisms enable resource sharing, security and confidentiality of code and data, and task isolation. The virtual 8086 approach is supported, easy to execute 8086 programs. The protection mode has many advantages. One of the most direct advantages is that the memory uses paging and segmented management methods, so that application relocation and virtual memory become possible. Your program can use more memory!
Paging and segmentation are controlled by the operating system. Therefore, compared with the actual mode, applications have much less permission to directly operate on hardware. Therefore, the system cannot crash due to application crash, so it is called "protection ".
Virtual 8086 mode is the real mode running in protection mode, in order to execute pure 16-bit programs in 32-bit protection mode. It is not a real CPU mode, but also a protection mode.

2. identify the reasons for the real and protection Modes
At the beginning of the x86 system, the processor had only 20 address lines and the addressing register was 16 bits. We know that 16-bit registers can access 64 K address space. If the program wants to access memory larger than 64 K, it needs to segment the memory, each segment is 64 K, use the segment address + offset to access the address. In this way, the maximum addressing space can be 1 MB for the full use of 20 address lines, which is already very large memory space.
In fact, the real mode regards the entire physical memory as a segmented area. The program code and data are located in different regions, and the system program and user program are not treated differently, in addition, each pointer is directed to the actual physical address. In this way, if a pointer of a user program points to the system program area or other user program areas and modifies the content, then for the modified system program or user program, the consequences may be disastrous. Furthermore, with the development of software, the addressing space of 1 MB is far from meeting the actual needs. Finally, the demand for multi-task support for processors is becoming increasingly urgent, and all these have prompted the emergence of new technologies.
To overcome the problem of illegal memory access in real-world mode and meet the rapidly developing requirements of memory addressing and multi-task, processor vendors have developed a protection mode. In the protection mode, in addition to greatly improving the memory addressing space, the hardware supports multiple tasks, the physical memory address cannot be directly accessed by the program, and the internal address (virtual address) of the program) the program is not aware of the need to be accessed by converting the operating system to a physical address. At this point, the process (the running state of the program) has a strict boundary, and no other process can access its own physical memory region, not even in the scope of your own virtual address, because some virtual areas have been put into some public system runtime libraries. These regions cannot be modified at will. If modified, a segment error occurs in Linux or an invalid memory access dialog box in windows.
The fundamental difference between the protection mode and the actual mode is whether the process memory is protected or not. The difference between addressable spaces is only the result of this reason. The real mode regards the entire physical memory as a segmented area. The program code and data are located in different areas, and the system program and user program are not treated differently. In addition, each Pointer Points to a "real" physical address. In this way, if a pointer of a user program points to the system program area or other user program areas and changes the value, then for the modified system program or user program, the consequences may be disastrous. To overcome this poor memory management approach, processor vendors have developed a protection mode. In this way, the physical memory address cannot be directly accessed by the program. The internal address (virtual address) of the program must be converted from the operating system to the physical address for access. The program knows nothing about this.
At this point, the process (now we can call the program a process) has a strict boundary, and no other process can access its own physical memory area, not even in the scope of your own virtual address, because some virtual areas have been put into some public system runtime libraries. You cannot modify these regions as needed. If you modify these regions, there will be: SIGSEGV (Linux segment error); illegal memory access dialog box (Windows dialog box ). The CPU startup environment is in 16-bit real-time mode, and then you can switch to the protection mode. However, you cannot switch back to the actual mode from the protection mode.


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.