diff options
author | Marvin Borner | 2021-01-14 00:18:44 +0100 |
---|---|---|
committer | Marvin Borner | 2021-01-14 00:18:44 +0100 |
commit | 388b3fa1bd8af8c5df6aef8447ffd2a8b2cb9300 (patch) | |
tree | 2effeb407e96f4e43dc5332346c6f9d378f9b8ef /kernel | |
parent | 91abed9333241731d0cd877beba4e2d4675989c8 (diff) |
Added kernel idle process
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/features/load.c | 24 | ||||
-rw-r--r-- | kernel/features/proc.c | 22 | ||||
-rw-r--r-- | kernel/inc/load.h | 55 | ||||
-rw-r--r-- | kernel/inc/proc.h | 2 |
4 files changed, 29 insertions, 74 deletions
diff --git a/kernel/features/load.c b/kernel/features/load.c index f7fc1a5..743c009 100644 --- a/kernel/features/load.c +++ b/kernel/features/load.c @@ -1,28 +1,30 @@ // MIT License, Copyright (c) 2020 Marvin Borner -#include <assert.h> -#include <cpu.h> -#include <def.h> #include <fs.h> #include <load.h> #include <mem.h> -#include <proc.h> #include <str.h> +void proc_load(struct proc *proc, void *data) +{ + u32 stack = (u32)malloc(0x2000) + 0x1000; + + proc->regs.ebp = (u32)stack; + proc->regs.useresp = (u32)stack; + proc->regs.eip = (u32)data; +} + int bin_load(char *path, struct proc *proc) { // TODO: Remove hardcoded filesize struct stat s = { 0 }; vfs_stat(path, &s); char *data = malloc(s.size); - vfs_read(path, data, 0, s.size); - - u32 stack = (u32)malloc(0x2000) + 0x1000; + if (!vfs_read(path, data, 0, s.size)) + return 0; - proc->regs.ebp = (u32)stack; - proc->regs.useresp = (u32)stack; - proc->regs.eip = (u32)data; strcpy(proc->name, path); + proc_load(proc, data); - return data ? 0 : 1; + return 1; } diff --git a/kernel/features/proc.c b/kernel/features/proc.c index 8fbb4c5..f792824 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -16,6 +16,7 @@ u32 current_pid = 0; u32 quantum = 0; struct proc *priority_proc; struct list *proc_list; +struct node *idle_proc; struct node *current; // TODO: Use less memcpy and only copy relevant registers @@ -44,12 +45,7 @@ void scheduler(struct regs *regs) } else if (((struct proc *)proc_list->head->data)->state == PROC_RUNNING) { current = proc_list->head; } else { - /* sti(); */ - /* hlt(); */ - /* cli(); */ - //print("TODO: All processes are sleeping!\n"); // TODO! - //loop(); - return; + current = idle_proc; } memcpy(regs, &((struct proc *)current->data)->regs, sizeof(struct regs)); @@ -67,6 +63,12 @@ void scheduler(struct regs *regs) /* printf("{%d}", ((struct proc *)current->data)->pid); */ } +void kernel_idle() +{ + while (1) + ; +} + void proc_print(void) { struct node *node = proc_list->head; @@ -247,7 +249,13 @@ void proc_init(void) device_add(dev); vfs_mount(dev, "/proc/"); - kernel_proc = proc_make(); + // Idle proc + struct proc *kernel_proc = proc_make(); + void (*func)() = kernel_idle; + proc_load(kernel_proc, *(void **)&func); + strcpy(kernel_proc->name, "idle"); + kernel_proc->state = PROC_SLEEPING; + idle_proc = list_add(proc_list, kernel_proc); struct node *new = list_add(proc_list, proc_make()); bin_load((char *)"/bin/init", new->data); diff --git a/kernel/inc/load.h b/kernel/inc/load.h index 43c941c..422a28c 100644 --- a/kernel/inc/load.h +++ b/kernel/inc/load.h @@ -5,60 +5,7 @@ #include <proc.h> -#define ELF_MAG 0x7F // 0 -#define ELF_32 (1) // 4: 32-bit Architecture -#define ELF_LITTLE (1) // 5: Little Endian -#define ELF_CURRENT (1) // 6: ELF Current Version -#define ELF_386 (3) // header->machine x86 machine type - -#define ET_NONE 0 // Unkown type -#define ET_REL 1 // Relocatable file -#define ET_EXEC 2 // Executable file - -#define PT_LOAD 1 - -struct elf_header { - u8 ident[16]; - u16 type; - u16 machine; - u32 version; - u32 entry; - u32 phoff; - u32 shoff; - u32 flags; - u16 ehsize; - u16 phentsize; - u16 phnum; - u16 shentsize; - u16 shnum; - u16 shstrndx; -}; - -struct elf_section_header { - u32 name; - u32 type; - u32 flags; - u32 addr; - u32 offset; - u32 size; - u32 link; - u32 info; - u32 addralign; - u32 entsize; -}; - -struct elf_program_header { - u32 type; - u32 offset; - u32 vaddr; - u32 paddr; - u32 filesz; - u32 memsz; - u32 flags; - u32 align; -}; - +void proc_load(struct proc *proc, void *data); int bin_load(char *path, struct proc *proc); -void elf_load(char *path, struct proc *proc); #endif diff --git a/kernel/inc/proc.h b/kernel/inc/proc.h index d4146fe..c198b19 100644 --- a/kernel/inc/proc.h +++ b/kernel/inc/proc.h @@ -28,8 +28,6 @@ struct proc { struct stack *messages; }; -struct proc *kernel_proc; - void scheduler(struct regs *regs); void proc_init(void); void proc_print(void); |