summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChuan Zhu <chuan.zhu@arm.com>2017-08-02 09:52:28 +0100
committerAndreas Sandberg <andreas.sandberg@arm.com>2018-02-16 09:25:14 +0000
commitd5231d14af1fbc52c9325b51cacb86bf2fd91686 (patch)
treec77656b38ac245cc7a9875c2e34d7a17ab2d958e
parentcf58af7cf2402a280d6789797a9bc956209bdc30 (diff)
downloadgem5-d5231d14af1fbc52c9325b51cacb86bf2fd91686.tar.xz
sim: Add gtoh/htog helpers that take an explicit endianness
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>
-rw-r--r--src/sim/byteswap.hh14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/sim/byteswap.hh b/src/sim/byteswap.hh
index 2c3517f24..a46f8f591 100644
--- a/src/sim/byteswap.hh
+++ b/src/sim/byteswap.hh
@@ -154,6 +154,20 @@ template <typename T> inline T betoh(T value) {return swap_byte(value);}
#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;