是否需要LDT?
作为 32 位 x86 处理器的某些操作系统开发的一部分,我正在考虑在中断描述符表中使用任务门作为页错误向量。目的是强制任务切换,以便保证处理程序的堆栈被映射(并避免被中断任务的部分堆栈未被映射的情况)。
我正在 QEMU 下运行我的内核(实际上是这样),但发现当发生页面错误时,它会崩溃(我回到命令提示符)。我一直在阅读和挖掘寻找可能帮助我找出确切原因的提示。我认为我遗漏了一些东西和/或误解了一些东西。顺便说一句,当我将页面错误向量设置为使用中断门时,我可以让事情按照我的预期工作。当我尝试为此使用任务门时,我遇到了问题(是的,我确实想坚持尝试使用任务门)。
IDT 部分已正确设置以注册页错误向量的任务门。它的选择器引用了 GDT 中 TSS 的描述符。至于 GDT 中 TSS 的描述符,我确信它也设置正确。
但是,我不能 100% 确定 TSS 是否已正确填充,并且到目前为止还无法准确确定如何设置其所有字段。其中一些例如 esp、eip、cs、ds、es、fs、gs、ss 和 eflags 相对简单。然而,其他诸如LDT段选择器之类的就不太清楚了。 LDT 段选择器必须非零并且指向 GDT 中的 LDT 描述符吗?对于上述场景,必须设置哪些字段?我花了很多时间来解决这个问题。
任何帮助将不胜感激。
As part of some OS development for a 32-bit x86 processor, I am considering using an task gate in the interrupt descriptor table for the page fault vector. The aim is to force a task switch so that the handler's stack will be guaranteed to be mapped (and avoid the case wherein part of stack of the interrupted task was not mapped).
I am running my kernel (such as it is) under QEMU, but am finding that when the page fault occurs, it crashes (I'm back to command prompt). I've been reading and digging searching for hints that may help me figure out the exact cause. I figure that I am missing something and/or have misunderstood something. Incidentally, when I set the page fault vecotr up to use an interrupt gate, I can get things to work as I expect them. It is when I try to use a task gate for this that I encounter problems (and yes, I do want to persist in trying to use the task gate).
The IDT portion is set up correctly to register a task gate for the page fault vector. Its selector refers to a descriptor for the TSS in the GDT. As far as the descriptor for the TSS in the GDT, I am certain that too is set up properly.
However, I am not 100% certain if I have the TSS properly populated and have been unable thus far to determine exactly how to set up all of its fields. Some of them such as esp, eip, cs, ds, es, fs, gs, ss and eflags have been relatively straight forward. However, others such as the LDT segment selector are less clear. Must the LDT segment selector be non-zero AND point to an LDT descriptor in the GDT? Which of these fields must be set for the scenario described above? I am having a heck of time figuring this one out.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LDT 在正常运行的 x86 操作系统中不是必需的(事实上,它在 x86-64 操作系统中是被禁止的)。
为了避免使用它,请将其设置为零。
特别要注意的一件事是 osdev.org 上关于 TSS 的结构是从后到前的 (http://wiki.osdev.org/TSS)。您需要小心,因为 TSS 错误将触发 TSS 错误异常。
The LDT is not necessary in a correctly functioning x86 operating system (indeed, it is forbidden in a x86-64 operating system).
To avoid using it, set it to zero.
One thing in particular to be aware of - the structures on osdev.org about TSS is back-to-front (http://wiki.osdev.org/TSS). You'll need to be careful, since getting the TSS wrong will trigger a TSS-fault exception.