x86_64 在长模式 64 位子模式下运行

问题描述 投票:0回答:1

我想询问 x86_64 处理器如何知道它处于 IA-32e 64 位子模式。

据我所知,必须设置

LM
EFER MSR
)内的
0xC0000080
位。此外,当前代码段描述符中的
L
位(当前缓存在
CS
描述符缓存中)必须设置为 (1)。

还有其他需要配置的地方吗?谢谢。

memory-management x86-64 64-bit intel amd
1个回答
0
投票

根据 Intel 10.8.5 “初始化 IA-32e 模式” 部分:

On Intel 64 processors, the IA32_EFER MSR is cleared on system reset.
The operating system must be in protected mode with paging enabled before attempting 
to initialize IA-32e mode. IA-32e mode operation also requires physical-address extensions 
with four or five levels of enhanced paging structures (see Section 4.5, “4-Level
Paging and 5-Level Paging”).

Operating systems should follow this sequence to initialize IA-32e mode:

    1. Starting from protected mode, disable paging by setting CR0.PG = 0. Use the MOV CR0 instruction to disable
       paging (the instruction must be located in an identity-mapped page).

    2. Enable physical-address extensions (PAE) by setting CR4.PAE = 1. Failure to enable PAE will result in a #GP
       fault when an attempt is made to initialize IA-32e mode.

    3. Load CR3 with the physical base address of the Level 4 page map table (PML4) or Level 5 page map table
       (PML5).

    4. Enable IA-32e mode by setting IA32_EFER.LME = 1.

    5. Enable paging by setting CR0.PG = 1. This causes the processor to set the IA32_EFER.LMA bit to 1. The MOV
       CR0 instruction that enables paging and the following instructions must be located in an identity-mapped page
       (until such time that a branch to non-identity mapped pages can be effected).

因此,您首先需要准备4/5级页表,接下来您必须启用PAE(物理地址扩展),然后才启用LME位。一旦启用 LME 位,您就可以启用 paging(如果在设置 LME 位之前启用它,处理器会认为您使用 32 位分页,即 2/3 级页表并产生错误的转换)。

这张图说明了分页模式转换的工作原理:

切换到 IA-32e 64 位子模式后,您必须重新加载系统数据结构(GDT、IDT、TSS 等)。特别是为了能够跳转到 64 位代码,您必须为 GDT 代码描述符打开

L
位。重新加载所有这些结构后,您可以在 64 位模式下照常工作。

© www.soinside.com 2019 - 2024. All rights reserved.