diff options
author | Marvin Borner | 2023-01-28 22:29:48 +0100 |
---|---|---|
committer | Marvin Borner | 2023-01-28 22:29:48 +0100 |
commit | de450bfb4354f716fb43fae69d90ed513068d10b (patch) | |
tree | b474219ae3baaeb8a075e6fbb5c57c3857faa588 /src/linux.c | |
parent | 75bb42663294b388377178b7257c6f8c0f787032 (diff) |
Rewrite, bootstrap
Rewriting without KVM, huge goals, won't finish, just for fun.
Diffstat (limited to 'src/linux.c')
-rw-r--r-- | src/linux.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/linux.c b/src/linux.c new file mode 100644 index 0000000..2e89049 --- /dev/null +++ b/src/linux.c @@ -0,0 +1,41 @@ +#include <stdint.h> +#include <unistd.h> + +#include <cpu.h> +#include <mem.h> +#include <linux.h> +#include <log.h> + +// TODO: Don't use unistd, emulate all syscalls for time-travel + +static void call_write(void) +{ + uint64_t fd = *(uint64_t *)cpu_get_reg(RDI); + char *buf = mem_phys(*(vaddr *)cpu_get_reg(RSI)); + uint64_t count = *(uint64_t *)cpu_get_reg(RDX); + int ret = write(fd, buf, count); + cpu_set_reg(RAX, ret); +} + +static void call_exit(void) +{ + int64_t code = *(int64_t *)cpu_get_reg(RDI); + logln("exiting with code %d", code); +} + +int linux_call(void) +{ + uint64_t call = *(uint64_t *)cpu_get_reg(RAX); + switch (call) { + case 1: + call_write(); + break; + case 60: + call_exit(); + return ERR; + default: + errln("invalid syscall %d", call); + return ERR; + } + return OK; +} |