xref: /openbsd-src/gnu/usr.bin/binutils/include/coff/mips.h (revision c074d1c999f3e07019cd5e9a2f190b057ef3b935)
12159047fSniklas /* ECOFF support on MIPS machines.
2b55d4692Sfgsch    coff/ecoff.h must be included before this file.
3b55d4692Sfgsch 
4b55d4692Sfgsch    Copyright 2001 Free Software Foundation, Inc.
5b55d4692Sfgsch 
6b55d4692Sfgsch    This program is free software; you can redistribute it and/or modify
7b55d4692Sfgsch    it under the terms of the GNU General Public License as published by
8b55d4692Sfgsch    the Free Software Foundation; either version 2 of the License, or
9b55d4692Sfgsch    (at your option) any later version.
10b55d4692Sfgsch 
11b55d4692Sfgsch    This program is distributed in the hope that it will be useful,
12b55d4692Sfgsch    but WITHOUT ANY WARRANTY; without even the implied warranty of
13b55d4692Sfgsch    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14b55d4692Sfgsch    GNU General Public License for more details.
15b55d4692Sfgsch 
16b55d4692Sfgsch    You should have received a copy of the GNU General Public License
17b55d4692Sfgsch    along with this program; if not, write to the Free Software
18b55d4692Sfgsch    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
192159047fSniklas 
20*c074d1c9Sdrahn #define DO_NOT_DEFINE_AOUTHDR
21*c074d1c9Sdrahn #define L_LNNO_SIZE 4
22*c074d1c9Sdrahn #include "coff/external.h"
232159047fSniklas 
242159047fSniklas /* Magic numbers are defined in coff/ecoff.h.  */
252159047fSniklas #define MIPS_ECOFF_BADMAG(x) (((x).f_magic!=MIPS_MAGIC_1) && \
262159047fSniklas 			      ((x).f_magic!=MIPS_MAGIC_LITTLE) &&\
272159047fSniklas 			      ((x).f_magic!=MIPS_MAGIC_BIG) && \
282159047fSniklas 			      ((x).f_magic!=MIPS_MAGIC_LITTLE2) && \
292159047fSniklas 			      ((x).f_magic!=MIPS_MAGIC_BIG2) && \
302159047fSniklas 			      ((x).f_magic!=MIPS_MAGIC_LITTLE3) && \
312159047fSniklas 			      ((x).f_magic!=MIPS_MAGIC_BIG3))
322159047fSniklas 
332159047fSniklas 
342159047fSniklas /********************** AOUT "OPTIONAL HEADER" **********************/
352159047fSniklas 
362159047fSniklas typedef struct external_aouthdr
372159047fSniklas {
382159047fSniklas   unsigned char magic[2];	/* type of file				*/
392159047fSniklas   unsigned char	vstamp[2];	/* version stamp			*/
402159047fSniklas   unsigned char	tsize[4];	/* text size in bytes, padded to FW bdry*/
412159047fSniklas   unsigned char	dsize[4];	/* initialized data "  "		*/
422159047fSniklas   unsigned char	bsize[4];	/* uninitialized data "   "		*/
432159047fSniklas   unsigned char	entry[4];	/* entry pt.				*/
442159047fSniklas   unsigned char text_start[4];	/* base of text used for this file */
452159047fSniklas   unsigned char data_start[4];	/* base of data used for this file */
462159047fSniklas   unsigned char bss_start[4];	/* base of bss used for this file */
472159047fSniklas   unsigned char gprmask[4];	/* ?? */
482159047fSniklas   unsigned char cprmask[4][4];	/* ?? */
492159047fSniklas   unsigned char gp_value[4];	/* value for gp register */
502159047fSniklas } AOUTHDR;
512159047fSniklas 
522159047fSniklas /* compute size of a header */
532159047fSniklas 
544361b62eSniklas #define AOUTSZ 56
554361b62eSniklas #define AOUTHDRSZ 56
562159047fSniklas 
572159047fSniklas /********************** RELOCATION DIRECTIVES **********************/
582159047fSniklas 
59*c074d1c9Sdrahn struct external_reloc
60*c074d1c9Sdrahn   {
612159047fSniklas     unsigned char r_vaddr[4];
622159047fSniklas     unsigned char r_bits[4];
632159047fSniklas   };
642159047fSniklas 
652159047fSniklas #define RELOC struct external_reloc
662159047fSniklas #define RELSZ 8
672159047fSniklas 
682159047fSniklas /* MIPS ECOFF uses a packed 8 byte format for relocs.  These constants
692159047fSniklas    are used to unpack the r_bits field.  */
702159047fSniklas 
712159047fSniklas #define RELOC_BITS0_SYMNDX_SH_LEFT_BIG		16
722159047fSniklas #define RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE	0
732159047fSniklas 
742159047fSniklas #define RELOC_BITS1_SYMNDX_SH_LEFT_BIG		8
752159047fSniklas #define RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE	8
762159047fSniklas 
772159047fSniklas #define RELOC_BITS2_SYMNDX_SH_LEFT_BIG		0
782159047fSniklas #define RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE	16
792159047fSniklas 
802159047fSniklas /* Originally, ECOFF used four bits for the reloc type and had three
812159047fSniklas    reserved bits.  Irix 4 added another bit for the reloc type, which
822159047fSniklas    was easy because it was big endian and one of the spare bits became
832159047fSniklas    the new most significant bit.  To make this also work for little
842159047fSniklas    endian ECOFF, we need to wrap one of the reserved bits around to
852159047fSniklas    become the most significant bit of the reloc type.  */
862159047fSniklas #define RELOC_BITS3_TYPE_BIG			0x3E
872159047fSniklas #define RELOC_BITS3_TYPE_SH_BIG			1
882159047fSniklas #define RELOC_BITS3_TYPE_LITTLE			0x78
892159047fSniklas #define RELOC_BITS3_TYPE_SH_LITTLE		3
902159047fSniklas #define RELOC_BITS3_TYPEHI_LITTLE		0x04
912159047fSniklas #define RELOC_BITS3_TYPEHI_SH_LITTLE		2
922159047fSniklas 
932159047fSniklas #define RELOC_BITS3_EXTERN_BIG			0x01
942159047fSniklas #define RELOC_BITS3_EXTERN_LITTLE		0x80
952159047fSniklas 
962159047fSniklas /* The r_type field in a reloc is one of the following values.  I
972159047fSniklas    don't know if any other values can appear.  These seem to be all
982159047fSniklas    that occur in the Ultrix 4.2 libraries.  */
992159047fSniklas #define MIPS_R_IGNORE	0
1002159047fSniklas #define MIPS_R_REFHALF	1
1012159047fSniklas #define MIPS_R_REFWORD	2
1022159047fSniklas #define MIPS_R_JMPADDR	3
1032159047fSniklas #define MIPS_R_REFHI	4
1042159047fSniklas #define MIPS_R_REFLO	5
1052159047fSniklas #define MIPS_R_GPREL	6
1062159047fSniklas #define MIPS_R_LITERAL	7
1072159047fSniklas 
1082159047fSniklas /* These reloc types are a Cygnus extension used when generating
1092159047fSniklas    position independent code for embedded systems.  The numbers are
1102159047fSniklas    taken from Irix 4, but at least for internal relocs Irix 5 does not
1112159047fSniklas    give them the same meaning.  For an internal reloc the symbol index
1122159047fSniklas    of RELHI and RELLO is modified as described below for
1132159047fSniklas    MIPS_R_SWITCH.  */
1142159047fSniklas #define MIPS_R_PCREL16	12
1152159047fSniklas #define MIPS_R_RELHI	13
1162159047fSniklas #define MIPS_R_RELLO	14
1172159047fSniklas 
1182159047fSniklas /* This reloc type is a Cygnus extension used when generating position
1192159047fSniklas    independent code for embedded systems.  It is used for an entry in
1202159047fSniklas    a switch table, which looks like this:
1212159047fSniklas      .word $L3-$LS12
1222159047fSniklas    The object file will contain the correct difference, and does not
1232159047fSniklas    require adjustment.  However, when the linker is relaxing PC
1242159047fSniklas    relative calls, it is possible for $L3 to move farther away.  This
1252159047fSniklas    reloc always appears in the .text section, and is always against
1262159047fSniklas    the .text section.  However, the symbol index is not
1272159047fSniklas    RELOC_SECTION_TEXT.  It is, instead, the distance between this
1282159047fSniklas    switch table entry and $LS12.  Thus, the original value of $L12 is
1292159047fSniklas      vaddr - symndx
1302159047fSniklas    and the original value of $L3 is
1312159047fSniklas      vaddr - symndx + addend
1322159047fSniklas    where addend is the value in the object file.  Knowing this, the
1332159047fSniklas    linker can know whether the addend in the object file must be
1342159047fSniklas    adjusted.  */
1352159047fSniklas #define MIPS_R_SWITCH	22
1362159047fSniklas 
1372159047fSniklas /********************** STABS **********************/
1382159047fSniklas 
1392159047fSniklas #define MIPS_IS_STAB ECOFF_IS_STAB
1402159047fSniklas #define MIPS_MARK_STAB ECOFF_MARK_STAB
1412159047fSniklas #define MIPS_UNMARK_STAB ECOFF_UNMARK_STAB
1422159047fSniklas 
1432159047fSniklas /********************** SYMBOLIC INFORMATION **********************/
1442159047fSniklas 
1452159047fSniklas /* Written by John Gilmore.  */
1462159047fSniklas 
1472159047fSniklas /* ECOFF uses COFF-like section structures, but its own symbol format.
1482159047fSniklas    This file defines the symbol format in fields whose size and alignment
1492159047fSniklas    will not vary on different host systems.  */
1502159047fSniklas 
1512159047fSniklas /* File header as a set of bytes */
1522159047fSniklas 
153*c074d1c9Sdrahn struct hdr_ext
154*c074d1c9Sdrahn {
1552159047fSniklas 	unsigned char 	h_magic[2];
1562159047fSniklas 	unsigned char	h_vstamp[2];
1572159047fSniklas 	unsigned char	h_ilineMax[4];
1582159047fSniklas 	unsigned char	h_cbLine[4];
1592159047fSniklas 	unsigned char	h_cbLineOffset[4];
1602159047fSniklas 	unsigned char	h_idnMax[4];
1612159047fSniklas 	unsigned char	h_cbDnOffset[4];
1622159047fSniklas 	unsigned char	h_ipdMax[4];
1632159047fSniklas 	unsigned char	h_cbPdOffset[4];
1642159047fSniklas 	unsigned char	h_isymMax[4];
1652159047fSniklas 	unsigned char	h_cbSymOffset[4];
1662159047fSniklas 	unsigned char	h_ioptMax[4];
1672159047fSniklas 	unsigned char	h_cbOptOffset[4];
1682159047fSniklas 	unsigned char	h_iauxMax[4];
1692159047fSniklas 	unsigned char	h_cbAuxOffset[4];
1702159047fSniklas 	unsigned char	h_issMax[4];
1712159047fSniklas 	unsigned char	h_cbSsOffset[4];
1722159047fSniklas 	unsigned char	h_issExtMax[4];
1732159047fSniklas 	unsigned char	h_cbSsExtOffset[4];
1742159047fSniklas 	unsigned char	h_ifdMax[4];
1752159047fSniklas 	unsigned char	h_cbFdOffset[4];
1762159047fSniklas 	unsigned char	h_crfd[4];
1772159047fSniklas 	unsigned char	h_cbRfdOffset[4];
1782159047fSniklas 	unsigned char	h_iextMax[4];
1792159047fSniklas 	unsigned char	h_cbExtOffset[4];
1802159047fSniklas };
1812159047fSniklas 
1822159047fSniklas /* File descriptor external record */
1832159047fSniklas 
184*c074d1c9Sdrahn struct fdr_ext
185*c074d1c9Sdrahn {
1862159047fSniklas 	unsigned char	f_adr[4];
1872159047fSniklas 	unsigned char	f_rss[4];
1882159047fSniklas 	unsigned char	f_issBase[4];
1892159047fSniklas 	unsigned char	f_cbSs[4];
1902159047fSniklas 	unsigned char	f_isymBase[4];
1912159047fSniklas 	unsigned char	f_csym[4];
1922159047fSniklas 	unsigned char	f_ilineBase[4];
1932159047fSniklas 	unsigned char	f_cline[4];
1942159047fSniklas 	unsigned char	f_ioptBase[4];
1952159047fSniklas 	unsigned char	f_copt[4];
1962159047fSniklas 	unsigned char	f_ipdFirst[2];
1972159047fSniklas 	unsigned char	f_cpd[2];
1982159047fSniklas 	unsigned char	f_iauxBase[4];
1992159047fSniklas 	unsigned char	f_caux[4];
2002159047fSniklas 	unsigned char	f_rfdBase[4];
2012159047fSniklas 	unsigned char	f_crfd[4];
2022159047fSniklas 	unsigned char	f_bits1[1];
2032159047fSniklas 	unsigned char	f_bits2[3];
2042159047fSniklas 	unsigned char	f_cbLineOffset[4];
2052159047fSniklas 	unsigned char	f_cbLine[4];
2062159047fSniklas };
2072159047fSniklas 
2082159047fSniklas #define	FDR_BITS1_LANG_BIG		0xF8
2092159047fSniklas #define	FDR_BITS1_LANG_SH_BIG		3
2102159047fSniklas #define	FDR_BITS1_LANG_LITTLE		0x1F
2112159047fSniklas #define	FDR_BITS1_LANG_SH_LITTLE	0
2122159047fSniklas 
2132159047fSniklas #define	FDR_BITS1_FMERGE_BIG		0x04
2142159047fSniklas #define	FDR_BITS1_FMERGE_LITTLE		0x20
2152159047fSniklas 
2162159047fSniklas #define	FDR_BITS1_FREADIN_BIG		0x02
2172159047fSniklas #define	FDR_BITS1_FREADIN_LITTLE	0x40
2182159047fSniklas 
2192159047fSniklas #define	FDR_BITS1_FBIGENDIAN_BIG	0x01
2202159047fSniklas #define	FDR_BITS1_FBIGENDIAN_LITTLE	0x80
2212159047fSniklas 
2222159047fSniklas #define	FDR_BITS2_GLEVEL_BIG		0xC0
2232159047fSniklas #define	FDR_BITS2_GLEVEL_SH_BIG		6
2242159047fSniklas #define	FDR_BITS2_GLEVEL_LITTLE		0x03
2252159047fSniklas #define	FDR_BITS2_GLEVEL_SH_LITTLE	0
2262159047fSniklas 
2272159047fSniklas /* We ignore the `reserved' field in bits2. */
2282159047fSniklas 
2292159047fSniklas /* Procedure descriptor external record */
2302159047fSniklas 
231*c074d1c9Sdrahn struct pdr_ext
232*c074d1c9Sdrahn {
2332159047fSniklas 	unsigned char	p_adr[4];
2342159047fSniklas 	unsigned char	p_isym[4];
2352159047fSniklas 	unsigned char	p_iline[4];
2362159047fSniklas 	unsigned char	p_regmask[4];
2372159047fSniklas 	unsigned char	p_regoffset[4];
2382159047fSniklas 	unsigned char	p_iopt[4];
2392159047fSniklas 	unsigned char	p_fregmask[4];
2402159047fSniklas 	unsigned char	p_fregoffset[4];
2412159047fSniklas 	unsigned char	p_frameoffset[4];
2422159047fSniklas 	unsigned char	p_framereg[2];
2432159047fSniklas 	unsigned char	p_pcreg[2];
2442159047fSniklas 	unsigned char	p_lnLow[4];
2452159047fSniklas 	unsigned char	p_lnHigh[4];
2462159047fSniklas 	unsigned char	p_cbLineOffset[4];
2472159047fSniklas };
2482159047fSniklas 
2492159047fSniklas /* Runtime procedure table */
2502159047fSniklas 
251*c074d1c9Sdrahn struct rpdr_ext
252*c074d1c9Sdrahn {
2532159047fSniklas 	unsigned char	p_adr[4];
2542159047fSniklas 	unsigned char	p_regmask[4];
2552159047fSniklas 	unsigned char	p_regoffset[4];
2562159047fSniklas 	unsigned char	p_fregmask[4];
2572159047fSniklas 	unsigned char	p_fregoffset[4];
2582159047fSniklas 	unsigned char	p_frameoffset[4];
2592159047fSniklas 	unsigned char	p_framereg[2];
2602159047fSniklas 	unsigned char	p_pcreg[2];
2612159047fSniklas 	unsigned char	p_irpss[4];
2622159047fSniklas 	unsigned char	p_reserved[4];
2632159047fSniklas 	unsigned char	p_exception_info[4];
2642159047fSniklas };
2652159047fSniklas 
2662159047fSniklas /* Line numbers */
2672159047fSniklas 
268*c074d1c9Sdrahn struct line_ext
269*c074d1c9Sdrahn {
2702159047fSniklas 	unsigned char	l_line[4];
2712159047fSniklas };
2722159047fSniklas 
2732159047fSniklas /* Symbol external record */
2742159047fSniklas 
275*c074d1c9Sdrahn struct sym_ext
276*c074d1c9Sdrahn {
2772159047fSniklas 	unsigned char	s_iss[4];
2782159047fSniklas 	unsigned char	s_value[4];
2792159047fSniklas 	unsigned char	s_bits1[1];
2802159047fSniklas 	unsigned char	s_bits2[1];
2812159047fSniklas 	unsigned char	s_bits3[1];
2822159047fSniklas 	unsigned char	s_bits4[1];
2832159047fSniklas };
2842159047fSniklas 
2852159047fSniklas #define	SYM_BITS1_ST_BIG		0xFC
2862159047fSniklas #define	SYM_BITS1_ST_SH_BIG		2
2872159047fSniklas #define	SYM_BITS1_ST_LITTLE		0x3F
2882159047fSniklas #define	SYM_BITS1_ST_SH_LITTLE		0
2892159047fSniklas 
2902159047fSniklas #define	SYM_BITS1_SC_BIG		0x03
2912159047fSniklas #define	SYM_BITS1_SC_SH_LEFT_BIG	3
2922159047fSniklas #define	SYM_BITS1_SC_LITTLE		0xC0
2932159047fSniklas #define	SYM_BITS1_SC_SH_LITTLE		6
2942159047fSniklas 
2952159047fSniklas #define	SYM_BITS2_SC_BIG		0xE0
2962159047fSniklas #define	SYM_BITS2_SC_SH_BIG		5
2972159047fSniklas #define	SYM_BITS2_SC_LITTLE		0x07
2982159047fSniklas #define	SYM_BITS2_SC_SH_LEFT_LITTLE	2
2992159047fSniklas 
3002159047fSniklas #define	SYM_BITS2_RESERVED_BIG		0x10
3012159047fSniklas #define	SYM_BITS2_RESERVED_LITTLE	0x08
3022159047fSniklas 
3032159047fSniklas #define	SYM_BITS2_INDEX_BIG		0x0F
3042159047fSniklas #define	SYM_BITS2_INDEX_SH_LEFT_BIG	16
3052159047fSniklas #define	SYM_BITS2_INDEX_LITTLE		0xF0
3062159047fSniklas #define	SYM_BITS2_INDEX_SH_LITTLE	4
3072159047fSniklas 
3082159047fSniklas #define	SYM_BITS3_INDEX_SH_LEFT_BIG	8
3092159047fSniklas #define	SYM_BITS3_INDEX_SH_LEFT_LITTLE	4
3102159047fSniklas 
3112159047fSniklas #define	SYM_BITS4_INDEX_SH_LEFT_BIG	0
3122159047fSniklas #define	SYM_BITS4_INDEX_SH_LEFT_LITTLE	12
3132159047fSniklas 
3142159047fSniklas /* External symbol external record */
3152159047fSniklas 
316*c074d1c9Sdrahn struct ext_ext
317*c074d1c9Sdrahn {
3182159047fSniklas 	unsigned char	es_bits1[1];
3192159047fSniklas 	unsigned char	es_bits2[1];
3202159047fSniklas 	unsigned char	es_ifd[2];
3212159047fSniklas 	struct	sym_ext es_asym;
3222159047fSniklas };
3232159047fSniklas 
3242159047fSniklas #define	EXT_BITS1_JMPTBL_BIG		0x80
3252159047fSniklas #define	EXT_BITS1_JMPTBL_LITTLE		0x01
3262159047fSniklas 
3272159047fSniklas #define	EXT_BITS1_COBOL_MAIN_BIG	0x40
3282159047fSniklas #define	EXT_BITS1_COBOL_MAIN_LITTLE	0x02
3292159047fSniklas 
3302159047fSniklas #define	EXT_BITS1_WEAKEXT_BIG		0x20
3312159047fSniklas #define	EXT_BITS1_WEAKEXT_LITTLE	0x04
3322159047fSniklas 
3332159047fSniklas /* Dense numbers external record */
3342159047fSniklas 
335*c074d1c9Sdrahn struct dnr_ext
336*c074d1c9Sdrahn {
3372159047fSniklas 	unsigned char	d_rfd[4];
3382159047fSniklas 	unsigned char	d_index[4];
3392159047fSniklas };
3402159047fSniklas 
3412159047fSniklas /* Relative file descriptor */
3422159047fSniklas 
343*c074d1c9Sdrahn struct rfd_ext
344*c074d1c9Sdrahn {
3452159047fSniklas   unsigned char	rfd[4];
3462159047fSniklas };
3472159047fSniklas 
3482159047fSniklas /* Optimizer symbol external record */
3492159047fSniklas 
350*c074d1c9Sdrahn struct opt_ext
351*c074d1c9Sdrahn {
3522159047fSniklas   unsigned char o_bits1[1];
3532159047fSniklas   unsigned char o_bits2[1];
3542159047fSniklas   unsigned char o_bits3[1];
3552159047fSniklas   unsigned char o_bits4[1];
3562159047fSniklas   struct rndx_ext o_rndx;
3572159047fSniklas   unsigned char o_offset[4];
3582159047fSniklas };
3592159047fSniklas 
3602159047fSniklas #define OPT_BITS2_VALUE_SH_LEFT_BIG	16
3612159047fSniklas #define OPT_BITS2_VALUE_SH_LEFT_LITTLE	0
3622159047fSniklas 
3632159047fSniklas #define OPT_BITS3_VALUE_SH_LEFT_BIG	8
3642159047fSniklas #define OPT_BITS3_VALUE_SH_LEFT_LITTLE	8
3652159047fSniklas 
3662159047fSniklas #define OPT_BITS4_VALUE_SH_LEFT_BIG	0
3672159047fSniklas #define OPT_BITS4_VALUE_SH_LEFT_LITTLE	16
368