1 1.1 christos /* Disassembler code for CRIS. 2 1.1.1.10 christos Copyright (C) 2000-2025 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.1.8 christos matching a switch-construct. */ 78 1.1 christos bool 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.1.8 christos 103 1.1 christos static bool 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.1.8 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.1.8 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 /* Save this value for the "case" support. */ 568 1.1 christos if (TRACE_CASE) 569 1.1 christos last_immediate = number; 570 1.1.1.9 christos 571 1.1 christos return outbuffer + sprintf (outbuffer, "0x%lx", number); 572 1.1 christos } 573 1.1 christos 574 1.1 christos /* Format number as decimal into outbuffer. Parameter signedp says 575 1.1 christos whether the number should be formatted as signed (!= 0) or 576 1.1 christos unsigned (== 0). */ 577 1.1 christos 578 1.1 christos static char * 579 1.1 christos format_dec (long number, char *outbuffer, int signedp) 580 1.1 christos { 581 1.1.1.9 christos last_immediate = number; 582 1.1 christos return outbuffer + sprintf (outbuffer, signedp ? "%ld" : "%lu", number); 583 1.1 christos } 584 1.1 christos 585 1.1 christos /* Format the name of the general register regno into outbuffer. */ 586 1.1 christos 587 1.1 christos static char * 588 1.1 christos format_reg (struct cris_disasm_data *disdata, 589 1.1.1.9 christos int regno, 590 1.1.1.8 christos char *outbuffer, 591 1.1 christos bool with_reg_prefix) 592 1.1 christos { 593 1.1 christos if (with_reg_prefix) 594 1.1 christos *outbuffer++ = REGISTER_PREFIX_CHAR; 595 1.1 christos 596 1.1 christos switch (regno) 597 1.1 christos { 598 1.1 christos case 15: 599 1.1 christos /* For v32, there is no context in which we output PC. */ 600 1.1.1.9 christos if (disdata->distype == cris_dis_v32) 601 1.1 christos outbuffer = stpcpy (outbuffer, "acr"); 602 1.1.1.9 christos else 603 1.1 christos outbuffer = stpcpy (outbuffer, "pc"); 604 1.1 christos break; 605 1.1 christos 606 1.1.1.9 christos case 14: 607 1.1 christos outbuffer = stpcpy (outbuffer, "sp"); 608 1.1 christos break; 609 1.1 christos 610 1.1.1.9 christos default: 611 1.1 christos outbuffer += sprintf (outbuffer, "r%d", regno); 612 1.1 christos break; 613 1.1 christos } 614 1.1.1.9 christos 615 1.1 christos return outbuffer; 616 1.1 christos } 617 1.1 christos 618 1.1 christos /* Format the name of a support register into outbuffer. */ 619 1.1 christos 620 1.1 christos static char * 621 1.1.1.9 christos format_sup_reg (unsigned int regno, 622 1.1.1.8 christos char *outbuffer, 623 1.1 christos bool with_reg_prefix) 624 1.1 christos { 625 1.1 christos int i; 626 1.1 christos 627 1.1 christos if (with_reg_prefix) 628 1.1 christos *outbuffer++ = REGISTER_PREFIX_CHAR; 629 1.1 christos 630 1.1 christos for (i = 0; cris_support_regs[i].name != NULL; i++) 631 1.1.1.9 christos if (cris_support_regs[i].number == regno) 632 1.1 christos return stpcpy (outbuffer, cris_support_regs[i].name); 633 1.1 christos 634 1.1 christos /* There's supposed to be register names covering all numbers, though 635 1.1.1.9 christos some may be generic names. */ 636 1.1 christos return stpcpy (outbuffer, "format_sup_reg-BUG"); 637 1.1 christos } 638 1.1 christos 639 1.1 christos /* Return the length of an instruction. */ 640 1.1 christos 641 1.1 christos static unsigned 642 1.1 christos bytes_to_skip (unsigned int insn, 643 1.1 christos const struct cris_opcode *matchedp, 644 1.1 christos enum cris_disass_family distype, 645 1.1 christos const struct cris_opcode *prefix_matchedp) 646 1.1 christos { 647 1.1 christos /* Each insn is a word plus "immediate" operands. */ 648 1.1 christos unsigned to_skip = 2; 649 1.1 christos const char *template_name = (const char *) matchedp->args; 650 1.1 christos const char *s; 651 1.1 christos 652 1.1 christos for (s = template_name; *s; s++) 653 1.1 christos if ((*s == 's' || *s == 'N' || *s == 'Y') 654 1.1 christos && (insn & 0x400) && (insn & 15) == 15 655 1.1 christos && prefix_matchedp == NULL) 656 1.1 christos { 657 1.1 christos /* Immediate via [pc+], so we have to check the size of the 658 1.1 christos operand. */ 659 1.1 christos int mode_size = 1 << ((insn >> 4) & (*template_name == 'z' ? 1 : 3)); 660 1.1 christos 661 1.1 christos if (matchedp->imm_oprnd_size == SIZE_FIX_32) 662 1.1 christos to_skip += 4; 663 1.1 christos else if (matchedp->imm_oprnd_size == SIZE_SPEC_REG) 664 1.1 christos { 665 1.1 christos const struct cris_spec_reg *sregp 666 1.1 christos = spec_reg_info ((insn >> 12) & 15, distype); 667 1.1 christos 668 1.1 christos /* FIXME: Improve error handling; should have been caught 669 1.1 christos earlier. */ 670 1.1 christos if (sregp == NULL) 671 1.1 christos return 2; 672 1.1 christos 673 1.1 christos /* PC is incremented by two, not one, for a byte. Except on 674 1.1 christos CRISv32, where constants are always DWORD-size for 675 1.1 christos special registers. */ 676 1.1 christos to_skip += 677 1.1 christos distype == cris_dis_v32 ? 4 : (sregp->reg_size + 1) & ~1; 678 1.1 christos } 679 1.1 christos else 680 1.1 christos to_skip += (mode_size + 1) & ~1; 681 1.1 christos } 682 1.1 christos else if (*s == 'n') 683 1.1 christos to_skip += 4; 684 1.1 christos else if (*s == 'b') 685 1.1 christos to_skip += 2; 686 1.1 christos 687 1.1 christos return to_skip; 688 1.1 christos } 689 1.1 christos 690 1.1 christos /* Print condition code flags. */ 691 1.1 christos 692 1.1 christos static char * 693 1.1 christos print_flags (struct cris_disasm_data *disdata, unsigned int insn, char *cp) 694 1.1 christos { 695 1.1 christos /* Use the v8 (Etrax 100) flag definitions for disassembly. 696 1.1 christos The differences with v0 (Etrax 1..4) vs. Svinto are: 697 1.1 christos v0 'd' <=> v8 'm' 698 1.1 christos v0 'e' <=> v8 'b'. 699 1.1 christos FIXME: Emit v0..v3 flag names somehow. */ 700 1.1 christos static const char v8_fnames[] = "cvznxibm"; 701 1.1 christos static const char v32_fnames[] = "cvznxiup"; 702 1.1 christos const char *fnames 703 1.1 christos = disdata->distype == cris_dis_v32 ? v32_fnames : v8_fnames; 704 1.1 christos 705 1.1 christos unsigned char flagbits = (((insn >> 8) & 0xf0) | (insn & 15)); 706 1.1 christos int i; 707 1.1 christos 708 1.1 christos for (i = 0; i < 8; i++) 709 1.1 christos if (flagbits & (1 << i)) 710 1.1 christos *cp++ = fnames[i]; 711 1.1 christos 712 1.1 christos return cp; 713 1.1 christos } 714 1.1 christos 715 1.1 christos /* Print out an insn with its operands, and update the info->insn_type 716 1.1 christos fields. The prefix_opcodep and the rest hold a prefix insn that is 717 1.1 christos supposed to be output as an address mode. */ 718 1.1 christos 719 1.1 christos static void 720 1.1 christos print_with_operands (const struct cris_opcode *opcodep, 721 1.1 christos unsigned int insn, 722 1.1 christos unsigned char *buffer, 723 1.1 christos bfd_vma addr, 724 1.1 christos disassemble_info *info, 725 1.1 christos /* If a prefix insn was before this insn (and is supposed 726 1.1 christos to be output as an address), here is a description of 727 1.1 christos it. */ 728 1.1 christos const struct cris_opcode *prefix_opcodep, 729 1.1 christos unsigned int prefix_insn, 730 1.1.1.8 christos unsigned char *prefix_buffer, 731 1.1 christos bool with_reg_prefix) 732 1.1 christos { 733 1.1 christos /* Get a buffer of somewhat reasonable size where we store 734 1.1 christos intermediate parts of the insn. */ 735 1.1 christos char temp[sizeof (".d [$r13=$r12-2147483648],$r10") * 2]; 736 1.1 christos char *tp = temp; 737 1.1 christos static const char mode_char[] = "bwd?"; 738 1.1 christos const char *s; 739 1.1 christos const char *cs; 740 1.1 christos struct cris_disasm_data *disdata 741 1.1 christos = (struct cris_disasm_data *) info->private_data; 742 1.1 christos 743 1.1 christos /* Print out the name first thing we do. */ 744 1.1 christos (*info->fprintf_func) (info->stream, "%s", opcodep->name); 745 1.1 christos 746 1.1 christos cs = opcodep->args; 747 1.1 christos s = cs; 748 1.1 christos 749 1.1 christos /* Ignore any prefix indicator. */ 750 1.1 christos if (*s == 'p') 751 1.1 christos s++; 752 1.1 christos 753 1.1 christos if (*s == 'm' || *s == 'M' || *s == 'z') 754 1.1 christos { 755 1.1 christos *tp++ = '.'; 756 1.1 christos 757 1.1 christos /* Get the size-letter. */ 758 1.1 christos *tp++ = *s == 'M' 759 1.1 christos ? (insn & 0x8000 ? 'd' 760 1.1 christos : insn & 0x4000 ? 'w' : 'b') 761 1.1 christos : mode_char[(insn >> 4) & (*s == 'z' ? 1 : 3)]; 762 1.1 christos 763 1.1 christos /* Ignore the size and the space character that follows. */ 764 1.1 christos s += 2; 765 1.1 christos } 766 1.1 christos 767 1.1 christos /* Add a space if this isn't a long-branch, because for those will add 768 1.1 christos the condition part of the name later. */ 769 1.1 christos if (opcodep->match != (BRANCH_PC_LOW + BRANCH_INCR_HIGH * 256)) 770 1.1 christos *tp++ = ' '; 771 1.1 christos 772 1.1 christos /* Fill in the insn-type if deducible from the name (and there's no 773 1.1 christos better way). */ 774 1.1 christos if (opcodep->name[0] == 'j') 775 1.1.1.8 christos { 776 1.1 christos if (startswith (opcodep->name, "jsr")) 777 1.1 christos /* It's "jsr" or "jsrc". */ 778 1.1 christos info->insn_type = dis_jsr; 779 1.1 christos else 780 1.1 christos /* Any other jump-type insn is considered a branch. */ 781 1.1 christos info->insn_type = dis_branch; 782 1.1 christos } 783 1.1 christos 784 1.1 christos /* We might know some more fields right now. */ 785 1.1 christos info->branch_delay_insns = opcodep->delayed; 786 1.1 christos 787 1.1 christos /* Handle operands. */ 788 1.1 christos for (; *s; s++) 789 1.1 christos { 790 1.1 christos switch (*s) 791 1.1 christos { 792 1.1 christos case 'T': 793 1.1 christos tp = format_sup_reg ((insn >> 12) & 15, tp, with_reg_prefix); 794 1.1 christos break; 795 1.1 christos 796 1.1 christos case 'A': 797 1.1 christos if (with_reg_prefix) 798 1.1 christos *tp++ = REGISTER_PREFIX_CHAR; 799 1.1 christos *tp++ = 'a'; 800 1.1 christos *tp++ = 'c'; 801 1.1 christos *tp++ = 'r'; 802 1.1.1.4 christos break; 803 1.1 christos 804 1.1 christos case '[': 805 1.1 christos case ']': 806 1.1 christos case ',': 807 1.1 christos *tp++ = *s; 808 1.1 christos break; 809 1.1 christos 810 1.1 christos case '!': 811 1.1 christos /* Ignore at this point; used at earlier stages to avoid 812 1.1 christos recognition if there's a prefix at something that in other 813 1.1 christos ways looks like a "pop". */ 814 1.1 christos break; 815 1.1 christos 816 1.1 christos case 'd': 817 1.1 christos /* Ignore. This is an optional ".d " on the large one of 818 1.1 christos relaxable insns. */ 819 1.1 christos break; 820 1.1 christos 821 1.1 christos case 'B': 822 1.1 christos /* This was the prefix that made this a "push". We've already 823 1.1 christos handled it by recognizing it, so signal that the prefix is 824 1.1 christos handled by setting it to NULL. */ 825 1.1 christos prefix_opcodep = NULL; 826 1.1 christos break; 827 1.1 christos 828 1.1 christos case 'D': 829 1.1 christos case 'r': 830 1.1 christos tp = format_reg (disdata, insn & 15, tp, with_reg_prefix); 831 1.1 christos break; 832 1.1 christos 833 1.1 christos case 'R': 834 1.1 christos tp = format_reg (disdata, (insn >> 12) & 15, tp, with_reg_prefix); 835 1.1 christos break; 836 1.1 christos 837 1.1 christos case 'n': 838 1.1 christos { 839 1.1.1.7 christos /* Like N but pc-relative to the start of the insn. */ 840 1.1.1.7 christos int32_t number = (buffer[2] + buffer[3] * 256 + buffer[4] * 65536 841 1.1 christos + buffer[5] * 0x1000000u); 842 1.1 christos 843 1.1 christos /* Finish off and output previous formatted bytes. */ 844 1.1 christos *tp = 0; 845 1.1 christos if (temp[0]) 846 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp); 847 1.1 christos tp = temp; 848 1.1.1.7 christos 849 1.1 christos (*info->print_address_func) (addr + number, info); 850 1.1 christos } 851 1.1 christos break; 852 1.1 christos 853 1.1 christos case 'u': 854 1.1 christos { 855 1.1.1.7 christos /* Like n but the offset is bits <3:0> in the instruction. */ 856 1.1 christos unsigned int number = (buffer[0] & 0xf) * 2; 857 1.1 christos 858 1.1 christos /* Finish off and output previous formatted bytes. */ 859 1.1 christos *tp = 0; 860 1.1 christos if (temp[0]) 861 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp); 862 1.1 christos tp = temp; 863 1.1.1.7 christos 864 1.1 christos (*info->print_address_func) (addr + number, info); 865 1.1 christos } 866 1.1 christos break; 867 1.1 christos 868 1.1 christos case 'N': 869 1.1 christos case 'y': 870 1.1 christos case 'Y': 871 1.1 christos case 'S': 872 1.1 christos case 's': 873 1.1 christos /* Any "normal" memory operand. */ 874 1.1 christos if ((insn & 0x400) && (insn & 15) == 15 && prefix_opcodep == NULL) 875 1.1 christos { 876 1.1 christos /* We're looking at [pc+], i.e. we need to output an immediate 877 1.1.1.7 christos number, where the size can depend on different things. */ 878 1.1 christos int32_t number; 879 1.1 christos int signedp 880 1.1 christos = ((*cs == 'z' && (insn & 0x20)) 881 1.1 christos || opcodep->match == BDAP_QUICK_OPCODE); 882 1.1 christos int nbytes; 883 1.1 christos 884 1.1 christos if (opcodep->imm_oprnd_size == SIZE_FIX_32) 885 1.1 christos nbytes = 4; 886 1.1 christos else if (opcodep->imm_oprnd_size == SIZE_SPEC_REG) 887 1.1 christos { 888 1.1 christos const struct cris_spec_reg *sregp 889 1.1 christos = spec_reg_info ((insn >> 12) & 15, disdata->distype); 890 1.1 christos 891 1.1 christos /* A NULL return should have been as a non-match earlier, 892 1.1 christos so catch it as an internal error in the error-case 893 1.1 christos below. */ 894 1.1 christos if (sregp == NULL) 895 1.1 christos /* Whatever non-valid size. */ 896 1.1 christos nbytes = 42; 897 1.1 christos else 898 1.1 christos /* PC is always incremented by a multiple of two. 899 1.1 christos For CRISv32, immediates are always 4 bytes for 900 1.1 christos special registers. */ 901 1.1 christos nbytes = disdata->distype == cris_dis_v32 902 1.1 christos ? 4 : (sregp->reg_size + 1) & ~1; 903 1.1 christos } 904 1.1 christos else 905 1.1 christos { 906 1.1 christos int mode_size = 1 << ((insn >> 4) & (*cs == 'z' ? 1 : 3)); 907 1.1 christos 908 1.1 christos if (mode_size == 1) 909 1.1 christos nbytes = 2; 910 1.1 christos else 911 1.1 christos nbytes = mode_size; 912 1.1 christos } 913 1.1 christos 914 1.1 christos switch (nbytes) 915 1.1 christos { 916 1.1 christos case 1: 917 1.1 christos number = buffer[2]; 918 1.1 christos if (signedp && number > 127) 919 1.1 christos number -= 256; 920 1.1 christos break; 921 1.1 christos 922 1.1 christos case 2: 923 1.1 christos number = buffer[2] + buffer[3] * 256; 924 1.1 christos if (signedp && number > 32767) 925 1.1 christos number -= 65536; 926 1.1 christos break; 927 1.1 christos 928 1.1.1.7 christos case 4: 929 1.1.1.7 christos number = (buffer[2] + buffer[3] * 256 + buffer[4] * 65536 930 1.1 christos + buffer[5] * 0x1000000u); 931 1.1 christos break; 932 1.1 christos 933 1.1 christos default: 934 1.1 christos strcpy (tp, "bug"); 935 1.1 christos tp += 3; 936 1.1 christos number = 42; 937 1.1 christos } 938 1.1 christos 939 1.1 christos if ((*cs == 'z' && (insn & 0x20)) 940 1.1 christos || (opcodep->match == BDAP_QUICK_OPCODE 941 1.1 christos && (nbytes <= 2 || buffer[1 + nbytes] == 0))) 942 1.1 christos tp = format_dec (number, tp, signedp); 943 1.1 christos else 944 1.1 christos { 945 1.1 christos unsigned int highbyte = (number >> 24) & 0xff; 946 1.1 christos 947 1.1 christos /* Either output this as an address or as a number. If it's 948 1.1 christos a dword with the same high-byte as the address of the 949 1.1 christos insn, assume it's an address, and also if it's a non-zero 950 1.1 christos non-0xff high-byte. If this is a jsr or a jump, then 951 1.1 christos it's definitely an address. */ 952 1.1 christos if (nbytes == 4 953 1.1 christos && (highbyte == ((addr >> 24) & 0xff) 954 1.1 christos || (highbyte != 0 && highbyte != 0xff) 955 1.1 christos || info->insn_type == dis_branch 956 1.1 christos || info->insn_type == dis_jsr)) 957 1.1 christos { 958 1.1 christos /* Finish off and output previous formatted bytes. */ 959 1.1 christos *tp = 0; 960 1.1 christos tp = temp; 961 1.1 christos if (temp[0]) 962 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp); 963 1.1 christos 964 1.1 christos (*info->print_address_func) ((bfd_vma) number, info); 965 1.1 christos 966 1.1 christos info->target = number; 967 1.1 christos } 968 1.1 christos else 969 1.1 christos tp = format_hex (number, tp, disdata); 970 1.1 christos } 971 1.1 christos } 972 1.1 christos else 973 1.1 christos { 974 1.1 christos /* Not an immediate number. Then this is a (possibly 975 1.1 christos prefixed) memory operand. */ 976 1.1 christos if (info->insn_type != dis_nonbranch) 977 1.1 christos { 978 1.1 christos int mode_size 979 1.1 christos = 1 << ((insn >> 4) 980 1.1 christos & (opcodep->args[0] == 'z' ? 1 : 3)); 981 1.1 christos int size; 982 1.1 christos info->insn_type = dis_dref; 983 1.1 christos info->flags |= CRIS_DIS_FLAG_MEMREF; 984 1.1 christos 985 1.1 christos if (opcodep->imm_oprnd_size == SIZE_FIX_32) 986 1.1 christos size = 4; 987 1.1 christos else if (opcodep->imm_oprnd_size == SIZE_SPEC_REG) 988 1.1 christos { 989 1.1 christos const struct cris_spec_reg *sregp 990 1.1 christos = spec_reg_info ((insn >> 12) & 15, disdata->distype); 991 1.1 christos 992 1.1 christos /* FIXME: Improve error handling; should have been caught 993 1.1 christos earlier. */ 994 1.1 christos if (sregp == NULL) 995 1.1 christos size = 4; 996 1.1 christos else 997 1.1 christos size = sregp->reg_size; 998 1.1 christos } 999 1.1 christos else 1000 1.1 christos size = mode_size; 1001 1.1 christos 1002 1.1 christos info->data_size = size; 1003 1.1 christos } 1004 1.1 christos 1005 1.1 christos *tp++ = '['; 1006 1.1 christos 1007 1.1 christos if (prefix_opcodep 1008 1.1 christos /* We don't match dip with a postincremented field 1009 1.1 christos as a side-effect address mode. */ 1010 1.1 christos && ((insn & 0x400) == 0 1011 1.1 christos || prefix_opcodep->match != DIP_OPCODE)) 1012 1.1 christos { 1013 1.1 christos if (insn & 0x400) 1014 1.1 christos { 1015 1.1 christos tp = format_reg (disdata, insn & 15, tp, with_reg_prefix); 1016 1.1 christos *tp++ = '='; 1017 1.1 christos } 1018 1.1 christos 1019 1.1 christos 1020 1.1 christos /* We mainly ignore the prefix format string when the 1021 1.1 christos address-mode syntax is output. */ 1022 1.1 christos switch (prefix_opcodep->match) 1023 1.1 christos { 1024 1.1 christos case DIP_OPCODE: 1025 1.1 christos /* It's [r], [r+] or [pc+]. */ 1026 1.1 christos if ((prefix_insn & 0x400) && (prefix_insn & 15) == 15) 1027 1.1 christos { 1028 1.1 christos /* It's [pc+]. This cannot possibly be anything 1029 1.1.1.7 christos but an address. */ 1030 1.1.1.7 christos int32_t number = (prefix_buffer[2] 1031 1.1.1.7 christos + prefix_buffer[3] * 256 1032 1.1.1.7 christos + prefix_buffer[4] * 65536 1033 1.1 christos + prefix_buffer[5] * 0x1000000u); 1034 1.1 christos 1035 1.1 christos info->target = (bfd_vma) number; 1036 1.1 christos 1037 1.1 christos /* Finish off and output previous formatted 1038 1.1 christos data. */ 1039 1.1 christos *tp = 0; 1040 1.1 christos tp = temp; 1041 1.1 christos if (temp[0]) 1042 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp); 1043 1.1 christos 1044 1.1 christos (*info->print_address_func) ((bfd_vma) number, info); 1045 1.1 christos } 1046 1.1 christos else 1047 1.1 christos { 1048 1.1 christos /* For a memref in an address, we use target2. 1049 1.1 christos In this case, target is zero. */ 1050 1.1 christos info->flags 1051 1.1 christos |= (CRIS_DIS_FLAG_MEM_TARGET2_IS_REG 1052 1.1 christos | CRIS_DIS_FLAG_MEM_TARGET2_MEM); 1053 1.1 christos 1054 1.1 christos info->target2 = prefix_insn & 15; 1055 1.1 christos 1056 1.1 christos *tp++ = '['; 1057 1.1 christos tp = format_reg (disdata, prefix_insn & 15, tp, 1058 1.1 christos with_reg_prefix); 1059 1.1 christos if (prefix_insn & 0x400) 1060 1.1 christos *tp++ = '+'; 1061 1.1 christos *tp++ = ']'; 1062 1.1 christos } 1063 1.1 christos break; 1064 1.1 christos 1065 1.1 christos case BDAP_QUICK_OPCODE: 1066 1.1 christos { 1067 1.1 christos int number; 1068 1.1 christos 1069 1.1 christos number = prefix_buffer[0]; 1070 1.1 christos if (number > 127) 1071 1.1 christos number -= 256; 1072 1.1 christos 1073 1.1 christos /* Output "reg+num" or, if num < 0, "reg-num". */ 1074 1.1 christos tp = format_reg (disdata, (prefix_insn >> 12) & 15, tp, 1075 1.1 christos with_reg_prefix); 1076 1.1 christos if (number >= 0) 1077 1.1 christos *tp++ = '+'; 1078 1.1 christos tp = format_dec (number, tp, 1); 1079 1.1 christos 1080 1.1 christos info->flags |= CRIS_DIS_FLAG_MEM_TARGET_IS_REG; 1081 1.1 christos info->target = (prefix_insn >> 12) & 15; 1082 1.1 christos info->target2 = (bfd_vma) number; 1083 1.1 christos break; 1084 1.1 christos } 1085 1.1 christos 1086 1.1 christos case BIAP_OPCODE: 1087 1.1 christos /* Output "r+R.m". */ 1088 1.1 christos tp = format_reg (disdata, prefix_insn & 15, tp, 1089 1.1 christos with_reg_prefix); 1090 1.1 christos *tp++ = '+'; 1091 1.1 christos tp = format_reg (disdata, (prefix_insn >> 12) & 15, tp, 1092 1.1 christos with_reg_prefix); 1093 1.1 christos *tp++ = '.'; 1094 1.1 christos *tp++ = mode_char[(prefix_insn >> 4) & 3]; 1095 1.1 christos 1096 1.1 christos info->flags 1097 1.1 christos |= (CRIS_DIS_FLAG_MEM_TARGET2_IS_REG 1098 1.1 christos | CRIS_DIS_FLAG_MEM_TARGET_IS_REG 1099 1.1 christos 1100 1.1 christos | ((prefix_insn & 0x8000) 1101 1.1 christos ? CRIS_DIS_FLAG_MEM_TARGET2_MULT4 1102 1.1 christos : ((prefix_insn & 0x8000) 1103 1.1 christos ? CRIS_DIS_FLAG_MEM_TARGET2_MULT2 : 0))); 1104 1.1 christos 1105 1.1 christos /* Is it the casejump? It's a "adds.w [pc+r%d.w],pc". */ 1106 1.1 christos if (insn == 0xf83f && (prefix_insn & ~0xf000) == 0x55f) 1107 1.1 christos /* Then start interpreting data as offsets. */ 1108 1.1 christos case_offset_counter = no_of_case_offsets; 1109 1.1 christos break; 1110 1.1 christos 1111 1.1 christos case BDAP_INDIR_OPCODE: 1112 1.1 christos /* Output "r+s.m", or, if "s" is [pc+], "r+s" or 1113 1.1 christos "r-s". */ 1114 1.1 christos tp = format_reg (disdata, (prefix_insn >> 12) & 15, tp, 1115 1.1 christos with_reg_prefix); 1116 1.1 christos 1117 1.1 christos if ((prefix_insn & 0x400) && (prefix_insn & 15) == 15) 1118 1.1.1.7 christos { 1119 1.1 christos int32_t number; 1120 1.1 christos unsigned int nbytes; 1121 1.1 christos 1122 1.1 christos /* It's a value. Get its size. */ 1123 1.1 christos int mode_size = 1 << ((prefix_insn >> 4) & 3); 1124 1.1 christos 1125 1.1 christos if (mode_size == 1) 1126 1.1 christos nbytes = 2; 1127 1.1 christos else 1128 1.1 christos nbytes = mode_size; 1129 1.1 christos 1130 1.1 christos switch (nbytes) 1131 1.1 christos { 1132 1.1 christos case 1: 1133 1.1 christos number = prefix_buffer[2]; 1134 1.1 christos if (number > 127) 1135 1.1 christos number -= 256; 1136 1.1 christos break; 1137 1.1 christos 1138 1.1 christos case 2: 1139 1.1 christos number = prefix_buffer[2] + prefix_buffer[3] * 256; 1140 1.1 christos if (number > 32767) 1141 1.1 christos number -= 65536; 1142 1.1 christos break; 1143 1.1 christos 1144 1.1.1.7 christos case 4: 1145 1.1.1.7 christos number = (prefix_buffer[2] + prefix_buffer[3] * 256 1146 1.1.1.7 christos + prefix_buffer[4] * 65536 1147 1.1 christos + prefix_buffer[5] * 0x1000000u); 1148 1.1 christos break; 1149 1.1 christos 1150 1.1 christos default: 1151 1.1 christos strcpy (tp, "bug"); 1152 1.1 christos tp += 3; 1153 1.1 christos number = 42; 1154 1.1 christos } 1155 1.1 christos 1156 1.1 christos info->flags |= CRIS_DIS_FLAG_MEM_TARGET_IS_REG; 1157 1.1 christos info->target2 = (bfd_vma) number; 1158 1.1 christos 1159 1.1 christos /* If the size is dword, then assume it's an 1160 1.1 christos address. */ 1161 1.1 christos if (nbytes == 4) 1162 1.1 christos { 1163 1.1 christos /* Finish off and output previous formatted 1164 1.1 christos bytes. */ 1165 1.1 christos *tp++ = '+'; 1166 1.1 christos *tp = 0; 1167 1.1 christos tp = temp; 1168 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp); 1169 1.1 christos 1170 1.1 christos (*info->print_address_func) ((bfd_vma) number, info); 1171 1.1 christos } 1172 1.1 christos else 1173 1.1 christos { 1174 1.1 christos if (number >= 0) 1175 1.1 christos *tp++ = '+'; 1176 1.1 christos tp = format_dec (number, tp, 1); 1177 1.1 christos } 1178 1.1 christos } 1179 1.1 christos else 1180 1.1 christos { 1181 1.1 christos /* Output "r+[R].m" or "r+[R+].m". */ 1182 1.1 christos *tp++ = '+'; 1183 1.1 christos *tp++ = '['; 1184 1.1 christos tp = format_reg (disdata, prefix_insn & 15, tp, 1185 1.1 christos with_reg_prefix); 1186 1.1 christos if (prefix_insn & 0x400) 1187 1.1 christos *tp++ = '+'; 1188 1.1 christos *tp++ = ']'; 1189 1.1 christos *tp++ = '.'; 1190 1.1 christos *tp++ = mode_char[(prefix_insn >> 4) & 3]; 1191 1.1 christos 1192 1.1 christos info->flags 1193 1.1 christos |= (CRIS_DIS_FLAG_MEM_TARGET2_IS_REG 1194 1.1 christos | CRIS_DIS_FLAG_MEM_TARGET2_MEM 1195 1.1 christos | CRIS_DIS_FLAG_MEM_TARGET_IS_REG 1196 1.1 christos 1197 1.1 christos | (((prefix_insn >> 4) == 2) 1198 1.1 christos ? 0 1199 1.1 christos : (((prefix_insn >> 4) & 3) == 1 1200 1.1 christos ? CRIS_DIS_FLAG_MEM_TARGET2_MEM_WORD 1201 1.1 christos : CRIS_DIS_FLAG_MEM_TARGET2_MEM_BYTE))); 1202 1.1 christos } 1203 1.1 christos break; 1204 1.1 christos 1205 1.1 christos default: 1206 1.1 christos (*info->fprintf_func) (info->stream, "?prefix-bug"); 1207 1.1 christos } 1208 1.1 christos 1209 1.1 christos /* To mark that the prefix is used, reset it. */ 1210 1.1 christos prefix_opcodep = NULL; 1211 1.1 christos } 1212 1.1 christos else 1213 1.1 christos { 1214 1.1 christos tp = format_reg (disdata, insn & 15, tp, with_reg_prefix); 1215 1.1 christos 1216 1.1 christos info->flags |= CRIS_DIS_FLAG_MEM_TARGET_IS_REG; 1217 1.1 christos info->target = insn & 15; 1218 1.1 christos 1219 1.1 christos if (insn & 0x400) 1220 1.1 christos *tp++ = '+'; 1221 1.1 christos } 1222 1.1 christos *tp++ = ']'; 1223 1.1 christos } 1224 1.1 christos break; 1225 1.1 christos 1226 1.1 christos case 'x': 1227 1.1 christos tp = format_reg (disdata, (insn >> 12) & 15, tp, with_reg_prefix); 1228 1.1 christos *tp++ = '.'; 1229 1.1 christos *tp++ = mode_char[(insn >> 4) & 3]; 1230 1.1 christos break; 1231 1.1 christos 1232 1.1 christos case 'I': 1233 1.1 christos tp = format_dec (insn & 63, tp, 0); 1234 1.1 christos break; 1235 1.1 christos 1236 1.1 christos case 'b': 1237 1.1 christos { 1238 1.1 christos int where = buffer[2] + buffer[3] * 256; 1239 1.1 christos 1240 1.1 christos if (where > 32767) 1241 1.1 christos where -= 65536; 1242 1.1 christos 1243 1.1 christos where += addr + ((disdata->distype == cris_dis_v32) ? 0 : 4); 1244 1.1 christos 1245 1.1 christos if (insn == BA_PC_INCR_OPCODE) 1246 1.1 christos info->insn_type = dis_branch; 1247 1.1 christos else 1248 1.1 christos info->insn_type = dis_condbranch; 1249 1.1 christos 1250 1.1 christos info->target = (bfd_vma) where; 1251 1.1 christos 1252 1.1 christos *tp = 0; 1253 1.1 christos tp = temp; 1254 1.1 christos (*info->fprintf_func) (info->stream, "%s%s ", 1255 1.1 christos temp, cris_cc_strings[insn >> 12]); 1256 1.1 christos 1257 1.1 christos (*info->print_address_func) ((bfd_vma) where, info); 1258 1.1 christos } 1259 1.1 christos break; 1260 1.1 christos 1261 1.1 christos case 'c': 1262 1.1 christos tp = format_dec (insn & 31, tp, 0); 1263 1.1 christos break; 1264 1.1 christos 1265 1.1 christos case 'C': 1266 1.1 christos tp = format_dec (insn & 15, tp, 0); 1267 1.1 christos break; 1268 1.1 christos 1269 1.1 christos case 'o': 1270 1.1 christos { 1271 1.1 christos long offset = insn & 0xfe; 1272 1.1 christos bfd_vma target; 1273 1.1 christos 1274 1.1 christos if (insn & 1) 1275 1.1 christos offset |= ~0xff; 1276 1.1 christos 1277 1.1 christos if (opcodep->match == BA_QUICK_OPCODE) 1278 1.1 christos info->insn_type = dis_branch; 1279 1.1 christos else 1280 1.1 christos info->insn_type = dis_condbranch; 1281 1.1 christos 1282 1.1 christos target = addr + ((disdata->distype == cris_dis_v32) ? 0 : 2) + offset; 1283 1.1 christos info->target = target; 1284 1.1 christos *tp = 0; 1285 1.1 christos tp = temp; 1286 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp); 1287 1.1 christos (*info->print_address_func) (target, info); 1288 1.1 christos } 1289 1.1 christos break; 1290 1.1 christos 1291 1.1 christos case 'Q': 1292 1.1 christos case 'O': 1293 1.1 christos { 1294 1.1 christos long number = buffer[0]; 1295 1.1 christos 1296 1.1 christos if (number > 127) 1297 1.1 christos number = number - 256; 1298 1.1 christos 1299 1.1 christos tp = format_dec (number, tp, 1); 1300 1.1 christos *tp++ = ','; 1301 1.1 christos tp = format_reg (disdata, (insn >> 12) & 15, tp, with_reg_prefix); 1302 1.1 christos } 1303 1.1 christos break; 1304 1.1 christos 1305 1.1 christos case 'f': 1306 1.1 christos tp = print_flags (disdata, insn, tp); 1307 1.1 christos break; 1308 1.1 christos 1309 1.1 christos case 'i': 1310 1.1 christos tp = format_dec ((insn & 32) ? (insn & 31) | ~31L : insn & 31, tp, 1); 1311 1.1 christos break; 1312 1.1 christos 1313 1.1 christos case 'P': 1314 1.1 christos { 1315 1.1 christos const struct cris_spec_reg *sregp 1316 1.1 christos = spec_reg_info ((insn >> 12) & 15, disdata->distype); 1317 1.1 christos 1318 1.1 christos if (sregp->name == NULL) 1319 1.1 christos /* Should have been caught as a non-match eariler. */ 1320 1.1 christos *tp++ = '?'; 1321 1.1 christos else 1322 1.1 christos { 1323 1.1 christos if (with_reg_prefix) 1324 1.1 christos *tp++ = REGISTER_PREFIX_CHAR; 1325 1.1 christos strcpy (tp, sregp->name); 1326 1.1 christos tp += strlen (tp); 1327 1.1 christos } 1328 1.1 christos } 1329 1.1 christos break; 1330 1.1 christos 1331 1.1 christos default: 1332 1.1 christos strcpy (tp, "???"); 1333 1.1 christos tp += 3; 1334 1.1 christos } 1335 1.1 christos } 1336 1.1 christos 1337 1.1 christos *tp = 0; 1338 1.1 christos 1339 1.1 christos if (prefix_opcodep) 1340 1.1 christos (*info->fprintf_func) (info->stream, " (OOPS unused prefix \"%s: %s\")", 1341 1.1 christos prefix_opcodep->name, prefix_opcodep->args); 1342 1.1 christos 1343 1.1 christos (*info->fprintf_func) (info->stream, "%s", temp); 1344 1.1 christos 1345 1.1 christos /* Get info for matching case-tables, if we don't have any active. 1346 1.1 christos We assume that the last constant seen is used; either in the insn 1347 1.1 christos itself or in a "move.d const,rN, sub.d rN,rM"-like sequence. */ 1348 1.1 christos if (TRACE_CASE && case_offset_counter == 0) 1349 1.1.1.8 christos { 1350 1.1 christos if (startswith (opcodep->name, "sub")) 1351 1.1 christos case_offset = last_immediate; 1352 1.1 christos 1353 1.1.1.8 christos /* It could also be an "add", if there are negative case-values. */ 1354 1.1 christos else if (startswith (opcodep->name, "add")) 1355 1.1 christos /* The first case is the negated operand to the add. */ 1356 1.1 christos case_offset = -last_immediate; 1357 1.1 christos 1358 1.1.1.8 christos /* A bound insn will tell us the number of cases. */ 1359 1.1 christos else if (startswith (opcodep->name, "bound")) 1360 1.1 christos no_of_case_offsets = last_immediate + 1; 1361 1.1 christos 1362 1.1 christos /* A jump or jsr or branch breaks the chain of insns for a 1363 1.1 christos case-table, so assume default first-case again. */ 1364 1.1 christos else if (info->insn_type == dis_jsr 1365 1.1 christos || info->insn_type == dis_branch 1366 1.1 christos || info->insn_type == dis_condbranch) 1367 1.1 christos case_offset = 0; 1368 1.1 christos } 1369 1.1 christos } 1370 1.1 christos 1371 1.1 christos 1372 1.1 christos /* Print the CRIS instruction at address memaddr on stream. Returns 1373 1.1 christos length of the instruction, in bytes. Prefix register names with `$' if 1374 1.1 christos WITH_REG_PREFIX. */ 1375 1.1 christos 1376 1.1 christos static int 1377 1.1 christos print_insn_cris_generic (bfd_vma memaddr, 1378 1.1.1.8 christos disassemble_info *info, 1379 1.1 christos bool with_reg_prefix) 1380 1.1 christos { 1381 1.1 christos int nbytes; 1382 1.1 christos unsigned int insn; 1383 1.1 christos const struct cris_opcode *matchedp; 1384 1.1 christos int advance = 0; 1385 1.1 christos struct cris_disasm_data *disdata 1386 1.1 christos = (struct cris_disasm_data *) info->private_data; 1387 1.1 christos 1388 1.1 christos /* No instruction will be disassembled as longer than this number of 1389 1.1 christos bytes; stacked prefixes will not be expanded. */ 1390 1.1 christos unsigned char buffer[MAX_BYTES_PER_CRIS_INSN]; 1391 1.1 christos unsigned char *bufp; 1392 1.1 christos int status = 0; 1393 1.1 christos bfd_vma addr; 1394 1.1 christos 1395 1.1 christos /* There will be an "out of range" error after the last instruction. 1396 1.1 christos Reading pairs of bytes in decreasing number, we hope that we will get 1397 1.1 christos at least the amount that we will consume. 1398 1.1 christos 1399 1.1 christos If we can't get any data, or we do not get enough data, we print 1400 1.1 christos the error message. */ 1401 1.1 christos 1402 1.1 christos for (nbytes = MAX_BYTES_PER_CRIS_INSN; nbytes > 0; nbytes -= 2) 1403 1.1 christos { 1404 1.1 christos status = (*info->read_memory_func) (memaddr, buffer, nbytes, info); 1405 1.1 christos if (status == 0) 1406 1.1 christos break; 1407 1.1 christos } 1408 1.1 christos 1409 1.1 christos /* If we did not get all we asked for, then clear the rest. 1410 1.1 christos Hopefully this makes a reproducible result in case of errors. */ 1411 1.1 christos if (nbytes != MAX_BYTES_PER_CRIS_INSN) 1412 1.1 christos memset (buffer + nbytes, 0, MAX_BYTES_PER_CRIS_INSN - nbytes); 1413 1.1 christos 1414 1.1 christos addr = memaddr; 1415 1.1 christos bufp = buffer; 1416 1.1 christos 1417 1.1 christos /* Set some defaults for the insn info. */ 1418 1.1 christos info->insn_info_valid = 1; 1419 1.1 christos info->branch_delay_insns = 0; 1420 1.1 christos info->data_size = 0; 1421 1.1 christos info->insn_type = dis_nonbranch; 1422 1.1 christos info->flags = 0; 1423 1.1 christos info->target = 0; 1424 1.1 christos info->target2 = 0; 1425 1.1 christos 1426 1.1 christos /* If we got any data, disassemble it. */ 1427 1.1 christos if (nbytes != 0) 1428 1.1 christos { 1429 1.1 christos matchedp = NULL; 1430 1.1 christos 1431 1.1 christos insn = bufp[0] + bufp[1] * 256; 1432 1.1 christos 1433 1.1 christos /* If we're in a case-table, don't disassemble the offsets. */ 1434 1.1 christos if (TRACE_CASE && case_offset_counter != 0) 1435 1.1 christos { 1436 1.1 christos info->insn_type = dis_noninsn; 1437 1.1 christos advance += 2; 1438 1.1 christos 1439 1.1 christos /* If to print data as offsets, then shortcut here. */ 1440 1.1 christos (*info->fprintf_func) (info->stream, "case %ld%s: -> ", 1441 1.1 christos case_offset + no_of_case_offsets 1442 1.1 christos - case_offset_counter, 1443 1.1 christos case_offset_counter == 1 ? "/default" : 1444 1.1 christos ""); 1445 1.1 christos 1446 1.1 christos (*info->print_address_func) ((bfd_vma) 1447 1.1 christos ((short) (insn) 1448 1.1 christos + (long) (addr 1449 1.1 christos - (no_of_case_offsets 1450 1.1 christos - case_offset_counter) 1451 1.1 christos * 2)), info); 1452 1.1 christos case_offset_counter--; 1453 1.1 christos 1454 1.1 christos /* The default case start (without a "sub" or "add") must be 1455 1.1 christos zero. */ 1456 1.1 christos if (case_offset_counter == 0) 1457 1.1 christos case_offset = 0; 1458 1.1 christos } 1459 1.1 christos else if (insn == 0) 1460 1.1 christos { 1461 1.1 christos /* We're often called to disassemble zeroes. While this is a 1462 1.1 christos valid "bcc .+2" insn, it is also useless enough and enough 1463 1.1 christos of a nuiscance that we will just output "bcc .+2" for it 1464 1.1 christos and signal it as a noninsn. */ 1465 1.1 christos (*info->fprintf_func) (info->stream, 1466 1.1 christos disdata->distype == cris_dis_v32 1467 1.1 christos ? "bcc ." : "bcc .+2"); 1468 1.1 christos info->insn_type = dis_noninsn; 1469 1.1 christos advance += 2; 1470 1.1 christos } 1471 1.1 christos else 1472 1.1 christos { 1473 1.1 christos const struct cris_opcode *prefix_opcodep = NULL; 1474 1.1 christos unsigned char *prefix_buffer = bufp; 1475 1.1 christos unsigned int prefix_insn = insn; 1476 1.1 christos int prefix_size = 0; 1477 1.1 christos 1478 1.1 christos matchedp = get_opcode_entry (insn, NO_CRIS_PREFIX, disdata); 1479 1.1 christos 1480 1.1 christos /* Check if we're supposed to write out prefixes as address 1481 1.1 christos modes and if this was a prefix. */ 1482 1.1 christos if (matchedp != NULL && PARSE_PREFIX && matchedp->args[0] == 'p') 1483 1.1 christos { 1484 1.1 christos /* If it's a prefix, put it into the prefix vars and get the 1485 1.1 christos main insn. */ 1486 1.1 christos prefix_size = bytes_to_skip (prefix_insn, matchedp, 1487 1.1 christos disdata->distype, NULL); 1488 1.1 christos prefix_opcodep = matchedp; 1489 1.1 christos 1490 1.1 christos insn = bufp[prefix_size] + bufp[prefix_size + 1] * 256; 1491 1.1 christos matchedp = get_opcode_entry (insn, prefix_insn, disdata); 1492 1.1 christos 1493 1.1 christos if (matchedp != NULL) 1494 1.1 christos { 1495 1.1 christos addr += prefix_size; 1496 1.1 christos bufp += prefix_size; 1497 1.1 christos advance += prefix_size; 1498 1.1 christos } 1499 1.1 christos else 1500 1.1 christos { 1501 1.1 christos /* The "main" insn wasn't valid, at least not when 1502 1.1 christos prefixed. Put back things enough to output the 1503 1.1 christos prefix insn only, as a normal insn. */ 1504 1.1 christos matchedp = prefix_opcodep; 1505 1.1 christos insn = prefix_insn; 1506 1.1 christos prefix_opcodep = NULL; 1507 1.1 christos } 1508 1.1 christos } 1509 1.1 christos 1510 1.1 christos if (matchedp == NULL) 1511 1.1 christos { 1512 1.1 christos (*info->fprintf_func) (info->stream, "??0x%x", insn); 1513 1.1 christos advance += 2; 1514 1.1 christos 1515 1.1 christos info->insn_type = dis_noninsn; 1516 1.1 christos } 1517 1.1 christos else 1518 1.1 christos { 1519 1.1 christos advance 1520 1.1 christos += bytes_to_skip (insn, matchedp, disdata->distype, 1521 1.1 christos prefix_opcodep); 1522 1.1 christos 1523 1.1 christos /* The info_type and assorted fields will be set according 1524 1.1 christos to the operands. */ 1525 1.1 christos print_with_operands (matchedp, insn, bufp, addr, info, 1526 1.1 christos prefix_opcodep, prefix_insn, 1527 1.1 christos prefix_buffer, with_reg_prefix); 1528 1.1 christos } 1529 1.1 christos } 1530 1.1 christos } 1531 1.1 christos else 1532 1.1 christos info->insn_type = dis_noninsn; 1533 1.1 christos 1534 1.1 christos /* If we read less than MAX_BYTES_PER_CRIS_INSN, i.e. we got an error 1535 1.1 christos status when reading that much, and the insn decoding indicated a 1536 1.1 christos length exceeding what we read, there is an error. */ 1537 1.1 christos if (status != 0 && (nbytes == 0 || advance > nbytes)) 1538 1.1 christos { 1539 1.1 christos (*info->memory_error_func) (status, memaddr, info); 1540 1.1 christos return -1; 1541 1.1 christos } 1542 1.1 christos 1543 1.1 christos /* Max supported insn size with one folded prefix insn. */ 1544 1.1 christos info->bytes_per_line = MAX_BYTES_PER_CRIS_INSN; 1545 1.1 christos 1546 1.1 christos /* I would like to set this to a fixed value larger than the actual 1547 1.1 christos number of bytes to print in order to avoid spaces between bytes, 1548 1.1 christos but objdump.c (2.9.1) does not like that, so we print 16-bit 1549 1.1 christos chunks, which is the next choice. */ 1550 1.1 christos info->bytes_per_chunk = 2; 1551 1.1 christos 1552 1.1 christos /* Printing bytes in order of increasing addresses makes sense, 1553 1.1 christos especially on a little-endian target. 1554 1.1 christos This is completely the opposite of what you think; setting this to 1555 1.1 christos BFD_ENDIAN_LITTLE will print bytes in order N..0 rather than the 0..N 1556 1.1 christos we want. */ 1557 1.1 christos info->display_endian = BFD_ENDIAN_BIG; 1558 1.1 christos 1559 1.1 christos return advance; 1560 1.1 christos } 1561 1.1 christos 1562 1.1 christos /* Disassemble, prefixing register names with `$'. CRIS v0..v10. */ 1563 1.1 christos 1564 1.1 christos static int 1565 1.1 christos print_insn_cris_with_register_prefix (bfd_vma vma, 1566 1.1 christos disassemble_info *info) 1567 1.1 christos { 1568 1.1 christos if (info->private_data == NULL 1569 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_v0_v10)) 1570 1.1.1.8 christos return -1; 1571 1.1 christos return print_insn_cris_generic (vma, info, true); 1572 1.1 christos } 1573 1.1 christos 1574 1.1 christos /* Disassemble, prefixing register names with `$'. CRIS v32. */ 1575 1.1 christos 1576 1.1 christos static int 1577 1.1 christos print_insn_crisv32_with_register_prefix (bfd_vma vma, 1578 1.1 christos disassemble_info *info) 1579 1.1 christos { 1580 1.1 christos if (info->private_data == NULL 1581 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_v32)) 1582 1.1.1.8 christos return -1; 1583 1.1 christos return print_insn_cris_generic (vma, info, true); 1584 1.1 christos } 1585 1.1 christos 1586 1.1 christos /* Disassemble, prefixing register names with `$'. 1587 1.1 christos Common v10 and v32 subset. */ 1588 1.1 christos 1589 1.1 christos static int 1590 1.1 christos print_insn_crisv10_v32_with_register_prefix (bfd_vma vma, 1591 1.1 christos disassemble_info *info) 1592 1.1 christos { 1593 1.1 christos if (info->private_data == NULL 1594 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_common_v10_v32)) 1595 1.1.1.8 christos return -1; 1596 1.1 christos return print_insn_cris_generic (vma, info, true); 1597 1.1 christos } 1598 1.1 christos 1599 1.1 christos /* Disassemble, no prefixes on register names. CRIS v0..v10. */ 1600 1.1 christos 1601 1.1 christos static int 1602 1.1 christos print_insn_cris_without_register_prefix (bfd_vma vma, 1603 1.1 christos disassemble_info *info) 1604 1.1 christos { 1605 1.1 christos if (info->private_data == NULL 1606 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_v0_v10)) 1607 1.1.1.8 christos return -1; 1608 1.1 christos return print_insn_cris_generic (vma, info, false); 1609 1.1 christos } 1610 1.1 christos 1611 1.1 christos /* Disassemble, no prefixes on register names. CRIS v32. */ 1612 1.1 christos 1613 1.1 christos static int 1614 1.1 christos print_insn_crisv32_without_register_prefix (bfd_vma vma, 1615 1.1 christos disassemble_info *info) 1616 1.1 christos { 1617 1.1 christos if (info->private_data == NULL 1618 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_v32)) 1619 1.1.1.8 christos return -1; 1620 1.1 christos return print_insn_cris_generic (vma, info, false); 1621 1.1 christos } 1622 1.1 christos 1623 1.1 christos /* Disassemble, no prefixes on register names. 1624 1.1 christos Common v10 and v32 subset. */ 1625 1.1 christos 1626 1.1 christos static int 1627 1.1 christos print_insn_crisv10_v32_without_register_prefix (bfd_vma vma, 1628 1.1 christos disassemble_info *info) 1629 1.1 christos { 1630 1.1 christos if (info->private_data == NULL 1631 1.1 christos && !cris_parse_disassembler_options (info, cris_dis_common_v10_v32)) 1632 1.1.1.8 christos return -1; 1633 1.1 christos return print_insn_cris_generic (vma, info, false); 1634 1.1 christos } 1635 1.1 christos 1636 1.1 christos /* Return a disassembler-function that prints registers with a `$' prefix, 1637 1.1 christos or one that prints registers without a prefix. 1638 1.1 christos FIXME: We should improve the solution to avoid the multitude of 1639 1.1 christos functions seen above. */ 1640 1.1 christos 1641 1.1 christos disassembler_ftype 1642 1.1 christos cris_get_disassembler (bfd *abfd) 1643 1.1 christos { 1644 1.1 christos /* If there's no bfd in sight, we return what is valid as input in all 1645 1.1 christos contexts if fed back to the assembler: disassembly *with* register 1646 1.1 christos prefix. Unfortunately this will be totally wrong for v32. */ 1647 1.1 christos if (abfd == NULL) 1648 1.1 christos return print_insn_cris_with_register_prefix; 1649 1.1 christos 1650 1.1 christos if (bfd_get_symbol_leading_char (abfd) == 0) 1651 1.1 christos { 1652 1.1 christos if (bfd_get_mach (abfd) == bfd_mach_cris_v32) 1653 1.1 christos return print_insn_crisv32_with_register_prefix; 1654 1.1 christos if (bfd_get_mach (abfd) == bfd_mach_cris_v10_v32) 1655 1.1 christos return print_insn_crisv10_v32_with_register_prefix; 1656 1.1 christos 1657 1.1 christos /* We default to v10. This may be specifically specified in the 1658 1.1 christos bfd mach, but is also the default setting. */ 1659 1.1 christos return print_insn_cris_with_register_prefix; 1660 1.1 christos } 1661 1.1 christos 1662 1.1 christos if (bfd_get_mach (abfd) == bfd_mach_cris_v32) 1663 1.1 christos return print_insn_crisv32_without_register_prefix; 1664 1.1 christos if (bfd_get_mach (abfd) == bfd_mach_cris_v10_v32) 1665 1.1 christos return print_insn_crisv10_v32_without_register_prefix; 1666 1.1 christos return print_insn_cris_without_register_prefix; 1667 1.1 christos } 1668 1.1 christos 1669 1.1 christos /* Local variables: 1670 1.1 christos eval: (c-set-style "gnu") 1671 1.1 christos indent-tabs-mode: t 1672 End: */ 1673