xref: /onnv-gate/usr/src/uts/common/os/panic.c (revision 12967:ab9ae749152f)
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
55084Sjohnlev  * Common Development and Distribution License (the "License").
65084Sjohnlev  * 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 /*
2212269Srafael.vanoni@oracle.com  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate  * When the operating system detects that it is in an invalid state, a panic
270Sstevel@tonic-gate  * is initiated in order to minimize potential damage to user data and to
280Sstevel@tonic-gate  * facilitate debugging.  There are three major tasks to be performed in
290Sstevel@tonic-gate  * a system panic: recording information about the panic in memory (and thus
300Sstevel@tonic-gate  * making it part of the crash dump), synchronizing the file systems to
310Sstevel@tonic-gate  * preserve user file data, and generating the crash dump.  We define the
320Sstevel@tonic-gate  * system to be in one of four states with respect to the panic code:
330Sstevel@tonic-gate  *
340Sstevel@tonic-gate  * CALM    - the state of the system prior to any thread initiating a panic
350Sstevel@tonic-gate  *
360Sstevel@tonic-gate  * QUIESCE - the state of the system when the first thread to initiate
370Sstevel@tonic-gate  *           a system panic records information about the cause of the panic
380Sstevel@tonic-gate  *           and renders the system quiescent by stopping other processors
390Sstevel@tonic-gate  *
400Sstevel@tonic-gate  * SYNC    - the state of the system when we synchronize the file systems
410Sstevel@tonic-gate  * DUMP    - the state when we generate the crash dump.
420Sstevel@tonic-gate  *
430Sstevel@tonic-gate  * The transitions between these states are irreversible: once we begin
440Sstevel@tonic-gate  * panicking, we only make one attempt to perform the actions associated with
450Sstevel@tonic-gate  * each state.
460Sstevel@tonic-gate  *
470Sstevel@tonic-gate  * The panic code itself must be re-entrant because actions taken during any
480Sstevel@tonic-gate  * state may lead to another system panic.  Additionally, any Solaris
490Sstevel@tonic-gate  * thread may initiate a panic at any time, and so we must have synchronization
500Sstevel@tonic-gate  * between threads which attempt to initiate a state transition simultaneously.
510Sstevel@tonic-gate  * The panic code makes use of a special locking primitive, a trigger, to
520Sstevel@tonic-gate  * perform this synchronization.  A trigger is simply a word which is set
530Sstevel@tonic-gate  * atomically and can only be set once.  We declare three triggers, one for
540Sstevel@tonic-gate  * each transition between the four states.  When a thread enters the panic
550Sstevel@tonic-gate  * code it attempts to set each trigger; if it fails it moves on to the
560Sstevel@tonic-gate  * next trigger.  A special case is the first trigger: if two threads race
570Sstevel@tonic-gate  * to perform the transition to QUIESCE, the losing thread may execute before
580Sstevel@tonic-gate  * the winner has a chance to stop its CPU.  To solve this problem, we have
590Sstevel@tonic-gate  * the loser look ahead to see if any other triggers are set; if not, it
600Sstevel@tonic-gate  * presumes a panic is underway and simply spins.  Unfortunately, since we
610Sstevel@tonic-gate  * are panicking, it is not possible to know this with absolute certainty.
620Sstevel@tonic-gate  *
630Sstevel@tonic-gate  * There are two common reasons for re-entering the panic code once a panic
640Sstevel@tonic-gate  * has been initiated: (1) after we debug_enter() at the end of QUIESCE,
650Sstevel@tonic-gate  * the operator may type "sync" instead of "go", and the PROM's sync callback
660Sstevel@tonic-gate  * routine will invoke panic(); (2) if the clock routine decides that sync
670Sstevel@tonic-gate  * or dump is not making progress, it will invoke panic() to force a timeout.
680Sstevel@tonic-gate  * The design assumes that a third possibility, another thread causing an
690Sstevel@tonic-gate  * unrelated panic while sync or dump is still underway, is extremely unlikely.
700Sstevel@tonic-gate  * If this situation occurs, we may end up triggering dump while sync is
710Sstevel@tonic-gate  * still in progress.  This third case is considered extremely unlikely because
720Sstevel@tonic-gate  * all other CPUs are stopped and low-level interrupts have been blocked.
730Sstevel@tonic-gate  *
740Sstevel@tonic-gate  * The panic code is entered via a call directly to the vpanic() function,
750Sstevel@tonic-gate  * or its varargs wrappers panic() and cmn_err(9F).  The vpanic routine
760Sstevel@tonic-gate  * is implemented in assembly language to record the current machine
770Sstevel@tonic-gate  * registers, attempt to set the trigger for the QUIESCE state, and
780Sstevel@tonic-gate  * if successful, switch stacks on to the panic_stack before calling into
790Sstevel@tonic-gate  * the common panicsys() routine.  The first thread to initiate a panic
800Sstevel@tonic-gate  * is allowed to make use of the reserved panic_stack so that executing
810Sstevel@tonic-gate  * the panic code itself does not overwrite valuable data on that thread's
820Sstevel@tonic-gate  * stack *ahead* of the current stack pointer.  This data will be preserved
830Sstevel@tonic-gate  * in the crash dump and may prove invaluable in determining what this
840Sstevel@tonic-gate  * thread has previously been doing.  The first thread, saved in panic_thread,
850Sstevel@tonic-gate  * is also responsible for stopping the other CPUs as quickly as possible,
860Sstevel@tonic-gate  * and then setting the various panic_* variables.  Most important among
870Sstevel@tonic-gate  * these is panicstr, which allows threads to subsequently bypass held
880Sstevel@tonic-gate  * locks so that we can proceed without ever blocking.  We must stop the
890Sstevel@tonic-gate  * other CPUs *prior* to setting panicstr in case threads running there are
900Sstevel@tonic-gate  * currently spinning to acquire a lock; we want that state to be preserved.
910Sstevel@tonic-gate  * Every thread which initiates a panic has its T_PANIC flag set so we can
920Sstevel@tonic-gate  * identify all such threads in the crash dump.
930Sstevel@tonic-gate  *
940Sstevel@tonic-gate  * The panic_thread is also allowed to make use of the special memory buffer
950Sstevel@tonic-gate  * panicbuf, which on machines with appropriate hardware is preserved across
960Sstevel@tonic-gate  * reboots.  We allow the panic_thread to store its register set and panic
970Sstevel@tonic-gate  * message in this buffer, so even if we fail to obtain a crash dump we will
980Sstevel@tonic-gate  * be able to examine the machine after reboot and determine some of the
990Sstevel@tonic-gate  * state at the time of the panic.  If we do get a dump, the panic buffer
1000Sstevel@tonic-gate  * data is structured so that a debugger can easily consume the information
1010Sstevel@tonic-gate  * therein (see <sys/panic.h>).
1020Sstevel@tonic-gate  *
1030Sstevel@tonic-gate  * Each platform or architecture is required to implement the functions
1040Sstevel@tonic-gate  * panic_savetrap() to record trap-specific information to panicbuf,
1050Sstevel@tonic-gate  * panic_saveregs() to record a register set to panicbuf, panic_stopcpus()
1060Sstevel@tonic-gate  * to halt all CPUs but the panicking CPU, panic_quiesce_hw() to perform
1070Sstevel@tonic-gate  * miscellaneous platform-specific tasks *after* panicstr is set,
1080Sstevel@tonic-gate  * panic_showtrap() to print trap-specific information to the console,
1090Sstevel@tonic-gate  * and panic_dump_hw() to perform platform tasks prior to calling dumpsys().
1100Sstevel@tonic-gate  *
1110Sstevel@tonic-gate  * A Note on Word Formation, courtesy of the Oxford Guide to English Usage:
1120Sstevel@tonic-gate  *
1130Sstevel@tonic-gate  * Words ending in -c interpose k before suffixes which otherwise would
1140Sstevel@tonic-gate  * indicate a soft c, and thus the verb and adjective forms of 'panic' are
1150Sstevel@tonic-gate  * spelled "panicked", "panicking", and "panicky" respectively.  Use of
1160Sstevel@tonic-gate  * the ill-conceived "panicing" and "panic'd" is discouraged.
1170Sstevel@tonic-gate  */
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate #include <sys/types.h>
1200Sstevel@tonic-gate #include <sys/varargs.h>
1210Sstevel@tonic-gate #include <sys/sysmacros.h>
1220Sstevel@tonic-gate #include <sys/cmn_err.h>
1230Sstevel@tonic-gate #include <sys/cpuvar.h>
1240Sstevel@tonic-gate #include <sys/thread.h>
1250Sstevel@tonic-gate #include <sys/t_lock.h>
1260Sstevel@tonic-gate #include <sys/cred.h>
1270Sstevel@tonic-gate #include <sys/systm.h>
1285084Sjohnlev #include <sys/archsystm.h>
1290Sstevel@tonic-gate #include <sys/uadmin.h>
1300Sstevel@tonic-gate #include <sys/callb.h>
1310Sstevel@tonic-gate #include <sys/vfs.h>
1320Sstevel@tonic-gate #include <sys/log.h>
1330Sstevel@tonic-gate #include <sys/disp.h>
1340Sstevel@tonic-gate #include <sys/param.h>
1350Sstevel@tonic-gate #include <sys/dumphdr.h>
1360Sstevel@tonic-gate #include <sys/ftrace.h>
1370Sstevel@tonic-gate #include <sys/reboot.h>
1380Sstevel@tonic-gate #include <sys/debug.h>
1390Sstevel@tonic-gate #include <sys/stack.h>
1400Sstevel@tonic-gate #include <sys/spl.h>
1410Sstevel@tonic-gate #include <sys/errorq.h>
1420Sstevel@tonic-gate #include <sys/panic.h>
1431414Scindi #include <sys/fm/util.h>
14411066Srafael.vanoni@sun.com #include <sys/clock_impl.h>
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate /*
1470Sstevel@tonic-gate  * Panic variables which are set once during the QUIESCE state by the
1480Sstevel@tonic-gate  * first thread to initiate a panic.  These are examined by post-mortem
1490Sstevel@tonic-gate  * debugging tools; the inconsistent use of 'panic' versus 'panic_' in
1500Sstevel@tonic-gate  * the variable naming is historical and allows legacy tools to work.
1510Sstevel@tonic-gate  */
1520Sstevel@tonic-gate #pragma align STACK_ALIGN(panic_stack)
1530Sstevel@tonic-gate char panic_stack[PANICSTKSIZE];		/* reserved stack for panic_thread */
1540Sstevel@tonic-gate kthread_t *panic_thread;		/* first thread to call panicsys() */
1550Sstevel@tonic-gate cpu_t panic_cpu;			/* cpu from first call to panicsys() */
1560Sstevel@tonic-gate label_t panic_regs;			/* setjmp label from panic_thread */
1570Sstevel@tonic-gate struct regs *panic_reg;			/* regs struct from first panicsys() */
1580Sstevel@tonic-gate char *volatile panicstr;		/* format string to first panicsys() */
1590Sstevel@tonic-gate va_list panicargs;			/* arguments to first panicsys() */
1600Sstevel@tonic-gate clock_t panic_lbolt;			/* lbolt at time of panic */
1610Sstevel@tonic-gate int64_t panic_lbolt64;			/* lbolt64 at time of panic */
1620Sstevel@tonic-gate hrtime_t panic_hrtime;			/* hrtime at time of panic */
1630Sstevel@tonic-gate timespec_t panic_hrestime;		/* hrestime at time of panic */
1640Sstevel@tonic-gate int panic_ipl;				/* ipl on panic_cpu at time of panic */
1650Sstevel@tonic-gate ushort_t panic_schedflag;		/* t_schedflag for panic_thread */
1660Sstevel@tonic-gate cpu_t *panic_bound_cpu;			/* t_bound_cpu for panic_thread */
1670Sstevel@tonic-gate char panic_preempt;			/* t_preempt for panic_thread */
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate /*
1700Sstevel@tonic-gate  * Panic variables which can be set via /etc/system or patched while
1710Sstevel@tonic-gate  * the system is in operation.  Again, the stupid names are historic.
1720Sstevel@tonic-gate  */
1730Sstevel@tonic-gate char *panic_bootstr = NULL;		/* mdboot string to use after panic */
1740Sstevel@tonic-gate int panic_bootfcn = AD_BOOT;		/* mdboot function to use after panic */
1750Sstevel@tonic-gate int halt_on_panic = 0;  		/* halt after dump instead of reboot? */
1760Sstevel@tonic-gate int nopanicdebug = 0;			/* reboot instead of call debugger? */
1770Sstevel@tonic-gate int in_sync = 0;			/* skip vfs_syncall() and just dump? */
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate /*
1800Sstevel@tonic-gate  * The do_polled_io flag is set by the panic code to inform the SCSI subsystem
1810Sstevel@tonic-gate  * to use polled mode instead of interrupt-driven i/o.
1820Sstevel@tonic-gate  */
1830Sstevel@tonic-gate int do_polled_io = 0;
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate /*
1860Sstevel@tonic-gate  * The panic_forced flag is set by the uadmin A_DUMP code to inform the
1870Sstevel@tonic-gate  * panic subsystem that it should not attempt an initial debug_enter.
1880Sstevel@tonic-gate  */
1890Sstevel@tonic-gate int panic_forced = 0;
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate /*
1920Sstevel@tonic-gate  * Triggers for panic state transitions:
1930Sstevel@tonic-gate  */
1940Sstevel@tonic-gate int panic_quiesce;			/* trigger for CALM    -> QUIESCE */
1950Sstevel@tonic-gate int panic_sync;				/* trigger for QUIESCE -> SYNC */
1960Sstevel@tonic-gate int panic_dump;				/* trigger for SYNC    -> DUMP */
1970Sstevel@tonic-gate 
1989160SSherry.Moore@Sun.COM /*
1999160SSherry.Moore@Sun.COM  * Variable signifying quiesce(9E) is in progress.
2009160SSherry.Moore@Sun.COM  */
2019160SSherry.Moore@Sun.COM volatile int quiesce_active = 0;
2029160SSherry.Moore@Sun.COM 
2030Sstevel@tonic-gate void
panicsys(const char * format,va_list alist,struct regs * rp,int on_panic_stack)2040Sstevel@tonic-gate panicsys(const char *format, va_list alist, struct regs *rp, int on_panic_stack)
2050Sstevel@tonic-gate {
2060Sstevel@tonic-gate 	int s = spl8();
2070Sstevel@tonic-gate 	kthread_t *t = curthread;
2080Sstevel@tonic-gate 	cpu_t *cp = CPU;
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate 	caddr_t intr_stack = NULL;
2110Sstevel@tonic-gate 	uint_t intr_actv;
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 	ushort_t schedflag = t->t_schedflag;
2140Sstevel@tonic-gate 	cpu_t *bound_cpu = t->t_bound_cpu;
2150Sstevel@tonic-gate 	char preempt = t->t_preempt;
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 	(void) setjmp(&t->t_pcb);
2180Sstevel@tonic-gate 	t->t_flag |= T_PANIC;
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 	t->t_schedflag |= TS_DONT_SWAP;
2210Sstevel@tonic-gate 	t->t_bound_cpu = cp;
2220Sstevel@tonic-gate 	t->t_preempt++;
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 	panic_enter_hw(s);
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 	/*
2270Sstevel@tonic-gate 	 * If we're on the interrupt stack and an interrupt thread is available
2280Sstevel@tonic-gate 	 * in this CPU's pool, preserve the interrupt stack by detaching an
2290Sstevel@tonic-gate 	 * interrupt thread and making its stack the intr_stack.
2300Sstevel@tonic-gate 	 */
2310Sstevel@tonic-gate 	if (CPU_ON_INTR(cp) && cp->cpu_intr_thread != NULL) {
2320Sstevel@tonic-gate 		kthread_t *it = cp->cpu_intr_thread;
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate 		intr_stack = cp->cpu_intr_stack;
2350Sstevel@tonic-gate 		intr_actv = cp->cpu_intr_actv;
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate 		cp->cpu_intr_stack = thread_stk_init(it->t_stk);
2380Sstevel@tonic-gate 		cp->cpu_intr_thread = it->t_link;
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 		/*
2410Sstevel@tonic-gate 		 * Clear only the high level bits of cpu_intr_actv.
2420Sstevel@tonic-gate 		 * We want to indicate that high-level interrupts are
2430Sstevel@tonic-gate 		 * not active without destroying the low-level interrupt
2440Sstevel@tonic-gate 		 * information stored there.
2450Sstevel@tonic-gate 		 */
2460Sstevel@tonic-gate 		cp->cpu_intr_actv &= ((1 << (LOCK_LEVEL + 1)) - 1);
2470Sstevel@tonic-gate 	}
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate 	/*
2500Sstevel@tonic-gate 	 * Record one-time panic information and quiesce the other CPUs.
2510Sstevel@tonic-gate 	 * Then print out the panic message and stack trace.
2520Sstevel@tonic-gate 	 */
2530Sstevel@tonic-gate 	if (on_panic_stack) {
2540Sstevel@tonic-gate 		panic_data_t *pdp = (panic_data_t *)panicbuf;
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate 		pdp->pd_version = PANICBUFVERS;
2570Sstevel@tonic-gate 		pdp->pd_msgoff = sizeof (panic_data_t) - sizeof (panic_nv_t);
2580Sstevel@tonic-gate 
259*12967Sgavin.maltby@oracle.com 		(void) strncpy(pdp->pd_uuid, dump_get_uuid(),
260*12967Sgavin.maltby@oracle.com 		    sizeof (pdp->pd_uuid));
261*12967Sgavin.maltby@oracle.com 
2620Sstevel@tonic-gate 		if (t->t_panic_trap != NULL)
2630Sstevel@tonic-gate 			panic_savetrap(pdp, t->t_panic_trap);
2640Sstevel@tonic-gate 		else
2650Sstevel@tonic-gate 			panic_saveregs(pdp, rp);
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 		(void) vsnprintf(&panicbuf[pdp->pd_msgoff],
2680Sstevel@tonic-gate 		    PANICBUFSIZE - pdp->pd_msgoff, format, alist);
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 		/*
2710Sstevel@tonic-gate 		 * Call into the platform code to stop the other CPUs.
2720Sstevel@tonic-gate 		 * We currently have all interrupts blocked, and expect that
2730Sstevel@tonic-gate 		 * the platform code will lower ipl only as far as needed to
2740Sstevel@tonic-gate 		 * perform cross-calls, and will acquire as *few* locks as is
2750Sstevel@tonic-gate 		 * possible -- panicstr is not set so we can still deadlock.
2760Sstevel@tonic-gate 		 */
2770Sstevel@tonic-gate 		panic_stopcpus(cp, t, s);
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate 		panicstr = (char *)format;
2800Sstevel@tonic-gate 		va_copy(panicargs, alist);
28111099Srafael.vanoni@sun.com 		panic_lbolt = LBOLT_NO_ACCOUNT;
28211099Srafael.vanoni@sun.com 		panic_lbolt64 = LBOLT_NO_ACCOUNT64;
2830Sstevel@tonic-gate 		panic_hrestime = hrestime;
2840Sstevel@tonic-gate 		panic_hrtime = gethrtime_waitfree();
2850Sstevel@tonic-gate 		panic_thread = t;
2860Sstevel@tonic-gate 		panic_regs = t->t_pcb;
2870Sstevel@tonic-gate 		panic_reg = rp;
2880Sstevel@tonic-gate 		panic_cpu = *cp;
2890Sstevel@tonic-gate 		panic_ipl = spltoipl(s);
2900Sstevel@tonic-gate 		panic_schedflag = schedflag;
2910Sstevel@tonic-gate 		panic_bound_cpu = bound_cpu;
2920Sstevel@tonic-gate 		panic_preempt = preempt;
2930Sstevel@tonic-gate 
2940Sstevel@tonic-gate 		if (intr_stack != NULL) {
2950Sstevel@tonic-gate 			panic_cpu.cpu_intr_stack = intr_stack;
2960Sstevel@tonic-gate 			panic_cpu.cpu_intr_actv = intr_actv;
2970Sstevel@tonic-gate 		}
2980Sstevel@tonic-gate 
2990Sstevel@tonic-gate 		/*
3000Sstevel@tonic-gate 		 * Lower ipl to 10 to keep clock() from running, but allow
3010Sstevel@tonic-gate 		 * keyboard interrupts to enter the debugger.  These callbacks
3020Sstevel@tonic-gate 		 * are executed with panicstr set so they can bypass locks.
3030Sstevel@tonic-gate 		 */
3040Sstevel@tonic-gate 		splx(ipltospl(CLOCK_LEVEL));
3050Sstevel@tonic-gate 		panic_quiesce_hw(pdp);
3060Sstevel@tonic-gate 		(void) FTRACE_STOP();
3070Sstevel@tonic-gate 		(void) callb_execute_class(CB_CL_PANIC, NULL);
3080Sstevel@tonic-gate 
3095630Sjbeck 		if (log_intrq != NULL)
3105630Sjbeck 			log_flushq(log_intrq);
3115630Sjbeck 
3125630Sjbeck 		/*
3135630Sjbeck 		 * If log_consq has been initialized and syslogd has started,
3145630Sjbeck 		 * print any messages in log_consq that haven't been consumed.
3155630Sjbeck 		 */
3165630Sjbeck 		if (log_consq != NULL && log_consq != log_backlogq)
3175630Sjbeck 			log_printq(log_consq);
3185630Sjbeck 
3190Sstevel@tonic-gate 		fm_banner();
3200Sstevel@tonic-gate 
3215084Sjohnlev #if defined(__x86)
3225084Sjohnlev 		/*
3235084Sjohnlev 		 * A hypervisor panic originates outside of Solaris, so we
3245084Sjohnlev 		 * don't want to prepend the panic message with misleading
3255084Sjohnlev 		 * pointers from within Solaris.
3265084Sjohnlev 		 */
3275084Sjohnlev 		if (!IN_XPV_PANIC())
3285084Sjohnlev #endif
3295084Sjohnlev 			printf("\n\rpanic[cpu%d]/thread=%p: ", cp->cpu_id,
3305084Sjohnlev 			    (void *)t);
3310Sstevel@tonic-gate 		vprintf(format, alist);
3320Sstevel@tonic-gate 		printf("\n\n");
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate 		if (t->t_panic_trap != NULL) {
3350Sstevel@tonic-gate 			panic_showtrap(t->t_panic_trap);
3360Sstevel@tonic-gate 			printf("\n");
3370Sstevel@tonic-gate 		}
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate 		traceregs(rp);
3400Sstevel@tonic-gate 		printf("\n");
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate 		if (((boothowto & RB_DEBUG) || obpdebug) &&
3430Sstevel@tonic-gate 		    !nopanicdebug && !panic_forced) {
3440Sstevel@tonic-gate 			if (dumpvp != NULL) {
3450Sstevel@tonic-gate 				debug_enter("panic: entering debugger "
3460Sstevel@tonic-gate 				    "(continue to save dump)");
3470Sstevel@tonic-gate 			} else {
3480Sstevel@tonic-gate 				debug_enter("panic: entering debugger "
3490Sstevel@tonic-gate 				    "(no dump device, continue to reboot)");
3500Sstevel@tonic-gate 			}
3510Sstevel@tonic-gate 		}
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate 	} else if (panic_dump != 0 || panic_sync != 0 || panicstr != NULL) {
3540Sstevel@tonic-gate 		printf("\n\rpanic[cpu%d]/thread=%p: ", cp->cpu_id, (void *)t);
3550Sstevel@tonic-gate 		vprintf(format, alist);
3560Sstevel@tonic-gate 		printf("\n");
3570Sstevel@tonic-gate 	} else
3580Sstevel@tonic-gate 		goto spin;
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 	/*
3610Sstevel@tonic-gate 	 * Prior to performing sync or dump, we make sure that do_polled_io is
3620Sstevel@tonic-gate 	 * set, but we'll leave ipl at 10; deadman(), a CY_HIGH_LEVEL cyclic,
3630Sstevel@tonic-gate 	 * will re-enter panic if we are not making progress with sync or dump.
3640Sstevel@tonic-gate 	 */
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate 	/*
3670Sstevel@tonic-gate 	 * Sync the filesystems.  Reset t_cred if not set because much of
3680Sstevel@tonic-gate 	 * the filesystem code depends on CRED() being valid.
3690Sstevel@tonic-gate 	 */
3700Sstevel@tonic-gate 	if (!in_sync && panic_trigger(&panic_sync)) {
3710Sstevel@tonic-gate 		if (t->t_cred == NULL)
3720Sstevel@tonic-gate 			t->t_cred = kcred;
3730Sstevel@tonic-gate 		splx(ipltospl(CLOCK_LEVEL));
3740Sstevel@tonic-gate 		do_polled_io = 1;
3750Sstevel@tonic-gate 		vfs_syncall();
3760Sstevel@tonic-gate 	}
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate 	/*
3790Sstevel@tonic-gate 	 * Take the crash dump.  If the dump trigger is already set, try to
3800Sstevel@tonic-gate 	 * enter the debugger again before rebooting the system.
3810Sstevel@tonic-gate 	 */
3820Sstevel@tonic-gate 	if (panic_trigger(&panic_dump)) {
3830Sstevel@tonic-gate 		panic_dump_hw(s);
3840Sstevel@tonic-gate 		splx(ipltospl(CLOCK_LEVEL));
3855197Sstephh 		errorq_panic();
3860Sstevel@tonic-gate 		do_polled_io = 1;
3870Sstevel@tonic-gate 		dumpsys();
3880Sstevel@tonic-gate 	} else if (((boothowto & RB_DEBUG) || obpdebug) && !nopanicdebug) {
3890Sstevel@tonic-gate 		debug_enter("panic: entering debugger (continue to reboot)");
3900Sstevel@tonic-gate 	} else
3910Sstevel@tonic-gate 		printf("dump aborted: please record the above information!\n");
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate 	if (halt_on_panic)
394136Sachartre 		mdboot(A_REBOOT, AD_HALT, NULL, B_FALSE);
3950Sstevel@tonic-gate 	else
396136Sachartre 		mdboot(A_REBOOT, panic_bootfcn, panic_bootstr, B_FALSE);
3970Sstevel@tonic-gate spin:
3980Sstevel@tonic-gate 	/*
3990Sstevel@tonic-gate 	 * Restore ipl to at most CLOCK_LEVEL so we don't end up spinning
4000Sstevel@tonic-gate 	 * and unable to jump into the debugger.
4010Sstevel@tonic-gate 	 */
4020Sstevel@tonic-gate 	splx(MIN(s, ipltospl(CLOCK_LEVEL)));
4035084Sjohnlev 	for (;;)
4045084Sjohnlev 		;
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate 
4070Sstevel@tonic-gate void
panic(const char * format,...)4080Sstevel@tonic-gate panic(const char *format, ...)
4090Sstevel@tonic-gate {
4100Sstevel@tonic-gate 	va_list alist;
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate 	va_start(alist, format);
4130Sstevel@tonic-gate 	vpanic(format, alist);
4140Sstevel@tonic-gate 	va_end(alist);
4150Sstevel@tonic-gate }
416