aboutsummaryrefslogtreecommitdiff
path: root/user/include/weenix/trap.h
diff options
context:
space:
mode:
authornthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
committernthnluu <nate1299@me.com>2024-01-28 21:20:27 -0500
commitc63f340d90800895f007de64b7d2d14624263331 (patch)
tree2c0849fa597dd6da831c8707b6f2603403778d7b /user/include/weenix/trap.h
Created student weenix repository
Diffstat (limited to 'user/include/weenix/trap.h')
-rw-r--r--user/include/weenix/trap.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/user/include/weenix/trap.h b/user/include/weenix/trap.h
new file mode 100644
index 0000000..fade1eb
--- /dev/null
+++ b/user/include/weenix/trap.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include "errno.h"
+#include "stddef.h"
+#include "sys/types.h"
+#include "weenix/syscall.h"
+
+#define TRAP_INTR_STRING QUOTE(INTR_SYSCALL)
+
+/* ssize_t will be 32 bits or 64 bits wide as appropriate.
+ args are passed via %(r/e)ax and %(r/e)dx, so they need
+ to be the size of a register. */
+
+static inline ssize_t trap(ssize_t num, ssize_t arg)
+{
+ ssize_t ret;
+ __asm__ volatile("int $" TRAP_INTR_STRING
+ : "=a"(ret)
+ : "a"(num), "d"(arg));
+
+ /* Copy in errno */
+ __asm__ volatile("int $" TRAP_INTR_STRING
+ : "=a"(errno)
+ : "a"(SYS_errno));
+ return ret;
+}