2 * memmove routine for Z8000
3 * Copyright (C) 2004 Christian Groessler <chris@groessler.org>
5 * Permission to use, copy, modify, and distribute this file
6 * for any purpose is hereby granted without fee, provided that
7 * the above copyright notice and this notice appears in all
10 * This file is distributed WITHOUT ANY WARRANTY; without even the implied
11 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 /* void *memmove(void *dest, const void *src, size_t length);
36 /* rr2 - length (high word ignored)
44 /* check for destructive overlap (src < dest && dest < src + length) */
47 jp ule,memmove_entry /* non-destructive, let memcpy do the work */
49 addl rr0,rr4 /* rr0 = src + length */
51 jp ult,memmove_entry /* non-destructive, let memcpy do the work */
53 /* set-up pointers to copy backwards, add (length - 1) */
54 addl rr4,rr2 /* src + length */
55 addl rr6,rr2 /* dest + length */
60 bitb rl7,#0 /* odd destination address? */
62 bitb rl5,#0 /* odd source address? */
68 jr nz,odd_copy /* src even, dest odd */
70 jr ov,finish /* jump if r5 is zero now */
74 ld r2,r3 /* remember length */
76 /* jr z,no_words it cannot be zero here */
83 bitb rl2,#0 /* odd length? */
87 lddb @rr6,@rr4,r2 /* yes, copy last byte */
102 #else /* above Z8001, below Z8002 */
112 ld r2,r7 /* buffer pointer return value */
122 /* check for destructive overlap (src < dest && dest < src + length) */
125 jp ule,memmove_entry /* non-destructive, let memcpy do the work */
127 add r0,r6 /* r0 = src + length */
129 jp ult,memmove_entry /* non-destructive, let memcpy do the work */
131 /* set-up pointers to copy backwards, add (length - 1) */
132 add r6,r5 /* src + length */
133 add r7,r5 /* dest + length */
137 /* check alignment */
138 bitb rl7,#0 /* odd destination address? */
140 bitb rl6,#0 /* odd source address? */
146 jr nz,odd_copy /* src even, dest odd */
148 jr ov,finish /* jump if r5 is zero now */
152 ld r4,r5 /* remember length */
154 /* jr z,no_words it cannot be zero here */
161 bitb rl4,#0 /* odd length? */
165 lddb @r7,@r6,r4 /* yes, copy last byte */