Received: from eggs.gnu.org ([2001:4830:134:3::10]:39726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyMUD-00048E-FD for qemu-devel@nongnu.org; Mon, 16 Nov 2015 11:18:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZyMU9-00077f-Cd for qemu-devel@nongnu.org; Mon, 16 Nov 2015 11:18:33 -0500 Received: from mailapp01.imgtec.com ([195.59.15.196]:58493) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyMU9-00077C-6p for qemu-devel@nongnu.org; Mon, 16 Nov 2015 11:18:29 -0500 From: James Hogan Date: Mon, 16 Nov 2015 16:18:18 +0000 Message-ID: <1447690698-20276-1-git-send-email-james.hogan@imgtec.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH] target-mips: Fix exceptions while UX=0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Leon Alrae Cc: James Hogan , qemu-devel@nongnu.org, Aurelien Jarno Commit 01f728857941 ("target-mips: Status.UX/SX/KX enable 32-bit address wrapping") added a new hflag MIPS_HFLAG_AWRAP, which indicates that 64-bit addressing is disallowed in the current mode, so hflag users don't need to worry about the complexities of working that out, for example checking both MIPS_HFLAG_KSU and MIPS_HFLAG_UX. However when exceptions are taken outside of exception level, mips_cpu_do_interrupt() manipulates the env->hflags directly rather than using compute_hflags() to update them, and this code wasn't updated accordingly. As a result, when UX is cleared, MIPS_HFLAG_AWRAP is set, but it doesn't get cleared on entry back into kernel mode due to an exception. Kernel mode then cannot access the 64-bit segments resulting in a nested exception loop. Fix by updating mips_cpu_do_interrupt() to clear the MIPS_HFLAG_WRAP flag when necessary, according to compute_hflags(). Fixes: 01f728857941 ("target-mips: Status.UX/SX/KX enable 32-bit...") Signed-off-by: James Hogan Cc: Leon Alrae Cc: Aurelien Jarno --- Note, compute_hflags() doesn't seem to take KX into account pre-r6, which seems wrong. --- target-mips/helper.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target-mips/helper.c b/target-mips/helper.c index b3fe816fecf8..0625f610a015 100644 --- a/target-mips/helper.c +++ b/target-mips/helper.c @@ -725,6 +725,10 @@ void mips_cpu_do_interrupt(CPUState *cs) env->CP0_Status |= (1 << CP0St_EXL); if (env->insn_flags & ISA_MIPS3) { env->hflags |= MIPS_HFLAG_64; + if (!(env->insn_flags & ISA_MIPS64R6) || + env->CP0_Status & (1 << CP0St_KX)) { + env->hflags &= ~MIPS_HFLAG_AWRAP; + } } env->hflags |= MIPS_HFLAG_CP0; env->hflags &= ~(MIPS_HFLAG_KSU); -- 2.4.10