Skip to content

Commit

Permalink
armv8-m: Do not overwrite Control register value
Browse files Browse the repository at this point in the history
The current ARMv8-M FreeRTOS-Kernel Port code
implementation is modified in a way that allows
the CONTROL register's value to be retained
rather than being overwritten.

This is needed for adding PACBTI support as
the special-purpose CONTROL register `PAC_EN`,
`UPAC_EN`, `BTI_EN`, and `UBTI_EN` PACBTI
enablement bits should be configured before calling
`vRestoreContextOfFirstTask()` function which currently
overwrite the value inside the CONTROL register.

Signed-off-by: Ahmed Ismail <[email protected]>
  • Loading branch information
Ahmed Ismail authored and AhmedIsmail02 committed Sep 13, 2024
1 parent 950fdf4 commit 53e9117
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2024 Arm Limited and/or its affiliates
* <[email protected]>
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -130,8 +132,9 @@
" \n"
" ldm r0!, {r1-r2} \n" /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
" msr psplim, r1 \n" /* Set this task's PSPLIM value. */
" movs r1, #2 \n" /* r1 = 2. */
" msr CONTROL, r1 \n" /* Switch to use PSP in the thread mode. */
" mrs r3, control \n" /* Obtain current control register value. */
" orrs r3, r3, #2 \n" /* r3 = r3 | 0x2. */
" msr control, r3 \n" /* Write back the new control register value. */
" adds r0, #32 \n" /* Discard everything up to r0. */
" msr psp, r0 \n" /* This is now the new top of stack to use in the task. */
" isb \n"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2024 Arm Limited and/or its affiliates
* <[email protected]>
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -165,8 +167,9 @@ vRestoreContextOfFirstTask:

ldm r0!, {r1-r2} /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
msr psplim, r1 /* Set this task's PSPLIM value. */
movs r1, #2 /* r1 = 2. */
msr CONTROL, r1 /* Switch to use PSP in the thread mode. */
mrs r3, control /* Obtain current control register value. */
orrs r3, r3, #2 /* r3 = r3 | 0x2 */
msr control, r3 /* Write back the new control register value. */
adds r0, #32 /* Discard everything up to r0. */
msr psp, r0 /* This is now the new top of stack to use in the task. */
isb
Expand Down
7 changes: 5 additions & 2 deletions portable/GCC/ARM_CM33_NTZ/non_secure/portasm.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2024 Arm Limited and/or its affiliates
* <[email protected]>
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -130,8 +132,9 @@
" \n"
" ldm r0!, {r1-r2} \n" /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
" msr psplim, r1 \n" /* Set this task's PSPLIM value. */
" movs r1, #2 \n" /* r1 = 2. */
" msr CONTROL, r1 \n" /* Switch to use PSP in the thread mode. */
" mrs r3, control \n" /* Obtain current control register value. */
" orrs r3, r3, #2 \n" /* r3 = r3 | 0x2. */
" msr control, r3 \n" /* Write back the new control register value. */
" adds r0, #32 \n" /* Discard everything up to r0. */
" msr psp, r0 \n" /* This is now the new top of stack to use in the task. */
" isb \n"
Expand Down
7 changes: 5 additions & 2 deletions portable/GCC/ARM_CM35P_NTZ/non_secure/portasm.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2024 Arm Limited and/or its affiliates
* <[email protected]>
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -130,8 +132,9 @@
" \n"
" ldm r0!, {r1-r2} \n" /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
" msr psplim, r1 \n" /* Set this task's PSPLIM value. */
" movs r1, #2 \n" /* r1 = 2. */
" msr CONTROL, r1 \n" /* Switch to use PSP in the thread mode. */
" mrs r3, control \n" /* Obtain current control register value. */
" orrs r3, r3, #2 \n" /* r3 = r3 | 0x2. */
" msr control, r3 \n" /* Write back the new control register value. */
" adds r0, #32 \n" /* Discard everything up to r0. */
" msr psp, r0 \n" /* This is now the new top of stack to use in the task. */
" isb \n"
Expand Down
7 changes: 5 additions & 2 deletions portable/GCC/ARM_CM55_NTZ/non_secure/portasm.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2024 Arm Limited and/or its affiliates
* <[email protected]>
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -130,8 +132,9 @@
" \n"
" ldm r0!, {r1-r2} \n" /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
" msr psplim, r1 \n" /* Set this task's PSPLIM value. */
" movs r1, #2 \n" /* r1 = 2. */
" msr CONTROL, r1 \n" /* Switch to use PSP in the thread mode. */
" mrs r3, control \n" /* Obtain current control register value. */
" orrs r3, r3, #2 \n" /* r3 = r3 | 0x2. */
" msr control, r3 \n" /* Write back the new control register value. */
" adds r0, #32 \n" /* Discard everything up to r0. */
" msr psp, r0 \n" /* This is now the new top of stack to use in the task. */
" isb \n"
Expand Down
7 changes: 5 additions & 2 deletions portable/GCC/ARM_CM85_NTZ/non_secure/portasm.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2024 Arm Limited and/or its affiliates
* <[email protected]>
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -130,8 +132,9 @@
" \n"
" ldm r0!, {r1-r2} \n" /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
" msr psplim, r1 \n" /* Set this task's PSPLIM value. */
" movs r1, #2 \n" /* r1 = 2. */
" msr CONTROL, r1 \n" /* Switch to use PSP in the thread mode. */
" mrs r3, control \n" /* Obtain current control register value. */
" orrs r3, r3, #2 \n" /* r3 = r3 | 0x2. */
" msr control, r3 \n" /* Write back the new control register value. */
" adds r0, #32 \n" /* Discard everything up to r0. */
" msr psp, r0 \n" /* This is now the new top of stack to use in the task. */
" isb \n"
Expand Down
7 changes: 5 additions & 2 deletions portable/IAR/ARM_CM33_NTZ/non_secure/portasm.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2024 Arm Limited and/or its affiliates
* <[email protected]>
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -165,8 +167,9 @@ vRestoreContextOfFirstTask:

ldm r0!, {r1-r2} /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
msr psplim, r1 /* Set this task's PSPLIM value. */
movs r1, #2 /* r1 = 2. */
msr CONTROL, r1 /* Switch to use PSP in the thread mode. */
mrs r3, control /* Obtain current control register value. */
orrs r3, r3, #2 /* r3 = r3 | 0x2 */
msr control, r3 /* Write back the new control register value. */
adds r0, #32 /* Discard everything up to r0. */
msr psp, r0 /* This is now the new top of stack to use in the task. */
isb
Expand Down
7 changes: 5 additions & 2 deletions portable/IAR/ARM_CM35P_NTZ/non_secure/portasm.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2024 Arm Limited and/or its affiliates
* <[email protected]>
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -165,8 +167,9 @@ vRestoreContextOfFirstTask:

ldm r0!, {r1-r2} /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
msr psplim, r1 /* Set this task's PSPLIM value. */
movs r1, #2 /* r1 = 2. */
msr CONTROL, r1 /* Switch to use PSP in the thread mode. */
mrs r3, control /* Obtain current control register value. */
orrs r3, r3, #2 /* r3 = r3 | 0x2 */
msr control, r3 /* Write back the new control register value. */
adds r0, #32 /* Discard everything up to r0. */
msr psp, r0 /* This is now the new top of stack to use in the task. */
isb
Expand Down
7 changes: 5 additions & 2 deletions portable/IAR/ARM_CM55_NTZ/non_secure/portasm.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2024 Arm Limited and/or its affiliates
* <[email protected]>
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -165,8 +167,9 @@ vRestoreContextOfFirstTask:

ldm r0!, {r1-r2} /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
msr psplim, r1 /* Set this task's PSPLIM value. */
movs r1, #2 /* r1 = 2. */
msr CONTROL, r1 /* Switch to use PSP in the thread mode. */
mrs r3, control /* Obtain current control register value. */
orrs r3, r3, #2 /* r3 = r3 | 0x2 */
msr control, r3 /* Write back the new control register value. */
adds r0, #32 /* Discard everything up to r0. */
msr psp, r0 /* This is now the new top of stack to use in the task. */
isb
Expand Down
7 changes: 5 additions & 2 deletions portable/IAR/ARM_CM85_NTZ/non_secure/portasm.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright 2024 Arm Limited and/or its affiliates
* <[email protected]>
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -165,8 +167,9 @@ vRestoreContextOfFirstTask:

ldm r0!, {r1-r2} /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
msr psplim, r1 /* Set this task's PSPLIM value. */
movs r1, #2 /* r1 = 2. */
msr CONTROL, r1 /* Switch to use PSP in the thread mode. */
mrs r3, control /* Obtain current control register value. */
orrs r3, r3, #2 /* r3 = r3 | 0x2 */
msr control, r3 /* Write back the new control register value. */
adds r0, #32 /* Discard everything up to r0. */
msr psp, r0 /* This is now the new top of stack to use in the task. */
isb
Expand Down

0 comments on commit 53e9117

Please sign in to comment.