xref: /titanic_52/usr/src/uts/common/sys/panic.h (revision 5f149bca52352f45598e5563debe72ce04bd7a21)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_PANIC_H
27 #define	_SYS_PANIC_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #if !defined(_ASM)
32 #include <sys/types.h>
33 #include <sys/thread.h>
34 #include <sys/cpuvar.h>
35 #endif	/* !_ASM */
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #ifdef _LP64
42 #define	PANICSTKSIZE	16384
43 #else
44 #define	PANICSTKSIZE	8192
45 #endif
46 
47 #define	PANICBUFSIZE	8192
48 #define	PANICBUFVERS	1
49 
50 #define	PANICNVNAMELEN	16
51 
52 /*
53  * Panicbuf Format:
54  *
55  * The kernel records the formatted panic message and an optional array of
56  * name/value pairs into panicbuf[], a fixed-size buffer which is saved in
57  * the crash dump and, on some platforms, is persistent across reboots.
58  * The initial part of the buffer is a struct of type panic_data_t, which
59  * includes a version number for identifying the format of subsequent data.
60  *
61  * The pd_msgoff word identifies the byte offset into panicbuf[] at which the
62  * null-terminated panic message is located.  This is followed by an optional
63  * variable-sized array of panic_nv_t items, which are used to record CPU
64  * register values.  The number of items in pd_nvdata is computed as follows:
65  *
66  * (pd_msgoff - (sizeof (panic_data_t) - sizeof (panic_nv_t))) /
67  * 	sizeof (panic_nv_t);
68  *
69  * In addition to panicbuf, debuggers can access the panic_* variables shown
70  * below to determine more information about the initiator of the panic.
71  */
72 
73 #if !defined(_ASM)
74 
75 typedef struct panic_nv {
76 	char pnv_name[PANICNVNAMELEN];	/* String name */
77 	uint64_t pnv_value;		/* Value */
78 } panic_nv_t;
79 
80 typedef struct panic_data {
81 	uint32_t pd_version;		/* Version number of panic_data_t */
82 	uint32_t pd_msgoff;		/* Message byte offset in panicbuf */
83 	panic_nv_t pd_nvdata[1];	/* Array of named data */
84 } panic_data_t;
85 
86 #if defined(_KERNEL)
87 
88 /*
89  * Kernel macros for adding information to pd_nvdata[].  PANICNVGET() returns
90  * a panic_nv_t pointer (pnv) after the end of the existing data, PANICNVADD()
91  * modifies the current item and increments pnv, and PANICNVSET() rewrites
92  * pd_msgoff to indicate the end of pd_nvdata[].
93  */
94 #define	PANICNVGET(pdp)							\
95 	((pdp)->pd_nvdata + (((pdp)->pd_msgoff -			\
96 	(sizeof (panic_data_t) - sizeof (panic_nv_t))) / sizeof (panic_nv_t)))
97 
98 #define	PANICNVADD(pnv, n, v)						\
99 	{								\
100 		(void) strncpy((pnv)->pnv_name, (n), PANICNVNAMELEN);	\
101 		(pnv)->pnv_value = (uint64_t)(v); (pnv)++;		\
102 	}
103 
104 #define	PANICNVSET(pdp, pnv) \
105 	(pdp)->pd_msgoff = (uint32_t)((char *)(pnv) - (char *)(pdp));
106 
107 /*
108  * Kernel panic data; preserved in crash dump for debuggers.
109  */
110 #pragma align 8(panicbuf)
111 extern char panicbuf[PANICBUFSIZE];
112 extern kthread_t *panic_thread;
113 extern cpu_t panic_cpu;
114 extern hrtime_t panic_hrtime;
115 extern timespec_t panic_hrestime;
116 
117 /*
118  * Forward declarations for types:
119  */
120 struct panic_trap_info;
121 struct regs;
122 
123 /*
124  * Miscellaneous state variables defined in or used by the panic code:
125  */
126 extern char *panic_bootstr;
127 extern int panic_bootfcn;
128 extern int panic_forced;
129 extern int halt_on_panic;
130 extern int nopanicdebug;
131 extern int do_polled_io;
132 extern int obpdebug;
133 extern int in_sync;
134 extern int panic_quiesce;
135 extern int panic_sync;
136 extern int panic_dump;
137 extern int64_t panic_lbolt64;
138 extern label_t panic_regs;
139 extern struct regs *panic_reg;
140 
141 /*
142  * Panic functions called from the common panic code which must be
143  * implemented by architecture or platform-specific code:
144  */
145 extern void panic_saveregs(panic_data_t *, struct regs *);
146 extern void panic_savetrap(panic_data_t *, struct panic_trap_info *);
147 extern void panic_showtrap(struct panic_trap_info *);
148 extern void panic_stopcpus(cpu_t *, kthread_t *, int);
149 extern void panic_enter_hw(int);
150 extern void panic_quiesce_hw(panic_data_t *);
151 extern void panic_dump_hw(int);
152 extern int panic_trigger(int *);
153 
154 #endif /* _KERNEL */
155 #endif /* !_ASM */
156 
157 #ifdef	__cplusplus
158 }
159 #endif
160 
161 #endif	/* _SYS_PANIC_H */
162