xref: /onnv-gate/usr/src/uts/sun4u/ml/mach_xc.s (revision 11172:a792f425ae2e)
10Sstevel@tonic-gate/*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*11172SHaik.Aftandilian@Sun.COM * Common Development and Distribution License (the "License").
6*11172SHaik.Aftandilian@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate/*
22*11172SHaik.Aftandilian@Sun.COM * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate#if defined(lint)
270Sstevel@tonic-gate#include <sys/types.h>
280Sstevel@tonic-gate#include <sys/cpuvar.h>
290Sstevel@tonic-gate#else	/*lint */
300Sstevel@tonic-gate#include "assym.h"
310Sstevel@tonic-gate#endif	/* lint */
320Sstevel@tonic-gate
330Sstevel@tonic-gate#include <sys/asm_linkage.h>
340Sstevel@tonic-gate#include <sys/privregs.h>
350Sstevel@tonic-gate#include <sys/x_call.h>
360Sstevel@tonic-gate#include <sys/xc_impl.h>
370Sstevel@tonic-gate
380Sstevel@tonic-gate#ifdef TRAPTRACE
390Sstevel@tonic-gate#include <sys/traptrace.h>
400Sstevel@tonic-gate#endif /* TRAPTRACE */
410Sstevel@tonic-gate
420Sstevel@tonic-gate
430Sstevel@tonic-gate#if defined(lint)
440Sstevel@tonic-gate
450Sstevel@tonic-gate/* ARGSUSED */
460Sstevel@tonic-gatevoid
470Sstevel@tonic-gateself_xcall(struct cpu *cpu, uint64_t arg1, uint64_t arg2, xcfunc_t *func)
480Sstevel@tonic-gate{}
490Sstevel@tonic-gate
500Sstevel@tonic-gate#else
510Sstevel@tonic-gate
520Sstevel@tonic-gate/*
530Sstevel@tonic-gate * Entered by the software trap (TT=ST_SELFXCALL, TL>0) thru send_self_xcall().
540Sstevel@tonic-gate * Emulate the mondo handler - vec_interrupt().
550Sstevel@tonic-gate *
560Sstevel@tonic-gate * Global registers are the Alternate Globals.
570Sstevel@tonic-gate * Arguments:
580Sstevel@tonic-gate * 	%o0 - CPU
590Sstevel@tonic-gate * 	ILP32 kernel:
600Sstevel@tonic-gate * 		%o5 - function to call
610Sstevel@tonic-gate * 		%o1, %o2, %o3, %o4  - arguments
620Sstevel@tonic-gate * 	LP64 kernel:
630Sstevel@tonic-gate * 		%o3 - function to call
640Sstevel@tonic-gate * 		%o1, %o2 - arguments
650Sstevel@tonic-gate */
660Sstevel@tonic-gate	ENTRY_NP(self_xcall)
670Sstevel@tonic-gate	!
680Sstevel@tonic-gate	! TL>0 handlers are expected to do "retry"
690Sstevel@tonic-gate	! prepare their return PC and nPC now
700Sstevel@tonic-gate	!
710Sstevel@tonic-gate	rdpr	%tnpc, %g1
720Sstevel@tonic-gate	wrpr	%g1, %tpc			!  PC <- TNPC[TL]
730Sstevel@tonic-gate 	add	%g1, 4, %g1
740Sstevel@tonic-gate	wrpr	%g1, %tnpc			! nPC <- TNPC[TL] + 4
750Sstevel@tonic-gate
760Sstevel@tonic-gate#ifdef TRAPTRACE
770Sstevel@tonic-gate	TRACE_PTR(%g4, %g6)
78*11172SHaik.Aftandilian@Sun.COM	GET_TRACE_TICK(%g6, %g3)
790Sstevel@tonic-gate	stxa	%g6, [%g4 + TRAP_ENT_TICK]%asi
800Sstevel@tonic-gate	rdpr	%tl, %g6
810Sstevel@tonic-gate	stha	%g6, [%g4 + TRAP_ENT_TL]%asi
820Sstevel@tonic-gate	rdpr	%tt, %g6
830Sstevel@tonic-gate	stha	%g6, [%g4 + TRAP_ENT_TT]%asi
840Sstevel@tonic-gate	stna	%o3, [%g4 + TRAP_ENT_TR]%asi ! pc of the TL>0 handler
850Sstevel@tonic-gate	rdpr	%tpc, %g6
860Sstevel@tonic-gate	stna	%g6, [%g4 + TRAP_ENT_TPC]%asi
870Sstevel@tonic-gate	rdpr	%tstate, %g6
880Sstevel@tonic-gate	stxa	%g6, [%g4 + TRAP_ENT_TSTATE]%asi
890Sstevel@tonic-gate	stna	%sp, [%g4 + TRAP_ENT_SP]%asi
900Sstevel@tonic-gate	stna	%o1, [%g4 + TRAP_ENT_F1]%asi ! arg 1
910Sstevel@tonic-gate	stna	%o2, [%g4 + TRAP_ENT_F2]%asi ! arg 2
920Sstevel@tonic-gate	stna	%g0, [%g4 + TRAP_ENT_F3]%asi
930Sstevel@tonic-gate	stna	%g0, [%g4 + TRAP_ENT_F4]%asi
940Sstevel@tonic-gate	TRACE_NEXT(%g4, %g6, %g3)
950Sstevel@tonic-gate#endif /* TRAPTRACE */
960Sstevel@tonic-gate	!
970Sstevel@tonic-gate	! Load the arguments for the fast trap handler.
980Sstevel@tonic-gate	!
990Sstevel@tonic-gate	mov	%o1, %g1
1000Sstevel@tonic-gate	jmp	%o3				! call the fast trap handler
1010Sstevel@tonic-gate	mov	%o2, %g2
1020Sstevel@tonic-gate	/* Not Reached */
1030Sstevel@tonic-gate	SET_SIZE(self_xcall)
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate#endif	/* lint */
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate#ifdef  TRAPTRACE
1080Sstevel@tonic-gate#if defined(lint)
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate/* ARGSUSED */
1110Sstevel@tonic-gatevoid
1120Sstevel@tonic-gatexc_trace(u_int traptype, cpuset_t *cpu_set, xcfunc_t *func,
1130Sstevel@tonic-gate	uint64_t arg1, uint64_t arg2)
1140Sstevel@tonic-gate{}
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate#else	/* lint */
1170Sstevel@tonic-gate	ENTRY(xc_trace)
1180Sstevel@tonic-gate	rdpr	%pstate, %g1
1190Sstevel@tonic-gate	andn	%g1, PSTATE_IE | PSTATE_AM, %g2
1200Sstevel@tonic-gate	wrpr	%g0, %g2, %pstate			/* disable interrupts */
1210Sstevel@tonic-gate	TRACE_PTR(%g3, %g4)
122*11172SHaik.Aftandilian@Sun.COM	GET_TRACE_TICK(%g6, %g4)
1230Sstevel@tonic-gate	stxa	%g6, [%g3 + TRAP_ENT_TICK]%asi
1240Sstevel@tonic-gate	stha	%g0, [%g3 + TRAP_ENT_TL]%asi
1250Sstevel@tonic-gate	set	TT_XCALL, %g2
1260Sstevel@tonic-gate	or	%o0, %g2, %g4
1270Sstevel@tonic-gate	stha	%g4, [%g3 + TRAP_ENT_TT]%asi
1280Sstevel@tonic-gate	stna	%o7, [%g3 + TRAP_ENT_TPC]%asi
1290Sstevel@tonic-gate	ldn	[%o1], %g2
1300Sstevel@tonic-gate	stna	%g2, [%g3 + TRAP_ENT_SP]%asi		/* sp = cpuset */
1310Sstevel@tonic-gate	stna	%o2, [%g3 + TRAP_ENT_TR]%asi		/* tr = func */
1320Sstevel@tonic-gate	stna	%o3, [%g3 + TRAP_ENT_F1]%asi		/* f1 = arg1 */
1330Sstevel@tonic-gate	stna	%o4, [%g3 + TRAP_ENT_F2]%asi		/* f2 = arg2 */
1340Sstevel@tonic-gate	stna	%g0, [%g3 + TRAP_ENT_F3]%asi		/* f3 = 0 */
1350Sstevel@tonic-gate	stna	%i7, [%g3 + TRAP_ENT_F4]%asi		/* f4 = xcall caller */
1360Sstevel@tonic-gate	stxa	%g1, [%g3 + TRAP_ENT_TSTATE]%asi	/* tstate = pstate */
1370Sstevel@tonic-gate	TRACE_NEXT(%g2, %g3, %g4)
1380Sstevel@tonic-gate/*
1390Sstevel@tonic-gate * In the case of a cpuset of greater size than a long we
1400Sstevel@tonic-gate * grab extra trace buffers just to store the cpuset.
1410Sstevel@tonic-gate * Seems like a waste but popular opinion opted for this
1420Sstevel@tonic-gate * rather than increase the size of the buffer.
1430Sstevel@tonic-gate */
1440Sstevel@tonic-gate#if CPUSET_SIZE > CLONGSIZE
1450Sstevel@tonic-gate	add	%o1, CPUSET_SIZE, %g5			/* end of cpuset */
1460Sstevel@tonic-gate	clr	%o2
1470Sstevel@tonic-gate1:
1480Sstevel@tonic-gate	TRACE_PTR(%g3, %g4)
1490Sstevel@tonic-gate	stha	%g0, [%g3 + TRAP_ENT_TL]%asi
1500Sstevel@tonic-gate	set	TT_XCALL_CONT, %g2
1510Sstevel@tonic-gate	or	%g2, %o2, %g2				/* continuation # */
1520Sstevel@tonic-gate	stha	%g2, [%g3 + TRAP_ENT_TT]%asi
1530Sstevel@tonic-gate	stxa	%g6, [%g3 + TRAP_ENT_TICK]%asi		/* same tick */
1540Sstevel@tonic-gate	stna	%g0, [%g3 + TRAP_ENT_TPC]%asi		/* clr unused fields */
1550Sstevel@tonic-gate	stna	%g0, [%g3 + TRAP_ENT_SP]%asi
1560Sstevel@tonic-gate	stna	%g0, [%g3 + TRAP_ENT_TR]%asi
1570Sstevel@tonic-gate	stxa	%g0, [%g3 + TRAP_ENT_TSTATE]%asi
1580Sstevel@tonic-gate	stna	%g0, [%g3 + TRAP_ENT_F2]%asi
1590Sstevel@tonic-gate	stna	%g0, [%g3 + TRAP_ENT_F3]%asi
1600Sstevel@tonic-gate	stna	%g0, [%g3 + TRAP_ENT_F4]%asi
1610Sstevel@tonic-gate	ldn	[%o1], %g2
1620Sstevel@tonic-gate	stna	%g2, [%g3 + TRAP_ENT_F1]%asi
1630Sstevel@tonic-gate	add	%o1, CLONGSIZE, %o1
1640Sstevel@tonic-gate	cmp	%o1, %g5
1650Sstevel@tonic-gate	bge	2f
1660Sstevel@tonic-gate	ldn	[%o1], %g2
1670Sstevel@tonic-gate	stna	%g2, [%g3 + TRAP_ENT_F2]%asi
1680Sstevel@tonic-gate	add	%o1, CLONGSIZE, %o1
1690Sstevel@tonic-gate	cmp	%o1, %g5
1700Sstevel@tonic-gate	bge	2f
1710Sstevel@tonic-gate	ldn	[%o1], %g2
1720Sstevel@tonic-gate	stna	%g2, [%g3 + TRAP_ENT_F3]%asi
1730Sstevel@tonic-gate	add	%o1, CLONGSIZE, %o1
1740Sstevel@tonic-gate	cmp	%o1, %g5
1750Sstevel@tonic-gate	bge	2f
1760Sstevel@tonic-gate	ldn	[%o1], %g2
1770Sstevel@tonic-gate	stna	%g2, [%g3 + TRAP_ENT_F4]%asi
1780Sstevel@tonic-gate	add	%o1, CLONGSIZE, %o1
1790Sstevel@tonic-gate2:
1800Sstevel@tonic-gate	TRACE_NEXT(%g2, %g3, %g4)
1810Sstevel@tonic-gate	cmp	%o1, %g5
1820Sstevel@tonic-gate	bl	1b
1830Sstevel@tonic-gate	inc	%o2
1840Sstevel@tonic-gate#endif	/* CPUSET_SIZE */
1850Sstevel@tonic-gate	retl
1860Sstevel@tonic-gate	wrpr	%g0, %g1, %pstate			/* enable interrupts */
1870Sstevel@tonic-gate	SET_SIZE(xc_trace)
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate#endif	/* lint */
1900Sstevel@tonic-gate#endif	/* TRAPTRACE */
1910Sstevel@tonic-gate
1920Sstevel@tonic-gate#if defined(lint)
1930Sstevel@tonic-gate
1940Sstevel@tonic-gate/* ARGSUSED */
1950Sstevel@tonic-gatevoid
1960Sstevel@tonic-gatext_sync_tl1(uint64_t *cpu_sync_addr)
1970Sstevel@tonic-gate{}
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate#else
2000Sstevel@tonic-gate/*
2010Sstevel@tonic-gate * This dummy tl1 function is there to ensure that previously called
2020Sstevel@tonic-gate * xtrap handlers have exececuted. The hardware (mondo dispatch
2030Sstevel@tonic-gate * mechanism) is such that return from xtrap doesn't guarantee execution
2040Sstevel@tonic-gate * of xtrap handler. So, callers can call this xtrap-handler to ensure
2050Sstevel@tonic-gate * that the previous one is complete. This is because the hardware only
2060Sstevel@tonic-gate * can handle 1 mondo at a time - when this mondo is handled, we are sure
2070Sstevel@tonic-gate * that the mondo for the previous xtrap must have been handled.
2080Sstevel@tonic-gate */
2090Sstevel@tonic-gate	ENTRY_NP(xt_sync_tl1)
2100Sstevel@tonic-gate	retry
2110Sstevel@tonic-gate	SET_SIZE(xt_sync_tl1)
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate#endif  /* lint */
214