2.9
[glibc/nacl-glibc.git] / sysdeps / s390 / s390-32 / s390-mcount.S
blob6d11f9bbdbd577cf37680776d456527dc48c9ef7
1 /* S/390-specific implemetation of profiling support.
2    Copyright (C) 2000, 2001 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com)
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, write to the Free
18    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
21 #include <sysdep.h>
24  * How profiling works on S/390:
25  * On the start of each function _mcount is called with the address of a
26  * data word in %r1 (initialized to 0, used for counting). The compiler
27  * with the option -p generates code of the form:
28  *
29  *         STM    6,15,24(15)
30  *         BRAS   13,.LTN0_0
31  * .LT0_0:
32  * .LC12:  .long  _mcount
33  * .LC13:  .long  .LP0
34  *         .data
35  *         .align 4
36  * .LP0:   .long  0
37  *         .text
38  * # function profiler
39  *         st     14,4(15)
40  *         l      14,.LC12-.LT0_0(13)
41  *         l      1,.LC13-.LT0_0(13)
42  *         basr   14,14
43  *         l      14,4(15)
44  *
45  * The _mcount implementation now has to call __mcount_internal with the
46  * address of .LP0 as first parameter and the return address as second
47  * parameter. &.LP0 was loaded to %r1 and the return address is in %r14.
48  * _mcount may not modify any register.
49  */
51         ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(_mcount)
52         ASM_TYPE_DIRECTIVE(C_SYMBOL_NAME(_mcount), @function)
53         .align ALIGNARG(4)
54 C_LABEL(_mcount)
55         /* Save the caller-clobbered registers.  */
56         ahi   %r15,-128
57         stm   %r14,%r5,96(%r15)
58         l     %r2,132(%r15)       # callers address  = first parameter
59         la    %r2,0(%r2)          # clear bit 0
60         la    %r3,0(%r14)         # callees address  = second parameter
62 #ifdef PIC
63         bras  %r14,0f
64         .long _GLOBAL_OFFSET_TABLE_-.
65 0:      al    %r14,0(%r14)
66         l     %r14,__mcount_internal@GOT(%r14)
67 #else
68         bras  %r14,0f
69         .long __mcount_internal
70 0:      l     %r14,0(%r14)
71 #endif
72         basr  %r14,%r14
74         /*
75          * Pop the saved registers.  Please note that `mcount' has no
76          * return value.
77          */
78         lm    %r14,%r5,96(%r15)
79         ahi   %r15,128
80         br    %r14
81         ASM_SIZE_DIRECTIVE(C_SYMBOL_NAME(_mcount))
83 #undef mcount
84 weak_alias (_mcount, mcount)