1 /* HP PA-RISC SOM object file format: definitions internal to BFD.
2 Copyright (C) 1990-1991 Free Software Foundation, Inc.
4 Contributed by the Center for Software Science at the
5 University of Utah (pa-gdb-bugs@cs.utah.edu).
7 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
26 #define BYTES_IN_WORD 4
36 /* HP PA-RISC relocation types */
38 enum hppa_reloc_field_selector_type
57 /* for compatibility */
58 enum hppa_reloc_field_selector_type_alt
61 e_lssel = R_HPPA_LSSEL,
62 e_rssel = R_HPPA_RSSEL,
65 e_ldsel = R_HPPA_LDSEL,
66 e_rdsel = R_HPPA_RDSEL,
67 e_lrsel = R_HPPA_LRSEL,
68 e_rrsel = R_HPPA_RRSEL,
70 e_lpsel = R_HPPA_LPSEL,
71 e_rpsel = R_HPPA_RPSEL,
73 e_ltsel = R_HPPA_LTSEL,
74 e_rtsel = R_HPPA_RTSEL
77 enum hppa_reloc_expr_type
87 /* for compatibility */
88 enum hppa_reloc_expr_type_alt
92 e_pcrel = R_HPPA_E_PCREL,
94 e_plabel = R_HPPA_E_PLABEL,
99 /* Some functions to manipulate PA instructions. */
100 static INLINE unsigned int
104 return (((x & 1) << 2) | ((x & 6) >> 1)) & 7;
108 dis_assemble_3 (x, r)
112 *r = (((x & 4) >> 2) | ((x & 3) << 1)) & 7;
115 static INLINE unsigned int
119 return (((y & 1) << 11) | ((x & 1) << 10) | ((x & 0x7fe) >> 1)) & 0xfff;
123 dis_assemble_12 (as12, x, y)
127 *y = (as12 & 0x800) >> 11;
128 *x = ((as12 & 0x3ff) << 1) | ((as12 & 0x400) >> 10);
131 static INLINE unsigned long
132 assemble_17 (x, y, z)
133 unsigned int x, y, z;
137 temp = ((z & 1) << 16) |
141 return temp & 0x1ffff;
145 dis_assemble_17 (as17, x, y, z)
147 unsigned int *x, *y, *z;
150 *z = (as17 & 0x10000) >> 16;
151 *x = (as17 & 0x0f800) >> 11;
152 *y = (((as17 & 0x00400) >> 10) | ((as17 & 0x3ff) << 1)) & 0x7ff;
155 static INLINE unsigned long
161 temp = ((x & 1) << 20) |
163 ((x & 0xc000) >> 7) |
164 ((x & 0x1f0000) >> 14) |
165 ((x & 0x003000) >> 12);
166 return temp & 0x1fffff;
170 dis_assemble_21 (as21, x)
171 unsigned int as21, *x;
176 temp = (as21 & 0x100000) >> 20;
177 temp |= (as21 & 0x0ffe00) >> 8;
178 temp |= (as21 & 0x000180) << 7;
179 temp |= (as21 & 0x00007c) << 14;
180 temp |= (as21 & 0x000003) << 12;
184 static INLINE unsigned long
188 return (x << (32 - len)) >> (32 - len);
191 static INLINE unsigned int
195 unsigned int len_ones;
202 len_ones = (len_ones << 1) | 1;
210 sign_unext (x, len, result)
212 unsigned int *result;
214 unsigned int len_ones;
216 len_ones = ones (len);
218 *result = x & len_ones;
221 static INLINE unsigned long
222 low_sign_ext (x, len)
225 unsigned int temp1, temp2;
226 unsigned int len_ones;
228 len_ones = ones (len);
230 temp1 = (x & 1) << (len - 1);
231 temp2 = ((x & 0xfffffffe) & len_ones) >> 1;
232 return sign_ext ((temp1 | temp2), len);
236 low_sign_unext (x, len, result)
238 unsigned int *result;
243 unsigned int one_bit_at_len;
244 unsigned int len_ones;
246 len_ones = ones (len);
247 one_bit_at_len = 1 << (len - 1);
249 sign_unext (x, len, &temp);
250 sign = temp & one_bit_at_len;
253 rest = temp & (len_ones ^ one_bit_at_len);
256 *result = rest | sign;
259 /* Handle field selectors for PA instructions. */
261 static INLINE unsigned long
262 hppa_field_adjust (value, constant_value, r_field)
264 unsigned long constant_value;
265 unsigned short r_field;
267 unsigned long init_value = value;
268 value += constant_value;
271 case e_fsel: /* F : no change */
274 case e_lssel: /* LS : if (bit 21) then add 0x800
275 arithmetic shift right 11 bits */
276 if (value & 0x00000400)
278 value = (value & 0xfffff800) >> 11;
281 case e_rssel: /* RS : Sign extend from bit 21 */
282 if (value & 0x00000400)
288 case e_lsel: /* L : Arithmetic shift right 11 bits */
289 value = (value & 0xfffff800) >> 11;
292 case e_rsel: /* R : Set bits 0-20 to zero */
293 value = value & 0x7ff;
296 case e_ldsel: /* LD : Add 0x800, arithmetic shift
299 value = (value & 0xfffff800) >> 11;
302 case e_rdsel: /* RD : Set bits 0-20 to one */
306 case e_lrsel: /* LR : L with "rounded" constant */
307 value = value + ((constant_value + 0x1000) & 0xffffe000);
308 value = (value & 0xfffff800) >> 11;
311 case e_rrsel: /* RR : R with "rounded" constant */
312 value = value + ((constant_value + 0x1000) & 0xffffe000);
313 value = (value & 0x7ff) + constant_value - ((constant_value + 0x1000) & 0xffffe000);