Skip to content

Commit 53e9117

Browse files
Ahmed IsmailAhmedIsmail02
Ahmed Ismail
authored andcommitted
armv8-m: Do not overwrite Control register value
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 <Ahmed.Ismail@arm.com>
1 parent 950fdf4 commit 53e9117

File tree

10 files changed

+50
-20
lines changed

10 files changed

+50
-20
lines changed

portable/ARMv8M/non_secure/portable/GCC/ARM_CM33_NTZ/portasm.c

Lines changed: 5 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
*
@@ -130,8 +132,9 @@
130132
" \n"
131133
" ldm r0!, {r1-r2} \n" /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
132134
" msr psplim, r1 \n" /* Set this task's PSPLIM value. */
133-
" movs r1, #2 \n" /* r1 = 2. */
134-
" msr CONTROL, r1 \n" /* Switch to use PSP in the thread mode. */
135+
" mrs r3, control \n" /* Obtain current control register value. */
136+
" orrs r3, r3, #2 \n" /* r3 = r3 | 0x2. */
137+
" msr control, r3 \n" /* Write back the new control register value. */
135138
" adds r0, #32 \n" /* Discard everything up to r0. */
136139
" msr psp, r0 \n" /* This is now the new top of stack to use in the task. */
137140
" isb \n"

portable/ARMv8M/non_secure/portable/IAR/ARM_CM33_NTZ/portasm.s

Lines changed: 5 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
*
@@ -165,8 +167,9 @@ vRestoreContextOfFirstTask:
165167

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

portable/GCC/ARM_CM33_NTZ/non_secure/portasm.c

Lines changed: 5 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
*
@@ -130,8 +132,9 @@
130132
" \n"
131133
" ldm r0!, {r1-r2} \n" /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
132134
" msr psplim, r1 \n" /* Set this task's PSPLIM value. */
133-
" movs r1, #2 \n" /* r1 = 2. */
134-
" msr CONTROL, r1 \n" /* Switch to use PSP in the thread mode. */
135+
" mrs r3, control \n" /* Obtain current control register value. */
136+
" orrs r3, r3, #2 \n" /* r3 = r3 | 0x2. */
137+
" msr control, r3 \n" /* Write back the new control register value. */
135138
" adds r0, #32 \n" /* Discard everything up to r0. */
136139
" msr psp, r0 \n" /* This is now the new top of stack to use in the task. */
137140
" isb \n"

portable/GCC/ARM_CM35P_NTZ/non_secure/portasm.c

Lines changed: 5 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
*
@@ -130,8 +132,9 @@
130132
" \n"
131133
" ldm r0!, {r1-r2} \n" /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
132134
" msr psplim, r1 \n" /* Set this task's PSPLIM value. */
133-
" movs r1, #2 \n" /* r1 = 2. */
134-
" msr CONTROL, r1 \n" /* Switch to use PSP in the thread mode. */
135+
" mrs r3, control \n" /* Obtain current control register value. */
136+
" orrs r3, r3, #2 \n" /* r3 = r3 | 0x2. */
137+
" msr control, r3 \n" /* Write back the new control register value. */
135138
" adds r0, #32 \n" /* Discard everything up to r0. */
136139
" msr psp, r0 \n" /* This is now the new top of stack to use in the task. */
137140
" isb \n"

portable/GCC/ARM_CM55_NTZ/non_secure/portasm.c

Lines changed: 5 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
*
@@ -130,8 +132,9 @@
130132
" \n"
131133
" ldm r0!, {r1-r2} \n" /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
132134
" msr psplim, r1 \n" /* Set this task's PSPLIM value. */
133-
" movs r1, #2 \n" /* r1 = 2. */
134-
" msr CONTROL, r1 \n" /* Switch to use PSP in the thread mode. */
135+
" mrs r3, control \n" /* Obtain current control register value. */
136+
" orrs r3, r3, #2 \n" /* r3 = r3 | 0x2. */
137+
" msr control, r3 \n" /* Write back the new control register value. */
135138
" adds r0, #32 \n" /* Discard everything up to r0. */
136139
" msr psp, r0 \n" /* This is now the new top of stack to use in the task. */
137140
" isb \n"

portable/GCC/ARM_CM85_NTZ/non_secure/portasm.c

Lines changed: 5 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
*
@@ -130,8 +132,9 @@
130132
" \n"
131133
" ldm r0!, {r1-r2} \n" /* Read from stack - r1 = PSPLIM and r2 = EXC_RETURN. */
132134
" msr psplim, r1 \n" /* Set this task's PSPLIM value. */
133-
" movs r1, #2 \n" /* r1 = 2. */
134-
" msr CONTROL, r1 \n" /* Switch to use PSP in the thread mode. */
135+
" mrs r3, control \n" /* Obtain current control register value. */
136+
" orrs r3, r3, #2 \n" /* r3 = r3 | 0x2. */
137+
" msr control, r3 \n" /* Write back the new control register value. */
135138
" adds r0, #32 \n" /* Discard everything up to r0. */
136139
" msr psp, r0 \n" /* This is now the new top of stack to use in the task. */
137140
" isb \n"

portable/IAR/ARM_CM33_NTZ/non_secure/portasm.s

Lines changed: 5 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
*
@@ -165,8 +167,9 @@ vRestoreContextOfFirstTask:
165167

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

portable/IAR/ARM_CM35P_NTZ/non_secure/portasm.s

Lines changed: 5 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
*
@@ -165,8 +167,9 @@ vRestoreContextOfFirstTask:
165167

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

portable/IAR/ARM_CM55_NTZ/non_secure/portasm.s

Lines changed: 5 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
*
@@ -165,8 +167,9 @@ vRestoreContextOfFirstTask:
165167

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

portable/IAR/ARM_CM85_NTZ/non_secure/portasm.s

Lines changed: 5 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
*
@@ -165,8 +167,9 @@ vRestoreContextOfFirstTask:
165167

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

0 commit comments

Comments
 (0)