1 /* Print IBM RS/6000 instructions for GNU software.
2 Copyright 1991 Free Software Foundation, Inc.
3 Contributed by IBM Corporation.
5 This file is part of GDB and the GNU binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 #include "rs6k-opcode.h"
24 /* Print the rs6k instruction at address MEMADDR in debugged memory,
25 on STREAM. Returns length of the instruction, in bytes. */
28 print_insn (memaddr, stream)
32 int pop, eop; /* primary and extended opcodes */
34 int best = -1; /* found best opcode index */
36 unsigned int the_insn;
38 read_memory (memaddr, &the_insn, sizeof (the_insn));
39 pop = (unsigned)(the_insn >> 26);
40 eop = ((the_insn) >> 1) & 0x3ff;
41 min = 0, max = NOPCODES-1;
44 best = (min + max) / 2;
46 /* see if we are running in loops */
51 if (pop < rs6k_ops [best].p_opcode)
54 else if (pop > rs6k_ops [best].p_opcode)
58 /* opcode matched, check extended opcode. */
60 if (rs6k_ops [best].e_opcode == -1) {
61 /* there is no valid extended opcode, what we've got is
66 else if (eop < rs6k_ops [best].e_opcode) {
68 while (pop == rs6k_ops [best].p_opcode) {
69 if (eop == rs6k_ops [best].e_opcode) /* found it! */
76 else if (eop > rs6k_ops [best].e_opcode) {
78 while (pop == rs6k_ops [best].p_opcode) {
79 if (eop == rs6k_ops [best].e_opcode) /* found it! */
86 else /* eop == rs6k_ops [best].e_opcode */
92 if (pop == rs6k_ops [best].p_opcode &&
93 (rs6k_ops [best].e_opcode == -1 || rs6k_ops [best].e_opcode == eop))
101 print_operator (stream, memaddr, the_insn, best);
105 fprintf (stream, "0x%08x", the_insn);
111 /* condition code names */
112 static char *cond_code [] = {
113 "lt", "gt", "eq", "so", "ge", "le", "ne", "ns", "nl", "ng", "z", "nz" };
116 print_operator (stream, memaddr, insn_word, insn_no)
124 char *pp = rs6k_ops[insn_no].opr_ext;
126 int nocomma = 0; /* true if no comma needed */
144 if ((insn_word & 0x03e00000) == 0x01800000)
149 if ((insn_word & 0x03e00000) == 0x00800000)
159 if (insn_word & 0x4000)
163 case '1': /* exception #1 for bb/bc ambiguity */
164 tmp = (insn_word >> 21) & 0x1f; /* extract BO */
165 if (tmp != 0xc && tmp != 0x4) {
166 /* you can't use `bb' now. switch to `bc' */
169 pp = rs6k_ops[insn_no].opr_ext;
181 /* tab between operator and operand */
184 /* parse the operand now. */
185 pp = rs6k_ops[insn_no].oprnd_format;
190 sprintf (qq, "%d", (insn_word >> 21) & 0x1f);
195 sprintf (qq, "r%d", (insn_word >> 21) & 0x1f);
199 tmp = (insn_word >> 16) & 0x1f;
201 fprintf (stderr, "Internal error: unknown cond code: 0x%x\n", insn_word);
204 sprintf (qq, "%s", cond_code [tmp]);
209 tmp = (insn_word & 0xfffc);
210 if (tmp & 0x8000) /* fix sign extension */
213 if ((insn_word & 0x2) == 0) /* if AA not set */
216 sprintf (qq, "0x%x", tmp);
220 tmp = insn_word & 0x03fffffc;
224 if ((insn_word & 0x2) == 0) /* if no AA bit set */
227 sprintf (qq, "0x%x", tmp);
230 case LEV : /* for svc only */
231 if (insn_word & 0x2) { /* SA is set */
236 sprintf (qq, "%d", (insn_word >> 5) & 0x7f);
239 case FL1 : /* for svc only */
240 if (insn_word & 0x2) { /* SA is set */
245 sprintf (qq, "%d", (insn_word >> 12) & 0xf);
248 case FL2 : /* for svc only */
250 if (insn_word & 0x2) /* SA is set */
251 sprintf (qq, "%d", (insn_word >> 2) & 0x3fff);
253 sprintf (qq, "%d", (insn_word >> 2) & 0x7);
258 sprintf (qq, "r%d)", (insn_word >> 16) & 0x1f);
262 sprintf (qq, "r%d", (insn_word >> 16) & 0x1f);
266 sprintf (qq, "r%d", (insn_word >> 11) & 0x1f);
270 tmp = insn_word & 0xffff;
273 sprintf (qq, "%d", tmp);
277 sprintf (qq, "%d", insn_word & 0xffff);
281 sprintf (qq, "%d", (insn_word >> 23) & 0x7);
285 sprintf (qq, "%d", (insn_word >> 18) & 0x7);
289 sprintf (qq, "%d", (insn_word >> 21) & 0x1f);
293 sprintf (qq, "%d", (insn_word >> 16) & 0x1f);
297 sprintf (qq, "%d", (insn_word >> 11) & 0x1f);
301 sprintf (qq, "%d", (insn_word >> 21) & 0x1f);
305 sprintf (qq, "%d", (insn_word >> 16) & 0x1f);
309 sprintf (qq, "%d", (insn_word >> 11) & 0x1f);
313 sprintf (qq, "0x%x", (insn_word >> 6) & 0x1f);
317 sprintf (qq, "0x%x", (insn_word >> 1) & 0x1f);
321 sprintf (qq, "%d", (insn_word >> 16) & 0x1f);
326 tmp = insn_word & 0xffff;
329 sprintf (qq, "%d(", tmp);
333 sprintf (qq, "0x%x", (insn_word >> 12) & 0xff);
338 sprintf (qq, "f%d", (insn_word >> 21) & 0x1f);
342 sprintf (qq, "f%d", (insn_word >> 16) & 0x1f);
346 sprintf (qq, "f%d", (insn_word >> 11) & 0x1f);
350 sprintf (qq, "f%d", (insn_word >> 6) & 0x1f);
354 sprintf (qq, "0x%x", (insn_word >> 17) & 0xff);
358 sprintf (qq, "%d", (insn_word >> 11) & 0x1f);
362 sprintf (qq, "%d", (insn_word >> 12) & 0xf);
366 sprintf (qq, "Unknown operand format identifier %d????", *pp);
369 while (*qq) ++qq; /* Walk to end of string printed so far. */
379 fprintf (stream, "0x%08x\t%s%s",
380 insn_word, rs6k_ops[insn_no].operator, buf);