/* Generic ECOFF support.
This does not include symbol information, found in sym.h and
symconst.h.
Copyright (C) 2001-2024 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef ECOFF_H
#define ECOFF_H
#include "coff/sym.h"
/* Mips magic numbers used in filehdr. MIPS_MAGIC_LITTLE is used on
little endian machines. MIPS_MAGIC_BIG is used on big endian
machines. Where is MIPS_MAGIC_1 from? */
#define MIPS_MAGIC_1 0x0180
#define MIPS_MAGIC_LITTLE 0x0162
#define MIPS_MAGIC_BIG 0x0160
/* These are the magic numbers used for MIPS code compiled at ISA
level 2. */
#define MIPS_MAGIC_LITTLE2 0x0166
#define MIPS_MAGIC_BIG2 0x0163
/* These are the magic numbers used for MIPS code compiled at ISA
level 3. */
#define MIPS_MAGIC_LITTLE3 0x142
#define MIPS_MAGIC_BIG3 0x140
/* Alpha magic numbers used in filehdr. */
#define ALPHA_MAGIC 0x183
#define ALPHA_MAGIC_BSD 0x185
/* A compressed version of an ALPHA_MAGIC file created by DEC's tools. */
#define ALPHA_MAGIC_COMPRESSED 0x188
/* Magic numbers used in a.out header. */
#define ECOFF_AOUT_OMAGIC 0407 /* not demand paged (ld -N). */
#define ECOFF_AOUT_ZMAGIC 0413 /* demand load format, eg normal ld output */
/* The linker needs a section to hold small common variables while
linking. There is no convenient way to create it when the linker
needs it, so we always create one for each BFD. We then avoid
writing it out. */
#define SCOMMON ".scommon"
/* If the extern bit in a reloc is 1, then r_symndx is an index into
the external symbol table. If the extern bit is 0, then r_symndx
indicates a section, and is one of the following values. */
#define RELOC_SECTION_NONE 0
#define RELOC_SECTION_TEXT 1
#define RELOC_SECTION_RDATA 2
#define RELOC_SECTION_DATA 3
#define RELOC_SECTION_SDATA 4
#define RELOC_SECTION_SBSS 5
#define RELOC_SECTION_BSS 6
#define RELOC_SECTION_INIT 7
#define RELOC_SECTION_LIT8 8
#define RELOC_SECTION_LIT4 9
#define RELOC_SECTION_XDATA 10
#define RELOC_SECTION_PDATA 11
#define RELOC_SECTION_FINI 12
#define RELOC_SECTION_LITA 13
#define RELOC_SECTION_ABS 14
#define RELOC_SECTION_RCONST 15
/* gcc uses mips-tfile to output type information in special stabs
entries. These must match the corresponding definition in
gcc/config/mips.h. At some point, these should probably go into a
shared include file, but currently gcc and gdb do not share any
directories. */
#define CODE_MASK 0x8F300
#define ECOFF_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
#define ECOFF_MARK_STAB(code) ((code)+CODE_MASK)
#define ECOFF_UNMARK_STAB(code) ((code)-CODE_MASK)
#define STABS_SYMBOL "@stabs"
/* gcc also uses mips-tfile to output COFF debugging information.
These are the values it uses when outputting the .type directive.
These should also be in a shared include file. */
#define N_BTMASK (017)
#define N_TMASK (060)
#define N_BTSHFT (4)
#define N_TSHIFT (2)
/********************** AUX **********************/
/* The auxiliary type information is the same on all known ECOFF
targets. I can't see any reason that it would ever change, so I am
going to gamble and define the external structures here, in the
target independent ECOFF header file. The internal forms are
defined in coff/sym.h, which was originally donated by MIPS
Computer Systems. */
/* For efficiency, gdb deals directly with the unswapped symbolic
information (that way it only takes the time to swap information
that it really needs to read). gdb originally retrieved the
information directly from the BFD backend information, but that
strategy, besides being sort of ugly, does not work for MIPS ELF,
which also uses ECOFF debugging information. This structure holds
pointers to the (mostly) unswapped symbolic information. */
/* Pointers to the unswapped symbolic information. Note that the
pointers to external structures point to different sorts of
information on different ECOFF targets. The ecoff_debug_swap
structure provides the sizes of the structures and the functions
needed to swap the information in and out. These pointers are
all pointers to arrays, not single structures. They will be NULL
if there are no instances of the relevant structure. These
fields are also used by the assembler to output ECOFF debugging
information. If alloc_syments is true then the pointers are to
objalloc memory, or into a single malloc'd buffer, or otherwise
should not be freed. */
bool alloc_syments;
unsigned char *line;
void *external_dnr; /* struct dnr_ext */
void *external_pdr; /* struct pdr_ext */
void *external_sym; /* struct sym_ext */
void *external_opt; /* struct opt_ext */
union aux_ext *external_aux;
char *ss;
char *ssext;
void *external_fdr; /* struct fdr_ext */
void *external_rfd; /* struct rfd_ext */
void *external_ext; /* struct ext_ext */
/* These fields are used when linking. They may disappear at some
point. */
char *ssext_end;
void *external_ext_end;
/* When linking, this field holds a mapping from the input FDR
numbers to the output numbers, and is used when writing out the
external symbols. It is NULL if no mapping is required. */
RFDT *ifdmap;
/* The swapped FDR information. Currently this is never NULL, but
code using this structure should probably double-check in case
this changes in the future. This is a pointer to an array, not a
single structure. */
FDR *fdr;
};
/* These structures are used by the ECOFF find_nearest_line function. */
struct ecoff_fdrtab_entry
{
/* Base address in .text of this FDR. */
bfd_vma base_addr;
FDR *fdr;
};
struct ecoff_find_line
{
/* Allocated memory to hold function and file names. */
char *find_buffer;
/* FDR table, sorted by address: */
long fdrtab_len;
struct ecoff_fdrtab_entry *fdrtab;
/* Cache entry for most recently found line information. The sect
field is NULL if this cache does not contain valid information. */
struct
{
asection *sect;
bfd_vma start;
bfd_vma stop;
const char *filename;
const char *functionname;
unsigned int line_num;
} cache;
};
/* The generic ECOFF code needs to be able to swap debugging
information in and out in the specific format used by a particular
ECOFF implementation. This structure provides the information
needed to do this. */