/*1* User Space Access Routines2*3* Copyright (C) 2000-2002 Hewlett-Packard (John Marvin)4* Copyright (C) 2000 Richard Hirst <rhirst with parisc-linux.org>5* Copyright (C) 2001 Matthieu Delahaye <delahaym at esiee.fr>6* Copyright (C) 2003 Randolph Chung <tausq with parisc-linux.org>7*8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2, or (at your option)12* any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, write to the Free Software21* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA22*/2324/*25* These routines still have plenty of room for optimization26* (word & doubleword load/store, dual issue, store hints, etc.).27*/2829/*30* The following routines assume that space register 3 (sr3) contains31* the space id associated with the current users address space.32*/333435.text3637#include <asm/assembly.h>38#include <asm/errno.h>39#include <linux/linkage.h>4041/*42* get_sr gets the appropriate space value into43* sr1 for kernel/user space access, depending44* on the flag stored in the task structure.45*/4647.macro get_sr48mfctl %cr30,%r149ldw TI_SEGMENT(%r1),%r2250mfsp %sr3,%r151or,<> %r22,%r0,%r052copy %r0,%r153mtsp %r1,%sr154.endm5556.macro fixup_branch lbl57ldil L%\lbl, %r158ldo R%\lbl(%r1), %r159bv %r0(%r1)60.endm6162/*63* long lstrncpy_from_user(char *dst, const char *src, long n)64*65* Returns -EFAULT if exception before terminator,66* N if the entire buffer filled,67* otherwise strlen (i.e. excludes zero byte)68*/6970ENTRY(lstrncpy_from_user)71.proc72.callinfo NO_CALLS73.entry74comib,= 0,%r24,$lsfu_done75copy %r24,%r2376get_sr771: ldbs,ma 1(%sr1,%r25),%r178$lsfu_loop:79stbs,ma %r1,1(%r26)80comib,=,n 0,%r1,$lsfu_done81addib,<>,n -1,%r24,$lsfu_loop822: ldbs,ma 1(%sr1,%r25),%r183$lsfu_done:84sub %r23,%r24,%r2885$lsfu_exit:86bv %r0(%r2)87nop88.exit89ENDPROC(lstrncpy_from_user)9091.section .fixup,"ax"923: fixup_branch $lsfu_exit93ldi -EFAULT,%r2894.previous9596.section __ex_table,"aw"97ASM_ULONG_INSN 1b,3b98ASM_ULONG_INSN 2b,3b99.previous100101.procend102103/*104* unsigned long lclear_user(void *to, unsigned long n)105*106* Returns 0 for success.107* otherwise, returns number of bytes not transferred.108*/109110ENTRY(lclear_user)111.proc112.callinfo NO_CALLS113.entry114comib,=,n 0,%r25,$lclu_done115get_sr116$lclu_loop:117addib,<> -1,%r25,$lclu_loop1181: stbs,ma %r0,1(%sr1,%r26)119120$lclu_done:121bv %r0(%r2)122copy %r25,%r28123.exit124ENDPROC(lclear_user)125126.section .fixup,"ax"1272: fixup_branch $lclu_done128ldo 1(%r25),%r25129.previous130131.section __ex_table,"aw"132ASM_ULONG_INSN 1b,2b133.previous134135.procend136137/*138* long lstrnlen_user(char *s, long n)139*140* Returns 0 if exception before zero byte or reaching N,141* N+1 if N would be exceeded,142* else strlen + 1 (i.e. includes zero byte).143*/144145ENTRY(lstrnlen_user)146.proc147.callinfo NO_CALLS148.entry149comib,= 0,%r25,$lslen_nzero150copy %r26,%r24151get_sr1521: ldbs,ma 1(%sr1,%r26),%r1153$lslen_loop:154comib,=,n 0,%r1,$lslen_done155addib,<> -1,%r25,$lslen_loop1562: ldbs,ma 1(%sr1,%r26),%r1157$lslen_done:158bv %r0(%r2)159sub %r26,%r24,%r28160.exit161162$lslen_nzero:163b $lslen_done164ldo 1(%r26),%r26 /* special case for N == 0 */165ENDPROC(lstrnlen_user)166167.section .fixup,"ax"1683: fixup_branch $lslen_done169copy %r24,%r26 /* reset r26 so 0 is returned on fault */170.previous171172.section __ex_table,"aw"173ASM_ULONG_INSN 1b,3b174ASM_ULONG_INSN 2b,3b175.previous176177.procend178179.end180181182