summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-05-27 10:39:56 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-06-12 22:21:15 +0000
commit2af21940a3ead5d45cb703a3851868cc6e9b7fbe (patch)
tree3beb0214865008d35c449c9a57f836022fe0485d
parent35fbc972e9dae2fb85cce6837868352ad39aa981 (diff)
downloadchrome-ec-2af21940a3ead5d45cb703a3851868cc6e9b7fbe.tar.gz
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 <shawnn@chromium.org> Change-Id: I6014ccf739dcc4c8f4f960be2b89f01e423b65b5 Reviewed-on: https://chromium-review.googlesource.com/273541 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--core/cortex-m/task.c4
-rw-r--r--core/cortex-m0/task.c4
-rw-r--r--core/nds32/task.c4
-rw-r--r--include/config.h6
4 files changed, 18 insertions, 0 deletions
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
+
/*****************************************************************************/
/*