summaryrefslogtreecommitdiffstats
path: root/src/import
diff options
context:
space:
mode:
authorChristian Geddes <crgeddes@us.ibm.com>2018-11-29 18:38:19 -0600
committerRaja Das <rajadas2@in.ibm.com>2019-07-26 00:53:32 -0500
commitf8a9eff2853ede884ddd0da06914aba4294f25e0 (patch)
tree70fe746e29b4c5ad271438431659dc123ed08ae7 /src/import
parentaab9c4426e90397844b66a4640a3b9ae5b706d5e (diff)
downloadtalos-sbe-f8a9eff2853ede884ddd0da06914aba4294f25e0.tar.gz
talos-sbe-f8a9eff2853ede884ddd0da06914aba4294f25e0.zip
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: I953170acd40521a0dd940d7bc5e184c5e09c8bce Original-Change-Id: If5374c9a8ad12e391f78e3ea323776fdd8567b4f Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/69269 Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com> Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com> Tested-by: Hostboot CI <hostboot-ci+hostboot@us.ibm.com> Reviewed-by: ANDRE A. MARIN <aamarin@us.ibm.com> Reviewed-by: Louis Stermole <stermole@us.ibm.com> Reviewed-by: Jennifer A. Stofer <stofer@us.ibm.com>
Diffstat (limited to 'src/import')
-rw-r--r--src/import/generic/memory/lib/utils/endian_utils.H47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/import/generic/memory/lib/utils/endian_utils.H b/src/import/generic/memory/lib/utils/endian_utils.H
index 446dcc86..6675e553 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<uint8_t>& 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);
@@ -84,6 +84,51 @@ inline void forceLEArray(const T* i_input, const uint64_t i_size, std::vector<ui
}
///
+/// @brief Forces native data into BE order
+/// @tparam T the data type to process
+/// @param[in] i_input inputted data to process
+/// @param[in,out] io_data vector to append data to
+///
+template < typename T >
+void forceBE(const T& i_input, std::vector<uint8_t>& io_data)
+{
+ // Temporary variable to process - we'll be doing bit shifts below
+ T l_temp = i_input;
+
+ std::vector<uint8_t> 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<uint8_t>& 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
/// @param[in] i_input inputted data to process
OpenPOWER on IntegriCloud