Update core_cmFunc.h

Remove `sp` from the clobber list in the __set_MSP() inline function.
This commit is contained in:
froloffw7 2024-01-09 12:40:35 +01:00 committed by GitHub
parent b3adac6168
commit 4b0f23e110
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -459,7 +459,19 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void)
*/
__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
{
// https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers
// The clobber list should not contain the stack pointer register.
// This is because the compiler requires the value of the stack pointer
// to be the same after an asm statement as it was on entry to the statement.
// However, previous versions of GCC did not enforce this rule and allowed the
// stack pointer to appear in the list, with unclear semantics.
// This behavior is deprecated and listing the stack pointer may become an error
// in future versions of GCC.
#if __GNUC__ >= 9
__ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack));
#else
__ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
#endif
}