From 8c977b5cea3f2e76205bd0ed666db06a84e05f6a Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 26 Jul 2022 00:14:30 +0200 Subject: user_bootstrap: link against user/lib I have no idea why I didn't do this right from the start, it makes this whole thing much easier. --- src/user_bootstrap/main.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/user_bootstrap/main.c') diff --git a/src/user_bootstrap/main.c b/src/user_bootstrap/main.c index 52d7058..8fed3ce 100644 --- a/src/user_bootstrap/main.c +++ b/src/user_bootstrap/main.c @@ -1,19 +1,12 @@ #include #include #include -#include +#include extern char _bss_start; extern char _bss_end; extern char _initrd; -/* libc stubs */ -int printf(const char *fmt, ...) {(void)fmt; return 0;} -void *malloc(size_t size) {(void)size; _syscall_exit(1);} -void free(void *ptr) {(void)ptr;} -int file_read(libc_file *f, char *buf, size_t len) {(void)f; (void)buf; (void)len; _syscall_exit(1);} - - static void *tar_find(void *tar, const char *path); static int oct_parse(char *str, size_t len); @@ -26,6 +19,7 @@ static void *tar_find(void *tar, const char *path) { if (0 != memcmp(tar + off + 257, "ustar", 5)) return NULL; // not a metadata sector, end of archive + _klogf("%s", tar + off); size = oct_parse(tar + off + 124, 11); if (0 == memcmp(tar + off, path, path_len) && *(char*)(tar + off + path_len) == '\0') @@ -52,12 +46,16 @@ int main(void) { _syscall_memflag(&_bss_start, &_bss_end - &_bss_start, MEMFLAG_PRESENT); void *init = tar_find(&_initrd, "init.elf"); + if (!init) { + _klogf("couldn't find init.elf\n"); + _syscall_exit(0); + } void (*entry)(void*) = elf_partialexec(init); if (entry) { // TODO dynamically link initrd entry(&_initrd); } else { - _syscall_debug_klog("bootstrap failed", sizeof("bootstrap failed")); + _klogf("couldn't execute init.elf\n"); } _syscall_exit(0); } -- cgit v1.2.3