common bcopy used by all the m68k ports
authorderaadt <deraadt@openbsd.org>
Fri, 15 Dec 1995 01:53:03 +0000 (01:53 +0000)
committerderaadt <deraadt@openbsd.org>
Fri, 15 Dec 1995 01:53:03 +0000 (01:53 +0000)
sys/arch/m68k/m68k/copy.s

index 1f2bdc4..263bbfb 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: copy.s,v 1.21 1995/02/11 21:59:29 mycroft Exp $        */
+/*     $NetBSD: copy.s,v 1.22 1995/12/11 02:37:55 thorpej Exp $        */
 
 /*-
  * Copyright (c) 1994, 1995 Charles Hannum.
@@ -455,3 +455,78 @@ Lsdone:
        clrl    a1@(PCB_ONFAULT)        | clear fault handler
        rts
 
+/*
+ * {ov}bcopy(from, to, len)
+ * memcpy(to, from, len)
+ *
+ * Works for counts up to 128K.
+ */
+ENTRY(memcpy)
+       movl    sp@(12),d0              | get count
+       jeq     Lbccpyexit              | if zero, return
+       movl    sp@(8), a0              | src address
+       movl    sp@(4), a1              | dest address
+       jra     Lbcdocopy               | jump into bcopy
+ALTENTRY(ovbcopy, _bcopy)
+ENTRY(bcopy)
+       movl    sp@(12),d0              | get count
+       jeq     Lbccpyexit              | if zero, return
+       movl    sp@(4),a0               | src address
+       movl    sp@(8),a1               | dest address
+Lbcdocopy:
+       cmpl    a1,a0                   | src before dest?
+       jlt     Lbccpyback              | yes, copy backwards (avoids overlap)
+       movl    a0,d1
+       btst    #0,d1                   | src address odd?
+       jeq     Lbccfeven               | no, go check dest
+       movb    a0@+,a1@+               | yes, copy a byte
+       subql   #1,d0                   | update count
+       jeq     Lbccpyexit              | exit if done
+Lbccfeven:
+       movl    a1,d1
+       btst    #0,d1                   | dest address odd?
+       jne     Lbccfbyte               | yes, must copy by bytes
+       movl    d0,d1                   | no, get count
+       lsrl    #2,d1                   | convert to longwords
+       jeq     Lbccfbyte               | no longwords, copy bytes
+       subql   #1,d1                   | set up for dbf
+Lbccflloop:
+       movl    a0@+,a1@+               | copy longwords
+       dbf     d1,Lbccflloop           | til done
+       andl    #3,d0                   | get remaining count
+       jeq     Lbccpyexit              | done if none
+Lbccfbyte:
+       subql   #1,d0                   | set up for dbf
+Lbccfbloop:
+       movb    a0@+,a1@+               | copy bytes
+       dbf     d0,Lbccfbloop           | til done
+Lbccpyexit:
+       rts
+Lbccpyback:
+       addl    d0,a0                   | add count to src
+       addl    d0,a1                   | add count to dest
+       movl    a0,d1
+       btst    #0,d1                   | src address odd?
+       jeq     Lbccbeven               | no, go check dest
+       movb    a0@-,a1@-               | yes, copy a byte
+       subql   #1,d0                   | update count
+       jeq     Lbccpyexit              | exit if done
+Lbccbeven:
+       movl    a1,d1
+       btst    #0,d1                   | dest address odd?
+       jne     Lbccbbyte               | yes, must copy by bytes
+       movl    d0,d1                   | no, get count
+       lsrl    #2,d1                   | convert to longwords
+       jeq     Lbccbbyte               | no longwords, copy bytes
+       subql   #1,d1                   | set up for dbf
+Lbccblloop:
+       movl    a0@-,a1@-               | copy longwords
+       dbf     d1,Lbccblloop           | til done
+       andl    #3,d0                   | get remaining count
+       jeq     Lbccpyexit              | done if none
+Lbccbbyte:
+       subql   #1,d0                   | set up for dbf
+Lbccbbloop:
+       movb    a0@-,a1@-               | copy bytes
+       dbf     d0,Lbccbbloop           | til done
+       rts