Home | History | Annotate | Line # | Download | only in string
memset.S revision 1.9
      1  1.9   mlelstv /*	$NetBSD: memset.S,v 1.9 2023/01/19 18:03:03 mlelstv Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright 2003 Wasabi Systems, Inc.
      5  1.1  christos  * All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * Written by Steve C. Woodford for Wasabi Systems, Inc.
      8  1.1  christos  *
      9  1.1  christos  * Redistribution and use in source and binary forms, with or without
     10  1.1  christos  * modification, are permitted provided that the following conditions
     11  1.1  christos  * are met:
     12  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     13  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     14  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  christos  *    documentation and/or other materials provided with the distribution.
     17  1.1  christos  * 3. All advertising materials mentioning features or use of this software
     18  1.1  christos  *    must display the following acknowledgement:
     19  1.1  christos  *      This product includes software developed for the NetBSD Project by
     20  1.1  christos  *      Wasabi Systems, Inc.
     21  1.1  christos  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1  christos  *    or promote products derived from this software without specific prior
     23  1.1  christos  *    written permission.
     24  1.1  christos  *
     25  1.1  christos  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1  christos  */
     37  1.1  christos /*
     38  1.1  christos  * Copyright (c) 1995 Mark Brinicombe.
     39  1.1  christos  * All rights reserved.
     40  1.1  christos  *
     41  1.1  christos  * Redistribution and use in source and binary forms, with or without
     42  1.1  christos  * modification, are permitted provided that the following conditions
     43  1.1  christos  * are met:
     44  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     45  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     46  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     47  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     48  1.1  christos  *    documentation and/or other materials provided with the distribution.
     49  1.1  christos  * 3. All advertising materials mentioning features or use of this software
     50  1.1  christos  *    must display the following acknowledgement:
     51  1.1  christos  *	This product includes software developed by Mark Brinicombe.
     52  1.1  christos  * 4. The name of the company nor the name of the author may be used to
     53  1.1  christos  *    endorse or promote products derived from this software without specific
     54  1.1  christos  *    prior written permission.
     55  1.1  christos  *
     56  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     57  1.1  christos  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     58  1.1  christos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     59  1.1  christos  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     60  1.1  christos  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     61  1.1  christos  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     62  1.1  christos  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     63  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     64  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     65  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     66  1.1  christos  * SUCH DAMAGE.
     67  1.1  christos  */
     68  1.1  christos 
     69  1.1  christos #include <machine/asm.h>
     70  1.1  christos 
     71  1.8    justin #if defined(__ARM_EABI__) && !defined(_BZERO) && !defined(_RUMPKERNEL)
     72  1.7     joerg ENTRY(__aeabi_memset)
     73  1.7     joerg 	mov	r3, r1
     74  1.7     joerg 	mov	r1, r2
     75  1.7     joerg 	mov	r2, r3
     76  1.7     joerg 	b	memset
     77  1.7     joerg END(__aeabi_memset)
     78  1.7     joerg STRONG_ALIAS(__aeabi_memset4, __aeabi_memset)
     79  1.7     joerg STRONG_ALIAS(__aeabi_memset8, __aeabi_memset)
     80  1.7     joerg 
     81  1.7     joerg ENTRY(__aeabi_memclr)
     82  1.7     joerg 	mov	r2, r1
     83  1.7     joerg 	mov	r1, #0
     84  1.7     joerg 	b	memset
     85  1.7     joerg END(__aeabi_memclr)
     86  1.7     joerg STRONG_ALIAS(__aeabi_memclr4, __aeabi_memclr)
     87  1.7     joerg STRONG_ALIAS(__aeabi_memclr8, __aeabi_memclr)
     88  1.3      matt #endif
     89  1.3      matt 
     90  1.1  christos /*
     91  1.1  christos  * memset: Sets a block of memory to the specified value
     92  1.1  christos  *
     93  1.1  christos  * On entry:
     94  1.1  christos  *   r0 - dest address
     95  1.1  christos  *   r1 - byte to write
     96  1.1  christos  *   r2 - number of bytes to write
     97  1.1  christos  *
     98  1.1  christos  * On exit:
     99  1.1  christos  *   r0 - dest address
    100  1.1  christos  */
    101  1.1  christos #ifdef _BZERO
    102  1.1  christos /* LINTSTUB: Func: void bzero(void *, size_t) */
    103  1.1  christos ENTRY(bzero)
    104  1.1  christos 	mov	r3, #0x00
    105  1.1  christos #else
    106  1.1  christos /* LINTSTUB: Func: void *memset(void *, int, size_t) */
    107  1.1  christos ENTRY(memset)
    108  1.1  christos 	and	r3, r1, #0xff		/* We deal with bytes */
    109  1.1  christos 	mov	r1, r2
    110  1.1  christos #endif
    111  1.1  christos 	cmp	r1, #0x04		/* Do we have less than 4 bytes */
    112  1.1  christos 	mov	ip, r0
    113  1.9   mlelstv 	blo	.Lmemset_lessthanfour
    114  1.1  christos 
    115  1.1  christos 	/* Ok first we will word align the address */
    116  1.1  christos 	ands	r2, ip, #0x03		/* Get the bottom two bits */
    117  1.1  christos 	bne	.Lmemset_wordunaligned	/* The address is not word aligned */
    118  1.1  christos 
    119  1.1  christos 	/* We are now word aligned */
    120  1.1  christos .Lmemset_wordaligned:
    121  1.1  christos #ifndef _BZERO
    122  1.1  christos 	orr	r3, r3, r3, lsl #8	/* Extend value to 16-bits */
    123  1.1  christos #endif
    124  1.2      matt #ifdef _ARM_ARCH_DWORD_OK
    125  1.1  christos 	tst	ip, #0x04		/* Quad-align for Xscale */
    126  1.1  christos #else
    127  1.1  christos 	cmp	r1, #0x10
    128  1.1  christos #endif
    129  1.1  christos #ifndef _BZERO
    130  1.1  christos 	orr	r3, r3, r3, lsl #16	/* Extend value to 32-bits */
    131  1.1  christos #endif
    132  1.2      matt #ifdef _ARM_ARCH_DWORD_OK
    133  1.1  christos 	subne	r1, r1, #0x04		/* Quad-align if necessary */
    134  1.1  christos 	strne	r3, [ip], #0x04
    135  1.1  christos 	cmp	r1, #0x10
    136  1.1  christos #endif
    137  1.9   mlelstv 	blo	.Lmemset_loop4		/* If less than 16 then use words */
    138  1.1  christos 	mov	r2, r3			/* Duplicate data */
    139  1.1  christos 	cmp	r1, #0x80		/* If < 128 then skip the big loop */
    140  1.9   mlelstv 	blo	.Lmemset_loop32
    141  1.1  christos 
    142  1.1  christos 	/* Do 128 bytes at a time */
    143  1.1  christos .Lmemset_loop128:
    144  1.1  christos 	subs	r1, r1, #0x80
    145  1.2      matt #ifdef _ARM_ARCH_DWORD_OK
    146  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    147  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    148  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    149  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    150  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    151  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    152  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    153  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    154  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    155  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    156  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    157  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    158  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    159  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    160  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    161  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    162  1.4      matt #else
    163  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    164  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    165  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    166  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    167  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    168  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    169  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    170  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    171  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    172  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    173  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    174  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    175  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    176  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    177  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    178  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    179  1.1  christos #endif
    180  1.9   mlelstv 	bhi	.Lmemset_loop128
    181  1.1  christos 	RETc(eq)			/* Zero length so just exit */
    182  1.1  christos 
    183  1.1  christos 	add	r1, r1, #0x80		/* Adjust for extra sub */
    184  1.1  christos 
    185  1.1  christos 	/* Do 32 bytes at a time */
    186  1.1  christos .Lmemset_loop32:
    187  1.1  christos 	subs	r1, r1, #0x20
    188  1.2      matt #ifdef _ARM_ARCH_DWORD_OK
    189  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    190  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    191  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    192  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    193  1.4      matt #else
    194  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    195  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    196  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    197  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    198  1.1  christos #endif
    199  1.9   mlelstv 	bhi	.Lmemset_loop32
    200  1.1  christos 	RETc(eq)			/* Zero length so just exit */
    201  1.1  christos 
    202  1.1  christos 	adds	r1, r1, #0x10		/* Partially adjust for extra sub */
    203  1.1  christos 
    204  1.1  christos 	/* Deal with 16 bytes or more */
    205  1.2      matt #ifdef _ARM_ARCH_DWORD_OK
    206  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    207  1.9   mlelstv 	strdhs	r2, r3, [ip], #0x08
    208  1.1  christos #else
    209  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    210  1.9   mlelstv 	stmiahs	ip!, {r2-r3}
    211  1.1  christos #endif
    212  1.1  christos 	RETc(eq)			/* Zero length so just exit */
    213  1.1  christos 
    214  1.9   mlelstv 	addlo	r1, r1, #0x10		/* Possibly adjust for extra sub */
    215  1.1  christos 
    216  1.1  christos 	/* We have at least 4 bytes so copy as words */
    217  1.1  christos .Lmemset_loop4:
    218  1.1  christos 	subs	r1, r1, #0x04
    219  1.9   mlelstv 	strhs	r3, [ip], #0x04
    220  1.9   mlelstv 	bhi	.Lmemset_loop4
    221  1.1  christos 	RETc(eq)			/* Zero length so just exit */
    222  1.1  christos 
    223  1.2      matt #ifdef _ARM_ARCH_DWORD_OK
    224  1.1  christos 	/* Compensate for 64-bit alignment check */
    225  1.1  christos 	adds	r1, r1, #0x04
    226  1.1  christos 	RETc(eq)
    227  1.1  christos 	cmp	r1, #2
    228  1.1  christos #else
    229  1.1  christos 	cmp	r1, #-2
    230  1.1  christos #endif
    231  1.1  christos 
    232  1.1  christos 	strb	r3, [ip], #0x01		/* Set 1 byte */
    233  1.9   mlelstv 	strbhs	r3, [ip], #0x01		/* Set another byte */
    234  1.9   mlelstv 	strbhi	r3, [ip]		/* and a third */
    235  1.1  christos 	RET				/* Exit */
    236  1.1  christos 
    237  1.1  christos .Lmemset_wordunaligned:
    238  1.1  christos 	rsb	r2, r2, #0x004
    239  1.1  christos 	strb	r3, [ip], #0x01		/* Set 1 byte */
    240  1.1  christos 	cmp	r2, #0x02
    241  1.9   mlelstv 	strbhs	r3, [ip], #0x01		/* Set another byte */
    242  1.1  christos 	sub	r1, r1, r2
    243  1.9   mlelstv 	strbhi	r3, [ip], #0x01		/* and a third */
    244  1.1  christos 	cmp	r1, #0x04		/* More than 4 bytes left? */
    245  1.9   mlelstv 	bhs	.Lmemset_wordaligned	/* Yup */
    246  1.1  christos 
    247  1.1  christos .Lmemset_lessthanfour:
    248  1.1  christos 	cmp	r1, #0x00
    249  1.1  christos 	RETc(eq)				/* Zero length so exit */
    250  1.1  christos 	strb	r3, [ip], #0x01		/* Set 1 byte */
    251  1.1  christos 	cmp	r1, #0x02
    252  1.9   mlelstv 	strbhs	r3, [ip], #0x01		/* Set another byte */
    253  1.9   mlelstv 	strbhi	r3, [ip]		/* and a third */
    254  1.1  christos 	RET				/* Exit */
    255  1.5      matt #ifdef _BZERO
    256  1.5      matt END(bzero)
    257  1.5      matt #else
    258  1.5      matt END(memset)
    259  1.5      matt #endif
    260