[RFC,1/5] gdb/arm: Introduce control_s and control_ns registers

Message ID 1667641476-31602-1-git-send-email-vanekt@fbl.cz
State New
Headers
Series [RFC,1/5] gdb/arm: Introduce control_s and control_ns registers |

Commit Message

Tomas Vanek Nov. 5, 2022, 9:44 a.m. UTC
  The M-profile security extension registers will be used for stack
selection in FNC_RETURN and return from secure to non-secure state.

The presence of the registers is optional.
If one or both are missing the security extension profile is accepted.
The code using the registers must check m_profile_control_[n]?s_regnum
for -1.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
---
 gdb/arm-tdep.c | 20 ++++++++++++++++++++
 gdb/arm-tdep.h |  2 ++
 2 files changed, 22 insertions(+)
  

Comments

Luis Machado Nov. 8, 2022, 11:23 a.m. UTC | #1
Hi Tomas,

On 11/5/22 09:44, Tomas Vanek wrote:
> The M-profile security extension registers will be used for stack
> selection in FNC_RETURN and return from secure to non-secure state.
> 
> The presence of the registers is optional.
> If one or both are missing the security extension profile is accepted.
> The code using the registers must check m_profile_control_[n]?s_regnum
> for -1.
> 
> Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
> ---
>   gdb/arm-tdep.c | 20 ++++++++++++++++++++
>   gdb/arm-tdep.h |  2 ++
>   2 files changed, 22 insertions(+)
> 
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index 3105543..564ee43 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -9996,6 +9996,8 @@ enum arm_vfp_cprc_base_type
>     int m_profile_psp_ns_regnum = -1;
>     int m_profile_msp_s_regnum = -1;
>     int m_profile_psp_s_regnum = -1;
> +  int m_profile_control_s_regnum = -1;
> +  int m_profile_control_ns_regnum = -1;
>     int tls_regnum = 0;
>   
>     /* If we have an object to base this architecture on, try to determine
> @@ -10473,6 +10475,22 @@ enum arm_vfp_cprc_base_type
>   		}
>   	      m_profile_psp_s_regnum = register_count++;
>   
> +	      /* Regard the control_s and control_ns registers optional,
> +	       * accept the security extension feature even without them */
> +	      valid_p = tdesc_numbered_register (feature, tdesc_data.get (),
> +						 register_count, "control_s");

What tools are advertising control_s and control_ns? We need to document those properly if we're planning on using them
as part of decision-making in GDB.


> +	      if (!valid_p)
> +		warning (_("M-profile secext feature is missing required register control_s."));
> +	      else
> +		m_profile_control_s_regnum = register_count++;
> +
> +	      valid_p = tdesc_numbered_register (feature, tdesc_data.get (),
> +						 register_count, "control_ns");
> +	      if (!valid_p)
> +		warning (_("M-profile secext feature is missing required register control_ns."));
> +	      else
> +		m_profile_control_ns_regnum = register_count++;
> +
>   	      have_sec_ext = true;
>   	    }
>   
> @@ -10553,6 +10571,8 @@ enum arm_vfp_cprc_base_type
>         tdep->m_profile_psp_ns_regnum = m_profile_psp_ns_regnum;
>         tdep->m_profile_msp_s_regnum = m_profile_msp_s_regnum;
>         tdep->m_profile_psp_s_regnum = m_profile_psp_s_regnum;
> +      tdep->m_profile_control_s_regnum = m_profile_control_s_regnum;
> +      tdep->m_profile_control_ns_regnum = m_profile_control_ns_regnum;
>       }
>   
>     arm_register_g_packet_guesses (gdbarch);
> diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h
> index bcd7e08..11670e9 100644
> --- a/gdb/arm-tdep.h
> +++ b/gdb/arm-tdep.h
> @@ -133,6 +133,8 @@ struct arm_gdbarch_tdep : gdbarch_tdep_base
>     int m_profile_psp_ns_regnum = ARM_SP_REGNUM;	/* M-profile PSP_NS register number.  */
>     int m_profile_msp_s_regnum = ARM_SP_REGNUM;	/* M-profile MSP_S register number.  */
>     int m_profile_psp_s_regnum = ARM_SP_REGNUM;	/* M-profile PSP_S register number.  */
> +  int m_profile_control_s_regnum = -1;		/* M-profile CONTROL_S register number.  */
> +  int m_profile_control_ns_regnum = -1;		/* M-profile CONTROL_NS register number.  */
>   
>     int tls_regnum = 0;		/* Number of the tpidruro register.  */
>
  
Tomas Vanek Nov. 8, 2022, 3:52 p.m. UTC | #2
Hi Luis,

On 08/11/2022 12:23, Luis Machado wrote:
> Hi Tomas,
>
> On 11/5/22 09:44, Tomas Vanek wrote:
>> The M-profile security extension registers will be used for stack
>> selection in FNC_RETURN and return from secure to non-secure state.
>>
>> The presence of the registers is optional.
>> If one or both are missing the security extension profile is accepted.
>> The code using the registers must check m_profile_control_[n]?s_regnum
>> for -1.
>>
>> Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
>> ---
>>   gdb/arm-tdep.c | 20 ++++++++++++++++++++
>>   gdb/arm-tdep.h |  2 ++
>>   2 files changed, 22 insertions(+)
>>
>> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
>> index 3105543..564ee43 100644
>> --- a/gdb/arm-tdep.c
>> +++ b/gdb/arm-tdep.c
>> @@ -9996,6 +9996,8 @@ enum arm_vfp_cprc_base_type
>>     int m_profile_psp_ns_regnum = -1;
>>     int m_profile_msp_s_regnum = -1;
>>     int m_profile_psp_s_regnum = -1;
>> +  int m_profile_control_s_regnum = -1;
>> +  int m_profile_control_ns_regnum = -1;
>>     int tls_regnum = 0;
>>       /* If we have an object to base this architecture on, try to 
>> determine
>> @@ -10473,6 +10475,22 @@ enum arm_vfp_cprc_base_type
>>           }
>>             m_profile_psp_s_regnum = register_count++;
>>   +          /* Regard the control_s and control_ns registers optional,
>> +           * accept the security extension feature even without them */
>> +          valid_p = tdesc_numbered_register (feature, tdesc_data.get 
>> (),
>> +                         register_count, "control_s");
>
> What tools are advertising control_s and control_ns? We need to 
> document those properly if we're planning on using them
> as part of decision-making in GDB.

Good question.

OpenOCD exposes them, like other M-profile security extension registers 
they have the feature name "v8-m.sp".
There is a pending patch to change the feature name to 
"org.gnu.gdb.arm.secext"
7265: target/armv7m: fix feature name of ARMv8M security extension regs 
| https://review.openocd.org/c/openocd/+/7265

PyOCD exposes them, like other M-profile security extension registers 
they have the feature name "v8-m.sp".

ST-LINK GDB server. Version 5.6.0 (I assume not the latest version) 
exposes them (and other M-profile security extension registers too)
in the feature "org.gnu.gdb.arm.vfp"?? Obviously a bug!

I have no access to Keil tools.

Please be aware that control_s and control_ns are optional, the most of 
security extension support is functional
even in the case they are not accessible in the connected gdbserver.

>
>
>> +          if (!valid_p)
>> +        warning (_("M-profile secext feature is missing required 
>> register control_s."));
>> +          else
>> +        m_profile_control_s_regnum = register_count++;
>> +
>> +          valid_p = tdesc_numbered_register (feature, tdesc_data.get 
>> (),
>> +                         register_count, "control_ns");
>> +          if (!valid_p)
>> +        warning (_("M-profile secext feature is missing required 
>> register control_ns."));
>> +          else
>> +        m_profile_control_ns_regnum = register_count++;
>> +
>>             have_sec_ext = true;
>>           }
>>   @@ -10553,6 +10571,8 @@ enum arm_vfp_cprc_base_type
>>         tdep->m_profile_psp_ns_regnum = m_profile_psp_ns_regnum;
>>         tdep->m_profile_msp_s_regnum = m_profile_msp_s_regnum;
>>         tdep->m_profile_psp_s_regnum = m_profile_psp_s_regnum;
>> +      tdep->m_profile_control_s_regnum = m_profile_control_s_regnum;
>> +      tdep->m_profile_control_ns_regnum = m_profile_control_ns_regnum;
>>       }
>>       arm_register_g_packet_guesses (gdbarch);
>> diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h
>> index bcd7e08..11670e9 100644
>> --- a/gdb/arm-tdep.h
>> +++ b/gdb/arm-tdep.h
>> @@ -133,6 +133,8 @@ struct arm_gdbarch_tdep : gdbarch_tdep_base
>>     int m_profile_psp_ns_regnum = ARM_SP_REGNUM;    /* M-profile 
>> PSP_NS register number.  */
>>     int m_profile_msp_s_regnum = ARM_SP_REGNUM;    /* M-profile MSP_S 
>> register number.  */
>>     int m_profile_psp_s_regnum = ARM_SP_REGNUM;    /* M-profile PSP_S 
>> register number.  */
>> +  int m_profile_control_s_regnum = -1;        /* M-profile CONTROL_S 
>> register number.  */
>> +  int m_profile_control_ns_regnum = -1;        /* M-profile 
>> CONTROL_NS register number.  */
>>       int tls_regnum = 0;        /* Number of the tpidruro register.  */
>
  
Tomas Vanek Nov. 8, 2022, 3:58 p.m. UTC | #3
On 08/11/2022 16:52, Tomas Vanek wrote:
> Hi Luis,
>
> On 08/11/2022 12:23, Luis Machado wrote:
>> Hi Tomas,
>>
>> On 11/5/22 09:44, Tomas Vanek wrote:
>>> The M-profile security extension registers will be used for stack
>>> selection in FNC_RETURN and return from secure to non-secure state.
>>>
>>> The presence of the registers is optional.
>>> If one or both are missing the security extension profile is accepted.
>>> The code using the registers must check m_profile_control_[n]?s_regnum
>>> for -1.
>>>
>>> Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
>>> ---
>>>   gdb/arm-tdep.c | 20 ++++++++++++++++++++
>>>   gdb/arm-tdep.h |  2 ++
>>>   2 files changed, 22 insertions(+)
>>>
>>> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
>>> index 3105543..564ee43 100644
>>> --- a/gdb/arm-tdep.c
>>> +++ b/gdb/arm-tdep.c
>>> @@ -9996,6 +9996,8 @@ enum arm_vfp_cprc_base_type
>>>     int m_profile_psp_ns_regnum = -1;
>>>     int m_profile_msp_s_regnum = -1;
>>>     int m_profile_psp_s_regnum = -1;
>>> +  int m_profile_control_s_regnum = -1;
>>> +  int m_profile_control_ns_regnum = -1;
>>>     int tls_regnum = 0;
>>>       /* If we have an object to base this architecture on, try to 
>>> determine
>>> @@ -10473,6 +10475,22 @@ enum arm_vfp_cprc_base_type
>>>           }
>>>             m_profile_psp_s_regnum = register_count++;
>>>   +          /* Regard the control_s and control_ns registers optional,
>>> +           * accept the security extension feature even without 
>>> them */
>>> +          valid_p = tdesc_numbered_register (feature, 
>>> tdesc_data.get (),
>>> +                         register_count, "control_s");
>>
>> What tools are advertising control_s and control_ns? We need to 
>> document those properly if we're planning on using them
>> as part of decision-making in GDB.
>
> Good question.
>
> OpenOCD exposes them, like other M-profile security extension 
> registers they have the feature name "v8-m.sp".
> There is a pending patch to change the feature name to 
> "org.gnu.gdb.arm.secext"
> 7265: target/armv7m: fix feature name of ARMv8M security extension 
> regs | https://review.openocd.org/c/openocd/+/7265
>
> PyOCD exposes them, like other M-profile security extension registers 
> they have the feature name "v8-m.sp".

Oops, PyOCD exposes just control, no control_s and control_ns variants.

>
> ST-LINK GDB server. Version 5.6.0 (I assume not the latest version) 
> exposes them (and other M-profile security extension registers too)
> in the feature "org.gnu.gdb.arm.vfp"?? Obviously a bug!
>
> I have no access to Keil tools.
>
> Please be aware that control_s and control_ns are optional, the most 
> of security extension support is functional
> even in the case they are not accessible in the connected gdbserver.
>
>>
>>
>>> +          if (!valid_p)
>>> +        warning (_("M-profile secext feature is missing required 
>>> register control_s."));
>>> +          else
>>> +        m_profile_control_s_regnum = register_count++;
>>> +
>>> +          valid_p = tdesc_numbered_register (feature, 
>>> tdesc_data.get (),
>>> +                         register_count, "control_ns");
>>> +          if (!valid_p)
>>> +        warning (_("M-profile secext feature is missing required 
>>> register control_ns."));
>>> +          else
>>> +        m_profile_control_ns_regnum = register_count++;
>>> +
>>>             have_sec_ext = true;
>>>           }
>>>   @@ -10553,6 +10571,8 @@ enum arm_vfp_cprc_base_type
>>>         tdep->m_profile_psp_ns_regnum = m_profile_psp_ns_regnum;
>>>         tdep->m_profile_msp_s_regnum = m_profile_msp_s_regnum;
>>>         tdep->m_profile_psp_s_regnum = m_profile_psp_s_regnum;
>>> +      tdep->m_profile_control_s_regnum = m_profile_control_s_regnum;
>>> +      tdep->m_profile_control_ns_regnum = m_profile_control_ns_regnum;
>>>       }
>>>       arm_register_g_packet_guesses (gdbarch);
>>> diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h
>>> index bcd7e08..11670e9 100644
>>> --- a/gdb/arm-tdep.h
>>> +++ b/gdb/arm-tdep.h
>>> @@ -133,6 +133,8 @@ struct arm_gdbarch_tdep : gdbarch_tdep_base
>>>     int m_profile_psp_ns_regnum = ARM_SP_REGNUM;    /* M-profile 
>>> PSP_NS register number.  */
>>>     int m_profile_msp_s_regnum = ARM_SP_REGNUM;    /* M-profile 
>>> MSP_S register number.  */
>>>     int m_profile_psp_s_regnum = ARM_SP_REGNUM;    /* M-profile 
>>> PSP_S register number.  */
>>> +  int m_profile_control_s_regnum = -1;        /* M-profile 
>>> CONTROL_S register number.  */
>>> +  int m_profile_control_ns_regnum = -1;        /* M-profile 
>>> CONTROL_NS register number.  */
>>>       int tls_regnum = 0;        /* Number of the tpidruro 
>>> register.  */
>>
>
  
Torbjorn SVENSSON Nov. 8, 2022, 4:48 p.m. UTC | #4
On 2022-11-08 16:52, Tomas Vanek wrote:
> Hi Luis,
> 
> On 08/11/2022 12:23, Luis Machado wrote:
>> Hi Tomas,
>>
>> On 11/5/22 09:44, Tomas Vanek wrote:
>>> The M-profile security extension registers will be used for stack
>>> selection in FNC_RETURN and return from secure to non-secure state.
>>>
>>> The presence of the registers is optional.
>>> If one or both are missing the security extension profile is accepted.
>>> The code using the registers must check m_profile_control_[n]?s_regnum
>>> for -1.
>>>
>>> Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
>>> ---
>>>   gdb/arm-tdep.c | 20 ++++++++++++++++++++
>>>   gdb/arm-tdep.h |  2 ++
>>>   2 files changed, 22 insertions(+)
>>>
>>> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
>>> index 3105543..564ee43 100644
>>> --- a/gdb/arm-tdep.c
>>> +++ b/gdb/arm-tdep.c
>>> @@ -9996,6 +9996,8 @@ enum arm_vfp_cprc_base_type
>>>     int m_profile_psp_ns_regnum = -1;
>>>     int m_profile_msp_s_regnum = -1;
>>>     int m_profile_psp_s_regnum = -1;
>>> +  int m_profile_control_s_regnum = -1;
>>> +  int m_profile_control_ns_regnum = -1;
>>>     int tls_regnum = 0;
>>>       /* If we have an object to base this architecture on, try to 
>>> determine
>>> @@ -10473,6 +10475,22 @@ enum arm_vfp_cprc_base_type
>>>           }
>>>             m_profile_psp_s_regnum = register_count++;
>>>   +          /* Regard the control_s and control_ns registers optional,
>>> +           * accept the security extension feature even without them */
>>> +          valid_p = tdesc_numbered_register (feature, tdesc_data.get 
>>> (),
>>> +                         register_count, "control_s");
>>
>> What tools are advertising control_s and control_ns? We need to 
>> document those properly if we're planning on using them
>> as part of decision-making in GDB.
> 
> Good question.
> 
> OpenOCD exposes them, like other M-profile security extension registers 
> they have the feature name "v8-m.sp".
> There is a pending patch to change the feature name to 
> "org.gnu.gdb.arm.secext"
> 7265: target/armv7m: fix feature name of ARMv8M security extension regs 
> | https://review.openocd.org/c/openocd/+/7265
> 
> PyOCD exposes them, like other M-profile security extension registers 
> they have the feature name "v8-m.sp".
> 
> ST-LINK GDB server. Version 5.6.0 (I assume not the latest version) 
> exposes them (and other M-profile security extension registers too)
> in the feature "org.gnu.gdb.arm.vfp"?? Obviously a bug!

This was fixed in 5.9.0 and the latest released version i 7.0.0.

IIRC, SEGGER JLink exposes both CONTROL registers too, but I can't 
confirm that right now.

Kind regards,
Torbjörn
  
Luis Machado Nov. 9, 2022, 3:27 p.m. UTC | #5
Hi,

On 11/8/22 15:58, Tomas Vanek wrote:
> On 08/11/2022 16:52, Tomas Vanek wrote:
>> Hi Luis,
>>
>> On 08/11/2022 12:23, Luis Machado wrote:
>>> Hi Tomas,
>>>
>>> On 11/5/22 09:44, Tomas Vanek wrote:
>>>> The M-profile security extension registers will be used for stack
>>>> selection in FNC_RETURN and return from secure to non-secure state.
>>>>
>>>> The presence of the registers is optional.
>>>> If one or both are missing the security extension profile is accepted.
>>>> The code using the registers must check m_profile_control_[n]?s_regnum
>>>> for -1.
>>>>
>>>> Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
>>>> ---
>>>>   gdb/arm-tdep.c | 20 ++++++++++++++++++++
>>>>   gdb/arm-tdep.h |  2 ++
>>>>   2 files changed, 22 insertions(+)
>>>>
>>>> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
>>>> index 3105543..564ee43 100644
>>>> --- a/gdb/arm-tdep.c
>>>> +++ b/gdb/arm-tdep.c
>>>> @@ -9996,6 +9996,8 @@ enum arm_vfp_cprc_base_type
>>>>     int m_profile_psp_ns_regnum = -1;
>>>>     int m_profile_msp_s_regnum = -1;
>>>>     int m_profile_psp_s_regnum = -1;
>>>> +  int m_profile_control_s_regnum = -1;
>>>> +  int m_profile_control_ns_regnum = -1;
>>>>     int tls_regnum = 0;
>>>>       /* If we have an object to base this architecture on, try to determine
>>>> @@ -10473,6 +10475,22 @@ enum arm_vfp_cprc_base_type
>>>>           }
>>>>             m_profile_psp_s_regnum = register_count++;
>>>>   +          /* Regard the control_s and control_ns registers optional,
>>>> +           * accept the security extension feature even without them */
>>>> +          valid_p = tdesc_numbered_register (feature, tdesc_data.get (),
>>>> +                         register_count, "control_s");
>>>
>>> What tools are advertising control_s and control_ns? We need to document those properly if we're planning on using them
>>> as part of decision-making in GDB.
>>
>> Good question.
>>
>> OpenOCD exposes them, like other M-profile security extension registers they have the feature name "v8-m.sp".
>> There is a pending patch to change the feature name to "org.gnu.gdb.arm.secext"
>> 7265: target/armv7m: fix feature name of ARMv8M security extension regs | https://review.openocd.org/c/openocd/+/7265
>>
>> PyOCD exposes them, like other M-profile security extension registers they have the feature name "v8-m.sp".
> 
> Oops, PyOCD exposes just control, no control_s and control_ns variants.
> 

Should we coordinate this a bit better between PyOCD and ST-LINK to expose the same set of registers. That would make it easier for
gdb to deal with it.

>>
>> ST-LINK GDB server. Version 5.6.0 (I assume not the latest version) exposes them (and other M-profile security extension registers too)
>> in the feature "org.gnu.gdb.arm.vfp"?? Obviously a bug!
>>
>> I have no access to Keil tools.
>>
>> Please be aware that control_s and control_ns are optional, the most of security extension support is functional
>> even in the case they are not accessible in the connected gdbserver.
>>
>>>
>>>
>>>> +          if (!valid_p)
>>>> +        warning (_("M-profile secext feature is missing required register control_s."));
>>>> +          else
>>>> +        m_profile_control_s_regnum = register_count++;
>>>> +
>>>> +          valid_p = tdesc_numbered_register (feature, tdesc_data.get (),
>>>> +                         register_count, "control_ns");
>>>> +          if (!valid_p)
>>>> +        warning (_("M-profile secext feature is missing required register control_ns."));
>>>> +          else
>>>> +        m_profile_control_ns_regnum = register_count++;
>>>> +
>>>>             have_sec_ext = true;
>>>>           }
>>>>   @@ -10553,6 +10571,8 @@ enum arm_vfp_cprc_base_type
>>>>         tdep->m_profile_psp_ns_regnum = m_profile_psp_ns_regnum;
>>>>         tdep->m_profile_msp_s_regnum = m_profile_msp_s_regnum;
>>>>         tdep->m_profile_psp_s_regnum = m_profile_psp_s_regnum;
>>>> +      tdep->m_profile_control_s_regnum = m_profile_control_s_regnum;
>>>> +      tdep->m_profile_control_ns_regnum = m_profile_control_ns_regnum;
>>>>       }
>>>>       arm_register_g_packet_guesses (gdbarch);
>>>> diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h
>>>> index bcd7e08..11670e9 100644
>>>> --- a/gdb/arm-tdep.h
>>>> +++ b/gdb/arm-tdep.h
>>>> @@ -133,6 +133,8 @@ struct arm_gdbarch_tdep : gdbarch_tdep_base
>>>>     int m_profile_psp_ns_regnum = ARM_SP_REGNUM;    /* M-profile PSP_NS register number.  */
>>>>     int m_profile_msp_s_regnum = ARM_SP_REGNUM;    /* M-profile MSP_S register number.  */
>>>>     int m_profile_psp_s_regnum = ARM_SP_REGNUM;    /* M-profile PSP_S register number.  */
>>>> +  int m_profile_control_s_regnum = -1;        /* M-profile CONTROL_S register number.  */
>>>> +  int m_profile_control_ns_regnum = -1;        /* M-profile CONTROL_NS register number.  */
>>>>       int tls_regnum = 0;        /* Number of the tpidruro register.  */
>>>
>>
>
  

Patch

diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 3105543..564ee43 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -9996,6 +9996,8 @@  enum arm_vfp_cprc_base_type
   int m_profile_psp_ns_regnum = -1;
   int m_profile_msp_s_regnum = -1;
   int m_profile_psp_s_regnum = -1;
+  int m_profile_control_s_regnum = -1;
+  int m_profile_control_ns_regnum = -1;
   int tls_regnum = 0;
 
   /* If we have an object to base this architecture on, try to determine
@@ -10473,6 +10475,22 @@  enum arm_vfp_cprc_base_type
 		}
 	      m_profile_psp_s_regnum = register_count++;
 
+	      /* Regard the control_s and control_ns registers optional,
+	       * accept the security extension feature even without them */
+	      valid_p = tdesc_numbered_register (feature, tdesc_data.get (),
+						 register_count, "control_s");
+	      if (!valid_p)
+		warning (_("M-profile secext feature is missing required register control_s."));
+	      else
+		m_profile_control_s_regnum = register_count++;
+
+	      valid_p = tdesc_numbered_register (feature, tdesc_data.get (),
+						 register_count, "control_ns");
+	      if (!valid_p)
+		warning (_("M-profile secext feature is missing required register control_ns."));
+	      else
+		m_profile_control_ns_regnum = register_count++;
+
 	      have_sec_ext = true;
 	    }
 
@@ -10553,6 +10571,8 @@  enum arm_vfp_cprc_base_type
       tdep->m_profile_psp_ns_regnum = m_profile_psp_ns_regnum;
       tdep->m_profile_msp_s_regnum = m_profile_msp_s_regnum;
       tdep->m_profile_psp_s_regnum = m_profile_psp_s_regnum;
+      tdep->m_profile_control_s_regnum = m_profile_control_s_regnum;
+      tdep->m_profile_control_ns_regnum = m_profile_control_ns_regnum;
     }
 
   arm_register_g_packet_guesses (gdbarch);
diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h
index bcd7e08..11670e9 100644
--- a/gdb/arm-tdep.h
+++ b/gdb/arm-tdep.h
@@ -133,6 +133,8 @@  struct arm_gdbarch_tdep : gdbarch_tdep_base
   int m_profile_psp_ns_regnum = ARM_SP_REGNUM;	/* M-profile PSP_NS register number.  */
   int m_profile_msp_s_regnum = ARM_SP_REGNUM;	/* M-profile MSP_S register number.  */
   int m_profile_psp_s_regnum = ARM_SP_REGNUM;	/* M-profile PSP_S register number.  */
+  int m_profile_control_s_regnum = -1;		/* M-profile CONTROL_S register number.  */
+  int m_profile_control_ns_regnum = -1;		/* M-profile CONTROL_NS register number.  */
 
   int tls_regnum = 0;		/* Number of the tpidruro register.  */