Annotation of sys/arch/m68k/m68k/bcopy.s, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: bcopy.s,v 1.2 2003/06/02 23:27:48 millert Exp $ */
2: /* $NetBSD: bcopy.s,v 1.1 1997/03/17 19:44:33 gwr Exp $ */
3:
4: /*-
5: * Copyright (c) 1990 The Regents of the University of California.
6: * All rights reserved.
7: *
8: * This code is derived from software contributed to Berkeley by
9: * the Systems Programming Group of the University of Utah Computer
10: * Science Department.
11: *
12: * Redistribution and use in source and binary forms, with or without
13: * modification, are permitted provided that the following conditions
14: * are met:
15: * 1. Redistributions of source code must retain the above copyright
16: * notice, this list of conditions and the following disclaimer.
17: * 2. Redistributions in binary form must reproduce the above copyright
18: * notice, this list of conditions and the following disclaimer in the
19: * documentation and/or other materials provided with the distribution.
20: * 3. Neither the name of the University nor the names of its contributors
21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34: * SUCH DAMAGE.
35: */
36:
37: /*
38: * This is based on: src/lib/libc/arch/m68k/string/bcopy.S
39: * identified as: @(#)bcopy.s 5.1 (Berkeley) 5/12/90
40: */
41:
42: #include <machine/asm.h>
43:
44: .file "bcopy.s"
45: .text
46:
47: /*
48: * {ov}bcopy(from, to, len)
49: * memcpy(to, from, len)
50: *
51: * Works for counts up to 128K.
52: */
53: ALTENTRY(memmove, _memcpy)
54: ENTRY(memcpy)
55: movl sp@(12),d0 | get count
56: jeq Lbccpyexit | if zero, return
57: movl sp@(8), a0 | src address
58: movl sp@(4), a1 | dest address
59: jra Lbcdocopy | jump into bcopy
60: ALTENTRY(ovbcopy, _bcopy)
61: ENTRY(bcopy)
62: movl sp@(12),d0 | get count
63: jeq Lbccpyexit | if zero, return
64: movl sp@(4),a0 | src address
65: movl sp@(8),a1 | dest address
66: Lbcdocopy:
67: cmpl a1,a0 | src before dest?
68: jlt Lbccpyback | yes, copy backwards (avoids overlap)
69: movl a0,d1
70: btst #0,d1 | src address odd?
71: jeq Lbccfeven | no, go check dest
72: movb a0@+,a1@+ | yes, copy a byte
73: subql #1,d0 | update count
74: jeq Lbccpyexit | exit if done
75: Lbccfeven:
76: movl a1,d1
77: btst #0,d1 | dest address odd?
78: jne Lbccfbyte | yes, must copy by bytes
79: movl d0,d1 | no, get count
80: lsrl #2,d1 | convert to longwords
81: jeq Lbccfbyte | no longwords, copy bytes
82: subql #1,d1 | set up for dbf
83: Lbccflloop:
84: movl a0@+,a1@+ | copy longwords
85: dbf d1,Lbccflloop | til done
86: andl #3,d0 | get remaining count
87: jeq Lbccpyexit | done if none
88: Lbccfbyte:
89: subql #1,d0 | set up for dbf
90: Lbccfbloop:
91: movb a0@+,a1@+ | copy bytes
92: dbf d0,Lbccfbloop | til done
93: Lbccpyexit:
94: rts
95: Lbccpyback:
96: addl d0,a0 | add count to src
97: addl d0,a1 | add count to dest
98: movl a0,d1
99: btst #0,d1 | src address odd?
100: jeq Lbccbeven | no, go check dest
101: movb a0@-,a1@- | yes, copy a byte
102: subql #1,d0 | update count
103: jeq Lbccpyexit | exit if done
104: Lbccbeven:
105: movl a1,d1
106: btst #0,d1 | dest address odd?
107: jne Lbccbbyte | yes, must copy by bytes
108: movl d0,d1 | no, get count
109: lsrl #2,d1 | convert to longwords
110: jeq Lbccbbyte | no longwords, copy bytes
111: subql #1,d1 | set up for dbf
112: Lbccblloop:
113: movl a0@-,a1@- | copy longwords
114: dbf d1,Lbccblloop | til done
115: andl #3,d0 | get remaining count
116: jeq Lbccpyexit | done if none
117: Lbccbbyte:
118: subql #1,d0 | set up for dbf
119: Lbccbbloop:
120: movb a0@-,a1@- | copy bytes
121: dbf d0,Lbccbbloop | til done
122: rts
CVSweb