1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 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 5 * strlen. 6 * 7 * Inputs: 8 * in0: address of buffer 9 * in1: string length limit N 10 * Outputs: 11 * r8: 0 in case of fault, strlen(buffer)+1 otherwise 12 * 13 * Copyright (C) 1999, 2001 David Mosberger-Tang <davidm@hpl.hp.com> 14 */ 15 16#include <linux/export.h> 17#include <asm/asmmacro.h> 18 19GLOBAL_ENTRY(__strnlen_user) 20 .prologue 21 alloc r2=ar.pfs,2,0,0,0 22 .save ar.lc, r16 23 mov r16=ar.lc // preserve ar.lc 24 25 .body 26 27 add r3=-1,in1 28 ;; 29 mov ar.lc=r3 30 mov r9=0 31 ;; 32 // XXX braindead strlen loop---this needs to be optimized 33.Loop1: 34 EXCLR(.Lexit, ld1 r8=[in0],1) 35 add r9=1,r9 36 ;; 37 cmp.eq p6,p0=r8,r0 38(p6) br.cond.dpnt .Lexit 39 br.cloop.dptk.few .Loop1 40 41 add r9=1,in1 // NUL not found---return N+1 42 ;; 43.Lexit: 44 mov r8=r9 45 mov ar.lc=r16 // restore ar.lc 46 br.ret.sptk.many rp 47END(__strnlen_user) 48EXPORT_SYMBOL(__strnlen_user) 49