From 8e5b59c7fd96fa03154457e8f99ef05d64d32053 Mon Sep 17 00:00:00 2001 From: shockrahwow Date: Fri, 29 Nov 2019 01:53:46 -0800 Subject: [PATCH] working timer interrupt --- interrupts.c | 8 ++++++-- kernel.c | 4 ++-- pit.c | 3 --- pit.h | 3 +++ stlio.c | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/interrupts.c b/interrupts.c index 1c31b98..cf44e3c 100644 --- a/interrupts.c +++ b/interrupts.c @@ -4,6 +4,7 @@ #include "mem.h" #include "types.h" #include "ports.h" +#include "pit.h" const char* err_msg[] = { "Divide by zero\n", @@ -84,7 +85,7 @@ extern void irq_handler_13(); extern void irq_handler_14(); extern void irq_handler_15(); -void* irq_handlers[16]; +void* irq_handlers[16] = {0}; void setup_idt_entry(u32 t_idx, u32 base, u16 sel, u8 type_attrs) { // Configuring a single given entry in the IDT table @@ -116,7 +117,8 @@ void init_irq_handler(u32 irq, void (*handler)(struct cpu_reg_state* cpu)) { void irq_handler(struct cpu_reg_state* cpu) { void (*handler)(struct cpu_reg_state* cpu); // Dispatcher for irq's - handler = irq_handlers[cpu->int_no]; + handler = irq_handlers[cpu->int_no - 0x20]; + // Handler the timer by hand because fuck this tbh if(handler) { handler(cpu); } @@ -178,6 +180,8 @@ void init_idt() { // clear table in case there's garbage in there memset((u8*)irq_handlers, 0, sizeof(void*)); + irq_handlers[0] = inc_ticks; // LULW + // Remap irq's to proper location serialport_write_byte(0x20, 0x11); serialport_write_byte(0xA0, 0x11); diff --git a/kernel.c b/kernel.c index 4be1958..cd6609b 100644 --- a/kernel.c +++ b/kernel.c @@ -18,7 +18,7 @@ void kprintp(const u32 ptr) { const char _chars[] = "0123456789abcdef"; u32 idx = 0; // used as hash into the _chars mapping // iterate over each nibble - for(u32 i = 0 ;i < 7;i++) { + for(u32 i = 0 ;i < 8;i++) { idx = (ptr << (i * 4)) & 0xf0000000; idx = idx >> 28; putch(_chars[idx]); @@ -32,5 +32,5 @@ void kprints(const char* s) { // Should kmain return, we fall back to the loader which then just keeps in a hung state void kmain() { kinit(); - kprints("i guess we're good now?"); + timer_wait(50); // in ms } diff --git a/pit.c b/pit.c index 8dc2125..b0462f0 100644 --- a/pit.c +++ b/pit.c @@ -8,9 +8,6 @@ volatile u32 timer_ticks = 0; void inc_ticks(struct cpu_reg_state* cpu) { timer_ticks++; - if(timer_ticks % 18 == 0) { - printf("One second passed\n"); - } } void timer_wait(u32 time) { diff --git a/pit.h b/pit.h index 336fba2..3add40b 100644 --- a/pit.h +++ b/pit.h @@ -1,3 +1,5 @@ +#ifndef PIT_H +#define PIT_H #include "interrupts.h" #include "types.h" @@ -12,3 +14,4 @@ void inc_ticks(struct cpu_reg_state*); void timer_wait(u32); void pit_install_timer(void); +#endif diff --git a/stlio.c b/stlio.c index 100b707..b32490d 100644 --- a/stlio.c +++ b/stlio.c @@ -49,7 +49,7 @@ void printhex(u32 num) { u32 idx = 0; // used as hash into the _chars mapping // iterate over each nibble for(u32 i = 0 ;i < 8;i++) { - idx = (ptr << (i * 4)) & 0xf0000000; + idx = (num << (i * 4)) & 0xf0000000; idx = idx >> 28; putch(_chars[idx]); }