From 51992fa80af477097ece177610ec9e05aef03df4 Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Fri, 21 Aug 2020 11:53:18 +0100 Subject: [PATCH] base, sim: Make ByteOrder into a ScopedEnum accessible to Python There is currently no good way of passing a byte order as a Param since the ByteOrder type is defined in C++. Make this into a generated ScopedEnum that can be used in Params. Change-Id: I990f402340c17c4e0799de57df19516ae61794d4 Signed-off-by: Andreas Sandberg Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/33174 Tested-by: kokoro Reviewed-by: Gabe Black --- src/arch/arm/aapcs32.hh | 4 +- src/arch/arm/freebsd/freebsd.hh | 2 +- src/arch/arm/isa_traits.hh | 2 +- src/arch/arm/linux/linux.hh | 2 +- src/arch/arm/process.cc | 4 +- src/arch/arm/utility.hh | 2 +- src/arch/generic/memhelpers.hh | 20 +-- src/arch/mips/isa_traits.hh | 2 +- src/arch/mips/linux/linux.hh | 2 +- src/arch/mips/process.cc | 4 +- src/arch/power/isa_traits.hh | 2 +- src/arch/power/linux/linux.hh | 2 +- src/arch/power/process.cc | 4 +- src/arch/riscv/isa_traits.hh | 2 +- src/arch/riscv/linux/linux.hh | 2 +- src/arch/sparc/isa_traits.hh | 2 +- src/arch/sparc/linux/linux.hh | 2 +- src/arch/sparc/process.cc | 4 +- src/arch/sparc/solaris/solaris.hh | 2 +- src/arch/x86/isa_traits.hh | 2 +- src/arch/x86/linux/linux.hh | 2 +- src/arch/x86/process.cc | 4 +- src/base/pixel.cc | 8 +- src/base/pixel.hh | 2 +- src/base/types.hh | 7 +- src/base/vnc/vncserver.cc | 4 +- src/dev/arm/amba_device.cc | 2 +- src/dev/arm/fvp_base_pwr_ctrl.cc | 4 +- src/dev/arm/generic_timer.cc | 8 +- src/dev/arm/gic_v3.cc | 4 +- src/dev/arm/gic_v3_its.cc | 2 +- src/dev/arm/hdlcd.cc | 2 +- src/dev/arm/kmi.cc | 6 +- src/dev/arm/pl011.cc | 2 +- src/dev/arm/pl111.cc | 10 +- src/dev/arm/rtc_pl031.cc | 2 +- src/dev/arm/watchdog_sp805.cc | 6 +- src/dev/serial/simple.cc | 2 +- src/mem/cache/prefetch/base.hh | 4 +- src/mem/packet_access.hh | 8 +- src/python/m5/params.py | 8 + src/sim/byteswap.hh | 8 +- src/sim/byteswap.test.cc | 288 +++++++++++++++--------------- 43 files changed, 233 insertions(+), 228 deletions(-) diff --git a/src/arch/arm/aapcs32.hh b/src/arch/arm/aapcs32.hh index 7f40bd39b..3cd2c50fd 100644 --- a/src/arch/arm/aapcs32.hh +++ b/src/arch/arm/aapcs32.hh @@ -165,7 +165,7 @@ struct Result::value) { tc->setIntReg(ArmISA::INTREG_R0, (uint32_t)i); - } else if (ArmISA::byteOrder(tc) == LittleEndianByteOrder) { + } else if (ArmISA::byteOrder(tc) == ByteOrder::little) { tc->setIntReg(ArmISA::INTREG_R0, (uint32_t)(i >> 0)); tc->setIntReg(ArmISA::INTREG_R1, (uint32_t)(i >> 32)); } else { @@ -213,7 +213,7 @@ struct ArgumentreadIntReg(state.ncrn++) & mask(32); high = tc->readIntReg(state.ncrn++) & mask(32); } else { diff --git a/src/arch/arm/freebsd/freebsd.hh b/src/arch/arm/freebsd/freebsd.hh index b1360473e..ef9da65fa 100644 --- a/src/arch/arm/freebsd/freebsd.hh +++ b/src/arch/arm/freebsd/freebsd.hh @@ -38,7 +38,7 @@ class ArmFreebsd : public FreeBSD { public: - static const ByteOrder byteOrder = LittleEndianByteOrder; + static const ByteOrder byteOrder = ByteOrder::little; }; class ArmFreebsd32 : public ArmFreebsd diff --git a/src/arch/arm/isa_traits.hh b/src/arch/arm/isa_traits.hh index 4a7312c4c..81d4b4f94 100644 --- a/src/arch/arm/isa_traits.hh +++ b/src/arch/arm/isa_traits.hh @@ -46,7 +46,7 @@ namespace ArmISA { - const ByteOrder GuestByteOrder = LittleEndianByteOrder; + const ByteOrder GuestByteOrder = ByteOrder::little; const Addr PageShift = 12; const Addr PageBytes = ULL(1) << PageShift; diff --git a/src/arch/arm/linux/linux.hh b/src/arch/arm/linux/linux.hh index 6aee4466d..5fd6cdc0c 100644 --- a/src/arch/arm/linux/linux.hh +++ b/src/arch/arm/linux/linux.hh @@ -48,7 +48,7 @@ class ArmLinux : public Linux { public: - static const ByteOrder byteOrder = LittleEndianByteOrder; + static const ByteOrder byteOrder = ByteOrder::little; static void archClone(uint64_t flags, diff --git a/src/arch/arm/process.cc b/src/arch/arm/process.cc index c5ef141e3..1734066cc 100644 --- a/src/arch/arm/process.cc +++ b/src/arch/arm/process.cc @@ -435,9 +435,9 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) auxv_array_end += sizeof(zero); copyStringArray(envp, envp_array_base, env_data_base, - LittleEndianByteOrder, *initVirtMem); + ByteOrder::little, *initVirtMem); copyStringArray(argv, argv_array_base, arg_data_base, - LittleEndianByteOrder, *initVirtMem); + ByteOrder::little, *initVirtMem); initVirtMem->writeBlob(argc_base, &guestArgc, intSize); diff --git a/src/arch/arm/utility.hh b/src/arch/arm/utility.hh index f17ebc5f9..636625d8b 100644 --- a/src/arch/arm/utility.hh +++ b/src/arch/arm/utility.hh @@ -448,7 +448,7 @@ uint8_t encodePhysAddrRange64(int pa_size); inline ByteOrder byteOrder(const ThreadContext *tc) { - return isBigEndian64(tc) ? BigEndianByteOrder : LittleEndianByteOrder; + return isBigEndian64(tc) ? ByteOrder::big : ByteOrder::little; }; bool isUnpriviledgeAccess(ThreadContext * tc); diff --git a/src/arch/generic/memhelpers.hh b/src/arch/generic/memhelpers.hh index d08bea914..2a5a380e3 100644 --- a/src/arch/generic/memhelpers.hh +++ b/src/arch/generic/memhelpers.hh @@ -72,14 +72,14 @@ template void getMemLE(PacketPtr pkt, MemT &mem, Trace::InstRecord *traceData) { - getMem(pkt, mem, traceData); + getMem(pkt, mem, traceData); } template void getMemBE(PacketPtr pkt, MemT &mem, Trace::InstRecord *traceData) { - getMem(pkt, mem, traceData); + getMem(pkt, mem, traceData); } /// Read from memory in atomic mode. @@ -103,7 +103,7 @@ Fault readMemAtomicLE(XC *xc, Trace::InstRecord *traceData, Addr addr, MemT &mem, Request::Flags flags) { - return readMemAtomic( + return readMemAtomic( xc, traceData, addr, mem, flags); } @@ -112,7 +112,7 @@ Fault readMemAtomicBE(XC *xc, Trace::InstRecord *traceData, Addr addr, MemT &mem, Request::Flags flags) { - return readMemAtomic(xc, traceData, addr, mem, flags); + return readMemAtomic(xc, traceData, addr, mem, flags); } /// Write to memory in timing mode. @@ -133,7 +133,7 @@ Fault writeMemTimingLE(XC *xc, Trace::InstRecord *traceData, MemT mem, Addr addr, Request::Flags flags, uint64_t *res) { - return writeMemTiming( + return writeMemTiming( xc, traceData, mem, addr, flags, res); } @@ -142,7 +142,7 @@ Fault writeMemTimingBE(XC *xc, Trace::InstRecord *traceData, MemT mem, Addr addr, Request::Flags flags, uint64_t *res) { - return writeMemTiming( + return writeMemTiming( xc, traceData, mem, addr, flags, res); } @@ -172,7 +172,7 @@ Fault writeMemAtomicLE(XC *xc, Trace::InstRecord *traceData, const MemT &mem, Addr addr, Request::Flags flags, uint64_t *res) { - return writeMemAtomic( + return writeMemAtomic( xc, traceData, mem, addr, flags, res); } @@ -181,7 +181,7 @@ Fault writeMemAtomicBE(XC *xc, Trace::InstRecord *traceData, const MemT &mem, Addr addr, Request::Flags flags, uint64_t *res) { - return writeMemAtomic( + return writeMemAtomic( xc, traceData, mem, addr, flags, res); } @@ -213,7 +213,7 @@ Fault amoMemAtomicLE(XC *xc, Trace::InstRecord *traceData, MemT &mem, Addr addr, Request::Flags flags, AtomicOpFunctor *_amo_op) { - return amoMemAtomic( + return amoMemAtomic( xc, traceData, mem, addr, flags, _amo_op); } @@ -222,7 +222,7 @@ Fault amoMemAtomicBE(XC *xc, Trace::InstRecord *traceData, MemT &mem, Addr addr, Request::Flags flags, AtomicOpFunctor *_amo_op) { - return amoMemAtomic( + return amoMemAtomic( xc, traceData, mem, addr, flags, _amo_op); } diff --git a/src/arch/mips/isa_traits.hh b/src/arch/mips/isa_traits.hh index 5aa167eb4..aac595a2d 100644 --- a/src/arch/mips/isa_traits.hh +++ b/src/arch/mips/isa_traits.hh @@ -35,7 +35,7 @@ namespace MipsISA { -const ByteOrder GuestByteOrder = LittleEndianByteOrder; +const ByteOrder GuestByteOrder = ByteOrder::little; const Addr PageShift = 13; const Addr PageBytes = ULL(1) << PageShift; diff --git a/src/arch/mips/linux/linux.hh b/src/arch/mips/linux/linux.hh index 4fcc71072..ca24c8999 100644 --- a/src/arch/mips/linux/linux.hh +++ b/src/arch/mips/linux/linux.hh @@ -35,7 +35,7 @@ class MipsLinux : public Linux { public: - static const ByteOrder byteOrder = LittleEndianByteOrder; + static const ByteOrder byteOrder = ByteOrder::little; static const int TGT_SIGHUP = 0x000001; static const int TGT_SIGINT = 0x000002; diff --git a/src/arch/mips/process.cc b/src/arch/mips/process.cc index cdda2b293..f8916af8b 100644 --- a/src/arch/mips/process.cc +++ b/src/arch/mips/process.cc @@ -170,10 +170,10 @@ MipsProcess::argsInit(int pageSize) initVirtMem->writeBlob(memState->getStackMin(), &argc, intSize); copyStringArray(argv, argv_array_base, arg_data_base, - LittleEndianByteOrder, *initVirtMem); + ByteOrder::little, *initVirtMem); copyStringArray(envp, envp_array_base, env_data_base, - LittleEndianByteOrder, *initVirtMem); + ByteOrder::little, *initVirtMem); // Fix up the aux vectors which point to data. for (auto &aux: auxv) { diff --git a/src/arch/power/isa_traits.hh b/src/arch/power/isa_traits.hh index ba7b2f390..4cf0c4430 100644 --- a/src/arch/power/isa_traits.hh +++ b/src/arch/power/isa_traits.hh @@ -36,7 +36,7 @@ namespace PowerISA { -const ByteOrder GuestByteOrder = BigEndianByteOrder; +const ByteOrder GuestByteOrder = ByteOrder::big; const Addr PageShift = 12; const Addr PageBytes = ULL(1) << PageShift; diff --git a/src/arch/power/linux/linux.hh b/src/arch/power/linux/linux.hh index 40dfbfbb1..86936cb2d 100644 --- a/src/arch/power/linux/linux.hh +++ b/src/arch/power/linux/linux.hh @@ -40,7 +40,7 @@ class PowerLinux : public Linux { public: - static const ByteOrder byteOrder = BigEndianByteOrder; + static const ByteOrder byteOrder = ByteOrder::big; typedef int32_t time_t; diff --git a/src/arch/power/process.cc b/src/arch/power/process.cc index 8168482c4..19834e999 100644 --- a/src/arch/power/process.cc +++ b/src/arch/power/process.cc @@ -261,9 +261,9 @@ PowerProcess::argsInit(int intSize, int pageSize) auxv_array_end += sizeof(zero); copyStringArray(envp, envp_array_base, env_data_base, - BigEndianByteOrder, *initVirtMem); + ByteOrder::big, *initVirtMem); copyStringArray(argv, argv_array_base, arg_data_base, - BigEndianByteOrder, *initVirtMem); + ByteOrder::big, *initVirtMem); initVirtMem->writeBlob(argc_base, &guestArgc, intSize); diff --git a/src/arch/riscv/isa_traits.hh b/src/arch/riscv/isa_traits.hh index 1bb2d264e..4cf455db8 100644 --- a/src/arch/riscv/isa_traits.hh +++ b/src/arch/riscv/isa_traits.hh @@ -47,7 +47,7 @@ namespace RiscvISA { -const ByteOrder GuestByteOrder = LittleEndianByteOrder; +const ByteOrder GuestByteOrder = ByteOrder::little; const Addr PageShift = 12; const Addr PageBytes = ULL(1) << PageShift; diff --git a/src/arch/riscv/linux/linux.hh b/src/arch/riscv/linux/linux.hh index 89c114db8..0b10b7a48 100644 --- a/src/arch/riscv/linux/linux.hh +++ b/src/arch/riscv/linux/linux.hh @@ -35,7 +35,7 @@ class RiscvLinux : public Linux { public: - static const ByteOrder byteOrder = LittleEndianByteOrder; + static const ByteOrder byteOrder = ByteOrder::little; }; class RiscvLinux64 : public RiscvLinux diff --git a/src/arch/sparc/isa_traits.hh b/src/arch/sparc/isa_traits.hh index e1917f910..3f7cdac0f 100644 --- a/src/arch/sparc/isa_traits.hh +++ b/src/arch/sparc/isa_traits.hh @@ -34,7 +34,7 @@ namespace SparcISA { -const ByteOrder GuestByteOrder = BigEndianByteOrder; +const ByteOrder GuestByteOrder = ByteOrder::big; const Addr PageShift = 13; const Addr PageBytes = ULL(1) << PageShift; diff --git a/src/arch/sparc/linux/linux.hh b/src/arch/sparc/linux/linux.hh index 89cd207fb..ed50a30c3 100644 --- a/src/arch/sparc/linux/linux.hh +++ b/src/arch/sparc/linux/linux.hh @@ -36,7 +36,7 @@ class SparcLinux : public Linux { public: - static const ByteOrder byteOrder = BigEndianByteOrder; + static const ByteOrder byteOrder = ByteOrder::big; struct tgt_stat { diff --git a/src/arch/sparc/process.cc b/src/arch/sparc/process.cc index d28189cdb..159f58237 100644 --- a/src/arch/sparc/process.cc +++ b/src/arch/sparc/process.cc @@ -381,9 +381,9 @@ SparcProcess::argsInit(int pageSize) auxv_array_end += sizeof(zero); copyStringArray(envp, envp_array_base, env_data_base, - BigEndianByteOrder, *initVirtMem); + ByteOrder::big, *initVirtMem); copyStringArray(argv, argv_array_base, arg_data_base, - BigEndianByteOrder, *initVirtMem); + ByteOrder::big, *initVirtMem); initVirtMem->writeBlob(argc_base, &guestArgc, intSize); diff --git a/src/arch/sparc/solaris/solaris.hh b/src/arch/sparc/solaris/solaris.hh index 5ca811d25..0462832c4 100644 --- a/src/arch/sparc/solaris/solaris.hh +++ b/src/arch/sparc/solaris/solaris.hh @@ -35,7 +35,7 @@ class SparcSolaris : public Solaris { public: - static const ByteOrder byteOrder = BigEndianByteOrder; + static const ByteOrder byteOrder = ByteOrder::big; static SyscallFlagTransTable openFlagTable[]; diff --git a/src/arch/x86/isa_traits.hh b/src/arch/x86/isa_traits.hh index ce90b4bbd..dee98dc3a 100644 --- a/src/arch/x86/isa_traits.hh +++ b/src/arch/x86/isa_traits.hh @@ -42,7 +42,7 @@ namespace X86ISA { - const ByteOrder GuestByteOrder = LittleEndianByteOrder; + const ByteOrder GuestByteOrder = ByteOrder::little; const Addr PageShift = 12; const Addr PageBytes = ULL(1) << PageShift; diff --git a/src/arch/x86/linux/linux.hh b/src/arch/x86/linux/linux.hh index 470512321..de27a742b 100644 --- a/src/arch/x86/linux/linux.hh +++ b/src/arch/x86/linux/linux.hh @@ -46,7 +46,7 @@ class X86Linux : public Linux { public: - static const ByteOrder byteOrder = LittleEndianByteOrder; + static const ByteOrder byteOrder = ByteOrder::little; static void archClone(uint64_t flags, diff --git a/src/arch/x86/process.cc b/src/arch/x86/process.cc index 0324e9420..7718fdcaa 100644 --- a/src/arch/x86/process.cc +++ b/src/arch/x86/process.cc @@ -969,9 +969,9 @@ X86Process::argsInit(int pageSize, initVirtMem->writeString(aux_data_base, platform.c_str()); copyStringArray(envp, envp_array_base, env_data_base, - LittleEndianByteOrder, *initVirtMem); + ByteOrder::little, *initVirtMem); copyStringArray(argv, argv_array_base, arg_data_base, - LittleEndianByteOrder, *initVirtMem); + ByteOrder::little, *initVirtMem); initVirtMem->writeBlob(argc_base, &guestArgc, intSize); diff --git a/src/base/pixel.cc b/src/base/pixel.cc index 44cb2d1cc..c21d0f192 100644 --- a/src/base/pixel.cc +++ b/src/base/pixel.cc @@ -43,10 +43,10 @@ const PixelConverter PixelConverter::rgba8888_le(4, 0, 8, 16, 8, 8, 8); const PixelConverter PixelConverter::rgba8888_be(4, 0, 8, 16, 8, 8, 8, - BigEndianByteOrder); + ByteOrder::big); const PixelConverter PixelConverter::rgb565_le(2, 0, 5, 11, 5, 6, 5); const PixelConverter PixelConverter::rgb565_be(2, 0, 5, 11, 5, 6, 5, - BigEndianByteOrder); + ByteOrder::big); PixelConverter::PixelConverter(unsigned _length, unsigned ro, unsigned go, unsigned bo, @@ -74,7 +74,7 @@ PixelConverter::readWord(const uint8_t *p) const { uint32_t word(0); - if (byte_order == LittleEndianByteOrder) { + if (byte_order == ByteOrder::little) { for (int i = 0; i < length; ++i) word |= p[i] << (8 * i); } else { @@ -88,7 +88,7 @@ PixelConverter::readWord(const uint8_t *p) const void PixelConverter::writeWord(uint8_t *p, uint32_t word) const { - if (byte_order == LittleEndianByteOrder) { + if (byte_order == ByteOrder::little) { for (int i = 0; i < length; ++i) p[i] = (word >> (8 * i)) & 0xFF; } else { diff --git a/src/base/pixel.hh b/src/base/pixel.hh index a1c2b9a9f..7937e8956 100644 --- a/src/base/pixel.hh +++ b/src/base/pixel.hh @@ -127,7 +127,7 @@ class PixelConverter PixelConverter(unsigned length, unsigned ro, unsigned go, unsigned bo, unsigned rw, unsigned gw, unsigned bw, - ByteOrder byte_order = LittleEndianByteOrder); + ByteOrder byte_order = ByteOrder::little); /** Get the Pixel representation of a color word. */ Pixel toPixel(uint32_t word) const { diff --git a/src/base/types.hh b/src/base/types.hh index 4f606cd26..7ae573dd7 100644 --- a/src/base/types.hh +++ b/src/base/types.hh @@ -43,6 +43,8 @@ #include #include "base/refcnt.hh" +/* Hide the fact that this enum is generated by Python */ +#include "enums/ByteOrder.hh" /** uint64_t constant */ #define ULL(N) ((uint64_t)N##ULL) @@ -242,9 +244,4 @@ typedef std::shared_ptr Fault; // we just create an alias. constexpr decltype(nullptr) NoFault = nullptr; -enum ByteOrder { - BigEndianByteOrder, - LittleEndianByteOrder -}; - #endif // __BASE_TYPES_HH__ diff --git a/src/base/vnc/vncserver.cc b/src/base/vnc/vncserver.cc index c6b1fe661..dbf4d9c16 100644 --- a/src/base/vnc/vncserver.cc +++ b/src/base/vnc/vncserver.cc @@ -75,7 +75,7 @@ const PixelConverter VncServer::pixelConverter( 4, // 4 bytes / pixel 16, 8, 0, // R in [23, 16], G in [15, 8], B in [7, 0] 8, 8, 8, // 8 bits / channel - LittleEndianByteOrder); + ByteOrder::little); /** @file * Implementiation of a VNC server @@ -130,7 +130,7 @@ VncServer::VncServer(const Params *p) // around for telling the client and making sure it cooperates pixelFormat.bpp = 8 * pixelConverter.length; pixelFormat.depth = pixelConverter.depth; - pixelFormat.bigendian = pixelConverter.byte_order == BigEndianByteOrder; + pixelFormat.bigendian = pixelConverter.byte_order == ByteOrder::big; pixelFormat.truecolor = 1; pixelFormat.redmax = pixelConverter.ch_r.mask; pixelFormat.greenmax = pixelConverter.ch_g.mask; diff --git a/src/dev/arm/amba_device.cc b/src/dev/arm/amba_device.cc index 76872b197..4daf94327 100644 --- a/src/dev/arm/amba_device.cc +++ b/src/dev/arm/amba_device.cc @@ -81,6 +81,6 @@ AmbaDevice::readId(PacketPtr pkt, uint64_t amba_id, Addr pio_addr) (amba_id >> byte) & 0xFF, pkt->getAddr() - pio_addr, byte); - pkt->setUintX((amba_id >> byte) & 0xFF, LittleEndianByteOrder); + pkt->setUintX((amba_id >> byte) & 0xFF, ByteOrder::little); return true; } diff --git a/src/dev/arm/fvp_base_pwr_ctrl.cc b/src/dev/arm/fvp_base_pwr_ctrl.cc index 7ab4e4091..86275989b 100644 --- a/src/dev/arm/fvp_base_pwr_ctrl.cc +++ b/src/dev/arm/fvp_base_pwr_ctrl.cc @@ -151,7 +151,7 @@ FVPBasePwrCtrl::read(PacketPtr pkt) DPRINTF(FVPBasePwrCtrl, "FVPBasePwrCtrl::read: 0x%x<-0x%x(%i)\n", resp, addr, size); - pkt->setUintX(resp, LittleEndianByteOrder); + pkt->setUintX(resp, ByteOrder::little); pkt->makeResponse(); return pioDelay; } @@ -163,7 +163,7 @@ FVPBasePwrCtrl::write(PacketPtr pkt) const size_t size = pkt->getSize(); panic_if(size != 4, "FVPBasePwrCtrl::write: Invalid size %i\n", size); - uint64_t data = pkt->getUintX(LittleEndianByteOrder); + uint64_t data = pkt->getUintX(ByteOrder::little); // Software may use the power controller to check for core presence // If core is not present, return an invalid MPID as notification diff --git a/src/dev/arm/generic_timer.cc b/src/dev/arm/generic_timer.cc index da8de08bd..254175a7d 100644 --- a/src/dev/arm/generic_timer.cc +++ b/src/dev/arm/generic_timer.cc @@ -999,7 +999,7 @@ GenericTimerFrame::read(PacketPtr pkt) DPRINTF(Timer, "GenericTimerFrame::read: 0x%x<-0x%x(%i) [S = %u]\n", resp, addr, size, is_sec); - pkt->setUintX(resp, LittleEndianByteOrder); + pkt->setUintX(resp, ByteOrder::little); pkt->makeResponse(); return 0; } @@ -1014,7 +1014,7 @@ GenericTimerFrame::write(PacketPtr pkt) "GenericTimerFrame::write: Invalid size %i\n", size); bool to_el0 = false; - const uint64_t data = pkt->getUintX(LittleEndianByteOrder); + const uint64_t data = pkt->getUintX(ByteOrder::little); Addr offset = 0; if (timerRange.contains(addr)) { offset = addr - timerRange.start(); @@ -1313,7 +1313,7 @@ GenericTimerMem::read(PacketPtr pkt) DPRINTF(Timer, "GenericTimerMem::read: 0x%x<-0x%x(%i) [S = %u]\n", resp, addr, size, is_sec); - pkt->setUintX(resp, LittleEndianByteOrder); + pkt->setUintX(resp, ByteOrder::little); pkt->makeResponse(); return 0; } @@ -1327,7 +1327,7 @@ GenericTimerMem::write(PacketPtr pkt) panic_if(size != 4 && size != 8, "GenericTimerMem::write: Invalid size %i\n", size); - const uint64_t data = pkt->getUintX(LittleEndianByteOrder); + const uint64_t data = pkt->getUintX(ByteOrder::little); if (counterCtrlRange.contains(addr)) counterCtrlWrite(addr - counterCtrlRange.start(), size, data, is_sec); else if (counterStatusRange.contains(addr)) diff --git a/src/dev/arm/gic_v3.cc b/src/dev/arm/gic_v3.cc index 83f2c8321..596f170f2 100644 --- a/src/dev/arm/gic_v3.cc +++ b/src/dev/arm/gic_v3.cc @@ -127,7 +127,7 @@ Gicv3::read(PacketPtr pkt) panic("Gicv3::read(): unknown address %#x\n", addr); } - pkt->setUintX(resp, LittleEndianByteOrder); + pkt->setUintX(resp, ByteOrder::little); pkt->makeAtomicResponse(); return delay; } @@ -136,7 +136,7 @@ Tick Gicv3::write(PacketPtr pkt) { const size_t size = pkt->getSize(); - uint64_t data = pkt->getUintX(LittleEndianByteOrder); + uint64_t data = pkt->getUintX(ByteOrder::little); const Addr addr = pkt->getAddr(); bool is_secure_access = pkt->isSecure(); Tick delay = 0; diff --git a/src/dev/arm/gic_v3_its.cc b/src/dev/arm/gic_v3_its.cc index 442008f51..4ea721958 100644 --- a/src/dev/arm/gic_v3_its.cc +++ b/src/dev/arm/gic_v3_its.cc @@ -882,7 +882,7 @@ Gicv3Its::read(PacketPtr pkt) } } - pkt->setUintX(value, LittleEndianByteOrder); + pkt->setUintX(value, ByteOrder::little); pkt->makeAtomicResponse(); return pioDelay; } diff --git a/src/dev/arm/hdlcd.cc b/src/dev/arm/hdlcd.cc index 347844950..cf5995a84 100644 --- a/src/dev/arm/hdlcd.cc +++ b/src/dev/arm/hdlcd.cc @@ -434,7 +434,7 @@ PixelConverter HDLcd::pixelConverter() const { ByteOrder byte_order( - pixel_format.big_endian ? BigEndianByteOrder : LittleEndianByteOrder); + pixel_format.big_endian ? ByteOrder::big : ByteOrder::little); /* Some Linux kernels have a broken driver that swaps the red and * blue color select registers. */ diff --git a/src/dev/arm/kmi.cc b/src/dev/arm/kmi.cc index 246fedb39..517a79ffe 100644 --- a/src/dev/arm/kmi.cc +++ b/src/dev/arm/kmi.cc @@ -95,7 +95,7 @@ Pl050::read(PacketPtr pkt) default: if (readId(pkt, ambaId, pioAddr)) { // Hack for variable size accesses - data = pkt->getUintX(LittleEndianByteOrder); + data = pkt->getUintX(ByteOrder::little); break; } @@ -103,7 +103,7 @@ Pl050::read(PacketPtr pkt) break; } - pkt->setUintX(data, LittleEndianByteOrder); + pkt->setUintX(data, ByteOrder::little); pkt->makeAtomicResponse(); return pioDelay; } @@ -115,7 +115,7 @@ Pl050::write(PacketPtr pkt) assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize); Addr daddr = pkt->getAddr() - pioAddr; - const uint32_t data = pkt->getUintX(LittleEndianByteOrder); + const uint32_t data = pkt->getUintX(ByteOrder::little); panic_if(pkt->getSize() != 1, "PL050: Unexpected write size " diff --git a/src/dev/arm/pl011.cc b/src/dev/arm/pl011.cc index a60276d5c..9b83cf8c7 100755 --- a/src/dev/arm/pl011.cc +++ b/src/dev/arm/pl011.cc @@ -137,7 +137,7 @@ Pl011::read(PacketPtr pkt) default: if (readId(pkt, AMBA_ID, pioAddr)) { // Hack for variable size accesses - data = pkt->getUintX(LittleEndianByteOrder); + data = pkt->getUintX(ByteOrder::little); break; } diff --git a/src/dev/arm/pl111.cc b/src/dev/arm/pl111.cc index 111de0358..f36b33f17 100644 --- a/src/dev/arm/pl111.cc +++ b/src/dev/arm/pl111.cc @@ -182,7 +182,7 @@ Pl111::read(PacketPtr pkt) default: if (readId(pkt, AMBA_ID, pioAddr)) { // Hack for variable size accesses - data = pkt->getUintX(LittleEndianByteOrder); + data = pkt->getUintX(ByteOrder::little); break; } else if (daddr >= CrsrImage && daddr <= 0xBFC) { // CURSOR IMAGE @@ -203,7 +203,7 @@ Pl111::read(PacketPtr pkt) } } - pkt->setUintX(data, LittleEndianByteOrder); + pkt->setUintX(data, ByteOrder::little); pkt->makeAtomicResponse(); return pioDelay; } @@ -215,7 +215,7 @@ Pl111::write(PacketPtr pkt) // use a temporary data since the LCD registers are read/written with // different size operations // - const uint32_t data = pkt->getUintX(LittleEndianByteOrder); + const uint32_t data = pkt->getUintX(ByteOrder::little); assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize); @@ -383,13 +383,13 @@ Pl111::pixelConverter() const bytesPerPixel, offsets[2], offsets[1], offsets[0], rw, gw, bw, - LittleEndianByteOrder); + ByteOrder::little); } else { return PixelConverter( bytesPerPixel, offsets[0], offsets[1], offsets[2], rw, gw, bw, - LittleEndianByteOrder); + ByteOrder::little); } } diff --git a/src/dev/arm/rtc_pl031.cc b/src/dev/arm/rtc_pl031.cc index b2b232249..3ff478f73 100644 --- a/src/dev/arm/rtc_pl031.cc +++ b/src/dev/arm/rtc_pl031.cc @@ -90,7 +90,7 @@ PL031::read(PacketPtr pkt) default: if (readId(pkt, ambaId, pioAddr)) { // Hack for variable sized access - data = pkt->getUintX(LittleEndianByteOrder); + data = pkt->getUintX(ByteOrder::little); break; } panic("Tried to read PL031 at offset %#x that doesn't exist\n", daddr); diff --git a/src/dev/arm/watchdog_sp805.cc b/src/dev/arm/watchdog_sp805.cc index 3fd7006ae..32417e020 100644 --- a/src/dev/arm/watchdog_sp805.cc +++ b/src/dev/arm/watchdog_sp805.cc @@ -93,7 +93,7 @@ Sp805::read(PacketPtr pkt) break; default: if (readId(pkt, ambaId, pioAddr)) - resp = pkt->getUintX(LittleEndianByteOrder); + resp = pkt->getUintX(ByteOrder::little); else warn("Sp805::read: Unexpected address (0x%x:%i), assuming RAZ\n", addr, size); @@ -101,7 +101,7 @@ Sp805::read(PacketPtr pkt) DPRINTF(Sp805, "Sp805::read: 0x%x<-0x%x(%i)\n", resp, addr, size); - pkt->setUintX(resp, LittleEndianByteOrder); + pkt->setUintX(resp, ByteOrder::little); pkt->makeResponse(); return pioDelay; } @@ -113,7 +113,7 @@ Sp805::write(PacketPtr pkt) const size_t size = pkt->getSize(); panic_if(size != 4, "Sp805::write: Invalid size %i\n", size); - uint64_t data = pkt->getUintX(LittleEndianByteOrder); + uint64_t data = pkt->getUintX(ByteOrder::little); switch (addr) { case WDOGLOAD: if (writeAccessEnabled) { diff --git a/src/dev/serial/simple.cc b/src/dev/serial/simple.cc index 9450b89bf..97018abbe 100644 --- a/src/dev/serial/simple.cc +++ b/src/dev/serial/simple.cc @@ -44,7 +44,7 @@ SimpleUart::SimpleUart(const SimpleUartParams *p) : Uart(p, p->pio_size), - byteOrder(p->big_endian ? BigEndianByteOrder : LittleEndianByteOrder), + byteOrder(p->big_endian ? ByteOrder::big : ByteOrder::little), endOnEOT(p->end_on_eot) { } diff --git a/src/mem/cache/prefetch/base.hh b/src/mem/cache/prefetch/base.hh index cdd0f5bd4..4afacf0d7 100644 --- a/src/mem/cache/prefetch/base.hh +++ b/src/mem/cache/prefetch/base.hh @@ -206,10 +206,10 @@ class Base : public ClockedObject panic("PrefetchInfo::get called with a request with no data."); } switch (endian) { - case BigEndianByteOrder: + case ByteOrder::big: return betoh(*(T*)data); - case LittleEndianByteOrder: + case ByteOrder::little: return letoh(*(T*)data); default: diff --git a/src/mem/packet_access.hh b/src/mem/packet_access.hh index 98f328332..2190840e6 100644 --- a/src/mem/packet_access.hh +++ b/src/mem/packet_access.hh @@ -82,10 +82,10 @@ inline T Packet::get(ByteOrder endian) const { switch (endian) { - case BigEndianByteOrder: + case ByteOrder::big: return getBE(); - case LittleEndianByteOrder: + case ByteOrder::little: return getLE(); default: @@ -112,10 +112,10 @@ inline void Packet::set(T v, ByteOrder endian) { switch (endian) { - case BigEndianByteOrder: + case ByteOrder::big: return setBE(v); - case LittleEndianByteOrder: + case ByteOrder::little: return setLE(v); default: diff --git a/src/python/m5/params.py b/src/python/m5/params.py index c5d26d4ea..4e586671f 100644 --- a/src/python/m5/params.py +++ b/src/python/m5/params.py @@ -1513,6 +1513,14 @@ class ScopedEnum(Enum): # If not None, use this as the enum name rather than this class name enum_name = None +class ByteOrder(ScopedEnum): + """Enum representing component's byte order (endianness)""" + + vals = [ + 'big', + 'little', + ] + # how big does a rounding error need to be before we warn about it? frequency_tolerance = 0.001 # 0.1% diff --git a/src/sim/byteswap.hh b/src/sim/byteswap.hh index 06205cd6e..fbe0302f8 100644 --- a/src/sim/byteswap.hh +++ b/src/sim/byteswap.hh @@ -136,13 +136,13 @@ template inline T letobe(T value) {return swap_byte(value);} //For conversions not involving the guest system, we can define the functions //conditionally based on the BYTE_ORDER macro and outside of the namespaces #if (defined(_BIG_ENDIAN) || !defined(_LITTLE_ENDIAN)) && BYTE_ORDER == BIG_ENDIAN -const ByteOrder HostByteOrder = BigEndianByteOrder; +const ByteOrder HostByteOrder = ByteOrder::big; template inline T htole(T value) {return swap_byte(value);} template inline T letoh(T value) {return swap_byte(value);} template inline T htobe(T value) {return value;} template inline T betoh(T value) {return value;} #elif defined(_LITTLE_ENDIAN) || BYTE_ORDER == LITTLE_ENDIAN -const ByteOrder HostByteOrder = LittleEndianByteOrder; +const ByteOrder HostByteOrder = ByteOrder::little; template inline T htole(T value) {return value;} template inline T letoh(T value) {return value;} template inline T htobe(T value) {return swap_byte(value);} @@ -154,14 +154,14 @@ template inline T betoh(T value) {return swap_byte(value);} template inline T htog(T value, ByteOrder guest_byte_order) { - return guest_byte_order == BigEndianByteOrder ? + return guest_byte_order == ByteOrder::big ? htobe(value) : htole(value); } template inline T gtoh(T value, ByteOrder guest_byte_order) { - return guest_byte_order == BigEndianByteOrder ? + return guest_byte_order == ByteOrder::big ? betoh(value) : letoh(value); } diff --git a/src/sim/byteswap.test.cc b/src/sim/byteswap.test.cc index 08c4dd320..27e1fc616 100644 --- a/src/sim/byteswap.test.cc +++ b/src/sim/byteswap.test.cc @@ -86,102 +86,102 @@ TEST(ByteswapTest, htog) { #if (defined(_BIG_ENDIAN)||!defined(_LITTLE_ENDIAN)) && BYTE_ORDER==BIG_ENDIAN EXPECT_EQ(0xefcdab8967452301, htog((uint64_t)0xefcdab8967452301, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0x1032547698badcfe, htog((uint64_t)0x1032547698badcfe, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0xb14171b771b01c0b, htog((uint64_t)0xb14171b771b01c0b, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0xffffffff00000000, htog((uint64_t)0xffffffff00000000, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0x5555555555555555, htog((uint64_t)0x5555555555555555, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0xa0a0a0a0a0a0a0a0, htog((uint64_t)0xa0a0a0a0a0a0a0a0, - BigEndianByteOrder)); - EXPECT_EQ(0xefcd2301, htog((uint32_t)0xefcd2301, BigEndianByteOrder)); - EXPECT_EQ(0x1032dcfe, htog((uint32_t)0x1032dcfe, BigEndianByteOrder)); - EXPECT_EQ(0xb1411c0b, htog((uint32_t)0xb1411c0b, BigEndianByteOrder)); - EXPECT_EQ(0xffff0000, htog((uint32_t)0xffff0000, BigEndianByteOrder)); - EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, BigEndianByteOrder)); - EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, BigEndianByteOrder)); - EXPECT_EQ(0xef01, htog((uint16_t)0xef01, BigEndianByteOrder)); - EXPECT_EQ(0x10fe, htog((uint16_t)0x10fe, BigEndianByteOrder)); - EXPECT_EQ(0xb10b, htog((uint16_t)0xb10b, BigEndianByteOrder)); - EXPECT_EQ(0xff00, htog((uint16_t)0xff00, BigEndianByteOrder)); - EXPECT_EQ(0x5555, htog((uint16_t)0x5555, BigEndianByteOrder)); - EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, BigEndianByteOrder)); + ByteOrder::big)); + EXPECT_EQ(0xefcd2301, htog((uint32_t)0xefcd2301, ByteOrder::big)); + EXPECT_EQ(0x1032dcfe, htog((uint32_t)0x1032dcfe, ByteOrder::big)); + EXPECT_EQ(0xb1411c0b, htog((uint32_t)0xb1411c0b, ByteOrder::big)); + EXPECT_EQ(0xffff0000, htog((uint32_t)0xffff0000, ByteOrder::big)); + EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, ByteOrder::big)); + EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, ByteOrder::big)); + EXPECT_EQ(0xef01, htog((uint16_t)0xef01, ByteOrder::big)); + EXPECT_EQ(0x10fe, htog((uint16_t)0x10fe, ByteOrder::big)); + EXPECT_EQ(0xb10b, htog((uint16_t)0xb10b, ByteOrder::big)); + EXPECT_EQ(0xff00, htog((uint16_t)0xff00, ByteOrder::big)); + EXPECT_EQ(0x5555, htog((uint16_t)0x5555, ByteOrder::big)); + EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, ByteOrder::big)); EXPECT_EQ(0x0123456789abcdef, htog((uint64_t)0xefcdab8967452301, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0xfedcba9876543210, htog((uint64_t)0x1032547698badcfe, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0x0b1cb071b77141b1, htog((uint64_t)0xb14171b771b01c0b, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0x00000000ffffffff, htog((uint64_t)0xffffffff00000000, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0x5555555555555555, htog((uint64_t)0x5555555555555555, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0xa0a0a0a0a0a0a0a0, htog((uint64_t)0xa0a0a0a0a0a0a0a0, - LittleEndianByteOrder)); - EXPECT_EQ(0x0123cdef, htog((uint32_t)0xefcd2301, LittleEndianByteOrder)); - EXPECT_EQ(0xfedc3210, htog((uint32_t)0x1032dcfe, LittleEndianByteOrder)); - EXPECT_EQ(0x0b1c41b1, htog((uint32_t)0xb1411c0b, LittleEndianByteOrder)); - EXPECT_EQ(0x0000ffff, htog((uint32_t)0xffff0000, LittleEndianByteOrder)); - EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, LittleEndianByteOrder)); - EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, LittleEndianByteOrder)); - EXPECT_EQ(0x01ef, htog((uint16_t)0xef01, LittleEndianByteOrder)); - EXPECT_EQ(0xfe10, htog((uint16_t)0x10fe, LittleEndianByteOrder)); - EXPECT_EQ(0x0bb1, htog((uint16_t)0xb10b, LittleEndianByteOrder)); - EXPECT_EQ(0x00ff, htog((uint16_t)0xff00, LittleEndianByteOrder)); - EXPECT_EQ(0x5555, htog((uint16_t)0x5555, LittleEndianByteOrder)); - EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, LittleEndianByteOrder)); + ByteOrder::little)); + EXPECT_EQ(0x0123cdef, htog((uint32_t)0xefcd2301, ByteOrder::little)); + EXPECT_EQ(0xfedc3210, htog((uint32_t)0x1032dcfe, ByteOrder::little)); + EXPECT_EQ(0x0b1c41b1, htog((uint32_t)0xb1411c0b, ByteOrder::little)); + EXPECT_EQ(0x0000ffff, htog((uint32_t)0xffff0000, ByteOrder::little)); + EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, ByteOrder::little)); + EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, ByteOrder::little)); + EXPECT_EQ(0x01ef, htog((uint16_t)0xef01, ByteOrder::little)); + EXPECT_EQ(0xfe10, htog((uint16_t)0x10fe, ByteOrder::little)); + EXPECT_EQ(0x0bb1, htog((uint16_t)0xb10b, ByteOrder::little)); + EXPECT_EQ(0x00ff, htog((uint16_t)0xff00, ByteOrder::little)); + EXPECT_EQ(0x5555, htog((uint16_t)0x5555, ByteOrder::little)); + EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, ByteOrder::little)); #elif defined(_LITTLE_ENDIAN) || BYTE_ORDER==LITTLE_ENDIAN EXPECT_EQ(0x0123456789abcdef, htog((uint64_t)0xefcdab8967452301, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0xfedcba9876543210, htog((uint64_t)0x1032547698badcfe, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0x0b1cb071b77141b1, htog((uint64_t)0xb14171b771b01c0b, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0x00000000ffffffff, htog((uint64_t)0xffffffff00000000, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0x5555555555555555, htog((uint64_t)0x5555555555555555, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0xa0a0a0a0a0a0a0a0, htog((uint64_t)0xa0a0a0a0a0a0a0a0, - BigEndianByteOrder)); - EXPECT_EQ(0x0123cdef, htog((uint32_t)0xefcd2301, BigEndianByteOrder)); - EXPECT_EQ(0xfedc3210, htog((uint32_t)0x1032dcfe, BigEndianByteOrder)); - EXPECT_EQ(0x0b1c41b1, htog((uint32_t)0xb1411c0b, BigEndianByteOrder)); - EXPECT_EQ(0x0000ffff, htog((uint32_t)0xffff0000, BigEndianByteOrder)); - EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, BigEndianByteOrder)); - EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, BigEndianByteOrder)); - EXPECT_EQ(0x01ef, htog((uint16_t)0xef01, BigEndianByteOrder)); - EXPECT_EQ(0xfe10, htog((uint16_t)0x10fe, BigEndianByteOrder)); - EXPECT_EQ(0x0bb1, htog((uint16_t)0xb10b, BigEndianByteOrder)); - EXPECT_EQ(0x00ff, htog((uint16_t)0xff00, BigEndianByteOrder)); - EXPECT_EQ(0x5555, htog((uint16_t)0x5555, BigEndianByteOrder)); - EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, BigEndianByteOrder)); + ByteOrder::big)); + EXPECT_EQ(0x0123cdef, htog((uint32_t)0xefcd2301, ByteOrder::big)); + EXPECT_EQ(0xfedc3210, htog((uint32_t)0x1032dcfe, ByteOrder::big)); + EXPECT_EQ(0x0b1c41b1, htog((uint32_t)0xb1411c0b, ByteOrder::big)); + EXPECT_EQ(0x0000ffff, htog((uint32_t)0xffff0000, ByteOrder::big)); + EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, ByteOrder::big)); + EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, ByteOrder::big)); + EXPECT_EQ(0x01ef, htog((uint16_t)0xef01, ByteOrder::big)); + EXPECT_EQ(0xfe10, htog((uint16_t)0x10fe, ByteOrder::big)); + EXPECT_EQ(0x0bb1, htog((uint16_t)0xb10b, ByteOrder::big)); + EXPECT_EQ(0x00ff, htog((uint16_t)0xff00, ByteOrder::big)); + EXPECT_EQ(0x5555, htog((uint16_t)0x5555, ByteOrder::big)); + EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, ByteOrder::big)); EXPECT_EQ(0xefcdab8967452301, htog((uint64_t)0xefcdab8967452301, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0x1032547698badcfe, htog((uint64_t)0x1032547698badcfe, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0xb14171b771b01c0b, htog((uint64_t)0xb14171b771b01c0b, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0xffffffff00000000, htog((uint64_t)0xffffffff00000000, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0x5555555555555555, htog((uint64_t)0x5555555555555555, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0xa0a0a0a0a0a0a0a0, htog((uint64_t)0xa0a0a0a0a0a0a0a0, - LittleEndianByteOrder)); - EXPECT_EQ(0xefcd2301, htog((uint32_t)0xefcd2301, LittleEndianByteOrder)); - EXPECT_EQ(0x1032dcfe, htog((uint32_t)0x1032dcfe, LittleEndianByteOrder)); - EXPECT_EQ(0xb1411c0b, htog((uint32_t)0xb1411c0b, LittleEndianByteOrder)); - EXPECT_EQ(0xffff0000, htog((uint32_t)0xffff0000, LittleEndianByteOrder)); - EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, LittleEndianByteOrder)); - EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, LittleEndianByteOrder)); - EXPECT_EQ(0xef01, htog((uint16_t)0xef01, LittleEndianByteOrder)); - EXPECT_EQ(0x10fe, htog((uint16_t)0x10fe, LittleEndianByteOrder)); - EXPECT_EQ(0xb10b, htog((uint16_t)0xb10b, LittleEndianByteOrder)); - EXPECT_EQ(0xff00, htog((uint16_t)0xff00, LittleEndianByteOrder)); - EXPECT_EQ(0x5555, htog((uint16_t)0x5555, LittleEndianByteOrder)); - EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, LittleEndianByteOrder)); + ByteOrder::little)); + EXPECT_EQ(0xefcd2301, htog((uint32_t)0xefcd2301, ByteOrder::little)); + EXPECT_EQ(0x1032dcfe, htog((uint32_t)0x1032dcfe, ByteOrder::little)); + EXPECT_EQ(0xb1411c0b, htog((uint32_t)0xb1411c0b, ByteOrder::little)); + EXPECT_EQ(0xffff0000, htog((uint32_t)0xffff0000, ByteOrder::little)); + EXPECT_EQ(0x55555555, htog((uint32_t)0x55555555, ByteOrder::little)); + EXPECT_EQ(0xa0a0a0a0, htog((uint32_t)0xa0a0a0a0, ByteOrder::little)); + EXPECT_EQ(0xef01, htog((uint16_t)0xef01, ByteOrder::little)); + EXPECT_EQ(0x10fe, htog((uint16_t)0x10fe, ByteOrder::little)); + EXPECT_EQ(0xb10b, htog((uint16_t)0xb10b, ByteOrder::little)); + EXPECT_EQ(0xff00, htog((uint16_t)0xff00, ByteOrder::little)); + EXPECT_EQ(0x5555, htog((uint16_t)0x5555, ByteOrder::little)); + EXPECT_EQ(0xa0a0, htog((uint16_t)0xa0a0, ByteOrder::little)); #else #error Invalid Endianess #endif @@ -191,102 +191,102 @@ TEST(ByteswapTest, gtoh) { #if (defined(_BIG_ENDIAN)||!defined(_LITTLE_ENDIAN)) && BYTE_ORDER==BIG_ENDIAN EXPECT_EQ(0xefcdab8967452301, gtoh((uint64_t)0xefcdab8967452301, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0x1032547698badcfe, gtoh((uint64_t)0x1032547698badcfe, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0xb14171b771b01c0b, gtoh((uint64_t)0xb14171b771b01c0b, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0xffffffff00000000, gtoh((uint64_t)0xffffffff00000000, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0x5555555555555555, gtoh((uint64_t)0x5555555555555555, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0xa0a0a0a0a0a0a0a0, gtoh((uint64_t)0xa0a0a0a0a0a0a0a0, - BigEndianByteOrder)); - EXPECT_EQ(0xefcd2301, gtoh((uint32_t)0xefcd2301, BigEndianByteOrder)); - EXPECT_EQ(0x1032dcfe, gtoh((uint32_t)0x1032dcfe, BigEndianByteOrder)); - EXPECT_EQ(0xb1411c0b, gtoh((uint32_t)0xb1411c0b, BigEndianByteOrder)); - EXPECT_EQ(0xffff0000, gtoh((uint32_t)0xffff0000, BigEndianByteOrder)); - EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, BigEndianByteOrder)); - EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, BigEndianByteOrder)); - EXPECT_EQ(0xef01, gtoh((uint16_t)0xef01, BigEndianByteOrder)); - EXPECT_EQ(0x10fe, gtoh((uint16_t)0x10fe, BigEndianByteOrder)); - EXPECT_EQ(0xb10b, gtoh((uint16_t)0xb10b, BigEndianByteOrder)); - EXPECT_EQ(0xff00, gtoh((uint16_t)0xff00, BigEndianByteOrder)); - EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, BigEndianByteOrder)); - EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, BigEndianByteOrder)); + ByteOrder::big)); + EXPECT_EQ(0xefcd2301, gtoh((uint32_t)0xefcd2301, ByteOrder::big)); + EXPECT_EQ(0x1032dcfe, gtoh((uint32_t)0x1032dcfe, ByteOrder::big)); + EXPECT_EQ(0xb1411c0b, gtoh((uint32_t)0xb1411c0b, ByteOrder::big)); + EXPECT_EQ(0xffff0000, gtoh((uint32_t)0xffff0000, ByteOrder::big)); + EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, ByteOrder::big)); + EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, ByteOrder::big)); + EXPECT_EQ(0xef01, gtoh((uint16_t)0xef01, ByteOrder::big)); + EXPECT_EQ(0x10fe, gtoh((uint16_t)0x10fe, ByteOrder::big)); + EXPECT_EQ(0xb10b, gtoh((uint16_t)0xb10b, ByteOrder::big)); + EXPECT_EQ(0xff00, gtoh((uint16_t)0xff00, ByteOrder::big)); + EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, ByteOrder::big)); + EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, ByteOrder::big)); EXPECT_EQ(0x0123456789abcdef, gtoh((uint64_t)0xefcdab8967452301, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0xfedcba9876543210, gtoh((uint64_t)0x1032547698badcfe, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0x0b1cb071b77141b1, gtoh((uint64_t)0xb14171b771b01c0b, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0x00000000ffffffff, gtoh((uint64_t)0xffffffff00000000, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0x5555555555555555, gtoh((uint64_t)0x5555555555555555, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0xa0a0a0a0a0a0a0a0, gtoh((uint64_t)0xa0a0a0a0a0a0a0a0, - LittleEndianByteOrder)); - EXPECT_EQ(0x0123cdef, gtoh((uint32_t)0xefcd2301, LittleEndianByteOrder)); - EXPECT_EQ(0xfedc3210, gtoh((uint32_t)0x1032dcfe, LittleEndianByteOrder)); - EXPECT_EQ(0x0b1c41b1, gtoh((uint32_t)0xb1411c0b, LittleEndianByteOrder)); - EXPECT_EQ(0x0000ffff, gtoh((uint32_t)0xffff0000, LittleEndianByteOrder)); - EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, LittleEndianByteOrder)); - EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, LittleEndianByteOrder)); - EXPECT_EQ(0x01ef, gtoh((uint16_t)0xef01, LittleEndianByteOrder)); - EXPECT_EQ(0xfe10, gtoh((uint16_t)0x10fe, LittleEndianByteOrder)); - EXPECT_EQ(0x0bb1, gtoh((uint16_t)0xb10b, LittleEndianByteOrder)); - EXPECT_EQ(0x00ff, gtoh((uint16_t)0xff00, LittleEndianByteOrder)); - EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, LittleEndianByteOrder)); - EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, LittleEndianByteOrder)); + ByteOrder::little)); + EXPECT_EQ(0x0123cdef, gtoh((uint32_t)0xefcd2301, ByteOrder::little)); + EXPECT_EQ(0xfedc3210, gtoh((uint32_t)0x1032dcfe, ByteOrder::little)); + EXPECT_EQ(0x0b1c41b1, gtoh((uint32_t)0xb1411c0b, ByteOrder::little)); + EXPECT_EQ(0x0000ffff, gtoh((uint32_t)0xffff0000, ByteOrder::little)); + EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, ByteOrder::little)); + EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, ByteOrder::little)); + EXPECT_EQ(0x01ef, gtoh((uint16_t)0xef01, ByteOrder::little)); + EXPECT_EQ(0xfe10, gtoh((uint16_t)0x10fe, ByteOrder::little)); + EXPECT_EQ(0x0bb1, gtoh((uint16_t)0xb10b, ByteOrder::little)); + EXPECT_EQ(0x00ff, gtoh((uint16_t)0xff00, ByteOrder::little)); + EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, ByteOrder::little)); + EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, ByteOrder::little)); #elif defined(_LITTLE_ENDIAN) || BYTE_ORDER==LITTLE_ENDIAN EXPECT_EQ(0x0123456789abcdef, gtoh((uint64_t)0xefcdab8967452301, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0xfedcba9876543210, gtoh((uint64_t)0x1032547698badcfe, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0x0b1cb071b77141b1, gtoh((uint64_t)0xb14171b771b01c0b, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0x00000000ffffffff, gtoh((uint64_t)0xffffffff00000000, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0x5555555555555555, gtoh((uint64_t)0x5555555555555555, - BigEndianByteOrder)); + ByteOrder::big)); EXPECT_EQ(0xa0a0a0a0a0a0a0a0, gtoh((uint64_t)0xa0a0a0a0a0a0a0a0, - BigEndianByteOrder)); - EXPECT_EQ(0x0123cdef, gtoh((uint32_t)0xefcd2301, BigEndianByteOrder)); - EXPECT_EQ(0xfedc3210, gtoh((uint32_t)0x1032dcfe, BigEndianByteOrder)); - EXPECT_EQ(0x0b1c41b1, gtoh((uint32_t)0xb1411c0b, BigEndianByteOrder)); - EXPECT_EQ(0x0000ffff, gtoh((uint32_t)0xffff0000, BigEndianByteOrder)); - EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, BigEndianByteOrder)); - EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, BigEndianByteOrder)); - EXPECT_EQ(0x01ef, gtoh((uint16_t)0xef01, BigEndianByteOrder)); - EXPECT_EQ(0xfe10, gtoh((uint16_t)0x10fe, BigEndianByteOrder)); - EXPECT_EQ(0x0bb1, gtoh((uint16_t)0xb10b, BigEndianByteOrder)); - EXPECT_EQ(0x00ff, gtoh((uint16_t)0xff00, BigEndianByteOrder)); - EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, BigEndianByteOrder)); - EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, BigEndianByteOrder)); + ByteOrder::big)); + EXPECT_EQ(0x0123cdef, gtoh((uint32_t)0xefcd2301, ByteOrder::big)); + EXPECT_EQ(0xfedc3210, gtoh((uint32_t)0x1032dcfe, ByteOrder::big)); + EXPECT_EQ(0x0b1c41b1, gtoh((uint32_t)0xb1411c0b, ByteOrder::big)); + EXPECT_EQ(0x0000ffff, gtoh((uint32_t)0xffff0000, ByteOrder::big)); + EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, ByteOrder::big)); + EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, ByteOrder::big)); + EXPECT_EQ(0x01ef, gtoh((uint16_t)0xef01, ByteOrder::big)); + EXPECT_EQ(0xfe10, gtoh((uint16_t)0x10fe, ByteOrder::big)); + EXPECT_EQ(0x0bb1, gtoh((uint16_t)0xb10b, ByteOrder::big)); + EXPECT_EQ(0x00ff, gtoh((uint16_t)0xff00, ByteOrder::big)); + EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, ByteOrder::big)); + EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, ByteOrder::big)); EXPECT_EQ(0xefcdab8967452301, gtoh((uint64_t)0xefcdab8967452301, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0x1032547698badcfe, gtoh((uint64_t)0x1032547698badcfe, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0xb14171b771b01c0b, gtoh((uint64_t)0xb14171b771b01c0b, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0xffffffff00000000, gtoh((uint64_t)0xffffffff00000000, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0x5555555555555555, gtoh((uint64_t)0x5555555555555555, - LittleEndianByteOrder)); + ByteOrder::little)); EXPECT_EQ(0xa0a0a0a0a0a0a0a0, gtoh((uint64_t)0xa0a0a0a0a0a0a0a0, - LittleEndianByteOrder)); - EXPECT_EQ(0xefcd2301, gtoh((uint32_t)0xefcd2301, LittleEndianByteOrder)); - EXPECT_EQ(0x1032dcfe, gtoh((uint32_t)0x1032dcfe, LittleEndianByteOrder)); - EXPECT_EQ(0xb1411c0b, gtoh((uint32_t)0xb1411c0b, LittleEndianByteOrder)); - EXPECT_EQ(0xffff0000, gtoh((uint32_t)0xffff0000, LittleEndianByteOrder)); - EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, LittleEndianByteOrder)); - EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, LittleEndianByteOrder)); - EXPECT_EQ(0xef01, gtoh((uint16_t)0xef01, LittleEndianByteOrder)); - EXPECT_EQ(0x10fe, gtoh((uint16_t)0x10fe, LittleEndianByteOrder)); - EXPECT_EQ(0xb10b, gtoh((uint16_t)0xb10b, LittleEndianByteOrder)); - EXPECT_EQ(0xff00, gtoh((uint16_t)0xff00, LittleEndianByteOrder)); - EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, LittleEndianByteOrder)); - EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, LittleEndianByteOrder)); + ByteOrder::little)); + EXPECT_EQ(0xefcd2301, gtoh((uint32_t)0xefcd2301, ByteOrder::little)); + EXPECT_EQ(0x1032dcfe, gtoh((uint32_t)0x1032dcfe, ByteOrder::little)); + EXPECT_EQ(0xb1411c0b, gtoh((uint32_t)0xb1411c0b, ByteOrder::little)); + EXPECT_EQ(0xffff0000, gtoh((uint32_t)0xffff0000, ByteOrder::little)); + EXPECT_EQ(0x55555555, gtoh((uint32_t)0x55555555, ByteOrder::little)); + EXPECT_EQ(0xa0a0a0a0, gtoh((uint32_t)0xa0a0a0a0, ByteOrder::little)); + EXPECT_EQ(0xef01, gtoh((uint16_t)0xef01, ByteOrder::little)); + EXPECT_EQ(0x10fe, gtoh((uint16_t)0x10fe, ByteOrder::little)); + EXPECT_EQ(0xb10b, gtoh((uint16_t)0xb10b, ByteOrder::little)); + EXPECT_EQ(0xff00, gtoh((uint16_t)0xff00, ByteOrder::little)); + EXPECT_EQ(0x5555, gtoh((uint16_t)0x5555, ByteOrder::little)); + EXPECT_EQ(0xa0a0, gtoh((uint16_t)0xa0a0, ByteOrder::little)); #else #error Invalid Endianess #endif -- 2.30.2