nios2: fix register saving during thread switch instrumentation

This changes to use stack to store registers before calling thread
switch instrumentation functions, instead of using the thread's
register saving struct.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2020-10-15 13:34:16 -07:00 committed by Anas Nashif
parent 939d48cb02
commit 270ce0b850

View file

@ -22,31 +22,18 @@ GTEXT(_k_neg_eagain)
SECTION_FUNC(exception.other, arch_swap)
#if defined(CONFIG_INSTRUMENT_THREAD_SWITCHING)
/* Get a reference to _kernel in r10 */
movhi r10, %hi(_kernel)
ori r10, r10, %lo(_kernel)
/* Get the pointer to kernel->current */
ldw r11, _kernel_offset_to_current(r10)
stw r2, _thread_offset_to_r16(r11)
stw r3, _thread_offset_to_r17(r11)
stw r4, _thread_offset_to_r18(r11)
stw ra, _thread_offset_to_ra(r11)
stw sp, _thread_offset_to_sp(r11)
/* Need to preserve r4 as it has the function argument. */
addi sp, sp, -12
stw ra, 8(sp)
stw fp, 4(sp)
stw r4, 0(sp)
call z_thread_mark_switched_out
/* Get a reference to _kernel in r10 */
movhi r10, %hi(_kernel)
ori r10, r10, %lo(_kernel)
/* Get the pointer to kernel->current */
ldw r11, _kernel_offset_to_current(r10)
ldw r2, _thread_offset_to_r16(r11)
ldw r3, _thread_offset_to_r17(r11)
ldw r4, _thread_offset_to_r18(r11)
ldw ra, _thread_offset_to_ra(r11)
ldw sp, _thread_offset_to_sp(r11)
ldw r4, 0(sp)
ldw fp, 4(sp)
ldw ra, 8(sp)
addi sp, sp, 12
#endif
/* Get a reference to _kernel in r10 */
@ -136,30 +123,22 @@ no_unlock:
#endif
#if defined(CONFIG_INSTRUMENT_THREAD_SWITCHING)
/* Get a reference to _kernel in r10 */
movhi r10, %hi(_kernel)
ori r10, r10, %lo(_kernel)
ldw r11, _kernel_offset_to_current(r10)
stw r2, _thread_offset_to_r16(r11)
stw r3, _thread_offset_to_r17(r11)
stw r4, _thread_offset_to_r18(r11)
stw ra, _thread_offset_to_ra(r11)
stw sp, _thread_offset_to_sp(r11)
/* Also need to preserve r2, r3 as return values */
addi sp, sp, -20
stw ra, 16(sp)
stw fp, 12(sp)
stw r4, 8(sp)
stw r3, 4(sp)
stw r2, 0(sp)
call z_thread_mark_switched_in
/* Get a reference to _kernel in r10 */
movhi r10, %hi(_kernel)
ori r10, r10, %lo(_kernel)
/* Get the pointer to kernel->current */
ldw r11, _kernel_offset_to_current(r10)
ldw r2, _thread_offset_to_r16(r11)
ldw r3, _thread_offset_to_r17(r11)
ldw r4, _thread_offset_to_r18(r11)
ldw ra, _thread_offset_to_ra(r11)
ldw sp, _thread_offset_to_sp(r11)
ldw r2, 0(sp)
ldw r3, 4(sp)
ldw r4, 8(sp)
ldw fp, 12(sp)
ldw ra, 16(sp)
addi sp, sp, 20
#endif
ret