cris-dis.c revision 1.1.1.1 1 1.1 christos /* Disassembler code for CRIS.
2 1.1 christos Copyright 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2012
3 1.1 christos Free Software Foundation, Inc.
4 1.1 christos Contributed by Axis Communications AB, Lund, Sweden.
5 1.1 christos Written by Hans-Peter Nilsson.
6 1.1 christos
7 1.1 christos This file is part of the GNU opcodes library.
8 1.1 christos
9 1.1 christos This library is free software; you can redistribute it and/or modify
10 1.1 christos it under the terms of the GNU General Public License as published by
11 1.1 christos the Free Software Foundation; either version 3, or (at your option)
12 1.1 christos any later version.
13 1.1 christos
14 1.1 christos It is distributed in the hope that it will be useful, but WITHOUT
15 1.1 christos ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 1.1 christos or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
17 1.1 christos License for more details.
18 1.1 christos
19 1.1 christos You should have received a copy of the GNU General Public License
20 1.1 christos along with this program; if not, write to the Free Software
21 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 1.1 christos MA 02110-1301, USA. */
23 1.1 christos
24 1.1 christos #include "sysdep.h"
25 1.1 christos #include "dis-asm.h"
26 1.1 christos #include "opcode/cris.h"
27 1.1 christos #include "libiberty.h"
28 1.1 christos
29 1.1 christos /* No instruction will be disassembled longer than this. In theory, and
31 1.1 christos in silicon, address prefixes can be cascaded. In practice, cascading
32 1.1 christos is not used by GCC, and not supported by the assembler. */
33 1.1 christos #ifndef MAX_BYTES_PER_CRIS_INSN
34 1.1 christos #define MAX_BYTES_PER_CRIS_INSN 8
35 1.1 christos #endif
36 1.1 christos
37 1.1 christos /* Whether or not to decode prefixes, folding it into the following
38 1.1 christos instruction. FIXME: Make this optional later. */
39 1.1 christos #ifndef PARSE_PREFIX
40 1.1 christos #define PARSE_PREFIX 1
41 1.1 christos #endif
42 1.1 christos
43 1.1 christos /* Sometimes we prefix all registers with this character. */
44 1.1 christos #define REGISTER_PREFIX_CHAR '$'
45 1.1 christos
46 1.1 christos /* Whether or not to trace the following sequence:
47 1.1 christos sub* X,r%d
48 1.1 christos bound* Y,r%d
49 1.1 christos adds.w [pc+r%d.w],pc
50 1.1 christos
51 1.1 christos This is the assembly form of a switch-statement in C.
52 1.1 christos The "sub is optional. If there is none, then X will be zero.
53 1.1 christos X is the value of the first case,
54 1.1 christos Y is the number of cases (including default).
55 1.1 christos
56 1.1 christos This results in case offsets printed on the form:
57 1.1 christos case N: -> case_address
58 1.1 christos where N is an estimation on the corresponding 'case' operand in C,
59 1.1 christos and case_address is where execution of that case continues after the
60 1.1 christos sequence presented above.
61 1.1 christos
62 1.1 christos The old style of output was to print the offsets as instructions,
63 1.1 christos which made it hard to follow "case"-constructs in the disassembly,
64 1.1 christos and caused a lot of annoying warnings about undefined instructions.
65 1.1 christos
66 1.1 christos FIXME: Make this optional later. */
67 1.1 christos #ifndef TRACE_CASE
68 1.1 christos #define TRACE_CASE (disdata->trace_case)
69 1.1 christos #endif
70 1.1 christos
71 1.1 christos enum cris_disass_family
72 1.1 christos { cris_dis_v0_v10, cris_dis_common_v10_v32, cris_dis_v32 };
73 1.1 christos
74 1.1 christos /* Stored in the disasm_info->private_data member. */
75 1.1 christos struct cris_disasm_data
76 1.1 christos {
77 1.1 christos /* Whether to print something less confusing if we find something
78 1.1 christos matching a switch-construct. */
79 1.1 christos bfd_boolean trace_case;
80 1.1 christos
81 1.1 christos /* Whether this code is flagged as crisv32. FIXME: Should be an enum
82 1.1 christos that includes "compatible". */
83 1.1 christos enum cris_disass_family distype;
84 1.1 christos };
85 1.1 christos
86 1.1 christos /* Value of first element in switch. */
87 1.1 christos static long case_offset = 0;
88 1.1 christos
89 1.1 christos /* How many more case-offsets to print. */
90 1.1 christos static long case_offset_counter = 0;
91 1.1 christos
92 1.1 christos /* Number of case offsets. */
93 1.1 christos static long no_of_case_offsets = 0;
94 1.1 christos
95 1.1 christos /* Candidate for next case_offset. */
96 1.1 christos static long last_immediate = 0;
97 1.1 christos
98 1.1 christos static int cris_constraint
99 1.1 christos (const char *, unsigned, unsigned, struct cris_disasm_data *);
100 1.1 christos
101 1.1 christos /* Parse disassembler options and store state in info. FIXME: For the
102 1.1 christos time being, we abuse static variables. */
103 1.1 christos
104 1.1 christos static bfd_boolean
105 1.1 christos cris_parse_disassembler_options (disassemble_info *info,
106 1.1 christos enum cris_disass_family distype)
107 1.1 christos {
108 1.1 christos struct cris_disasm_data *disdata;
109 1.1 christos
110 1.1 christos info->private_data = calloc (1, sizeof (struct cris_disasm_data));
111 1.1 christos disdata = (struct cris_disasm_data *) info->private_data;
112 1.1 christos if (disdata == NULL)
113 1.1 christos return FALSE;
114 1.1 christos
115 1.1 christos /* Default true. */
116 1.1 christos disdata->trace_case
117 1.1 christos = (info->disassembler_options == NULL
118 1.1 christos || (strcmp (info->disassembler_options, "nocase") != 0));
119 1.1 christos
120 1.1 christos disdata->distype = distype;
121 1.1 christos return TRUE;
122 1.1 christos }
123 1.1 christos
124 1.1 christos static const struct cris_spec_reg *
125 1.1 christos spec_reg_info (unsigned int sreg, enum cris_disass_family distype)
126 1.1 christos {
127 1.1 christos int i;
128 1.1 christos
129 1.1 christos for (i = 0; cris_spec_regs[i].name != NULL; i++)
130 1.1 christos {
131 1.1 christos if (cris_spec_regs[i].number == sreg)
132 1.1 christos {
133 1.1 christos if (distype == cris_dis_v32)
134 1.1 christos switch (cris_spec_regs[i].applicable_version)
135 1.1 christos {
136 1.1 christos case cris_ver_warning:
137 1.1 christos case cris_ver_version_all:
138 1.1 christos case cris_ver_v3p:
139 1.1 christos case cris_ver_v8p:
140 1.1 christos case cris_ver_v10p:
141 1.1 christos case cris_ver_v32p:
142 1.1 christos /* No ambiguous sizes or register names with CRISv32. */
143 1.1 christos if (cris_spec_regs[i].warning == NULL)
144 1.1 christos return &cris_spec_regs[i];
145 1.1 christos default:
146 1.1 christos ;
147 1.1 christos }
148 1.1 christos else if (cris_spec_regs[i].applicable_version != cris_ver_v32p)
149 1.1 christos return &cris_spec_regs[i];
150 1.1 christos }
151 1.1 christos }
152 1.1 christos
153 1.1 christos return NULL;
154 1.1 christos }
155 1.1 christos
156 1.1 christos /* Return the number of bits in the argument. */
157 1.1 christos
158 1.1 christos static int
159 1.1 christos number_of_bits (unsigned int val)
160 1.1 christos {
161 1.1 christos int bits;
162 1.1 christos
163 1.1 christos for (bits = 0; val != 0; val &= val - 1)
164 1.1 christos bits++;
165 1.1 christos
166 1.1 christos return bits;
167 1.1 christos }
168 1.1 christos
169 1.1 christos /* Get an entry in the opcode-table. */
170 1.1 christos
171 1.1 christos static const struct cris_opcode *
172 1.1 christos get_opcode_entry (unsigned int insn,
173 1.1 christos unsigned int prefix_insn,
174 1.1 christos struct cris_disasm_data *disdata)
175 1.1 christos {
176 1.1 christos /* For non-prefixed insns, we keep a table of pointers, indexed by the
177 1.1 christos insn code. Each entry is initialized when found to be NULL. */
178 1.1 christos static const struct cris_opcode **opc_table = NULL;
179 1.1 christos
180 1.1 christos const struct cris_opcode *max_matchedp = NULL;
181 1.1 christos const struct cris_opcode **prefix_opc_table = NULL;
182 1.1 christos
183 1.1 christos /* We hold a table for each prefix that need to be handled differently. */
184 1.1 christos static const struct cris_opcode **dip_prefixes = NULL;
185 1.1 christos static const struct cris_opcode **bdapq_m1_prefixes = NULL;
186 1.1 christos static const struct cris_opcode **bdapq_m2_prefixes = NULL;
187 1.1 christos static const struct cris_opcode **bdapq_m4_prefixes = NULL;
188 1.1 christos static const struct cris_opcode **rest_prefixes = NULL;
189 1.1 christos
190 1.1 christos /* Allocate and clear the opcode-table. */
191 1.1 christos if (opc_table == NULL)
192 1.1 christos {
193 1.1 christos opc_table = malloc (65536 * sizeof (opc_table[0]));
194 1.1 christos if (opc_table == NULL)
195 1.1 christos return NULL;
196 1.1 christos
197 1.1 christos memset (opc_table, 0, 65536 * sizeof (const struct cris_opcode *));
198 1.1 christos
199 1.1 christos dip_prefixes
200 1.1 christos = malloc (65536 * sizeof (const struct cris_opcode **));
201 1.1 christos if (dip_prefixes == NULL)
202 1.1 christos return NULL;
203 1.1 christos
204 1.1 christos memset (dip_prefixes, 0, 65536 * sizeof (dip_prefixes[0]));
205 1.1 christos
206 1.1 christos bdapq_m1_prefixes
207 1.1 christos = malloc (65536 * sizeof (const struct cris_opcode **));
208 1.1 christos if (bdapq_m1_prefixes == NULL)
209 1.1 christos return NULL;
210 1.1 christos
211 1.1 christos memset (bdapq_m1_prefixes, 0, 65536 * sizeof (bdapq_m1_prefixes[0]));
212 1.1 christos
213 1.1 christos bdapq_m2_prefixes
214 1.1 christos = malloc (65536 * sizeof (const struct cris_opcode **));
215 1.1 christos if (bdapq_m2_prefixes == NULL)
216 1.1 christos return NULL;
217 1.1 christos
218 1.1 christos memset (bdapq_m2_prefixes, 0, 65536 * sizeof (bdapq_m2_prefixes[0]));
219 1.1 christos
220 1.1 christos bdapq_m4_prefixes
221 1.1 christos = malloc (65536 * sizeof (const struct cris_opcode **));
222 1.1 christos if (bdapq_m4_prefixes == NULL)
223 1.1 christos return NULL;
224 1.1 christos
225 1.1 christos memset (bdapq_m4_prefixes, 0, 65536 * sizeof (bdapq_m4_prefixes[0]));
226 1.1 christos
227 1.1 christos rest_prefixes
228 1.1 christos = malloc (65536 * sizeof (const struct cris_opcode **));
229 1.1 christos if (rest_prefixes == NULL)
230 1.1 christos return NULL;
231 1.1 christos
232 1.1 christos memset (rest_prefixes, 0, 65536 * sizeof (rest_prefixes[0]));
233 1.1 christos }
234 1.1 christos
235 1.1 christos /* Get the right table if this is a prefix.
236 1.1 christos This code is connected to cris_constraints in that it knows what
237 1.1 christos prefixes play a role in recognition of patterns; the necessary
238 1.1 christos state is reflected by which table is used. If constraints
239 1.1 christos involving match or non-match of prefix insns are changed, then this
240 1.1 christos probably needs changing too. */
241 1.1 christos if (prefix_insn != NO_CRIS_PREFIX)
242 1.1 christos {
243 1.1 christos const struct cris_opcode *popcodep
244 1.1 christos = (opc_table[prefix_insn] != NULL
245 1.1 christos ? opc_table[prefix_insn]
246 1.1 christos : get_opcode_entry (prefix_insn, NO_CRIS_PREFIX, disdata));
247 1.1 christos
248 1.1 christos if (popcodep == NULL)
249 1.1 christos return NULL;
250 1.1 christos
251 1.1 christos if (popcodep->match == BDAP_QUICK_OPCODE)
252 1.1 christos {
253 1.1 christos /* Since some offsets are recognized with "push" macros, we
254 1.1 christos have to have different tables for them. */
255 1.1 christos int offset = (prefix_insn & 255);
256 1.1 christos
257 1.1 christos if (offset > 127)
258 1.1 christos offset -= 256;
259 1.1 christos
260 1.1 christos switch (offset)
261 1.1 christos {
262 1.1 christos case -4:
263 1.1 christos prefix_opc_table = bdapq_m4_prefixes;
264 1.1 christos break;
265 1.1 christos
266 1.1 christos case -2:
267 1.1 christos prefix_opc_table = bdapq_m2_prefixes;
268 1.1 christos break;
269 1.1 christos
270 1.1 christos case -1:
271 1.1 christos prefix_opc_table = bdapq_m1_prefixes;
272 1.1 christos break;
273 1.1 christos
274 1.1 christos default:
275 1.1 christos prefix_opc_table = rest_prefixes;
276 1.1 christos break;
277 1.1 christos }
278 1.1 christos }
279 1.1 christos else if (popcodep->match == DIP_OPCODE)
280 1.1 christos /* We don't allow postincrement when the prefix is DIP, so use a
281 1.1 christos different table for DIP. */
282 1.1 christos prefix_opc_table = dip_prefixes;
283 1.1 christos else
284 1.1 christos prefix_opc_table = rest_prefixes;
285 1.1 christos }
286 1.1 christos
287 1.1 christos if (prefix_insn != NO_CRIS_PREFIX
288 1.1 christos && prefix_opc_table[insn] != NULL)
289 1.1 christos max_matchedp = prefix_opc_table[insn];
290 1.1 christos else if (prefix_insn == NO_CRIS_PREFIX && opc_table[insn] != NULL)
291 1.1 christos max_matchedp = opc_table[insn];
292 1.1 christos else
293 1.1 christos {
294 1.1 christos const struct cris_opcode *opcodep;
295 1.1 christos int max_level_of_match = -1;
296 1.1 christos
297 1.1 christos for (opcodep = cris_opcodes;
298 1.1 christos opcodep->name != NULL;
299 1.1 christos opcodep++)
300 1.1 christos {
301 1.1 christos int level_of_match;
302 1.1 christos
303 1.1 christos if (disdata->distype == cris_dis_v32)
304 1.1 christos {
305 1.1 christos switch (opcodep->applicable_version)
306 1.1 christos {
307 1.1 christos case cris_ver_version_all:
308 1.1 christos break;
309 1.1 christos
310 1.1 christos case cris_ver_v0_3:
311 1.1 christos case cris_ver_v0_10:
312 1.1 christos case cris_ver_v3_10:
313 1.1 christos case cris_ver_sim_v0_10:
314 1.1 christos case cris_ver_v8_10:
315 1.1 christos case cris_ver_v10:
316 1.1 christos case cris_ver_warning:
317 1.1 christos continue;
318 1.1 christos
319 1.1 christos case cris_ver_v3p:
320 1.1 christos case cris_ver_v8p:
321 1.1 christos case cris_ver_v10p:
322 1.1 christos case cris_ver_v32p:
323 1.1 christos break;
324 1.1 christos
325 1.1 christos case cris_ver_v8:
326 1.1 christos abort ();
327 1.1 christos default:
328 1.1 christos abort ();
329 1.1 christos }
330 1.1 christos }
331 1.1 christos else
332 1.1 christos {
333 1.1 christos switch (opcodep->applicable_version)
334 1.1 christos {
335 1.1 christos case cris_ver_version_all:
336 1.1 christos case cris_ver_v0_3:
337 1.1 christos case cris_ver_v3p:
338 1.1 christos case cris_ver_v0_10:
339 1.1 christos case cris_ver_v8p:
340 1.1 christos case cris_ver_v8_10:
341 1.1 christos case cris_ver_v10:
342 1.1 christos case cris_ver_sim_v0_10:
343 1.1 christos case cris_ver_v10p:
344 1.1 christos case cris_ver_warning:
345 1.1 christos break;
346 1.1 christos
347 1.1 christos case cris_ver_v32p:
348 1.1 christos continue;
349 1.1 christos
350 1.1 christos case cris_ver_v8:
351 1.1 christos abort ();
352 1.1 christos default:
353 1.1 christos abort ();
354 1.1 christos }
355 1.1 christos }
356 1.1 christos
357 1.1 christos /* We give a double lead for bits matching the template in
358 1.1 christos cris_opcodes. Not even, because then "move p8,r10" would
359 1.1 christos be given 2 bits lead over "clear.d r10". When there's a
360 1.1 christos tie, the first entry in the table wins. This is
361 1.1 christos deliberate, to avoid a more complicated recognition
362 1.1 christos formula. */
363 1.1 christos if ((opcodep->match & insn) == opcodep->match
364 1.1 christos && (opcodep->lose & insn) == 0
365 1.1 christos && ((level_of_match
366 1.1 christos = cris_constraint (opcodep->args,
367 1.1 christos insn,
368 1.1 christos prefix_insn,
369 1.1 christos disdata))
370 1.1 christos >= 0)
371 1.1 christos && ((level_of_match
372 1.1 christos += 2 * number_of_bits (opcodep->match
373 1.1 christos | opcodep->lose))
374 1.1 christos > max_level_of_match))
375 1.1 christos {
376 1.1 christos max_matchedp = opcodep;
377 1.1 christos max_level_of_match = level_of_match;
378 1.1 christos
379 1.1 christos /* If there was a full match, never mind looking
380 1.1 christos further. */
381 1.1 christos if (level_of_match >= 2 * 16)
382 1.1 christos break;
383 1.1 christos }
384 1.1 christos }
385 1.1 christos /* Fill in the new entry.
386 1.1 christos
387 1.1 christos If there are changes to the opcode-table involving prefixes, and
388 1.1 christos disassembly then does not work correctly, try removing the
389 1.1 christos else-clause below that fills in the prefix-table. If that
390 1.1 christos helps, you need to change the prefix_opc_table setting above, or
391 1.1 christos something related. */
392 1.1 christos if (prefix_insn == NO_CRIS_PREFIX)
393 1.1 christos opc_table[insn] = max_matchedp;
394 1.1 christos else
395 1.1 christos prefix_opc_table[insn] = max_matchedp;
396 1.1 christos }
397 1.1 christos
398 1.1 christos return max_matchedp;
399 1.1 christos }
400 1.1 christos
401 1.1 christos /* Return -1 if the constraints of a bitwise-matched instruction say
402 1.1 christos that there is no match. Otherwise return a nonnegative number
403 1.1 christos indicating the confidence in the match (higher is better). */
404 1.1 christos
405 1.1 christos static int
406 1.1 christos cris_constraint (const char *cs,
407 1.1 christos unsigned int insn,
408 1.1 christos unsigned int prefix_insn,
409 1.1 christos struct cris_disasm_data *disdata)
410 1.1 christos {
411 1.1 christos int retval = 0;
412 1.1 christos int tmp;
413 1.1 christos int prefix_ok = 0;
414 1.1 christos const char *s;
415 1.1 christos
416 1.1 christos for (s = cs; *s; s++)
417 1.1 christos switch (*s)
418 1.1 christos {
419 1.1 christos case '!':
420 1.1 christos /* Do not recognize "pop" if there's a prefix and then only for
421 1.1 christos v0..v10. */
422 1.1 christos if (prefix_insn != NO_CRIS_PREFIX
423 1.1 christos || disdata->distype != cris_dis_v0_v10)
424 1.1 christos return -1;
425 1.1 christos break;
426 1.1 christos
427 1.1 christos case 'U':
428 1.1 christos /* Not recognized at disassembly. */
429 1.1 christos return -1;
430 1.1 christos
431 1.1 christos case 'M':
432 1.1 christos /* Size modifier for "clear", i.e. special register 0, 4 or 8.
433 1.1 christos Check that it is one of them. Only special register 12 could
434 1.1 christos be mismatched, but checking for matches is more logical than
435 1.1 christos checking for mismatches when there are only a few cases. */
436 1.1 christos tmp = ((insn >> 12) & 0xf);
437 1.1 christos if (tmp != 0 && tmp != 4 && tmp != 8)
438 1.1 christos return -1;
439 1.1 christos break;
440 1.1 christos
441 1.1 christos case 'm':
442 1.1 christos if ((insn & 0x30) == 0x30)
443 1.1 christos return -1;
444 1.1 christos break;
445 1.1 christos
446 1.1 christos case 'S':
447 1.1 christos /* A prefix operand without side-effect. */
448 1.1 christos if (prefix_insn != NO_CRIS_PREFIX && (insn & 0x400) == 0)
449 1.1 christos {
450 1.1 christos prefix_ok = 1;
451 1.1 christos break;
452 1.1 christos }
453 1.1 christos else
454 1.1 christos return -1;
455 1.1 christos
456 1.1 christos case 's':
457 1.1 christos case 'y':
458 1.1 christos case 'Y':
459 1.1 christos /* If this is a prefixed insn with postincrement (side-effect),
460 1.1 christos the prefix must not be DIP. */
461 1.1 christos if (prefix_insn != NO_CRIS_PREFIX)
462 1.1 christos {
463 1.1 christos if (insn & 0x400)
464 1.1 christos {
465 1.1 christos const struct cris_opcode *prefix_opcodep
466 1.1 christos = get_opcode_entry (prefix_insn, NO_CRIS_PREFIX, disdata);
467 1.1 christos
468 1.1 christos if (prefix_opcodep->match == DIP_OPCODE)
469 1.1 christos return -1;
470 1.1 christos }
471 1.1 christos
472 1.1 christos prefix_ok = 1;
473 1.1 christos }
474 1.1 christos break;
475 1.1 christos
476 1.1 christos case 'B':
477 1.1 christos /* If we don't fall through, then the prefix is ok. */
478 1.1 christos prefix_ok = 1;
479 1.1 christos
480 1.1 christos /* A "push" prefix. Check for valid "push" size.
481 1.1 christos In case of special register, it may be != 4. */
482 1.1 christos if (prefix_insn != NO_CRIS_PREFIX)
483 1.1 christos {
484 1.1 christos /* Match the prefix insn to BDAPQ. */
485 1.1 christos const struct cris_opcode *prefix_opcodep
486 1.1 christos = get_opcode_entry (prefix_insn, NO_CRIS_PREFIX, disdata);
487 1.1 christos
488 1.1 christos if (prefix_opcodep->match == BDAP_QUICK_OPCODE)
489 1.1 christos {
490 1.1 christos int pushsize = (prefix_insn & 255);
491 1.1 christos
492 1.1 christos if (pushsize > 127)
493 1.1 christos pushsize -= 256;
494 1.1 christos
495 1.1 christos if (s[1] == 'P')
496 1.1 christos {
497 1.1 christos unsigned int spec_reg = (insn >> 12) & 15;
498 1.1 christos const struct cris_spec_reg *sregp
499 1.1 christos = spec_reg_info (spec_reg, disdata->distype);
500 1.1 christos
501 1.1 christos /* For a special-register, the "prefix size" must
502 1.1 christos match the size of the register. */
503 1.1 christos if (sregp && sregp->reg_size == (unsigned int) -pushsize)
504 1.1 christos break;
505 1.1 christos }
506 1.1 christos else if (s[1] == 'R')
507 1.1 christos {
508 1.1 christos if ((insn & 0x30) == 0x20 && pushsize == -4)
509 1.1 christos break;
510 1.1 christos }
511 1.1 christos /* FIXME: Should abort here; next constraint letter
512 1.1 christos *must* be 'P' or 'R'. */
513 1.1 christos }
514 1.1 christos }
515 1.1 christos return -1;
516 1.1 christos
517 1.1 christos case 'D':
518 1.1 christos retval = (((insn >> 12) & 15) == (insn & 15));
519 1.1 christos if (!retval)
520 1.1 christos return -1;
521 1.1 christos else
522 1.1 christos retval += 4;
523 1.1 christos break;
524 1.1 christos
525 1.1 christos case 'P':
526 1.1 christos {
527 1.1 christos const struct cris_spec_reg *sregp
528 1.1 christos = spec_reg_info ((insn >> 12) & 15, disdata->distype);
529 1.1 christos
530 1.1 christos /* Since we match four bits, we will give a value of 4-1 = 3
531 1.1 christos in a match. If there is a corresponding exact match of a
532 1.1 christos special register in another pattern, it will get a value of
533 1.1 christos 4, which will be higher. This should be correct in that an
534 1.1 christos exact pattern would match better than a general pattern.
535 1.1 christos
536 1.1 christos Note that there is a reason for not returning zero; the
537 1.1 christos pattern for "clear" is partly matched in the bit-pattern
538 1.1 christos (the two lower bits must be zero), while the bit-pattern
539 1.1 christos for a move from a special register is matched in the
540 1.1 christos register constraint. */
541 1.1 christos
542 1.1 christos if (sregp != NULL)
543 1.1 christos {
544 1.1 christos retval += 3;
545 1.1 christos break;
546 1.1 christos }
547 1.1 christos else
548 1.1 christos return -1;
549 1.1 christos }
550 1.1 christos }
551 1.1 christos
552 1.1 christos if (prefix_insn != NO_CRIS_PREFIX && ! prefix_ok)
553 1.1 christos return -1;
554 1.1 christos
555 1.1 christos return retval;
556 1.1 christos }
557 1.1 christos
558 1.1 christos /* Format number as hex with a leading "0x" into outbuffer. */
559 1.1 christos
560 1.1 christos static char *
561 1.1 christos format_hex (unsigned long number,
562 1.1 christos char *outbuffer,
563 1.1 christos struct cris_disasm_data *disdata)
564 1.1 christos {
565 1.1 christos /* Truncate negative numbers on >32-bit hosts. */
566 1.1 christos number &= 0xffffffff;
567 1.1 christos
568 1.1 christos sprintf (outbuffer, "0x%lx", number);
569 1.1 christos
570 1.1 christos /* Save this value for the "case" support. */
571 1.1 christos if (TRACE_CASE)
572 1.1 christos last_immediate = number;
573 1.1 christos
574 1.1 christos return outbuffer + strlen (outbuffer);
575 1.1 christos }
576 1.1 christos
577 1.1 christos /* Format number as decimal into outbuffer. Parameter signedp says
578 1.1 christos whether the number should be formatted as signed (!= 0) or
579 1.1 christos unsigned (== 0). */
580 1.1 christos
581 1.1 christos static char *
582 1.1 christos format_dec (long number, char *outbuffer, int signedp)
583 1.1 christos {
584 1.1 christos last_immediate = number;
585 1.1 christos if (signedp)
586 1.1 christos sprintf (outbuffer, "%ld", number);
587 1.1 christos else
588 1.1 christos sprintf (outbuffer, "%lu", (unsigned long) number);
589 1.1 christos
590 1.1 christos return outbuffer + strlen (outbuffer);
591 1.1 christos }
592 1.1 christos
593 1.1 christos /* Format the name of the general register regno into outbuffer. */
594 1.1 christos
595 1.1 christos static char *
596 1.1 christos format_reg (struct cris_disasm_data *disdata,
597 1.1 christos int regno,
598 1.1 christos char *outbuffer_start,
599 1.1 christos bfd_boolean with_reg_prefix)
600 1.1 christos {
601 1.1 christos char *outbuffer = outbuffer_start;
602 1.1 christos
603 1.1 christos if (with_reg_prefix)
604 1.1 christos *outbuffer++ = REGISTER_PREFIX_CHAR;
605 1.1 christos
606 1.1 christos switch (regno)
607 1.1 christos {
608 1.1 christos case 15:
609 1.1 christos /* For v32, there is no context in which we output PC. */
610 1.1 christos if (disdata->distype == cris_dis_v32)
611 1.1 christos strcpy (outbuffer, "acr");
612 1.1 christos else
613 1.1 christos strcpy (outbuffer, "pc");
614 1.1 christos break;
615 1.1 christos
616 1.1 christos case 14:
617 1.1 christos strcpy (outbuffer, "sp");
618 1.1 christos break;
619 1.1 christos
620 1.1 christos default:
621 1.1 christos sprintf (outbuffer, "r%d", regno);
622 1.1 christos break;
623 1.1 christos }
624 1.1 christos
625 1.1 christos return outbuffer_start + strlen (outbuffer_start);
626 1.1 christos }
627 1.1 christos
628 1.1 christos /* Format the name of a support register into outbuffer. */
629 1.1 christos
630 1.1 christos static char *
631 1.1 christos format_sup_reg (unsigned int regno,
632 1.1 christos char *outbuffer_start,
633 1.1 christos bfd_boolean with_reg_prefix)
634 1.1 christos {
635 1.1 christos char *outbuffer = outbuffer_start;
636 1.1 christos int i;
637 1.1 christos
638 1.1 christos if (with_reg_prefix)
639 1.1 christos *outbuffer++ = REGISTER_PREFIX_CHAR;
640 1.1 christos
641 1.1 christos for (i = 0; cris_support_regs[i].name != NULL; i++)
642 1.1 christos if (cris_support_regs[i].number == regno)
643 1.1 christos {
644 1.1 christos sprintf (outbuffer, "%s", cris_support_regs[i].name);
645 1.1 christos return outbuffer_start + strlen (outbuffer_start);
646 1.1 christos }
647 1.1 christos
648 1.1 christos /* There's supposed to be register names covering all numbers, though
649 1.1 christos some may be generic names. */
650 1.1 christos sprintf (outbuffer, "format_sup_reg-BUG");
651 1.1 christos return outbuffer_start + strlen (outbuffer_start);
652 1.1 christos }
653 1.1 christos
654 1.1 christos /* Return the length of an instruction. */
655 1.1 christos
656 1.1 christos static unsigned
657 1.1 christos bytes_to_skip (unsigned int insn,
658 1.1 christos const struct cris_opcode *matchedp,
659 1.1 christos enum cris_disass_family distype,
660 1.1 christos const struct cris_opcode *prefix_matchedp)
661 1.1 christos {
662 1.1 christos /* Each insn is a word plus "immediate" operands. */
663 1.1 christos unsigned to_skip = 2;
664 1.1 christos const char *template_name = (const char *) matchedp->args;
665 1.1 christos const char *s;
666 1.1 christos
667 1.1 christos for (s = template_name; *s; s++)
668 1.1 christos if ((*s == 's' || *s == 'N' || *s == 'Y')
669 1.1 christos && (insn & 0x400) && (insn & 15) == 15
670 1.1 christos && prefix_matchedp == NULL)
671 1.1 christos {
672 1.1 christos /* Immediate via [pc+], so we have to check the size of the
673 1.1 christos operand. */
674 1.1 christos int mode_size = 1 << ((insn >> 4) & (*template_name == 'z' ? 1 : 3));
675 1.1 christos
676 1.1 christos if (matchedp->imm_oprnd_size == SIZE_FIX_32)
677 1.1 christos to_skip += 4;
678 1.1 christos else if (matchedp->imm_oprnd_size == SIZE_SPEC_REG)
679 1.1 christos {
680 1.1 christos const struct cris_spec_reg *sregp
681 1.1 christos = spec_reg_info ((insn >> 12) & 15, distype);
682 1.1 christos
683 1.1 christos /* FIXME: Improve error handling; should have been caught
684 1.1 christos earlier. */
685 1.1 christos if (sregp == NULL)
686 1.1 christos return 2;
687 1.1 christos
688 1.1 christos /* PC is incremented by two, not one, for a byte. Except on
689 1.1 christos CRISv32, where constants are always DWORD-size for
690 1.1 christos special registers. */
691 1.1 christos to_skip +=
692 1.1 christos distype == cris_dis_v32 ? 4 : (sregp->reg_size + 1) & ~1;
693 1.1 christos }
694 1.1 christos else
695 1.1 christos to_skip += (mode_size + 1) & ~1;
696 1.1 christos }
697 1.1 christos else if (*s == 'n')
698 1.1 christos to_skip += 4;
699 1.1 christos else if (*s == 'b')
700 1.1 christos to_skip += 2;
701 1.1 christos
702 1.1 christos return to_skip;
703 1.1 christos }
704 1.1 christos
705 1.1 christos /* Print condition code flags. */
706 1.1 christos
707 1.1 christos static char *
708 1.1 christos print_flags (struct cris_disasm_data *disdata, unsigned int insn, char *cp)
709 1.1 christos {
710 1.1 christos /* Use the v8 (Etrax 100) flag definitions for disassembly.
711 1.1 christos The differences with v0 (Etrax 1..4) vs. Svinto are:
712 1.1 christos v0 'd' <=> v8 'm'
713 1.1 christos v0 'e' <=> v8 'b'.
714 1.1 christos FIXME: Emit v0..v3 flag names somehow. */
715 1.1 christos static const char v8_fnames[] = "cvznxibm";
716 1.1 christos static const char v32_fnames[] = "cvznxiup";
717 1.1 christos const char *fnames
718 1.1 christos = disdata->distype == cris_dis_v32 ? v32_fnames : v8_fnames;
719 1.1 christos
720 1.1 christos unsigned char flagbits = (((insn >> 8) & 0xf0) | (insn & 15));
721 1.1 christos int i;
722 1.1 christos
723 1.1 christos for (i = 0; i < 8; i++)
724 1.1 christos if (flagbits & (1 << i))
725 1.1 christos *cp++ = fnames[i];
726 1.1 christos
727 1.1 christos return cp;
728 1.1 christos }
729 1.1 christos
730 1.1 christos /* Print out an insn with its operands, and update the info->insn_type
731 1.1 christos fields. The prefix_opcodep and the rest hold a prefix insn that is
732 1.1 christos supposed to be output as an address mode. */
733 1.1 christos
734 1.1 christos static void
735 1.1 christos print_with_operands (const struct cris_opcode *opcodep,
736 1.1 christos unsigned int insn,
737 1.1 christos unsigned char *buffer,
738 1.1 christos bfd_vma addr,
739 1.1 christos disassemble_info *info,
740 1.1 christos /* If a prefix insn was before this insn (and is supposed
741 1.1 christos to be output as an address), here is a description of
742 1.1 christos it. */
743 1.1 christos const struct cris_opcode *prefix_opcodep,
744 1.1 christos unsigned int prefix_insn,
745 1.1 christos unsigned char *prefix_buffer,
746 1.1 christos bfd_boolean with_reg_prefix)
747 1.1 christos {
748 1.1 christos /* Get a buffer of somewhat reasonable size where we store
749 1.1 christos intermediate parts of the insn. */
750 1.1 christos char temp[sizeof (".d [$r13=$r12-2147483648],$r10") * 2];
751 1.1 christos char *tp = temp;
752 1.1 christos static const char mode_char[] = "bwd?";
753 1.1 christos const char *s;
754 1.1 christos const char *cs;
755 1.1 christos struct cris_disasm_data *disdata
756 1.1 christos = (struct cris_disasm_data *) info->private_data;
757 1.1 christos
758 1.1 christos /* Print out the name first thing we do. */
759 1.1 christos (*info->fprintf_func) (info->stream, "%s", opcodep->name);
760 1.1 christos
761 1.1 christos cs = opcodep->args;
762 1.1 christos s = cs;
763 1.1 christos
764 1.1 christos /* Ignore any prefix indicator. */
765 1.1 christos if (*s == 'p')
766 1.1 christos s++;
767 1.1 christos
768 1.1 christos if (*s == 'm' || *s == 'M' || *s == 'z')
769 1.1 christos {
770 1.1 christos *tp++ = '.';
771 1.1 christos
772 1.1 christos /* Get the size-letter. */
773 1.1 christos *tp++ = *s == 'M'
774 1.1 christos ? (insn & 0x8000 ? 'd'
775 1.1 christos : insn & 0x4000 ? 'w' : 'b')
776 1.1 christos : mode_char[(insn >> 4) & (*s == 'z' ? 1 : 3)];
777 1.1 christos
778 1.1 christos /* Ignore the size and the space character that follows. */
779 1.1 christos s += 2;
780 1.1 christos }
781 1.1 christos
782 1.1 christos /* Add a space if this isn't a long-branch, because for those will add
783 1.1 christos the condition part of the name later. */
784 1.1 christos if (opcodep->match != (BRANCH_PC_LOW + BRANCH_INCR_HIGH * 256))
785 1.1 christos *tp++ = ' ';
786 1.1 christos
787 1.1 christos /* Fill in the insn-type if deducible from the name (and there's no
788 1.1 christos better way). */
789 1.1 christos if (opcodep->name[0] == 'j')
790 1.1 christos {
791 1.1 christos if (CONST_STRNEQ (opcodep->name, "jsr"))
792 1.1 christos /* It's "jsr" or "jsrc". */
793 1.1 christos info->insn_type = dis_jsr;
794 1.1 christos else
795 1.1 christos /* Any other jump-type insn is considered a branch. */
796 1.1 christos info->insn_type = dis_branch;
797 1.1 christos }
798 1.1 christos
799 1.1 christos /* We might know some more fields right now. */
800 1.1 christos info->branch_delay_insns = opcodep->delayed;
801 1.1 christos
802 1.1 christos /* Handle operands. */
803 1.1 christos for (; *s; s++)
804 1.1 christos {
805 1.1 christos switch (*s)
806 1.1 christos {
807 1.1 christos case 'T':
808 1.1 christos tp = format_sup_reg ((insn >> 12) & 15, tp, with_reg_prefix);
809 1.1 christos break;
810 1.1 christos
811 1.1 christos case 'A':
812 1.1 christos if (with_reg_prefix)
813 1.1 christos *tp++ = REGISTER_PREFIX_CHAR;
814 1.1 christos *tp++ = 'a';
815 1.1 christos *tp++ = 'c';
816 1.1 christos *tp++ = 'r';
817 1.1 christos break;
818 1.1 christos
819 1.1 christos case '[':
820 1.1 christos case ']':
821 1.1 christos case ',':
822 1.1 christos *tp++ = *s;
823 1.1 christos break;
824 1.1 christos
825 1.1 christos case '!':
826 1.1 christos /* Ignore at this point; used at earlier stages to avoid
827 1.1 christos recognition if there's a prefix at something that in other
828 1.1 christos ways looks like a "pop". */
829 1.1 christos break;
830 1.1 christos
831 1.1 christos case 'd':
832 1.1 christos /* Ignore. This is an optional ".d " on the large one of
833 1.1 christos relaxable insns. */
834 1.1 christos break;
835 1.1 christos
836 1.1 christos case 'B':
837 1.1 christos /* This was the prefix that made this a "push". We've already
838 1.1 christos handled it by recognizing it, so signal that the prefix is
839 1.1 christos handled by setting it to NULL. */
840 1.1 christos prefix_opcodep = NULL;
841 1.1 christos break;
842 1.1 christos
843 1.1 christos case 'D':
844 1.1 christos case 'r':
845 1.1 christos tp = format_reg (disdata, insn & 15, tp, with_reg_prefix);
846 1.1 christos break;
847 1.1 christos
848 1.1 christos case 'R':
849 1.1 christos tp = format_reg (disdata, (insn >> 12) & 15, tp, with_reg_prefix);
850 1.1 christos break;
851 1.1 christos
852 1.1 christos case 'n':
853 1.1 christos {
854 1.1 christos /* Like N but pc-relative to the start of the insn. */
855 1.1 christos unsigned long number
856 1.1 christos = (buffer[2] + buffer[3] * 256 + buffer[4] * 65536
857 1.1 christos + buffer[5] * 0x1000000 + addr);
858 1.1 christos
859 1.1 christos /* Finish off and output previous formatted bytes. */
860 1.1 christos *tp = 0;
861 1.1 christos if (temp[0])
862 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
863 1.1 christos tp = temp;
864 1.1 christos
865 1.1 christos (*info->print_address_func) ((bfd_vma) number, info);
866 1.1 christos }
867 1.1 christos break;
868 1.1 christos
869 1.1 christos case 'u':
870 1.1 christos {
871 1.1 christos /* Like n but the offset is bits <3:0> in the instruction. */
872 1.1 christos unsigned long number = (buffer[0] & 0xf) * 2 + addr;
873 1.1 christos
874 1.1 christos /* Finish off and output previous formatted bytes. */
875 1.1 christos *tp = 0;
876 1.1 christos if (temp[0])
877 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
878 1.1 christos tp = temp;
879 1.1 christos
880 1.1 christos (*info->print_address_func) ((bfd_vma) number, info);
881 1.1 christos }
882 1.1 christos break;
883 1.1 christos
884 1.1 christos case 'N':
885 1.1 christos case 'y':
886 1.1 christos case 'Y':
887 1.1 christos case 'S':
888 1.1 christos case 's':
889 1.1 christos /* Any "normal" memory operand. */
890 1.1 christos if ((insn & 0x400) && (insn & 15) == 15 && prefix_opcodep == NULL)
891 1.1 christos {
892 1.1 christos /* We're looking at [pc+], i.e. we need to output an immediate
893 1.1 christos number, where the size can depend on different things. */
894 1.1 christos long number;
895 1.1 christos int signedp
896 1.1 christos = ((*cs == 'z' && (insn & 0x20))
897 1.1 christos || opcodep->match == BDAP_QUICK_OPCODE);
898 1.1 christos int nbytes;
899 1.1 christos
900 1.1 christos if (opcodep->imm_oprnd_size == SIZE_FIX_32)
901 1.1 christos nbytes = 4;
902 1.1 christos else if (opcodep->imm_oprnd_size == SIZE_SPEC_REG)
903 1.1 christos {
904 1.1 christos const struct cris_spec_reg *sregp
905 1.1 christos = spec_reg_info ((insn >> 12) & 15, disdata->distype);
906 1.1 christos
907 1.1 christos /* A NULL return should have been as a non-match earlier,
908 1.1 christos so catch it as an internal error in the error-case
909 1.1 christos below. */
910 1.1 christos if (sregp == NULL)
911 1.1 christos /* Whatever non-valid size. */
912 1.1 christos nbytes = 42;
913 1.1 christos else
914 1.1 christos /* PC is always incremented by a multiple of two.
915 1.1 christos For CRISv32, immediates are always 4 bytes for
916 1.1 christos special registers. */
917 1.1 christos nbytes = disdata->distype == cris_dis_v32
918 1.1 christos ? 4 : (sregp->reg_size + 1) & ~1;
919 1.1 christos }
920 1.1 christos else
921 1.1 christos {
922 1.1 christos int mode_size = 1 << ((insn >> 4) & (*cs == 'z' ? 1 : 3));
923 1.1 christos
924 1.1 christos if (mode_size == 1)
925 1.1 christos nbytes = 2;
926 1.1 christos else
927 1.1 christos nbytes = mode_size;
928 1.1 christos }
929 1.1 christos
930 1.1 christos switch (nbytes)
931 1.1 christos {
932 1.1 christos case 1:
933 1.1 christos number = buffer[2];
934 1.1 christos if (signedp && number > 127)
935 1.1 christos number -= 256;
936 1.1 christos break;
937 1.1 christos
938 1.1 christos case 2:
939 1.1 christos number = buffer[2] + buffer[3] * 256;
940 1.1 christos if (signedp && number > 32767)
941 1.1 christos number -= 65536;
942 1.1 christos break;
943 1.1 christos
944 1.1 christos case 4:
945 1.1 christos number
946 1.1 christos = buffer[2] + buffer[3] * 256 + buffer[4] * 65536
947 1.1 christos + buffer[5] * 0x1000000;
948 1.1 christos break;
949 1.1 christos
950 1.1 christos default:
951 1.1 christos strcpy (tp, "bug");
952 1.1 christos tp += 3;
953 1.1 christos number = 42;
954 1.1 christos }
955 1.1 christos
956 1.1 christos if ((*cs == 'z' && (insn & 0x20))
957 1.1 christos || (opcodep->match == BDAP_QUICK_OPCODE
958 1.1 christos && (nbytes <= 2 || buffer[1 + nbytes] == 0)))
959 1.1 christos tp = format_dec (number, tp, signedp);
960 1.1 christos else
961 1.1 christos {
962 1.1 christos unsigned int highbyte = (number >> 24) & 0xff;
963 1.1 christos
964 1.1 christos /* Either output this as an address or as a number. If it's
965 1.1 christos a dword with the same high-byte as the address of the
966 1.1 christos insn, assume it's an address, and also if it's a non-zero
967 1.1 christos non-0xff high-byte. If this is a jsr or a jump, then
968 1.1 christos it's definitely an address. */
969 1.1 christos if (nbytes == 4
970 1.1 christos && (highbyte == ((addr >> 24) & 0xff)
971 1.1 christos || (highbyte != 0 && highbyte != 0xff)
972 1.1 christos || info->insn_type == dis_branch
973 1.1 christos || info->insn_type == dis_jsr))
974 1.1 christos {
975 1.1 christos /* Finish off and output previous formatted bytes. */
976 1.1 christos *tp = 0;
977 1.1 christos tp = temp;
978 1.1 christos if (temp[0])
979 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
980 1.1 christos
981 1.1 christos (*info->print_address_func) ((bfd_vma) number, info);
982 1.1 christos
983 1.1 christos info->target = number;
984 1.1 christos }
985 1.1 christos else
986 1.1 christos tp = format_hex (number, tp, disdata);
987 1.1 christos }
988 1.1 christos }
989 1.1 christos else
990 1.1 christos {
991 1.1 christos /* Not an immediate number. Then this is a (possibly
992 1.1 christos prefixed) memory operand. */
993 1.1 christos if (info->insn_type != dis_nonbranch)
994 1.1 christos {
995 1.1 christos int mode_size
996 1.1 christos = 1 << ((insn >> 4)
997 1.1 christos & (opcodep->args[0] == 'z' ? 1 : 3));
998 1.1 christos int size;
999 1.1 christos info->insn_type = dis_dref;
1000 1.1 christos info->flags |= CRIS_DIS_FLAG_MEMREF;
1001 1.1 christos
1002 1.1 christos if (opcodep->imm_oprnd_size == SIZE_FIX_32)
1003 1.1 christos size = 4;
1004 1.1 christos else if (opcodep->imm_oprnd_size == SIZE_SPEC_REG)
1005 1.1 christos {
1006 1.1 christos const struct cris_spec_reg *sregp
1007 1.1 christos = spec_reg_info ((insn >> 12) & 15, disdata->distype);
1008 1.1 christos
1009 1.1 christos /* FIXME: Improve error handling; should have been caught
1010 1.1 christos earlier. */
1011 1.1 christos if (sregp == NULL)
1012 1.1 christos size = 4;
1013 1.1 christos else
1014 1.1 christos size = sregp->reg_size;
1015 1.1 christos }
1016 1.1 christos else
1017 1.1 christos size = mode_size;
1018 1.1 christos
1019 1.1 christos info->data_size = size;
1020 1.1 christos }
1021 1.1 christos
1022 1.1 christos *tp++ = '[';
1023 1.1 christos
1024 1.1 christos if (prefix_opcodep
1025 1.1 christos /* We don't match dip with a postincremented field
1026 1.1 christos as a side-effect address mode. */
1027 1.1 christos && ((insn & 0x400) == 0
1028 1.1 christos || prefix_opcodep->match != DIP_OPCODE))
1029 1.1 christos {
1030 1.1 christos if (insn & 0x400)
1031 1.1 christos {
1032 1.1 christos tp = format_reg (disdata, insn & 15, tp, with_reg_prefix);
1033 1.1 christos *tp++ = '=';
1034 1.1 christos }
1035 1.1 christos
1036 1.1 christos
1037 1.1 christos /* We mainly ignore the prefix format string when the
1038 1.1 christos address-mode syntax is output. */
1039 1.1 christos switch (prefix_opcodep->match)
1040 1.1 christos {
1041 1.1 christos case DIP_OPCODE:
1042 1.1 christos /* It's [r], [r+] or [pc+]. */
1043 1.1 christos if ((prefix_insn & 0x400) && (prefix_insn & 15) == 15)
1044 1.1 christos {
1045 1.1 christos /* It's [pc+]. This cannot possibly be anything
1046 1.1 christos but an address. */
1047 1.1 christos unsigned long number
1048 1.1 christos = prefix_buffer[2] + prefix_buffer[3] * 256
1049 1.1 christos + prefix_buffer[4] * 65536
1050 1.1 christos + prefix_buffer[5] * 0x1000000;
1051 1.1 christos
1052 1.1 christos info->target = (bfd_vma) number;
1053 1.1 christos
1054 1.1 christos /* Finish off and output previous formatted
1055 1.1 christos data. */
1056 1.1 christos *tp = 0;
1057 1.1 christos tp = temp;
1058 1.1 christos if (temp[0])
1059 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
1060 1.1 christos
1061 1.1 christos (*info->print_address_func) ((bfd_vma) number, info);
1062 1.1 christos }
1063 1.1 christos else
1064 1.1 christos {
1065 1.1 christos /* For a memref in an address, we use target2.
1066 1.1 christos In this case, target is zero. */
1067 1.1 christos info->flags
1068 1.1 christos |= (CRIS_DIS_FLAG_MEM_TARGET2_IS_REG
1069 1.1 christos | CRIS_DIS_FLAG_MEM_TARGET2_MEM);
1070 1.1 christos
1071 1.1 christos info->target2 = prefix_insn & 15;
1072 1.1 christos
1073 1.1 christos *tp++ = '[';
1074 1.1 christos tp = format_reg (disdata, prefix_insn & 15, tp,
1075 1.1 christos with_reg_prefix);
1076 1.1 christos if (prefix_insn & 0x400)
1077 1.1 christos *tp++ = '+';
1078 1.1 christos *tp++ = ']';
1079 1.1 christos }
1080 1.1 christos break;
1081 1.1 christos
1082 1.1 christos case BDAP_QUICK_OPCODE:
1083 1.1 christos {
1084 1.1 christos int number;
1085 1.1 christos
1086 1.1 christos number = prefix_buffer[0];
1087 1.1 christos if (number > 127)
1088 1.1 christos number -= 256;
1089 1.1 christos
1090 1.1 christos /* Output "reg+num" or, if num < 0, "reg-num". */
1091 1.1 christos tp = format_reg (disdata, (prefix_insn >> 12) & 15, tp,
1092 1.1 christos with_reg_prefix);
1093 1.1 christos if (number >= 0)
1094 1.1 christos *tp++ = '+';
1095 1.1 christos tp = format_dec (number, tp, 1);
1096 1.1 christos
1097 1.1 christos info->flags |= CRIS_DIS_FLAG_MEM_TARGET_IS_REG;
1098 1.1 christos info->target = (prefix_insn >> 12) & 15;
1099 1.1 christos info->target2 = (bfd_vma) number;
1100 1.1 christos break;
1101 1.1 christos }
1102 1.1 christos
1103 1.1 christos case BIAP_OPCODE:
1104 1.1 christos /* Output "r+R.m". */
1105 1.1 christos tp = format_reg (disdata, prefix_insn & 15, tp,
1106 1.1 christos with_reg_prefix);
1107 1.1 christos *tp++ = '+';
1108 1.1 christos tp = format_reg (disdata, (prefix_insn >> 12) & 15, tp,
1109 1.1 christos with_reg_prefix);
1110 1.1 christos *tp++ = '.';
1111 1.1 christos *tp++ = mode_char[(prefix_insn >> 4) & 3];
1112 1.1 christos
1113 1.1 christos info->flags
1114 1.1 christos |= (CRIS_DIS_FLAG_MEM_TARGET2_IS_REG
1115 1.1 christos | CRIS_DIS_FLAG_MEM_TARGET_IS_REG
1116 1.1 christos
1117 1.1 christos | ((prefix_insn & 0x8000)
1118 1.1 christos ? CRIS_DIS_FLAG_MEM_TARGET2_MULT4
1119 1.1 christos : ((prefix_insn & 0x8000)
1120 1.1 christos ? CRIS_DIS_FLAG_MEM_TARGET2_MULT2 : 0)));
1121 1.1 christos
1122 1.1 christos /* Is it the casejump? It's a "adds.w [pc+r%d.w],pc". */
1123 1.1 christos if (insn == 0xf83f && (prefix_insn & ~0xf000) == 0x55f)
1124 1.1 christos /* Then start interpreting data as offsets. */
1125 1.1 christos case_offset_counter = no_of_case_offsets;
1126 1.1 christos break;
1127 1.1 christos
1128 1.1 christos case BDAP_INDIR_OPCODE:
1129 1.1 christos /* Output "r+s.m", or, if "s" is [pc+], "r+s" or
1130 1.1 christos "r-s". */
1131 1.1 christos tp = format_reg (disdata, (prefix_insn >> 12) & 15, tp,
1132 1.1 christos with_reg_prefix);
1133 1.1 christos
1134 1.1 christos if ((prefix_insn & 0x400) && (prefix_insn & 15) == 15)
1135 1.1 christos {
1136 1.1 christos long number;
1137 1.1 christos unsigned int nbytes;
1138 1.1 christos
1139 1.1 christos /* It's a value. Get its size. */
1140 1.1 christos int mode_size = 1 << ((prefix_insn >> 4) & 3);
1141 1.1 christos
1142 1.1 christos if (mode_size == 1)
1143 1.1 christos nbytes = 2;
1144 1.1 christos else
1145 1.1 christos nbytes = mode_size;
1146 1.1 christos
1147 1.1 christos switch (nbytes)
1148 1.1 christos {
1149 1.1 christos case 1:
1150 1.1 christos number = prefix_buffer[2];
1151 1.1 christos if (number > 127)
1152 1.1 christos number -= 256;
1153 1.1 christos break;
1154 1.1 christos
1155 1.1 christos case 2:
1156 1.1 christos number = prefix_buffer[2] + prefix_buffer[3] * 256;
1157 1.1 christos if (number > 32767)
1158 1.1 christos number -= 65536;
1159 1.1 christos break;
1160 1.1 christos
1161 1.1 christos case 4:
1162 1.1 christos number
1163 1.1 christos = prefix_buffer[2] + prefix_buffer[3] * 256
1164 1.1 christos + prefix_buffer[4] * 65536
1165 1.1 christos + prefix_buffer[5] * 0x1000000;
1166 1.1 christos break;
1167 1.1 christos
1168 1.1 christos default:
1169 1.1 christos strcpy (tp, "bug");
1170 1.1 christos tp += 3;
1171 1.1 christos number = 42;
1172 1.1 christos }
1173 1.1 christos
1174 1.1 christos info->flags |= CRIS_DIS_FLAG_MEM_TARGET_IS_REG;
1175 1.1 christos info->target2 = (bfd_vma) number;
1176 1.1 christos
1177 1.1 christos /* If the size is dword, then assume it's an
1178 1.1 christos address. */
1179 1.1 christos if (nbytes == 4)
1180 1.1 christos {
1181 1.1 christos /* Finish off and output previous formatted
1182 1.1 christos bytes. */
1183 1.1 christos *tp++ = '+';
1184 1.1 christos *tp = 0;
1185 1.1 christos tp = temp;
1186 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
1187 1.1 christos
1188 1.1 christos (*info->print_address_func) ((bfd_vma) number, info);
1189 1.1 christos }
1190 1.1 christos else
1191 1.1 christos {
1192 1.1 christos if (number >= 0)
1193 1.1 christos *tp++ = '+';
1194 1.1 christos tp = format_dec (number, tp, 1);
1195 1.1 christos }
1196 1.1 christos }
1197 1.1 christos else
1198 1.1 christos {
1199 1.1 christos /* Output "r+[R].m" or "r+[R+].m". */
1200 1.1 christos *tp++ = '+';
1201 1.1 christos *tp++ = '[';
1202 1.1 christos tp = format_reg (disdata, prefix_insn & 15, tp,
1203 1.1 christos with_reg_prefix);
1204 1.1 christos if (prefix_insn & 0x400)
1205 1.1 christos *tp++ = '+';
1206 1.1 christos *tp++ = ']';
1207 1.1 christos *tp++ = '.';
1208 1.1 christos *tp++ = mode_char[(prefix_insn >> 4) & 3];
1209 1.1 christos
1210 1.1 christos info->flags
1211 1.1 christos |= (CRIS_DIS_FLAG_MEM_TARGET2_IS_REG
1212 1.1 christos | CRIS_DIS_FLAG_MEM_TARGET2_MEM
1213 1.1 christos | CRIS_DIS_FLAG_MEM_TARGET_IS_REG
1214 1.1 christos
1215 1.1 christos | (((prefix_insn >> 4) == 2)
1216 1.1 christos ? 0
1217 1.1 christos : (((prefix_insn >> 4) & 3) == 1
1218 1.1 christos ? CRIS_DIS_FLAG_MEM_TARGET2_MEM_WORD
1219 1.1 christos : CRIS_DIS_FLAG_MEM_TARGET2_MEM_BYTE)));
1220 1.1 christos }
1221 1.1 christos break;
1222 1.1 christos
1223 1.1 christos default:
1224 1.1 christos (*info->fprintf_func) (info->stream, "?prefix-bug");
1225 1.1 christos }
1226 1.1 christos
1227 1.1 christos /* To mark that the prefix is used, reset it. */
1228 1.1 christos prefix_opcodep = NULL;
1229 1.1 christos }
1230 1.1 christos else
1231 1.1 christos {
1232 1.1 christos tp = format_reg (disdata, insn & 15, tp, with_reg_prefix);
1233 1.1 christos
1234 1.1 christos info->flags |= CRIS_DIS_FLAG_MEM_TARGET_IS_REG;
1235 1.1 christos info->target = insn & 15;
1236 1.1 christos
1237 1.1 christos if (insn & 0x400)
1238 1.1 christos *tp++ = '+';
1239 1.1 christos }
1240 1.1 christos *tp++ = ']';
1241 1.1 christos }
1242 1.1 christos break;
1243 1.1 christos
1244 1.1 christos case 'x':
1245 1.1 christos tp = format_reg (disdata, (insn >> 12) & 15, tp, with_reg_prefix);
1246 1.1 christos *tp++ = '.';
1247 1.1 christos *tp++ = mode_char[(insn >> 4) & 3];
1248 1.1 christos break;
1249 1.1 christos
1250 1.1 christos case 'I':
1251 1.1 christos tp = format_dec (insn & 63, tp, 0);
1252 1.1 christos break;
1253 1.1 christos
1254 1.1 christos case 'b':
1255 1.1 christos {
1256 1.1 christos int where = buffer[2] + buffer[3] * 256;
1257 1.1 christos
1258 1.1 christos if (where > 32767)
1259 1.1 christos where -= 65536;
1260 1.1 christos
1261 1.1 christos where += addr + ((disdata->distype == cris_dis_v32) ? 0 : 4);
1262 1.1 christos
1263 1.1 christos if (insn == BA_PC_INCR_OPCODE)
1264 1.1 christos info->insn_type = dis_branch;
1265 1.1 christos else
1266 1.1 christos info->insn_type = dis_condbranch;
1267 1.1 christos
1268 1.1 christos info->target = (bfd_vma) where;
1269 1.1 christos
1270 1.1 christos *tp = 0;
1271 1.1 christos tp = temp;
1272 1.1 christos (*info->fprintf_func) (info->stream, "%s%s ",
1273 1.1 christos temp, cris_cc_strings[insn >> 12]);
1274 1.1 christos
1275 1.1 christos (*info->print_address_func) ((bfd_vma) where, info);
1276 1.1 christos }
1277 1.1 christos break;
1278 1.1 christos
1279 1.1 christos case 'c':
1280 1.1 christos tp = format_dec (insn & 31, tp, 0);
1281 1.1 christos break;
1282 1.1 christos
1283 1.1 christos case 'C':
1284 1.1 christos tp = format_dec (insn & 15, tp, 0);
1285 1.1 christos break;
1286 1.1 christos
1287 1.1 christos case 'o':
1288 1.1 christos {
1289 1.1 christos long offset = insn & 0xfe;
1290 1.1 christos bfd_vma target;
1291 1.1 christos
1292 1.1 christos if (insn & 1)
1293 1.1 christos offset |= ~0xff;
1294 1.1 christos
1295 1.1 christos if (opcodep->match == BA_QUICK_OPCODE)
1296 1.1 christos info->insn_type = dis_branch;
1297 1.1 christos else
1298 1.1 christos info->insn_type = dis_condbranch;
1299 1.1 christos
1300 1.1 christos target = addr + ((disdata->distype == cris_dis_v32) ? 0 : 2) + offset;
1301 1.1 christos info->target = target;
1302 1.1 christos *tp = 0;
1303 1.1 christos tp = temp;
1304 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
1305 1.1 christos (*info->print_address_func) (target, info);
1306 1.1 christos }
1307 1.1 christos break;
1308 1.1 christos
1309 1.1 christos case 'Q':
1310 1.1 christos case 'O':
1311 1.1 christos {
1312 1.1 christos long number = buffer[0];
1313 1.1 christos
1314 1.1 christos if (number > 127)
1315 1.1 christos number = number - 256;
1316 1.1 christos
1317 1.1 christos tp = format_dec (number, tp, 1);
1318 1.1 christos *tp++ = ',';
1319 1.1 christos tp = format_reg (disdata, (insn >> 12) & 15, tp, with_reg_prefix);
1320 1.1 christos }
1321 1.1 christos break;
1322 1.1 christos
1323 1.1 christos case 'f':
1324 1.1 christos tp = print_flags (disdata, insn, tp);
1325 1.1 christos break;
1326 1.1 christos
1327 1.1 christos case 'i':
1328 1.1 christos tp = format_dec ((insn & 32) ? (insn & 31) | ~31L : insn & 31, tp, 1);
1329 1.1 christos break;
1330 1.1 christos
1331 1.1 christos case 'P':
1332 1.1 christos {
1333 1.1 christos const struct cris_spec_reg *sregp
1334 1.1 christos = spec_reg_info ((insn >> 12) & 15, disdata->distype);
1335 1.1 christos
1336 1.1 christos if (sregp->name == NULL)
1337 1.1 christos /* Should have been caught as a non-match eariler. */
1338 1.1 christos *tp++ = '?';
1339 1.1 christos else
1340 1.1 christos {
1341 1.1 christos if (with_reg_prefix)
1342 1.1 christos *tp++ = REGISTER_PREFIX_CHAR;
1343 1.1 christos strcpy (tp, sregp->name);
1344 1.1 christos tp += strlen (tp);
1345 1.1 christos }
1346 1.1 christos }
1347 1.1 christos break;
1348 1.1 christos
1349 1.1 christos default:
1350 1.1 christos strcpy (tp, "???");
1351 1.1 christos tp += 3;
1352 1.1 christos }
1353 1.1 christos }
1354 1.1 christos
1355 1.1 christos *tp = 0;
1356 1.1 christos
1357 1.1 christos if (prefix_opcodep)
1358 1.1 christos (*info->fprintf_func) (info->stream, " (OOPS unused prefix \"%s: %s\")",
1359 1.1 christos prefix_opcodep->name, prefix_opcodep->args);
1360 1.1 christos
1361 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
1362 1.1 christos
1363 1.1 christos /* Get info for matching case-tables, if we don't have any active.
1364 1.1 christos We assume that the last constant seen is used; either in the insn
1365 1.1 christos itself or in a "move.d const,rN, sub.d rN,rM"-like sequence. */
1366 1.1 christos if (TRACE_CASE && case_offset_counter == 0)
1367 1.1 christos {
1368 1.1 christos if (CONST_STRNEQ (opcodep->name, "sub"))
1369 1.1 christos case_offset = last_immediate;
1370 1.1 christos
1371 1.1 christos /* It could also be an "add", if there are negative case-values. */
1372 1.1 christos else if (CONST_STRNEQ (opcodep->name, "add"))
1373 1.1 christos /* The first case is the negated operand to the add. */
1374 1.1 christos case_offset = -last_immediate;
1375 1.1 christos
1376 1.1 christos /* A bound insn will tell us the number of cases. */
1377 1.1 christos else if (CONST_STRNEQ (opcodep->name, "bound"))
1378 1.1 christos no_of_case_offsets = last_immediate + 1;
1379 1.1 christos
1380 1.1 christos /* A jump or jsr or branch breaks the chain of insns for a
1381 1.1 christos case-table, so assume default first-case again. */
1382 1.1 christos else if (info->insn_type == dis_jsr
1383 1.1 christos || info->insn_type == dis_branch
1384 1.1 christos || info->insn_type == dis_condbranch)
1385 1.1 christos case_offset = 0;
1386 1.1 christos }
1387 1.1 christos }
1388 1.1 christos
1389 1.1 christos
1390 1.1 christos /* Print the CRIS instruction at address memaddr on stream. Returns
1391 1.1 christos length of the instruction, in bytes. Prefix register names with `$' if
1392 1.1 christos WITH_REG_PREFIX. */
1393 1.1 christos
1394 1.1 christos static int
1395 1.1 christos print_insn_cris_generic (bfd_vma memaddr,
1396 1.1 christos disassemble_info *info,
1397 1.1 christos bfd_boolean with_reg_prefix)
1398 1.1 christos {
1399 1.1 christos int nbytes;
1400 1.1 christos unsigned int insn;
1401 1.1 christos const struct cris_opcode *matchedp;
1402 1.1 christos int advance = 0;
1403 1.1 christos struct cris_disasm_data *disdata
1404 1.1 christos = (struct cris_disasm_data *) info->private_data;
1405 1.1 christos
1406 1.1 christos /* No instruction will be disassembled as longer than this number of
1407 1.1 christos bytes; stacked prefixes will not be expanded. */
1408 1.1 christos unsigned char buffer[MAX_BYTES_PER_CRIS_INSN];
1409 1.1 christos unsigned char *bufp;
1410 1.1 christos int status = 0;
1411 1.1 christos bfd_vma addr;
1412 1.1 christos
1413 1.1 christos /* There will be an "out of range" error after the last instruction.
1414 1.1 christos Reading pairs of bytes in decreasing number, we hope that we will get
1415 1.1 christos at least the amount that we will consume.
1416 1.1 christos
1417 1.1 christos If we can't get any data, or we do not get enough data, we print
1418 1.1 christos the error message. */
1419 1.1 christos
1420 1.1 christos for (nbytes = MAX_BYTES_PER_CRIS_INSN; nbytes > 0; nbytes -= 2)
1421 1.1 christos {
1422 1.1 christos status = (*info->read_memory_func) (memaddr, buffer, nbytes, info);
1423 1.1 christos if (status == 0)
1424 1.1 christos break;
1425 1.1 christos }
1426 1.1 christos
1427 1.1 christos /* If we did not get all we asked for, then clear the rest.
1428 1.1 christos Hopefully this makes a reproducible result in case of errors. */
1429 1.1 christos if (nbytes != MAX_BYTES_PER_CRIS_INSN)
1430 1.1 christos memset (buffer + nbytes, 0, MAX_BYTES_PER_CRIS_INSN - nbytes);
1431 1.1 christos
1432 1.1 christos addr = memaddr;
1433 1.1 christos bufp = buffer;
1434 1.1 christos
1435 1.1 christos /* Set some defaults for the insn info. */
1436 1.1 christos info->insn_info_valid = 1;
1437 1.1 christos info->branch_delay_insns = 0;
1438 1.1 christos info->data_size = 0;
1439 1.1 christos info->insn_type = dis_nonbranch;
1440 1.1 christos info->flags = 0;
1441 1.1 christos info->target = 0;
1442 1.1 christos info->target2 = 0;
1443 1.1 christos
1444 1.1 christos /* If we got any data, disassemble it. */
1445 1.1 christos if (nbytes != 0)
1446 1.1 christos {
1447 1.1 christos matchedp = NULL;
1448 1.1 christos
1449 1.1 christos insn = bufp[0] + bufp[1] * 256;
1450 1.1 christos
1451 1.1 christos /* If we're in a case-table, don't disassemble the offsets. */
1452 1.1 christos if (TRACE_CASE && case_offset_counter != 0)
1453 1.1 christos {
1454 1.1 christos info->insn_type = dis_noninsn;
1455 1.1 christos advance += 2;
1456 1.1 christos
1457 1.1 christos /* If to print data as offsets, then shortcut here. */
1458 1.1 christos (*info->fprintf_func) (info->stream, "case %ld%s: -> ",
1459 1.1 christos case_offset + no_of_case_offsets
1460 1.1 christos - case_offset_counter,
1461 1.1 christos case_offset_counter == 1 ? "/default" :
1462 1.1 christos "");
1463 1.1 christos
1464 1.1 christos (*info->print_address_func) ((bfd_vma)
1465 1.1 christos ((short) (insn)
1466 1.1 christos + (long) (addr
1467 1.1 christos - (no_of_case_offsets
1468 1.1 christos - case_offset_counter)
1469 1.1 christos * 2)), info);
1470 1.1 christos case_offset_counter--;
1471 1.1 christos
1472 1.1 christos /* The default case start (without a "sub" or "add") must be
1473 1.1 christos zero. */
1474 1.1 christos if (case_offset_counter == 0)
1475 1.1 christos case_offset = 0;
1476 1.1 christos }
1477 1.1 christos else if (insn == 0)
1478 1.1 christos {
1479 1.1 christos /* We're often called to disassemble zeroes. While this is a
1480 1.1 christos valid "bcc .+2" insn, it is also useless enough and enough
1481 1.1 christos of a nuiscance that we will just output "bcc .+2" for it
1482 1.1 christos and signal it as a noninsn. */
1483 1.1 christos (*info->fprintf_func) (info->stream,
1484 1.1 christos disdata->distype == cris_dis_v32
1485 1.1 christos ? "bcc ." : "bcc .+2");
1486 1.1 christos info->insn_type = dis_noninsn;
1487 1.1 christos advance += 2;
1488 1.1 christos }
1489 1.1 christos else
1490 1.1 christos {
1491 1.1 christos const struct cris_opcode *prefix_opcodep = NULL;
1492 1.1 christos unsigned char *prefix_buffer = bufp;
1493 1.1 christos unsigned int prefix_insn = insn;
1494 1.1 christos int prefix_size = 0;
1495 1.1 christos
1496 1.1 christos matchedp = get_opcode_entry (insn, NO_CRIS_PREFIX, disdata);
1497 1.1 christos
1498 1.1 christos /* Check if we're supposed to write out prefixes as address
1499 1.1 christos modes and if this was a prefix. */
1500 1.1 christos if (matchedp != NULL && PARSE_PREFIX && matchedp->args[0] == 'p')
1501 1.1 christos {
1502 1.1 christos /* If it's a prefix, put it into the prefix vars and get the
1503 1.1 christos main insn. */
1504 1.1 christos prefix_size = bytes_to_skip (prefix_insn, matchedp,
1505 1.1 christos disdata->distype, NULL);
1506 1.1 christos prefix_opcodep = matchedp;
1507 1.1 christos
1508 1.1 christos insn = bufp[prefix_size] + bufp[prefix_size + 1] * 256;
1509 1.1 christos matchedp = get_opcode_entry (insn, prefix_insn, disdata);
1510 1.1 christos
1511 1.1 christos if (matchedp != NULL)
1512 1.1 christos {
1513 1.1 christos addr += prefix_size;
1514 1.1 christos bufp += prefix_size;
1515 1.1 christos advance += prefix_size;
1516 1.1 christos }
1517 1.1 christos else
1518 1.1 christos {
1519 1.1 christos /* The "main" insn wasn't valid, at least not when
1520 1.1 christos prefixed. Put back things enough to output the
1521 1.1 christos prefix insn only, as a normal insn. */
1522 1.1 christos matchedp = prefix_opcodep;
1523 1.1 christos insn = prefix_insn;
1524 1.1 christos prefix_opcodep = NULL;
1525 1.1 christos }
1526 1.1 christos }
1527 1.1 christos
1528 1.1 christos if (matchedp == NULL)
1529 1.1 christos {
1530 1.1 christos (*info->fprintf_func) (info->stream, "??0x%x", insn);
1531 1.1 christos advance += 2;
1532 1.1 christos
1533 1.1 christos info->insn_type = dis_noninsn;
1534 1.1 christos }
1535 1.1 christos else
1536 1.1 christos {
1537 1.1 christos advance
1538 1.1 christos += bytes_to_skip (insn, matchedp, disdata->distype,
1539 1.1 christos prefix_opcodep);
1540 1.1 christos
1541 1.1 christos /* The info_type and assorted fields will be set according
1542 1.1 christos to the operands. */
1543 1.1 christos print_with_operands (matchedp, insn, bufp, addr, info,
1544 1.1 christos prefix_opcodep, prefix_insn,
1545 1.1 christos prefix_buffer, with_reg_prefix);
1546 1.1 christos }
1547 1.1 christos }
1548 1.1 christos }
1549 1.1 christos else
1550 1.1 christos info->insn_type = dis_noninsn;
1551 1.1 christos
1552 1.1 christos /* If we read less than MAX_BYTES_PER_CRIS_INSN, i.e. we got an error
1553 1.1 christos status when reading that much, and the insn decoding indicated a
1554 1.1 christos length exceeding what we read, there is an error. */
1555 1.1 christos if (status != 0 && (nbytes == 0 || advance > nbytes))
1556 1.1 christos {
1557 1.1 christos (*info->memory_error_func) (status, memaddr, info);
1558 1.1 christos return -1;
1559 1.1 christos }
1560 1.1 christos
1561 1.1 christos /* Max supported insn size with one folded prefix insn. */
1562 1.1 christos info->bytes_per_line = MAX_BYTES_PER_CRIS_INSN;
1563 1.1 christos
1564 1.1 christos /* I would like to set this to a fixed value larger than the actual
1565 1.1 christos number of bytes to print in order to avoid spaces between bytes,
1566 1.1 christos but objdump.c (2.9.1) does not like that, so we print 16-bit
1567 1.1 christos chunks, which is the next choice. */
1568 1.1 christos info->bytes_per_chunk = 2;
1569 1.1 christos
1570 1.1 christos /* Printing bytes in order of increasing addresses makes sense,
1571 1.1 christos especially on a little-endian target.
1572 1.1 christos This is completely the opposite of what you think; setting this to
1573 1.1 christos BFD_ENDIAN_LITTLE will print bytes in order N..0 rather than the 0..N
1574 1.1 christos we want. */
1575 1.1 christos info->display_endian = BFD_ENDIAN_BIG;
1576 1.1 christos
1577 1.1 christos return advance;
1578 1.1 christos }
1579 1.1 christos
1580 1.1 christos /* Disassemble, prefixing register names with `$'. CRIS v0..v10. */
1581 1.1 christos
1582 1.1 christos static int
1583 1.1 christos print_insn_cris_with_register_prefix (bfd_vma vma,
1584 1.1 christos disassemble_info *info)
1585 1.1 christos {
1586 1.1 christos if (info->private_data == NULL
1587 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_v0_v10))
1588 1.1 christos return -1;
1589 1.1 christos return print_insn_cris_generic (vma, info, TRUE);
1590 1.1 christos }
1591 1.1 christos
1592 1.1 christos /* Disassemble, prefixing register names with `$'. CRIS v32. */
1593 1.1 christos
1594 1.1 christos static int
1595 1.1 christos print_insn_crisv32_with_register_prefix (bfd_vma vma,
1596 1.1 christos disassemble_info *info)
1597 1.1 christos {
1598 1.1 christos if (info->private_data == NULL
1599 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_v32))
1600 1.1 christos return -1;
1601 1.1 christos return print_insn_cris_generic (vma, info, TRUE);
1602 1.1 christos }
1603 1.1 christos
1604 1.1 christos /* Disassemble, prefixing register names with `$'.
1605 1.1 christos Common v10 and v32 subset. */
1606 1.1 christos
1607 1.1 christos static int
1608 1.1 christos print_insn_crisv10_v32_with_register_prefix (bfd_vma vma,
1609 1.1 christos disassemble_info *info)
1610 1.1 christos {
1611 1.1 christos if (info->private_data == NULL
1612 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_common_v10_v32))
1613 1.1 christos return -1;
1614 1.1 christos return print_insn_cris_generic (vma, info, TRUE);
1615 1.1 christos }
1616 1.1 christos
1617 1.1 christos /* Disassemble, no prefixes on register names. CRIS v0..v10. */
1618 1.1 christos
1619 1.1 christos static int
1620 1.1 christos print_insn_cris_without_register_prefix (bfd_vma vma,
1621 1.1 christos disassemble_info *info)
1622 1.1 christos {
1623 1.1 christos if (info->private_data == NULL
1624 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_v0_v10))
1625 1.1 christos return -1;
1626 1.1 christos return print_insn_cris_generic (vma, info, FALSE);
1627 1.1 christos }
1628 1.1 christos
1629 1.1 christos /* Disassemble, no prefixes on register names. CRIS v32. */
1630 1.1 christos
1631 1.1 christos static int
1632 1.1 christos print_insn_crisv32_without_register_prefix (bfd_vma vma,
1633 1.1 christos disassemble_info *info)
1634 1.1 christos {
1635 1.1 christos if (info->private_data == NULL
1636 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_v32))
1637 1.1 christos return -1;
1638 1.1 christos return print_insn_cris_generic (vma, info, FALSE);
1639 1.1 christos }
1640 1.1 christos
1641 1.1 christos /* Disassemble, no prefixes on register names.
1642 1.1 christos Common v10 and v32 subset. */
1643 1.1 christos
1644 1.1 christos static int
1645 1.1 christos print_insn_crisv10_v32_without_register_prefix (bfd_vma vma,
1646 1.1 christos disassemble_info *info)
1647 1.1 christos {
1648 1.1 christos if (info->private_data == NULL
1649 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_common_v10_v32))
1650 1.1 christos return -1;
1651 1.1 christos return print_insn_cris_generic (vma, info, FALSE);
1652 1.1 christos }
1653 1.1 christos
1654 1.1 christos /* Return a disassembler-function that prints registers with a `$' prefix,
1655 1.1 christos or one that prints registers without a prefix.
1656 1.1 christos FIXME: We should improve the solution to avoid the multitude of
1657 1.1 christos functions seen above. */
1658 1.1 christos
1659 1.1 christos disassembler_ftype
1660 1.1 christos cris_get_disassembler (bfd *abfd)
1661 1.1 christos {
1662 1.1 christos /* If there's no bfd in sight, we return what is valid as input in all
1663 1.1 christos contexts if fed back to the assembler: disassembly *with* register
1664 1.1 christos prefix. Unfortunately this will be totally wrong for v32. */
1665 1.1 christos if (abfd == NULL)
1666 1.1 christos return print_insn_cris_with_register_prefix;
1667 1.1 christos
1668 1.1 christos if (bfd_get_symbol_leading_char (abfd) == 0)
1669 1.1 christos {
1670 1.1 christos if (bfd_get_mach (abfd) == bfd_mach_cris_v32)
1671 1.1 christos return print_insn_crisv32_with_register_prefix;
1672 1.1 christos if (bfd_get_mach (abfd) == bfd_mach_cris_v10_v32)
1673 1.1 christos return print_insn_crisv10_v32_with_register_prefix;
1674 1.1 christos
1675 1.1 christos /* We default to v10. This may be specifically specified in the
1676 1.1 christos bfd mach, but is also the default setting. */
1677 1.1 christos return print_insn_cris_with_register_prefix;
1678 1.1 christos }
1679 1.1 christos
1680 1.1 christos if (bfd_get_mach (abfd) == bfd_mach_cris_v32)
1681 1.1 christos return print_insn_crisv32_without_register_prefix;
1682 1.1 christos if (bfd_get_mach (abfd) == bfd_mach_cris_v10_v32)
1683 1.1 christos return print_insn_crisv10_v32_without_register_prefix;
1684 1.1 christos return print_insn_cris_without_register_prefix;
1685 1.1 christos }
1686 1.1 christos
1687 1.1 christos /* Local variables:
1688 1.1 christos eval: (c-set-style "gnu")
1689 1.1 christos indent-tabs-mode: t
1690 End: */
1691