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