使用lgdt初始化GDT并将其加载到GDTR后,如何更新GDT?
如果我使用sgdt命令获取基地址,然后更新或添加条目,然后再用lgdt重新加载条目,是否正确?还有别的办法吗?
还是我遗漏了什么,而GDT从来没有“意思”要更新一次初始化和加载?
发布于 2022-04-16 23:28:38
我知道这个问题很老,但是我想强调一些评论没有提到的东西,那就是CPU缓存的内容和没有缓存的内容。
一些术语:GDT的条目称为描述符,对于这个答案,我们只感兴趣的是段descriptors
cs、ds、es、fs、gs、ss、ldtr、tr)和指定段描述符的段选择器。段选择器总是16位,由:CPU不缓存GDT,将值加载到descriptor (由GDT的基本地址及其大小组成)
H 135每个段寄存器有2部分:F 136H 137“可视部分”,其中包含段选择器H 238H 139“隐藏部分”包含段段的缓存副本。- When you execute `mov es, ax`, with `ax` having the value 0x0010 for example:
1. The "Visible Part" gets the value 0x0010
2. The "Hidden Part" receives a copy of the information stored in the 3rd entry of the GDT (because 0x0010 means 3rd entry)- When using the segment register, only the "Hidden Part" dictates its characteristics (base, limit, access information).
- The GDT segment descriptor that was used to load the segment register may be modified or not be present at all
- The `gdtr` may point to a different location, even an invalid one, and may have any size, again, even an invalid one - the CPU does not care.- The "Visible Part" does absolute nothing expect holding the segment selector used to load the segment register, that value can be then retrieved by a `mov ax, es`. (`ax` becomes 0x0010, even thought that GDT segment descriptor may contain anything or may not even exist at the present time)
- So, in order to load a new segment descriptor to a segment register, you need to load another (or even the same) selector, that will update-reload the "Hidden Part" - cache尽管如此,
。
资料来源:Intel 64和IA-32架构软件开发人员手册第3卷:系统编程指南第3章:保护模式内存管理
我建议您也看看wiki.osdev.org,特别是:
请要求澄清。
https://stackoverflow.com/questions/63092564
复制相似问题