From 43184e40b14a5e41383ffb053e7c69c93ff81036 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 7 May 2020 22:16:09 +0200 Subject: Some debugging and fixing Still didn't fix the bugs --- src/kernel/tasks/process.c | 20 ++++++++++++++++---- src/kernel/tasks/userspace.c | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'src/kernel/tasks') diff --git a/src/kernel/tasks/process.c b/src/kernel/tasks/process.c index b8dd808..32433d8 100644 --- a/src/kernel/tasks/process.c +++ b/src/kernel/tasks/process.c @@ -31,12 +31,15 @@ void scheduler(struct regs *regs) current_proc = root; } + debug("Max pid: %d", pid); debug("Task switch to %s with pid %d", current_proc->name, current_proc->pid); while (current_proc->state == PROC_ASLEEP) { current_proc = current_proc->next; - if (current_proc == NULL) + if (current_proc == NULL) { + warn("No next process!"); current_proc = root; + } } memcpy(regs, ¤t_proc->registers, sizeof(struct regs)); @@ -46,6 +49,8 @@ void scheduler(struct regs *regs) void process_init(struct process *proc) { + log("Initializing process %d", pid + 1); + cli(); root = proc; root->pid = pid++; root->next = NULL; @@ -59,6 +64,7 @@ void process_init(struct process *proc) void process_kill(u32 pid) { + debug("Killing process %d", pid); struct process *proc = process_from_pid(pid); if (proc == PID_NOT_FOUND) @@ -76,6 +82,7 @@ void process_kill(u32 pid) u32 process_spawn(struct process *process) { + debug("Spawning process %d", process->pid); process->next = root->next; root->next = process; process->state = PROC_RUNNING; @@ -125,6 +132,7 @@ u32 process_wait_pid(u32 pid, u32 *status) void process_suspend(u32 pid) { + debug("Suspending process %d", pid); struct process *proc = process_from_pid(pid); if (proc == PID_NOT_FOUND) { @@ -137,6 +145,7 @@ void process_suspend(u32 pid) void process_wake(u32 pid) { + debug("Waking process %d", pid); struct process *proc = process_from_pid(pid); if (proc == PID_NOT_FOUND) @@ -147,13 +156,13 @@ void process_wake(u32 pid) u32 process_child(struct process *child, u32 pid) { + debug("Spawning child process %d", pid); process_suspend(pid); struct process *parent = process_from_pid(pid); - if (parent == PID_NOT_FOUND) { + if (parent == PID_NOT_FOUND) panic("Child process spawned without parent"); - } child->parent = parent; @@ -192,6 +201,7 @@ struct process *process_from_pid(u32 pid) struct process *process_make_new() { + debug("Making new process %d", pid); struct process *proc = (struct process *)kmalloc_a(sizeof(struct process)); proc->registers.cs = 0x1B; proc->registers.ds = 0x23; @@ -210,6 +220,7 @@ struct process *process_make_new() u32 kexec(char *path) { + debug("Starting kernel process %s", path); struct process *proc = elf_load(path); if (proc == NULL) return -1; @@ -224,6 +235,7 @@ u32 kexec(char *path) u32 uexec(char *path) { + debug("Starting user process %s", path); process_suspend(current_proc->pid); struct process *proc = elf_load(path); @@ -238,4 +250,4 @@ u32 uexec(char *path) proc->gid = current_proc->pid; process_spawn(proc); return 0; -} \ No newline at end of file +} diff --git a/src/kernel/tasks/userspace.c b/src/kernel/tasks/userspace.c index 9457b7e..77392a1 100644 --- a/src/kernel/tasks/userspace.c +++ b/src/kernel/tasks/userspace.c @@ -29,8 +29,8 @@ void userspace_enter(struct process *proc) current_proc = proc; - sti(); // TODO: Prevent race conditions in userspace jumping debug("Jumping to userspace!"); + sti(); // TODO: Prevent race conditions in userspace jumping jump_userspace(); } @@ -63,4 +63,4 @@ u32 single_exit(struct regs *regs) paging_switch_directory(proc_bottom->cr3); return hold; -} \ No newline at end of file +} -- cgit v1.2.3