/src/binutils-gdb/bfd/cpu-aarch64.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* BFD support for AArch64. |
2 | | Copyright (C) 2009-2025 Free Software Foundation, Inc. |
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 | | #include "cpu-aarch64.h" |
26 | | |
27 | | /* This routine is provided two arch_infos and works out which Aarch64 |
28 | | machine which would be compatible with both and returns a pointer |
29 | | to its info structure. */ |
30 | | |
31 | | static const bfd_arch_info_type * |
32 | | compatible (const bfd_arch_info_type * a, const bfd_arch_info_type * b) |
33 | 0 | { |
34 | | /* If a & b are for different architecture we can do nothing. */ |
35 | 0 | if (a->arch != b->arch) |
36 | 0 | return NULL; |
37 | | |
38 | | /* If a & b are for the same machine then all is well. */ |
39 | 0 | if (a->mach == b->mach) |
40 | 0 | return a; |
41 | | |
42 | | /* Don't allow mixing data models. */ |
43 | 0 | if ((a->mach ^ b->mach) & (bfd_mach_aarch64_ilp32 | bfd_mach_aarch64_llp64)) |
44 | 0 | return NULL; |
45 | | |
46 | | /* Otherwise if either a or b is the 'default' machine |
47 | | then it can be polymorphed into the other. */ |
48 | 0 | if (a->the_default) |
49 | 0 | return b; |
50 | | |
51 | 0 | if (b->the_default) |
52 | 0 | return a; |
53 | | |
54 | | /* So far all newer cores are |
55 | | supersets of previous cores. */ |
56 | 0 | if (a->mach < b->mach) |
57 | 0 | return b; |
58 | 0 | else if (a->mach > b->mach) |
59 | 0 | return a; |
60 | | |
61 | | /* Never reached! */ |
62 | 0 | return NULL; |
63 | 0 | } |
64 | | |
65 | | static struct |
66 | | { |
67 | | unsigned int mach; |
68 | | char *name; |
69 | | } |
70 | | processors[] = |
71 | | { |
72 | | { bfd_mach_aarch64, "cortex-a34" }, |
73 | | { bfd_mach_aarch64, "cortex-a65" }, |
74 | | { bfd_mach_aarch64, "cortex-a65ae" }, |
75 | | { bfd_mach_aarch64, "cortex-a76ae" }, |
76 | | { bfd_mach_aarch64, "cortex-a77" }, |
77 | | { bfd_mach_aarch64, "cortex-a720" }, |
78 | | { bfd_mach_aarch64, "cortex-x3" }, |
79 | | { bfd_mach_aarch64, "cortex-x4" }, |
80 | | }; |
81 | | |
82 | | static bool |
83 | | scan (const struct bfd_arch_info *info, const char *string) |
84 | 0 | { |
85 | 0 | int i; |
86 | | |
87 | | /* First test for an exact match. */ |
88 | 0 | if (strcasecmp (string, info->printable_name) == 0) |
89 | 0 | return true; |
90 | | |
91 | | /* If there is a prefix of "aarch64:" then skip it. */ |
92 | 0 | const char * colon; |
93 | 0 | if ((colon = strchr (string, ':')) != NULL) |
94 | 0 | { |
95 | 0 | if (strncasecmp (string, "aarch64", colon - string) != 0) |
96 | 0 | return false; |
97 | 0 | string = colon + 1; |
98 | 0 | } |
99 | | |
100 | | /* Next check for a processor name instead of an Architecture name. */ |
101 | 0 | for (i = sizeof (processors) / sizeof (processors[0]); i--;) |
102 | 0 | { |
103 | 0 | if (strcasecmp (string, processors[i].name) == 0) |
104 | 0 | break; |
105 | 0 | } |
106 | |
|
107 | 0 | if (i != -1 && info->mach == processors[i].mach) |
108 | 0 | return true; |
109 | | |
110 | | /* Finally check for the default architecture. */ |
111 | 0 | if (strcasecmp (string, "aarch64") == 0) |
112 | 0 | return info->the_default; |
113 | | |
114 | 0 | return false; |
115 | 0 | } |
116 | | |
117 | | /* Figure out if llp64 is default */ |
118 | | #if DEFAULT_VECTOR == aarch64_pe_le_vec |
119 | | #define LLP64_DEFAULT true |
120 | | #define AARCH64_DEFAULT false |
121 | | #else |
122 | | #define LLP64_DEFAULT false |
123 | | #define AARCH64_DEFAULT true |
124 | | #endif |
125 | | |
126 | | #define N(NUMBER, PRINT, WORDSIZE, ADDRSIZE, DEFAULT, NEXT) \ |
127 | | { WORDSIZE, ADDRSIZE, 8, bfd_arch_aarch64, NUMBER, \ |
128 | | "aarch64", PRINT, 4, DEFAULT, compatible, scan, \ |
129 | | bfd_arch_default_fill, NEXT, 0 } |
130 | | |
131 | | static const bfd_arch_info_type bfd_aarch64_arch_v8_r = |
132 | | N (bfd_mach_aarch64_8R, "aarch64:armv8-r", 64, 64, false, NULL); |
133 | | |
134 | | static const bfd_arch_info_type bfd_aarch64_arch_ilp32 = |
135 | | N (bfd_mach_aarch64_ilp32, "aarch64:ilp32", 32, 32, false, |
136 | | &bfd_aarch64_arch_v8_r); |
137 | | |
138 | | static const bfd_arch_info_type bfd_aarch64_arch_llp64 = |
139 | | N (bfd_mach_aarch64_llp64, "aarch64:llp64", 32, 64, LLP64_DEFAULT, |
140 | | &bfd_aarch64_arch_ilp32); |
141 | | |
142 | | const bfd_arch_info_type bfd_aarch64_arch = |
143 | | N (0, "aarch64", 64, 64, AARCH64_DEFAULT, &bfd_aarch64_arch_llp64); |
144 | | |
145 | | bool |
146 | | bfd_is_aarch64_special_symbol_name (const char *name, int type) |
147 | 73 | { |
148 | 73 | if (!name || name[0] != '$') |
149 | 73 | return false; |
150 | 0 | if (name[1] == 'x' || name[1] == 'd') |
151 | 0 | type &= BFD_AARCH64_SPECIAL_SYM_TYPE_MAP; |
152 | 0 | else if (name[1] == 'm' || name[1] == 'f' || name[1] == 'p') |
153 | 0 | type &= BFD_AARCH64_SPECIAL_SYM_TYPE_TAG; |
154 | 0 | else |
155 | 0 | return false; |
156 | | |
157 | 0 | return (type != 0 && (name[2] == 0 || name[2] == '.')); |
158 | 0 | } |