Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * Hypervisor Software File: debug.h | |
5 | * | |
6 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
7 | * | |
8 | * - Do no alter or remove copyright notices | |
9 | * | |
10 | * - Redistribution and use of this software in source and binary forms, with | |
11 | * or without modification, are permitted provided that the following | |
12 | * conditions are met: | |
13 | * | |
14 | * - Redistribution of source code must retain the above copyright notice, | |
15 | * this list of conditions and the following disclaimer. | |
16 | * | |
17 | * - Redistribution in binary form must reproduce the above copyright notice, | |
18 | * this list of conditions and the following disclaimer in the | |
19 | * documentation and/or other materials provided with the distribution. | |
20 | * | |
21 | * Neither the name of Sun Microsystems, Inc. or the names of contributors | |
22 | * may be used to endorse or promote products derived from this software | |
23 | * without specific prior written permission. | |
24 | * | |
25 | * This software is provided "AS IS," without a warranty of any kind. | |
26 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
27 | * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
28 | * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
29 | * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
30 | * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
31 | * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
32 | * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
33 | * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
34 | * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
35 | * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
36 | * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
37 | * | |
38 | * You acknowledge that this software is not designed, licensed or | |
39 | * intended for use in the design, construction, operation or maintenance of | |
40 | * any nuclear facility. | |
41 | * | |
42 | * ========== Copyright Header End ============================================ | |
43 | */ | |
44 | /* | |
45 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved. | |
46 | * Use is subject to license terms. | |
47 | */ | |
48 | ||
49 | #ifndef _DEBUG_H | |
50 | #define _DEBUG_H | |
51 | ||
52 | #pragma ident "@(#)debug.h 1.10 07/09/14 SMI" | |
53 | ||
54 | #ifdef __cplusplus | |
55 | extern "C" { | |
56 | #endif | |
57 | ||
58 | #include <legion.h> | |
59 | ||
60 | #ifndef _ASM | |
61 | extern uint64_t hv_debug_flags; | |
62 | #endif | |
63 | ||
64 | #define DEBUG_DBG_PRINT (1 << 0) | |
65 | #define DEBUG_DBGL_PRINT (1 << 1) | |
66 | #define DEBUG_DBGHL_PRINT (1 << 2) | |
67 | #define DEBUG_DBGPE_PRINT (1 << 3) | |
68 | #define DEBUG_DBG2_PRINT (1 << 4) | |
69 | #define DEBUG_DBG3_PRINT (1 << 5) | |
70 | #define DEBUG_DBGINIT_PRINT (1 << 6) | |
71 | #define DEBUG_DBGSVC_PRINT (1 << 7) | |
72 | #define DEBUG_DBGVCPU_PRINT (1 << 8) | |
73 | #define DEBUG_DBGG_PRINT (1 << 9) | |
74 | #define DEBUG_DBGBR_PRINT (1 << 10) | |
75 | #define DEBUG_DBGEQ_PRINT (1 << 11) | |
76 | #define DEBUG_DBG_CWQ_PRINT (1 << 12) | |
77 | #define DEBUG_DBG_MAU_PRINT (1 << 13) | |
78 | #define DEBUG_DBG_NET_PRINT (1 << 14) | |
79 | ||
80 | #ifdef DEBUG | |
81 | #define DBG(_s) if (hv_debug_flags & DEBUG_DBG_PRINT) \ | |
82 | do { _s; } while (0) | |
83 | #define DBGL(_s) if (hv_debug_flags & DEBUG_DBGL_PRINT) \ | |
84 | do { _s; } while (0) /* LDCs */ | |
85 | #define DBGHL(_s) if (hv_debug_flags & DEBUG_DBGHL_PRINT) \ | |
86 | do { _s; } while (0) /* HV LDCs */ | |
87 | #define DBGPE(_s) if (hv_debug_flags & DEBUG_DBGPE_PRINT) \ | |
88 | do { _s; } while (0) /* PCI-E */ | |
89 | #define DBG2(_s) if (hv_debug_flags & DEBUG_DBG2_PRINT) \ | |
90 | do { _s; } while (0) | |
91 | #define DBG3(_s) if (hv_debug_flags & DEBUG_DBG3_PRINT) \ | |
92 | do { _s; } while (0) | |
93 | #define DBGINIT(_s) if (hv_debug_flags & DEBUG_DBGINIT_PRINT) \ | |
94 | do { _s; } while (0) | |
95 | #define DBGSVC(_s) if (hv_debug_flags & DEBUG_DBGSVC_PRINT) \ | |
96 | do { _s; } while (0) | |
97 | #define DBGVCPU(_s) if (hv_debug_flags & DEBUG_DBGVCPU_PRINT) \ | |
98 | do { _s; } while (0) | |
99 | #define DBGG(_s) if (hv_debug_flags & DEBUG_DBGG_PRINT) \ | |
100 | do { _s; } while (0) | |
101 | #define DBGBR(_s) if (hv_debug_flags & DEBUG_DBGBR_PRINT) \ | |
102 | do { _s; } while (0) /* PCI-E Bus Reset */ | |
103 | #define DBGEQ(_s) if (hv_debug_flags & DEBUG_DBGEQ_PRINT) \ | |
104 | do { _s; } while (0) /* PCI-E MSI EQ mapping */ | |
105 | #define DBG_CWQ(_s) if (hv_debug_flags & DEBUG_DBG_CWQ_PRINT) \ | |
106 | do { _s; } while (0) /* N1/N2 MAU */ | |
107 | #define DBG_MAU(_s) if (hv_debug_flags & DEBUG_DBG_MAU_PRINT) \ | |
108 | do { _s; } while (0) /* N1/N2 MAU */ | |
109 | #define DBGNET(_s) if (hv_debug_flags & DEBUG_DBG_NET_PRINT) \ | |
110 | do { _s; } while (0) /* Network */ | |
111 | #else | |
112 | #define DBG(_s) | |
113 | #define DBGL(_s) | |
114 | #define DBGHL(_s) | |
115 | #define DBGPE(_s) | |
116 | #define DBG2(_s) | |
117 | #define DBG3(_s) | |
118 | #define DBGINIT(_s) | |
119 | #define DBGSVC(_s) | |
120 | #define DBGVCPU(_s) | |
121 | #define DBGG(_s) | |
122 | #define DBGBR(_s) | |
123 | #define DBGEQ(_s) | |
124 | #define DBG_CWQ(_s) | |
125 | #define DBG_MAU(_s) | |
126 | #define DBGNET(_s) | |
127 | #endif | |
128 | ||
129 | /* | |
130 | * Debugging aids | |
131 | */ | |
132 | ||
133 | /* BEGIN CSTYLED */ | |
134 | #define _PRINT_SPINLOCK_ENTER(scr1, scr2, scr3) \ | |
135 | .pushlocals ;\ | |
136 | STRAND_STRUCT(scr2) ;\ | |
137 | ldub [scr2 + STRAND_ID], scr2 ;\ | |
138 | inc scr2 /* lockID = cpuid + 1 */ ;\ | |
139 | ROOT_STRUCT(scr1) ;\ | |
140 | add scr1, CONFIG_PRINT_SPINLOCK, scr1 /* scr1 = lockaddr */ ;\ | |
141 | 1: nop; nop; nop; nop; /* delay */ ;\ | |
142 | mov scr2, scr3 ;\ | |
143 | casxa [scr1]0x4, %g0, scr3 /* if zero, write my lockID */ ;\ | |
144 | brnz scr3, 1b ;\ | |
145 | nop ;\ | |
146 | .poplocals | |
147 | ||
148 | #define _PRINT_SPINLOCK_EXIT(scr1) \ | |
149 | ROOT_STRUCT(scr1) ;\ | |
150 | add scr1, CONFIG_PRINT_SPINLOCK, scr1 /* scr1 = lockaddr */ ;\ | |
151 | stx %g0, [scr1] | |
152 | /* END CSTYLED */ | |
153 | ||
154 | /* | |
155 | * These PRINT macros clobber %g7 | |
156 | * | |
157 | * XXX - when gl is too high ta 0x13/0x14 which will print "lost message" error | |
158 | */ | |
159 | ||
160 | #define MAX_PRINTTRAP_GL 2 | |
161 | ||
162 | /* BEGIN CSTYLED */ | |
163 | #define _PRINTX(x) \ | |
164 | .pushlocals ;\ | |
165 | rdpr %gl, %g7 ;\ | |
166 | cmp %g7, MAX_PRINTTRAP_GL ;\ | |
167 | bgu,pt %xcc, 2f ;\ | |
168 | nop ;\ | |
169 | mov %o0, %g7 ;\ | |
170 | mov x, %o0 ;\ | |
171 | ta 0x14 ;\ | |
172 | mov %g7, %o0 ;\ | |
173 | 2: ;\ | |
174 | .poplocals | |
175 | ||
176 | #define _PRINT(s) \ | |
177 | .pushlocals ;\ | |
178 | rdpr %gl, %g7 ;\ | |
179 | cmp %g7, MAX_PRINTTRAP_GL ;\ | |
180 | bgu,pt %xcc, 2f ;\ | |
181 | nop ;\ | |
182 | mov %o0, %g7 ;\ | |
183 | ba 1f ;\ | |
184 | rd %pc, %o0 ;\ | |
185 | .asciz s ;\ | |
186 | .align 4 ;\ | |
187 | 1: add %o0, 4, %o0 ;\ | |
188 | ta 0x13 ;\ | |
189 | mov %g7, %o0 ;\ | |
190 | 2: ;\ | |
191 | .poplocals | |
192 | ||
193 | #define _PRINT_REGISTER(desc, reg) \ | |
194 | _PRINT(desc) ;\ | |
195 | _PRINT(" = 0x") ;\ | |
196 | _PRINTX(reg) ;\ | |
197 | _PRINT("\r\n") | |
198 | ||
199 | /* | |
200 | * clobbers %g1-%g4,%g7 | |
201 | */ | |
202 | #define _PRINT_NOTRAP(s) \ | |
203 | .pushlocals ;\ | |
204 | ba 1f ;\ | |
205 | rd %pc, %g1 ;\ | |
206 | 2: .asciz s ;\ | |
207 | .align 4 ;\ | |
208 | 1: add %g1, 4, %g1 ;\ | |
209 | ba puts ;\ | |
210 | rd %pc, %g7 ;\ | |
211 | .poplocals | |
212 | ||
213 | /* | |
214 | * clobbers %g1-%g5,%g7 | |
215 | */ | |
216 | #define _PRINTX_NOTRAP(x) \ | |
217 | mov x, %g1 ;\ | |
218 | ba putx ;\ | |
219 | rd %pc, %g7 | |
220 | ||
221 | /* END CSTYLED */ | |
222 | ||
223 | #ifdef DEBUG | |
224 | ||
225 | #define PRINT(s) _PRINT(s) | |
226 | #define PRINTX(x) _PRINTX(x) | |
227 | #define PRINT_REGISTER(d, x) _PRINT_REGISTER(d, x) | |
228 | #define PRINT_NOTRAP(s) _PRINT_NOTRAP(s) | |
229 | #define PRINTX_NOTRAP(x) _PRINTX_NOTRAP(x) | |
230 | ||
231 | #define DEBUG_SPINLOCK_ENTER(s1, s2, s3) _PRINT_SPINLOCK_ENTER(s1, s2, s3) | |
232 | #define DEBUG_SPINLOCK_EXIT(s) _PRINT_SPINLOCK_EXIT(s) | |
233 | ||
234 | #else /* !DEBUG */ | |
235 | ||
236 | #define PRINT(x) | |
237 | #define PRINTX(x) | |
238 | #define PRINT_REGISTER(d, x) | |
239 | #define PRINTX_NOTRAP(x) | |
240 | #define PRINT_NOTRAP(x) | |
241 | ||
242 | #define DEBUG_SPINLOCK_ENTER(s1, s2, s3) | |
243 | #define DEBUG_SPINLOCK_EXIT(s) | |
244 | ||
245 | #endif /* !DEBUG */ | |
246 | ||
247 | /* | |
248 | * The following macros are only intended for messages that | |
249 | * should always get printed to the hypervisor console. | |
250 | */ | |
251 | #define HV_PRINT(s) _PRINT(s) | |
252 | #define HV_PRINTX(x) _PRINTX(x) | |
253 | #define HV_PRINT_REGISTER(d, x) _PRINT_REGISTER(d, x) | |
254 | #define HV_PRINT_NOTRAP(s) _PRINT_NOTRAP(s) | |
255 | #define HV_PRINTX_NOTRAP(x) _PRINTX_NOTRAP(x) | |
256 | ||
257 | #define HV_PRINT_SPINLOCK_ENTER(s1, s2, s3) _PRINT_SPINLOCK_ENTER(s1, s2, s3) | |
258 | #define HV_PRINT_SPINLOCK_EXIT(s) _PRINT_SPINLOCK_EXIT(s) | |
259 | ||
260 | #ifdef __cplusplus | |
261 | } | |
262 | #endif | |
263 | ||
264 | #endif /* _DEBUG_H */ |