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