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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [config/] [or32/] [initfini.c] - Blame information for rev 192

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 177 jeremybenn
/* .init/.fini section handling + C++ global constructor/destructor handling.
2
   This file is based on crtstuff.c, sol2-crti.asm, sol2-crtn.asm.
3
 
4
Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
5
 
6
This file is part of GCC.
7
 
8
GCC is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2, or (at your option)
11
any later version.
12
 
13
In addition to the permissions in the GNU General Public License, the
14
Free Software Foundation gives you unlimited permission to link the
15
compiled version of this file into combinations with other programs,
16
and to distribute those combinations without any restriction coming
17
from the use of this file.  (The General Public License restrictions
18
do apply in other respects; for example, they cover modification of
19
the file, and distribution when not linked into a combine
20
executable.)
21
 
22
GCC is distributed in the hope that it will be useful,
23
but WITHOUT ANY WARRANTY; without even the implied warranty of
24
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
GNU General Public License for more details.
26
 
27
You should have received a copy of the GNU General Public License
28
along with GCC; see the file COPYING.  If not, write to
29
the Free Software Foundation, 51 Franklin Street, Fifth Floor,
30
Boston, MA 02110-1301, USA.  */
31
 
32
/*  Declare a pointer to void function type.  */
33
typedef void (*func_ptr) (void);
34
 
35
#ifdef CRT_INIT
36
 
37
/* NOTE:  In order to be able to support SVR4 shared libraries, we arrange
38
   to have one set of symbols { __CTOR_LIST__, __DTOR_LIST__, __CTOR_END__,
39
   __DTOR_END__ } per root executable and also one set of these symbols
40
   per shared library.  So in any given whole process image, we may have
41
   multiple definitions of each of these symbols.  In order to prevent
42
   these definitions from conflicting with one another, and in order to
43
   ensure that the proper lists are used for the initialization/finalization
44
   of each individual shared library (respectively), we give these symbols
45
   only internal (i.e. `static') linkage, and we also make it a point to
46
   refer to only the __CTOR_END__ symbol in crtfini.o and the __DTOR_LIST__
47
   symbol in crtinit.o, where they are defined.  */
48
 
49
static func_ptr __CTOR_LIST__[1] __attribute__ ((section (".ctors")))
50
                                 __attribute__ ((used))
51
     = { (func_ptr) (-1) };
52
 
53
static func_ptr __DTOR_LIST__[1] __attribute__ ((section (".dtors")))
54
     = { (func_ptr) (-1) };
55
 
56
/* Run all the global destructors on exit from the program.  */
57
 
58
/* Some systems place the number of pointers in the first word of the
59
   table.  On SVR4 however, that word is -1.  In all cases, the table is
60
   null-terminated.  On SVR4, we start from the beginning of the list and
61
   invoke each per-compilation-unit destructor routine in order
62
   until we find that null.
63
 
64
   Note that this function MUST be static.  There will be one of these
65
   functions in each root executable and one in each shared library, but
66
   although they all have the same code, each one is unique in that it
67
   refers to one particular associated `__DTOR_LIST__' which belongs to the
68
   same particular root executable or shared library file.  */
69
 
70
static void _do_global_dtors (void)
71
asm ("__do_global_dtors") __attribute__ ((section (".text")))
72
                          __attribute ((used));
73
 
74
static void
75
_do_global_dtors (void)
76
{
77
  func_ptr *p;
78
  for (p = __DTOR_LIST__ + 1; *p; p++)
79
    (*p) ();
80
}
81
 
82
/* .init section start.
83
   This must appear at the start of the .init section.  */
84
 
85
asm ("\n\
86
        .section .init\n\
87
        .global init\n\
88
        .word 0\n\
89
init:\n\
90
        l.addi  r1,r1,-16\n\
91
        l.sw    12(r1),r2\n\
92
        l.addi  r2,r1,16\n\
93
        l.sw    8(r1),r9\n\
94
");
95
 
96
/* .fini section start.
97 192 jeremybenn
   This must appear at the start of the .init section.
98 177 jeremybenn
 
99 192 jeremybenn
   Note that the prologue is slightly different order to standard. Saving the
100
   link register in the delay slot will pick up the wrong value!
101
*/
102
 
103 177 jeremybenn
asm ("\n\
104
        .section .fini\n\
105
        .global fini\n\
106
        .word 0\n\
107
fini:\n\
108
        l.addi  r1,r1,-16\n\
109
        l.sw    12(r1),r2\n\
110 192 jeremybenn
        l.sw    8(r1),r9\n\
111
        l.jal   __do_global_dtors\n\
112 177 jeremybenn
        l.addi  r2,r1,16\n\
113
");
114
 
115
#endif /* CRT_INIT */
116
 
117
#ifdef CRT_FINI
118
 
119
/* Put a word containing zero at the end of each of our two lists of function
120
   addresses.  Note that the words defined here go into the .ctors and .dtors
121
   sections of the crtend.o file, and since that file is always linked in
122
   last, these words naturally end up at the very ends of the two lists
123
   contained in these two sections.  */
124
 
125
static func_ptr __CTOR_END__[1] __attribute__ ((section (".ctors")))
126
     = { (func_ptr) 0 };
127
 
128
static func_ptr __DTOR_END__[1] __attribute__ ((section (".dtors")))
129
                                __attribute__ ((used))
130
     = { (func_ptr) 0 };
131
 
132
/* Run all global constructors for the program.
133
   Note that they are run in reverse order.  */
134
 
135
static void _do_global_ctors (void)
136
asm ("__do_global_ctors") __attribute__ ((section (".text")))
137
                          __attribute ((used));
138
 
139
static void
140
_do_global_ctors (void)
141
{
142
  func_ptr *p;
143
  for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
144
    (*p) ();
145
}
146
 
147
/* .init section end.
148
   This must live at the end of the .init section.  */
149
 
150
asm ("\n\
151
        .section .init\n\
152 192 jeremybenn
        l.jal   __do_global_ctors\n\
153
        l.nop\n\
154 177 jeremybenn
        l.lwz   r9,8(r1)\n\
155
        l.lwz   r2,12(r1)\n\
156
        l.jr    r9\n\
157
        l.addi  r1,r1,16\n\
158
");
159
 
160
/* .fini section end.
161
   This must live at the end of the .fini section.  */
162
 
163
asm ("\n\
164
        .section .fini\n\
165
        l.lwz   r9,8(r1)\n\
166
        l.lwz   r2,12(r1)\n\
167
        l.jr    r9\n\
168
        l.addi  r1,r1,16\n\
169
");
170
 
171
#endif /* CRT_FINI */

powered by: WebSVN 2.1.0

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