From 0dd3f5e6f4f7607611ce23510858ab3597b5df9f Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 16 Aug 2020 17:13:32 +0200 Subject: Added events and map syscall --- kernel/features/event.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 kernel/features/event.c (limited to 'kernel/features/event.c') diff --git a/kernel/features/event.c b/kernel/features/event.c new file mode 100644 index 0000000..e91dcab --- /dev/null +++ b/kernel/features/event.c @@ -0,0 +1,32 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#include +#include +#include + +u32 (*event_table[])() = { [EVENT_KEYBOARD] = NULL, [EVENT_MOUSE] = NULL }; + +u32 event_map(enum event id, u32 (*function)()) +{ + printf("%x to %x\n", id, function); + if (id >= sizeof(event_table) / sizeof(*event_table)) + return -1; + + event_table[id] = function; + return 0; +} + +u32 event_trigger(enum event id, u32 *data) +{ + assert(id < sizeof(event_table) / sizeof(*event_table)); + + u32 (*location)(u32 *) = event_table[id]; + if (!location) { + printf("Event %d not mapped!\n", id); + return -1; + } + + // TODO: Execute event function in ring3 with process stack, ... + location(data); + return 0; +} -- cgit v1.2.3