Making all installed memory available causes a triple fault
Posted: Wed Nov 29, 2017 6:22 pm
Hi,
I am trying to start using all the installed memory on my computer instead of using just 16mb. I have no problems detecting memory, nor parsing the memory map, but when I attempt to deinitialize a used memory region (by making the frame unavailable in my physical memory manager) and to enable paging after this my kernel triple faults. If I remove the code that deinitializes the regions the kernel works fine with all the memory (until the point where it tries to use memory in a used region).
The code that is causing the issue is the following:
And the code that enables paging is the following:
You can find my kernels sourcecode at: https://github.com/sofferjacob/jslk, the memory related code is located at "hal/x86/memory".
Thanks in advance
I am trying to start using all the installed memory on my computer instead of using just 16mb. I have no problems detecting memory, nor parsing the memory map, but when I attempt to deinitialize a used memory region (by making the frame unavailable in my physical memory manager) and to enable paging after this my kernel triple faults. If I remove the code that deinitializes the regions the kernel works fine with all the memory (until the point where it tries to use memory in a used region).
The code that is causing the issue is the following:
Code: Select all
int initRegions(multiboot_info_t* bootinfo) {
// Check GRUB passed the memmory map
if (!(bootinfo->flags & MULTIBOOT_INFO_MEM_MAP)) {
PANIC("Couldn't load memory map");
}
memory_map_t* mmap = bootinfo->mmap_addr;
uint8_t regNum = 0;
while (mmap < bootinfo->mmap_addr + bootinfo->mmap_length) {
if (mmap->type > 4) {
mmap->type = 2;
}
kprint("Found section ");kernelPrintDec(regNum);kprint(" of type ");kprint(memTypes[mmap->type]);kprint(". \n");
kprint("Section base: ");kernelPrintHex(mmap->base_addr_low); kprint("\n");
if (mmap->type == 2) {
for (uint64_t i = 0; i < mmap->length_low; i += 0x1000) {
if (mmap->base_addr_low + i > 0xFFFFFFFF) break;
set_frame((mmap->base_addr_low + i) /*& 0xFFFFF000*/);
}
kprintf("Deinitialized region %i\n", regNum);
}
mmap = (memory_map_t*)((unsigned int)mmap + mmap->size + sizeof(mmap->size));
regNum++;
}
}
Code: Select all
void switch_page_directory(page_directory_t *dir) {
current_directory = dir;
asm volatile("mov %0, %%cr3":: "r"(&dir->tablesPhysical));
uint32_t cr0;
asm volatile("mov %%cr0, %0": "=r"(cr0));
cr0 |= 0x80000000; // Enable paging!
asm volatile("mov %0, %%cr0":: "r"(cr0));
}
Thanks in advance