/*1* internal version of memcpy(), issued by the compiler to copy blocks of2* data around. This is really memmove() - it has to be able to deal with3* possible overlaps, because that ambiguity is when the compiler gives up4* and calls a function. We have our own, internal version so that we get5* something we trust, even if the user has redefined the normal symbol.6*7* Copyright 2004-2009 Analog Devices Inc.8*9* Licensed under the ADI BSD license or the GPL-2 (or later)10*/1112#include <linux/linkage.h>1314/* void *memcpy(void *dest, const void *src, size_t n);15* R0 = To Address (dest) (leave unchanged to form result)16* R1 = From Address (src)17* R2 = count18*19* Note: Favours word alignment20*/2122#ifdef CONFIG_MEMCPY_L123.section .l1.text24#else25.text26#endif2728.align 22930ENTRY(_memcpy)31CC = R2 <= 0; /* length not positive? */32IF CC JUMP .L_P1L2147483647; /* Nothing to do */3334P0 = R0 ; /* dst*/35P1 = R1 ; /* src*/36P2 = R2 ; /* length */3738/* check for overlapping data */39CC = R1 < R0; /* src < dst */40IF !CC JUMP .Lno_overlap;41R3 = R1 + R2;42CC = R0 < R3; /* and dst < src+len */43IF CC JUMP .Lhas_overlap;4445.Lno_overlap:46/* Check for aligned data.*/4748R3 = R1 | R0;49R1 = 0x3;50R3 = R3 & R1;51CC = R3; /* low bits set on either address? */52IF CC JUMP .Lnot_aligned;5354/* Both addresses are word-aligned, so we can copy55at least part of the data using word copies.*/56P2 = P2 >> 2;57CC = P2 <= 2;58IF !CC JUMP .Lmore_than_seven;59/* less than eight bytes... */60P2 = R2;61LSETUP(.Lthree_start, .Lthree_end) LC0=P2;62.Lthree_start:63R3 = B[P1++] (X);64.Lthree_end:65B[P0++] = R3;6667RTS;6869.Lmore_than_seven:70/* There's at least eight bytes to copy. */71P2 += -1; /* because we unroll one iteration */72LSETUP(.Lword_loops, .Lword_loope) LC0=P2;73I1 = P1;74R3 = [I1++];75#if ANOMALY_0500020276.Lword_loops:77[P0++] = R3;78.Lword_loope:79R3 = [I1++];80#else81.Lword_loops:82.Lword_loope:83MNOP || [P0++] = R3 || R3 = [I1++];84#endif85[P0++] = R3;86/* Any remaining bytes to copy? */87R3 = 0x3;88R3 = R2 & R3;89CC = R3 == 0;90P1 = I1; /* in case there's something left, */91IF !CC JUMP .Lbytes_left;92RTS;93.Lbytes_left: P2 = R3;94.Lnot_aligned:95/* From here, we're copying byte-by-byte. */96LSETUP (.Lbyte_start, .Lbyte_end) LC0=P2;97.Lbyte_start:98R1 = B[P1++] (X);99.Lbyte_end:100B[P0++] = R1;101102.L_P1L2147483647:103RTS;104105.Lhas_overlap:106/* Need to reverse the copying, because the107* dst would clobber the src.108* Don't bother to work out alignment for109* the reverse case.110*/111P0 = P0 + P2;112P0 += -1;113P1 = P1 + P2;114P1 += -1;115LSETUP(.Lover_start, .Lover_end) LC0=P2;116.Lover_start:117R1 = B[P1--] (X);118.Lover_end:119B[P0--] = R1;120121RTS;122123ENDPROC(_memcpy)124125126