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.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
27 h8300_scan (const struct bfd_arch_info *info, const char *string)
29 if (*string != 'h' && *string != 'H')
52 /* In ELF linker scripts, we typically express the architecture/machine
53 as architecture:machine.
55 So if we've matched so far and encounter a colon, try to match the
56 string following the colon. */
60 return h8300_scan (info, string);
63 if (*string == 'h' || *string == 'H')
66 if (*string == 'n' || *string == 'N')
67 return (info->mach == bfd_mach_h8300hn);
69 return (info->mach == bfd_mach_h8300h);
71 else if (*string == 's' || *string == 'S')
74 if (*string == 'n' || *string == 'N')
75 return (info->mach == bfd_mach_h8300sn);
77 if (*string == 'x' || *string == 'X')
80 if (*string == 'n' || *string == 'N')
81 return (info->mach == bfd_mach_h8300sxn);
83 return (info->mach == bfd_mach_h8300sx);
86 return (info->mach == bfd_mach_h8300s);
89 return info->mach == bfd_mach_h8300;
92 /* This routine is provided two arch_infos and works out the machine
93 which would be compatible with both and returns a pointer to its
96 static const bfd_arch_info_type *
97 compatible (const bfd_arch_info_type *in, const bfd_arch_info_type *out)
99 if (in->arch != out->arch)
101 if (in->mach == bfd_mach_h8300sx && out->mach == bfd_mach_h8300s)
103 if (in->mach == bfd_mach_h8300s && out->mach == bfd_mach_h8300sx)
105 if (in->mach == bfd_mach_h8300sxn && out->mach == bfd_mach_h8300sn)
107 if (in->mach == bfd_mach_h8300sn && out->mach == bfd_mach_h8300sxn)
109 /* It's really not a good idea to mix and match modes. */
110 if (in->mach != out->mach)
116 static const bfd_arch_info_type h8300sxn_info_struct =
118 32, /* 32 bits in a word */
119 16, /* 16 bits in an address */
120 8, /* 8 bits in a byte */
123 "h8300sxn", /* arch_name */
124 "h8300sxn", /* printable name */
126 FALSE, /* the default machine */
129 bfd_arch_default_fill,
133 static const bfd_arch_info_type h8300sx_info_struct =
135 32, /* 32 bits in a word */
136 32, /* 32 bits in an address */
137 8, /* 8 bits in a byte */
140 "h8300sx", /* arch_name */
141 "h8300sx", /* printable name */
143 FALSE, /* the default machine */
146 bfd_arch_default_fill,
147 &h8300sxn_info_struct
150 static const bfd_arch_info_type h8300sn_info_struct =
152 32, /* 32 bits in a word. */
153 16, /* 16 bits in an address. */
154 8, /* 8 bits in a byte. */
157 "h8300sn", /* Architecture name. */
158 "h8300sn", /* Printable name. */
160 FALSE, /* The default machine. */
163 bfd_arch_default_fill,
167 static const bfd_arch_info_type h8300hn_info_struct =
169 32, /* 32 bits in a word. */
170 16, /* 16 bits in an address. */
171 8, /* 8 bits in a byte. */
174 "h8300hn", /* Architecture name. */
175 "h8300hn", /* Printable name. */
177 FALSE, /* The default machine. */
180 bfd_arch_default_fill,
184 static const bfd_arch_info_type h8300s_info_struct =
186 32, /* 32 bits in a word. */
187 32, /* 32 bits in an address. */
188 8, /* 8 bits in a byte. */
191 "h8300s", /* Architecture name. */
192 "h8300s", /* Printable name. */
194 FALSE, /* The default machine. */
197 bfd_arch_default_fill,
198 & h8300hn_info_struct
201 static const bfd_arch_info_type h8300h_info_struct =
203 32, /* 32 bits in a word. */
204 32, /* 32 bits in an address. */
205 8, /* 8 bits in a byte. */
208 "h8300h", /* Architecture name. */
209 "h8300h", /* Printable name. */
211 FALSE, /* The default machine. */
214 bfd_arch_default_fill,
218 const bfd_arch_info_type bfd_h8300_arch =
220 16, /* 16 bits in a word. */
221 16, /* 16 bits in an address. */
222 8, /* 8 bits in a byte. */
225 "h8300", /* Architecture name. */
226 "h8300", /* Printable name. */
228 TRUE, /* The default machine. */
231 bfd_arch_default_fill,
235 /* Pad the given address to 32 bits, converting 16-bit and 24-bit
236 addresses into the values they would have had on a h8s target. */
239 bfd_h8300_pad_address (bfd *abfd, bfd_vma address)
241 /* Cope with bfd_vma's larger than 32 bits. */
242 address &= 0xffffffffu;
244 switch (bfd_get_mach (abfd))
247 case bfd_mach_h8300hn:
248 case bfd_mach_h8300sn:
249 case bfd_mach_h8300sxn:
250 /* Sign extend a 16-bit address. */
251 if (address >= 0x8000)
252 return address | 0xffff0000u;
255 case bfd_mach_h8300h:
256 /* Sign extend a 24-bit address. */
257 if (address >= 0x800000)
258 return address | 0xff000000u;
261 case bfd_mach_h8300s:
262 case bfd_mach_h8300sx: