gpt4 book ai didi

x86 - 是否有关于如何布置全局描述符表条目的约定?

转载 作者:行者123 更新时间:2023-12-04 07:20:26 25 4
gpt4 key购买 nike

操作系统是否有约定的约定,指定每个表索引应描述的内容?例如,在 Windows 系统上(如 here 所述),条目 4 描述 32 位用户模式代码( RPL = 3 ),条目 6 描述 64 位用户模式代码。这是公约吗?其他条目呢?

最佳答案

x86-64 syscall/sysret , 和 32 位 sysenter/sysexit ,显然确实关心您的 GDT 条目的顺序:内核 CS、内核数据、用户 CS、用户数据的顺序。 (感谢@Brendan 提供的详细信息。)或者至少, syscall 将固定值加载到 CS 和 SS 内部状态:

SYSCALL loads the CS and SS selectors with values derived from bits 47:32 of the IA32_STAR MSR. However, the CS and SS descriptor caches are not loaded from the descriptors (in GDT or LDT) referenced by those selectors. Instead, the descriptor caches are loaded with fixed values. See the Operation section for details. It is the responsibility of OS software to ensure that the descriptors (in GDT or LDT) referenced by those selector values correspond to the fixed values loaded into the descriptor caches; the SYSCALL instruction does not ensure this correspondence.


除此之外,硬件并不关心。如果您只使用像 int 0x80 这样的遗留系统调用机制,任何对您有意义的模式都可以。 .
AFAIK,跨操作系统没有标准约定,但这不是我看过的。

当内核设置条目时(例如,在上下文切换时),条目可能通过缓存获取,因此将一起使用的条目放在同一个 64 字节缓存行中可能会有微小的优势。 (减少缓存未命中/占用的缓存行数。)特别是对于 32 位用户空间,如果您不能仅将空选择器 ( 0 ) 用于他们的 SS/DS/ES。
但是如果整个 GDT 是 8 个条目或更少,则整个内容适合一个缓存行(如果您将开头对齐 64)。较旧的 CPU(在 Pentium 4/Core 2 之前)有 32 字节缓存线,但它们不支持 64 位模式,因此需要的 GDT 条目较少。
请注意,索引 0 永远不会被 CPU 实际访问,因此您可以将第一个“真正的”GDT 条目和 lgdt 对齐。该地址减去 8。(“空描述符”是一种特殊情况。)

关于x86 - 是否有关于如何布置全局描述符表条目的约定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68537488/

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