From ca7d400b7705ba887df69391cb774d4de83e8bf3 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 17 Aug 2020 13:52:51 +0200 Subject: Added event unmap --- apps/wm.c | 4 ++-- kernel/features/event.c | 14 ++++++++++++++ kernel/features/syscall.c | 6 +++++- kernel/inc/event.h | 3 ++- libc/inc/sys.h | 13 ++++++++++++- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/apps/wm.c b/apps/wm.c index aa46b8f..5f9503e 100644 --- a/apps/wm.c +++ b/apps/wm.c @@ -23,8 +23,8 @@ void main(char **argv) print("WM loaded.\n"); printf("VBE: %dx%d\n", vbe->width, vbe->height); - const u32 color[3] = { 0xff, 0xff, 0 }; - const u32 text[3] = { 0, 0, 0 }; + const u32 color[3] = { 0, 0, 0 }; + const u32 text[3] = { 0xff, 0xff, 0xff }; vesa_fill(vbe, color); gui_init("/font/spleen-16x32.psfu"); gui_write(vbe, 50, 50, text, "hallo"); diff --git a/kernel/features/event.c b/kernel/features/event.c index 320b45a..8bdba1a 100644 --- a/kernel/features/event.c +++ b/kernel/features/event.c @@ -19,6 +19,20 @@ u32 event_map(enum event id, u32 *func) return 0; } +// TODO: Fix unmap +void event_unmap(enum event id, u32 *func) +{ + struct list *list = ((struct list *)event_table[id]); + struct node *iterator = list->head; + while (iterator->data != (void *)func) { + iterator = iterator->next; + if (!iterator) + return; + } + + list_remove(list, iterator); +} + u32 event_trigger(enum event id, u32 *data) { assert(id < sizeof(event_table) / sizeof(*event_table)); diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index 2a01d8a..9d5ac82 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -53,7 +53,11 @@ void syscall_handler(struct regs *r) break; } case SYS_MAP: { - event_map(r->ebx, (u32(*)())r->ecx); + event_map(r->ebx, (u32 *)r->ecx); + break; + } + case SYS_UNMAP: { + event_unmap(r->ebx, (u32 *)r->ecx); break; } default: { diff --git a/kernel/inc/event.h b/kernel/inc/event.h index f4025b4..e40b345 100644 --- a/kernel/inc/event.h +++ b/kernel/inc/event.h @@ -6,7 +6,8 @@ #include #include -u32 event_map(enum event id, u32 (*function)()); +u32 event_map(enum event id, u32 *func); +void event_unmap(enum event id, u32 *func); u32 event_trigger(enum event id, u32 *data); #endif diff --git a/libc/inc/sys.h b/libc/inc/sys.h index 99f5920..88d83df 100644 --- a/libc/inc/sys.h +++ b/libc/inc/sys.h @@ -4,7 +4,17 @@ #ifndef SYS_H #define SYS_H -enum sys { SYS_LOOP, SYS_MALLOC, SYS_FREE, SYS_READ, SYS_WRITE, SYS_EXEC, SYS_EXIT, SYS_MAP }; +enum sys { + SYS_LOOP, + SYS_MALLOC, + SYS_FREE, + SYS_READ, + SYS_WRITE, + SYS_EXEC, + SYS_EXIT, + SYS_MAP, + SYS_UNMAP +}; enum event { EVENT_KEYBOARD, EVENT_MOUSE }; #if defined(userspace) @@ -32,6 +42,7 @@ int sysv(enum sys num, ...); } \ } #define map(id, func) sys2(SYS_MAP, (int)id, (int)func) +#define unmap(id, func) sys2(SYS_UNMAP, (int)id, (int)func) #endif #endif -- cgit v1.2.3