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
parent 44bfddd784
commit 300d67411a

View File

@@ -153,7 +153,7 @@ void vPortEndScheduler(void)
// ------------------------ Stack -------------------------- // ------------------------ 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 /* 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 its caller as there is nothing to return to. If a task wants to exit it
@@ -166,6 +166,15 @@ static void prvTaskExitError(void)
abort(); 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) StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters)
{ {
extern uint32_t __global_pointer$; extern uint32_t __global_pointer$;
@@ -228,7 +237,9 @@ StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxC
sp -= RV_STK_FRMSZ; sp -= RV_STK_FRMSZ;
RvExcFrame *frame = (RvExcFrame *)sp; RvExcFrame *frame = (RvExcFrame *)sp;
memset(frame, 0, sizeof(*frame)); 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->mepc = (UBaseType_t)pxCode;
frame->a0 = (UBaseType_t)pvParameters; frame->a0 = (UBaseType_t)pvParameters;
frame->gp = (UBaseType_t)&__global_pointer$; frame->gp = (UBaseType_t)&__global_pointer$;