Sanitization changes to reflect other comings and goings
[deliverable/binutils-gdb.git] / bfd / libhppa.h
CommitLineData
76c7e44d
SG
1/* HP PA-RISC SOM object file format: definitions internal to BFD.
2 Copyright (C) 1990-1991 Free Software Foundation, Inc.
3
4 Contributed by the Center for Software Science at the
5 University of Utah (pa-gdb-bugs@cs.utah.edu).
6
d9ad93bc 7 This file is part of BFD, the Binary File Descriptor library.
76c7e44d 8
d9ad93bc
KR
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
76c7e44d 13
d9ad93bc
KR
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
76c7e44d 18
d9ad93bc
KR
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
76c7e44d 22
d9ad93bc
KR
23#ifndef _HPPA_H
24#define _HPPA_H
d325e28c 25
d9ad93bc 26#define BYTES_IN_WORD 4
205d660d 27
d9ad93bc
KR
28#ifndef INLINE
29#ifdef __GNUC__
30#define INLINE inline
31#else
32#define INLINE
33#endif /* GNU C? */
34#endif /* INLINE */
d325e28c 35
d9ad93bc 36/* HP PA-RISC relocation types */
d325e28c 37
d9ad93bc
KR
38enum hppa_reloc_field_selector_type
39 {
40 R_HPPA_FSEL = 0x0,
41 R_HPPA_LSSEL = 0x1,
42 R_HPPA_RSSEL = 0x2,
43 R_HPPA_LSEL = 0x3,
44 R_HPPA_RSEL = 0x4,
45 R_HPPA_LDSEL = 0x5,
46 R_HPPA_RDSEL = 0x6,
47 R_HPPA_LRSEL = 0x7,
48 R_HPPA_RRSEL = 0x8,
49 R_HPPA_PSEL = 0x9,
50 R_HPPA_LPSEL = 0xa,
51 R_HPPA_RPSEL = 0xb,
52 R_HPPA_TSEL = 0xc,
53 R_HPPA_LTSEL = 0xd,
54 R_HPPA_RTSEL = 0xe
55 };
89c789f6 56
aef3ae9a
JK
57/* /usr/include/reloc.h defines these to constants. We want to use
58 them in enums, so #undef them before we start using them. We might
59 be able to fix this another way by simply managing not to include
60 /usr/include/reloc.h, but currently GDB picks up these defines
61 somewhere. */
62#undef e_fsel
63#undef e_lssel
64#undef e_rssel
65#undef e_lsel
66#undef e_rsel
67#undef e_ldsel
68#undef e_rdsel
69#undef e_lrsel
70#undef e_rrsel
71#undef e_psel
72#undef e_lpsel
73#undef e_rpsel
74#undef e_tsel
75#undef e_ltsel
76#undef e_rtsel
77#undef e_one
78#undef e_two
79#undef e_pcrel
80#undef e_con
81#undef e_plabel
82#undef e_abs
83
d9ad93bc
KR
84/* for compatibility */
85enum hppa_reloc_field_selector_type_alt
86 {
87 e_fsel = R_HPPA_FSEL,
88 e_lssel = R_HPPA_LSSEL,
89 e_rssel = R_HPPA_RSSEL,
90 e_lsel = R_HPPA_LSEL,
91 e_rsel = R_HPPA_RSEL,
92 e_ldsel = R_HPPA_LDSEL,
93 e_rdsel = R_HPPA_RDSEL,
94 e_lrsel = R_HPPA_LRSEL,
95 e_rrsel = R_HPPA_RRSEL,
96 e_psel = R_HPPA_PSEL,
97 e_lpsel = R_HPPA_LPSEL,
98 e_rpsel = R_HPPA_RPSEL,
99 e_tsel = R_HPPA_TSEL,
100 e_ltsel = R_HPPA_LTSEL,
101 e_rtsel = R_HPPA_RTSEL
102 };
89c789f6 103
d9ad93bc
KR
104enum hppa_reloc_expr_type
105 {
106 R_HPPA_E_ONE = 0,
107 R_HPPA_E_TWO = 1,
108 R_HPPA_E_PCREL = 2,
109 R_HPPA_E_CON = 3,
110 R_HPPA_E_PLABEL = 7,
111 R_HPPA_E_ABS = 18
112 };
d325e28c 113
d9ad93bc
KR
114/* for compatibility */
115enum hppa_reloc_expr_type_alt
116 {
117 e_one = R_HPPA_E_ONE,
118 e_two = R_HPPA_E_TWO,
119 e_pcrel = R_HPPA_E_PCREL,
120 e_con = R_HPPA_E_CON,
121 e_plabel = R_HPPA_E_PLABEL,
122 e_abs = R_HPPA_E_ABS
123 };
124
125
126/* Some functions to manipulate PA instructions. */
127static INLINE unsigned int
128assemble_3 (x)
129 unsigned int x;
130{
131 return (((x & 1) << 2) | ((x & 6) >> 1)) & 7;
132}
d325e28c 133
d9ad93bc
KR
134static INLINE void
135dis_assemble_3 (x, r)
136 unsigned int x;
137 unsigned int *r;
138{
139 *r = (((x & 4) >> 2) | ((x & 3) << 1)) & 7;
140}
89c789f6 141
d9ad93bc
KR
142static INLINE unsigned int
143assemble_12 (x, y)
144 unsigned int x, y;
145{
146 return (((y & 1) << 11) | ((x & 1) << 10) | ((x & 0x7fe) >> 1)) & 0xfff;
147}
89c789f6 148
d9ad93bc
KR
149static INLINE void
150dis_assemble_12 (as12, x, y)
151 unsigned int as12;
152 unsigned int *x, *y;
153{
154 *y = (as12 & 0x800) >> 11;
155 *x = ((as12 & 0x3ff) << 1) | ((as12 & 0x400) >> 10);
156}
76c7e44d 157
d9ad93bc
KR
158static INLINE unsigned long
159assemble_17 (x, y, z)
160 unsigned int x, y, z;
161{
162 unsigned long temp;
163
164 temp = ((z & 1) << 16) |
165 ((x & 0x1f) << 11) |
166 ((y & 1) << 10) |
167 ((y & 0x7fe) >> 1);
168 return temp & 0x1ffff;
169}
170
171static INLINE void
172dis_assemble_17 (as17, x, y, z)
173 unsigned int as17;
174 unsigned int *x, *y, *z;
175{
76c7e44d 176
d9ad93bc
KR
177 *z = (as17 & 0x10000) >> 16;
178 *x = (as17 & 0x0f800) >> 11;
179 *y = (((as17 & 0x00400) >> 10) | ((as17 & 0x3ff) << 1)) & 0x7ff;
180}
76c7e44d 181
d9ad93bc
KR
182static INLINE unsigned long
183assemble_21 (x)
184 unsigned int x;
76c7e44d 185{
d9ad93bc
KR
186 unsigned long temp;
187
188 temp = ((x & 1) << 20) |
189 ((x & 0xffe) << 8) |
190 ((x & 0xc000) >> 7) |
191 ((x & 0x1f0000) >> 14) |
192 ((x & 0x003000) >> 12);
193 return temp & 0x1fffff;
194}
195
196static INLINE void
197dis_assemble_21 (as21, x)
198 unsigned int as21, *x;
76c7e44d 199{
d9ad93bc 200 unsigned long temp;
76c7e44d 201
76c7e44d 202
d9ad93bc
KR
203 temp = (as21 & 0x100000) >> 20;
204 temp |= (as21 & 0x0ffe00) >> 8;
205 temp |= (as21 & 0x000180) << 7;
206 temp |= (as21 & 0x00007c) << 14;
207 temp |= (as21 & 0x000003) << 12;
208 *x = temp;
209}
76c7e44d 210
d9ad93bc
KR
211static INLINE unsigned long
212sign_ext (x, len)
213 unsigned int x, len;
214{
215 return (x << (32 - len)) >> (32 - len);
216}
76c7e44d 217
d9ad93bc
KR
218static INLINE unsigned int
219ones (n)
220 int n;
221{
222 unsigned int len_ones;
223 int i;
224
225 i = 0;
226 len_ones = 0;
227 while (i < n)
228 {
229 len_ones = (len_ones << 1) | 1;
230 i++;
231 }
232
233 return len_ones;
234}
235
236static INLINE void
237sign_unext (x, len, result)
238 unsigned int x, len;
239 unsigned int *result;
240{
241 unsigned int len_ones;
76c7e44d 242
d9ad93bc 243 len_ones = ones (len);
76c7e44d 244
d9ad93bc
KR
245 *result = x & len_ones;
246}
76c7e44d 247
d9ad93bc
KR
248static INLINE unsigned long
249low_sign_ext (x, len)
250 unsigned int x, len;
251{
252 unsigned int temp1, temp2;
253 unsigned int len_ones;
76c7e44d 254
d9ad93bc 255 len_ones = ones (len);
76c7e44d 256
d9ad93bc
KR
257 temp1 = (x & 1) << (len - 1);
258 temp2 = ((x & 0xfffffffe) & len_ones) >> 1;
259 return sign_ext ((temp1 | temp2), len);
260}
205d660d 261
d9ad93bc
KR
262static INLINE void
263low_sign_unext (x, len, result)
264 unsigned int x, len;
265 unsigned int *result;
76c7e44d 266{
d9ad93bc
KR
267 unsigned int temp;
268 unsigned int sign;
269 unsigned int rest;
270 unsigned int one_bit_at_len;
271 unsigned int len_ones;
8568acaa 272
d9ad93bc
KR
273 len_ones = ones (len);
274 one_bit_at_len = 1 << (len - 1);
8568acaa 275
d9ad93bc
KR
276 sign_unext (x, len, &temp);
277 sign = temp & one_bit_at_len;
278 sign >>= (len - 1);
b2057735 279
d9ad93bc
KR
280 rest = temp & (len_ones ^ one_bit_at_len);
281 rest <<= 1;
8568acaa 282
d9ad93bc
KR
283 *result = rest | sign;
284}
8568acaa 285
d9ad93bc
KR
286/* Handle field selectors for PA instructions. */
287
288static INLINE unsigned long
289hppa_field_adjust (value, constant_value, r_field)
290 unsigned long value;
291 unsigned long constant_value;
292 unsigned short r_field;
8568acaa 293{
d9ad93bc
KR
294 unsigned long init_value = value;
295 value += constant_value;
296 switch (r_field)
297 {
298 case e_fsel: /* F : no change */
299 break;
300
301 case e_lssel: /* LS : if (bit 21) then add 0x800
302 arithmetic shift right 11 bits */
303 if (value & 0x00000400)
304 value += 0x800;
305 value = (value & 0xfffff800) >> 11;
306 break;
307
308 case e_rssel: /* RS : Sign extend from bit 21 */
309 if (value & 0x00000400)
310 value |= 0xfffff800;
311 else
312 value &= 0x7ff;
313 break;
314
315 case e_lsel: /* L : Arithmetic shift right 11 bits */
316 value = (value & 0xfffff800) >> 11;
317 break;
318
319 case e_rsel: /* R : Set bits 0-20 to zero */
320 value = value & 0x7ff;
321 break;
322
323 case e_ldsel: /* LD : Add 0x800, arithmetic shift
324 right 11 bits */
325 value += 0x800;
326 value = (value & 0xfffff800) >> 11;
327 break;
328
329 case e_rdsel: /* RD : Set bits 0-20 to one */
330 value |= 0xfffff800;
331 break;
332
333 case e_lrsel: /* LR : L with "rounded" constant */
334 value = value + ((constant_value + 0x1000) & 0xffffe000);
335 value = (value & 0xfffff800) >> 11;
336 break;
337
338 case e_rrsel: /* RR : R with "rounded" constant */
339 value = value + ((constant_value + 0x1000) & 0xffffe000);
340 value = (value & 0x7ff) + constant_value - ((constant_value + 0x1000) & 0xffffe000);
341 break;
342
343 default:
344 abort ();
345 }
346 return value;
347
348}
349#endif /* _HPPA_H */
This page took 0.084347 seconds and 4 git commands to generate.