str.S revision 1.2
11.2Sdsl/*	$NetBSD: str.S,v 1.2 2003/09/04 10:40:44 dsl 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.2SdslENTRY(memcmp, 0)
751.2Sdsl	brb	10f
761.1SmattENTRY(bcmp, 0)
771.2Sdsl10:	movl	4(%ap), %r2
781.1Smatt	movl	8(%ap), %r1
791.1Smatt	movl	12(%ap), %r0
801.1Smatt2:	cmpb	(%r2)+, (%r1)+
811.1Smatt	bneq	1f
821.1Smatt	decl	%r0
831.1Smatt	bneq	2b
841.2Sdsl3:	ret
851.2Sdsl1:	bgtru	5f
861.2Sdsl	movl	$-1, %r0
871.2Sdsl	brb	3b
881.2Sdsl5:	movl    $1, %r0
891.2Sdsl	ret
901.1Smatt
911.1Smatt/*
921.1Smatt * Is movc3/movc5 emulated on any CPU? I dont think so; use them here.
931.1Smatt */
941.1SmattENTRY(bzero,0)
951.1Smatt	movc5	$0,*4(%ap),$0,8(%ap),*4(%ap)
961.1Smatt	ret
971.1Smatt
981.1SmattENTRY(bcopy,0)
991.1Smatt	movc3	12(%ap), *4(%ap), *8(%ap)
1001.1Smatt	ret
1011.1Smatt
1021.2SdslENTRY(memset,0)
1031.2Sdsl	movc5	$0,*4(%ap),8(%ap),12(%ap),*4(%ap)
1041.2Sdsl	movl    4(%ap), %r0
1051.2Sdsl	ret
1061.2Sdsl
1071.2SdslENTRY(memcpy,0)
1081.2Sdsl	movc3	12(%ap), *8(%ap), *4(%ap)
1091.2Sdsl	movl    4(%ap), %r0
1101.2Sdsl	ret
1111.2Sdsl
1121.1SmattENTRY(strlen, 0)
1131.1Smatt	movl	4(%ap), %r0
1141.1Smatt1:	tstb	(%r0)+
1151.1Smatt	bneq	1b
1161.1Smatt	decl	%r0
1171.1Smatt	subl2	4(%ap), %r0
1181.1Smatt	ret
1191.1Smatt
1201.1SmattENTRY(strncmp, 0)
1211.1Smatt	movl	12(%ap), %r3
1221.2Sdsl	bneq	5f
1231.2Sdsl	brb	4f
1241.1Smatt
1251.1SmattENTRY(strcmp, 0)
1261.1Smatt	movl	$250, %r3	# max string len to compare
1271.1Smatt5:	movl	4(%ap), %r2
1281.1Smatt	movl	8(%ap), %r1
1291.1Smatt	movl	$1, %r0
1301.1Smatt
1311.1Smatt2:	cmpb	(%r2),(%r1)+
1321.1Smatt	bneq	1f		# something differ
1331.1Smatt	tstb	(%r2)+
1341.1Smatt	beql	4f		# continue, strings unequal
1351.1Smatt	decl	%r3		# max string len encountered?
1361.1Smatt	bneq	2b
1371.1Smatt
1381.1Smatt4:	clrl	%r0		# We are done, strings equal.
1391.1Smatt	ret
1401.1Smatt
1411.2Sdsl1:	bgtru	3f
1421.1Smatt	mnegl	%r0, %r0
1431.1Smatt3:	ret
1441.1Smatt
1451.1SmattENTRY(strncpy, 0)
1461.1Smatt	movl	4(%ap), %r1
1471.1Smatt	movl	8(%ap), %r2
1481.1Smatt	movl	12(%ap), %r3
1491.1Smatt	bleq	2f
1501.1Smatt
1511.1Smatt1:	movb	(%r2)+, (%r1)+
1521.1Smatt	beql	2f
1531.1Smatt	decl	%r3
1541.1Smatt	bneq	1b
1551.1Smatt2:	ret
1561.1Smatt
1571.1SmattENTRY(strcat, 0)
1581.1Smatt	pushl	4(%ap)
1591.1Smatt	calls	$1,_C_LABEL(strlen)
1601.1Smatt	addl2	4(%ap),%r0
1611.1Smatt	movl	8(%ap),%r1
1621.1Smatt1:	movb	(%r1)+,(%r0)+
1631.1Smatt	bneq	1b
1641.1Smatt	ret
1651.1Smatt
1661.1SmattENTRY(setjmp, 0)
1671.1Smatt	movl	4(%ap), %r0
1681.1Smatt	movl	8(%fp), (%r0)
1691.1Smatt	movl	12(%fp), 4(%r0)
1701.1Smatt	movl	16(%fp), 8(%r0)
1711.1Smatt	addl3	%fp,$28,12(%r0)
1721.1Smatt	clrl	%r0
1731.1Smatt	ret
1741.1Smatt
1751.1SmattENTRY(longjmp, 0)
1761.1Smatt	movl	4(%ap), %r1
1771.1Smatt	movl	8(%ap), %r0
1781.1Smatt	movl	(%r1), %ap
1791.1Smatt	movl	4(%r1), %fp
1801.1Smatt	movl	12(%r1), %sp
1811.1Smatt	jmp	*8(%r1)
1821.1Smatt
183