Skip to content

Commit 3a52b68

Browse files
Ahmed IsmailAhmedIsmail02
Ahmed Ismail
authored andcommitted
armv8.1-m: Add PACBTI support to kernel NTZ implementation
In this commit, Pointer Authentication, and Branch Target Identification Extension (PACBTI) support is added for Non-TrustZone variant 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 <[email protected]>
1 parent 53e9117 commit 3a52b68

File tree

77 files changed

+2425
-0
lines changed

Some content is hidden

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

77 files changed

+2425
-0
lines changed

portable/ARMv8M/non_secure/port.c

Lines changed: 66 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+
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,13 @@ typedef void ( * portISR_t )( void );
373376
* any secure calls.
374377
*/
375378
#define portNO_SECURE_CONTEXT 0
379+
380+
/**
381+
* @brief Constant required to check PACBTI security feature implementation.
382+
*/
383+
#if (portPROCESSOR_VARIANT == 85)
384+
#define portID_ISAR5_REG ( *( ( volatile uint32_t * ) 0xe000ed74 ) )
385+
#endif /* portPROCESSOR_VARIANT == 85 */
376386
/*-----------------------------------------------------------*/
377387

378388
/**
@@ -410,6 +420,16 @@ static void prvTaskExitError( void );
410420
static void prvSetupFPU( void ) PRIVILEGED_FUNCTION;
411421
#endif /* configENABLE_FPU */
412422

423+
#if (portPROCESSOR_VARIANT == 85)
424+
425+
/**
426+
* @brief Enable/Disable pointer authentication, and/or branch target identification
427+
* based on the selected configuration using the FREERTOS_ARM_V_8_1_M_PACBTI_CONFIG CMake variable.
428+
* Currently, only Cortex-M85 (ARMv8.1-M architecture based) target supports PACBTI security feature.
429+
*/
430+
static void prvConfigurePacBti ( void );
431+
#endif /* portPROCESSOR_VARIANT == 85 */
432+
413433
/**
414434
* @brief Setup the timer to generate the tick interrupts.
415435
*
@@ -1740,6 +1760,13 @@ BaseType_t xPortStartScheduler( void ) /* PRIVILEGED_FUNCTION */
17401760
portNVIC_SHPR3_REG |= portNVIC_SYSTICK_PRI;
17411761
portNVIC_SHPR2_REG = 0;
17421762

1763+
#if (portPROCESSOR_VARIANT == 85)
1764+
{
1765+
/* Check and configure PACBTI security feature before starting the first task. */
1766+
prvConfigurePacBti();
1767+
}
1768+
#endif /* portPROCESSOR_VARIANT == 85 */
1769+
17431770
#if ( configENABLE_MPU == 1 )
17441771
{
17451772
/* Setup the Memory Protection Unit (MPU). */
@@ -2158,3 +2185,42 @@ BaseType_t xPortIsInsideInterrupt( void )
21582185

21592186
#endif /* #if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) */
21602187
/*-----------------------------------------------------------*/
2188+
2189+
#if (portPROCESSOR_VARIANT == 85)
2190+
static void prvConfigurePacBti ( void )
2191+
{
2192+
#if defined ( portARM_V_8_1_M_PACBTI_CONFIG )
2193+
uint32_t ulIdIsar5 = portID_ISAR5_REG;
2194+
configASSERT(ulIdIsar5 != 0x0);
2195+
2196+
/* Enable UsageFault exception if the selected configuration is not portARM_V_8_1_M_PACBTI_CONFIG_NONE */
2197+
#if ( portARM_V_8_1_M_PACBTI_CONFIG != portARM_V_8_1_M_PACBTI_CONFIG_NONE )
2198+
portSCB_SYS_HANDLER_CTRL_STATE_REG |= portSCB_USG_FAULT_ENABLE_BIT;
2199+
#endif
2200+
2201+
uint32_t ulControl;
2202+
#if ( ( portARM_V_8_1_M_PACBTI_CONFIG == portARM_V_8_1_M_PACBTI_CONFIG_STANDARD ) || \
2203+
( portARM_V_8_1_M_PACBTI_CONFIG == portARM_V_8_1_M_PACBTI_CONFIG_PACRET_LEAF_BTI ) )
2204+
/* Set UPAC_EN, PAC_EN, UBTI_EN, and BTI_EN control bits */
2205+
ulControl = 0xF0;
2206+
__asm volatile ( "msr control, %0" : : "r" ( ulControl ) );
2207+
#elif ( ( portARM_V_8_1_M_PACBTI_CONFIG == portARM_V_8_1_M_PACBTI_CONFIG_PACRET ) || \
2208+
( portARM_V_8_1_M_PACBTI_CONFIG == portARM_V_8_1_M_PACBTI_CONFIG_PACRET_LEAF ) )
2209+
/* Set UPAC_EN, and PAC_EN control bits */
2210+
ulControl = 0xC0;
2211+
__asm volatile ( "msr control, %0" : : "r" ( ulControl ) );
2212+
#elif ( portARM_V_8_1_M_PACBTI_CONFIG == portARM_V_8_1_M_PACBTI_CONFIG_BTI )
2213+
/* Set UBTI_EN, and BTI_EN control bits */
2214+
ulControl = 0x30;
2215+
__asm volatile ( "msr control, %0" : : "r" ( ulControl ) );
2216+
#elif ( portARM_V_8_1_M_PACBTI_CONFIG == portARM_V_8_1_M_PACBTI_CONFIG_NONE )
2217+
/* Clear UPAC_EN, PAC_EN, UBTI_EN, and BTI_EN control bits */
2218+
ulControl = 0x00;
2219+
__asm volatile ( "msr control, %0" : : "r" ( ulControl ) );
2220+
#else
2221+
#error "Invalid portARM_V_8_1_M_PACBTI_CONFIG option chosen"
2222+
#endif
2223+
#endif
2224+
}
2225+
#endif /* portPROCESSOR_VARIANT == 85 */
2226+
/*-----------------------------------------------------------*/

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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -48,6 +50,7 @@
4850
/**
4951
* Architecture specifics.
5052
*/
53+
#define portPROCESSOR_VARIANT 23
5154
#define portARCH_NAME "Cortex-M23"
5255
#define portHAS_ARMV8M_MAIN_EXTENSION 0
5356
#define portARMV8M_MINOR_VERSION 0

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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -48,6 +50,7 @@
4850
/**
4951
* Architecture specifics.
5052
*/
53+
#define portPROCESSOR_VARIANT 23
5154
#define portARCH_NAME "Cortex-M23"
5255
#define portHAS_ARMV8M_MAIN_EXTENSION 0
5356
#define portARMV8M_MINOR_VERSION 0

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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -48,6 +50,7 @@
4850
/**
4951
* Architecture specifics.
5052
*/
53+
#define portPROCESSOR_VARIANT 33
5154
#define portARCH_NAME "Cortex-M33"
5255
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5356
#define portARMV8M_MINOR_VERSION 0

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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -48,6 +50,7 @@
4850
/**
4951
* Architecture specifics.
5052
*/
53+
#define portPROCESSOR_VARIANT 33
5154
#define portARCH_NAME "Cortex-M33"
5255
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5356
#define portARMV8M_MINOR_VERSION 0

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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -48,6 +50,7 @@
4850
/**
4951
* Architecture specifics.
5052
*/
53+
#define portPROCESSOR_VARIANT 35
5154
#define portARCH_NAME "Cortex-M35P"
5255
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5356
#define portARMV8M_MINOR_VERSION 0

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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -53,6 +55,7 @@
5355
/**
5456
* Architecture specifics.
5557
*/
58+
#define portPROCESSOR_VARIANT 55
5659
#define portARCH_NAME "Cortex-M55"
5760
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5861
#define portARMV8M_MINOR_VERSION 1

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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -53,6 +55,7 @@
5355
/**
5456
* Architecture specifics.
5557
*/
58+
#define portPROCESSOR_VARIANT 85
5659
#define portARCH_NAME "Cortex-M85"
5760
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5861
#define portARMV8M_MINOR_VERSION 1

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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -48,6 +50,7 @@
4850
/**
4951
* Architecture specifics.
5052
*/
53+
#define portPROCESSOR_VARIANT 23
5154
#define portARCH_NAME "Cortex-M23"
5255
#define portHAS_ARMV8M_MAIN_EXTENSION 0
5356
#define portARMV8M_MINOR_VERSION 0

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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -48,6 +50,7 @@
4850
/**
4951
* Architecture specifics.
5052
*/
53+
#define portPROCESSOR_VARIANT 23
5154
#define portARCH_NAME "Cortex-M23"
5255
#define portHAS_ARMV8M_MAIN_EXTENSION 0
5356
#define portARMV8M_MINOR_VERSION 0

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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -48,6 +50,7 @@
4850
/**
4951
* Architecture specifics.
5052
*/
53+
#define portPROCESSOR_VARIANT 33
5154
#define portARCH_NAME "Cortex-M33"
5255
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5356
#define portARMV8M_MINOR_VERSION 0

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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -48,6 +50,7 @@
4850
/**
4951
* Architecture specifics.
5052
*/
53+
#define portPROCESSOR_VARIANT 33
5154
#define portARCH_NAME "Cortex-M33"
5255
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5356
#define portARMV8M_MINOR_VERSION 0

portable/ARMv8M/non_secure/portable/IAR/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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -48,6 +50,7 @@
4850
/**
4951
* Architecture specifics.
5052
*/
53+
#define portPROCESSOR_VARIANT 35
5154
#define portARCH_NAME "Cortex-M35P"
5255
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5356
#define portARMV8M_MINOR_VERSION 0

portable/ARMv8M/non_secure/portable/IAR/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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -53,6 +55,7 @@
5355
/**
5456
* Architecture specifics.
5557
*/
58+
#define portPROCESSOR_VARIANT 55
5659
#define portARCH_NAME "Cortex-M55"
5760
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5861
#define portARMV8M_MINOR_VERSION 1

portable/ARMv8M/non_secure/portable/IAR/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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -53,6 +55,7 @@
5355
/**
5456
* Architecture specifics.
5557
*/
58+
#define portPROCESSOR_VARIANT 85
5659
#define portARCH_NAME "Cortex-M85"
5760
#define portHAS_ARMV8M_MAIN_EXTENSION 1
5861
#define portARMV8M_MINOR_VERSION 1

portable/ARMv8M/non_secure/portmacrocommon.h

Lines changed: 40 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+
46
*
57
* SPDX-License-Identifier: MIT
68
*
@@ -507,6 +509,44 @@ extern void vClearInterruptMask( uint32_t ulMask ) /* __attribute__(( naked )) P
507509
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
508510
/*-----------------------------------------------------------*/
509511

512+
#if (portPROCESSOR_VARIANT == 85)
513+
514+
/**
515+
* @brief PACBTI Security Feature Disabled
516+
*/
517+
#define portARM_V_8_1_M_PACBTI_CONFIG_NONE 0
518+
519+
/**
520+
* @brief PACBTI Security Feature Standard Configuration
521+
* (PAC enabled without leaf functions support, and BTI enabled ).
522+
*/
523+
#define portARM_V_8_1_M_PACBTI_CONFIG_STANDARD 1
524+
525+
/**
526+
* @brief PACBTI Security Feature with only PAC enabled.
527+
*/
528+
#define portARM_V_8_1_M_PACBTI_CONFIG_PACRET 2
529+
530+
/**
531+
* @brief PACBTI Security Feature with PAC
532+
* and PAC for leaf functions support enabled.
533+
*/
534+
#define portARM_V_8_1_M_PACBTI_CONFIG_PACRET_LEAF 3
535+
536+
/**
537+
* @brief PACBTI Security Feature Standard + Leaf Configuration
538+
* (PAC enabled with leaf functions support, and BTI enabled).
539+
*/
540+
#define portARM_V_8_1_M_PACBTI_CONFIG_PACRET_LEAF_BTI 4
541+
542+
/**
543+
* @brief PACBTI Security Feature with only BTI enabled.
544+
*/
545+
#define portARM_V_8_1_M_PACBTI_CONFIG_BTI 5
546+
547+
#endif /* portPROCESSOR_VARIANT == 85 */
548+
/*-----------------------------------------------------------*/
549+
510550
/* *INDENT-OFF* */
511551
#ifdef __cplusplus
512552
}

0 commit comments

Comments
 (0)