kernel: C++ read_once() and write_once() functions
This commit is contained in:
@@ -15,14 +15,14 @@ namespace arch::acpi {
|
||||
|
||||
uint32_t io_apic::read(uint32_t reg)
|
||||
{
|
||||
*(volatile uint32_t *)(io_base) = reg & 0xFF;
|
||||
return *(volatile uint32_t *)((char *)io_base + 0x10);
|
||||
write_once(io_base, reg & 0xFF);
|
||||
return read_once(io_base + 4);
|
||||
}
|
||||
|
||||
void io_apic::write(uint32_t reg, uint32_t val)
|
||||
{
|
||||
*(volatile uint32_t *)(io_base) = reg & 0xFF;
|
||||
*(volatile uint32_t *)((char *)io_base + 0x10) = val;
|
||||
write_once(io_base, reg & 0xFF);
|
||||
write_once(io_base + 4, val);
|
||||
}
|
||||
|
||||
kern_status_t io_apic::read_irq(unsigned int index, irq_entry &entry)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <arch/acpi/local_apic.hpp>
|
||||
#include <socks/vm.h>
|
||||
#include <socks/compiler.h>
|
||||
|
||||
#define LAPIC_REG_EOI 0xB0
|
||||
|
||||
@@ -10,16 +11,16 @@ namespace arch::acpi {
|
||||
|
||||
uint32_t local_apic::read(uint32_t reg)
|
||||
{
|
||||
return *(volatile uint32_t *)((char *)base_ + reg);
|
||||
return read_once(base_ + (reg >> 2));
|
||||
}
|
||||
|
||||
void local_apic::write(uint32_t reg, uint32_t val)
|
||||
{
|
||||
*(volatile uint32_t *)((char *)base_ + reg) = val;
|
||||
write_once(base_ + (reg >> 2), val);
|
||||
}
|
||||
|
||||
void local_apic::ack()
|
||||
{
|
||||
*(volatile uint32_t *)((char *)base_ + LAPIC_REG_EOI) = 0;
|
||||
write(LAPIC_REG_EOI, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,20 @@
|
||||
#define READ_ONCE(t, p) (*((const volatile t *)&(p)))
|
||||
#define WRITE_ONCE(t, p, v) *(volatile t *)&(p) = (v)
|
||||
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
T read_once(const volatile T *ptr)
|
||||
{
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void write_once(volatile T *ptr, T value)
|
||||
{
|
||||
*ptr = value;
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef __used
|
||||
#define __used __attribute__((used))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user