I'm using James Molloy's tutorials to develop parts of my OS and I'm looking at the section where he implements multitasking. However, I get a triple fault whenever I use switch_page_directory at the end of my init_paging function.
Code: Select all
current_directory = clone_directory(kernel_directory);
switch_page_directory(current_directory);
Code: Select all
void switch_page_directory(page_directory_t* dir) {
current_directory = dir;
asm volatile("mov %0, %%cr3" : : "r"(dir->physicalAddr));
}
And clone_directory looks like
Code: Select all
page_directory_t* clone_directory(page_directory_t* src) {
uint32_t phys;
//make new page directory and get physaddr
page_directory_t* dir = (page_directory_t*)kmalloc_ap(sizeof(page_directory_t), &phys);
//blank it
memset((uint8_t*)dir, 0, sizeof(page_directory_t));
//get offset of tablesPhysical from start of page_directory_t
uint32_t offset = (uint32_t)dir->tablesPhysical - (uint32_t)dir;
dir->physicalAddr = phys + offset;
printf_dbg("dir->physicalAddr: %x", dir->physicalAddr);
//for each page table
//if in kernel directory, don't make copy
for (int i = 0; i < 1024; i++) {
if (!src->tables[i]) continue;
if (kernel_directory->tables[i] == src->tables[i]) {
//in kernel, so just reuse same pointer
dir->tables[i] = src->tables[i];
dir->tablesPhysical[i] = src->tablesPhysical[i];
}
else {
//copy table
uint32_t phys;
dir->tables[i] = clone_table(src->tables[i], &phys);
dir->tablesPhysical[i] = phys | 0x07;
}
}
return dir;
}
Thanks!