diff options
author | Marvin Borner | 2020-08-22 13:20:40 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-22 13:20:40 +0200 |
commit | 00a64ff4675b4c1e22d6b4856e1f6b7c04ed96d8 (patch) | |
tree | e4f2e6df5750fc6b7334c35ee3d8554cd4b303ce /kernel | |
parent | 593c80e99342df5e1147b3c0fc893f77ec6f00d5 (diff) |
Added proc event list
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/features/event.c | 17 | ||||
-rw-r--r-- | kernel/features/proc.c | 22 | ||||
-rw-r--r-- | kernel/inc/event.h | 3 | ||||
-rw-r--r-- | kernel/inc/proc.h | 9 |
4 files changed, 35 insertions, 16 deletions
diff --git a/kernel/features/event.c b/kernel/features/event.c index 9bcce6d..e0a7d93 100644 --- a/kernel/features/event.c +++ b/kernel/features/event.c @@ -24,10 +24,11 @@ u32 event_map(enum event id, struct proc *proc, u32 *func) } while ((iterator = iterator->next) != NULL); struct event_descriptor *desc = malloc(sizeof(*desc)); + desc->id = id; desc->func = func; desc->proc = proc; - list_add((struct list *)event_table[id], (void *)desc); + list_add(event_table[id], (void *)desc); return 0; } @@ -36,9 +37,10 @@ void event_unmap(enum event id, struct proc *proc, u32 *func) assert(id < sizeof(event_table) / sizeof(*event_table)); assert(func); - struct list *list = ((struct list *)event_table[id]); + struct list *list = event_table[id]; struct event_descriptor *desc = malloc(sizeof(*desc)); + desc->id = id; desc->func = func; desc->proc = proc; @@ -49,21 +51,24 @@ void event_unmap(enum event id, struct proc *proc, u32 *func) } while ((iterator = iterator->next) != NULL); } -u32 event_trigger(enum event id, u32 *data) +u32 event_trigger(enum event id, void *data) { (void)data; assert(id < sizeof(event_table) / sizeof(*event_table)); - struct node *iterator = ((struct list *)event_table[id])->head; + struct node *iterator = event_table[id]->head; - if (memcmp(event_table[id], 0, sizeof(struct list)) == 0) { + 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; - desc->proc->event = 1 << id; + proc_event->desc = desc; + proc_event->data = data; + list_add(desc->proc->events, proc_event); iterator = iterator->next; if (iterator == NULL) break; diff --git a/kernel/features/proc.c b/kernel/features/proc.c index 86e444b..c38c196 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -47,14 +47,6 @@ void scheduler(struct regs *regs) memcpy(regs, &((struct proc *)current->data)->regs, sizeof(struct regs)); - if (((struct proc *)current->data)->event) { - struct proc *proc = (struct proc *)current->data; - // TODO: Modify and backup EIP - printf("Event %d for pid %d\n", proc->event, proc->pid); - // TODO: Clear bit after resolve - proc->event = 0; - } - if (regs->cs != GDT_USER_CODE_OFFSET) { regs->gs = GDT_USER_DATA_OFFSET; regs->fs = GDT_USER_DATA_OFFSET; @@ -64,6 +56,18 @@ void scheduler(struct regs *regs) regs->cs = GDT_USER_CODE_OFFSET; regs->eflags = EFLAGS_ALWAYS | EFLAGS_INTERRUPTS; } + + struct proc *proc = (struct proc *)current->data; + if (!proc->events || !proc->events->head) + return; + + struct node *iterator = proc->events->head; + do { + struct proc_event *proc_event = iterator->data; + printf("Event %d for pid %d\n", proc_event->desc->id, proc->pid); + list_remove(proc->events, iterator); + } while ((iterator = iterator->next) != NULL); + /* printf("{%d}", ((struct proc *)current->data)->pid); */ } @@ -101,6 +105,7 @@ void proc_exit(struct proc *proc, int status) } } while ((iterator = iterator->next) != NULL); + quantum = 0; // TODO: Add quantum to each process struct? sti(); hlt(); } @@ -109,6 +114,7 @@ struct proc *proc_make() { struct proc *proc = malloc(sizeof(*proc)); proc->pid = pid++; + proc->events = list_new(); if (current) list_add(proc_list, proc); diff --git a/kernel/inc/event.h b/kernel/inc/event.h index d14fdb0..0a42f97 100644 --- a/kernel/inc/event.h +++ b/kernel/inc/event.h @@ -8,12 +8,13 @@ #include <sys.h> struct event_descriptor { + enum event id; u32 *func; 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, u32 *data); +u32 event_trigger(enum event id, void *data); #endif diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h index 8f93e43..7e13652 100644 --- a/kernel/inc/proc.h +++ b/kernel/inc/proc.h @@ -4,7 +4,9 @@ #define PROC_H #include <def.h> +#include <event.h> #include <interrupts.h> +#include <list.h> #define PROC_QUANTUM 42 // Milliseconds @@ -18,7 +20,12 @@ struct proc { u32 pid; char name[32]; struct regs regs; - u32 event; + struct list *events; +}; + +struct proc_event { + struct event_descriptor *desc; + void *data; }; void proc_init(); |