.
[glibc-ports.git] / sysdeps / hppa / elf / initfini.c
blob35f5dd52fe9e91aca2c6b393ff90716c7f22d365
1 /* Special .init and .fini section support for HPPA
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 /* If we use the standard C version, the linkage table pointer won't
48 be properly preserved due to the splitting up of function prologues
49 and epilogues. Therefore we write these in assembly to make sure
50 they do the right thing.
52 Note that we cannot have a weak undefined __gmon_start__, because
53 that would require this to be PIC, and the linker is currently not
54 able to generate a proper procedure descriptor for _init. Sad but
55 true. Anyway, HPPA is one of those horrible architectures where
56 making the comparison and indirect call is quite expensive (see the
57 comment in sysdeps/generic/initfini.c). */
59 __asm__ ("\
60 \n\
61 #include \"defs.h\"\n\
62 \n\
63 /*@HEADER_ENDS*/\n\
64 \n\
65 /*@_init_PROLOG_BEGINS*/\n\
66 .section .init\n\
67 .align 4\n\
68 .globl _init\n\
69 .type _init,@function\n\
70 _init:\n\
71 stw %rp,-20(%sp)\n\
72 stwm %r4,64(%sp)\n\
73 stw %r19,-32(%sp)\n\
74 bl __gmon_start__,%rp\n\
75 copy %r19,%r4 /* delay slot */\n\
76 copy %r4,%r19\n\
77 /*@_init_PROLOG_ENDS*/\n\
78 \n\
79 /*@_init_EPILOG_BEGINS*/\n\
80 .text\n\
81 .align 4\n\
82 .weak __gmon_start__\n\
83 .type __gmon_start__,@function\n\
84 __gmon_start__:\n\
85 .proc\n\
86 .callinfo\n\
87 .entry\n\
88 bv,n %r0(%r2)\n\
89 .exit\n\
90 .procend\n\
91 \n\
92 /* Here is the tail end of _init. We put __gmon_start before this so\n\
93 that the assembler creates the .PARISC.unwind section for us, ie.\n\
94 with the right attributes. */\n\
95 .section .init\n\
96 ldw -84(%sp),%rp\n\
97 copy %r4,%r19\n\
98 bv %r0(%rp)\n\
99 _end_init:\n\
100 ldwm -64(%sp),%r4\n\
102 /* Our very own unwind info, because the assembler can't handle\n\
103 functions split into two or more pieces. */\n\
104 .section .PARISC.unwind\n\
105 .extern _init\n\
106 .word _init, _end_init\n\
107 .byte 0x08, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08\n\
109 /*@_init_EPILOG_ENDS*/\n\
111 /*@_fini_PROLOG_BEGINS*/\n\
112 .section .fini\n\
113 .align 4\n\
114 .globl _fini\n\
115 .type _fini,@function\n\
116 _fini:\n\
117 stw %rp,-20(%sp)\n\
118 stwm %r4,64(%sp)\n\
119 stw %r19,-32(%sp)\n\
120 copy %r19,%r4\n\
121 /*@_fini_PROLOG_ENDS*/\n\
123 /*@_fini_EPILOG_BEGINS*/\n\
124 .section .fini\n\
125 ldw -84(%sp),%rp\n\
126 copy %r4,%r19\n\
127 bv %r0(%rp)\n\
128 _end_fini:\n\
129 ldwm -64(%sp),%r4\n\
131 .section .PARISC.unwind\n\
132 .extern _fini\n\
133 .word _fini, _end_fini\n\
134 .byte 0x08, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08\n\
136 /*@_fini_EPILOG_ENDS*/\n\
138 /*@TRAILER_BEGINS*/\