aboutsummaryrefslogtreecommitdiffstats
path: root/sys/contrib/ia64/libuwx/src/uwx_trace.h
blob: 38a2e9dbb9c8f9aa79926393d0868aedbec5569b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/*
Copyright (c) 2003 Hewlett-Packard Development Company, L.P.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

#define UWX_TRACE_SB		1	/* UWX_TRACE=b: scoreboard mgmt */
#define UWX_TRACE_UINFO		2	/* UWX_TRACE=i: unwind info */
#define UWX_TRACE_RSTATE	4	/* UWX_TRACE=r: reg state vector */
#define UWX_TRACE_STEP		8	/* UWX_TRACE=s: step */
#define UWX_TRACE_UTABLE	16	/* UWX_TRACE=t: unwind tbl search */
#define UWX_TRACE_CONTEXT	32	/* UWX_TRACE=c: context */
#define UWX_TRACE_COPYIN	64	/* UWX_TRACE=C: copyin callback */
#define UWX_TRACE_LOOKUPIP	128	/* UWX_TRACE=L: lookupip callback */

#ifdef UWX_TRACE_ENABLE

extern void uwx_trace_init(struct uwx_env *env);

extern void uwx_dump_rstate(int regid, uint64_t rstate);

struct uwx_rhdr;

extern void uwx_dump_scoreboard(
    struct uwx_scoreboard *scoreboard,
    int nsbreg,
    struct uwx_rhdr *rhdr,
    int cur_slot,
    int ip_slot);

#define TRACE_INIT uwx_trace_init(env);

#define TRACE_B_REUSE(id) \
    if (env->trace & UWX_TRACE_SB) \
	printf("uwx_alloc_scoreboard: reuse id %d\n", (id));

#define TRACE_B_ALLOC(id) \
    if (env->trace & UWX_TRACE_SB) \
	printf("uwx_alloc_scoreboard: alloc id %d\n", (id));

#define TRACE_B_POP(id) \
    if (env->trace & UWX_TRACE_SB) \
	printf("uwx_pop_scoreboards: free id %d\n", (id));

#define TRACE_B_LABEL(label) \
    if (env->trace & UWX_TRACE_SB) \
	printf("uwx_label_scoreboard: label %d\n", (label));

#define TRACE_B_LABEL_COPY(id) \
    if (env->trace & UWX_TRACE_SB) \
	printf("uwx_label_scoreboard: copy id %d\n", (id));

#define TRACE_B_LABEL_REVERSE(back, new) \
    if (env->trace & UWX_TRACE_SB) \
	printf("uwx_label_scoreboard: reverse link %d -> %d\n", \
			    (new)->id, ((back) == 0) ? -1 : (back)->id);

#define TRACE_B_COPY(label, id) \
    if (env->trace & UWX_TRACE_SB) \
	printf("uwx_copy_scoreboard: label %d, cur sb id %d\n", (label), (id));

#define TRACE_B_COPY_FREE(id) \
    if (env->trace & UWX_TRACE_SB) \
	printf("uwx_copy_scoreboard: free id %d\n", (id));

#define TRACE_B_COPY_FOUND(id) \
    if (env->trace & UWX_TRACE_SB) \
	printf("uwx_copy_scoreboard: found id %d\n", (id));

#define TRACE_B_COPY_COPY(id) \
    if (env->trace & UWX_TRACE_SB) \
	printf("uwx_copy_scoreboard: copy id %d\n", (id));

#define TRACE_B_COPY_REVERSE(back, new) \
    if (env->trace & UWX_TRACE_SB) \
	printf("uwx_copy_scoreboard: reverse link %d -> %d\n", \
			    (new)->id, ((back) == 0) ? -1 : (back)->id);

#define TRACE_B_FREE(id) \
    if (env->trace & UWX_TRACE_SB) \
	printf("uwx_free_scoreboards: free id %d\n", (id));

#define TRACE_I_DECODE_RHDR_1(name, b0) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_rhdr:     %02x                   %s\n", \
			(b0), (name));

#define TRACE_I_DECODE_RHDR_1L(name, b0, val) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_rhdr:     %02x %08x          %s\n", \
			(b0), (int)(val), (name));

#define TRACE_I_DECODE_RHDR_2L(name, b0, b1, val) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_rhdr:     %02x %02x %08x       %s\n", \
			(b0), (b1), (int)(val), (name));

#define TRACE_I_DECODE_PROLOGUE_1(name, b0) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_prologue: %02x                   %s\n", \
			(b0), (name));

#define TRACE_I_DECODE_PROLOGUE_1L(name, b0, val) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_prologue: %02x %08x          %s\n", \
			(b0), (int)(val), (name));

#define TRACE_I_DECODE_PROLOGUE_1LL(name, b0, val1, val2) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_prologue: %02x %08x %08x %s\n", \
			(b0), (int)(val1), (int)(val2), (name));

#define TRACE_I_DECODE_PROLOGUE_2(name, b0, b1) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_prologue: %02x %02x                %s\n", \
			(b0), (b1), (name));

#define TRACE_I_DECODE_PROLOGUE_2L(name, b0, b1, val) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_prologue: %02x %02x %08x       %s\n", \
			(b0), (b1), (int)(val), (name));

#define TRACE_I_DECODE_PROLOGUE_3(name, b0, b1, b2) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_prologue: %02x %02x %02x             %s\n", \
			(b0), (b1), (b2), (name));

#define TRACE_I_DECODE_PROLOGUE_4(name, b0, b1, b2, b3) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_prologue: %02x %02x %02x %02x          %s\n", \
			(b0), (b1), (b2), (b3), (name));

#define TRACE_I_DECODE_PROLOGUE_SPILL_BASE(spill_base) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_prologue: spill base = %08x\n", (int)(spill_base));

#define TRACE_I_DECODE_PROLOGUE_MASKS(gr_mem_mask, gr_gr_mask) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_prologue: gr_mem_mask = %02x; gr_gr_mask = %02x\n", \
			(gr_mem_mask), (gr_gr_mask));

#define TRACE_I_DECODE_PROLOGUE_NSPILL(ngr) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_prologue: ngr = %d\n", (ngr));

#define TRACE_I_DECODE_BODY_1(name, b0) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_body:     %02x                   %s\n", \
			(b0), (name));

#define TRACE_I_DECODE_BODY_1L(name, b0, val) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_body:     %02x %08x          %s\n", \
			(b0), (int)(val), (name));

#define TRACE_I_DECODE_BODY_1LL(name, b0, val1, val2) \
    if (env->trace & UWX_TRACE_UINFO) \
	printf("uwx_decode_body:     %02x %08x %08x %s\n", \
			(b0), (int)(val1), (int)(val2), (name));

#define TRACE_R_UIB(uentry, ulen) \
    if (env->trace & UWX_TRACE_RSTATE) \
	printf("Unwind info block (flags = %08x %08x, ulen = %d)\n", \
		    (unsigned int)((uentry)->unwind_flags >> 32), \
		    (unsigned int)(uentry)->unwind_flags, \
		    (ulen));

#define TRACE_R_DUMP_SB(scoreboard, rhdr, cur_slot, ip_slot) \
    if (env->trace & UWX_TRACE_RSTATE) \
	uwx_dump_scoreboard(scoreboard, env->nsbreg, \
				&(rhdr), cur_slot, ip_slot);

#define TRACE_S_STEP(rstate) \
    if (env->trace & UWX_TRACE_STEP) { \
	printf("uwx_restore_markers:\n"); \
	uwx_dump_rstate(SBREG_RP, (rstate)[SBREG_RP]); \
	uwx_dump_rstate(SBREG_PSP, (rstate)[SBREG_PSP]); \
	uwx_dump_rstate(SBREG_PFS, (rstate)[SBREG_PFS]); \
    }

#define TRACE_S_RESTORE_REG(regname, rstate, val) \
    if (env->trace & UWX_TRACE_STEP) \
	printf("  restore %-7s (rstate = %08x %08x) = %08x %08x\n", \
			regname, \
			(unsigned int) ((rstate) >> 32), \
			(unsigned int) (rstate), \
			(unsigned int) ((val) >> 32), \
			(unsigned int) (val));

#define TRACE_S_RESTORE_GR(regid, rstate, val) \
    if (env->trace & UWX_TRACE_STEP) \
	printf("  restore GR%d     (rstate = %08x %08x) = %08x %08x\n", \
			(regid) + 4, \
			(unsigned int) ((rstate) >> 32), \
			(unsigned int) (rstate), \
			(unsigned int) ((val) >> 32), \
			(unsigned int) (val));

#define TRACE_S_RESTORE_BR(regid, rstate, val) \
    if (env->trace & UWX_TRACE_STEP) \
	printf("  restore BR%d     (rstate = %08x %08x) = %08x %08x\n", \
			(regid) + 1, \
			(unsigned int) ((rstate) >> 32), \
			(unsigned int) (rstate), \
			(unsigned int) ((val) >> 32), \
			(unsigned int) (val));

#define TRACE_S_RESTORE_FR(regid, rstate, fval) \
    if (env->trace & UWX_TRACE_STEP) \
	printf("  restore FR%d     (rstate = %08x %08x) = %08x %08x %08x %08x\n", \
			(regid) + 1, \
			(unsigned int) ((rstate) >> 32), \
			(unsigned int) (rstate), \
			(unsigned int) ((fval[0]) >> 32), \
			(unsigned int) (fval[0]), \
			(unsigned int) ((fval[1]) >> 32), \
			(unsigned int) (fval[1]));

#define TRACE_T_SEARCH32(ip) \
    if (env->trace & UWX_TRACE_UTABLE) \
	printf("uwx_search_utable32 (relative ip = %08x)\n", (ip));

#define TRACE_T_BINSEARCH32(lb, ub, mid, code_start, code_end) \
    if (env->trace & UWX_TRACE_UTABLE) \
	printf("    lb/ub = %d/%d, mid = %d, start/end = %08x %08x\n", \
			    lb, ub, mid, code_start, code_end);

#define TRACE_C_GET_REG(regid, bsp) \
	if (env->trace & UWX_TRACE_CONTEXT) \
	    printf("uwx_get_reg (gr%d, bsp = %08x %08x)\n", \
			(regid) - UWX_REG_GR(0), \
			(unsigned int) ((bsp) >> 32), \
			(unsigned int) (bsp));

#define TRACE_C_ROTATE_GR(regid, sor, rrb_gr, newregid) \
	if (env->trace & UWX_TRACE_CONTEXT) \
	    printf("uwx_get_reg (gr%d, sor = %d, rrb = %d) --> gr%d\n", \
			(regid) + 32, \
			(sor), \
			(rrb_gr), \
			(newregid) + 32);

#define TRACE_SELF_COPYIN4(rem, len, wp) \
    if (info->trace & UWX_TRACE_COPYIN) \
	printf("copyin (rem = %08x %08x, len = %d, val = %08x)\n", \
			(unsigned int) ((rem) >> 32), \
			(unsigned int) (rem), \
			(len), *(wp));

#define TRACE_SELF_COPYIN8(rem, len, dp) \
    if (info->trace & UWX_TRACE_COPYIN) \
	printf("copyin (rem = %08x %08x, len = %d, val = %08x %08x)\n", \
			(unsigned int) ((rem) >> 32), \
			(unsigned int) (rem), \
			(len), \
			((unsigned int *)(dp))[0], \
			((unsigned int *)(dp))[1]);

#define TRACE_SELF_LOOKUP(ip) \
    if (info->trace & UWX_TRACE_LOOKUPIP) \
	printf("Lookup IP callback: ip = %08x %08x\n", \
			(unsigned int) ((ip) >> 32), \
			(unsigned int) (ip));

#define TRACE_SELF_LOOKUP_DESC(text_base, unwind_base) \
	if (info->trace & UWX_TRACE_LOOKUPIP) { \
	    printf("  text base:    %08x %08x\n", \
			(unsigned int) ((text_base) >> 32), \
			(unsigned int) (text_base)); \
	    printf("  unwind base:  %08x %08x\n", \
			(unsigned int) ((uint64_t)(unwind_base) >> 32), \
			(unsigned int) (unwind_base)); \
	    printf("  unwind flags: %08x %08x\n", \
			(unsigned int) ((unwind_base)[0] >> 32), \
			(unsigned int) (unwind_base)[0]); \
	    printf("  unwind start: %08x %08x\n", \
			(unsigned int) (((text_base)+(unwind_base)[1]) >> 32), \
			(unsigned int) ((text_base)+(unwind_base)[1])); \
	    printf("  unwind end:   %08x %08x\n", \
			(unsigned int) (((text_base)+(unwind_base)[2]) >> 32), \
			(unsigned int) ((text_base)+(unwind_base)[2])); \
	}

#else /* !UWX_TRACE_ENABLE */

#define TRACE_INIT
#define TRACE_B_REUSE(id)
#define TRACE_B_ALLOC(id)
#define TRACE_B_POP(id)
#define TRACE_B_LABEL(label)
#define TRACE_B_LABEL_COPY(id)
#define TRACE_B_LABEL_REVERSE(back, new)
#define TRACE_B_COPY(label, id)
#define TRACE_B_COPY_FREE(id)
#define TRACE_B_COPY_FOUND(id)
#define TRACE_B_COPY_COPY(id)
#define TRACE_B_COPY_REVERSE(back, new)
#define TRACE_B_FREE(id)
#define TRACE_I_DECODE_RHDR_1(name, b0)
#define TRACE_I_DECODE_RHDR_1L(name, b0, val)
#define TRACE_I_DECODE_RHDR_2L(name, b0, b1, val)
#define TRACE_I_DECODE_PROLOGUE_1(name, b0)
#define TRACE_I_DECODE_PROLOGUE_1L(name, b0, val)
#define TRACE_I_DECODE_PROLOGUE_1LL(name, b0, val1, val2)
#define TRACE_I_DECODE_PROLOGUE_2(name, b0, b1)
#define TRACE_I_DECODE_PROLOGUE_2L(name, b0, b1, parm1)
#define TRACE_I_DECODE_PROLOGUE_3(name, b0, b1, b2)
#define TRACE_I_DECODE_PROLOGUE_4(name, b0, b1, b2, b3)
#define TRACE_I_DECODE_PROLOGUE_SPILL_BASE(spill_base)
#define TRACE_I_DECODE_PROLOGUE_MASKS(gr_mem_mask, gr_gr_mask)
#define TRACE_I_DECODE_PROLOGUE_NSPILL(ngr)
#define TRACE_I_DECODE_BODY_1(name, b0)
#define TRACE_I_DECODE_BODY_1L(name, b0, parm1)
#define TRACE_I_DECODE_BODY_1LL(name, b0, parm1, parm2)
#define TRACE_R_UIB(uentry, ulen)
#define TRACE_R_DUMP_SB(scoreboard, rhdr, cur_slot, ip_slot)
#define TRACE_S_STEP(rstate)
#define TRACE_S_RESTORE_REG(regname, rstate, val)
#define TRACE_S_RESTORE_GR(regid, rstate, val)
#define TRACE_S_RESTORE_BR(regid, rstate, val)
#define TRACE_S_RESTORE_FR(regid, rstate, val)
#define TRACE_T_SEARCH32(ip)
#define TRACE_T_BINSEARCH32(lb, ub, mid, code_start, code_end)
#define TRACE_C_GET_REG(regid, bsp)
#define TRACE_C_ROTATE_GR(regid, sor, rrb_gr, newregid)
#define TRACE_SELF_COPYIN4(rem, len, wp)
#define TRACE_SELF_COPYIN8(rem, len, dp)
#define TRACE_SELF_LOOKUP(ip)
#define TRACE_SELF_LOOKUP_DESC(text_base, unwind_base)

#endif /* UWX_TRACE_ENABLE */