Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * User Space Access Routines |
| 3 | * |
| 4 | * Copyright (C) 2000-2002 Hewlett-Packard (John Marvin) |
| 5 | * Copyright (C) 2000 Richard Hirst <rhirst with parisc-linux.org> |
| 6 | * Copyright (C) 2001 Matthieu Delahaye <delahaym at esiee.fr> |
| 7 | * Copyright (C) 2003 Randolph Chung <tausq with parisc-linux.org> |
| 8 | * |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2, or (at your option) |
| 13 | * any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | * These routines still have plenty of room for optimization |
| 27 | * (word & doubleword load/store, dual issue, store hints, etc.). |
| 28 | */ |
| 29 | |
| 30 | /* |
| 31 | * The following routines assume that space register 3 (sr3) contains |
| 32 | * the space id associated with the current users address space. |
| 33 | */ |
| 34 | |
| 35 | |
Kyle McMartin | dfcf753 | 2008-05-22 14:36:31 -0400 | [diff] [blame] | 36 | .text |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <asm/assembly.h> |
| 39 | #include <asm/errno.h> |
Helge Deller | 0b3d643 | 2007-01-28 14:52:57 +0100 | [diff] [blame] | 40 | #include <linux/linkage.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * get_sr gets the appropriate space value into |
| 44 | * sr1 for kernel/user space access, depending |
| 45 | * on the flag stored in the task structure. |
| 46 | */ |
| 47 | |
| 48 | .macro get_sr |
| 49 | mfctl %cr30,%r1 |
| 50 | ldw TI_SEGMENT(%r1),%r22 |
| 51 | mfsp %sr3,%r1 |
| 52 | or,<> %r22,%r0,%r0 |
| 53 | copy %r0,%r1 |
| 54 | mtsp %r1,%sr1 |
| 55 | .endm |
| 56 | |
| 57 | .macro fixup_branch lbl |
| 58 | ldil L%\lbl, %r1 |
| 59 | ldo R%\lbl(%r1), %r1 |
| 60 | bv %r0(%r1) |
| 61 | .endm |
| 62 | |
| 63 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | * unsigned long lclear_user(void *to, unsigned long n) |
| 65 | * |
| 66 | * Returns 0 for success. |
| 67 | * otherwise, returns number of bytes not transferred. |
| 68 | */ |
| 69 | |
Helge Deller | 0b3d643 | 2007-01-28 14:52:57 +0100 | [diff] [blame] | 70 | ENTRY(lclear_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | .proc |
| 72 | .callinfo NO_CALLS |
| 73 | .entry |
| 74 | comib,=,n 0,%r25,$lclu_done |
| 75 | get_sr |
| 76 | $lclu_loop: |
| 77 | addib,<> -1,%r25,$lclu_loop |
| 78 | 1: stbs,ma %r0,1(%sr1,%r26) |
| 79 | |
| 80 | $lclu_done: |
| 81 | bv %r0(%r2) |
| 82 | copy %r25,%r28 |
| 83 | .exit |
Helge Deller | 0b3d643 | 2007-01-28 14:52:57 +0100 | [diff] [blame] | 84 | ENDPROC(lclear_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | .section .fixup,"ax" |
| 87 | 2: fixup_branch $lclu_done |
| 88 | ldo 1(%r25),%r25 |
| 89 | .previous |
| 90 | |
| 91 | .section __ex_table,"aw" |
Helge Deller | 0b3d643 | 2007-01-28 14:52:57 +0100 | [diff] [blame] | 92 | ASM_ULONG_INSN 1b,2b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | .previous |
| 94 | |
| 95 | .procend |
| 96 | |
| 97 | /* |
| 98 | * long lstrnlen_user(char *s, long n) |
| 99 | * |
| 100 | * Returns 0 if exception before zero byte or reaching N, |
| 101 | * N+1 if N would be exceeded, |
| 102 | * else strlen + 1 (i.e. includes zero byte). |
| 103 | */ |
| 104 | |
Helge Deller | 0b3d643 | 2007-01-28 14:52:57 +0100 | [diff] [blame] | 105 | ENTRY(lstrnlen_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | .proc |
| 107 | .callinfo NO_CALLS |
| 108 | .entry |
| 109 | comib,= 0,%r25,$lslen_nzero |
| 110 | copy %r26,%r24 |
| 111 | get_sr |
| 112 | 1: ldbs,ma 1(%sr1,%r26),%r1 |
| 113 | $lslen_loop: |
| 114 | comib,=,n 0,%r1,$lslen_done |
| 115 | addib,<> -1,%r25,$lslen_loop |
| 116 | 2: ldbs,ma 1(%sr1,%r26),%r1 |
| 117 | $lslen_done: |
| 118 | bv %r0(%r2) |
| 119 | sub %r26,%r24,%r28 |
| 120 | .exit |
| 121 | |
| 122 | $lslen_nzero: |
| 123 | b $lslen_done |
| 124 | ldo 1(%r26),%r26 /* special case for N == 0 */ |
Helge Deller | 0b3d643 | 2007-01-28 14:52:57 +0100 | [diff] [blame] | 125 | ENDPROC(lstrnlen_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
| 127 | .section .fixup,"ax" |
| 128 | 3: fixup_branch $lslen_done |
| 129 | copy %r24,%r26 /* reset r26 so 0 is returned on fault */ |
| 130 | .previous |
| 131 | |
| 132 | .section __ex_table,"aw" |
Helge Deller | 0b3d643 | 2007-01-28 14:52:57 +0100 | [diff] [blame] | 133 | ASM_ULONG_INSN 1b,3b |
| 134 | ASM_ULONG_INSN 2b,3b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | .previous |
| 136 | |
| 137 | .procend |
| 138 | |
| 139 | .end |