18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Just like strncpy() except that if a fault occurs during copying, 48c2ecf20Sopenharmony_ci * -EFAULT is returned. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Inputs: 78c2ecf20Sopenharmony_ci * in0: address of destination buffer 88c2ecf20Sopenharmony_ci * in1: address of string to be copied 98c2ecf20Sopenharmony_ci * in2: length of buffer in bytes 108c2ecf20Sopenharmony_ci * Outputs: 118c2ecf20Sopenharmony_ci * r8: -EFAULT in case of fault or number of bytes copied if no fault 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * Copyright (C) 1998-2001 Hewlett-Packard Co 148c2ecf20Sopenharmony_ci * Copyright (C) 1998-2001 David Mosberger-Tang <davidm@hpl.hp.com> 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * 00/03/06 D. Mosberger Fixed to return proper return value (bug found by 178c2ecf20Sopenharmony_ci * by Andreas Schwab <schwab@suse.de>). 188c2ecf20Sopenharmony_ci */ 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#include <asm/asmmacro.h> 218c2ecf20Sopenharmony_ci#include <asm/export.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ciGLOBAL_ENTRY(__strncpy_from_user) 248c2ecf20Sopenharmony_ci alloc r2=ar.pfs,3,0,0,0 258c2ecf20Sopenharmony_ci mov r8=0 268c2ecf20Sopenharmony_ci mov r9=in1 278c2ecf20Sopenharmony_ci ;; 288c2ecf20Sopenharmony_ci add r10=in1,in2 298c2ecf20Sopenharmony_ci cmp.eq p6,p0=r0,in2 308c2ecf20Sopenharmony_ci(p6) br.ret.spnt.many rp 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci // XXX braindead copy loop---this needs to be optimized 338c2ecf20Sopenharmony_ci.Loop1: 348c2ecf20Sopenharmony_ci EX(.Lexit, ld1 r8=[in1],1) 358c2ecf20Sopenharmony_ci ;; 368c2ecf20Sopenharmony_ci EX(.Lexit, st1 [in0]=r8,1) 378c2ecf20Sopenharmony_ci cmp.ne p6,p7=r8,r0 388c2ecf20Sopenharmony_ci ;; 398c2ecf20Sopenharmony_ci(p6) cmp.ne.unc p8,p0=in1,r10 408c2ecf20Sopenharmony_ci(p8) br.cond.dpnt.few .Loop1 418c2ecf20Sopenharmony_ci ;; 428c2ecf20Sopenharmony_ci(p6) mov r8=in2 // buffer filled up---return buffer length 438c2ecf20Sopenharmony_ci(p7) sub r8=in1,r9,1 // return string length (excluding NUL character) 448c2ecf20Sopenharmony_ci[.Lexit:] 458c2ecf20Sopenharmony_ci br.ret.sptk.many rp 468c2ecf20Sopenharmony_ciEND(__strncpy_from_user) 478c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__strncpy_from_user) 48