aboutsummaryrefslogtreecommitdiff
path: root/src/linux.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/linux.c')
-rw-r--r--src/linux.c41
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;
+}