1*0Sstevel@tonic-gate/* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate/* 23*0Sstevel@tonic-gate * Copyright 1987-2003 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate .ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate .file "%M%" 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate/* 32*0Sstevel@tonic-gate * char *memset(sp, c, n) 33*0Sstevel@tonic-gate * 34*0Sstevel@tonic-gate * Set an array of n chars starting at sp to the character c. 35*0Sstevel@tonic-gate * Return sp. 36*0Sstevel@tonic-gate * 37*0Sstevel@tonic-gate * Fast assembler language version of the following C-program for memset 38*0Sstevel@tonic-gate * which represents the `standard' for the C-library. 39*0Sstevel@tonic-gate * 40*0Sstevel@tonic-gate * void * 41*0Sstevel@tonic-gate * memset(void *sp1, int c, size_t n) 42*0Sstevel@tonic-gate * { 43*0Sstevel@tonic-gate * if (n != 0) { 44*0Sstevel@tonic-gate * char *sp = sp1; 45*0Sstevel@tonic-gate * do { 46*0Sstevel@tonic-gate * *sp++ = (char)c; 47*0Sstevel@tonic-gate * } while (--n != 0); 48*0Sstevel@tonic-gate * } 49*0Sstevel@tonic-gate * return (sp1); 50*0Sstevel@tonic-gate * } 51*0Sstevel@tonic-gate */ 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate#include <sys/asm_linkage.h> 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate ANSI_PRAGMA_WEAK(memset,function) 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gate#include "synonyms.h" 58*0Sstevel@tonic-gate 59*0Sstevel@tonic-gate .weak _private_memset 60*0Sstevel@tonic-gate .type _private_memset, #function 61*0Sstevel@tonic-gate _private_memset = memset 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate ENTRY(memset) 64*0Sstevel@tonic-gate mov %o0, %o5 ! copy sp before using it 65*0Sstevel@tonic-gate cmp %o2, 7 ! if small counts, just write bytes 66*0Sstevel@tonic-gate blu .wrchar 67*0Sstevel@tonic-gate .empty ! following lable is ok in delay slot 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate.walign:btst 3, %o5 ! if bigger, align to 4 bytes 70*0Sstevel@tonic-gate bz .wrword 71*0Sstevel@tonic-gate andn %o2, 3, %o3 ! create word sized count in %o3 72*0Sstevel@tonic-gate dec %o2 ! decrement count 73*0Sstevel@tonic-gate stb %o1, [%o5] ! clear a byte 74*0Sstevel@tonic-gate b .walign 75*0Sstevel@tonic-gate inc %o5 ! next byte 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate.wrword:and %o1, 0xff, %o1 ! generate a word filled with c 78*0Sstevel@tonic-gate sll %o1, 8, %o4 79*0Sstevel@tonic-gate or %o1, %o4, %o1 80*0Sstevel@tonic-gate sll %o1, 16, %o4 81*0Sstevel@tonic-gate or %o1, %o4, %o1 82*0Sstevel@tonic-gate1: st %o1, [%o5] ! word writing loop 83*0Sstevel@tonic-gate subcc %o3, 4, %o3 84*0Sstevel@tonic-gate bnz 1b 85*0Sstevel@tonic-gate inc 4, %o5 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate and %o2, 3, %o2 ! leftover count, if any 88*0Sstevel@tonic-gate.wrchar:deccc %o2 ! byte clearing loop 89*0Sstevel@tonic-gate inc %o5 90*0Sstevel@tonic-gate bgeu,a .wrchar 91*0Sstevel@tonic-gate stb %o1, [%o5 + -1] ! we've already incremented the address 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate retl 94*0Sstevel@tonic-gate nop 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate SET_SIZE(memset) 97