Back to index

glibc  2.9
initfini.c
Go to the documentation of this file.
00001 /* Special .init and .fini section support for HPPA
00002    Copyright (C) 2000, 2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    In addition to the permissions in the GNU Lesser General Public
00011    License, the Free Software Foundation gives you unlimited
00012    permission to link the compiled version of this file with other
00013    programs, and to distribute those programs without any restriction
00014    coming from the use of this file. (The GNU Lesser General Public
00015    License restrictions do apply in other respects; for example, they
00016    cover modification of the file, and distribution when not linked
00017    into another program.)
00018 
00019    Note that people who make modified versions of this file are not
00020    obligated to grant this special exception for their modified
00021    versions; it is their choice whether to do so. The GNU Lesser
00022    General Public License gives permission to release a modified
00023    version without this exception; this exception also makes it
00024    possible to release a modified version which carries forward this
00025    exception.
00026 
00027    The GNU C Library is distributed in the hope that it will be useful,
00028    but WITHOUT ANY WARRANTY; without even the implied warranty of
00029    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00030    Lesser General Public License for more details.
00031 
00032    You should have received a copy of the GNU Lesser General Public
00033    License along with the GNU C Library; if not, write to the Free
00034    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00035    02111-1307 USA.  */
00036 
00037 /* This file is compiled into assembly code which is then munged by a sed
00038    script into two files: crti.s and crtn.s.
00039 
00040    * crti.s puts a function prologue at the beginning of the
00041    .init and .fini sections and defines global symbols for
00042    those addresses, so they can be called as functions.
00043 
00044    * crtn.s puts the corresponding function epilogues
00045    in the .init and .fini sections. */
00046 
00047 /* If we use the standard C version, the linkage table pointer won't
00048    be properly preserved due to the splitting up of function prologues
00049    and epilogues.  Therefore we write these in assembly to make sure
00050    they do the right thing.
00051 
00052    Note that we cannot have a weak undefined __gmon_start__, because
00053    that would require this to be PIC, and the linker is currently not
00054    able to generate a proper procedure descriptor for _init.  Sad but
00055    true.  Anyway, HPPA is one of those horrible architectures where
00056    making the comparison and indirect call is quite expensive (see the
00057    comment in sysdeps/generic/initfini.c). */
00058 
00059 __asm__ ("\
00060 \n\
00061 #include \"defs.h\"\n\
00062 \n\
00063 /*@HEADER_ENDS*/\n\
00064 \n\
00065 /*@_init_PROLOG_BEGINS*/\n\
00066        .section .init\n\
00067        .align 4\n\
00068        .globl _init\n\
00069        .type _init,@function\n\
00070 _init:\n\
00071        stw    %rp,-20(%sp)\n\
00072        stwm   %r4,64(%sp)\n\
00073        stw    %r19,-32(%sp)\n\
00074        bl     __gmon_start__,%rp\n\
00075        copy   %r19,%r4      /* delay slot */\n\
00076        copy   %r4,%r19\n\
00077 /*@_init_PROLOG_ENDS*/\n\
00078 \n\
00079 /*@_init_EPILOG_BEGINS*/\n\
00080         .text\n\
00081         .align 4\n\
00082         .weak   __gmon_start__\n\
00083         .type    __gmon_start__,@function\n\
00084 __gmon_start__:\n\
00085        .proc\n\
00086        .callinfo\n\
00087        .entry\n\
00088         bv,n %r0(%r2)\n\
00089        .exit\n\
00090        .procend\n\
00091 \n\
00092 /* Here is the tail end of _init.  We put __gmon_start before this so\n\
00093    that the assembler creates the .PARISC.unwind section for us, ie.\n\
00094    with the right attributes.  */\n\
00095        .section .init\n\
00096        ldw    -84(%sp),%rp\n\
00097        copy   %r4,%r19\n\
00098        bv     %r0(%rp)\n\
00099 _end_init:\n\
00100        ldwm   -64(%sp),%r4\n\
00101 \n\
00102 /* Our very own unwind info, because the assembler can't handle\n\
00103    functions split into two or more pieces.  */\n\
00104        .section .PARISC.unwind\n\
00105        .extern _init\n\
00106        .word  _init, _end_init\n\
00107        .byte  0x08, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08\n\
00108 \n\
00109 /*@_init_EPILOG_ENDS*/\n\
00110 \n\
00111 /*@_fini_PROLOG_BEGINS*/\n\
00112        .section .fini\n\
00113        .align 4\n\
00114        .globl _fini\n\
00115        .type _fini,@function\n\
00116 _fini:\n\
00117        stw    %rp,-20(%sp)\n\
00118        stwm   %r4,64(%sp)\n\
00119        stw    %r19,-32(%sp)\n\
00120        copy   %r19,%r4\n\
00121 /*@_fini_PROLOG_ENDS*/\n\
00122 \n\
00123 /*@_fini_EPILOG_BEGINS*/\n\
00124        .section .fini\n\
00125        ldw    -84(%sp),%rp\n\
00126        copy   %r4,%r19\n\
00127        bv     %r0(%rp)\n\
00128 _end_fini:\n\
00129        ldwm   -64(%sp),%r4\n\
00130 \n\
00131        .section .PARISC.unwind\n\
00132        .extern _fini\n\
00133        .word  _fini, _end_fini\n\
00134        .byte  0x08, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08\n\
00135 \n\
00136 /*@_fini_EPILOG_ENDS*/\n\
00137 \n\
00138 /*@TRAILER_BEGINS*/\
00139 ");