cpu-h8300.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* BFD library support routines for the Renesas H8/300 architecture.
  2. Copyright (C) 1990-2022 Free Software Foundation, Inc.
  3. Hacked by Steve Chamberlain of Cygnus Support.
  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. #include "cpu-h8300.h"
  21. static bool
  22. h8300_scan (const struct bfd_arch_info *info, const char *string)
  23. {
  24. if (*string != 'h' && *string != 'H')
  25. return false;
  26. string++;
  27. if (*string != '8')
  28. return false;
  29. string++;
  30. if (*string == '/')
  31. string++;
  32. if (*string != '3')
  33. return false;
  34. string++;
  35. if (*string != '0')
  36. return false;
  37. string++;
  38. if (*string != '0')
  39. return false;
  40. string++;
  41. if (*string == '-')
  42. string++;
  43. /* In ELF linker scripts, we typically express the architecture/machine
  44. as architecture:machine.
  45. So if we've matched so far and encounter a colon, try to match the
  46. string following the colon. */
  47. if (*string == ':')
  48. {
  49. string++;
  50. return h8300_scan (info, string);
  51. }
  52. if (*string == 'h' || *string == 'H')
  53. {
  54. string++;
  55. if (*string == 'n' || *string == 'N')
  56. return (info->mach == bfd_mach_h8300hn);
  57. return (info->mach == bfd_mach_h8300h);
  58. }
  59. else if (*string == 's' || *string == 'S')
  60. {
  61. string++;
  62. if (*string == 'n' || *string == 'N')
  63. return (info->mach == bfd_mach_h8300sn);
  64. if (*string == 'x' || *string == 'X')
  65. {
  66. string++;
  67. if (*string == 'n' || *string == 'N')
  68. return (info->mach == bfd_mach_h8300sxn);
  69. return (info->mach == bfd_mach_h8300sx);
  70. }
  71. return (info->mach == bfd_mach_h8300s);
  72. }
  73. else
  74. return info->mach == bfd_mach_h8300;
  75. }
  76. /* This routine is provided two arch_infos and works out the machine
  77. which would be compatible with both and returns a pointer to its
  78. info structure. */
  79. static const bfd_arch_info_type *
  80. compatible (const bfd_arch_info_type *in, const bfd_arch_info_type *out)
  81. {
  82. if (in->arch != out->arch)
  83. return 0;
  84. if (in->mach == bfd_mach_h8300sx && out->mach == bfd_mach_h8300s)
  85. return in;
  86. if (in->mach == bfd_mach_h8300s && out->mach == bfd_mach_h8300sx)
  87. return out;
  88. if (in->mach == bfd_mach_h8300sxn && out->mach == bfd_mach_h8300sn)
  89. return in;
  90. if (in->mach == bfd_mach_h8300sn && out->mach == bfd_mach_h8300sxn)
  91. return out;
  92. /* It's really not a good idea to mix and match modes. */
  93. if (in->mach != out->mach)
  94. return 0;
  95. else
  96. return in;
  97. }
  98. #define N(word, addr, number, name, print, default, next) \
  99. { word, addr, 8, bfd_arch_h8300, number, name, print, 1, default, \
  100. compatible, h8300_scan, bfd_arch_default_fill, next, 0 }
  101. static const bfd_arch_info_type h8300sxn_info_struct =
  102. N (32, 16, bfd_mach_h8300sxn, "h8300sxn", "h8300sxn", false, NULL);
  103. static const bfd_arch_info_type h8300sx_info_struct =
  104. N (32, 32, bfd_mach_h8300sx, "h8300sx", "h8300sx", false, &h8300sxn_info_struct);
  105. static const bfd_arch_info_type h8300sn_info_struct =
  106. N (32, 16, bfd_mach_h8300sn, "h8300sn", "h8300sn", false, &h8300sx_info_struct);
  107. static const bfd_arch_info_type h8300hn_info_struct =
  108. N (32, 16, bfd_mach_h8300hn, "h8300hn", "h8300hn", false, &h8300sn_info_struct);
  109. static const bfd_arch_info_type h8300s_info_struct =
  110. N (32, 32, bfd_mach_h8300s, "h8300s", "h8300s", false, & h8300hn_info_struct);
  111. static const bfd_arch_info_type h8300h_info_struct =
  112. N (32, 32, bfd_mach_h8300h, "h8300h", "h8300h", false, &h8300s_info_struct);
  113. const bfd_arch_info_type bfd_h8300_arch =
  114. N (16, 16, bfd_mach_h8300, "h8300", "h8300", true, &h8300h_info_struct);
  115. /* Pad the given address to 32 bits, converting 16-bit and 24-bit
  116. addresses into the values they would have had on a h8s target. */
  117. bfd_vma
  118. bfd_h8300_pad_address (bfd *abfd, bfd_vma address)
  119. {
  120. /* Cope with bfd_vma's larger than 32 bits. */
  121. address &= 0xffffffffu;
  122. switch (bfd_get_mach (abfd))
  123. {
  124. case bfd_mach_h8300:
  125. case bfd_mach_h8300hn:
  126. case bfd_mach_h8300sn:
  127. case bfd_mach_h8300sxn:
  128. /* Sign extend a 16-bit address. */
  129. if (address >= 0x8000)
  130. return address | 0xffff0000u;
  131. return address;
  132. case bfd_mach_h8300h:
  133. /* Sign extend a 24-bit address. */
  134. if (address >= 0x800000)
  135. return address | 0xff000000u;
  136. return address;
  137. case bfd_mach_h8300s:
  138. case bfd_mach_h8300sx:
  139. return address;
  140. default:
  141. abort ();
  142. }
  143. }