summaryrefslogtreecommitdiffstats
path: root/syscall/handler.c
diff options
context:
space:
mode:
Diffstat (limited to 'syscall/handler.c')
-rw-r--r--syscall/handler.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/syscall/handler.c b/syscall/handler.c
new file mode 100644
index 0000000..efab179
--- /dev/null
+++ b/syscall/handler.c
@@ -0,0 +1,66 @@
+#include "syscall.h"
+#include "object.h"
+#include "handles.h"
+#include "device/processor.h"
+#include "print.h"
+#include <stdint.h>
+#include <stddef.h>
+
+static int
+s_syscall_handle_invoke(objdir_t *root_dir, void *payload)
+{
+ struct syscallInvokeHeader *invokeHeader = payload;
+ uintmax_t target_path = invokeHeader->target_path;
+ objdir_entry_t *target_entry = objdir_seek(root_dir, target_path);
+
+ klogf("target entry %x:%p func %i\n", target_path, target_entry->data, invokeHeader->func_id);
+
+ if(target_entry == NULL) return -1;
+ switch(target_entry->type) {
+ case KO_NONE:
+ return -1;
+ case KO_OBJECT_DIRECTORY:
+ return syscall_handle_invoke_objdir(root_dir, (objdir_t*)target_entry->data, payload);
+ default:
+ klogf("Missing implementation of invoke for type %i\n", target_entry->type);
+ return -1;
+ }
+}
+
+int
+_syscall_handler(uintmax_t argsi, int calli)
+{
+ objdir_t *objdir = ((processor_t*)processor_current())->odir;
+ objdir_entry_t *payload_entry = objdir_seek(objdir, argsi);
+ if(payload_entry == NULL) {
+ klogf("Missing object for syscall %i (%x)\n", calli, argsi);
+ return -1;
+ }
+ if(payload_entry->type != KO_MESSAGE) {
+ klogf("Tried to invoke syscall %i with invalid object %x\n", calli, argsi);
+ return -1;
+ }
+
+ uintmax_t *payload = (void*)payload_entry->data;
+
+ switch(calli) {
+ case SYSCALL_INVOKE: return s_syscall_handle_invoke(objdir, payload);
+ case SYSCALL_DEBUG_PUTC:
+ kprintf("%c", (char)payload[0]);
+ return 0;
+ case SYSCALL_DEBUG_IDENTIFY:
+ {
+ objdir_entry_t *target_entry = objdir_seek(objdir, payload[0]);
+ if(payload_entry == NULL) {
+ payload[0] = KO_NONE;
+ } else {
+ payload[0] = target_entry->type;
+ }
+ return 0;
+ }
+ default:
+ klogf("Invalid syscall %i caught! Failing.\n", calli);
+ return -1;
+ }
+ return -1;
+}