1 /* bfd back-end for HP PA-RISC SOM objects.
2 Copyright (C) 1990-1991 Free Software Foundation, Inc.
4 Contributed by the Center for Software Science at the
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. */
30 /* #include "aout/hppa.h" */
33 #include <sys/types.h>
34 #include <sys/param.h>
37 #include <machine/reg.h>
39 #include <aout/hppa.h>
40 #include <machine/pcb.h>
42 #include <hpux/hpux.h>
43 #define USRSTACK 0x68FF3000
45 #include <sys/user.h> /* After a.out.h */
52 struct som_exec_auxhdr e;
62 fill_spaces(abfd, file_hdr, dbx_subspace, dbx_strings_subspace)
64 struct header *file_hdr;
65 struct subspace_dictionary_record *dbx_subspace, *dbx_strings_subspace;
67 char *space_strings = (char *) alloca (file_hdr->space_strings_size);
69 /* for millicode games. */
70 struct space_dictionary_record space;
71 struct subspace_dictionary_record subspace;
73 /* indices of subspace entries for $TEXT$ and $GDB_DEBUG$ */
74 int text_index = 0, gdb_debug_index = 0;
76 /* initialize in case we don't find any dbx symbols. */
77 dbx_subspace->subspace_length = dbx_strings_subspace->subspace_length = 0;
78 bfd_seek (abfd, file_hdr->space_strings_location, SEEK_SET);
79 if (bfd_read ((PTR) space_strings, 1, file_hdr->space_strings_size, abfd)
80 != file_hdr->space_strings_size)
82 bfd_error = wrong_format; /* space strings table corrupted. */
85 bfd_seek (abfd, file_hdr->space_location, SEEK_SET);
86 for (i = 0; i < file_hdr->space_total; i++)
88 bfd_read ((PTR) &space, 1, sizeof(space), abfd);
89 index = (file_hdr->subspace_location +
90 (space.subspace_index * sizeof(subspace)));
91 if (!strcmp (space_strings + space.name.n_strx, "$TEXT$"))
93 else if (!strcmp (space_strings + space.name.n_strx, "$GDB_DEBUG$"))
94 gdb_debug_index = index;
96 /* search out the beginning and end if millicode */
97 bfd_seek (abfd, text_index, SEEK_SET);
100 bfd_read ((PTR) &subspace, 1, sizeof(subspace), abfd);
101 if (!strcmp (space_strings + subspace.name.n_strx, "$MILLICODE$"))
103 millicode_start = subspace.subspace_start;
104 millicode_end = (millicode_start + subspace.subspace_length);
108 /* read symbols subspace and strings subspace in possibly arbitrary
110 bfd_seek (abfd, gdb_debug_index, SEEK_SET);
111 bfd_read ((PTR) &subspace, 1, sizeof(struct subspace_dictionary_record),
113 if (!strcmp (space_strings + subspace.name.n_strx, "$GDB_STRINGS$"))
115 *dbx_strings_subspace = subspace;
116 bfd_read ((PTR) dbx_subspace, 1,
117 sizeof(struct subspace_dictionary_record), abfd);
121 *dbx_subspace = subspace;
122 bfd_read ((PTR) dbx_strings_subspace, 1,
123 sizeof(struct subspace_dictionary_record), abfd);
128 DEFUN(hppa_object_setup,(abfd, file_hdrp, aux_hdrp, dbx_subspace,
129 dbx_strings_subspace),
131 struct header *file_hdrp AND
132 struct som_exec_auxhdr *aux_hdrp AND
133 struct subspace_dictionary_record *dbx_subspace AND
134 struct subspace_dictionary_record *dbx_strings_subspace)
136 struct container *rawptr;
138 struct hppa_data_struct *rawptr1;
140 rawptr = (struct container *) bfd_zalloc (abfd, sizeof (struct container));
141 if (rawptr == NULL) {
142 bfd_error = no_memory;
146 rawptr1 = (struct hppa_data_struct *) bfd_zalloc (abfd, sizeof (struct hppa_data_struct));
147 if (rawptr1 == NULL) {
148 bfd_error = no_memory;
152 abfd->tdata.hppa_data = rawptr1;
153 obj_file_hdr (abfd) = &rawptr->f;
154 obj_aux_hdr (abfd) = &rawptr->e;
155 *obj_file_hdr (abfd) = *file_hdrp;
156 *obj_aux_hdr (abfd) = *aux_hdrp;
158 /* Set the file flags */
159 abfd->flags = NO_FLAGS;
160 if (file_hdrp->entry_offset)
161 abfd->flags |= HAS_RELOC;
162 if (file_hdrp->symbol_total)
163 abfd->flags |= HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS;
165 bfd_get_start_address (abfd) = aux_hdrp->exec_entry;
167 obj_hp_symbol_entry_size (abfd) = sizeof(struct symbol_dictionary_record);
168 obj_dbx_symbol_entry_size (abfd) = 12;
170 obj_pa_symbols (abfd) = (hppa_symbol_type *)NULL;
171 obj_hp_sym_count (abfd) = file_hdrp->symbol_total;
172 obj_dbx_sym_count (abfd) = dbx_subspace->subspace_length /
173 obj_dbx_symbol_entry_size (abfd);
174 bfd_get_symcount (abfd) = obj_hp_sym_count (abfd) + obj_dbx_sym_count (abfd);
176 bfd_default_set_arch_mach(abfd, bfd_arch_hppa, 0);
178 /* create the sections. This is raunchy, but bfd_close wants to reclaim
180 obj_textsec (abfd) = (asection *)NULL;
181 obj_datasec (abfd) = (asection *)NULL;
182 obj_bsssec (abfd) = (asection *)NULL;
183 (void)bfd_make_section(abfd, ".text");
184 (void)bfd_make_section(abfd, ".data");
185 (void)bfd_make_section(abfd, ".bss");
187 abfd->sections = obj_textsec (abfd);
188 obj_textsec (abfd)->next = obj_datasec (abfd);
189 obj_datasec (abfd)->next = obj_bsssec (abfd);
191 obj_datasec (abfd)->_raw_size = aux_hdrp->exec_dsize;
192 obj_bsssec (abfd)->_raw_size = aux_hdrp->exec_bsize;
193 obj_textsec (abfd)->_raw_size = aux_hdrp->exec_tsize;
195 obj_textsec (abfd)->flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS);
196 obj_datasec (abfd)->flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS);
197 obj_bsssec (abfd)->flags = SEC_ALLOC;
199 /* The virtual memory addresses of the sections */
200 obj_datasec (abfd)->vma = aux_hdrp->exec_dmem;
201 obj_bsssec (abfd)->vma = aux_hdrp->exec_bfill;
202 obj_textsec (abfd)->vma = aux_hdrp->exec_tmem;
204 /* The file offsets of the sections */
205 obj_textsec (abfd)->filepos = aux_hdrp->exec_tfile;
206 obj_datasec (abfd)->filepos = aux_hdrp->exec_dfile;
208 /* The file offsets of the relocation info */
209 obj_textsec (abfd)->rel_filepos = 0;
210 obj_datasec (abfd)->rel_filepos = 0;
212 /* The file offsets of the string table and symbol table. */
213 obj_hp_sym_filepos (abfd) = file_hdrp->symbol_location;
214 obj_hp_str_filepos (abfd) = file_hdrp->symbol_strings_location;
215 obj_dbx_sym_filepos (abfd) = dbx_subspace->file_loc_init_value;
216 obj_dbx_str_filepos (abfd) = dbx_strings_subspace->file_loc_init_value;
217 obj_hp_stringtab_size (abfd) = file_hdrp->symbol_strings_size;
218 obj_dbx_stringtab_size (abfd) = dbx_strings_subspace->subspace_length;
224 DEFUN(hppa_object_p,(abfd),
227 struct header file_hdr;
228 struct som_exec_auxhdr aux_hdr;
229 struct subspace_dictionary_record dbx_subspace;
230 struct subspace_dictionary_record dbx_strings_subspace;
232 if (bfd_read ((PTR) &file_hdr, 1, FILE_HDR_SIZE, abfd) != FILE_HDR_SIZE)
234 bfd_error = wrong_format;
237 if (bfd_read ((PTR) &aux_hdr, 1, AUX_HDR_SIZE, abfd) != AUX_HDR_SIZE)
239 bfd_error = wrong_format;
243 fill_spaces(abfd, &file_hdr, &dbx_subspace, &dbx_strings_subspace);
245 return hppa_object_setup(abfd, &file_hdr, &aux_hdr, &dbx_subspace, &dbx_strings_subspace);
250 DEFUN(hppa_mkobject,(abfd),
253 fprintf (stderr, "hppa_mkobject unimplemented\n");
260 DEFUN(hppa_write_object_contents,(abfd),
263 fprintf (stderr, "hppa_write_object_contents unimplemented\n");
272 DEFUN(hppa_get_symtab_upper_bound,(abfd),
275 fprintf (stderr, "hppa_get_symtab_upper_bound unimplemented\n");
282 DEFUN(hppa_get_reloc_upper_bound,(abfd, asect),
286 fprintf (stderr, "hppa_get_reloc_upper_bound unimplemented\n");
293 DEFUN(hppa_canonicalize_reloc,(abfd, section, relptr, symbols),
299 fprintf (stderr, "hppa_canonicalize_reloc unimplemented\n");
304 extern bfd_target hppa_vec;
306 DEFUN(hppa_get_symtab,(abfd, location),
310 fprintf (stderr, "hppa_get_symtab unimplemented\n");
317 DEFUN(hppa_make_empty_symbol,(abfd),
320 hppa_symbol_type *new =
321 (hppa_symbol_type *)bfd_zalloc (abfd, sizeof (hppa_symbol_type));
322 new->symbol.the_bfd = abfd;
329 DEFUN(hppa_print_symbol,(ignore_abfd, afile, symbol, how),
333 bfd_print_symbol_type how)
335 fprintf (stderr, "hppa_print_symbol unimplemented\n");
343 DEFUN(hppa_new_section_hook,(abfd, newsect),
347 /* align to double at least */
348 newsect->alignment_power = 3;
350 if (bfd_get_format (abfd) == bfd_object) {
351 if (obj_textsec(abfd) == NULL && !strcmp(newsect->name, ".text")) {
352 obj_textsec(abfd)= newsect;
356 if (obj_datasec(abfd) == NULL && !strcmp(newsect->name, ".data")) {
357 obj_datasec(abfd) = newsect;
361 if (obj_bsssec(abfd) == NULL && !strcmp(newsect->name, ".bss")) {
362 obj_bsssec(abfd) = newsect;
367 /* We allow more than three sections internally */
375 DEFUN(hppa_set_section_contents,(abfd, section, location, offset, count),
382 fprintf (stderr, "hppa_set_section_contents unimplimented\n");
390 DEFUN(hppa_set_arch_mach,(abfd, arch, machine),
392 enum bfd_architecture arch AND
393 unsigned long machine)
395 fprintf (stderr, "hppa_set_arch_mach unimplemented\n");
397 /* Allow any architecture to be supported by the hppa backend */
398 return bfd_default_set_arch_mach(abfd, arch, machine);
403 DEFUN (hppa_find_nearest_line,(abfd,
411 asection *section AND
412 asymbol **symbols AND
414 CONST char **filename_ptr AND
415 CONST char **functionname_ptr AND
416 unsigned int *line_ptr)
418 fprintf (stderr, "hppa_find_nearest_line unimplemented\n");
425 DEFUN (hppa_sizeof_headers, (abfd, reloc),
429 fprintf (stderr, "hppa_sizeof_headers unimplemented\n");
436 #define hppa_core_file_p _bfd_dummy_target
439 hppa_core_file_p (abfd)
444 unsigned int reg_offset, fp_reg_offset;
445 /* This struct is just for allocating two things with one zalloc, so
446 they will be freed together, without violating alignment constraints. */
448 struct hppa_core_struct coredata;
452 val = bfd_read ((void *)&u, 1, sizeof u, abfd);
454 return 0; /* Too small to be a core file */
456 /* Sanity check perhaps??? */
457 if (u.u_dsize > 0x1000000) /* Remember, it's in pages... */
459 if (u.u_ssize > 0x1000000)
461 /* Check that the size claimed is no greater than the file size. FIXME. */
463 /* OK, we believe you. You're a core file (sure, sure). */
465 /* Allocate both the upage and the struct core_data at once, so
466 a single free() will free them both. */
467 rawptr = (struct core_user *)bfd_zalloc (abfd, sizeof (struct core_user));
468 if (rawptr == NULL) {
469 bfd_error = no_memory;
473 abfd->tdata.hppa_core_data = &rawptr->coredata;
474 core_upage (abfd) = &rawptr->u;
475 *core_upage (abfd) = u; /* Save that upage! */
477 /* Create the sections. This is raunchy, but bfd_close wants to free
479 core_stacksec (abfd) = (asection *) zalloc (sizeof (asection));
480 if (core_stacksec (abfd) == NULL) {
482 bfd_error = no_memory;
483 free ((void *)rawptr);
486 core_datasec (abfd) = (asection *) zalloc (sizeof (asection));
487 if (core_datasec (abfd) == NULL) {
489 free ((void *)core_stacksec (abfd));
492 core_regsec (abfd) = (asection *) zalloc (sizeof (asection));
493 if (core_regsec (abfd) == NULL) {
495 free ((void *)core_datasec (abfd));
500 core_stacksec (abfd)->name = ".stack";
501 core_datasec (abfd)->name = ".data";
502 core_regsec (abfd)->name = ".reg";
504 core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
505 core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
506 core_regsec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
508 core_datasec (abfd)->_raw_size = NBPG * u.u_dsize;
509 core_stacksec (abfd)->_raw_size = NBPG * u.u_ssize;
510 core_regsec (abfd)->_raw_size = NBPG * UPAGES; /* Larger than sizeof struct u */
512 core_datasec (abfd)->vma = u.hpuxu_exdata.somexec.a_Dmem;
513 core_stacksec (abfd)->vma = USRSTACK; /* from sys/param */
514 /* This is tricky. As the "register section", we give them the entire
515 upage and stack. u.u_ar0 points to where "register 0" is stored.
516 There are two tricks with this, though. One is that the rest of the
517 registers might be at positive or negative (or both) displacements
518 from *u_ar0. The other is that u_ar0 is sometimes an absolute address
519 in kernel memory, and on other systems it is an offset from the beginning
520 of the `struct user'.
522 As a practical matter, we don't know where the registers actually are,
523 so we have to pass the whole area to GDB. We encode the value of u_ar0
524 by setting the .regs section up so that its virtual memory address
525 0 is at the place pointed to by u_ar0 (by setting the vma of the start
526 of the section to -u_ar0). GDB uses this info to locate the regs,
527 using minor trickery to get around the offset-or-absolute-addr problem. */
528 core_regsec (abfd)->vma = 0 - NBPG * USIZE; /* -u_ar0 */
530 core_datasec (abfd)->filepos = NBPG * UPAGES;
531 core_stacksec (abfd)->filepos = (NBPG * UPAGES) + NBPG * u.u_dsize;
532 core_regsec (abfd)->filepos = 0; /* Register segment is the upage */
534 /* Align to word at least */
535 core_stacksec (abfd)->alignment_power = 2;
536 core_datasec (abfd)->alignment_power = 2;
537 core_regsec (abfd)->alignment_power = 2;
539 abfd->sections = core_stacksec (abfd);
540 core_stacksec (abfd)->next = core_datasec (abfd);
541 core_datasec (abfd)->next = core_regsec (abfd);
542 abfd->section_count = 3;
549 #define hppa_core_file_failing_command (char *(*)())(bfd_nullvoidptr)
552 hppa_core_file_failing_command (abfd)
555 #ifndef NO_CORE_COMMAND
556 if (*core_upage (abfd)->u_comm)
557 return core_upage (abfd)->u_comm;
566 hppa_core_file_failing_signal (ignore_abfd)
569 return -1; /* FIXME, where is it? */
574 hppa_core_file_matches_executable_p (core_bfd, exec_bfd)
575 bfd *core_bfd, *exec_bfd;
577 return true; /* FIXME, We have no way of telling at this point */
580 #define hppa_bfd_debug_info_start bfd_void
581 #define hppa_bfd_debug_info_end bfd_void
582 #define hppa_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
586 #define hppa_openr_next_archived_file bfd_generic_openr_next_archived_file
587 #define hppa_generic_stat_arch_elt bfd_generic_stat_arch_elt
588 #define hppa_slurp_armap bfd_false
589 #define hppa_slurp_extended_name_table _bfd_slurp_extended_name_table
590 #define hppa_truncate_arname (void (*)())bfd_nullvoidptr
591 #define hppa_write_armap 0
593 #define hppa_get_lineno (struct lineno_cache_entry *(*)())bfd_nullvoidptr
594 #define hppa_close_and_cleanup bfd_generic_close_and_cleanup
595 #define hppa_get_section_contents bfd_generic_get_section_contents
597 #define hppa_bfd_get_relocated_section_contents \
598 bfd_generic_get_relocated_section_contents
599 #define hppa_bfd_relax_section bfd_generic_relax_section
602 bfd_target hppa_vec =
605 bfd_target_hppa_flavour,
606 true, /* target byte order */
607 true, /* target headers byte order */
608 (HAS_RELOC | EXEC_P | /* object flags */
609 HAS_LINENO | HAS_DEBUG |
610 HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT | D_PAGED),
611 (SEC_CODE|SEC_DATA|SEC_ROM|SEC_HAS_CONTENTS
612 |SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
613 ' ', /* ar_pad_char */
614 16, /* ar_max_namelen */
615 3, /* minimum alignment */
616 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* data */
617 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16, /* hdrs */
620 hppa_object_p, /* bfd_check_format */
621 bfd_generic_archive_p,
627 _bfd_generic_mkarchive,
632 hppa_write_object_contents,
633 _bfd_write_archive_contents,
640 #else /* notdef hp9000s800 */
641 /* Prevent "empty translation unit" warnings from the idiots at X3J11. */
642 static char ansi_c_idiots = 69;
643 #endif /* hp9000s800 */