xref: /illumos-gate/usr/src/uts/common/sys/panic.h (revision e77c795bcbe51aebd7579fe13cbf2a6d56eca47f)
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 (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef	_SYS_PANIC_H
26 #define	_SYS_PANIC_H
27 
28 #if !defined(_ASM)
29 #include <sys/types.h>
30 #include <sys/thread.h>
31 #include <sys/cpuvar.h>
32 #endif	/* !_ASM */
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #ifdef _LP64
39 #define	PANICSTKSIZE	16384
40 #else
41 #define	PANICSTKSIZE	8192
42 #endif
43 
44 #define	PANICBUFSIZE	8192
45 #define	PANICBUFVERS	2
46 
47 #define	PANICNVNAMELEN	16
48 
49 #define	STACK_BUF_SIZE	2048
50 #define	SUMMARY_MAGIC	0xdead0d8a
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 	char pd_uuid[36 + 1];		/* image uuid */
84 	panic_nv_t pd_nvdata[1];	/* Array of named data */
85 } panic_data_t;
86 
87 typedef struct summary_dump {
88 	uint32_t sd_magic;		/* magic number */
89 	uint32_t sd_ssum;		/* checsksum32(stack buffer) */
90 	/*
91 	 * stack buffer and other summary data follow here -- see
92 	 * dump_summary()
93 	 */
94 } summary_dump_t;
95 
96 #if defined(_KERNEL)
97 
98 /*
99  * Kernel macros for adding information to pd_nvdata[].  PANICNVGET() returns
100  * a panic_nv_t pointer (pnv) after the end of the existing data, PANICNVADD()
101  * modifies the current item and increments pnv, and PANICNVSET() rewrites
102  * pd_msgoff to indicate the end of pd_nvdata[].
103  */
104 #define	PANICNVGET(pdp)							\
105 	((pdp)->pd_nvdata + (((pdp)->pd_msgoff -			\
106 	(sizeof (panic_data_t) - sizeof (panic_nv_t))) / sizeof (panic_nv_t)))
107 
108 #define	PANICNVADD(pnv, n, v)						\
109 	{								\
110 		(void) strncpy((pnv)->pnv_name, (n), PANICNVNAMELEN);	\
111 		(pnv)->pnv_value = (uint64_t)(v); (pnv)++;		\
112 	}
113 
114 #define	PANICNVSET(pdp, pnv) \
115 	(pdp)->pd_msgoff = (uint32_t)((char *)(pnv) - (char *)(pdp));
116 
117 /*
118  * Kernel panic data; preserved in crash dump for debuggers.
119  */
120 #pragma align 8(panicbuf)
121 extern char panicbuf[PANICBUFSIZE];
122 extern kthread_t *panic_thread;
123 extern cpu_t panic_cpu;
124 extern hrtime_t panic_hrtime;
125 extern timespec_t panic_hrestime;
126 
127 /*
128  * Forward declarations for types:
129  */
130 struct panic_trap_info;
131 struct regs;
132 
133 /*
134  * Miscellaneous state variables defined in or used by the panic code:
135  */
136 extern char *panic_bootstr;
137 extern int panic_bootfcn;
138 extern int panic_forced;
139 extern int halt_on_panic;
140 extern int nopanicdebug;
141 extern int do_polled_io;
142 extern int obpdebug;
143 extern int in_sync;
144 extern int panic_quiesce;
145 extern int panic_sync;
146 extern int panic_dump;
147 extern int64_t panic_lbolt64;
148 extern label_t panic_regs;
149 extern struct regs *panic_reg;
150 
151 /*
152  * Panic functions called from the common panic code which must be
153  * implemented by architecture or platform-specific code:
154  */
155 extern void panic_saveregs(panic_data_t *, struct regs *);
156 extern void panic_savetrap(panic_data_t *, struct panic_trap_info *);
157 extern void panic_showtrap(struct panic_trap_info *);
158 extern void panic_stopcpus(cpu_t *, kthread_t *, int);
159 extern void panic_enter_hw(int);
160 extern void panic_quiesce_hw(panic_data_t *);
161 extern void panic_dump_hw(int);
162 extern int panic_trigger(int *);
163 
164 #endif /* _KERNEL */
165 #endif /* !_ASM */
166 
167 #ifdef	__cplusplus
168 }
169 #endif
170 
171 #endif	/* _SYS_PANIC_H */
172