summaryrefslogtreecommitdiff
path: root/gdbserver
diff options
context:
space:
mode:
authorLuis Machado <luis.machado@arm.com>2022-08-22 17:04:41 +0100
committerLuis Machado <luis.machado@arm.com>2022-12-09 13:41:15 +0000
commitba60b96371b1cfdf5c4548545269f89bc42649ef (patch)
treecbf099bc27493fddaaf8f4816a9ba5b6738ef7a2 /gdbserver
parent73425813c1b6286fd589fcf0ef9335e8240137a9 (diff)
[aarch64] Add TPIDR2 register support for Linux
With the AArch64 Scalable Matrix Extension we have a new TPIDR2 register, and it will be added to the existing NT_ARM_TLS register set. Kernel patches are being reviewed here: https://lore.kernel.org/linux-arm-kernel/20220818170111.351889-1-broonie@kernel.org/ From GDB's perspective, we handle it in a similar way to the existing TPIDR register. But we need to consider cases of systems that only have TPIDR and systems that have both TPIDR and TPIDR2. With that in mind, the following patch adds the required code to support TPIDR2 and turns the org.gnu.gdb.aarch64.tls feature into a dynamically-generated target description as opposed to a static target description containing only TPIDR. That means we can remove the gdb/features/aarch64-tls.xml file and replace the existing gdb/features/aarch64-tls.c auto-generated file with a new file that dynamically generates the target description containing either TPIDR alone or TPIDR and TPIDR2. In the future, when *BSD's start to support this register, they can just enable it as is being done for the AArch64 Linux target. The core file read/write code has been updated to support TPIDR2 as well. On GDBserver's side, there is a small change to the find_regno function to expose a non-throwing version of it. It always seemed strange to me how find_regno causes the whole operation to abort if it doesn't find a particular register name. The patch moves code from find_regno into find_regno_no_throw and makes find_regno call find_regno_no_throw instead. This allows us to do register name lookups to find a particular register number without risking erroring out if nothing is found. The patch also adjusts the feature detection code for aarch64-fbsd, since the infrastructure is shared amongst all aarch64 targets. I haven't added code to support TPIDR2 in aarch64-fbsd though, as I'm not sure when/if that will happen.
Diffstat (limited to 'gdbserver')
-rw-r--r--gdbserver/linux-aarch64-low.cc24
-rw-r--r--gdbserver/regcache.cc20
-rw-r--r--gdbserver/regcache.h5
3 files changed, 40 insertions, 9 deletions
diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc
index db508696261..b657a265ee7 100644
--- a/gdbserver/linux-aarch64-low.cc
+++ b/gdbserver/linux-aarch64-low.cc
@@ -292,9 +292,16 @@ aarch64_store_mteregset (struct regcache *regcache, const void *buf)
static void
aarch64_fill_tlsregset (struct regcache *regcache, void *buf)
{
+ gdb_byte *tls_buf = (gdb_byte *) buf;
int tls_regnum = find_regno (regcache->tdesc, "tpidr");
- collect_register (regcache, tls_regnum, buf);
+ collect_register (regcache, tls_regnum, tls_buf);
+
+ /* Read TPIDR2, if it exists. */
+ gdb::optional<int> regnum = find_regno_no_throw (regcache->tdesc, "tpidr2");
+
+ if (regnum.has_value ())
+ collect_register (regcache, *regnum, tls_buf + sizeof (uint64_t));
}
/* Store TLS register to regcache. */
@@ -302,9 +309,16 @@ aarch64_fill_tlsregset (struct regcache *regcache, void *buf)
static void
aarch64_store_tlsregset (struct regcache *regcache, const void *buf)
{
+ gdb_byte *tls_buf = (gdb_byte *) buf;
int tls_regnum = find_regno (regcache->tdesc, "tpidr");
- supply_register (regcache, tls_regnum, buf);
+ supply_register (regcache, tls_regnum, tls_buf);
+
+ /* Write TPIDR2, if it exists. */
+ gdb::optional<int> regnum = find_regno_no_throw (regcache->tdesc, "tpidr2");
+
+ if (regnum.has_value ())
+ supply_register (regcache, *regnum, tls_buf + sizeof (uint64_t));
}
bool
@@ -795,8 +809,8 @@ aarch64_adjust_register_sets (const struct aarch64_features &features)
regset->size = AARCH64_LINUX_SIZEOF_MTE;
break;
case NT_ARM_TLS:
- if (features.tls)
- regset->size = AARCH64_TLS_REGS_SIZE;
+ if (features.tls > 0)
+ regset->size = AARCH64_TLS_REGISTER_SIZE * features.tls;
break;
default:
gdb_assert_not_reached ("Unknown register set found.");
@@ -829,7 +843,7 @@ aarch64_target::low_arch_setup ()
features.pauth = linux_get_hwcap (8) & AARCH64_HWCAP_PACA;
/* A-profile MTE is 64-bit only. */
features.mte = linux_get_hwcap2 (8) & HWCAP2_MTE;
- features.tls = true;
+ features.tls = aarch64_tls_register_count (tid);
current_process ()->tdesc = aarch64_linux_read_description (features);
diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 5cbcea978a0..1c84ef674bf 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -244,16 +244,28 @@ registers_from_string (struct regcache *regcache, char *buf)
hex2bin (buf, registers, len / 2);
}
-int
-find_regno (const struct target_desc *tdesc, const char *name)
+/* See regcache.h */
+
+gdb::optional<int>
+find_regno_no_throw (const struct target_desc *tdesc, const char *name)
{
for (int i = 0; i < tdesc->reg_defs.size (); ++i)
{
if (strcmp (name, find_register_by_number (tdesc, i).name) == 0)
return i;
}
- internal_error ("Unknown register %s requested",
- name);
+ return {};
+}
+
+int
+find_regno (const struct target_desc *tdesc, const char *name)
+{
+ gdb::optional<int> regnum = find_regno_no_throw (tdesc, name);
+
+ if (regnum.has_value ())
+ return *regnum;
+
+ internal_error ("Unknown register %s requested", name);
}
static void
diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h
index 731c18d16e2..b67eefbe04b 100644
--- a/gdbserver/regcache.h
+++ b/gdbserver/regcache.h
@@ -110,6 +110,11 @@ int register_cache_size (const struct target_desc *tdesc);
int register_size (const struct target_desc *tdesc, int n);
+/* No throw version of find_regno. If NAME is not a known register, return
+ an empty value. */
+gdb::optional<int> find_regno_no_throw (const struct target_desc *tdesc,
+ const char *name);
+
int find_regno (const struct target_desc *tdesc, const char *name);
void supply_register (struct regcache *regcache, int n, const void *buf);