arc-func.h revision 1.1.1.6 1 1.1 christos /* Replace functions for the ARC relocs.
2 1.1.1.6 christos Copyright (C) 2015-2024 Free Software Foundation, Inc.
3 1.1 christos
4 1.1 christos This file is part of GAS, the GNU Assembler, GDB, the GNU debugger, and
5 1.1 christos the GNU Binutils.
6 1.1 christos
7 1.1 christos GAS/GDB is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3, or (at your option)
10 1.1 christos any later version.
11 1.1 christos
12 1.1 christos GAS/GDB is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with GAS or GDB; see the file COPYING3. If not, write to
19 1.1 christos the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
20 1.1 christos MA 02110-1301, USA. */
21 1.1 christos
22 1.1 christos /* mask = 00000000000000000000000000000000. */
23 1.1 christos #ifndef REPLACE_none
24 1.1 christos #define REPLACE_none
25 1.1 christos ATTRIBUTE_UNUSED static unsigned
26 1.1 christos replace_none (unsigned insn, int value ATTRIBUTE_UNUSED)
27 1.1 christos {
28 1.1.1.2 christos insn = insn & ~0x00;
29 1.1 christos
30 1.1 christos return insn;
31 1.1 christos }
32 1.1 christos
33 1.1 christos #endif /* REPLACE_none */
34 1.1 christos
35 1.1 christos /* mask = 11111111. */
36 1.1 christos #ifndef REPLACE_bits8
37 1.1 christos #define REPLACE_bits8
38 1.1 christos ATTRIBUTE_UNUSED static unsigned
39 1.1 christos replace_bits8 (unsigned insn, int value ATTRIBUTE_UNUSED)
40 1.1 christos {
41 1.1.1.2 christos insn = insn & ~0xff;
42 1.1 christos insn |= ((value >> 0) & 0x00ff) << 0;
43 1.1 christos
44 1.1 christos return insn;
45 1.1 christos }
46 1.1 christos
47 1.1 christos #endif /* REPLACE_bits8 */
48 1.1 christos
49 1.1 christos /* mask = 1111111111111111. */
50 1.1 christos #ifndef REPLACE_bits16
51 1.1 christos #define REPLACE_bits16
52 1.1 christos ATTRIBUTE_UNUSED static unsigned
53 1.1 christos replace_bits16 (unsigned insn, int value ATTRIBUTE_UNUSED)
54 1.1 christos {
55 1.1.1.2 christos insn = insn & ~0xffff;
56 1.1 christos insn |= ((value >> 0) & 0xffff) << 0;
57 1.1 christos
58 1.1 christos return insn;
59 1.1 christos }
60 1.1 christos
61 1.1 christos #endif /* REPLACE_bits16 */
62 1.1 christos
63 1.1 christos /* mask = 111111111111111111111111. */
64 1.1 christos #ifndef REPLACE_bits24
65 1.1 christos #define REPLACE_bits24
66 1.1 christos ATTRIBUTE_UNUSED static unsigned
67 1.1 christos replace_bits24 (unsigned insn, int value ATTRIBUTE_UNUSED)
68 1.1 christos {
69 1.1.1.2 christos insn = insn & ~0xffffff;
70 1.1 christos insn |= ((value >> 0) & 0xffffff) << 0;
71 1.1 christos
72 1.1 christos return insn;
73 1.1 christos }
74 1.1 christos
75 1.1 christos #endif /* REPLACE_bits24 */
76 1.1 christos
77 1.1.1.2 christos /* Special 24 bit replace for big endian. */
78 1.1.1.2 christos /* mask = 111111111111111111111111. */
79 1.1.1.2 christos #ifndef REPLACE_bits24_be
80 1.1.1.2 christos #define REPLACE_bits24_be
81 1.1.1.2 christos ATTRIBUTE_UNUSED static unsigned
82 1.1.1.2 christos replace_bits24_be (unsigned insn, int value ATTRIBUTE_UNUSED)
83 1.1.1.2 christos {
84 1.1.1.2 christos insn = insn & ~0xffffff00;
85 1.1.1.2 christos insn |= ((value >> 0) & 0xffffff) << 8;
86 1.1.1.2 christos
87 1.1.1.2 christos return insn;
88 1.1.1.2 christos }
89 1.1.1.2 christos
90 1.1.1.2 christos #endif /* REPLACE_bits24_be */
91 1.1.1.2 christos
92 1.1 christos /* mask = 11111111111111111111111111111111. */
93 1.1 christos #ifndef REPLACE_word32
94 1.1 christos #define REPLACE_word32
95 1.1 christos ATTRIBUTE_UNUSED static unsigned
96 1.1 christos replace_word32 (unsigned insn, int value ATTRIBUTE_UNUSED)
97 1.1 christos {
98 1.1.1.2 christos insn = insn & ~0xffffffff;
99 1.1 christos insn |= ((value >> 0) & 0xffffffff) << 0;
100 1.1 christos
101 1.1 christos return insn;
102 1.1 christos }
103 1.1 christos
104 1.1 christos #endif /* REPLACE_word32 */
105 1.1 christos
106 1.1 christos /* mask = 0000000000000000000000000000000011111111111111111111111111111111. */
107 1.1 christos #ifndef REPLACE_limm
108 1.1 christos #define REPLACE_limm
109 1.1 christos ATTRIBUTE_UNUSED static unsigned
110 1.1 christos replace_limm (unsigned insn, int value ATTRIBUTE_UNUSED)
111 1.1 christos {
112 1.1.1.2 christos insn = insn & ~0xffffffff;
113 1.1 christos insn |= ((value >> 0) & 0xffffffff) << 0;
114 1.1 christos
115 1.1 christos return insn;
116 1.1 christos }
117 1.1 christos
118 1.1 christos #endif /* REPLACE_limm */
119 1.1 christos
120 1.1 christos /* mask = 000000000000000011111111111111111111111111111111. */
121 1.1 christos #ifndef REPLACE_limms
122 1.1 christos #define REPLACE_limms
123 1.1 christos ATTRIBUTE_UNUSED static unsigned
124 1.1 christos replace_limms (unsigned insn, int value ATTRIBUTE_UNUSED)
125 1.1 christos {
126 1.1.1.2 christos insn = insn & ~0xffffffff;
127 1.1 christos insn |= ((value >> 0) & 0xffffffff) << 0;
128 1.1 christos
129 1.1 christos return insn;
130 1.1 christos }
131 1.1 christos
132 1.1 christos #endif /* REPLACE_limms */
133 1.1 christos
134 1.1 christos /* mask = 00000111111111102222222222000000. */
135 1.1 christos #ifndef REPLACE_disp21h
136 1.1 christos #define REPLACE_disp21h
137 1.1 christos ATTRIBUTE_UNUSED static unsigned
138 1.1 christos replace_disp21h (unsigned insn, int value ATTRIBUTE_UNUSED)
139 1.1 christos {
140 1.1.1.2 christos insn = insn & ~0x7feffc0;
141 1.1 christos insn |= ((value >> 0) & 0x03ff) << 17;
142 1.1 christos insn |= ((value >> 10) & 0x03ff) << 6;
143 1.1 christos
144 1.1 christos return insn;
145 1.1 christos }
146 1.1 christos
147 1.1 christos #endif /* REPLACE_disp21h */
148 1.1 christos
149 1.1 christos /* mask = 00000111111111002222222222000000. */
150 1.1 christos #ifndef REPLACE_disp21w
151 1.1 christos #define REPLACE_disp21w
152 1.1 christos ATTRIBUTE_UNUSED static unsigned
153 1.1 christos replace_disp21w (unsigned insn, int value ATTRIBUTE_UNUSED)
154 1.1 christos {
155 1.1.1.2 christos insn = insn & ~0x7fcffc0;
156 1.1 christos insn |= ((value >> 0) & 0x01ff) << 18;
157 1.1 christos insn |= ((value >> 9) & 0x03ff) << 6;
158 1.1 christos
159 1.1 christos return insn;
160 1.1 christos }
161 1.1 christos
162 1.1 christos #endif /* REPLACE_disp21w */
163 1.1 christos
164 1.1 christos /* mask = 00000111111111102222222222003333. */
165 1.1 christos #ifndef REPLACE_disp25h
166 1.1 christos #define REPLACE_disp25h
167 1.1 christos ATTRIBUTE_UNUSED static unsigned
168 1.1 christos replace_disp25h (unsigned insn, int value ATTRIBUTE_UNUSED)
169 1.1 christos {
170 1.1.1.2 christos insn = insn & ~0x7feffcf;
171 1.1 christos insn |= ((value >> 0) & 0x03ff) << 17;
172 1.1 christos insn |= ((value >> 10) & 0x03ff) << 6;
173 1.1 christos insn |= ((value >> 20) & 0x000f) << 0;
174 1.1 christos
175 1.1 christos return insn;
176 1.1 christos }
177 1.1 christos
178 1.1 christos #endif /* REPLACE_disp25h */
179 1.1 christos
180 1.1 christos /* mask = 00000111111111002222222222003333. */
181 1.1 christos #ifndef REPLACE_disp25w
182 1.1 christos #define REPLACE_disp25w
183 1.1 christos ATTRIBUTE_UNUSED static unsigned
184 1.1 christos replace_disp25w (unsigned insn, int value ATTRIBUTE_UNUSED)
185 1.1 christos {
186 1.1.1.2 christos insn = insn & ~0x7fcffcf;
187 1.1 christos insn |= ((value >> 0) & 0x01ff) << 18;
188 1.1 christos insn |= ((value >> 9) & 0x03ff) << 6;
189 1.1 christos insn |= ((value >> 19) & 0x000f) << 0;
190 1.1 christos
191 1.1 christos return insn;
192 1.1 christos }
193 1.1 christos
194 1.1 christos #endif /* REPLACE_disp25w */
195 1.1 christos
196 1.1 christos /* mask = 00000000000000000000000111111111. */
197 1.1 christos #ifndef REPLACE_disp9
198 1.1 christos #define REPLACE_disp9
199 1.1 christos ATTRIBUTE_UNUSED static unsigned
200 1.1 christos replace_disp9 (unsigned insn, int value ATTRIBUTE_UNUSED)
201 1.1 christos {
202 1.1.1.2 christos insn = insn & ~0x1ff;
203 1.1 christos insn |= ((value >> 0) & 0x01ff) << 0;
204 1.1 christos
205 1.1 christos return insn;
206 1.1 christos }
207 1.1 christos
208 1.1 christos #endif /* REPLACE_disp9 */
209 1.1 christos
210 1.1 christos /* mask = 00000000111111112000000000000000. */
211 1.1 christos #ifndef REPLACE_disp9ls
212 1.1 christos #define REPLACE_disp9ls
213 1.1 christos ATTRIBUTE_UNUSED static unsigned
214 1.1 christos replace_disp9ls (unsigned insn, int value ATTRIBUTE_UNUSED)
215 1.1 christos {
216 1.1.1.2 christos insn = insn & ~0xff8000;
217 1.1 christos insn |= ((value >> 0) & 0x00ff) << 16;
218 1.1 christos insn |= ((value >> 8) & 0x0001) << 15;
219 1.1 christos
220 1.1 christos return insn;
221 1.1 christos }
222 1.1 christos
223 1.1 christos #endif /* REPLACE_disp9ls */
224 1.1 christos
225 1.1 christos /* mask = 0000000111111111. */
226 1.1 christos #ifndef REPLACE_disp9s
227 1.1 christos #define REPLACE_disp9s
228 1.1 christos ATTRIBUTE_UNUSED static unsigned
229 1.1 christos replace_disp9s (unsigned insn, int value ATTRIBUTE_UNUSED)
230 1.1 christos {
231 1.1.1.2 christos insn = insn & ~0x1ff;
232 1.1 christos insn |= ((value >> 0) & 0x01ff) << 0;
233 1.1 christos
234 1.1 christos return insn;
235 1.1 christos }
236 1.1 christos
237 1.1 christos #endif /* REPLACE_disp9s */
238 1.1 christos
239 1.1 christos /* mask = 0000011111111111. */
240 1.1 christos #ifndef REPLACE_disp13s
241 1.1 christos #define REPLACE_disp13s
242 1.1 christos ATTRIBUTE_UNUSED static unsigned
243 1.1 christos replace_disp13s (unsigned insn, int value ATTRIBUTE_UNUSED)
244 1.1 christos {
245 1.1.1.2 christos insn = insn & ~0x7ff;
246 1.1 christos insn |= ((value >> 0) & 0x07ff) << 0;
247 1.1 christos
248 1.1 christos return insn;
249 1.1 christos }
250 1.1 christos
251 1.1 christos #endif /* REPLACE_disp13s */
252 1.1 christos
253 1.1 christos /* mask = 0000022222200111. */
254 1.1 christos #ifndef REPLACE_disp9s1
255 1.1 christos #define REPLACE_disp9s1
256 1.1 christos ATTRIBUTE_UNUSED static unsigned
257 1.1 christos replace_disp9s1 (unsigned insn, int value ATTRIBUTE_UNUSED)
258 1.1 christos {
259 1.1.1.2 christos insn = insn & ~0x7e7;
260 1.1 christos insn |= ((value >> 0) & 0x0007) << 0;
261 1.1 christos insn |= ((value >> 3) & 0x003f) << 5;
262 1.1 christos
263 1.1 christos return insn;
264 1.1 christos }
265 1.1 christos
266 1.1 christos #endif /* REPLACE_disp9s1 */
267 1.1.1.3 christos
268 1.1.1.3 christos /* mask = 00000000000000000000111111222222. */
269 1.1.1.3 christos #ifndef REPLACE_disp12s
270 1.1.1.3 christos #define REPLACE_disp12s
271 1.1.1.3 christos ATTRIBUTE_UNUSED static unsigned
272 1.1.1.3 christos replace_disp12s (unsigned insn, int value ATTRIBUTE_UNUSED)
273 1.1.1.3 christos {
274 1.1.1.3 christos insn = insn & ~0xfff;
275 1.1.1.3 christos insn |= ((value >> 0) & 0x003f) << 6;
276 1.1.1.3 christos insn |= ((value >> 6) & 0x003f) << 0;
277 1.1.1.3 christos return insn;
278 1.1.1.3 christos }
279 1.1.1.3 christos
280 1.1.1.3 christos #endif /* REPLACE_disp12s */
281 1.1.1.3 christos
282 1.1.1.3 christos /* mask = 0000001111111111. */
283 1.1.1.3 christos #ifndef REPLACE_jli
284 1.1.1.3 christos #define REPLACE_jli
285 1.1.1.3 christos ATTRIBUTE_UNUSED static unsigned
286 1.1.1.3 christos replace_jli (unsigned insn, int value)
287 1.1.1.3 christos {
288 1.1.1.3 christos insn = insn & ~0x3ff;
289 1.1.1.3 christos insn |= ((value >> 0) & 0x03ff) << 0;
290 1.1.1.3 christos
291 1.1.1.3 christos return insn;
292 1.1.1.3 christos }
293 1.1.1.3 christos
294 1.1.1.3 christos #endif /* REPLACE_jli */
295