cpu-aarch64.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* BFD support for AArch64.
  2. Copyright (C) 2009-2015 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. /* This routine is provided two arch_infos and works out which Aarch64
  21. machine which would be compatible with both and returns a pointer
  22. to its info structure. */
  23. static const bfd_arch_info_type *
  24. compatible (const bfd_arch_info_type * a, const bfd_arch_info_type * b)
  25. {
  26. /* If a & b are for different architecture we can do nothing. */
  27. if (a->arch != b->arch)
  28. return NULL;
  29. /* If a & b are for the same machine then all is well. */
  30. if (a->mach == b->mach)
  31. return a;
  32. /* Don't allow mixing ilp32 with lp64. */
  33. if ((a->mach & bfd_mach_aarch64_ilp32) != (b->mach & bfd_mach_aarch64_ilp32))
  34. return NULL;
  35. /* Otherwise if either a or b is the 'default' machine
  36. then it can be polymorphed into the other. */
  37. if (a->the_default)
  38. return b;
  39. if (b->the_default)
  40. return a;
  41. /* So far all newer cores are
  42. supersets of previous cores. */
  43. if (a->mach < b->mach)
  44. return b;
  45. else if (a->mach > b->mach)
  46. return a;
  47. /* Never reached! */
  48. return NULL;
  49. }
  50. static struct
  51. {
  52. unsigned int mach;
  53. char *name;
  54. }
  55. processors[] =
  56. {
  57. /* These two are example CPUs supported in GCC, once we have real
  58. CPUs they will be removed. */
  59. { bfd_mach_aarch64, "example-1" },
  60. { bfd_mach_aarch64, "example-2" }
  61. };
  62. static bfd_boolean
  63. scan (const struct bfd_arch_info *info, const char *string)
  64. {
  65. int i;
  66. /* First test for an exact match. */
  67. if (strcasecmp (string, info->printable_name) == 0)
  68. return TRUE;
  69. /* Next check for a processor name instead of an Architecture name. */
  70. for (i = sizeof (processors) / sizeof (processors[0]); i--;)
  71. {
  72. if (strcasecmp (string, processors[i].name) == 0)
  73. break;
  74. }
  75. if (i != -1 && info->mach == processors[i].mach)
  76. return TRUE;
  77. /* Finally check for the default architecture. */
  78. if (strcasecmp (string, "aarch64") == 0)
  79. return info->the_default;
  80. return FALSE;
  81. }
  82. #define N(NUMBER, PRINT, DEFAULT, NEXT) \
  83. { 64, 64, 8, bfd_arch_aarch64, NUMBER, \
  84. "aarch64", PRINT, 4, DEFAULT, compatible, scan, \
  85. bfd_arch_default_fill, NEXT }
  86. static const bfd_arch_info_type bfd_aarch64_arch_ilp32 =
  87. N (bfd_mach_aarch64_ilp32, "aarch64:ilp32", FALSE, NULL);
  88. const bfd_arch_info_type bfd_aarch64_arch =
  89. N (0, "aarch64", TRUE, &bfd_aarch64_arch_ilp32);
  90. bfd_boolean
  91. bfd_is_aarch64_special_symbol_name (const char *name, int type)
  92. {
  93. if (!name || name[0] != '$')
  94. return FALSE;
  95. if (name[1] == 'x' || name[1] == 'd')
  96. type &= BFD_AARCH64_SPECIAL_SYM_TYPE_MAP;
  97. else if (name[1] == 'm' || name[1] == 'f' || name[1] == 'p')
  98. type &= BFD_AARCH64_SPECIAL_SYM_TYPE_TAG;
  99. else
  100. return FALSE;
  101. return (type != 0 && (name[2] == 0 || name[2] == '.'));
  102. }