diff options
-rw-r--r-- | kernel/features/event.c | 20 | ||||
-rw-r--r-- | kernel/features/proc.c | 12 | ||||
-rw-r--r-- | kernel/inc/event.h | 6 | ||||
-rw-r--r-- | kernel/inc/proc.h | 3 |
4 files changed, 37 insertions, 4 deletions
diff --git a/kernel/features/event.c b/kernel/features/event.c index 8bdba1a..02f5f1d 100644 --- a/kernel/features/event.c +++ b/kernel/features/event.c @@ -2,7 +2,10 @@ #include <assert.h> #include <def.h> +#include <event.h> #include <list.h> +#include <mem.h> +#include <proc.h> #include <sys.h> struct list *event_table[] = { [EVENT_KEYBOARD] = NULL, [EVENT_MOUSE] = NULL }; @@ -15,7 +18,12 @@ u32 event_map(enum event id, u32 *func) if (event_table[id] == NULL) event_table[id] = (struct list *)list_new(); - list_add((struct list *)event_table[id], (void *)func); + + struct event_descriptor *desc = malloc(sizeof(*desc)); + desc->func = func; + desc->proc = proc_current(); + + list_add((struct list *)event_table[id], (void *)desc); return 0; } @@ -23,8 +31,13 @@ u32 event_map(enum event id, u32 *func) void event_unmap(enum event id, u32 *func) { struct list *list = ((struct list *)event_table[id]); + + struct event_descriptor *desc = malloc(sizeof(*desc)); + desc->func = func; + desc->proc = proc_current(); + struct node *iterator = list->head; - while (iterator->data != (void *)func) { + while (memcmp(iterator->data, (void *)desc, sizeof(*desc)) == 0) { iterator = iterator->next; if (!iterator) return; @@ -45,7 +58,8 @@ u32 event_trigger(enum event id, u32 *data) } while (1) { - u32 *func = iterator->data; + struct event_descriptor *desc = iterator->data; + desc->proc->event = 1 << id; iterator = iterator->next; if (iterator == NULL) break; diff --git a/kernel/features/proc.c b/kernel/features/proc.c index f6e1fe6..b43b800 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -40,6 +40,13 @@ void scheduler(struct regs *regs) /* proc_print(); */ memcpy(regs, ¤t->regs, sizeof(struct regs)); + if (current->event) { + // TODO: Modify and backup EIP + printf("Event %d for %d\n", current->event, current->pid); + // TODO: Clear bit after resolve + current->event = 0; + } + if (regs->cs != GDT_USER_CODE_OFFSET) { regs->gs = GDT_USER_DATA_OFFSET; regs->fs = GDT_USER_DATA_OFFSET; @@ -65,6 +72,11 @@ void proc_print() printf("\n"); } +struct proc *proc_current() +{ + return current; +} + void proc_attach(struct proc *proc) { if (!last->next) { diff --git a/kernel/inc/event.h b/kernel/inc/event.h index e40b345..d0fe4fc 100644 --- a/kernel/inc/event.h +++ b/kernel/inc/event.h @@ -4,8 +4,14 @@ #define EVENT_H #include <def.h> +#include <proc.h> #include <sys.h> +struct event_descriptor { + u32 *func; + struct proc *proc; +}; + u32 event_map(enum event id, u32 *func); void event_unmap(enum event id, u32 *func); u32 event_trigger(enum event id, u32 *data); diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h index 9f3816d..1ed5df2 100644 --- a/kernel/inc/proc.h +++ b/kernel/inc/proc.h @@ -19,12 +19,13 @@ struct proc { enum state state; char name[32]; struct regs regs; - /* struct proc *parent; */ struct proc *next; + u32 event; }; void proc_init(); void proc_print(); +struct proc *proc_current(); void proc_exit(); struct proc *proc_make(); |