From: Chuan Zhu Date: Wed, 2 Aug 2017 08:52:28 +0000 (+0100) Subject: sim: Add gtoh/htog helpers that take an explicit endianness X-Git-Tag: v19.0.0.0~2298 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d5231d14af1fbc52c9325b51cacb86bf2fd91686;p=gem5.git 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 Reviewed-on: https://gem5-review.googlesource.com/8201 Reviewed-by: Jason Lowe-Power --- 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 inline T betoh(T value) {return swap_byte(value);} #error Invalid Endianess #endif +template +inline T htog(T value, ByteOrder guest_byte_order) +{ + return guest_byte_order == BigEndianByteOrder ? + htobe(value) : htole(value); +} + +template +inline T gtoh(T value, ByteOrder guest_byte_order) +{ + return guest_byte_order == BigEndianByteOrder ? + betoh(value) : letoh(value); +} + namespace BigEndianGuest { const ByteOrder GuestByteOrder = BigEndianByteOrder;