diff --git a/components/freertos/port/riscv/port.c b/components/freertos/port/riscv/port.c index 2f6786841a..886d0a6a98 100644 --- a/components/freertos/port/riscv/port.c +++ b/components/freertos/port/riscv/port.c @@ -161,7 +161,7 @@ void vPortSetupTimer(void) systimer_hal_enable_alarm_int(SYSTIMER_ALARM_0); } -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 @@ -174,6 +174,15 @@ void prvTaskExitError(void) abort(); } +__attribute__((naked)) static void prvTaskExitError(void) +{ + asm volatile(".option push\n" \ + ".option norvc\n" \ + "nop\n" \ + ".option pop"); + _prvTaskExitError(); +} + /* Clear current interrupt mask and set given mask */ void vPortClearInterruptMask(int mask) { @@ -282,7 +291,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$;