From 9ad0eafcf7e2f3e0532666c5353b0f5294401b06 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 20 Jul 2021 21:38:09 +0200 Subject: per-process virtual memory VGA is only mapped into the virtual memory because there are no other ways of interacting with the OS. --- src/kernel/main.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'src/kernel/main.c') diff --git a/src/kernel/main.c b/src/kernel/main.c index a59c014..729e39d 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -6,32 +6,29 @@ #include #include -static void setup_paging() { - struct pagedir *dir = pagedir_new(); +static void run_init(struct kmain_info *info) { + struct process *proc = process_new(); + void *init_base = (void*) 0x200000; - // map VGA - pagedir_map(dir, 0xB8000, 0xB8000, true, true); + // map VGA for testing + pagedir_map(proc->pages, 0xB8000, 0xB8000, true, true); - // map the kernel - for (size_t p = 0x100000; p < &_bss_end; p += PAGE_SIZE) - pagedir_map(dir, p, p, false, true); // yes, .text is writeable too + // map the module as rw + for (uintptr_t off = 0; off < info->init.size; off += PAGE_SIZE) + pagedir_map(proc->pages, init_base + off, info->init.at + off, + true, true); + proc->eip = init_base; - pagedir_switch(dir); + log_const("switching..."); + process_switch(proc); } void kmain(struct kmain_info info) { log_const("mem..."); mem_init(&info); - log_const("paging..."); - setup_paging(); - - log_const("creating process..."); + log_const("loading init..."); + run_init(&info); - void *init_addr = (void*)0x200000; - memcpy(init_addr, info.init.at, info.init.size); - - struct process *proc = process_new(init_addr); - log_const("switching..."); - process_switch(proc); + panic(); } -- cgit v1.2.3