OSDN Git Service

Provide CLOCK_REALTIME on Tru64 UNIX
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-oscons-tmplt.c
index 625f1e0..340abe9 100644 (file)
@@ -7,25 +7,23 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2000-2009, Free Software Foundation, Inc.         --
+--          Copyright (C) 2000-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
--- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
--- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
--- for  more details.  You should have  received  a copy of the GNU General --
--- Public License  distributed with GNAT;  see file COPYING.  If not, write --
--- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
--- Boston, MA 02110-1301, USA.                                              --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
 --                                                                          --
--- As a special exception,  if other files  instantiate  generics from this --
--- unit, or you link  this unit with other files  to produce an executable, --
--- this  unit  does not  by itself cause  the resulting  executable  to  be --
--- covered  by the  GNU  General  Public  License.  This exception does not --
--- however invalidate  any other reasons why  the executable file  might be --
--- covered by the  GNU Public License.                                      --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
+--                                                                          --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
 --                                                                          --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
@@ -60,7 +58,7 @@ pragma Style_Checks ("M32766");
  **  s-oscons-tmpl.s.
  **
  **  The default one assumes that the template can be compiled by the newly-
- **  build cross compiler. It uses markup produced in the (pseudo-)assembly
+ **  built cross compiler. It uses markup produced in the (pseudo-)assembly
  **  listing:
  **
  **     xgcc -DTARGET=\"$target\" -C -E s-oscons-tmplt.c > s-oscons-tmplt.i
@@ -78,24 +76,91 @@ pragma Style_Checks ("M32766");
  **  $ DEFINE/USER SYS$OUTPUT s-oscons-tmplt.s
  **  $ RUN s-oscons-tmplt
  **  $ RUN xoscons
- **
  **/
 
-#ifndef TARGET
-# error Please define TARGET
+/* Feature macro definitions */
+
+#if defined (__linux__) && !defined (_XOPEN_SOURCE)
+/** For Linux _XOPEN_SOURCE must be defined, otherwise IOV_MAX is not defined
+ **/
+#define _XOPEN_SOURCE 500
+
+#elif defined (__alpha__) && defined (__osf__)
+/** For Tru64 UNIX, _XOPEN_SOURCE must be defined, otherwise CLOCK_REALTIME
+ ** is not defined.
+ **/
+#define _XOPEN_SOURCE 500
+
+#elif defined (__mips) && defined (__sgi)
+/** For IRIX 6, _XOPEN5 must be defined and _XOPEN_IOV_MAX must be used as
+ ** IOV_MAX, otherwise IOV_MAX is not defined.  IRIX 5 has neither.
+ **/
+#ifdef _XOPEN_IOV_MAX
+#define _XOPEN5
+#define IOV_MAX _XOPEN_IOV_MAX
 #endif
+#endif
+
+/* Include gsocket.h before any system header so it can redefine FD_SETSIZE */
+
+#include "gsocket.h"
 
 #include <stdlib.h>
 #include <string.h>
 #include <limits.h>
 #include <fcntl.h>
+#include <time.h>
+
+#if defined (__alpha__) && defined (__osf__)
+/** Tru64 is unable to do vector IO operations with default value of IOV_MAX,
+ ** so its value is redefined to a small one which is known to work properly.
+ **/
+#undef IOV_MAX
+#define IOV_MAX 16
+#endif
+
+#if defined (__VMS)
+/** VMS is unable to do vector IO operations with default value of IOV_MAX,
+ ** so its value is redefined to a small one which is known to work properly.
+ **/
+#undef IOV_MAX
+#define IOV_MAX 16
+#endif
 
 #if ! (defined (__vxworks) || defined (__VMS) || defined (__MINGW32__) || \
        defined (__nucleus__))
 # define HAVE_TERMIOS
 #endif
 
-#include "gsocket.h"
+#if defined (__vxworks)
+
+/**
+ ** For VxWorks, always include vxWorks.h (gsocket.h provides it only for
+ ** the case of runtime libraries that support sockets).
+ **/
+
+# include <vxWorks.h>
+#endif
+
+#ifdef DUMMY
+
+# if defined (TARGET)
+#   error TARGET may not be defined when generating the dummy version
+# else
+#   define TARGET "batch runtime compilation (dummy values)"
+# endif
+
+# if !(defined (HAVE_SOCKETS) && defined (HAVE_TERMIOS))
+#   error Features missing on platform
+# endif
+
+# define NATIVE
+
+#endif /* DUMMY */
+
+#ifndef TARGET
+# error Please define TARGET
+#endif
 
 #ifndef HAVE_SOCKETS
 # include <errno.h>
@@ -109,14 +174,30 @@ pragma Style_Checks ("M32766");
 # include <_types.h>
 #endif
 
+#ifdef __linux__
+# include <pthread.h>
+# include <signal.h>
+#endif
+
 #ifdef NATIVE
 #include <stdio.h>
+
+#ifdef DUMMY
+int counter = 0;
+# define _VAL(x) counter++
+#else
+# define _VAL(x) x
+#endif
+
 #define CND(name,comment) \
-  printf ("\n->CND:$%d:" #name ":$%d:" comment, __LINE__, ((int) name));
+  printf ("\n->CND:$%d:" #name ":$%d:" comment, __LINE__, ((int) _VAL (name)));
 
 #define CNS(name,comment) \
   printf ("\n->CNS:$%d:" #name ":" name ":" comment, __LINE__);
 
+#define C(sname,type,value,comment)\
+  printf ("\n->C:$%d:" sname ":" #type ":" value ":" comment, __LINE__);
+
 #define TXT(text) \
   printf ("\n->TXT:$%d:" text, __LINE__);
 
@@ -130,14 +211,24 @@ pragma Style_Checks ("M32766");
 #define CNS(name, comment) \
   asm volatile("\n->CNS:%0:" #name ":" name ":" comment \
   : : "i" (__LINE__));
-/* General expression constant */
+/* General expression named number */
+
+#define C(sname, type, value, comment) \
+  asm volatile("\n->C:%0:" sname ":" #type ":" value ":" comment \
+  : : "i" (__LINE__));
+/* Typed constant */
 
 #define TXT(text) \
   asm volatile("\n->TXT:%0:" text \
   : : "i" (__LINE__));
 /* Freeform text */
 
-#endif
+#endif /* NATIVE */
+
+#define CST(name,comment) C(#name,String,name,comment)
+
+#define STR(x) STR1(x)
+#define STR1(x) #x
 
 #ifdef __MINGW32__
 unsigned int _CRT_fmode = _O_BINARY;
@@ -182,6 +273,24 @@ package System.OS_Constants is
 
 /*
 
+   -----------------------------
+   -- Platform identification --
+   -----------------------------
+
+   type OS_Type is (Windows, VMS, Other_OS);
+*/
+#if defined (__MINGW32__)
+# define TARGET_OS "Windows"
+#elif defined (__VMS)
+# define TARGET_OS "VMS"
+#else
+# define TARGET_OS "Other_OS"
+#endif
+C("Target_OS", OS_Type, TARGET_OS, "")
+#define Target_Name TARGET
+CST(Target_Name, "")
+/*
+
    -------------------
    -- System limits --
    -------------------
@@ -453,6 +562,11 @@ CND(ENOTSOCK, "Operation on non socket")
 #endif
 CND(EOPNOTSUPP, "Operation not supported")
 
+#ifndef EPIPE
+# define EPIPE -1
+#endif
+CND(EPIPE, "Broken pipe")
+
 #ifndef EPFNOSUPPORT
 # define EPFNOSUPPORT -1
 #endif
@@ -468,6 +582,11 @@ CND(EPROTONOSUPPORT, "Unknown protocol")
 #endif
 CND(EPROTOTYPE, "Unknown protocol type")
 
+#ifndef ERANGE
+# define ERANGE -1
+#endif
+CND(ERANGE, "Result too large")
+
 #ifndef ESHUTDOWN
 # define ESHUTDOWN -1
 #endif
@@ -817,6 +936,21 @@ CND(VEOL2, "Alternative EOL")
 
 #endif /* HAVE_TERMIOS */
 
+/*
+
+   -----------------------------
+   -- Pseudo terminal library --
+   -----------------------------
+
+*/
+
+#if defined (__FreeBSD__) || defined (linux)
+# define PTY_Library "-lutil"
+#else
+# define PTY_Library ""
+#endif
+CST(PTY_Library, "for g-exptty")
+
 /**
  **  Sockets constants
  **/
@@ -845,7 +979,7 @@ CND(AF_INET, "IPv4 address family")
 #endif
 
 /**
- ** Tru64 UNIX V4.0F defines AF_INET6 without IPv6 support, specificially
+ ** Tru64 UNIX V4.0F defines AF_INET6 without IPv6 support, specifically
  ** without struct sockaddr_in6.  We use _SS_MAXSIZE (used for the definition
  ** of struct sockaddr_storage on Tru64 UNIX V5.1) to detect this.
  **/
@@ -981,8 +1115,14 @@ CND(MSG_PEEK, "Peek at incoming data")
 CND(MSG_EOR, "Send end of record")
 
 #ifndef MSG_WAITALL
+#ifdef __MINWGW32__
+/* The value of MSG_WAITALL is 8.  Nevertheless winsock.h doesn't
+   define it, but it is still usable as we link to winsock2 API.  */
+# define MSG_WAITALL (1 << 3)
+#else
 # define MSG_WAITALL -1
 #endif
+#endif
 CND(MSG_WAITALL, "Wait for full reception")
 
 #ifndef MSG_NOSIGNAL
@@ -1110,10 +1250,30 @@ CND(IP_PKTINFO, "Get datagram info")
 CND(SIZEOF_tv_sec, "tv_sec")
 #define SIZEOF_tv_usec (sizeof tv.tv_usec)
 CND(SIZEOF_tv_usec, "tv_usec")
+/*
+
+   --  Maximum allowed value for tv_sec
+*/
+
+/**
+ ** On Solaris and IRIX, field tv_sec in struct timeval has an undocumented
+ ** hard-wired limit of 100 million.
+ ** On IA64 HP-UX the limit is 2**31 - 1.
+ **/
+#if defined (sun) || (defined (__mips) && defined (__sgi))
+# define MAX_tv_sec "100_000_000"
+
+#elif defined (__hpux__)
+# define MAX_tv_sec "16#7fffffff#"
+
+#else
+# define MAX_tv_sec "2 ** (SIZEOF_tv_sec * 8 - 1) - 1"
+#endif
+CNS(MAX_tv_sec, "")
 }
 /*
 
-   --  Sizes of protocol specific address types (for sockaddr.sa_len)
+   --  Sizes of various data types
 */
 
 #define SIZEOF_sockaddr_in (sizeof (struct sockaddr_in))
@@ -1125,27 +1285,32 @@ CND(SIZEOF_sockaddr_in, "struct sockaddr_in")
 #endif
 CND(SIZEOF_sockaddr_in6, "struct sockaddr_in6")
 
-/*
-
-   --  Size of file descriptor sets
-*/
 #define SIZEOF_fd_set (sizeof (fd_set))
 CND(SIZEOF_fd_set, "fd_set");
+CND(FD_SETSIZE, "Max fd value");
+
+#define SIZEOF_struct_hostent (sizeof (struct hostent))
+CND(SIZEOF_struct_hostent, "struct hostent");
+
+#define SIZEOF_struct_servent (sizeof (struct servent))
+CND(SIZEOF_struct_servent, "struct servent");
+
+#if defined (__linux__)
+#define SIZEOF_sigset (sizeof (sigset_t))
+CND(SIZEOF_sigset, "sigset");
+#endif
 /*
 
-   --  Fields of struct hostent
+   --  Fields of struct msghdr
 */
 
-#ifdef __MINGW32__
-# define h_addrtype_t "short"
-# define h_length_t   "short"
+#if defined (__sun__) || defined (__hpux__)
+# define msg_iovlen_t "int"
 #else
-# define h_addrtype_t "int"
-# define h_length_t   "int"
+# define msg_iovlen_t "size_t"
 #endif
 
-TXT("   subtype H_Addrtype_T is Interfaces.C." h_addrtype_t ";")
-TXT("   subtype H_Length_T   is Interfaces.C." h_length_t ";")
+TXT("   subtype Msg_Iovlen_T is Interfaces.C." msg_iovlen_t ";")
 
 /*
 
@@ -1156,24 +1321,139 @@ TXT("   subtype H_Length_T   is Interfaces.C." h_length_t ";")
 */
 
 CND(Need_Netdb_Buffer, "Need buffer for Netdb ops")
+CND(Need_Netdb_Lock,   "Need lock for Netdb ops")
 CND(Has_Sockaddr_Len,  "Sockaddr has sa_len field")
 
 /**
  ** Do not change the format of the line below without also updating the
  ** MaRTE Makefile.
  **/
-TXT("   Thread_Blocking_IO  : constant Boolean := True;")
+C("Thread_Blocking_IO", Boolean, "True", "")
 /*
    --  Set False for contexts where socket i/o are process blocking
+
 */
 
+#ifdef HAVE_INET_PTON
+# define Inet_Pton_Linkname "inet_pton"
+#else
+# define Inet_Pton_Linkname "__gnat_inet_pton"
+#endif
+CST(Inet_Pton_Linkname, "")
+
 #endif /* HAVE_SOCKETS */
 
+/*
+
+   ---------------------
+   -- Threads support --
+   ---------------------
+
+   --  Clock identifier definitions
+
+*/
+
+/* Note: On HP-UX, CLOCK_REALTIME is an enum, not a macro. */
+
+#if defined(CLOCK_REALTIME) || defined (__hpux__)
+# define HAVE_CLOCK_REALTIME
+#endif
+
+#ifdef HAVE_CLOCK_REALTIME
+CND(CLOCK_REALTIME, "System realtime clock")
+#endif
+
+#ifdef CLOCK_MONOTONIC
+CND(CLOCK_MONOTONIC, "System monotonic clock")
+#endif
+
+#ifdef CLOCK_FASTEST
+CND(CLOCK_FASTEST, "Fastest clock")
+#endif
+
+#if defined (__sgi)
+CND(CLOCK_SGI_FAST,  "SGI fast clock")
+CND(CLOCK_SGI_CYCLE, "SGI CPU clock")
+#endif
+
+#ifndef CLOCK_THREAD_CPUTIME_ID
+# define CLOCK_THREAD_CPUTIME_ID -1
+#endif
+CND(CLOCK_THREAD_CPUTIME_ID, "Thread CPU clock")
+
+#if defined(__APPLE__)
+/* There's no clock_gettime or clock_id's on Darwin, generate a dummy value */
+# define CLOCK_RT_Ada "-1"
+
+#elif defined(FreeBSD) || defined(_AIX)
+/** On these platforms use system provided monotonic clock instead of
+ ** the default CLOCK_REALTIME. We then need to set up cond var attributes
+ ** appropriately (see thread.c).
+ **/
+# define CLOCK_RT_Ada "CLOCK_MONOTONIC"
+# define NEED_PTHREAD_CONDATTR_SETCLOCK
+
+#elif defined(HAVE_CLOCK_REALTIME)
+/* By default use CLOCK_REALTIME */
+# define CLOCK_RT_Ada "CLOCK_REALTIME"
+#endif
+
+#ifdef CLOCK_RT_Ada
+CNS(CLOCK_RT_Ada, "")
+#endif
+
+#if defined (__APPLE__) || defined (__linux__) || defined (DUMMY)
+/*
+
+   --  Sizes of pthread data types
+
+*/
+
+#if defined (__APPLE__) || defined (DUMMY)
+/*
+   --  (on Darwin, these are just placeholders)
+
+*/
+#define PTHREAD_SIZE            __PTHREAD_SIZE__
+#define PTHREAD_ATTR_SIZE       __PTHREAD_ATTR_SIZE__
+#define PTHREAD_MUTEXATTR_SIZE  __PTHREAD_MUTEXATTR_SIZE__
+#define PTHREAD_MUTEX_SIZE      __PTHREAD_MUTEX_SIZE__
+#define PTHREAD_CONDATTR_SIZE   __PTHREAD_CONDATTR_SIZE__
+#define PTHREAD_COND_SIZE       __PTHREAD_COND_SIZE__
+#define PTHREAD_RWLOCKATTR_SIZE __PTHREAD_RWLOCKATTR_SIZE__
+#define PTHREAD_RWLOCK_SIZE     __PTHREAD_RWLOCK_SIZE__
+#define PTHREAD_ONCE_SIZE       __PTHREAD_ONCE_SIZE__
+#else
+#define PTHREAD_SIZE            (sizeof (pthread_t))
+#define PTHREAD_ATTR_SIZE       (sizeof (pthread_attr_t))
+#define PTHREAD_MUTEXATTR_SIZE  (sizeof (pthread_mutexattr_t))
+#define PTHREAD_MUTEX_SIZE      (sizeof (pthread_mutex_t))
+#define PTHREAD_CONDATTR_SIZE   (sizeof (pthread_condattr_t))
+#define PTHREAD_COND_SIZE       (sizeof (pthread_cond_t))
+#define PTHREAD_RWLOCKATTR_SIZE (sizeof (pthread_rwlockattr_t))
+#define PTHREAD_RWLOCK_SIZE     (sizeof (pthread_rwlock_t))
+#define PTHREAD_ONCE_SIZE       (sizeof (pthread_once_t))
+#endif
+
+CND(PTHREAD_SIZE,            "pthread_t")
+CND(PTHREAD_ATTR_SIZE,       "pthread_attr_t")
+CND(PTHREAD_MUTEXATTR_SIZE,  "pthread_mutexattr_t")
+CND(PTHREAD_MUTEX_SIZE,      "pthread_mutex_t")
+CND(PTHREAD_CONDATTR_SIZE,   "pthread_condattr_t")
+CND(PTHREAD_COND_SIZE,       "pthread_cond_t")
+CND(PTHREAD_RWLOCKATTR_SIZE, "pthread_rwlockattr_t")
+CND(PTHREAD_RWLOCK_SIZE,     "pthread_rwlock_t")
+CND(PTHREAD_ONCE_SIZE,       "pthread_once_t")
+
+#endif /* __APPLE__ || __linux__ */
+
 /**
  **  System-specific constants follow
+ **  Each section should be activated if compiling for the corresponding
+ **  platform *or* generating the dummy version for runtime test compilation.
  **/
 
-#ifdef __vxworks
+#if defined (__vxworks) || defined (DUMMY)
 
 /*
 
@@ -1188,9 +1468,9 @@ TXT("   Thread_Blocking_IO  : constant Boolean := True;")
 CND(OK,    "VxWorks generic success")
 CND(ERROR, "VxWorks generic error")
 
-#endif
+#endif /* __vxworks */
 
-#ifdef __MINGW32__
+#if defined (__MINGW32__) || defined (DUMMY)
 /*
 
    ------------------------------
@@ -1206,52 +1486,16 @@ CND(WSAVERNOTSUPPORTED, "Version not supported")
 CND(WSANOTINITIALISED,  "Winsock not initialized")
 CND(WSAEDISCON,         "Disconnected")
 
-#endif
+#endif /* __MINGW32__ */
+
+/**
+ ** End of constants definitions
+ **/
 
 #ifdef NATIVE
    putchar ('\n');
 #endif
 
-#ifdef __APPLE__
-/*
-
-   -------------------------------
-   -- Darwin-specific constants --
-   -------------------------------
-
-   --  These constants may be used only within the Darwin version of the GNAT
-   --  runtime library.
-*/
-
-#define PTHREAD_SIZE __PTHREAD_SIZE__
-CND(PTHREAD_SIZE, "Pad in pthread_t")
-
-#define PTHREAD_ATTR_SIZE __PTHREAD_ATTR_SIZE__
-CND(PTHREAD_ATTR_SIZE, "Pad in pthread_attr_t")
-
-#define PTHREAD_MUTEXATTR_SIZE __PTHREAD_MUTEXATTR_SIZE__
-CND(PTHREAD_MUTEXATTR_SIZE, "Pad in pthread_mutexattr_t")
-
-#define PTHREAD_MUTEX_SIZE __PTHREAD_MUTEX_SIZE__
-CND(PTHREAD_MUTEX_SIZE, "Pad in pthread_mutex_t")
-
-#define PTHREAD_CONDATTR_SIZE __PTHREAD_CONDATTR_SIZE__
-CND(PTHREAD_CONDATTR_SIZE, "Pad in pthread_condattr_t")
-
-#define PTHREAD_COND_SIZE __PTHREAD_COND_SIZE__
-CND(PTHREAD_COND_SIZE, "Pad in pthread_cond_t")
-
-#define PTHREAD_RWLOCKATTR_SIZE __PTHREAD_RWLOCKATTR_SIZE__
-CND(PTHREAD_RWLOCKATTR_SIZE, "Pad in pthread_rwlockattr_t")
-
-#define PTHREAD_RWLOCK_SIZE __PTHREAD_RWLOCK_SIZE__
-CND(PTHREAD_RWLOCK_SIZE, "Pad in pthread_rwlock_t")
-
-#define PTHREAD_ONCE_SIZE __PTHREAD_ONCE_SIZE__
-CND(PTHREAD_ONCE_SIZE, "Pad in pthread_once_t")
-
-#endif
-
 /*
 
 end System.OS_Constants;