Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / arch / unicore32 / lib / strnlen_user.S
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * linux/arch/unicore32/lib/strnlen_user.S
4  *
5  * Code specific to PKUnity SoC and UniCore ISA
6  *
7  * Copyright (C) 2001-2010 GUAN Xue-tao
8  */
9 #include <linux/linkage.h>
10 #include <asm/assembler.h>
11 #include <asm/errno.h>
12
13         .text
14         .align  5
15
16 /* Prototype: unsigned long __strnlen_user(const char *str, long n)
17  * Purpose  : get length of a string in user memory
18  * Params   : str - address of string in user memory
19  * Returns  : length of string *including terminator*
20  *            or zero on exception, or n + 1 if too long
21  */
22 ENTRY(__strnlen_user)
23         mov     r2, r0
24 1:
25         ldrusr  r3, r0, 1
26         cxor.a  r3, #0
27         beq     2f
28         sub.a   r1, r1, #1
29         bne     1b
30         add     r0, r0, #1
31 2:      sub     r0, r0, r2
32         mov     pc, lr
33 ENDPROC(__strnlen_user)
34
35         .pushsection .fixup,"ax"
36         .align  0
37 9001:   mov     r0, #0
38         mov     pc, lr
39         .popsection