Skip to content

Commit ef388c1

Browse files
Ahmed IsmailAhmedIsmail02
Ahmed Ismail
authored andcommitted
armv8.1-m: Add PACBTI support to kernel non-secure implementation
In this commit, Pointer Authentication, and Branch Target Identification Extension (PACBTI) support is added for Non-Secure and Non-TrustZone variants of Cortex-M85 FreeRTOS-Kernel Port. The PACBTI support is added for Arm Compiler For Embedded, and IAR toolchains only. The support in the kernel is not yet enabled for GNU toolchain due to known issues. Signed-off-by: Ahmed Ismail <Ahmed.Ismail@arm.com>
1 parent e633f7f commit ef388c1

File tree

79 files changed

+2485
-42
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2485
-42
lines changed

.github/.cSpellWords.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ MAINRDY
448448
MAIR
449449
Mang
450450
Mbits
451+
mbranch
451452
mcause
452453
MCFR
453454
MCKA
@@ -586,6 +587,8 @@ OWATCOM
586587
OWDR
587588
OWER
588589
OWSR
590+
pacbti
591+
PACBTI
589592
PAGEN
590593
PCDR
591594
PCER
@@ -900,6 +903,7 @@ TXTEN
900903
TXUBR
901904
TXVC
902905
TXVDIS
906+
UBTI
903907
UDCP
904908
UNACKED
905909
uncrustify
@@ -915,6 +919,7 @@ UNSUB
915919
UNSUBACK
916920
unsubscriptions
917921
unsuspended
922+
UPAC
918923
URAD
919924
URAT
920925
URSTEN

include/FreeRTOS.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,6 +3032,18 @@
30323032
#define configCONTROL_INFINITE_LOOP()
30333033
#endif
30343034

3035+
/* Set configENABLE_PAC and/or configENABLE_BTI to 1 to enable PAC and/or BTI
3036+
* support and 0 to disable them. These are currently used in ARMv8.1-M ports. */
3037+
#if ( portHAS_PACBTI_FEATURE == 1 )
3038+
#ifndef configENABLE_PAC
3039+
#define configENABLE_PAC 0
3040+
#endif
3041+
3042+
#ifndef configENABLE_BTI
3043+
#define configENABLE_BTI 0
3044+
#endif
3045+
#endif
3046+
30353047
/* Sometimes the FreeRTOSConfig.h settings only allow a task to be created using
30363048
* dynamically allocated RAM, in which case when any task is deleted it is known
30373049
* that both the task's stack and TCB need to be freed. Sometimes the

portable/ARMv8M/non_secure/port.c

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
33
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2024 Arm Limited and/or its affiliates
5+
* <open-source-office@arm.com>
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -110,6 +112,7 @@ typedef void ( * portISR_t )( void );
110112
#define portSCB_VTOR_REG ( *( ( portISR_t ** ) 0xe000ed08 ) )
111113
#define portSCB_SYS_HANDLER_CTRL_STATE_REG ( *( ( volatile uint32_t * ) 0xe000ed24 ) )
112114
#define portSCB_MEM_FAULT_ENABLE_BIT ( 1UL << 16UL )
115+
#define portSCB_USG_FAULT_ENABLE_BIT ( 1UL << 18UL )
113116
/*-----------------------------------------------------------*/
114117

115118
/**
@@ -373,6 +376,20 @@ typedef void ( * portISR_t )( void );
373376
* any secure calls.
374377
*/
375378
#define portNO_SECURE_CONTEXT 0
379+
380+
/**
381+
* @brief Constants required to check and configure PACBTI security feature implementation.
382+
*/
383+
#if ( portHAS_PACBTI_FEATURE == 1 )
384+
385+
#define portID_ISAR5_REG ( *( ( volatile uint32_t * ) 0xe000ed74 ) )
386+
387+
#define portCONTROL_UPAC_EN ( 1UL << 7UL )
388+
#define portCONTROL_PAC_EN ( 1UL << 6UL )
389+
#define portCONTROL_UBTI_EN ( 1UL << 5UL )
390+
#define portCONTROL_BTI_EN ( 1UL << 4UL )
391+
392+
#endif /* portHAS_PACBTI_FEATURE */
376393
/*-----------------------------------------------------------*/
377394

378395
/**
@@ -410,6 +427,26 @@ static void prvTaskExitError( void );
410427
static void prvSetupFPU( void ) PRIVILEGED_FUNCTION;
411428
#endif /* configENABLE_FPU */
412429

430+
#if ( portHAS_PACBTI_FEATURE == 1 )
431+
432+
/**
433+
* @brief Configures PACBTI features.
434+
*
435+
* This function configures the Pointer Authentication, and Branch Target
436+
* Identification security features as per the user configuration. It returns
437+
* the value of the special purpose CONTROL register accordingly, and optionally
438+
* updates the CONTROL register value. Currently, only Cortex-M85 (ARMv8.1-M
439+
* architecture based) target supports PACBTI security feature.
440+
*
441+
* @param xWriteControlRegister Used to control whether the special purpose
442+
* CONTROL register should be updated or not.
443+
*
444+
* @return CONTROL register value according to the configured PACBTI option.
445+
*/
446+
static uint32_t prvConfigurePACBTI( BaseType_t xWriteControlRegister );
447+
448+
#endif /* portHAS_PACBTI_FEATURE */
449+
413450
/**
414451
* @brief Setup the timer to generate the tick interrupts.
415452
*
@@ -1457,6 +1494,7 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
14571494
xMPU_SETTINGS * xMPUSettings ) /* PRIVILEGED_FUNCTION */
14581495
{
14591496
uint32_t ulIndex = 0;
1497+
uint32_t ulControl = 0x0;
14601498

14611499
xMPUSettings->ulContext[ ulIndex ] = 0x04040404; /* r4. */
14621500
ulIndex++;
@@ -1503,16 +1541,24 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
15031541
xMPUSettings->ulContext[ ulIndex ] = ( uint32_t ) pxEndOfStack; /* PSPLIM. */
15041542
ulIndex++;
15051543

1544+
#if ( portHAS_PACBTI_FEATURE == 1 )
1545+
{
1546+
/* Check PACBTI security feature configuration before pushing the
1547+
* CONTROL register's value on task's TCB. */
1548+
ulControl = prvConfigurePACBTI( pdFALSE );
1549+
}
1550+
#endif /* portHAS_PACBTI_FEATURE */
1551+
15061552
if( xRunPrivileged == pdTRUE )
15071553
{
15081554
xMPUSettings->ulTaskFlags |= portTASK_IS_PRIVILEGED_FLAG;
1509-
xMPUSettings->ulContext[ ulIndex ] = ( uint32_t ) portINITIAL_CONTROL_PRIVILEGED; /* CONTROL. */
1555+
xMPUSettings->ulContext[ ulIndex ] = ( ulControl | ( uint32_t ) portINITIAL_CONTROL_PRIVILEGED ); /* CONTROL. */
15101556
ulIndex++;
15111557
}
15121558
else
15131559
{
15141560
xMPUSettings->ulTaskFlags &= ( ~portTASK_IS_PRIVILEGED_FLAG );
1515-
xMPUSettings->ulContext[ ulIndex ] = ( uint32_t ) portINITIAL_CONTROL_UNPRIVILEGED; /* CONTROL. */
1561+
xMPUSettings->ulContext[ ulIndex ] = ( ulControl | ( uint32_t ) portINITIAL_CONTROL_UNPRIVILEGED ); /* CONTROL. */
15161562
ulIndex++;
15171563
}
15181564

@@ -1740,6 +1786,14 @@ BaseType_t xPortStartScheduler( void ) /* PRIVILEGED_FUNCTION */
17401786
portNVIC_SHPR3_REG |= portNVIC_SYSTICK_PRI;
17411787
portNVIC_SHPR2_REG = 0;
17421788

1789+
#if ( portHAS_PACBTI_FEATURE == 1 )
1790+
{
1791+
/* Set the CONTROL register value based on PACBTI security feature
1792+
* configuration before starting the first task. */
1793+
( void) prvConfigurePACBTI( pdTRUE );
1794+
}
1795+
#endif /* portHAS_PACBTI_FEATURE */
1796+
17431797
#if ( configENABLE_MPU == 1 )
17441798
{
17451799
/* Setup the Memory Protection Unit (MPU). */
@@ -2158,3 +2212,42 @@ BaseType_t xPortIsInsideInterrupt( void )
21582212

21592213
#endif /* #if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) */
21602214
/*-----------------------------------------------------------*/
2215+
2216+
#if ( portHAS_PACBTI_FEATURE == 1 )
2217+
2218+
static uint32_t prvConfigurePACBTI( BaseType_t xWriteControlRegister )
2219+
{
2220+
uint32_t ulControl = 0x0;
2221+
2222+
/* Ensure that PACBTI is implemented. */
2223+
configASSERT( portID_ISAR5_REG != 0x0 );
2224+
2225+
/* Enable UsageFault exception if PAC or BTI is enabled. */
2226+
#if( ( configENABLE_PAC == 1 ) || ( configENABLE_BTI == 1 ) )
2227+
{
2228+
portSCB_SYS_HANDLER_CTRL_STATE_REG |= portSCB_USG_FAULT_ENABLE_BIT;
2229+
}
2230+
#endif
2231+
2232+
#if( configENABLE_PAC == 1 )
2233+
{
2234+
ulControl |= ( portCONTROL_UPAC_EN | portCONTROL_PAC_EN );
2235+
}
2236+
#endif
2237+
2238+
#if( configENABLE_BTI == 1 )
2239+
{
2240+
ulControl |= ( portCONTROL_UBTI_EN | portCONTROL_BTI_EN );
2241+
}
2242+
#endif
2243+
2244+
if( xWriteControlRegister == pdTRUE )
2245+
{
2246+
__asm volatile ( "msr control, %0" : : "r" ( ulControl ) );
2247+
}
2248+
2249+
return ulControl;
2250+
}
2251+
2252+
#endif /* #if ( portHAS_PACBTI_FEATURE == 1 ) */
2253+
/*-----------------------------------------------------------*/

portable/ARMv8M/non_secure/portable/GCC/ARM_CM23/portmacro.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
33
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2024 Arm Limited and/or its affiliates
5+
* <open-source-office@arm.com>
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -51,6 +53,7 @@
5153
#define portARCH_NAME "Cortex-M23"
5254
#define portHAS_ARMV8M_MAIN_EXTENSION 0
5355
#define portARMV8M_MINOR_VERSION 0
56+
#define portHAS_PACBTI_FEATURE 0
5457
#define portDONT_DISCARD __attribute__( ( used ) )
5558
/*-----------------------------------------------------------*/
5659

portable/ARMv8M/non_secure/portable/GCC/ARM_CM23_NTZ/portmacro.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
33
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2024 Arm Limited and/or its affiliates
5+
* <open-source-office@arm.com>
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -51,6 +53,7 @@
5153
#define portARCH_NAME "Cortex-M23"
5254
#define portHAS_ARMV8M_MAIN_EXTENSION 0
5355
#define portARMV8M_MINOR_VERSION 0
56+
#define portHAS_PACBTI_FEATURE 0
5457
#define portDONT_DISCARD __attribute__( ( used ) )
5558
/*-----------------------------------------------------------*/
5659

portable/ARMv8M/non_secure/portable/GCC/ARM_CM33/portmacro.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
33
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2024 Arm Limited and/or its affiliates
5+
* <open-source-office@arm.com>
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -51,6 +53,7 @@
5153
#define portARCH_NAME "Cortex-M33"
5254
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5355
#define portARMV8M_MINOR_VERSION 0
56+
#define portHAS_PACBTI_FEATURE 0
5457
#define portDONT_DISCARD __attribute__( ( used ) )
5558
/*-----------------------------------------------------------*/
5659

portable/ARMv8M/non_secure/portable/GCC/ARM_CM33_NTZ/portmacro.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
33
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2024 Arm Limited and/or its affiliates
5+
* <open-source-office@arm.com>
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -51,6 +53,7 @@
5153
#define portARCH_NAME "Cortex-M33"
5254
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5355
#define portARMV8M_MINOR_VERSION 0
56+
#define portHAS_PACBTI_FEATURE 0
5457
#define portDONT_DISCARD __attribute__( ( used ) )
5558
/*-----------------------------------------------------------*/
5659

portable/ARMv8M/non_secure/portable/GCC/ARM_CM35P/portmacro.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
33
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2024 Arm Limited and/or its affiliates
5+
* <open-source-office@arm.com>
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -51,6 +53,7 @@
5153
#define portARCH_NAME "Cortex-M35P"
5254
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5355
#define portARMV8M_MINOR_VERSION 0
56+
#define portHAS_PACBTI_FEATURE 0
5457
#define portDONT_DISCARD __attribute__( ( used ) )
5558
/*-----------------------------------------------------------*/
5659

portable/ARMv8M/non_secure/portable/GCC/ARM_CM55/portmacro.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
33
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2024 Arm Limited and/or its affiliates
5+
* <open-source-office@arm.com>
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -56,6 +58,7 @@
5658
#define portARCH_NAME "Cortex-M55"
5759
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5860
#define portARMV8M_MINOR_VERSION 1
61+
#define portHAS_PACBTI_FEATURE 0
5962
#define portDONT_DISCARD __attribute__( ( used ) )
6063
/*-----------------------------------------------------------*/
6164

portable/ARMv8M/non_secure/portable/GCC/ARM_CM85/portmacro.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
33
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2024 Arm Limited and/or its affiliates
5+
* <open-source-office@arm.com>
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -56,6 +58,7 @@
5658
#define portARCH_NAME "Cortex-M85"
5759
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5860
#define portARMV8M_MINOR_VERSION 1
61+
#define portHAS_PACBTI_FEATURE 1
5962
#define portDONT_DISCARD __attribute__( ( used ) )
6063
/*-----------------------------------------------------------*/
6164

portable/ARMv8M/non_secure/portable/IAR/ARM_CM23/portmacro.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
33
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2024 Arm Limited and/or its affiliates
5+
* <open-source-office@arm.com>
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -51,6 +53,7 @@
5153
#define portARCH_NAME "Cortex-M23"
5254
#define portHAS_ARMV8M_MAIN_EXTENSION 0
5355
#define portARMV8M_MINOR_VERSION 0
56+
#define portHAS_PACBTI_FEATURE 0
5457
#define portDONT_DISCARD __root
5558
/*-----------------------------------------------------------*/
5659

portable/ARMv8M/non_secure/portable/IAR/ARM_CM23_NTZ/portmacro.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
33
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2024 Arm Limited and/or its affiliates
5+
* <open-source-office@arm.com>
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -51,6 +53,7 @@
5153
#define portARCH_NAME "Cortex-M23"
5254
#define portHAS_ARMV8M_MAIN_EXTENSION 0
5355
#define portARMV8M_MINOR_VERSION 0
56+
#define portHAS_PACBTI_FEATURE 0
5457
#define portDONT_DISCARD __root
5558
/*-----------------------------------------------------------*/
5659

portable/ARMv8M/non_secure/portable/IAR/ARM_CM33/portmacro.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
33
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2024 Arm Limited and/or its affiliates
5+
* <open-source-office@arm.com>
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -51,6 +53,7 @@
5153
#define portARCH_NAME "Cortex-M33"
5254
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5355
#define portARMV8M_MINOR_VERSION 0
56+
#define portHAS_PACBTI_FEATURE 0
5457
#define portDONT_DISCARD __root
5558
/*-----------------------------------------------------------*/
5659

portable/ARMv8M/non_secure/portable/IAR/ARM_CM33_NTZ/portmacro.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
33
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2024 Arm Limited and/or its affiliates
5+
* <open-source-office@arm.com>
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -51,6 +53,7 @@
5153
#define portARCH_NAME "Cortex-M33"
5254
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5355
#define portARMV8M_MINOR_VERSION 0
56+
#define portHAS_PACBTI_FEATURE 0
5457
#define portDONT_DISCARD __root
5558
/*-----------------------------------------------------------*/
5659

0 commit comments

Comments
 (0)