This article comes from: http: //os.silversand.net Author: sunmoon (2001-09-01 09:05:00)
We finished the segmentation mechanism. Next we need to analyze the second storage management mechanism of the protection mode: paging mode. In the previous we mention the turning station and the control register group. They include EFLAGS, ELP. And 4 32-bit control registers CRO CR1CR2 CER3. One of the PEs in the CRO is used to sign the use of protection mode or real mode. One PG defines whether to use paging mode (1 or 0). When pg = 1, the system uses the paging mechanism. 80386 uses a large bit 4K page, and the boundary of each page. That is, each page can be divided by 4K. Such 4G bytes are divided into 1m page. The paging mechanism maps the linear page into a physical page. Let's take a look at the LinuxE Subject: 1. Multi-level page table structure contains 1M page in Linux. Each page table accounts for 4 bytes. Then need to occupy the 4M continuous memory so Linux introduces a 2-level page table structure. The secondary page table is defined in the last 10 bits (22-32) in the linear address. The secondary page table has 1K byte, page exists] A 4K page. And the actual physical address is achieved by the first 20 bits. I said it is not very clear about this place. It can be understood roughly. Such as: There are nin tables. Every one is a page. The content of the last page is a pointer (or an index item) of another second-level refining table 2, the page item and the page directory item for each page. There will be a page item. It is used to indicate whether the usage of this page is idle. Whether in memory, etc. And these meetings are stored as a joint. To reduce the query time when using the table. And each page table, there will be 1024 page items, which is the real "page". 3, linear address to the physical address switch
The CR contains the starting address of the page directory, which is added with the index of the page directory of the 31-22 bit in the 32-bit address, adds the starting address of the CR3 page directory. Get the address of the corresponding page table to remove the 32-bit page directory item from the specified address. Its $ 12 is 0 Use this 32-bit address 21-12 bit as an index of the page in the page table. Accepted it by the starting address of 4 and page tables, get the 32-bit address prize 11-0 bit as the offset of the relative page address, adding to the 32-bit page address. Form 32-bit physical address. 4, page cache, of course, the system is frequently accessing the secondary page list, which will cause a lot of time to waste, so introduced the page table cache to save the recently used page, or frequently used the page, the principle about Cache is not Detailed explanation, interested friends can check some, computer professional base textbooks, Linux used 836 protection models, basically explained. As for control transfer and task switching. And general assembly programming is much different, I have too low. Not in the general, the switching of multitasking, and the application of the protection mode. Implementation of virtual storage systems is based on hardware technical support. Personally, Linux's storage management. It is completely different from different machines, as for Linux provides a unified interface. I am not too clear. See the source code of other models