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/elfload.c | 1 - src/user_bootstrap/elfload.h | 1 - src/user_bootstrap/linker.ld | 6 ++++++ src/user_bootstrap/main.c | 16 +++++++--------- src/user_bootstrap/syscall.c | 1 - src/user_bootstrap/syscall.s | 1 - 6 files changed, 13 insertions(+), 13 deletions(-) delete mode 120000 src/user_bootstrap/elfload.c delete mode 120000 src/user_bootstrap/elfload.h delete mode 120000 src/user_bootstrap/syscall.c delete mode 120000 src/user_bootstrap/syscall.s (limited to 'src') diff --git a/src/user_bootstrap/elfload.c b/src/user_bootstrap/elfload.c deleted file mode 120000 index 75a5cb2..0000000 --- a/src/user_bootstrap/elfload.c +++ /dev/null @@ -1 +0,0 @@ -../user/lib/elfload.c \ No newline at end of file diff --git a/src/user_bootstrap/elfload.h b/src/user_bootstrap/elfload.h deleted file mode 120000 index 5b09fdc..0000000 --- a/src/user_bootstrap/elfload.h +++ /dev/null @@ -1 +0,0 @@ -../user/lib/elfload.h \ No newline at end of file diff --git a/src/user_bootstrap/linker.ld b/src/user_bootstrap/linker.ld index f2c9d24..917388c 100644 --- a/src/user_bootstrap/linker.ld +++ b/src/user_bootstrap/linker.ld @@ -3,6 +3,11 @@ OUTPUT_FORMAT("binary") SECTIONS { + /* Not an ELF, but we need this to link with elfreloc.c. + * Not that we need to link with it, it's just easier that way */ + _DYNAMIC = 0; + _image_base = 0; + . = 2M; .text BLOCK(4K) : ALIGN(4K) { @@ -18,6 +23,7 @@ SECTIONS *(.data) } + . = ALIGN(32); /* seems to be necessary? */ _initrd = .; /* is just appended onto the end of the binary */ . += 2M; 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); } diff --git a/src/user_bootstrap/syscall.c b/src/user_bootstrap/syscall.c deleted file mode 120000 index c6d5b0f..0000000 --- a/src/user_bootstrap/syscall.c +++ /dev/null @@ -1 +0,0 @@ -../user/lib/syscall.c \ No newline at end of file diff --git a/src/user_bootstrap/syscall.s b/src/user_bootstrap/syscall.s deleted file mode 120000 index ac2e0f9..0000000 --- a/src/user_bootstrap/syscall.s +++ /dev/null @@ -1 +0,0 @@ -../user/lib/syscall.s \ No newline at end of file -- cgit v1.2.3