From patchwork Mon Jun 1 03:39:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Chen X-Patchwork-Id: 11581189 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B71314F6 for ; Mon, 1 Jun 2020 03:40:27 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 47793206C3 for ; Mon, 1 Jun 2020 03:40:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="DcZf5M+T"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="f+sXrWpg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 47793206C3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:MIME-Version: Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9R35bhp9wOMsOfqu7C7Ex549gBWsaOIaUsg0Jdgmxuc=; b=DcZf5M+TaKL6TV bkRWgnTwrDevq5UcZ4iB8TnKehqLYww7E2OKX0TTxusnz5s5g3Vw76OGGnUyygS8PZRe78oGrVYEm 370klieulJNT+2MPNHInoinX9QBmtH1Azq9pnrNZ2U0tKio9ovkcS8URY6oO1PkohqQsDYvpVUol8 XApaeZ3/5ZIyrHGdjIpm5Xr6nJEPoPDuBVGkuYYbEG8RtdmB0VH9yTnP1XJ6l62EJ9WicOM+N8jOh 2zVEhVHoaMdVBNOvTTvxaQXMWy8uiqmS1s4QbY/KI9+gBNQeVLwZIKyaZH33K/C2IhvOP/tZ/oI5a yvqfOAbvTGpKT1bUDTXQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jfbJH-0001Md-DO; Mon, 01 Jun 2020 03:40:23 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jfbJ1-0007q2-CO for linux-riscv@lists.infradead.org; Mon, 01 Jun 2020 03:40:09 +0000 Received: by mail-pl1-x643.google.com with SMTP id n9so546509plk.1 for ; Sun, 31 May 2020 20:40:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9R35bhp9wOMsOfqu7C7Ex549gBWsaOIaUsg0Jdgmxuc=; b=f+sXrWpgo5tcm9HgCpaIDwO4TaPacCQtJJvL6/HJ9+JK0F0sNwiyPEDe2yhKj5+EeN jJQySI9vYVOFEf71RzwLwrfZ5Wz4HegkLS1MzbIS8WXIfpkiUQLMc/0VpUnOM0CJ6B/B kQJaufifIG41HKnGvcVhMmmPYe9DCWLdobzvwJBGiDNeURLe5jnUt+DtZf4pPAOWomH0 w/BHuJVmpVfVysJiRQqjXhTfe3iOEU8s6pVDe3+9l8y403Mf1aKnTZ8Ub6oWnX9SKvx2 i8uso5GFQFMNwipv+lKVhDGr1EVd9c0uIpIkpR84ohhg9WgvvIlPWH1+DCpaEXh1VY7L 6VDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9R35bhp9wOMsOfqu7C7Ex549gBWsaOIaUsg0Jdgmxuc=; b=c0gKHjs5Hw3iOKGkbzoNDKaQaV75ryMIPgTVpShOLQuHDRft6E3Z6unBh3iVWVC0bv Odz4fOgTqrdlgHXourSkTjwxU0eev0NGAAxoEtkiqsm2hmDfOCiVu6L5lZWeArIqyR3q LmvkXPFCIyL17izVktEapdU5kRL3ZmO5+lU572ZBP0REAllBHGeRqZYi9r4lBTLfH/uX WlhNqxYbUG9R2HGkobwZr3h51Wxzp1PgnA/ngp/650w6IJHOZYqvTxg4pK3bG7aNnhW3 7fmAJsc4803d+fhOsayQLhSrpggdvvX7yHCBUqey1SbM+ailXy6/XtQ8yTHrCaVSqaiD k71g== X-Gm-Message-State: AOAM533O75P6RQrYl21EjpNsiNDS3r8NaxzijrNs7Ndvw0TbZjVZYAJg qKwHZaguMG782nMAJzm3U2f0Yw== X-Google-Smtp-Source: ABdhPJzMbHWMrql4TwE1IweM27kqF51Ry+ehCvY4LaqufRYaEIxBJfKwGBgVgZAxJZKkh/hOrVdg7w== X-Received: by 2002:a17:90a:64c9:: with SMTP id i9mr157695pjm.135.1590982805644; Sun, 31 May 2020 20:40:05 -0700 (PDT) Received: from VincentChen-ThinkPad-T480s.internal.sifive.com (2001-b400-e3df-96c7-30f0-f751-b645-f4e3.emome-ip6.hinet.net. [2001:b400:e3df:96c7:30f0:f751:b645:f4e3]) by smtp.gmail.com with ESMTPSA id a7sm13102527pfa.187.2020.05.31.20.40.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 May 2020 20:40:05 -0700 (PDT) From: Vincent Chen To: paul.walmsley@sifive.com, palmer@dabbelt.com, daniel.thompson@linaro.org Subject: [V5 patch 5/6] riscv: Use the XML target descriptions to report 3 system registers Date: Mon, 1 Jun 2020 11:39:10 +0800 Message-Id: <1590982751-13401-6-git-send-email-vincent.chen@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1590982751-13401-1-git-send-email-vincent.chen@sifive.com> References: <1590982751-13401-1-git-send-email-vincent.chen@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200531_204007_564473_A8CFD91E X-CRM114-Status: GOOD ( 15.05 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:643 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kgdb-bugreport@lists.sourceforge.net, linux-riscv@lists.infradead.org, Vincent Chen Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org The $status, $badaddr, and $cause registers belong to the thread context, so KGDB can obtain their contents from pt_regs in each trap. However, the sequential number of these registers in the gdb register list is far from the general-purpose registers. If riscv port uses the existing method to report these three registers, many trivial registers with sequence numbers in the middle of them will also be packaged to the reply packets. To solve this problem, the riscv port wants to introduce the GDB target description mechanism to customize the reported register list. By the list, the KGDB can ignore the intermediate registers and just reports the general-purpose registers and these three system registers. Signed-off-by: Vincent Chen Reviewed-by: Palmer Dabbelt --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/gdb_xml.h | 116 +++++++++++++++++++++++++++++++++++++++ arch/riscv/include/asm/kgdb.h | 10 +++- arch/riscv/kernel/kgdb.c | 15 +++++ 4 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/include/asm/gdb_xml.h diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index c12d471280f7..4f95c0ea24b1 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -70,6 +70,7 @@ config RISCV select HAVE_COPY_THREAD_TLS select HAVE_ARCH_KASAN if MMU && 64BIT select HAVE_ARCH_KGDB + select HAVE_ARCH_KGDB_QXFER_PKT config ARCH_MMAP_RND_BITS_MIN default 18 if 64BIT diff --git a/arch/riscv/include/asm/gdb_xml.h b/arch/riscv/include/asm/gdb_xml.h new file mode 100644 index 000000000000..09342111f227 --- /dev/null +++ b/arch/riscv/include/asm/gdb_xml.h @@ -0,0 +1,116 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ASM_GDB_XML_H_ +#define __ASM_GDB_XML_H_ + +const char riscv_gdb_stub_feature[64] = + "PacketSize=800;qXfer:features:read+;"; + +static const char gdb_xfer_read_target[31] = "qXfer:features:read:target.xml:"; + +#ifdef CONFIG_64BIT +static const char gdb_xfer_read_cpuxml[39] = + "qXfer:features:read:riscv-64bit-cpu.xml"; + +static const char riscv_gdb_stub_target_desc[256] = +"l" +"" +"" +"" +""; + +static const char riscv_gdb_stub_cpuxml[2048] = +"l" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +""; +#else +static const char gdb_xfer_read_cpuxml[39] = + "qXfer:features:read:riscv-32bit-cpu.xml"; + +static const char riscv_gdb_stub_target_desc[256] = +"l" +"" +"" +"" +""; + +static const char riscv_gdb_stub_cpuxml[2048] = +"l" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +""; +#endif +#endif diff --git a/arch/riscv/include/asm/kgdb.h b/arch/riscv/include/asm/kgdb.h index a348efbf04d1..46677daf708b 100644 --- a/arch/riscv/include/asm/kgdb.h +++ b/arch/riscv/include/asm/kgdb.h @@ -7,7 +7,7 @@ #define GDB_SIZEOF_REG sizeof(unsigned long) -#define DBG_MAX_REG_NUM (33) +#define DBG_MAX_REG_NUM (36) #define NUMREGBYTES ((DBG_MAX_REG_NUM) * GDB_SIZEOF_REG) #define CACHE_FLUSH_IS_SAFE 1 #define BUFMAX 2048 @@ -64,6 +64,9 @@ static inline void arch_kgdb_breakpoint(void) #define DBG_REG_T5 "t5" #define DBG_REG_T6 "t6" #define DBG_REG_EPC "pc" +#define DBG_REG_STATUS "sstatus" +#define DBG_REG_BADADDR "stval" +#define DBG_REG_CAUSE "scause" #define DBG_REG_ZERO_OFF 0 #define DBG_REG_RA_OFF 1 @@ -101,5 +104,10 @@ static inline void arch_kgdb_breakpoint(void) #define DBG_REG_STATUS_OFF 33 #define DBG_REG_BADADDR_OFF 34 #define DBG_REG_CAUSE_OFF 35 + +extern const char riscv_gdb_stub_feature[64]; + +#define kgdb_arch_gdb_stub_feature riscv_gdb_stub_feature + #endif #endif diff --git a/arch/riscv/kernel/kgdb.c b/arch/riscv/kernel/kgdb.c index e6b1f989f704..3b7276cadbe3 100644 --- a/arch/riscv/kernel/kgdb.c +++ b/arch/riscv/kernel/kgdb.c @@ -10,6 +10,7 @@ #include #include #include +#include enum { NOT_KGDB_BREAK = 0, @@ -51,6 +52,9 @@ struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = { {DBG_REG_T5, GDB_SIZEOF_REG, offsetof(struct pt_regs, t5)}, {DBG_REG_T6, GDB_SIZEOF_REG, offsetof(struct pt_regs, t6)}, {DBG_REG_EPC, GDB_SIZEOF_REG, offsetof(struct pt_regs, epc)}, + {DBG_REG_STATUS, GDB_SIZEOF_REG, offsetof(struct pt_regs, status)}, + {DBG_REG_BADADDR, GDB_SIZEOF_REG, offsetof(struct pt_regs, badaddr)}, + {DBG_REG_CAUSE, GDB_SIZEOF_REG, offsetof(struct pt_regs, cause)}, }; char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs) @@ -103,6 +107,17 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc) regs->epc = pc; } +void kgdb_arch_handle_qxfer_pkt(char *remcom_in_buffer, + char *remcom_out_buffer) +{ + if (!strncmp(remcom_in_buffer, gdb_xfer_read_target, + sizeof(gdb_xfer_read_target))) + strcpy(remcom_out_buffer, riscv_gdb_stub_target_desc); + else if (!strncmp(remcom_in_buffer, gdb_xfer_read_cpuxml, + sizeof(gdb_xfer_read_cpuxml))) + strcpy(remcom_out_buffer, riscv_gdb_stub_cpuxml); +} + static inline void kgdb_arch_update_addr(struct pt_regs *regs, char *remcom_in_buffer) {