OSDN Git Service

* config/frv/frv.c (frv_default_flags_for_cpu): Use gcc_assert and
[pf3gnuchains/gcc-fork.git] / gcc / config / frv / frvbegin.c
1 /* Frv initialization file linked before all user modules
2    Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
3     Contributed by Red Hat, Inc.
4   
5    This file is part of GCC.
6   
7    GCC is free software ; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation * either version 2, or (at your option)
10    any later version.
11   
12    GCC is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY ; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16   
17    You should have received a copy of the GNU General Public License
18    along with GCC; see the file COPYING.  If not, write to
19    the Free Software Foundation, 59 Temple Place - Suite 330,
20    Boston, MA 02111-1307, USA.
21
22    This file was originally taken from the file crtstuff.c in the
23    main compiler directory, and simplified.  */
24
25 /* As a special exception, if you link this library with other files,
26    some of which are compiled with GCC, to produce an executable,
27    this library does not by itself cause the resulting executable
28    to be covered by the GNU General Public License.
29    This exception does not however invalidate any other reasons why
30    the executable file might be covered by the GNU General Public License.  */
31
32 #include "defaults.h"
33 #include <stddef.h>
34 #include "unwind-dw2-fde.h"
35 #include "gbl-ctors.h"
36
37 /*  Declare a pointer to void function type.  */
38 #define STATIC static
39
40 #ifdef __FRV_UNDERSCORE__
41 #define UNDERSCORE "_"
42 #else
43 #define UNDERSCORE ""
44 #endif
45
46 #define INIT_SECTION_NEG_ONE(SECTION, FLAGS, NAME)                      \
47 __asm__ (".section " SECTION "," FLAGS "\n\t"                           \
48          ".globl   " UNDERSCORE NAME "\n\t"                             \
49          ".type    " UNDERSCORE NAME ",@object\n\t"                     \
50          ".p2align  2\n"                                                \
51          UNDERSCORE NAME ":\n\t"                                        \
52          ".word     -1\n\t"                                             \
53          ".previous")
54
55 #define INIT_SECTION(SECTION, FLAGS, NAME)                              \
56 __asm__ (".section " SECTION "," FLAGS "\n\t"                           \
57          ".globl   " UNDERSCORE NAME "\n\t"                             \
58          ".type    " UNDERSCORE NAME ",@object\n\t"                     \
59          ".p2align  2\n"                                                \
60          UNDERSCORE NAME ":\n\t"                                        \
61          ".previous")
62
63 /* Beginning of .ctor/.dtor sections that provides a list of constructors and
64    destructors to run.  */
65
66 INIT_SECTION_NEG_ONE (".ctors", "\"aw\"", "__CTOR_LIST__");
67 INIT_SECTION_NEG_ONE (".dtors", "\"aw\"", "__DTOR_LIST__");
68
69 /* Beginning of .eh_frame section that provides all of the exception handling
70    tables.  */
71
72 INIT_SECTION (".eh_frame", "\"aw\"", "__EH_FRAME_BEGIN__");
73
74 #if ! __FRV_FDPIC__
75 /* In FDPIC, the linker itself generates this.  */
76 /* Beginning of .rofixup section that provides a list of pointers that we
77    need to adjust.  */
78
79 INIT_SECTION (".rofixup", "\"a\"", "__ROFIXUP_LIST__");
80 #endif /* __FRV_FDPIC__ */
81
82 extern void __frv_register_eh(void) __attribute__((__constructor__));
83 extern void __frv_deregister_eh(void) __attribute__((__destructor__));
84
85 extern func_ptr __EH_FRAME_BEGIN__[];
86
87 /* Register the exception handling table as the first constructor.  */
88 void
89 __frv_register_eh (void)
90 {
91   static struct object object;
92   if (__register_frame_info)
93     __register_frame_info (__EH_FRAME_BEGIN__, &object);
94 }
95
96 /* Note, do not declare __{,de}register_frame_info weak as it seems
97    to interfere with the pic support.  */
98
99 /* Unregister the exception handling table as a deconstructor.  */
100 void
101 __frv_deregister_eh (void)
102 {
103   static int completed = 0;
104
105   if (completed)
106     return;
107
108   if (__deregister_frame_info)
109     __deregister_frame_info (__EH_FRAME_BEGIN__);
110
111   completed = 1;
112 }
113
114 /* Run the global destructors.  */
115 void
116 __do_global_dtors (void)
117 {
118   static func_ptr *p = __DTOR_LIST__ + 1;
119   while (*p)
120     {
121       p++;
122       (*(p-1)) ();
123     }
124 }
125
126 /* Run the global constructors.  */
127 void
128 __do_global_ctors (void)
129 {
130   unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];
131   unsigned i;
132
133   if (nptrs == (unsigned long)-1)
134     for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);
135
136   for (i = nptrs; i >= 1; i--)
137     __CTOR_LIST__[i] ();
138
139   atexit (__do_global_dtors);
140 }
141
142 /* Subroutine called automatically by `main'.
143    Compiling a global function named `main'
144    produces an automatic call to this function at the beginning.
145
146    For many systems, this routine calls __do_global_ctors.
147    For systems which support a .init section we use the .init section
148    to run __do_global_ctors, so we need not do anything here.  */
149
150 void
151 __main (void)
152 {
153   /* Support recursive calls to `main': run initializers just once.  */
154   static int initialized;
155   if (! initialized)
156     {
157       initialized = 1;
158       __do_global_ctors ();
159     }
160 }