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 "util/u_debug.h"
36 struct debug_stream
*stream
,
42 va_start( args
, fmt
);
43 debug_vprintf( fmt
, args
);
48 static const char *opcodes
[0x20] = {
84 static const int args
[0x20] = {
120 static const char *regname
[0x8] = {
132 print_reg_type_nr(struct debug_stream
*stream
, unsigned type
, unsigned nr
)
138 PRINTF(stream
, "T_DIFFUSE");
141 PRINTF(stream
, "T_SPECULAR");
144 PRINTF(stream
, "T_FOG_W");
147 PRINTF(stream
, "T_TEX%d", nr
);
152 PRINTF(stream
, "oC");
158 PRINTF(stream
, "oD");
166 PRINTF(stream
, "%s[%d]", regname
[type
], nr
);
169 #define REG_SWIZZLE_MASK 0x7777
170 #define REG_NEGATE_MASK 0x8888
172 #define REG_SWIZZLE_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) | \
173 (SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) | \
174 (SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) | \
175 (SRC_W << A2_SRC2_CHANNEL_W_SHIFT))
179 print_reg_neg_swizzle(struct debug_stream
*stream
, unsigned reg
)
183 if ((reg
& REG_SWIZZLE_MASK
) == REG_SWIZZLE_XYZW
&&
184 (reg
& REG_NEGATE_MASK
) == 0)
189 for (i
= 3; i
>= 0; i
--) {
190 if (reg
& (1 << ((i
* 4) + 3)))
193 switch ((reg
>> (i
* 4)) & 0x7) {
221 print_src_reg(struct debug_stream
*stream
, unsigned dword
)
223 unsigned nr
= (dword
>> A2_SRC2_NR_SHIFT
) & REG_NR_MASK
;
224 unsigned type
= (dword
>> A2_SRC2_TYPE_SHIFT
) & REG_TYPE_MASK
;
225 print_reg_type_nr(stream
, type
, nr
);
226 print_reg_neg_swizzle(stream
, dword
);
231 print_dest_reg(struct debug_stream
*stream
, unsigned dword
)
233 unsigned nr
= (dword
>> A0_DEST_NR_SHIFT
) & REG_NR_MASK
;
234 unsigned type
= (dword
>> A0_DEST_TYPE_SHIFT
) & REG_TYPE_MASK
;
235 print_reg_type_nr(stream
, type
, nr
);
236 if ((dword
& A0_DEST_CHANNEL_ALL
) == A0_DEST_CHANNEL_ALL
)
239 if (dword
& A0_DEST_CHANNEL_X
)
241 if (dword
& A0_DEST_CHANNEL_Y
)
243 if (dword
& A0_DEST_CHANNEL_Z
)
245 if (dword
& A0_DEST_CHANNEL_W
)
250 #define GET_SRC0_REG(r0, r1) ((r0<<14)|(r1>>A1_SRC0_CHANNEL_W_SHIFT))
251 #define GET_SRC1_REG(r0, r1) ((r0<<8)|(r1>>A2_SRC1_CHANNEL_W_SHIFT))
252 #define GET_SRC2_REG(r) (r)
256 print_arith_op(struct debug_stream
*stream
,
257 unsigned opcode
, const unsigned * program
)
259 if (opcode
!= A0_NOP
) {
260 print_dest_reg(stream
, program
[0]);
261 if (program
[0] & A0_DEST_SATURATE
)
262 PRINTF(stream
, " = SATURATE ");
264 PRINTF(stream
, " = ");
267 PRINTF(stream
, "%s ", opcodes
[opcode
]);
269 print_src_reg(stream
, GET_SRC0_REG(program
[0], program
[1]));
270 if (args
[opcode
] == 1) {
271 PRINTF(stream
, "\n");
275 PRINTF(stream
, ", ");
276 print_src_reg(stream
, GET_SRC1_REG(program
[1], program
[2]));
277 if (args
[opcode
] == 2) {
278 PRINTF(stream
, "\n");
282 PRINTF(stream
, ", ");
283 print_src_reg(stream
, GET_SRC2_REG(program
[2]));
284 PRINTF(stream
, "\n");
290 print_tex_op(struct debug_stream
*stream
,
291 unsigned opcode
, const unsigned * program
)
293 print_dest_reg(stream
, program
[0] | A0_DEST_CHANNEL_ALL
);
294 PRINTF(stream
, " = ");
296 PRINTF(stream
, "%s ", opcodes
[opcode
]);
298 PRINTF(stream
, "S[%d],", program
[0] & T0_SAMPLER_NR_MASK
);
300 print_reg_type_nr(stream
,
301 (program
[1] >> T1_ADDRESS_REG_TYPE_SHIFT
) &
303 (program
[1] >> T1_ADDRESS_REG_NR_SHIFT
) & REG_NR_MASK
);
304 PRINTF(stream
, "\n");
308 print_texkil_op(struct debug_stream
*stream
,
309 unsigned opcode
, const unsigned * program
)
311 PRINTF(stream
, "TEXKIL ");
313 print_reg_type_nr(stream
,
314 (program
[1] >> T1_ADDRESS_REG_TYPE_SHIFT
) &
316 (program
[1] >> T1_ADDRESS_REG_NR_SHIFT
) & REG_NR_MASK
);
317 PRINTF(stream
, "\n");
321 print_dcl_op(struct debug_stream
*stream
,
322 unsigned opcode
, const unsigned * program
)
324 PRINTF(stream
, "%s ", opcodes
[opcode
]);
325 print_dest_reg(stream
,
326 program
[0] | A0_DEST_CHANNEL_ALL
);
327 PRINTF(stream
, "\n");
332 i915_disassemble_program(struct debug_stream
*stream
,
333 const unsigned * program
, unsigned sz
)
337 PRINTF(stream
, "\t\tBEGIN\n");
339 assert((program
[0] & 0x1ff) + 2 == sz
);
342 for (i
= 1; i
< sz
; i
+= 3, program
+= 3) {
343 unsigned opcode
= program
[0] & (0x1f << 24);
345 PRINTF(stream
, "\t\t");
347 if ((int) opcode
>= A0_NOP
&& opcode
<= A0_SLT
)
348 print_arith_op(stream
, opcode
>> 24, program
);
349 else if (opcode
>= T0_TEXLD
&& opcode
< T0_TEXKILL
)
350 print_tex_op(stream
, opcode
>> 24, program
);
351 else if (opcode
== T0_TEXKILL
)
352 print_texkil_op(stream
, opcode
>> 24, program
);
353 else if (opcode
== D0_DCL
)
354 print_dcl_op(stream
, opcode
>> 24, program
);
356 PRINTF(stream
, "Unknown opcode 0x%x\n", opcode
);
359 PRINTF(stream
, "\t\tEND\n\n");