1 /* copy_user.S: Sparc optimized copy_from_user and copy_to_user code.
3 * Copyright(C) 1995 Linus Torvalds
4 * Copyright(C) 1996 David S. Miller
5 * Copyright(C) 1996 Eddie C. Dost
6 * Copyright(C) 1996,1998 Jakub Jelinek
9 * e-mail between David and Eddie.
11 * Returns 0 if successful, otherwise count of bytes not copied yet
14 #include <asm/ptrace.h>
15 #include <asm/asmmacro.h>
17 #include <asm/thread_info.h>
19 /* Work around cpp -rob */
21 #define EXECINSTR #execinstr
24 .section .fixup,ALLOC,EXECINSTR; \
28 .section __ex_table,ALLOC; \
34 #define EX2(x,y,c,d,e,a,b) \
36 .section .fixup,ALLOC,EXECINSTR; \
41 .section __ex_table,ALLOC; \
49 .section __ex_table,ALLOC; \
55 #define EXT(start,end,handler) \
56 .section __ex_table,ALLOC; \
58 .word start, 0, end, handler; \
62 /* Please do not change following macros unless you change logic used
63 * in .fixup at the end of this file as well
66 /* Both these macros have to start with exactly the same insn */
67 #define MOVE_BIGCHUNK(src, dst, offset, t0, t1, t2, t3, t4, t5, t6, t7) \
68 ldd [%src + (offset) + 0x00], %t0; \
69 ldd [%src + (offset) + 0x08], %t2; \
70 ldd [%src + (offset) + 0x10], %t4; \
71 ldd [%src + (offset) + 0x18], %t6; \
72 st %t0, [%dst + (offset) + 0x00]; \
73 st %t1, [%dst + (offset) + 0x04]; \
74 st %t2, [%dst + (offset) + 0x08]; \
75 st %t3, [%dst + (offset) + 0x0c]; \
76 st %t4, [%dst + (offset) + 0x10]; \
77 st %t5, [%dst + (offset) + 0x14]; \
78 st %t6, [%dst + (offset) + 0x18]; \
79 st %t7, [%dst + (offset) + 0x1c];
81 #define MOVE_BIGALIGNCHUNK(src, dst, offset, t0, t1, t2, t3, t4, t5, t6, t7) \
82 ldd [%src + (offset) + 0x00], %t0; \
83 ldd [%src + (offset) + 0x08], %t2; \
84 ldd [%src + (offset) + 0x10], %t4; \
85 ldd [%src + (offset) + 0x18], %t6; \
86 std %t0, [%dst + (offset) + 0x00]; \
87 std %t2, [%dst + (offset) + 0x08]; \
88 std %t4, [%dst + (offset) + 0x10]; \
89 std %t6, [%dst + (offset) + 0x18];
91 #define MOVE_LASTCHUNK(src, dst, offset, t0, t1, t2, t3) \
92 ldd [%src - (offset) - 0x10], %t0; \
93 ldd [%src - (offset) - 0x08], %t2; \
94 st %t0, [%dst - (offset) - 0x10]; \
95 st %t1, [%dst - (offset) - 0x0c]; \
96 st %t2, [%dst - (offset) - 0x08]; \
97 st %t3, [%dst - (offset) - 0x04];
99 #define MOVE_HALFCHUNK(src, dst, offset, t0, t1, t2, t3) \
100 lduh [%src + (offset) + 0x00], %t0; \
101 lduh [%src + (offset) + 0x02], %t1; \
102 lduh [%src + (offset) + 0x04], %t2; \
103 lduh [%src + (offset) + 0x06], %t3; \
104 sth %t0, [%dst + (offset) + 0x00]; \
105 sth %t1, [%dst + (offset) + 0x02]; \
106 sth %t2, [%dst + (offset) + 0x04]; \
107 sth %t3, [%dst + (offset) + 0x06];
109 #define MOVE_SHORTCHUNK(src, dst, offset, t0, t1) \
110 ldub [%src - (offset) - 0x02], %t0; \
111 ldub [%src - (offset) - 0x01], %t1; \
112 stb %t0, [%dst - (offset) - 0x02]; \
113 stb %t1, [%dst - (offset) - 0x01];
118 .globl __copy_user_begin
127 EXO2(ldub [%o1], %g2)
134 EXO2(lduh [%o1], %g2)
141 EXO2(lduh [%o1], %g2)
148 __copy_user: /* %o0=dst %o1=src %o2=len */
156 bleu short_aligned_end
172 andcc %g1, 0xffffff80, %g7
178 MOVE_BIGCHUNK(o1, o0, 0x00, o2, o3, o4, o5, g2, g3, g4, g5)
179 MOVE_BIGCHUNK(o1, o0, 0x20, o2, o3, o4, o5, g2, g3, g4, g5)
180 MOVE_BIGCHUNK(o1, o0, 0x40, o2, o3, o4, o5, g2, g3, g4, g5)
181 MOVE_BIGCHUNK(o1, o0, 0x60, o2, o3, o4, o5, g2, g3, g4, g5)
190 be copy_user_table_end
193 sethi %hi(copy_user_table_end), %o5
198 jmpl %o5 + %lo(copy_user_table_end), %g0
202 MOVE_LASTCHUNK(o1, o0, 0x60, g2, g3, g4, g5)
203 MOVE_LASTCHUNK(o1, o0, 0x50, g2, g3, g4, g5)
204 MOVE_LASTCHUNK(o1, o0, 0x40, g2, g3, g4, g5)
205 MOVE_LASTCHUNK(o1, o0, 0x30, g2, g3, g4, g5)
206 MOVE_LASTCHUNK(o1, o0, 0x20, g2, g3, g4, g5)
207 MOVE_LASTCHUNK(o1, o0, 0x10, g2, g3, g4, g5)
208 MOVE_LASTCHUNK(o1, o0, 0x00, g2, g3, g4, g5)
210 EXT(copy_user_table, copy_user_table_end, 51f)
214 EX(ldd [%o1], %g2, and %g1, 0xf)
217 EX(st %g2, [%o0 - 0x08], and %g1, 0xf)
218 EX2(st %g3, [%o0 - 0x04], and %g1, 0xf, %g1, sub %g1, 4)
223 EX(ld [%o1], %g2, and %g1, 7)
225 EX(st %g2, [%o0], and %g1, 7)
231 EX(lduh [%o1], %g2, and %g1, 3)
233 EX(sth %g2, [%o0], and %g1, 3)
239 EX(ldub [%o1], %g2, add %g0, 1)
240 EX(stb %g2, [%o0], add %g0, 1)
246 MOVE_BIGALIGNCHUNK(o1, o0, 0x00, o2, o3, o4, o5, g2, g3, g4, g5)
247 MOVE_BIGALIGNCHUNK(o1, o0, 0x20, o2, o3, o4, o5, g2, g3, g4, g5)
248 MOVE_BIGALIGNCHUNK(o1, o0, 0x40, o2, o3, o4, o5, g2, g3, g4, g5)
249 MOVE_BIGALIGNCHUNK(o1, o0, 0x60, o2, o3, o4, o5, g2, g3, g4, g5)
251 EXT(ldd_std, 81b, 52f)
258 be copy_user_table_end
261 sethi %hi(copy_user_table_end), %o5
266 jmpl %o5 + %lo(copy_user_table_end), %g0
274 and %o2, 0xfffffff0, %o3
280 EXO2(ldub [%o1], %g2)
284 andcc %o2, 0xfffffff0, %o3
288 MOVE_HALFCHUNK(o1, o0, 0x00, g2, g3, g4, g5)
289 MOVE_HALFCHUNK(o1, o0, 0x08, g2, g3, g4, g5)
300 MOVE_SHORTCHUNK(o1, o0, -0x02, g2, g3)
301 MOVE_SHORTCHUNK(o1, o0, -0x04, g2, g3)
302 MOVE_SHORTCHUNK(o1, o0, -0x06, g2, g3)
303 MOVE_SHORTCHUNK(o1, o0, -0x08, g2, g3)
304 MOVE_SHORTCHUNK(o1, o0, -0x0a, g2, g3)
305 MOVE_SHORTCHUNK(o1, o0, -0x0c, g2, g3)
306 MOVE_SHORTCHUNK(o1, o0, -0x0e, g2, g3)
307 MOVE_SHORTCHUNK(o1, o0, -0x10, g2, g3)
309 EXT(byte_chunk, 83b, 54f)
318 sethi %hi(short_table_end), %o5
323 jmpl %o5 + %lo(short_table_end), %g0
326 MOVE_SHORTCHUNK(o1, o0, 0x0c, g2, g3)
327 MOVE_SHORTCHUNK(o1, o0, 0x0a, g2, g3)
328 MOVE_SHORTCHUNK(o1, o0, 0x08, g2, g3)
329 MOVE_SHORTCHUNK(o1, o0, 0x06, g2, g3)
330 MOVE_SHORTCHUNK(o1, o0, 0x04, g2, g3)
331 MOVE_SHORTCHUNK(o1, o0, 0x02, g2, g3)
332 MOVE_SHORTCHUNK(o1, o0, 0x00, g2, g3)
334 EXT(84b, short_table_end, 55f)
337 EX(ldub [%o1], %g2, add %g0, 1)
338 EX(stb %g2, [%o0], add %g0, 1)
350 EXO2(ld [%o1 + 0x00], %g2)
351 EXO2(ld [%o1 + 0x04], %g3)
353 EXO2(st %g2, [%o0 + 0x00])
354 EX(st %g3, [%o0 + 0x04], sub %o2, 4)
360 .section .fixup,#alloc,#execinstr
365 sethi %hi(PAGE_OFFSET), %g1
370 ld [%g6 + TI_PREEMPT], %g1
382 /* exception routine sets %g2 to (broken_insn - first_insn)>>2 */
384 /* This magic counts how many bytes are left when crash in MOVE_BIGCHUNK
385 * happens. This is derived from the amount ldd reads, st stores, etc.
387 * g3 = g1 + g7 - ((g2 / 12) * 32 + (x < 4) ? 0 : (x - 4) * 4);
388 * o0 += (g2 / 12) * 32;
409 60: and %g1, 0x7f, %g3
415 /* i = 41 - g2; j = i % 6;
416 * g3 = (g1 & 15) + (i / 6) * 16 + (j < 4) ? (j + 1) * 4 : 16;
417 * o0 -= (i / 6) * 16 + 16;
437 /* g3 = g1 + g7 - (g2 / 8) * 32 + (g2 & 4) ? (g2 & 3) * 8 : 0;
438 o0 += (g2 / 8) * 32 */
450 /* g3 = o3 + (o2 & 15) - (g2 & 8) - (g2 & 4) ? (g2 & 3) * 2 : 0;
464 /* g3 = o3 + (o2 & 15) - (g2 / 4) * 2 - (g2 & 2) ? (g2 & 1) : 0;
465 o0 += (g2 / 4) * 2 */
479 g3 = (o2 & 1) + i / 4 * 2 + !(i & 3);
480 o0 -= i / 4 * 2 + 1 */
495 .globl __copy_user_end