nRF52: support stack coloration

This commit is contained in:
Matias N 2021-01-18 13:42:20 -03:00 committed by Alan Carvalho de Assis
parent 3620728db2
commit 5fc34a6e8c

View File

@ -81,6 +81,11 @@
* Private Functions
****************************************************************************/
#ifdef CONFIG_STACK_COLORATION
static void go_nx_start(void *pv, unsigned int nbytes)
__attribute__ ((naked, no_instrument_function, noreturn));
#endif
/****************************************************************************
* Name: nrf52_fpuconfig
*
@ -168,6 +173,47 @@ static inline void nrf52_fpuconfig(void)
# define nrf52_fpuconfig()
#endif
/****************************************************************************
* Name: go_nx_start
*
* Description:
* Set the IDLE stack to the coloration value and jump into nx_start()
*
****************************************************************************/
#ifdef CONFIG_STACK_COLORATION
static void go_nx_start(void *pv, unsigned int nbytes)
{
/* Set the IDLE stack to the stack coloration value then jump to
* nx_start(). We take extreme care here because were currently
* executing on this stack.
*
* We want to avoid sneak stack access generated by the compiler.
*/
__asm__ __volatile__
(
"\tmovs r1, r1, lsr #2\n" /* R1 = nwords = nbytes >> 2 */
"\tcmp r1, #0\n" /* Check (nwords == 0) */
"\tbeq 2f\n" /* (should not happen) */
"\tbic r0, r0, #3\n" /* R0 = Aligned stackptr */
"\tmovw r2, #0xbeef\n" /* R2 = STACK_COLOR = 0xdeadbeef */
"\tmovt r2, #0xdead\n"
"1:\n" /* Top of the loop */
"\tsub r1, r1, #1\n" /* R1 nwords-- */
"\tcmp r1, #0\n" /* Check (nwords == 0) */
"\tstr r2, [r0], #4\n" /* Save stack color word, increment stackptr */
"\tbne 1b\n" /* Bottom of the loop */
"2:\n"
"\tmov r14, #0\n" /* LR = return address (none) */
"\tb nx_start\n" /* Branch to nx_start */
);
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -266,9 +312,16 @@ void __start(void)
showprogress('\r');
showprogress('\n');
#ifdef CONFIG_STACK_COLORATION
/* Set the IDLE stack to the coloration value and jump into nx_start() */
go_nx_start((FAR void *)&_ebss, CONFIG_IDLETHREAD_STACKSIZE);
#else
nx_start();
/* Shouldn't get here */
for (; ; );
#endif
}