xref: /illumos-gate/usr/src/uts/common/sys/panic.h (revision 843e19887f64dde75055cf8842fc4db2171eff45)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*843e1988Sjohnlev  * Common Development and Distribution License (the "License").
6*843e1988Sjohnlev  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*843e1988Sjohnlev  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_PANIC_H
277c478bd9Sstevel@tonic-gate #define	_SYS_PANIC_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #if !defined(_ASM)
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/thread.h>
347c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
357c478bd9Sstevel@tonic-gate #endif	/* !_ASM */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef _LP64
427c478bd9Sstevel@tonic-gate #define	PANICSTKSIZE	16384
437c478bd9Sstevel@tonic-gate #else
447c478bd9Sstevel@tonic-gate #define	PANICSTKSIZE	8192
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #define	PANICBUFSIZE	8192
487c478bd9Sstevel@tonic-gate #define	PANICBUFVERS	1
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #define	PANICNVNAMELEN	16
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * Panicbuf Format:
547c478bd9Sstevel@tonic-gate  *
557c478bd9Sstevel@tonic-gate  * The kernel records the formatted panic message and an optional array of
567c478bd9Sstevel@tonic-gate  * name/value pairs into panicbuf[], a fixed-size buffer which is saved in
577c478bd9Sstevel@tonic-gate  * the crash dump and, on some platforms, is persistent across reboots.
587c478bd9Sstevel@tonic-gate  * The initial part of the buffer is a struct of type panic_data_t, which
597c478bd9Sstevel@tonic-gate  * includes a version number for identifying the format of subsequent data.
607c478bd9Sstevel@tonic-gate  *
617c478bd9Sstevel@tonic-gate  * The pd_msgoff word identifies the byte offset into panicbuf[] at which the
627c478bd9Sstevel@tonic-gate  * null-terminated panic message is located.  This is followed by an optional
637c478bd9Sstevel@tonic-gate  * variable-sized array of panic_nv_t items, which are used to record CPU
647c478bd9Sstevel@tonic-gate  * register values.  The number of items in pd_nvdata is computed as follows:
657c478bd9Sstevel@tonic-gate  *
667c478bd9Sstevel@tonic-gate  * (pd_msgoff - (sizeof (panic_data_t) - sizeof (panic_nv_t))) /
677c478bd9Sstevel@tonic-gate  * 	sizeof (panic_nv_t);
687c478bd9Sstevel@tonic-gate  *
697c478bd9Sstevel@tonic-gate  * In addition to panicbuf, debuggers can access the panic_* variables shown
707c478bd9Sstevel@tonic-gate  * below to determine more information about the initiator of the panic.
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #if !defined(_ASM)
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate typedef struct panic_nv {
767c478bd9Sstevel@tonic-gate 	char pnv_name[PANICNVNAMELEN];	/* String name */
777c478bd9Sstevel@tonic-gate 	uint64_t pnv_value;		/* Value */
787c478bd9Sstevel@tonic-gate } panic_nv_t;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate typedef struct panic_data {
817c478bd9Sstevel@tonic-gate 	uint32_t pd_version;		/* Version number of panic_data_t */
827c478bd9Sstevel@tonic-gate 	uint32_t pd_msgoff;		/* Message byte offset in panicbuf */
837c478bd9Sstevel@tonic-gate 	panic_nv_t pd_nvdata[1];	/* Array of named data */
847c478bd9Sstevel@tonic-gate } panic_data_t;
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * Kernel macros for adding information to pd_nvdata[].  PANICNVGET() returns
907c478bd9Sstevel@tonic-gate  * a panic_nv_t pointer (pnv) after the end of the existing data, PANICNVADD()
917c478bd9Sstevel@tonic-gate  * modifies the current item and increments pnv, and PANICNVSET() rewrites
927c478bd9Sstevel@tonic-gate  * pd_msgoff to indicate the end of pd_nvdata[].
937c478bd9Sstevel@tonic-gate  */
947c478bd9Sstevel@tonic-gate #define	PANICNVGET(pdp)							\
957c478bd9Sstevel@tonic-gate 	((pdp)->pd_nvdata + (((pdp)->pd_msgoff -			\
967c478bd9Sstevel@tonic-gate 	(sizeof (panic_data_t) - sizeof (panic_nv_t))) / sizeof (panic_nv_t)))
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate #define	PANICNVADD(pnv, n, v)						\
997c478bd9Sstevel@tonic-gate 	{								\
1007c478bd9Sstevel@tonic-gate 		(void) strncpy((pnv)->pnv_name, (n), PANICNVNAMELEN);	\
1017c478bd9Sstevel@tonic-gate 		(pnv)->pnv_value = (uint64_t)(v); (pnv)++;		\
1027c478bd9Sstevel@tonic-gate 	}
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate #define	PANICNVSET(pdp, pnv) \
1057c478bd9Sstevel@tonic-gate 	(pdp)->pd_msgoff = (uint32_t)((char *)(pnv) - (char *)(pdp));
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate  * Kernel panic data; preserved in crash dump for debuggers.
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate #pragma align 8(panicbuf)
1117c478bd9Sstevel@tonic-gate extern char panicbuf[PANICBUFSIZE];
1127c478bd9Sstevel@tonic-gate extern kthread_t *panic_thread;
1137c478bd9Sstevel@tonic-gate extern cpu_t panic_cpu;
1147c478bd9Sstevel@tonic-gate extern hrtime_t panic_hrtime;
1157c478bd9Sstevel@tonic-gate extern timespec_t panic_hrestime;
1167c478bd9Sstevel@tonic-gate 
117*843e1988Sjohnlev /*
118*843e1988Sjohnlev  * Forward declarations for types:
119*843e1988Sjohnlev  */
120*843e1988Sjohnlev struct panic_trap_info;
121*843e1988Sjohnlev struct regs;
122*843e1988Sjohnlev 
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * Miscellaneous state variables defined in or used by the panic code:
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate extern char *panic_bootstr;
1277c478bd9Sstevel@tonic-gate extern int panic_bootfcn;
1287c478bd9Sstevel@tonic-gate extern int panic_forced;
1297c478bd9Sstevel@tonic-gate extern int halt_on_panic;
1307c478bd9Sstevel@tonic-gate extern int nopanicdebug;
1317c478bd9Sstevel@tonic-gate extern int do_polled_io;
1327c478bd9Sstevel@tonic-gate extern int obpdebug;
1337c478bd9Sstevel@tonic-gate extern int in_sync;
1347c478bd9Sstevel@tonic-gate extern int panic_quiesce;
1357c478bd9Sstevel@tonic-gate extern int panic_sync;
1367c478bd9Sstevel@tonic-gate extern int panic_dump;
137*843e1988Sjohnlev extern int64_t panic_lbolt64;
138*843e1988Sjohnlev extern label_t panic_regs;
139*843e1988Sjohnlev extern struct regs *panic_reg;
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate /*
1427c478bd9Sstevel@tonic-gate  * Panic functions called from the common panic code which must be
1437c478bd9Sstevel@tonic-gate  * implemented by architecture or platform-specific code:
1447c478bd9Sstevel@tonic-gate  */
1457c478bd9Sstevel@tonic-gate extern void panic_saveregs(panic_data_t *, struct regs *);
146*843e1988Sjohnlev extern void panic_savetrap(panic_data_t *, struct panic_trap_info *);
147*843e1988Sjohnlev extern void panic_showtrap(struct panic_trap_info *);
1487c478bd9Sstevel@tonic-gate extern void panic_stopcpus(cpu_t *, kthread_t *, int);
1497c478bd9Sstevel@tonic-gate extern void panic_enter_hw(int);
1507c478bd9Sstevel@tonic-gate extern void panic_quiesce_hw(panic_data_t *);
1517c478bd9Sstevel@tonic-gate extern void panic_dump_hw(int);
1527c478bd9Sstevel@tonic-gate extern int panic_trigger(int *);
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
1557c478bd9Sstevel@tonic-gate #endif /* !_ASM */
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1587c478bd9Sstevel@tonic-gate }
1597c478bd9Sstevel@tonic-gate #endif
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate #endif	/* _SYS_PANIC_H */
162