aboutsummaryrefslogtreecommitdiff
path: root/arch/riscv/lib/strrchr.S
blob: ac58b20ca21d15f073d14c4aa1cd73870b58030c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* SPDX-License-Identifier: GPL-2.0-only */

/*
 * Copyright (C) 2025 Feng Jiang <jiangfeng@kylinos.cn>
 */

#include <linux/linkage.h>
#include <asm/asm.h>

/* char *strrchr(const char *s, int c) */
SYM_FUNC_START(strrchr)
	/*
	 * Parameters
	 *	a0 - The string to be searched
	 *	a1 - The character to seaerch for
	 *
	 * Returns
	 *	a0 - Address of last occurrence of 'c' or 0
	 *
	 * Clobbers
	 *	t0, t1
	 */
	andi	a1, a1, 0xff
	mv	t1, a0
	li	a0, 0
1:
	lbu	t0, 0(t1)
	bne	t0, a1, 2f
	mv	a0, t1
2:
	addi	t1, t1, 1
	bnez	t0, 1b
	ret
SYM_FUNC_END(strrchr)

SYM_FUNC_ALIAS_WEAK(__pi_strrchr, strrchr)
EXPORT_SYMBOL(strrchr)