diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/drivers/interrupts.asm | 3 | ||||
-rw-r--r-- | kernel/drivers/interrupts.c | 7 | ||||
-rw-r--r-- | kernel/drivers/keyboard.c | 2 | ||||
-rw-r--r-- | kernel/drivers/mouse.c | 2 | ||||
-rw-r--r-- | kernel/features/fs.c | 14 | ||||
-rw-r--r-- | kernel/features/proc.c | 294 | ||||
-rw-r--r-- | kernel/features/syscall.c | 11 | ||||
-rw-r--r-- | kernel/inc/fs.h | 4 | ||||
-rw-r--r-- | kernel/inc/proc.h | 34 | ||||
-rw-r--r-- | kernel/main.c | 2 |
10 files changed, 194 insertions, 179 deletions
diff --git a/kernel/drivers/interrupts.asm b/kernel/drivers/interrupts.asm index 59c323c..9f475fb 100644 --- a/kernel/drivers/interrupts.asm +++ b/kernel/drivers/interrupts.asm @@ -5,7 +5,6 @@ %macro IRQ 2 global irq%1 irq%1: - cli push byte 0 push byte %2 jmp irq_common_stub @@ -63,7 +62,6 @@ irq_common_stub: %macro ISR_NOERRCODE 1 global isr%1 isr%1: - cli push byte 0 push %1 jmp isr_common_stub @@ -72,7 +70,6 @@ irq_common_stub: %macro ISR_ERRCODE 1 global isr%1 isr%1: - cli push byte %1 jmp isr_common_stub %endmacro diff --git a/kernel/drivers/interrupts.c b/kernel/drivers/interrupts.c index 255f976..917733f 100644 --- a/kernel/drivers/interrupts.c +++ b/kernel/drivers/interrupts.c @@ -176,10 +176,9 @@ void isr_panic(struct regs *r) r->err_code, r->eip, r->cs & 3); struct proc *proc = proc_current(); if (proc) { - printf("\t-> Exception occurred in %s at addr 0x%x\n", proc->name, - r->eip - proc->entry); - proc_exit(proc, 1); - proc_yield(r); + printf("\t-> Exception occurred in %s at addr 0x%x (offset 0x%x)\n", proc->name, + r->eip, r->eip - proc->entry); + proc_exit(proc, r, 1); } else { __asm__ volatile("cli\nhlt"); } diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c index b123bcc..63005b9 100644 --- a/kernel/drivers/keyboard.c +++ b/kernel/drivers/keyboard.c @@ -45,7 +45,7 @@ static void keyboard_handler(struct regs *r) state = 0; merged = 0; - proc_enable_waiting(dev_id, PROC_WAIT_DEV); + proc_unblock(dev_id, PROC_BLOCK_DEV); } /*static void keyboard_acknowledge(void) diff --git a/kernel/drivers/mouse.c b/kernel/drivers/mouse.c index ad36cc4..db0d2fb 100644 --- a/kernel/drivers/mouse.c +++ b/kernel/drivers/mouse.c @@ -47,7 +47,7 @@ static void mouse_handler(struct regs *r) event->but3 = (mouse_byte[0] >> 2) & 1; stack_push_bot(queue, event); mouse_cycle = 0; - proc_enable_waiting(dev_id, PROC_WAIT_DEV); + proc_unblock(dev_id, PROC_BLOCK_DEV); break; default: break; diff --git a/kernel/features/fs.c b/kernel/features/fs.c index 753adb4..0ffe80f 100644 --- a/kernel/features/fs.c +++ b/kernel/features/fs.c @@ -233,7 +233,7 @@ res vfs_stat(const char *path, struct stat *buf) return m->dev->vfs->stat(path, buf, m->dev); } -res vfs_wait(const char *path, u32 func_ptr) +res vfs_block(const char *path, u32 func_ptr) { if (!func_ptr || !memory_valid(path)) return -EFAULT; @@ -242,9 +242,9 @@ res vfs_wait(const char *path, u32 func_ptr) if (!m || !m->dev || !m->dev->vfs) return -ENOENT; - // Default wait - if (!m->dev->vfs->wait) { - proc_wait_for(vfs_find_dev(path)->id, PROC_WAIT_DEV, func_ptr); + // Default block + if (!m->dev->vfs->block) { + proc_block(vfs_find_dev(path)->id, PROC_BLOCK_DEV, func_ptr); return EOK; } @@ -252,7 +252,7 @@ res vfs_wait(const char *path, u32 func_ptr) if (len > 1) path += len; - return m->dev->vfs->wait(path, func_ptr, m->dev); + return m->dev->vfs->block(path, func_ptr, m->dev); } res vfs_poll(const char **files) @@ -269,9 +269,9 @@ res vfs_poll(const char **files) } for (const char **p = files; *p && memory_valid(*p) && **p; p++) - vfs_wait(*p, (u32)vfs_poll); + vfs_block(*p, (u32)vfs_poll); - return PROC_MAX_WAIT_IDS + 1; + return PROC_MAX_BLOCK_IDS + 1; } res vfs_ready(const char *path) diff --git a/kernel/features/proc.c b/kernel/features/proc.c index fde49bd..a17a655 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -14,72 +14,58 @@ #include <str.h> #include <timer.h> -u32 current_pid = 0; -u32 quantum = 0; -struct proc *priority_proc = NULL; -struct list *proc_list = NULL; -struct node *idle_proc = NULL; -struct node *current = NULL; - -// TODO: Use less memcpy and only copy relevant registers (rewrite for efficiency argh) +#define PROC(node) ((struct proc *)node->data) + +static u8 locked = 0; +static u32 current_pid = 0; +static struct node *idle_proc = NULL; +static struct node *current = NULL; + +static struct list *proc_list_running = NULL; +static struct list *proc_list_blocked = NULL; +static struct list *proc_list_idle = NULL; + +// TODO: Use less memcpy and only copy relevant registers // TODO: 20 priority queues (https://www.kernel.org/doc/html/latest/scheduler/sched-nice-design.html) -// TODO: Optimize scheduler HOT FLATTEN void scheduler(struct regs *regs) { - if (quantum == 0) { - quantum = PROC_QUANTUM; + spinlock(&locked); + + PROC(current)->ticks++; + + if (PROC(current)->quantum.cnt >= PROC(current)->quantum.val) { + PROC(current)->quantum.cnt = 0; } else { - quantum--; + PROC(current)->quantum.cnt++; + locked = 0; return; } - assert(proc_list->head); - - if (current) - memcpy(&((struct proc *)current->data)->regs, regs, sizeof(struct regs)); + memcpy(&PROC(current)->regs, regs, sizeof(*regs)); - if (priority_proc && priority_proc->state == PROC_RUNNING) { - current = list_first_data(proc_list, priority_proc); - priority_proc = NULL; - assert(current); - } else if (current && current->next && - ((struct proc *)current->next->data)->state == PROC_RUNNING) { + if (current->next) { current = current->next; - } else if (((struct proc *)proc_list->head->data)->state == PROC_RUNNING) { - current = proc_list->head; + } else if (proc_list_running->head) { + current = proc_list_running->head; } else { current = idle_proc; - struct node *iterator = proc_list->head; - while (iterator) { - if (((struct proc *)iterator->data)->state == PROC_RUNNING) { - current = iterator; - break; - } - iterator = iterator->next; - } } - struct proc *p = current->data; - memory_switch_dir(p->page_dir); - memcpy(regs, &p->regs, sizeof(*regs)); - - if (current == idle_proc) - quantum = 0; + memory_switch_dir(PROC(current)->page_dir); + memcpy(regs, &PROC(current)->regs, sizeof(*regs)); - /* printf("{%d}", ((struct proc *)current->data)->pid); */ + locked = 0; } void proc_print(void) { - struct node *node = proc_list->head; + struct node *node = proc_list_running->head; + struct proc *proc = NULL; printf("--- PROCESSES ---\n"); - struct proc *proc = NULL; while (node && (proc = node->data)) { - printf("Process %d: %s [%s] [entry: %x; stack: %x]\n", proc->pid, proc->name, - proc->state == PROC_RUNNING ? "RUNNING" : "SLEEPING", - virtual_to_physical(proc->page_dir, proc->entry), - virtual_to_physical(proc->page_dir, proc->regs.ebp)); + printf("Process %d: %s [%s]\n", proc->pid, proc->name, + proc->state == PROC_RUNNING ? "RUNNING" : "SLEEPING"); node = node->next; } printf("\n"); @@ -103,37 +89,60 @@ u8 proc_super(void) struct proc *proc_from_pid(u32 pid) { - struct node *iterator = proc_list->head; - while (iterator != NULL) { + struct node *iterator = NULL; + + iterator = proc_list_blocked->head; + while (iterator) { if (((struct proc *)iterator->data)->pid == pid) return iterator->data; iterator = iterator->next; } + + iterator = proc_list_running->head; + while (iterator) { + if (((struct proc *)iterator->data)->pid == pid) + return iterator->data; + iterator = iterator->next; + } + return NULL; } -void proc_clear_quantum(void) +void proc_set_quantum(struct proc *proc, u32 value) { - quantum = 0; + proc->quantum.val = value; } -void proc_exit(struct proc *proc, s32 status) +void proc_reset_quantum(struct proc *proc) { - u8 found = 0; - struct node *iterator = proc_list->head; - while (iterator) { - if (iterator->data == proc) { - found = 1; - list_remove(proc_list, iterator); - break; - } - iterator = iterator->next; + proc->quantum.cnt = proc->quantum.val; +} + +void proc_state(struct proc *proc, enum proc_state state) +{ + if (state == PROC_RUNNING && !list_first_data(proc_list_running, proc)) { + assert(list_remove(proc_list_blocked, list_first_data(proc_list_blocked, proc))); + assert(list_add(proc_list_running, proc)); + } else if (state == PROC_BLOCKED && !list_first_data(proc_list_blocked, proc)) { + assert(list_remove(proc_list_running, list_first_data(proc_list_running, proc))); + assert(list_add(proc_list_blocked, proc)); } + // else: Nothing to do! +} - assert(found); +void proc_exit(struct proc *proc, struct regs *r, s32 status) +{ + struct node *running = list_first_data(proc_list_running, proc); + if (!running || !list_remove(proc_list_running, running)) { + struct node *blocked = list_first_data(proc_list_blocked, proc); + assert(blocked && list_remove(proc_list_blocked, blocked)); + // Idle procs can't be killed -> assertion failure. + } - if (memcmp(proc, current->data, sizeof(*proc)) == 0) - current = NULL; + if (current->data == proc) { + current = idle_proc; + memcpy(r, &PROC(idle_proc)->regs, sizeof(*r)); + } printf("Process %s (%d) exited with status %d (%s)\n", proc->name[0] ? proc->name : "UNKNOWN", proc->pid, status, @@ -145,40 +154,77 @@ void proc_exit(struct proc *proc, s32 status) free(proc); - proc_clear_quantum(); // TODO: Add quantum to each process struct? - - // The caller has to yield itself + if (current->data == proc) + proc_yield(r); } void proc_yield(struct regs *r) { - proc_clear_quantum(); + proc_reset_quantum(PROC(current)); scheduler(r); } -void proc_enable_waiting(u32 id, enum proc_wait_type type) +void proc_block(u32 id, enum proc_block_type type, u32 func_ptr) +{ + u8 already_exists = 0; + struct proc *p = proc_current(); + + // Check if already exists + for (u32 i = 0; i < p->block.id_cnt; i++) { + if (p->block.ids[i].id == id && p->block.ids[i].type == type) { + assert(p->block.ids[i].func_ptr == func_ptr); + already_exists = 1; + } + } + + if (already_exists) + goto end; + + assert(p->block.id_cnt + 1 < PROC_MAX_BLOCK_IDS); + + // Find slot + struct proc_block_identifier *slot = NULL; + for (u32 i = 0; i < PROC_MAX_BLOCK_IDS; i++) { + if (p->block.ids[i].magic != PROC_BLOCK_MAGIC) { + slot = &p->block.ids[i]; + break; + } + } + assert(slot); + + slot->magic = PROC_BLOCK_MAGIC; + slot->id = id; + slot->type = type; + slot->func_ptr = func_ptr; + p->block.id_cnt++; + +end: + proc_state(p, PROC_BLOCKED); +} + +void proc_unblock(u32 id, enum proc_block_type type) { struct page_dir *dir_bak; memory_backup_dir(&dir_bak); - struct proc *proc_bak = proc_current(); + struct node *proc_bak = current; if (!proc_bak) return; - struct node *iterator = proc_list->head; + struct node *iterator = proc_list_blocked->head; while (iterator) { struct proc *p = iterator->data; - struct proc_wait *w = &p->wait; + struct proc_block *w = &p->block; if (!p || !w || w->id_cnt == 0) { iterator = iterator->next; continue; } - current = list_first_data(proc_list, p); - assert(w->id_cnt < PROC_MAX_WAIT_IDS); + current = list_first_data(proc_list_blocked, p); + assert(w->id_cnt < PROC_MAX_BLOCK_IDS); for (u32 i = 0; i < w->id_cnt; i++) { - if (w->ids[i].magic == PROC_WAIT_MAGIC && w->ids[i].id == id && + if (w->ids[i].magic == PROC_BLOCK_MAGIC && w->ids[i].id == id && w->ids[i].type == type) { struct regs *r = &p->regs; u32 (*func)(u32, u32, u32, u32) = @@ -189,8 +235,8 @@ void proc_enable_waiting(u32 id, enum proc_wait_type type) memory_switch_dir(dir_bak); } memset(&w->ids[i], 0, sizeof(w->ids[i])); - p->wait.id_cnt--; - p->state = PROC_RUNNING; + p->block.id_cnt--; + proc_state(p, PROC_RUNNING); break; } } @@ -198,46 +244,8 @@ void proc_enable_waiting(u32 id, enum proc_wait_type type) iterator = iterator->next; } - if (current->data != proc_bak) - current = list_first_data(proc_list, proc_bak); -} - -void proc_wait_for(u32 id, enum proc_wait_type type, u32 func_ptr) -{ - u8 already_exists = 0; - struct proc *p = proc_current(); - - // Check if already exists - for (u32 i = 0; i < p->wait.id_cnt; i++) { - if (p->wait.ids[i].id == id && p->wait.ids[i].type == type) { - assert(p->wait.ids[i].func_ptr == func_ptr); - already_exists = 1; - } - } - - if (already_exists) - goto end; - - assert(p->wait.id_cnt + 1 < PROC_MAX_WAIT_IDS); - - // Find slot - struct proc_wait_identifier *slot = NULL; - for (u32 i = 0; i < PROC_MAX_WAIT_IDS; i++) { - if (p->wait.ids[i].magic != PROC_WAIT_MAGIC) { - slot = &p->wait.ids[i]; - break; - } - } - assert(slot != NULL); - - slot->magic = PROC_WAIT_MAGIC; - slot->id = id; - slot->type = type; - slot->func_ptr = func_ptr; - p->wait.id_cnt++; - -end: - p->state = PROC_SLEEPING; + if (current != proc_bak) + current = proc_bak; } struct proc *proc_make(enum proc_priv priv) @@ -249,6 +257,8 @@ struct proc *proc_make(enum proc_priv priv) proc->memory = list_new(); proc->state = PROC_RUNNING; proc->page_dir = virtual_create_dir(); + proc->quantum.val = PROC_QUANTUM; + proc->quantum.cnt = 0; // Init regs u8 is_kernel = priv == PROC_PRIV_KERNEL; @@ -262,8 +272,7 @@ struct proc *proc_make(enum proc_priv priv) proc->regs.cs = code; proc->regs.eflags = EFLAGS_ALWAYS | EFLAGS_INTERRUPTS; - if (current) - list_add(proc_list, proc); + list_add(proc_list_running, proc); return proc; } @@ -339,7 +348,7 @@ static res procfs_write(const char *path, void *buf, u32 offset, u32 count, stru msg->data = msg_data; msg->size = count; stack_push_bot(p->messages, msg); // TODO: Use offset - proc_enable_waiting(pid, PROC_WAIT_MSG); + proc_unblock(pid, PROC_BLOCK_MSG); return count; } else if (!memcmp(path, "io/", 3)) { path += 3; @@ -355,7 +364,7 @@ static res procfs_write(const char *path, void *buf, u32 offset, u32 count, stru assert(stream->offset_write + count < STREAM_MAX_SIZE); // TODO: Resize memcpy((char *)(stream->data + stream->offset_write), buf, count); stream->offset_write += count; - proc_enable_waiting(dev->id, PROC_WAIT_DEV); + proc_unblock(dev->id, PROC_BLOCK_DEV); return count; } } @@ -414,7 +423,7 @@ static res procfs_read(const char *path, void *buf, u32 offset, u32 count, struc return -ENOENT; } -static res procfs_wait(const char *path, u32 func_ptr, struct device *dev) +static res procfs_block(const char *path, u32 func_ptr, struct device *dev) { u32 pid = 0; procfs_parse_path(&path, &pid); @@ -426,10 +435,10 @@ static res procfs_wait(const char *path, u32 func_ptr, struct device *dev) path++; if (!memcmp(path, "msg", 4)) { - proc_wait_for(pid, PROC_WAIT_MSG, func_ptr); + proc_block(pid, PROC_BLOCK_MSG, func_ptr); return EOK; } else { - proc_wait_for(dev->id, PROC_WAIT_DEV, func_ptr); + proc_block(dev->id, PROC_BLOCK_DEV, func_ptr); return EOK; } } @@ -479,21 +488,23 @@ static res procfs_ready(const char *path, struct device *dev) extern void proc_jump_userspace(void); u32 _esp, _eip; -void proc_init(void) +NORETURN void proc_init(void) { - if (proc_list) - return; + if (proc_list_running) + panic("Already initialized processes!"); cli(); scheduler_enable(); - proc_list = list_new(); + proc_list_running = list_new(); + proc_list_blocked = list_new(); + proc_list_idle = list_new(); // Procfs struct vfs *vfs = zalloc(sizeof(*vfs)); vfs->type = VFS_PROCFS; vfs->read = procfs_read; vfs->write = procfs_write; - vfs->wait = procfs_wait; + vfs->block = procfs_block; vfs->perm = procfs_perm; vfs->ready = procfs_ready; vfs->data = NULL; @@ -502,29 +513,32 @@ void proc_init(void) dev->type = DEV_CHAR; dev->vfs = vfs; device_add(dev); - assert(vfs_mount(dev, "/proc/") == 0); + assert(vfs_mount(dev, "/proc/") == EOK); // Idle proc struct proc *kernel_proc = proc_make(PROC_PRIV_KERNEL); - assert(elf_load("/bin/idle", kernel_proc) == 0); - kernel_proc->state = PROC_SLEEPING; - idle_proc = list_add(proc_list, kernel_proc); + assert(elf_load("/bin/idle", kernel_proc) == EOK); + kernel_proc->state = PROC_BLOCKED; + kernel_proc->quantum.val = 0; + kernel_proc->quantum.cnt = 0; + idle_proc = list_add(proc_list_idle, kernel_proc); + list_remove(proc_list_running, list_first_data(proc_list_running, kernel_proc)); // Init proc (root) - struct node *new = list_add(proc_list, proc_make(PROC_PRIV_ROOT)); - assert(elf_load("/bin/init", new->data) == 0); - current = new; - proc_stack_push(new->data, 0); + struct proc *init = proc_make(PROC_PRIV_ROOT); + assert(elf_load("/bin/init", init) == EOK); + proc_stack_push(init, 0); + current = list_first_data(proc_list_running, init); - _eip = ((struct proc *)new->data)->regs.eip; - _esp = ((struct proc *)new->data)->regs.useresp; + _eip = init->regs.eip; + _esp = init->regs.useresp; - memory_switch_dir(((struct proc *)new->data)->page_dir); + memory_switch_dir(init->page_dir); printf("Jumping to userspace!\n"); + // You're waiting for a train. A train that will take you far away... proc_jump_userspace(); - while (1) { - }; + panic("Returned from limbo!\n"); } diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index 44caff8..ab14539 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -50,7 +50,7 @@ static 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 { - res wait = vfs_wait((char *)r->ebx, (u32)vfs_read); + res wait = vfs_block((char *)r->ebx, (u32)vfs_read); if (wait != 0) r->eax = wait; else @@ -70,7 +70,7 @@ static void syscall_handler(struct regs *r) case SYS_POLL: { res ret = vfs_poll((const char **)r->ebx); r->eax = ret; - if (ret == PROC_MAX_WAIT_IDS + 1) + if (ret == PROC_MAX_BLOCK_IDS + 1) proc_yield(r); break; } @@ -78,8 +78,8 @@ static void syscall_handler(struct regs *r) char *path = (char *)r->ebx; struct proc *proc = proc_make(PROC_PRIV_NONE); r->eax = (u32)elf_load(path, proc); - if (r->eax != 0) { - proc_exit(proc, -r->eax); + if (r->eax != EOK) { + proc_exit(proc, r, -r->eax); } else { // TODO: Reimplement argc,argv proc_stack_push(proc, 0); @@ -88,8 +88,7 @@ static void syscall_handler(struct regs *r) break; } case SYS_EXIT: { - proc_exit(proc_current(), (s32)r->ebx); - proc_yield(r); + proc_exit(proc_current(), r, (s32)r->ebx); break; } case SYS_BOOT: { // TODO: Move diff --git a/kernel/inc/fs.h b/kernel/inc/fs.h index b6c30a2..1a78072 100644 --- a/kernel/inc/fs.h +++ b/kernel/inc/fs.h @@ -47,7 +47,7 @@ struct vfs { res (*ioctl)(const char *path, u32 request, void *arg1, void *arg2, void *arg3, struct device *dev) ATTR((nonnull(1, 6))); res (*stat)(const char *path, struct stat *buf, struct device *dev) NONNULL; - res (*wait)(const char *path, u32 func_ptr, struct device *dev) NONNULL; + res (*block)(const char *path, u32 func_ptr, struct device *dev) NONNULL; res (*ready)(const char *path, struct device *dev) NONNULL; res (*perm)(const char *path, enum vfs_perm perm, struct device *dev) NONNULL; }; @@ -68,7 +68,7 @@ res vfs_read(const char *path, void *buf, u32 offset, u32 count) NONNULL; res vfs_write(const char *path, void *buf, u32 offset, u32 count) NONNULL; res vfs_ioctl(const char *path, u32 request, void *arg1, void *arg2, void *arg3) ATTR((nonnull(1))); res vfs_stat(const char *path, struct stat *buf) NONNULL; -res vfs_wait(const char *path, u32 func_ptr) NONNULL; +res vfs_block(const char *path, u32 func_ptr) NONNULL; res vfs_poll(const char **files) NONNULL; res vfs_ready(const char *path) NONNULL; diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h index 8a68131..c9dadaa 100644 --- a/kernel/inc/proc.h +++ b/kernel/inc/proc.h @@ -19,25 +19,25 @@ #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) -#define PROC_MAX_WAIT_IDS 16 -#define PROC_WAIT_MAGIC 0x00528491 +#define PROC_MAX_BLOCK_IDS 16 +#define PROC_BLOCK_MAGIC 0x00528491 #define STREAM_MAX_SIZE 4096 enum stream_defaults { STREAM_IN, STREAM_OUT, STREAM_ERR, STREAM_LOG, STREAM_UNKNOWN = -1 }; enum proc_priv { PROC_PRIV_NONE, PROC_PRIV_ROOT, PROC_PRIV_KERNEL }; -enum proc_state { PROC_RUNNING, PROC_SLEEPING }; -enum proc_wait_type { PROC_WAIT_DEV, PROC_WAIT_MSG }; +enum proc_state { PROC_RUNNING, PROC_BLOCKED }; +enum proc_block_type { PROC_BLOCK_DEV, PROC_BLOCK_MSG }; -struct proc_wait_identifier { +struct proc_block_identifier { u32 magic; u32 id; - enum proc_wait_type type; + enum proc_block_type type; u32 func_ptr; }; -struct proc_wait { - struct proc_wait_identifier ids[PROC_MAX_WAIT_IDS]; +struct proc_block { + struct proc_block_identifier ids[PROC_MAX_BLOCK_IDS]; u32 id_cnt; }; @@ -54,11 +54,17 @@ struct proc { struct stream streams[4]; struct page_dir *page_dir; struct regs regs; - struct proc_wait wait; // dev_id + struct proc_block block; // dev_id enum proc_priv priv; enum proc_state state; struct stack *messages; struct list *memory; + + u32 ticks; + struct { + u8 val; + u8 cnt; + } quantum; }; void scheduler(struct regs *regs) NONNULL; @@ -67,11 +73,13 @@ void proc_print(void); struct proc *proc_current(void); u8 proc_super(void); struct proc *proc_from_pid(u32 pid); -void proc_exit(struct proc *proc, s32 status) NONNULL; +void proc_exit(struct proc *proc, struct regs *r, s32 status) NONNULL; void proc_yield(struct regs *r) NONNULL; -void proc_clear_quantum(void); -void proc_enable_waiting(u32 id, enum proc_wait_type type); -void proc_wait_for(u32 id, enum proc_wait_type type, u32 func_ptr); +void proc_set_quantum(struct proc *proc, u32 value); +void proc_reset_quantum(struct proc *proc); +void proc_state(struct proc *proc, enum proc_state state); +void proc_block(u32 id, enum proc_block_type type, u32 func_ptr); +void proc_unblock(u32 id, enum proc_block_type type); struct proc *proc_make(enum proc_priv priv); void proc_stack_push(struct proc *proc, u32 data) NONNULL; diff --git a/kernel/main.c b/kernel/main.c index 3ff0463..e28915b 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -52,6 +52,4 @@ void kernel_main(struct mem_info *mem_info, struct vid_info *vid_info) syscall_init(); proc_init(); - - idle(); } |