From patchwork Thu Jan 29 16:15:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Alrae X-Patchwork-Id: 434596 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 8EB5714017D for ; Fri, 30 Jan 2015 03:15:33 +1100 (AEDT) Received: from localhost ([::1]:60608 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGrkh-0001C8-GR for incoming@patchwork.ozlabs.org; Thu, 29 Jan 2015 11:15:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57687) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGrkP-0000vN-80 for qemu-devel@nongnu.org; Thu, 29 Jan 2015 11:15:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGrkM-0000L4-1H for qemu-devel@nongnu.org; Thu, 29 Jan 2015 11:15:13 -0500 Received: from mailapp01.imgtec.com ([195.59.15.196]:19314) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGrkL-0000Km-N0 for qemu-devel@nongnu.org; Thu, 29 Jan 2015 11:15:09 -0500 Received: from KLMAIL01.kl.imgtec.org (unknown [192.168.5.35]) by Websense Email Security Gateway with ESMTPS id D6288E72879F9; Thu, 29 Jan 2015 16:15:04 +0000 (GMT) Received: from lalrae-linux.kl.imgtec.org (192.168.14.163) by KLMAIL01.kl.imgtec.org (192.168.5.35) with Microsoft SMTP Server (TLS) id 14.3.195.1; Thu, 29 Jan 2015 16:15:07 +0000 From: Leon Alrae To: Date: Thu, 29 Jan 2015 16:15:00 +0000 Message-ID: <1422548100-27048-1-git-send-email-leon.alrae@imgtec.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-Originating-IP: [192.168.14.163] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.59.15.196 Cc: aurelien@aurel32.net Subject: [Qemu-devel] [PATCH] target-mips: fix hflags modified in delay / forbidden slot 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 All instructions which may change hflags terminate tb. However, this doesn't work if such an instruction is placed in delay or forbidden slot. gen_branch() clears MIPS_HFLAG_BMASK in ctx->hflags and then generates code to overwrite hflags with ctx->hflags, consequently we loose any execution-time hflags modifications. For example, in the following scenario hflag related to Status.CU1 will not be updated: /* Set Status.CU1 in delay slot */ mfc0 $24, $12, 0 lui $25, 0x2000 or $25, $25, $24 b check_Status_CU1 mtc0 $25, $12, 0 With this change we clear MIPS_HFLAG_BMASK in execution-time hflags if instruction in delay or forbidden slot wants to terminate tb for some reason (i.e. ctx->bstate != BS_NONE). Also, die early and loudly if "unknown branch" is encountered as this should never happen. Signed-off-by: Leon Alrae --- target-mips/translate.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/target-mips/translate.c b/target-mips/translate.c index 1347451..f420dc7 100644 --- a/target-mips/translate.c +++ b/target-mips/translate.c @@ -10531,14 +10531,25 @@ static void gen_rdhwr(DisasContext *ctx, int rt, int rd) tcg_temp_free(t0); } +static inline void clear_branch_hflags(DisasContext *ctx) +{ + ctx->hflags &= ~MIPS_HFLAG_BMASK; + if (ctx->bstate == BS_NONE) { + save_cpu_state(ctx, 0); + } else { + /* it is not safe to save ctx->hflags as hflags may be changed + in execution time by the instruction in delay / forbidden slot. */ + tcg_gen_andi_i32(hflags, hflags, ~MIPS_HFLAG_BMASK); + } +} + static void gen_branch(DisasContext *ctx, int insn_bytes) { if (ctx->hflags & MIPS_HFLAG_BMASK) { int proc_hflags = ctx->hflags & MIPS_HFLAG_BMASK; /* Branches completion */ - ctx->hflags &= ~MIPS_HFLAG_BMASK; + clear_branch_hflags(ctx); ctx->bstate = BS_BRANCH; - save_cpu_state(ctx, 0); /* FIXME: Need to clear can_do_io. */ switch (proc_hflags & MIPS_HFLAG_BMASK_BASE) { case MIPS_HFLAG_FBNSLOT: @@ -10596,8 +10607,8 @@ static void gen_branch(DisasContext *ctx, int insn_bytes) tcg_gen_exit_tb(0); break; default: - MIPS_DEBUG("unknown branch"); - break; + fprintf(stderr, "unknown branch 0x%x\n", proc_hflags); + abort(); } } }