summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2007-03-08 18:34:11 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2007-03-08 18:34:11 +0000
commit7438867827e6a38b110d94cec59114640867b521 (patch)
tree83f8273dcee57f28f22a6f1b01460125f8135835
parent9011da274b29ed5a3433a5146c9243ddf44a51c9 (diff)
Fix c5471 signal handling + deallocation bug
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@44 7fd9a85b-ad96-42d3-883c-3090e2eb8679
-rw-r--r--nuttx/arch/c5471/defconfig2
-rw-r--r--nuttx/arch/c5471/src/up_assert.c78
-rw-r--r--nuttx/arch/c5471/src/up_internal.h9
-rw-r--r--nuttx/arch/c5471/src/up_schedulesigaction.c4
-rw-r--r--nuttx/arch/c5471/src/up_serial.c9
-rw-r--r--nuttx/arch/c5471/src/up_sigdeliver.c13
-rw-r--r--nuttx/examples/ostest/main.c2
-rw-r--r--nuttx/fs/fs_files.c2
-rw-r--r--nuttx/mm/mm_free.c2
-rw-r--r--nuttx/mm/mm_initialize.c2
-rw-r--r--nuttx/mm/mm_malloc.c1
-rw-r--r--nuttx/sched/sig_deliver.c2
12 files changed, 109 insertions, 17 deletions
diff --git a/nuttx/arch/c5471/defconfig b/nuttx/arch/c5471/defconfig
index 8a6d501896..dea8e2c0ca 100644
--- a/nuttx/arch/c5471/defconfig
+++ b/nuttx/arch/c5471/defconfig
@@ -40,11 +40,13 @@
# CONFIG_ROM_VECTORS - unique to c5471
# CONFIG_DRAM_END - the size of installed DRAM.
# Unique to c5471
+# CONFIG_C5471_LEDS - Use LEDs to show state. Unique to c5471.
#
CONFIG_ARCH=c5471
CONFIG_ARCH_C5471=y
CONFIG_ROM_VECTORS=n
CONFIG_DRAM_END=0x11000000
+CONFIG_C5471_LEDS=y
#
# C5471 specific device driver settings
diff --git a/nuttx/arch/c5471/src/up_assert.c b/nuttx/arch/c5471/src/up_assert.c
index 679a01f297..570a80ad6d 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 5f7e4307ef..a5eb40ae80 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 3f4e32ec9f..47b565e2b2 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 b51e48c0ec..d0d5ed6bab 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 df1040314a..d19881c53b 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);
}
diff --git a/nuttx/examples/ostest/main.c b/nuttx/examples/ostest/main.c
index 4e360e6b59..10f4ac2c65 100644
--- a/nuttx/examples/ostest/main.c
+++ b/nuttx/examples/ostest/main.c
@@ -204,7 +204,7 @@ int user_start(int parm1, int parm2, int parm3, int parm4)
}
else
{
- printf("user_start: Started user_main at PID=%d\n", result);
+ printf("user_start: Started user_main at PID=%d\n", result);
}
return 0;
diff --git a/nuttx/fs/fs_files.c b/nuttx/fs/fs_files.c
index 30c2bbed3f..8d300b8cea 100644
--- a/nuttx/fs/fs_files.c
+++ b/nuttx/fs/fs_files.c
@@ -141,7 +141,7 @@ int files_releaselist(FAR struct filelist *list)
/* Decrement the reference count */
_files_semtake(list);
- crefs = --list->fl_crefs;
+ crefs = --(list->fl_crefs);
_files_semgive(list);
/* If the count decrements to zero, then there is no reference
diff --git a/nuttx/mm/mm_free.c b/nuttx/mm/mm_free.c
index 276a734d08..4e32332571 100644
--- a/nuttx/mm/mm_free.c
+++ b/nuttx/mm/mm_free.c
@@ -68,6 +68,8 @@ void free(FAR void *mem)
FAR struct mm_freenode_s *prev;
FAR struct mm_freenode_s *next;
+ vdbg("Freeing %p\n", mem);
+
/* Protect against attempts to free a NULL reference */
if (!mem)
diff --git a/nuttx/mm/mm_initialize.c b/nuttx/mm/mm_initialize.c
index c9c1c4bad2..65be6a4b7a 100644
--- a/nuttx/mm/mm_initialize.c
+++ b/nuttx/mm/mm_initialize.c
@@ -165,6 +165,8 @@ void mm_addregion(FAR void *heapstart, size_t heapsize)
heapend = MM_ALIGN_DOWN((size_t)heapstart + (size_t)heapsize);
heapsize = heapend - heapbase;
+ lldbg("Region %d: base=%p size=%d\n", IDX+1, heapstart, heapsize);
+
/* Add the size of this region to the total size of the heap */
g_heapsize += heapsize;
diff --git a/nuttx/mm/mm_malloc.c b/nuttx/mm/mm_malloc.c
index 05c0f73c86..e9fb96fb56 100644
--- a/nuttx/mm/mm_malloc.c
+++ b/nuttx/mm/mm_malloc.c
@@ -199,5 +199,6 @@ FAR void *malloc(size_t size)
}
mm_givesemaphore();
+ vdbg("Allocated %p\n", ret);
return ret;
}
diff --git a/nuttx/sched/sig_deliver.c b/nuttx/sched/sig_deliver.c
index 5eb24d307b..a2e8c9b5a5 100644
--- a/nuttx/sched/sig_deliver.c
+++ b/nuttx/sched/sig_deliver.c
@@ -132,7 +132,7 @@ void sig_deliver(FAR _TCB *stcb)
rpid = getpid();
- /* Deliver the signal using its address environment */
+ /* Deliver the signal */
(*sigq->action.sighandler)(sigq->info.si_signo, &sigq->info, NULL);