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 177

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
   This must appear at the start of the .init section.  */
98
 
99
asm ("\n\
100
        .section .fini\n\
101
        .global fini\n\
102
        .word 0\n\
103
fini:\n\
104
        l.addi  r1,r1,-16\n\
105
        l.sw    12(r1),r2\n\
106
        l.addi  r2,r1,16\n\
107
        l.sw    8(r1),r9\n\
108
        l.j     __do_global_dtors\n\
109
");
110
 
111
#endif /* CRT_INIT */
112
 
113
#ifdef CRT_FINI
114
 
115
/* Put a word containing zero at the end of each of our two lists of function
116
   addresses.  Note that the words defined here go into the .ctors and .dtors
117
   sections of the crtend.o file, and since that file is always linked in
118
   last, these words naturally end up at the very ends of the two lists
119
   contained in these two sections.  */
120
 
121
static func_ptr __CTOR_END__[1] __attribute__ ((section (".ctors")))
122
     = { (func_ptr) 0 };
123
 
124
static func_ptr __DTOR_END__[1] __attribute__ ((section (".dtors")))
125
                                __attribute__ ((used))
126
     = { (func_ptr) 0 };
127
 
128
/* Run all global constructors for the program.
129
   Note that they are run in reverse order.  */
130
 
131
static void _do_global_ctors (void)
132
asm ("__do_global_ctors") __attribute__ ((section (".text")))
133
                          __attribute ((used));
134
 
135
static void
136
_do_global_ctors (void)
137
{
138
  func_ptr *p;
139
  for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
140
    (*p) ();
141
}
142
 
143
/* .init section end.
144
   This must live at the end of the .init section.  */
145
 
146
asm ("\n\
147
        .section .init\n\
148
        l.j     __do_global_ctors\n\
149
        l.lwz   r9,8(r1)\n\
150
        l.lwz   r2,12(r1)\n\
151
        l.jr    r9\n\
152
        l.addi  r1,r1,16\n\
153
");
154
 
155
/* .fini section end.
156
   This must live at the end of the .fini section.  */
157
 
158
asm ("\n\
159
        .section .fini\n\
160
        l.lwz   r9,8(r1)\n\
161
        l.lwz   r2,12(r1)\n\
162
        l.jr    r9\n\
163
        l.addi  r1,r1,16\n\
164
");
165
 
166
#endif /* CRT_FINI */

powered by: WebSVN 2.1.0

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