1/* $NetBSD: str.S,v 1.6 2017/05/22 17:00:19 ragge 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 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27/* 28 * Small versions of the most common functions not using any 29 * emulated instructions. 30 */ 31 32#include "asm.h" 33 34/* 35 * atoi() used in devopen. 36 */ 37ENTRY(atoi, 0) 38 movl 4(%ap),%r1 39 clrl %r0 40 412: movzbl (%r1)+,%r2 42 cmpb %r2,$48 43 blss 1f 44 cmpb %r2,$57 45 bgtr 1f 46 subl2 $48,%r2 47 mull2 $10,%r0 48 addl2 %r2,%r0 49 brb 2b 501: ret 51 52/* 53 * strchr() small and easy. 54 */ 55ENTRY(strchr, 0) 56 movq 4(%ap),%r0 571: cmpb (%r0), 8(%ap) 58 beql 2f 59 tstb (%r0)+ 60 bneq 1b 61 clrl %r0 622: ret 63 64/* 65 * cmpc3 is emulated on MVII. 66 */ 67ENTRY(memcmp, 0) 68 brb 10f 69ENTRY(bcmp, 0) 7010: movl 4(%ap), %r2 71 movl 8(%ap), %r1 72 movl 12(%ap), %r0 732: cmpb (%r2)+, (%r1)+ 74 bneq 1f 75 sobgtr %r0, 2b 763: ret 771: bgtru 5f 78 movl $-1, %r0 79 brb 3b 805: movl $1, %r0 81 ret 82 83/* 84 * movc can't do length in excess of 64K, so we shall not use them. 85 */ 86ENTRY(bzero,0) 87 movl 4(%ap),%r0 88 movl 8(%ap),%r1 891: clrb (%r0)+ 90 sobgtr %r1,1b 91 ret 92 93/* 94 * memcpy and bcopy are the same, except for argument order. Silly stuff. 95 */ 96ENTRY(memcpy,0) 97 movl 8(%ap),%r0 98 movl 4(%ap),%r1 99 brb 1f 100ENTRY(bcopy,0) 101 movl 4(%ap),%r0 102 movl 8(%ap),%r1 1031: movl 12(%ap),%r2 104 cmpl %r0,%r1 105 bgtru 3f 106 addl2 %r2,%r0 107 addl2 %r2,%r1 1082: movb -(%r0),-(%r1) 109 sobgtr %r2,2b 110 ret 1113: movb (%r0)+,(%r1)+ 112 sobgtr %r2,3b 113 ret 114 115ENTRY(memset,0) 116 movl 4(%ap),%r0 117 movl 12(%ap),%r1 1181: movb 8(%ap),(%r0)+ 119 sobgtr %r1,1b 120 ret 121 122ENTRY(strlen, 0) 123 movl 4(%ap), %r0 1241: tstb (%r0)+ 125 bneq 1b 126 decl %r0 127 subl2 4(%ap), %r0 128 ret 129 130ENTRY(strncmp, 0) 131 movl 12(%ap), %r3 132 bneq 5f 133 brb 4f 134 135ENTRY(strcmp, 0) 136 movl $250, %r3 # max string len to compare 1375: movl 4(%ap), %r2 138 movl 8(%ap), %r1 139 movl $1, %r0 140 1412: cmpb (%r2),(%r1)+ 142 bneq 1f # something differ 143 tstb (%r2)+ 144 beql 4f # continue, strings unequal 145 decl %r3 # max string len encountered? 146 bneq 2b 147 1484: clrl %r0 # We are done, strings equal. 149 ret 150 1511: bgtru 3f 152 mnegl %r0, %r0 1533: ret 154 155ENTRY(strncpy, 0) 156 movl 4(%ap), %r1 157 movl 8(%ap), %r2 158 movl 12(%ap), %r3 159 bleq 2f 160 1611: movb (%r2)+, (%r1)+ 162 beql 2f 163 sobgtr %r3,1b 164 ret 1652: decl %r1 1663: clrb (%r1)+ 167 sobgtr %r3,3b 168 ret 169 170ENTRY(strcat, 0) 171 pushl 4(%ap) 172 calls $1,_C_LABEL(strlen) 173 addl2 4(%ap),%r0 174 movl 8(%ap),%r1 1751: movb (%r1)+,(%r0)+ 176 bneq 1b 177 ret 178 179ENTRY(setjmp, 0) 180 movl 4(%ap), %r0 181 movl 8(%fp), (%r0) 182 movl 12(%fp), 4(%r0) 183 movl 16(%fp), 8(%r0) 184 addl3 %fp,$28,12(%r0) 185 clrl %r0 186 ret 187 188ENTRY(longjmp, 0) 189 movl 4(%ap), %r1 190 movl 8(%ap), %r0 191 movl (%r1), %ap 192 movl 4(%r1), %fp 193 movl 12(%r1), %sp 194 jmp *8(%r1) 195 196