首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在初始加载后更新GDT条目?

如何在初始加载后更新GDT条目?
EN

Stack Overflow用户
提问于 2020-07-25 19:20:43
回答 1查看 205关注 0票数 2

使用lgdt初始化GDT并将其加载到GDTR后,如何更新GDT?

如果我使用sgdt命令获取基地址,然后更新或添加条目,然后再用lgdt重新加载条目,是否正确?还有别的办法吗?

还是我遗漏了什么,而GDT从来没有“意思”要更新一次初始化和加载?

EN

回答 1

Stack Overflow用户

发布于 2022-04-16 23:28:38

我知道这个问题很老,但是我想强调一些评论没有提到的东西,那就是CPU缓存的内容和没有缓存的内容。

一些术语:GDT的条目称为描述符,对于这个答案,我们只感兴趣的是段descriptors

  • Segment寄存器(csdsesfsgsssldtrtr)和指定段描述符的段选择器。段选择器总是16位,由:
  1. 13位:描述符入口索引
  2. 1位:0表示LDT
  3. 2位:请求的特权级别
  4. 1位。

CPU不缓存GDT,将值加载到descriptor (由GDT的基本地址及其大小组成)

  • ,CPU 缓存每个段寄存器使用的GDT描述符,当该段加载一个新的段选择器:H 135每个段寄存器有2部分:F 136H 137“可视部分”,其中包含段选择器H 238H 139“隐藏部分”包含段段的缓存副本。

代码语言:javascript
复制
- 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)
代码语言:javascript
复制
- 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.
代码语言:javascript
复制
- 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

尽管如此,

  1. 有很多理由来保持GDT中使用的条目不变,一个简单的原因是,当从内核模式转移到用户模式(反之亦然)时,您会更改段;因此,这些描述符必须存在于GDT中。( CPU还会在其他情况下自动加载新段,例如远程呼叫、中断、任务门、呼叫门、.)。在排序中,只有在操作系统不再使用描述符时才删除描述符。如果要添加段描述符(或任何其他描述符),将其添加到当前的GDT中,只需将适当的值放入一个空闲描述符条目中,然后将新的选择器加载到段(如果此时需要,则可以更改GDT的大小),这也很难使something
  2. Finally,回答您的问题。如果您想更新一个段描述符,在GDT中更新它,然后重新加载所有使用它的段,如果不这样做,段将只使用旧的缓存值。

资料来源:Intel 64和IA-32架构软件开发人员手册第3卷:系统编程指南第3章:保护模式内存管理

我建议您也看看wiki.osdev.org,特别是:

请要求澄清。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63092564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档