working timer interrupt
This commit is contained in:
parent
d5baae3734
commit
8e5b59c7fd
@ -4,6 +4,7 @@
|
|||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "ports.h"
|
#include "ports.h"
|
||||||
|
#include "pit.h"
|
||||||
|
|
||||||
const char* err_msg[] = {
|
const char* err_msg[] = {
|
||||||
"Divide by zero\n",
|
"Divide by zero\n",
|
||||||
@ -84,7 +85,7 @@ extern void irq_handler_13();
|
|||||||
extern void irq_handler_14();
|
extern void irq_handler_14();
|
||||||
extern void irq_handler_15();
|
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) {
|
void setup_idt_entry(u32 t_idx, u32 base, u16 sel, u8 type_attrs) {
|
||||||
// Configuring a single given entry in the IDT table
|
// 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 irq_handler(struct cpu_reg_state* cpu) {
|
||||||
void (*handler)(struct cpu_reg_state* cpu);
|
void (*handler)(struct cpu_reg_state* cpu);
|
||||||
// Dispatcher for irq's
|
// 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) {
|
if(handler) {
|
||||||
handler(cpu);
|
handler(cpu);
|
||||||
}
|
}
|
||||||
@ -178,6 +180,8 @@ void init_idt() {
|
|||||||
|
|
||||||
// clear table in case there's garbage in there
|
// clear table in case there's garbage in there
|
||||||
memset((u8*)irq_handlers, 0, sizeof(void*));
|
memset((u8*)irq_handlers, 0, sizeof(void*));
|
||||||
|
irq_handlers[0] = inc_ticks; // LULW
|
||||||
|
|
||||||
// Remap irq's to proper location
|
// Remap irq's to proper location
|
||||||
serialport_write_byte(0x20, 0x11);
|
serialport_write_byte(0x20, 0x11);
|
||||||
serialport_write_byte(0xA0, 0x11);
|
serialport_write_byte(0xA0, 0x11);
|
||||||
|
4
kernel.c
4
kernel.c
@ -18,7 +18,7 @@ void kprintp(const u32 ptr) {
|
|||||||
const char _chars[] = "0123456789abcdef";
|
const char _chars[] = "0123456789abcdef";
|
||||||
u32 idx = 0; // used as hash into the _chars mapping
|
u32 idx = 0; // used as hash into the _chars mapping
|
||||||
// iterate over each nibble
|
// iterate over each nibble
|
||||||
for(u32 i = 0 ;i < 7;i++) {
|
for(u32 i = 0 ;i < 8;i++) {
|
||||||
idx = (ptr << (i * 4)) & 0xf0000000;
|
idx = (ptr << (i * 4)) & 0xf0000000;
|
||||||
idx = idx >> 28;
|
idx = idx >> 28;
|
||||||
putch(_chars[idx]);
|
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
|
// Should kmain return, we fall back to the loader which then just keeps in a hung state
|
||||||
void kmain() {
|
void kmain() {
|
||||||
kinit();
|
kinit();
|
||||||
kprints("i guess we're good now?");
|
timer_wait(50); // in ms
|
||||||
}
|
}
|
||||||
|
3
pit.c
3
pit.c
@ -8,9 +8,6 @@ volatile u32 timer_ticks = 0;
|
|||||||
|
|
||||||
void inc_ticks(struct cpu_reg_state* cpu) {
|
void inc_ticks(struct cpu_reg_state* cpu) {
|
||||||
timer_ticks++;
|
timer_ticks++;
|
||||||
if(timer_ticks % 18 == 0) {
|
|
||||||
printf("One second passed\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer_wait(u32 time) {
|
void timer_wait(u32 time) {
|
||||||
|
3
pit.h
3
pit.h
@ -1,3 +1,5 @@
|
|||||||
|
#ifndef PIT_H
|
||||||
|
#define PIT_H
|
||||||
#include "interrupts.h"
|
#include "interrupts.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
@ -12,3 +14,4 @@ void inc_ticks(struct cpu_reg_state*);
|
|||||||
void timer_wait(u32);
|
void timer_wait(u32);
|
||||||
|
|
||||||
void pit_install_timer(void);
|
void pit_install_timer(void);
|
||||||
|
#endif
|
||||||
|
2
stlio.c
2
stlio.c
@ -49,7 +49,7 @@ void printhex(u32 num) {
|
|||||||
u32 idx = 0; // used as hash into the _chars mapping
|
u32 idx = 0; // used as hash into the _chars mapping
|
||||||
// iterate over each nibble
|
// iterate over each nibble
|
||||||
for(u32 i = 0 ;i < 8;i++) {
|
for(u32 i = 0 ;i < 8;i++) {
|
||||||
idx = (ptr << (i * 4)) & 0xf0000000;
|
idx = (num << (i * 4)) & 0xf0000000;
|
||||||
idx = idx >> 28;
|
idx = idx >> 28;
|
||||||
putch(_chars[idx]);
|
putch(_chars[idx]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user