xref: /openbmc/linux/arch/ia64/lib/strncpy_from_user.S (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1b2441318SGreg Kroah-Hartman/* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds/*
31da177e4SLinus Torvalds * Just like strncpy() except that if a fault occurs during copying,
41da177e4SLinus Torvalds * -EFAULT is returned.
51da177e4SLinus Torvalds *
61da177e4SLinus Torvalds * Inputs:
71da177e4SLinus Torvalds *	in0:	address of destination buffer
81da177e4SLinus Torvalds *	in1:	address of string to be copied
91da177e4SLinus Torvalds *	in2:	length of buffer in bytes
101da177e4SLinus Torvalds * Outputs:
111da177e4SLinus Torvalds *	r8:	-EFAULT in case of fault or number of bytes copied if no fault
121da177e4SLinus Torvalds *
131da177e4SLinus Torvalds * Copyright (C) 1998-2001 Hewlett-Packard Co
141da177e4SLinus Torvalds * Copyright (C) 1998-2001 David Mosberger-Tang <davidm@hpl.hp.com>
151da177e4SLinus Torvalds *
161da177e4SLinus Torvalds * 00/03/06 D. Mosberger Fixed to return proper return value (bug found by
171da177e4SLinus Torvalds *			 by Andreas Schwab <schwab@suse.de>).
181da177e4SLinus Torvalds */
191da177e4SLinus Torvalds
20*ab03e604SMasahiro Yamada#include <linux/export.h>
211da177e4SLinus Torvalds#include <asm/asmmacro.h>
221da177e4SLinus Torvalds
231da177e4SLinus TorvaldsGLOBAL_ENTRY(__strncpy_from_user)
241da177e4SLinus Torvalds	alloc r2=ar.pfs,3,0,0,0
251da177e4SLinus Torvalds	mov r8=0
261da177e4SLinus Torvalds	mov r9=in1
271da177e4SLinus Torvalds	;;
281da177e4SLinus Torvalds	add r10=in1,in2
291da177e4SLinus Torvalds	cmp.eq p6,p0=r0,in2
301da177e4SLinus Torvalds(p6)	br.ret.spnt.many rp
311da177e4SLinus Torvalds
321da177e4SLinus Torvalds	// XXX braindead copy loop---this needs to be optimized
331da177e4SLinus Torvalds.Loop1:
341da177e4SLinus Torvalds	EX(.Lexit, ld1 r8=[in1],1)
351da177e4SLinus Torvalds	;;
361da177e4SLinus Torvalds	EX(.Lexit, st1 [in0]=r8,1)
371da177e4SLinus Torvalds	cmp.ne p6,p7=r8,r0
381da177e4SLinus Torvalds	;;
391da177e4SLinus Torvalds(p6)	cmp.ne.unc p8,p0=in1,r10
401da177e4SLinus Torvalds(p8)	br.cond.dpnt.few .Loop1
411da177e4SLinus Torvalds	;;
421da177e4SLinus Torvalds(p6)	mov r8=in2		// buffer filled up---return buffer length
431da177e4SLinus Torvalds(p7)	sub r8=in1,r9,1		// return string length (excluding NUL character)
441da177e4SLinus Torvalds[.Lexit:]
451da177e4SLinus Torvalds	br.ret.sptk.many rp
461da177e4SLinus TorvaldsEND(__strncpy_from_user)
47e007c533SAl ViroEXPORT_SYMBOL(__strncpy_from_user)
48