Skip to content
Snippets Groups Projects
Commit 22b5de86 authored by Ian Martin's avatar Ian Martin
Browse files

add mpu_stack_guard pseudomodule (just Cortex-M for now)

triggers an exception during stack overflow,
but at a cost of 32-63 bytes of RAM per thread.
parent 28a7ddc9
No related branches found
No related tags found
No related merge requests found
...@@ -34,6 +34,7 @@ PSEUDOMODULES += lwip_stats ...@@ -34,6 +34,7 @@ PSEUDOMODULES += lwip_stats
PSEUDOMODULES += lwip_tcp PSEUDOMODULES += lwip_tcp
PSEUDOMODULES += lwip_udp PSEUDOMODULES += lwip_udp
PSEUDOMODULES += lwip_udplite PSEUDOMODULES += lwip_udplite
PSEUDOMODULES += mpu_stack_guard
PSEUDOMODULES += netdev_default PSEUDOMODULES += netdev_default
PSEUDOMODULES += netif PSEUDOMODULES += netif
PSEUDOMODULES += netstats PSEUDOMODULES += netstats
......
...@@ -28,9 +28,14 @@ ...@@ -28,9 +28,14 @@
#include "cpu.h" #include "cpu.h"
#include "kernel_init.h" #include "kernel_init.h"
#include "board.h" #include "board.h"
#include "mpu.h"
#include "panic.h" #include "panic.h"
#include "vectors_cortexm.h" #include "vectors_cortexm.h"
#ifndef SRAM_BASE
#define SRAM_BASE 0
#endif
/** /**
* @brief Memory markers, defined in the linker script * @brief Memory markers, defined in the linker script
* @{ * @{
...@@ -48,6 +53,8 @@ extern uint32_t _sram; ...@@ -48,6 +53,8 @@ extern uint32_t _sram;
extern uint32_t _eram; extern uint32_t _eram;
/** @} */ /** @} */
static const uintptr_t stack_base = (uintptr_t)&_sstack;
/** /**
* @brief Allocation of the interrupt stack * @brief Allocation of the interrupt stack
*/ */
...@@ -94,6 +101,18 @@ void reset_handler_default(void) ...@@ -94,6 +101,18 @@ void reset_handler_default(void)
*(dst++) = 0; *(dst++) = 0;
} }
#ifdef MODULE_MPU_STACK_GUARD
if (stack_base != SRAM_BASE) {
mpu_configure(
0, /* MPU region 0 */
stack_base + 31, /* Base Address (rounded up) */
MPU_ATTR(1, AP_RO_RO, 0, 1, 0, 1, MPU_SIZE_32B) /* Attributes and Size */
);
mpu_enable();
}
#endif
post_startup(); post_startup();
/* initialize the board (which also initiates CPU initialization) */ /* initialize the board (which also initiates CPU initialization) */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment