aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorMarvin Borner2023-01-28 22:29:48 +0100
committerMarvin Borner2023-01-28 22:29:48 +0100
commitde450bfb4354f716fb43fae69d90ed513068d10b (patch)
treeb474219ae3baaeb8a075e6fbb5c57c3857faa588 /src/main.c
parent75bb42663294b388377178b7257c6f8c0f787032 (diff)
Rewrite, bootstrap
Rewriting without KVM, huge goals, won't finish, just for fun.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c70
1 files changed, 9 insertions, 61 deletions
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 <errno.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <kvm.h>
+#include <cpu.h>
+#include <mem.h>
#include <log.h>
-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;
}