From patchwork Fri Oct 16 13:58:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 55106 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id BEF2922EAC for ; Fri, 16 Oct 2015 13:59:25 +0000 (UTC) Received: by wicgb1 with SMTP id gb1sf2873461wic.3 for ; Fri, 16 Oct 2015 06:59:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=vgjZx4bGQbHMMjnPwEG7VpOBaLcPMLiHHS6Z8ynHrYw=; b=QeDesphU7r8AxrZ0s1buqOsd58XAWAvplLYSEI5bJ1vHx/rnr3GczGXI9Q659j0FNE ecXFqziQevxC//7Kvyj/hR6CmciFONoS6VqiIZe1ZHB6GFr1+OTTzc75GVwFv6AeqrRQ f34Bx2s+9SRyv/QktiUNiegbpBOEJFia5Zyje6Zj8r1uUEY3DQ3a3uN10N7xzmrG1XUP zmLLEy4grDjHRecKbED2IsLiUPzM1nZQcY3hDnYu5cNkjSPRVlhr+6rdnXrPISINJW34 ENUZcR7T0g/X9h+yFIANnmeBM8EUazpZJuOSi7dBlnCXg3507IiUV1QLHQ8TDVQlOKPu lLGA== X-Gm-Message-State: ALoCoQmzmv4lguxCQnwPpG+I+s7DDeCVMQKIT4oCtDTvCYEwcPli5ZmI3z/9kfiU//VxrBQHJbld X-Received: by 10.180.184.164 with SMTP id ev4mr1185974wic.3.1445003964867; Fri, 16 Oct 2015 06:59:24 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.37.144 with SMTP id l138ls344324lfl.8.gmail; Fri, 16 Oct 2015 06:59:24 -0700 (PDT) X-Received: by 10.25.149.139 with SMTP id x133mr4214790lfd.53.1445003964709; Fri, 16 Oct 2015 06:59:24 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id m142si12997589lfg.118.2015.10.16.06.59.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Oct 2015 06:59:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbbes7 with SMTP id es7so11434859lbb.2 for ; Fri, 16 Oct 2015 06:59:24 -0700 (PDT) X-Received: by 10.112.64.72 with SMTP id m8mr8165508lbs.41.1445003964473; Fri, 16 Oct 2015 06:59:24 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1307781lbq; Fri, 16 Oct 2015 06:59:23 -0700 (PDT) X-Received: by 10.140.148.210 with SMTP id 201mr11316659qhu.6.1445003963504; Fri, 16 Oct 2015 06:59:23 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 81si17557294qhu.7.2015.10.16.06.59.23 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 16 Oct 2015 06:59:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:53828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn5XW-00039H-Vj for patch@linaro.org; Fri, 16 Oct 2015 09:59:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn5WM-00020T-P3 for qemu-devel@nongnu.org; Fri, 16 Oct 2015 09:58:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zn5WL-0000jq-BK for qemu-devel@nongnu.org; Fri, 16 Oct 2015 09:58:10 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:35158) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn5WL-0000ht-3O for qemu-devel@nongnu.org; Fri, 16 Oct 2015 09:58:09 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Zn5WK-0003my-6m for qemu-devel@nongnu.org; Fri, 16 Oct 2015 14:58:08 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 16 Oct 2015 14:58:07 +0100 Message-Id: <1445003887-14475-14-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1445003887-14475-1-git-send-email-peter.maydell@linaro.org> References: <1445003887-14475-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 13/13] target-arm: Fix CPU breakpoint handling 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Sergey Fedorov A QEMU breakpoint match is not definitely an architectural breakpoint match. If an exception is generated unconditionally during translation, it is hardly possible to ignore it in the debug exception handler. Generate a call to a helper to check CPU breakpoints and raise an exception only if any breakpoint matches architecturally. Signed-off-by: Sergey Fedorov Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- target-arm/helper.h | 2 ++ target-arm/op_helper.c | 29 ++++++++++++++++++----------- target-arm/translate-a64.c | 17 ++++++++++++----- target-arm/translate.c | 19 ++++++++++++++----- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/target-arm/helper.h b/target-arm/helper.h index 827b33d..c2a85c7 100644 --- a/target-arm/helper.h +++ b/target-arm/helper.h @@ -54,6 +54,8 @@ DEF_HELPER_1(yield, void, env) DEF_HELPER_1(pre_hvc, void, env) DEF_HELPER_2(pre_smc, void, env, i32) +DEF_HELPER_1(check_breakpoints, void, env) + DEF_HELPER_3(cpsr_write, void, env, i32, i32) DEF_HELPER_1(cpsr_read, i32, env) diff --git a/target-arm/op_helper.c b/target-arm/op_helper.c index 67b18c0..7929c71 100644 --- a/target-arm/op_helper.c +++ b/target-arm/op_helper.c @@ -867,6 +867,15 @@ static bool check_breakpoints(ARMCPU *cpu) return false; } +void HELPER(check_breakpoints)(CPUARMState *env) +{ + ARMCPU *cpu = arm_env_get_cpu(env); + + if (check_breakpoints(cpu)) { + HELPER(exception_internal(env, EXCP_DEBUG)); + } +} + void arm_debug_excp_handler(CPUState *cs) { /* Called by core code when a watchpoint or breakpoint fires; @@ -898,23 +907,21 @@ void arm_debug_excp_handler(CPUState *cs) } } else { uint64_t pc = is_a64(env) ? env->pc : env->regs[15]; + bool same_el = (arm_debug_target_el(env) == arm_current_el(env)); if (cpu_breakpoint_test(cs, pc, BP_GDB)) { return; } - if (check_breakpoints(cpu)) { - bool same_el = (arm_debug_target_el(env) == arm_current_el(env)); - if (extended_addresses_enabled(env)) { - env->exception.fsr = (1 << 9) | 0x22; - } else { - env->exception.fsr = 0x2; - } - /* FAR is UNKNOWN, so doesn't need setting */ - raise_exception(env, EXCP_PREFETCH_ABORT, - syn_breakpoint(same_el), - arm_debug_target_el(env)); + if (extended_addresses_enabled(env)) { + env->exception.fsr = (1 << 9) | 0x22; + } else { + env->exception.fsr = 0x2; } + /* FAR is UNKNOWN, so doesn't need setting */ + raise_exception(env, EXCP_PREFETCH_ABORT, + syn_breakpoint(same_el), + arm_debug_target_el(env)); } } diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c index a4580c0..19f9d8d 100644 --- a/target-arm/translate-a64.c +++ b/target-arm/translate-a64.c @@ -11090,11 +11090,18 @@ void gen_intermediate_code_a64(ARMCPU *cpu, TranslationBlock *tb) CPUBreakpoint *bp; QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { if (bp->pc == dc->pc) { - gen_exception_internal_insn(dc, 0, EXCP_DEBUG); - /* Advance PC so that clearing the breakpoint will - invalidate this TB. */ - dc->pc += 2; - goto done_generating; + if (bp->flags & BP_CPU) { + gen_helper_check_breakpoints(cpu_env); + /* End the TB early; it likely won't be executed */ + dc->is_jmp = DISAS_UPDATE; + } else { + gen_exception_internal_insn(dc, 0, EXCP_DEBUG); + /* Advance PC so that clearing the breakpoint will + invalidate this TB. */ + dc->pc += 4; + goto done_generating; + } + break; } } } diff --git a/target-arm/translate.c b/target-arm/translate.c index 1273000..9f1d740 100644 --- a/target-arm/translate.c +++ b/target-arm/translate.c @@ -11342,11 +11342,20 @@ void gen_intermediate_code(CPUARMState *env, TranslationBlock *tb) CPUBreakpoint *bp; QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { if (bp->pc == dc->pc) { - gen_exception_internal_insn(dc, 0, EXCP_DEBUG); - /* Advance PC so that clearing the breakpoint will - invalidate this TB. */ - dc->pc += 2; - goto done_generating; + if (bp->flags & BP_CPU) { + gen_helper_check_breakpoints(cpu_env); + /* End the TB early; it's likely not going to be executed */ + dc->is_jmp = DISAS_UPDATE; + } else { + gen_exception_internal_insn(dc, 0, EXCP_DEBUG); + /* Advance PC so that clearing the breakpoint will + invalidate this TB. */ + /* TODO: Advance PC by correct instruction length to + * avoid disassembler error messages */ + dc->pc += 2; + goto done_generating; + } + break; } } }