1 /* Instruction printing code for the ARC.
2 Copyright (C) 1994 Free Software Foundation, Inc.
3 Contributed by Doug Evans (dje@cygnus.com).
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 #include "opcode/arc.h"
22 /* Print one instruction from PC on INFO->STREAM.
23 Return the size of the instruction (4 or 8 for the ARC). */
26 print_insn_arc (pc
, info
)
28 struct disassemble_info
*info
;
30 const struct arc_opcode
*opcode
,*opcode_end
;
32 void *stream
= info
->stream
;
33 fprintf_ftype func
= info
->fprintf_func
;
35 /* First element is insn, second element is limm (if present). */
38 static int initialized
= 0;
42 /* ??? Hmmm... what do we pass here? */
43 arc_opcode_init_tables (ARC_HAVE_MULT_SHIFT
);
47 status
= (*info
->read_memory_func
) (pc
, buffer
, 4, info
);
50 (*info
->memory_error_func
) (status
, pc
, info
);
53 insn
[0] = bfd_getb32 (buffer
);
55 func (stream
, "%08lx\t", insn
[0]);
57 opcode_end
= arc_opcodes
+ arc_opcodes_count
;
58 for (opcode
= arc_opcodes
; opcode
< opcode_end
; opcode
++)
63 const struct arc_operand
*operand
;
64 const struct arc_operand_value
*opval
;
66 if ((insn
[0] & opcode
->mask
) != opcode
->value
)
69 /* Make two passes over the operands. First see if any of them
70 have extraction functions, and, if they do, make sure the
71 instruction is valid. */
73 arc_opcode_init_extract ();
76 /* ??? Granted, this is slower than the `ppc' way. Maybe when this is
77 done it'll be clear what the right way to do this is. */
78 /* Instructions like "add.f r0,r1,1" are tricky because the ".f" gets
79 printed first, but we don't know how to print it until we've processed
80 the regs. Since we're scanning all the args before printing the insn
81 anyways, it's quite easy. */
83 for (syn
= opcode
->syntax
; *syn
; ++syn
)
85 if (*syn
!= '%' || *++syn
== '%')
88 while (ARC_MOD_P (arc_operands
[arc_operand_map
[*syn
]].flags
))
90 mods
|= arc_operands
[arc_operand_map
[*syn
]].flags
& ARC_MOD_BITS
;
93 operand
= arc_operands
+ arc_operand_map
[*syn
];
95 (*operand
->extract
) (insn
, operand
, mods
,
96 (const struct arc_operand_value
**) NULL
,
102 /* The instruction is valid. */
104 /* If we have an insn with a limm, fetch it now. Scanning the insns
105 twice lets us do this. */
106 if (arc_opcode_limm_p (NULL
))
108 status
= (*info
->read_memory_func
) (pc
+ 4, buffer
, 4, info
);
111 (*info
->memory_error_func
) (status
, pc
, info
);
114 insn
[1] = bfd_getb32 (buffer
);
118 for (syn
= opcode
->syntax
; *syn
; ++syn
)
120 if (*syn
!= '%' || *++syn
== '%')
122 func (stream
, "%c", *syn
);
126 /* We have an operand. Fetch any special modifiers. */
128 while (ARC_MOD_P (arc_operands
[arc_operand_map
[*syn
]].flags
))
130 mods
|= arc_operands
[arc_operand_map
[*syn
]].flags
& ARC_MOD_BITS
;
133 operand
= arc_operands
+ arc_operand_map
[*syn
];
135 /* Extract the value from the instruction. */
137 if (operand
->extract
)
139 value
= (*operand
->extract
) (insn
, operand
, mods
,
140 &opval
, (int *) NULL
);
144 value
= (insn
[0] >> operand
->shift
) & ((1 << operand
->bits
) - 1);
145 if ((operand
->flags
& ARC_OPERAND_SIGNED
)
146 && (value
& (1 << (operand
->bits
- 1))))
147 value
-= 1 << operand
->bits
;
149 /* If this is a suffix operand, set `opval'. */
150 if (operand
->flags
& ARC_OPERAND_SUFFIX
)
151 opval
= arc_opcode_lookup_suffix (operand
, value
);
154 /* Print the operand as directed by the flags. */
155 if (operand
->flags
& ARC_OPERAND_FAKE
)
156 ; /* nothing to do (??? at least not yet) */
157 else if (operand
->flags
& ARC_OPERAND_SUFFIX
)
159 /* Default suffixes aren't printed. Fortunately, they all have
160 zero values. Also, zero values for boolean suffixes are
161 represented by the absence of text. */
165 /* ??? OPVAL should have a value. If it doesn't just cope
166 as we want disassembly to be reasonably robust.
167 Also remember that several condition code values (16-31)
168 aren't defined yet. For these cases just print the
169 number suitably decorated. */
171 func (stream
, "%s%s",
172 mods
& ARC_MOD_DOT
? "." : "",
175 func (stream
, "%s%c%d",
176 mods
& ARC_MOD_DOT
? "." : "",
177 operand
->fmt
, value
);
180 else if (operand
->flags
& ARC_OPERAND_RELATIVE
)
181 (*info
->print_address_func
) (pc
+ value
, info
);
182 /* ??? Not all cases of this are currently caught. */
183 else if (operand
->flags
& ARC_OPERAND_ABSOLUTE
)
184 (*info
->print_address_func
) ((bfd_vma
) value
& 0xffffffff, info
);
186 /* Note that this case catches both normal and auxiliary regs. */
187 func (stream
, "%s", opval
->name
);
189 func (stream
, "%ld", value
);
192 /* We have found and printed an instruction; return. */
193 return got_limm_p
? 8 : 4;
196 func (stream
, "*unknown*");
This page took 0.039718 seconds and 5 git commands to generate.