aboutsummaryrefslogtreecommitdiff
path: root/kernel/features
diff options
context:
space:
mode:
authorMarvin Borner2020-08-24 12:21:23 +0200
committerMarvin Borner2020-08-24 12:21:23 +0200
commit0a4c8dd2d6048fe9851b8d92a311bba7aaa83a57 (patch)
tree5e1e235f4ff22b3233f43db768ddd373f6063856 /kernel/features
parent0e05b395cb8868b77d91d9d614ff5ae09b3b853a (diff)
Removed async events
Diffstat (limited to 'kernel/features')
-rw-r--r--kernel/features/event.c41
-rw-r--r--kernel/features/proc.c26
-rw-r--r--kernel/features/syscall.c17
3 files changed, 20 insertions, 64 deletions
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: {