str.S revision 1.2
1/* $NetBSD: str.S,v 1.2 2003/09/04 10:40:44 dsl Exp $ */ 2/* 3 * Copyright (c) 1996 Ludd, University of Lule}, Sweden. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed at Ludd, University of 17 * Lule}, Sweden and its contributors. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33/* 34 * Small versions of the most common functions not using any 35 * emulated instructions. 36 */ 37 38#include "asm.h" 39 40/* 41 * atoi() used in devopen. 42 */ 43ENTRY(atoi, 0) 44 movl 4(%ap),%r1 45 clrl %r0 46 472: movzbl (%r1)+,%r2 48 cmpb %r2,$48 49 blss 1f 50 cmpb %r2,$57 51 bgtr 1f 52 subl2 $48,%r2 53 mull2 $10,%r0 54 addl2 %r2,%r0 55 brb 2b 561: ret 57 58/* 59 * index() small and easy. 60 * doesnt work if we search for null. 61 */ 62ENTRY(index, 0) 63 movq 4(%ap),%r0 641: cmpb (%r0), %r1 65 beql 2f 66 tstb (%r0)+ 67 bneq 1b 68 clrl %r0 692: ret 70 71/* 72 * cmpc3 is emulated on MVII. 73 */ 74ENTRY(memcmp, 0) 75 brb 10f 76ENTRY(bcmp, 0) 7710: movl 4(%ap), %r2 78 movl 8(%ap), %r1 79 movl 12(%ap), %r0 802: cmpb (%r2)+, (%r1)+ 81 bneq 1f 82 decl %r0 83 bneq 2b 843: ret 851: bgtru 5f 86 movl $-1, %r0 87 brb 3b 885: movl $1, %r0 89 ret 90 91/* 92 * Is movc3/movc5 emulated on any CPU? I dont think so; use them here. 93 */ 94ENTRY(bzero,0) 95 movc5 $0,*4(%ap),$0,8(%ap),*4(%ap) 96 ret 97 98ENTRY(bcopy,0) 99 movc3 12(%ap), *4(%ap), *8(%ap) 100 ret 101 102ENTRY(memset,0) 103 movc5 $0,*4(%ap),8(%ap),12(%ap),*4(%ap) 104 movl 4(%ap), %r0 105 ret 106 107ENTRY(memcpy,0) 108 movc3 12(%ap), *8(%ap), *4(%ap) 109 movl 4(%ap), %r0 110 ret 111 112ENTRY(strlen, 0) 113 movl 4(%ap), %r0 1141: tstb (%r0)+ 115 bneq 1b 116 decl %r0 117 subl2 4(%ap), %r0 118 ret 119 120ENTRY(strncmp, 0) 121 movl 12(%ap), %r3 122 bneq 5f 123 brb 4f 124 125ENTRY(strcmp, 0) 126 movl $250, %r3 # max string len to compare 1275: movl 4(%ap), %r2 128 movl 8(%ap), %r1 129 movl $1, %r0 130 1312: cmpb (%r2),(%r1)+ 132 bneq 1f # something differ 133 tstb (%r2)+ 134 beql 4f # continue, strings unequal 135 decl %r3 # max string len encountered? 136 bneq 2b 137 1384: clrl %r0 # We are done, strings equal. 139 ret 140 1411: bgtru 3f 142 mnegl %r0, %r0 1433: ret 144 145ENTRY(strncpy, 0) 146 movl 4(%ap), %r1 147 movl 8(%ap), %r2 148 movl 12(%ap), %r3 149 bleq 2f 150 1511: movb (%r2)+, (%r1)+ 152 beql 2f 153 decl %r3 154 bneq 1b 1552: ret 156 157ENTRY(strcat, 0) 158 pushl 4(%ap) 159 calls $1,_C_LABEL(strlen) 160 addl2 4(%ap),%r0 161 movl 8(%ap),%r1 1621: movb (%r1)+,(%r0)+ 163 bneq 1b 164 ret 165 166ENTRY(setjmp, 0) 167 movl 4(%ap), %r0 168 movl 8(%fp), (%r0) 169 movl 12(%fp), 4(%r0) 170 movl 16(%fp), 8(%r0) 171 addl3 %fp,$28,12(%r0) 172 clrl %r0 173 ret 174 175ENTRY(longjmp, 0) 176 movl 4(%ap), %r1 177 movl 8(%ap), %r0 178 movl (%r1), %ap 179 movl 4(%r1), %fp 180 movl 12(%r1), %sp 181 jmp *8(%r1) 182 183