我正在尝试编写一个内核,主要用于娱乐目的,而且我遇到了一个问题,我认为它是三重故障。在我尝试启用分页之前一切正常。被打破的代码是这样的:自家内核中的三重故障
void switch_page_directory(page_directory_t *dir){
current_directory = dir;
asm volatile("mov %0, %%cr3":: "r"(&dir->tablesPhysical));
u32int cr0;
asm volatile("mov %%cr0, %0": "=r"(cr0));
cr0 |= 0x80000000;//enable paging
asm volatile("mov %0, %%cr0":: "r"(cr0)); //this line breaks
}//switch page directory
我一直在关注这个各种教程/文档,但我使用寻呼的一个是这样http://www.jamesmolloy.co.uk/tutorial_html/6.-Paging.html。我不确定其他代码对于解决这个问题是有用的,但是如果有更多的我应该提供,我会非常乐意这样做。
编辑=====
相信CS,DS和SS在这里选择正确的项是用来设置它们
global gdt_flush
extern gp
gdt_flush:
lgdt [gp] ; Load the GDT with our 'gp' which is a special pointer
mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump!
flush2:
ret ; Returns back to the C code!
代码和这里的GDT结构本身
struct gdt_entry{
unsigned short limit_low;
unsigned short base_low;
unsigned char base_middle;
unsigned char access;
unsigned char granularity;
unsigned char base_high;
} __attribute__((packed));
struct gdt_ptr{
unsigned short limit;
unsigned int base;
} __attribute__((packed));
struct gdt_entry gdt[5];
struct gdt_ptr gp;
IDT与此非常相似。
那么当你执行有问题的行时究竟发生了什么? – sth 2010-11-02 19:31:11
虚拟机重新启动自己,并将im带回引导装载程序 – bschaffer13 2010-11-02 19:40:26
我不认为这里有足够的信息:许多事情可能出错了,特别是如果你是从各种教程中混合的东西。你如何设置GDT? CS,DS和SS(至少)是否都选择了合适的GDT条目?那么IDT呢?是否正确设置了页面表以进行标识映射?你在运行什么虚拟机环境? – 2010-11-03 01:00:03