From 8d09d845a7373cce52d3943f5dca1a2ac34a4f83 Mon Sep 17 00:00:00 2001 From: Marcus Comstedt Date: Sun, 11 Oct 2020 13:36:13 +0200 Subject: Implement support for big-endian targets --- fesvr/htif.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'fesvr/htif.h') diff --git a/fesvr/htif.h b/fesvr/htif.h index 44a3b12..66a626d 100644 --- a/fesvr/htif.h +++ b/fesvr/htif.h @@ -6,9 +6,11 @@ #include "memif.h" #include "syscall.h" #include "device.h" +#include "byteorder.h" #include #include #include +#include class htif_t : public chunked_memif_t { @@ -27,6 +29,30 @@ class htif_t : public chunked_memif_t virtual memif_t& memif() { return mem; } + template inline T from_target(T n) const + { +#ifdef RISCV_ENABLE_DUAL_ENDIAN + memif_endianness_t endianness = get_target_endianness(); + assert(endianness == memif_endianness_little || endianness == memif_endianness_big); + + return endianness == memif_endianness_big? from_be(n) : from_le(n); +#else + return from_le(n); +#endif + } + + template inline T to_target(T n) const + { +#ifdef RISCV_ENABLE_DUAL_ENDIAN + memif_endianness_t endianness = get_target_endianness(); + assert(endianness == memif_endianness_little || endianness == memif_endianness_big); + + return endianness == memif_endianness_big? to_be(n) : to_le(n); +#else + return to_le(n); +#endif + } + protected: virtual void reset() = 0; -- cgit v1.1