From 44bfddd784a7fa6217bf4e16c08bb7f295c41869 Mon Sep 17 00:00:00 2001 From: Alexey Gerenkov Date: Thu, 27 Jan 2022 00:39:52 +0300 Subject: [PATCH] riscv: Fixes GDB backtrace of interrupted threads Save missed SP value on stack --- components/riscv/vectors.S | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/riscv/vectors.S b/components/riscv/vectors.S index 1006d5bea5..e0558d4f97 100644 --- a/components/riscv/vectors.S +++ b/components/riscv/vectors.S @@ -223,6 +223,17 @@ _interrupt_handler: save_regs save_mepc + /* Though it is not necessary we save GP and SP here. + * SP is necessary to help GDB to properly unwind + * the backtrace of threads preempted by interrupts (OS tick etc.). + * GP is saved just to have its proper value in GDB. */ + /* As gp register is not saved by the macro, save it here */ + sw gp, RV_STK_GP(sp) + /* Same goes for the SP value before trapping */ + addi t0, sp, CONTEXT_SIZE /* restore sp with the value when interrupt happened */ + /* Save SP */ + sw t0, RV_STK_SP(sp) + /* Before doing anythig preserve the stack pointer */ /* It will be saved in current TCB, if needed */ mv a0, sp