Update.
[glibc.git] / sysdeps / sh / elf / initfini.c
blob7697e93f492cf4ac70b3441297d764fbbf395a0f
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 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 /* This file is compiled into assembly code which is then munged by a sed
21 script into two files: crti.s and crtn.s.
23 * crti.s puts a function prologue at the beginning of the
24 .init and .fini sections and defines global symbols for
25 those addresses, so they can be called as functions.
27 * crtn.s puts the corresponding function epilogues
28 in the .init and .fini sections. */
30 __asm__ ("\
31 \n\
32 #include \"defs.h\"\n\
33 #define SHARED\n\
34 \n\
35 /*@HEADER_ENDS*/\n\
36 \n\
37 /*@TESTS_BEGIN*/\n\
38 \n\
39 /*@TESTS_END*/\n\
40 \n\
41 /*@_init_PROLOG_BEGINS*/\n\
42 .section .init\n\
43 .align 5\n\
44 .global _init\n\
45 .type _init,@function\n\
46 _init:\n\
47 mov.l r12,@-r15\n\
48 mov.l r14,@-r15\n\
49 sts.l pr,@-r15\n\
50 #ifdef SHARED\n\
51 mova .L22,r0\n\
52 mov.l .L22,r12\n\
53 add r0,r12\n\
54 mova .L23,r0\n\
55 mov.l .L23,r1\n\
56 add r0,r1\n\
57 #else\n\
58 mov.l .L23,r1\n\
59 #endif\n\
60 jsr @r1\n\
61 mov r15,r14\n\
62 bra 1f\n\
63 nop\n\
64 .align 2\n\
65 #ifdef SHARED\n\
66 .L22:\n\
67 .long _GLOBAL_OFFSET_TABLE_\n\
68 .L23:\n\
69 .long __gmon_start__@PLT\n\
70 #else\n\
71 .L23:\n\
72 .long __gmon_start__\n\
73 #endif\n\
74 1:\n\
75 ALIGN\n\
76 END_INIT\n\
77 \n\
78 \n\
79 /*@_init_PROLOG_ENDS*/\n\
80 \n\
81 /*@_init_EPILOG_BEGINS*/\n\
82 .section .init\n\
83 mov r14,r15\n\
84 lds.l @r15+,pr\n\
85 mov.l @r15+,r14\n\
86 rts \n\
87 mov.l @r15+,r12\n\
88 END_INIT\n\
89 .section .text\n\
90 .align 5\n\
91 .weak __gmon_start__\n\
92 .type __gmon_start__,@function\n\
93 __gmon_start__:\n\
94 mov.l r14,@-r15\n\
95 mov r15,r14\n\
96 mov r14,r15\n\
97 rts \n\
98 mov.l @r15+,r14\n\
99 \n\
100 /*@_init_EPILOG_ENDS*/\n\
102 /*@_fini_PROLOG_BEGINS*/\n\
103 .section .fini\n\
104 .align 5\n\
105 .global _fini\n\
106 .type _fini,@function\n\
107 _fini:\n\
108 mov.l r12,@-r15\n\
109 mov.l r14,@-r15\n\
110 sts.l pr,@-r15\n\
111 #ifdef SHARED\n\
112 mova .L27,r0\n\
113 mov.l .L27,r12\n\
114 add r0,r12\n\
115 #endif\n\
116 mov r15,r14\n\
117 ALIGN\n\
118 END_FINI\n\
119 #ifdef SHARED\n\
120 bra 1f\n\
121 nop\n\
122 .align 2\n\
123 .L27:\n\
124 .long _GLOBAL_OFFSET_TABLE_\n\
125 #endif\n\
126 1:\n\
127 /*@_fini_PROLOG_ENDS*/\n\
129 /*@_fini_EPILOG_BEGINS*/\n\
130 .section .fini\n\
131 mov r14,r15\n\
132 lds.l @r15+,pr\n\
133 mov.l @r15+,r14\n\
134 rts \n\
135 mov.l @r15+,r12\n\
137 END_FINI\n\
139 /*@_fini_EPILOG_ENDS*/\n\
141 /*@TRAILER_BEGINS*/\