xref: /openbmc/openpower-hw-diags/analyzer/util.hpp (revision 8f60a621c72bcb134459e4bc5d2cf8b3fa3b41d8)
1*8f60a621SZane Shelley #pragma once
2*8f60a621SZane Shelley 
3*8f60a621SZane Shelley /**
4*8f60a621SZane Shelley  * @brief Specially utilities that are specific to the analyzer (typically
5*8f60a621SZane Shelley  *        stuff that involves libhei).
6*8f60a621SZane Shelley  */
7*8f60a621SZane Shelley 
8*8f60a621SZane Shelley #include <hei_main.hpp>
9*8f60a621SZane Shelley #include <util/bin_stream.hpp>
10*8f60a621SZane Shelley 
11*8f60a621SZane Shelley namespace util
12*8f60a621SZane Shelley {
13*8f60a621SZane Shelley 
14*8f60a621SZane Shelley /** @brief Extracts big-endian data to host RegisterId_t. */
15*8f60a621SZane Shelley template <>
operator >>(libhei::RegisterId_t & r)16*8f60a621SZane Shelley inline BinFileReader& BinFileReader::operator>>(libhei::RegisterId_t& r)
17*8f60a621SZane Shelley {
18*8f60a621SZane Shelley     // A register ID is only 3 bytes, but there isn't a 3-byte integer type.
19*8f60a621SZane Shelley     // So extract 3 bytes to a uint32_t and drop the unused byte.
20*8f60a621SZane Shelley     uint32_t tmp = 0;
21*8f60a621SZane Shelley     read(&tmp, 3);
22*8f60a621SZane Shelley     r = static_cast<libhei::RegisterId_t>(be32toh(tmp) >> 8);
23*8f60a621SZane Shelley     return *this;
24*8f60a621SZane Shelley }
25*8f60a621SZane Shelley 
26*8f60a621SZane Shelley /** @brief Inserts host RegisterId_t to big-endian data. */
27*8f60a621SZane Shelley template <>
operator <<(libhei::RegisterId_t r)28*8f60a621SZane Shelley inline BinFileWriter& BinFileWriter::operator<<(libhei::RegisterId_t r)
29*8f60a621SZane Shelley {
30*8f60a621SZane Shelley     // A register ID is only 3 bytes, but there isn't a 3-byte integer type.
31*8f60a621SZane Shelley     // So extract 3 bytes to a uint32_t and drop the unused byte.
32*8f60a621SZane Shelley     uint32_t tmp = htobe32(static_cast<uint32_t>(r) << 8);
33*8f60a621SZane Shelley     write(&tmp, 3);
34*8f60a621SZane Shelley     return *this;
35*8f60a621SZane Shelley }
36*8f60a621SZane Shelley 
37*8f60a621SZane Shelley } // namespace util
38