xref: /openbmc/linux/arch/s390/kernel/mcount.S (revision 9726bfcd)
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright IBM Corp. 2008, 2009
4 *
5 *   Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>,
6 *
7 */
8
9#include <linux/linkage.h>
10#include <asm/asm-offsets.h>
11#include <asm/ftrace.h>
12#include <asm/nospec-insn.h>
13#include <asm/ptrace.h>
14#include <asm/export.h>
15
16	GEN_BR_THUNK %r1
17	GEN_BR_THUNK %r14
18
19	.section .kprobes.text, "ax"
20
21ENTRY(ftrace_stub)
22	BR_EX	%r14
23ENDPROC(ftrace_stub)
24
25#define STACK_FRAME_SIZE  (STACK_FRAME_OVERHEAD + __PT_SIZE)
26#define STACK_PTREGS	  (STACK_FRAME_OVERHEAD)
27#define STACK_PTREGS_GPRS (STACK_PTREGS + __PT_GPRS)
28#define STACK_PTREGS_PSW  (STACK_PTREGS + __PT_PSW)
29
30ENTRY(_mcount)
31	BR_EX	%r14
32ENDPROC(_mcount)
33EXPORT_SYMBOL(_mcount)
34
35ENTRY(ftrace_caller)
36	.globl	ftrace_regs_caller
37	.set	ftrace_regs_caller,ftrace_caller
38	lgr	%r1,%r15
39#if !(defined(CC_USING_HOTPATCH) || defined(CC_USING_NOP_MCOUNT))
40	aghi	%r0,MCOUNT_RETURN_FIXUP
41#endif
42	aghi	%r15,-STACK_FRAME_SIZE
43	stg	%r1,__SF_BACKCHAIN(%r15)
44	stg	%r1,(STACK_PTREGS_GPRS+15*8)(%r15)
45	stg	%r0,(STACK_PTREGS_PSW+8)(%r15)
46	stmg	%r2,%r14,(STACK_PTREGS_GPRS+2*8)(%r15)
47#ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
48	aghik	%r2,%r0,-MCOUNT_INSN_SIZE
49	lgrl	%r4,function_trace_op
50	lgrl	%r1,ftrace_trace_function
51#else
52	lgr	%r2,%r0
53	aghi	%r2,-MCOUNT_INSN_SIZE
54	larl	%r4,function_trace_op
55	lg	%r4,0(%r4)
56	larl	%r1,ftrace_trace_function
57	lg	%r1,0(%r1)
58#endif
59	lgr	%r3,%r14
60	la	%r5,STACK_PTREGS(%r15)
61	BASR_EX	%r14,%r1
62#ifdef CONFIG_FUNCTION_GRAPH_TRACER
63# The j instruction gets runtime patched to a nop instruction.
64# See ftrace_enable_ftrace_graph_caller.
65	.globl ftrace_graph_caller
66ftrace_graph_caller:
67	j	ftrace_graph_caller_end
68	lmg	%r2,%r3,(STACK_PTREGS_GPRS+14*8)(%r15)
69	lg	%r4,(STACK_PTREGS_PSW+8)(%r15)
70	brasl	%r14,prepare_ftrace_return
71	stg	%r2,(STACK_PTREGS_GPRS+14*8)(%r15)
72ftrace_graph_caller_end:
73	.globl	ftrace_graph_caller_end
74#endif
75	lg	%r1,(STACK_PTREGS_PSW+8)(%r15)
76	lmg	%r2,%r15,(STACK_PTREGS_GPRS+2*8)(%r15)
77	BR_EX	%r1
78ENDPROC(ftrace_caller)
79
80#ifdef CONFIG_FUNCTION_GRAPH_TRACER
81
82ENTRY(return_to_handler)
83	stmg	%r2,%r5,32(%r15)
84	lgr	%r1,%r15
85	aghi	%r15,-STACK_FRAME_OVERHEAD
86	stg	%r1,__SF_BACKCHAIN(%r15)
87	brasl	%r14,ftrace_return_to_handler
88	aghi	%r15,STACK_FRAME_OVERHEAD
89	lgr	%r14,%r2
90	lmg	%r2,%r5,32(%r15)
91	BR_EX	%r14
92ENDPROC(return_to_handler)
93
94#endif
95