From d3843a5afb317bac91880f14a8a306a78ca4f577 Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Tue, 6 Mar 2012 09:46:31 -0800 Subject: Add a trap for tasks which exit their task functions Signed-off-by: Randall Spangler BUG=chrome-os-partner:8350 TEST=manual Hack a task function to return. Then see that it prints an error to the debug console and the EC continues running, instead of seeing a hard-fault. Change-Id: Iacd2b83c4d4845bb8e6c61e07c3150df8edc7e49 --- core/cortex-m/switch.S | 2 +- core/cortex-m/task.c | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) (limited to 'core') diff --git a/core/cortex-m/switch.S b/core/cortex-m/switch.S index 4d974251cd..1e4108b173 100644 --- a/core/cortex-m/switch.S +++ b/core/cortex-m/switch.S @@ -26,7 +26,7 @@ * * must be called from interrupt context * - * the structure of tje saved context on the stack is : + * the structure of the saved context on the stack is : * r0, r1, r2, r3, r12, lr, pc, psr, r4, r5, r6, r7, r8, r9, r10, r11 * exception frame <|> additional registers */ diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c index c053c027db..aed0a6b13c 100644 --- a/core/cortex-m/task.c +++ b/core/cortex-m/task.c @@ -39,15 +39,34 @@ void __idle(void); CONFIG_TASK_LIST #undef TASK +/* store the task names for easier debugging */ +#define TASK(n, r, d) #n, +#include TASK_LIST +static const char * const task_names[] = { + "<< idle >>", + CONFIG_TASK_LIST +}; +#undef TASK extern void __switchto(task_ *from, task_ *to); +static void task_exit_trap(void) +{ + int i = task_get_current(); + uart_printf("[Task %d (%s) exited!]\n", i, task_names[i]); + /* Exited tasks simply sleep forever */ + while (1) + task_wait_msg(-1); +} + + + /* declare and fill the contexts for all the tasks */ #define TASK(n, r, d) { \ .context[0] = (uint32_t)(tasks + TASK_ID_##n + 1) - 64, \ .context[TASK_SIZE/4 - 8/*r0*/] = (uint32_t)d, \ - /* TODO set a LR to a trap */ \ + .context[TASK_SIZE/4 - 3/*lr*/] = (uint32_t)task_exit_trap, \ .context[TASK_SIZE/4 - 2/*pc*/] = (uint32_t)r, \ .context[TASK_SIZE/4 - 1/*psr*/] = 0x01000000 }, #include TASK_LIST @@ -353,15 +372,6 @@ void mutex_unlock(struct mutex *mtx) #ifdef CONFIG_DEBUG -/* store the task names for easier debugging */ -#define TASK(n, r, d) #n, -#include TASK_LIST -static const char * const task_names[] = { - "<< idle >>", - CONFIG_TASK_LIST -}; -#undef TASK - int command_task_info(int argc, char **argv) { -- cgit v1.2.1