Automatic date update in version.in
[deliverable/binutils-gdb.git] / bfd / cpu-h8300.c
1 /* BFD library support routines for the Renesas H8/300 architecture.
2 Copyright (C) 1990-2019 Free Software Foundation, Inc.
3 Hacked by Steve Chamberlain of Cygnus Support.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
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.
11
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.
16
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. */
21
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "libbfd.h"
25
26 static bfd_boolean
27 h8300_scan (const struct bfd_arch_info *info, const char *string)
28 {
29 if (*string != 'h' && *string != 'H')
30 return FALSE;
31
32 string++;
33 if (*string != '8')
34 return FALSE;
35
36 string++;
37 if (*string == '/')
38 string++;
39
40 if (*string != '3')
41 return FALSE;
42 string++;
43 if (*string != '0')
44 return FALSE;
45 string++;
46 if (*string != '0')
47 return FALSE;
48 string++;
49 if (*string == '-')
50 string++;
51
52 /* In ELF linker scripts, we typically express the architecture/machine
53 as architecture:machine.
54
55 So if we've matched so far and encounter a colon, try to match the
56 string following the colon. */
57 if (*string == ':')
58 {
59 string++;
60 return h8300_scan (info, string);
61 }
62
63 if (*string == 'h' || *string == 'H')
64 {
65 string++;
66 if (*string == 'n' || *string == 'N')
67 return (info->mach == bfd_mach_h8300hn);
68
69 return (info->mach == bfd_mach_h8300h);
70 }
71 else if (*string == 's' || *string == 'S')
72 {
73 string++;
74 if (*string == 'n' || *string == 'N')
75 return (info->mach == bfd_mach_h8300sn);
76
77 if (*string == 'x' || *string == 'X')
78 {
79 string++;
80 if (*string == 'n' || *string == 'N')
81 return (info->mach == bfd_mach_h8300sxn);
82
83 return (info->mach == bfd_mach_h8300sx);
84 }
85
86 return (info->mach == bfd_mach_h8300s);
87 }
88 else
89 return info->mach == bfd_mach_h8300;
90 }
91
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
94 info structure. */
95
96 static const bfd_arch_info_type *
97 compatible (const bfd_arch_info_type *in, const bfd_arch_info_type *out)
98 {
99 if (in->arch != out->arch)
100 return 0;
101 if (in->mach == bfd_mach_h8300sx && out->mach == bfd_mach_h8300s)
102 return in;
103 if (in->mach == bfd_mach_h8300s && out->mach == bfd_mach_h8300sx)
104 return out;
105 if (in->mach == bfd_mach_h8300sxn && out->mach == bfd_mach_h8300sn)
106 return in;
107 if (in->mach == bfd_mach_h8300sn && out->mach == bfd_mach_h8300sxn)
108 return out;
109 /* It's really not a good idea to mix and match modes. */
110 if (in->mach != out->mach)
111 return 0;
112 else
113 return in;
114 }
115
116 #define N(word, addr, number, name, print, default, next) \
117 { word, addr, 8, bfd_arch_h8300, number, name, print, 1, default, \
118 compatible, h8300_scan, bfd_arch_default_fill, next, 0 }
119
120 static const bfd_arch_info_type h8300sxn_info_struct =
121 N (32, 16, bfd_mach_h8300sxn, "h8300sxn", "h8300sxn", FALSE, NULL);
122
123 static const bfd_arch_info_type h8300sx_info_struct =
124 N (32, 32, bfd_mach_h8300sx, "h8300sx", "h8300sx", FALSE, &h8300sxn_info_struct);
125
126 static const bfd_arch_info_type h8300sn_info_struct =
127 N (32, 16, bfd_mach_h8300sn, "h8300sn", "h8300sn", FALSE, &h8300sx_info_struct);
128
129 static const bfd_arch_info_type h8300hn_info_struct =
130 N (32, 16, bfd_mach_h8300hn, "h8300hn", "h8300hn", FALSE, &h8300sn_info_struct);
131
132 static const bfd_arch_info_type h8300s_info_struct =
133 N (32, 32, bfd_mach_h8300s, "h8300s", "h8300s", FALSE, & h8300hn_info_struct);
134
135 static const bfd_arch_info_type h8300h_info_struct =
136 N (32, 32, bfd_mach_h8300h, "h8300h", "h8300h", FALSE, &h8300s_info_struct);
137
138 const bfd_arch_info_type bfd_h8300_arch =
139 N (16, 16, bfd_mach_h8300, "h8300", "h8300", TRUE, &h8300h_info_struct);
140
141 /* Pad the given address to 32 bits, converting 16-bit and 24-bit
142 addresses into the values they would have had on a h8s target. */
143
144 bfd_vma
145 bfd_h8300_pad_address (bfd *abfd, bfd_vma address)
146 {
147 /* Cope with bfd_vma's larger than 32 bits. */
148 address &= 0xffffffffu;
149
150 switch (bfd_get_mach (abfd))
151 {
152 case bfd_mach_h8300:
153 case bfd_mach_h8300hn:
154 case bfd_mach_h8300sn:
155 case bfd_mach_h8300sxn:
156 /* Sign extend a 16-bit address. */
157 if (address >= 0x8000)
158 return address | 0xffff0000u;
159 return address;
160
161 case bfd_mach_h8300h:
162 /* Sign extend a 24-bit address. */
163 if (address >= 0x800000)
164 return address | 0xff000000u;
165 return address;
166
167 case bfd_mach_h8300s:
168 case bfd_mach_h8300sx:
169 return address;
170
171 default:
172 abort ();
173 }
174 }
This page took 0.03411 seconds and 4 git commands to generate.