diff options
author | Marvin Borner | 2020-05-07 22:16:09 +0200 |
---|---|---|
committer | Marvin Borner | 2020-05-07 22:16:09 +0200 |
commit | 43184e40b14a5e41383ffb053e7c69c93ff81036 (patch) | |
tree | 54dd707cd997f1a5483d03ef6f7e6320b07227ac | |
parent | 4286b14839c0c4ec016d816e426660f6685ae349 (diff) |
Some debugging and fixing
Still didn't fix the bugs
-rw-r--r-- | src/kernel/fs/elf.c | 8 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_get_pid.c | 2 | ||||
-rw-r--r-- | src/kernel/syscall/actions/sys_wait.c | 2 | ||||
-rw-r--r-- | src/kernel/syscall/syscall.c | 2 | ||||
-rw-r--r-- | src/kernel/tasks/process.c | 20 | ||||
-rw-r--r-- | src/kernel/tasks/userspace.c | 4 | ||||
-rw-r--r-- | src/userspace/programs/init.c | 28 | ||||
-rw-r--r-- | src/userspace/programs/sh.c | 2 |
8 files changed, 44 insertions, 24 deletions
diff --git a/src/kernel/fs/elf.c b/src/kernel/fs/elf.c index bee53c9..9a9b105 100644 --- a/src/kernel/fs/elf.c +++ b/src/kernel/fs/elf.c @@ -40,7 +40,7 @@ struct process *elf_load(char *path) } struct process *proc = process_make_new(); - proc->name = path; + strcpy(proc->name, path); proc->registers.eip = header->entry; paging_switch_directory(proc->cr3); @@ -54,8 +54,7 @@ struct process *elf_load(char *path) switch (program_header->type) { case 0: break; - case 1: - debug("Allocating space for ELF binary section..."); + case 1: { u32 loc = (u32)kmalloc_a(PAGE_S); paging_map_user(proc->cr3, loc, program_header->vaddr); memcpy((void *)program_header->vaddr, @@ -64,6 +63,7 @@ struct process *elf_load(char *path) if (program_header->filesz > PAGE_S) panic("ELF binary section too large"); break; + } default: warn("Unknown header type"); } @@ -71,4 +71,4 @@ struct process *elf_load(char *path) paging_switch_directory(paging_root_directory); return proc; -}
\ No newline at end of file +} diff --git a/src/kernel/syscall/actions/sys_get_pid.c b/src/kernel/syscall/actions/sys_get_pid.c index 1184ce7..eb00abe 100644 --- a/src/kernel/syscall/actions/sys_get_pid.c +++ b/src/kernel/syscall/actions/sys_get_pid.c @@ -4,4 +4,4 @@ u32 sys_get_pid() { return current_proc->pid; -}
\ No newline at end of file +} diff --git a/src/kernel/syscall/actions/sys_wait.c b/src/kernel/syscall/actions/sys_wait.c index 6015b8b..4d12886 100644 --- a/src/kernel/syscall/actions/sys_wait.c +++ b/src/kernel/syscall/actions/sys_wait.c @@ -24,4 +24,4 @@ u32 sys_wait(u32 pid, u32 *status, u32 options) } return ret; -}
\ No newline at end of file +} diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c index a5048ef..956bc37 100644 --- a/src/kernel/syscall/syscall.c +++ b/src/kernel/syscall/syscall.c @@ -46,4 +46,4 @@ void syscall_handler(struct regs *r) void syscalls_install() { isr_install_handler(0x80, syscall_handler); -}
\ No newline at end of file +} 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 +} diff --git a/src/userspace/programs/init.c b/src/userspace/programs/init.c index 1d53ee8..e749e2f 100644 --- a/src/userspace/programs/init.c +++ b/src/userspace/programs/init.c @@ -5,6 +5,11 @@ #include <unistd.h> #include <gui.h> +void test(u8 *data) +{ + printf("."); +} + void main() { if (get_pid() != 2) { @@ -15,19 +20,22 @@ void main() // TODO: Fix page fault when mallocing printf("Initializing userspace...\n"); + // TODO: Find out, why init gets PID 1 and stops + syscall_map(MAP_KEYBOARD, (u8)&test); + // TODO: Fix occasional race conditions with cli/sti // TODO: Fix scheduler turning off randomly.. - u32 x; - u32 f = fork(); - if (f == 0) { - printf("Waiting...\n"); - wait(&x); - } else { - printf("Executing...\n"); - exec("/bin/sh"); - } + /* u32 x; */ + /* u32 f = fork(); */ + /* if (f == 0) { */ + /* printf("Waiting...\n"); */ + /* wait(&x); */ + /* } else { */ + /* printf("Executing...\n"); */ + /* exec("/bin/sh"); */ + /* } */ while (1) { //printf("B"); }; -}
\ No newline at end of file +} diff --git a/src/userspace/programs/sh.c b/src/userspace/programs/sh.c index 12f8b2c..fc6b6d6 100644 --- a/src/userspace/programs/sh.c +++ b/src/userspace/programs/sh.c @@ -18,4 +18,4 @@ void main() while (1) { //printf("A"); }; -}
\ No newline at end of file +} |