1*18ec38eaSchs/* $NetBSD: memset.S,v 1.7 2013/09/07 19:06:29 chs Exp $ */ 237c9f0a6Schristos 337c9f0a6Schristos/*- 437c9f0a6Schristos * Copyright (c) 1997 The NetBSD Foundation, Inc. 537c9f0a6Schristos * All rights reserved. 637c9f0a6Schristos * 737c9f0a6Schristos * This code is derived from software contributed to The NetBSD Foundation 837c9f0a6Schristos * by J.T. Conklin. 937c9f0a6Schristos * 1037c9f0a6Schristos * Redistribution and use in source and binary forms, with or without 1137c9f0a6Schristos * modification, are permitted provided that the following conditions 1237c9f0a6Schristos * are met: 1337c9f0a6Schristos * 1. Redistributions of source code must retain the above copyright 1437c9f0a6Schristos * notice, this list of conditions and the following disclaimer. 1537c9f0a6Schristos * 2. Redistributions in binary form must reproduce the above copyright 1637c9f0a6Schristos * notice, this list of conditions and the following disclaimer in the 1737c9f0a6Schristos * documentation and/or other materials provided with the distribution. 1837c9f0a6Schristos * 1937c9f0a6Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2037c9f0a6Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2137c9f0a6Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2237c9f0a6Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2337c9f0a6Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2437c9f0a6Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2537c9f0a6Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2637c9f0a6Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2737c9f0a6Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2837c9f0a6Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2937c9f0a6Schristos * POSSIBILITY OF SUCH DAMAGE. 3037c9f0a6Schristos */ 3137c9f0a6Schristos 3237c9f0a6Schristos/*- 3337c9f0a6Schristos * Copyright (c) 1990 The Regents of the University of California. 3437c9f0a6Schristos * All rights reserved. 3537c9f0a6Schristos * 3637c9f0a6Schristos * This code is derived from software contributed to Berkeley by 3737c9f0a6Schristos * the Systems Programming Group of the University of Utah Computer 3837c9f0a6Schristos * Science Department. 3937c9f0a6Schristos * 4037c9f0a6Schristos * Redistribution and use in source and binary forms, with or without 4137c9f0a6Schristos * modification, are permitted provided that the following conditions 4237c9f0a6Schristos * are met: 4337c9f0a6Schristos * 1. Redistributions of source code must retain the above copyright 4437c9f0a6Schristos * notice, this list of conditions and the following disclaimer. 4537c9f0a6Schristos * 2. Redistributions in binary form must reproduce the above copyright 4637c9f0a6Schristos * notice, this list of conditions and the following disclaimer in the 4737c9f0a6Schristos * documentation and/or other materials provided with the distribution. 4837c9f0a6Schristos * 3. Neither the name of the University nor the names of its contributors 4937c9f0a6Schristos * may be used to endorse or promote products derived from this software 5037c9f0a6Schristos * without specific prior written permission. 5137c9f0a6Schristos * 5237c9f0a6Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 5337c9f0a6Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 5437c9f0a6Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5537c9f0a6Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 5637c9f0a6Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 5737c9f0a6Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 5837c9f0a6Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 5937c9f0a6Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 6037c9f0a6Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 6137c9f0a6Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 6237c9f0a6Schristos * SUCH DAMAGE. 6337c9f0a6Schristos */ 6437c9f0a6Schristos 6537c9f0a6Schristos#include <machine/asm.h> 6637c9f0a6Schristos 6737c9f0a6Schristos#if defined(LIBC_SCCS) && !defined(lint) 6837c9f0a6Schristos#if 0 6937c9f0a6Schristos RCSID("from: @(#)bzero.s 5.1 (Berkeley) 5/12/90") 7037c9f0a6Schristos#else 71*18ec38eaSchs RCSID("$NetBSD: memset.S,v 1.7 2013/09/07 19:06:29 chs Exp $") 7237c9f0a6Schristos#endif 7337c9f0a6Schristos#endif /* LIBC_SCCS and not lint */ 7437c9f0a6Schristos 7537c9f0a6SchristosENTRY(memset) 7607a0a325Smatt movl %d2,-(%sp) 7707a0a325Smatt movl 8(%sp),%a0 | destination 7807a0a325Smatt movl 16(%sp),%d1 | count 791d398a17Smatt movb 15(%sp),%d2 | get fill character 8037c9f0a6Schristos 8137c9f0a6Schristos /* 8237c9f0a6Schristos * It isn't worth the overhead of aligning to {long}word boundries 8337c9f0a6Schristos * if the string is too short. 8437c9f0a6Schristos */ 8537c9f0a6Schristos cmpl #15,%d1 86*18ec38eaSchs jlt .Lbzbyte 8737c9f0a6Schristos 88cb2ad9b1Smatt clrl %d0 89cb2ad9b1Smatt moveb %d2,%d0 90cb2ad9b1Smatt movel %d0,%d2 91cb2ad9b1Smatt lsll #8,%d0 92cb2ad9b1Smatt orl %d0,%d2 93cb2ad9b1Smatt lsll #8,%d0 94cb2ad9b1Smatt orl %d0,%d2 95cb2ad9b1Smatt lsll #8,%d0 96cb2ad9b1Smatt orl %d0,%d2 9737c9f0a6Schristos 9837c9f0a6Schristos /* word align */ 9937c9f0a6Schristos movl %a0,%d0 10037c9f0a6Schristos btst #0,%d0 | if (dst & 1) 101*18ec38eaSchs jeq .Lbzalgndw | 10207a0a325Smatt movb %d2,(%a0)+ | *(char *)dst++ = X 10337c9f0a6Schristos subql #1,%d1 | len-- 10437c9f0a6Schristos addql #1,%d0 105*18ec38eaSchs.Lbzalgndw: 10637c9f0a6Schristos#ifndef __mc68010__ 10737c9f0a6Schristos /* long word align */ 10837c9f0a6Schristos btst #1,%d0 | if (dst & 2) 109*18ec38eaSchs jeq .Lbzalgndl | 11007a0a325Smatt movw %d2,(%a0)+ | *(short *)dst++ = X 11137c9f0a6Schristos subql #2,%d1 | len -= 2 112*18ec38eaSchs.Lbzalgndl: 11337c9f0a6Schristos /* set by 8 longwords */ 11437c9f0a6Schristos movel %d1,%d0 11537c9f0a6Schristos lsrl #5,%d0 | cnt = len / 32 116*18ec38eaSchs jeq .Lbzlong | if (cnt) 11737c9f0a6Schristos andl #31,%d1 | len %= 32 11837c9f0a6Schristos subql #1,%d0 | set up for dbf 119*18ec38eaSchs.Lbz32loop: 12007a0a325Smatt movl %d2,(%a0)+ | set 8 long words 12107a0a325Smatt movl %d2,(%a0)+ 12207a0a325Smatt movl %d2,(%a0)+ 12307a0a325Smatt movl %d2,(%a0)+ 12407a0a325Smatt movl %d2,(%a0)+ 12507a0a325Smatt movl %d2,(%a0)+ 12607a0a325Smatt movl %d2,(%a0)+ 12707a0a325Smatt movl %d2,(%a0)+ 1281d398a17Smatt#ifndef __mcoldfire__ 129*18ec38eaSchs dbf %d0,.Lbz32loop | till done 13037c9f0a6Schristos clrw %d0 1311d398a17Smatt#endif 13237c9f0a6Schristos subql #1,%d0 133*18ec38eaSchs jcc .Lbz32loop 13437c9f0a6Schristos#endif /* !__mc68010__ */ 13537c9f0a6Schristos 136*18ec38eaSchs.Lbzlong: 13737c9f0a6Schristos /* set by longwords */ 13837c9f0a6Schristos movel %d1,%d0 13937c9f0a6Schristos lsrl #2,%d0 | cnt = len / 4 140*18ec38eaSchs jeq .Lbzbyte | if (cnt) 14137c9f0a6Schristos subql #1,%d0 | set up for dbf 142*18ec38eaSchs.Lbzlloop: 14307a0a325Smatt movl %d2,(%a0)+ | clear longwords 1441d398a17Smatt#ifndef __mcoldfire__ 145*18ec38eaSchs dbf %d0,.Lbzlloop | till done 1461d398a17Smatt#endif 14737c9f0a6Schristos#ifdef __mc68010__ 14837c9f0a6Schristos clrw %d0 1491d398a17Smatt#endif /* __mc68010__ */ 1501d398a17Smatt#if defined(__m68010) || defined(__mcoldfire__) 15137c9f0a6Schristos subql #1,%d0 152*18ec38eaSchs jcc .Lbzlloop 1531d398a17Smatt#endif /* __mc68010__ || __mcoldfire__ */ 15437c9f0a6Schristos andl #3,%d1 | len %= 4 155*18ec38eaSchs jeq .Lbzdone 15637c9f0a6Schristos 15737c9f0a6Schristos subql #1,%d1 | set up for dbf 158*18ec38eaSchs.Lbzbloop: 15907a0a325Smatt movb %d2,(%a0)+ | set bytes 160*18ec38eaSchs.Lbzbyte: 1611d398a17Smatt#ifdef __mcoldfire__ 1621d398a17Smatt subql #1,%d1 | decrement 163*18ec38eaSchs jcc .Lbzbloop | till done 1641d398a17Smatt#else 165*18ec38eaSchs dbf %d1,.Lbzbloop | till done 1661d398a17Smatt#endif 167*18ec38eaSchs.Lbzdone: 16807a0a325Smatt movl 8(%sp),%d0 | return destination 16937c9f0a6Schristos#ifdef __SVR4_ABI__ 17037c9f0a6Schristos moveal %d0,%a0 17137c9f0a6Schristos#endif 17207a0a325Smatt movl (%sp)+,%d2 17337c9f0a6Schristos rts 17465726debSmattEND(memset) 175