aboutsummaryrefslogtreecommitdiff
path: root/kernel/features
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/features')
-rw-r--r--kernel/features/event.c17
-rw-r--r--kernel/features/proc.c22
2 files changed, 25 insertions, 14 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);