cris-dis.c revision 1.1.1.7 1 1.1 christos /* Disassembler code for CRIS.
2 1.1.1.7 christos Copyright (C) 2000-2020 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.1.2 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.1.1.4 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.1.7 christos /* Like N but pc-relative to the start of the insn. */
854 1.1.1.7 christos int32_t number = (buffer[2] + buffer[3] * 256 + buffer[4] * 65536
855 1.1 christos + buffer[5] * 0x1000000u);
856 1.1 christos
857 1.1 christos /* Finish off and output previous formatted bytes. */
858 1.1 christos *tp = 0;
859 1.1 christos if (temp[0])
860 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
861 1.1 christos tp = temp;
862 1.1.1.7 christos
863 1.1 christos (*info->print_address_func) (addr + number, info);
864 1.1 christos }
865 1.1 christos break;
866 1.1 christos
867 1.1 christos case 'u':
868 1.1 christos {
869 1.1.1.7 christos /* Like n but the offset is bits <3:0> in the instruction. */
870 1.1 christos unsigned int number = (buffer[0] & 0xf) * 2;
871 1.1 christos
872 1.1 christos /* Finish off and output previous formatted bytes. */
873 1.1 christos *tp = 0;
874 1.1 christos if (temp[0])
875 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
876 1.1 christos tp = temp;
877 1.1.1.7 christos
878 1.1 christos (*info->print_address_func) (addr + number, info);
879 1.1 christos }
880 1.1 christos break;
881 1.1 christos
882 1.1 christos case 'N':
883 1.1 christos case 'y':
884 1.1 christos case 'Y':
885 1.1 christos case 'S':
886 1.1 christos case 's':
887 1.1 christos /* Any "normal" memory operand. */
888 1.1 christos if ((insn & 0x400) && (insn & 15) == 15 && prefix_opcodep == NULL)
889 1.1 christos {
890 1.1 christos /* We're looking at [pc+], i.e. we need to output an immediate
891 1.1.1.7 christos number, where the size can depend on different things. */
892 1.1 christos int32_t number;
893 1.1 christos int signedp
894 1.1 christos = ((*cs == 'z' && (insn & 0x20))
895 1.1 christos || opcodep->match == BDAP_QUICK_OPCODE);
896 1.1 christos int nbytes;
897 1.1 christos
898 1.1 christos if (opcodep->imm_oprnd_size == SIZE_FIX_32)
899 1.1 christos nbytes = 4;
900 1.1 christos else if (opcodep->imm_oprnd_size == SIZE_SPEC_REG)
901 1.1 christos {
902 1.1 christos const struct cris_spec_reg *sregp
903 1.1 christos = spec_reg_info ((insn >> 12) & 15, disdata->distype);
904 1.1 christos
905 1.1 christos /* A NULL return should have been as a non-match earlier,
906 1.1 christos so catch it as an internal error in the error-case
907 1.1 christos below. */
908 1.1 christos if (sregp == NULL)
909 1.1 christos /* Whatever non-valid size. */
910 1.1 christos nbytes = 42;
911 1.1 christos else
912 1.1 christos /* PC is always incremented by a multiple of two.
913 1.1 christos For CRISv32, immediates are always 4 bytes for
914 1.1 christos special registers. */
915 1.1 christos nbytes = disdata->distype == cris_dis_v32
916 1.1 christos ? 4 : (sregp->reg_size + 1) & ~1;
917 1.1 christos }
918 1.1 christos else
919 1.1 christos {
920 1.1 christos int mode_size = 1 << ((insn >> 4) & (*cs == 'z' ? 1 : 3));
921 1.1 christos
922 1.1 christos if (mode_size == 1)
923 1.1 christos nbytes = 2;
924 1.1 christos else
925 1.1 christos nbytes = mode_size;
926 1.1 christos }
927 1.1 christos
928 1.1 christos switch (nbytes)
929 1.1 christos {
930 1.1 christos case 1:
931 1.1 christos number = buffer[2];
932 1.1 christos if (signedp && number > 127)
933 1.1 christos number -= 256;
934 1.1 christos break;
935 1.1 christos
936 1.1 christos case 2:
937 1.1 christos number = buffer[2] + buffer[3] * 256;
938 1.1 christos if (signedp && number > 32767)
939 1.1 christos number -= 65536;
940 1.1 christos break;
941 1.1 christos
942 1.1.1.7 christos case 4:
943 1.1.1.7 christos number = (buffer[2] + buffer[3] * 256 + buffer[4] * 65536
944 1.1 christos + buffer[5] * 0x1000000u);
945 1.1 christos break;
946 1.1 christos
947 1.1 christos default:
948 1.1 christos strcpy (tp, "bug");
949 1.1 christos tp += 3;
950 1.1 christos number = 42;
951 1.1 christos }
952 1.1 christos
953 1.1 christos if ((*cs == 'z' && (insn & 0x20))
954 1.1 christos || (opcodep->match == BDAP_QUICK_OPCODE
955 1.1 christos && (nbytes <= 2 || buffer[1 + nbytes] == 0)))
956 1.1 christos tp = format_dec (number, tp, signedp);
957 1.1 christos else
958 1.1 christos {
959 1.1 christos unsigned int highbyte = (number >> 24) & 0xff;
960 1.1 christos
961 1.1 christos /* Either output this as an address or as a number. If it's
962 1.1 christos a dword with the same high-byte as the address of the
963 1.1 christos insn, assume it's an address, and also if it's a non-zero
964 1.1 christos non-0xff high-byte. If this is a jsr or a jump, then
965 1.1 christos it's definitely an address. */
966 1.1 christos if (nbytes == 4
967 1.1 christos && (highbyte == ((addr >> 24) & 0xff)
968 1.1 christos || (highbyte != 0 && highbyte != 0xff)
969 1.1 christos || info->insn_type == dis_branch
970 1.1 christos || info->insn_type == dis_jsr))
971 1.1 christos {
972 1.1 christos /* Finish off and output previous formatted bytes. */
973 1.1 christos *tp = 0;
974 1.1 christos tp = temp;
975 1.1 christos if (temp[0])
976 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
977 1.1 christos
978 1.1 christos (*info->print_address_func) ((bfd_vma) number, info);
979 1.1 christos
980 1.1 christos info->target = number;
981 1.1 christos }
982 1.1 christos else
983 1.1 christos tp = format_hex (number, tp, disdata);
984 1.1 christos }
985 1.1 christos }
986 1.1 christos else
987 1.1 christos {
988 1.1 christos /* Not an immediate number. Then this is a (possibly
989 1.1 christos prefixed) memory operand. */
990 1.1 christos if (info->insn_type != dis_nonbranch)
991 1.1 christos {
992 1.1 christos int mode_size
993 1.1 christos = 1 << ((insn >> 4)
994 1.1 christos & (opcodep->args[0] == 'z' ? 1 : 3));
995 1.1 christos int size;
996 1.1 christos info->insn_type = dis_dref;
997 1.1 christos info->flags |= CRIS_DIS_FLAG_MEMREF;
998 1.1 christos
999 1.1 christos if (opcodep->imm_oprnd_size == SIZE_FIX_32)
1000 1.1 christos size = 4;
1001 1.1 christos else if (opcodep->imm_oprnd_size == SIZE_SPEC_REG)
1002 1.1 christos {
1003 1.1 christos const struct cris_spec_reg *sregp
1004 1.1 christos = spec_reg_info ((insn >> 12) & 15, disdata->distype);
1005 1.1 christos
1006 1.1 christos /* FIXME: Improve error handling; should have been caught
1007 1.1 christos earlier. */
1008 1.1 christos if (sregp == NULL)
1009 1.1 christos size = 4;
1010 1.1 christos else
1011 1.1 christos size = sregp->reg_size;
1012 1.1 christos }
1013 1.1 christos else
1014 1.1 christos size = mode_size;
1015 1.1 christos
1016 1.1 christos info->data_size = size;
1017 1.1 christos }
1018 1.1 christos
1019 1.1 christos *tp++ = '[';
1020 1.1 christos
1021 1.1 christos if (prefix_opcodep
1022 1.1 christos /* We don't match dip with a postincremented field
1023 1.1 christos as a side-effect address mode. */
1024 1.1 christos && ((insn & 0x400) == 0
1025 1.1 christos || prefix_opcodep->match != DIP_OPCODE))
1026 1.1 christos {
1027 1.1 christos if (insn & 0x400)
1028 1.1 christos {
1029 1.1 christos tp = format_reg (disdata, insn & 15, tp, with_reg_prefix);
1030 1.1 christos *tp++ = '=';
1031 1.1 christos }
1032 1.1 christos
1033 1.1 christos
1034 1.1 christos /* We mainly ignore the prefix format string when the
1035 1.1 christos address-mode syntax is output. */
1036 1.1 christos switch (prefix_opcodep->match)
1037 1.1 christos {
1038 1.1 christos case DIP_OPCODE:
1039 1.1 christos /* It's [r], [r+] or [pc+]. */
1040 1.1 christos if ((prefix_insn & 0x400) && (prefix_insn & 15) == 15)
1041 1.1 christos {
1042 1.1 christos /* It's [pc+]. This cannot possibly be anything
1043 1.1.1.7 christos but an address. */
1044 1.1.1.7 christos int32_t number = (prefix_buffer[2]
1045 1.1.1.7 christos + prefix_buffer[3] * 256
1046 1.1.1.7 christos + prefix_buffer[4] * 65536
1047 1.1 christos + prefix_buffer[5] * 0x1000000u);
1048 1.1 christos
1049 1.1 christos info->target = (bfd_vma) number;
1050 1.1 christos
1051 1.1 christos /* Finish off and output previous formatted
1052 1.1 christos data. */
1053 1.1 christos *tp = 0;
1054 1.1 christos tp = temp;
1055 1.1 christos if (temp[0])
1056 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
1057 1.1 christos
1058 1.1 christos (*info->print_address_func) ((bfd_vma) number, info);
1059 1.1 christos }
1060 1.1 christos else
1061 1.1 christos {
1062 1.1 christos /* For a memref in an address, we use target2.
1063 1.1 christos In this case, target is zero. */
1064 1.1 christos info->flags
1065 1.1 christos |= (CRIS_DIS_FLAG_MEM_TARGET2_IS_REG
1066 1.1 christos | CRIS_DIS_FLAG_MEM_TARGET2_MEM);
1067 1.1 christos
1068 1.1 christos info->target2 = prefix_insn & 15;
1069 1.1 christos
1070 1.1 christos *tp++ = '[';
1071 1.1 christos tp = format_reg (disdata, prefix_insn & 15, tp,
1072 1.1 christos with_reg_prefix);
1073 1.1 christos if (prefix_insn & 0x400)
1074 1.1 christos *tp++ = '+';
1075 1.1 christos *tp++ = ']';
1076 1.1 christos }
1077 1.1 christos break;
1078 1.1 christos
1079 1.1 christos case BDAP_QUICK_OPCODE:
1080 1.1 christos {
1081 1.1 christos int number;
1082 1.1 christos
1083 1.1 christos number = prefix_buffer[0];
1084 1.1 christos if (number > 127)
1085 1.1 christos number -= 256;
1086 1.1 christos
1087 1.1 christos /* Output "reg+num" or, if num < 0, "reg-num". */
1088 1.1 christos tp = format_reg (disdata, (prefix_insn >> 12) & 15, tp,
1089 1.1 christos with_reg_prefix);
1090 1.1 christos if (number >= 0)
1091 1.1 christos *tp++ = '+';
1092 1.1 christos tp = format_dec (number, tp, 1);
1093 1.1 christos
1094 1.1 christos info->flags |= CRIS_DIS_FLAG_MEM_TARGET_IS_REG;
1095 1.1 christos info->target = (prefix_insn >> 12) & 15;
1096 1.1 christos info->target2 = (bfd_vma) number;
1097 1.1 christos break;
1098 1.1 christos }
1099 1.1 christos
1100 1.1 christos case BIAP_OPCODE:
1101 1.1 christos /* Output "r+R.m". */
1102 1.1 christos tp = format_reg (disdata, prefix_insn & 15, tp,
1103 1.1 christos with_reg_prefix);
1104 1.1 christos *tp++ = '+';
1105 1.1 christos tp = format_reg (disdata, (prefix_insn >> 12) & 15, tp,
1106 1.1 christos with_reg_prefix);
1107 1.1 christos *tp++ = '.';
1108 1.1 christos *tp++ = mode_char[(prefix_insn >> 4) & 3];
1109 1.1 christos
1110 1.1 christos info->flags
1111 1.1 christos |= (CRIS_DIS_FLAG_MEM_TARGET2_IS_REG
1112 1.1 christos | CRIS_DIS_FLAG_MEM_TARGET_IS_REG
1113 1.1 christos
1114 1.1 christos | ((prefix_insn & 0x8000)
1115 1.1 christos ? CRIS_DIS_FLAG_MEM_TARGET2_MULT4
1116 1.1 christos : ((prefix_insn & 0x8000)
1117 1.1 christos ? CRIS_DIS_FLAG_MEM_TARGET2_MULT2 : 0)));
1118 1.1 christos
1119 1.1 christos /* Is it the casejump? It's a "adds.w [pc+r%d.w],pc". */
1120 1.1 christos if (insn == 0xf83f && (prefix_insn & ~0xf000) == 0x55f)
1121 1.1 christos /* Then start interpreting data as offsets. */
1122 1.1 christos case_offset_counter = no_of_case_offsets;
1123 1.1 christos break;
1124 1.1 christos
1125 1.1 christos case BDAP_INDIR_OPCODE:
1126 1.1 christos /* Output "r+s.m", or, if "s" is [pc+], "r+s" or
1127 1.1 christos "r-s". */
1128 1.1 christos tp = format_reg (disdata, (prefix_insn >> 12) & 15, tp,
1129 1.1 christos with_reg_prefix);
1130 1.1 christos
1131 1.1 christos if ((prefix_insn & 0x400) && (prefix_insn & 15) == 15)
1132 1.1.1.7 christos {
1133 1.1 christos int32_t number;
1134 1.1 christos unsigned int nbytes;
1135 1.1 christos
1136 1.1 christos /* It's a value. Get its size. */
1137 1.1 christos int mode_size = 1 << ((prefix_insn >> 4) & 3);
1138 1.1 christos
1139 1.1 christos if (mode_size == 1)
1140 1.1 christos nbytes = 2;
1141 1.1 christos else
1142 1.1 christos nbytes = mode_size;
1143 1.1 christos
1144 1.1 christos switch (nbytes)
1145 1.1 christos {
1146 1.1 christos case 1:
1147 1.1 christos number = prefix_buffer[2];
1148 1.1 christos if (number > 127)
1149 1.1 christos number -= 256;
1150 1.1 christos break;
1151 1.1 christos
1152 1.1 christos case 2:
1153 1.1 christos number = prefix_buffer[2] + prefix_buffer[3] * 256;
1154 1.1 christos if (number > 32767)
1155 1.1 christos number -= 65536;
1156 1.1 christos break;
1157 1.1 christos
1158 1.1.1.7 christos case 4:
1159 1.1.1.7 christos number = (prefix_buffer[2] + prefix_buffer[3] * 256
1160 1.1.1.7 christos + prefix_buffer[4] * 65536
1161 1.1 christos + prefix_buffer[5] * 0x1000000u);
1162 1.1 christos break;
1163 1.1 christos
1164 1.1 christos default:
1165 1.1 christos strcpy (tp, "bug");
1166 1.1 christos tp += 3;
1167 1.1 christos number = 42;
1168 1.1 christos }
1169 1.1 christos
1170 1.1 christos info->flags |= CRIS_DIS_FLAG_MEM_TARGET_IS_REG;
1171 1.1 christos info->target2 = (bfd_vma) number;
1172 1.1 christos
1173 1.1 christos /* If the size is dword, then assume it's an
1174 1.1 christos address. */
1175 1.1 christos if (nbytes == 4)
1176 1.1 christos {
1177 1.1 christos /* Finish off and output previous formatted
1178 1.1 christos bytes. */
1179 1.1 christos *tp++ = '+';
1180 1.1 christos *tp = 0;
1181 1.1 christos tp = temp;
1182 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
1183 1.1 christos
1184 1.1 christos (*info->print_address_func) ((bfd_vma) number, info);
1185 1.1 christos }
1186 1.1 christos else
1187 1.1 christos {
1188 1.1 christos if (number >= 0)
1189 1.1 christos *tp++ = '+';
1190 1.1 christos tp = format_dec (number, tp, 1);
1191 1.1 christos }
1192 1.1 christos }
1193 1.1 christos else
1194 1.1 christos {
1195 1.1 christos /* Output "r+[R].m" or "r+[R+].m". */
1196 1.1 christos *tp++ = '+';
1197 1.1 christos *tp++ = '[';
1198 1.1 christos tp = format_reg (disdata, prefix_insn & 15, tp,
1199 1.1 christos with_reg_prefix);
1200 1.1 christos if (prefix_insn & 0x400)
1201 1.1 christos *tp++ = '+';
1202 1.1 christos *tp++ = ']';
1203 1.1 christos *tp++ = '.';
1204 1.1 christos *tp++ = mode_char[(prefix_insn >> 4) & 3];
1205 1.1 christos
1206 1.1 christos info->flags
1207 1.1 christos |= (CRIS_DIS_FLAG_MEM_TARGET2_IS_REG
1208 1.1 christos | CRIS_DIS_FLAG_MEM_TARGET2_MEM
1209 1.1 christos | CRIS_DIS_FLAG_MEM_TARGET_IS_REG
1210 1.1 christos
1211 1.1 christos | (((prefix_insn >> 4) == 2)
1212 1.1 christos ? 0
1213 1.1 christos : (((prefix_insn >> 4) & 3) == 1
1214 1.1 christos ? CRIS_DIS_FLAG_MEM_TARGET2_MEM_WORD
1215 1.1 christos : CRIS_DIS_FLAG_MEM_TARGET2_MEM_BYTE)));
1216 1.1 christos }
1217 1.1 christos break;
1218 1.1 christos
1219 1.1 christos default:
1220 1.1 christos (*info->fprintf_func) (info->stream, "?prefix-bug");
1221 1.1 christos }
1222 1.1 christos
1223 1.1 christos /* To mark that the prefix is used, reset it. */
1224 1.1 christos prefix_opcodep = NULL;
1225 1.1 christos }
1226 1.1 christos else
1227 1.1 christos {
1228 1.1 christos tp = format_reg (disdata, insn & 15, tp, with_reg_prefix);
1229 1.1 christos
1230 1.1 christos info->flags |= CRIS_DIS_FLAG_MEM_TARGET_IS_REG;
1231 1.1 christos info->target = insn & 15;
1232 1.1 christos
1233 1.1 christos if (insn & 0x400)
1234 1.1 christos *tp++ = '+';
1235 1.1 christos }
1236 1.1 christos *tp++ = ']';
1237 1.1 christos }
1238 1.1 christos break;
1239 1.1 christos
1240 1.1 christos case 'x':
1241 1.1 christos tp = format_reg (disdata, (insn >> 12) & 15, tp, with_reg_prefix);
1242 1.1 christos *tp++ = '.';
1243 1.1 christos *tp++ = mode_char[(insn >> 4) & 3];
1244 1.1 christos break;
1245 1.1 christos
1246 1.1 christos case 'I':
1247 1.1 christos tp = format_dec (insn & 63, tp, 0);
1248 1.1 christos break;
1249 1.1 christos
1250 1.1 christos case 'b':
1251 1.1 christos {
1252 1.1 christos int where = buffer[2] + buffer[3] * 256;
1253 1.1 christos
1254 1.1 christos if (where > 32767)
1255 1.1 christos where -= 65536;
1256 1.1 christos
1257 1.1 christos where += addr + ((disdata->distype == cris_dis_v32) ? 0 : 4);
1258 1.1 christos
1259 1.1 christos if (insn == BA_PC_INCR_OPCODE)
1260 1.1 christos info->insn_type = dis_branch;
1261 1.1 christos else
1262 1.1 christos info->insn_type = dis_condbranch;
1263 1.1 christos
1264 1.1 christos info->target = (bfd_vma) where;
1265 1.1 christos
1266 1.1 christos *tp = 0;
1267 1.1 christos tp = temp;
1268 1.1 christos (*info->fprintf_func) (info->stream, "%s%s ",
1269 1.1 christos temp, cris_cc_strings[insn >> 12]);
1270 1.1 christos
1271 1.1 christos (*info->print_address_func) ((bfd_vma) where, info);
1272 1.1 christos }
1273 1.1 christos break;
1274 1.1 christos
1275 1.1 christos case 'c':
1276 1.1 christos tp = format_dec (insn & 31, tp, 0);
1277 1.1 christos break;
1278 1.1 christos
1279 1.1 christos case 'C':
1280 1.1 christos tp = format_dec (insn & 15, tp, 0);
1281 1.1 christos break;
1282 1.1 christos
1283 1.1 christos case 'o':
1284 1.1 christos {
1285 1.1 christos long offset = insn & 0xfe;
1286 1.1 christos bfd_vma target;
1287 1.1 christos
1288 1.1 christos if (insn & 1)
1289 1.1 christos offset |= ~0xff;
1290 1.1 christos
1291 1.1 christos if (opcodep->match == BA_QUICK_OPCODE)
1292 1.1 christos info->insn_type = dis_branch;
1293 1.1 christos else
1294 1.1 christos info->insn_type = dis_condbranch;
1295 1.1 christos
1296 1.1 christos target = addr + ((disdata->distype == cris_dis_v32) ? 0 : 2) + offset;
1297 1.1 christos info->target = target;
1298 1.1 christos *tp = 0;
1299 1.1 christos tp = temp;
1300 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
1301 1.1 christos (*info->print_address_func) (target, info);
1302 1.1 christos }
1303 1.1 christos break;
1304 1.1 christos
1305 1.1 christos case 'Q':
1306 1.1 christos case 'O':
1307 1.1 christos {
1308 1.1 christos long number = buffer[0];
1309 1.1 christos
1310 1.1 christos if (number > 127)
1311 1.1 christos number = number - 256;
1312 1.1 christos
1313 1.1 christos tp = format_dec (number, tp, 1);
1314 1.1 christos *tp++ = ',';
1315 1.1 christos tp = format_reg (disdata, (insn >> 12) & 15, tp, with_reg_prefix);
1316 1.1 christos }
1317 1.1 christos break;
1318 1.1 christos
1319 1.1 christos case 'f':
1320 1.1 christos tp = print_flags (disdata, insn, tp);
1321 1.1 christos break;
1322 1.1 christos
1323 1.1 christos case 'i':
1324 1.1 christos tp = format_dec ((insn & 32) ? (insn & 31) | ~31L : insn & 31, tp, 1);
1325 1.1 christos break;
1326 1.1 christos
1327 1.1 christos case 'P':
1328 1.1 christos {
1329 1.1 christos const struct cris_spec_reg *sregp
1330 1.1 christos = spec_reg_info ((insn >> 12) & 15, disdata->distype);
1331 1.1 christos
1332 1.1 christos if (sregp->name == NULL)
1333 1.1 christos /* Should have been caught as a non-match eariler. */
1334 1.1 christos *tp++ = '?';
1335 1.1 christos else
1336 1.1 christos {
1337 1.1 christos if (with_reg_prefix)
1338 1.1 christos *tp++ = REGISTER_PREFIX_CHAR;
1339 1.1 christos strcpy (tp, sregp->name);
1340 1.1 christos tp += strlen (tp);
1341 1.1 christos }
1342 1.1 christos }
1343 1.1 christos break;
1344 1.1 christos
1345 1.1 christos default:
1346 1.1 christos strcpy (tp, "???");
1347 1.1 christos tp += 3;
1348 1.1 christos }
1349 1.1 christos }
1350 1.1 christos
1351 1.1 christos *tp = 0;
1352 1.1 christos
1353 1.1 christos if (prefix_opcodep)
1354 1.1 christos (*info->fprintf_func) (info->stream, " (OOPS unused prefix \"%s: %s\")",
1355 1.1 christos prefix_opcodep->name, prefix_opcodep->args);
1356 1.1 christos
1357 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp);
1358 1.1 christos
1359 1.1 christos /* Get info for matching case-tables, if we don't have any active.
1360 1.1 christos We assume that the last constant seen is used; either in the insn
1361 1.1 christos itself or in a "move.d const,rN, sub.d rN,rM"-like sequence. */
1362 1.1 christos if (TRACE_CASE && case_offset_counter == 0)
1363 1.1 christos {
1364 1.1 christos if (CONST_STRNEQ (opcodep->name, "sub"))
1365 1.1 christos case_offset = last_immediate;
1366 1.1 christos
1367 1.1 christos /* It could also be an "add", if there are negative case-values. */
1368 1.1 christos else if (CONST_STRNEQ (opcodep->name, "add"))
1369 1.1 christos /* The first case is the negated operand to the add. */
1370 1.1 christos case_offset = -last_immediate;
1371 1.1 christos
1372 1.1 christos /* A bound insn will tell us the number of cases. */
1373 1.1 christos else if (CONST_STRNEQ (opcodep->name, "bound"))
1374 1.1 christos no_of_case_offsets = last_immediate + 1;
1375 1.1 christos
1376 1.1 christos /* A jump or jsr or branch breaks the chain of insns for a
1377 1.1 christos case-table, so assume default first-case again. */
1378 1.1 christos else if (info->insn_type == dis_jsr
1379 1.1 christos || info->insn_type == dis_branch
1380 1.1 christos || info->insn_type == dis_condbranch)
1381 1.1 christos case_offset = 0;
1382 1.1 christos }
1383 1.1 christos }
1384 1.1 christos
1385 1.1 christos
1386 1.1 christos /* Print the CRIS instruction at address memaddr on stream. Returns
1387 1.1 christos length of the instruction, in bytes. Prefix register names with `$' if
1388 1.1 christos WITH_REG_PREFIX. */
1389 1.1 christos
1390 1.1 christos static int
1391 1.1 christos print_insn_cris_generic (bfd_vma memaddr,
1392 1.1 christos disassemble_info *info,
1393 1.1 christos bfd_boolean with_reg_prefix)
1394 1.1 christos {
1395 1.1 christos int nbytes;
1396 1.1 christos unsigned int insn;
1397 1.1 christos const struct cris_opcode *matchedp;
1398 1.1 christos int advance = 0;
1399 1.1 christos struct cris_disasm_data *disdata
1400 1.1 christos = (struct cris_disasm_data *) info->private_data;
1401 1.1 christos
1402 1.1 christos /* No instruction will be disassembled as longer than this number of
1403 1.1 christos bytes; stacked prefixes will not be expanded. */
1404 1.1 christos unsigned char buffer[MAX_BYTES_PER_CRIS_INSN];
1405 1.1 christos unsigned char *bufp;
1406 1.1 christos int status = 0;
1407 1.1 christos bfd_vma addr;
1408 1.1 christos
1409 1.1 christos /* There will be an "out of range" error after the last instruction.
1410 1.1 christos Reading pairs of bytes in decreasing number, we hope that we will get
1411 1.1 christos at least the amount that we will consume.
1412 1.1 christos
1413 1.1 christos If we can't get any data, or we do not get enough data, we print
1414 1.1 christos the error message. */
1415 1.1 christos
1416 1.1 christos for (nbytes = MAX_BYTES_PER_CRIS_INSN; nbytes > 0; nbytes -= 2)
1417 1.1 christos {
1418 1.1 christos status = (*info->read_memory_func) (memaddr, buffer, nbytes, info);
1419 1.1 christos if (status == 0)
1420 1.1 christos break;
1421 1.1 christos }
1422 1.1 christos
1423 1.1 christos /* If we did not get all we asked for, then clear the rest.
1424 1.1 christos Hopefully this makes a reproducible result in case of errors. */
1425 1.1 christos if (nbytes != MAX_BYTES_PER_CRIS_INSN)
1426 1.1 christos memset (buffer + nbytes, 0, MAX_BYTES_PER_CRIS_INSN - nbytes);
1427 1.1 christos
1428 1.1 christos addr = memaddr;
1429 1.1 christos bufp = buffer;
1430 1.1 christos
1431 1.1 christos /* Set some defaults for the insn info. */
1432 1.1 christos info->insn_info_valid = 1;
1433 1.1 christos info->branch_delay_insns = 0;
1434 1.1 christos info->data_size = 0;
1435 1.1 christos info->insn_type = dis_nonbranch;
1436 1.1 christos info->flags = 0;
1437 1.1 christos info->target = 0;
1438 1.1 christos info->target2 = 0;
1439 1.1 christos
1440 1.1 christos /* If we got any data, disassemble it. */
1441 1.1 christos if (nbytes != 0)
1442 1.1 christos {
1443 1.1 christos matchedp = NULL;
1444 1.1 christos
1445 1.1 christos insn = bufp[0] + bufp[1] * 256;
1446 1.1 christos
1447 1.1 christos /* If we're in a case-table, don't disassemble the offsets. */
1448 1.1 christos if (TRACE_CASE && case_offset_counter != 0)
1449 1.1 christos {
1450 1.1 christos info->insn_type = dis_noninsn;
1451 1.1 christos advance += 2;
1452 1.1 christos
1453 1.1 christos /* If to print data as offsets, then shortcut here. */
1454 1.1 christos (*info->fprintf_func) (info->stream, "case %ld%s: -> ",
1455 1.1 christos case_offset + no_of_case_offsets
1456 1.1 christos - case_offset_counter,
1457 1.1 christos case_offset_counter == 1 ? "/default" :
1458 1.1 christos "");
1459 1.1 christos
1460 1.1 christos (*info->print_address_func) ((bfd_vma)
1461 1.1 christos ((short) (insn)
1462 1.1 christos + (long) (addr
1463 1.1 christos - (no_of_case_offsets
1464 1.1 christos - case_offset_counter)
1465 1.1 christos * 2)), info);
1466 1.1 christos case_offset_counter--;
1467 1.1 christos
1468 1.1 christos /* The default case start (without a "sub" or "add") must be
1469 1.1 christos zero. */
1470 1.1 christos if (case_offset_counter == 0)
1471 1.1 christos case_offset = 0;
1472 1.1 christos }
1473 1.1 christos else if (insn == 0)
1474 1.1 christos {
1475 1.1 christos /* We're often called to disassemble zeroes. While this is a
1476 1.1 christos valid "bcc .+2" insn, it is also useless enough and enough
1477 1.1 christos of a nuiscance that we will just output "bcc .+2" for it
1478 1.1 christos and signal it as a noninsn. */
1479 1.1 christos (*info->fprintf_func) (info->stream,
1480 1.1 christos disdata->distype == cris_dis_v32
1481 1.1 christos ? "bcc ." : "bcc .+2");
1482 1.1 christos info->insn_type = dis_noninsn;
1483 1.1 christos advance += 2;
1484 1.1 christos }
1485 1.1 christos else
1486 1.1 christos {
1487 1.1 christos const struct cris_opcode *prefix_opcodep = NULL;
1488 1.1 christos unsigned char *prefix_buffer = bufp;
1489 1.1 christos unsigned int prefix_insn = insn;
1490 1.1 christos int prefix_size = 0;
1491 1.1 christos
1492 1.1 christos matchedp = get_opcode_entry (insn, NO_CRIS_PREFIX, disdata);
1493 1.1 christos
1494 1.1 christos /* Check if we're supposed to write out prefixes as address
1495 1.1 christos modes and if this was a prefix. */
1496 1.1 christos if (matchedp != NULL && PARSE_PREFIX && matchedp->args[0] == 'p')
1497 1.1 christos {
1498 1.1 christos /* If it's a prefix, put it into the prefix vars and get the
1499 1.1 christos main insn. */
1500 1.1 christos prefix_size = bytes_to_skip (prefix_insn, matchedp,
1501 1.1 christos disdata->distype, NULL);
1502 1.1 christos prefix_opcodep = matchedp;
1503 1.1 christos
1504 1.1 christos insn = bufp[prefix_size] + bufp[prefix_size + 1] * 256;
1505 1.1 christos matchedp = get_opcode_entry (insn, prefix_insn, disdata);
1506 1.1 christos
1507 1.1 christos if (matchedp != NULL)
1508 1.1 christos {
1509 1.1 christos addr += prefix_size;
1510 1.1 christos bufp += prefix_size;
1511 1.1 christos advance += prefix_size;
1512 1.1 christos }
1513 1.1 christos else
1514 1.1 christos {
1515 1.1 christos /* The "main" insn wasn't valid, at least not when
1516 1.1 christos prefixed. Put back things enough to output the
1517 1.1 christos prefix insn only, as a normal insn. */
1518 1.1 christos matchedp = prefix_opcodep;
1519 1.1 christos insn = prefix_insn;
1520 1.1 christos prefix_opcodep = NULL;
1521 1.1 christos }
1522 1.1 christos }
1523 1.1 christos
1524 1.1 christos if (matchedp == NULL)
1525 1.1 christos {
1526 1.1 christos (*info->fprintf_func) (info->stream, "??0x%x", insn);
1527 1.1 christos advance += 2;
1528 1.1 christos
1529 1.1 christos info->insn_type = dis_noninsn;
1530 1.1 christos }
1531 1.1 christos else
1532 1.1 christos {
1533 1.1 christos advance
1534 1.1 christos += bytes_to_skip (insn, matchedp, disdata->distype,
1535 1.1 christos prefix_opcodep);
1536 1.1 christos
1537 1.1 christos /* The info_type and assorted fields will be set according
1538 1.1 christos to the operands. */
1539 1.1 christos print_with_operands (matchedp, insn, bufp, addr, info,
1540 1.1 christos prefix_opcodep, prefix_insn,
1541 1.1 christos prefix_buffer, with_reg_prefix);
1542 1.1 christos }
1543 1.1 christos }
1544 1.1 christos }
1545 1.1 christos else
1546 1.1 christos info->insn_type = dis_noninsn;
1547 1.1 christos
1548 1.1 christos /* If we read less than MAX_BYTES_PER_CRIS_INSN, i.e. we got an error
1549 1.1 christos status when reading that much, and the insn decoding indicated a
1550 1.1 christos length exceeding what we read, there is an error. */
1551 1.1 christos if (status != 0 && (nbytes == 0 || advance > nbytes))
1552 1.1 christos {
1553 1.1 christos (*info->memory_error_func) (status, memaddr, info);
1554 1.1 christos return -1;
1555 1.1 christos }
1556 1.1 christos
1557 1.1 christos /* Max supported insn size with one folded prefix insn. */
1558 1.1 christos info->bytes_per_line = MAX_BYTES_PER_CRIS_INSN;
1559 1.1 christos
1560 1.1 christos /* I would like to set this to a fixed value larger than the actual
1561 1.1 christos number of bytes to print in order to avoid spaces between bytes,
1562 1.1 christos but objdump.c (2.9.1) does not like that, so we print 16-bit
1563 1.1 christos chunks, which is the next choice. */
1564 1.1 christos info->bytes_per_chunk = 2;
1565 1.1 christos
1566 1.1 christos /* Printing bytes in order of increasing addresses makes sense,
1567 1.1 christos especially on a little-endian target.
1568 1.1 christos This is completely the opposite of what you think; setting this to
1569 1.1 christos BFD_ENDIAN_LITTLE will print bytes in order N..0 rather than the 0..N
1570 1.1 christos we want. */
1571 1.1 christos info->display_endian = BFD_ENDIAN_BIG;
1572 1.1 christos
1573 1.1 christos return advance;
1574 1.1 christos }
1575 1.1 christos
1576 1.1 christos /* Disassemble, prefixing register names with `$'. CRIS v0..v10. */
1577 1.1 christos
1578 1.1 christos static int
1579 1.1 christos print_insn_cris_with_register_prefix (bfd_vma vma,
1580 1.1 christos disassemble_info *info)
1581 1.1 christos {
1582 1.1 christos if (info->private_data == NULL
1583 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_v0_v10))
1584 1.1 christos return -1;
1585 1.1 christos return print_insn_cris_generic (vma, info, TRUE);
1586 1.1 christos }
1587 1.1 christos
1588 1.1 christos /* Disassemble, prefixing register names with `$'. CRIS v32. */
1589 1.1 christos
1590 1.1 christos static int
1591 1.1 christos print_insn_crisv32_with_register_prefix (bfd_vma vma,
1592 1.1 christos disassemble_info *info)
1593 1.1 christos {
1594 1.1 christos if (info->private_data == NULL
1595 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_v32))
1596 1.1 christos return -1;
1597 1.1 christos return print_insn_cris_generic (vma, info, TRUE);
1598 1.1 christos }
1599 1.1 christos
1600 1.1 christos /* Disassemble, prefixing register names with `$'.
1601 1.1 christos Common v10 and v32 subset. */
1602 1.1 christos
1603 1.1 christos static int
1604 1.1 christos print_insn_crisv10_v32_with_register_prefix (bfd_vma vma,
1605 1.1 christos disassemble_info *info)
1606 1.1 christos {
1607 1.1 christos if (info->private_data == NULL
1608 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_common_v10_v32))
1609 1.1 christos return -1;
1610 1.1 christos return print_insn_cris_generic (vma, info, TRUE);
1611 1.1 christos }
1612 1.1 christos
1613 1.1 christos /* Disassemble, no prefixes on register names. CRIS v0..v10. */
1614 1.1 christos
1615 1.1 christos static int
1616 1.1 christos print_insn_cris_without_register_prefix (bfd_vma vma,
1617 1.1 christos disassemble_info *info)
1618 1.1 christos {
1619 1.1 christos if (info->private_data == NULL
1620 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_v0_v10))
1621 1.1 christos return -1;
1622 1.1 christos return print_insn_cris_generic (vma, info, FALSE);
1623 1.1 christos }
1624 1.1 christos
1625 1.1 christos /* Disassemble, no prefixes on register names. CRIS v32. */
1626 1.1 christos
1627 1.1 christos static int
1628 1.1 christos print_insn_crisv32_without_register_prefix (bfd_vma vma,
1629 1.1 christos disassemble_info *info)
1630 1.1 christos {
1631 1.1 christos if (info->private_data == NULL
1632 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_v32))
1633 1.1 christos return -1;
1634 1.1 christos return print_insn_cris_generic (vma, info, FALSE);
1635 1.1 christos }
1636 1.1 christos
1637 1.1 christos /* Disassemble, no prefixes on register names.
1638 1.1 christos Common v10 and v32 subset. */
1639 1.1 christos
1640 1.1 christos static int
1641 1.1 christos print_insn_crisv10_v32_without_register_prefix (bfd_vma vma,
1642 1.1 christos disassemble_info *info)
1643 1.1 christos {
1644 1.1 christos if (info->private_data == NULL
1645 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_common_v10_v32))
1646 1.1 christos return -1;
1647 1.1 christos return print_insn_cris_generic (vma, info, FALSE);
1648 1.1 christos }
1649 1.1 christos
1650 1.1 christos /* Return a disassembler-function that prints registers with a `$' prefix,
1651 1.1 christos or one that prints registers without a prefix.
1652 1.1 christos FIXME: We should improve the solution to avoid the multitude of
1653 1.1 christos functions seen above. */
1654 1.1 christos
1655 1.1 christos disassembler_ftype
1656 1.1 christos cris_get_disassembler (bfd *abfd)
1657 1.1 christos {
1658 1.1 christos /* If there's no bfd in sight, we return what is valid as input in all
1659 1.1 christos contexts if fed back to the assembler: disassembly *with* register
1660 1.1 christos prefix. Unfortunately this will be totally wrong for v32. */
1661 1.1 christos if (abfd == NULL)
1662 1.1 christos return print_insn_cris_with_register_prefix;
1663 1.1 christos
1664 1.1 christos if (bfd_get_symbol_leading_char (abfd) == 0)
1665 1.1 christos {
1666 1.1 christos if (bfd_get_mach (abfd) == bfd_mach_cris_v32)
1667 1.1 christos return print_insn_crisv32_with_register_prefix;
1668 1.1 christos if (bfd_get_mach (abfd) == bfd_mach_cris_v10_v32)
1669 1.1 christos return print_insn_crisv10_v32_with_register_prefix;
1670 1.1 christos
1671 1.1 christos /* We default to v10. This may be specifically specified in the
1672 1.1 christos bfd mach, but is also the default setting. */
1673 1.1 christos return print_insn_cris_with_register_prefix;
1674 1.1 christos }
1675 1.1 christos
1676 1.1 christos if (bfd_get_mach (abfd) == bfd_mach_cris_v32)
1677 1.1 christos return print_insn_crisv32_without_register_prefix;
1678 1.1 christos if (bfd_get_mach (abfd) == bfd_mach_cris_v10_v32)
1679 1.1 christos return print_insn_crisv10_v32_without_register_prefix;
1680 1.1 christos return print_insn_cris_without_register_prefix;
1681 1.1 christos }
1682 1.1 christos
1683 1.1 christos /* Local variables:
1684 1.1 christos eval: (c-set-style "gnu")
1685 1.1 christos indent-tabs-mode: t
1686 End: */
1687