加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactos操作系统实现(10)

发布时间:2020-12-15 05:02:39 所属栏目:百科 来源:网络整理
导读:看到下面的语句,你能看得懂吗? /* Load the GDT and IDT */ Ke386SetGlobalDescriptorTable(*(PKDESCRIPTOR)KiGdtDescriptor.Limit); 如果没有去看 INTEL 的文档,是看不懂的。因为它是跟 INTEL 的 CPU 架构密切相关的。现在就去解一下什么叫做全局描述符
看到下面的语句,你能看得懂吗?

/* 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里,这样就初始化了全局描述符。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读