From 3a59a64355520e1f428b1c9d0bddb000eed179f2 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 4 Aug 2023 15:12:29 +0300 Subject: [PATCH] Kernel: Implement basic MMIO functions This is equivalent to IO.h except for memory mapped io instead of IO ports --- kernel/include/kernel/MMIO.h | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 kernel/include/kernel/MMIO.h diff --git a/kernel/include/kernel/MMIO.h b/kernel/include/kernel/MMIO.h new file mode 100644 index 00000000..9b9cd2d3 --- /dev/null +++ b/kernel/include/kernel/MMIO.h @@ -0,0 +1,49 @@ +#pragma once + +#include +#include + +namespace MMIO +{ + + static inline void write8(uintptr_t addr, uint8_t val) + { + *(volatile uint8_t*)addr = val; + } + + static inline void write16(uintptr_t addr, uint16_t val) + { + *(volatile uint16_t*)addr = val; + } + + static inline void write32(uintptr_t addr, uint32_t val) + { + *(volatile uint32_t*)addr = val; + } + + static inline void write64(uintptr_t addr, uint64_t val) + { + *(volatile uint64_t*)addr = val; + } + + static inline uint8_t read8(uintptr_t addr) + { + return *(volatile uint8_t*)addr; + } + + static inline uint16_t read16(uintptr_t addr) + { + return *(volatile uint16_t*)addr; + } + + static inline uint32_t read32(uintptr_t addr) + { + return *(volatile uint32_t*)addr; + } + + static inline uint64_t read64(uintptr_t addr) + { + return *(volatile uint64_t*)addr; + } + +} \ No newline at end of file