Initial commit

This commit is contained in:
2021-01-28 22:59:39 +01:00
commit d7f0e8dd36
30 changed files with 2092 additions and 0 deletions

26
kernel/cpu/timer.c Normal file
View File

@@ -0,0 +1,26 @@
//
// Created by rick on 9/22/19.
//
#include "timer.h"
#include <drivers/ports.h>
#include <cpu/isr.h>
u32 tick = 0;
static void timer_callback(registers_t regs) {
tick++;
}
int init_timer(u32 freq) {
register_interrupt_handler(IRQ0, timer_callback);
u32 divisor = 1193180 / freq;
u8 low = (u8) (divisor & 0xFF);
u8 high = (u8) ((divisor >> 8) & 0xFF);
port_byte_out(PORT_PIT_COMMAND, PIT_MODE_BIN | PIT_MODE_SQUARE_WAVE | PIT_ACCESS_MODE_HL | PIT_CHANNEL_0);
port_byte_out(PORT_PIT_DATA_0, low);
port_byte_out(PORT_PIT_DATA_0, high);
return 0;
}