diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-07-05 19:38:11 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-07-05 19:38:11 +0300 |
| commit | e09edb5d54e39bd9509a1dc450df5ab320759f97 (patch) | |
| tree | 78e050b0db87df3a3ddfbb6570d44513ac34e02a /src/proc.c | |
| parent | 98f21e694a6b0964d6d08196cb6bfbc1c2ae2ff4 (diff) | |
| download | kmi-e09edb5d54e39bd9509a1dc450df5ab320759f97.tar.gz kmi-e09edb5d54e39bd9509a1dc450df5ab320759f97.zip | |
allow booting with Qemu's -kernel flag directly
+ Took some fairly significant changes, for one the kernel is no longer
relocated at the start of a boot, instead it sits wherever the user
decides the kernel should sit. Similarly, the initial kernel stack and
page table are stored within the binary, slightly bloating the size
but making it much safer to boot since there's really no chance of us
overwriting the fdt or initrd in memory.
Diffstat (limited to 'src/proc.c')
| -rw-r--r-- | src/proc.c | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -9,12 +9,15 @@ #include <kmi/elf.h> #include <kmi/proc.h> #include <kmi/conf.h> +#include <kmi/debug.h> #include <kmi/string.h> #include <kmi/initrd.h> #include <arch/arch.h> #include <arch/proc.h> #include <arch/cpu.h> +#include <libfdt.h> + stat_t prepare_proc(struct tcb *t, vm_t bin, vm_t interp) { vm_t entry = load_elf(t, bin, interp); @@ -27,7 +30,7 @@ stat_t prepare_proc(struct tcb *t, vm_t bin, vm_t interp) return OK; } -stat_t init_proc(void *fdt) +stat_t init_proc(void *fdt, vm_t *proc_fdt, vm_t *proc_initrd) { init_tcbs(); @@ -42,18 +45,32 @@ stat_t init_proc(void *fdt) /* force tcb for core */ tcb_assign(t); - /* set current tcb */ - use_tcb(t); + t->notify_id = t->tid; /* init process has all capabilities */ set_caps(t->caps, 0, CAP_CAPS | CAP_PROC | CAP_SIGNAL | CAP_POWER | CAP_NOTIFY); - t->notify_id = t->tid; + /* we shall try to map the fdt and initrd into the new address space, so + * save them here before we switch */ + use_tcb(t); - /* allocate stacks after ELF file to make sure nothing of importance + /* allocate stacks etc after ELF file to make sure nothing of importance * clashes */ - return prepare_proc(t, get_init_base(fdt), 0); + prepare_proc(t, get_init_base(fdt), 0); /** \todo start one thread per core, with special handling for init in * that each thread starts at the entry point of init? */ + + *proc_fdt = map_fixed_mem(t, + (pm_t)fdt, fdt_totalsize(fdt), + VM_V | VM_R | VM_U); + + pm_t initrd = (pm_t)__va(get_initrdbase(fdt)); + *proc_initrd = map_fixed_mem(t, + initrd, get_initrdsize(fdt), + VM_V | VM_R | VM_U); + + info("mapped fdt at %p\n", (void *)*proc_fdt); + info("mapped initrd at %p\n", (void *)*proc_initrd); + return OK; } |
