diff options
author | Marvin Borner | 2020-08-22 15:08:57 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-22 15:08:57 +0200 |
commit | d748a6f54ce7af45afde487936d5a02cb2a91b05 (patch) | |
tree | 1ec6b0c8b3576fa15f21a305dfcad5196aac6e01 /kernel | |
parent | 00a64ff4675b4c1e22d6b4856e1f6b7c04ed96d8 (diff) |
Added event resolving
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/drivers/keyboard.c | 5 | ||||
-rw-r--r-- | kernel/features/proc.c | 38 | ||||
-rw-r--r-- | kernel/features/syscall.c | 5 | ||||
-rw-r--r-- | kernel/inc/proc.h | 5 |
4 files changed, 39 insertions, 14 deletions
diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c index b08278d..b60e437 100644 --- a/kernel/drivers/keyboard.c +++ b/kernel/drivers/keyboard.c @@ -24,12 +24,11 @@ void keyboard_handler() } // TODO: "Merge" scancode to linux keycode? - printf("%x %x = %x\n", scancode, state ? 0xe0 : 0, merged); + /* printf("%x %x = %x\n", scancode, state ? 0xe0 : 0, merged); */ if ((scancode & 0x80) == 0) { // PRESS event_trigger(EVENT_KEYBOARD, (u32 *)scancode); - } else - print("\n"); + } state = 0; merged = 0; diff --git a/kernel/features/proc.c b/kernel/features/proc.c index c38c196..b968032 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -26,6 +26,11 @@ void scheduler(struct regs *regs) return; } + if (current && ((struct proc *)current->data)->state == PROC_RESOLVED) { + memcpy(regs, &((struct proc *)current->data)->regs_backup, sizeof(struct regs)); + ((struct proc *)current->data)->state = PROC_DEFAULT; + } + if (current) memcpy(&((struct proc *)current->data)->regs, regs, sizeof(struct regs)); @@ -57,16 +62,18 @@ void scheduler(struct regs *regs) 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; + 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); - list_remove(proc->events, iterator); - } while ((iterator = iterator->next) != NULL); + memcpy(&proc->regs_backup, regs, sizeof(struct regs)); + regs->eip = (u32)proc_event->desc->func; + + quantum = PROC_QUANTUM; + proc->state = PROC_IN_EVENT; + list_remove(proc->events, proc->events->head); + ((u32 *)regs->useresp)[1] = (u32)proc_event->data; // Huh + } /* printf("{%d}", ((struct proc *)current->data)->pid); */ } @@ -77,7 +84,7 @@ void proc_print() printf("\nPROCESSES\n"); struct proc *proc; - while (node && (proc = ((struct proc *)node->data))) { + while (node && (proc = node->data)) { printf("Process %d: %s\n", proc->pid, proc->name); node = node->next; } @@ -87,11 +94,19 @@ void proc_print() struct proc *proc_current() { if (current) - return (struct proc *)current->data; + return current->data; else return NULL; } +void proc_resolve(struct proc *proc) +{ + proc->state = PROC_RESOLVED; + quantum = 0; + sti(); + hlt(); +} + void proc_exit(struct proc *proc, int status) { assert(proc); @@ -115,6 +130,7 @@ struct proc *proc_make() struct proc *proc = malloc(sizeof(*proc)); proc->pid = pid++; proc->events = list_new(); + proc->state = PROC_DEFAULT; if (current) list_add(proc_list, proc); diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index e96cb65..157f10c 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -76,6 +76,11 @@ void syscall_handler(struct regs *r) event_unmap(r->ebx, proc_current(), (u32 *)r->ecx); break; } + case SYS_RESOLVE: { + printf("resolve\n"); + proc_resolve(proc_current()); + break; + } default: { printf("unknown\n"); loop(); diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h index 7e13652..48bd7d7 100644 --- a/kernel/inc/proc.h +++ b/kernel/inc/proc.h @@ -16,10 +16,14 @@ #define GDT_USER_CODE_OFFSET 0x1b // User code segment offset in GDT (with ring3 mask) #define GDT_USER_DATA_OFFSET 0x23 // User data segment offset in GDT (with ring3 mask) +enum proc_state { PROC_DEFAULT, PROC_IN_EVENT, PROC_RESOLVED }; + struct proc { u32 pid; char name[32]; struct regs regs; + struct regs regs_backup; + enum proc_state state; struct list *events; }; @@ -31,6 +35,7 @@ struct proc_event { void proc_init(); void proc_print(); struct proc *proc_current(); +void proc_resolve(struct proc *proc); void proc_exit(struct proc *proc, int status); struct proc *proc_make(); |