]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/s390/s390-64/s390x-mcount.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / s390 / s390-64 / s390x-mcount.h
1 /* 64 bit S/390-specific implementation of profiling support.
2 Copyright (C) 2001-2021 Free Software Foundation, Inc.
3 Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com)
4 This file is part of the GNU C Library.
5
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.
10
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.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20 #include <sysdep.h>
21
22 /* How profiling works on 64 bit S/390:
23 On the start of each function _mcount is called with the address of a
24 data word in %r1 (initialized to 0, used for counting). The compiler
25 with the option -p generates code of the form:
26
27 STM 6,15,24(15)
28 BRAS 13,.LTN0_0
29 .LT0_0:
30 .LC13: .long .LP0
31 .data
32 .align 4
33 .LP0: .long 0
34 .text
35 # function profiler
36 stg 14,8(15)
37 lg 1,.LC13-.LT0_0(13)
38 brasl 14,_mcount
39 lg 14,8(15)
40
41 The _mcount implementation now has to call __mcount_internal with the
42 address of .LP0 as first parameter and the return address as second
43 parameter. &.LP0 was loaded to %r1 and the return address is in %r14.
44 _mcount may not modify any register.
45
46 Alternatively, at the start of each function __fentry__ is called using a
47 single
48
49 # function profiler
50 brasl 0,__fentry__
51
52 instruction. In this case %r0 points to the callee, and %r14 points to the
53 caller. These values need to be passed to __mcount_internal using the same
54 sequence as for _mcount, so the code below is shared between both functions.
55 The only major difference is that __fentry__ cannot return through %r0, in
56 which the return address is located, because br instruction is a no-op with
57 this register. Therefore %r1, which is clobbered by the PLT anyway, is
58 used. */
59
60 #define xglue(x, y) x ## y
61 #define glue(x, y) xglue(x, y)
62
63 .globl C_SYMBOL_NAME(MCOUNT_SYMBOL)
64 .type C_SYMBOL_NAME(MCOUNT_SYMBOL), @function
65 cfi_startproc
66 .align ALIGNARG(4)
67 C_LABEL(MCOUNT_SYMBOL)
68 cfi_return_column (glue(r, MCOUNT_CALLEE_REG))
69 /* Save the caller-clobbered registers. */
70 aghi %r15,-224
71 cfi_adjust_cfa_offset (224)
72 /* binutils 2.28+: .cfi_val_offset r15, -160 */
73 .cfi_escape \
74 /* DW_CFA_val_offset */ 0x14, \
75 /* r15 */ 0x0f, \
76 /* scaled offset */ 0x14
77 stmg %r14,%r5,160(%r15)
78 cfi_offset (r14, -224)
79 cfi_offset (r0, -224+16)
80 lg %r2,MCOUNT_CALLER_OFF(%r15) # callers address = 1st param
81 lgr %r3,glue(%r, MCOUNT_CALLEE_REG) # callees address = 2nd param
82
83 #ifdef PIC
84 brasl %r14,__mcount_internal@PLT
85 #else
86 brasl %r14,__mcount_internal
87 #endif
88
89 /* Pop the saved registers. Please note that `mcount' has no
90 return value. */
91 lmg %r14,%r5,160(%r15)
92 aghi %r15,224
93 cfi_adjust_cfa_offset (-224)
94 #if MCOUNT_RETURN_REG != MCOUNT_CALLEE_REG
95 lgr glue(%r, MCOUNT_RETURN_REG),glue(%r, MCOUNT_CALLEE_REG)
96 #endif
97 br glue(%r, MCOUNT_RETURN_REG)
98 cfi_endproc
99 ASM_SIZE_DIRECTIVE(C_SYMBOL_NAME(MCOUNT_SYMBOL))