OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc1/] [gcc/] [ada/] [initialize.c] - Diff between revs 281 and 338

Only display areas with differences | Details | Blame | View Log

Rev 281 Rev 338
/****************************************************************************
/****************************************************************************
 *                                                                          *
 *                                                                          *
 *                         GNAT COMPILER COMPONENTS                         *
 *                         GNAT COMPILER COMPONENTS                         *
 *                                                                          *
 *                                                                          *
 *                           I N I T I A L I Z E                            *
 *                           I N I T I A L I Z E                            *
 *                                                                          *
 *                                                                          *
 *                          C Implementation File                           *
 *                          C Implementation File                           *
 *                                                                          *
 *                                                                          *
 *          Copyright (C) 1992-2009, Free Software Foundation, Inc.         *
 *          Copyright (C) 1992-2009, Free Software Foundation, Inc.         *
 *                                                                          *
 *                                                                          *
 * GNAT is free software;  you can  redistribute it  and/or modify it under *
 * 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- *
 * terms of the  GNU General Public License as published  by the Free Soft- *
 * ware  Foundation;  either version 3,  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- *
 * sion.  GNAT is distributed in the hope that it will be useful, but WITH- *
 * OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY *
 * OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY *
 * or FITNESS FOR A PARTICULAR PURPOSE.                                     *
 * or FITNESS FOR A PARTICULAR PURPOSE.                                     *
 *                                                                          *
 *                                                                          *
 * As a special exception under Section 7 of GPL version 3, you are granted *
 * As a special exception under Section 7 of GPL version 3, you are granted *
 * additional permissions described in the GCC Runtime Library Exception,   *
 * additional permissions described in the GCC Runtime Library Exception,   *
 * version 3.1, as published by the Free Software Foundation.               *
 * version 3.1, as published by the Free Software Foundation.               *
 *                                                                          *
 *                                                                          *
 * You should have received a copy of the GNU General Public License and    *
 * 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;     *
 * a copy of the GCC Runtime Library Exception along with this program;     *
 * see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    *
 * see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    *
 * <http://www.gnu.org/licenses/>.                                          *
 * <http://www.gnu.org/licenses/>.                                          *
 *                                                                          *
 *                                                                          *
 * GNAT was originally developed  by the GNAT team at  New York University. *
 * GNAT was originally developed  by the GNAT team at  New York University. *
 * Extensive contributions were provided by Ada Core Technologies Inc.      *
 * Extensive contributions were provided by Ada Core Technologies Inc.      *
 *                                                                          *
 *                                                                          *
 ****************************************************************************/
 ****************************************************************************/
 
 
/*  This unit provides default implementation for __gnat_initialize ()
/*  This unit provides default implementation for __gnat_initialize ()
    which is called before the elaboration of the partition. It is provided
    which is called before the elaboration of the partition. It is provided
    in a separate file/object so that users can replace it easily.
    in a separate file/object so that users can replace it easily.
    The default implementation should be null on most targets. */
    The default implementation should be null on most targets. */
 
 
/* The following include is here to meet the published VxWorks requirement
/* The following include is here to meet the published VxWorks requirement
   that the __vxworks header appear before any other include. */
   that the __vxworks header appear before any other include. */
#ifdef __vxworks
#ifdef __vxworks
#include "vxWorks.h"
#include "vxWorks.h"
#endif
#endif
 
 
#ifdef IN_RTS
#ifdef IN_RTS
#include "tconfig.h"
#include "tconfig.h"
#include "tsystem.h"
#include "tsystem.h"
/* We don't have libiberty, so use malloc.  */
/* We don't have libiberty, so use malloc.  */
#define xmalloc(S) malloc (S)
#define xmalloc(S) malloc (S)
#define xrealloc(V,S) realloc (V,S)
#define xrealloc(V,S) realloc (V,S)
#else
#else
#include "config.h"
#include "config.h"
#include "system.h"
#include "system.h"
#endif
#endif
 
 
#include "raise.h"
#include "raise.h"
 
 
/******************************************/
/******************************************/
/* __gnat_initialize (NT-mingw32 Version) */
/* __gnat_initialize (NT-mingw32 Version) */
/******************************************/
/******************************************/
 
 
#if defined (__MINGW32__)
#if defined (__MINGW32__)
#include "mingw32.h"
#include "mingw32.h"
#include <windows.h>
#include <windows.h>
 
 
extern void __gnat_init_float (void);
extern void __gnat_init_float (void);
extern void __gnat_install_SEH_handler (void *);
extern void __gnat_install_SEH_handler (void *);
 
 
extern int gnat_argc;
extern int gnat_argc;
extern char **gnat_argv;
extern char **gnat_argv;
 
 
#ifdef GNAT_UNICODE_SUPPORT
#ifdef GNAT_UNICODE_SUPPORT
 
 
#define EXPAND_ARGV_RATE 128
#define EXPAND_ARGV_RATE 128
 
 
static void
static void
append_arg (int *index, LPWSTR dir, LPWSTR value,
append_arg (int *index, LPWSTR dir, LPWSTR value,
            char ***argv, int *last, int quoted)
            char ***argv, int *last, int quoted)
{
{
  int size;
  int size;
  LPWSTR fullvalue;
  LPWSTR fullvalue;
  int vallen = _tcslen (value);
  int vallen = _tcslen (value);
  int dirlen;
  int dirlen;
 
 
  if (dir == NULL)
  if (dir == NULL)
    {
    {
      /* no dir prefix */
      /* no dir prefix */
      dirlen = 0;
      dirlen = 0;
      fullvalue = xmalloc ((vallen + 1) * sizeof(TCHAR));
      fullvalue = xmalloc ((vallen + 1) * sizeof(TCHAR));
    }
    }
  else
  else
    {
    {
      /* Add dir first */
      /* Add dir first */
      dirlen = _tcslen (dir);
      dirlen = _tcslen (dir);
 
 
      fullvalue = xmalloc ((dirlen + vallen + 1) * sizeof(TCHAR));
      fullvalue = xmalloc ((dirlen + vallen + 1) * sizeof(TCHAR));
      _tcscpy (fullvalue, dir);
      _tcscpy (fullvalue, dir);
    }
    }
 
 
  /* Append value */
  /* Append value */
 
 
  if (quoted)
  if (quoted)
    {
    {
      _tcsncpy (fullvalue + dirlen, value + 1, vallen - 1);
      _tcsncpy (fullvalue + dirlen, value + 1, vallen - 1);
      fullvalue [dirlen + vallen - sizeof(TCHAR)] = _T('\0');
      fullvalue [dirlen + vallen - sizeof(TCHAR)] = _T('\0');
    }
    }
  else
  else
    _tcscpy (fullvalue + dirlen, value);
    _tcscpy (fullvalue + dirlen, value);
 
 
  if (*last <= *index)
  if (*last <= *index)
    {
    {
      *last += EXPAND_ARGV_RATE;
      *last += EXPAND_ARGV_RATE;
      *argv = (char **) xrealloc (*argv, (*last) * sizeof (char *));
      *argv = (char **) xrealloc (*argv, (*last) * sizeof (char *));
    }
    }
 
 
  size = WS2SC (NULL, fullvalue, 0);
  size = WS2SC (NULL, fullvalue, 0);
  (*argv)[*index] = (char *) xmalloc (size + sizeof(TCHAR));
  (*argv)[*index] = (char *) xmalloc (size + sizeof(TCHAR));
  WS2SC ((*argv)[*index], fullvalue, size);
  WS2SC ((*argv)[*index], fullvalue, size);
 
 
  free (fullvalue);
  free (fullvalue);
 
 
  (*index)++;
  (*index)++;
}
}
#endif
#endif
 
 
void
void
__gnat_initialize (void *eh ATTRIBUTE_UNUSED)
__gnat_initialize (void *eh ATTRIBUTE_UNUSED)
{
{
   /* Initialize floating-point coprocessor. This call is needed because
   /* Initialize floating-point coprocessor. This call is needed because
      the MS libraries default to 64-bit precision instead of 80-bit
      the MS libraries default to 64-bit precision instead of 80-bit
      precision, and we require the full precision for proper operation,
      precision, and we require the full precision for proper operation,
      given that we have set Max_Digits etc with this in mind */
      given that we have set Max_Digits etc with this in mind */
   __gnat_init_float ();
   __gnat_init_float ();
 
 
#ifdef GNAT_UNICODE_SUPPORT
#ifdef GNAT_UNICODE_SUPPORT
   /* Set current code page for filenames handling. */
   /* Set current code page for filenames handling. */
   {
   {
     char *codepage = getenv ("GNAT_CODE_PAGE");
     char *codepage = getenv ("GNAT_CODE_PAGE");
 
 
     /* Default code page is UTF-8.  */
     /* Default code page is UTF-8.  */
     CurrentCodePage = CP_UTF8;
     CurrentCodePage = CP_UTF8;
 
 
     if (codepage != NULL)
     if (codepage != NULL)
       {
       {
         if (strcmp (codepage, "CP_ACP") == 0)
         if (strcmp (codepage, "CP_ACP") == 0)
           CurrentCodePage = CP_ACP;
           CurrentCodePage = CP_ACP;
         else if (strcmp (codepage, "CP_UTF8") == 0)
         else if (strcmp (codepage, "CP_UTF8") == 0)
           CurrentCodePage = CP_UTF8;
           CurrentCodePage = CP_UTF8;
       }
       }
   }
   }
 
 
   /* Adjust gnat_argv to support Unicode characters. */
   /* Adjust gnat_argv to support Unicode characters. */
   {
   {
     LPWSTR *wargv;
     LPWSTR *wargv;
     int wargc;
     int wargc;
     int k;
     int k;
     int last;
     int last;
     int argc_expanded = 0;
     int argc_expanded = 0;
     TCHAR result [MAX_PATH];
     TCHAR result [MAX_PATH];
     int quoted;
     int quoted;
 
 
     wargv = CommandLineToArgvW (GetCommandLineW(), &wargc);
     wargv = CommandLineToArgvW (GetCommandLineW(), &wargc);
 
 
     if (wargv != NULL)
     if (wargv != NULL)
       {
       {
         /* Set gnat_argv with arguments encoded in UTF-8. */
         /* Set gnat_argv with arguments encoded in UTF-8. */
         last = wargc + 1;
         last = wargc + 1;
         gnat_argv = (char **) xmalloc ((last) * sizeof (char *));
         gnat_argv = (char **) xmalloc ((last) * sizeof (char *));
 
 
         /* argv[0] is the executable full path-name. */
         /* argv[0] is the executable full path-name. */
 
 
         SearchPath (NULL, wargv[0], _T(".exe"), MAX_PATH, result, NULL);
         SearchPath (NULL, wargv[0], _T(".exe"), MAX_PATH, result, NULL);
         append_arg (&argc_expanded, NULL, result, &gnat_argv, &last, 0);
         append_arg (&argc_expanded, NULL, result, &gnat_argv, &last, 0);
 
 
         for (k=1; k<wargc; k++)
         for (k=1; k<wargc; k++)
           {
           {
             quoted = (wargv[k][0] == _T('\''));
             quoted = (wargv[k][0] == _T('\''));
 
 
             /* Check for wildcard expansion if the argument is not quoted. */
             /* Check for wildcard expansion if the argument is not quoted. */
             if (!quoted
             if (!quoted
                 && (_tcsstr (wargv[k], _T("?")) != 0 ||
                 && (_tcsstr (wargv[k], _T("?")) != 0 ||
                     _tcsstr (wargv[k], _T("*")) != 0))
                     _tcsstr (wargv[k], _T("*")) != 0))
               {
               {
                 /* Wilcards are present, append all corresponding matches. */
                 /* Wilcards are present, append all corresponding matches. */
                 WIN32_FIND_DATA FileData;
                 WIN32_FIND_DATA FileData;
                 HANDLE hDir = FindFirstFile (wargv[k], &FileData);
                 HANDLE hDir = FindFirstFile (wargv[k], &FileData);
                 LPWSTR dir = NULL;
                 LPWSTR dir = NULL;
                 LPWSTR ldir = _tcsrchr (wargv[k], _T('\\'));
                 LPWSTR ldir = _tcsrchr (wargv[k], _T('\\'));
 
 
                 if (ldir == NULL)
                 if (ldir == NULL)
                   ldir = _tcsrchr (wargv[k], _T('/'));
                   ldir = _tcsrchr (wargv[k], _T('/'));
 
 
                 if (hDir == INVALID_HANDLE_VALUE)
                 if (hDir == INVALID_HANDLE_VALUE)
                   {
                   {
                     /* No match, append arg as-is. */
                     /* No match, append arg as-is. */
                     append_arg (&argc_expanded, NULL, wargv[k],
                     append_arg (&argc_expanded, NULL, wargv[k],
                                 &gnat_argv, &last, quoted);
                                 &gnat_argv, &last, quoted);
                   }
                   }
                 else
                 else
                   {
                   {
                     if (ldir != NULL)
                     if (ldir != NULL)
                       {
                       {
                         int n = ldir - wargv[k] + 1;
                         int n = ldir - wargv[k] + 1;
                         dir = xmalloc ((n + 1) * sizeof (TCHAR));
                         dir = xmalloc ((n + 1) * sizeof (TCHAR));
                         _tcsncpy (dir, wargv[k], n);
                         _tcsncpy (dir, wargv[k], n);
                         dir[n] = _T('\0');
                         dir[n] = _T('\0');
                       }
                       }
 
 
                     /* Append first match and all remaining ones.  */
                     /* Append first match and all remaining ones.  */
 
 
                     do {
                     do {
                       /* Do not add . and .. special entries */
                       /* Do not add . and .. special entries */
 
 
                       if (_tcscmp (FileData.cFileName, _T(".")) != 0
                       if (_tcscmp (FileData.cFileName, _T(".")) != 0
                           && _tcscmp (FileData.cFileName, _T("..")) != 0)
                           && _tcscmp (FileData.cFileName, _T("..")) != 0)
                         append_arg (&argc_expanded, dir, FileData.cFileName,
                         append_arg (&argc_expanded, dir, FileData.cFileName,
                                     &gnat_argv, &last, 0);
                                     &gnat_argv, &last, 0);
                     } while (FindNextFile (hDir, &FileData));
                     } while (FindNextFile (hDir, &FileData));
 
 
                     FindClose (hDir);
                     FindClose (hDir);
 
 
                     if (dir != NULL)
                     if (dir != NULL)
                       free (dir);
                       free (dir);
                   }
                   }
               }
               }
             else
             else
               {
               {
                 /*  No wildcard. Store parameter as-is. Remove quote if
                 /*  No wildcard. Store parameter as-is. Remove quote if
                     needed. */
                     needed. */
                 append_arg (&argc_expanded, NULL, wargv[k],
                 append_arg (&argc_expanded, NULL, wargv[k],
                             &gnat_argv, &last, quoted);
                             &gnat_argv, &last, quoted);
               }
               }
           }
           }
 
 
         LocalFree (wargv);
         LocalFree (wargv);
         gnat_argc = argc_expanded;
         gnat_argc = argc_expanded;
         gnat_argv = (char **) xrealloc
         gnat_argv = (char **) xrealloc
           (gnat_argv, argc_expanded * sizeof (char *));
           (gnat_argv, argc_expanded * sizeof (char *));
       }
       }
   }
   }
#endif
#endif
 
 
   /* Note that we do not activate this for the compiler itself to avoid a
   /* Note that we do not activate this for the compiler itself to avoid a
      bootstrap path problem.  Older version of gnatbind will generate a call
      bootstrap path problem.  Older version of gnatbind will generate a call
      to __gnat_initialize() without argument. Therefore we cannot use eh in
      to __gnat_initialize() without argument. Therefore we cannot use eh in
      this case.  It will be possible to remove the following #ifdef at some
      this case.  It will be possible to remove the following #ifdef at some
      point.  */
      point.  */
#ifdef IN_RTS
#ifdef IN_RTS
   /* Install the Structured Exception handler.  */
   /* Install the Structured Exception handler.  */
   if (eh)
   if (eh)
     __gnat_install_SEH_handler (eh);
     __gnat_install_SEH_handler (eh);
#endif
#endif
}
}
 
 
/******************************************/
/******************************************/
/* __gnat_initialize (init_float version) */
/* __gnat_initialize (init_float version) */
/******************************************/
/******************************************/
 
 
#elif defined (__Lynx__) || defined (__FreeBSD__) || defined(__NetBSD__) \
#elif defined (__Lynx__) || defined (__FreeBSD__) || defined(__NetBSD__) \
  || defined (__OpenBSD__)
  || defined (__OpenBSD__)
 
 
extern void __gnat_init_float (void);
extern void __gnat_init_float (void);
 
 
void
void
__gnat_initialize (void *eh ATTRIBUTE_UNUSED)
__gnat_initialize (void *eh ATTRIBUTE_UNUSED)
{
{
   __gnat_init_float ();
   __gnat_init_float ();
}
}
 
 
/***************************************/
/***************************************/
/* __gnat_initialize (VxWorks Version) */
/* __gnat_initialize (VxWorks Version) */
/***************************************/
/***************************************/
 
 
#elif defined(__vxworks)
#elif defined(__vxworks)
 
 
extern void __gnat_init_float (void);
extern void __gnat_init_float (void);
 
 
void
void
__gnat_initialize (void *eh)
__gnat_initialize (void *eh)
{
{
  __gnat_init_float ();
  __gnat_init_float ();
 
 
  /* On targets where we use the ZCX scheme, we need to register the frame
  /* On targets where we use the ZCX scheme, we need to register the frame
     tables at load/startup time.
     tables at load/startup time.
 
 
     For applications loaded as a set of "modules", the crtstuff objects
     For applications loaded as a set of "modules", the crtstuff objects
     linked in (crtbegin.o/end.o) are tailored to provide this service
     linked in (crtbegin.o/end.o) are tailored to provide this service
     automatically, a-la C++ constructor fashion, triggered by the VxWorks
     automatically, a-la C++ constructor fashion, triggered by the VxWorks
     loader thanks to a special variable declaration in crtbegin.o (_ctors).
     loader thanks to a special variable declaration in crtbegin.o (_ctors).
 
 
     Automatic de-registration is handled symmetrically, a-la C++ destructor
     Automatic de-registration is handled symmetrically, a-la C++ destructor
     fashion (with a _dtors variable also in crtbegin.o) triggered by the
     fashion (with a _dtors variable also in crtbegin.o) triggered by the
     dynamic unloader.
     dynamic unloader.
 
 
     Note that since the tables shall be registered against a common
     Note that since the tables shall be registered against a common
     data structure, libgcc should be one of the modules (vs being partially
     data structure, libgcc should be one of the modules (vs being partially
     linked against all the others at build time) and shall be loaded first.
     linked against all the others at build time) and shall be loaded first.
 
 
     For applications linked with the kernel, the scheme above would lead to
     For applications linked with the kernel, the scheme above would lead to
     duplicated symbols because the VxWorks kernel build "munches" by default,
     duplicated symbols because the VxWorks kernel build "munches" by default,
     so we link against crtbeginT.o instead of crtbegin.o, which doesn't
     so we link against crtbeginT.o instead of crtbegin.o, which doesn't
     include the special variables. We know which set of crt objects is used
     include the special variables. We know which set of crt objects is used
     thanks to a boolean indicator present in both sets (__module_has_ctors),
     thanks to a boolean indicator present in both sets (__module_has_ctors),
     and directly call the appropriate function here in the not-automatic
     and directly call the appropriate function here in the not-automatic
     case. We'll never unload that, so there is no de-registration to worry
     case. We'll never unload that, so there is no de-registration to worry
     about.
     about.
 
 
     For whole applications loaded as a single module, we may use one scheme
     For whole applications loaded as a single module, we may use one scheme
     or the other, except for the mixed Ada/C++ case in which the first scheme
     or the other, except for the mixed Ada/C++ case in which the first scheme
     would fail for the same reason as in the linked-with-kernel situation.
     would fail for the same reason as in the linked-with-kernel situation.
 
 
     Selecting the crt set with the ctors/dtors capabilities (first scheme
     Selecting the crt set with the ctors/dtors capabilities (first scheme
     above) is triggered by adding "-dynamic" to the gcc *link* command line
     above) is triggered by adding "-dynamic" to the gcc *link* command line
     options. Selecting the other set is achieved by using "-static" instead.
     options. Selecting the other set is achieved by using "-static" instead.
 
 
     This is a first approach, tightly synchronized with a number of GCC
     This is a first approach, tightly synchronized with a number of GCC
     configuration and crtstuff changes. We need to ensure that those changes
     configuration and crtstuff changes. We need to ensure that those changes
     are there to activate this circuitry.  */
     are there to activate this circuitry.  */
 
 
#if (__GNUC__ >= 3) && (defined (_ARCH_PPC) || defined (__ppc))
#if (__GNUC__ >= 3) && (defined (_ARCH_PPC) || defined (__ppc))
 {
 {
   /* The scheme described above is only useful for the actual ZCX case, and
   /* The scheme described above is only useful for the actual ZCX case, and
      we don't want any reference to the crt provided symbols otherwise.  We
      we don't want any reference to the crt provided symbols otherwise.  We
      may not link with any of the crt objects in the non-ZCX case, e.g. from
      may not link with any of the crt objects in the non-ZCX case, e.g. from
      documented procedures instructing the use of -nostdlib, and references
      documented procedures instructing the use of -nostdlib, and references
      to the ctors symbols here would just remain unsatisfied.
      to the ctors symbols here would just remain unsatisfied.
 
 
      We have no way to avoid those references in the right conditions in this
      We have no way to avoid those references in the right conditions in this
      C module, because we have nothing like a IN_ZCX_RTS macro.  This aspect
      C module, because we have nothing like a IN_ZCX_RTS macro.  This aspect
      is then deferred to an Ada routine, which can do that based on a test
      is then deferred to an Ada routine, which can do that based on a test
      against a constant System flag value.  */
      against a constant System flag value.  */
 
 
   extern void __gnat_vxw_setup_for_eh (void);
   extern void __gnat_vxw_setup_for_eh (void);
   __gnat_vxw_setup_for_eh ();
   __gnat_vxw_setup_for_eh ();
 }
 }
#endif
#endif
}
}
 
 
#elif defined(_T_HPUX10) || (!defined(IN_RTS) && defined(_X_HPUX10))
#elif defined(_T_HPUX10) || (!defined(IN_RTS) && defined(_X_HPUX10))
 
 
/************************************************/
/************************************************/
/* __gnat_initialize (PA-RISC HP-UX 10 Version) */
/* __gnat_initialize (PA-RISC HP-UX 10 Version) */
/************************************************/
/************************************************/
 
 
extern void __main (void);
extern void __main (void);
 
 
void
void
__gnat_initialize (void *eh ATTRIBUTE_UNUSED)
__gnat_initialize (void *eh ATTRIBUTE_UNUSED)
{
{
  __main ();
  __main ();
}
}
 
 
#else
#else
 
 
/* For all other versions of GNAT, the initialize routine and handler
/* For all other versions of GNAT, the initialize routine and handler
   installation do nothing */
   installation do nothing */
 
 
/***************************************/
/***************************************/
/* __gnat_initialize (Default Version) */
/* __gnat_initialize (Default Version) */
/***************************************/
/***************************************/
 
 
void
void
__gnat_initialize (void *eh ATTRIBUTE_UNUSED)
__gnat_initialize (void *eh ATTRIBUTE_UNUSED)
{
{
}
}
 
 
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.