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