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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 38 julius
/* .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
     = { (func_ptr) (-1) };
51
 
52
static func_ptr __DTOR_LIST__[1] __attribute__ ((section (".dtors")))
53
     = { (func_ptr) (-1) };
54
 
55
/* Run all the global destructors on exit from the program.  */
56
 
57
/* Some systems place the number of pointers in the first word of the
58
   table.  On SVR4 however, that word is -1.  In all cases, the table is
59
   null-terminated.  On SVR4, we start from the beginning of the list and
60
   invoke each per-compilation-unit destructor routine in order
61
   until we find that null.
62
 
63
   Note that this function MUST be static.  There will be one of these
64
   functions in each root executable and one in each shared library, but
65
   although they all have the same code, each one is unique in that it
66
   refers to one particular associated `__DTOR_LIST__' which belongs to the
67
   same particular root executable or shared library file.  */
68
 
69
static void __do_global_dtors (void)
70
asm ("__do_global_dtors") __attribute__ ((section (".text")));
71
 
72
static void
73
__do_global_dtors (void)
74
{
75
  func_ptr *p;
76
  for (p = __DTOR_LIST__ + 1; *p; p++)
77
    (*p) ();
78
}
79
 
80
/* .init section start.
81
   This must appear at the start of the .init section.  */
82
 
83
asm ("\n\
84
        .section .init\n\
85
        .global init\n\
86
        .word 0\n\
87
init:\n\
88
        st blink,[sp,4]\n\
89
        st fp,[sp]\n\
90
        mov fp,sp\n\
91
        sub sp,sp,16\n\
92
");
93
 
94
/* .fini section start.
95
   This must appear at the start of the .init section.  */
96
 
97
asm ("\n\
98
        .section .fini\n\
99
        .global fini\n\
100
        .word 0\n\
101
fini:\n\
102
        st blink,[sp,4]\n\
103
        st fp,[sp]\n\
104
        mov fp,sp\n\
105
        sub sp,sp,16\n\
106
        bl.nd __do_global_dtors\n\
107
");
108
 
109
#endif /* CRT_INIT */
110
 
111
#ifdef CRT_FINI
112
 
113
/* Put a word containing zero at the end of each of our two lists of function
114
   addresses.  Note that the words defined here go into the .ctors and .dtors
115
   sections of the crtend.o file, and since that file is always linked in
116
   last, these words naturally end up at the very ends of the two lists
117
   contained in these two sections.  */
118
 
119
static func_ptr __CTOR_END__[1] __attribute__ ((section (".ctors")))
120
     = { (func_ptr) 0 };
121
 
122
static func_ptr __DTOR_END__[1] __attribute__ ((section (".dtors")))
123
     = { (func_ptr) 0 };
124
 
125
/* Run all global constructors for the program.
126
   Note that they are run in reverse order.  */
127
 
128
static void __do_global_ctors (void)
129
asm ("__do_global_ctors") __attribute__ ((section (".text")));
130
 
131
static void
132
__do_global_ctors (void)
133
{
134
  func_ptr *p;
135
  for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
136
    (*p) ();
137
}
138
 
139
/* .init section end.
140
   This must live at the end of the .init section.  */
141
 
142
asm ("\n\
143
        .section .init\n\
144
        bl.nd __do_global_ctors\n\
145
        ld blink,[fp,4]\n\
146
        j.d blink\n\
147
        ld.a fp,[sp,16]\n\
148
");
149
 
150
/* .fini section end.
151
   This must live at the end of the .fini section.  */
152
 
153
asm ("\n\
154
        .section .fini\n\
155
        ld blink,[fp,4]\n\
156
        j.d blink\n\
157
        ld.a fp,[sp,16]\n\
158
");
159
 
160
#endif /* CRT_FINI */

powered by: WebSVN 2.1.0

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