Skip to content

Commit a4124e7

Browse files
ezequielgarciaRussell King
authored andcommitted
ARM: 8451/1: v7-M: Set an early stack for __v7m_setup
On ARM v7-M, when PROCINFO_INITFUNC (__v7m_setup) is called, a stack is needed before calling the supervisor call (SVC), which is used by the supervisor call to save the context. Currently, __v7m_setup() prepares a temporary stack in the .text.init section, which is is broken if the kernel is executing directly from read-only memory. In particular, this is the case for LPC43xx, which allows to execute the kernel in-place from a serial flash through its SPIFI controller. This commit fixes the issue by seting an early stack to its usual location. Also, __v7m_setup() is currently saving and restoring the previous stack. That was bogus, because there's no stack previously set, so this commit removes it. Acked-by: Uwe Kleine-König <[email protected]> Signed-off-by: Ezequiel Garcia <[email protected]> Signed-off-by: Russell King <[email protected]>
1 parent 440ee36 commit a4124e7

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

arch/arm/mm/proc-v7m.S

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
#include <linux/linkage.h>
1414
#include <asm/assembler.h>
15+
#include <asm/memory.h>
1516
#include <asm/v7m.h>
1617
#include "proc-macros.S"
1718

@@ -97,19 +98,19 @@ __v7m_setup:
9798
mov r5, #0x00800000
9899
str r5, [r0, V7M_SCB_SHPR3] @ set PendSV priority
99100

100-
@ SVC to run the kernel in this mode
101+
@ SVC to switch to handler mode. Notice that this requires sp to
102+
@ point to writeable memory because the processor saves
103+
@ some registers to the stack.
101104
badr r1, 1f
102105
ldr r5, [r12, #11 * 4] @ read the SVC vector entry
103106
str r1, [r12, #11 * 4] @ write the temporary SVC vector entry
104107
mov r6, lr @ save LR
105-
mov r7, sp @ save SP
106-
ldr sp, =__v7m_setup_stack_top
108+
ldr sp, =init_thread_union + THREAD_START_SP
107109
cpsie i
108110
svc #0
109111
1: cpsid i
110112
str r5, [r12, #11 * 4] @ restore the original SVC vector entry
111113
mov lr, r6 @ restore LR
112-
mov sp, r7 @ restore SP
113114

114115
@ Special-purpose control register
115116
mov r1, #1
@@ -123,11 +124,6 @@ __v7m_setup:
123124
ret lr
124125
ENDPROC(__v7m_setup)
125126

126-
.align 2
127-
__v7m_setup_stack:
128-
.space 4 * 8 @ 8 registers
129-
__v7m_setup_stack_top:
130-
131127
define_processor_functions v7m, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1
132128

133129
.section ".rodata"

0 commit comments

Comments
 (0)