The Physical Address Extension (PAE) Paging Mechanism

The amount of RAM supported by a processor is limited by the number of address pins connected to the address bus.

PAE is activated by setting the Physical Address Extension ( PAE ) flag in the cr4 control register. The Page Size ( PS ) flag in the page directory entry enables large page sizes (2 MB when PAE is enabled).

When mapping linear addresses to 4 KB pages ( PS flag cleared in Page Directory entry), the 32 bits of a linear address are interpreted in the following way:

cr3

        Points to a PDPT

bits 31–30

        Point to 1 of 4 possible entries in PDPT

bits 29–21

        Point to 1 of 512 possible entries in Page Directory

bits 20–12

        Point to 1 of 512 possible entries in Page Table

bits 11–0

        Offset of 4-KB page

When mapping linear addresses to 2-MB pages ( PS flag set in Page Directory entry), the 32 bits of a linear address are interpreted in the following way:

cr3
        Points to a PDPT
bits 31–30
       Point to 1 of 4 possible entries in PDPT
bits 29–21
       Point to 1 of 512 possible entries in Page Directory
bits 20–0
       Offset of 2-MB page

To summarize, once cr3 is set, it is possible to address up to 4 GB of RAM. If we want to address more RAM, we’ll have to put a new value in cr3 or change the content of the PDPT.

Clearly, PAE does not enlarge the linear address space of a process, because it deals only with physical addresses. Furthermore, only the kernel can modify the page tables of the processes, thus a process running in User Mode cannot use a physical address space larger than 4 GB.


Note: For linear address, only the last 12-bit offset are the size of the page frame. Other fields are the numbers of the corresponding entries in the table. When the base address pointer plug the number, it will get be 'base address + number * 4(or 8) = the entry address'.


### PAE技术详解 PAEPhysical Address Extension,物理地址扩展)是IA-32架构中的一种内存管理技术,允许32位处理器访问超过4GB的物理内存。在标准32位寻址模式下,处理器能够直接寻址的最大内存为4GB。通过启用PAE,可以将物理地址空间扩展到36位,从而支持最多64GB的物理内存[^2]。 #### PAE技术的核心机制 1. **页表结构扩展**: 在标准分页机制中,页目录和页表各占10位,形成一个两级页表结构。启用PAE后,增加了页目录指针表(Page Directory Pointer Table, PDPT),形成了三级页表结构。CR3寄存器不再存储页目录基址,而是存储页目录指针表基址[^2]。 2. **页目录指针表(PDPT)**: 每个PDPTE(Page Directory Pointer Table Entry)占用64位,其中高20位用于指向页目录的基址。这种设计使得页表结构更加灵活,能够支持更大的物理地址空间[^2]。 3. **标志位设置**: - CR0寄存器中的PG标志必须开启以启用分页机制。 - CR4寄存器中的PAE标志必须开启以启用PAE机制。 当这两个标志都被设置时,处理器进入PAE模式,CR3寄存器被重新定义为页目录指针表基址(PDPTR)[^2]。 4. **硬件支持**: 启用PAE的前提是CPU支持该特性。可以通过执行`CPUID`指令检查EDX寄存器的第6位是否为1来确认CPU是否支持PAE[^2]。 #### PAE测试方法 以下是进行PAE相关测试的具体方法: 1. **检查CPU是否支持PAE**: 使用`CPUID`指令或工具检测CPU是否支持PAE特性。例如,在Linux系统中可以运行以下命令: ```bash grep pae /proc/cpuinfo ``` 如果输出包含`pae`,则表示CPU支持PAE[^2]。 2. **验证操作系统是否启用了PAE**: 在Linux系统中,可以通过内核参数或模块加载情况判断是否启用了PAE。例如: ```bash uname -r ``` 如果内核名称中包含`pae`,则表示启用了PAE模式。此外,也可以通过以下命令检查: ```bash dmesg | grep PAE ``` 3. **测试大内存环境下的性能**: 构建一个超过4GB的物理内存环境,并运行应用程序测试其性能表现。例如,使用`memtest86+`工具对内存进行压力测试,观察是否存在错误或不稳定现象。 4. **驱动程序接口测试**: 通过编写或调用驱动程序接口,加载并解析页目录指针表(PDPT)、页目录表(PDT)和页表(PT)的内容。例如,参考引用中提到的MFC程序可以调用驱动程序接口加载PDPTE,并展示有效表项[^1]。 #### 示例代码:检查CPU是否支持PAE 以下是一个简单的C语言程序,用于检测CPU是否支持PAE特性: ```c #include <stdio.h> int main() { unsigned int eax, ebx, ecx, edx; // 获取 CPUID 信息 __asm__ volatile("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(1)); if (edx & (1 << 6)) { printf("CPU supports PAE.\n"); } else { printf("CPU does not support PAE.\n"); } return 0; } ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值