From 693922d7894cf5f352f973c62aa0f11db5b8a844 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 25 Jul 2012 17:50:44 +0200 Subject: [PATCH] Support for 64-bit registers in 'util/register.h' For 64-bit registers we cannot compute MASK and SHIFT values via enums because enum values are always of type int. But we can use static member functions instead. Furthermore, the patch fixes the type trait for 64-bit registers. (apparently, this access width was never used so far) --- base/include/util/register.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/base/include/util/register.h b/base/include/util/register.h index 6f5d64e3c4..1d5d800b06 100644 --- a/base/include/util/register.h +++ b/base/include/util/register.h @@ -61,7 +61,7 @@ namespace Genode template <> struct Uint_type<64> : Uint_type<32> { - typedef uint32_t Type; + typedef uint64_t Type; enum { WIDTH_LOG2 = 6 }; }; @@ -120,14 +120,14 @@ namespace Genode /** * Fetch template parameters */ - SHIFT = _SHIFT, - WIDTH = _WIDTH, - - MASK = (1 << WIDTH) - 1, - REG_MASK = MASK << SHIFT, - CLEAR_MASK = ~REG_MASK, + SHIFT = _SHIFT, + WIDTH = _WIDTH, }; + static access_t mask() { return ((access_t)1 << WIDTH) - 1; } + static access_t reg_mask() { return mask() << SHIFT; } + static access_t clear_mask() { return ~reg_mask(); } + /** * Back reference to containing register */ @@ -141,7 +141,7 @@ namespace Genode * bitfields into one operation */ static inline access_t bits(access_t const value) { - return (value & MASK) << SHIFT; } + return (value & mask()) << SHIFT; } /** * Get a register value 'reg' masked according to this bitfield @@ -149,18 +149,19 @@ namespace Genode * \detail E.g. '0x1234' masked according to a * 'Register<16>::Bitfield<5,7>' returns '0x0220' */ - static inline access_t masked(access_t const reg) { return reg & REG_MASK; } + static inline access_t masked(access_t const reg) { + return reg & reg_mask(); } /** * Get value of this bitfield from 'reg' */ static inline access_t get(access_t const reg) { - return (reg >> SHIFT) & MASK; } + return (reg >> SHIFT) & mask(); } /** * Get registervalue 'reg' with this bitfield set to zero */ - static inline void clear(access_t & reg) { reg &= CLEAR_MASK; } + static inline void clear(access_t & reg) { reg &= clear_mask(); } /** * Get registervalue 'reg' with this bitfield set to 'value' @@ -168,7 +169,7 @@ namespace Genode static inline void set(access_t & reg, access_t const value = ~0) { clear(reg); - reg |= (value & MASK) << SHIFT; + reg |= (value & mask()) << SHIFT; }; }; };