1/*
2 * trampoline entry and return code for kretprobes.
3 */
4
5#include <linux/linkage.h>
6#include <asm/asm-offsets.h>
7#include <asm/assembler.h>
8
9	.text
10
11	.macro	save_all_base_regs
12	stp x0, x1, [sp, #S_X0]
13	stp x2, x3, [sp, #S_X2]
14	stp x4, x5, [sp, #S_X4]
15	stp x6, x7, [sp, #S_X6]
16	stp x8, x9, [sp, #S_X8]
17	stp x10, x11, [sp, #S_X10]
18	stp x12, x13, [sp, #S_X12]
19	stp x14, x15, [sp, #S_X14]
20	stp x16, x17, [sp, #S_X16]
21	stp x18, x19, [sp, #S_X18]
22	stp x20, x21, [sp, #S_X20]
23	stp x22, x23, [sp, #S_X22]
24	stp x24, x25, [sp, #S_X24]
25	stp x26, x27, [sp, #S_X26]
26	stp x28, x29, [sp, #S_X28]
27	add x0, sp, #S_FRAME_SIZE
28	stp lr, x0, [sp, #S_LR]
29	/*
30	 * Construct a useful saved PSTATE
31	 */
32	mrs x0, nzcv
33	mrs x1, daif
34	orr x0, x0, x1
35	mrs x1, CurrentEL
36	orr x0, x0, x1
37	mrs x1, SPSel
38	orr x0, x0, x1
39	stp xzr, x0, [sp, #S_PC]
40	.endm
41
42	.macro	restore_all_base_regs
43	ldr x0, [sp, #S_PSTATE]
44	and x0, x0, #(PSR_N_BIT | PSR_Z_BIT | PSR_C_BIT | PSR_V_BIT)
45	msr nzcv, x0
46	ldp x0, x1, [sp, #S_X0]
47	ldp x2, x3, [sp, #S_X2]
48	ldp x4, x5, [sp, #S_X4]
49	ldp x6, x7, [sp, #S_X6]
50	ldp x8, x9, [sp, #S_X8]
51	ldp x10, x11, [sp, #S_X10]
52	ldp x12, x13, [sp, #S_X12]
53	ldp x14, x15, [sp, #S_X14]
54	ldp x16, x17, [sp, #S_X16]
55	ldp x18, x19, [sp, #S_X18]
56	ldp x20, x21, [sp, #S_X20]
57	ldp x22, x23, [sp, #S_X22]
58	ldp x24, x25, [sp, #S_X24]
59	ldp x26, x27, [sp, #S_X26]
60	ldp x28, x29, [sp, #S_X28]
61	.endm
62
63ENTRY(kretprobe_trampoline)
64	sub sp, sp, #S_FRAME_SIZE
65
66	save_all_base_regs
67
68	mov x0, sp
69	bl trampoline_probe_handler
70	/*
71	 * Replace trampoline address in lr with actual orig_ret_addr return
72	 * address.
73	 */
74	mov lr, x0
75
76	restore_all_base_regs
77
78	add sp, sp, #S_FRAME_SIZE
79	ret
80
81ENDPROC(kretprobe_trampoline)
82