Commit a1668e16 authored by Max Filippov's avatar Max Filippov Committed by Luis Henriques

xtensa: fix kernel register spilling

commit 77d6273e upstream.

call12 can't be safely used as the first call in the inline function,
because the compiler does not extend the stack frame of the bounding
function accordingly, which may result in corruption of local variables.

If a call needs to be done, do call8 first followed by call12.

For pure assembly code in _switch_to increase stack frame size of the
bounding function.
Signed-off-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 3cb19874
...@@ -25,30 +25,39 @@ static inline void spill_registers(void) ...@@ -25,30 +25,39 @@ static inline void spill_registers(void)
{ {
#if XCHAL_NUM_AREGS > 16 #if XCHAL_NUM_AREGS > 16
__asm__ __volatile__ ( __asm__ __volatile__ (
" call12 1f\n" " call8 1f\n"
" _j 2f\n" " _j 2f\n"
" retw\n" " retw\n"
" .align 4\n" " .align 4\n"
"1:\n" "1:\n"
#if XCHAL_NUM_AREGS == 32
" _entry a1, 32\n"
" addi a8, a0, 3\n"
" _entry a1, 16\n"
" mov a12, a12\n"
" retw\n"
#else
" _entry a1, 48\n" " _entry a1, 48\n"
" addi a12, a0, 3\n" " call12 1f\n"
#if XCHAL_NUM_AREGS > 32 " retw\n"
" .rept (" __stringify(XCHAL_NUM_AREGS) " - 32) / 12\n" " .align 4\n"
"1:\n"
" .rept (" __stringify(XCHAL_NUM_AREGS) " - 16) / 12\n"
" _entry a1, 48\n" " _entry a1, 48\n"
" mov a12, a0\n" " mov a12, a0\n"
" .endr\n" " .endr\n"
#endif " _entry a1, 16\n"
" _entry a1, 48\n"
#if XCHAL_NUM_AREGS % 12 == 0 #if XCHAL_NUM_AREGS % 12 == 0
" mov a8, a8\n"
#elif XCHAL_NUM_AREGS % 12 == 4
" mov a12, a12\n" " mov a12, a12\n"
#elif XCHAL_NUM_AREGS % 12 == 8 #elif XCHAL_NUM_AREGS % 12 == 4
" mov a4, a4\n" " mov a4, a4\n"
#elif XCHAL_NUM_AREGS % 12 == 8
" mov a8, a8\n"
#endif #endif
" retw\n" " retw\n"
#endif
"2:\n" "2:\n"
: : : "a12", "a13", "memory"); : : : "a8", "a9", "memory");
#else #else
__asm__ __volatile__ ( __asm__ __volatile__ (
" mov a12, a12\n" " mov a12, a12\n"
......
...@@ -1793,7 +1793,7 @@ ENDPROC(system_call) ...@@ -1793,7 +1793,7 @@ ENDPROC(system_call)
mov a12, a0 mov a12, a0
.endr .endr
#endif #endif
_entry a1, 48 _entry a1, 16
#if XCHAL_NUM_AREGS % 12 == 0 #if XCHAL_NUM_AREGS % 12 == 0
mov a8, a8 mov a8, a8
#elif XCHAL_NUM_AREGS % 12 == 4 #elif XCHAL_NUM_AREGS % 12 == 4
...@@ -1817,7 +1817,7 @@ ENDPROC(system_call) ...@@ -1817,7 +1817,7 @@ ENDPROC(system_call)
ENTRY(_switch_to) ENTRY(_switch_to)
entry a1, 16 entry a1, 48
mov a11, a3 # and 'next' (a3) mov a11, a3 # and 'next' (a3)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment