From 7dcdae9807b6ab3a1c1e25e36b36258c22223beb Mon Sep 17 00:00:00 2001 From: Mark Cave-Ayland Date: Fri, 23 Feb 2018 13:37:14 -0500 Subject: [PATCH] target-sparc: fix ldstub sign-extension bug ldstub [addr], reg incorrectly reads a signed byte from memory which causes problems in the 32-bit Solaris mutex code. Here the byte value being read is 0xff which is incorrectly sign-extended to 0xffffffff before being written back to the target register causing lock detection to behave incorrectly. This fixes the intermittent hangs and MUTEX_HELD warnings issued to the console when running 32-bit Solaris images under qemu-system-sparc. With thanks to Joseph Dery for providing a condensed test image to consistently reproduce the problem on demand, and Martin Husemann for allowing me access to real hardware for comparison. Backports commit 4553e10360a0713e31647220ed396942f9a6fca0 from qemu --- qemu/target-sparc/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu/target-sparc/translate.c b/qemu/target-sparc/translate.c index fd573cce..e9999cfe 100644 --- a/qemu/target-sparc/translate.c +++ b/qemu/target-sparc/translate.c @@ -4807,7 +4807,7 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn, bool hook_ins TCGv r_const; gen_address_mask(dc, cpu_addr); - tcg_gen_qemu_ld8s(dc->uc, cpu_val, cpu_addr, dc->mem_idx); + tcg_gen_qemu_ld8u(dc->uc, cpu_val, cpu_addr, dc->mem_idx); r_const = tcg_const_tl(tcg_ctx, 0xff); tcg_gen_qemu_st8(dc->uc, r_const, cpu_addr, dc->mem_idx); tcg_temp_free(tcg_ctx, r_const);