diff options
author | dzwdz | 2023-08-14 18:51:07 +0200 |
---|---|---|
committer | dzwdz | 2023-08-14 18:51:07 +0200 |
commit | 642b5fb0007b64c77d186fcb018d571152ee1d47 (patch) | |
tree | 1c466461f3602d306be309a053edae558ef2568e /src/bootstrap/main.c | |
parent | 8050069c57b729c18c19b1a03ab6e4bf63b4735e (diff) |
reorganization: first steps
Diffstat (limited to 'src/bootstrap/main.c')
-rw-r--r-- | src/bootstrap/main.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/bootstrap/main.c b/src/bootstrap/main.c new file mode 100644 index 0000000..d27da39 --- /dev/null +++ b/src/bootstrap/main.c @@ -0,0 +1,43 @@ +#include <_proc.h> +#include <camellia/flags.h> +#include <camellia/syscalls.h> +#include <stdio.h> +#include <string.h> +#include <elfload.h> +#include <camellia/fs/misc.h> + +#include "tar.h" + +extern char _bss_start; +extern char _bss_end; +extern char _initrd; + +__attribute__((section(".text"))) +int main(void) { + _sys_memflag(_psdata_loc, 1, MEMFLAG_PRESENT); + setprogname("bootstrap"); + + _sys_mount(HANDLE_PROCFS, "/proc/", strlen("/proc/")); + MOUNT_AT("/") { + fs_dirinject2((const char*[]) { + "/proc/", + "/init/", + NULL + }); + } + MOUNT_AT("/init/") { + tar_driver(&_initrd); + } + + const char *initpath = "bin/amd64/init"; + char *initargv[] = {"init", NULL}; + void *init = tar_find(initpath, strlen(initpath), &_initrd, ~0) + 512; + if (init) { + _klogf("execing init"); + elf_exec(init, initargv, NULL); + _klogf("elf_exec failed"); + } else { + _klogf("couldn't find init.elf"); + } + _sys_exit(1); +} |