eliminate most prototypes so ansidecl.h isn't needed before this file (incomplete)
[deliverable/binutils-gdb.git] / bfd / hppa.c
CommitLineData
e3c01e92 1/* bfd back-end for HP PA-RISC SOM objects.
0dc1bc8b 2 Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
e3c01e92
SG
3
4 Contributed by the Center for Software Science at the
5 University of Utah (pa-gdb-bugs@cs.utah.edu).
6
7This file is part of BFD, the Binary File Descriptor library.
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22
e3c01e92 23#include "bfd.h"
76c7e44d 24#include "sysdep.h"
205d660d 25
09f080a5
KR
26/* @@FIXME This is not a reasonable set of conditions to permit
27 cross-compilation, obviously. It also isn't enough to support hppa-elf
28 targets either. Can we eliminate the HPUX or BSD dependencies, or
29 at least get the conditionals more localized? */
9a5e3a9a 30#if defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD)
205d660d 31
e3c01e92
SG
32#include "libbfd.h"
33#include "libhppa.h"
34
e3c01e92
SG
35#include <stdio.h>
36#include <sys/types.h>
37#include <sys/param.h>
38#include <sys/dir.h>
39#include <signal.h>
40#include <machine/reg.h>
7050286d 41#include <sys/user.h> /* After a.out.h */
e3c01e92
SG
42#include <sys/file.h>
43#include <errno.h>
0093d9e6 44
155171de
KR
45/* Magic not defined in standard HP-UX header files until 8.0 */
46
47#ifndef CPU_PA_RISC1_0
48#define CPU_PA_RISC1_0 0x20B
49#endif /* CPU_PA_RISC1_0 */
d325e28c 50
155171de
KR
51#ifndef CPU_PA_RISC1_1
52#define CPU_PA_RISC1_1 0x210
53#endif /* CPU_PA_RISC1_1 */
d325e28c 54
155171de
KR
55#ifndef _PA_RISC1_0_ID
56#define _PA_RISC1_0_ID CPU_PA_RISC1_0
57#endif /* _PA_RISC1_0_ID */
d325e28c 58
155171de
KR
59#ifndef _PA_RISC1_1_ID
60#define _PA_RISC1_1_ID CPU_PA_RISC1_1
61#endif /* _PA_RISC1_1_ID */
d325e28c 62
155171de
KR
63#ifndef _PA_RISC_MAXID
64#define _PA_RISC_MAXID 0x2FF
65#endif /* _PA_RISC_MAXID */
d325e28c 66
155171de
KR
67#ifndef _PA_RISC_ID
68#define _PA_RISC_ID(__m_num) \
69 (((__m_num) == _PA_RISC1_0_ID) || \
70 ((__m_num) >= _PA_RISC1_1_ID && (__m_num) <= _PA_RISC_MAXID))
71#endif /* _PA_RISC_ID */
72
7050286d
KR
73struct container
74 {
75 struct header f;
76 struct som_exec_auxhdr e;
77 };
e3c01e92 78
edff0587
SG
79static bfd_target *
80hppa_object_setup (abfd, file_hdrp, aux_hdrp)
e3c01e92 81 bfd *abfd;
edff0587
SG
82 struct header *file_hdrp;
83 struct som_exec_auxhdr *aux_hdrp;
e3c01e92
SG
84{
85 struct container *rawptr;
86 struct header *f;
87 struct hppa_data_struct *rawptr1;
d0a650a4 88 asection *text, *data, *bss;
e3c01e92
SG
89
90 rawptr = (struct container *) bfd_zalloc (abfd, sizeof (struct container));
7050286d
KR
91 if (rawptr == NULL)
92 {
93 bfd_error = no_memory;
94 return 0;
95 }
e3c01e92
SG
96
97 rawptr1 = (struct hppa_data_struct *) bfd_zalloc (abfd, sizeof (struct hppa_data_struct));
7050286d
KR
98 if (rawptr1 == NULL)
99 {
100 bfd_error = no_memory;
101 return 0;
102 }
103
e3c01e92
SG
104 abfd->tdata.hppa_data = rawptr1;
105 obj_file_hdr (abfd) = &rawptr->f;
106 obj_aux_hdr (abfd) = &rawptr->e;
107 *obj_file_hdr (abfd) = *file_hdrp;
108 *obj_aux_hdr (abfd) = *aux_hdrp;
109
110 /* Set the file flags */
111 abfd->flags = NO_FLAGS;
112 if (file_hdrp->entry_offset)
113 abfd->flags |= HAS_RELOC;
114 if (file_hdrp->symbol_total)
115 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
116
117 bfd_get_start_address (abfd) = aux_hdrp->exec_entry;
118
7050286d 119 obj_pa_symbols (abfd) = (hppa_symbol_type *) NULL;
d0a650a4 120 bfd_get_symcount (abfd) = file_hdrp->symbol_total;
e3c01e92 121
7050286d 122 bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 0);
e3c01e92
SG
123
124 /* create the sections. This is raunchy, but bfd_close wants to reclaim
125 them */
d0a650a4 126
7050286d
KR
127 text = bfd_make_section (abfd, ".text");
128 data = bfd_make_section (abfd, ".data");
129 bss = bfd_make_section (abfd, ".bss");
d0a650a4
SG
130
131 text->_raw_size = aux_hdrp->exec_tsize;
132 data->_raw_size = aux_hdrp->exec_dsize;
133 bss->_raw_size = aux_hdrp->exec_bsize;
134
135 text->flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS);
136 data->flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS);
137 bss->flags = SEC_ALLOC;
e3c01e92 138
7050286d
KR
139 /* The virtual memory addresses of the sections */
140 text->vma = aux_hdrp->exec_tmem;
141 data->vma = aux_hdrp->exec_dmem;
142 bss->vma = aux_hdrp->exec_bfill;
143
144 /* The file offsets of the sections */
145 text->filepos = aux_hdrp->exec_tfile;
146 data->filepos = aux_hdrp->exec_dfile;
147
148 /* The file offsets of the relocation info */
149 text->rel_filepos = 0;
150 data->rel_filepos = 0;
151
152 /* The file offsets of the string table and symbol table. */
153 obj_sym_filepos (abfd) = file_hdrp->symbol_location;
d0a650a4 154 bfd_get_symcount (abfd) = file_hdrp->symbol_total;
7050286d 155 obj_str_filepos (abfd) = file_hdrp->symbol_strings_location;
d0a650a4 156 obj_stringtab_size (abfd) = file_hdrp->symbol_strings_size;
e3c01e92
SG
157
158 return abfd->xvec;
159}
160
edff0587
SG
161/* Create a new BFD section for NAME. If NAME already exists, then create a
162 new unique name, with NAME as the prefix. This exists because SOM .o files
163 created by the native compiler can have a $CODE$ section for each
164 subroutine.
165 */
166
167static asection *
168make_unique_section (abfd, name, num)
169 bfd *abfd;
170 CONST char *name;
171 int num;
172{
173 asection *sect;
174 char *newname;
175 char altname[100];
176
177 sect = bfd_make_section (abfd, name);
178 while (!sect)
179 {
7050286d 180 sprintf (altname, "%s-%d", name, num++);
edff0587
SG
181 sect = bfd_make_section (abfd, altname);
182 }
183
7050286d 184 newname = bfd_alloc (abfd, strlen (sect->name) + 1);
edff0587
SG
185 strcpy (newname, sect->name);
186
187 sect->name = newname;
188 return sect;
189}
190
191/* Convert all of the space and subspace info into BFD sections. Each space
192 contains a number of subspaces, which in turn describe the mapping between
193 regions of the exec file, and the address space that the program runs in.
194 BFD sections which correspond to spaces will overlap the sections for the
195 associated subspaces. */
196
197static int
198setup_sections (abfd, file_hdr)
199 bfd *abfd;
200 struct header *file_hdr;
201{
202 char *space_strings;
203 int space_index;
204
7050286d 205 /* First, read in space names */
edff0587
SG
206
207 space_strings = alloca (file_hdr->space_strings_size);
208 if (!space_strings)
209 return 0;
210
211 if (bfd_seek (abfd, file_hdr->space_strings_location, SEEK_SET) < 0)
212 return 0;
213 if (bfd_read (space_strings, 1, file_hdr->space_strings_size, abfd)
214 != file_hdr->space_strings_size)
215 return 0;
216
217 /* Loop over all of the space dictionaries, building up sections */
218
219 for (space_index = 0; space_index < file_hdr->space_total; space_index++)
220 {
221 struct space_dictionary_record space;
222 struct subspace_dictionary_record subspace;
223 int subspace_index, tmp;
224 asection *space_asect;
225
226 /* Read the space dictionary element */
227 if (bfd_seek (abfd, file_hdr->space_location
7050286d 228 + space_index * sizeof space, SEEK_SET) < 0)
edff0587
SG
229 return 0;
230 if (bfd_read (&space, 1, sizeof space, abfd) != sizeof space)
231 return 0;
232
233 /* Setup the space name string */
234 space.name.n_name = space.name.n_strx + space_strings;
235
236 /* Make a section out of it */
237 space_asect = make_unique_section (abfd, space.name.n_name, space_index);
238 if (!space_asect)
239 return 0;
240
241 /* Now, read in the first subspace for this space */
242 if (bfd_seek (abfd, file_hdr->subspace_location
7050286d
KR
243 + space.subspace_index * sizeof subspace,
244 SEEK_SET) < 0)
edff0587
SG
245 return 0;
246 if (bfd_read (&subspace, 1, sizeof subspace, abfd) != sizeof subspace)
247 return 0;
248 /* Seek back to the start of the subspaces for loop below */
249 if (bfd_seek (abfd, file_hdr->subspace_location
7050286d
KR
250 + space.subspace_index * sizeof subspace,
251 SEEK_SET) < 0)
edff0587
SG
252 return 0;
253
254 /* Setup the section flags as appropriate (this is somewhat bogus, as
255 there isn't a clear mapping between what's in the space record, and
256 what BFD can describe here). */
257 if (space.is_loadable)
258 space_asect->flags |= SEC_ALLOC;
259 if (space.is_defined)
260 space_asect->flags |= SEC_LOAD;
261
262 /* Setup the start address and file loc from the first subspace record */
263 space_asect->vma = subspace.subspace_start;
264 space_asect->filepos = subspace.file_loc_init_value;
265 space_asect->alignment_power = subspace.alignment;
266
267 /* Loop over the rest of the subspaces, building up more sections */
268 for (subspace_index = 0; subspace_index < space.subspace_quantity;
269 subspace_index++)
270 {
271 asection *subspace_asect;
272
273 /* Read in the next subspace */
274 if (bfd_read (&subspace, 1, sizeof subspace, abfd)
275 != sizeof subspace)
276 return 0;
277
278 /* Setup the subspace name string */
279 subspace.name.n_name = subspace.name.n_strx + space_strings;
280
281 /* Make a section out of this subspace */
282 subspace_asect = make_unique_section (abfd, subspace.name.n_name,
7050286d 283 space.subspace_index + subspace_index);
edff0587
SG
284
285 if (!subspace_asect)
286 return 0;
287
288 if (subspace.is_loadable)
289 subspace_asect->flags |= SEC_ALLOC | SEC_LOAD;
290 if (subspace.code_only)
291 subspace_asect->flags |= SEC_CODE;
292
293 subspace_asect->vma = subspace.subspace_start;
294 subspace_asect->_cooked_size = subspace.subspace_length;
295 subspace_asect->_raw_size = subspace.initialization_length;
296 subspace_asect->alignment_power = subspace.alignment;
297 subspace_asect->filepos = subspace.file_loc_init_value;
298
299 }
300 /* Setup the sizes for the space section based upon the info in the
301 last subspace of the space. */
302 space_asect->_cooked_size = (subspace.subspace_start - space_asect->vma)
7050286d 303 + subspace.subspace_length;
edff0587
SG
304 space_asect->_raw_size = (subspace.file_loc_init_value
305 - space_asect->filepos)
7050286d 306 + subspace.initialization_length;
edff0587
SG
307 }
308}
309
310static bfd_target *
311hppa_object_p (abfd)
312 bfd *abfd;
e3c01e92
SG
313{
314 struct header file_hdr;
315 struct som_exec_auxhdr aux_hdr;
e3c01e92 316
7050286d 317 if (bfd_read ((PTR) & file_hdr, 1, FILE_HDR_SIZE, abfd) != FILE_HDR_SIZE)
edff0587
SG
318 return 0;
319
320 if (!_PA_RISC_ID (file_hdr.system_id))
e3c01e92
SG
321 {
322 bfd_error = wrong_format;
323 return 0;
324 }
205d660d 325
205d660d
SG
326 switch (file_hdr.a_magic)
327 {
7050286d 328 case RELOC_MAGIC: /* I'm not really sure about all of these types... */
205d660d
SG
329 case EXEC_MAGIC:
330 case SHARE_MAGIC:
331 case DEMAND_MAGIC:
0093d9e6 332#ifdef DL_MAGIC
205d660d 333 case DL_MAGIC:
0093d9e6
KR
334#endif
335#ifdef SHL_MAGIC
205d660d 336 case SHL_MAGIC:
0093d9e6 337#endif
205d660d
SG
338 break;
339 default:
edff0587 340 bfd_error = wrong_format;
205d660d
SG
341 return 0;
342 }
343
edff0587
SG
344 if (file_hdr.version_id != VERSION_ID
345 && file_hdr.version_id != NEW_VERSION_ID)
e3c01e92
SG
346 {
347 bfd_error = wrong_format;
348 return 0;
349 }
e3c01e92 350
7050286d 351 if (bfd_read ((PTR) & aux_hdr, 1, AUX_HDR_SIZE, abfd) != AUX_HDR_SIZE)
edff0587 352 bfd_error = wrong_format;
e3c01e92 353
edff0587
SG
354 if (!setup_sections (abfd, &file_hdr))
355 return 0;
356
7050286d 357 return hppa_object_setup (abfd, &file_hdr, &aux_hdr);
edff0587 358}
e3c01e92
SG
359
360static boolean
7050286d
KR
361DEFUN (hppa_mkobject, (abfd),
362 bfd * abfd)
363{
e3c01e92
SG
364 fprintf (stderr, "hppa_mkobject unimplemented\n");
365 fflush (stderr);
366 abort ();
367 return (false);
368}
369
370boolean
7050286d
KR
371DEFUN (hppa_write_object_contents, (abfd),
372 bfd * abfd)
e3c01e92
SG
373{
374 fprintf (stderr, "hppa_write_object_contents unimplemented\n");
375 fflush (stderr);
376 abort ();
377 return (false);
378}
379
edff0587
SG
380static unsigned int
381hppa_get_symtab_upper_bound (abfd)
382 bfd *abfd;
e3c01e92
SG
383{
384 fprintf (stderr, "hppa_get_symtab_upper_bound unimplemented\n");
385 fflush (stderr);
386 abort ();
387 return (0);
388}
389
edff0587
SG
390static unsigned int
391hppa_get_reloc_upper_bound (abfd, asect)
392 bfd *abfd;
393 sec_ptr asect;
e3c01e92
SG
394{
395 fprintf (stderr, "hppa_get_reloc_upper_bound unimplemented\n");
396 fflush (stderr);
397 abort ();
398 return (0);
399}
400
edff0587
SG
401static unsigned int
402hppa_canonicalize_reloc (abfd, section, relptr, symbols)
403 bfd *abfd;
404 sec_ptr section;
405 arelent **relptr;
406 asymbol **symbols;
e3c01e92
SG
407{
408 fprintf (stderr, "hppa_canonicalize_reloc unimplemented\n");
409 fflush (stderr);
410 abort ();
411}
412
413extern bfd_target hppa_vec;
edff0587
SG
414
415static unsigned int
416hppa_get_symtab (abfd, location)
417 bfd *abfd;
418 asymbol **location;
e3c01e92
SG
419{
420 fprintf (stderr, "hppa_get_symtab unimplemented\n");
421 fflush (stderr);
422 abort ();
423 return (0);
424}
425
edff0587
SG
426static asymbol *
427hppa_make_empty_symbol (abfd)
428 bfd *abfd;
e3c01e92 429{
7050286d
KR
430 hppa_symbol_type *new =
431 (hppa_symbol_type *) bfd_zalloc (abfd, sizeof (hppa_symbol_type));
e3c01e92
SG
432 new->symbol.the_bfd = abfd;
433
434 return &new->symbol;
435}
436
7050286d
KR
437static void
438hppa_print_symbol (ignore_abfd, afile, symbol, how)
edff0587
SG
439 bfd *ignore_abfd;
440 PTR afile;
441 asymbol *symbol;
442 bfd_print_symbol_type how;
e3c01e92
SG
443{
444 fprintf (stderr, "hppa_print_symbol unimplemented\n");
445 fflush (stderr);
446 abort ();
447}
448
edff0587
SG
449static boolean
450hppa_new_section_hook (abfd, newsect)
451 bfd *abfd;
452 asection *newsect;
e3c01e92 453{
e3c01e92
SG
454 newsect->alignment_power = 3;
455
e3c01e92
SG
456 /* We allow more than three sections internally */
457 return true;
458}
459
edff0587
SG
460static boolean
461hppa_set_section_contents (abfd, section, location, offset, count)
462 bfd *abfd;
463 sec_ptr section;
464 PTR location;
465 file_ptr offset;
466 bfd_size_type count;
e3c01e92
SG
467{
468 fprintf (stderr, "hppa_set_section_contents unimplimented\n");
469 fflush (stderr);
7050286d 470 abort ();
e3c01e92
SG
471 return false;
472}
473
edff0587
SG
474static boolean
475hppa_set_arch_mach (abfd, arch, machine)
476 bfd *abfd;
477 enum bfd_architecture arch;
478 unsigned long machine;
e3c01e92
SG
479{
480 fprintf (stderr, "hppa_set_arch_mach unimplemented\n");
481 fflush (stderr);
482 /* Allow any architecture to be supported by the hppa backend */
7050286d 483 return bfd_default_set_arch_mach (abfd, arch, machine);
e3c01e92
SG
484}
485
e3c01e92 486static boolean
edff0587
SG
487hppa_find_nearest_line (abfd, section, symbols, offset, filename_ptr,
488 functionname_ptr, line_ptr)
489 bfd *abfd;
490 asection *section;
491 asymbol **symbols;
492 bfd_vma offset;
493 CONST char **filename_ptr;
494 CONST char **functionname_ptr;
495 unsigned int *line_ptr;
e3c01e92
SG
496{
497 fprintf (stderr, "hppa_find_nearest_line unimplemented\n");
498 fflush (stderr);
499 abort ();
500 return (false);
501}
502
503static int
edff0587 504hppa_sizeof_headers (abfd, reloc)
7050286d
KR
505 bfd *abfd;
506 boolean reloc;
e3c01e92
SG
507{
508 fprintf (stderr, "hppa_sizeof_headers unimplemented\n");
509 fflush (stderr);
510 abort ();
511 return (0);
512}
513
205d660d
SG
514static asection *
515make_bfd_asection (abfd, name, flags, _raw_size, vma, alignment_power)
e3c01e92 516 bfd *abfd;
75dd6a3e 517 CONST char *name;
205d660d
SG
518 flagword flags;
519 bfd_size_type _raw_size;
520 bfd_vma vma;
521 unsigned int alignment_power;
e3c01e92 522{
205d660d 523 asection *asect;
e3c01e92 524
edff0587 525 asect = bfd_make_section (abfd, name);
205d660d 526 if (!asect)
edff0587 527 return NULL;
e3c01e92 528
205d660d
SG
529 asect->flags = flags;
530 asect->_raw_size = _raw_size;
531 asect->vma = vma;
532 asect->filepos = bfd_tell (abfd);
533 asect->alignment_power = alignment_power;
e3c01e92 534
205d660d
SG
535 return asect;
536}
537
d325e28c 538#ifdef HOST_HPPAHPUX
edff0587 539static bfd_target *
205d660d
SG
540hppa_core_file_p (abfd)
541 bfd *abfd;
542{
543 core_hdr (abfd) = bfd_zalloc (abfd, sizeof (struct hppa_core_struct));
544 if (!core_hdr (abfd))
545 return NULL;
e3c01e92 546
205d660d
SG
547 while (1)
548 {
549 int val;
550 struct corehead core_header;
551
7050286d 552 val = bfd_read ((void *) &core_header, 1, sizeof core_header, abfd);
205d660d
SG
553 if (val <= 0)
554 break;
555 switch (core_header.type)
556 {
557 case CORE_KERNEL:
558 case CORE_FORMAT:
7050286d 559 bfd_seek (abfd, core_header.len, SEEK_CUR); /* Just skip this */
205d660d
SG
560 break;
561 case CORE_EXEC:
562 {
563 struct proc_exec proc_exec;
7050286d 564 bfd_read ((void *) &proc_exec, 1, core_header.len, abfd);
205d660d
SG
565 strncpy (core_command (abfd), proc_exec.cmd, MAXCOMLEN + 1);
566 }
567 break;
568 case CORE_PROC:
569 {
570 struct proc_info proc_info;
571 core_regsec (abfd) = make_bfd_asection (abfd, ".reg",
7050286d 572 SEC_ALLOC + SEC_HAS_CONTENTS,
205d660d 573 core_header.len,
7050286d 574 (int) &proc_info - (int) &proc_info.hw_regs,
205d660d
SG
575 2);
576 bfd_read (&proc_info, 1, core_header.len, abfd);
577 core_signal (abfd) = proc_info.sig;
578 }
579 if (!core_regsec (abfd))
580 return NULL;
581 break;
582 case CORE_DATA:
583 core_datasec (abfd) = make_bfd_asection (abfd, ".data",
7050286d 584 SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
205d660d
SG
585 core_header.len,
586 core_header.addr,
587 2);
588 if (!core_datasec (abfd))
589 return NULL;
590 bfd_seek (abfd, core_header.len, SEEK_CUR);
591 break;
592 case CORE_STACK:
edff0587 593 core_stacksec (abfd) = make_bfd_asection (abfd, ".stack",
7050286d 594 SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
205d660d
SG
595 core_header.len,
596 core_header.addr,
597 2);
598 if (!core_stacksec (abfd))
599 return NULL;
600 bfd_seek (abfd, core_header.len, SEEK_CUR);
601 break;
602 default:
603 fprintf (stderr, "Unknown HPPA/HPUX core file section type %d\n",
604 core_header.type);
605 bfd_seek (abfd, core_header.len, SEEK_CUR);
606 break;
607 }
608 }
e3c01e92 609
205d660d 610 /* OK, we believe you. You're a core file (sure, sure). */
e3c01e92
SG
611
612 return abfd->xvec;
613}
e3c01e92 614
edff0587 615static char *
e3c01e92
SG
616hppa_core_file_failing_command (abfd)
617 bfd *abfd;
618{
205d660d 619 return core_command (abfd);
e3c01e92 620}
e3c01e92
SG
621
622/* ARGSUSED */
edff0587 623static int
205d660d
SG
624hppa_core_file_failing_signal (abfd)
625 bfd *abfd;
e3c01e92 626{
205d660d 627 return core_signal (abfd);
e3c01e92
SG
628}
629
630/* ARGSUSED */
edff0587 631static boolean
7050286d 632hppa_core_file_matches_executable_p (core_bfd, exec_bfd)
e3c01e92
SG
633 bfd *core_bfd, *exec_bfd;
634{
7050286d 635 return true; /* FIXME, We have no way of telling at this point */
e3c01e92 636}
09f080a5 637
7050286d
KR
638#endif /* HOST_HPPAHPUX */
639
09f080a5
KR
640/* Miscellaneous Support Functions -- Control Structures and Functions
641 for the PA. */
642
7050286d
KR
643unsigned int
644assemble_3 (x)
09f080a5
KR
645 unsigned int x;
646{
7050286d 647 return (((x & 1) << 2) | ((x & 6) >> 1)) & 7;
09f080a5
KR
648}
649
7050286d
KR
650void
651dis_assemble_3 (x, r)
09f080a5
KR
652 unsigned int x;
653 unsigned int *r;
654{
7050286d 655 *r = (((x & 4) >> 2) | ((x & 3) << 1)) & 7;
09f080a5
KR
656}
657
7050286d
KR
658unsigned int
659assemble_12 (x, y)
660 unsigned int x, y;
09f080a5 661{
7050286d 662 return (((y & 1) << 11) | ((x & 1) << 10) | ((x & 0x7fe) >> 1)) & 0xfff;
09f080a5
KR
663}
664
7050286d
KR
665void
666dis_assemble_12 (as12, x, y)
09f080a5 667 unsigned int as12;
7050286d 668 unsigned int *x, *y;
09f080a5 669{
7050286d
KR
670 *y = (as12 & 0x800) >> 11;
671 *x = ((as12 & 0x3ff) << 1) | ((as12 & 0x400) >> 10);
09f080a5
KR
672}
673
7050286d
KR
674unsigned long
675assemble_17 (x, y, z)
676 unsigned int x, y, z;
09f080a5
KR
677{
678 unsigned long temp;
679
7050286d
KR
680 temp = ((z & 1) << 16) |
681 ((x & 0x1f) << 11) |
682 ((y & 1) << 10) |
683 ((y & 0x7fe) >> 1);
09f080a5
KR
684 return temp & 0x1ffff;
685}
686
7050286d
KR
687void
688dis_assemble_17 (as17, x, y, z)
09f080a5 689 unsigned int as17;
7050286d 690 unsigned int *x, *y, *z;
09f080a5
KR
691{
692
7050286d
KR
693 *z = (as17 & 0x10000) >> 16;
694 *x = (as17 & 0x0f800) >> 11;
695 *y = (((as17 & 0x00400) >> 10) | ((as17 & 0x3ff) << 1)) & 0x7ff;
09f080a5
KR
696}
697
7050286d
KR
698unsigned long
699assemble_21 (x)
09f080a5
KR
700 unsigned int x;
701{
702 unsigned long temp;
703
7050286d
KR
704 temp = ((x & 1) << 20) |
705 ((x & 0xffe) << 8) |
706 ((x & 0xc000) >> 7) |
707 ((x & 0x1f0000) >> 14) |
708 ((x & 0x003000) >> 12);
09f080a5
KR
709 return temp & 0x1fffff;
710}
711
7050286d
KR
712void
713dis_assemble_21 (as21, x)
714 unsigned int as21, *x;
09f080a5
KR
715{
716 unsigned long temp;
717
718
7050286d
KR
719 temp = (as21 & 0x100000) >> 20;
720 temp |= (as21 & 0x0ffe00) >> 8;
721 temp |= (as21 & 0x000180) << 7;
722 temp |= (as21 & 0x00007c) << 14;
723 temp |= (as21 & 0x000003) << 12;
09f080a5
KR
724 *x = temp;
725}
726
7050286d
KR
727#if 0
728unsigned long
729sign_ext (x, len)
730 unsigned int x, len;
09f080a5
KR
731{
732 unsigned int sign;
733 unsigned int result;
734 unsigned int len_ones;
735 int i;
736
737 i = 0;
738 len_ones = 0;
7050286d
KR
739 while (i < len)
740 {
741 len_ones = (len_ones << 1) | 1;
742 i++;
743 }
09f080a5 744
7050286d 745 sign = (x >> (len - 1)) & 1;
09f080a5 746
7050286d
KR
747 if (sign)
748 result = (~0 ^ len_ones) | (len_ones & x);
09f080a5
KR
749 else
750 result = len_ones & x;
751
752 return result;
753}
754
7050286d
KR
755#endif
756static unsigned long
757sign_ext (x, len)
758 unsigned int x, len;
759{
760 return (x << (32 - len)) >> (32 - len);
761}
762
763static unsigned int
764ones (n)
09f080a5
KR
765 int n;
766{
767 unsigned int len_ones;
768 int i;
769
770 i = 0;
771 len_ones = 0;
7050286d
KR
772 while (i < n)
773 {
774 len_ones = (len_ones << 1) | 1;
775 i++;
776 }
09f080a5
KR
777
778 return len_ones;
779}
780
7050286d
KR
781void
782sign_unext (x, len, result)
783 unsigned int x, len;
09f080a5
KR
784 unsigned int *result;
785{
786 unsigned int len_ones;
787
7050286d 788 len_ones = ones (len);
09f080a5
KR
789
790 *result = x & len_ones;
791}
792
7050286d
KR
793unsigned long
794low_sign_ext (x, len)
795 unsigned int x, len;
09f080a5 796{
7050286d 797 unsigned int temp1, temp2;
09f080a5
KR
798 unsigned int len_ones;
799
7050286d 800 len_ones = ones (len);
09f080a5 801
7050286d
KR
802 temp1 = (x & 1) << (len - 1);
803 temp2 = ((x & 0xfffffffe) & len_ones) >> 1;
804 return sign_ext ((temp1 | temp2), len);
09f080a5
KR
805}
806
7050286d
KR
807void
808low_sign_unext (x, len, result)
809 unsigned int x, len;
09f080a5
KR
810 unsigned int *result;
811{
812 unsigned int temp;
813 unsigned int sign;
814 unsigned int rest;
815 unsigned int one_bit_at_len;
816 unsigned int len_ones;
817
7050286d
KR
818 len_ones = ones (len);
819 one_bit_at_len = 1 << (len - 1);
09f080a5 820
7050286d 821 sign_unext (x, len, &temp);
09f080a5 822 sign = temp & one_bit_at_len;
7050286d 823 sign >>= (len - 1);
09f080a5 824
7050286d 825 rest = temp & (len_ones ^ one_bit_at_len);
09f080a5
KR
826 rest <<= 1;
827
828 *result = rest | sign;
829}
830
831/* These work when 'y' is a power of two only. */
832
7050286d
KR
833static long
834round_down (x, y)
835 long x, y;
09f080a5 836{
7050286d 837 return x & ~(y - 1);
09f080a5
KR
838}
839
7050286d
KR
840static long
841round (x, y)
842 long x, y;
09f080a5 843{
7050286d 844 return (x + y / 2) & ~(y - 1);
09f080a5
KR
845}
846
7050286d
KR
847static long
848round_up (x, y)
849 long x, y;
09f080a5 850{
7050286d 851 return x - (x | ~(y - 1));
09f080a5
KR
852}
853
854/* L(Symbol, Addend): */
855/* round_down (Symbol + Addend, 2048) */
856
7050286d
KR
857static long
858L (Symbol, Addend)
09f080a5 859{
7050286d 860 return (round_down (Symbol + Addend, 2048)) >> 11;
09f080a5
KR
861}
862
863/* R(Symbol, Addend): */
864/* Symbol + Addend - round_down (Symbol + Addend, 2048) */
865
7050286d
KR
866static long
867R (Symbol, Addend)
09f080a5 868{
7050286d 869 return Symbol + Addend - round_down (Symbol + Addend, 2048);
09f080a5
KR
870}
871
872/* LS(Symbol, Addend): */
873/* round (Symbol + Addend, 2048) */
874
7050286d
KR
875static long
876LS (Symbol, Addend)
09f080a5 877{
7050286d 878 return round (Symbol + Addend, 2048);
09f080a5
KR
879}
880
881/* RS(Symbol, Addend): */
882/* Symbol + Addend - round (Symbol + Addend, 2048) */
883
7050286d
KR
884static long
885RS (Symbol, Addend)
09f080a5 886{
7050286d 887 return Symbol + Addend - round (Symbol + Addend, 2048);
09f080a5
KR
888}
889
890/* LD(Symbol, Addend): */
891/* round_up (Symbol + Addend, 2048) */
892
7050286d
KR
893static long
894LD (Symbol, Addend)
09f080a5 895{
7050286d 896 return (round_up (Symbol + Addend, 2048)) >> 11;
09f080a5
KR
897}
898
899/* RD(Symbol, Addend): */
900/* Symbol + Addend - round_up (Symbol + Addend, 2048) */
901
7050286d
KR
902static long
903RD (Symbol, Addend)
09f080a5 904{
7050286d 905 return Symbol + Addend - round_up (Symbol + Addend, 2048);
09f080a5
KR
906}
907
908/* LR(Symbol, Addend): */
909/* round_down (Symbol, 2048) + round (Addend, 8192) */
910
7050286d
KR
911static long
912LR (Symbol, Addend)
09f080a5 913{
7050286d 914 return (round_down (Symbol, 2048) + round (Addend, 8192)) >> 11;
09f080a5
KR
915}
916
917/* RR(Symbol, Addend): */
918/* Symbol - round_down (Symbol, 2048) + */
919/* Addend - round (Addend, 8192) */
920
7050286d
KR
921static long
922RR (Symbol, Addend)
09f080a5 923{
7050286d
KR
924 return Symbol
925 - round_down (Symbol, 2048)
926 + Addend - round (Addend, 8192);
09f080a5
KR
927}
928
929unsigned long
7050286d
KR
930DEFUN (hppa_field_adjust, (value, constant_value, r_field),
931 unsigned long value AND
932 unsigned long constant_value AND
933 unsigned short r_field)
09f080a5 934{
7050286d
KR
935 unsigned long init_value = value;
936 value += constant_value;
937 switch (r_field)
938 {
939 case e_fsel: /* F : no change */
940 break;
09f080a5 941
7050286d 942 case e_lssel: /* LS : if (bit 21) then add 0x800
09f080a5 943 arithmetic shift right 11 bits */
7050286d
KR
944 if (value & 0x00000400)
945 value += 0x800;
946 value = (value & 0xfffff800) >> 11;
947 BFD_ASSERT (value == LS (init_value, constant_value));
948 break;
949
950 case e_rssel: /* RS : Sign extend from bit 21 */
951 if (value & 0x00000400)
952 value |= 0xfffff800;
953 else
954 value &= 0x7ff;
955 BFD_ASSERT (value == RS (init_value, constant_value));
956 break;
957
958 case e_lsel: /* L : Arithmetic shift right 11 bits */
959 value = (value & 0xfffff800) >> 11;
960 BFD_ASSERT (value == L (init_value, constant_value));
961 break;
962
963 case e_rsel: /* R : Set bits 0-20 to zero */
964 value = value & 0x7ff;
965 BFD_ASSERT (value == R (init_value, constant_value));
966 break;
967
968 case e_ldsel: /* LD : Add 0x800, arithmetic shift
09f080a5 969 right 11 bits */
7050286d
KR
970 value += 0x800;
971 value = (value & 0xfffff800) >> 11;
972 BFD_ASSERT (value == LD (init_value, constant_value));
973 break;
09f080a5 974
7050286d
KR
975 case e_rdsel: /* RD : Set bits 0-20 to one */
976 value |= 0xfffff800;
977 BFD_ASSERT (value == RD (init_value, constant_value));
978 break;
979
980 case e_lrsel: /* LR : L with "rounded" constant */
981 value = value + ((constant_value + 0x1000) & 0xffffe000);
982 value = (value & 0xfffff800) >> 11;
983 BFD_ASSERT (value == LR (init_value, constant_value));
984 break;
985
986 case e_rrsel: /* RR : R with "rounded" constant */
987 value = value + ((constant_value + 0x1000) & 0xffffe000);
988 value = (value & 0x7ff) + constant_value - ((constant_value + 0x1000) & 0xffffe000);
989 BFD_ASSERT (value == RR (init_value, constant_value));
990 break;
991
992 default:
993 fprintf (stderr, "Unrecognized field_selector 0x%02x\n", r_field);
994 break;
995 }
09f080a5 996 return value;
7050286d 997
09f080a5
KR
998}
999
1000/* End of miscellaneous support functions. */
d325e28c
SG
1001
1002#ifdef HOST_HPPABSD
7050286d 1003/* All the core file code for BSD needs to be rewritten cleanly. For
d325e28c
SG
1004 now we do not support core files under BSD. */
1005
1006#define hppa_core_file_p _bfd_dummy_target
1007#define hppa_core_file_failing_command _bfd_dummy_core_file_failing_command
1008#define hppa_core_file_failing_signal _bfd_dummy_core_file_failing_signal
1009#define hppa_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
1010#endif /* HOST_HPPABSD */
e3c01e92
SG
1011
1012#define hppa_bfd_debug_info_start bfd_void
1013#define hppa_bfd_debug_info_end bfd_void
1014#define hppa_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
1015
e3c01e92
SG
1016#define hppa_openr_next_archived_file bfd_generic_openr_next_archived_file
1017#define hppa_generic_stat_arch_elt bfd_generic_stat_arch_elt
1018#define hppa_slurp_armap bfd_false
1019#define hppa_slurp_extended_name_table _bfd_slurp_extended_name_table
1020#define hppa_truncate_arname (void (*)())bfd_nullvoidptr
1021#define hppa_write_armap 0
1022
1023#define hppa_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
1024#define hppa_close_and_cleanup bfd_generic_close_and_cleanup
1025#define hppa_get_section_contents bfd_generic_get_section_contents
1026
1027#define hppa_bfd_get_relocated_section_contents \
1028 bfd_generic_get_relocated_section_contents
1029#define hppa_bfd_relax_section bfd_generic_relax_section
0c2fae09 1030#define hppa_bfd_seclet_link bfd_generic_seclet_link
8feff717
ILT
1031#define hppa_bfd_reloc_type_lookup \
1032 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
1033#define hppa_bfd_make_debug_symbol \
1034 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
e3c01e92 1035
e3c01e92
SG
1036bfd_target hppa_vec =
1037{
1038 "hppa", /* name */
1039 bfd_target_hppa_flavour,
1040 true, /* target byte order */
1041 true, /* target headers byte order */
1042 (HAS_RELOC | EXEC_P | /* object flags */
1043 HAS_LINENO | HAS_DEBUG |
1044 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
7050286d
KR
1045 (SEC_CODE | SEC_DATA | SEC_ROM | SEC_HAS_CONTENTS
1046 | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
4e98653c 1047
7050286d 1048/* leading_symbol_char: is the first char of a user symbol
4e98653c 1049 predictable, and if so what is it */
7050286d 1050 0,
e3c01e92
SG
1051 ' ', /* ar_pad_char */
1052 16, /* ar_max_namelen */
7050286d
KR
1053 3, /* minimum alignment */
1054 _do_getb64, _do_getb_signed_64, _do_putb64,
1055 _do_getb32, _do_getb_signed_32, _do_putb32,
1056 _do_getb16, _do_getb_signed_16, _do_putb16, /* data */
1057 _do_getb64, _do_getb_signed_64, _do_putb64,
1058 _do_getb32, _do_getb_signed_32, _do_putb32,
1059 _do_getb16, _do_getb_signed_16, _do_putb16, /* hdrs */
1060 {_bfd_dummy_target,
1061 hppa_object_p, /* bfd_check_format */
1062 bfd_generic_archive_p,
1063 hppa_core_file_p,
1064 },
e3c01e92
SG
1065 {
1066 bfd_false,
7050286d 1067 hppa_mkobject,
e3c01e92
SG
1068 _bfd_generic_mkarchive,
1069 bfd_false
7050286d 1070 },
e3c01e92
SG
1071 {
1072 bfd_false,
1073 hppa_write_object_contents,
1074 _bfd_write_archive_contents,
1075 bfd_false,
1076 },
acc7c493 1077#undef hppa
7050286d 1078 JUMP_TABLE (hppa),
8feff717 1079 (PTR) 0
e3c01e92
SG
1080};
1081
9a5e3a9a 1082#endif /* HOST_HPPAHPUX || HOST_HPPABSD */
This page took 0.097117 seconds and 4 git commands to generate.