2e3234a2aa266e25d23e7d46d70792a639db5e45
[platform/upstream/glibc.git] / sysdeps / ia64 / elf / initfini.c
1 /* Special .init and .fini section support for ia64.
2    Copyright (C) 2000, 2002 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
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.
9
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.
14
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.  */
19
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.
22
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.
26
27    * crtn.s puts the corresponding function epilogues
28    in the .init and .fini sections. */
29
30 __asm__ ("\n\
31 \n\
32 #include \"defs.h\"\n\
33 \n\
34 /*@HEADER_ENDS*/\n\
35 \n\
36 /*@_init_PROLOG_BEGINS*/\n\
37         .section .init\n\
38         .align 16\n\
39         .global _init#\n\
40         .proc _init#\n\
41 _init:\n\
42         alloc r34 = ar.pfs, 0, 3, 0, 0\n\
43         mov r32 = r12\n\
44         mov r33 = b0\n\
45         adds r12 = -16, r12\n\
46         addl r14 = @ltoff(@fptr(__gmon_start__#)), gp\n\
47         ;;\n\
48         ld8 r15 = [r14]\n\
49         ;;\n\
50         cmp.eq p6, p7 = 0, r15\n\
51         (p6) br.cond.dptk .L5\n\
52 \n\
53 /* we could use r35 to save gp, but we use the stack since that's what\n\
54  * all the other init routines will do --davidm 00/04/05 */\n\
55         st8 [r12] = gp, -16\n\
56         br.call.sptk.many b0 = __gmon_start__# ;;\n\
57         adds r12 = 16, r12\n\
58         ;;\n\
59         ld8 gp = [r12]\n\
60         ;;\n\
61 .L5:\n\
62         .align 16\n\
63         .endp _init#\n\
64 \n\
65 /*@_init_PROLOG_ENDS*/\n\
66 \n\
67 /*@_init_EPILOG_BEGINS*/\n\
68         .section .init\n\
69         .regstk 0,2,0,0\n\
70         mov r12 = r32\n\
71         mov ar.pfs = r34\n\
72         mov b0 = r33\n\
73         br.ret.sptk.many b0\n\
74         .endp _init#\n\
75 /*@_init_EPILOG_ENDS*/\n\
76 \n\
77 /*@_fini_PROLOG_BEGINS*/\n\
78         .section .fini\n\
79         .align 16\n\
80         .global _fini#\n\
81         .proc _fini#\n\
82 _fini:\n\
83         alloc r34 = ar.pfs, 0, 3, 0, 0\n\
84         mov r32 = r12\n\
85         mov r33 = b0\n\
86         adds r12 = -16, r12\n\
87         ;;\n\
88         .align 16\n\
89         .endp _fini#\n\
90 \n\
91 /*@_fini_PROLOG_ENDS*/\n\
92         br.call.sptk.many b0 = i_am_not_a_leaf# ;;\n\
93         ;;\n\
94 \n\
95 /*@_fini_EPILOG_BEGINS*/\n\
96         .section .fini\n\
97         mov r12 = r32\n\
98         mov ar.pfs = r34\n\
99         mov b0 = r33\n\
100         br.ret.sptk.many b0\n\
101         .endp _fini#\n\
102 \n\
103 /*@_fini_EPILOG_ENDS*/\n\
104 \n\
105 /*@TRAILER_BEGINS*/\n\
106         .weak   __gmon_start__#\n\
107 ");