]>
Commit | Line | Data |
---|---|---|
36a05131 | 1 | /* Frv initialization file linked before all user modules |
83ffe9cd | 2 | Copyright (C) 1999-2023 Free Software Foundation, Inc. |
36a05131 BS |
3 | Contributed by Red Hat, Inc. |
4 | ||
7ec022b2 | 5 | This file is part of GCC. |
36a05131 | 6 | |
7ec022b2 | 7 | GCC is free software ; you can redistribute it and/or modify |
36a05131 | 8 | it under the terms of the GNU General Public License as published by |
748086b7 | 9 | the Free Software Foundation; either version 3, or (at your option) |
36a05131 BS |
10 | any later version. |
11 | ||
7ec022b2 | 12 | GCC is distributed in the hope that it will be useful, |
36a05131 BS |
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 | ||
748086b7 JJ |
17 | Under Section 7 of GPL version 3, you are granted additional |
18 | permissions described in the GCC Runtime Library Exception, version | |
19 | 3.1, as published by the Free Software Foundation. | |
20 | ||
21 | You should have received a copy of the GNU General Public License and | |
22 | a copy of the GCC Runtime Library Exception along with this program; | |
23 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
24 | <http://www.gnu.org/licenses/>. | |
36a05131 BS |
25 | |
26 | This file was originally taken from the file crtstuff.c in the | |
87b483a1 | 27 | main compiler directory, and simplified. */ |
36a05131 | 28 | |
36a05131 | 29 | #include <stddef.h> |
0fad9ab9 | 30 | #include "../libgcc/unwind-dw2-fde.h" |
36a05131 BS |
31 | #include "gbl-ctors.h" |
32 | ||
33 | /* Declare a pointer to void function type. */ | |
34 | #define STATIC static | |
35 | ||
36 | #ifdef __FRV_UNDERSCORE__ | |
37 | #define UNDERSCORE "_" | |
38 | #else | |
39 | #define UNDERSCORE "" | |
40 | #endif | |
41 | ||
42 | #define INIT_SECTION_NEG_ONE(SECTION, FLAGS, NAME) \ | |
43 | __asm__ (".section " SECTION "," FLAGS "\n\t" \ | |
44 | ".globl " UNDERSCORE NAME "\n\t" \ | |
45 | ".type " UNDERSCORE NAME ",@object\n\t" \ | |
46 | ".p2align 2\n" \ | |
47 | UNDERSCORE NAME ":\n\t" \ | |
48 | ".word -1\n\t" \ | |
49 | ".previous") | |
50 | ||
51 | #define INIT_SECTION(SECTION, FLAGS, NAME) \ | |
52 | __asm__ (".section " SECTION "," FLAGS "\n\t" \ | |
53 | ".globl " UNDERSCORE NAME "\n\t" \ | |
54 | ".type " UNDERSCORE NAME ",@object\n\t" \ | |
55 | ".p2align 2\n" \ | |
56 | UNDERSCORE NAME ":\n\t" \ | |
57 | ".previous") | |
58 | ||
59 | /* Beginning of .ctor/.dtor sections that provides a list of constructors and | |
60 | destructors to run. */ | |
61 | ||
7214fce3 JL |
62 | INIT_SECTION_NEG_ONE (".ctors", "\"a\"", "__CTOR_LIST__"); |
63 | INIT_SECTION_NEG_ONE (".dtors", "\"a\"", "__DTOR_LIST__"); | |
36a05131 BS |
64 | |
65 | /* Beginning of .eh_frame section that provides all of the exception handling | |
66 | tables. */ | |
67 | ||
68 | INIT_SECTION (".eh_frame", "\"aw\"", "__EH_FRAME_BEGIN__"); | |
69 | ||
34208acf AO |
70 | #if ! __FRV_FDPIC__ |
71 | /* In FDPIC, the linker itself generates this. */ | |
36a05131 BS |
72 | /* Beginning of .rofixup section that provides a list of pointers that we |
73 | need to adjust. */ | |
74 | ||
75 | INIT_SECTION (".rofixup", "\"a\"", "__ROFIXUP_LIST__"); | |
34208acf | 76 | #endif /* __FRV_FDPIC__ */ |
36a05131 BS |
77 | |
78 | extern void __frv_register_eh(void) __attribute__((__constructor__)); | |
79 | extern void __frv_deregister_eh(void) __attribute__((__destructor__)); | |
80 | ||
81 | extern func_ptr __EH_FRAME_BEGIN__[]; | |
82 | ||
87b483a1 | 83 | /* Register the exception handling table as the first constructor. */ |
36a05131 BS |
84 | void |
85 | __frv_register_eh (void) | |
86 | { | |
87 | static struct object object; | |
88 | if (__register_frame_info) | |
89 | __register_frame_info (__EH_FRAME_BEGIN__, &object); | |
90 | } | |
91 | ||
92 | /* Note, do not declare __{,de}register_frame_info weak as it seems | |
93 | to interfere with the pic support. */ | |
94 | ||
87b483a1 | 95 | /* Unregister the exception handling table as a deconstructor. */ |
36a05131 BS |
96 | void |
97 | __frv_deregister_eh (void) | |
98 | { | |
99 | static int completed = 0; | |
100 | ||
101 | if (completed) | |
102 | return; | |
103 | ||
104 | if (__deregister_frame_info) | |
105 | __deregister_frame_info (__EH_FRAME_BEGIN__); | |
106 | ||
107 | completed = 1; | |
108 | } | |
109 | ||
87b483a1 | 110 | /* Run the global destructors. */ |
36a05131 | 111 | void |
f2206911 | 112 | __do_global_dtors (void) |
36a05131 BS |
113 | { |
114 | static func_ptr *p = __DTOR_LIST__ + 1; | |
115 | while (*p) | |
116 | { | |
117 | p++; | |
118 | (*(p-1)) (); | |
119 | } | |
120 | } | |
121 | ||
87b483a1 | 122 | /* Run the global constructors. */ |
36a05131 | 123 | void |
f2206911 | 124 | __do_global_ctors (void) |
36a05131 BS |
125 | { |
126 | unsigned long nptrs = (unsigned long) __CTOR_LIST__[0]; | |
127 | unsigned i; | |
128 | ||
129 | if (nptrs == (unsigned long)-1) | |
130 | for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++); | |
131 | ||
132 | for (i = nptrs; i >= 1; i--) | |
133 | __CTOR_LIST__[i] (); | |
134 | ||
135 | atexit (__do_global_dtors); | |
136 | } | |
137 | ||
138 | /* Subroutine called automatically by `main'. | |
139 | Compiling a global function named `main' | |
140 | produces an automatic call to this function at the beginning. | |
141 | ||
142 | For many systems, this routine calls __do_global_ctors. | |
143 | For systems which support a .init section we use the .init section | |
144 | to run __do_global_ctors, so we need not do anything here. */ | |
145 | ||
146 | void | |
f2206911 | 147 | __main (void) |
36a05131 BS |
148 | { |
149 | /* Support recursive calls to `main': run initializers just once. */ | |
150 | static int initialized; | |
151 | if (! initialized) | |
152 | { | |
153 | initialized = 1; | |
154 | __do_global_ctors (); | |
155 | } | |
156 | } |