2 Copyright (c) 2003-2006 Hewlett-Packard Development Company, L.P.
3 Permission is hereby granted, free of charge, to any person
4 obtaining a copy of this software and associated documentation
5 files (the "Software"), to deal in the Software without
6 restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following
12 The above copyright notice and this permission notice shall be
13 included in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 OTHER DEALINGS IN THE SOFTWARE.
25 #define UWX_TRACE_SB 1 /* UWX_TRACE=b: scoreboard mgmt */
26 #define UWX_TRACE_UINFO 2 /* UWX_TRACE=i: unwind info */
27 #define UWX_TRACE_RSTATE 4 /* UWX_TRACE=r: reg state vector */
28 #define UWX_TRACE_STEP 8 /* UWX_TRACE=s: step */
29 #define UWX_TRACE_UTABLE 16 /* UWX_TRACE=t: unwind tbl search */
30 #define UWX_TRACE_CONTEXT 32 /* UWX_TRACE=c: context */
31 #define UWX_TRACE_COPYIN 64 /* UWX_TRACE=C: copyin callback */
32 #define UWX_TRACE_LOOKUPIP 128 /* UWX_TRACE=L: lookupip callback */
34 #ifdef UWX_TRACE_ENABLE
36 extern void uwx_trace_init(struct uwx_env *env);
38 extern void uwx_dump_rstate(int regid, uint64_t rstate);
42 extern void uwx_dump_scoreboard(
43 struct uwx_scoreboard *scoreboard,
45 struct uwx_rhdr *rhdr,
49 #define TRACE_INIT uwx_trace_init(env);
51 #define TRACE_B_REUSE(id) \
52 if (env->trace & UWX_TRACE_SB) \
53 fprintf(stderr, "uwx_alloc_scoreboard: reuse id %d\n", (id));
55 #define TRACE_B_PREALLOC(id) \
56 if (env->trace & UWX_TRACE_SB) \
57 fprintf(stderr, "uwx_prealloc_scoreboard: prealloc id %d\n", (id));
59 #define TRACE_B_ALLOC(id) \
60 if (env->trace & UWX_TRACE_SB) \
61 fprintf(stderr, "uwx_alloc_scoreboard: alloc id %d\n", (id));
63 #define TRACE_B_POP(id) \
64 if (env->trace & UWX_TRACE_SB) \
65 fprintf(stderr, "uwx_pop_scoreboards: free id %d\n", (id));
67 #define TRACE_B_LABEL(label) \
68 if (env->trace & UWX_TRACE_SB) \
69 fprintf(stderr, "uwx_label_scoreboard: label %d\n", (label));
71 #define TRACE_B_LABEL_COPY(id) \
72 if (env->trace & UWX_TRACE_SB) \
73 fprintf(stderr, "uwx_label_scoreboard: copy id %d\n", (id));
75 #define TRACE_B_LABEL_REVERSE(back, new) \
76 if (env->trace & UWX_TRACE_SB) \
77 fprintf(stderr, "uwx_label_scoreboard: reverse link %d -> %d\n", \
78 (new)->id, ((back) == 0) ? -1 : (back)->id);
80 #define TRACE_B_COPY(label, id) \
81 if (env->trace & UWX_TRACE_SB) \
82 fprintf(stderr, "uwx_copy_scoreboard: label %d, cur sb id %d\n", (label), (id));
84 #define TRACE_B_COPY_FREE(id) \
85 if (env->trace & UWX_TRACE_SB) \
86 fprintf(stderr, "uwx_copy_scoreboard: free id %d\n", (id));
88 #define TRACE_B_COPY_FOUND(id) \
89 if (env->trace & UWX_TRACE_SB) \
90 fprintf(stderr, "uwx_copy_scoreboard: found id %d\n", (id));
92 #define TRACE_B_COPY_COPY(id) \
93 if (env->trace & UWX_TRACE_SB) \
94 fprintf(stderr, "uwx_copy_scoreboard: copy id %d\n", (id));
96 #define TRACE_B_COPY_REVERSE(back, new) \
97 if (env->trace & UWX_TRACE_SB) \
98 fprintf(stderr, "uwx_copy_scoreboard: reverse link %d -> %d\n", \
99 (new)->id, ((back) == 0) ? -1 : (back)->id);
101 #define TRACE_B_FREE(id) \
102 if (env->trace & UWX_TRACE_SB) \
103 fprintf(stderr, "uwx_free_scoreboards: free id %d\n", (id));
105 #define TRACE_I_DECODE_RHDR_1(name, b0) \
106 if (env->trace & UWX_TRACE_UINFO) \
107 fprintf(stderr, "uwx_decode_rhdr: %02x %s\n", \
110 #define TRACE_I_DECODE_RHDR_1L(name, b0, val) \
111 if (env->trace & UWX_TRACE_UINFO) \
112 fprintf(stderr, "uwx_decode_rhdr: %02x %08x %s\n", \
113 (b0), (int)(val), (name));
115 #define TRACE_I_DECODE_RHDR_2L(name, b0, b1, val) \
116 if (env->trace & UWX_TRACE_UINFO) \
117 fprintf(stderr, "uwx_decode_rhdr: %02x %02x %08x %s\n", \
118 (b0), (b1), (int)(val), (name));
120 #define TRACE_I_DECODE_PROLOGUE_1(name, b0) \
121 if (env->trace & UWX_TRACE_UINFO) \
122 fprintf(stderr, "uwx_decode_prologue: %02x %s\n", \
125 #define TRACE_I_DECODE_PROLOGUE_1L(name, b0, val) \
126 if (env->trace & UWX_TRACE_UINFO) \
127 fprintf(stderr, "uwx_decode_prologue: %02x %08x %s\n", \
128 (b0), (int)(val), (name));
130 #define TRACE_I_DECODE_PROLOGUE_1LL(name, b0, val1, val2) \
131 if (env->trace & UWX_TRACE_UINFO) \
132 fprintf(stderr, "uwx_decode_prologue: %02x %08x %08x %s\n", \
133 (b0), (int)(val1), (int)(val2), (name));
135 #define TRACE_I_DECODE_PROLOGUE_2(name, b0, b1) \
136 if (env->trace & UWX_TRACE_UINFO) \
137 fprintf(stderr, "uwx_decode_prologue: %02x %02x %s\n", \
140 #define TRACE_I_DECODE_PROLOGUE_2L(name, b0, b1, val) \
141 if (env->trace & UWX_TRACE_UINFO) \
142 fprintf(stderr, "uwx_decode_prologue: %02x %02x %08x %s\n", \
143 (b0), (b1), (int)(val), (name));
145 #define TRACE_I_DECODE_PROLOGUE_3(name, b0, b1, b2) \
146 if (env->trace & UWX_TRACE_UINFO) \
147 fprintf(stderr, "uwx_decode_prologue: %02x %02x %02x %s\n", \
148 (b0), (b1), (b2), (name));
150 #define TRACE_I_DECODE_PROLOGUE_4(name, b0, b1, b2, b3) \
151 if (env->trace & UWX_TRACE_UINFO) \
152 fprintf(stderr, "uwx_decode_prologue: %02x %02x %02x %02x %s\n", \
153 (b0), (b1), (b2), (b3), (name));
155 #define TRACE_I_DECODE_PROLOGUE_SPILL_BASE(spill_base) \
156 if (env->trace & UWX_TRACE_UINFO) \
157 fprintf(stderr, "uwx_decode_prologue: spill base = %08x\n", (int)(spill_base));
159 #define TRACE_I_DECODE_PROLOGUE_MASKS(gr_mem_mask, gr_gr_mask) \
160 if (env->trace & UWX_TRACE_UINFO) \
161 fprintf(stderr, "uwx_decode_prologue: gr_mem_mask = %02x; gr_gr_mask = %02x\n", \
162 (gr_mem_mask), (gr_gr_mask));
164 #define TRACE_I_DECODE_PROLOGUE_NSPILL(ngr) \
165 if (env->trace & UWX_TRACE_UINFO) \
166 fprintf(stderr, "uwx_decode_prologue: ngr = %d\n", (ngr));
168 #define TRACE_I_DECODE_BODY_1(name, b0) \
169 if (env->trace & UWX_TRACE_UINFO) \
170 fprintf(stderr, "uwx_decode_body: %02x %s\n", \
173 #define TRACE_I_DECODE_BODY_1L(name, b0, val) \
174 if (env->trace & UWX_TRACE_UINFO) \
175 fprintf(stderr, "uwx_decode_body: %02x %08x %s\n", \
176 (b0), (int)(val), (name));
178 #define TRACE_I_DECODE_BODY_1LL(name, b0, val1, val2) \
179 if (env->trace & UWX_TRACE_UINFO) \
180 fprintf(stderr, "uwx_decode_body: %02x %08x %08x %s\n", \
181 (b0), (int)(val1), (int)(val2), (name));
183 #define TRACE_R_UIB(uentry, ulen) \
184 if (env->trace & UWX_TRACE_RSTATE) { \
185 fprintf(stderr, "Unwind info block (info = %08x %08x, flags = %08x %08x, ulen = %d)\n", \
186 (unsigned int)((uentry)->unwind_info >> 32), \
187 (unsigned int)(uentry)->unwind_info, \
188 (unsigned int)((uentry)->unwind_flags >> 32), \
189 (unsigned int)(uentry)->unwind_flags, \
191 if (!env->remote) uwx_dump_uinfo_block(uentry, ulen); \
194 #define TRACE_R_DUMP_SB(scoreboard, rhdr, cur_slot, ip_slot) \
195 if (env->trace & UWX_TRACE_RSTATE) \
196 uwx_dump_scoreboard(scoreboard, env->nsbreg, \
197 &(rhdr), cur_slot, ip_slot);
199 #define TRACE_S_STEP(rstate) \
200 if (env->trace & UWX_TRACE_STEP) { \
201 fprintf(stderr, "uwx_restore_markers:\n"); \
202 uwx_dump_rstate(SBREG_RP, (rstate)[SBREG_RP]); \
203 uwx_dump_rstate(SBREG_PSP, (rstate)[SBREG_PSP]); \
204 uwx_dump_rstate(SBREG_PFS, (rstate)[SBREG_PFS]); \
207 #define TRACE_S_RESTORE_REG(regname, rstate, val) \
208 if (env->trace & UWX_TRACE_STEP) \
209 fprintf(stderr, " restore %-7s (rstate = %08x %08x) = %08x %08x\n", \
211 (unsigned int) ((rstate) >> 32), \
212 (unsigned int) (rstate), \
213 (unsigned int) ((val) >> 32), \
214 (unsigned int) (val));
216 #define TRACE_S_RESTORE_GR(regid, rstate, val) \
217 if (env->trace & UWX_TRACE_STEP) \
218 fprintf(stderr, " restore GR%d (rstate = %08x %08x) = %08x %08x\n", \
220 (unsigned int) ((rstate) >> 32), \
221 (unsigned int) (rstate), \
222 (unsigned int) ((val) >> 32), \
223 (unsigned int) (val));
225 #define TRACE_S_RESTORE_BR(regid, rstate, val) \
226 if (env->trace & UWX_TRACE_STEP) \
227 fprintf(stderr, " restore BR%d (rstate = %08x %08x) = %08x %08x\n", \
229 (unsigned int) ((rstate) >> 32), \
230 (unsigned int) (rstate), \
231 (unsigned int) ((val) >> 32), \
232 (unsigned int) (val));
234 #define TRACE_S_RESTORE_FR(regid, rstate, fval) \
235 if (env->trace & UWX_TRACE_STEP) \
236 fprintf(stderr, " restore FR%d (rstate = %08x %08x) = %08x %08x %08x %08x\n", \
238 (unsigned int) ((rstate) >> 32), \
239 (unsigned int) (rstate), \
240 (unsigned int) ((fval[0]) >> 32), \
241 (unsigned int) (fval[0]), \
242 (unsigned int) ((fval[1]) >> 32), \
243 (unsigned int) (fval[1]));
245 #define TRACE_T_SEARCH32(ip) \
246 if (env->trace & UWX_TRACE_UTABLE) \
247 fprintf(stderr, "uwx_search_utable32 (relative ip = %08x)\n", (ip));
249 #define TRACE_T_BINSEARCH32(lb, ub, mid, code_start, code_end) \
250 if (env->trace & UWX_TRACE_UTABLE) \
251 fprintf(stderr, " lb/ub = %d/%d, mid = %d, start/end = %08x %08x\n", \
252 lb, ub, mid, code_start, code_end);
254 #define TRACE_C_GET_REG(regid, bsp) \
255 if (env->trace & UWX_TRACE_CONTEXT) \
256 fprintf(stderr, "uwx_get_reg (gr%d, bsp = %08x %08x)\n", \
257 (regid) - UWX_REG_GR(0), \
258 (unsigned int) ((bsp) >> 32), \
259 (unsigned int) (bsp));
261 #define TRACE_C_ROTATE_GR(regid, sor, rrb_gr, newregid) \
262 if (env->trace & UWX_TRACE_CONTEXT) \
263 fprintf(stderr, "uwx_get_reg (gr%d, sor = %d, rrb = %d) --> gr%d\n", \
269 #define TRACE_SELF_COPYIN4(rem, len, wp) \
270 if (info->trace & UWX_TRACE_COPYIN) \
271 fprintf(stderr, "copyin (rem = %08x %08x, len = %d, val = %08x)\n", \
272 (unsigned int) ((rem) >> 32), \
273 (unsigned int) (rem), \
276 #define TRACE_SELF_COPYIN8(rem, len, dp) \
277 if (info->trace & UWX_TRACE_COPYIN) \
278 fprintf(stderr, "copyin (rem = %08x %08x, len = %d, val = %08x %08x)\n", \
279 (unsigned int) ((rem) >> 32), \
280 (unsigned int) (rem), \
282 ((unsigned int *)(dp))[0], \
283 ((unsigned int *)(dp))[1]);
285 #define TRACE_SELF_LOOKUP(ip) \
286 if (info->trace & UWX_TRACE_LOOKUPIP) \
287 fprintf(stderr, "Lookup IP callback: ip = %08x %08x\n", \
288 (unsigned int) ((ip) >> 32), \
289 (unsigned int) (ip));
291 #define TRACE_SELF_LOOKUP_DESC(text_base, linkage_ptr, unwind_base) \
292 if (info->trace & UWX_TRACE_LOOKUPIP) { \
293 fprintf(stderr, " text base: %08x %08x\n", \
294 (unsigned int) ((text_base) >> 32), \
295 (unsigned int) (text_base)); \
296 fprintf(stderr, " linkage ptr: %08x %08x\n", \
297 (unsigned int) ((linkage_ptr) >> 32), \
298 (unsigned int) (linkage_ptr)); \
299 fprintf(stderr, " unwind base: %08x %08x\n", \
300 (unsigned int) ((uint64_t)(unwind_base) >> 32), \
301 (unsigned int) (unwind_base)); \
302 fprintf(stderr, " unwind flags: %08x %08x\n", \
303 (unsigned int) ((unwind_base)[0] >> 32), \
304 (unsigned int) (unwind_base)[0]); \
305 fprintf(stderr, " unwind start: %08x %08x\n", \
306 (unsigned int) (((text_base)+(unwind_base)[1]) >> 32), \
307 (unsigned int) ((text_base)+(unwind_base)[1])); \
308 fprintf(stderr, " unwind end: %08x %08x\n", \
309 (unsigned int) (((text_base)+(unwind_base)[2]) >> 32), \
310 (unsigned int) ((text_base)+(unwind_base)[2])); \
313 #else /* !UWX_TRACE_ENABLE */
316 #define TRACE_B_REUSE(id)
317 #define TRACE_B_PREALLOC(id)
318 #define TRACE_B_ALLOC(id)
319 #define TRACE_B_POP(id)
320 #define TRACE_B_LABEL(label)
321 #define TRACE_B_LABEL_COPY(id)
322 #define TRACE_B_LABEL_REVERSE(back, new)
323 #define TRACE_B_COPY(label, id)
324 #define TRACE_B_COPY_FREE(id)
325 #define TRACE_B_COPY_FOUND(id)
326 #define TRACE_B_COPY_COPY(id)
327 #define TRACE_B_COPY_REVERSE(back, new)
328 #define TRACE_B_FREE(id)
329 #define TRACE_I_DECODE_RHDR_1(name, b0)
330 #define TRACE_I_DECODE_RHDR_1L(name, b0, val)
331 #define TRACE_I_DECODE_RHDR_2L(name, b0, b1, val)
332 #define TRACE_I_DECODE_PROLOGUE_1(name, b0)
333 #define TRACE_I_DECODE_PROLOGUE_1L(name, b0, val)
334 #define TRACE_I_DECODE_PROLOGUE_1LL(name, b0, val1, val2)
335 #define TRACE_I_DECODE_PROLOGUE_2(name, b0, b1)
336 #define TRACE_I_DECODE_PROLOGUE_2L(name, b0, b1, parm1)
337 #define TRACE_I_DECODE_PROLOGUE_3(name, b0, b1, b2)
338 #define TRACE_I_DECODE_PROLOGUE_4(name, b0, b1, b2, b3)
339 #define TRACE_I_DECODE_PROLOGUE_SPILL_BASE(spill_base)
340 #define TRACE_I_DECODE_PROLOGUE_MASKS(gr_mem_mask, gr_gr_mask)
341 #define TRACE_I_DECODE_PROLOGUE_NSPILL(ngr)
342 #define TRACE_I_DECODE_BODY_1(name, b0)
343 #define TRACE_I_DECODE_BODY_1L(name, b0, parm1)
344 #define TRACE_I_DECODE_BODY_1LL(name, b0, parm1, parm2)
345 #define TRACE_R_UIB(uentry, ulen)
346 #define TRACE_R_DUMP_SB(scoreboard, rhdr, cur_slot, ip_slot)
347 #define TRACE_S_STEP(rstate)
348 #define TRACE_S_RESTORE_REG(regname, rstate, val)
349 #define TRACE_S_RESTORE_GR(regid, rstate, val)
350 #define TRACE_S_RESTORE_BR(regid, rstate, val)
351 #define TRACE_S_RESTORE_FR(regid, rstate, val)
352 #define TRACE_T_SEARCH32(ip)
353 #define TRACE_T_BINSEARCH32(lb, ub, mid, code_start, code_end)
354 #define TRACE_C_GET_REG(regid, bsp)
355 #define TRACE_C_ROTATE_GR(regid, sor, rrb_gr, newregid)
356 #define TRACE_SELF_COPYIN4(rem, len, wp)
357 #define TRACE_SELF_COPYIN8(rem, len, dp)
358 #define TRACE_SELF_LOOKUP(ip)
359 #define TRACE_SELF_LOOKUP_DESC(text_base, linkage_ptr, unwind_base)
361 #endif /* UWX_TRACE_ENABLE */