target/mips: Fix handling of LL/SC instructions after 7dd547e5ab

After 7dd547e5ab the env->llval value
is loaded as an unsigned value (instead of sign-extended as before).
Therefore, the CMPXCHG in gen_st_cond() in translate.c fails if the
sign bit is set in the loaded value.

Fix this by sign-extending the llval value for the 32-bit case.

I discovered this issue because FreeBSD MIPS64 was looping forever
in an atomic helper function when trying to start /sbin/init.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Fixes: 7dd547e5ab ("target/mips: Use cpu_*_mmuidx_ra instead of MMU_MODE*_SUFFIX")
Buglink: https://bugs.launchpad.net/qemu/+bug/1861605
Cc: Aurelien Jarno <aurelien@aurel32.net>
Cc: Aleksandar Markovic <amarkovic@wavecomp.com>
Cc: Aleksandar Rikalo <aleksandar.rikalo@rt-rk.com>
Cc: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: James Clarke <jrtc27@jrtc27.com>
Signed-off-by: Aleksandar Markovic <amarkovic@wavecomp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20200202153409.28534-1-jrtc27@jrtc27.com>
This commit is contained in:
Alex Richardson 2020-02-02 15:34:09 +00:00 committed by Aleksandar Markovic
parent f31160c7d1
commit ec860426df

View File

@ -305,7 +305,7 @@ static inline hwaddr do_translate_address(CPUMIPSState *env,
} }
} }
#define HELPER_LD_ATOMIC(name, insn, almask) \ #define HELPER_LD_ATOMIC(name, insn, almask, do_cast) \
target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx) \ target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx) \
{ \ { \
if (arg & almask) { \ if (arg & almask) { \
@ -316,12 +316,12 @@ target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx) \
} \ } \
env->CP0_LLAddr = do_translate_address(env, arg, 0, GETPC()); \ env->CP0_LLAddr = do_translate_address(env, arg, 0, GETPC()); \
env->lladdr = arg; \ env->lladdr = arg; \
env->llval = cpu_##insn##_mmuidx_ra(env, arg, mem_idx, GETPC()); \ env->llval = do_cast cpu_##insn##_mmuidx_ra(env, arg, mem_idx, GETPC()); \
return env->llval; \ return env->llval; \
} }
HELPER_LD_ATOMIC(ll, ldl, 0x3) HELPER_LD_ATOMIC(ll, ldl, 0x3, (target_long)(int32_t))
#ifdef TARGET_MIPS64 #ifdef TARGET_MIPS64
HELPER_LD_ATOMIC(lld, ldq, 0x7) HELPER_LD_ATOMIC(lld, ldq, 0x7, (target_ulong))
#endif #endif
#undef HELPER_LD_ATOMIC #undef HELPER_LD_ATOMIC
#endif #endif