tilegx-dis.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* tilegx-dis.c. Disassembly routines for the TILE-Gx architecture.
  2. Copyright (C) 2011-2022 Free Software Foundation, Inc.
  3. This file is part of the GNU opcodes library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #include "sysdep.h"
  17. #include <stddef.h>
  18. #include <assert.h>
  19. #include "bfd.h"
  20. #include "elf/tilegx.h"
  21. #include "elf-bfd.h"
  22. #include "disassemble.h"
  23. #include "opcode/tilegx.h"
  24. int
  25. print_insn_tilegx (bfd_vma memaddr, disassemble_info *info)
  26. {
  27. struct tilegx_decoded_instruction
  28. decoded[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE];
  29. bfd_byte opbuf[TILEGX_BUNDLE_SIZE_IN_BYTES];
  30. int status, i, num_instructions, num_printed;
  31. tilegx_mnemonic padding_mnemonic;
  32. status = (*info->read_memory_func) (memaddr, opbuf,
  33. TILEGX_BUNDLE_SIZE_IN_BYTES, info);
  34. if (status != 0)
  35. {
  36. (*info->memory_error_func) (status, memaddr, info);
  37. return -1;
  38. }
  39. info->bytes_per_line = TILEGX_BUNDLE_SIZE_IN_BYTES;
  40. info->bytes_per_chunk = TILEGX_BUNDLE_SIZE_IN_BYTES;
  41. info->octets_per_byte = 1;
  42. info->display_endian = BFD_ENDIAN_LITTLE;
  43. /* Parse the instructions in the bundle. */
  44. num_instructions =
  45. parse_insn_tilegx (bfd_getl64 (opbuf), memaddr, decoded);
  46. /* Print the instructions in the bundle. */
  47. info->fprintf_func (info->stream, "{ ");
  48. num_printed = 0;
  49. /* Determine which nop opcode is used for padding and should be skipped. */
  50. padding_mnemonic = TILEGX_OPC_FNOP;
  51. for (i = 0; i < num_instructions; i++)
  52. {
  53. if (!decoded[i].opcode->can_bundle)
  54. {
  55. /* Instructions that cannot be bundled are padded out with nops,
  56. rather than fnops. Displaying them is always clutter. */
  57. padding_mnemonic = TILEGX_OPC_NOP;
  58. break;
  59. }
  60. }
  61. for (i = 0; i < num_instructions; i++)
  62. {
  63. const struct tilegx_opcode *opcode = decoded[i].opcode;
  64. const char *name;
  65. int j;
  66. /* Do not print out fnops, unless everything is an fnop, in
  67. which case we will print out just the last one. */
  68. if (opcode->mnemonic == padding_mnemonic
  69. && (num_printed > 0 || i + 1 < num_instructions))
  70. continue;
  71. if (num_printed > 0)
  72. info->fprintf_func (info->stream, " ; ");
  73. ++num_printed;
  74. name = opcode->name;
  75. if (name == NULL)
  76. name = "<invalid>";
  77. info->fprintf_func (info->stream, "%s", name);
  78. for (j = 0; j < opcode->num_operands; j++)
  79. {
  80. bfd_vma num;
  81. const struct tilegx_operand *op;
  82. const char *spr_name;
  83. if (j > 0)
  84. info->fprintf_func (info->stream, ",");
  85. info->fprintf_func (info->stream, " ");
  86. num = decoded[i].operand_values[j];
  87. op = decoded[i].operands[j];
  88. switch (op->type)
  89. {
  90. case TILEGX_OP_TYPE_REGISTER:
  91. info->fprintf_func (info->stream, "%s",
  92. tilegx_register_names[(int) num]);
  93. break;
  94. case TILEGX_OP_TYPE_SPR:
  95. spr_name = get_tilegx_spr_name (num);
  96. if (spr_name != NULL)
  97. info->fprintf_func (info->stream, "%s", spr_name);
  98. else
  99. info->fprintf_func (info->stream, "%d", (int)num);
  100. break;
  101. case TILEGX_OP_TYPE_IMMEDIATE:
  102. info->fprintf_func (info->stream, "%d", (int)num);
  103. break;
  104. case TILEGX_OP_TYPE_ADDRESS:
  105. info->print_address_func (num, info);
  106. break;
  107. default:
  108. abort ();
  109. }
  110. }
  111. }
  112. info->fprintf_func (info->stream, " }");
  113. return TILEGX_BUNDLE_SIZE_IN_BYTES;
  114. }