xref: /onnv-gate/usr/src/uts/sparc/v9/ml/crt.s (revision 0:68f95e015346)
1*0Sstevel@tonic-gate/*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate/*
23*0Sstevel@tonic-gate *	Copyright (c) 1988-1991 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate */
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"	/* From SunOS 4.1 1.6 */
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate#if defined(lint)
29*0Sstevel@tonic-gate#include <sys/types.h>
30*0Sstevel@tonic-gate#include <sys/regset.h>
31*0Sstevel@tonic-gate#include <sys/privregs.h>
32*0Sstevel@tonic-gate#endif  /* lint */
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate#include <sys/asm_linkage.h>
35*0Sstevel@tonic-gate#include <sys/trap.h>
36*0Sstevel@tonic-gate#include <sys/machtrap.h>
37*0Sstevel@tonic-gate#include <sys/simulate.h>
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gate/*
40*0Sstevel@tonic-gate * C run time subroutines.
41*0Sstevel@tonic-gate *
42*0Sstevel@tonic-gate *	Those beginning in `.' are not callable from C and hence do not
43*0Sstevel@tonic-gate *	get lint prototypes.
44*0Sstevel@tonic-gate */
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate#if !defined(lint)
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate/*
49*0Sstevel@tonic-gate * Structure return
50*0Sstevel@tonic-gate */
51*0Sstevel@tonic-gate#define UNIMP		0
52*0Sstevel@tonic-gate#define MASK		0x00000fff
53*0Sstevel@tonic-gate#define STRUCT_VAL_OFF	(16*4)
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gate	RTENTRY(.stret4)
56*0Sstevel@tonic-gate	RTENTRY(.stret8)
57*0Sstevel@tonic-gate	!
58*0Sstevel@tonic-gate	! see if key matches: if not, structure value not expected,
59*0Sstevel@tonic-gate	! so just return
60*0Sstevel@tonic-gate	!
61*0Sstevel@tonic-gate	ld	[%i7 + 8], %o3
62*0Sstevel@tonic-gate	and	%o1, MASK, %o4
63*0Sstevel@tonic-gate	sethi	%hi(UNIMP), %o5
64*0Sstevel@tonic-gate	or	%o4, %o5, %o5
65*0Sstevel@tonic-gate	cmp	%o5, %o3
66*0Sstevel@tonic-gate	be,a	0f
67*0Sstevel@tonic-gate	ld	[%fp + STRUCT_VAL_OFF], %i0	! set expected return value
68*0Sstevel@tonic-gate	ret
69*0Sstevel@tonic-gate	restore
70*0Sstevel@tonic-gate0:						! copy the struct
71*0Sstevel@tonic-gate	subcc	%o1, 4, %o1
72*0Sstevel@tonic-gate	ld	[%o0 + %o1], %o4
73*0Sstevel@tonic-gate	bg	0b
74*0Sstevel@tonic-gate	st	%o4, [%i0 + %o1]		! delay slot
75*0Sstevel@tonic-gate	add	%i7, 0x4, %i7			! bump return address
76*0Sstevel@tonic-gate	ret
77*0Sstevel@tonic-gate	restore
78*0Sstevel@tonic-gate	SET_SIZE(.stret4)
79*0Sstevel@tonic-gate	SET_SIZE(.stret8)
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate	RTENTRY(.stret2)
82*0Sstevel@tonic-gate	!
83*0Sstevel@tonic-gate	! see if key matches: if not, structure value not expected,
84*0Sstevel@tonic-gate	! so just return
85*0Sstevel@tonic-gate	!
86*0Sstevel@tonic-gate	ld	[%i7 + 8], %o3
87*0Sstevel@tonic-gate	and	%o1, MASK, %o4
88*0Sstevel@tonic-gate	sethi	%hi(UNIMP), %o5
89*0Sstevel@tonic-gate	or	%o4, %o5, %o5
90*0Sstevel@tonic-gate	cmp	%o5, %o3
91*0Sstevel@tonic-gate	be,a	0f
92*0Sstevel@tonic-gate	ld	[%fp + STRUCT_VAL_OFF], %i0	! set expected return value
93*0Sstevel@tonic-gate	ret
94*0Sstevel@tonic-gate	restore
95*0Sstevel@tonic-gate0:						! copy the struct
96*0Sstevel@tonic-gate	subcc	%o1, 2, %o1
97*0Sstevel@tonic-gate	lduh	[%o0 + %o1], %o4
98*0Sstevel@tonic-gate	bg	0b
99*0Sstevel@tonic-gate	sth	%o4, [%i0 + %o1]		! delay slot
100*0Sstevel@tonic-gate	add	%i7, 0x4, %i7			! bump return address
101*0Sstevel@tonic-gate	ret
102*0Sstevel@tonic-gate	restore
103*0Sstevel@tonic-gate	SET_SIZE(.stret2)
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gate/*
106*0Sstevel@tonic-gate * Convert 32-bit arg pairs in %o0:o1 and %o2:%o3 to 64-bit args in %o1 and %o2
107*0Sstevel@tonic-gate */
108*0Sstevel@tonic-gate#define	ARGS_TO_64				\
109*0Sstevel@tonic-gate	sllx	%o0, 32, %o0;			\
110*0Sstevel@tonic-gate	srl	%o1, 0, %o1;			\
111*0Sstevel@tonic-gate	sllx	%o2, 32, %o2;			\
112*0Sstevel@tonic-gate	srl	%o3, 0, %o3;			\
113*0Sstevel@tonic-gate	or	%o0, %o1, %o1;			\
114*0Sstevel@tonic-gate	or	%o2, %o3, %o2
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gate	RTENTRY(__mul64)
117*0Sstevel@tonic-gate	ALTENTRY(__umul64)
118*0Sstevel@tonic-gate	ARGS_TO_64
119*0Sstevel@tonic-gate	sub	%o1, %o2, %o0	! %o0 = a - b
120*0Sstevel@tonic-gate	movrlz	%o0, %g0, %o0	! %o0 = (a < b) ? 0 : a - b
121*0Sstevel@tonic-gate	sub	%o1, %o0, %o1	! %o1 = (a < b) ? a : b = min(a, b)
122*0Sstevel@tonic-gate	add	%o2, %o0, %o2	! %o2 = (a < b) ? b : a = max(a, b)
123*0Sstevel@tonic-gate	mulx	%o1, %o2, %o1	! min(a, b) in "rs1" for early exit
124*0Sstevel@tonic-gate	retl
125*0Sstevel@tonic-gate	srax	%o1, 32, %o0
126*0Sstevel@tonic-gate	SET_SIZE(__mul64)
127*0Sstevel@tonic-gate	SET_SIZE(__umul64)
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate	RTENTRY(__div64)
130*0Sstevel@tonic-gate	ARGS_TO_64
131*0Sstevel@tonic-gate	sdivx	%o1, %o2, %o1
132*0Sstevel@tonic-gate	retl
133*0Sstevel@tonic-gate	srax	%o1, 32, %o0
134*0Sstevel@tonic-gate	SET_SIZE(__div64)
135*0Sstevel@tonic-gate
136*0Sstevel@tonic-gate	RTENTRY(__udiv64)
137*0Sstevel@tonic-gate	ARGS_TO_64
138*0Sstevel@tonic-gate	udivx	%o1, %o2, %o1
139*0Sstevel@tonic-gate	retl
140*0Sstevel@tonic-gate	srax	%o1, 32, %o0
141*0Sstevel@tonic-gate	SET_SIZE(__udiv64)
142*0Sstevel@tonic-gate
143*0Sstevel@tonic-gate	RTENTRY(__rem64)
144*0Sstevel@tonic-gate	ARGS_TO_64
145*0Sstevel@tonic-gate	sdivx	%o1, %o2, %o3
146*0Sstevel@tonic-gate	mulx	%o2, %o3, %o3
147*0Sstevel@tonic-gate	sub	%o1, %o3, %o1
148*0Sstevel@tonic-gate	retl
149*0Sstevel@tonic-gate	srax	%o1, 32, %o0
150*0Sstevel@tonic-gate	SET_SIZE(__rem64)
151*0Sstevel@tonic-gate
152*0Sstevel@tonic-gate	RTENTRY(__urem64)
153*0Sstevel@tonic-gate	ARGS_TO_64
154*0Sstevel@tonic-gate	udivx	%o1, %o2, %o3
155*0Sstevel@tonic-gate	mulx	%o2, %o3, %o3
156*0Sstevel@tonic-gate	sub	%o1, %o3, %o1
157*0Sstevel@tonic-gate	retl
158*0Sstevel@tonic-gate	srax	%o1, 32, %o0
159*0Sstevel@tonic-gate	SET_SIZE(__urem64)
160*0Sstevel@tonic-gate
161*0Sstevel@tonic-gate#endif /* !lint */
162