For some reason when I try enable paging I am getting a page fault which eventually turns into a triple fault right after enabling paging before returning from the assembly function call.
Is there anything obvious I have missed?
The code should map everything 1:1 to start off with as a test.
Code:
struct PageDirectory {
unsigned Present : 1;
unsigned ReadWrite : 1;
unsigned UserSupervisor : 1;
unsigned CacheWriteThrough : 1;
unsigned CacheDisable : 1;
unsigned Accessed : 1;
unsigned NotUsed0 : 1;
unsigned PageSize : 1;
unsigned NotUsed1 : 4;
unsigned Address : 20;
} __attribute__((packed));
struct PageEntry {
unsigned Present : 1;
unsigned ReadWrite : 1;
unsigned UserSupervisor : 1;
unsigned CacheWriteThrough : 1;
unsigned CacheDisable : 1;
unsigned Accessed : 1;
unsigned Dirty : 1;
unsigned PageAttributeTable : 1;
unsigned Global : 1;
unsigned NotUsed0 : 3;
unsigned Address : 20;
} __attribute__((packed));
Code:
extern "C" __attribute__((fastcall)) void enable_paging(PageDirectory* address);
PageDirectory directories[1024] __attribute__((aligned(4096)));
PageEntry tables[1024 * 1024] __attribute__((aligned(4096)));
void enable() {
for (uint32_t i = 0; i < 1024; i++) {
PageDirectory& directory = directories[i];
directory.UserSupervisor = 1;
directory.ReadWrite = 1;
directory.Present = 1;
directory.Address = reinterpret_cast<uint32_t>(&tables[i * 1024]);
}
for (uint32_t i = 0; i < 1024 * 1024; i++) {
PageEntry& entry = tables[i];
entry.UserSupervisor = 1;
entry.Present = 1;
entry.Address = i * 4096;
}
enable_paging(&directories[0]);
}
Code:
global enable_paging
enable_paging:
mov eax, ecx
mov cr3, eax
mov eax, cr0
or eax, 0x80000001
mov cr0, eax
ret
Any ideas?
X86 kernel with C++ and NASM - no PAE enabled