From 197ea3ca20879b29fca41a07cf43e5b04b9c5083 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 26 Oct 2020 16:36:40 +0100 Subject: Optimizations --- kernel/drivers/fpu.c | 2 +- kernel/drivers/ide.c | 2 +- kernel/drivers/interrupts.c | 17 +++++++++-------- kernel/drivers/timer.c | 4 +--- kernel/features/event.c | 2 +- kernel/features/fs.c | 10 +++++----- kernel/features/proc.c | 7 ++++--- kernel/main.c | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) (limited to 'kernel') diff --git a/kernel/drivers/fpu.c b/kernel/drivers/fpu.c index d8a2b79..f7eeceb 100644 --- a/kernel/drivers/fpu.c +++ b/kernel/drivers/fpu.c @@ -10,7 +10,7 @@ void set_fpu_cw(const u16 cw) void fpu_install() { __asm__ volatile("clts"); - u32 t; + u32 t = 0; __asm__ volatile("mov %%cr0, %0" : "=r"(t)); t &= ~(1 << 2); t |= (1 << 1); diff --git a/kernel/drivers/ide.c b/kernel/drivers/ide.c index c1c0227..1a94ae3 100644 --- a/kernel/drivers/ide.c +++ b/kernel/drivers/ide.c @@ -16,7 +16,7 @@ int ide_stat() void ide_wait() { - u8 stat; + u8 stat = 0; do stat = ide_stat(); while ((stat & IDE_BUSY) != 0); diff --git a/kernel/drivers/interrupts.c b/kernel/drivers/interrupts.c index 9088915..57b0ab5 100644 --- a/kernel/drivers/interrupts.c +++ b/kernel/drivers/interrupts.c @@ -6,6 +6,7 @@ #include #include #include +#include #include /** @@ -166,18 +167,18 @@ void isr_uninstall_handler(int isr) void isr_handler(struct regs *r) { - void (*handler)(struct regs * r); - // Execute fault handler if exists - handler = isr_routines[r->int_no]; + void (*handler)(struct regs * r) = isr_routines[r->int_no]; if (handler) { handler(r); } else if (r->int_no <= 32) { - cli(); - printf("\n%s Exception, halting!\n", isr_exceptions[r->int_no]); - printf("Error code: %d\n", r->err_code); - while (1) { - }; + printf("%s Exception, exiting!\n", isr_exceptions[r->int_no]); + struct proc *proc = proc_current(); + if (proc) + proc_exit(proc, 1); + else + __asm__ volatile("cli\nhlt"); + proc_yield(r); } } diff --git a/kernel/drivers/timer.c b/kernel/drivers/timer.c index 812bde7..3bc1811 100644 --- a/kernel/drivers/timer.c +++ b/kernel/drivers/timer.c @@ -31,9 +31,7 @@ void timer_handler() // "Delay" function with CPU sleep void timer_wait(u32 ticks) { - u32 eticks; - - eticks = timer_ticks + ticks; + u32 eticks = timer_ticks + ticks; while (timer_ticks < eticks) { __asm__ volatile("sti//hlt//cli"); } diff --git a/kernel/features/event.c b/kernel/features/event.c index 633f633..d79d531 100644 --- a/kernel/features/event.c +++ b/kernel/features/event.c @@ -46,7 +46,7 @@ u32 event_trigger(u32 id, void *data) { assert(id < sizeof(event_table) / sizeof(*event_table)); - if (memcmp(event_table[id], 0, sizeof(struct list)) == 0 || !event_table[id]->head) { + if (!event_table[id] || !event_table[id]->head) { printf("Event %d not mapped!\n", id); return 1; } diff --git a/kernel/features/fs.c b/kernel/features/fs.c index 2db0a97..c52a7b6 100644 --- a/kernel/features/fs.c +++ b/kernel/features/fs.c @@ -68,10 +68,10 @@ void *read_inode(struct inode *in) printf("Loading %dKiB\n", sz >> 10); assert(buf != NULL); - int indirect; + int indirect = 0; - int blocknum; - char *data; + int blocknum = 0; + char *data = 0; // TODO: Support triply indirect pointers // TODO: This can be heavily optimized by saving the indirect block lists for (int i = 0; i < num_blocks; i++) { @@ -105,7 +105,7 @@ void *read_file(char *path) path++; u32 current_inode = EXT2_ROOT; - int i; + int i = 0; while (1) { for (i = 0; path[i] != '/' && path[i] != '\0'; i++) ; @@ -176,7 +176,7 @@ void ls_root() struct dirent *d = (struct dirent *)buf; int sum = 0; - int calc; + int calc = 0; printf("\nRoot directory:\n"); do { calc = (sizeof(struct dirent) + d->name_len + 4) & ~0x3; diff --git a/kernel/features/proc.c b/kernel/features/proc.c index b6ed442..5d1a437 100644 --- a/kernel/features/proc.c +++ b/kernel/features/proc.c @@ -34,13 +34,14 @@ void scheduler(struct regs *regs) assert(proc_list->head); - memcpy(&((struct proc *)current->data)->regs, regs, sizeof(struct regs)); + if (current) + memcpy(&((struct proc *)current->data)->regs, regs, sizeof(struct regs)); if (priority_proc) { current = list_first_data(proc_list, priority_proc); priority_proc = NULL; assert(current); - } else if (current->next) { + } else if (current && current->next) { current = current->next; } else { current = proc_list->head; @@ -76,7 +77,7 @@ void proc_print() struct node *node = proc_list->head; printf("\nPROCESSES\n"); - struct proc *proc; + struct proc *proc = NULL; while (node && (proc = node->data)) { printf("Process %d: %s\n", proc->pid, proc->name); node = node->next; diff --git a/kernel/main.c b/kernel/main.c index 0c2a513..6e666b5 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -32,7 +32,7 @@ void kernel_main(struct vid_info *vid_info) acpi_install(); pci_install(); interrupts_install(); - fpu_install(); + /* fpu_install(); */ timer_install(); keyboard_install(); mouse_install(); -- cgit v1.2.3