1*3d8817e4Smiod /* ECOFF support on MIPS machines. 2*3d8817e4Smiod coff/ecoff.h must be included before this file. 3*3d8817e4Smiod 4*3d8817e4Smiod Copyright 1999, 2004 Free Software Foundation, Inc. 5*3d8817e4Smiod 6*3d8817e4Smiod This program is free software; you can redistribute it and/or modify 7*3d8817e4Smiod it under the terms of the GNU General Public License as published by 8*3d8817e4Smiod the Free Software Foundation; either version 2 of the License, or 9*3d8817e4Smiod (at your option) any later version. 10*3d8817e4Smiod 11*3d8817e4Smiod This program is distributed in the hope that it will be useful, 12*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of 13*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*3d8817e4Smiod GNU General Public License for more details. 15*3d8817e4Smiod 16*3d8817e4Smiod You should have received a copy of the GNU General Public License 17*3d8817e4Smiod along with this program; if not, write to the Free Software 18*3d8817e4Smiod Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 19*3d8817e4Smiod 20*3d8817e4Smiod #define DO_NOT_DEFINE_AOUTHDR 21*3d8817e4Smiod #define L_LNNO_SIZE 4 22*3d8817e4Smiod #include "coff/external.h" 23*3d8817e4Smiod 24*3d8817e4Smiod /* Magic numbers are defined in coff/ecoff.h. */ 25*3d8817e4Smiod #define MIPS_ECOFF_BADMAG(x) (((x).f_magic!=MIPS_MAGIC_1) && \ 26*3d8817e4Smiod ((x).f_magic!=MIPS_MAGIC_LITTLE) &&\ 27*3d8817e4Smiod ((x).f_magic!=MIPS_MAGIC_BIG) && \ 28*3d8817e4Smiod ((x).f_magic!=MIPS_MAGIC_LITTLE2) && \ 29*3d8817e4Smiod ((x).f_magic!=MIPS_MAGIC_BIG2) && \ 30*3d8817e4Smiod ((x).f_magic!=MIPS_MAGIC_LITTLE3) && \ 31*3d8817e4Smiod ((x).f_magic!=MIPS_MAGIC_BIG3)) 32*3d8817e4Smiod 33*3d8817e4Smiod 34*3d8817e4Smiod /********************** AOUT "OPTIONAL HEADER" **********************/ 35*3d8817e4Smiod 36*3d8817e4Smiod typedef struct external_aouthdr 37*3d8817e4Smiod { 38*3d8817e4Smiod unsigned char magic[2]; /* type of file */ 39*3d8817e4Smiod unsigned char vstamp[2]; /* version stamp */ 40*3d8817e4Smiod unsigned char tsize[4]; /* text size in bytes, padded to FW bdry*/ 41*3d8817e4Smiod unsigned char dsize[4]; /* initialized data " " */ 42*3d8817e4Smiod unsigned char bsize[4]; /* uninitialized data " " */ 43*3d8817e4Smiod unsigned char entry[4]; /* entry pt. */ 44*3d8817e4Smiod unsigned char text_start[4]; /* base of text used for this file */ 45*3d8817e4Smiod unsigned char data_start[4]; /* base of data used for this file */ 46*3d8817e4Smiod unsigned char bss_start[4]; /* base of bss used for this file */ 47*3d8817e4Smiod unsigned char gprmask[4]; /* ?? */ 48*3d8817e4Smiod unsigned char cprmask[4][4]; /* ?? */ 49*3d8817e4Smiod unsigned char gp_value[4]; /* value for gp register */ 50*3d8817e4Smiod } AOUTHDR; 51*3d8817e4Smiod 52*3d8817e4Smiod /* compute size of a header */ 53*3d8817e4Smiod 54*3d8817e4Smiod #define AOUTSZ 56 55*3d8817e4Smiod #define AOUTHDRSZ 56 56*3d8817e4Smiod 57*3d8817e4Smiod /********************** RELOCATION DIRECTIVES **********************/ 58*3d8817e4Smiod 59*3d8817e4Smiod struct external_reloc 60*3d8817e4Smiod { 61*3d8817e4Smiod unsigned char r_vaddr[4]; 62*3d8817e4Smiod unsigned char r_bits[4]; 63*3d8817e4Smiod }; 64*3d8817e4Smiod 65*3d8817e4Smiod #define RELOC struct external_reloc 66*3d8817e4Smiod #define RELSZ 8 67*3d8817e4Smiod 68*3d8817e4Smiod /* MIPS ECOFF uses a packed 8 byte format for relocs. These constants 69*3d8817e4Smiod are used to unpack the r_bits field. */ 70*3d8817e4Smiod 71*3d8817e4Smiod #define RELOC_BITS0_SYMNDX_SH_LEFT_BIG 16 72*3d8817e4Smiod #define RELOC_BITS0_SYMNDX_SH_LEFT_LITTLE 0 73*3d8817e4Smiod 74*3d8817e4Smiod #define RELOC_BITS1_SYMNDX_SH_LEFT_BIG 8 75*3d8817e4Smiod #define RELOC_BITS1_SYMNDX_SH_LEFT_LITTLE 8 76*3d8817e4Smiod 77*3d8817e4Smiod #define RELOC_BITS2_SYMNDX_SH_LEFT_BIG 0 78*3d8817e4Smiod #define RELOC_BITS2_SYMNDX_SH_LEFT_LITTLE 16 79*3d8817e4Smiod 80*3d8817e4Smiod /* Originally, ECOFF used four bits for the reloc type and had three 81*3d8817e4Smiod reserved bits. Irix 4 added another bit for the reloc type, which 82*3d8817e4Smiod was easy because it was big endian and one of the spare bits became 83*3d8817e4Smiod the new most significant bit. To make this also work for little 84*3d8817e4Smiod endian ECOFF, we need to wrap one of the reserved bits around to 85*3d8817e4Smiod become the most significant bit of the reloc type. */ 86*3d8817e4Smiod #define RELOC_BITS3_TYPE_BIG 0x3E 87*3d8817e4Smiod #define RELOC_BITS3_TYPE_SH_BIG 1 88*3d8817e4Smiod #define RELOC_BITS3_TYPE_LITTLE 0x78 89*3d8817e4Smiod #define RELOC_BITS3_TYPE_SH_LITTLE 3 90*3d8817e4Smiod #define RELOC_BITS3_TYPEHI_LITTLE 0x04 91*3d8817e4Smiod #define RELOC_BITS3_TYPEHI_SH_LITTLE 2 92*3d8817e4Smiod 93*3d8817e4Smiod #define RELOC_BITS3_EXTERN_BIG 0x01 94*3d8817e4Smiod #define RELOC_BITS3_EXTERN_LITTLE 0x80 95*3d8817e4Smiod 96*3d8817e4Smiod /* The r_type field in a reloc is one of the following values. I 97*3d8817e4Smiod don't know if any other values can appear. These seem to be all 98*3d8817e4Smiod that occur in the Ultrix 4.2 libraries. */ 99*3d8817e4Smiod #define MIPS_R_IGNORE 0 100*3d8817e4Smiod #define MIPS_R_REFHALF 1 101*3d8817e4Smiod #define MIPS_R_REFWORD 2 102*3d8817e4Smiod #define MIPS_R_JMPADDR 3 103*3d8817e4Smiod #define MIPS_R_REFHI 4 104*3d8817e4Smiod #define MIPS_R_REFLO 5 105*3d8817e4Smiod #define MIPS_R_GPREL 6 106*3d8817e4Smiod #define MIPS_R_LITERAL 7 107*3d8817e4Smiod 108*3d8817e4Smiod /* FIXME: This relocation is used (internally only) to represent branches 109*3d8817e4Smiod when assembling. It should never appear in output files, and 110*3d8817e4Smiod be removed. (It used to be used for embedded-PIC support.) */ 111*3d8817e4Smiod #define MIPS_R_PCREL16 12 112*3d8817e4Smiod 113*3d8817e4Smiod /********************** STABS **********************/ 114*3d8817e4Smiod 115*3d8817e4Smiod #define MIPS_IS_STAB ECOFF_IS_STAB 116*3d8817e4Smiod #define MIPS_MARK_STAB ECOFF_MARK_STAB 117*3d8817e4Smiod #define MIPS_UNMARK_STAB ECOFF_UNMARK_STAB 118*3d8817e4Smiod 119*3d8817e4Smiod /********************** SYMBOLIC INFORMATION **********************/ 120*3d8817e4Smiod 121*3d8817e4Smiod /* Written by John Gilmore. */ 122*3d8817e4Smiod 123*3d8817e4Smiod /* ECOFF uses COFF-like section structures, but its own symbol format. 124*3d8817e4Smiod This file defines the symbol format in fields whose size and alignment 125*3d8817e4Smiod will not vary on different host systems. */ 126*3d8817e4Smiod 127*3d8817e4Smiod /* File header as a set of bytes */ 128*3d8817e4Smiod 129*3d8817e4Smiod struct hdr_ext 130*3d8817e4Smiod { 131*3d8817e4Smiod unsigned char h_magic[2]; 132*3d8817e4Smiod unsigned char h_vstamp[2]; 133*3d8817e4Smiod unsigned char h_ilineMax[4]; 134*3d8817e4Smiod unsigned char h_cbLine[4]; 135*3d8817e4Smiod unsigned char h_cbLineOffset[4]; 136*3d8817e4Smiod unsigned char h_idnMax[4]; 137*3d8817e4Smiod unsigned char h_cbDnOffset[4]; 138*3d8817e4Smiod unsigned char h_ipdMax[4]; 139*3d8817e4Smiod unsigned char h_cbPdOffset[4]; 140*3d8817e4Smiod unsigned char h_isymMax[4]; 141*3d8817e4Smiod unsigned char h_cbSymOffset[4]; 142*3d8817e4Smiod unsigned char h_ioptMax[4]; 143*3d8817e4Smiod unsigned char h_cbOptOffset[4]; 144*3d8817e4Smiod unsigned char h_iauxMax[4]; 145*3d8817e4Smiod unsigned char h_cbAuxOffset[4]; 146*3d8817e4Smiod unsigned char h_issMax[4]; 147*3d8817e4Smiod unsigned char h_cbSsOffset[4]; 148*3d8817e4Smiod unsigned char h_issExtMax[4]; 149*3d8817e4Smiod unsigned char h_cbSsExtOffset[4]; 150*3d8817e4Smiod unsigned char h_ifdMax[4]; 151*3d8817e4Smiod unsigned char h_cbFdOffset[4]; 152*3d8817e4Smiod unsigned char h_crfd[4]; 153*3d8817e4Smiod unsigned char h_cbRfdOffset[4]; 154*3d8817e4Smiod unsigned char h_iextMax[4]; 155*3d8817e4Smiod unsigned char h_cbExtOffset[4]; 156*3d8817e4Smiod }; 157*3d8817e4Smiod 158*3d8817e4Smiod /* File descriptor external record */ 159*3d8817e4Smiod 160*3d8817e4Smiod struct fdr_ext 161*3d8817e4Smiod { 162*3d8817e4Smiod unsigned char f_adr[4]; 163*3d8817e4Smiod unsigned char f_rss[4]; 164*3d8817e4Smiod unsigned char f_issBase[4]; 165*3d8817e4Smiod unsigned char f_cbSs[4]; 166*3d8817e4Smiod unsigned char f_isymBase[4]; 167*3d8817e4Smiod unsigned char f_csym[4]; 168*3d8817e4Smiod unsigned char f_ilineBase[4]; 169*3d8817e4Smiod unsigned char f_cline[4]; 170*3d8817e4Smiod unsigned char f_ioptBase[4]; 171*3d8817e4Smiod unsigned char f_copt[4]; 172*3d8817e4Smiod unsigned char f_ipdFirst[2]; 173*3d8817e4Smiod unsigned char f_cpd[2]; 174*3d8817e4Smiod unsigned char f_iauxBase[4]; 175*3d8817e4Smiod unsigned char f_caux[4]; 176*3d8817e4Smiod unsigned char f_rfdBase[4]; 177*3d8817e4Smiod unsigned char f_crfd[4]; 178*3d8817e4Smiod unsigned char f_bits1[1]; 179*3d8817e4Smiod unsigned char f_bits2[3]; 180*3d8817e4Smiod unsigned char f_cbLineOffset[4]; 181*3d8817e4Smiod unsigned char f_cbLine[4]; 182*3d8817e4Smiod }; 183*3d8817e4Smiod 184*3d8817e4Smiod #define FDR_BITS1_LANG_BIG 0xF8 185*3d8817e4Smiod #define FDR_BITS1_LANG_SH_BIG 3 186*3d8817e4Smiod #define FDR_BITS1_LANG_LITTLE 0x1F 187*3d8817e4Smiod #define FDR_BITS1_LANG_SH_LITTLE 0 188*3d8817e4Smiod 189*3d8817e4Smiod #define FDR_BITS1_FMERGE_BIG 0x04 190*3d8817e4Smiod #define FDR_BITS1_FMERGE_LITTLE 0x20 191*3d8817e4Smiod 192*3d8817e4Smiod #define FDR_BITS1_FREADIN_BIG 0x02 193*3d8817e4Smiod #define FDR_BITS1_FREADIN_LITTLE 0x40 194*3d8817e4Smiod 195*3d8817e4Smiod #define FDR_BITS1_FBIGENDIAN_BIG 0x01 196*3d8817e4Smiod #define FDR_BITS1_FBIGENDIAN_LITTLE 0x80 197*3d8817e4Smiod 198*3d8817e4Smiod #define FDR_BITS2_GLEVEL_BIG 0xC0 199*3d8817e4Smiod #define FDR_BITS2_GLEVEL_SH_BIG 6 200*3d8817e4Smiod #define FDR_BITS2_GLEVEL_LITTLE 0x03 201*3d8817e4Smiod #define FDR_BITS2_GLEVEL_SH_LITTLE 0 202*3d8817e4Smiod 203*3d8817e4Smiod /* We ignore the `reserved' field in bits2. */ 204*3d8817e4Smiod 205*3d8817e4Smiod /* Procedure descriptor external record */ 206*3d8817e4Smiod 207*3d8817e4Smiod struct pdr_ext 208*3d8817e4Smiod { 209*3d8817e4Smiod unsigned char p_adr[4]; 210*3d8817e4Smiod unsigned char p_isym[4]; 211*3d8817e4Smiod unsigned char p_iline[4]; 212*3d8817e4Smiod unsigned char p_regmask[4]; 213*3d8817e4Smiod unsigned char p_regoffset[4]; 214*3d8817e4Smiod unsigned char p_iopt[4]; 215*3d8817e4Smiod unsigned char p_fregmask[4]; 216*3d8817e4Smiod unsigned char p_fregoffset[4]; 217*3d8817e4Smiod unsigned char p_frameoffset[4]; 218*3d8817e4Smiod unsigned char p_framereg[2]; 219*3d8817e4Smiod unsigned char p_pcreg[2]; 220*3d8817e4Smiod unsigned char p_lnLow[4]; 221*3d8817e4Smiod unsigned char p_lnHigh[4]; 222*3d8817e4Smiod unsigned char p_cbLineOffset[4]; 223*3d8817e4Smiod }; 224*3d8817e4Smiod 225*3d8817e4Smiod /* Runtime procedure table */ 226*3d8817e4Smiod 227*3d8817e4Smiod struct rpdr_ext 228*3d8817e4Smiod { 229*3d8817e4Smiod unsigned char p_adr[4]; 230*3d8817e4Smiod unsigned char p_regmask[4]; 231*3d8817e4Smiod unsigned char p_regoffset[4]; 232*3d8817e4Smiod unsigned char p_fregmask[4]; 233*3d8817e4Smiod unsigned char p_fregoffset[4]; 234*3d8817e4Smiod unsigned char p_frameoffset[4]; 235*3d8817e4Smiod unsigned char p_framereg[2]; 236*3d8817e4Smiod unsigned char p_pcreg[2]; 237*3d8817e4Smiod unsigned char p_irpss[4]; 238*3d8817e4Smiod unsigned char p_reserved[4]; 239*3d8817e4Smiod unsigned char p_exception_info[4]; 240*3d8817e4Smiod }; 241*3d8817e4Smiod 242*3d8817e4Smiod /* Line numbers */ 243*3d8817e4Smiod 244*3d8817e4Smiod struct line_ext 245*3d8817e4Smiod { 246*3d8817e4Smiod unsigned char l_line[4]; 247*3d8817e4Smiod }; 248*3d8817e4Smiod 249*3d8817e4Smiod /* Symbol external record */ 250*3d8817e4Smiod 251*3d8817e4Smiod struct sym_ext 252*3d8817e4Smiod { 253*3d8817e4Smiod unsigned char s_iss[4]; 254*3d8817e4Smiod unsigned char s_value[4]; 255*3d8817e4Smiod unsigned char s_bits1[1]; 256*3d8817e4Smiod unsigned char s_bits2[1]; 257*3d8817e4Smiod unsigned char s_bits3[1]; 258*3d8817e4Smiod unsigned char s_bits4[1]; 259*3d8817e4Smiod }; 260*3d8817e4Smiod 261*3d8817e4Smiod #define SYM_BITS1_ST_BIG 0xFC 262*3d8817e4Smiod #define SYM_BITS1_ST_SH_BIG 2 263*3d8817e4Smiod #define SYM_BITS1_ST_LITTLE 0x3F 264*3d8817e4Smiod #define SYM_BITS1_ST_SH_LITTLE 0 265*3d8817e4Smiod 266*3d8817e4Smiod #define SYM_BITS1_SC_BIG 0x03 267*3d8817e4Smiod #define SYM_BITS1_SC_SH_LEFT_BIG 3 268*3d8817e4Smiod #define SYM_BITS1_SC_LITTLE 0xC0 269*3d8817e4Smiod #define SYM_BITS1_SC_SH_LITTLE 6 270*3d8817e4Smiod 271*3d8817e4Smiod #define SYM_BITS2_SC_BIG 0xE0 272*3d8817e4Smiod #define SYM_BITS2_SC_SH_BIG 5 273*3d8817e4Smiod #define SYM_BITS2_SC_LITTLE 0x07 274*3d8817e4Smiod #define SYM_BITS2_SC_SH_LEFT_LITTLE 2 275*3d8817e4Smiod 276*3d8817e4Smiod #define SYM_BITS2_RESERVED_BIG 0x10 277*3d8817e4Smiod #define SYM_BITS2_RESERVED_LITTLE 0x08 278*3d8817e4Smiod 279*3d8817e4Smiod #define SYM_BITS2_INDEX_BIG 0x0F 280*3d8817e4Smiod #define SYM_BITS2_INDEX_SH_LEFT_BIG 16 281*3d8817e4Smiod #define SYM_BITS2_INDEX_LITTLE 0xF0 282*3d8817e4Smiod #define SYM_BITS2_INDEX_SH_LITTLE 4 283*3d8817e4Smiod 284*3d8817e4Smiod #define SYM_BITS3_INDEX_SH_LEFT_BIG 8 285*3d8817e4Smiod #define SYM_BITS3_INDEX_SH_LEFT_LITTLE 4 286*3d8817e4Smiod 287*3d8817e4Smiod #define SYM_BITS4_INDEX_SH_LEFT_BIG 0 288*3d8817e4Smiod #define SYM_BITS4_INDEX_SH_LEFT_LITTLE 12 289*3d8817e4Smiod 290*3d8817e4Smiod /* External symbol external record */ 291*3d8817e4Smiod 292*3d8817e4Smiod struct ext_ext 293*3d8817e4Smiod { 294*3d8817e4Smiod unsigned char es_bits1[1]; 295*3d8817e4Smiod unsigned char es_bits2[1]; 296*3d8817e4Smiod unsigned char es_ifd[2]; 297*3d8817e4Smiod struct sym_ext es_asym; 298*3d8817e4Smiod }; 299*3d8817e4Smiod 300*3d8817e4Smiod #define EXT_BITS1_JMPTBL_BIG 0x80 301*3d8817e4Smiod #define EXT_BITS1_JMPTBL_LITTLE 0x01 302*3d8817e4Smiod 303*3d8817e4Smiod #define EXT_BITS1_COBOL_MAIN_BIG 0x40 304*3d8817e4Smiod #define EXT_BITS1_COBOL_MAIN_LITTLE 0x02 305*3d8817e4Smiod 306*3d8817e4Smiod #define EXT_BITS1_WEAKEXT_BIG 0x20 307*3d8817e4Smiod #define EXT_BITS1_WEAKEXT_LITTLE 0x04 308*3d8817e4Smiod 309*3d8817e4Smiod /* Dense numbers external record */ 310*3d8817e4Smiod 311*3d8817e4Smiod struct dnr_ext 312*3d8817e4Smiod { 313*3d8817e4Smiod unsigned char d_rfd[4]; 314*3d8817e4Smiod unsigned char d_index[4]; 315*3d8817e4Smiod }; 316*3d8817e4Smiod 317*3d8817e4Smiod /* Relative file descriptor */ 318*3d8817e4Smiod 319*3d8817e4Smiod struct rfd_ext 320*3d8817e4Smiod { 321*3d8817e4Smiod unsigned char rfd[4]; 322*3d8817e4Smiod }; 323*3d8817e4Smiod 324*3d8817e4Smiod /* Optimizer symbol external record */ 325*3d8817e4Smiod 326*3d8817e4Smiod struct opt_ext 327*3d8817e4Smiod { 328*3d8817e4Smiod unsigned char o_bits1[1]; 329*3d8817e4Smiod unsigned char o_bits2[1]; 330*3d8817e4Smiod unsigned char o_bits3[1]; 331*3d8817e4Smiod unsigned char o_bits4[1]; 332*3d8817e4Smiod struct rndx_ext o_rndx; 333*3d8817e4Smiod unsigned char o_offset[4]; 334*3d8817e4Smiod }; 335*3d8817e4Smiod 336*3d8817e4Smiod #define OPT_BITS2_VALUE_SH_LEFT_BIG 16 337*3d8817e4Smiod #define OPT_BITS2_VALUE_SH_LEFT_LITTLE 0 338*3d8817e4Smiod 339*3d8817e4Smiod #define OPT_BITS3_VALUE_SH_LEFT_BIG 8 340*3d8817e4Smiod #define OPT_BITS3_VALUE_SH_LEFT_LITTLE 8 341*3d8817e4Smiod 342*3d8817e4Smiod #define OPT_BITS4_VALUE_SH_LEFT_BIG 0 343*3d8817e4Smiod #define OPT_BITS4_VALUE_SH_LEFT_LITTLE 16 344