1*7c478bd9Sstevel@tonic-gate/*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate/*
23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate/*
30*7c478bd9Sstevel@tonic-gate * System-resumption code.  kaif_resume is called whenever the world, as a whole
31*7c478bd9Sstevel@tonic-gate * or merely a single CPU, is to be resumed.
32*7c478bd9Sstevel@tonic-gate */
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gate#if !defined(__lint)
35*7c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
36*7c478bd9Sstevel@tonic-gate#include <sys/trap.h>
37*7c478bd9Sstevel@tonic-gate#include <sys/machtrap.h>
38*7c478bd9Sstevel@tonic-gate#include <sys/mmu.h>
39*7c478bd9Sstevel@tonic-gate#include <sys/machasi.h>
40*7c478bd9Sstevel@tonic-gate#define _KERNEL
41*7c478bd9Sstevel@tonic-gate#include <sys/privregs.h>
42*7c478bd9Sstevel@tonic-gate#undef _KERNEL
43*7c478bd9Sstevel@tonic-gate#include <sys/machthread.h>
44*7c478bd9Sstevel@tonic-gate#include <sys/machparam.h>
45*7c478bd9Sstevel@tonic-gate#endif
46*7c478bd9Sstevel@tonic-gate
47*7c478bd9Sstevel@tonic-gate#if defined(__lint)
48*7c478bd9Sstevel@tonic-gate#include <sys/ddi.h>
49*7c478bd9Sstevel@tonic-gate#include <sys/sunddi.h>
50*7c478bd9Sstevel@tonic-gate#endif
51*7c478bd9Sstevel@tonic-gate
52*7c478bd9Sstevel@tonic-gate#include <mdb/mdb_kreg.h>
53*7c478bd9Sstevel@tonic-gate#include <kmdb/kaif_asmutil.h>
54*7c478bd9Sstevel@tonic-gate#include <kmdb/kaif_off.h>
55*7c478bd9Sstevel@tonic-gate#include <kmdb/kaif.h>
56*7c478bd9Sstevel@tonic-gate
57*7c478bd9Sstevel@tonic-gate#if defined(__lint)
58*7c478bd9Sstevel@tonic-gate/*ARGSUSED*/
59*7c478bd9Sstevel@tonic-gatevoid
60*7c478bd9Sstevel@tonic-gatekaif_resume(int work_required)
61*7c478bd9Sstevel@tonic-gate{
62*7c478bd9Sstevel@tonic-gate}
63*7c478bd9Sstevel@tonic-gate#else /* __lint */
64*7c478bd9Sstevel@tonic-gate
65*7c478bd9Sstevel@tonic-gate	/*
66*7c478bd9Sstevel@tonic-gate	 * Used to start the world back up, as a whole or in part (single-step).
67*7c478bd9Sstevel@tonic-gate	 * Arguments:
68*7c478bd9Sstevel@tonic-gate	 *    %l5 - the CPU-specific gregs save area
69*7c478bd9Sstevel@tonic-gate	 *    %l6 - the CPU-specific save area
70*7c478bd9Sstevel@tonic-gate	 */
71*7c478bd9Sstevel@tonic-gate	ENTRY_NP(kaif_resume)
72*7c478bd9Sstevel@tonic-gate
73*7c478bd9Sstevel@tonic-gate	/* globals only from here on out */
74*7c478bd9Sstevel@tonic-gate	mov	%l5, %g5
75*7c478bd9Sstevel@tonic-gate	mov	%l6, %g6
76*7c478bd9Sstevel@tonic-gate
77*7c478bd9Sstevel@tonic-gate	/*
78*7c478bd9Sstevel@tonic-gate	 * To resume the world, we reverse what we did in startup
79*7c478bd9Sstevel@tonic-gate	 */
80*7c478bd9Sstevel@tonic-gate
81*7c478bd9Sstevel@tonic-gate	/* FP state */
82*7c478bd9Sstevel@tonic-gate	add	%g6, KRS_FPREGS, %g4	! %g4 = &cpusave[this_cpuid].krs_fpregs
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate	ldx	[%g4 + FPU_FPRS], %g2
85*7c478bd9Sstevel@tonic-gate	btst	FPRS_FEF, %g2		! was fp enabled?
86*7c478bd9Sstevel@tonic-gate	bz,pt	%icc, 1f		! nope drive on...
87*7c478bd9Sstevel@tonic-gate	wr	%g2, %fprs		! restore %fprs regardless
88*7c478bd9Sstevel@tonic-gate
89*7c478bd9Sstevel@tonic-gate	LOAD_FPREGS(%g4)
90*7c478bd9Sstevel@tonic-gate	ldx	[%g4 + FPU_FSR], %fsr
91*7c478bd9Sstevel@tonic-gate
92*7c478bd9Sstevel@tonic-gate1:
93*7c478bd9Sstevel@tonic-gate	/* Register windows */
94*7c478bd9Sstevel@tonic-gate	GET_NWIN(%g1, %g4);		! %g1 is scratch, %g4 set to nwin-1
95*7c478bd9Sstevel@tonic-gate	wrpr	%g4, %cleanwin
96*7c478bd9Sstevel@tonic-gate
97*7c478bd9Sstevel@tonic-gate	sub	%g4, 1, %g1
98*7c478bd9Sstevel@tonic-gate	wrpr	%g1, %cansave
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate	wrpr	%g0, %otherwin
101*7c478bd9Sstevel@tonic-gate	wrpr	%g0, %canrestore
102*7c478bd9Sstevel@tonic-gate	wrpr	%g0, %cwp
103*7c478bd9Sstevel@tonic-gate	clr	%g2
104*7c478bd9Sstevel@tonic-gate
105*7c478bd9Sstevel@tonic-gate	ldx	[%g6 + KRS_RWINS], %g3	! %g3 = &cpusave[this_cpuid].krs_wins
106*7c478bd9Sstevel@tonic-gate
107*7c478bd9Sstevel@tonic-gate1:
108*7c478bd9Sstevel@tonic-gate	RESTORE_V9WINDOW(%g3)
109*7c478bd9Sstevel@tonic-gate	add	%g2, 1, %g2
110*7c478bd9Sstevel@tonic-gate	add	%g3, RWIN_SIZE, %g3
111*7c478bd9Sstevel@tonic-gate	cmp	%g2, %g4
112*7c478bd9Sstevel@tonic-gate	ble	1b
113*7c478bd9Sstevel@tonic-gate	wrpr	%g2, %cwp
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate	/* Restore various privileged registers */
116*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_CWP)], %g4
117*7c478bd9Sstevel@tonic-gate	wrpr	%g4, %cwp
118*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_OTHERWIN)], %g4
119*7c478bd9Sstevel@tonic-gate	wrpr	%g4, %otherwin
120*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_CLEANWIN)], %g4
121*7c478bd9Sstevel@tonic-gate	wrpr	%g4, %cleanwin
122*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_CANSAVE)], %g4
123*7c478bd9Sstevel@tonic-gate	wrpr	%g4, %cansave
124*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_CANRESTORE)], %g4
125*7c478bd9Sstevel@tonic-gate	wrpr	%g4, %canrestore
126*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_WSTATE)], %g4
127*7c478bd9Sstevel@tonic-gate	wrpr	%g4, %wstate
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_Y)], %g4
130*7c478bd9Sstevel@tonic-gate	wr	%g4, %y
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_PIL)], %g4
133*7c478bd9Sstevel@tonic-gate	wrpr	%g4, %pil
134*7c478bd9Sstevel@tonic-gate
135*7c478bd9Sstevel@tonic-gate	/* Set up the return from the trap */
136*7c478bd9Sstevel@tonic-gate	wrpr	%g0, 1, %tl
137*7c478bd9Sstevel@tonic-gate
138*7c478bd9Sstevel@tonic-gate	/*
139*7c478bd9Sstevel@tonic-gate	 * Restore the MMU primary context.
140*7c478bd9Sstevel@tonic-gate	 */
141*7c478bd9Sstevel@tonic-gate	mov	MMU_PCONTEXT, %g3
142*7c478bd9Sstevel@tonic-gate	ldx	[%g6 + KRS_MMU_PCONTEXT], %g4
143*7c478bd9Sstevel@tonic-gate	KAIF_DEMAP_TLB_ALL(%g2)
144*7c478bd9Sstevel@tonic-gate	stxa	%g4, [%g3]ASI_MMU_CTX
145*7c478bd9Sstevel@tonic-gate	membar	#Sync
146*7c478bd9Sstevel@tonic-gate
147*7c478bd9Sstevel@tonic-gate	ldx	[%g6 + KRS_TSTATE], %g4
148*7c478bd9Sstevel@tonic-gate	wrpr	%g4, %tstate
149*7c478bd9Sstevel@tonic-gate
150*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_PC)], %g4
151*7c478bd9Sstevel@tonic-gate	wrpr	%g4, %tpc
152*7c478bd9Sstevel@tonic-gate
153*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_NPC)], %g4
154*7c478bd9Sstevel@tonic-gate	wrpr	%g4, %tnpc
155*7c478bd9Sstevel@tonic-gate
156*7c478bd9Sstevel@tonic-gate	/*
157*7c478bd9Sstevel@tonic-gate	 * If we're here because of the debugger trap (most likely from
158*7c478bd9Sstevel@tonic-gate	 * kaif_entry), we don't want to jump back to %tpc, since it
159*7c478bd9Sstevel@tonic-gate	 * is likely to be the ta that brought us here in the first place.
160*7c478bd9Sstevel@tonic-gate	 * We'll test for it here, and we'll leave %xcc untouched until
161*7c478bd9Sstevel@tonic-gate	 * the end when we're about to return.
162*7c478bd9Sstevel@tonic-gate	 */
163*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_TT)], %g4
164*7c478bd9Sstevel@tonic-gate	wrpr	%g4, %tt
165*7c478bd9Sstevel@tonic-gate	cmp	%g4, ST_KMDB_TRAP|T_SOFTWARE_TRAP
166*7c478bd9Sstevel@tonic-gate
167*7c478bd9Sstevel@tonic-gate	/* Restore saved globals */
168*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_G1)], %g1
169*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_G2)], %g2
170*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_G3)], %g3
171*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_G4)], %g4
172*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_G6)], %g6
173*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_G7)], %g7
174*7c478bd9Sstevel@tonic-gate	be	%xcc, 1f			! the trap type check, above
175*7c478bd9Sstevel@tonic-gate	ldx	[%g5 + KREG_OFF(KREG_G5)], %g5
176*7c478bd9Sstevel@tonic-gate
177*7c478bd9Sstevel@tonic-gate	retry
178*7c478bd9Sstevel@tonic-gate1:
179*7c478bd9Sstevel@tonic-gate	done
180*7c478bd9Sstevel@tonic-gate
181*7c478bd9Sstevel@tonic-gate	SET_SIZE(kaif_resume)
182*7c478bd9Sstevel@tonic-gate
183*7c478bd9Sstevel@tonic-gate#endif	/* __lint */
184