Chinaunix首页 | 论坛 | 博客
  • 博客访问: 56214
  • 博文数量: 47
  • 博客积分: 2095
  • 博客等级: 大尉
  • 技术积分: 560
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-01 18:42
文章分类

全部博文(47)

文章存档

2011年(1)

2008年(46)

我的朋友

分类: LINUX

2008-04-06 22:23:46

Hardware Protection Scheme

The paging unit uses a different protection scheme from the segmentation unit. While 80x86 processors allow four possible privilege levels to a segment, only two privilege levels are associated with pages and Page Tables, because privileges are controlled by the User/Supervisor flag mentioned in the earlier section "Regular Paging." When this flag is 0, the page can be addressed only when the CPL is less than 3 (this means, for Linux, when the processor is in Kernel Mode). When the flag is 1, the page can always be addressed.

分页部件采用了与分段部件不同的保护机制。尽管x86处理器允许一个段有4个可能的权限级别,只有2个级别用于页和页表,因为级别是由User/Supervisor标志控制的。当这个标志为0时,只有当CPL小于3,也就是Linux的内核模式下,可以寻址该页。当这个标志为1时,总是可以对该页寻址。

Furthermore, instead of the three types of access rights (Read, Write, and Execute) associated with segments, only two types of access rights (Read and Write) are associated with pages. If the Read/Write flag of a Page Directory or Page Table entry is equal to 0, the corresponding Page Table or page can only be read; otherwise it can be read and written.[*]

[*] Recent Intel Pentium 4 processors sport an NX (No eXecute) flag in each 64-bit Page Table entry (PAE must be enabled, see the section "The Physical Address Extension (PAE) Paging Mechanism" later in this chapter). Linux 2.6.11 supports this hardware feature.

还有,与段的三种访问方式(读、写和执行)不同的是,页只有两种访问方式(读和写)。如果页目录或者页表项中Read/Write字段为0时,对应的页表或页是只读的;否则它是可读写的。

Inter Pentium4处理器在每个64bit的页表项中支持NX(不可执行)标志(PAE必须启用)。Linux2.6.11支持这种硬件特性。

An Example of Regular Paging

A simple example will help in clarifying how regular paging works. Let's assume that the kernel assigns the linear address space between 0x20000000 and 0x2003ffff to a running process.[] This space consists of exactly 64 pages. We don't care about the physical addresses of the page frames containing the pages; in fact, some of them might not even be in main memory. We are interested only in the remaining fields of the Page Table entries.

[] As we shall see in the following chapters, the 3 GB linear address space is an upper limit, but a User Mode process is allowed to reference only a subset of it.

假设内核将0x200000000x2003ffff之间的线性地址空间分配给一个正在运行的进程。这块空间包含了64页。我们不考虑存储这些页的页帧;事实上,有的页可能并不在内存中。我们只对页表项的剩余字段感兴趣。

我们以后会看到,3GB线性地址空间是一个上限,但是一个用户模式进程允许引用其中一个子集。

Let's start with the 10 most significant bits of the linear addresses assigned to the process, which are interpreted as the Directory field by the paging unit. The addresses start with a 2 followed by zeros, so the 10 bits all have the same value, namely 0x080 or 128 decimal. Thus the Directory field in all the addresses refers to the 129th entry of the process Page Directory. The corresponding entry must contain the physical address of the Page Table assigned to the process (see Figure 2-9). If no other linear addresses are assigned to the process, all the remaining 1,023 entries of the Page Directory are filled with zeros.

从这段线性地址的最高10bit开始,它们被分页部件解释为目录字段。所有的地址都是以2开始后面接了60,因此这10bit的值相同,也就是0x080或者十进制的128.所有地址的目录字段都指向进程页目录的第129项。对应的项必须包含分配给进程的对应页表的物理地址。如果没有其他地址分配给这个进程,页目录的其他1023项全部填充0.

Figure 2-9. An example of paging

The values assumed by the intermediate 10 bits, (that is, the values of the Table field) range from 0 to 0x03f, or from 0 to 63 decimal. Thus, only the first 64 entries of the Page Table are valid. The remaining 960 entries are filled with zeros.

中间的10bit也就是页表字段的值范围是从00x3f,十进制是063.因此,页表只有前64项是有效的。剩余的960项全部填充0.

Suppose that the process needs to read the byte at linear address 0x20021406. This address is handled by the paging unit as follows:

假设进程需要读取线性地址为0x20021406的字节。分页部件如下处理地址:

1.    The Directory field 0x80 is used to select entry 0x80 of the Page Directory, which points to the Page Table associated with the process's pages.

目录字段0x80用在选择页目录的0x80项,该项指向了管理该进程页的页表。

2.    The Table field 0x21 is used to select entry 0x21 of the Page Table, which points to the page frame containing the desired page.

页表字段0x21用在选择页表的0x21项,该项指向存储该页的页帧。

3.    Finally, the Offset field 0x406 is used to select the byte at offset 0x406 in the desired page frame.

最后,偏移字段0x406用在选择目的页帧的0x406偏移处的字节。

If the Present flag of the 0x21 entry of the Page Table is cleared, the page is not present in main memory; in this case, the paging unit issues a Page Fault exception while translating the linear address. The same exception is issued whenever the process attempts to access linear addresses outside of the interval delimited by 0x20000000 and 0x2003ffff, because the Page Table entries not assigned to the process are filled with zeros; in particular, their Present flags are all cleared.

如果页表的0x21项的Present标志是空的,那么这一页不在内存中;在这种情况下,分页部件产生一个缺页异常。同样的异常也会在进程企图访问0x200000000x2003ffff这个间隔外的线性地址时产生,因为没有分配给进程的页表项填充了0,也就是说Present标志都为空。

阅读(368) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~