[BUG] - The CCS_ARM_CR4 port jumps to address 0x3C starting tasks

Abierto
#1,381 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
30/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
c

Línea de trabajo

Start with the stack initialisation in portable/CCS/ARM_Cortex-R4/port.c around line 103, where the R14 slot is filled with 0x0, then read portRESTORE_CONTEXT in portable/CCS/ARM_Cortex-R4/portASM.asm near line 130 to see how LR is used. Done means the restore path reaches the task entry address on a CR4 target instead of jumping to 0x3C; the proposed pxOriginalTOS - 0x40 patch is untested and needs hardware verification.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

Describe the bug

The task stack initialization function fills R14 backup with 0x0 and the context restoration routine jumps to R14+0x3C=0x3C. The context restoration routine should jump to the task address given during the task creation instead.

In ARM CORTEX R4, R14 is also the Link Register (LR) when in User Mode (source).

Target

  • Development board: Whichever (based on TI's TMS570LS31xx)
  • Instruction Set Architecture: ARMv7-R
  • IDE and version: Code Composer Studio 12
  • Toolchain and version: ti-cgt-arm_20.2.7.LTS

Host

  • Host OS: Ubuntu
  • Version: 24.04

To Reproduce

  • Build any FreeRTOS project using the CCS_ARM_CR4 port
  • Load on any CR4 target
  • Add a breakpoint at 0x3C
  • Run the program: it should hit the breakpoint.

Alternatively, set the breakpoint in the portRESTORE_CONTEXT routine and step until reaching the instruction "SUBS PC, LR, #4" (last instruction in the routine). The PC is just about to be loaded with 0x3C (the contents of LR/R14).

Suggested solution
I fixed it locally with the patch:

diff --git a/portable/CCS/ARM_Cortex-R4/port.c b/portable/CCS/ARM_Cortex-R4/port.c
index 64e96bbe7..43481c5ad 100644
--- a/portable/CCS/ARM_Cortex-R4/port.c
+++ b/portable/CCS/ARM_Cortex-R4/port.c
@@ -100,7 +100,7 @@ StackType_t *pxOriginalTOS;
     *pxTopOfStack = ( StackType_t ) pxCode + portINSTRUCTION_SIZE;
     pxTopOfStack--;
 
-    *pxTopOfStack = ( StackType_t ) 0x00000000; /* R14 */
+    *pxTopOfStack = ( StackType_t ) pxOriginalTOS - 0x40; /* R14, LR */
     pxTopOfStack--;
     *pxTopOfStack = ( StackType_t ) pxOriginalTOS; /* Stack used when task starts goes in R13. */
     pxTopOfStack--;

which fills R14 with the right address to jump (the task function address).

Lenguaje dominante
C
Estrellas
4.6k
Forks
1.6k
Merge medio
2 d 22 h
PR fusionados (30 d)
4

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de FreeRTOS/FreeRTOS-Kernel

Todos los issues de FreeRTOS/FreeRTOS-Kernel

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.