Skip to content

Commit 26597a3

Browse files
committed
arch: arm: Separate common swap code
There are too many differences between Cortex-A/R and Cortex-M on swap code. For reducing the complexity and easier to maintain, this commit introduces the following major changes 1. Separate swap.c and swap_helper.S into two different parts based on the architecture. 2. Rename 'z_arm_pendsv' to 'z_arm_do_swap' for Cortex-A/R. 3. Removes the part related to the option 'CONFIG_BUILTIN_STACK_GUARD' in 'cortex_a_r/swap_helper.S' because this code is written for the Cortex-M architecture. Signed-off-by: Huifeng Zhang <[email protected]>
1 parent fe5d8c7 commit 26597a3

File tree

8 files changed

+468
-380
lines changed

8 files changed

+468
-380
lines changed

arch/arm/core/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ zephyr_library_sources(
99
nmi.c
1010
nmi_on_reset.S
1111
prep_c.c
12-
swap.c
13-
swap_helper.S
1412
thread.c
1513
)
1614

arch/arm/core/cortex_a_r/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ zephyr_library_sources(
1212
stacks.c
1313
tcm.c
1414
vector_table.S
15+
swap.c
16+
swap_helper.S
1517
)
1618

1719
zephyr_library_sources_ifdef(CONFIG_USERSPACE thread.c)

arch/arm/core/cortex_a_r/exc_exit.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _ASM_FILE_PROLOGUE
2323

2424
GTEXT(z_arm_exc_exit)
2525
GTEXT(z_arm_int_exit)
26-
GTEXT(z_arm_pendsv)
26+
GTEXT(z_arm_do_swap)
2727
GDATA(_kernel)
2828

2929
.macro userspace_exc_exit
@@ -148,7 +148,7 @@ SECTION_SUBSEC_FUNC(TEXT, _HandlerModeExit, z_arm_int_exit)
148148
ldr r1, [r3, #_kernel_offset_to_current]
149149
ldr r0, [r3, #_kernel_offset_to_ready_q_cache]
150150
cmp r0, r1
151-
blne z_arm_pendsv
151+
blne z_arm_do_swap
152152
__EXIT_INT:
153153
#endif /* CONFIG_PREEMPT_ENABLED */
154154

@@ -231,12 +231,12 @@ SECTION_SUBSEC_FUNC(TEXT, _HandlerModeExit, z_arm_exc_exit)
231231
/*
232232
* Switch in the next scheduled thread.
233233
*
234-
* Note that z_arm_pendsv must be called in the SVC mode because it
234+
* Note that z_arm_do_swap must be called in the SVC mode because it
235235
* switches to the SVC mode during context switch and returns to the
236236
* caller using lr_svc.
237237
*/
238238
cps #MODE_SVC
239-
bl z_arm_pendsv
239+
bl z_arm_do_swap
240240

241241
/* Decrement exception nesting count */
242242
ldr r3, =_kernel

arch/arm/core/cortex_a_r/swap.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2018 Linaro, Limited
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <kernel_internal.h>
9+
10+
extern const int _k_neg_eagain;
11+
12+
/* The 'key' actually represents the BASEPRI register
13+
* prior to disabling interrupts via the BASEPRI mechanism.
14+
*
15+
* arch_swap() itself does not do much.
16+
*/
17+
int arch_swap(unsigned int key)
18+
{
19+
/* store off key and return value */
20+
_current->arch.basepri = key;
21+
_current->arch.swap_return_value = _k_neg_eagain;
22+
23+
z_arm_cortex_r_svc();
24+
irq_unlock(key);
25+
26+
/* Context switch is performed here. Returning implies the
27+
* thread has been context-switched-in again.
28+
*/
29+
return _current->arch.swap_return_value;
30+
}

0 commit comments

Comments
 (0)