public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Yvan Roux <yvan.roux@foss.st.com>
To: <gdb-patches@sourceware.org>
Cc: Luis Machado <luis.machado@arm.com>,
	Torbjorn SVENSSON <torbjorn.svensson@foss.st.com>
Subject: [PATCH] gdb/arm: Only stack S16..S31 when FPU registers are secure
Date: Tue, 14 Jun 2022 16:47:51 +0200	[thread overview]
Message-ID: <20220614144751.GA12000@gnbcxd0114.gnb.st.com> (raw)

Hi,

The FPCCR.TS bit is used to identify if FPU registers are considered
non-secure or secure. If they are secure, then callee saved registers
(S16 to S31) are stacked on exception entry or otherwise skipped.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Signed-off-by: Yvan Roux <yvan.roux@foss.st.com>
---
 gdb/arch/arm.h | 6 ++++++
 gdb/arm-tdep.c | 9 ++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/gdb/arch/arm.h b/gdb/arch/arm.h
index 4ad329f6f1f..de1b472fe71 100644
--- a/gdb/arch/arm.h
+++ b/gdb/arch/arm.h
@@ -136,6 +136,12 @@ enum arm_m_profile_type {
 
 #define XPSR_T		0x01000000
 
+/* System control registers addresses.  */
+
+/* M-profile Floating-Point Context Control Register address, defined in ARMv7-M
+   (Section B3.2.2) and ARMv8-M (Section D1.2.99) reference manuals.  */
+#define FPCCR		0xE000EF34
+
 /* Size of registers.  */
 
 #define ARM_INT_REGISTER_SIZE		4
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 456649afdaa..abc812817aa 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -3519,6 +3519,13 @@ arm_m_exception_cache (struct frame_info *this_frame)
     {
       int i;
       int fpu_regs_stack_offset;
+      ULONGEST fpccr;
+      bool fpccr_ts;
+
+      /* Read FPCCR register */
+      gdb_assert (safe_read_memory_unsigned_integer (FPCCR, 4, byte_order,
+						     &fpccr));
+      fpccr_ts = fpccr & (1 << 26);
 
       /* This code does not take into account the lazy stacking, see "Lazy
 	 context save of FP state", in B1.5.7, also ARM AN298, supported
@@ -3538,7 +3545,7 @@ arm_m_exception_cache (struct frame_info *this_frame)
       cache->saved_regs[ARM_FPSCR_REGNUM].set_addr (unwound_sp + sp_r0_offset + 0x60);
       fpu_regs_stack_offset += 4;
 
-      if (tdep->have_sec_ext && !default_callee_register_stacking)
+      if (tdep->have_sec_ext && !default_callee_register_stacking && fpccr_ts)
 	{
 	  /* Handle floating-point callee saved registers.  */
 	  fpu_regs_stack_offset = unwound_sp + sp_r0_offset + 0x68;
-- 
2.17.1

             reply	other threads:[~2022-06-14 14:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14 14:47 Yvan Roux [this message]
2022-06-21 14:19 ` Luis Machado
2022-06-29  9:52   ` Yvan Roux
2022-06-29 10:55     ` 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=20220614144751.GA12000@gnbcxd0114.gnb.st.com \
    --to=yvan.roux@foss.st.com \
    --cc=gdb-patches@sourceware.org \
    --cc=luis.machado@arm.com \
    --cc=torbjorn.svensson@foss.st.com \
    /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).