From de450bfb4354f716fb43fae69d90ed513068d10b Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 28 Jan 2023 22:29:48 +0100 Subject: Rewrite, bootstrap Rewriting without KVM, huge goals, won't finish, just for fun. --- src/main.c | 70 ++++++++------------------------------------------------------ 1 file changed, 9 insertions(+), 61 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 9ffe99a..b8bbe93 100644 --- a/src/main.c +++ b/src/main.c @@ -1,71 +1,19 @@ -#include -#include -#include -#include -#include - -#include +#include +#include #include -struct aalloc_info { - void *actual_ptr; -}; - -static void *aalloc(int size, int align) -{ - int adjusted = align - 1; - void *actual = calloc(1, sizeof(void *) + size + adjusted); - struct aalloc_info *ai = - (void *)(((uintptr_t)((long)actual + sizeof(void *) + adjusted) & ~adjusted) - - sizeof(void *)); - ai->actual_ptr = actual; - return ((char *)ai) + sizeof(void *); -} - -static void afree(void *ptr) -{ - struct aalloc_info *a = (void *)((char *)ptr - sizeof(void *)); - free(a->actual_ptr); -} - -static void load_bios(const char *path) -{ - FILE *bios = fopen(path, "rb"); - if (!bios) { - errln("Couldn't open '%s': %s", path, strerror(errno)); - exit(1); - } - fseek(bios, 0, SEEK_END); - int size = ftell(bios); - fseek(bios, 0, SEEK_SET); - - void *data = aalloc(size, 4096); - if (fread(data, size, 1, bios) != 1) { - errln("Couldn't read '%s': %s", path, strerror(errno)); - exit(1); - } - - fclose(bios); - - int load = kvm_load(0, (long)data, size); - if (load < 0) { - errln("Couldn't load '%s'", path); - exit(1); - } - - afree(data); -} - int main(int argc, char *argv[]) { (void)argc; (void)argv; - int cpu = kvm_init(); - if (cpu < 0) - exit(1); - load_bios("build/test"); - kvm_exec(); + if (argc != 2) { + logln("invalid arguments"); + return 1; + } + + cpu_exec(argv[1]); + mem_free_all(); return 0; } -- cgit v1.2.3