cpu-h8300.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /* BFD library support routines for the Renesas H8/300 architecture.
  2. Copyright (C) 1990-2015 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. static bfd_boolean
  21. h8300_scan (const struct bfd_arch_info *info, const char *string)
  22. {
  23. if (*string != 'h' && *string != 'H')
  24. return FALSE;
  25. string++;
  26. if (*string != '8')
  27. return FALSE;
  28. string++;
  29. if (*string == '/')
  30. string++;
  31. if (*string != '3')
  32. return FALSE;
  33. string++;
  34. if (*string != '0')
  35. return FALSE;
  36. string++;
  37. if (*string != '0')
  38. return FALSE;
  39. string++;
  40. if (*string == '-')
  41. string++;
  42. /* In ELF linker scripts, we typically express the architecture/machine
  43. as architecture:machine.
  44. So if we've matched so far and encounter a colon, try to match the
  45. string following the colon. */
  46. if (*string == ':')
  47. {
  48. string++;
  49. return h8300_scan (info, string);
  50. }
  51. if (*string == 'h' || *string == 'H')
  52. {
  53. string++;
  54. if (*string == 'n' || *string == 'N')
  55. return (info->mach == bfd_mach_h8300hn);
  56. return (info->mach == bfd_mach_h8300h);
  57. }
  58. else if (*string == 's' || *string == 'S')
  59. {
  60. string++;
  61. if (*string == 'n' || *string == 'N')
  62. return (info->mach == bfd_mach_h8300sn);
  63. if (*string == 'x' || *string == 'X')
  64. {
  65. string++;
  66. if (*string == 'n' || *string == 'N')
  67. return (info->mach == bfd_mach_h8300sxn);
  68. return (info->mach == bfd_mach_h8300sx);
  69. }
  70. return (info->mach == bfd_mach_h8300s);
  71. }
  72. else
  73. return info->mach == bfd_mach_h8300;
  74. }
  75. /* This routine is provided two arch_infos and works out the machine
  76. which would be compatible with both and returns a pointer to its
  77. info structure. */
  78. static const bfd_arch_info_type *
  79. compatible (const bfd_arch_info_type *in, const bfd_arch_info_type *out)
  80. {
  81. if (in->arch != out->arch)
  82. return 0;
  83. if (in->mach == bfd_mach_h8300sx && out->mach == bfd_mach_h8300s)
  84. return in;
  85. if (in->mach == bfd_mach_h8300s && out->mach == bfd_mach_h8300sx)
  86. return out;
  87. if (in->mach == bfd_mach_h8300sxn && out->mach == bfd_mach_h8300sn)
  88. return in;
  89. if (in->mach == bfd_mach_h8300sn && out->mach == bfd_mach_h8300sxn)
  90. return out;
  91. /* It's really not a good idea to mix and match modes. */
  92. if (in->mach != out->mach)
  93. return 0;
  94. else
  95. return in;
  96. }
  97. static const bfd_arch_info_type h8300sxn_info_struct =
  98. {
  99. 32, /* 32 bits in a word */
  100. 16, /* 16 bits in an address */
  101. 8, /* 8 bits in a byte */
  102. bfd_arch_h8300,
  103. bfd_mach_h8300sxn,
  104. "h8300sxn", /* arch_name */
  105. "h8300sxn", /* printable name */
  106. 1,
  107. FALSE, /* the default machine */
  108. compatible,
  109. h8300_scan,
  110. bfd_arch_default_fill,
  111. 0
  112. };
  113. static const bfd_arch_info_type h8300sx_info_struct =
  114. {
  115. 32, /* 32 bits in a word */
  116. 32, /* 32 bits in an address */
  117. 8, /* 8 bits in a byte */
  118. bfd_arch_h8300,
  119. bfd_mach_h8300sx,
  120. "h8300sx", /* arch_name */
  121. "h8300sx", /* printable name */
  122. 1,
  123. FALSE, /* the default machine */
  124. compatible,
  125. h8300_scan,
  126. bfd_arch_default_fill,
  127. &h8300sxn_info_struct
  128. };
  129. static const bfd_arch_info_type h8300sn_info_struct =
  130. {
  131. 32, /* 32 bits in a word. */
  132. 16, /* 16 bits in an address. */
  133. 8, /* 8 bits in a byte. */
  134. bfd_arch_h8300,
  135. bfd_mach_h8300sn,
  136. "h8300sn", /* Architecture name. */
  137. "h8300sn", /* Printable name. */
  138. 1,
  139. FALSE, /* The default machine. */
  140. compatible,
  141. h8300_scan,
  142. bfd_arch_default_fill,
  143. &h8300sx_info_struct
  144. };
  145. static const bfd_arch_info_type h8300hn_info_struct =
  146. {
  147. 32, /* 32 bits in a word. */
  148. 16, /* 16 bits in an address. */
  149. 8, /* 8 bits in a byte. */
  150. bfd_arch_h8300,
  151. bfd_mach_h8300hn,
  152. "h8300hn", /* Architecture name. */
  153. "h8300hn", /* Printable name. */
  154. 1,
  155. FALSE, /* The default machine. */
  156. compatible,
  157. h8300_scan,
  158. bfd_arch_default_fill,
  159. &h8300sn_info_struct
  160. };
  161. static const bfd_arch_info_type h8300s_info_struct =
  162. {
  163. 32, /* 32 bits in a word. */
  164. 32, /* 32 bits in an address. */
  165. 8, /* 8 bits in a byte. */
  166. bfd_arch_h8300,
  167. bfd_mach_h8300s,
  168. "h8300s", /* Architecture name. */
  169. "h8300s", /* Printable name. */
  170. 1,
  171. FALSE, /* The default machine. */
  172. compatible,
  173. h8300_scan,
  174. bfd_arch_default_fill,
  175. & h8300hn_info_struct
  176. };
  177. static const bfd_arch_info_type h8300h_info_struct =
  178. {
  179. 32, /* 32 bits in a word. */
  180. 32, /* 32 bits in an address. */
  181. 8, /* 8 bits in a byte. */
  182. bfd_arch_h8300,
  183. bfd_mach_h8300h,
  184. "h8300h", /* Architecture name. */
  185. "h8300h", /* Printable name. */
  186. 1,
  187. FALSE, /* The default machine. */
  188. compatible,
  189. h8300_scan,
  190. bfd_arch_default_fill,
  191. &h8300s_info_struct
  192. };
  193. const bfd_arch_info_type bfd_h8300_arch =
  194. {
  195. 16, /* 16 bits in a word. */
  196. 16, /* 16 bits in an address. */
  197. 8, /* 8 bits in a byte. */
  198. bfd_arch_h8300,
  199. bfd_mach_h8300,
  200. "h8300", /* Architecture name. */
  201. "h8300", /* Printable name. */
  202. 1,
  203. TRUE, /* The default machine. */
  204. compatible,
  205. h8300_scan,
  206. bfd_arch_default_fill,
  207. &h8300h_info_struct
  208. };
  209. /* Pad the given address to 32 bits, converting 16-bit and 24-bit
  210. addresses into the values they would have had on a h8s target. */
  211. bfd_vma
  212. bfd_h8300_pad_address (bfd *abfd, bfd_vma address)
  213. {
  214. /* Cope with bfd_vma's larger than 32 bits. */
  215. address &= 0xffffffffu;
  216. switch (bfd_get_mach (abfd))
  217. {
  218. case bfd_mach_h8300:
  219. case bfd_mach_h8300hn:
  220. case bfd_mach_h8300sn:
  221. case bfd_mach_h8300sxn:
  222. /* Sign extend a 16-bit address. */
  223. if (address >= 0x8000)
  224. return address | 0xffff0000u;
  225. return address;
  226. case bfd_mach_h8300h:
  227. /* Sign extend a 24-bit address. */
  228. if (address >= 0x800000)
  229. return address | 0xff000000u;
  230. return address;
  231. case bfd_mach_h8300s:
  232. case bfd_mach_h8300sx:
  233. return address;
  234. default:
  235. abort ();
  236. }
  237. }