str.S revision 1.1
11.1Smatt/* $NetBSD: str.S,v 1.1 2002/02/24 01:04:25 matt Exp $ */ 21.1Smatt/* 31.1Smatt * Copyright (c) 1996 Ludd, University of Lule}, Sweden. 41.1Smatt * All rights reserved. 51.1Smatt * 61.1Smatt * Redistribution and use in source and binary forms, with or without 71.1Smatt * modification, are permitted provided that the following conditions 81.1Smatt * are met: 91.1Smatt * 1. Redistributions of source code must retain the above copyright 101.1Smatt * notice, this list of conditions and the following disclaimer. 111.1Smatt * 2. Redistributions in binary form must reproduce the above copyright 121.1Smatt * notice, this list of conditions and the following disclaimer in the 131.1Smatt * documentation and/or other materials provided with the distribution. 141.1Smatt * 3. All advertising materials mentioning features or use of this software 151.1Smatt * must display the following acknowledgement: 161.1Smatt * This product includes software developed at Ludd, University of 171.1Smatt * Lule}, Sweden and its contributors. 181.1Smatt * 4. The name of the author may not be used to endorse or promote products 191.1Smatt * derived from this software without specific prior written permission 201.1Smatt * 211.1Smatt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 221.1Smatt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 231.1Smatt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 241.1Smatt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 251.1Smatt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 261.1Smatt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 271.1Smatt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 281.1Smatt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 291.1Smatt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 301.1Smatt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 311.1Smatt */ 321.1Smatt 331.1Smatt/* 341.1Smatt * Small versions of the most common functions not using any 351.1Smatt * emulated instructions. 361.1Smatt */ 371.1Smatt 381.1Smatt#include "asm.h" 391.1Smatt 401.1Smatt/* 411.1Smatt * atoi() used in devopen. 421.1Smatt */ 431.1SmattENTRY(atoi, 0) 441.1Smatt movl 4(%ap),%r1 451.1Smatt clrl %r0 461.1Smatt 471.1Smatt2: movzbl (%r1)+,%r2 481.1Smatt cmpb %r2,$48 491.1Smatt blss 1f 501.1Smatt cmpb %r2,$57 511.1Smatt bgtr 1f 521.1Smatt subl2 $48,%r2 531.1Smatt mull2 $10,%r0 541.1Smatt addl2 %r2,%r0 551.1Smatt brb 2b 561.1Smatt1: ret 571.1Smatt 581.1Smatt/* 591.1Smatt * index() small and easy. 601.1Smatt * doesnt work if we search for null. 611.1Smatt */ 621.1SmattENTRY(index, 0) 631.1Smatt movq 4(%ap),%r0 641.1Smatt1: cmpb (%r0), %r1 651.1Smatt beql 2f 661.1Smatt tstb (%r0)+ 671.1Smatt bneq 1b 681.1Smatt clrl %r0 691.1Smatt2: ret 701.1Smatt 711.1Smatt/* 721.1Smatt * cmpc3 is emulated on MVII. 731.1Smatt */ 741.1SmattENTRY(bcmp, 0) 751.1Smatt movl 4(%ap), %r2 761.1Smatt movl 8(%ap), %r1 771.1Smatt movl 12(%ap), %r0 781.1Smatt2: cmpb (%r2)+, (%r1)+ 791.1Smatt bneq 1f 801.1Smatt decl %r0 811.1Smatt bneq 2b 821.1Smatt1: ret 831.1Smatt 841.1Smatt/* 851.1Smatt * Is movc3/movc5 emulated on any CPU? I dont think so; use them here. 861.1Smatt */ 871.1SmattENTRY(bzero,0) 881.1Smatt movc5 $0,*4(%ap),$0,8(%ap),*4(%ap) 891.1Smatt ret 901.1Smatt 911.1SmattENTRY(bcopy,0) 921.1Smatt movc3 12(%ap), *4(%ap), *8(%ap) 931.1Smatt ret 941.1Smatt 951.1SmattENTRY(strlen, 0) 961.1Smatt movl 4(%ap), %r0 971.1Smatt1: tstb (%r0)+ 981.1Smatt bneq 1b 991.1Smatt decl %r0 1001.1Smatt subl2 4(%ap), %r0 1011.1Smatt ret 1021.1Smatt 1031.1SmattENTRY(strncmp, 0) 1041.1Smatt movl 12(%ap), %r3 1051.1Smatt brb 5f 1061.1Smatt 1071.1SmattENTRY(strcmp, 0) 1081.1Smatt movl $250, %r3 # max string len to compare 1091.1Smatt5: movl 4(%ap), %r2 1101.1Smatt movl 8(%ap), %r1 1111.1Smatt movl $1, %r0 1121.1Smatt 1131.1Smatt2: cmpb (%r2),(%r1)+ 1141.1Smatt bneq 1f # something differ 1151.1Smatt tstb (%r2)+ 1161.1Smatt beql 4f # continue, strings unequal 1171.1Smatt decl %r3 # max string len encountered? 1181.1Smatt bneq 2b 1191.1Smatt 1201.1Smatt4: clrl %r0 # We are done, strings equal. 1211.1Smatt ret 1221.1Smatt 1231.1Smatt1: bgtr 3f 1241.1Smatt mnegl %r0, %r0 1251.1Smatt3: ret 1261.1Smatt 1271.1SmattENTRY(strncpy, 0) 1281.1Smatt movl 4(%ap), %r1 1291.1Smatt movl 8(%ap), %r2 1301.1Smatt movl 12(%ap), %r3 1311.1Smatt bleq 2f 1321.1Smatt 1331.1Smatt1: movb (%r2)+, (%r1)+ 1341.1Smatt beql 2f 1351.1Smatt decl %r3 1361.1Smatt bneq 1b 1371.1Smatt2: ret 1381.1Smatt 1391.1SmattENTRY(strcat, 0) 1401.1Smatt pushl 4(%ap) 1411.1Smatt calls $1,_C_LABEL(strlen) 1421.1Smatt addl2 4(%ap),%r0 1431.1Smatt movl 8(%ap),%r1 1441.1Smatt1: movb (%r1)+,(%r0)+ 1451.1Smatt bneq 1b 1461.1Smatt ret 1471.1Smatt 1481.1SmattENTRY(setjmp, 0) 1491.1Smatt movl 4(%ap), %r0 1501.1Smatt movl 8(%fp), (%r0) 1511.1Smatt movl 12(%fp), 4(%r0) 1521.1Smatt movl 16(%fp), 8(%r0) 1531.1Smatt addl3 %fp,$28,12(%r0) 1541.1Smatt clrl %r0 1551.1Smatt ret 1561.1Smatt 1571.1SmattENTRY(longjmp, 0) 1581.1Smatt movl 4(%ap), %r1 1591.1Smatt movl 8(%ap), %r0 1601.1Smatt movl (%r1), %ap 1611.1Smatt movl 4(%r1), %fp 1621.1Smatt movl 12(%r1), %sp 1631.1Smatt jmp *8(%r1) 1641.1Smatt 165