当我在学习第三章时,代码pmtest1.asm中对于GDT的定义使我迷惑了,第一个Descriptor是一个空描述符,在代码中根本就没有使用该描述符,既然如此,为何还要这个描述符呢?
试验是检验真理的唯一标准,于是我删除了该描述符,以LABEL_DESC_CODE32作为GDT中的第一个descriptor,编译后在微软虚拟机中运行该程序。虚拟机报错“An unrecoverable processor error has been encontered. The virtual machine will reset now.”看来这个空描述符虽然在程序中没有显示使用,但也是必不可少的。查询Intel的Architecture software developer's manual, volume 3A,在3.5.1 segment decritpor tables一节中有这样的说明:
The first descriptor in the GDT is not used by the processor. A segment selector to this “null
descriptor” does not generate an exception when loaded into a data-segment register (DS, ES,
FS, or GS), but it always generates a general-protection exception (#GP) when an attempt is
made to access memory using the descriptor. By initializing the segment registers with this
segment selector, accidental reference to unused segment registers can be guaranteed to generate
an exception.
GDT中的第一个描述符将不会被处理器使用,当将一个指向该描述符的segment selecor加载到数据段寄存器中时,将不会产生异常。但如果尝试用这个描述符去访问内存,将产生一个通用保护异常。使用该selector来初始化段寄存器,可以保证对未使用段寄存器的错误访问导致异常。
这样看来,空描述符还是有作用的,适用它来初始化所有的段寄存器,可以防止在程序中对未使用寄存器的错误访问,因为这一定会导致异常。不过在pmtest1.asm中作者并没有使用该selector来初始化所有段寄存器,我想可能是因为这个问题对作者解释保护模式并不重要,因此作者就没有提及。
Intel为何不使用GDT中的第一个Descriptor?
最新推荐文章于 2024-07-20 08:18:41 发布
作者:Maverick
blog:
http://blog.youkuaiyun.com/zhaohuabing
转载请注明出处