1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Returns 0 if exception before NUL or reaching the supplied limit (N),
4 * a value greater than N if the string is longer than the limit, else
8 * in0: address of buffer
9 * in1: string length limit N
11 * r8: 0 in case of fault, strlen(buffer)+1 otherwise
13 * Copyright (C) 1999, 2001 David Mosberger-Tang <davidm@hpl.hp.com>
16 #include <asm/asmmacro.h>
17 #include <asm/export.h>
19 GLOBAL_ENTRY(__strnlen_user)
21 alloc r2=ar.pfs,2,0,0,0
23 mov r16=ar.lc // preserve ar.lc
32 // XXX braindead strlen loop---this needs to be optimized
34 EXCLR(.Lexit, ld1 r8=[in0],1)
38 (p6) br.cond.dpnt .Lexit
39 br.cloop.dptk.few .Loop1
41 add r9=1,in1 // NUL not found---return N+1
45 mov ar.lc=r16 // restore ar.lc
48 EXPORT_SYMBOL(__strnlen_user)