2.9
[glibc/nacl-glibc.git] / sysdeps / sh / elf / initfini.c
blob6c8ed85292bddcd32794d3819a12da40be5af0fa
1 /* Special .init and .fini section support for SH.
2 Copyright (C) 2000, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 In addition to the permissions in the GNU Lesser General Public
11 License, the Free Software Foundation gives you unlimited
12 permission to link the compiled version of this file with other
13 programs, and to distribute those programs without any restriction
14 coming from the use of this file. (The GNU Lesser General Public
15 License restrictions do apply in other respects; for example, they
16 cover modification of the file, and distribution when not linked
17 into another program.)
19 Note that people who make modified versions of this file are not
20 obligated to grant this special exception for their modified
21 versions; it is their choice whether to do so. The GNU Lesser
22 General Public License gives permission to release a modified
23 version without this exception; this exception also makes it
24 possible to release a modified version which carries forward this
25 exception.
27 The GNU C Library is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 Lesser General Public License for more details.
32 You should have received a copy of the GNU Lesser General Public
33 License along with the GNU C Library; if not, write to the Free
34 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
35 02111-1307 USA. */
37 /* This file is compiled into assembly code which is then munged by a sed
38 script into two files: crti.s and crtn.s.
40 * crti.s puts a function prologue at the beginning of the
41 .init and .fini sections and defines global symbols for
42 those addresses, so they can be called as functions.
44 * crtn.s puts the corresponding function epilogues
45 in the .init and .fini sections. */
47 __asm__ ("\
48 \n\
49 #include \"defs.h\"\n\
50 #define SHARED\n\
51 \n\
52 /*@HEADER_ENDS*/\n\
53 \n\
54 /*@TESTS_BEGIN*/\n\
55 \n\
56 /*@TESTS_END*/\n\
57 \n\
58 /*@_init_PROLOG_BEGINS*/\n\
59 .section .init\n\
60 .align 5\n\
61 .global _init\n\
62 .type _init,@function\n\
63 _init:\n\
64 mov.l r12,@-r15\n\
65 mov.l r14,@-r15\n\
66 sts.l pr,@-r15\n\
67 #ifdef SHARED\n\
68 mova .L22,r0\n\
69 mov.l .L22,r12\n\
70 add r0,r12\n\
71 mova .L23,r0\n\
72 mov.l .L23,r1\n\
73 add r0,r1\n\
74 #else\n\
75 mov.l .L23,r1\n\
76 #endif\n\
77 jsr @r1\n\
78 mov r15,r14\n\
79 bra 1f\n\
80 nop\n\
81 .align 2\n\
82 #ifdef SHARED\n\
83 .L22:\n\
84 .long _GLOBAL_OFFSET_TABLE_\n\
85 .L23:\n\
86 .long __gmon_start__@PLT\n\
87 #else\n\
88 .L23:\n\
89 .long __gmon_start__\n\
90 #endif\n\
91 1:\n\
92 ALIGN\n\
93 END_INIT\n\
94 \n\
95 \n\
96 /*@_init_PROLOG_ENDS*/\n\
97 \n\
98 /*@_init_EPILOG_BEGINS*/\n\
99 .section .init\n\
100 mov r14,r15\n\
101 lds.l @r15+,pr\n\
102 mov.l @r15+,r14\n\
103 rts \n\
104 mov.l @r15+,r12\n\
105 END_INIT\n\
106 .section .text\n\
107 .align 5\n\
108 .weak __gmon_start__\n\
109 .type __gmon_start__,@function\n\
110 __gmon_start__:\n\
111 mov.l r14,@-r15\n\
112 mov r15,r14\n\
113 mov r14,r15\n\
114 rts \n\
115 mov.l @r15+,r14\n\
117 /*@_init_EPILOG_ENDS*/\n\
119 /*@_fini_PROLOG_BEGINS*/\n\
120 .section .fini\n\
121 .align 5\n\
122 .global _fini\n\
123 .type _fini,@function\n\
124 _fini:\n\
125 mov.l r12,@-r15\n\
126 mov.l r14,@-r15\n\
127 sts.l pr,@-r15\n\
128 #ifdef SHARED\n\
129 mova .L27,r0\n\
130 mov.l .L27,r12\n\
131 add r0,r12\n\
132 #endif\n\
133 mov r15,r14\n\
134 ALIGN\n\
135 END_FINI\n\
136 #ifdef SHARED\n\
137 bra 1f\n\
138 nop\n\
139 .align 2\n\
140 .L27:\n\
141 .long _GLOBAL_OFFSET_TABLE_\n\
142 #endif\n\
143 1:\n\
144 /*@_fini_PROLOG_ENDS*/\n\
146 /*@_fini_EPILOG_BEGINS*/\n\
147 .section .fini\n\
148 mov r14,r15\n\
149 lds.l @r15+,pr\n\
150 mov.l @r15+,r14\n\
151 rts \n\
152 mov.l @r15+,r12\n\
154 END_FINI\n\
156 /*@_fini_EPILOG_ENDS*/\n\
158 /*@TRAILER_BEGINS*/\