cpu-aarch64.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* BFD support for AArch64.
  2. Copyright (C) 2009-2022 Free Software Foundation, Inc.
  3. Contributed by ARM Ltd.
  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; see the file COPYING3. If not,
  15. see <http://www.gnu.org/licenses/>. */
  16. #include "sysdep.h"
  17. #include "bfd.h"
  18. #include "libbfd.h"
  19. #include "libiberty.h"
  20. #include "cpu-aarch64.h"
  21. /* This routine is provided two arch_infos and works out which Aarch64
  22. machine which would be compatible with both and returns a pointer
  23. to its info structure. */
  24. static const bfd_arch_info_type *
  25. compatible (const bfd_arch_info_type * a, const bfd_arch_info_type * b)
  26. {
  27. /* If a & b are for different architecture we can do nothing. */
  28. if (a->arch != b->arch)
  29. return NULL;
  30. /* If a & b are for the same machine then all is well. */
  31. if (a->mach == b->mach)
  32. return a;
  33. /* Don't allow mixing ilp32 with lp64. */
  34. if ((a->mach & bfd_mach_aarch64_ilp32) != (b->mach & bfd_mach_aarch64_ilp32))
  35. return NULL;
  36. /* Otherwise if either a or b is the 'default' machine
  37. then it can be polymorphed into the other. */
  38. if (a->the_default)
  39. return b;
  40. if (b->the_default)
  41. return a;
  42. /* So far all newer cores are
  43. supersets of previous cores. */
  44. if (a->mach < b->mach)
  45. return b;
  46. else if (a->mach > b->mach)
  47. return a;
  48. /* Never reached! */
  49. return NULL;
  50. }
  51. static struct
  52. {
  53. unsigned int mach;
  54. char *name;
  55. }
  56. processors[] =
  57. {
  58. { bfd_mach_aarch64, "cortex-a34" },
  59. { bfd_mach_aarch64, "cortex-a65" },
  60. { bfd_mach_aarch64, "cortex-a65ae" },
  61. { bfd_mach_aarch64, "cortex-a76ae" },
  62. { bfd_mach_aarch64, "cortex-a77" }
  63. };
  64. static bool
  65. scan (const struct bfd_arch_info *info, const char *string)
  66. {
  67. int i;
  68. /* First test for an exact match. */
  69. if (strcasecmp (string, info->printable_name) == 0)
  70. return true;
  71. /* Next check for a processor name instead of an Architecture name. */
  72. for (i = sizeof (processors) / sizeof (processors[0]); i--;)
  73. {
  74. if (strcasecmp (string, processors[i].name) == 0)
  75. break;
  76. }
  77. if (i != -1 && info->mach == processors[i].mach)
  78. return true;
  79. /* Finally check for the default architecture. */
  80. if (strcasecmp (string, "aarch64") == 0)
  81. return info->the_default;
  82. return false;
  83. }
  84. #define N(NUMBER, PRINT, WORDSIZE, DEFAULT, NEXT) \
  85. { WORDSIZE, WORDSIZE, 8, bfd_arch_aarch64, NUMBER, \
  86. "aarch64", PRINT, 4, DEFAULT, compatible, scan, \
  87. bfd_arch_default_fill, NEXT, 0 }
  88. static const bfd_arch_info_type bfd_aarch64_arch_v8_r =
  89. N (bfd_mach_aarch64_8R, "aarch64:armv8-r", 64, false, NULL);
  90. static const bfd_arch_info_type bfd_aarch64_arch_ilp32 =
  91. N (bfd_mach_aarch64_ilp32, "aarch64:ilp32", 32, false,
  92. &bfd_aarch64_arch_v8_r);
  93. const bfd_arch_info_type bfd_aarch64_arch =
  94. N (0, "aarch64", 64, true, &bfd_aarch64_arch_ilp32);
  95. bool
  96. bfd_is_aarch64_special_symbol_name (const char *name, int type)
  97. {
  98. if (!name || name[0] != '$')
  99. return false;
  100. if (name[1] == 'x' || name[1] == 'd')
  101. type &= BFD_AARCH64_SPECIAL_SYM_TYPE_MAP;
  102. else if (name[1] == 'm' || name[1] == 'f' || name[1] == 'p')
  103. type &= BFD_AARCH64_SPECIAL_SYM_TYPE_TAG;
  104. else
  105. return false;
  106. return (type != 0 && (name[2] == 0 || name[2] == '.'));
  107. }