#ifndef __JABYENGINE_IOPORT_HPP__ #define __JABYENGINE_IOPORT_HPP__ #include "../../Auxiliary/complex_bitmap.hpp" namespace JabyEngine { template class __no_align IOPort { private: T value; public: // decltype(this) instead of IOPort* lead to wrong runtime behaviour somethow... constexpr T read() const { return const_cast*>(this)->value; } template constexpr void write_combined(const ARGS&... value) { IOPort::write(T::with(value...)); } template constexpr void write(const BitRangeValue& value) { IOPort::write(T::with(value)); } constexpr void write(const T& value) { const_cast*>(this)->value = value; } // We keep this a POD so we will not add assignment operators anymore // We also removed ref() to be more percise }; struct __no_align ubus32_t { ComplexBitMap low; ComplexBitMap high; constexpr ubus32_t(uint32_t value) { *this = value; } constexpr operator uint32_t() const { return ((this->high.raw << 16) | this->low.raw); } operator uint32_t() const volatile { return ((this->high.raw << 16) | this->low.raw); } constexpr ubus32_t& operator=(uint32_t value) { this->low.raw = (value & 0xFFFF); this->high.raw = (value >> 16); return *this; } constexpr void operator=(uint32_t value) volatile { this->low.raw = (value & 0xFFFF); this->high.raw = (value >> 16); } }; static constexpr uintptr_t IO_Base_Mask = 0xF0000000; static constexpr uintptr_t IO_Base_Adr = 0x10000000; #define __io_port_adr(adr) (IO_Base_Adr + (adr & ~IO_Base_Mask)) #define __declare_io_port_global_raw(cv, type, name, adr) static __always_inline cv auto& name = *reinterpret_cast*>(__io_port_adr(adr)) #define __declare_io_port_global(type, name, adr) __declare_io_port_global_raw(, type, name, adr) #define __declare_io_port_global_const(type, name, adr) __declare_io_port_global_raw(const, type, name, adr) #define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast(*reinterpret_cast((IO_Base_Adr + (adr & ~IO_Base_Mask)))) #define __declare_io_port_global_struct(type, name, adr) static __always_inline auto& name = *reinterpret_cast(__io_port_adr(adr)) #define __io_port_inherit_complex_bit_map(name) \ constexpr __always_inline name() = default; \ constexpr __always_inline name(ComplexBitMap value) : ComplexBitMap(value) { \ } \ template \ static constexpr __always_inline name with(ARGS...args) { \ return {ComplexBitMap::with(args...)}; \ }\ template \ constexpr void __always_inline operator=(ComplexBitMap value) volatile { \ this->raw = value.raw; \ } } #endif //!__JABYENGINE_IOPORT_HPP__