public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Luis Machado <luis.machado@arm.com>
To: <gdb-patches@sourceware.org>
Cc: <thiago.bauermann@linaro.org>
Subject: [PATCH v5 3/6] [gdb/aarch64] sme2: signal frame support
Date: Mon, 18 Sep 2023 22:27:05 +0100	[thread overview]
Message-ID: <20230918212708.660213-4-luis.machado@arm.com> (raw)
In-Reply-To: <20230918212708.660213-1-luis.machado@arm.com>

Teach gdb about the ZT state on signal frames and how to restore
the contents of the registers.

There is a new ZT_MAGIC context that the Linux Kernel uses to communicate
the ZT register state to gdb.

As mentioned before, the ZT state should only be available when the ZA state
is available.

Validated under Fast Models.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
---
 gdb/aarch64-linux-tdep.c | 65 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index 21efa42b2e6..41629902f49 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -159,6 +159,7 @@
 #define AARCH64_SVE_MAGIC			0x53564501
 #define AARCH64_ZA_MAGIC			0x54366345
 #define AARCH64_TPIDR2_MAGIC			0x54504902
+#define AARCH64_ZT_MAGIC			0x5a544e01
 
 /* Defines for the extra_context that follows an AARCH64_EXTRA_MAGIC.  */
 #define AARCH64_EXTRA_DATAP_OFFSET		8
@@ -192,6 +193,14 @@
 /* TPIDR2 register value offset in the TPIDR2 signal frame context.  */
 #define AARCH64_TPIDR2_CONTEXT_TPIDR2_OFFSET	8
 
+/* SME2 (ZT) constants.  */
+/* Offset of the field containing the number of registers in the SME2 signal
+   context state.  */
+#define AARCH64_SME2_CONTEXT_NREGS_OFFSET	8
+/* Offset of the beginning of the register data for the first ZT register in
+   the signal context state.  */
+#define AARCH64_SME2_CONTEXT_REGS_OFFSET	16
+
 /* Holds information about the signal frame.  */
 struct aarch64_linux_sigframe
 {
@@ -214,6 +223,8 @@ struct aarch64_linux_sigframe
   CORE_ADDR za_section = 0;
   /* Starting address of the section containing the TPIDR2 register.  */
   CORE_ADDR tpidr2_section = 0;
+  /* Starting address of the section containing the ZT registers.  */
+  CORE_ADDR zt_section = 0;
   /* Starting address of the section containing extra information.  */
   CORE_ADDR extra_section = 0;
 
@@ -221,10 +232,15 @@ struct aarch64_linux_sigframe
   ULONGEST vl = 0;
   /* The streaming vector length (SSVE/ZA).  */
   ULONGEST svl = 0;
+  /* Number of ZT registers in this context.  */
+  unsigned int zt_register_count = 0;
+
   /* True if we are in streaming mode, false otherwise.  */
   bool streaming_mode = false;
   /* True if we have a ZA payload, false otherwise.  */
   bool za_payload = false;
+  /* True if we have a ZT entry in the signal context, false otherwise.  */
+  bool zt_available = false;
 };
 
 /* Read an aarch64_ctx, returning the magic value, and setting *SIZE to the
@@ -478,6 +494,33 @@ aarch64_linux_read_signal_frame_info (frame_info_ptr this_frame,
 	  {
 	    /* This is context containing the tpidr2 register.  */
 	    signal_frame.tpidr2_section = section;
+	    section += size;
+	    break;
+	  }
+	case AARCH64_ZT_MAGIC:
+	  {
+	    gdb_byte buf[2];
+
+	    /* Extract the number of ZT registers available in this
+	       context.  */
+	    if (target_read_memory (section + AARCH64_SME2_CONTEXT_NREGS_OFFSET,
+				    buf, 2) != 0)
+	      {
+		warning (_("Failed to read the number of ZT registers from the "
+			   "ZT signal frame context."));
+		section += size;
+		break;
+	      }
+
+	    signal_frame.zt_register_count
+	      = extract_unsigned_integer (buf, 2, byte_order);
+
+	    /* This is a context containing the ZT registers.  This should only
+	       exist if we also have the ZA context.  The presence of the ZT
+	       context without the ZA context is invalid.  */
+	    signal_frame.zt_section = section;
+	    signal_frame.zt_available = true;
+
 	    section += size;
 	    break;
 	  }
@@ -515,6 +558,12 @@ aarch64_linux_read_signal_frame_info (frame_info_ptr this_frame,
       if (!extra_found && section > section_end)
 	break;
     }
+
+    /* Sanity check that if the ZT entry exists, the ZA entry must also
+       exist.  */
+    if (signal_frame.zt_available && !signal_frame.za_payload)
+      error (_("While reading signal context information, found a ZT context "
+	       "without a ZA context, which is invalid."));
 }
 
 /* Implement the "init" method of struct tramp_frame.  */
@@ -620,6 +669,22 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self,
       /* Restore SVG.  */
       trad_frame_set_reg_value (this_cache, tdep->sme_svg_regnum,
 				sve_vg_from_vl (signal_frame.svl));
+
+      /* Handle SME2 (ZT).  */
+      if (tdep->has_sme2 ()
+	  && signal_frame.za_section != 0
+	  && signal_frame.zt_register_count > 0)
+	{
+	  /* Is ZA state available?  */
+	  gdb_assert (svcr & SVCR_ZA_BIT);
+
+	  /* Restore the ZT state.  For now we assume that we only have
+	     a single ZT register.  If/When more ZT registers appear, we
+	     should update the code to handle that case accordingly.  */
+	  trad_frame_set_reg_addr (this_cache, tdep->sme2_zt0_regnum,
+				   signal_frame.zt_section
+				   + AARCH64_SME2_CONTEXT_REGS_OFFSET);
+	}
     }
 
   /* Restore the tpidr2 register, if the target supports it and if there is
-- 
2.25.1


  parent reply	other threads:[~2023-09-18 21:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-18 21:27 [PATCH v5 0/6] SME2 support for AArch64 gdb/gdbserver on Linux Luis Machado
2023-09-18 21:27 ` [PATCH v5 1/6] [gdb/aarch64] sme2: Enable SME2 for AArch64 gdb " Luis Machado
2023-09-18 21:27 ` [PATCH v5 2/6] [gdbserver/aarch64] sme2: Enable SME2 support in gdbserver Luis Machado
2023-09-18 21:27 ` Luis Machado [this message]
2023-09-18 21:27 ` [PATCH v5 4/6] [gdb/aarch64] sme2: Core file support for ZT register set Luis Machado
2023-09-18 21:27 ` [PATCH v5 5/6] [gdb/testsuite] sme2: Extend SME tests to include SME2 Luis Machado
2023-09-18 21:27 ` [PATCH v5 6/6] [gdb/docs] sme2: Document SME2 registers and features Luis Machado
2023-10-04 15:28 ` [PATCH v5 0/6] SME2 support for AArch64 gdb/gdbserver on Linux Luis Machado

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=20230918212708.660213-4-luis.machado@arm.com \
    --to=luis.machado@arm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=thiago.bauermann@linaro.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).