From 83e513c32f34c1b28787888674f43681b5e1b6b5 Mon Sep 17 00:00:00 2001 From: 0x35c Date: Thu, 3 Oct 2024 16:43:48 +0200 Subject: [PATCH] fix: read_reg and write_reg are better now, no more double fault --- libbozo/headers/sys/io.h | 10 ---------- src/interrupt/apic.c | 13 +++++++++++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/libbozo/headers/sys/io.h b/libbozo/headers/sys/io.h index 0ac1700..fc6781b 100644 --- a/libbozo/headers/sys/io.h +++ b/libbozo/headers/sys/io.h @@ -31,13 +31,3 @@ static inline void io_wait(void) { outb(0x80, 0); } - -static inline void write_reg(size_t addr, uint32_t val) -{ - *(volatile uint32_t *)addr = val; -} - -static inline uint32_t read_reg(size_t addr) -{ - return *(volatile uint32_t *)addr; -} diff --git a/src/interrupt/apic.c b/src/interrupt/apic.c index 3ceccf5..930c417 100644 --- a/src/interrupt/apic.c +++ b/src/interrupt/apic.c @@ -1,6 +1,5 @@ #include "apic.h" #include "cpuid.h" -#include "sys/io.h" #include #include #include @@ -49,6 +48,16 @@ static uintptr_t cpu_get_apic_base(void) #endif } +static uint32_t read_apic_register(uint32_t reg) +{ + return *((volatile uint32_t *)(cpu_get_apic_base()) + reg); +} + +static void write_apic_register(uint32_t reg, uint32_t value) +{ + *((volatile uint32_t *)(cpu_get_apic_base() + reg)) = value; +} + void enable_apic(void) { /* Hardware enable the Local APIC if it wasn't enabled */ @@ -56,5 +65,5 @@ void enable_apic(void) /* Set the Spurious Interrupt Vector Register bit 8 to start receiving * interrupts */ - write_reg(0xF0, read_reg(0xF0) | 0x100); + write_apic_register(0xF0, read_apic_register(0xF0) | 0x100); }