1c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell/**************************************************************************
2c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell *
3c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * All Rights Reserved.
5c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell *
6c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
7c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * copy of this software and associated documentation files (the
8c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * "Software"), to deal in the Software without restriction, including
9c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * without limitation the rights to use, copy, modify, merge, publish,
10c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * distribute, sub license, and/or sell copies of the Software, and to
11c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * permit persons to whom the Software is furnished to do so, subject to
12c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * the following conditions:
13c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell *
14c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * The above copyright notice and this permission notice (including the
15c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * next paragraph) shall be included in all copies or substantial portions
16c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * of the Software.
17c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell *
18c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell *
26c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell **************************************************************************/
27c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
28c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
29c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#include "i915_reg.h"
30c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#include "i915_debug.h"
31abbb1bde06990cb15c82ebcdb9ac07b00cb0ab4fJakob Bornecrantz#include "i915_debug_private.h"
32f6cecbb36164b060e194709938f4376a49795b93José Fonseca#include "util/u_debug.h"
3340a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell
34c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
350e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michalstatic void
360e31e24659a1e691bdfa213fcd073bbfaa4ed6e9MichalPRINTF(
370e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   struct debug_stream  *stream,
380e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   const char           *fmt,
390e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal                        ... )
400e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal{
410e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   va_list  args;
42cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell
430e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   va_start( args, fmt );
44baab98a637d526871fb77ec6f313012f49c0e998José Fonseca   debug_vprintf( fmt, args );
450e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   va_end( args );
460e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal}
47cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell
48cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell
49c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic const char *opcodes[0x20] = {
50c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "NOP",
51c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "ADD",
52c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "MOV",
53c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "MUL",
54c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "MAD",
55c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "DP2ADD",
56c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "DP3",
57c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "DP4",
58c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "FRC",
59c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "RCP",
60c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "RSQ",
61c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "EXP",
62c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "LOG",
63c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "CMP",
64c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "MIN",
65c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "MAX",
66c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "FLR",
67c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "MOD",
68c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "TRC",
69c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "SGE",
70c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "SLT",
71c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "TEXLD",
72c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "TEXLDP",
73c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "TEXLDB",
74c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "TEXKILL",
75c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "DCL",
76c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "0x1a",
77c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "0x1b",
78c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "0x1c",
79c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "0x1d",
80c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "0x1e",
81c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "0x1f",
82c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell};
83c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
84c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
85c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic const int args[0x20] = {
86c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,                           /* 0 nop */
87c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* 1 add */
88c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* 2 mov */
89c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* 3 m ul */
90c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   3,                           /* 4 mad */
91c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   3,                           /* 5 dp2add */
92c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* 6 dp3 */
93c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* 7 dp4 */
94c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* 8 frc */
95c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* 9 rcp */
96c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* a rsq */
97c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* b exp */
98c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* c log */
99c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   3,                           /* d cmp */
100c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* e min */
101c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* f max */
102c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* 10 flr */
103c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* 11 mod */
104c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,                           /* 12 trc */
105c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* 13 sge */
106c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   2,                           /* 14 slt */
107c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,
108c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,
109c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,
110c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   1,
111c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
112c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
113c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
114c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
115c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
116c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
117c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   0,
118c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell};
119c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
120c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
121c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic const char *regname[0x8] = {
122c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "R",
123c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "T",
124c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "CONST",
125c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "S",
126c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "OC",
127c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "OD",
128c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "U",
129c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   "UNKNOWN",
130c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell};
131c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
132c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
13340a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwellprint_reg_type_nr(struct debug_stream *stream, unsigned type, unsigned nr)
134c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
135c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   switch (type) {
136c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   case REG_TYPE_T:
137c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      switch (nr) {
138c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case T_DIFFUSE:
1390e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "T_DIFFUSE");
140c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         return;
141c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case T_SPECULAR:
1420e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "T_SPECULAR");
143c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         return;
144c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case T_FOG_W:
1450e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "T_FOG_W");
146c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         return;
147c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      default:
1480e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "T_TEX%d", nr);
149c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         return;
150c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      }
151c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   case REG_TYPE_OC:
152c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      if (nr == 0) {
1530e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "oC");
154c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         return;
155c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      }
156c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      break;
157c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   case REG_TYPE_OD:
158c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      if (nr == 0) {
1590e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "oD");
160c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         return;
161c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      }
162c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      break;
163c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   default:
164c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      break;
165c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   }
166c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
1670e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, "%s[%d]", regname[type], nr);
168c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
169c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
170c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#define REG_SWIZZLE_MASK 0x7777
171c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#define REG_NEGATE_MASK 0x8888
172c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
173c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#define REG_SWIZZLE_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) |	\
174c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell		      (SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) |	\
175c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell		      (SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) |	\
176c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell		      (SRC_W << A2_SRC2_CHANNEL_W_SHIFT))
177c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
178c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
179c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
18040a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwellprint_reg_neg_swizzle(struct debug_stream *stream, unsigned reg)
181c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
182c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   int i;
183c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
184c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if ((reg & REG_SWIZZLE_MASK) == REG_SWIZZLE_XYZW &&
185c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell       (reg & REG_NEGATE_MASK) == 0)
186c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      return;
187c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
1880e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, ".");
189c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
190c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   for (i = 3; i >= 0; i--) {
191c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      if (reg & (1 << ((i * 4) + 3)))
1920e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "-");
193c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
194c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      switch ((reg >> (i * 4)) & 0x7) {
195c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case 0:
1960e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "x");
197c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
198c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case 1:
1990e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "y");
200c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
201c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case 2:
2020e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "z");
203c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
204c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case 3:
2050e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "w");
206c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
207c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case 4:
2080e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "0");
209c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
210c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      case 5:
2110e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "1");
212c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
213c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      default:
2140e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "?");
215c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell         break;
216c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      }
217c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   }
218c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
219c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
220c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
221c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
22240a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwellprint_src_reg(struct debug_stream *stream, unsigned dword)
223c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
22440a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell   unsigned nr = (dword >> A2_SRC2_NR_SHIFT) & REG_NR_MASK;
22540a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell   unsigned type = (dword >> A2_SRC2_TYPE_SHIFT) & REG_TYPE_MASK;
226cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_reg_type_nr(stream, type, nr);
227cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_reg_neg_swizzle(stream, dword);
228c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
229c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
230c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
231c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
23240a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwellprint_dest_reg(struct debug_stream *stream, unsigned dword)
233c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
23440a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell   unsigned nr = (dword >> A0_DEST_NR_SHIFT) & REG_NR_MASK;
23540a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell   unsigned type = (dword >> A0_DEST_TYPE_SHIFT) & REG_TYPE_MASK;
236cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_reg_type_nr(stream, type, nr);
237c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if ((dword & A0_DEST_CHANNEL_ALL) == A0_DEST_CHANNEL_ALL)
238c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      return;
2390e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, ".");
240c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (dword & A0_DEST_CHANNEL_X)
2410e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal      PRINTF(stream, "x");
242c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (dword & A0_DEST_CHANNEL_Y)
2430e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal      PRINTF(stream, "y");
244c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (dword & A0_DEST_CHANNEL_Z)
2450e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal      PRINTF(stream, "z");
246c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (dword & A0_DEST_CHANNEL_W)
2470e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal      PRINTF(stream, "w");
248c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
249c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
250c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
251c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#define GET_SRC0_REG(r0, r1) ((r0<<14)|(r1>>A1_SRC0_CHANNEL_W_SHIFT))
252c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#define GET_SRC1_REG(r0, r1) ((r0<<8)|(r1>>A2_SRC1_CHANNEL_W_SHIFT))
253c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell#define GET_SRC2_REG(r)      (r)
254c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
255c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
256c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
257cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwellprint_arith_op(struct debug_stream *stream,
25840a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell	       unsigned opcode, const unsigned * program)
259c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
260c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (opcode != A0_NOP) {
261cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell      print_dest_reg(stream, program[0]);
262c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      if (program[0] & A0_DEST_SATURATE)
2630e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, " = SATURATE ");
264c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      else
2650e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, " = ");
266c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   }
267c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
2680e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, "%s ", opcodes[opcode]);
269c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
270cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_src_reg(stream, GET_SRC0_REG(program[0], program[1]));
271c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (args[opcode] == 1) {
2720e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal      PRINTF(stream, "\n");
273c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      return;
274c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   }
275c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
2760e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, ", ");
277cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_src_reg(stream, GET_SRC1_REG(program[1], program[2]));
278c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   if (args[opcode] == 2) {
2790e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal      PRINTF(stream, "\n");
280c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      return;
281c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   }
282c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
2830e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, ", ");
284cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_src_reg(stream, GET_SRC2_REG(program[2]));
2850e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, "\n");
286c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   return;
287c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
288c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
289c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
290c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
291cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwellprint_tex_op(struct debug_stream *stream,
29240a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell	     unsigned opcode, const unsigned * program)
293c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
294cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_dest_reg(stream, program[0] | A0_DEST_CHANNEL_ALL);
2950e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, " = ");
296c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
2970e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, "%s ", opcodes[opcode]);
298c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
2990e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, "S[%d],", program[0] & T0_SAMPLER_NR_MASK);
300c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
301cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_reg_type_nr(stream,
302cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell		     (program[1] >> T1_ADDRESS_REG_TYPE_SHIFT) &
303c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell                     REG_TYPE_MASK,
304c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell                     (program[1] >> T1_ADDRESS_REG_NR_SHIFT) & REG_NR_MASK);
3050e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, "\n");
306c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
307c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
308c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellstatic void
30929db69e222b04b5a616942b06bd118c9ac75ec41Brianprint_texkil_op(struct debug_stream *stream,
31029db69e222b04b5a616942b06bd118c9ac75ec41Brian                unsigned opcode, const unsigned * program)
31129db69e222b04b5a616942b06bd118c9ac75ec41Brian{
3120e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, "TEXKIL ");
31329db69e222b04b5a616942b06bd118c9ac75ec41Brian
31429db69e222b04b5a616942b06bd118c9ac75ec41Brian   print_reg_type_nr(stream,
31529db69e222b04b5a616942b06bd118c9ac75ec41Brian		     (program[1] >> T1_ADDRESS_REG_TYPE_SHIFT) &
31629db69e222b04b5a616942b06bd118c9ac75ec41Brian                     REG_TYPE_MASK,
31729db69e222b04b5a616942b06bd118c9ac75ec41Brian                     (program[1] >> T1_ADDRESS_REG_NR_SHIFT) & REG_NR_MASK);
3180e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, "\n");
31929db69e222b04b5a616942b06bd118c9ac75ec41Brian}
32029db69e222b04b5a616942b06bd118c9ac75ec41Brian
32129db69e222b04b5a616942b06bd118c9ac75ec41Brianstatic void
322cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwellprint_dcl_op(struct debug_stream *stream,
32340a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell	     unsigned opcode, const unsigned * program)
324c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
3250e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, "%s ", opcodes[opcode]);
326cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell   print_dest_reg(stream,
327cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell		  program[0] | A0_DEST_CHANNEL_ALL);
3280e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, "\n");
329c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
330c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
331c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
332c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwellvoid
333cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwelli915_disassemble_program(struct debug_stream *stream,
33440a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell			 const unsigned * program, unsigned sz)
335c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell{
3365961732c1b59403b4e736fa354a64d4a0e5d8af2Michal   unsigned i;
337c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
3380e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, "\t\tBEGIN\n");
339c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
34026bcef898af4e6dfd578783ed33818a2bd38b06dKeith Whitwell   assert((program[0] & 0x1ff) + 2 == sz);
341c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
342c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   program++;
343c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   for (i = 1; i < sz; i += 3, program += 3) {
34440a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell      unsigned opcode = program[0] & (0x1f << 24);
345c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
3460e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal      PRINTF(stream, "\t\t");
347c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
34840a86b20478024ca7c55400019c536cb5ff631d1Keith Whitwell      if ((int) opcode >= A0_NOP && opcode <= A0_SLT)
349cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell         print_arith_op(stream, opcode >> 24, program);
35029db69e222b04b5a616942b06bd118c9ac75ec41Brian      else if (opcode >= T0_TEXLD && opcode < T0_TEXKILL)
351cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell         print_tex_op(stream, opcode >> 24, program);
35229db69e222b04b5a616942b06bd118c9ac75ec41Brian      else if (opcode == T0_TEXKILL)
35329db69e222b04b5a616942b06bd118c9ac75ec41Brian         print_texkil_op(stream, opcode >> 24, program);
354c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      else if (opcode == D0_DCL)
355cb2d95ba68affe665619cc0ec7b74fd0aaae7fc2Keith Whitwell         print_dcl_op(stream, opcode >> 24, program);
356c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell      else
3570e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal         PRINTF(stream, "Unknown opcode 0x%x\n", opcode);
358c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell   }
359c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
3600e31e24659a1e691bdfa213fcd073bbfaa4ed6e9Michal   PRINTF(stream, "\t\tEND\n\n");
361c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell}
362c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
363c046174eb047c95e25f31390019f04f310ae2b8eKeith Whitwell
364