gpt4 book ai didi

assembly - IA-32e 64 位 IDT 门描述符

转载 作者:行者123 更新时间:2023-12-02 08:02:18 26 4
gpt4 key购买 nike

Intel 的 64 位 IDT 门描述符中有一个段选择器。然而,根据我对 5 部分 Intel 手册的理解,中断处理程序的线性地址从 IDT 门描述符中指定的 64 位偏移量加载到 RIP 中。

段选择器的唯一用途是检查:

  1. 权限级别是否发生变化
  2. 中断处理程序真正指向代码段

我的问题是:

  1. RIP 是否仅从 64 位偏移量中获取?或者是 RIP = 偏移量(符号扩展为 64 位)+ 段选择器基数?
  2. IDT门描述符中的段选择器指向的基地址是否被忽略?或者说有什么用处吗?

非常感谢!

最佳答案

如果我的解释正确的话,根据英特尔手册,x64 不使用分段。我读过AMD's System programming for AMD64为了理解这一点,因为我发现他们的解释更容易理解,因为他们明确地处理 x86_64 (我想他们确实发明了它);他们说:

In long mode, the effects of segmentation depend on whether the processor is running in compatibility mode or 64-bit mode:

  • In compatibility mode, segmentation functions just as it does in legacy mode, using legacy 16-bit or 32-bit protected mode semantics.
  • 64-bit mode, segmentation is disabled, creating a flat 64-bit virtual-address space. As will be seen, certain functions of some segment registers, particularly the system-segment registers, continue to be used in 64-bit mode.

具体来说,请查找第 4.8 节长模式段描述符。回答你的第二个问题:

Fields Ignored in 64-Bit Mode. Segmentation is disabled in 64-bit mode, and code segments span all of virtual memory. In this mode, code-segment base addresses are ignored. For the purpose of virtual-address calculations, the base address is treated as if it has a value of zero.

解释一下:因为 x86_64 中的“段”是整个地址空间,所以基地址除了 0 之外没有任何意义,因为偏移量都是绝对的(相对于 0)。

因此,这将回答我认为的第一个问题 - RIP 被视为 64 位偏移值。来自同章的门描述符页面:

In long mode, gate descriptors are expanded by 64 bits, allowing them to hold 64-bit offsets.

处理数据段时会变得更加复杂:

Data segments referenced by the FS and GS segment registers receive special treatment in 64-bit mode. For these segments, the base address field is not ignored, and a non-zero value can be used in virtual-address calculations. A 64-bit segment-base address can be specified using model- specific registers. See “FS and GS Registers in 64-Bit Mode” on page 70 for more information.

该部分指出:

FS and GS Registers in 64-Bit Mode. Unlike the CS, DS, ES, and SS segments, the FS and GS segment overrides can be used in 64-bit mode. When FS and GS segment overrides are used in 64-bit mode, their respective base addresses are used in the effective-address (EA) calculation. The complete EA calculation then becomes (FS or GS).base + base + (scale ∗ index) + displacement. The FS.base and GS.base values are also expanded to the full 64-bit virtual-address size, as shown in Figure 4-5. The resulting EA calculation is allowed to wrap across positive and negative addresses.

In 64-bit mode, FS-segment and GS-segment overrides are not checked for limit or attributes. Instead, the processor checks that all virtual-address references are in canonical form.

换句话说,数据段可以像使用分段一样,尽管只检查分段的形式,而不检查访问的形式是否位于段的范围内。

我认为这是正确的解释;然而,非常感谢更正/指针。

关于assembly - IA-32e 64 位 IDT 门描述符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8284756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com