]>
Commit | Line | Data |
---|---|---|
c2dcd04e | 1 | /* BFD library support routines for the Renesas H8/300 architecture. |
9553c638 | 2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 2000, 2001, 2002, |
3db64b00 | 3 | 2003, 2004, 2007 Free Software Foundation, Inc. |
252b5132 RH |
4 | Hacked by Steve Chamberlain of Cygnus Support. |
5 | ||
c2dcd04e | 6 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 7 | |
c2dcd04e NC |
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 | |
cd123cb7 | 10 | the Free Software Foundation; either version 3 of the License, or |
c2dcd04e | 11 | (at your option) any later version. |
252b5132 | 12 | |
c2dcd04e NC |
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. | |
252b5132 | 17 | |
c2dcd04e NC |
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 | |
cd123cb7 NC |
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
21 | MA 02110-1301, USA. */ | |
252b5132 | 22 | |
252b5132 | 23 | #include "sysdep.h" |
3db64b00 | 24 | #include "bfd.h" |
252b5132 RH |
25 | #include "libbfd.h" |
26 | ||
b34976b6 | 27 | static bfd_boolean |
c6baf75e | 28 | h8300_scan (const struct bfd_arch_info *info, const char *string) |
252b5132 RH |
29 | { |
30 | if (*string != 'h' && *string != 'H') | |
b34976b6 | 31 | return FALSE; |
252b5132 RH |
32 | |
33 | string++; | |
34 | if (*string != '8') | |
b34976b6 | 35 | return FALSE; |
252b5132 RH |
36 | |
37 | string++; | |
38 | if (*string == '/') | |
39 | string++; | |
40 | ||
41 | if (*string != '3') | |
b34976b6 | 42 | return FALSE; |
252b5132 RH |
43 | string++; |
44 | if (*string != '0') | |
b34976b6 | 45 | return FALSE; |
252b5132 RH |
46 | string++; |
47 | if (*string != '0') | |
b34976b6 | 48 | return FALSE; |
252b5132 RH |
49 | string++; |
50 | if (*string == '-') | |
51 | string++; | |
0a83638b JL |
52 | |
53 | /* In ELF linker scripts, we typically express the architecture/machine | |
54 | as architecture:machine. | |
55 | ||
56 | So if we've matched so far and encounter a colon, try to match the | |
57 | string following the colon. */ | |
58 | if (*string == ':') | |
59 | { | |
60 | string++; | |
eea78af1 | 61 | return h8300_scan (info, string); |
0a83638b JL |
62 | } |
63 | ||
252b5132 RH |
64 | if (*string == 'h' || *string == 'H') |
65 | { | |
8d9cd6b1 NC |
66 | string++; |
67 | if (*string == 'n' || *string == 'N') | |
68 | return (info->mach == bfd_mach_h8300hn); | |
69 | ||
252b5132 RH |
70 | return (info->mach == bfd_mach_h8300h); |
71 | } | |
72 | else if (*string == 's' || *string == 'S') | |
73 | { | |
8d9cd6b1 NC |
74 | string++; |
75 | if (*string == 'n' || *string == 'N') | |
76 | return (info->mach == bfd_mach_h8300sn); | |
77 | ||
5d1db417 | 78 | if (*string == 'x' || *string == 'X') |
f4984206 RS |
79 | { |
80 | string++; | |
81 | if (*string == 'n' || *string == 'N') | |
82 | return (info->mach == bfd_mach_h8300sxn); | |
83 | ||
84 | return (info->mach == bfd_mach_h8300sx); | |
85 | } | |
5d1db417 | 86 | |
252b5132 RH |
87 | return (info->mach == bfd_mach_h8300s); |
88 | } | |
89 | else | |
8d9cd6b1 | 90 | return info->mach == bfd_mach_h8300; |
252b5132 RH |
91 | } |
92 | ||
cc040812 NC |
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 | |
95 | info structure. */ | |
252b5132 RH |
96 | |
97 | static const bfd_arch_info_type * | |
c6baf75e | 98 | compatible (const bfd_arch_info_type *in, const bfd_arch_info_type *out) |
252b5132 | 99 | { |
aa02cc63 AO |
100 | if (in->arch != out->arch) |
101 | return 0; | |
102 | if (in->mach == bfd_mach_h8300sx && out->mach == bfd_mach_h8300s) | |
103 | return in; | |
104 | if (in->mach == bfd_mach_h8300s && out->mach == bfd_mach_h8300sx) | |
105 | return out; | |
106 | if (in->mach == bfd_mach_h8300sxn && out->mach == bfd_mach_h8300sn) | |
107 | return in; | |
108 | if (in->mach == bfd_mach_h8300sn && out->mach == bfd_mach_h8300sxn) | |
109 | return out; | |
252b5132 | 110 | /* It's really not a good idea to mix and match modes. */ |
aa02cc63 | 111 | if (in->mach != out->mach) |
252b5132 RH |
112 | return 0; |
113 | else | |
114 | return in; | |
115 | } | |
116 | ||
f4984206 RS |
117 | static const bfd_arch_info_type h8300sxn_info_struct = |
118 | { | |
119 | 32, /* 32 bits in a word */ | |
d4e2de6b | 120 | 16, /* 16 bits in an address */ |
f4984206 RS |
121 | 8, /* 8 bits in a byte */ |
122 | bfd_arch_h8300, | |
123 | bfd_mach_h8300sxn, | |
124 | "h8300sxn", /* arch_name */ | |
125 | "h8300sxn", /* printable name */ | |
126 | 1, | |
127 | FALSE, /* the default machine */ | |
128 | compatible, | |
129 | h8300_scan, | |
130 | 0 | |
131 | }; | |
132 | ||
5d1db417 MS |
133 | static const bfd_arch_info_type h8300sx_info_struct = |
134 | { | |
135 | 32, /* 32 bits in a word */ | |
136 | 32, /* 32 bits in an address */ | |
137 | 8, /* 8 bits in a byte */ | |
138 | bfd_arch_h8300, | |
139 | bfd_mach_h8300sx, | |
140 | "h8300sx", /* arch_name */ | |
141 | "h8300sx", /* printable name */ | |
142 | 1, | |
143 | FALSE, /* the default machine */ | |
144 | compatible, | |
145 | h8300_scan, | |
f4984206 | 146 | &h8300sxn_info_struct |
5d1db417 MS |
147 | }; |
148 | ||
8d9cd6b1 NC |
149 | static const bfd_arch_info_type h8300sn_info_struct = |
150 | { | |
151 | 32, /* 32 bits in a word. */ | |
d4e2de6b | 152 | 16, /* 16 bits in an address. */ |
8d9cd6b1 NC |
153 | 8, /* 8 bits in a byte. */ |
154 | bfd_arch_h8300, | |
155 | bfd_mach_h8300sn, | |
156 | "h8300sn", /* Architecture name. */ | |
157 | "h8300sn", /* Printable name. */ | |
158 | 1, | |
159 | FALSE, /* The default machine. */ | |
160 | compatible, | |
161 | h8300_scan, | |
5d1db417 | 162 | &h8300sx_info_struct |
8d9cd6b1 NC |
163 | }; |
164 | ||
8d9cd6b1 NC |
165 | static const bfd_arch_info_type h8300hn_info_struct = |
166 | { | |
167 | 32, /* 32 bits in a word. */ | |
d4e2de6b | 168 | 16, /* 16 bits in an address. */ |
8d9cd6b1 NC |
169 | 8, /* 8 bits in a byte. */ |
170 | bfd_arch_h8300, | |
171 | bfd_mach_h8300hn, | |
172 | "h8300hn", /* Architecture name. */ | |
173 | "h8300hn", /* Printable name. */ | |
174 | 1, | |
175 | FALSE, /* The default machine. */ | |
176 | compatible, | |
177 | h8300_scan, | |
178 | &h8300sn_info_struct | |
179 | }; | |
180 | ||
4c7aad1c | 181 | static const bfd_arch_info_type h8300s_info_struct = |
252b5132 | 182 | { |
8d9cd6b1 NC |
183 | 32, /* 32 bits in a word. */ |
184 | 32, /* 32 bits in an address. */ | |
185 | 8, /* 8 bits in a byte. */ | |
252b5132 | 186 | bfd_arch_h8300, |
4c7aad1c | 187 | bfd_mach_h8300s, |
8d9cd6b1 NC |
188 | "h8300s", /* Architecture name. */ |
189 | "h8300s", /* Printable name. */ | |
252b5132 | 190 | 1, |
8d9cd6b1 | 191 | FALSE, /* The default machine. */ |
252b5132 RH |
192 | compatible, |
193 | h8300_scan, | |
8d9cd6b1 | 194 | & h8300hn_info_struct |
252b5132 RH |
195 | }; |
196 | ||
197 | static const bfd_arch_info_type h8300h_info_struct = | |
198 | { | |
8d9cd6b1 NC |
199 | 32, /* 32 bits in a word. */ |
200 | 32, /* 32 bits in an address. */ | |
201 | 8, /* 8 bits in a byte. */ | |
252b5132 RH |
202 | bfd_arch_h8300, |
203 | bfd_mach_h8300h, | |
8d9cd6b1 NC |
204 | "h8300h", /* Architecture name. */ |
205 | "h8300h", /* Printable name. */ | |
252b5132 | 206 | 1, |
8d9cd6b1 | 207 | FALSE, /* The default machine. */ |
252b5132 RH |
208 | compatible, |
209 | h8300_scan, | |
4c7aad1c | 210 | &h8300s_info_struct |
252b5132 RH |
211 | }; |
212 | ||
213 | const bfd_arch_info_type bfd_h8300_arch = | |
214 | { | |
8d9cd6b1 NC |
215 | 16, /* 16 bits in a word. */ |
216 | 16, /* 16 bits in an address. */ | |
217 | 8, /* 8 bits in a byte. */ | |
252b5132 | 218 | bfd_arch_h8300, |
4c7aad1c | 219 | bfd_mach_h8300, |
8d9cd6b1 NC |
220 | "h8300", /* Architecture name. */ |
221 | "h8300", /* Printable name. */ | |
252b5132 | 222 | 1, |
8d9cd6b1 | 223 | TRUE, /* The default machine. */ |
252b5132 RH |
224 | compatible, |
225 | h8300_scan, | |
4c7aad1c | 226 | &h8300h_info_struct |
252b5132 | 227 | }; |
2808c7aa RS |
228 | |
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. */ | |
231 | ||
232 | bfd_vma | |
233 | bfd_h8300_pad_address (bfd *abfd, bfd_vma address) | |
234 | { | |
235 | /* Cope with bfd_vma's larger than 32 bits. */ | |
236 | address &= 0xffffffffu; | |
237 | ||
238 | switch (bfd_get_mach (abfd)) | |
239 | { | |
240 | case bfd_mach_h8300: | |
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; | |
247 | return address; | |
248 | ||
249 | case bfd_mach_h8300h: | |
250 | /* Sign extend a 24-bit address. */ | |
251 | if (address >= 0x800000) | |
252 | return address | 0xff000000u; | |
253 | return address; | |
254 | ||
255 | case bfd_mach_h8300s: | |
256 | case bfd_mach_h8300sx: | |
257 | return address; | |
258 | ||
259 | default: | |
260 | abort (); | |
261 | } | |
262 | } |