1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 #include "i915_debug.h"
31 #include "i915_debug_private.h"
32 #include "util/u_debug.h"
37 struct debug_stream
*stream
,
43 va_start( args
, fmt
);
44 debug_vprintf( fmt
, args
);
49 static const char *opcodes
[0x20] = {
85 static const int args
[0x20] = {
121 static const char *regname
[0x8] = {
133 print_reg_type_nr(struct debug_stream
*stream
, unsigned type
, unsigned nr
)
139 PRINTF(stream
, "T_DIFFUSE");
142 PRINTF(stream
, "T_SPECULAR");
145 PRINTF(stream
, "T_FOG_W");
148 PRINTF(stream
, "T_TEX%d", nr
);
153 PRINTF(stream
, "oC");
159 PRINTF(stream
, "oD");
167 PRINTF(stream
, "%s[%d]", regname
[type
], nr
);
170 #define REG_SWIZZLE_MASK 0x7777
171 #define REG_NEGATE_MASK 0x8888
173 #define REG_SWIZZLE_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) | \
174 (SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) | \
175 (SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) | \
176 (SRC_W << A2_SRC2_CHANNEL_W_SHIFT))
180 print_reg_neg_swizzle(struct debug_stream
*stream
, unsigned reg
)
184 if ((reg
& REG_SWIZZLE_MASK
) == REG_SWIZZLE_XYZW
&&
185 (reg
& REG_NEGATE_MASK
) == 0)
190 for (i
= 3; i
>= 0; i
--) {
191 if (reg
& (1 << ((i
* 4) + 3)))
194 switch ((reg
>> (i
* 4)) & 0x7) {
222 print_src_reg(struct debug_stream
*stream
, unsigned dword
)
224 unsigned nr
= (dword
>> A2_SRC2_NR_SHIFT
) & REG_NR_MASK
;
225 unsigned type
= (dword
>> A2_SRC2_TYPE_SHIFT
) & REG_TYPE_MASK
;
226 print_reg_type_nr(stream
, type
, nr
);
227 print_reg_neg_swizzle(stream
, dword
);
232 print_dest_reg(struct debug_stream
*stream
, unsigned dword
)
234 unsigned nr
= (dword
>> A0_DEST_NR_SHIFT
) & REG_NR_MASK
;
235 unsigned type
= (dword
>> A0_DEST_TYPE_SHIFT
) & REG_TYPE_MASK
;
236 print_reg_type_nr(stream
, type
, nr
);
237 if ((dword
& A0_DEST_CHANNEL_ALL
) == A0_DEST_CHANNEL_ALL
)
240 if (dword
& A0_DEST_CHANNEL_X
)
242 if (dword
& A0_DEST_CHANNEL_Y
)
244 if (dword
& A0_DEST_CHANNEL_Z
)
246 if (dword
& A0_DEST_CHANNEL_W
)
251 #define GET_SRC0_REG(r0, r1) ((r0<<14)|(r1>>A1_SRC0_CHANNEL_W_SHIFT))
252 #define GET_SRC1_REG(r0, r1) ((r0<<8)|(r1>>A2_SRC1_CHANNEL_W_SHIFT))
253 #define GET_SRC2_REG(r) (r)
257 print_arith_op(struct debug_stream
*stream
,
258 unsigned opcode
, const unsigned * program
)
260 if (opcode
!= A0_NOP
) {
261 print_dest_reg(stream
, program
[0]);
262 if (program
[0] & A0_DEST_SATURATE
)
263 PRINTF(stream
, " = SATURATE ");
265 PRINTF(stream
, " = ");
268 PRINTF(stream
, "%s ", opcodes
[opcode
]);
270 print_src_reg(stream
, GET_SRC0_REG(program
[0], program
[1]));
271 if (args
[opcode
] == 1) {
272 PRINTF(stream
, "\n");
276 PRINTF(stream
, ", ");
277 print_src_reg(stream
, GET_SRC1_REG(program
[1], program
[2]));
278 if (args
[opcode
] == 2) {
279 PRINTF(stream
, "\n");
283 PRINTF(stream
, ", ");
284 print_src_reg(stream
, GET_SRC2_REG(program
[2]));
285 PRINTF(stream
, "\n");
291 print_tex_op(struct debug_stream
*stream
,
292 unsigned opcode
, const unsigned * program
)
294 print_dest_reg(stream
, program
[0] | A0_DEST_CHANNEL_ALL
);
295 PRINTF(stream
, " = ");
297 PRINTF(stream
, "%s ", opcodes
[opcode
]);
299 PRINTF(stream
, "S[%d],", program
[0] & T0_SAMPLER_NR_MASK
);
301 print_reg_type_nr(stream
,
302 (program
[1] >> T1_ADDRESS_REG_TYPE_SHIFT
) &
304 (program
[1] >> T1_ADDRESS_REG_NR_SHIFT
) & REG_NR_MASK
);
305 PRINTF(stream
, "\n");
309 print_texkil_op(struct debug_stream
*stream
,
310 unsigned opcode
, const unsigned * program
)
312 PRINTF(stream
, "TEXKIL ");
314 print_reg_type_nr(stream
,
315 (program
[1] >> T1_ADDRESS_REG_TYPE_SHIFT
) &
317 (program
[1] >> T1_ADDRESS_REG_NR_SHIFT
) & REG_NR_MASK
);
318 PRINTF(stream
, "\n");
322 print_dcl_op(struct debug_stream
*stream
,
323 unsigned opcode
, const unsigned * program
)
325 PRINTF(stream
, "%s ", opcodes
[opcode
]);
326 print_dest_reg(stream
,
327 program
[0] | A0_DEST_CHANNEL_ALL
);
328 PRINTF(stream
, "\n");
333 i915_disassemble_program(struct debug_stream
*stream
,
334 const unsigned * program
, unsigned sz
)
338 PRINTF(stream
, "\t\tBEGIN\n");
340 assert((program
[0] & 0x1ff) + 2 == sz
);
343 for (i
= 1; i
< sz
; i
+= 3, program
+= 3) {
344 unsigned opcode
= program
[0] & (0x1f << 24);
346 PRINTF(stream
, "\t\t");
348 if ((int) opcode
>= A0_NOP
&& opcode
<= A0_SLT
)
349 print_arith_op(stream
, opcode
>> 24, program
);
350 else if (opcode
>= T0_TEXLD
&& opcode
< T0_TEXKILL
)
351 print_tex_op(stream
, opcode
>> 24, program
);
352 else if (opcode
== T0_TEXKILL
)
353 print_texkil_op(stream
, opcode
>> 24, program
);
354 else if (opcode
== D0_DCL
)
355 print_dcl_op(stream
, opcode
>> 24, program
);
357 PRINTF(stream
, "Unknown opcode 0x%x\n", opcode
);
360 PRINTF(stream
, "\t\tEND\n\n");