Skip to content

Commit 2fab8cb

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 320a07c commit 2fab8cb

File tree

78 files changed

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

78 files changed

+2808
-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

portable/ARMv8M/non_secure/port.c

Lines changed: 84 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,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,23 @@ 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 Checks the pointer authentication, and branch target identification security feature
427+
* configuration based on the selected option using the FREERTOS_ARM_V_8_1_M_PACBTI_CONFIG CMake variable,
428+
* returns the value of the special purpose control register accordingly, and optionally updates
429+
* the Control register value. Currently, only Cortex-M85 (ARMv8.1-M architecture based)
430+
* target supports PACBTI security feature.
431+
*
432+
* @param xWriteControlRegister used to control whether the special purpose Control register
433+
* should be updated or not.
434+
*
435+
* @return Control register value according to the configured PACBTI option.
436+
*/
437+
static uint32_t prvCheckAndConfigPacBti ( BaseType_t xWriteControlRegister );
438+
#endif /* portPROCESSOR_VARIANT == 85 */
439+
413440
/**
414441
* @brief Setup the timer to generate the tick interrupts.
415442
*
@@ -1503,16 +1530,23 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
15031530
xMPUSettings->ulContext[ ulIndex ] = ( uint32_t ) pxEndOfStack; /* PSPLIM. */
15041531
ulIndex++;
15051532

1533+
uint32_t ulControl = 0x0;
1534+
#if (portPROCESSOR_VARIANT == 85)
1535+
{
1536+
/* Check PACBTI security feature configuration before pushing the control register's value on task's TCB. */
1537+
ulControl = prvCheckAndConfigPacBti(pdFALSE);
1538+
}
1539+
#endif /* portPROCESSOR_VARIANT == 85 */
15061540
if( xRunPrivileged == pdTRUE )
15071541
{
15081542
xMPUSettings->ulTaskFlags |= portTASK_IS_PRIVILEGED_FLAG;
1509-
xMPUSettings->ulContext[ ulIndex ] = ( uint32_t ) portINITIAL_CONTROL_PRIVILEGED; /* CONTROL. */
1543+
xMPUSettings->ulContext[ ulIndex ] = ( ulControl | ( uint32_t ) portINITIAL_CONTROL_PRIVILEGED ); /* CONTROL. */
15101544
ulIndex++;
15111545
}
15121546
else
15131547
{
15141548
xMPUSettings->ulTaskFlags &= ( ~portTASK_IS_PRIVILEGED_FLAG );
1515-
xMPUSettings->ulContext[ ulIndex ] = ( uint32_t ) portINITIAL_CONTROL_UNPRIVILEGED; /* CONTROL. */
1549+
xMPUSettings->ulContext[ ulIndex ] = ( ulControl | ( uint32_t ) portINITIAL_CONTROL_UNPRIVILEGED ); /* CONTROL. */
15161550
ulIndex++;
15171551
}
15181552

@@ -1740,6 +1774,13 @@ BaseType_t xPortStartScheduler( void ) /* PRIVILEGED_FUNCTION */
17401774
portNVIC_SHPR3_REG |= portNVIC_SYSTICK_PRI;
17411775
portNVIC_SHPR2_REG = 0;
17421776

1777+
#if (portPROCESSOR_VARIANT == 85)
1778+
{
1779+
/* Set the Control register value based on PACBTI security feature configuration before starting the first task. */
1780+
( void) prvCheckAndConfigPacBti(pdTRUE);
1781+
}
1782+
#endif /* portPROCESSOR_VARIANT == 85 */
1783+
17431784
#if ( configENABLE_MPU == 1 )
17441785
{
17451786
/* Setup the Memory Protection Unit (MPU). */
@@ -2158,3 +2199,44 @@ BaseType_t xPortIsInsideInterrupt( void )
21582199

21592200
#endif /* #if ( ( configENABLE_MPU == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) ) */
21602201
/*-----------------------------------------------------------*/
2202+
2203+
#if (portPROCESSOR_VARIANT == 85)
2204+
static uint32_t prvCheckAndConfigPacBti ( BaseType_t xWriteControlRegister )
2205+
{
2206+
#if defined ( portARM_V_8_1_M_PACBTI_CONFIG )
2207+
uint32_t ulIdIsar5 = portID_ISAR5_REG;
2208+
configASSERT(ulIdIsar5 != 0x0);
2209+
2210+
/* Enable UsageFault exception if the selected configuration is not portARM_V_8_1_M_PACBTI_CONFIG_NONE */
2211+
#if ( portARM_V_8_1_M_PACBTI_CONFIG != portARM_V_8_1_M_PACBTI_CONFIG_NONE )
2212+
portSCB_SYS_HANDLER_CTRL_STATE_REG |= portSCB_USG_FAULT_ENABLE_BIT;
2213+
#endif
2214+
2215+
uint32_t ulControl = 0x0;
2216+
#if ( ( portARM_V_8_1_M_PACBTI_CONFIG == portARM_V_8_1_M_PACBTI_CONFIG_STANDARD ) || \
2217+
( portARM_V_8_1_M_PACBTI_CONFIG == portARM_V_8_1_M_PACBTI_CONFIG_PACRET_LEAF_BTI ) )
2218+
/* Set UPAC_EN, PAC_EN, UBTI_EN, and BTI_EN control bits to one */
2219+
ulControl = 0xF0;
2220+
#elif ( ( portARM_V_8_1_M_PACBTI_CONFIG == portARM_V_8_1_M_PACBTI_CONFIG_PACRET ) || \
2221+
( portARM_V_8_1_M_PACBTI_CONFIG == portARM_V_8_1_M_PACBTI_CONFIG_PACRET_LEAF ) )
2222+
/* Set UPAC_EN, and PAC_EN control bits to one */
2223+
ulControl = 0xC0;
2224+
#elif ( portARM_V_8_1_M_PACBTI_CONFIG == portARM_V_8_1_M_PACBTI_CONFIG_BTI )
2225+
/* Set UBTI_EN, and BTI_EN control bits to one */
2226+
ulControl = 0x30;
2227+
#elif ( portARM_V_8_1_M_PACBTI_CONFIG == portARM_V_8_1_M_PACBTI_CONFIG_NONE )
2228+
/* Clear UPAC_EN, PAC_EN, UBTI_EN, and BTI_EN control bits */
2229+
ulControl = 0x00;
2230+
#else
2231+
#error "Invalid portARM_V_8_1_M_PACBTI_CONFIG option chosen"
2232+
#endif
2233+
if ( xWriteControlRegister == pdTRUE )
2234+
{
2235+
__asm volatile ( "msr control, %0" : : "r" ( ulControl ) );
2236+
}
2237+
2238+
return ulControl;
2239+
#endif
2240+
}
2241+
#endif /* portPROCESSOR_VARIANT == 85 */
2242+
/*-----------------------------------------------------------*/

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

0 commit comments

Comments
 (0)