From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id JbH0HEoLGGDbCAAAWB0awg (envelope-from ) for ; Mon, 01 Feb 2021 09:08:10 -0500 Received: by simark.ca (Postfix, from userid 112) id 6EA611EF80; Mon, 1 Feb 2021 09:08:10 -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.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,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 F1AEB1E590 for ; Mon, 1 Feb 2021 09:08:09 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A33FA388A403; Mon, 1 Feb 2021 14:08:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A33FA388A403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1612188489; bh=+gJXH8wZF8bYlJ1H92pzM0E1+pvcg4IjsjLjuvg9mtw=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=X2/Eg7Quk2AOMJfRf32HXOMDG5l8V47OiZ2ZrdnoAA5NQcxeg9gJiOMOXPtW65Qzv Ei96jx87XuHDh4xxiAeoh5KwsETbfYLwQqUdITQ1U1Gl4UJhLB0xPyjJ3lt7LrfxgE 0i3ZN9Z3ng+lcqT44Q2K2BYe9sup0cZ8q77Ejd1Q= Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by sourceware.org (Postfix) with ESMTPS id BD61E3836C21 for ; Mon, 1 Feb 2021 14:08:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BD61E3836C21 Received: by mail-qt1-x82a.google.com with SMTP id v3so12270042qtw.4 for ; Mon, 01 Feb 2021 06:08:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=+gJXH8wZF8bYlJ1H92pzM0E1+pvcg4IjsjLjuvg9mtw=; b=Om+Aw2IJmKadaUlnhcz4TvEri2iDg6MRhG2O8E8YmWbnM0+UVht5Fxpzc/wAJBqaC1 2iKAzLbJcqH9bPzG0/0Q5FLviFCOF/RC07C+pUiXCIFntv8FqfNFlXlgod1z2oLDOEYG ep8eqybHTNMwTsIT+31XU/Dyd7TPXIr0HPwLoUTe4RKF1Z5VvoiJBxhhW1lQUCk+ZTbs s2V5p8r3z3SdZ/nu99jzWxYMDi+HB5PLkq9O8whnBgRRf+A3GHDemvYcbdK9XDL+/rCE XigpSMTt4gBeUrWmceomh2d4U+tk/jjuyM3C6SQ/1c3BTGQqkGiOl2HwSRoAOWUMrDN2 sYyw== X-Gm-Message-State: AOAM531FUn/6t4j050BqrRkhb36Jn2R4sRM47vrv0rokEBCDWUOwBS61 sZxjdGjFvit2lBk4y66iPXfmqg== X-Google-Smtp-Source: ABdhPJwUecAHKjVQc/dpbzlLNbAmx6JHUgrqRszVMTbY/Wwvy3Y6Px/fZIhpQdxhuEhe6knUX+S1dw== X-Received: by 2002:ac8:6bcd:: with SMTP id b13mr6430694qtt.30.1612188485222; Mon, 01 Feb 2021 06:08:05 -0800 (PST) Received: from ?IPv6:2804:7f0:8284:848d:c0e:b160:155c:b079? ([2804:7f0:8284:848d:c0e:b160:155c:b079]) by smtp.gmail.com with ESMTPSA id y66sm14333896qka.17.2021.02.01.06.08.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Feb 2021 06:08:04 -0800 (PST) Subject: Re: [PATCHv2 6/9] bfd/binutils: add support for RISC-V CSRs in core files To: Andrew Burgess , gdb-patches@sourceware.org, binutils@sourceware.org References: <20210201120036.GT265215@embecosm.com> Message-ID: Date: Mon, 1 Feb 2021 11:08:01 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210201120036.GT265215@embecosm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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: , From: Luis Machado via Gdb-patches Reply-To: Luis Machado Cc: Fredrik Hederstierna Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 2/1/21 9:00 AM, Andrew Burgess wrote: > Here is an update version of this patch. > > In this patch I have placed the CSRs into a note named "GDB". This > should protect us if, in the future, the note type number I have used > is reused by some other core file producer (Linux / FreeBSD) and given > a different meaning. > > Any feedback? > > Thanks, > Andrew > > > --- > > commit 15bcb460981a000e74b2d3dc4f59f0f06bc0cd52 > Author: Andrew Burgess > Date: Fri Nov 27 14:04:16 2020 +0000 > > bfd/binutils: add support for RISC-V CSRs in core files > > 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 > > As I have not yet heard if the above patch will be accepted into the > kernel or not I have set the note name string to "GDB", and the note > type to NT_RISCV_CSR. > > This means that if the above patch is rejected from the kernel, and > the note type number 0x900 is assigned to some other note type, we > will still be able to distinguish between the GDB produced > NT_RISCV_CSR, and the kernel produced notes, where the name would be > set to "CORE". > > 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. > > diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h > index 779acc745bc..5b7eb8897c8 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 c6cf7fe2d6e..d1fd29f380a 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) > { > @@ -10583,6 +10589,13 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note) > else > return TRUE; > > + case NT_RISCV_CSR: > + if (note->namesz == 4 > + && strcmp (note->namedata, "GDB") == 0) > + return elfcore_grok_riscv_csr (abfd, note); > + else > + return TRUE; > + > case NT_PRPSINFO: > case NT_PSINFO: > if (bed->elf_backend_grok_psinfo) > @@ -11964,6 +11977,18 @@ 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 = "GDB"; > + return elfcore_write_note (abfd, buf, bufsiz, > + note_name, NT_RISCV_CSR, csrs, size); > +} > + > char * > elfcore_write_gdb_tdesc (bfd *abfd, > char *buf, > @@ -12062,6 +12087,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..4cb3748e4fd 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. */ > > LGTM.