I've read the Osdev wiki article about paging, so I've written a little code to activate it, but after activating it ( by or-ing CR0 with 0x80000000 ), Bochs says ">> (invalid) : FFFF" ...
Here's the code( I'm not sure the page tables initialization is correct... ) :
Code: Select all
#include "paging.h"
u32int page_dir[1024];
u32int page_table[1048576];
void init_pagedir(){
int i = 0;
for( i = 0; i <= 1024; i++ ){
page_dir[i] ^= page_dir[i];
page_dir[i] = page_table + 1024 * i;
page_dir[i] = page_dir[i] >> 12;
page_dir[i] = page_dir[i] << 12;
page_dir[i] = page_dir[i] | 3;
}
}
void init_pagetable(){
int i = 0;
for( i = 0; i < 1048576; i++ ){
page_table[i] ^= page_table[i];
page_table[i] = i*4096;
page_table[i] = page_table[i] | 3;
}
}
void load_pagedir(){
asm volatile ("\
movl %0, %%eax; \
movl %%eax, %%cr3; \
" :: "r" (page_dir));
}
void activate_paging(){
asm volatile ("\
movl %cr0, %eax; \
or $0x80000000, %eax; \
movl %eax, %cr0 \
");
}
void init_paging(){
printf("[DEBUG] activate_paging is located at 0x8:%h ( %d )\n", &activate_paging, &activate_paging);
init_pagedir();
init_pagetable();
printf("\n *Loading page directory...");
load_pagedir();
printf("[DONE]");
printf("\n *Activating paging...");
activate_paging();
printf("[DONE]");
printf("\n *Paging is...");
}
I wrote this code with the feet?
I personally don't understand all the paging articles I've read on JamesM's kernel development tutorials, Brokenthorn tutorials, the Osdev wiki, and SOS's tutorial... SOS uses complicated macros so it doesn't help me much, it's because I'm dumb or maybe not ready for this subject ...
Thanks