From cda012113b8dd35fc6d440ea05c9e37ca9c71af6 Mon Sep 17 00:00:00 2001 From: Christian Geddes Date: Thu, 29 Nov 2018 18:38:19 -0600 Subject: Add forceBE option to endian_utils.H There are some helper function to force LE and I found a case where I wanted to force BE so I added here also. Change-Id: If5374c9a8ad12e391f78e3ea323776fdd8567b4f Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/69269 Tested-by: FSP CI Jenkins Tested-by: Jenkins Server Tested-by: Hostboot CI Reviewed-by: ANDRE A. MARIN Reviewed-by: Louis Stermole Reviewed-by: Jennifer A. Stofer Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/69272 Tested-by: Jenkins OP Build CI Tested-by: Jenkins OP HW Reviewed-by: Christian R. Geddes --- src/import/generic/memory/lib/utils/endian_utils.H | 47 +++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'src/import/generic') diff --git a/src/import/generic/memory/lib/utils/endian_utils.H b/src/import/generic/memory/lib/utils/endian_utils.H index 5d59be68b..369148701 100644 --- a/src/import/generic/memory/lib/utils/endian_utils.H +++ b/src/import/generic/memory/lib/utils/endian_utils.H @@ -58,7 +58,7 @@ void forceLE(const T& i_input, std::vector& io_data) for(size_t i = 0; i < sizeof(i_input); i++) { - // Grab the lowe rorder byte and add it to the back of the vector + // Grab the lowest order byte and add it to the back of the vector const uint8_t l_byte = l_temp & 0xFF; io_data.push_back(l_byte); @@ -83,6 +83,51 @@ inline void forceLEArray(const T* i_input, const uint64_t i_size, std::vector +void forceBE(const T& i_input, std::vector& io_data) +{ + // Temporary variable to process - we'll be doing bit shifts below + T l_temp = i_input; + + std::vector l_tempBuffer; + + // This loop will put i_input into l_tempBuffer in BE order + for(size_t i = 0; i < sizeof(i_input); i++) + { + // Grab the lowest order byte and add it to the front of the vector + const uint8_t l_byte = l_temp & 0xFF; + l_tempBuffer.insert(l_tempBuffer.begin(), l_byte); + + // Shift higher byte value into lowest no matter existing endianness + l_temp >>= BITS_PER_BYTE; + } + + // Put the new BE formatted data at the end of the input buffer + io_data.insert(io_data.end(), l_tempBuffer.begin(), l_tempBuffer.end()); +} + +/// +/// @brief Forces native data into BE order for an array +/// @tparam T the data type to process +/// @param[in] i_input inputted data to process +/// @param[in] i_size size of the array +/// @param[in,out] io_data vector to append data to +/// +template < typename T > +inline void forceBEArray(const T* i_input, const uint64_t i_size, std::vector& io_data) +{ + for(size_t i = 0; i < i_size; i++) + { + forceBE(i_input[i], io_data); + } +} + /// /// @brief Converts LE data into native order /// @tparam T the data type to output to -- cgit v1.2.1