diff options
author | dzwdz | 2022-04-21 19:17:29 +0200 |
---|---|---|
committer | dzwdz | 2022-04-21 19:17:29 +0200 |
commit | a60b3ca993ac7ff428c4a545c357484237450c22 (patch) | |
tree | d7d153e2ec6da67cc33be964ac9a65bacf03ee28 /src | |
parent | a990307680233460b2243c84002725b05a68b94a (diff) |
kernel: consolidate `process_seed` and `run_init`
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/main.c | 20 | ||||
-rw-r--r-- | src/kernel/proc.c | 10 | ||||
-rw-r--r-- | src/kernel/proc.h | 2 |
3 files changed, 13 insertions, 19 deletions
diff --git a/src/kernel/main.c b/src/kernel/main.c index d1046b2..a0fdd07 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -6,21 +6,6 @@ #include <kernel/util.h> #include <stdint.h> -_Noreturn static void run_init(struct kmain_info *info) { - // TODO move all of this to process_seed - struct process *proc = process_seed(); - void __user *init_base = (userptr_t)0x200000; - - // 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->regs.eip = init_base; - - kprintf("switching...\n"); - process_switch_any(); -} - void kmain(struct kmain_info info) { kprintf("mem...\n"); mem_init(&info); @@ -29,7 +14,10 @@ void kmain(struct kmain_info info) { tests_all(); kprintf("loading init...\n"); - run_init(&info); + process_seed(&info); + + kprintf("switching...\n"); + process_switch_any(); } void shutdown(void) { diff --git a/src/kernel/proc.c b/src/kernel/proc.c index bb4509b..94a448a 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -12,7 +12,7 @@ struct process *process_first; struct process *process_current; static uint32_t next_pid = 0; -struct process *process_seed(void) { +struct process *process_seed(struct kmain_info *info) { struct process *proc = kmalloc(sizeof *proc); proc->pages = pagedir_new(); proc->state = PS_RUNNING; @@ -39,7 +39,13 @@ struct process *process_seed(void) { for (size_t p = 0x100000; p < (size_t)&_bss_end; p += PAGE_SIZE) pagedir_map(proc->pages, (userptr_t)p, (void*)p, false, true); - // the kernel still has to load the executable code and set EIP + // map the init module as rw + void __user *init_base = (userptr_t)0x200000; + 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->regs.eip = init_base; + return proc; } diff --git a/src/kernel/proc.h b/src/kernel/proc.h index 3d3459d..7389b74 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -60,7 +60,7 @@ extern struct process *process_first; extern struct process *process_current; // creates the root process -struct process *process_seed(void); +struct process *process_seed(struct kmain_info *info); struct process *process_fork(struct process *parent); void process_free(struct process *); _Noreturn void process_switch_any(void); // switches to any running process |