2.9
[glibc/nacl-glibc.git] / sysdeps / s390 / s390-64 / s390x-mcount.S
blob78b55218a97dbb5434e6db8b5ffc29400249094e
1 /* 64 bit S/390-specific implemetation of profiling support.
2    Copyright (C) 2001 Free Software Foundation, Inc.
3    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com)
4    This file is part of the GNU C Library.
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>
23 /* How profiling works on 64 bit S/390:
24    On the start of each function _mcount is called with the address of a
25    data word in %r1 (initialized to 0, used for counting). The compiler
26    with the option -p generates code of the form:
27   
28            STM    6,15,24(15)
29            BRAS   13,.LTN0_0
30    .LT0_0: 
31    .LC13:  .long  .LP0
32            .data
33            .align 4
34    .LP0:   .long  0
35            .text
36    # function profiler
37            stg    14,4(15)
38            lg     1,.LC13-.LT0_0(13)
39            brasl  14,_mcount
40            lg     14,4(15)
41   
42    The _mcount implementation now has to call __mcount_internal with the
43    address of .LP0 as first parameter and the return address as second
44    parameter. &.LP0 was loaded to %r1 and the return address is in %r14.
45    _mcount may not modify any register.  */
47         ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(_mcount)
48         ASM_TYPE_DIRECTIVE(C_SYMBOL_NAME(_mcount), @function)
49         .align ALIGNARG(4)
50 C_LABEL(_mcount)
51         /* Save the caller-clobbered registers.  */
52         aghi  %r15,-224
53         stmg  %r14,%r5,160(%r15)
54         lg    %r2,232(%r15)       # callers address  = first parameter
55         la    %r2,0(%r2)          # clear bit 0
56         la    %r3,0(%r14)         # callees address  = second parameter
58 #ifdef PIC
59         brasl %r14,__mcount_internal@PLT
60 #else
61         brasl %r14,__mcount_internal
62 #endif
64         /* Pop the saved registers.  Please note that `mcount' has no
65            return value.  */
66         lmg   %r14,%r5,160(%r15)
67         aghi   %r15,224
68         br    %r14
69         ASM_SIZE_DIRECTIVE(C_SYMBOL_NAME(_mcount))
71 #undef mcount
72 weak_alias (_mcount, mcount)