cpu-arc.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* BFD support for the ARC processor
  2. Copyright (C) 1994-2022 Free Software Foundation, Inc.
  3. Contributed by Doug Evans (dje@cygnus.com).
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include "bfd.h"
  19. #include "libbfd.h"
  20. static const bfd_arch_info_type *
  21. arc_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b);
  22. #define ARC(mach, print_name, default_p, next) \
  23. { \
  24. 32, /* Bits in a word. */ \
  25. 32, /* Bits in an address. */ \
  26. 8, /* Bits in a byte. */ \
  27. bfd_arch_arc, \
  28. mach, \
  29. "arc", \
  30. print_name, \
  31. 4, /* Section alignment power. */ \
  32. default_p, \
  33. arc_compatible, \
  34. bfd_default_scan, \
  35. bfd_arch_default_fill, \
  36. next, \
  37. 0 /* Maximum offset of a reloc from the start of an insn. */ \
  38. }
  39. static const bfd_arch_info_type arch_info_struct[] =
  40. {
  41. ARC (bfd_mach_arc_arc600, "A6" , false, &arch_info_struct[1]),
  42. ARC (bfd_mach_arc_arc601, "ARC601", false, &arch_info_struct[2]),
  43. ARC (bfd_mach_arc_arc700, "ARC700", false, &arch_info_struct[3]),
  44. ARC (bfd_mach_arc_arc700, "A7", false, &arch_info_struct[4]),
  45. ARC (bfd_mach_arc_arcv2, "ARCv2", false, &arch_info_struct[5]),
  46. ARC (bfd_mach_arc_arcv2, "EM", false, &arch_info_struct[6]),
  47. ARC (bfd_mach_arc_arcv2, "HS", false, NULL),
  48. };
  49. const bfd_arch_info_type bfd_arc_arch =
  50. ARC (bfd_mach_arc_arc600, "ARC600", true, &arch_info_struct[0]);
  51. /* ARC-specific "compatible" function. The general rule is that if A and B are
  52. compatible, then this function should return architecture that is more
  53. "feature-rich", that is, can run both A and B. ARCv2, EM and HS all has
  54. same mach number, so bfd_default_compatible assumes they are the same, and
  55. returns an A. That causes issues with GDB, because GDB assumes that if
  56. machines are compatible, then "compatible ()" always returns same machine
  57. regardless of argument order. As a result GDB gets confused because, for
  58. example, compatible (ARCv2, EM) returns ARCv2, but compatible (EM, ARCv2)
  59. returns EM, hence GDB is not sure if they are compatible and prints a
  60. warning. */
  61. static const bfd_arch_info_type *
  62. arc_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b)
  63. {
  64. const bfd_arch_info_type * const em = &arch_info_struct[5];
  65. const bfd_arch_info_type * const hs = &arch_info_struct[6];
  66. /* Trivial case where a and b is the same instance. Some callers already
  67. check this condition but some do not and get an invalid result. */
  68. if (a == b)
  69. return a;
  70. /* If a & b are for different architecture we can do nothing. */
  71. if (a->arch != b->arch)
  72. return NULL;
  73. if (a->bits_per_word != b->bits_per_word)
  74. return NULL;
  75. /* ARCv2|EM and EM. */
  76. if ((a->mach == bfd_mach_arc_arcv2 && b == em)
  77. || (b->mach == bfd_mach_arc_arcv2 && a == em))
  78. return em;
  79. /* ARCv2|HS and HS. */
  80. if ((a->mach == bfd_mach_arc_arcv2 && b == hs)
  81. || (b->mach == bfd_mach_arc_arcv2 && a == hs))
  82. return hs;
  83. return bfd_default_compatible (a, b);
  84. }