working timer interrupt

This commit is contained in:
shockrahwow 2019-11-29 01:53:46 -08:00
parent d5baae3734
commit 8e5b59c7fd
5 changed files with 12 additions and 8 deletions

View File

@ -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);

View File

@ -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
}

3
pit.c
View File

@ -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) {

3
pit.h
View File

@ -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

View File

@ -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]);
}