80386 Protection Method Introduction

Source: Internet
Author: User
Tags execution

80386 has three ways of working: Real mode, protected mode, and virtual 8086 mode. This paper introduces 80386 and related program design contents in the protection mode. The basic concepts of 80386 registers, addressing methods and instructions in real mode are still maintained in addition to the external protection method.
Although the 80386 function in real mode is much larger than its previous processor (8086/8088,80186,80286), only 80386 can really play a larger role in the protection mode. Under the protection mode, all 32 address lines are valid, addressable up to 4G bytes of physical address space, extended memory segmentation management mechanism and optional memory paging management mechanism, not only provide hardware support for memory sharing and protection, but also provide hardware support for virtual storage; support multitasking, Can quickly task switching and Protection task environment, 4 privilege level and perfect privilege checking mechanism, can realize resource sharing and guarantee code and data security and confidentiality and task isolation, support virtual 8086 mode, easy to execute 8086 programs.
< a > Storage management mechanism
In order to provide hardware support for the protection and sharing of program and data in memory, in order to provide hardware support for realizing virtual memory, 80386 not only adopts extended memory partition management mechanism, but also provides optional memory paging management mechanism. These storage management mechanisms are implemented by the 80386 storage Management components MMU.
1. Target
80386 has 32 address lines, and they all work in protected mode, so addressable physical address space can be as high as 4G bytes. In a PC compatible computer system with 80386 and above processors as CPU, the memory of the address under 1M is called conventional memory, and the memory of the address above 1M is called extended memory.
80386 also provides support for implementing virtual storage. Although 80386 addressable physical address space is large compared to 8086 addressable 1M byte physical address space, it is not possible for the actual microcomputer system to install such physical memory. Therefore, in order to run large programs and truly multi-task, virtual memory must be used. Virtual memory is a combination of hardware and software that provides much larger storage space than the physical main memory that can actually be used in a computer system. In this way, programmers do not have to consider the actual capacity of physical memory in a computer when writing programs.
80386 also provides support for the sharing and protection of code and data stored in the memory. Task A and Task B coexist, the task A and task B must be isolated to avoid mutual influence. But they might also want to share some of the code and data. As a result, 80386 supports both task isolation, sharing of shared code and data, and support for privileged protection.
2. Address space and address translation
The virtual storage in the protected mode consists of a variable size storage block, which is called a segment. 80386 describes the position, size, and use of the segment using data called descriptors. The address (logical address) of a virtual memory consists of a selector that indicates the descriptor and an offset in the paragraph, such that the address set is called the virtual address space. 80386 the virtual address space supported can be up to 64T bytes. The storage address space that programmers use when they write programs is virtual address space, so they can think of a large enough storage space to use.
Obviously, only programs in physical memory can be run, and only data in physical storage can be accessed. Therefore, the virtual address space must be mapped to the physical address space, and the two-dimensional virtual address must be transformed into a one-dimensional physical address. Because the physical address space is much less than the virtual address space, only parts of the virtual address space can be mapped to the physical address space. Because the physical memory size is much smaller than the physical address space, only the parts of the above section can actually be mapped to physical storage.
Each task has a virtual address space. In order to avoid multiple virtual address spaces of multiple parallel tasks mapping directly to the same physical address space, the virtual address space and the physical address space are isolated by linear address space. The linear address space is composed of one-dimensional linear addresses, and the linear address space and the physical address space are equivalent. Linear address 32 bit long, linear address space capacity of 4G bytes.
80386 in two steps to achieve the virtual address space to the physical address space to the physical address space mapping, that is, two steps to achieve virtual address to the physical address of the transformation, but the second step is optional. The following figure is a schematic diagram of the address map transformation.

The mapping of virtual address space to linear address space is realized by describing the chart and descriptor, and the two-dimension virtual address is converted into one-dimensional linear address by the segmentation management mechanism. This step is always there.
The paging management mechanism divides the linear address space and the physical address space into blocks of the same size, which are called pages. Through the mapping table established between the page of the linear address space and the page of the physical address space, the paging management mechanism realizes the mapping of the linear address space to the physical address space, and realizes the transformation of the linear address to the physical address. The paging management mechanism is optional, and when the paging management mechanism is not adopted, the linear address space is equivalent to the physical address space, and the linear address is equal to the physical address.
Segmented management mechanism is used in the variable size block, the time Division management mechanism is more suitable for dealing with complex system logical segmentation. The size of the storage block can be defined according to the appropriate logical meaning, regardless of the human limitations imposed by a fixed size page. Each segment can be treated as an independent unit to simplify the protection and sharing of segments. The fixed size blocks used by the paging mechanism are best suited for managing physical memory, both for managing memory and for external storage. Paging management mechanism can effectively support the implementation of virtual memory.
The two mechanisms of segment and pagination are two different conversion mechanisms, which are different conversion stages of the whole address translation function. Although both mechanisms utilize the conversion tables stored in the main memory, these tables have a separate structure. In fact, the Cong is stored in the linear address space, and the page table is stored in the physical address space. Therefore, the Segment conversion table can be relocated by the paging mechanism without the participation of the segment mechanism. The segment conversion mechanism converts the virtual address into a linear address and accesses the form of the segment conversion mechanism in a linear address without perceiving that the paging mechanism has converted the linear address to the physical address. Similarly, the paging mechanism is ignorant of the virtual address space used by the program's resulting address. The paging mechanism simply translates the linear address into the physical address and accesses the conversion form in the physical address, and does not know the existence of the virtual address space or even the existence of the segment conversion mechanism.
3. Virtual Memory Concept
Virtual memory is a design technique that provides much larger storage space than the physical main memory that can actually be used in a computer system. The user creates an illusion as if a very large physical storage space can be used in a program. The advantage of using virtual storage is that a program can easily run on a computer with a wide range of physical memory capacity, and programmers using virtual memory can write programs that are much larger than any physically configured physical memory. Virtual storage is supported by a storage management mechanism and a large capacity fast hard disk memory. At any point in the program's operation, only a small portion of the virtual address space is mapped to the main memory, while the remainder is stored on disk. Because only a portion of the virtual memory stored in the main storage can be used by the processor, this virtual storage technology relies on the internal access of the program to the local characteristics of the memory, where only a small amount of storage content in the entire virtual memory resides in the main storage. When the scope of the access memory changes, it is necessary to transfer some parts of the virtual memory from the disk into the main memory, the other part of the virtual memory, can also be transferred from the main memory back to disk.
The address translation mechanism supports virtual storage in two ways.
First, the virtual memory which resides in the main memory is marked as invalid, and the virtual-physical mapping relation of the virtual memory resident part is established, and the corresponding virtual memory address of the resident part is converted to the address of the corresponding physical memory. If the program accesses a virtual address that corresponds to a part of the virtual storage that is not resident, the exception is caused by invalid mapping information. The operating system handles this exception by reading the non-resident part from the disk into the main memory and updating the address Translation table as needed. After the cause of the exception is excluded, the exception handler completes the processing of the exception event and returns the original program to resume execution. As you'll see later in the article, when you return from the exception handler, you want to rerun the instruction that originally caused the exception, and the instruction will be successfully completed in the latter execution.
Second, the address translation mechanism supports virtual memory by collecting usage statistics that reside in the part of the virtual memory residing in the main memory, which uses statistics to help the operating system decide which parts can be transferred back to disk when the primary memory space is scarce.

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.