Skip to content

Commit ef74d93

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 <Ahmed.Ismail@arm.com>
1 parent 53e9117 commit ef74d93

File tree

78 files changed

+2430
-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.

78 files changed

+2430
-0
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

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+
* <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,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+
* <open-source-office@arm.com>
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+
* <open-source-office@arm.com>
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+
* <open-source-office@arm.com>
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+
* <open-source-office@arm.com>
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+
* <open-source-office@arm.com>
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+
* <open-source-office@arm.com>
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+
* <open-source-office@arm.com>
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+
* <open-source-office@arm.com>
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+
* <open-source-office@arm.com>
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+
* <open-source-office@arm.com>
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+
* <open-source-office@arm.com>
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+
* <open-source-office@arm.com>
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+
* <open-source-office@arm.com>
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+
* <open-source-office@arm.com>
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

0 commit comments

Comments
 (0)