1/* $NetBSD: bzero.S,v 1.1 2005/12/20 19:28:49 christos Exp $ */ 2 3/*- 4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by J.T. Conklin. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39/*- 40 * Copyright (c) 1990 The Regents of the University of California. 41 * All rights reserved. 42 * 43 * This code is derived from software contributed to Berkeley by 44 * the Systems Programming Group of the University of Utah Computer 45 * Science Department. 46 * 47 * Redistribution and use in source and binary forms, with or without 48 * modification, are permitted provided that the following conditions 49 * are met: 50 * 1. Redistributions of source code must retain the above copyright 51 * notice, this list of conditions and the following disclaimer. 52 * 2. Redistributions in binary form must reproduce the above copyright 53 * notice, this list of conditions and the following disclaimer in the 54 * documentation and/or other materials provided with the distribution. 55 * 3. Neither the name of the University nor the names of its contributors 56 * may be used to endorse or promote products derived from this software 57 * without specific prior written permission. 58 * 59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 69 * SUCH DAMAGE. 70 */ 71 72#include <machine/asm.h> 73 74#if defined(LIBC_SCCS) && !defined(lint) 75#if 0 76 RCSID("from: @(#)bzero.s 5.1 (Berkeley) 5/12/90") 77#else 78 RCSID("$NetBSD: bzero.S,v 1.1 2005/12/20 19:28:49 christos Exp $") 79#endif 80#endif /* LIBC_SCCS and not lint */ 81 82ENTRY(bzero) 83 movl %d2,%sp@- 84 movl %sp@(8),%a0 | destination 85 movl %sp@(12),%d1 | count 86 87 movql #0,%d2 88 89 /* 90 * It isn't worth the overhead of aligning to {long}word boundries 91 * if the string is too short. 92 */ 93 cmpl #8,%d1 94 jlt Lbzbyte 95 96 /* word align */ 97 movl %a0,%d0 98 btst #0,%d0 | if (dst & 1) 99 jeq Lbzalgndw | 100 movb %d2,%a0@+ | *(char *)dst++ = 0 101 subql #1,%d1 | len-- 102Lbzalgndw: 103 /* long word align */ 104 btst #1,%d0 | if (dst & 2) 105 jeq Lbzalgndl | 106 movw %d2,%a0@+ | *(short *)dst++ = 0 107 subql #2,%d1 | len -= 2 108Lbzalgndl: 109 /* zero by 8 longwords */ 110 movel %d1,%d0 111 lsrl #5,%d0 | cnt = len / 32 112 jeq Lbzlong | if (cnt) 113 andl #31,%d1 | len %= 32 114 subql #1,%d0 | set up for dbf 115Lbz32loop: 116 movl %d2,%a0@+ | zero 8 long words 117 movl %d2,%a0@+ 118 movl %d2,%a0@+ 119 movl %d2,%a0@+ 120 movl %d2,%a0@+ 121 movl %d2,%a0@+ 122 movl %d2,%a0@+ 123 movl %d2,%a0@+ 124 dbf %d0,Lbz32loop | till done 125 clrw %d0 126 subql #1,%d0 127 jcc Lbz32loop 128 129Lbzlong: 130 /* copy by longwords */ 131 movel %d1,%d0 132 lsrl #2,%d0 | cnt = len / 4 133 jeq Lbzbyte | if (cnt) 134 subql #1,%d0 | set up for dbf 135Lbzlloop: 136 movl %d2,%a0@+ | clear longwords 137 dbf %d0,Lbzlloop | till done 138 andl #3,%d1 | len %= 4 139 jeq Lbzdone 140 141 subql #1,%d1 | set up for dbf 142Lbzbloop: 143 movb %d2,%a0@+ | zero bytes 144Lbzbyte: 145 dbf %d1,Lbzbloop | till done 146Lbzdone: 147 movl %sp@+,%d2 148 rts 149