Fixed ELF loading again, memory management needs to be redone properly
This commit is contained in:
parent
67f719c73f
commit
819a24ab8d
9 changed files with 68 additions and 28 deletions
|
@ -23,6 +23,9 @@
|
|||
#include <mm/vmm.h>
|
||||
#include <vfs/vfs.h>
|
||||
#include <print.h>
|
||||
#include <axboot.h>
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
|
||||
extern __attribute__((noreturn)) void aurix_handoff(void *pagemap, void *stack, uint64_t entry, void *params);
|
||||
extern char _aurix_handoff_start[], _aurix_handoff_end[];
|
||||
|
@ -35,20 +38,24 @@ void aurix_load(char *kernel)
|
|||
|
||||
// TODO: Do something with the kernel :p
|
||||
pagetable *pm = create_pagemap();
|
||||
// __asm__ volatile("mov %%cr3, %0" : "=r"(pm));
|
||||
if (!pm) {
|
||||
debug("aurix_load(): Failed to create kernel pagemap! Halting...\n");
|
||||
// TODO: Halt
|
||||
while (1);
|
||||
}
|
||||
|
||||
map_pages(pm, (uintptr_t)_aurix_handoff_start, (uintptr_t)_aurix_handoff_start, (uint64_t)_aurix_handoff_end - (uint64_t)_aurix_handoff_start, VMM_PRESENT | VMM_USER | VMM_WRITABLE);
|
||||
|
||||
map_pages(pm, (uintptr_t)pm, (uintptr_t)pm, PAGE_SIZE, VMM_WRITABLE);
|
||||
map_pages(pm, (uintptr_t)_aurix_handoff_start, (uintptr_t)_aurix_handoff_start, (uint64_t)_aurix_handoff_end - (uint64_t)_aurix_handoff_start, 0);
|
||||
|
||||
void *stack = mem_alloc(16*1024); // 16 KiB stack should be well more than enough
|
||||
if (!stack) {
|
||||
debug("aurix_load(): Failed to allocate stack! Halting...\n");
|
||||
while (1);
|
||||
}
|
||||
|
||||
map_pages(pm, (uintptr_t)stack, (uintptr_t)stack, 16*1024, VMM_WRITABLE | VMM_NX);
|
||||
|
||||
void *kernel_entry = (void *)elf_load(kbuf, pm);
|
||||
if (!kernel_entry) {
|
||||
debug("aurix_load(): Failed to load '%s'! Halting...\n", kernel);
|
||||
|
@ -60,10 +67,14 @@ void aurix_load(char *kernel)
|
|||
|
||||
debug("aurix_load(): Handoff state: pm=0x%llx, stack=0x%llx, kernel_entry=0x%llx\n", pm, stack, kernel_entry);
|
||||
|
||||
aurix_handoff(pm, (void *)((uint8_t)stack + 16*1024), (uint64_t)kernel_entry, (void *)parameters);
|
||||
// this triggers a #GP ????
|
||||
// aurix_handoff(pm, stack, (uint64_t)kernel_entry, (void *)parameters);
|
||||
// __builtin_unreachable();
|
||||
|
||||
// __asm__ volatile("movq %[pml4], %%cr3\n" :: [pml4]"r"(pm) : "memory");
|
||||
__asm__ volatile("movq %[pml4], %%cr3\n"
|
||||
"movq %[stack], %%rsp\n"
|
||||
"callq *%[entry]\n"
|
||||
:: [pml4]"r"(pm), [stack]"r"(stack), [entry]"r"(kernel_entry) : "memory");
|
||||
// __asm__ volatile("callq *%[entry]\n"
|
||||
// :: [entry]"r"(kernel_entry));
|
||||
|
||||
}
|
||||
// :: [entry]"r"(kernel_entry));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue