1 /* BFD library support routines for the Renesas H8/300 architecture.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 2000, 2001, 2002,
3 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
4 Hacked by Steve Chamberlain of Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
28 h8300_scan (const struct bfd_arch_info
*info
, const char *string
)
30 if (*string
!= 'h' && *string
!= 'H')
53 /* In ELF linker scripts, we typically express the architecture/machine
54 as architecture:machine.
56 So if we've matched so far and encounter a colon, try to match the
57 string following the colon. */
61 return h8300_scan (info
, string
);
64 if (*string
== 'h' || *string
== 'H')
67 if (*string
== 'n' || *string
== 'N')
68 return (info
->mach
== bfd_mach_h8300hn
);
70 return (info
->mach
== bfd_mach_h8300h
);
72 else if (*string
== 's' || *string
== 'S')
75 if (*string
== 'n' || *string
== 'N')
76 return (info
->mach
== bfd_mach_h8300sn
);
78 if (*string
== 'x' || *string
== 'X')
81 if (*string
== 'n' || *string
== 'N')
82 return (info
->mach
== bfd_mach_h8300sxn
);
84 return (info
->mach
== bfd_mach_h8300sx
);
87 return (info
->mach
== bfd_mach_h8300s
);
90 return info
->mach
== bfd_mach_h8300
;
93 /* This routine is provided two arch_infos and works out the machine
94 which would be compatible with both and returns a pointer to its
97 static const bfd_arch_info_type
*
98 compatible (const bfd_arch_info_type
*in
, const bfd_arch_info_type
*out
)
100 if (in
->arch
!= out
->arch
)
102 if (in
->mach
== bfd_mach_h8300sx
&& out
->mach
== bfd_mach_h8300s
)
104 if (in
->mach
== bfd_mach_h8300s
&& out
->mach
== bfd_mach_h8300sx
)
106 if (in
->mach
== bfd_mach_h8300sxn
&& out
->mach
== bfd_mach_h8300sn
)
108 if (in
->mach
== bfd_mach_h8300sn
&& out
->mach
== bfd_mach_h8300sxn
)
110 /* It's really not a good idea to mix and match modes. */
111 if (in
->mach
!= out
->mach
)
117 static const bfd_arch_info_type h8300sxn_info_struct
=
119 32, /* 32 bits in a word */
120 16, /* 16 bits in an address */
121 8, /* 8 bits in a byte */
124 "h8300sxn", /* arch_name */
125 "h8300sxn", /* printable name */
127 FALSE
, /* the default machine */
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 &h8300sxn_info_struct
149 static const bfd_arch_info_type h8300sn_info_struct
=
151 32, /* 32 bits in a word. */
152 16, /* 16 bits in an address. */
153 8, /* 8 bits in a byte. */
156 "h8300sn", /* Architecture name. */
157 "h8300sn", /* Printable name. */
159 FALSE
, /* The default machine. */
165 static const bfd_arch_info_type h8300hn_info_struct
=
167 32, /* 32 bits in a word. */
168 16, /* 16 bits in an address. */
169 8, /* 8 bits in a byte. */
172 "h8300hn", /* Architecture name. */
173 "h8300hn", /* Printable name. */
175 FALSE
, /* The default machine. */
181 static const bfd_arch_info_type h8300s_info_struct
=
183 32, /* 32 bits in a word. */
184 32, /* 32 bits in an address. */
185 8, /* 8 bits in a byte. */
188 "h8300s", /* Architecture name. */
189 "h8300s", /* Printable name. */
191 FALSE
, /* The default machine. */
194 & h8300hn_info_struct
197 static const bfd_arch_info_type h8300h_info_struct
=
199 32, /* 32 bits in a word. */
200 32, /* 32 bits in an address. */
201 8, /* 8 bits in a byte. */
204 "h8300h", /* Architecture name. */
205 "h8300h", /* Printable name. */
207 FALSE
, /* The default machine. */
213 const bfd_arch_info_type bfd_h8300_arch
=
215 16, /* 16 bits in a word. */
216 16, /* 16 bits in an address. */
217 8, /* 8 bits in a byte. */
220 "h8300", /* Architecture name. */
221 "h8300", /* Printable name. */
223 TRUE
, /* The default machine. */
229 /* Pad the given address to 32 bits, converting 16-bit and 24-bit
230 addresses into the values they would have had on a h8s target. */
233 bfd_h8300_pad_address (bfd
*abfd
, bfd_vma address
)
235 /* Cope with bfd_vma's larger than 32 bits. */
236 address
&= 0xffffffffu
;
238 switch (bfd_get_mach (abfd
))
241 case bfd_mach_h8300hn
:
242 case bfd_mach_h8300sn
:
243 case bfd_mach_h8300sxn
:
244 /* Sign extend a 16-bit address. */
245 if (address
>= 0x8000)
246 return address
| 0xffff0000u
;
249 case bfd_mach_h8300h
:
250 /* Sign extend a 24-bit address. */
251 if (address
>= 0x800000)
252 return address
| 0xff000000u
;
255 case bfd_mach_h8300s
:
256 case bfd_mach_h8300sx
: