1112158Sdas/* $NetBSD: bzero.S,v 1.9 2009/12/14 01:07:42 matt Exp $ */ 2112158Sdas 3112158Sdas/*- 4112158Sdas * Copyright (c) 1991, 1993 5112158Sdas * The Regents of the University of California. All rights reserved. 6112158Sdas * 7112158Sdas * This code is derived from software contributed to Berkeley by 8112158Sdas * Ralph Campbell. 9112158Sdas * 10112158Sdas * Redistribution and use in source and binary forms, with or without 11112158Sdas * modification, are permitted provided that the following conditions 12112158Sdas * are met: 13112158Sdas * 1. Redistributions of source code must retain the above copyright 14112158Sdas * notice, this list of conditions and the following disclaimer. 15112158Sdas * 2. Redistributions in binary form must reproduce the above copyright 16112158Sdas * notice, this list of conditions and the following disclaimer in the 17112158Sdas * documentation and/or other materials provided with the distribution. 18112158Sdas * 3. Neither the name of the University nor the names of its contributors 19112158Sdas * may be used to endorse or promote products derived from this software 20112158Sdas * without specific prior written permission. 21112158Sdas * 22112158Sdas * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23112158Sdas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24112158Sdas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25112158Sdas * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26112158Sdas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27112158Sdas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28112158Sdas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29112158Sdas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30112158Sdas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31112158Sdas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32112158Sdas * SUCH DAMAGE. 33112158Sdas */ 34112158Sdas 35112158Sdas#include <mips/asm.h> 36112158Sdas 37112158Sdas#if defined(LIBC_SCCS) && !defined(lint) 38112158Sdas#if 0 39112158Sdas RCSID("from: @(#)bzero.s 8.1 (Berkeley) 6/4/93") 40112158Sdas#else 41112158Sdas RCSID("$NetBSD: bzero.S,v 1.9 2009/12/14 01:07:42 matt Exp $") 42112158Sdas#endif 43112158Sdas#endif /* LIBC_SCCS and not lint */ 44112158Sdas 45112158Sdas 46112158Sdas#define _LOCORE /* XXX not really, just assembly-code source */ 47112158Sdas#include <machine/endian.h> 48112158Sdas 49112158Sdas/* bzero(s1, n) */ 50112158Sdas 51112158SdasLEAF(bzero) 52112158Sdas .set noreorder 53112158Sdas blt a1, 3*SZREG, smallclr # small amount to clear? 54112158Sdas PTR_SUBU a3, zero, a0 # compute # bytes to word align address 55112158Sdas and a3, a3, SZREG-1 56112158Sdas beq a3, zero, 1f # skip if word aligned 57112158Sdas#if SZREG == 4 58112158Sdas PTR_SUBU a1, a1, a3 # subtract from remaining count 59112158Sdas SWHI zero, 0(a0) # clear 1, 2, or 3 bytes to align 60112158Sdas PTR_ADDU a0, a0, a3 61112158Sdas#endif 62112158Sdas#if SZREG == 8 63112158Sdas PTR_SUBU a1, a1, a3 # subtract from remaining count 64112158Sdas PTR_ADDU a0, a0, a3 # align dst to next word 65112158Sdas sll a3, a3, 3 # bits to bytes 66112158Sdas li a2, -1 # make a mask 67112158Sdas#if _BYTE_ORDER == _BIG_ENDIAN 68112158Sdas REG_SRLV a2, a2, a3 # we want to keep the MSB bytes 69112158Sdas#endif 70112158Sdas#if _BYTE_ORDER == _LITTLE_ENDIAN 71112158Sdas REG_SLLV a2, a2, a3 # we want to keep the LSB bytes 72112158Sdas#endif 73112158Sdas nor a2, zero, a2 # complement the mask 74112158Sdas REG_L v0, -SZREG(a0) # load the word to partially clear 75112158Sdas and v0, v0, a2 # clear the bytes 76112158Sdas REG_S v0, -SZREG(a0) # store it back 77112158Sdas#endif 78112158Sdas1: 79112158Sdas and v0, a1, SZREG-1 # compute number of words left 80112158Sdas PTR_SUBU a3, a1, v0 81112158Sdas move a1, v0 82112158Sdas PTR_ADDU a3, a3, a0 # compute ending address 83112158Sdas2: 84112158Sdas PTR_ADDU a0, a0, SZREG # clear words 85112158Sdas bne a0, a3, 2b # unrolling loop doesnt help 86112158Sdas REG_S zero, -SZREG(a0) # since we are limited by memory speed 87112158Sdassmallclr: 88112158Sdas ble a1, zero, 2f 89112158Sdas PTR_ADDU a3, a1, a0 # compute ending address 90112158Sdas1: 91112158Sdas PTR_ADDU a0, a0, 1 # clear bytes 92112158Sdas bne a0, a3, 1b 93112158Sdas sb zero, -1(a0) 94112158Sdas2: 95112158Sdas j ra 96112158Sdas nop 97112158SdasEND(bzero) 98112158Sdas