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