1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
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 VMWARE 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 **************************************************************************/
31 #include "i915_debug.h"
32 #include "util/imports.h"
33 #include "main/glheader.h"
35 static const char *opcodes
[0x20] = {
71 static const int args
[0x20] = {
107 static const char *regname
[0x8] = {
119 print_reg_type_nr(GLuint type
, GLuint nr
)
128 printf("T_SPECULAR");
134 printf("T_TEX%d", nr
);
153 printf("%s[%d]", regname
[type
], nr
);
156 #define REG_SWIZZLE_MASK 0x7777
157 #define REG_NEGATE_MASK 0x8888
159 #define REG_SWIZZLE_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) | \
160 (SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) | \
161 (SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) | \
162 (SRC_W << A2_SRC2_CHANNEL_W_SHIFT))
166 print_reg_neg_swizzle(GLuint reg
)
170 if ((reg
& REG_SWIZZLE_MASK
) == REG_SWIZZLE_XYZW
&&
171 (reg
& REG_NEGATE_MASK
) == 0)
176 for (i
= 3; i
>= 0; i
--) {
177 if (reg
& (1 << ((i
* 4) + 3)))
180 switch ((reg
>> (i
* 4)) & 0x7) {
208 print_src_reg(GLuint dword
)
210 GLuint nr
= (dword
>> A2_SRC2_NR_SHIFT
) & REG_NR_MASK
;
211 GLuint type
= (dword
>> A2_SRC2_TYPE_SHIFT
) & REG_TYPE_MASK
;
212 print_reg_type_nr(type
, nr
);
213 print_reg_neg_swizzle(dword
);
218 print_dest_reg(GLuint dword
)
220 GLuint nr
= (dword
>> A0_DEST_NR_SHIFT
) & REG_NR_MASK
;
221 GLuint type
= (dword
>> A0_DEST_TYPE_SHIFT
) & REG_TYPE_MASK
;
222 print_reg_type_nr(type
, nr
);
223 if ((dword
& A0_DEST_CHANNEL_ALL
) == A0_DEST_CHANNEL_ALL
)
226 if (dword
& A0_DEST_CHANNEL_X
)
228 if (dword
& A0_DEST_CHANNEL_Y
)
230 if (dword
& A0_DEST_CHANNEL_Z
)
232 if (dword
& A0_DEST_CHANNEL_W
)
237 #define GET_SRC0_REG(r0, r1) ((r0<<14)|(r1>>A1_SRC0_CHANNEL_W_SHIFT))
238 #define GET_SRC1_REG(r0, r1) ((r0<<8)|(r1>>A2_SRC1_CHANNEL_W_SHIFT))
239 #define GET_SRC2_REG(r) (r)
243 print_arith_op(GLuint opcode
, const GLuint
* program
)
245 if (opcode
!= A0_NOP
) {
246 print_dest_reg(program
[0]);
247 if (program
[0] & A0_DEST_SATURATE
)
248 printf(" = SATURATE ");
253 printf("%s ", opcodes
[opcode
]);
255 print_src_reg(GET_SRC0_REG(program
[0], program
[1]));
256 if (args
[opcode
] == 1) {
262 print_src_reg(GET_SRC1_REG(program
[1], program
[2]));
263 if (args
[opcode
] == 2) {
269 print_src_reg(GET_SRC2_REG(program
[2]));
276 print_tex_op(GLuint opcode
, const GLuint
* program
)
278 print_dest_reg(program
[0] | A0_DEST_CHANNEL_ALL
);
281 printf("%s ", opcodes
[opcode
]);
283 printf("S[%d],", program
[0] & T0_SAMPLER_NR_MASK
);
285 print_reg_type_nr((program
[1] >> T1_ADDRESS_REG_TYPE_SHIFT
) &
287 (program
[1] >> T1_ADDRESS_REG_NR_SHIFT
) & REG_NR_MASK
);
292 print_dcl_op(GLuint opcode
, const GLuint
* program
)
294 printf("%s ", opcodes
[opcode
]);
295 print_dest_reg(program
[0] | A0_DEST_CHANNEL_ALL
);
301 i915_disassemble_program(const GLuint
* program
, GLuint sz
)
305 printf("\t\tBEGIN\n");
307 assert((program
[0] & 0x1ff) + 2 == sz
);
310 for (i
= 1; i
< sz
; i
+= 3, program
+= 3) {
311 GLuint opcode
= program
[0] & (0x1f << 24);
315 if ((GLint
) opcode
>= A0_NOP
&& opcode
<= A0_SLT
)
316 print_arith_op(opcode
>> 24, program
);
317 else if (opcode
>= T0_TEXLD
&& opcode
<= T0_TEXKILL
)
318 print_tex_op(opcode
>> 24, program
);
319 else if (opcode
== D0_DCL
)
320 print_dcl_op(opcode
>> 24, program
);
322 printf("Unknown opcode 0x%x\n", opcode
);
325 printf("\t\tEND\n\n");