From a8872bea509f507b8f595e210e49fd06d8aa0d49 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 8 Mar 2007 18:34:11 +0000 Subject: Fix c5471 signal handling + deallocation bug git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@44 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/arch/c5471/src/up_assert.c | 78 +++++++++++++++++++++++++++++ nuttx/arch/c5471/src/up_internal.h | 9 ++-- nuttx/arch/c5471/src/up_schedulesigaction.c | 4 ++ nuttx/arch/c5471/src/up_serial.c | 9 ++-- nuttx/arch/c5471/src/up_sigdeliver.c | 13 ++--- 5 files changed, 99 insertions(+), 14 deletions(-) (limited to 'nuttx/arch/c5471/src') diff --git a/nuttx/arch/c5471/src/up_assert.c b/nuttx/arch/c5471/src/up_assert.c index 679a01f29..570a80ad6 100644 --- a/nuttx/arch/c5471/src/up_assert.c +++ b/nuttx/arch/c5471/src/up_assert.c @@ -58,6 +58,64 @@ * Private Functions ************************************************************/ +/************************************************************ + * Name: up_getsp + ************************************************************/ + +/* I don't know if the builtin to get SP is enabled */ + +static inline uint32 up_getsp(void) +{ + uint32 sp; + __asm__ + ( + "\tmov %0, sp\n\t" + : "=r"(sp) + ); + return sp; +} + +/************************************************************ + * Name: up_stackdump + ************************************************************/ + +#ifdef CONFIG_C5471_STACKDUMP +static void up_stackdump(void) +{ + _TCB *rtcb = (_TCB*)g_readytorun.head; + uint32 stack_base = (uint32)rtcb->adj_stack_ptr; + uint32 sp = up_getsp(); + + lldbg("stack_base: %08x\n", stack_base); + lldbg("stack_size: %08x\n", rtcb->adj_stack_size); + lldbg("sp: %08x\n", sp); + + if (sp >= stack_base || sp < stack_base - rtcb->adj_stack_size) + { + lldbg("ERROR: Stack pointer is not within allocated stack\n"); + return; + } + else + { + uint32 stack = sp & ~0x1f; + + for (stack = sp & ~0x1f; stack < stack_base; stack += 32) + { + uint32 *ptr = (uint32*)stack; + lldbg("%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", + stack, ptr[0], ptr[1], ptr[2], ptr[3], + ptr[4], ptr[5], ptr[6], ptr[7]); + } + } +} +#else +# define up_stackdump() +#endif + +/************************************************************ + * Name: _up_assert + ************************************************************/ + static void _up_assert(int errorcode) /* __attribute__ ((noreturn)) */ { /* Are we in an interrupt handler or the idle task? */ @@ -91,9 +149,19 @@ static void _up_assert(int errorcode) /* __attribute__ ((noreturn)) */ void up_assert(const ubyte *filename, int lineno) { +#if CONFIG_TASK_NAME_SIZE > 0 + _TCB *rtcb = (_TCB*)g_readytorun.head; +#endif + up_ledon(LED_ASSERTION); +#if CONFIG_TASK_NAME_SIZE > 0 + dbg("Assertion failed at file:%s line: %d task: %s\n", + filename, lineno, rtcb->name); +#else dbg("Assertion failed at file:%s line: %d\n", filename, lineno); +#endif + up_stackdump(); _up_assert(EXIT_FAILURE); } @@ -103,8 +171,18 @@ void up_assert(const ubyte *filename, int lineno) void up_assert_code(const ubyte *filename, int lineno, int errorcode) { +#if CONFIG_TASK_NAME_SIZE > 0 + _TCB *rtcb = (_TCB*)g_readytorun.head; +#endif + up_ledon(LED_ASSERTION); +#if CONFIG_TASK_NAME_SIZE > 0 + dbg("Assertion failed at file:%s line: %d task: %s error code: %d\n", + filename, lineno, rtcb->name, errorcode); +#else dbg("Assertion failed at file:%s line: %d error code: %d\n", filename, lineno, errorcode); +#endif + up_stackdump(); _up_assert(errorcode); } diff --git a/nuttx/arch/c5471/src/up_internal.h b/nuttx/arch/c5471/src/up_internal.h index 5f7e4307e..a5eb40ae8 100644 --- a/nuttx/arch/c5471/src/up_internal.h +++ b/nuttx/arch/c5471/src/up_internal.h @@ -44,13 +44,16 @@ * Definitions ************************************************************/ -/* Bring-up debug configurations */ +/* Bring-up debug configurations. These are here (vs defconfig) + * because these should only be controlled during low level + * board bring-up and not part of normal platform configuration. + */ #define CONFIG_SUPPRESS_INTERRUPTS 1 /* Do not enable interrupts */ #undef CONFIG_SUPPRESS_UART_CONFIG /* Do not reconfig UART */ -#define CONFIG_C5471_LEDS 1 /* Use LEDs to show state */ +#define CONFIG_C5471_STACKDUMP 1 /* Dump stack on assertion */ -/* LED meanings */ +/* LED definitions */ #define LED_STARTED 0 #define LED_HEAPALLOCATE 1 diff --git a/nuttx/arch/c5471/src/up_schedulesigaction.c b/nuttx/arch/c5471/src/up_schedulesigaction.c index 3f4e32ec9..47b565e2b 100644 --- a/nuttx/arch/c5471/src/up_schedulesigaction.c +++ b/nuttx/arch/c5471/src/up_schedulesigaction.c @@ -99,6 +99,8 @@ void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver) { /* Refuse to handle nested signal actions */ + dbg("tcb=0x%p sigdeliver=0x%p\n", tcb, sigdeliver); + if (!tcb->xcp.sigdeliver) { irqstate_t flags; @@ -111,6 +113,8 @@ void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver) * being delivered to the currently executing task. */ + dbg("rtcb=0x%p current_regs=0x%p\n", g_readytorun.head, current_regs); + if (tcb == (_TCB*)g_readytorun.head) { /* CASE 1: We are not in an interrupt handler and diff --git a/nuttx/arch/c5471/src/up_serial.c b/nuttx/arch/c5471/src/up_serial.c index b51e48c0e..d0d5ed6ba 100644 --- a/nuttx/arch/c5471/src/up_serial.c +++ b/nuttx/arch/c5471/src/up_serial.c @@ -589,14 +589,13 @@ static void up_xmitchars(up_dev_t *dev) static void up_putxmitchar(up_dev_t *dev, int ch) { int nexthead = dev->xmit.head + 1; + if (nexthead >= dev->xmit.size) + { + nexthead = 0; + } for(;;) { - if (nexthead >= dev->xmit.size) - { - nexthead = 0; - } - if (nexthead != dev->xmit.tail) { dev->xmit.buffer[dev->xmit.head] = ch; diff --git a/nuttx/arch/c5471/src/up_sigdeliver.c b/nuttx/arch/c5471/src/up_sigdeliver.c index df1040314..d19881c53 100644 --- a/nuttx/arch/c5471/src/up_sigdeliver.c +++ b/nuttx/arch/c5471/src/up_sigdeliver.c @@ -81,7 +81,10 @@ void up_sigdeliver(void) sig_deliver_t sigdeliver; up_ledon(LED_SIGNAL); - ASSERT(rtcb->xcp.sigdeliver); + + dbg("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n", + rtcb, rtcb->xcp.sigdeliver, rtcb->sigpendactionq.head); + ASSERT(rtcb->xcp.sigdeliver != NULL); /* Save the real return state on the stack. */ @@ -99,12 +102,9 @@ void up_sigdeliver(void) sigdeliver = rtcb->xcp.sigdeliver; rtcb->xcp.sigdeliver = NULL; - /* Then enable interrupts. We should still be safe from - * any further signal handling actions until we also - * nullify tcb->xcp.sigdeliver. - */ + /* Then restore the task interrupt statat. */ - irqrestore(SVC_MODE | F_BIT); + irqrestore(regs[REG_CPSR]); /* Deliver the signals */ @@ -115,5 +115,6 @@ void up_sigdeliver(void) */ up_ledoff(LED_SIGNAL); + dbg("Resuming\n"); up_fullcontextrestore(regs); } -- cgit v1.2.3