4 ! by Toshiyasu Morita (tm@netcom.com)
5 ! hacked by J"orn Rernnecke (joern.rennecke@superh.com) ("o for o-umlaut)
6 ! SH5 code Copyright 2002 SuperH Ltd.
8 ! Entry: ARG0: destination pointer
12 ! Exit: RESULT: destination pointer
13 ! any other registers in the range r0-r7: trashed
15 ! Notes: Usually one wants to do small reads and write a longword, but
16 ! unfortunately it is difficult in some cases to concatanate bytes
17 ! into a longword on the SH, so this does a longword read and small
20 ! This implementation makes two assumptions about how it is called:
22 ! 1.: If the byte count is nonzero, the address of the last byte to be
23 ! copied is unsigned greater than the address of the first byte to
24 ! be copied. This could be easily swapped for a signed comparison,
25 ! but the algorithm used needs some comparison.
27 ! 2.: When there are two or three bytes in the last word of an 11-or-more
28 ! bytes memory chunk to b copied, the rest of the word can be read
29 ! without side effects.
30 ! This could be easily changed by increasing the minumum size of
31 ! a fast memcpy and the amount subtracted from r7 before L_2l_loop be 2,
32 ! however, this would cost a few extra cyles on average.
33 ! For SHmedia, the assumption is that any quadword can be read in its
34 ! enirety if at least one byte is included in the copy.
36 /* Imported into Linux kernel by Richard Curnow. This is used to implement the
37 __copy_user function in the general case, so it has to be a distinct
38 function from intra-kernel memcpy to allow for exception fix-ups in the
39 event that the user pointer is bad somewhere in the copy (e.g. due to
40 running off the end of the vma).
42 Note, this algorithm will be slightly wasteful in the case where the source
43 and destination pointers are equally aligned, because the stlo/sthi pairs
44 could then be merged back into single stores. If there are a lot of cache
45 misses, this is probably offset by the stall lengths on the preloads.
49 .section .text..SHmedia32,"ax"
52 .global copy_user_memcpy
53 .global copy_user_memcpy_end
56 #define LDUAQ(P,O,D0,D1) ldlo.q P,O,D0; ldhi.q P,O+7,D1
57 #define STUAQ(P,O,D0,D1) stlo.q P,O,D0; sthi.q P,O+7,D1
58 #define LDUAL(P,O,D0,D1) ldlo.l P,O,D0; ldhi.l P,O+3,D1
59 #define STUAL(P,O,D0,D1) stlo.l P,O,D0; sthi.l P,O+3,D1
67 movi (L1-L0+63*32 + 1) & 0xffff,r1
75 /* Rearranged to make cut2 safe */
77 L4_7: /* 4..7 byte memcpy cntd. */
85 L1: /* 0 byte memcpy */
93 L2_3: /* 2 or 3 byte memcpy cntd. */
102 L8_15: /* 8..15 byte memcpy cntd. */
109 /* 2 or 3 byte memcpy */
119 /* 4 .. 7 byte memcpy */
120 LDUAL (r3, 0, r0, r1)
128 /* 8 .. 15 byte memcpy */
129 LDUAQ (r3, 0, r0, r1)
137 /* 16 .. 24 byte memcpy */
138 LDUAQ (r3, 0, r0, r1)
139 LDUAQ (r3, 8, r8, r9)
162 movi 64+8, r27 ! could subtract r7 from that.
212 copy_user_memcpy_end: