From 1001d1f35e61227354c0a4badf2b063a0a728956 Mon Sep 17 00:00:00 2001
From: patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>
Date: Thu, 7 Apr 2011 01:54:59 +0000
Subject: [PATCH] Fix AVR build, Add hooks for kernel threads

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3477 42af7a65-404d-4744-a932-0658087f49c3
---
 Documentation/NuttX.html         | 14 +++++++++++++-
 arch/avr/src/Makefile            |  5 -----
 arch/hc/src/common/up_doirq.c    |  2 +-
 arch/hc/src/common/up_internal.h |  2 +-
 include/nuttx/sched.h            | 12 ++++++++----
 sched/exit.c                     |  2 ++
 sched/pthread_create.c           |  2 +-
 sched/sched_releasetcb.c         |  6 +++---
 8 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html
index 5721c5eff2..891e619bb0 100644
--- a/Documentation/NuttX.html
+++ b/Documentation/NuttX.html
@@ -8,7 +8,7 @@
   <tr align="center" bgcolor="#e4e4e4">
     <td>
       <h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1>
-      <p>Last Updated: April 3, 2011</p>
+      <p>Last Updated: April 6, 2011</p>
     </td>
   </tr>
 </table>
@@ -2201,6 +2201,15 @@ nuttx-6.1 2011-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
       separately linked images: (1) a kernel-mode RTOS image, and (2) a user-
       mode application image that communicates to the RTOS kernel via system
       calls.  A lot more still must be done.
+    * user_initialize(): Eliminated the user_initialize() initialization hook.
+      It is difficult to maintain and redundant:  Board level initialization
+      an up_initialize() provide the same kind of capability.
+    * arch/*/include/*/type.h: On some compilers, char defaults as unsigned.
+      Explicitly add signed to integer types if signed is what is required.
+    * arch/*: For all architectures -- Global register state save structure
+      (usually called current_regs) should be marked volatile; Added general
+      capability to support nested interrupts (not fully realized for all
+      architectures).
 
 apps-6.1 2011-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
 
@@ -2228,6 +2237,9 @@ buildroot-1.10 2011-xx-xx &lt;spudmonkey@racsa.co.cr&gt;
     * Makefile - Alter copy arguements to avoid permissions problems when
       copying NuttX header files.
     * toolchain/nxflat/nxflat.mk and Makefile - Fix include paths.
+    * toolchain/gcc/3.3.6 - Added a patch to fixed compilation error on Ubuntu
+      9.10.
+
 </pre></ul>
 
 <table width ="100%">
diff --git a/arch/avr/src/Makefile b/arch/avr/src/Makefile
index 531a2100d9..1704aad622 100644
--- a/arch/avr/src/Makefile
+++ b/arch/avr/src/Makefile
@@ -108,11 +108,6 @@ nuttx: $(HEAD_AOBJ) board/libboard$(LIBEXT)
 	@echo "LD: nuttx"
 	@$(LD) --entry=__start $(LDFLAGS) $(LIBPATHS) -o $(NUTTX)$(EXEEXT) $(HEAD_AOBJ) $(EXTRA_OBJS) \
 		--start-group $(LDLIBS) -lboard --end-group $(EXTRA_LIBS) $(LIBGCC)
-ifeq ($(CONFIG_BOOT_RUNFROMFLASH),y)
-	@export flashloc=`$(OBJDUMP) --all-headers $(NUTTX)$(EXEEXT) | grep _eronly | cut -d' ' -f1`;  \
-	$(OBJCOPY) $(OBJCOPYARGS) --adjust-section-vma=.data=0x$$flashloc $(NUTTX)$(EXEEXT) $(NUTTX).flashimage
-	@mv $(NUTTX).flashimage $(NUTTX)$(EXEEXT)
-endif
 	@$(NM) $(NUTTX)$(EXEEXT) | \
 	grep -v '\(compiled\)\|\(\$(OBJEXT)$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \
 	sort > $(TOPDIR)/System.map
diff --git a/arch/hc/src/common/up_doirq.c b/arch/hc/src/common/up_doirq.c
index adb3f81ce8..4fc52224ef 100644
--- a/arch/hc/src/common/up_doirq.c
+++ b/arch/hc/src/common/up_doirq.c
@@ -101,7 +101,7 @@ uint8_t *up_doirq(int irq, uint8_t *regs)
    * switch occurred during interrupt processing.
    */
 
-  regs = current_regs;
+  regs = (uint8_t*)current_regs;
 
   /* Restore the previous value of current_regs.  NULL would indicate that
    * we are no longer in an interrupt handler.  It will be non-NULL if we
diff --git a/arch/hc/src/common/up_internal.h b/arch/hc/src/common/up_internal.h
index 1a30f28e5d..efc4ce4b0b 100755
--- a/arch/hc/src/common/up_internal.h
+++ b/arch/hc/src/common/up_internal.h
@@ -101,7 +101,7 @@ typedef void (*up_vector_t)(void);
  * structure.  If is non-NULL only during interrupt processing.
  */
 
-extern uint8_t *current_regs;
+extern volatile uint8_t *current_regs;
 
 /* This is the beginning of heap as provided from processor-specific logic.
  * This is the first address in RAM after the loaded program+bss+idle stack.
diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h
index 1b5d28f82b..78e6f6b378 100644
--- a/include/nuttx/sched.h
+++ b/include/nuttx/sched.h
@@ -66,10 +66,14 @@
 
 /* Values for the _TCB flags flag bits */
 
-#define TCB_FLAG_PTHREAD        0x0001 /* Thread is a pthread */
-#define TCB_FLAG_NONCANCELABLE  0x0002 /* Pthread is non-cancelable */
-#define TCB_FLAG_CANCEL_PENDING 0x0004 /* Pthread cancel is pending */
-#define TCB_FLAG_ROUND_ROBIN    0x0008 /* Round robin sched enabled */
+#define TCB_FLAG_TTYPE_SHIFT     (0)      /* Bits 0-1: thread type */
+#define TCB_FLAG_TTYPE_MASK      (3 << TCB_FLAG_TTYPE_SHIFT)
+#  define TCB_FLAG_TTYPE_TASK    (0 << TCB_FLAG_TTYPE_SHIFT) /* Normal user task */
+#  define TCB_FLAG_TTYPE_PTHREAD (1 << TCB_FLAG_TTYPE_SHIFT) /* User pthread */
+#  define TCB_FLAG_TTYPE_KERNEL  (2 << TCB_FLAG_TTYPE_SHIFT) /* Kernel thread */
+#define TCB_FLAG_NONCANCELABLE   (1 << 2) /* Bit 2: Pthread is non-cancelable */
+#define TCB_FLAG_CANCEL_PENDING  (1 << 3) /* Bit 3: Pthread cancel is pending */
+#define TCB_FLAG_ROUND_ROBIN     (1 << 4) /* Bit 4: Round robin sched enabled */
 
 /********************************************************************************
  * Global Type Definitions
diff --git a/sched/exit.c b/sched/exit.c
index 93e24a29d0..6793eae77a 100644
--- a/sched/exit.c
+++ b/sched/exit.c
@@ -91,7 +91,9 @@
 
 void exit(int status)
 {
+#if CONFIG_NFILE_STREAMS > 0 || defined(CONFIG_SCHED_WAITPID) || defined(CONFIG_SCHED_ATEXIT)
   _TCB *tcb = (_TCB*)g_readytorun.head;
+#endif
 
   /* Only the lower 8 bits of the exit status are used */
 
diff --git a/sched/pthread_create.c b/sched/pthread_create.c
index d1f838a9e7..e247ce372f 100644
--- a/sched/pthread_create.c
+++ b/sched/pthread_create.c
@@ -354,7 +354,7 @@ int pthread_create(FAR pthread_t *thread, FAR pthread_attr_t *attr,
 
   /* Mark this task as a pthread */
 
-  ptcb->flags |= TCB_FLAG_PTHREAD;
+  ptcb->flags |= TCB_FLAG_TTYPE_PTHREAD;
 
   /* Configure the TCB for a pthread receiving on parameter
    * passed by value
diff --git a/sched/sched_releasetcb.c b/sched/sched_releasetcb.c
index 2be77b77be..5fd5090069 100644
--- a/sched/sched_releasetcb.c
+++ b/sched/sched_releasetcb.c
@@ -151,11 +151,11 @@ int sched_releasetcb(FAR _TCB *tcb)
         }
 #endif
 
-      /* Release command line arguments that were allocated
-       * for task start/re-start.
+      /* Release command line arguments that were allocated for task
+       * start/re-start.
        */
 
-      if ((tcb->flags & TCB_FLAG_PTHREAD) == 0)
+      if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_TASK)
         {
           for (i = 1; i < CONFIG_MAX_TASK_ARGS+1 && tcb->argv[i]; i++)
             {
-- 
GitLab