OSDN Git Service

Fix copyright notice.
[pf3gnuchains/gcc-fork.git] / gcc / ada / initialize.c
1 /****************************************************************************
2  *                                                                          *
3  *                         GNAT COMPILER COMPONENTS                         *
4  *                                                                          *
5  *                           I N I T I A L I Z E                            *
6  *                                                                          *
7  *                          C Implementation File                           *
8  *                                                                          *
9  *          Copyright (C) 1992-2008, Free Software Foundation, Inc.         *
10  *                                                                          *
11  * GNAT is free software;  you can  redistribute it  and/or modify it under *
12  * terms of the  GNU General Public License as published  by the Free Soft- *
13  * ware  Foundation;  either version 2,  or (at your option) any later ver- *
14  * sion.  GNAT is distributed in the hope that it will be useful, but WITH- *
15  * OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY *
16  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License *
17  * for  more details.  You should have  received  a copy of the GNU General *
18  * Public License  distributed with GNAT;  see file COPYING.  If not, write *
19  * to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, *
20  * Boston, MA 02110-1301, USA.                                              *
21  *                                                                          *
22  * As a  special  exception,  if you  link  this file  with other  files to *
23  * produce an executable,  this file does not by itself cause the resulting *
24  * executable to be covered by the GNU General Public License. This except- *
25  * ion does not  however invalidate  any other reasons  why the  executable *
26  * file might be covered by the  GNU Public License.                        *
27  *                                                                          *
28  * GNAT was originally developed  by the GNAT team at  New York University. *
29  * Extensive contributions were provided by Ada Core Technologies Inc.      *
30  *                                                                          *
31  ****************************************************************************/
32
33 /*  This unit provides default implementation for __gnat_initialize ()
34     which is called before the elaboration of the partition. It is provided
35     in a separate file/object so that users can replace it easily.
36     The default implementation should be null on most targets. */
37
38 /* The following include is here to meet the published VxWorks requirement
39    that the __vxworks header appear before any other include. */
40 #ifdef __vxworks
41 #include "vxWorks.h"
42 #endif
43
44 #ifdef IN_RTS
45 #include "tconfig.h"
46 #include "tsystem.h"
47 #else
48 #include "config.h"
49 #include "system.h"
50 #endif
51
52 #include "raise.h"
53
54 /******************************************/
55 /* __gnat_initialize (NT-mingw32 Version) */
56 /******************************************/
57
58 #if defined (__MINGW32__)
59 #include <windows.h>
60
61 extern void __gnat_init_float (void);
62 extern void __gnat_install_SEH_handler (void *);
63
64 #ifndef RTX
65 /* Do not define for RTX since it is only used for creating child processes
66    which is not supported in RTX. */
67 extern void __gnat_plist_init (void);
68 #endif
69
70 void
71 __gnat_initialize (void *eh)
72 {
73    /* Initialize floating-point coprocessor. This call is needed because
74       the MS libraries default to 64-bit precision instead of 80-bit
75       precision, and we require the full precision for proper operation,
76       given that we have set Max_Digits etc with this in mind */
77    __gnat_init_float ();
78
79 #ifndef RTX
80    /* Initialize a lock for a process handle list - see adaint.c for the
81       implementation of __gnat_portable_no_block_spawn, __gnat_portable_wait */
82    __gnat_plist_init();
83 #endif
84
85    /* Note that we do not activate this for the compiler itself to avoid a
86       bootstrap path problem.  Older version of gnatbind will generate a call
87       to __gnat_initialize() without argument. Therefore we cannot use eh in
88       this case.  It will be possible to remove the following #ifdef at some
89       point.  */
90 #ifdef IN_RTS
91    /* Install the Structured Exception handler.  */
92    if (eh)
93      __gnat_install_SEH_handler (eh);
94 #endif
95 }
96
97 /******************************************/
98 /* __gnat_initialize (init_float version) */
99 /******************************************/
100
101 #elif defined (__Lynx__) || defined (__FreeBSD__) || defined(__NetBSD__) \
102   || defined (__OpenBSD__)
103
104 extern void __gnat_init_float (void);
105
106 void
107 __gnat_initialize (void *eh ATTRIBUTE_UNUSED)
108 {
109    __gnat_init_float ();
110 }
111
112 /***************************************/
113 /* __gnat_initialize (VxWorks Version) */
114 /***************************************/
115
116 #elif defined(__vxworks)
117
118 extern void __gnat_init_float (void);
119
120 void
121 __gnat_initialize (void *eh)
122 {
123   __gnat_init_float ();
124
125   /* On targets where we use the ZCX scheme, we need to register the frame
126      tables at load/startup time.
127
128      For applications loaded as a set of "modules", the crtstuff objects
129      linked in (crtbegin.o/end.o) are tailored to provide this service
130      automatically, a-la C++ constructor fashion, triggered by the VxWorks
131      loader thanks to a special variable declaration in crtbegin.o (_ctors).
132
133      Automatic de-registration is handled symmetrically, a-la C++ destructor
134      fashion (with a _dtors variable also in crtbegin.o) triggered by the
135      dynamic unloader.
136
137      Note that since the tables shall be registered against a common
138      data structure, libgcc should be one of the modules (vs being partially
139      linked against all the others at build time) and shall be loaded first.
140
141      For applications linked with the kernel, the scheme above would lead to
142      duplicated symbols because the VxWorks kernel build "munches" by default,
143      so we link against crtbeginT.o instead of crtbegin.o, which doesn't
144      include the special variables. We know which set of crt objects is used
145      thanks to a boolean indicator present in both sets (__module_has_ctors),
146      and directly call the appropriate function here in the not-automatic
147      case. We'll never unload that, so there is no de-registration to worry
148      about.
149
150      For whole applications loaded as a single module, we may use one scheme
151      or the other, except for the mixed Ada/C++ case in which the first scheme
152      would fail for the same reason as in the linked-with-kernel situation.
153
154      Selecting the crt set with the ctors/dtors capabilities (first scheme
155      above) is triggered by adding "-dynamic" to the gcc *link* command line
156      options. Selecting the other set is achieved by using "-static" instead.
157
158      This is a first approach, tightly synchronized with a number of GCC
159      configuration and crtstuff changes. We need to ensure that those changes
160      are there to activate this circuitry.  */
161
162 #if (__GNUC__ >= 3) && (defined (_ARCH_PPC) || defined (__ppc))
163  {
164    /* The scheme described above is only useful for the actual ZCX case, and
165       we don't want any reference to the crt provided symbols otherwise.  We
166       may not link with any of the crt objects in the non-ZCX case, e.g. from
167       documented procedures instructing the use of -nostdlib, and references
168       to the ctors symbols here would just remain unsatisfied.
169
170       We have no way to avoid those references in the right conditions in this
171       C module, because we have nothing like a IN_ZCX_RTS macro.  This aspect
172       is then deferred to an Ada routine, which can do that based on a test
173       against a constant System flag value.  */
174
175    extern void __gnat_vxw_setup_for_eh (void);
176    __gnat_vxw_setup_for_eh ();
177  }
178 #endif
179 }
180
181 #elif defined(_T_HPUX10) || (!defined(IN_RTS) && defined(_X_HPUX10))
182
183 /************************************************/
184 /* __gnat_initialize (PA-RISC HP-UX 10 Version) */
185 /************************************************/
186
187 extern void __main (void);
188
189 void
190 __gnat_initialize (void *eh ATTRIBUTE_UNUSED)
191 {
192   __main ();
193 }
194
195 #else
196
197 /* For all other versions of GNAT, the initialize routine and handler
198    installation do nothing */
199
200 /***************************************/
201 /* __gnat_initialize (Default Version) */
202 /***************************************/
203
204 void
205 __gnat_initialize (void *eh ATTRIBUTE_UNUSED)
206 {
207 }
208
209 #endif