From patchwork Sun Apr 12 01:42:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Chen X-Patchwork-Id: 11484277 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 ADAB481 for ; Sun, 12 Apr 2020 01:42:54 +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 8659120708 for ; Sun, 12 Apr 2020 01:42:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PD/lfmvG"; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="bfGoqTX3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8659120708 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=A+oedu93ee4lBnDm/Q0/OOEeGi6QyaP6RZRVkOxDT3Y=; b=PD/lfmvG7YW1j/ 6D43lx3j5S+lVZT4868jjOwd9d+KK4qjA4bRd5vkcjdejIwdOA61cIJtcB/PH0IkuLGBiHLkttiQj 4bXFVCKfn2M4hX1zL3IDLTbDQPBD5BDc3ABsG3cIrgh+pdsYs8+OCwqSPSOXdbzMK46tMgV/TtKfp GzO5UJhOK6I5p7Fz7d2UKVaI9tdtDJeZU2HvLwrcGT9pM1sB0surbRrX8fHerHrqyB2X2gdQmfDOX KcTz9OBeXCVDc09GE83BmOatUQhxt1sf7FNTB8aWUm6QJUW8QWjhVpqt3MXiIIbYrwtD3BrbUfz5X dFW3p+9Cq0ESkG+TNtDw==; 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 1jNRe5-0004By-EQ; Sun, 12 Apr 2020 01:42:49 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jNRdz-00046C-Nu for linux-riscv@lists.infradead.org; Sun, 12 Apr 2020 01:42:45 +0000 Received: by mail-pg1-x544.google.com with SMTP id n13so2849972pgp.11 for ; Sat, 11 Apr 2020 18:42:43 -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=A+oedu93ee4lBnDm/Q0/OOEeGi6QyaP6RZRVkOxDT3Y=; b=bfGoqTX3asZVTxuEt1mjtWuXh+cM02cG8VIeObf//T6gjDhgCMiA3Dlld9oKhmVql8 lbNJg+upbba3iA0gHXKxAnHn9Dpeq/JPXVHvvmlnw4Cl8n96fXkUWaYUo98vJ8pJ1Oy8 bt+gHt0adxx+q1N8d0qTg2nvkyBKxuVc+eejz0BEggH0URYrxDrRD/wn39z89LsGqnoI 9meYwUupLWlpifU60bz1McZ31rgyK9vGlshx/SzhwTaviomPrT/+SUoaVZhOHW2u5Uvy JomzOet7xAD14pWQD07NpGVMXLeYXESHrV98Nb29/a3LXiIbMBIqnzMPdGufgwqujuZg Eqsw== 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=A+oedu93ee4lBnDm/Q0/OOEeGi6QyaP6RZRVkOxDT3Y=; b=Szn3SywnyvsaGoC/YI3whNw0emQE/uXErS0xkbTYO2qlEYMKKQ6OEU1ldfJDOq+lac HUGgBEVkrDLv2vtDRkXJ18rw29QIEwc0tehh6YeuNcFArOfftRV3j7VzzZlXAMJNQ1xM lYUsaddwHob2VHsK9mogx4TJlaPskNSg9Pu6E8X/HdxbzALZQSe0ikDKOWgiMdb3y3g3 BEnWTDzEQmzWZy+d54B9tR1zxmyrL7ZB9ZXu2ycwVXHzvDjL/M7b8nObDEkT2sCSr3pe cHj2qTb7mE5unnZHQpKCt3uhKjfUWXGzBJG4T8+YoqnNpoMSThtj/Edrjgp+td1OjD06 4AYQ== X-Gm-Message-State: AGi0PuYveS5kQtUYnXY4QN8wax2IbNvy6j6+VbKiBOOHhKRtdHHLY+dP a8bamBurJpWyy0SVXuu/F05NEtxuWGQ= X-Google-Smtp-Source: APiQypKqQrGXGJCj6/2G8NG6u3zg5TsvaOe4fYBrcprgQlA/QWCheAVDVs18AUN4LPSmPgeybc/Djg== X-Received: by 2002:aa7:9471:: with SMTP id t17mr11716246pfq.272.1586655762986; Sat, 11 Apr 2020 18:42:42 -0700 (PDT) Received: from localhost.localdomain (123-195-35-41.dynamic.kbronet.com.tw. [123.195.35.41]) by smtp.gmail.com with ESMTPSA id w90sm5252900pjj.2.2020.04.11.18.42.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Apr 2020 18:42:42 -0700 (PDT) From: Vincent Chen To: daniel.thompson@linaro.org, paul.walmsley@sifive.com, palmer@dabbelt.com Subject: [PATCH v3 4/5] riscv: Use the XML target descriptions to report 3 system registers Date: Sun, 12 Apr 2020 09:42:00 +0800 Message-Id: <1586655721-22567-5-git-send-email-vincent.chen@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1586655721-22567-1-git-send-email-vincent.chen@sifive.com> References: <1586655721-22567-1-git-send-email-vincent.chen@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200411_184243_850836_24E8DFFC X-CRM114-Status: GOOD ( 15.09 ) 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:544 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_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 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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 $sstatus, $badaddr, and $scause 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 --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/gdb_xml.h | 117 +++++++++++++++++++++++++++++++++++++++ arch/riscv/include/asm/kgdb.h | 8 ++- arch/riscv/kernel/kgdb.c | 15 +++++ 4 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/include/asm/gdb_xml.h diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 7db9a81cda75..6730468e8b92 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -69,6 +69,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..041b45f5b997 --- /dev/null +++ b/arch/riscv/include/asm/gdb_xml.h @@ -0,0 +1,117 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ASM_GDB_XML_H_ +#define __ASM_GDB_XML_H_ + +#define kgdb_arch_gdb_stub_feature riscv_gdb_stub_feature +static 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 69bc6a03081d..6c35a853940d 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 @@ -66,6 +66,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 @@ -103,5 +106,8 @@ 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 + +#include + #endif #endif diff --git a/arch/riscv/kernel/kgdb.c b/arch/riscv/kernel/kgdb.c index 6bdc0908a5b8..eb1afab47679 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) {