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