File Index
Files and directories
Sign in
FILE

test-kprobes-asm.S

File preview with syntax highlighting.

linux-6.19.14/arch/riscv/kernel/tests/kprobes/test-kprobes-asm.S GAS
  1/* SPDX-License-Identifier: GPL-2.0+ */
  2
  3#include <linux/linkage.h>
  4#include <asm/asm.h>
  5#include "test-kprobes.h"
  6
  7SYM_FUNC_START(test_kprobes_add)
  8	li a1, KPROBE_TEST_MAGIC_UPPER
  9	li a2, KPROBE_TEST_MAGIC_LOWER
 10test_kprobes_add_addr1:
 11	add a1, a1, a2
 12test_kprobes_add_addr2:
 13	add a0, a1, x0
 14	ret
 15SYM_FUNC_END(test_kprobes_add)
 16
 17SYM_FUNC_START(test_kprobes_jal)
 18	li a0, 0
 19	mv a1, ra
 20	.option push
 21	.option norvc
 22test_kprobes_jal_addr1:
 23	jal x0, 2f
 24	ret
 25	.option pop
 261:	li a0, KPROBE_TEST_MAGIC_UPPER
 27	ret
 28	.option push
 29	.option norvc
 30test_kprobes_jal_addr2:
 312:	jal 1b
 32	.option pop
 33	li a2, KPROBE_TEST_MAGIC_LOWER
 34	add a0, a0, a2
 35	jr a1
 36SYM_FUNC_END(test_kprobes_jal)
 37
 38SYM_FUNC_START(test_kprobes_jalr)
 39	la a0, 1f
 40	mv a1, ra
 41	.option push
 42	.option norvc
 43test_kprobes_jalr_addr:
 44	jalr a0
 45	.option pop
 46	li t0, KPROBE_TEST_MAGIC_UPPER
 47	add a0, a0, t0
 48	jr a1
 491:	li a0, KPROBE_TEST_MAGIC_LOWER
 50	ret
 51SYM_FUNC_END(test_kprobes_jalr)
 52
 53SYM_FUNC_START(test_kprobes_auipc)
 54test_kprobes_auipc_addr:
 55	auipc a0, KPROBE_TEST_MAGIC_LOWER
 56	la a1, test_kprobes_auipc_addr
 57	sub a0, a0, a1
 58	srli a0, a0, 12
 59	li a1, KPROBE_TEST_MAGIC_UPPER
 60	add a0, a0, a1
 61	ret
 62SYM_FUNC_END(test_kprobes_auipc)
 63
 64SYM_FUNC_START(test_kprobes_branch)
 65	.option push
 66	.option norvc
 67	li a0, 0
 68	li a1, 1
 69	li a2, 2
 70test_kprobes_branch_addr1:
 71	beqz a0, 1f
 72	ret
 731:
 74test_kprobes_branch_addr2:
 75	beqz a1, 3f
 76test_kprobes_branch_addr3:
 77	bnez a0, 3f
 78test_kprobes_branch_addr4:
 79	bnez a2, 1f
 80	ret
 811:
 82test_kprobes_branch_addr5:
 83	bge a1, a2, 3f
 84test_kprobes_branch_addr6:
 85	bge a2, a1, 2f
 86	ret
 871:
 88	li t0, KPROBE_TEST_MAGIC_UPPER
 89	add a0, a0, t0
 90	ret
 912:
 92test_kprobes_branch_addr7:
 93	blt a2, a1, 3f
 94	li a0, KPROBE_TEST_MAGIC_LOWER
 95test_kprobes_branch_addr8:
 96	blt a1, a2, 1b
 973:
 98	li a0, 0
 99	ret
100	.option pop
101SYM_FUNC_END(test_kprobes_branch)
102
103#ifdef CONFIG_RISCV_ISA_C
104
105SYM_FUNC_START(test_kprobes_c_j)
106	li a0, 0
107test_kprobes_branch_c_j_addr1:
108	c.j 2f
1091:
110	li a1, KPROBE_TEST_MAGIC_UPPER
111	add a0, a0, a1
112	ret
1132:	li a0, KPROBE_TEST_MAGIC_LOWER
114test_kprobes_branch_c_j_addr2:
115	c.j 1b
116SYM_FUNC_END(test_kprobes_c_j)
117
118SYM_FUNC_START(test_kprobes_c_jr)
119	la a0, 2f
120test_kprobes_c_jr_addr1:
121	c.jr a0
122	ret
1231:	li a1, KPROBE_TEST_MAGIC_LOWER
124	add a0, a0, a1
125	ret
1262:
127	li a0, KPROBE_TEST_MAGIC_UPPER
128	la a1, 1b
129test_kprobes_c_jr_addr2:
130	c.jr a1
131SYM_FUNC_END(test_kprobes_c_jr)
132
133SYM_FUNC_START(test_kprobes_c_jalr)
134	mv a1, ra
135	la a0, 1f
136test_kprobes_c_jalr_addr:
137	c.jalr a0
138	li a2, KPROBE_TEST_MAGIC_UPPER
139	add a0, a0, a2
140	jr a1
1411:	li a0, KPROBE_TEST_MAGIC_LOWER
142	ret
143SYM_FUNC_END(test_kprobes_c_jalr)
144
145SYM_FUNC_START(test_kprobes_c_beqz)
146	li a0, 0
147	li a1, 1
148test_kprobes_c_beqz_addr1:
149	c.beqz a0, 2f
150	ret
1511:	li a1, KPROBE_TEST_MAGIC_UPPER
152	add a0, a0, a1
153	ret
154test_kprobes_c_beqz_addr2:
1552:	c.beqz a1, 3f
156	li a0, KPROBE_TEST_MAGIC_LOWER
157	mv a1, x0
158test_kprobes_c_beqz_addr3:
159	c.beqz a1, 1b
1603:	li a0, 0
161	ret
162SYM_FUNC_END(test_kprobes_c_beqz)
163
164SYM_FUNC_START(test_kprobes_c_bnez)
165	li a0, 0
166	li a1, 1
167test_kprobes_c_bnez_addr1:
168	c.bnez a1, 2f
169	ret
1701:	li a1, KPROBE_TEST_MAGIC_UPPER
171	add a0, a0, a1
172	ret
173test_kprobes_c_bnez_addr2:
1742:	c.bnez a0, 3f
175	li a0, KPROBE_TEST_MAGIC_LOWER
176test_kprobes_c_bnez_addr3:
177	c.bnez a0, 1b
1783:	li a0, 0
179	ret
180SYM_FUNC_END(test_kprobes_c_bnez)
181
182#endif /* CONFIG_RISCV_ISA_C */
183
184.section .rodata
185SYM_DATA_START(test_kprobes_addresses)
186	RISCV_PTR test_kprobes_add_addr1
187	RISCV_PTR test_kprobes_add_addr2
188	RISCV_PTR test_kprobes_jal_addr1
189	RISCV_PTR test_kprobes_jal_addr2
190	RISCV_PTR test_kprobes_jalr_addr
191	RISCV_PTR test_kprobes_auipc_addr
192	RISCV_PTR test_kprobes_branch_addr1
193	RISCV_PTR test_kprobes_branch_addr2
194	RISCV_PTR test_kprobes_branch_addr3
195	RISCV_PTR test_kprobes_branch_addr4
196	RISCV_PTR test_kprobes_branch_addr5
197	RISCV_PTR test_kprobes_branch_addr6
198	RISCV_PTR test_kprobes_branch_addr7
199	RISCV_PTR test_kprobes_branch_addr8
200#ifdef CONFIG_RISCV_ISA_C
201	RISCV_PTR test_kprobes_branch_c_j_addr1
202	RISCV_PTR test_kprobes_branch_c_j_addr2
203	RISCV_PTR test_kprobes_c_jr_addr1
204	RISCV_PTR test_kprobes_c_jr_addr2
205	RISCV_PTR test_kprobes_c_jalr_addr
206	RISCV_PTR test_kprobes_c_beqz_addr1
207	RISCV_PTR test_kprobes_c_beqz_addr2
208	RISCV_PTR test_kprobes_c_beqz_addr3
209	RISCV_PTR test_kprobes_c_bnez_addr1
210	RISCV_PTR test_kprobes_c_bnez_addr2
211	RISCV_PTR test_kprobes_c_bnez_addr3
212#endif /* CONFIG_RISCV_ISA_C */
213	RISCV_PTR 0
214SYM_DATA_END(test_kprobes_addresses)
215
216.section .rodata
217SYM_DATA_START(test_kprobes_functions)
218	RISCV_PTR test_kprobes_add
219	RISCV_PTR test_kprobes_jal
220	RISCV_PTR test_kprobes_jalr
221	RISCV_PTR test_kprobes_auipc
222	RISCV_PTR test_kprobes_branch
223#ifdef CONFIG_RISCV_ISA_C
224	RISCV_PTR test_kprobes_c_j
225	RISCV_PTR test_kprobes_c_jr
226	RISCV_PTR test_kprobes_c_jalr
227	RISCV_PTR test_kprobes_c_beqz
228	RISCV_PTR test_kprobes_c_bnez
229#endif /* CONFIG_RISCV_ISA_C */
230	RISCV_PTR 0
231SYM_DATA_END(test_kprobes_functions)
~/ Read-only file preview.