str.S revision 1.4
11.4Sjdolecek/*	$NetBSD: str.S,v 1.4 2003/11/01 13:02:04 jdolecek 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.4Sjdolecek * strchr() small and easy.
601.1Smatt */
611.4SjdolecekENTRY(strchr, 0)
621.1Smatt	movq	4(%ap),%r0
631.3Sragge1:	cmpb	(%r0), 8(%ap)
641.1Smatt	beql	2f
651.1Smatt	tstb	(%r0)+
661.1Smatt	bneq	1b
671.1Smatt	clrl	%r0
681.1Smatt2:	ret
691.1Smatt
701.1Smatt/*
711.1Smatt * cmpc3 is emulated on MVII.
721.1Smatt */
731.2SdslENTRY(memcmp, 0)
741.2Sdsl	brb	10f
751.1SmattENTRY(bcmp, 0)
761.2Sdsl10:	movl	4(%ap), %r2
771.1Smatt	movl	8(%ap), %r1
781.1Smatt	movl	12(%ap), %r0
791.1Smatt2:	cmpb	(%r2)+, (%r1)+
801.1Smatt	bneq	1f
811.3Sragge	sobgtr	%r0, 2b
821.2Sdsl3:	ret
831.2Sdsl1:	bgtru	5f
841.2Sdsl	movl	$-1, %r0
851.2Sdsl	brb	3b
861.2Sdsl5:	movl    $1, %r0
871.2Sdsl	ret
881.1Smatt
891.1Smatt/*
901.3Sragge * movc can't do length in excess of 64K, so we shall not use them.
911.1Smatt */
921.1SmattENTRY(bzero,0)
931.3Sragge	movl	4(%ap),%r0
941.3Sragge	movl	8(%ap),%r1
951.3Sragge1:	clrb	(%r0)+
961.3Sragge	sobgtr	%r1,1b
971.1Smatt	ret
981.1Smatt
991.3Sragge/*
1001.3Sragge * memcpy and bcopy are the same, except for argument order. Silly stuff.
1011.3Sragge */
1021.3SraggeENTRY(memcpy,0)
1031.3Sragge	movl	8(%ap),%r0
1041.3Sragge	movl	4(%ap),%r1
1051.3Sragge	brb	1f
1061.1SmattENTRY(bcopy,0)
1071.3Sragge	movl	4(%ap),%r0
1081.3Sragge	movl	8(%ap),%r1
1091.3Sragge1:	movl	12(%ap),%r2
1101.3Sragge	cmpl	%r0,%r1
1111.3Sragge	bgtru	3f
1121.3Sragge	addl2	%r2,%r0
1131.3Sragge	addl2	%r2,%r1
1141.3Sragge2:	movb	-(%r0),-(%r1)
1151.3Sragge	sobgtr	%r2,2b
1161.3Sragge	ret
1171.3Sragge3:	movb	(%r0)+,(%r1)+
1181.3Sragge	sobgtr	%r2,3b
1191.1Smatt	ret
1201.1Smatt
1211.2SdslENTRY(memset,0)
1221.3Sragge	movl	4(%ap),%r0
1231.3Sragge	movl	12(%ap),%r1
1241.3Sragge1:	movb	8(%ap),(%r0)+
1251.3Sragge	sobgtr	%r1,1b
1261.2Sdsl	ret
1271.2Sdsl
1281.1SmattENTRY(strlen, 0)
1291.1Smatt	movl	4(%ap), %r0
1301.1Smatt1:	tstb	(%r0)+
1311.1Smatt	bneq	1b
1321.1Smatt	decl	%r0
1331.1Smatt	subl2	4(%ap), %r0
1341.1Smatt	ret
1351.1Smatt
1361.1SmattENTRY(strncmp, 0)
1371.1Smatt	movl	12(%ap), %r3
1381.2Sdsl	bneq	5f
1391.2Sdsl	brb	4f
1401.1Smatt
1411.1SmattENTRY(strcmp, 0)
1421.1Smatt	movl	$250, %r3	# max string len to compare
1431.1Smatt5:	movl	4(%ap), %r2
1441.1Smatt	movl	8(%ap), %r1
1451.1Smatt	movl	$1, %r0
1461.1Smatt
1471.1Smatt2:	cmpb	(%r2),(%r1)+
1481.1Smatt	bneq	1f		# something differ
1491.1Smatt	tstb	(%r2)+
1501.1Smatt	beql	4f		# continue, strings unequal
1511.1Smatt	decl	%r3		# max string len encountered?
1521.1Smatt	bneq	2b
1531.1Smatt
1541.1Smatt4:	clrl	%r0		# We are done, strings equal.
1551.1Smatt	ret
1561.1Smatt
1571.2Sdsl1:	bgtru	3f
1581.1Smatt	mnegl	%r0, %r0
1591.1Smatt3:	ret
1601.1Smatt
1611.1SmattENTRY(strncpy, 0)
1621.1Smatt	movl	4(%ap), %r1
1631.1Smatt	movl	8(%ap), %r2
1641.1Smatt	movl	12(%ap), %r3
1651.1Smatt	bleq	2f
1661.1Smatt
1671.1Smatt1:	movb	(%r2)+, (%r1)+
1681.1Smatt	beql	2f
1691.3Sragge	sobgtr	%r3,1b
1701.3Sragge	ret
1711.3Sragge2:	decl	%r1
1721.3Sragge3:	clrb	(%r1)+
1731.3Sragge	sobgtr	%r3,3b
1741.3Sragge	ret
1751.1Smatt
1761.1SmattENTRY(strcat, 0)
1771.1Smatt	pushl	4(%ap)
1781.1Smatt	calls	$1,_C_LABEL(strlen)
1791.1Smatt	addl2	4(%ap),%r0
1801.1Smatt	movl	8(%ap),%r1
1811.1Smatt1:	movb	(%r1)+,(%r0)+
1821.1Smatt	bneq	1b
1831.1Smatt	ret
1841.1Smatt
1851.1SmattENTRY(setjmp, 0)
1861.1Smatt	movl	4(%ap), %r0
1871.1Smatt	movl	8(%fp), (%r0)
1881.1Smatt	movl	12(%fp), 4(%r0)
1891.1Smatt	movl	16(%fp), 8(%r0)
1901.1Smatt	addl3	%fp,$28,12(%r0)
1911.1Smatt	clrl	%r0
1921.1Smatt	ret
1931.1Smatt
1941.1SmattENTRY(longjmp, 0)
1951.1Smatt	movl	4(%ap), %r1
1961.1Smatt	movl	8(%ap), %r0
1971.1Smatt	movl	(%r1), %ap
1981.1Smatt	movl	4(%r1), %fp
1991.1Smatt	movl	12(%r1), %sp
2001.1Smatt	jmp	*8(%r1)
2011.1Smatt
202