/* Get GDT,IDT,PCR and TSS pointers */
@H_502_1@KiGetMachineBootPointers(&Gdt,&Idt,&Pcr,&Tss);
它是代表什么意思呢?实际上是获取全局描述符表、中断描述符表、进程控制块和任务状态段的指针。那么这个函数又是怎么样实现的呢?@H_502_1@
先来分析怎么样获取@H_502_1@GDT@H_502_1@和@H_502_1@IDT@H_502_1@的指针,它的代码如下:@H_502_1@
#001 @H_502_1@/* Get GDT and IDT descriptors */
#002 @H_502_1@Ke386GetGlobalDescriptorTable(*(PKDESCRIPTOR)&GdtDescriptor.Limit);
#003 @H_502_1@Ke386GetInterruptDescriptorTable(*(PKDESCRIPTOR)&IdtDescriptor.Limit);
#005 @H_502_1@/* Save IDT and GDT */
#006 @H_502_1@*Gdt = (PKGDTENTRY)GdtDescriptor.Base;
#007 @H_502_1@*Idt = (PKIDTENTRY)IdtDescriptor.Base;
GDT@H_502_1@是先从@H_502_1@GDTR@H_502_1@寄存器里获取到全局描述符表,然后再从里面得到全局描述符表所地的基地址。相应的@H_502_1@IDT@H_502_1@也是从@H_502_1@IDTR@H_502_1@寄存器获取中断描述符表,然后从里得到@H_502_1@IDT@H_502_1@所指针的基地址,也就是指针地址了。@H_502_1@
#001 @H_502_1@/* Get TSS and FS Selectors */
#002 @H_502_1@Ke386GetTr(Tr);
#003 @H_502_1@if (Tr != KGDT_TSS) Tr = KGDT_TSS; // FIXME: HACKHACK
#004 @H_502_1@Fs = Ke386GetFs();
第@H_502_1@2@H_502_1@行是从任务寄存器@H_502_1@TR@H_502_1@里获取到任务描述符,如果这个描述符不是内核任务,就强制转换为内核任务。@H_502_1@
第@H_502_1@4@H_502_1@行是获取@H_502_1@FS@H_502_1@段选择子,以便后面获取@H_502_1@PCR@H_502_1@指针。@H_502_1@
#001 @H_502_1@/* Get PCR Selector,mask it and get its GDT Entry */
#002 @H_502_1@PcrSelector = *(PKGDTENTRY)((ULONG_PTR)*Gdt + (Fs & ~RPL_MASK));
#004 @H_502_1@/* Get the KPCR itself */
#005 @H_502_1@*Pcr = (PKIPCR)(ULONG_PTR)(PcrSelector.BaseLow |
#006 @H_502_1@PcrSelector.HighWord.Bytes.BaseMid << 16 |
#007 @H_502_1@PcrSelector.HighWord.Bytes.BaseHi << 24);
这段代码第@H_502_1@2@H_502_1@行是获取进程序控制控制块的描述符,第@H_502_1@5@H_502_1@行代码是通过描述符计算出@H_502_1@PCR@H_502_1@所在位置。@H_502_1@
#001 @H_502_1@/* Get TSS Selector,mask it and get its GDT Entry */
#002 @H_502_1@TssSelector = *(PKGDTENTRY)((ULONG_PTR)*Gdt + (Tr & ~RPL_MASK));
#004 @H_502_1@/* Get the KTSS itself */
#005 @H_502_1@*Tss = (PKTSS)(ULONG_PTR)(TssSelector.BaseLow |
#006 @H_502_1@TssSelector.HighWord.Bytes.BaseMid << 16 |
#007 @H_502_1@TssSelector.HighWord.Bytes.BaseHi << 24);
这段代码,主要获取@H_502_1@TSS@H_502_1@的描述符,然后通过描述符计算出@H_502_1@TSS@H_502_1@任务所在地址。@H_502_1@