From: Andrew Burgess <andrew.burgess@embecosm.com>
To: binutils@sourceware.org, gdb-patches@sourceware.org
Subject: [PATCH 8/8] gdb/riscv: write CSRs into baremetal core dumps
Date: Wed, 2 Dec 2020 17:39:32 +0000 [thread overview]
Message-ID: <1596bba6bdc41f131291740162ac6c8f0aac7aac.1606930261.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1606930261.git.andrew.burgess@embecosm.com>
Use the current target description to include CSRs into the RISC-V
baremetal core dumps.
Every CSR declared in the current target description will be included
in the core dump. If a CSR fails to read then the value 0 will be
placed into the core dump instead.
It will be critical for users that they have the same target
description in use when loading the core file as was in use when
writing the core file. This should be fine if the user allows the
target description to be written into the core file.
gdb/ChangeLog:
* riscv-non-tdep.c (riscv_csrset): New static global.
(riscv_update_csrmap): New function.
(riscv_iterate_over_regset_sections): Process CSRs.
---
gdb/ChangeLog | 7 +++++
gdb/riscv-none-tdep.c | 60 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+)
diff --git a/gdb/riscv-none-tdep.c b/gdb/riscv-none-tdep.c
index 0a4215a60e9..b20e2d8f475 100644
--- a/gdb/riscv-none-tdep.c
+++ b/gdb/riscv-none-tdep.c
@@ -27,6 +27,8 @@
#include "riscv-tdep.h"
#include "elf-bfd.h"
#include "regset.h"
+#include "user-regs.h"
+#include "target-descriptions.h"
/* Function declarations. */
@@ -250,6 +252,42 @@ static const struct regset riscv_fregset =
riscv_fregmap, riscv_supply_regset, regcache_collect_regset
};
+/* Define the CSR regset, this is not constant as the regmap field is
+ updated dynamically based on the current target description. */
+
+static struct regset riscv_csrset =
+{
+ nullptr, regcache_supply_regset, regcache_collect_regset
+};
+
+/* Update the regmap field of RISCV_CSRSET based on the CSRs available in
+ the current target description. */
+
+static void
+riscv_update_csrmap (struct gdbarch *gdbarch,
+ const struct tdesc_feature *feature_csr)
+{
+ int i = 0;
+
+ /* Release any previously defined map. */
+ delete[] ((struct regcache_map_entry *) riscv_csrset.regmap);
+
+ /* Now create a register map for every csr found in the target
+ description. */
+ struct regcache_map_entry *riscv_csrmap
+ = new struct regcache_map_entry[feature_csr->registers.size() + 1];
+ for (auto &csr : feature_csr->registers)
+ {
+ int regnum = user_reg_map_name_to_regnum (gdbarch, csr->name.c_str(),
+ csr->name.length());
+ riscv_csrmap[i++] = {1, regnum, 0};
+ }
+
+ /* Mark the end of the array. */
+ riscv_csrmap[i] = {0};
+ riscv_csrset.regmap = riscv_csrmap;
+}
+
/* Callback for iterate_over_regset_sections that records a single regset
in the corefile note section. */
@@ -313,6 +351,28 @@ riscv_iterate_over_regset_sections (struct gdbarch *gdbarch,
+ register_size (gdbarch, RISCV_CSR_FCSR_REGNUM));
cb (".reg2", sz, sz, &riscv_fregset, NULL, cb_data);
}
+
+ /* Read or write the CSRs. The set of CSRs is defined by the current
+ target description. The user is responsible for ensuring that the
+ same target description is in use when reading the core file as was
+ in use when writing the core file. */
+ const struct target_desc *tdesc = gdbarch_target_desc (gdbarch);
+
+ /* Do not dump/load any CSRs if there is no target description or the target
+ description does not contain any CSRs. */
+ if (tdesc != nullptr)
+ {
+ const struct tdesc_feature *feature_csr
+ = tdesc_find_feature (tdesc, riscv_feature_name_csr);
+ if (feature_csr != nullptr && feature_csr->registers.size () > 0)
+ {
+ riscv_update_csrmap (gdbarch, feature_csr);
+ cb (".reg-riscv-csr",
+ (feature_csr->registers.size() * riscv_isa_xlen (gdbarch)),
+ (feature_csr->registers.size() * riscv_isa_xlen (gdbarch)),
+ &riscv_csrset, NULL, cb_data);
+ }
+ }
}
/* Initialize RISC-V bare-metal ABI info. */
--
2.25.4
next prev parent reply other threads:[~2020-12-02 17:40 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-02 17:39 [PATCH 0/8] Bare-metal core dumps for RISC-V Andrew Burgess
2020-12-02 17:39 ` [PATCH 1/8] gdb/riscv: use a single regset supply function for riscv fbsd & linux Andrew Burgess
2021-01-18 14:15 ` Andrew Burgess
2020-12-02 17:39 ` [PATCH 2/8] bfd/binutils: support for gdb target descriptions in the core file Andrew Burgess
2020-12-02 18:21 ` Luis Machado via Gdb-patches
2020-12-02 22:58 ` Jim Wilson
2020-12-03 12:16 ` Luis Machado via Gdb-patches
[not found] ` <20201214115512.GI2945@embecosm.com>
2021-01-11 10:19 ` Andrew Burgess
2021-01-11 13:03 ` Luis Machado via Gdb-patches
2020-12-07 12:48 ` Andrew Burgess
2020-12-02 17:39 ` [PATCH 3/8] gdb: write target description into " Andrew Burgess
2020-12-03 20:36 ` Tom Tromey
2020-12-07 14:38 ` Andrew Burgess
2020-12-02 17:39 ` [PATCH 4/8] bfd/riscv: prepare to handle bare metal core dump creation Andrew Burgess
2020-12-02 23:24 ` Jim Wilson
2020-12-07 14:39 ` Andrew Burgess
2020-12-02 17:39 ` [PATCH 5/8] gdb/riscv: introduce bare metal core dump support Andrew Burgess
2020-12-02 18:12 ` Luis Machado via Gdb-patches
2020-12-07 15:17 ` Andrew Burgess
2020-12-07 15:58 ` Luis Machado via Gdb-patches
2020-12-07 16:58 ` Andrew Burgess
2020-12-07 17:24 ` Luis Machado via Gdb-patches
2020-12-07 18:11 ` Andrew Burgess
2020-12-07 19:00 ` Luis Machado via Gdb-patches
2020-12-07 19:23 ` Andrew Burgess
2020-12-07 19:39 ` Luis Machado via Gdb-patches
2020-12-07 19:51 ` Paul Mathieu via Gdb-patches
2020-12-13 10:13 ` Fredrik Hederstierna via Gdb-patches
2020-12-02 17:39 ` [PATCH 6/8] bfd/binutils: add support for RISC-V CSRs in core files Andrew Burgess
2020-12-02 23:50 ` Jim Wilson
2020-12-07 15:19 ` Andrew Burgess
2020-12-14 13:37 ` Andrew Burgess
2020-12-02 17:39 ` [PATCH 7/8] gdb/riscv: make riscv target description names global Andrew Burgess
2020-12-02 17:39 ` Andrew Burgess [this message]
2020-12-02 23:59 ` [PATCH 0/8] Bare-metal core dumps for RISC-V Jim Wilson
2020-12-07 12:10 ` Andrew Burgess
2020-12-07 19:57 ` Jim Wilson
2020-12-03 20:40 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1596bba6bdc41f131291740162ac6c8f0aac7aac.1606930261.git.andrew.burgess@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=binutils@sourceware.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox