1 /* 64 bit S/390-specific implementation of profiling support.
2 Copyright (C) 2001-2024 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 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
21 /* How profiling works on 64 bit S/390:
22 On the start of each function _mcount is called with the address of a
23 data word in %r1 (initialized to 0, used for counting). The compiler
24 with the option -p generates code of the form:
40 The _mcount implementation now has to call __mcount_internal with the
41 address of .LP0 as first parameter and the return address as second
42 parameter. &.LP0 was loaded to %r1 and the return address is in %r14.
43 _mcount may not modify any register.
45 Alternatively, at the start of each function __fentry__ is called using a
51 instruction. In this case %r0 points to the callee, and %r14 points to the
52 caller. These values need to be passed to __mcount_internal using the same
53 sequence as for _mcount, so the code below is shared between both functions.
54 The only major difference is that __fentry__ cannot return through %r0, in
55 which the return address is located, because br instruction is a no-op with
56 this register. Therefore %r1, which is clobbered by the PLT anyway, is
59 #define xglue(x, y) x ## y
60 #define glue(x, y) xglue(x, y)
62 .globl
C_SYMBOL_NAME(MCOUNT_SYMBOL
)
63 .type
C_SYMBOL_NAME(MCOUNT_SYMBOL
), @function
66 C_LABEL(MCOUNT_SYMBOL
)
67 cfi_return_column (glue(r
, MCOUNT_CALLEE_REG
))
68 /* Save the caller-clobbered registers. */
70 cfi_adjust_cfa_offset (224)
71 /* binutils 2.28+: .cfi_val_offset r15, -160 */
73 /* DW_CFA_val_offset */ 0x14, \
75 /* scaled offset */ 0x14
76 stmg
%r14
,%r5
,160(%r15
)
77 cfi_offset (r14
, -224)
78 cfi_offset (r0
, -224+16)
79 lg
%r2
,MCOUNT_CALLER_OFF(%r15
) # callers address = 1st param
80 lgr
%r3
,glue(%r
, MCOUNT_CALLEE_REG
) # callees address = 2nd param
83 brasl
%r14
,__mcount_internal@PLT
85 brasl
%r14
,__mcount_internal
88 /* Pop the saved registers. Please note that `mcount' has no
90 lmg
%r14
,%r5
,160(%r15
)
92 cfi_adjust_cfa_offset (-224)
93 #if MCOUNT_RETURN_REG != MCOUNT_CALLEE_REG
94 lgr
glue(%r
, MCOUNT_RETURN_REG
),glue(%r
, MCOUNT_CALLEE_REG
)
96 br
glue(%r
, MCOUNT_RETURN_REG
)
98 ASM_SIZE_DIRECTIVE(C_SYMBOL_NAME(MCOUNT_SYMBOL
))