使用 LLDT 并为其配置 GDT
我正在开发一个小型操作系统,它将为每个进程使用单独的本地描述符表。我知道我需要使用 lldt 指令从 GDT 加载 LDT 段。我已经让内核在具有有效 GDT 的保护模式下运行,但我无法弄清楚 LDT 的 GDT 条目应该是什么样子。我知道它的基地址应该指向我的LDT,但我不知道权限级别和其他属性应该是什么。下面是代表 GDT 中 LDT 条目的 NASM 代码:
localTable equ $-gdt ; GDT entry #5 (selector 20h)
dw 0x1FF ; limit to 64 descriptors
dw 0x8000 ; base address
db 0x0
db 0x89 ; probably incorrect...
db 0x1f ; possibly incorrect...
db 0x0
如果您不熟悉 NASM 语法,该表条目的基地址为 0x8000,限制为 511(总共 512 字节,或 64 个条目)。我已经阅读了 i486 程序员参考手册中有关 GDT 和 LDT 的部分,但我无法完全理解我的 GDT 条目应该是什么样子。
不管怎样,我像这样加载LDT:
mov ax, 0x20
lldt ax
这段代码导致处理器生成一般保护错误(我用中断来处理它)。我想知道两件事:
1)我在 GDT 中正确描述了我的 LDT 吗?如果不是,需要改变什么? 2) LLDT 指令是否会因为我的 LDT 本身存在无效选择器而失败?我阅读了 LLDT 指令规范,在我看来,它甚至没有读取 LDT 的内存,但我只是想确保 LLDT 不会因为我的 LDT 数据中有拼写错误而失败。
I'm working on a small OS that will use a separate Local Descriptor Table for each process. I understand that I will need to use the lldt
instruction to load a LDT segment from my GDT. I already have my kernel running in protected mode with a valid GDT, but I cannot figure out what the GDT entry for my LDT should look like. I understand that its base address should point to my LDT, but I don't know what the privilege level and other attributes should be. Here is the NASM code that represents the LDT entry in my GDT:
localTable equ $-gdt ; GDT entry #5 (selector 20h)
dw 0x1FF ; limit to 64 descriptors
dw 0x8000 ; base address
db 0x0
db 0x89 ; probably incorrect...
db 0x1f ; possibly incorrect...
db 0x0
If you are not familiar with the NASM syntax, this table entry has a base address of 0x8000 and a limit of 511 (512 bytes total, or 64 entries). I have read the section about the GDT and LDT in the i486 programmer's reference manual, but I cannot fully understand what my GDT entry should look like.
Anyway, I load the LDT like so:
mov ax, 0x20
lldt ax
This code causes the processor to generate a general protection fault (I handle it with an interrupt). I would like to know two things:
1) Did I correctly describe my LDT in the GDT? If not, what needs to be changed?
2) Could the LLDT
instruction be failing because there are invalid selectors in my LDT itself? I read the LLDT instruction spec, and it seems to me that it doesn't even read the memory of the LDT, but I just want to be sure the LLDT isn't failing because I have a typo in my LDT's data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我明白了。我使用的类型 (
1001b
) 不是我需要的。我发现类型 2 (10b
) 用于 LDT 条目。作为记录,此信息位于《i486 微处理器程序员手册》第 6 章第 4 页中。我的功能 GDT 条目如下所示:Ok, I figured it out. The type that I was using (
1001b
) was not what I needed. I found that type 2 (10b
) is used for LDT entries. For the record, this information is in chapter 6, page 4, of the i486 Microprocessor Programmer's Manual. My functional GDT entry looks as follows: