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