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