^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* $Id: memcpy.S,v 1.3 2001/07/27 11:50:52 gniibe Exp $
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * "memcpy" implementation of SuperH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 1999 Niibe Yutaka
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * void *memcpy(void *dst, const void *src, size_t n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * No overlap between the memory of DST and of SRC are assumed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/linkage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) ENTRY(memcpy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) tst r6,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) bt/s 9f ! if n=0, do nothing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) mov r4,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) sub r4,r5 ! From here, r5 has the distance to r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) add r6,r0 ! From here, r0 points the end of copying point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) mov #12,r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) cmp/gt r6,r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) bt/s 7f ! if it's too small, copy a byte at once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) add #-1,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) add #1,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) ! From here, r6 is free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) ! r4 --> [ ... ] DST [ ... ] SRC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ! [ ... ] [ ... ]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) ! : :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ! r0 --> [ ... ] r0+r5 --> [ ... ]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) mov r5,r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) mov #3,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) and r2,r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) shll2 r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) mov r0,r3 ! Save the value on R0 to R3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) mova jmptable,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) add r1,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) mov.l @r0,r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) jmp @r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) mov r3,r0 ! and back to R0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .balign 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) jmptable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .long case0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .long case1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .long case2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .long case3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ! copy a byte at once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 7: mov r4,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) add #1,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) cmp/hi r2,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) mov.b @(r0,r5),r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) bt/s 8b ! while (r0>r2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) mov.b r1,@-r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 9:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) rts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) case0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) ! GHIJ KLMN OPQR --> GHIJ KLMN OPQR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ! First, align to long word boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) mov r0,r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) and r2,r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) tst r3,r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) bt/s 2f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) add #-4,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) add #3,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 1: dt r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) mov.b @(r0,r5),r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) bf/s 1b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) mov.b r1,@-r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) add #-3,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 2: ! Second, copy a long word at once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) mov r4,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) add #7,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 3: mov.l @(r0,r5),r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) cmp/hi r2,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) bt/s 3b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) mov.l r1,@-r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) ! Third, copy a byte at once, if necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) cmp/eq r4,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) bt/s 9b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) add #3,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) bra 8b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) add #-6,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) case1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ! GHIJ KLMN OPQR --> ...G HIJK LMNO PQR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) ! First, align to long word boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) mov r0,r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) and r2,r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) tst r3,r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) bt/s 2f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) add #-1,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 1: dt r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) mov.b @(r0,r5),r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) bf/s 1b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) mov.b r1,@-r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 2: ! Second, read a long word and write a long word at once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) mov.l @(r0,r5),r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) add #-4,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) mov r4,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) add #7,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #ifdef __LITTLE_ENDIAN__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 3: mov r1,r3 ! RQPO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) shll16 r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) shll8 r3 ! Oxxx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) mov.l @(r0,r5),r1 ! NMLK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) mov r1,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) shlr8 r6 ! xNML
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) or r6,r3 ! ONML
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) cmp/hi r2,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) bt/s 3b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) mov.l r3,@-r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 3: mov r1,r3 ! OPQR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) shlr16 r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) shlr8 r3 ! xxxO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) mov.l @(r0,r5),r1 ! KLMN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) mov r1,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) shll8 r6 ! LMNx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) or r6,r3 ! LMNO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) cmp/hi r2,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) bt/s 3b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) mov.l r3,@-r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ! Third, copy a byte at once, if necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) cmp/eq r4,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) bt/s 9b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) add #4,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) bra 8b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) add #-6,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) case2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ! GHIJ KLMN OPQR --> ..GH IJKL MNOP QR..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ! First, align to word boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) tst #1,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) bt/s 2f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) add #-1,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) mov.b @(r0,r5),r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) mov.b r1,@-r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 2: ! Second, read a word and write a word at once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) add #-1,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) mov r4,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) add #3,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 3: mov.w @(r0,r5),r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) cmp/hi r2,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) bt/s 3b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) mov.w r1,@-r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) ! Third, copy a byte at once, if necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) cmp/eq r4,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) bt/s 9b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) add #1,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) mov.b @(r0,r5),r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) rts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) mov.b r1,@-r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) case3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) ! GHIJ KLMN OPQR --> .GHI JKLM NOPQ R...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ! First, align to long word boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) mov r0,r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) and r2,r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) tst r3,r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) bt/s 2f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) add #-1,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 1: dt r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) mov.b @(r0,r5),r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) bf/s 1b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) mov.b r1,@-r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 2: ! Second, read a long word and write a long word at once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) add #-2,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) mov.l @(r0,r5),r1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) add #-4,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) mov r4,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) add #7,r2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #ifdef __LITTLE_ENDIAN__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 3: mov r1,r3 ! RQPO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) shll8 r3 ! QPOx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) mov.l @(r0,r5),r1 ! NMLK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) mov r1,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) shlr16 r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) shlr8 r6 ! xxxN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) or r6,r3 ! QPON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) cmp/hi r2,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) bt/s 3b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) mov.l r3,@-r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 3: mov r1,r3 ! OPQR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) shlr8 r3 ! xOPQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) mov.l @(r0,r5),r1 ! KLMN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) mov r1,r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) shll16 r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) shll8 r6 ! Nxxx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) or r6,r3 ! NOPQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) cmp/hi r2,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) bt/s 3b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) mov.l r3,@-r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) ! Third, copy a byte at once, if necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) cmp/eq r4,r0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) bt/s 9b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) add #6,r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) bra 8b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) add #-6,r2