mirror of
https://github.com/sendyne/cppreg.git
synced 2025-05-09 23:24:05 +00:00
REVISED CHECKS FOR PACKED REGISTER ALIGNMENT
This now relies on a is_aligned implementation. This will needs to be adapted once register width is defined through an enumeration. See #12.
This commit is contained in:
parent
1590e7c0e3
commit
c217f34e0c
@ -19,6 +19,9 @@
|
|||||||
namespace cppreg {
|
namespace cppreg {
|
||||||
|
|
||||||
|
|
||||||
|
//! cppreg::internals namespace.
|
||||||
|
namespace internals {
|
||||||
|
|
||||||
//! Memory map implementation.
|
//! Memory map implementation.
|
||||||
/**
|
/**
|
||||||
* @tparam Address Memory base address.
|
* @tparam Address Memory base address.
|
||||||
@ -55,6 +58,22 @@ namespace cppreg {
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//! is_aligned implementation.
|
||||||
|
/**
|
||||||
|
* @tparam Address Address to be checked for alignment.
|
||||||
|
* @tparam alignment Alignment constraint.
|
||||||
|
*/
|
||||||
|
template <Address_t Address, std::size_t alignment>
|
||||||
|
struct is_aligned : std::integral_constant<
|
||||||
|
bool,
|
||||||
|
(Address & (alignment - 1)) == 0
|
||||||
|
> {
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//! Register pack base implementation.
|
//! Register pack base implementation.
|
||||||
/**
|
/**
|
||||||
* @tparam PackBase Pack base address.
|
* @tparam PackBase Pack base address.
|
||||||
@ -109,11 +128,11 @@ namespace cppreg {
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
//! Memory map type.
|
//! Memory map type.
|
||||||
using mem_map_t = memory_map<
|
using mem_map_t = internals::memory_map<
|
||||||
RegisterPack::pack_base,
|
RegisterPack::pack_base,
|
||||||
RegisterPack::size_in_bytes,
|
RegisterPack::size_in_bytes,
|
||||||
RegWidth
|
RegWidth
|
||||||
>;
|
>;
|
||||||
|
|
||||||
//! Memory modifier.
|
//! Memory modifier.
|
||||||
/**
|
/**
|
||||||
@ -135,16 +154,18 @@ namespace cppreg {
|
|||||||
static_assert((BitOffset / 8u) <= RegisterPack::size_in_bytes,
|
static_assert((BitOffset / 8u) <= RegisterPack::size_in_bytes,
|
||||||
"packed register is overflowing the pack");
|
"packed register is overflowing the pack");
|
||||||
|
|
||||||
// Safety check to detect if the register is mis-aligned.
|
// A packed register of width N bits requires:
|
||||||
// A register is mis-aligned if it its offset is not a multiple of
|
// - the pack address to be N-bits aligned (N/8 aligned),
|
||||||
// its size and if the pack base address alignment is different from
|
// - the pack address with offset to be N-bits aligned (N/8 aligned).
|
||||||
// its type alignment.
|
static_assert(
|
||||||
static_assert((
|
internals::is_aligned<RegisterPack::pack_base, (RegWidth / 8)>
|
||||||
(BitOffset % RegWidth) == 0
|
::value
|
||||||
&&
|
&&
|
||||||
(RegisterPack::pack_base % (RegWidth / 8u) == 0)
|
internals::is_aligned<
|
||||||
),
|
RegisterPack::pack_base + (BitOffset / 8), (RegWidth / 8)
|
||||||
"register mis-alignment with respect to pack base");
|
>::value,
|
||||||
|
"register is mis-aligned in the pack"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user