From patchwork Fri Nov 7 20:05:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 408250 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 875401400D2 for ; Sat, 8 Nov 2014 07:06:22 +1100 (AEDT) Received: from localhost ([::1]:33734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmpnW-0005vy-4y for incoming@patchwork.ozlabs.org; Fri, 07 Nov 2014 15:06:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xmpn5-0005Th-9g for qemu-devel@nongnu.org; Fri, 07 Nov 2014 15:05:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xmpmy-0007kh-OE for qemu-devel@nongnu.org; Fri, 07 Nov 2014 15:05:50 -0500 Received: from relay1.mentorg.com ([192.94.38.131]:50303) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xmpmx-0007kU-QP for qemu-devel@nongnu.org; Fri, 07 Nov 2014 15:05:44 -0500 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1Xmpmv-0007IY-2K from Maciej_Rozycki@mentor.com ; Fri, 07 Nov 2014 12:05:41 -0800 Received: from localhost (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server (TLS) id 14.3.181.6; Fri, 7 Nov 2014 20:05:39 +0000 Date: Fri, 7 Nov 2014 20:05:35 +0000 From: "Maciej W. Rozycki" To: In-Reply-To: Message-ID: References: User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 Cc: Leon Alrae , Aurelien Jarno Subject: [Qemu-devel] [PATCH v2] mips: Correct MIPS16/microMIPS branch size calculation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Correct MIPS16/microMIPS branch size calculation in PC adjustment needed: - to set the value of CP0.ErrorEPC at the entry to the reset exception, - for the purpose of branch reexecution in the context of device I/O. Follow the approach taken in `exception_resume_pc' for ordinary, Debug and NMI exceptions. MIPS16 and microMIPS branches can be 2 or 4 bytes in size and that has to be reflected in calculation. Original MIPS ISA branches, which is where this code originates from, are always 4 bytes long, just as all original MIPS ISA instructions. Signed-off-by: Nathan Froyd Signed-off-by: Maciej W. Rozycki Reviewed-by: Leon Alrae --- Another change that has waited for too long, with the original discussion archived here: http://lists.nongnu.org/archive/html/qemu-devel/2012-06/msg01230.html Resending with what hopefully is a better description and updated to reflect the move of `cpu_io_recompile' from exec.c to translate-all.c. Please apply, Maciej qemu-mips-b16.diff Index: qemu-git-trunk/target-mips/translate.c =================================================================== --- qemu-git-trunk.orig/target-mips/translate.c 2014-11-07 18:34:30.927788566 +0000 +++ qemu-git-trunk/target-mips/translate.c 2014-11-07 18:34:35.428958223 +0000 @@ -19452,7 +19452,8 @@ void cpu_state_reset(CPUMIPSState *env) if (env->hflags & MIPS_HFLAG_BMASK) { /* If the exception was raised from a delay slot, come back to the jump. */ - env->CP0_ErrorEPC = env->active_tc.PC - 4; + env->CP0_ErrorEPC = (env->active_tc.PC + - (env->hflags & MIPS_HFLAG_B16 ? 2 : 4)); } else { env->CP0_ErrorEPC = env->active_tc.PC; } Index: qemu-git-trunk/translate-all.c =================================================================== --- qemu-git-trunk.orig/translate-all.c 2014-11-07 17:33:13.037575065 +0000 +++ qemu-git-trunk/translate-all.c 2014-11-07 18:34:35.428958223 +0000 @@ -1534,7 +1534,7 @@ void cpu_io_recompile(CPUState *cpu, uin branch. */ #if defined(TARGET_MIPS) if ((env->hflags & MIPS_HFLAG_BMASK) != 0 && n > 1) { - env->active_tc.PC -= 4; + env->active_tc.PC -= (env->hflags & MIPS_HFLAG_B16 ? 2 : 4); cpu->icount_decr.u16.low++; env->hflags &= ~MIPS_HFLAG_BMASK; }