1/* $NetBSD: memset.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: memset.S,v 1.1 2005/12/20 19:28:49 christos Exp $") 79#endif 80#endif /* LIBC_SCCS and not lint */ 81 82ENTRY(memset) 83 movl %d2,%sp@- 84 movl %sp@(8),%a0 | destination 85 movl %sp@(16),%d1 | count 86 movb %sp@(15),%d2 | character 87 88 /* 89 * It isn't worth the overhead of aligning to {long}word boundries 90 * if the string is too short. 91 */ 92 cmpl #15,%d1 93 jlt Lbzbyte 94 95 clrl %d0 | replicate byte to fill longword 96 movb %d2,%d0 97 movl %d0,%d2 98 lsll #8,%d0 99 orl %d0,%d2 100 lsll #8,%d0 101 orl %d0,%d2 102 lsll #8,%d0 103 orl %d0,%d2 104 105 /* word align */ 106 movl %a0,%d0 107 btst #0,%d0 | if (dst & 1) 108 jeq Lbzalgndw | 109 movb %d2,%a0@+ | *(char *)dst++ = X 110 subql #1,%d1 | len-- 111 addql #1,%d0 112Lbzalgndw: 113#ifndef __mc68010__ 114 /* long word align */ 115 btst #1,%d0 | if (dst & 2) 116 jeq Lbzalgndl | 117 movw %d2,%a0@+ | *(short *)dst++ = X 118 subql #2,%d1 | len -= 2 119Lbzalgndl: 120 /* set by 8 longwords */ 121 movel %d1,%d0 122 lsrl #5,%d0 | cnt = len / 32 123 jeq Lbzlong | if (cnt) 124 andl #31,%d1 | len %= 32 125 subql #1,%d0 | set up for dbf 126Lbz32loop: 127 movl %d2,%a0@+ | set 8 long words 128 movl %d2,%a0@+ 129 movl %d2,%a0@+ 130 movl %d2,%a0@+ 131 movl %d2,%a0@+ 132 movl %d2,%a0@+ 133 movl %d2,%a0@+ 134 movl %d2,%a0@+ 135 dbf %d0,Lbz32loop | till done 136 clrw %d0 137 subql #1,%d0 138 jcc Lbz32loop 139#endif /* !__mc68010__ */ 140 141Lbzlong: 142 /* set by longwords */ 143 movel %d1,%d0 144 lsrl #2,%d0 | cnt = len / 4 145 jeq Lbzbyte | if (cnt) 146 subql #1,%d0 | set up for dbf 147Lbzlloop: 148 movl %d2,%a0@+ | clear longwords 149 dbf %d0,Lbzlloop | till done 150#ifdef __mc68010__ 151 clrw %d0 152 subql #1,%d0 153 jcc Lbzlloop 154#endif /* __mc68010__ */ 155 andl #3,%d1 | len %= 4 156 jeq Lbzdone 157 158 subql #1,%d1 | set up for dbf 159Lbzbloop: 160 movb %d2,%a0@+ | set bytes 161Lbzbyte: 162 dbf %d1,Lbzbloop | till done 163Lbzdone: 164 movl %sp@(8),%d0 | return destination 165#ifdef __SVR4_ABI__ 166 moveal %d0,%a0 167#endif 168 movl %sp@+,%d2 169 rts 170