feat: made more definitions constant and did some more minor

improvements
This commit is contained in:
2021-01-29 20:25:37 +01:00
parent d7f0e8dd36
commit 5a1caef5b1
13 changed files with 114 additions and 30 deletions

View File

@@ -1,7 +1,7 @@
//
// Created by rick on 8/18/19.
//
#include "../types.h"
#include <types.h>
#ifndef MY_KERNEL_IDT_H
#define MY_KERNEL_IDT_H

View File

@@ -9,6 +9,8 @@
#include <libc/libc.h>
#include <drivers/ports.h>
#define PIC_END_OF_INTERRUPT 0x20
isr_t interrupt_handlers[256];
void isr_install() {
@@ -133,11 +135,11 @@ void register_interrupt_handler(u8 n, isr_t handler) {
void irq_handler(registers_t r) {
/* After every interrupt we need to send an EOI to the PICs
* or they will not send another interrupt again */
if (r.int_no >= 40) port_byte_out(0xA0, 0x20); /* slave */
port_byte_out(0x20, 0x20); /* master */
if (r.int_no >= 40) port_byte_out(PORT_PIC_SLAVE_COMMAND, PIC_END_OF_INTERRUPT); /* slave */
port_byte_out(PORT_PIC_MASTER_COMMAND, PIC_END_OF_INTERRUPT); /* master */
/* Handle the interrupt in a more modular way */
if (interrupt_handlers[r.int_no] != 0) {
if (interrupt_handlers[r.int_no] != NULL) {
isr_t handler = interrupt_handlers[r.int_no];
handler(r);
}

View File

@@ -2,7 +2,7 @@
// Created by rick on 8/18/19.
//
#include "../types.h"
#include <types.h>
#ifndef MY_KERNEL_ISR_H
#define MY_KERNEL_ISR_H

View File

@@ -7,6 +7,28 @@
#include <drivers/ports.h>
#include <cpu/isr.h>
// https://wiki.osdev.org/PIT
#define PIT_MODE_BIN_BCD (1 << 0)
#define PIT_MODE_BIN (0 << 0)
#define PIT_MODE_BCD (1 << 0)
#define PIT_GENERATOR_MODE (0b111 << 1)
#define PIT_MODE_INTERRUPT_ON_TERMINAL_COUNT (0b000 < 1)
#define PIT_MODE_HARDWARE_RETRIGGERABLE_ONE_SHOT (0b001 < 1)
#define PIT_MODE_HARDWARE_RATE_GENERATOR (0b010 < 1)
#define PIT_MODE_HARDWARE_SQUARE_WAVE_GENERATOR (0b011 < 1)
#define PIT_MODE_SOFTWARE_TRIGGERED_STROBE (0b100 << 1)
#define PIT_MODE_HARDWARE_TRIGGERED_STROBE (0b101 << 1)
#define PIT_ACCESS_MODE (0b11 << 4)
#define PIT_ACCESS_MODE_LATCH_COUNT (0b00 << 4)
#define PIT_ACCESS_MODE_L (0b01 << 4)
#define PIT_ACCESS_MODE_H (0b10 << 4)
#define PIT_ACCESS_MODE_LH (0b11 << 4)
#define PIT_CHANNEL (0b11 << 6)
#define PIT_CHANNEL_0 (0b00 << 6)
#define PIT_CHANNEL_1 (0b01 << 6)
#define PIT_CHANNEL_2 (0b10 << 6)
#define PIT_CHANNEL_READ_BACK (0b11 << 6)
u32 tick = 0;
static void timer_callback(registers_t regs) {
@@ -19,7 +41,7 @@ int init_timer(u32 freq) {
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_COMMAND, PIT_MODE_BIN | PIT_MODE_HARDWARE_SQUARE_WAVE_GENERATOR | PIT_ACCESS_MODE_LH | PIT_CHANNEL_0);
port_byte_out(PORT_PIT_DATA_0, low);
port_byte_out(PORT_PIT_DATA_0, high);
return 0;

View File

@@ -5,7 +5,7 @@
#ifndef MY_KERNEL_TIMER_H
#define MY_KERNEL_TIMER_H
#include "../types.h"
#include <types.h>
int init_timer(u32 freq);