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*1991Sheppo * Common Development and Distribution License (the "License").
6*1991Sheppo * 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 */
21*1991Sheppo
220Sstevel@tonic-gate /*
23*1991Sheppo * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate * Handling of unintentional faults (i.e. bugs) in the debugger.
310Sstevel@tonic-gate */
320Sstevel@tonic-gate
330Sstevel@tonic-gate #include <stdlib.h>
340Sstevel@tonic-gate
350Sstevel@tonic-gate #include <kmdb/kmdb_fault.h>
360Sstevel@tonic-gate #include <kmdb/kmdb_promif.h>
370Sstevel@tonic-gate #include <kmdb/kmdb_kdi.h>
380Sstevel@tonic-gate #include <kmdb/kmdb_dpi.h>
390Sstevel@tonic-gate #include <mdb/mdb_debug.h>
400Sstevel@tonic-gate #include <mdb/mdb_kreg.h>
410Sstevel@tonic-gate #include <mdb/mdb_io_impl.h>
420Sstevel@tonic-gate #include <mdb/mdb.h>
430Sstevel@tonic-gate
440Sstevel@tonic-gate void
kmdb_fault(kreg_t tt,kreg_t pc,kreg_t sp,int cpuid)450Sstevel@tonic-gate kmdb_fault(kreg_t tt, kreg_t pc, kreg_t sp, int cpuid)
460Sstevel@tonic-gate {
470Sstevel@tonic-gate int debug_self_confirm = 0, try;
480Sstevel@tonic-gate jmp_buf pcb, *old;
490Sstevel@tonic-gate char c;
500Sstevel@tonic-gate
510Sstevel@tonic-gate /* Make absolutely sure */
520Sstevel@tonic-gate kmdb_kdi_system_claim();
530Sstevel@tonic-gate
540Sstevel@tonic-gate try = 1;
550Sstevel@tonic-gate if (setjmp(pcb) != 0) {
560Sstevel@tonic-gate if (++try == 2) {
570Sstevel@tonic-gate mdb_iob_printf(mdb.m_err,
580Sstevel@tonic-gate "\n*** First stack trace attempt failed. "
590Sstevel@tonic-gate "Trying safe mode.\n\n");
600Sstevel@tonic-gate
610Sstevel@tonic-gate kmdb_fault_display(tt, pc, sp, 1);
620Sstevel@tonic-gate } else {
630Sstevel@tonic-gate mdb_iob_printf(mdb.m_err,
640Sstevel@tonic-gate "\n*** Unable to print stack trace.\n");
650Sstevel@tonic-gate }
660Sstevel@tonic-gate
670Sstevel@tonic-gate } else {
680Sstevel@tonic-gate old = kmdb_dpi_set_fault_hdlr(&pcb);
690Sstevel@tonic-gate
700Sstevel@tonic-gate mdb_iob_printf(mdb.m_err, "\n*** Debugger Fault (CPU %d)\n\n",
710Sstevel@tonic-gate cpuid);
720Sstevel@tonic-gate kmdb_fault_display(tt, pc, sp, 0);
730Sstevel@tonic-gate }
740Sstevel@tonic-gate
750Sstevel@tonic-gate kmdb_dpi_restore_fault_hdlr(old);
760Sstevel@tonic-gate
770Sstevel@tonic-gate if (mdb.m_term != NULL) {
780Sstevel@tonic-gate for (;;) {
790Sstevel@tonic-gate mdb_iob_printf(mdb.m_err, "\n%s: "
800Sstevel@tonic-gate #if defined(__sparc)
81*1991Sheppo #ifndef sun4v
82*1991Sheppo "(o)bp, "
83*1991Sheppo #endif /* sun4v */
84*1991Sheppo "(p)anic"
850Sstevel@tonic-gate #else
860Sstevel@tonic-gate "reboo(t)"
870Sstevel@tonic-gate #endif
880Sstevel@tonic-gate ", or (d)ebug with self? ", mdb.m_pname);
890Sstevel@tonic-gate mdb_iob_flush(mdb.m_err);
900Sstevel@tonic-gate
910Sstevel@tonic-gate if (IOP_READ(mdb.m_term, &c, sizeof (c)) != sizeof (c))
920Sstevel@tonic-gate goto fault_obp;
930Sstevel@tonic-gate
940Sstevel@tonic-gate mdb_iob_printf(mdb.m_err, "\n");
950Sstevel@tonic-gate
960Sstevel@tonic-gate switch (c) {
970Sstevel@tonic-gate #ifdef __sparc
980Sstevel@tonic-gate case 'p':
990Sstevel@tonic-gate kmdb_dpi_kernpanic(cpuid);
1000Sstevel@tonic-gate /*NOTREACHED*/
1010Sstevel@tonic-gate continue;
1020Sstevel@tonic-gate #endif
1030Sstevel@tonic-gate
104*1991Sheppo #ifndef sun4v
1050Sstevel@tonic-gate case 'o':
1060Sstevel@tonic-gate case 'O':
107*1991Sheppo #endif /* sun4v */
1080Sstevel@tonic-gate case 't':
1090Sstevel@tonic-gate case 'T':
1100Sstevel@tonic-gate kmdb_dpi_enter_mon();
1110Sstevel@tonic-gate continue;
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate case 'd':
1140Sstevel@tonic-gate case 'D':
1150Sstevel@tonic-gate /*
1160Sstevel@tonic-gate * Debug self - get confirmation, because they
1170Sstevel@tonic-gate * can't go back to their running system if
1180Sstevel@tonic-gate * they choose this one.
1190Sstevel@tonic-gate */
1200Sstevel@tonic-gate if (debug_self_confirm == 0) {
1210Sstevel@tonic-gate mdb_iob_printf(mdb.m_err,
1220Sstevel@tonic-gate "NOTE: You will not be able to "
1230Sstevel@tonic-gate "resume your system if you "
1240Sstevel@tonic-gate "choose this option.\nPlease "
1250Sstevel@tonic-gate "select 'd' again to confirm.\n");
1260Sstevel@tonic-gate debug_self_confirm = 1;
1270Sstevel@tonic-gate continue;
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate kmdb_dpi_set_state(DPI_STATE_LOST, 0);
1310Sstevel@tonic-gate return;
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate }
1340Sstevel@tonic-gate }
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate fault_obp:
1370Sstevel@tonic-gate exit(1);
1380Sstevel@tonic-gate /*NOTREACHED*/
1390Sstevel@tonic-gate }
140