xref: /netbsd/sys/arch/vax/boot/common/str.S (revision bf9ec67e)
1/*	$NetBSD: str.S,v 1.1 2002/02/24 01:04:25 matt 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(bcmp, 0)
75	movl	4(%ap), %r2
76	movl	8(%ap), %r1
77	movl	12(%ap), %r0
782:	cmpb	(%r2)+, (%r1)+
79	bneq	1f
80	decl	%r0
81	bneq	2b
821:	ret
83
84/*
85 * Is movc3/movc5 emulated on any CPU? I dont think so; use them here.
86 */
87ENTRY(bzero,0)
88	movc5	$0,*4(%ap),$0,8(%ap),*4(%ap)
89	ret
90
91ENTRY(bcopy,0)
92	movc3	12(%ap), *4(%ap), *8(%ap)
93	ret
94
95ENTRY(strlen, 0)
96	movl	4(%ap), %r0
971:	tstb	(%r0)+
98	bneq	1b
99	decl	%r0
100	subl2	4(%ap), %r0
101	ret
102
103ENTRY(strncmp, 0)
104	movl	12(%ap), %r3
105	brb	5f
106
107ENTRY(strcmp, 0)
108	movl	$250, %r3	# max string len to compare
1095:	movl	4(%ap), %r2
110	movl	8(%ap), %r1
111	movl	$1, %r0
112
1132:	cmpb	(%r2),(%r1)+
114	bneq	1f		# something differ
115	tstb	(%r2)+
116	beql	4f		# continue, strings unequal
117	decl	%r3		# max string len encountered?
118	bneq	2b
119
1204:	clrl	%r0		# We are done, strings equal.
121	ret
122
1231:	bgtr	3f
124	mnegl	%r0, %r0
1253:	ret
126
127ENTRY(strncpy, 0)
128	movl	4(%ap), %r1
129	movl	8(%ap), %r2
130	movl	12(%ap), %r3
131	bleq	2f
132
1331:	movb	(%r2)+, (%r1)+
134	beql	2f
135	decl	%r3
136	bneq	1b
1372:	ret
138
139ENTRY(strcat, 0)
140	pushl	4(%ap)
141	calls	$1,_C_LABEL(strlen)
142	addl2	4(%ap),%r0
143	movl	8(%ap),%r1
1441:	movb	(%r1)+,(%r0)+
145	bneq	1b
146	ret
147
148ENTRY(setjmp, 0)
149	movl	4(%ap), %r0
150	movl	8(%fp), (%r0)
151	movl	12(%fp), 4(%r0)
152	movl	16(%fp), 8(%r0)
153	addl3	%fp,$28,12(%r0)
154	clrl	%r0
155	ret
156
157ENTRY(longjmp, 0)
158	movl	4(%ap), %r1
159	movl	8(%ap), %r0
160	movl	(%r1), %ap
161	movl	4(%r1), %fp
162	movl	12(%r1), %sp
163	jmp	*8(%r1)
164
165