diff options
-rw-r--r-- | apps/wm.c | 15 | ||||
-rw-r--r-- | kernel/features/event.c | 41 | ||||
-rw-r--r-- | kernel/features/proc.c | 26 | ||||
-rw-r--r-- | kernel/features/syscall.c | 17 | ||||
-rw-r--r-- | kernel/inc/event.h | 9 | ||||
-rw-r--r-- | kernel/inc/proc.h | 9 | ||||
-rw-r--r-- | libc/inc/sys.h | 13 | ||||
-rw-r--r-- | libgui/inc/gui.h | 2 |
8 files changed, 36 insertions, 96 deletions
@@ -16,15 +16,6 @@ struct window *root; // Root window (wallpaper etc.) struct window *exchange; // Exchange buffer struct list *windows; -void onkey(u32 scancode) -{ - printf("WM KEY EVENT %d\n", scancode); - if (KEY_ALPHANUMERIC(scancode)) { - printf("ALPHANUMERIC!\n"); - } - event_resolve(); -} - static struct window *new_window(int x, int y, u16 width, u16 height) { struct window *win = malloc(sizeof(*win)); @@ -61,8 +52,7 @@ int main(int argc, char **argv) // TODO: Fix wallpaper /* gui_load_wallpaper(root, "/wall.bmp"); */ - // TODO: Remove async events completely - /* event_map(EVENT_KEYBOARD, onkey); */ + event_register(EVENT_KEYBOARD); struct message *msg; while (1) { @@ -87,6 +77,9 @@ int main(int argc, char **argv) msg_send(msg->src, MSG_NEW_WINDOW, win); list_add(windows, win); break; + case EVENT_KEYBOARD: + printf("Keypress %d!\n", msg->data); + break; default: printf("Unknown WM request %d from pid %d", msg->type, msg->src); } diff --git a/kernel/features/event.c b/kernel/features/event.c index e0a7d93..5436ef5 100644 --- a/kernel/features/event.c +++ b/kernel/features/event.c @@ -10,69 +10,50 @@ struct list *event_table[] = { [EVENT_KEYBOARD] = NULL, [EVENT_MOUSE] = NULL }; -u32 event_map(enum event id, struct proc *proc, u32 *func) +u32 event_register(enum message_type id, struct proc *proc) { assert(id < sizeof(event_table) / sizeof(*event_table)); - assert(func); if (event_table[id] == NULL) event_table[id] = (struct list *)list_new(); - struct node *iterator = event_table[id]->head; - do { - assert(((struct event_descriptor *)iterator->data)->func != func); - } while ((iterator = iterator->next) != NULL); - struct event_descriptor *desc = malloc(sizeof(*desc)); desc->id = id; - desc->func = func; desc->proc = proc; list_add(event_table[id], (void *)desc); return 0; } -void event_unmap(enum event id, struct proc *proc, u32 *func) +void event_unregister(enum message_type id, struct proc *proc) { assert(id < sizeof(event_table) / sizeof(*event_table)); - assert(func); - - struct list *list = event_table[id]; struct event_descriptor *desc = malloc(sizeof(*desc)); desc->id = id; - desc->func = func; desc->proc = proc; - struct node *iterator = list->head; + struct node *iterator = event_table[id]->head; do { - if (memcmp(iterator->data, desc, sizeof(*desc)) == 0) - list_remove(list, iterator); + struct event_descriptor *desc_comp = iterator->data; + if (desc_comp->id == desc->id && desc_comp->proc == desc->proc) + list_remove(event_table[id], iterator); } while ((iterator = iterator->next) != NULL); } -u32 event_trigger(enum event id, void *data) +u32 event_trigger(enum message_type id, void *data) { - (void)data; assert(id < sizeof(event_table) / sizeof(*event_table)); - struct node *iterator = event_table[id]->head; - if (memcmp(event_table[id], 0, sizeof(struct list)) == 0 || !event_table[id]->head) { printf("Event %d not mapped!\n", id); return 1; } - while (1) { - struct proc_event *proc_event = malloc(sizeof(*proc_event)); - struct event_descriptor *desc = iterator->data; - proc_event->desc = desc; - proc_event->data = data; - list_add(desc->proc->events, proc_event); - iterator = iterator->next; - if (iterator == NULL) - break; - } + struct node *iterator = event_table[id]->head; + do { + proc_send(kernel_proc, ((struct event_descriptor *)iterator->data)->proc, id, data); + } while ((iterator = iterator->next) != NULL); return 0; } diff --git a/kernel/features/proc.c b/kernel/features/proc.c index d358faa..5b4da1f 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -14,6 +14,7 @@ u32 pid = 0; u32 quantum = 0; +struct proc *kernel_proc; struct list *proc_list; struct node *current; @@ -63,20 +64,6 @@ void scheduler(struct regs *regs) regs->eflags = EFLAGS_ALWAYS | EFLAGS_INTERRUPTS; } - struct proc *proc = current->data; - if (proc->state == PROC_DEFAULT && proc->events && proc->events->head) { - struct proc_event *proc_event = proc->events->head->data; - printf("Event %d for pid %d\n", proc_event->desc->id, proc->pid); - memcpy(&proc->regs_backup, regs, sizeof(struct regs)); - regs->eip = (u32)proc_event->desc->func; - - quantum = PROC_QUANTUM; - proc->state = PROC_IN_EVENT; - regs->useresp += 4; - ((u32 *)regs->useresp)[1] = (u32)proc_event->data; // Huh - list_remove(proc->events, proc->events->head); - } - /* printf("{%d}", ((struct proc *)current->data)->pid); */ } @@ -123,14 +110,6 @@ struct proc_message *proc_receive(struct proc *proc) } } -void proc_resolve(struct proc *proc) -{ - proc->state = PROC_RESOLVED; - quantum = 0; - sti(); - hlt(); -} - struct proc *proc_from_pid(u32 pid) { struct node *iterator = proc_list->head; @@ -170,7 +149,6 @@ struct proc *proc_make() { struct proc *proc = malloc(sizeof(*proc)); proc->pid = pid++; - proc->events = list_new(); proc->messages = list_new(); proc->state = PROC_DEFAULT; @@ -192,6 +170,8 @@ void proc_init() irq_install_handler(0, scheduler); proc_list = list_new(); + kernel_proc = proc_make(); + struct node *new = list_add(proc_list, proc_make()); bin_load("/init", new->data); diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index e876553..fb6adf1 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -79,19 +79,14 @@ void syscall_handler(struct regs *r) r->eax = timer_get(); break; } - case SYS_MAP: { - printf("map\n"); - event_map(r->ebx, proc_current(), (u32 *)r->ecx); + case SYS_REGISTER: { + printf("register\n"); + event_register(r->ebx, proc_current()); break; } - case SYS_UNMAP: { - printf("unmap\n"); - event_unmap(r->ebx, proc_current(), (u32 *)r->ecx); - break; - } - case SYS_RESOLVE: { - printf("resolve\n"); - proc_resolve(proc_current()); + case SYS_UNREGISTER: { + printf("unregister\n"); + event_unregister(r->ebx, proc_current()); break; } case SYS_SEND: { diff --git a/kernel/inc/event.h b/kernel/inc/event.h index 0a42f97..89c3e56 100644 --- a/kernel/inc/event.h +++ b/kernel/inc/event.h @@ -8,13 +8,12 @@ #include <sys.h> struct event_descriptor { - enum event id; - u32 *func; + enum message_type id; struct proc *proc; }; -u32 event_map(enum event id, struct proc *proc, u32 *func); -void event_unmap(enum event id, struct proc *proc, u32 *func); -u32 event_trigger(enum event id, void *data); +u32 event_register(enum message_type id, struct proc *proc); +void event_unregister(enum message_type id, struct proc *proc); +u32 event_trigger(enum message_type id, void *data); #endif diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h index 186c18e..36d8e85 100644 --- a/kernel/inc/proc.h +++ b/kernel/inc/proc.h @@ -25,27 +25,22 @@ struct proc { struct regs regs; struct regs regs_backup; enum proc_state state; - struct list *events; struct list *messages; }; -struct proc_event { - struct event_descriptor *desc; - void *data; -}; - struct proc_message { struct proc *src; struct proc *dest; struct message *msg; }; +struct proc *kernel_proc; + void proc_init(); void proc_print(); struct proc *proc_current(); void proc_send(struct proc *src, struct proc *dest, enum message_type type, void *data); struct proc_message *proc_receive(struct proc *proc); -void proc_resolve(struct proc *proc); struct proc *proc_from_pid(u32 pid); void proc_exit(struct proc *proc, int status); void proc_yield(); diff --git a/libc/inc/sys.h b/libc/inc/sys.h index 8bff39b..77a8069 100644 --- a/libc/inc/sys.h +++ b/libc/inc/sys.h @@ -14,14 +14,12 @@ enum sys { SYS_EXIT, // Exit current process SYS_YIELD, // Switch to next process SYS_TIME, // Get kernel time - SYS_MAP, // Map event to function - SYS_UNMAP, // Unmap event - SYS_RESOLVE, // Resolve event (needs to be executed at end of function) + SYS_REGISTER, // Register for event + SYS_UNREGISTER, // Unregister event SYS_SEND, // Send message to process SYS_RECEIVE // Receive message (non-blocking/sync) }; -enum event { EVENT_KEYBOARD, EVENT_MOUSE }; -enum message_type { MSG_NEW_WINDOW }; +enum message_type { MSG_NEW_WINDOW, EVENT_KEYBOARD, EVENT_MOUSE }; struct message { int src; @@ -56,9 +54,8 @@ int sysv(enum sys num, ...); #define yield() (int)sys0(SYS_YIELD) #define time() (int)sys0(SYS_TIME) -#define event_map(id, func) sys2(SYS_MAP, (int)(id), (int)(func)) -#define event_unmap(id, func) sys2(SYS_UNMAP, (int)(id), (int)(func)) -#define event_resolve() sys0(SYS_RESOLVE) // TODO: Find method making event_resolve obsolete +#define event_register(id) sys1(SYS_REGISTER, (int)(id)) +#define event_unregister(id) sys1(SYS_UNREGISTER, (int)(id)) #define msg_send(pid, type, msg) sys3(SYS_SEND, (int)(pid), (int)(type), (int)(msg)) #define msg_receive() (struct message *)sys0(SYS_RECEIVE) diff --git a/libgui/inc/gui.h b/libgui/inc/gui.h index ccd4bd9..700500e 100644 --- a/libgui/inc/gui.h +++ b/libgui/inc/gui.h @@ -37,6 +37,6 @@ void gui_init(char *font_path); */ #define gui_new_window() \ - (msg_send(1, MSG_NEW_WINDOW, NULL), (struct window *)msg_receive_loop()->data) + (msg_send(2, MSG_NEW_WINDOW, NULL), (struct window *)msg_receive_loop()->data) #endif |