diff --git a/src/arch/arm/reg_abi.hh b/src/arch/arm/reg_abi.hh index ca349283e2..34fe44c16d 100644 --- a/src/arch/arm/reg_abi.hh +++ b/src/arch/arm/reg_abi.hh @@ -55,8 +55,6 @@ struct RegABI64 : public GenericSyscallABI64 namespace guest_abi { -using namespace pseudo_inst; - template struct Argument -struct Argument +struct Argument { using ABI = ArmISA::RegABI32; + using Arg = pseudo_inst::GuestAddr; - static GuestAddr + static Arg get(ThreadContext *tc, typename ABI::State &state) { panic_if(state + 1 >= ABI::ArgumentRegs.size(), "Ran out of syscall argument registers."); - auto arg = bits(tc->getReg(ABI::ArgumentRegs[state++]), 31, 0); - return *reinterpret_cast(&arg); + return (Arg)bits(tc->getReg(ABI::ArgumentRegs[state++]), 31, 0); } }; diff --git a/src/arch/arm/semihosting.hh b/src/arch/arm/semihosting.hh index 221c0ce3cb..7242581eb6 100644 --- a/src/arch/arm/semihosting.hh +++ b/src/arch/arm/semihosting.hh @@ -603,36 +603,33 @@ std::ostream &operator << ( namespace guest_abi { -using namespace pseudo_inst; - template struct Argument || std::is_same::value)>> + (std::is_integral_v || + std::is_same::value)>> { static Arg get(ThreadContext *tc, ArmSemihosting::Abi64::State &state) { - auto arg = state.get(tc); - return *reinterpret_cast(&arg); + return (Arg)state.get(tc); } }; template struct Argument || std::is_same::value)>> + (std::is_integral_v || + std::is_same::value)>> { static Arg get(ThreadContext *tc, ArmSemihosting::Abi32::State &state) { if (std::is_signed_v) { - auto arg = sext<32>(state.get(tc)); - return *reinterpret_cast(&arg); + return (Arg)sext<32>(state.get(tc)); } else { - auto arg = state.get(tc); - return *reinterpret_cast(&arg); + return (Arg)state.get(tc); } } }; diff --git a/src/arch/riscv/reg_abi.hh b/src/arch/riscv/reg_abi.hh index 0869e0f4a6..383e9df266 100644 --- a/src/arch/riscv/reg_abi.hh +++ b/src/arch/riscv/reg_abi.hh @@ -54,7 +54,6 @@ struct RegABI32 : public GenericSyscallABI32 namespace guest_abi { -using namespace pseudo_inst; // This method will be used if the size of argument type of function is // greater than 4 byte for Riscv 32. @@ -79,18 +78,18 @@ struct Argument -struct Argument +struct Argument { using ABI = RiscvISA::RegABI32; + using Arg = pseudo_inst::GuestAddr; - static GuestAddr + static Arg get(ThreadContext *tc, typename ABI::State &state) { panic_if(state >= ABI::ArgumentRegs.size(), "Ran out of syscall argument registers."); - auto arg = bits(tc->getReg(ABI::ArgumentRegs[state++]), 31, 0); - return *reinterpret_cast(&arg); + return (Arg)bits(tc->getReg(ABI::ArgumentRegs[state++]), 31, 0); } }; diff --git a/src/arch/sparc/pseudo_inst_abi.hh b/src/arch/sparc/pseudo_inst_abi.hh index 58b64d805a..569cfb8da8 100644 --- a/src/arch/sparc/pseudo_inst_abi.hh +++ b/src/arch/sparc/pseudo_inst_abi.hh @@ -44,8 +44,6 @@ struct SparcPseudoInstABI namespace guest_abi { -using namespace pseudo_inst; - template struct Result { @@ -71,14 +69,15 @@ struct Argument }; template <> -struct Argument +struct Argument { - static GuestAddr + using Arg = pseudo_inst::GuestAddr; + + static Arg get(ThreadContext *tc, SparcPseudoInstABI::State &state) { panic_if(state >= 6, "Too many psuedo inst arguments."); - auto arg = tc->getReg(SparcISA::int_reg::o(state++)); - return *reinterpret_cast(&arg); + return (Arg)tc->getReg(SparcISA::int_reg::o(state++)); } }; diff --git a/src/arch/x86/pseudo_inst_abi.hh b/src/arch/x86/pseudo_inst_abi.hh index 0c098f16e2..bfedb7a8cb 100644 --- a/src/arch/x86/pseudo_inst_abi.hh +++ b/src/arch/x86/pseudo_inst_abi.hh @@ -50,8 +50,6 @@ struct X86PseudoInstABI namespace guest_abi { -using namespace pseudo_inst; - template struct Result { @@ -88,9 +86,11 @@ struct Argument }; template <> -struct Argument +struct Argument { - static GuestAddr + using Arg = pseudo_inst::GuestAddr; + + static Arg get(ThreadContext *tc, X86PseudoInstABI::State &state) { // The first 6 integer arguments are passed in registers, the rest @@ -105,8 +105,7 @@ struct Argument int_reg::Rcx, int_reg::R8, int_reg::R9 }; - auto arg = tc->getReg(int_reg_map[state++]); - return *reinterpret_cast(&arg); + return (Arg)tc->getReg(int_reg_map[state++]); } }; diff --git a/src/sim/guest_abi/layout.hh b/src/sim/guest_abi/layout.hh index 3ea01c168c..9873a61215 100644 --- a/src/sim/guest_abi/layout.hh +++ b/src/sim/guest_abi/layout.hh @@ -169,8 +169,7 @@ template static Arg getArgument(ThreadContext *tc, typename ABI::State &state) { - auto arg = Argument::get(tc, state); - return *reinterpret_cast(&arg); + return (Arg)Argument::get(tc, state); } } // namespace guest_abi diff --git a/src/sim/pseudo_inst.hh b/src/sim/pseudo_inst.hh index 6eac340989..2d7b27715b 100644 --- a/src/sim/pseudo_inst.hh +++ b/src/sim/pseudo_inst.hh @@ -64,9 +64,17 @@ decodeAddrOffset(Addr offset, uint8_t &func) func = bits(offset, 15, 8); } +/** + * This struct wrapper for Addr enables m5ops for systems with 32 bit pointer, + * since it allows to distinguish between address arguments and native C++ + * types. GuestAddr is only a temporary solution and will likely replaced in + * the future. +*/ struct GuestAddr { - uint64_t addr; + Addr addr; + /** Constructor is necessary to cast from uint64_t to GuestAddr. */ + GuestAddr(Addr _addr) : addr(_addr) {} }; inline std::ostream& diff --git a/src/sim/syscall_abi.hh b/src/sim/syscall_abi.hh index 136555ea37..c50b1de16e 100644 --- a/src/sim/syscall_abi.hh +++ b/src/sim/syscall_abi.hh @@ -79,22 +79,20 @@ struct GenericSyscallABI32 : public GenericSyscallABI namespace guest_abi { -using namespace pseudo_inst; - // For 64 bit systems, return syscall args directly. template struct Argument && - (std::is_integral_v || std::is_same::value)>> + (std::is_integral_v || + std::is_same::value)>> { static Arg get(ThreadContext *tc, typename ABI::State &state) { panic_if(state >= ABI::ArgumentRegs.size(), "Ran out of syscall argument registers."); - auto arg = tc->getReg(ABI::ArgumentRegs[state++]); - return *reinterpret_cast(&arg); + return (Arg)tc->getReg(ABI::ArgumentRegs[state++]); } };