reactos操作系统实现 10

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

/*Load the GDT and IDT */

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

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


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

2.4.1 Global DescriptorTable Register (GDTR)

The GDTR registerholds the base address (32 bits in protected mode; 64 bits in IA-32e mode) andthe 16-bit table limit for the GDT. The base address specifies the linearaddress of byte 0 of the GDT; the table limit specifies the number of bytes inthe table.

The LGDT and SGDTinstructions load and store the GDTR register, respectively. On power up orreset of the processor, the base address is set to the default value of 0 andthe limit is set to 0FFFFH. A new base address must be loaded into the GDTR aspart 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://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/uytrrfg/article/details/86615612