smol-gilbraltar/include/mem.h
2024-12-23 01:46:17 +01:00

27 lines
675 B
C

#ifndef __GILBRALTAR_MEM__
#define __GILBRALTAR_MEM__
#include <stddef.h>
#include <stdint.h>
static inline uint8_t read8(uintptr_t addr) {
return *(uint8_t volatile *)addr;
}
static inline void write8(uintptr_t addr, uint8_t v) {
*(uint8_t volatile *)addr = v;
}
static inline uint32_t read32(uintptr_t addr) {
return *(uint32_t volatile *)addr;
}
static inline void write32(uintptr_t addr, uint32_t v) {
*(uint32_t volatile *)addr = v;
}
#define data_sync_barrier() __asm__ __volatile("dsb sy" ::: "memory")
#define data_mem_barrier() __asm__ __volatile("dmb sy" ::: "memory")
#define instruction_sync_barrier() __asm__ __volatile("isb" ::: "memory")
#endif