Commit | Line | Data |
---|---|---|
a06ea964 | 1 | /* BFD support for AArch64. |
82704155 | 2 | Copyright (C) 2009-2019 Free Software Foundation, Inc. |
a06ea964 NC |
3 | Contributed by ARM Ltd. |
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; see the file COPYING3. If not, | |
19 | see <http://www.gnu.org/licenses/>. */ | |
20 | ||
21 | #include "sysdep.h" | |
22 | #include "bfd.h" | |
23 | #include "libbfd.h" | |
24 | #include "libiberty.h" | |
25 | ||
26 | /* This routine is provided two arch_infos and works out which Aarch64 | |
27 | machine which would be compatible with both and returns a pointer | |
28 | to its info structure. */ | |
29 | ||
30 | static const bfd_arch_info_type * | |
31 | compatible (const bfd_arch_info_type * a, const bfd_arch_info_type * b) | |
32 | { | |
33 | /* If a & b are for different architecture we can do nothing. */ | |
34 | if (a->arch != b->arch) | |
35 | return NULL; | |
36 | ||
37 | /* If a & b are for the same machine then all is well. */ | |
38 | if (a->mach == b->mach) | |
39 | return a; | |
40 | ||
cec5225b YZ |
41 | /* Don't allow mixing ilp32 with lp64. */ |
42 | if ((a->mach & bfd_mach_aarch64_ilp32) != (b->mach & bfd_mach_aarch64_ilp32)) | |
43 | return NULL; | |
44 | ||
a06ea964 NC |
45 | /* Otherwise if either a or b is the 'default' machine |
46 | then it can be polymorphed into the other. */ | |
47 | if (a->the_default) | |
48 | return b; | |
49 | ||
50 | if (b->the_default) | |
51 | return a; | |
52 | ||
53 | /* So far all newer cores are | |
54 | supersets of previous cores. */ | |
55 | if (a->mach < b->mach) | |
56 | return b; | |
57 | else if (a->mach > b->mach) | |
58 | return a; | |
59 | ||
60 | /* Never reached! */ | |
61 | return NULL; | |
62 | } | |
63 | ||
64 | static struct | |
65 | { | |
66 | unsigned int mach; | |
67 | char *name; | |
68 | } | |
69 | processors[] = | |
70 | { | |
71 | /* These two are example CPUs supported in GCC, once we have real | |
72 | CPUs they will be removed. */ | |
73 | { bfd_mach_aarch64, "example-1" }, | |
74 | { bfd_mach_aarch64, "example-2" } | |
75 | }; | |
76 | ||
77 | static bfd_boolean | |
78 | scan (const struct bfd_arch_info *info, const char *string) | |
79 | { | |
80 | int i; | |
81 | ||
82 | /* First test for an exact match. */ | |
83 | if (strcasecmp (string, info->printable_name) == 0) | |
84 | return TRUE; | |
85 | ||
86 | /* Next check for a processor name instead of an Architecture name. */ | |
87 | for (i = sizeof (processors) / sizeof (processors[0]); i--;) | |
88 | { | |
89 | if (strcasecmp (string, processors[i].name) == 0) | |
90 | break; | |
91 | } | |
92 | ||
93 | if (i != -1 && info->mach == processors[i].mach) | |
94 | return TRUE; | |
95 | ||
96 | /* Finally check for the default architecture. */ | |
97 | if (strcasecmp (string, "aarch64") == 0) | |
98 | return info->the_default; | |
99 | ||
100 | return FALSE; | |
101 | } | |
102 | ||
3145b997 YN |
103 | #define N(NUMBER, PRINT, WORDSIZE, DEFAULT, NEXT) \ |
104 | { WORDSIZE, WORDSIZE, 8, bfd_arch_aarch64, NUMBER, \ | |
a06ea964 NC |
105 | "aarch64", PRINT, 4, DEFAULT, compatible, scan, \ |
106 | bfd_arch_default_fill, NEXT } | |
107 | ||
cec5225b | 108 | static const bfd_arch_info_type bfd_aarch64_arch_ilp32 = |
3145b997 | 109 | N (bfd_mach_aarch64_ilp32, "aarch64:ilp32", 32, FALSE, NULL); |
a06ea964 | 110 | |
cec5225b | 111 | const bfd_arch_info_type bfd_aarch64_arch = |
3145b997 | 112 | N (0, "aarch64", 64, TRUE, &bfd_aarch64_arch_ilp32); |
a06ea964 NC |
113 | |
114 | bfd_boolean | |
115 | bfd_is_aarch64_special_symbol_name (const char *name, int type) | |
116 | { | |
117 | if (!name || name[0] != '$') | |
118 | return FALSE; | |
119 | if (name[1] == 'x' || name[1] == 'd') | |
120 | type &= BFD_AARCH64_SPECIAL_SYM_TYPE_MAP; | |
121 | else if (name[1] == 'm' || name[1] == 'f' || name[1] == 'p') | |
122 | type &= BFD_AARCH64_SPECIAL_SYM_TYPE_TAG; | |
123 | else | |
124 | return FALSE; | |
125 | ||
126 | return (type != 0 && (name[2] == 0 || name[2] == '.')); | |
127 | } |