Skip to content

[rtos] Fixed registers clobbered SVC_Handler in IAR #1905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2016

Conversation

geky
Copy link
Contributor

@geky geky commented Jun 11, 2016

The rtx SVC_Handler for IAR clobbers r0-r3 despite the number of
arguments. However, in the SVC calls, the __swi function is declared
with fewer arguments. IAR doesn't understand that the other registers are
clobbered and stores variables in r0-r3 when multiple SVCs are
dispatched in a single function.

This bug was noticed in osThreadExit, which hard-faults on IAR,
preventing any threads from exiting.

The rtx SVC_Handler for IAR clobbers r0-r3 despite the number of
arguments. However, in the SVC calls, the __swi function is declared
with fewer arguments. IAR doesn't understand that the other registers are
clobbered and stores variables in r0-r3 when multiple SVCs are
dispatched in a single function.

This bug was noticed in osThreadExit, which hard-faults on IAR,
preventing any threads from exiting.
@geky
Copy link
Contributor Author

geky commented Jun 12, 2016

Here is the relevant SVC call: rt_CMSIS.c#L315
Here is the relevant SVC handler: HAL_CM4.S#L147

@geky geky force-pushed the rtx-iar-svc-clobbered branch from 894f189 to 70ebb6f Compare June 12, 2016 13:19
@sg-
Copy link
Contributor

sg- commented Jun 12, 2016

@mbed-bot: TEST

HOST_OSES=windows
BUILD_TOOLCHAINS=ALL
TARGETS=ALL

@@ -302,7 +302,7 @@ static inline t __##f (t1 a1, t2 a2, t3 a3, t4 a4) { \
#define SVC_Setup(f) \
__asm( \
"mov r12,%0\n" \
:: "r"(&f): "r12" \
:: "r"(&f): "r0", "r1", "r2", "r3", "r12" \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to add "memory" to the clobber list as well. This will force all global variables to be written out before the call.

Copy link
Contributor Author

@geky geky Jun 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is emitting an IAR specific __swi function declaration and call for each svc, so the compiler should be able to handle the memory ordering appropriately. The issue is that the functions are emitted with fewer arguments than are clobbered in the svc handler.

_Pragma("swi_number=0") __swi t _##f (t1 a1);

rt_CMSIS.c#L323

@mbed-bot
Copy link

[Build 466]
FAILURE: Something went wrong when building and testing.

@geky geky merged commit 6c24601 into ARMmbed:master Jun 12, 2016
@0xc0170
Copy link
Contributor

0xc0170 commented Jun 12, 2016

@geky Report this to cmsis repo (https://github.com/ARM-software/CMSIS) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants