Add helper functions to swap between guest byte order and host byte
order that take a guest endianness as a parameter. These functions are
called htog and htog to be consistent with the helper functions that
extract guest byte order from a compile time constant.
Change-Id: Ie6be7dfd3b7a58ad6bfb57b25be5f85b5f425929
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/8201
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
#error Invalid Endianess
#endif
+template <typename T>
+inline T htog(T value, ByteOrder guest_byte_order)
+{
+ return guest_byte_order == BigEndianByteOrder ?
+ htobe(value) : htole(value);
+}
+
+template <typename T>
+inline T gtoh(T value, ByteOrder guest_byte_order)
+{
+ return guest_byte_order == BigEndianByteOrder ?
+ betoh(value) : letoh(value);
+}
+
namespace BigEndianGuest
{
const ByteOrder GuestByteOrder = BigEndianByteOrder;