heading towards merging the 32/64 paging code

This commit is contained in:
Steffen Vogel 2014-05-14 18:56:15 +02:00
parent e2c8222f86
commit 4f5e2ce13b
4 changed files with 35 additions and 7 deletions

View file

@ -85,7 +85,7 @@
#define PAGE_CEIL(addr) ( (addr) & PAGE_MASK)
// Canonical address format
#ifdef CONFIG_x86_32
#ifdef CONFIG_X86_32
#define CANONICAL(addr) (addr)
#elif defined(CONFIG_X86_64)
#define CANONICAL(addr) sign_extend(addr, VIRT_BITS)

View file

@ -401,7 +401,7 @@ void smp_start(uint32_t id)
// On 64bit system, paging is already enabled
#ifdef CONFIG_X86_32
/* enable paging */
write_cr3((size_t)get_boot_pgd());
write_cr3((size_t) get_boot_page_map());
i = read_cr0();
i = i | (1 << 31);
write_cr0(i);

View file

@ -1,4 +1,4 @@
C_source := page$(BIT).c svm.c
C_source := page.c svm.c
MODULE := arch_x86_mm
include $(TOPDIR)/Makefile.inc

View file

@ -59,13 +59,28 @@ extern page_entry_t boot_pml4[PAGE_MAP_ENTRIES];
static spinlock_t kslock = SPINLOCK_INIT;
/// Mapping of self referenced page map (at the end of the VAS)
// TODO: find a more generic initialization
#ifdef CONFIG_X86_32
static page_entry_t* const current_map = (page_entry_t*) (1 * PAGE_MAP_PGD);
static page_entry_t* const src_map = (page_entry_t*) (2 * PAGE_MAP_PGD);
static page_entry_t* const dest_map = (page_entry_t*) (3 * PAGE_MAP_PGD);
#elif defined(CONFIG_X86_64)
static page_entry_t* const current_map = (page_entry_t*) (1 * PAGE_MAP_PML4);
static page_entry_t* const src_map = (page_entry_t*) (2 * PAGE_MAP_PML4);
static page_entry_t* const dest_map = (page_entry_t*) (3 * PAGE_MAP_PML4);
#endif
#ifdef CONFIG_X86_32
static page_entry_t boot_pgd[PAGE_MAP_ENTRIES];
#endif
page_entry_t* get_boot_page_map(void)
{
#ifdef CONFIG_X86_32
return boot_pgd;
#elif defined(CONFIG_X86_64)
return boot_pml4;
#endif
}
void page_dump(size_t mask)
@ -606,15 +621,28 @@ static void pagefault_handler(struct state *s)
}
default_handler:
kprintf("Page Fault Exception (%d) at cs:rip = %#x:%#lx, core = %u, task = %u, addr = %#lx, error = %#x [ %s %s %s %s %s ]\n"
"Register state: rflags = %#lx, rax = %#lx, rbx = %#lx, rcx = %#lx, rdx = %#lx, rdi = %#lx, rsi = %#lx, rbp = %#llx, rsp = %#lx\n",
s->int_no, s->cs, s->rip, CORE_ID, task->id, viraddr, s->error,
kprintf("Page Fault Exception (%d) at cs:ip = %#x:%#lx, core = %u, task = %u, addr = %#lx, error = %#x [ %s %s %s %s %s ]\n",
s->int_no, s->cs,
#ifdef CONFIG_X86_32
s->eip,
#elif defined(CONFIG_X86_64)
s->rip,
#endif
CORE_ID, task->id, viraddr, s->error,
(s->error & 0x4) ? "user" : "supervisor",
(s->error & 0x10) ? "instruction" : "data",
(s->error & 0x2) ? "write" : ((s->error & 0x10) ? "fetch" : "read"),
(s->error & 0x1) ? "protection" : "not present",
(s->error & 0x8) ? "reserved bit" : "\b",
(s->error & 0x8) ? "reserved bit" : "\b");
// TODO: move this to something like print_registers()
#ifdef CONFIG_X86_32
kprintf("Register state: eflags = %#lx, eax = %#lx, ebx = %#lx, ecx = %#lx, edx = %#lx, edi = %#lx, esi = %#lx, ebp = %#llx, esp = %#lx\n",
s->eflags, s->eax, s->ebx, s->ecx, s->edx, s->edi, s->esi, s->ebp, s->esp);
#elif defined(CONFIG_X86_64)
kprintf("Register state: rflags = %#lx, rax = %#lx, rbx = %#lx, rcx = %#lx, rdx = %#lx, rdi = %#lx, rsi = %#lx, rbp = %#llx, rsp = %#lx\n",
s->rflags, s->rax, s->rbx, s->rcx, s->rdx, s->rdi, s->rsi, s->rbp, s->rsp);
#endif
irq_enable();
abort();