xref: /openbmc/linux/arch/s390/kernel/mcount.S (revision feac8c8b)
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/ptrace.h>
13#include <asm/export.h>
14
15	.section .kprobes.text, "ax"
16
17ENTRY(ftrace_stub)
18	br	%r14
19
20#define STACK_FRAME_SIZE  (STACK_FRAME_OVERHEAD + __PT_SIZE)
21#define STACK_PTREGS	  (STACK_FRAME_OVERHEAD)
22#define STACK_PTREGS_GPRS (STACK_PTREGS + __PT_GPRS)
23#define STACK_PTREGS_PSW  (STACK_PTREGS + __PT_PSW)
24
25ENTRY(_mcount)
26	br	%r14
27
28EXPORT_SYMBOL(_mcount)
29
30ENTRY(ftrace_caller)
31	.globl	ftrace_regs_caller
32	.set	ftrace_regs_caller,ftrace_caller
33	lgr	%r1,%r15
34#ifndef CC_USING_HOTPATCH
35	aghi	%r0,MCOUNT_RETURN_FIXUP
36#endif
37	aghi	%r15,-STACK_FRAME_SIZE
38	stg	%r1,__SF_BACKCHAIN(%r15)
39	stg	%r1,(STACK_PTREGS_GPRS+15*8)(%r15)
40	stg	%r0,(STACK_PTREGS_PSW+8)(%r15)
41	stmg	%r2,%r14,(STACK_PTREGS_GPRS+2*8)(%r15)
42#ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
43	aghik	%r2,%r0,-MCOUNT_INSN_SIZE
44	lgrl	%r4,function_trace_op
45	lgrl	%r1,ftrace_trace_function
46#else
47	lgr	%r2,%r0
48	aghi	%r2,-MCOUNT_INSN_SIZE
49	larl	%r4,function_trace_op
50	lg	%r4,0(%r4)
51	larl	%r1,ftrace_trace_function
52	lg	%r1,0(%r1)
53#endif
54	lgr	%r3,%r14
55	la	%r5,STACK_PTREGS(%r15)
56	basr	%r14,%r1
57#ifdef CONFIG_FUNCTION_GRAPH_TRACER
58# The j instruction gets runtime patched to a nop instruction.
59# See ftrace_enable_ftrace_graph_caller.
60ENTRY(ftrace_graph_caller)
61	j	ftrace_graph_caller_end
62	lg	%r2,(STACK_PTREGS_GPRS+14*8)(%r15)
63	lg	%r3,(STACK_PTREGS_PSW+8)(%r15)
64	brasl	%r14,prepare_ftrace_return
65	stg	%r2,(STACK_PTREGS_GPRS+14*8)(%r15)
66ftrace_graph_caller_end:
67	.globl	ftrace_graph_caller_end
68#endif
69	lg	%r1,(STACK_PTREGS_PSW+8)(%r15)
70	lmg	%r2,%r15,(STACK_PTREGS_GPRS+2*8)(%r15)
71	br	%r1
72
73#ifdef CONFIG_FUNCTION_GRAPH_TRACER
74
75ENTRY(return_to_handler)
76	stmg	%r2,%r5,32(%r15)
77	lgr	%r1,%r15
78	aghi	%r15,-STACK_FRAME_OVERHEAD
79	stg	%r1,__SF_BACKCHAIN(%r15)
80	brasl	%r14,ftrace_return_to_handler
81	aghi	%r15,STACK_FRAME_OVERHEAD
82	lgr	%r14,%r2
83	lmg	%r2,%r5,32(%r15)
84	br	%r14
85
86#endif
87