diff options
author | Marvin Borner | 2021-03-20 19:55:51 +0100 |
---|---|---|
committer | GitHub | 2021-03-20 19:55:51 +0100 |
commit | 5132bac014d63331acf61bb60b9254023f76b869 (patch) | |
tree | 8e2946b7a6630da13ee403c787f77270aeb6185d /kernel/features/mm.c | |
parent | 435231378798819304eef427bad8e77dffea85df (diff) | |
parent | b96c27bba0b242fc860fc9a2fcb63f121312fa7e (diff) |
Merged ELF loading
Diffstat (limited to 'kernel/features/mm.c')
-rw-r--r-- | kernel/features/mm.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/kernel/features/mm.c b/kernel/features/mm.c index d007039..b804076 100644 --- a/kernel/features/mm.c +++ b/kernel/features/mm.c @@ -4,6 +4,7 @@ #include <assert.h> #include <cpu.h> #include <def.h> +#include <fb.h> #include <mem.h> #include <mm.h> #include <print.h> @@ -15,25 +16,27 @@ static struct page_table kernel_tables[PAGE_KERNEL_COUNT] ALIGNED(PAGE_SIZE) = { * Lowlevel paging */ -/*static void paging_disable(void) +static void paging_switch_dir(u32 dir) +{ + cr3_set(dir); +} + +extern void paging_invalidate_tlb(void); + +/*void paging_disable(void) { cr0_set(cr0_get() | 0x7fffffff); }*/ -static void paging_enable(void) +void paging_enable(void) { cr0_set(cr0_get() | 0x80000000); } -static void paging_switch_dir(u32 dir) -{ - cr3_set(dir); -} - -extern void paging_invalidate_tlb(void); - void page_fault_handler(struct regs *r) { + print("--- PAGE FAULT! ---\n"); + // Check error code const char *type = (r->err_code & 1) ? "present" : "non-present"; const char *operation = (r->err_code & 2) ? "write" : "read"; @@ -46,8 +49,8 @@ void page_fault_handler(struct regs *r) struct page_dir *dir = NULL; if (proc && proc->page_dir) { dir = proc->page_dir; - printf("Stack is at %x, entry at %x\n", virtual_to_physical(dir, proc->regs.ebp), - virtual_to_physical(dir, proc->entry)); + /* printf("Stack is at %x, entry at %x\n", virtual_to_physical(dir, proc->regs.ebp), */ + /* virtual_to_physical(dir, proc->entry)); */ } else { dir = &kernel_dir; } @@ -163,7 +166,7 @@ void physical_free(struct memory_range range) * Virtual */ -#define PDI(vaddr) (((vaddr) >> 22) & 0x03ff) +#define PDI(vaddr) ((vaddr) >> 22) #define PTI(vaddr) (((vaddr) >> 12) & 0x03ff) u8 virtual_present(struct page_dir *dir, u32 vaddr) @@ -413,19 +416,20 @@ void memory_backup_dir(struct page_dir **backup) static u8 memory_bypass_validity = 0; void memory_bypass_enable(void) { - memory_bypass_validity = 1; + /* memory_bypass_validity = 1; */ } void memory_bypass_disable(void) { - memory_bypass_validity = 0; + /* memory_bypass_validity = 0; */ } // TODO: Limit by proc stack and data range u8 memory_valid(const void *addr) { + /* return ((u32)addr) / PAGE_SIZE / PAGE_COUNT >= PAGE_KERNEL_COUNT; */ if (proc_current() && !memory_bypass_validity) - return ((u32)addr) / PAGE_SIZE / PAGE_COUNT >= PAGE_KERNEL_COUNT; + return (u32)addr >= 0x100000; else return 1; } @@ -503,9 +507,10 @@ void memory_install(struct mem_info *mem_info, struct vid_info *vid_info) memory_map_identity(&kernel_dir, memory_range_around(STACK_START - STACK_SIZE, STACK_SIZE), MEMORY_NONE); - // Map VBE data + // Map framebuffer memory_map_identity(&kernel_dir, memory_range_around((u32)vid_info->vbe, 0x1000), MEMORY_NONE); + fb_map_buffer(virtual_kernel_dir(), vid_info); // Unmap NULL byte/page struct memory_range zero = memory_range(0, PAGE_SIZE); |