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