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