From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QALXGFGRCGCuZAAAWB0awg (envelope-from ) for ; Wed, 20 Jan 2021 15:23:45 -0500 Received: by simark.ca (Postfix, from userid 112) id 0129E1EF80; Wed, 20 Jan 2021 15:23:43 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=DKIM_SIGNED,MAILING_LIST_MULTI, RDNS_NONE,T_DKIM_INVALID,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 40ABB1E590 for ; Wed, 20 Jan 2021 15:23:42 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8DD233971813; Wed, 20 Jan 2021 20:23:33 +0000 (GMT) Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 9BA133971823 for ; Wed, 20 Jan 2021 20:23:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9BA133971823 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x42f.google.com with SMTP id a9so20867280wrt.5 for ; Wed, 20 Jan 2021 12:23:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zC3JIQiBBLfJ7o8wMcg0Ru4B2vj0HEcWh3D+LsOtBS4=; b=TBAUKcsYIQBBEbRul1vNkk8U1wrFtwNhPSGLbWLE1jn+KKTvpSj/GoaXqFa5wqfMQw S/TR/7St5xvp9wuVJpiDnsgGJSXaSKnSkwbNM4crbFzX0MZIcLrJPjzJZ98gTlQhHvBh jEXiNzeagRr7CuTOATSV+hLF7U7WSAliwfycelzntt2QgPjPOUTquRbVgr3bhTH025MK Vqw7tyUsnAllqAxFAqGGCpOmUugr1s1W5EWcOkJCX2OgFsegIU9CkIZGkWbiARxj93me iqLhxMo63TRaMogyfRGEFyH5Lej4VPIDXp5Wj1m1xy32B+5v0vySUvT+XC+Juz+fXxqx fw6A== 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:mime-version:content-transfer-encoding; bh=zC3JIQiBBLfJ7o8wMcg0Ru4B2vj0HEcWh3D+LsOtBS4=; b=s/UOnDNOJ9bjZ30KFTPHvYnHDtKtHpEs+1EMg9x/TbGRbSHFJ/Yz1JcXuIrUB2L8AK LuVFyP45GA10XVHTW3QNzr2WSz2hRG9YTXwf1oxgNKProTGGRy86hof/sA8NN9VaBbbO lBayylcBdm6XJAU53/9QQ6lb4e15iBO7XgtoGbAh5macTNfjKchnsweLdkwvWFx0A1k1 lOsoCfH9O44JvB6JfNKwBRc4zyi4zYfdTTUClY1ZK3pJHMimjzHzjCDUP4Vws3OuvDGn wF0lyCTx/QUngr3AGqbs2PXQsnUxXD0IwSFszzLMQ/sQhm1qyTQMMcH0RJyJ0kAt7tYh ExYw== X-Gm-Message-State: AOAM533wRpRJZo5//eOMJ+HlAdvTJqiyIdwHXO3OCLV/BYt6LIdDpbAW WC+yPS2tcRmWY9FT6QwbFYEd+AFQiLEyrQ== X-Google-Smtp-Source: ABdhPJwtELs+8SrNV3I2574xSaWsdkEyGN4NART7D0GInOG2XTibhdndERjq4/EPR+/ftj+unRnaIA== X-Received: by 2002:adf:82c5:: with SMTP id 63mr11130958wrc.38.1611174208562; Wed, 20 Jan 2021 12:23:28 -0800 (PST) Received: from localhost (host86-180-62-229.range86-180.btcentralplus.com. [86.180.62.229]) by smtp.gmail.com with ESMTPSA id f68sm6039052wmf.6.2021.01.20.12.23.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 12:23:28 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org, binutils@sourceware.org Subject: [PATCHv2 6/9] bfd/binutils: add support for RISC-V CSRs in core files Date: Wed, 20 Jan 2021 20:23:12 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fredrik Hederstierna Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Adds support for including RISC-V control and status registers into core files. The value for the define NT_RISCV_CSR is set to 0x900, this corresponds to a patch I have proposed for the Linux kernel here: http://lists.infradead.org/pipermail/linux-riscv/2020-December/003910.html bfd/ChangeLog: * elf-bfd.h (elfcore_write_riscv_csr): Declare. * elf.c (elfcore_grok_riscv_csr): New function. (elfcore_grok_note): Handle NT_RISCV_CSR. (elfcore_write_riscv_csr): New function. (elfcore_write_register_note): Handle '.reg-riscv-csr'. binutils/ChangeLog: * readelf.c (get_note_type): Handle NT_RISCV_CSR. include/ChangeLog: * elf/common.h (NT_RISCV_CSR): Define. --- bfd/ChangeLog | 9 +++++++++ bfd/elf-bfd.h | 2 ++ bfd/elf.c | 31 +++++++++++++++++++++++++++---- binutils/ChangeLog | 5 +++++ binutils/readelf.c | 2 ++ include/ChangeLog | 5 +++++ include/elf/common.h | 2 ++ 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 4dce8114c0f..f0d90d070c3 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -2797,6 +2797,8 @@ extern char *elfcore_write_aarch_pauth (bfd *, char *, int *, const void *, int); extern char *elfcore_write_arc_v2 (bfd *, char *, int *, const void *, int); +extern char *elfcore_write_riscv_csr + (bfd *, char *, int *, const void *, int); extern char *elfcore_write_gdb_tdesc (bfd *, char *, int *, const void *, int); extern char *elfcore_write_lwpstatus diff --git a/bfd/elf.c b/bfd/elf.c index 9892ffa9faf..bdc15bf21ba 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -9912,6 +9912,12 @@ elfcore_grok_arc_v2 (bfd *abfd, Elf_Internal_Note *note) return elfcore_make_note_pseudosection (abfd, ".reg-arc-v2", note); } +static bfd_boolean +elfcore_grok_riscv_csr (bfd *abfd, Elf_Internal_Note *note) +{ + return elfcore_make_note_pseudosection (abfd, ".reg-riscv-csr", note); +} + static bfd_boolean elfcore_grok_gdb_tdesc (bfd *abfd, Elf_Internal_Note *note) { @@ -10579,6 +10585,9 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note) case NT_GDB_TDESC: return elfcore_grok_gdb_tdesc (abfd, note); + case NT_RISCV_CSR: + return elfcore_grok_riscv_csr (abfd, note); + case NT_PRPSINFO: case NT_PSINFO: if (bed->elf_backend_grok_psinfo) @@ -11960,12 +11969,24 @@ elfcore_write_arc_v2 (bfd *abfd, note_name, NT_ARC_V2, arc_v2, size); } +char * +elfcore_write_riscv_csr (bfd *abfd, + char *buf, + int *bufsiz, + const void *csrs, + int size) +{ + const char *note_name = "CORE"; + return elfcore_write_note (abfd, buf, bufsiz, + note_name, NT_RISCV_CSR, csrs, size); +} + char * elfcore_write_gdb_tdesc (bfd *abfd, - char *buf, - int *bufsiz, - const void *tdesc, - int size) + char *buf, + int *bufsiz, + const void *tdesc, + int size) { const char *note_name = "CORE"; return elfcore_write_note (abfd, buf, bufsiz, @@ -12058,6 +12079,8 @@ elfcore_write_register_note (bfd *abfd, return elfcore_write_arc_v2 (abfd, buf, bufsiz, data, size); if (strcmp (section, ".gdb-tdesc") == 0) return elfcore_write_gdb_tdesc (abfd, buf, bufsiz, data, size); + if (strcmp (section, ".reg-riscv-csr") == 0) + return elfcore_write_riscv_csr (abfd, buf, bufsiz, data, size); return NULL; } diff --git a/binutils/readelf.c b/binutils/readelf.c index feb458877c8..807eccfb026 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -18374,6 +18374,8 @@ get_note_type (Filedata * filedata, unsigned e_type) return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)"); case NT_ARC_V2: return _("NT_ARC_V2 (ARC HS accumulator/extra registers)"); + case NT_RISCV_CSR: + return _("NT_RISCV_CSR (RISC-V control and status registers)"); case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)"); case NT_FPREGS: diff --git a/include/elf/common.h b/include/elf/common.h index e6e9c278faa..79ec9cc09a8 100644 --- a/include/elf/common.h +++ b/include/elf/common.h @@ -674,6 +674,8 @@ /* note name must be "LINUX". */ #define NT_ARC_V2 0x600 /* ARC HS accumulator/extra registers. */ /* note name must be "LINUX". */ +#define NT_RISCV_CSR 0x900 /* RISC-V Control and Status Registers */ + /* note name must be "CORE". */ #define NT_SIGINFO 0x53494749 /* Fields of siginfo_t. */ #define NT_FILE 0x46494c45 /* Description of mapped files. */ -- 2.25.4