1 /* BFD library support routines for the Renesas H8/300 architecture.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 2000, 2001, 2002, 2003
3 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 static bfd_boolean h8300_scan
27 (const struct bfd_arch_info
*, const char *);
28 static const bfd_arch_info_type
* compatible
29 (const bfd_arch_info_type
*, const bfd_arch_info_type
*);
32 h8300_scan (const struct bfd_arch_info
*info
, const char *string
)
34 if (*string
!= 'h' && *string
!= 'H')
57 /* In ELF linker scripts, we typically express the architecture/machine
58 as architecture:machine.
60 So if we've matched so far and encounter a colon, try to match the
61 string following the colon. */
65 return h8300_scan (info
, string
);
68 if (*string
== 'h' || *string
== 'H')
71 if (*string
== 'n' || *string
== 'N')
72 return (info
->mach
== bfd_mach_h8300hn
);
74 return (info
->mach
== bfd_mach_h8300h
);
76 else if (*string
== 's' || *string
== 'S')
79 if (*string
== 'n' || *string
== 'N')
80 return (info
->mach
== bfd_mach_h8300sn
);
82 if (*string
== 'x' || *string
== 'X')
85 if (*string
== 'n' || *string
== 'N')
86 return (info
->mach
== bfd_mach_h8300sxn
);
88 return (info
->mach
== bfd_mach_h8300sx
);
91 return (info
->mach
== bfd_mach_h8300s
);
94 return info
->mach
== bfd_mach_h8300
;
97 /* This routine is provided two arch_infos and works out the machine
98 which would be compatible with both and returns a pointer to its
101 static const bfd_arch_info_type
*
102 compatible (const bfd_arch_info_type
*in
, const bfd_arch_info_type
*out
)
104 /* It's really not a good idea to mix and match modes. */
105 if (in
->arch
!= out
->arch
|| in
->mach
!= out
->mach
)
111 static const bfd_arch_info_type h8300sxn_info_struct
=
113 32, /* 32 bits in a word */
114 32, /* 32 bits in an address */
115 8, /* 8 bits in a byte */
118 "h8300sxn", /* arch_name */
119 "h8300sxn", /* printable name */
121 FALSE
, /* the default machine */
127 static const bfd_arch_info_type h8300sx_info_struct
=
129 32, /* 32 bits in a word */
130 32, /* 32 bits in an address */
131 8, /* 8 bits in a byte */
134 "h8300sx", /* arch_name */
135 "h8300sx", /* printable name */
137 FALSE
, /* the default machine */
140 &h8300sxn_info_struct
143 static const bfd_arch_info_type h8300sn_info_struct
=
145 32, /* 32 bits in a word. */
146 32, /* 32 bits in an address. */
147 8, /* 8 bits in a byte. */
150 "h8300sn", /* Architecture name. */
151 "h8300sn", /* Printable name. */
153 FALSE
, /* The default machine. */
160 static const bfd_arch_info_type h8300hn_info_struct
=
162 32, /* 32 bits in a word. */
163 32, /* 32 bits in an address. */
164 8, /* 8 bits in a byte. */
167 "h8300hn", /* Architecture name. */
168 "h8300hn", /* Printable name. */
170 FALSE
, /* The default machine. */
176 static const bfd_arch_info_type h8300s_info_struct
=
178 32, /* 32 bits in a word. */
179 32, /* 32 bits in an address. */
180 8, /* 8 bits in a byte. */
183 "h8300s", /* Architecture name. */
184 "h8300s", /* Printable name. */
186 FALSE
, /* The default machine. */
189 & h8300hn_info_struct
192 static const bfd_arch_info_type h8300h_info_struct
=
194 32, /* 32 bits in a word. */
195 32, /* 32 bits in an address. */
196 8, /* 8 bits in a byte. */
199 "h8300h", /* Architecture name. */
200 "h8300h", /* Printable name. */
202 FALSE
, /* The default machine. */
208 const bfd_arch_info_type bfd_h8300_arch
=
210 16, /* 16 bits in a word. */
211 16, /* 16 bits in an address. */
212 8, /* 8 bits in a byte. */
215 "h8300", /* Architecture name. */
216 "h8300", /* Printable name. */
218 TRUE
, /* The default machine. */
224 /* Pad the given address to 32 bits, converting 16-bit and 24-bit
225 addresses into the values they would have had on a h8s target. */
228 bfd_h8300_pad_address (bfd
*abfd
, bfd_vma address
)
230 /* Cope with bfd_vma's larger than 32 bits. */
231 address
&= 0xffffffffu
;
233 switch (bfd_get_mach (abfd
))
236 case bfd_mach_h8300hn
:
237 case bfd_mach_h8300sn
:
238 case bfd_mach_h8300sxn
:
239 /* Sign extend a 16-bit address. */
240 if (address
>= 0x8000)
241 return address
| 0xffff0000u
;
244 case bfd_mach_h8300h
:
245 /* Sign extend a 24-bit address. */
246 if (address
>= 0x800000)
247 return address
| 0xff000000u
;
250 case bfd_mach_h8300s
:
251 case bfd_mach_h8300sx
: