xref: /linux/arch/riscv/net/bpf_timed_may_goto.S (revision 5a8cd539ac19f7a68e68e1d25ef9ca2ff55b8500)
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (c) 2026 Feng Jiang <jiangfeng@kylinos.cn> */
3
4#include <linux/linkage.h>
5#include <asm/asm.h>
6
7/*
8 * Trampoline for the BPF timed may_goto loop bound. Custom calling convention:
9 *	- input:  stack offset in BPF_REG_AX (t0)
10 *	- output: updated count in BPF_REG_AX (t0)
11 *
12 * Calls bpf_check_timed_may_goto(ptr) with the standard RISC-V ABI, where
13 * ptr = BPF_REG_FP (s5) + BPF_REG_AX (t0). BPF R0-R5 (a5, a0-a4) are saved
14 * across the call; BPF_REG_FP (s5) is callee-saved and needs no saving.
15 */
16
17SYM_FUNC_START(arch_bpf_timed_may_goto)
18	addi	sp, sp, -(8*SZREG)
19	REG_S	ra, 7*SZREG(sp)
20	REG_S	s0, 6*SZREG(sp)
21	addi	s0, sp, 8*SZREG
22
23	/* Save BPF registers R0-R5 (a5, a0-a4) */
24	REG_S	a5, 5*SZREG(sp)
25	REG_S	a0, 4*SZREG(sp)
26	REG_S	a1, 3*SZREG(sp)
27	REG_S	a2, 2*SZREG(sp)
28	REG_S	a3, 1*SZREG(sp)
29	REG_S	a4, 0*SZREG(sp)
30
31	add	a0, t0, s5
32	call	bpf_check_timed_may_goto
33	mv	t0, a0
34
35	/* Restore BPF registers R0-R5 */
36	REG_L	a4, 0*SZREG(sp)
37	REG_L	a3, 1*SZREG(sp)
38	REG_L	a2, 2*SZREG(sp)
39	REG_L	a1, 3*SZREG(sp)
40	REG_L	a0, 4*SZREG(sp)
41	REG_L	a5, 5*SZREG(sp)
42
43	REG_L	s0, 6*SZREG(sp)
44	REG_L	ra, 7*SZREG(sp)
45	addi	sp, sp, 8*SZREG
46	ret
47SYM_FUNC_END(arch_bpf_timed_may_goto)
48