xref: /illumos-gate/usr/src/uts/sparc/v9/ml/crt.S (revision 5d9d9091)
17c478bd9Sstevel@tonic-gate/*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate/*
237c478bd9Sstevel@tonic-gate *	Copyright (c) 1988-1991 by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"	/* From SunOS 4.1 1.6 */
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
297c478bd9Sstevel@tonic-gate#include <sys/trap.h>
307c478bd9Sstevel@tonic-gate#include <sys/machtrap.h>
317c478bd9Sstevel@tonic-gate#include <sys/simulate.h>
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate/*
347c478bd9Sstevel@tonic-gate * C run time subroutines.
357c478bd9Sstevel@tonic-gate *
367c478bd9Sstevel@tonic-gate *	Those beginning in `.' are not callable from C and hence do not
377c478bd9Sstevel@tonic-gate *	get lint prototypes.
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate/*
417c478bd9Sstevel@tonic-gate * Structure return
427c478bd9Sstevel@tonic-gate */
437c478bd9Sstevel@tonic-gate#define UNIMP		0
447c478bd9Sstevel@tonic-gate#define MASK		0x00000fff
457c478bd9Sstevel@tonic-gate#define STRUCT_VAL_OFF	(16*4)
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate	RTENTRY(.stret4)
487c478bd9Sstevel@tonic-gate	RTENTRY(.stret8)
497c478bd9Sstevel@tonic-gate	!
507c478bd9Sstevel@tonic-gate	! see if key matches: if not, structure value not expected,
517c478bd9Sstevel@tonic-gate	! so just return
527c478bd9Sstevel@tonic-gate	!
537c478bd9Sstevel@tonic-gate	ld	[%i7 + 8], %o3
547c478bd9Sstevel@tonic-gate	and	%o1, MASK, %o4
557c478bd9Sstevel@tonic-gate	sethi	%hi(UNIMP), %o5
567c478bd9Sstevel@tonic-gate	or	%o4, %o5, %o5
577c478bd9Sstevel@tonic-gate	cmp	%o5, %o3
587c478bd9Sstevel@tonic-gate	be,a	0f
597c478bd9Sstevel@tonic-gate	ld	[%fp + STRUCT_VAL_OFF], %i0	! set expected return value
607c478bd9Sstevel@tonic-gate	ret
617c478bd9Sstevel@tonic-gate	restore
627c478bd9Sstevel@tonic-gate0:						! copy the struct
637c478bd9Sstevel@tonic-gate	subcc	%o1, 4, %o1
647c478bd9Sstevel@tonic-gate	ld	[%o0 + %o1], %o4
657c478bd9Sstevel@tonic-gate	bg	0b
667c478bd9Sstevel@tonic-gate	st	%o4, [%i0 + %o1]		! delay slot
677c478bd9Sstevel@tonic-gate	add	%i7, 0x4, %i7			! bump return address
687c478bd9Sstevel@tonic-gate	ret
697c478bd9Sstevel@tonic-gate	restore
707c478bd9Sstevel@tonic-gate	SET_SIZE(.stret4)
717c478bd9Sstevel@tonic-gate	SET_SIZE(.stret8)
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate	RTENTRY(.stret2)
747c478bd9Sstevel@tonic-gate	!
757c478bd9Sstevel@tonic-gate	! see if key matches: if not, structure value not expected,
767c478bd9Sstevel@tonic-gate	! so just return
777c478bd9Sstevel@tonic-gate	!
787c478bd9Sstevel@tonic-gate	ld	[%i7 + 8], %o3
797c478bd9Sstevel@tonic-gate	and	%o1, MASK, %o4
807c478bd9Sstevel@tonic-gate	sethi	%hi(UNIMP), %o5
817c478bd9Sstevel@tonic-gate	or	%o4, %o5, %o5
827c478bd9Sstevel@tonic-gate	cmp	%o5, %o3
837c478bd9Sstevel@tonic-gate	be,a	0f
847c478bd9Sstevel@tonic-gate	ld	[%fp + STRUCT_VAL_OFF], %i0	! set expected return value
857c478bd9Sstevel@tonic-gate	ret
867c478bd9Sstevel@tonic-gate	restore
877c478bd9Sstevel@tonic-gate0:						! copy the struct
887c478bd9Sstevel@tonic-gate	subcc	%o1, 2, %o1
897c478bd9Sstevel@tonic-gate	lduh	[%o0 + %o1], %o4
907c478bd9Sstevel@tonic-gate	bg	0b
917c478bd9Sstevel@tonic-gate	sth	%o4, [%i0 + %o1]		! delay slot
927c478bd9Sstevel@tonic-gate	add	%i7, 0x4, %i7			! bump return address
937c478bd9Sstevel@tonic-gate	ret
947c478bd9Sstevel@tonic-gate	restore
957c478bd9Sstevel@tonic-gate	SET_SIZE(.stret2)
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate/*
987c478bd9Sstevel@tonic-gate * Convert 32-bit arg pairs in %o0:o1 and %o2:%o3 to 64-bit args in %o1 and %o2
997c478bd9Sstevel@tonic-gate */
1007c478bd9Sstevel@tonic-gate#define	ARGS_TO_64				\
1017c478bd9Sstevel@tonic-gate	sllx	%o0, 32, %o0;			\
1027c478bd9Sstevel@tonic-gate	srl	%o1, 0, %o1;			\
1037c478bd9Sstevel@tonic-gate	sllx	%o2, 32, %o2;			\
1047c478bd9Sstevel@tonic-gate	srl	%o3, 0, %o3;			\
1057c478bd9Sstevel@tonic-gate	or	%o0, %o1, %o1;			\
1067c478bd9Sstevel@tonic-gate	or	%o2, %o3, %o2
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate	RTENTRY(__mul64)
1097c478bd9Sstevel@tonic-gate	ALTENTRY(__umul64)
1107c478bd9Sstevel@tonic-gate	ARGS_TO_64
1117c478bd9Sstevel@tonic-gate	sub	%o1, %o2, %o0	! %o0 = a - b
1127c478bd9Sstevel@tonic-gate	movrlz	%o0, %g0, %o0	! %o0 = (a < b) ? 0 : a - b
1137c478bd9Sstevel@tonic-gate	sub	%o1, %o0, %o1	! %o1 = (a < b) ? a : b = min(a, b)
1147c478bd9Sstevel@tonic-gate	add	%o2, %o0, %o2	! %o2 = (a < b) ? b : a = max(a, b)
1157c478bd9Sstevel@tonic-gate	mulx	%o1, %o2, %o1	! min(a, b) in "rs1" for early exit
1167c478bd9Sstevel@tonic-gate	retl
1177c478bd9Sstevel@tonic-gate	srax	%o1, 32, %o0
1187c478bd9Sstevel@tonic-gate	SET_SIZE(__mul64)
1197c478bd9Sstevel@tonic-gate	SET_SIZE(__umul64)
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate	RTENTRY(__div64)
1227c478bd9Sstevel@tonic-gate	ARGS_TO_64
1237c478bd9Sstevel@tonic-gate	sdivx	%o1, %o2, %o1
1247c478bd9Sstevel@tonic-gate	retl
1257c478bd9Sstevel@tonic-gate	srax	%o1, 32, %o0
1267c478bd9Sstevel@tonic-gate	SET_SIZE(__div64)
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate	RTENTRY(__udiv64)
1297c478bd9Sstevel@tonic-gate	ARGS_TO_64
1307c478bd9Sstevel@tonic-gate	udivx	%o1, %o2, %o1
1317c478bd9Sstevel@tonic-gate	retl
1327c478bd9Sstevel@tonic-gate	srax	%o1, 32, %o0
1337c478bd9Sstevel@tonic-gate	SET_SIZE(__udiv64)
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate	RTENTRY(__rem64)
1367c478bd9Sstevel@tonic-gate	ARGS_TO_64
1377c478bd9Sstevel@tonic-gate	sdivx	%o1, %o2, %o3
1387c478bd9Sstevel@tonic-gate	mulx	%o2, %o3, %o3
1397c478bd9Sstevel@tonic-gate	sub	%o1, %o3, %o1
1407c478bd9Sstevel@tonic-gate	retl
1417c478bd9Sstevel@tonic-gate	srax	%o1, 32, %o0
1427c478bd9Sstevel@tonic-gate	SET_SIZE(__rem64)
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate	RTENTRY(__urem64)
1457c478bd9Sstevel@tonic-gate	ARGS_TO_64
1467c478bd9Sstevel@tonic-gate	udivx	%o1, %o2, %o3
1477c478bd9Sstevel@tonic-gate	mulx	%o2, %o3, %o3
1487c478bd9Sstevel@tonic-gate	sub	%o1, %o3, %o1
1497c478bd9Sstevel@tonic-gate	retl
1507c478bd9Sstevel@tonic-gate	srax	%o1, 32, %o0
1517c478bd9Sstevel@tonic-gate	SET_SIZE(__urem64)
1527c478bd9Sstevel@tonic-gate
153