Kernel: Implement basic MMIO functions

This is equivalent to IO.h except for memory mapped io instead of
IO ports
This commit is contained in:
Bananymous 2023-08-04 15:12:29 +03:00
parent 7eb2c140fe
commit 3c31fc9c4b
1 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,49 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
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;
}
}