reactos操作系统实现(10)

看到下面的语句,你能看得懂吗?

/* Load the GDT and IDT */

    Ke386SetGlobalDescriptorTable(*(PKDESCRIPTOR)&KiGdtDescriptor.Limit);

如果没有去看INTEL的文档,是看不懂的。因为它是跟INTELCPU架构密切相关的。现在就去解一下什么叫做全局描述符。先来看看下图的结构:


上面红色的框内就是GDTR了,它的描述可以从INTEL的文档看到,如下:

2.4.1 Global Descriptor Table Register (GDTR)

The GDTR register holds the base address (32 bits in protected mode; 64 bits in IA-32e mode) and the 16-bit table limit for the GDT. The base address specifies the linear address of byte 0 of the GDT; the table limit specifies the number of bytes in the table.

The LGDT and SGDT instructions load and store the GDTR register, respectively. On power up or reset of the processor, the base address is set to the default value of 0 and the limit is set to 0FFFFH. A new base address must be loaded into the GDTR as part of the processor initialization process for protected-mode operation.

See also: Section 3.5.1, “Segment Descriptor Tables.”

 

从这段话里,可以知道GDTRIA-32里是48位的寄存器,用来保存全局描述符所在的位置,并且使用LGDTSGDT指令来操作它。用C语言的结构来表达它,就是这样:

#001  typedef struct _DESCRIPTOR

#002  {

#003      USHORT Pad;

#004      USHORT Limit;

#005      ULONG Base;

#006  } KDESCRIPTOR, *PKDESCRIPTOR;

Pad16位补齐字节,用来让这个结构从8个字节边界开始声明变量。

Limit16位的全局描述符长度。

Base32位的全局描述符的开始地址,也就是全局描述符所在的线性地址。

 

从上面那句语句里可以看到,是获取KiGdtDescriptor.Limit的开始地址,也就是说获取全局描述符的地址,并保存到GDTR寄存器里。如下图所示:


通过上面的函数,就可以设置引导的全局描述符到寄存器GDTR里,这样就初始化了全局描述符。

转载于:https://www.cnblogs.com/ajuanabc/archive/2008/12/17/2463900.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值