diff options
author | Marvin Borner | 2021-01-15 16:34:19 +0100 |
---|---|---|
committer | Marvin Borner | 2021-01-15 16:34:19 +0100 |
commit | 41cba1de51b328979ff2d0261b4141bb4e128fe6 (patch) | |
tree | 88ea7bda9e7a675ed0e043ea8662ea9cf3767ce3 | |
parent | d3924f541f36bc08fed87f25ec7fc6e64b86e511 (diff) |
Implemented basic dev ready-state waiting
-rw-r--r-- | kernel/drivers/keyboard.c | 5 | ||||
-rw-r--r-- | kernel/features/proc.c | 17 | ||||
-rw-r--r-- | kernel/features/syscall.c | 7 | ||||
-rw-r--r-- | kernel/inc/fs.h | 2 | ||||
-rw-r--r-- | kernel/inc/proc.h | 2 |
5 files changed, 29 insertions, 4 deletions
diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c index 6936c22..7e295c2 100644 --- a/kernel/drivers/keyboard.c +++ b/kernel/drivers/keyboard.c @@ -13,6 +13,7 @@ static struct event_keyboard *event = NULL; static struct stack *queue = NULL; +static u32 dev_id = 0; static int state = 0; static int merged = 0; @@ -43,8 +44,7 @@ void keyboard_handler() state = 0; merged = 0; - // TODO: Only enable waiting procs - proc_current()->state = PROC_RUNNING; + proc_enable_waiting(dev_id); } void keyboard_acknowledge(void) @@ -88,4 +88,5 @@ void keyboard_install(void) dev->read = keyboard_read; dev->ready = keyboard_ready; device_add(dev); + dev_id = dev->id; } diff --git a/kernel/features/proc.c b/kernel/features/proc.c index f792824..af6a307 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -105,7 +105,7 @@ void proc_exit(struct proc *proc, int status) int res = 0; struct node *iterator = proc_list->head; - while (iterator != NULL) { + while (iterator) { if (iterator->data == proc) { res = 1; list_remove(proc_list, iterator); @@ -131,6 +131,21 @@ void proc_yield(struct regs *r) scheduler(r); } +void proc_enable_waiting(u32 dev_id) +{ + printf("ENABLING %d\n", dev_id); + struct node *iterator = proc_list->head; + while (iterator) { + struct proc *p = iterator->data; + printf("\t-> %s: %d\n", p->name, p->waits_for); + if (p && p->waits_for && p->waits_for == dev_id) { + //printf("WAKING %s\n", p->name); + p->state = PROC_RUNNING; + } + iterator = iterator->next; + } +} + struct proc *proc_make(void) { struct proc *proc = malloc(sizeof(*proc)); diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index c5570c3..59965a5 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -40,8 +40,13 @@ void syscall_handler(struct regs *r) if (vfs_ready((char *)r->ebx)) { r->eax = (u32)vfs_read((char *)r->ebx, (void *)r->ecx, r->edx, r->esi); } else { - proc_current()->state = PROC_SLEEPING; + struct proc *p = proc_current(); + p->state = PROC_SLEEPING; + p->waits_for = vfs_find_dev((char *)r->ebx)->id; scheduler(r); + sti(); + while (1) + hlt(); } break; } diff --git a/kernel/inc/fs.h b/kernel/inc/fs.h index 1b2b073..e5c444c 100644 --- a/kernel/inc/fs.h +++ b/kernel/inc/fs.h @@ -52,6 +52,8 @@ void vfs_install(void); u32 vfs_mounted(struct device *dev, const char *path); u32 vfs_mount(struct device *dev, const char *path); +struct device *vfs_find_dev(const char *path); + u32 vfs_read(const char *path, void *buf, u32 offset, u32 count); u32 vfs_write(const char *path, void *buf, u32 offset, u32 count); u32 vfs_stat(const char *path, struct stat *buf); diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h index c198b19..75978e9 100644 --- a/kernel/inc/proc.h +++ b/kernel/inc/proc.h @@ -25,6 +25,7 @@ struct proc { struct regs regs; struct regs regs_backup; enum proc_state state; + u32 waits_for; // dev_id struct stack *messages; }; @@ -35,6 +36,7 @@ struct proc *proc_current(void); struct proc *proc_from_pid(u32 pid); void proc_exit(struct proc *proc, int status); void proc_yield(struct regs *r); +void proc_enable_waiting(u32 dev_id); struct proc *proc_make(void); #endif |