import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / sparc64 / lib / copy_in_user.S
1 /* copy_in_user.S: Copy from userspace to userspace.
2  *
3  * Copyright (C) 1999, 2000, 2004 David S. Miller (davem@redhat.com)
4  */
5
6 #include <asm/asi.h>
7
8 #define XCC xcc
9
10 #define EX(x,y)                 \
11 98:     x,y;                    \
12         .section .fixup;        \
13         .align 4;               \
14 99:     retl;                   \
15          mov 1, %o0;            \
16         .section __ex_table;    \
17         .align 4;               \
18         .word 98b, 99b;         \
19         .text;                  \
20         .align 4;
21
22         .register       %g2,#scratch
23         .register       %g3,#scratch
24
25         .text
26         .align  32
27
28         /* Don't try to get too fancy here, just nice and
29          * simple.  This is predominantly used for well aligned
30          * small copies in the compat layer.  It is also used
31          * to copy register windows around during thread cloning.
32          */
33
34         .globl  ___copy_in_user
35 ___copy_in_user:        /* %o0=dst, %o1=src, %o2=len */
36         /* Writing to %asi is _expensive_ so we hardcode it.
37          * Reading %asi to check for KERNEL_DS is comparatively
38          * cheap.
39          */
40         rd              %asi, %g1
41         cmp             %g1, ASI_AIUS
42         bne,pn          %icc, memcpy_user_stub
43          nop
44
45         cmp             %o2, 0
46         be,pn           %XCC, 85f
47          or             %o0, %o1, %o3
48         cmp             %o2, 16
49         bleu,a,pn       %XCC, 80f
50          or             %o3, %o2, %o3
51
52         /* 16 < len <= 64 */
53         andcc           %o3, 0x7, %g0
54         bne,pn          %XCC, 90f
55          sub            %o0, %o1, %o3
56
57         andn            %o2, 0x7, %o4
58         and             %o2, 0x7, %o2
59 1:      subcc           %o4, 0x8, %o4
60         EX(ldxa [%o1] %asi, %o5)
61         EX(stxa %o5, [%o1 + %o3] ASI_AIUS)
62         bgu,pt          %XCC, 1b
63          add            %o1, 0x8, %o1
64         andcc           %o2, 0x4, %g0
65         be,pt           %XCC, 1f
66          nop
67         sub             %o2, 0x4, %o2
68         EX(lduwa [%o1] %asi, %o5)
69         EX(stwa %o5, [%o1 + %o3] ASI_AIUS)
70         add             %o1, 0x4, %o1
71 1:      cmp             %o2, 0
72         be,pt           %XCC, 85f
73          nop
74         ba,pt           %xcc, 90f
75          nop
76
77 80:     /* 0 < len <= 16 */
78         andcc           %o3, 0x3, %g0
79         bne,pn          %XCC, 90f
80          sub            %o0, %o1, %o3
81
82 82:
83         subcc           %o2, 4, %o2
84         EX(lduwa [%o1] %asi, %g1)
85         EX(stwa %g1, [%o1 + %o3] ASI_AIUS)
86         bgu,pt          %XCC, 82b
87          add            %o1, 4, %o1
88
89 85:     retl
90          clr            %o0
91
92         .align  32
93 90:
94         subcc           %o2, 1, %o2
95         EX(lduba [%o1] %asi, %g1)
96         EX(stba %g1, [%o1 + %o3] ASI_AIUS)
97         bgu,pt          %XCC, 90b
98          add            %o1, 1, %o1
99         retl
100          clr            %o0
101
102         /* Act like copy_{to,in}_user(), ie. return zero instead
103          * of original destination pointer.  This is invoked when
104          * copy_{to,in}_user() finds that %asi is kernel space.
105          */
106         .globl          memcpy_user_stub
107 memcpy_user_stub:
108         save            %sp, -192, %sp
109         mov             %i0, %o0
110         mov             %i1, %o1
111         call            memcpy
112          mov            %i2, %o2
113         ret
114          restore        %g0, %g0, %o0