From patchwork Thu Dec 19 11:50:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vijay Kilari X-Patchwork-Id: 3377561 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DC64C9F314 for ; Thu, 19 Dec 2013 11:54:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3461720620 for ; Thu, 19 Dec 2013 11:54:27 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 537A420613 for ; Thu, 19 Dec 2013 11:54:22 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VtcAZ-00020N-9s; Thu, 19 Dec 2013 11:53:36 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VtcAM-0005aJ-1X; Thu, 19 Dec 2013 11:53:22 +0000 Received: from mail-pd0-x22e.google.com ([2607:f8b0:400e:c02::22e]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VtcA6-0005XQ-0o for linux-arm-kernel@lists.infradead.org; Thu, 19 Dec 2013 11:53:07 +0000 Received: by mail-pd0-f174.google.com with SMTP id x10so1016732pdj.19 for ; Thu, 19 Dec 2013 03:52:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=C17KCN9jlzUO0pscIkoInGz3b70YCH7Z5+0FNL9EM9E=; b=P+dbyzuV5kyrqcBqK7oeyLZ2bQ5Hjg23oNRGN+IeOi3okh9fb8IRR36dgjS6YI4+2u XscqDBOWHTTumTDMK0M6uzQA2dpCdp2h6ZtXdHs3XwawBx5vczMlD3orSx53jUfPWy2X 8BHShx58UzUJNovpOXBFvVw9ktq+slD2nQknKFcOasTxONraxWvjdQP17bHUVjrXnqpH f6rEv3CCKX2LyFzz4jvYzCgEYXbX9lPSQ71JV2e94t3u7Jxbinw1X3F7/5pJPgDT8tSq RhSU7RW4wunWCKNBP8Z1brTvVWjXtyAxHns2Z5wMyq04TXu83U4M3Hkik9fa3rCedD1w NPLQ== X-Received: by 10.66.149.231 with SMTP id ud7mr1259603pab.8.1387453964411; Thu, 19 Dec 2013 03:52:44 -0800 (PST) Received: from ubuntu.caveonetworks.com ([115.119.134.194]) by mx.google.com with ESMTPSA id oa3sm6749815pbb.15.2013.12.19.03.52.40 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Dec 2013 03:52:43 -0800 (PST) From: vijay.kilari@gmail.com To: will.deacon@arm.com, sandeepa.prabhu@linaro.org, jason.wessel@windriver.com, takahiro.akashi@linaro.org, Catalin.Marinas@arm.com, Mark.Rutland@arm.com, pinskia@gmail.com Subject: [PATCH v6 2/3] AArch64: KGDB: Add step debugging support Date: Thu, 19 Dec 2013 17:20:50 +0530 Message-Id: <1387453851-19341-3-git-send-email-vijay.kilari@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1387453851-19341-1-git-send-email-vijay.kilari@gmail.com> References: <1387453851-19341-1-git-send-email-vijay.kilari@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131219_065306_209607_DF31939C X-CRM114-Status: GOOD ( 17.49 ) X-Spam-Score: -2.0 (--) Cc: Prasun.Kapoor@caviumnetworks.com, Vijaya Kumar K , linaro-kernel@lists.linaro.org, linux@arm.linux.org.uk, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Vijaya Kumar K Add KGDB software step debugging support for EL1 debug in AArch64 mode. KGDB registers step debug handler with debug monitor. On receiving 'step' command from GDB tool, target enables software step debugging and step address is updated in ELR. Software Step debugging is disabled when 'continue' command is received Signed-off-by: Vijaya Kumar K Reviewed-by: Will Deacon --- arch/arm64/kernel/kgdb.c | 67 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c index 8530584..aeef75b 100644 --- a/arch/arm64/kernel/kgdb.c +++ b/arch/arm64/kernel/kgdb.c @@ -137,13 +137,26 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc) static int compiled_break; +static void kgdb_arch_update_addr(struct pt_regs *regs, + char *remcom_in_buffer) +{ + unsigned long addr; + char *ptr; + + ptr = &remcom_in_buffer[1]; + if (kgdb_hex2long(&ptr, &addr)) + kgdb_arch_set_pc(regs, addr); + else if (compiled_break == 1) + kgdb_arch_set_pc(regs, regs->pc + 4); + + compiled_break = 0; +} + int kgdb_arch_handle_exception(int exception_vector, int signo, int err_code, char *remcom_in_buffer, char *remcom_out_buffer, struct pt_regs *linux_regs) { - unsigned long addr; - char *ptr; int err; switch (remcom_in_buffer[0]) { @@ -153,6 +166,8 @@ int kgdb_arch_handle_exception(int exception_vector, int signo, * Packet D (Detach), k (kill). No special handling * is required here */ + atomic_set(&kgdb_cpu_doing_single_step, -1); + kgdb_single_step = 0; err = 0; break; case 'c': @@ -164,16 +179,39 @@ int kgdb_arch_handle_exception(int exception_vector, int signo, * to the next instruction else we will just breakpoint * over and over again. */ - ptr = &remcom_in_buffer[1]; - if (kgdb_hex2long(&ptr, &addr)) - kgdb_arch_set_pc(linux_regs, addr); - else if (compiled_break == 1) - kgdb_arch_set_pc(linux_regs, linux_regs->pc + 4); + kgdb_arch_update_addr(linux_regs, remcom_in_buffer); + atomic_set(&kgdb_cpu_doing_single_step, -1); + kgdb_single_step = 0; - compiled_break = 0; + /* + * Received continue command, disable single step + */ + if (kernel_active_single_step()) + kernel_disable_single_step(); err = 0; break; + case 's': + /* + * Update step address value with address passed + * with step packet. + * On debug exception return PC is copied to ELR + * So just update PC. + * If no step address is passed, resume from the address + * pointed by PC. Do not update PC + */ + kgdb_arch_update_addr(linux_regs, remcom_in_buffer); + atomic_set(&kgdb_cpu_doing_single_step, raw_smp_processor_id()); + kgdb_single_step = 1; + + /* + * Enable single step handling + */ + if (!kernel_active_single_step()) + kernel_enable_single_step(linux_regs); + err = 0; + break; + default: err = -1; } @@ -194,6 +232,12 @@ static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr) return 0; } +static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr) +{ + kgdb_handle_exception(1, SIGTRAP, 0, regs); + return 0; +} + static struct break_hook kgdb_brkpt_hook = { .esr_mask = 0xffffffff, .esr_val = DBG_ESR_VAL_BRK(KGDB_DYN_DGB_BRK_IMM), @@ -206,6 +250,10 @@ static struct break_hook kgdb_compiled_brkpt_hook = { .fn = kgdb_compiled_brk_fn }; +static struct step_hook kgdb_step_hook = { + .fn = kgdb_step_brk_fn +}; + static void kgdb_call_nmi_hook(void *ignored) { kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs()); @@ -262,7 +310,7 @@ int kgdb_arch_init(void) register_break_hook(&kgdb_brkpt_hook); register_break_hook(&kgdb_compiled_brkpt_hook); - + register_step_hook(&kgdb_step_hook); return 0; } @@ -275,6 +323,7 @@ void kgdb_arch_exit(void) { unregister_break_hook(&kgdb_brkpt_hook); unregister_break_hook(&kgdb_compiled_brkpt_hook); + unregister_step_hook(&kgdb_step_hook); unregister_die_notifier(&kgdb_notifier); }