简体   繁体   English

使用LLDT并为其配置GDT

[英]Using LLDT and configuring the GDT for it

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. 我知道我需要使用lldt指令从我的GDT加载LDT段。 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. 我已经使用有效的GDT在保护模式下运行我的内核,但我无法弄清楚我的LDT的GDT条目应该是什么样子。 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. 我知道它的基地址应该指向我的LDT,但我不知道特权级别和其他属性应该是什么。 Here is the NASM code that represents the LDT entry in my GDT: 这是代表我的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

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). 如果您不熟悉NASM语法,则此表条目的基址为0x8000,限制为511(总共512个字节,或64个条目)。 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. 我在i486程序员的参考手册中已经阅读了关于GDT和LDT的部分,但我无法完全理解我的GDT条目应该是什么样子。

Anyway, I load the LDT like so: 无论如何,我像这样加载LDT:

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? 1)我是否在GDT中正确描述了我的LDT? If not, what needs to be changed? 如果没有,需要改变什么? 2) Could the LLDT instruction be failing because there are invalid selectors in my LDT itself? 2) LLDT指令是否会失败,因为我的LDT本身存在无效的选择器? 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. 我读了LLDT指令规范,在我看来它甚至没有读取LDT的内存,但我只是想确定LLDT没有失败,因为我的LDT数据中有一个拼写错误。

Ok, I figured it out. 好的,我明白了。 The type that I was using ( 1001b ) was not what I needed. 我使用的类型( 1001b )不是我需要的。 I found that type 2 ( 10b ) is used for LDT entries. 我发现类型2( 10b )用于LDT条目。 For the record, this information is in chapter 6, page 4, of the i486 Microprocessor Programmer's Manual . 有关记录,此信息位于i486微处理器程序员手册的第6章第4页。 My functional GDT entry looks as follows: 我的功能GDT条目如下:

localTable equ $-gdt            ; GDT entry #5 (selector 20h)
dw 0x1FF                        ; limit to 64 descriptors
dw 0x8000                       ; base address
db 0x0
db 0x82                         ; 10000010b (segment present set, WTM)
db 0x1f
db 0x0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM