为什么全局描述符表的第一段描述只包含零? [英] Why have the first segment descriptor of the global descriptor table contain only zeroes?

查看:194
本文介绍了为什么全局描述符表的第一段描述只包含零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在很多教程我见过,第一个段选择只包含零,其次是code和数据段,例如:

In many tutorials I've seen, the first a segment selector contains only zeros, followed by the code and data segments, e.g.:

lgdt gdt_descriptor
/* More code. */

gdt_start:
gdt_null:
    .long 0x0
    .long 0x0
/* More descriptors. */
gdt_end:
gdt_descriptor:
   .word gdt_end - gdt_start
   .long gdt_start

这是什么第一个 gdt_null 段描述的目的是什么?

推荐答案

英特尔手动325384-053U第3部分第3.4.2节段选择说,任何企图通过第0描述由段寄存器访问内存导致的异常

The Intel manual 325384-053U part 3 section 3.4.2 Segment Selectors says that any attempt to access memory through the 0th descriptor by a segment register leads to an exception:

GDT的第一个条目不是由处理器使用。段选择指向GDT的该条目(即
  是,为0的索引和TI的标志设置为0)段选择被用作空的段选择。该处理器
  当一个段寄存器(比在CS或SS寄存器其它)被装入一个空不产生异常
  选择器。它,然而,当一个保持一个空选择段寄存器用于访问产生一个异常
  记忆。空选择器可以用来初始化未使用的段寄存器。加载CS或SS用空注册
  段选择会导致生成一般保护性异常(#GP)。

The first entry of the GDT is not used by the processor. A segment selector that points to this entry of the GDT (that is, a segment selector with an index of 0 and the TI flag set to 0) is used as a "null segment selector." The processor does not generate an exception when a segment register (other than the CS or SS registers) is loaded with a null selector. It does, however, generate an exception when a segment register holding a null selector is used to access memory. A null selector can be used to initialize unused segment registers. Loading the CS or SS register with a null segment selector causes a general-protection exception (#GP) to be generated.

因此​​,这似乎在暗示,这是不可能正确地使用它,而因此,你可以将它用于任何你想要的。

So this seems to imply that it is not possible to use it properly, and that therefore you can use it for whatever you want.

归零它,然后就是做最简单的事情,但任何价值可以用来代替。

Zeroing it then is just the simplest thing to do, but any value could be used instead.

这篇关于为什么全局描述符表的第一段描述只包含零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆