我正在嘗試編寫一個內核,主要用於娛樂目的,而且我遇到了一個問題,我認爲它是三重故障。在我嘗試啓用分頁之前一切正常。被打破的代碼是這樣的:自家內核中的三重故障
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