From 2af21940a3ead5d45cb703a3851868cc6e9b7fbe Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Wed, 27 May 2015 10:39:56 -0700 Subject: core: Assert if task_get_current() cannot return a valid task ID If task_get_current() is called early during initialization when we have not yet done a context switch, our current_task pointer is invalid. Add an assert to detect this case and put it behind CONFIG_DEBUG_BRINGUP, a new config that's intended to enable possibly-costly pre-production debugging. BUG=chrome-os-partner:40677 TEST=Manual on glados. Define CONFIG_DEBUG_BRINGUP, then call i2c_write from board_init and verify the new assert fails. Remove the i2c_write and verify the new assert passes. BRANCH=None Signed-off-by: Shawn Nematbakhsh Change-Id: I6014ccf739dcc4c8f4f960be2b89f01e423b65b5 Reviewed-on: https://chromium-review.googlesource.com/273541 Reviewed-by: Randall Spangler --- core/cortex-m/task.c | 4 ++++ core/cortex-m0/task.c | 4 ++++ core/nds32/task.c | 4 ++++ include/config.h | 6 ++++++ 4 files changed, 18 insertions(+) diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c index f9e4d11fdb..639cef9d48 100644 --- a/core/cortex-m/task.c +++ b/core/cortex-m/task.c @@ -177,6 +177,10 @@ inline int get_interrupt_context(void) task_id_t task_get_current(void) { +#ifdef CONFIG_DEBUG_BRINGUP + /* If we haven't done a context switch then our task ID isn't valid */ + ASSERT(current_task != (task_ *)scratchpad); +#endif return current_task - tasks; } diff --git a/core/cortex-m0/task.c b/core/cortex-m0/task.c index 1ab82d7d24..9d9b049c37 100644 --- a/core/cortex-m0/task.c +++ b/core/cortex-m0/task.c @@ -164,6 +164,10 @@ inline int get_interrupt_context(void) task_id_t task_get_current(void) { +#ifdef CONFIG_DEBUG_BRINGUP + /* If we haven't done a context switch then our task ID isn't valid */ + ASSERT(current_task != (task_ *)scratchpad); +#endif return current_task - tasks; } diff --git a/core/nds32/task.c b/core/nds32/task.c index 1725f2b498..269513092b 100644 --- a/core/nds32/task.c +++ b/core/nds32/task.c @@ -171,6 +171,10 @@ inline int in_interrupt_context(void) task_id_t task_get_current(void) { +#ifdef CONFIG_DEBUG_BRINGUP + /* If we haven't done a context switch then our task ID isn't valid */ + ASSERT(current_task != (task_ *)scratchpad); +#endif return current_task - tasks; } diff --git a/include/config.h b/include/config.h index c0c553fd38..1c6c04518e 100644 --- a/include/config.h +++ b/include/config.h @@ -200,6 +200,12 @@ /* Modify the default behavior to make system bringup easier. */ #undef CONFIG_BRINGUP +/* + * Enable debug prints / asserts that may helpful for debugging board bring-up, + * but probably shouldn't be enabled for production for performance reasons. + */ +#undef CONFIG_DEBUG_BRINGUP + /*****************************************************************************/ /* -- cgit v1.2.1