2.9
[glibc/nacl-glibc.git] / sysdeps / ia64 / elf / initfini.c
blobd0a65ece80556d5e5702ed9e64ac0fe617bf0aaf
1 /* Special .init and .fini section support for ia64.
2 Copyright (C) 2000, 2002, 2003, 2005 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__ ("\n\n"
48 "#include \"defs.h\"\n"
49 "\n"
50 "/*@HEADER_ENDS*/\n"
51 "\n"
52 "/*@_init_PROLOG_BEGINS*/\n");
55 /* If we have working .init_array support, we want to keep the .init
56 section empty (apart from the mandatory prologue/epilogue. This
57 ensures that the default unwind conventions (return-pointer in b0,
58 frame state in ar.pfs, etc.) will do the Right Thing. To ensure
59 an empty .init section, we register gmon_initializer() via the
60 .init_array.
62 --davidm 02/10/29 */
64 static void
65 __attribute__ ((used))
66 gmon_initializer (void)
68 extern void weak_function __gmon_start__ (void);
70 if (__gmon_start__)
71 (*__gmon_start__)();
74 __asm__ (".section .init_array, \"aw\"\n"
75 "\tdata8 @fptr(gmon_initializer)\n");
78 __asm__ (".section .init\n"
79 " .global _init#\n"
80 " .proc _init#\n"
81 "_init:\n"
82 " .prologue\n"
83 " .save ar.pfs, r34\n"
84 " alloc r34 = ar.pfs, 0, 3, 0, 0\n"
85 " .vframe r32\n"
86 " mov r32 = r12\n"
87 " .save rp, r33\n"
88 " mov r33 = b0\n"
89 " .body\n"
90 " adds r12 = -16, r12\n"
91 " ;;\n" /* see gmon_initializer() above */
92 " .endp _init#\n"
93 "\n"
94 "/*@_init_PROLOG_ENDS*/\n"
95 "\n"
96 "/*@_init_EPILOG_BEGINS*/\n"
97 " .section .init\n"
98 " .proc _init#\n"
99 "_init:\n"
100 " .prologue\n"
101 " .save ar.pfs, r34\n"
102 " .vframe r32\n"
103 " .save rp, r33\n"
104 " .body\n"
105 " .regstk 0,2,0,0\n"
106 " mov r12 = r32\n"
107 " mov ar.pfs = r34\n"
108 " mov b0 = r33\n"
109 " br.ret.sptk.many b0\n"
110 " .endp _init#\n"
111 "/*@_init_EPILOG_ENDS*/\n"
112 "\n"
113 "/*@_fini_PROLOG_BEGINS*/\n"
114 " .section .fini\n"
115 " .global _fini#\n"
116 " .proc _fini#\n"
117 "_fini:\n"
118 " .prologue\n"
119 " .save ar.pfs, r34\n"
120 " alloc r34 = ar.pfs, 0, 3, 0, 0\n"
121 " .vframe r32\n"
122 " mov r32 = r12\n"
123 " .save rp, r33\n"
124 " mov r33 = b0\n"
125 " .body\n"
126 " adds r12 = -16, r12\n"
127 " ;;\n"
128 " .endp _fini#\n"
129 "\n"
130 "/*@_fini_PROLOG_ENDS*/\n"
131 " br.call.sptk.many b0 = i_am_not_a_leaf# ;;\n"
132 " ;;\n"
133 "\n"
134 "/*@_fini_EPILOG_BEGINS*/\n"
135 " .section .fini\n"
136 " .proc _fini#\n"
137 "_fini:\n"
138 " .prologue\n"
139 " .save ar.pfs, r34\n"
140 " .vframe r32\n"
141 " .save rp, r33\n"
142 " .body\n"
143 " mov r12 = r32\n"
144 " mov ar.pfs = r34\n"
145 " mov b0 = r33\n"
146 " br.ret.sptk.many b0\n"
147 " .endp _fini#\n"
148 "\n"
149 "/*@_fini_EPILOG_ENDS*/\n"
150 "\n"
151 "/*@TRAILER_BEGINS*/\n"