1/* 2Copyright (c) 2009 Nick Clifton <nickc@redhat.com> 3 */ 4#include <picolibc.h> 5 6 .file "memmove.S" 7 8 .section .text 9 .global _memmove 10 .type _memmove,@function 11_memmove: 12 ;; R1: DEST 13 ;; R2: SRC 14 ;; R3: COUNT 15#ifdef __RX_DISALLOW_STRING_INSNS__ 16 /* Do not use the string instructions - they might prefetch 17 bytes from outside of valid memory. This is particularly 18 dangerous in I/O space. */ 19 20 cmp #0, r3 ; If the count is zero, do nothing 21 beq 4f 22 23 cmp r1, r2 24 blt 3f ; If SRC < DEST copy backwards 25 26 mov r1, r14 ; Save a copy of DEST 27 285: mov.b [r2+], r5 29 mov.b r5, [r14+] 30 sub #1, r3 31 bne 5b 32 334: rts 34 353: add r3, r1 36 add r3, r2 37 386: mov.b [-r2], r5 39 mov.b r5, [-r1] 40 sub #1, r3 41 bne 6b 42 43 rts 44#else 45 mov r1, r4 ; Save a copy of DEST 46 cmp r1, r2 47 blt 2f ; If SRC (r2) is less than DEST (r1) then copy backwards 48 smovf 491: 50 mov r4, r1 ; Return DEST 51 rts 522: 53 add r3, r1 ; The SMOVB instructions requires the DEST in r1 and the 54 add r3, r2 ; SRC in r2 but it needs them to point the last bytes of 55 sub #1, r2 ; the regions involved not the first bytes, hence these 56 sub #1, r1 ; additions and subtractions. 57 smovb 58 bra 1b 59 60#endif /* SMOVF allowed. */ 61 62 .size _memmove, . - _memmove 63