From 8403a62cdfc5242be2b69c6762332766e12d77a0 Mon Sep 17 00:00:00 2001
From: patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>
Date: Sun, 30 Dec 2007 23:34:20 +0000
Subject: [PATCH] More SDCC compilation fixes

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@468 42af7a65-404d-4744-a932-0658087f49c3
---
 TODO                                         | 16 ++++++---
 arch/z80/src/z80/Make.defs                   |  6 +++-
 configs/z80sim/README.txt                    | 14 ++++++++
 configs/z80sim/defconfig                     | 18 +++++-----
 configs/z80sim/sdcc-2.6.0-asz80-symlen.patch | 11 ++++++
 examples/ostest/posixtimer.c                 | 34 ++++++++++++++++---
 examples/ostest/timedmqueue.c                | 10 ++++--
 examples/ostest/timedwait.c                  | 35 +++++++++++++++++---
 include/stdio.h                              |  1 +
 include/sys/types.h                          | 35 +++++++++++---------
 sched/pthread_create.c                       |  2 +-
 sched/timer_create.c                         |  8 ++---
 sched/timer_settime.c                        |  2 +-
 13 files changed, 147 insertions(+), 45 deletions(-)
 create mode 100644 configs/z80sim/sdcc-2.6.0-asz80-symlen.patch

diff --git a/TODO b/TODO
index 33db2ed411..57c3de98b6 100644
--- a/TODO
+++ b/TODO
@@ -293,10 +293,18 @@ o pjrc-8052 / MCS51 (arch/pjrc-8051/)
   Priority:    Low
 
   Description: During build, there are several integer overflows reported:
-               gmtime_r.c aroud lines 184 and 185
-               clock_initialize.c at line 107
-               pthread_create.c at 330
-               sighand.c at 225 and 244
+               sched/gmtime_r.c aroud lines 184 and 185
+               sched/clock_initialize.c at line 107
+               sched/pthread_create.c at 330
+               examples/ostest/barrier.c around lines 53 and 74
+               examples/ostest/sighand.c at 225 and 244
   Status:      Open
   Priority:    Medium
 
+o z80 (arch/z80)
+ ^^^^^^^^^^^^^^^
+
+  Has the same problems with interger overflow during compilation as described
+  for pjrc-8051
+
+
diff --git a/arch/z80/src/z80/Make.defs b/arch/z80/src/z80/Make.defs
index 05dc8cd56f..d4e38b11cc 100644
--- a/arch/z80/src/z80/Make.defs
+++ b/arch/z80/src/z80/Make.defs
@@ -41,7 +41,11 @@ CMN_CSRCS	= up_initialize.c up_allocateheap.c up_initialstate.c \
 		  up_blocktask.c  up_unblocktask.c up_exit.c up_releasepending.c \
 		  up_reprioritizertr.c up_copystate.c up_irq.c up_idle.c \
 		  up_assert.c up_mdelay.c up_udelay.c \
-		  up_registerdump.c up_usestack.c \
+		  up_registerdump.c up_usestack.c
+
+ifneq ($(CONFIG_DISABLE_SIGNALS),y)
+CMD_CSRCS	+= up_schedulesigaction.c up_sigdeliver.c
+endif
 
 CHIP_ASRCS	= 
 CHIP_CSRCS	= 
diff --git a/configs/z80sim/README.txt b/configs/z80sim/README.txt
index 50be916e14..ff9754c04e 100644
--- a/configs/z80sim/README.txt
+++ b/configs/z80sim/README.txt
@@ -17,4 +17,18 @@ compatible with this build.  First start with the usual steps
   unpack
   cd sdcc
   ./configure
+
+But before making, we need to apply a patch to the SDCC 2.6.0 source
+so that the z80 assembler can handle long symbol names
+
+  Apply sdcc-2.6.0-asz80-symlen.patch
+  cd sdcc/device/lib
+
+Then make the SDCC binaries
+
+  cd sdcc
   make
+
+and install SDCC:
+
+  sudo make install
diff --git a/configs/z80sim/defconfig b/configs/z80sim/defconfig
index a993a6aeb1..6141c34b13 100644
--- a/configs/z80sim/defconfig
+++ b/configs/z80sim/defconfig
@@ -112,13 +112,13 @@ CONFIG_DEV_CONSOLE=n
 # o pthread_condtimedwait() depends on signals to wake
 #   up waiting tasks.
 #
-CONFIG_DISABLE_CLOCK=y
-CONFIG_DISABLE_POSIX_TIMERS=y
-CONFIG_DISABLE_PTHREAD=y
-CONFIG_DISABLE_SIGNALS=y
-CONFIG_DISABLE_MQUEUE=y
-CONFIG_DISABLE_MOUNTPOINT=y
-CONFIG_DISABLE_ENVIRON=y
+CONFIG_DISABLE_CLOCK=n
+CONFIG_DISABLE_POSIX_TIMERS=n
+CONFIG_DISABLE_PTHREAD=n
+CONFIG_DISABLE_SIGNALS=n
+CONFIG_DISABLE_MQUEUE=n
+CONFIG_DISABLE_MOUNTPOINT=n
+CONFIG_DISABLE_ENVIRON=n
 
 #
 # Misc libc settings
@@ -283,7 +283,7 @@ CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
 CONFIG_BOOT_FROM_FLASH=n
 CONFIG_CUSTOM_STACK=n
 CONFIG_PROC_STACK_SIZE=1024
-CONFIG_PTHREAD_STACK_MIN=
-CONFIG_PTHREAD_STACK_DEFAULT=
+CONFIG_PTHREAD_STACK_MIN=256
+CONFIG_PTHREAD_STACK_DEFAULT=1024
 CONFIG_HEAP_SIZE=
 CONFIG_HEAP_BASE=
diff --git a/configs/z80sim/sdcc-2.6.0-asz80-symlen.patch b/configs/z80sim/sdcc-2.6.0-asz80-symlen.patch
new file mode 100644
index 0000000000..d91c18d988
--- /dev/null
+++ b/configs/z80sim/sdcc-2.6.0-asz80-symlen.patch
@@ -0,0 +1,11 @@
+--- sdcc/as/z80/asm.h	2007-12-30 16:49:53.000000000 -0600
++++ sdcc.orig/as/z80/asm.h	2007-12-30 16:49:14.000000000 -0600
+@@ -65,7 +65,7 @@
+ #define	RTTERM	')'		/* Right expression delimeter */
+ 
+ #ifdef SDK
+-#define	NCPS	80		/* characters per symbol */
++#define	NCPS	32		/* characters per symbol */
+ #else /* SDK */
+ #define NCPS	8		/* Chars. per symbol */
+ #endif /* SDK */
diff --git a/examples/ostest/posixtimer.c b/examples/ostest/posixtimer.c
index 1b466c99fb..87498baa26 100644
--- a/examples/ostest/posixtimer.c
+++ b/examples/ostest/posixtimer.c
@@ -1,7 +1,7 @@
 /***********************************************************************
  * posixtimer.c
  *
- *   Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -14,7 +14,7 @@
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
- * 3. Neither the name Gregory Nutt nor the names of its contributors may be
+ * 3. Neither the name NuttX nor the names of its contributors may be
  *    used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
@@ -33,6 +33,10 @@
  *
  ***********************************************************************/
 
+/**************************************************************************
+ * Included Files
+ **************************************************************************/
+
 #include <sys/types.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -42,6 +46,10 @@
 #include <errno.h>
 #include "ostest.h"
 
+/**************************************************************************
+ * Private Definitions
+ **************************************************************************/
+
 #ifndef NULL
 # define NULL (void*)0
 #endif
@@ -49,9 +57,23 @@
 #define MY_TIMER_SIGNAL 17
 #define SIGVALUE_INT  42
 
+#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0
+#  define FFLUSH() fflush(stdout)
+#else
+#  define FFLUSH()
+#endif
+
+/**************************************************************************
+ * Private Data
+ **************************************************************************/
+
 static sem_t sem;
 static int g_nsigreceived = 0;
 
+/**************************************************************************
+ * Private Functions
+ **************************************************************************/
+
 static void timer_expiration(int signo, siginfo_t *info, void *ucontext)
 {
   sigset_t oldset;
@@ -119,6 +141,10 @@ static void timer_expiration(int signo, siginfo_t *info, void *ucontext)
 
 }
 
+/**************************************************************************
+ * Public Functions
+ **************************************************************************/
+
 void timer_test(void)
 {
   sigset_t           sigset;
@@ -200,7 +226,7 @@ void timer_test(void)
   for (i = 0; i < 5; i++)
     {
       printf("timer_test: Waiting on semaphore\n" );
-      fflush(stdout);
+      FFLUSH();
       status = sem_wait(&sem);
       if (status != 0)
         {
@@ -239,5 +265,5 @@ errorout:
   status = sigaction(MY_TIMER_SIGNAL, &act, &oact);
 
   printf("timer_test: done\n" );
-  fflush(stdout);
+  FFLUSH();
 }
diff --git a/examples/ostest/timedmqueue.c b/examples/ostest/timedmqueue.c
index 186296a06a..2ef0dedeae 100644
--- a/examples/ostest/timedmqueue.c
+++ b/examples/ostest/timedmqueue.c
@@ -66,6 +66,12 @@
 #define TEST_SEND_NMSGS     (10)
 #define TEST_RECEIVE_NMSGS  (10)
 
+#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0
+#  define FFLUSH() fflush(stdout)
+#else
+#  define FFLUSH()
+#endif
+
 /**************************************************************************
  * Private Types
  **************************************************************************/
@@ -180,7 +186,7 @@ static void *sender_thread(void *arg)
     }
 
   printf("sender_thread: returning nerrors=%d\n", nerrors);
-  fflush(stdout);
+  FFLUSH();
   return (pthread_addr_t)nerrors;
 }
 
@@ -305,7 +311,7 @@ static void *receiver_thread(void *arg)
     }
 
   printf("receiver_thread: returning nerrors=%d\n", nerrors);
-  fflush(stdout);
+  FFLUSH();
   pthread_exit((pthread_addr_t)nerrors);
   return (pthread_addr_t)nerrors;
 }
diff --git a/examples/ostest/timedwait.c b/examples/ostest/timedwait.c
index 0bc47c6937..51622bad81 100644
--- a/examples/ostest/timedwait.c
+++ b/examples/ostest/timedwait.c
@@ -1,7 +1,7 @@
 /***********************************************************************
- * timedwait.c
+ * examples/ostest/timedwait.c
  *
- *   Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -14,7 +14,7 @@
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
- * 3. Neither the name Gregory Nutt nor the names of its contributors may be
+ * 3. Neither the name NuttX nor the names of its contributors may be
  *    used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
@@ -33,16 +33,39 @@
  *
  ***********************************************************************/
 
+/**************************************************************************
+ * Included Files
+ **************************************************************************/
+
 #include <stdio.h>
 #include <time.h>
 #include <pthread.h>
 #include <unistd.h>
 #include <errno.h>
+
 #include "ostest.h"
 
+/**************************************************************************
+ * Private Definitions
+ **************************************************************************/
+
+#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0
+#  define FFLUSH() fflush(stdout)
+#else
+#  define FFLUSH()
+#endif
+
+/**************************************************************************
+ * Private Data
+ **************************************************************************/
+
 static pthread_mutex_t mutex;
 static pthread_cond_t  cond;
 
+/**************************************************************************
+ * Private Functions
+ **************************************************************************/
+
 static void *thread_waiter(void *parameter)
 {
   struct timespec time;
@@ -99,6 +122,10 @@ static void *thread_waiter(void *parameter)
   return NULL;
 }
 
+/**************************************************************************
+ * Public Definitions
+ **************************************************************************/
+
 void timedwait_test(void)
 {
   pthread_t waiter;
@@ -161,7 +188,7 @@ void timedwait_test(void)
     }
 
   printf("timedwait_test: Joining\n");
-  fflush(stdout);
+  FFLUSH();
   status = pthread_join(waiter, &result);
   if (status != 0)
     {
diff --git a/include/stdio.h b/include/stdio.h
index eaeb879d39..cfb722c6d7 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -41,6 +41,7 @@
  ************************************************************/
 
 #include <nuttx/config.h>
+
 #include <sys/types.h>
 #include <stdarg.h>
 #include <sched.h>
diff --git a/include/sys/types.h b/include/sys/types.h
index 0460c5e5c2..2fd53e41db 100644
--- a/include/sys/types.h
+++ b/include/sys/types.h
@@ -1,7 +1,7 @@
-/************************************************************
+/****************************************************************************
  * sys/types.h
  *
- *   Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -31,39 +31,44 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- ************************************************************/
+ ****************************************************************************/
 
 #ifndef __SYS_TYPES_H
 #define __SYS_TYPES_H
 
-/************************************************************
+/****************************************************************************
  * Included Files
- ************************************************************/
+ ****************************************************************************/
 
 #include <nuttx/config.h>
 #include <arch/types.h>
 #include <nuttx/compiler.h>
 
-/************************************************************
+/****************************************************************************
  * Definitions
- ************************************************************/
+ ****************************************************************************/
 
 /* Values for type boolean */
 
 #define TRUE 1
 #define FALSE 0
 
-/* NULL is usually defined in stddef.h */
+/* NULL is usually defined in stddef.h (which includes this file) */
 
 #ifndef NULL
-#define NULL (void*)0L
+    /* SDCC is sensitive to NULL pointer type conversions */
+#  ifdef SDCC
+#    define NULL (0)
+#  else
+#    define NULL ((void*)0)
+#  endif
 #endif
 
 /* POSIX-like OS return values: */
 
 #if !defined(__cplusplus)
-#undef  ERROR
-#define ERROR -1
+#  undef  ERROR
+#  define ERROR -1
 #endif
 
 #undef  OK
@@ -86,9 +91,9 @@
 #define SCHED_PRIORITY_MIN       1
 #define SCHED_PRIORITY_IDLE      0
 
-/************************************************************
+/****************************************************************************
  * Type Declarations
- ************************************************************/
+ ****************************************************************************/
 
 #ifndef __ASSEMBLY__
 #ifndef CONFIG_HAVE_DOUBLE
@@ -132,8 +137,8 @@ typedef int (*main_t)(int argc, char *argv[]);
 
 #endif
 
-/************************************************************
+/****************************************************************************
  * Global Function Prototypes
- ************************************************************/
+ ****************************************************************************/
 
 #endif /* __SYS_TYPES_H */
diff --git a/sched/pthread_create.c b/sched/pthread_create.c
index 24768664bf..bd86643f9d 100644
--- a/sched/pthread_create.c
+++ b/sched/pthread_create.c
@@ -357,7 +357,7 @@ int pthread_create(pthread_t *thread, pthread_attr_t *attr,
    * passed by value
    */
 
-  (void)pthread_argsetup(ptcb, arg);
+  pthread_argsetup(ptcb, arg);
 
   /* Attach the join info to the TCB. */
 
diff --git a/sched/timer_create.c b/sched/timer_create.c
index 40a660f500..645007c9fc 100644
--- a/sched/timer_create.c
+++ b/sched/timer_create.c
@@ -1,7 +1,7 @@
 /********************************************************************************
- * timer_create.c
+ * sched/timer_create.c
  *
- *   Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <spudmonkey@racsa.co.cr>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -14,7 +14,7 @@
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
- * 3. Neither the name Gregory Nutt nor the names of its contributors may be
+ * 3. Neither the name NuttX nor the names of its contributors may be
  *    used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
@@ -204,7 +204,7 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp, FAR timer_t *timer
 #ifdef CONFIG_CAN_PASS_STRUCTS
       ret->pt_value           = evp->sigev_value;
 #else
-      ret->pt_value.sival_ptr = evp->sigev_value.sigval_ptr;
+      ret->pt_value.sival_ptr = evp->sigev_value.sival_ptr;
 #endif
     }
   else
diff --git a/sched/timer_settime.c b/sched/timer_settime.c
index 29796a5933..a9a7fd7c44 100644
--- a/sched/timer_settime.c
+++ b/sched/timer_settime.c
@@ -104,7 +104,7 @@ static void inline timer_sigqueue(FAR struct posix_timer_s *timer)
 
        info.si_signo           = timer->pt_signo;
        info.si_code            = SI_TIMER;
-#ifndef CONFIG_CAN_PASS_STRUCTS
+#ifdef CONFIG_CAN_PASS_STRUCTS
        info.si_value           = timer->pt_value;
 #else
        info.si_value.sival_ptr = timer->pt_value.sival_ptr;
-- 
GitLab