riscv: Fixes GDB backtrace end function to point to prvTaskExitError

This commit is contained in:
Alexey Gerenkov 2022-01-27 12:06:30 +03:00 committed by Ivan Grokhotkov
parent 54569fb001
commit 088e940528

View File

@ -115,7 +115,7 @@ void vPortEndScheduler(void)
// ------------------------ Stack --------------------------
static void prvTaskExitError(void)
__attribute__((noreturn)) static void _prvTaskExitError(void)
{
/* A function that implements a task must not exit or attempt to return to
its caller as there is nothing to return to. If a task wants to exit it
@ -128,6 +128,15 @@ static void prvTaskExitError(void)
abort();
}
__attribute__((naked)) static void prvTaskExitError(void)
{
asm volatile(".option push\n" \
".option norvc\n" \
"nop\n" \
".option pop");
_prvTaskExitError();
}
StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters)
{
extern uint32_t __global_pointer$;
@ -190,7 +199,9 @@ StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxC
sp -= RV_STK_FRMSZ;
RvExcFrame *frame = (RvExcFrame *)sp;
memset(frame, 0, sizeof(*frame));
frame->ra = (UBaseType_t)prvTaskExitError;
/* Shifting RA into prvTaskExitError is necessary to make GDB backtrace ending inside that function.
Otherwise backtrace will end in the function laying just before prvTaskExitError in address space. */
frame->ra = (UBaseType_t)prvTaskExitError + 4/*nop size*/;
frame->mepc = (UBaseType_t)pxCode;
frame->a0 = (UBaseType_t)pvParameters;
frame->gp = (UBaseType_t)&__global_pointer$;