diff options
author | Marvin Borner | 2020-05-11 22:45:08 +0200 |
---|---|---|
committer | Marvin Borner | 2020-05-11 22:45:08 +0200 |
commit | fe4280eb69fbeb386b5442b3aeb515dde1c117ec (patch) | |
tree | 5837a5af36629ddad0215c248f30cd8ce6bb385c | |
parent | 9b959a402f1998a9c608b917034cae81bd03b088 (diff) |
Some scheduling improvements
And other stuff..
-rwxr-xr-x | run | 1 | ||||
-rw-r--r-- | src/kernel/boot.asm | 1 | ||||
-rw-r--r-- | src/kernel/interrupts/isr.c | 2 | ||||
-rw-r--r-- | src/kernel/kernel.c | 1 | ||||
-rw-r--r-- | src/kernel/memory/alloc.h | 2 | ||||
-rw-r--r-- | src/kernel/syscall/syscall.c | 1 | ||||
-rw-r--r-- | src/kernel/tasks/process.c | 16 | ||||
-rw-r--r-- | src/kernel/tasks/process.h | 1 | ||||
-rw-r--r-- | src/userspace/programs/init.c | 15 | ||||
-rw-r--r-- | src/userspace/programs/sh.c | 16 |
10 files changed, 21 insertions, 35 deletions
@@ -79,7 +79,6 @@ make_cross() { cd "${DIR}/.." else - # Should be sourced to take effect cd cross DIR=$(pwd) export PREFIX="${DIR}/opt" diff --git a/src/kernel/boot.asm b/src/kernel/boot.asm index 8e6761c..11f8a45 100644 --- a/src/kernel/boot.asm +++ b/src/kernel/boot.asm @@ -43,5 +43,4 @@ section .text push eax cli call kernel_main - cli jmp $
\ No newline at end of file diff --git a/src/kernel/interrupts/isr.c b/src/kernel/interrupts/isr.c index b24529f..8bfb7bd 100644 --- a/src/kernel/interrupts/isr.c +++ b/src/kernel/interrupts/isr.c @@ -129,7 +129,7 @@ void fault_handler(struct regs *r) warn("%s: Halting process %d", message, current_proc->pid); memcpy(¤t_proc->registers, r, sizeof(struct regs)); process_suspend(current_proc->pid); - scheduler(r); + process_force_switch(r); } else { if (faulting_address != (u32)fb) { panic("Page fault before multitasking started!"); diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index d28987b..2d98179 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -69,6 +69,5 @@ void kernel_main(u32 magic, u32 multiboot_address, u32 esp) syscalls_install(); kexec("/bin/init"); - halt_loop(); // asm ("div %0" :: "r"(0)); // Exception testing x/0 }
\ No newline at end of file diff --git a/src/kernel/memory/alloc.h b/src/kernel/memory/alloc.h index 952b61c..a7b05bc 100644 --- a/src/kernel/memory/alloc.h +++ b/src/kernel/memory/alloc.h @@ -5,7 +5,7 @@ #include <stddef.h> #include <stdint.h> -#define KHEAP_MAGIC 0x04206969 +#define KHEAP_MAGIC 0xCAFEBABE #define KHEAP_MAGIC2 0xDEADBEEF #define KHEAP_END 0xFFFFDEAD #define MEM_END 0x8000000 diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c index c98707f..21738f8 100644 --- a/src/kernel/syscall/syscall.c +++ b/src/kernel/syscall/syscall.c @@ -35,6 +35,7 @@ void syscall_handler(struct regs *r) r->edx, r->esi, r->edi); r->eax = location(r->ebx, r->ecx, r->edx, r->esi, r->edi); + debug("Finished syscall"); } void syscalls_install() diff --git a/src/kernel/tasks/process.c b/src/kernel/tasks/process.c index e1a6006..a361355 100644 --- a/src/kernel/tasks/process.c +++ b/src/kernel/tasks/process.c @@ -22,7 +22,7 @@ extern u32 stack_hold; void scheduler(struct regs *regs) { - log("%d", quantum); + serial_put('.'); if (quantum == 0 || current_proc->state != PROC_RUNNING) { quantum = 42; // For next process } else { @@ -54,6 +54,12 @@ void scheduler(struct regs *regs) paging_switch_directory(current_proc->cr3); } +void process_force_switch(struct regs *regs) +{ + quantum = 0; + scheduler(regs); +} + void process_init(struct process *proc) { log("Initializing process %d", pid); @@ -71,8 +77,8 @@ void process_init(struct process *proc) u32 process_spawn(struct process *process) { debug("Spawning process %d", process->pid); - process->next = root->next; - root->next = process; + process->next = current_proc->next; + current_proc->next = process; process->state = PROC_RUNNING; process->parent = current_proc; @@ -209,8 +215,6 @@ u32 uexec(char *path) if (proc == NULL) return -1; - proc->parent = current_proc; - proc->gid = current_proc->pid; process_spawn(proc); log("Spawned"); return 0; @@ -224,8 +228,6 @@ u32 uspawn(char *path) if (proc == NULL) return -1; - proc->parent = current_proc; - proc->gid = current_proc->pid; process_spawn(proc); log("Spawned"); return 0; diff --git a/src/kernel/tasks/process.h b/src/kernel/tasks/process.h index 4220d1e..c015df9 100644 --- a/src/kernel/tasks/process.h +++ b/src/kernel/tasks/process.h @@ -31,6 +31,7 @@ struct process { }; void scheduler(struct regs *regs); +void process_force_switch(struct regs *regs); u32 process_spawn(struct process *process); void process_suspend(u32 pid); diff --git a/src/userspace/programs/init.c b/src/userspace/programs/init.c index 019e5c3..7a4900b 100644 --- a/src/userspace/programs/init.c +++ b/src/userspace/programs/init.c @@ -21,10 +21,10 @@ int interrupts_enabled() void main() { - /* if (get_pid() != 1) { */ - /* printf("Wrong PID!\n"); */ - /* exit(1); */ - /* } */ + if (get_pid() != 1) { + printf("Wrong PID!\n"); + exit(1); + } if (interrupts_enabled()) printf("INTs enabled :)\n"); @@ -38,12 +38,9 @@ void main() // TODO: Fix occasional race conditions with cli/sti // TODO: Fix scheduler turning off at some point spawn("/bin/sh"); - if (interrupts_enabled()) - printf("INTs enabled :)\n"); - else - printf("INTs disabled :(\n"); + printf("Looping in init\n"); while (1) { - printf("B"); + //printf("B"); }; }
\ No newline at end of file diff --git a/src/userspace/programs/sh.c b/src/userspace/programs/sh.c index db8543d..d1ae1f8 100644 --- a/src/userspace/programs/sh.c +++ b/src/userspace/programs/sh.c @@ -27,23 +27,11 @@ int interrupts_enabled() void main() { - /* if (get_pid() != 1) { */ - /* printf("Wrong PID!\n"); */ - /* exit(1); */ - /* } */ + printf("Shell started\n"); - if (interrupts_enabled()) - printf("INTs enabled :)\n"); - else - printf("INTs disabled :(\n"); - printf("[~] "); - - /* while (1) { */ - /* putch(getch()); */ - /* } */ //syscall_map(MAP_KEYBOARD, (u32)&test); - /* syscall_halt(); */ + printf("Looping in shell\n"); while (1) { //printf("A"); }; |