From 1860c9ad09b98102a621a546a259ab69169f6579 Mon Sep 17 00:00:00 2001 From: Forty-Bot Date: Mon, 29 Jan 2024 00:37:43 -0500 Subject: [PATCH] GCC: MSP430F449: Fix pxPortInitialiseStack on EABI (#947) According to the MSP430 EABI [1] section 3.3, Arguments are assigned, in declared order, to the first available register single, pair, or quad from the following list into which it fits (with the following special exceptions). For MSP430 and MSP430X, the argument registers are: R12, R13, R14, R15 Therefore, pvParameters should be passed in R12, as it is the first argument, not R15. Keep passing the parameter in R15 for the MSP430 EABI, if anyone is still using it. [1] https://www.ti.com/lit/an/slaa534a/slaa534a.pdf --- portable/GCC/MSP430F449/port.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/portable/GCC/MSP430F449/port.c b/portable/GCC/MSP430F449/port.c index ca72b410b..488ad2d6f 100644 --- a/portable/GCC/MSP430F449/port.c +++ b/portable/GCC/MSP430F449/port.c @@ -183,16 +183,23 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack, pxTopOfStack--; *pxTopOfStack = ( StackType_t ) 0xbbbb; pxTopOfStack--; +#ifdef __MSPGCC__ *pxTopOfStack = ( StackType_t ) 0xcccc; +#else + /* The MSP430 EABI expects the function parameter in R12. */ + *pxTopOfStack = ( StackType_t ) pvParameters; +#endif pxTopOfStack--; *pxTopOfStack = ( StackType_t ) 0xdddd; pxTopOfStack--; *pxTopOfStack = ( StackType_t ) 0xeeee; pxTopOfStack--; - - /* When the task starts is will expect to find the function parameter in - * R15. */ +#ifdef __MSPGCC__ + /* The mspgcc ABI expects the function parameter in R15. */ *pxTopOfStack = ( StackType_t ) pvParameters; +#else + *pxTopOfStack = ( StackType_t ) 0xffff; +#endif pxTopOfStack--; /* The code generated by the mspgcc compiler does not maintain separate