Add Register Class
Register is an abstract base class for real and virtual registers. A
few examples of these registers are; HardwareRegister, ConstantRegister,
NotRegister, and AndRegister. As a base class of register types, the
Register class creates a place where these registers can be put
together like logical building blocks. For example, Register makes this
possible:
Register * fir = new HardwareRegister(REG_ADDRESS, REG_WIDTH,
DEFAULT_CHIP_TYPE, ACCESS_RO);
Register * mask = new ConstantRegister( 0xffffffff00000000 );
Register * fir_mask = new AndRegister(fir, mask);
const BitString * bs = fir_mask->getBitString();
The getBitString function (defined by each register) provides access to
the BitString that manages each register's data. In this example bs
will contain the result of fir & mask.
Change-Id: I497d997c1cc338c53cb04a827bf2f4aca6b781c9
Signed-off-by: Paul Greenwood <Paul.Greenwood@ibm.com>
diff --git a/src/chip_data/hei_chip_data.hpp b/src/chip_data/hei_chip_data.hpp
index ba3d2e9..a02987f 100644
--- a/src/chip_data/hei_chip_data.hpp
+++ b/src/chip_data/hei_chip_data.hpp
@@ -9,4 +9,4 @@
static constexpr ChipType_t DEFAULT_CHIP_TYPE = 0;
-} // end namespace libhei
+} //end namespace libhei
diff --git a/src/hei_includes.hpp b/src/hei_includes.hpp
index 36aa51a..ccf5ee6 100644
--- a/src/hei_includes.hpp
+++ b/src/hei_includes.hpp
@@ -1,7 +1,10 @@
#pragma once
-// The purpose of this file is to include common headers that will be used
-// throughout this library.
+/**
+@file hei_includes.hpp
+@brief The purpose of this file is to include common headers that will be used
+throughout this library.
+*/
// Standard library includes
#include <stdint.h>
diff --git a/src/register/hei_register.cpp b/src/register/hei_register.cpp
deleted file mode 100755
index ac31f91..0000000
--- a/src/register/hei_register.cpp
+++ /dev/null
@@ -1,245 +0,0 @@
-
-/* Module Description *************************************************/
-/* */
-/* Description: This module contains the implementation for the */
-/* Processor Runtime Diagnostics Scan Communication */
-/* Register class. */
-/* */
-/* Notes: Unless stated otherwise, assume that each function */
-/* specification has no side-effects, no dependencies, and */
-/* constant time complexity. */
-/* */
-/* End Module Description *********************************************/
-
-/*--------------------------------------------------------------------*/
-/* Includes */
-/*--------------------------------------------------------------------*/
-
-#include <hei_includes.hpp>
-#include <register/hei_register.hpp>
-#include <util/hei_bit_string.hpp>
-
-namespace libhei
-{
-
-/*--------------------------------------------------------------------*/
-/* User Types */
-/*--------------------------------------------------------------------*/
-
-/*--------------------------------------------------------------------*/
-/* Constants */
-/*--------------------------------------------------------------------*/
-
-/*--------------------------------------------------------------------*/
-/* Macros */
-/*--------------------------------------------------------------------*/
-
-/*--------------------------------------------------------------------*/
-/* Internal Function Prototypes */
-/*--------------------------------------------------------------------*/
-
-/*--------------------------------------------------------------------*/
-/* Global Variables */
-/*--------------------------------------------------------------------*/
-
-/*--------------------------------------------------------------------*/
-/* Static Variables */
-/*--------------------------------------------------------------------*/
-
-// Function Specification //////////////////////////////////////////
-//
-// Title: ~SCAN_COMM_REGISTER_CLASS (Virtual destructor)
-//
-// Purpose: This destructor deallocates the Bit String.
-//
-// Side-effects: Memory is deallocated.
-//
-// Dependencies: None.
-//
-// End Function Specification //////////////////////////////////////
-
-SCAN_COMM_REGISTER_CLASS::~SCAN_COMM_REGISTER_CLASS
-(
- void
- /*!i No parameters */
- )
-/*!o No value returned */
-{
-}
-
-// Function Specification ///////////////////////////////////////////
-//
-// Title: Read
-//
-// Purpose: This function reads the actual hardware register and
-// sets the Bit String data member values. The specified
-// Bit String is then used to mask the Bit String data
-// member. If an error occur, then the error is reported
-// and the Bit String values are undefined.
-//
-// Side-effects: Hardware register is read.
-// Bit String data member is modified.
-// Memory is reallocated.
-//
-// End Function Specification //////////////////////////////////////
-
-uint32_t SCAN_COMM_REGISTER_CLASS::Read
-(
- BitString & mask
- /*!i Reference to Bit String mask */
- )
-/*!o Error return code */
-{
- uint32_t rc = Read();
-
- if(rc == SUCCESS)
- {
- BitString & bitString = AccessBitString();
- bitString.maskString(mask);
- }
-
- return(rc);
-}
-// Function Specification //////////////////////////////////////////
-//
-// Title: Set Bit
-//
-// Purpose: This function sets(1) the specified bit position in
-// the Bit String. If the Bit String is NULL, then a
-// new Bit String is allocated and cleared to all zero
-// before setting the bit.
-//
-// Side-effects: Bit String is modified.
-// Memory may be allocated.
-//
-// Dependencies: bit_position must be in the string
-//
-// End Function Specification //////////////////////////////////////
-
-void SCAN_COMM_REGISTER_CLASS::SetBit
-(
- uint32_t bit_position
- /*!i Bit position in string */
- )
-/*!o No value returned */
-{
-
- BitString & bitString = AccessBitString();
- bitString.setBit(bit_position);
-}
-
-// Function Specification //////////////////////////////////////////
-//
-// Title: Clear Bit
-//
-// Purpose: This function clears(0) the specified bit position in
-// the Bit String. If the Bit String is NULL, then a
-// new Bit String is allocated and cleared to all zeros.
-//
-// Side-effects: Bit String is modified.
-// Memory may be allocated.
-//
-// Dependencies: bit_position must be in the string
-//
-// End Function Specification //////////////////////////////////////
-
-void SCAN_COMM_REGISTER_CLASS::ClearBit
-(
- uint32_t bit_position
- /*!i Bit position in string */
- )
-/*!o No value returned */
-{
- BitString & bitString = AccessBitString();
- bitString.clearBit(bit_position);
-}
-
-
-
-// Function Specification ///////////////////////////////////////////
-//
-// Title: Clear Bit String
-//
-// Purpose: This function clears the Bit String. If the data
-// member is NULL, then a new Bit String is allocated.
-// Upon return, the state of the Bit String is all zero.
-//
-// Side-effects: Bit String data member is modified.
-// Memory is allocated or reallocated.
-//
-// End Function Specification //////////////////////////////////////
-
-void SCAN_COMM_REGISTER_CLASS::clearAllBits()
-{
- BitString & bitString = AccessBitString();
- bitString.clearAll();
-}
-
-void SCAN_COMM_REGISTER_CLASS::setAllBits()
-{
- BitString & bitString = AccessBitString();
- bitString.setAll();
-}
-
-//------------------------------------------------------------------------------
-
-uint64_t SCAN_COMM_REGISTER_CLASS::GetBitFieldJustified( uint32_t i_pos,
- uint32_t i_len ) const
-{
- uint64_t o_value = 0;
-
- const uint32_t len_cpu_word = sizeof(CPU_WORD) * 8;
- const uint32_t len_uint64 = sizeof(uint64_t) * 8;
- const uint32_t pos_end = i_pos + i_len;
-
- PRDF_ASSERT( pos_end <= len_uint64 );
-
- const BitString * bs = GetBitString();
-
- for ( uint32_t pos = i_pos; pos < pos_end; pos += len_cpu_word )
- {
- // Calculate chunk length.
- uint32_t len_chunk = len_cpu_word;
- if ( len_chunk > pos_end - pos )
- len_chunk = pos_end - pos;
-
- o_value <<= len_chunk; // Make room for new chunk.
-
- // Get chunk.
- o_value |= static_cast<uint64_t>(bs->getFieldJustify(pos, len_chunk));
- }
-
- return o_value;
-}
-
-//------------------------------------------------------------------------------
-
-void SCAN_COMM_REGISTER_CLASS::SetBitFieldJustified( uint32_t i_pos,
- uint32_t i_len,
- uint64_t i_value )
-{
- const uint32_t len_cpu_word = sizeof(CPU_WORD) * 8;
- const uint32_t len_uint64 = sizeof(uint64_t) * 8;
-
- PRDF_ASSERT( i_pos + i_len <= len_uint64 );
-
- BitString & bs = AccessBitString();
-
- for ( uint32_t offset = 0; offset < i_len; offset += len_cpu_word )
- {
- // Calculate chunk length.
- uint32_t len_chunk = len_cpu_word;
- if ( len_chunk > i_len - offset )
- len_chunk = i_len - offset;
-
- uint64_t value = i_value;
- value >>= i_len - (offset + len_chunk); // right justify
-
- // Set chunk.
- bs.setFieldJustify( i_pos + offset, len_chunk,
- static_cast<CPU_WORD>(value) );
- }
-}
-
-} // end namespace libhei
-
diff --git a/src/register/hei_register.hpp b/src/register/hei_register.hpp
index be769f3..936d95e 100755
--- a/src/register/hei_register.hpp
+++ b/src/register/hei_register.hpp
@@ -1,404 +1,59 @@
#pragma once
-// Module Description **************************************************
-//
-// Description: This module contains the declarations for the
-// Processor Runtime Diagnostics Scan Communication
-// Register class.
-//
-// Notes: Unless stated otherwise, assume that each function
-// specification has no side-effects, no dependencies, and
-// constant time complexity.
-//
-// End Module Description **********************************************
-
-
-//----------------------------------------------------------------------
-// Includes
-//----------------------------------------------------------------------
-
+#include <stdio.h>
#include <hei_includes.hpp>
#include <util/hei_bit_string.hpp>
-#include <iipsdbug.h>
-#include <prdfMain.H>
-
namespace libhei
{
-/*--------------------------------------------------------------------*/
-/* Forward References */
-/*--------------------------------------------------------------------*/
-
-/*--------------------------------------------------------------------*/
-/* User Types */
-/*--------------------------------------------------------------------*/
-
-/*--------------------------------------------------------------------*/
-/* Constants */
-/*--------------------------------------------------------------------*/
-
-/*--------------------------------------------------------------------*/
-/* Macros */
-/*--------------------------------------------------------------------*/
-
-/*--------------------------------------------------------------------*/
-/* Global Variables */
-/*--------------------------------------------------------------------*/
-
-/*--------------------------------------------------------------------*/
-/* Function Prototypes */
-/*--------------------------------------------------------------------*/
-
-// Class Specification *************************************************
-//
-// Name: SCAN_COMM_REGISTER_CLASS
-//
-// Title: Scan Communication Register
-//
-// Purpose: SCAN_COMM_REGISTER_CLASS provides the representation
-// and access to a physical register.
-//
-// Usage: This is an abstract base class.
-//
-// Side-effects: Memory is allocated.
-//
-// Dependencies: None.
-//
-// Notes: The Scan Communication Register is a model of an actual
-// physical register. The bits in the register are represented by the
-// bit_string data member which is modified dynamically as operations
-// are preformed. It acts as a temporarily cached value of the
-// register. When a read is performed, the bit values are updated in
-// the bit string. When a write is performed, the current value of the
-// bits are used as the value to write. The current value of this
-// cached bit string can be accessed or modified by other objects via
-// the public interface. The physical address and bit length of the
-// hardware register are set during initialization and used on all
-// acceses.
-//
-// The basic Read() and Write() functions are virtual. The
-// actual implemenations are dependent on the actual hardware
-// and the software Hardware Manual Ops Scan Control Routines.
-// These function specifications describe a common behaviour
-// that every derived class must follow. Additional,
-// information may also be specified.
-//
-// A Read() function is also provided that has a Bit String
-// mask parameter. This function calls the virtual Read()
-// and then applies the mask so that the internal Bit String
-// contains the hardware register contents with certain bits
-// ignored (masked off).
-//
-// Cardinality: 0
-//
-// Space Complexity: Linear
-// K + Mn where K and M are constants and n is the
-// number of bits in the register.
-//
-// End Class Specification *********************************************
/**
- SCAN_COMM_REGISTER_CLASS
- @author Doug Gilbert
- @V5R2
- */
-class SCAN_COMM_REGISTER_CLASS
+@brief Description: The Register class.
+
+Purpose: Register is an abstract base class for real and virtual registers.
+A few examples of these registers are; HardwareRegister, ConstantRegister,
+NotRegister, and AndRegister. As a base class of register types, Register
+creates a place where these registers can be put together like logical
+building blocks. For example, Register makes this possible:
+
+Register * fir = new HardwareRegister(REG_ADDRESS, REG_WIDTH,
+ DEFAULT_CHIP_TYPE, ACCESS_RO);
+Register * mask = new ConstantRegister( 0xffffffff00000000 );
+Register * fir_mask = new AndRegister(fir, mask);
+const BitString * bs = fir_mask->getBitString();
+
+The getBitString function (defined by each register) provides access to
+the BitString that manages each register's data. In this example bs will
+contain the result of fir & mask.
+*/
+class Register
{
- public: // enums, structs, typedefs
-
- /** The register access level */
- enum AccessLevel
- {
- ACCESS_NONE = 0x0, ///< No access
- ACCESS_RO = 0x1, ///< Read-only access
- ACCESS_WO = 0x2, ///< Write-only access
- ACCESS_RW = 0x3, ///< Read/Write access
- };
-
- public: // functions
-
- /**
- Destructor
- */
- virtual ~SCAN_COMM_REGISTER_CLASS(void);
-
- /**
- Read hardware register (virtual)
- <ul>
- <br><b>Parameters: </b> None
- <br><b>Returns: </b> [SUCCESS | MOPs return code]
- <br><b>Requirements:</b> None.
- <br><b>Promises: </b> Internal bit string represents the value of the
- hardware register (if rc == SUCCESS)
- <br><b>Sideaffects: </b> Value guaranteed to be read from hardware.
- <br><b>Exceptions: </b> None.
- <br><b>Notes: </b> Default is to call Read(). If a child class cannot
- guarantee hardware access every time Read() is
- called then the function ForceRead() should be
- overridden.
- </ul><br>
- */
- virtual uint32_t ForceRead(void) const { return Read(); }
-
- /**
- Read hardware register (pure virtual)
- <ul>
- <br><b>Parameters: </b> None
- <br><b>Returns: </b> [SUCCESS | MOPs return code]
- <br><b>Requirements:</b> None.
- <br><b>Promises: </b> Internal bit string represents the value of the
- hardware register (if rc == SUCCESS)
- <br><b>Sideaffects: </b> The bit string value may or may not be retrieved
- from hardware; a buffered copy may be used.
- <br><b>Exceptions: </b> None.
- </ul><br>
- */
- virtual uint32_t Read(void) const = 0;
-
- /**
- Read hardware register and apply a mask
- <ul>
- <br><b>Parameters: </b> Mask to apply
- <br><b>Returns: </b> [SUCCESS | MOPs return code]
- <br><b>Requirements:</b> None.
- <br><b>Promises: </b> Internal bit string represents the value of the
- hardware register with the bits turned off as
- specified by the mask.
- <br><b>Sideaffects: </b> The bit string value may or may not be retrieved
- from hardware. a buffered copy may be used.
- <br><b>Exceptions: </b> None.
- <br><b>Notes: </b> if bits read from hardware = '00110100'
- and mask = '01110000'
- then internal bit sting = '00000100'
-
- if mask.Length() < GetBitString()->Length()
- then mask is right extended with 0's
- if mask.Length() > GetBitString()->Length()
- then extra mask bits are ignored.
- </ul><br>
- */
- uint32_t Read(BitString & mask);
-
- /**
- Write hardware register (pure virtual)
- <ul>
- <br><b>Parameters: </b> None
- <br><b>Returns: </b> [SUCCESS | MOPs return code]
- <br><b>Requirements:</b> None.
- <br><b>Promises: </b> Internal bit string value written to hardware
- <br><b>Exceptions: </b> None.
- <br><b>Notes: </b> If internal bitstring was never read/set/modified then
- zeros are written to corresponding hardware register.
- </ul><br>
- */
- virtual uint32_t Write(void) = 0;
-
- /**
- Access a copy of the scan comm address
- <ul>
- <br><b>Parameters: </b> None
- <br><b>Returns: </b> Returns scom address
- <br><b>Requirements:</b> None.
- <br><b>Promises: </b> None.
- <br><b>Exceptions: </b> None.
- </ul><br>
- */
- virtual uint64_t GetAddress(void) const {return 0 ;}
-
- /**
- Access a copy of the short id for signatures.
- <ul>
- <br><b>Parameters: </b> None
- <br><b>Returns: </b> ID.
- <br><b>Requirements:</b> None.
- <br><b>Promises: </b> None.
- <br><b>Exceptions: </b> None.
- </ul><br>
- */
- virtual uint16_t GetId(void) const = 0;
-
- /**
- Set the short id for signatures.
- <ul>
- <br><b>Parameters: </b> ID.
- <br><b>Returns: </b> None.
- <br><b>Requirements:</b> None.
- <br><b>Promises: </b> None.
- <br><b>Exceptions: </b> For virtual registers, this is not required to have
- any effect.
- </ul><br>
- */
- virtual void SetId(uint16_t) = 0;
-
-
- /**
- Access the bit length of the register
- <ul>
- <br><b>Parameters: </b> None
- <br><b>Returns: </b> bit length of the register
- <br><b>Requirements:</b> None.
- <br><b>Promises: </b> None.
- <br><b>Exceptions: </b> None.
- </ul><br>
- */
- virtual uint32_t GetBitLength(void) const { return DEFAULT_BIT_LENGTH ;}
-
- /**
- Access the internal bit string (pure virtual)
- <ul>
- <br><b>Parameters: </b> None
- <br><b>Returns: </b> ptr to the internal bit string (const)
- <br><b>Requirements:</b> None.
- <br><b>Promises: </b> None.
- <br><b>Exceptions: </b> None.
- <br><b>Notes: </b> If the internal bit string was never read/modified then
- all bits are zero
- </ul><br>
- */
- virtual
- const BitString * GetBitString(ATTENTION_TYPE
- i_type = INVALID_ATTENTION_TYPE
- ) const = 0;
-
- /**
- Modify the internal bit string (pure virtual)
- <ul>
- <br><b>Parameters: </b> a bit string
- <br><b>Returns: </b> Nothing
- <br><b>Requirements:</b> None.
- <br><b>Promises: </b> Internal bit string == *bs for first len bits where
- len is the smaller of the two lengths.
- Memory may be (re)allocated
- <br><b>Exceptions: </b> None.
- <br><b>Notes: </b> The hardware register value is not modified until
- Write() is called
- </ul><br>
- */
- virtual void SetBitString(const BitString * bs) = 0;
-
- /**
- SetBit
- <ul>
- <br><b>Parameters: </b> Position of bit to set (= 1)
- <br><b>Returns: </b> None.
- <br><b>Requirements:</b> bit position < GetBitString()->Length()
- <br><b>Promises: </b> GetBitString()->isBitSet(bit_position) == true
- <br><b>Exceptions: </b> None.
- <br><b> Notes: </b> Register value is not reflected in hardware until
- Write() is called
- </ul><br>
- */
- void SetBit(uint32_t bit_position);
-
- /**
- ClearBit (reset bit)
- <ul>
- <br><b>Parameters: </b> Position of bit to clear (= 0)
- <br><b>Returns: </b> None.
- <br><b>Requirements:</b> bit position < GetBitString()->Length()
- <br><b>Promises: </b> GetBitString()->isBitSet(bit_position) == false
- <br><b>Exceptions: </b> None.
- <br><b> Notes: </b> Register value is not reflected in hardware until
- Write() is called
- </ul><br>
- */
- void ClearBit(uint32_t bit_position);
+ public:
/**
- * @brief Will query if a bit is set.
- * @param i_bitPos The bit position to query.
- * @pre The bit position must be less than GetBitString()->Length()
- * @return TRUE if the bit is set, FALSE otherwise.
- */
- bool IsBitSet( uint32_t i_bitPos )
- { return GetBitString()->isBitSet(i_bitPos); }
-
- /** @brief Flushes all bits to 0. */
- void clearAllBits();
-
- /** @brief Flushes all bits to 1. */
- void setAllBits();
+ @brief Default constructor
+ */
+ Register() = default;
/**
- * @brief Returns target value from the BitString (right justified).
- * @param i_pos Starting position in the bit string.
- * @param i_len Length of target value.
- * @pre i_pos + i_len must be less than or equal 64 bits.
- * @return The target value (right justified).
- */
- uint64_t GetBitFieldJustified( uint32_t i_pos, uint32_t i_len ) const;
+ @brief Delete copy, assignment, and move operators. Deleting
+ copy causes the compiler to delete move.
+ */
+ Register(const Register&) = delete;
+ Register& operator=(const Register&) = delete;
/**
- * @brief Set a field within the BitString with a value (right justified).
- * @param i_pos Starting position in the bit string.
- * @param i_len Length of target value.
- * @param i_value Value to add to BitString.
- * @pre i_pos + i_len must be less than or equal 64 bits.
- */
- void SetBitFieldJustified( uint32_t i_pos, uint32_t i_len,
- uint64_t i_value );
+ @brief Default destructor
+ */
+ virtual ~Register() = default;
- /**
- Query if bit string is all zeros
- <ul>
- <br><b>Parameters: </b> None.
- <br><b>Returns: </b> [true | false]
- <br><b>Requirements:</b> None.
- <br><b>Promises: </b> None.
- <br><b>Exceptions: </b> None.
- </ul><br>
- */
- bool BitStringIsZero()
- { return GetBitString()->isZero(); }
-
- /**
- *@brief Returns TYPE_NA as type of Target associated with register.Actual
- * implementation is expected in derived class
- *@return TYPE_NA
- */
- virtual TARGETING::TYPE getChipType(void)const { return TARGETING::TYPE_NA; }
-
- /** @return The register access level (see enum AccessLevel). */
- virtual AccessLevel getAccessLevel() const { return ACCESS_RW; }
-
- /** @brief Sets the register access level (see enum AccessLevel). */
- virtual void setAccessLevel( AccessLevel i_op ) {}
-
-protected:
-
- /**
- Get modifiable reference to internal bit string (don't even thing about making this public!!!)
- <ul>
- <br><b>Parameters: </b> None.
- <br><b>Returns </b> Reference to the internal bit string
- <br><b>Requirments </b> None.
- <br><b>Promises </b> None.
- </ul><br>
- */
- virtual BitString & AccessBitString(void) = 0;
-private: // Data
- static const int DEFAULT_BIT_LENGTH = 64;
-
- // Enum Specification //////////////////////////////////////////////
- //
- // Purpose: These enumerated constants specify implementation data.
- //
- // End Enum Specification //////////////////////////////////////////
-
- enum
- {
- ODD_PARITY_SET_BIT_POSITION = 16
- };
-
- // Data Specification //////////////////////////////////////////////
- //
- // Purpose: These data members specify the physical properties of
- // register.
- //
- // End Data Specification //////////////////////////////////////////
-
+ /**
+ @brief Provides access to the BitString that manages
+ this register's data.
+ @return A pointer to a BitString.
+ */
+ virtual const BitString * getBitString() const = 0;
};
-} // end namespace libhei
-
+}//end namespace libhei
diff --git a/test/simulator/meson.build b/test/simulator/meson.build
index e581b1a..87b675b 100644
--- a/test/simulator/meson.build
+++ b/test/simulator/meson.build
@@ -1,6 +1,7 @@
sim_sources = [
'hei_sim_main.cpp',
- '../../src/isolator/hei_isolator.cpp'
+ '../../src/isolator/hei_isolator.cpp',
+ '../../src/util/hei_bit_string.cpp',
]
sim = executable('simulator', sim_sources, \