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