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
**************************************************************************/
29
#include "i915_context.h"
33
static const char *opcodes[0x20] = {
69
static const int args[0x20] = {
105
static const char *regname[0x8] = {
117
print_reg_type_nr(GLuint type, GLuint nr)
123
fprintf(stderr, "T_DIFFUSE");
126
fprintf(stderr, "T_SPECULAR");
129
fprintf(stderr, "T_FOG_W");
132
fprintf(stderr, "T_TEX%d", nr);
137
fprintf(stderr, "oC");
143
fprintf(stderr, "oD");
151
fprintf(stderr, "%s[%d]", regname[type], nr);
154
#define REG_SWIZZLE_MASK 0x7777
155
#define REG_NEGATE_MASK 0x8888
157
#define REG_SWIZZLE_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) | \
158
(SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) | \
159
(SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) | \
160
(SRC_W << A2_SRC2_CHANNEL_W_SHIFT))
164
print_reg_neg_swizzle(GLuint reg)
168
if ((reg & REG_SWIZZLE_MASK) == REG_SWIZZLE_XYZW &&
169
(reg & REG_NEGATE_MASK) == 0)
172
fprintf(stderr, ".");
174
for (i = 3; i >= 0; i--) {
175
if (reg & (1 << ((i * 4) + 3)))
176
fprintf(stderr, "-");
178
switch ((reg >> (i * 4)) & 0x7) {
180
fprintf(stderr, "x");
183
fprintf(stderr, "y");
186
fprintf(stderr, "z");
189
fprintf(stderr, "w");
192
fprintf(stderr, "0");
195
fprintf(stderr, "1");
198
fprintf(stderr, "?");
206
print_src_reg(GLuint dword)
208
GLuint nr = (dword >> A2_SRC2_NR_SHIFT) & REG_NR_MASK;
209
GLuint type = (dword >> A2_SRC2_TYPE_SHIFT) & REG_TYPE_MASK;
210
print_reg_type_nr(type, nr);
211
print_reg_neg_swizzle(dword);
215
i915_print_ureg(const char *msg, GLuint ureg)
217
fprintf(stderr, "%s: ", msg);
218
print_src_reg(ureg >> 8);
219
fprintf(stderr, "\n");
223
print_dest_reg(GLuint dword)
225
GLuint nr = (dword >> A0_DEST_NR_SHIFT) & REG_NR_MASK;
226
GLuint type = (dword >> A0_DEST_TYPE_SHIFT) & REG_TYPE_MASK;
227
print_reg_type_nr(type, nr);
228
if ((dword & A0_DEST_CHANNEL_ALL) == A0_DEST_CHANNEL_ALL)
230
fprintf(stderr, ".");
231
if (dword & A0_DEST_CHANNEL_X)
232
fprintf(stderr, "x");
233
if (dword & A0_DEST_CHANNEL_Y)
234
fprintf(stderr, "y");
235
if (dword & A0_DEST_CHANNEL_Z)
236
fprintf(stderr, "z");
237
if (dword & A0_DEST_CHANNEL_W)
238
fprintf(stderr, "w");
242
#define GET_SRC0_REG(r0, r1) ((r0<<14)|(r1>>A1_SRC0_CHANNEL_W_SHIFT))
243
#define GET_SRC1_REG(r0, r1) ((r0<<8)|(r1>>A2_SRC1_CHANNEL_W_SHIFT))
244
#define GET_SRC2_REG(r) (r)
248
print_arith_op(GLuint opcode, const GLuint * program)
250
if (opcode != A0_NOP) {
251
print_dest_reg(program[0]);
252
if (program[0] & A0_DEST_SATURATE)
253
fprintf(stderr, " = SATURATE ");
255
fprintf(stderr, " = ");
258
fprintf(stderr, "%s ", opcodes[opcode]);
260
print_src_reg(GET_SRC0_REG(program[0], program[1]));
261
if (args[opcode] == 1) {
262
fprintf(stderr, "\n");
266
fprintf(stderr, ", ");
267
print_src_reg(GET_SRC1_REG(program[1], program[2]));
268
if (args[opcode] == 2) {
269
fprintf(stderr, "\n");
273
fprintf(stderr, ", ");
274
print_src_reg(GET_SRC2_REG(program[2]));
275
fprintf(stderr, "\n");
281
print_tex_op(GLuint opcode, const GLuint * program)
283
print_dest_reg(program[0] | A0_DEST_CHANNEL_ALL);
284
fprintf(stderr, " = ");
286
fprintf(stderr, "%s ", opcodes[opcode]);
288
fprintf(stderr, "S[%d],", program[0] & T0_SAMPLER_NR_MASK);
290
print_reg_type_nr((program[1] >> T1_ADDRESS_REG_TYPE_SHIFT) &
292
(program[1] >> T1_ADDRESS_REG_NR_SHIFT) & REG_NR_MASK);
293
fprintf(stderr, "\n");
297
print_dcl_op(GLuint opcode, const GLuint * program)
299
fprintf(stderr, "%s ", opcodes[opcode]);
300
print_dest_reg(program[0] | A0_DEST_CHANNEL_ALL);
301
fprintf(stderr, "\n");
306
i915_disassemble_program(const GLuint * program, GLuint sz)
308
GLuint size = program[0] & 0x1ff;
311
fprintf(stderr, "BEGIN\n");
313
if (size + 2 != sz) {
314
fprintf(stderr, "%s: program size mismatch %d/%d\n", __FUNCTION__,
320
for (i = 1; i < sz; i += 3, program += 3) {
321
GLuint opcode = program[0] & (0x1f << 24);
323
if ((GLint) opcode >= A0_NOP && opcode <= A0_SLT)
324
print_arith_op(opcode >> 24, program);
325
else if (opcode >= T0_TEXLD && opcode <= T0_TEXKILL)
326
print_tex_op(opcode >> 24, program);
327
else if (opcode == D0_DCL)
328
print_dcl_op(opcode >> 24, program);
330
fprintf(stderr, "Unknown opcode 0x%x\n", opcode);
333
fprintf(stderr, "END\n\n");