* config/i386/uwin.h: Remove SUBTARGET_PROLOGUE.
[official-gcc.git] / gcc / config / frv / frvbegin.c
bloba5f5b1fa93e7bf2cedb572f376dd8898c8711c36
1 /* Frv initialization file linked before all user modules
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 Contributed by Red Hat, Inc.
5 This file is part of GNU CC.
7 GNU CC 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.
12 GNU CC 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.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 This file was originally taken from the file crtstuff.c in the
23 main compiler directory, and simplified. */
25 #include "defaults.h"
26 #include <stddef.h>
27 #include "unwind-dw2-fde.h"
28 #include "gbl-ctors.h"
30 /* Declare a pointer to void function type. */
31 #define STATIC static
33 #ifdef __FRV_UNDERSCORE__
34 #define UNDERSCORE "_"
35 #else
36 #define UNDERSCORE ""
37 #endif
39 #define INIT_SECTION_NEG_ONE(SECTION, FLAGS, NAME) \
40 __asm__ (".section " SECTION "," FLAGS "\n\t" \
41 ".globl " UNDERSCORE NAME "\n\t" \
42 ".type " UNDERSCORE NAME ",@object\n\t" \
43 ".p2align 2\n" \
44 UNDERSCORE NAME ":\n\t" \
45 ".word -1\n\t" \
46 ".previous")
48 #define INIT_SECTION(SECTION, FLAGS, NAME) \
49 __asm__ (".section " SECTION "," FLAGS "\n\t" \
50 ".globl " UNDERSCORE NAME "\n\t" \
51 ".type " UNDERSCORE NAME ",@object\n\t" \
52 ".p2align 2\n" \
53 UNDERSCORE NAME ":\n\t" \
54 ".previous")
56 /* Beginning of .ctor/.dtor sections that provides a list of constructors and
57 destructors to run. */
59 INIT_SECTION_NEG_ONE (".ctors", "\"aw\"", "__CTOR_LIST__");
60 INIT_SECTION_NEG_ONE (".dtors", "\"aw\"", "__DTOR_LIST__");
62 /* Beginning of .eh_frame section that provides all of the exception handling
63 tables. */
65 INIT_SECTION (".eh_frame", "\"aw\"", "__EH_FRAME_BEGIN__");
67 /* Beginning of .rofixup section that provides a list of pointers that we
68 need to adjust. */
70 INIT_SECTION (".rofixup", "\"a\"", "__ROFIXUP_LIST__");
72 extern void __frv_register_eh(void) __attribute__((__constructor__));
73 extern void __frv_deregister_eh(void) __attribute__((__destructor__));
75 extern func_ptr __EH_FRAME_BEGIN__[];
77 /* Register the exeception handling table as the first constructor */
78 void
79 __frv_register_eh (void)
81 static struct object object;
82 if (__register_frame_info)
83 __register_frame_info (__EH_FRAME_BEGIN__, &object);
86 /* Note, do not declare __{,de}register_frame_info weak as it seems
87 to interfere with the pic support. */
89 /* Unregister the exeception handling table as a deconstructor */
90 void
91 __frv_deregister_eh (void)
93 static int completed = 0;
95 if (completed)
96 return;
98 if (__deregister_frame_info)
99 __deregister_frame_info (__EH_FRAME_BEGIN__);
101 completed = 1;
104 /* Run the global destructors */
105 void
106 __do_global_dtors ()
108 static func_ptr *p = __DTOR_LIST__ + 1;
109 while (*p)
111 p++;
112 (*(p-1)) ();
116 /* Run the global constructors */
117 void
118 __do_global_ctors ()
120 unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];
121 unsigned i;
123 if (nptrs == (unsigned long)-1)
124 for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);
126 for (i = nptrs; i >= 1; i--)
127 __CTOR_LIST__[i] ();
129 atexit (__do_global_dtors);
132 /* Subroutine called automatically by `main'.
133 Compiling a global function named `main'
134 produces an automatic call to this function at the beginning.
136 For many systems, this routine calls __do_global_ctors.
137 For systems which support a .init section we use the .init section
138 to run __do_global_ctors, so we need not do anything here. */
140 void
141 __main ()
143 /* Support recursive calls to `main': run initializers just once. */
144 static int initialized;
145 if (! initialized)
147 initialized = 1;
148 __do_global_ctors ();