【发布时间】:2017-05-11 16:26:07
【问题描述】:
我正在编写一个操作系统,作为一部分,我需要告诉 CPU 内存中的段。基本思想是我用 LGDT 程序集调用加载 GDT 寄存器。它的参数是包含实际 GDT 的大小和位置的结构的内存地址。我遇到的问题是,在 GlobalDescriptorTable.h 的第 75 行上,我将结构中的数组地址设置为传递给 LGDT,但是当我检查结构给出的地址处的内存时,那里什么也没有。
class GlobalDescriptorTable {
private:
GdtEntry _gdt[256];
size_t size;
GdtDescriptor gdtd;
public:
GlobalDescriptorTable( ) ;
GdtEntry encodeGlobalDescriptorTableEntry(uint32_t limit,
uint32_t baseAddress, Access access, Flags flags);
void load( ) {
//get size, -1 because Int-hell hates you
size_t sizeOfGdt = (3 * sizeof(GdtEntry)) - 1;
//get the info to tell cpu about the GDT
gdtd.size = (uint16_t)sizeOfGdt;
gdtd.location = _gdt;
asm ("LGDT %[gdtd]" : : [gdtd] "m" (gdtd));
}
};
作业作为测试:
uint64_t temp = 0xF00FB00BEE00F0AA;
_gdt[0] = *((GdtEntry*) &temp);
任何帮助将不胜感激
【问题讨论】:
标签: c++ arrays pointers operating-system