This repository has been archived on 2023-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
FreeRTOS-Kernel/portable/ThirdParty/XCC/Xtensa
magicse7en 82df39764a
Xtensa: fix the coproc_area incorrect issue (#117)
* Xtensa: fix the coproc_area incorrect issue

foss-xtensa/amazon-freertos#2 mentioned a issue:
1.
In function pxPortInitialiseStack(StackType_t *pxTopOfStack....)
p = (uint32_t *)(((uint32_t) pxTopOfStack - XT_CP_SIZE) & ~0xf);

In function prvInitialiseNewTask (file: task.c)
pxTopOfStack = (pxStack + (ulStackDepth - 1)) & (~portBYTE_ALIGNMENT_MASK)

So the co-processor area is at
p = (uint32_t *)(((uint32_t)((pxStack + (ulStackDepth - 1)) & (~portBYTE_ALIGNMENT_MASK)) - XT_CP_SIZE) & ~0xf);

2.
In function vPortStoreTaskMPUSettings( .... , StackType_t pxBottomOfStack ...)
xMPUSettings->coproc_area = (StackType_t)((((uint32_t)(pxBottomOfStack + usStackDepth - 1)) - XT_CP_SIZE) & ~0xf);

pxBottomOfStack = pxStack

=> xMPUSettings->coproc_area = (StackType_t*)((((uint32_t)(pxStack+ ulStackDepth - 1)) - XT_CP_SIZE ) & ~0xf);

The p is coproc_area that should be equal to xMPUSettings->coproc_area.

For example, assume pxStack is 0xa0000000, ulStackDepth is 0x2000,
portBYTE_ALIGNMENT_MASK is 0x7f, XT_CP_SIZE is 0x100.

The p = (uint32_t)(((uint32_t)((pxStack + (ulStackDepth - 1)) & (~portBYTE_ALIGNMENT_MASK)) - XT_CP_SIZE) & ~0xf)
      = 0xa0001e80
The xMPUSettings->coproc_area = (StackType_t)((((uint32_t)(pxStack+ usStackDepth - 1)) - XT_CP_SIZE ) & ~0xf)
                              = 0xa0001ef0
Obviously, the p is not equal to the xMPUSettings->coproc_area, which will cause context switching error.

Signed-off-by: magicse7en <magicse7en@outlook.com>

* Update port.c

Co-authored-by: Carl Lundin <53273776+lundinc2@users.noreply.github.com>
2020-10-26 11:47:21 -07:00
..
Makefile Re-sync with upstream and stripping away none kernel related. 2020-02-10 13:45:57 -08:00
port.c Xtensa: fix the coproc_area incorrect issue (#117) 2020-10-26 11:47:21 -07:00
portasm.S Re-sync with upstream and stripping away none kernel related. 2020-02-10 13:45:57 -08:00
portbenchmark.h Style: Revert uncrustify for portable directories (#122) 2020-08-17 10:51:02 -07:00
portclib.c Style: Revert uncrustify for portable directories (#122) 2020-08-17 10:51:02 -07:00
portmacro.h Update version number to 10.4.1 (#173) 2020-09-17 15:25:15 -07:00
porttrace.h Style: Revert uncrustify for portable directories (#122) 2020-08-17 10:51:02 -07:00
readme_xtensa.txt Re-sync with upstream and stripping away none kernel related. 2020-02-10 13:45:57 -08:00
xtensa_api.h Style: Revert uncrustify for portable directories (#122) 2020-08-17 10:51:02 -07:00
xtensa_config.h Style: Revert uncrustify for portable directories (#122) 2020-08-17 10:51:02 -07:00
xtensa_context.h Style: Revert uncrustify for portable directories (#122) 2020-08-17 10:51:02 -07:00
xtensa_context.S Re-sync with upstream and stripping away none kernel related. 2020-02-10 13:45:57 -08:00
xtensa_init.c Style: Revert uncrustify for portable directories (#122) 2020-08-17 10:51:02 -07:00
xtensa_intr_asm.S Re-sync with upstream and stripping away none kernel related. 2020-02-10 13:45:57 -08:00
xtensa_intr.c Style: Revert uncrustify for portable directories (#122) 2020-08-17 10:51:02 -07:00
xtensa_overlay_os_hook.c Style: Revert uncrustify for portable directories (#122) 2020-08-17 10:51:02 -07:00
xtensa_rtos.h Style: Revert uncrustify for portable directories (#122) 2020-08-17 10:51:02 -07:00
xtensa_timer.h Style: Revert uncrustify for portable directories (#122) 2020-08-17 10:51:02 -07:00
xtensa_vectors.S Re-sync with upstream and stripping away none kernel related. 2020-02-10 13:45:57 -08:00