xtensa: selectively init interrupt stack at boot
During arch_kernel_init(), the interrupt stack is being initialized. However, if the current in-use stack is the interrupt stack, it would wipe all the data up to that point in stack, and might result in crash. So skip initializing the interrupt stack if the current stack pointer is within the boundary of interrupt stack. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
parent
6252fcfccf
commit
0e7def1977
1 changed files with 16 additions and 2 deletions
|
@ -53,8 +53,22 @@ static ALWAYS_INLINE void arch_kernel_init(void)
|
||||||
XTENSA_WSR(ZSR_CPU_STR, cpu0);
|
XTENSA_WSR(ZSR_CPU_STR, cpu0);
|
||||||
|
|
||||||
#ifdef CONFIG_INIT_STACKS
|
#ifdef CONFIG_INIT_STACKS
|
||||||
memset(Z_KERNEL_STACK_BUFFER(z_interrupt_stacks[0]), 0xAA,
|
char *stack_start = Z_KERNEL_STACK_BUFFER(z_interrupt_stacks[0]);
|
||||||
K_KERNEL_STACK_SIZEOF(z_interrupt_stacks[0]));
|
size_t stack_sz = K_KERNEL_STACK_SIZEOF(z_interrupt_stacks[0]);
|
||||||
|
char *stack_end = stack_start + stack_sz;
|
||||||
|
|
||||||
|
uint32_t sp;
|
||||||
|
|
||||||
|
__asm__ volatile("mov %0, sp" : "=a"(sp));
|
||||||
|
|
||||||
|
/* Only clear the interrupt stack if the current stack pointer
|
||||||
|
* is not within the interrupt stack. Or else we would be
|
||||||
|
* wiping the in-use stack.
|
||||||
|
*/
|
||||||
|
if (((uintptr_t)sp < (uintptr_t)stack_start) ||
|
||||||
|
((uintptr_t)sp >= (uintptr_t)stack_end)) {
|
||||||
|
memset(stack_start, 0xAA, stack_sz);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_XTENSA_MMU
|
#ifdef CONFIG_XTENSA_MMU
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue