From 2f1519d343c60230de10444fcdd5a74cc629a919 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 19 Mar 2011 18:22:19 +0000 Subject: [PATCH] Added stack checking to the Cortex-Mx RVCT port. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/stable_2.2.x@2836 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/ports/RVCT/ARMCMx/chcore_v6m.h | 9 +++++++++ os/ports/RVCT/ARMCMx/chcore_v7m.h | 11 ++++++++++- readme.txt | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/os/ports/RVCT/ARMCMx/chcore_v6m.h b/os/ports/RVCT/ARMCMx/chcore_v6m.h index a02709dfe..6c3e840dd 100644 --- a/os/ports/RVCT/ARMCMx/chcore_v6m.h +++ b/os/ports/RVCT/ARMCMx/chcore_v6m.h @@ -214,7 +214,16 @@ struct intctx { * @param[in] ntp the thread to be switched in * @param[in] otp the thread to be switched out */ +#if !defined(CH_DBG_ENABLE_STACK_CHECK) || defined(__DOXYGEN__) #define port_switch(ntp, otp) _port_switch(ntp, otp) +#else +#define port_switch(ntp, otp) { \ + struct intctx *r13 = (struct intctx *)__current_sp(); \ + if ((void *)(r13 - 1) < (void *)(otp + 1)) \ + chDbgPanic("stack overflow"); \ + _port_switch(ntp, otp); \ +} +#endif #ifdef __cplusplus extern "C" { diff --git a/os/ports/RVCT/ARMCMx/chcore_v7m.h b/os/ports/RVCT/ARMCMx/chcore_v7m.h index f779b6e58..94ef6bb4f 100644 --- a/os/ports/RVCT/ARMCMx/chcore_v7m.h +++ b/os/ports/RVCT/ARMCMx/chcore_v7m.h @@ -240,7 +240,16 @@ struct intctx { * @param[in] ntp the thread to be switched in * @param[in] otp the thread to be switched out */ -#define port_switch(ntp, otp) _port_switch(ntp, otp) +#if !defined(CH_DBG_ENABLE_STACK_CHECK) || defined(__DOXYGEN__) +#define port_switch(ntp, otp) _port_switch(ntp, otp) +#else +#define port_switch(ntp, otp) { \ + struct intctx *r13 = (struct intctx *)__current_sp(); \ + if ((void *)(r13 - 1) < (void *)(otp + 1)) \ + chDbgPanic("stack overflow"); \ + _port_switch(ntp, otp); \ +} +#endif #ifdef __cplusplus extern "C" { diff --git a/readme.txt b/readme.txt index b9c4fd9c0..4d31accfd 100644 --- a/readme.txt +++ b/readme.txt @@ -75,6 +75,7 @@ - FIX: Fixed wrong checks in PAL driver (bug 3224681). - FIX: Fixed wrong checks in I/O Queues (bug 3219197). - FIX: Fixed invalid assertion in adcConvert() (bug 3205410). +- NEW: Implemented stack checking in the Cortex-Mx RVCT port. - NEW: Improved preemption implementation for the Cortex-M0, now it uses the NMI vector in order to restore the original context. The change makes IRQ handling faster and also saves some RAM/ROM space. The GCC port code