Home | History | Annotate | Download | only in aout
      1 /* `a.out.adobe' differences from standard a.out files
      2 
      3    Copyright (C) 2001-2016 Free Software Foundation, Inc.
      4 
      5    This program is free software; you can redistribute it and/or modify
      6    it under the terms of the GNU General Public License as published by
      7    the Free Software Foundation; either version 3 of the License, or
      8    (at your option) any later version.
      9 
     10    This program is distributed in the hope that it will be useful,
     11    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13    GNU General Public License for more details.
     14 
     15    You should have received a copy of the GNU General Public License
     16    along with this program; if not, write to the Free Software
     17    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     18    MA 02110-1301, USA.  */
     19 
     20 #ifndef __A_OUT_ADOBE_H__
     21 #define __A_OUT_ADOBE_H__
     22 
     23 #define	BYTES_IN_WORD	4
     24 
     25 /* Struct external_exec is the same.  */
     26 
     27 /* This is the layout on disk of the 32-bit or 64-bit exec header. */
     28 
     29 struct external_exec
     30 {
     31   bfd_byte e_info[4];		/* magic number and stuff		*/
     32   bfd_byte e_text[BYTES_IN_WORD]; /* length of text section in bytes	*/
     33   bfd_byte e_data[BYTES_IN_WORD]; /* length of data section in bytes	*/
     34   bfd_byte e_bss[BYTES_IN_WORD]; /* length of bss area in bytes 	*/
     35   bfd_byte e_syms[BYTES_IN_WORD]; /* length of symbol table in bytes 	*/
     36   bfd_byte e_entry[BYTES_IN_WORD]; /* start address 			*/
     37   bfd_byte e_trsize[BYTES_IN_WORD]; /* length of text relocation info	*/
     38   bfd_byte e_drsize[BYTES_IN_WORD]; /* length of data relocation info 	*/
     39 };
     40 
     41 #define	EXEC_BYTES_SIZE	(4 + BYTES_IN_WORD * 7)
     42 
     43 /* Magic numbers for a.out files */
     44 
     45 #undef	ZMAGIC
     46 #define	ZMAGIC	0xAD0BE		/* Cute, eh?  */
     47 #undef	OMAGIC
     48 #undef	NMAGIC
     49 
     50 #define N_BADMAG(x)	  ((x)->a_info != ZMAGIC)
     51 
     52 /* By default, segment size is constant.  But some machines override this
     53    to be a function of the a.out header (e.g. machine type).  */
     54 #ifndef	N_SEGSIZE
     55 #define	N_SEGSIZE(x)	SEGMENT_SIZE
     56 #endif
     57 #undef N_SEGSIZE   /* FIXMEXXXX */
     58 
     59 /* Segment information for the a.out.Adobe format is specified after the
     60    file header.  It contains N segment descriptors, followed by one with
     61    a type of zero.
     62 
     63    The actual text of the segments starts at N_TXTOFF in the file,
     64    regardless of how many or how few segment headers there are.  */
     65 
     66 struct external_segdesc {
     67 	unsigned char e_type[1];
     68 	unsigned char e_size[3];
     69 	unsigned char e_virtbase[4];
     70 	unsigned char e_filebase[4];
     71 };
     72 
     73 struct internal_segdesc {
     74 	unsigned int	a_type:8;	/* Segment type N_TEXT, N_DATA, 0 */
     75 	unsigned int 	a_size:24;	/* Segment size */
     76 	bfd_vma		a_virtbase;	/* Virtual address */
     77 	unsigned int	a_filebase;	/* Base address in object file */
     78 };
     79 
     80 #define N_TXTADDR(x) is_this_really_unused?
     81 
     82 /* This is documented to be at 1024, but appears to really be at 2048.
     83    FIXME?!  */
     84 #define N_TXTOFF(x)	2048
     85 
     86 #define	N_TXTSIZE(x) ((x)->a_text)
     87 
     88 #define N_DATADDR(x) is_this_really_unused?
     89 
     90 #define N_BSSADDR(x) is_this_really_unused?
     91 
     92 /* Offsets of the various portions of the file after the text segment.  */
     93 
     94 #define N_DATOFF(x)	( N_TXTOFF(x) + N_TXTSIZE(x) )
     95 #define N_TRELOFF(x)	( N_DATOFF(x) + (x)->a_data )
     96 #define N_DRELOFF(x)	( N_TRELOFF(x) + (x)->a_trsize )
     97 #define N_SYMOFF(x)	( N_DRELOFF(x) + (x)->a_drsize )
     98 #define N_STROFF(x)	( N_SYMOFF(x) + (x)->a_syms )
     99 
    100 /* Symbols */
    102 struct external_nlist {
    103   bfd_byte e_strx[BYTES_IN_WORD];	/* index into string table of name */
    104   bfd_byte e_type[1];			/* type of symbol */
    105   bfd_byte e_other[1];			/* misc info (usually empty) */
    106   bfd_byte e_desc[2];			/* description field */
    107   bfd_byte e_value[BYTES_IN_WORD];	/* value of symbol */
    108 };
    109 
    110 #define EXTERNAL_NLIST_SIZE (BYTES_IN_WORD+4+BYTES_IN_WORD)
    111 
    112 struct internal_nlist {
    113   unsigned long n_strx;			/* index into string table of name */
    114   unsigned char n_type;			/* type of symbol */
    115   unsigned char n_other;		/* misc info (usually empty) */
    116   unsigned short n_desc;		/* description field */
    117   bfd_vma n_value;			/* value of symbol */
    118 };
    119 
    120 /* The n_type field is the symbol type, containing:  */
    121 
    122 #define N_UNDF	0	/* Undefined symbol */
    123 #define N_ABS 	2	/* Absolute symbol -- defined at particular addr */
    124 #define N_TEXT 	4	/* Text sym -- defined at offset in text seg */
    125 #define N_DATA 	6	/* Data sym -- defined at offset in data seg */
    126 #define N_BSS 	8	/* BSS  sym -- defined at offset in zero'd seg */
    127 #define	N_COMM	0x12	/* Common symbol (visible after shared lib dynlink) */
    128 #define N_FN	0x1f	/* File name of .o file */
    129 #define	N_FN_SEQ 0x0C	/* N_FN from Sequent compilers (sigh) */
    130 /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
    131    N_DATA, or N_BSS.  When the low-order bit of other types is set,
    132    (e.g. N_WARNING versus N_FN), they are two different types.  */
    133 #define N_EXT 	1	/* External symbol (as opposed to local-to-this-file) */
    134 #define N_TYPE  0x1e
    135 #define N_STAB 	0xe0	/* If any of these bits are on, it's a debug symbol */
    136 
    137 #define N_INDR 0x0a
    138 
    139 /* The following symbols refer to set elements.
    140    All the N_SET[ATDB] symbols with the same name form one set.
    141    Space is allocated for the set in the text section, and each set
    142    elements value is stored into one word of the space.
    143    The first word of the space is the length of the set (number of elements).
    144 
    145    The address of the set is made into an N_SETV symbol
    146    whose name is the same as the name of the set.
    147    This symbol acts like a N_DATA global symbol
    148    in that it can satisfy undefined external references.  */
    149 
    150 /* These appear as input to LD, in a .o file.  */
    151 #define	N_SETA	0x14		/* Absolute set element symbol */
    152 #define	N_SETT	0x16		/* Text set element symbol */
    153 #define	N_SETD	0x18		/* Data set element symbol */
    154 #define	N_SETB	0x1A		/* Bss set element symbol */
    155 
    156 /* This is output from LD.  */
    157 #define N_SETV	0x1C		/* Pointer to set vector in data area.  */
    158 
    159 /* Warning symbol. The text gives a warning message, the next symbol
    160    in the table will be undefined. When the symbol is referenced, the
    161    message is printed.  */
    162 
    163 #define	N_WARNING 0x1e
    164 
    165 /* Relocations
    166 
    167   There	are two types of relocation flavours for a.out systems,
    168   standard and extended. The standard form is used on systems where the
    169   instruction has room for all the bits of an offset to the operand, whilst
    170   the extended form is used when an address operand has to be split over n
    171   instructions. Eg, on the 68k, each move instruction can reference
    172   the target with a displacement of 16 or 32 bits. On the sparc, move
    173   instructions use an offset of 14 bits, so the offset is stored in
    174   the reloc field, and the data in the section is ignored.
    175 */
    176 
    177 /* This structure describes a single relocation to be performed.
    178    The text-relocation section of the file is a vector of these structures,
    179    all of which apply to the text section.
    180    Likewise, the data-relocation section applies to the data section.  */
    181 
    182 struct reloc_std_external {
    183   bfd_byte r_address[BYTES_IN_WORD];	/* offset of of data to relocate */
    184   bfd_byte r_index[3];	/* symbol table index of symbol 	*/
    185   bfd_byte r_type[1];	/* relocation type			*/
    186 };
    187 
    188 #define	RELOC_STD_BITS_PCREL_BIG	0x80
    189 #define	RELOC_STD_BITS_PCREL_LITTLE	0x01
    190 
    191 #define	RELOC_STD_BITS_LENGTH_BIG	0x60
    192 #define	RELOC_STD_BITS_LENGTH_SH_BIG	5	/* To shift to units place */
    193 #define	RELOC_STD_BITS_LENGTH_LITTLE	0x06
    194 #define	RELOC_STD_BITS_LENGTH_SH_LITTLE	1
    195 
    196 #define	RELOC_STD_BITS_EXTERN_BIG	0x10
    197 #define	RELOC_STD_BITS_EXTERN_LITTLE	0x08
    198 
    199 #define	RELOC_STD_BITS_BASEREL_BIG	0x08
    200 #define	RELOC_STD_BITS_BASEREL_LITTLE	0x08
    201 
    202 #define	RELOC_STD_BITS_JMPTABLE_BIG	0x04
    203 #define	RELOC_STD_BITS_JMPTABLE_LITTLE	0x04
    204 
    205 #define	RELOC_STD_BITS_RELATIVE_BIG	0x02
    206 #define	RELOC_STD_BITS_RELATIVE_LITTLE	0x02
    207 
    208 #define	RELOC_STD_SIZE	(BYTES_IN_WORD + 3 + 1)		/* Bytes per relocation entry */
    209 
    210 struct reloc_std_internal
    211 {
    212   bfd_vma r_address;		/* Address (within segment) to be relocated.  */
    213   /* The meaning of r_symbolnum depends on r_extern.  */
    214   unsigned int r_symbolnum:24;
    215   /* Nonzero means value is a pc-relative offset
    216      and it should be relocated for changes in its own address
    217      as well as for changes in the symbol or section specified.  */
    218   unsigned int r_pcrel:1;
    219   /* Length (as exponent of 2) of the field to be relocated.
    220      Thus, a value of 2 indicates 1<<2 bytes.  */
    221   unsigned int r_length:2;
    222   /* 1 => relocate with value of symbol.
    223      r_symbolnum is the index of the symbol
    224      in files the symbol table.
    225      0 => relocate with the address of a segment.
    226      r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
    227      (the N_EXT bit may be set also, but signifies nothing).  */
    228   unsigned int r_extern:1;
    229   /* The next three bits are for SunOS shared libraries, and seem to
    230      be undocumented.  */
    231   unsigned int r_baserel:1;	/* Linkage table relative */
    232   unsigned int r_jmptable:1;	/* pc-relative to jump table */
    233   unsigned int r_relative:1;	/* "relative relocation" */
    234   /* unused */
    235   unsigned int r_pad:1;		/* Padding -- set to zero */
    236 };
    237 
    238 
    239 /* EXTENDED RELOCS  */
    240 
    241 struct reloc_ext_external {
    242   bfd_byte r_address[BYTES_IN_WORD];	/* offset of of data to relocate 	*/
    243   bfd_byte r_index[3];	/* symbol table index of symbol 	*/
    244   bfd_byte r_type[1];	/* relocation type			*/
    245   bfd_byte r_addend[BYTES_IN_WORD];	/* datum addend				*/
    246 };
    247 
    248 #define	RELOC_EXT_BITS_EXTERN_BIG	0x80
    249 #define	RELOC_EXT_BITS_EXTERN_LITTLE	0x01
    250 
    251 #define	RELOC_EXT_BITS_TYPE_BIG		0x1F
    252 #define	RELOC_EXT_BITS_TYPE_SH_BIG	0
    253 #define	RELOC_EXT_BITS_TYPE_LITTLE	0xF8
    254 #define	RELOC_EXT_BITS_TYPE_SH_LITTLE	3
    255 
    256 /* Bytes per relocation entry */
    257 #define	RELOC_EXT_SIZE	(BYTES_IN_WORD + 3 + 1 + BYTES_IN_WORD)
    258 
    259 enum reloc_type
    260 {
    261   /* simple relocations */
    262   RELOC_8,			/* data[0:7] = addend + sv 		*/
    263   RELOC_16,			/* data[0:15] = addend + sv 		*/
    264   RELOC_32,			/* data[0:31] = addend + sv 		*/
    265   /* pc-rel displacement */
    266   RELOC_DISP8,			/* data[0:7] = addend - pc + sv 	*/
    267   RELOC_DISP16,			/* data[0:15] = addend - pc + sv 	*/
    268   RELOC_DISP32,			/* data[0:31] = addend - pc + sv 	*/
    269   /* Special */
    270   RELOC_WDISP30,		/* data[0:29] = (addend + sv - pc)>>2 	*/
    271   RELOC_WDISP22,		/* data[0:21] = (addend + sv - pc)>>2 	*/
    272   RELOC_HI22,			/* data[0:21] = (addend + sv)>>10 	*/
    273   RELOC_22,			/* data[0:21] = (addend + sv) 		*/
    274   RELOC_13,			/* data[0:12] = (addend + sv)		*/
    275   RELOC_LO10,			/* data[0:9] = (addend + sv)		*/
    276   RELOC_SFA_BASE,
    277   RELOC_SFA_OFF13,
    278   /* P.I.C. (base-relative) */
    279   RELOC_BASE10,  		/* Not sure - maybe we can do this the */
    280   RELOC_BASE13,			/* right way now */
    281   RELOC_BASE22,
    282   /* for some sort of pc-rel P.I.C. (?) */
    283   RELOC_PC10,
    284   RELOC_PC22,
    285   /* P.I.C. jump table */
    286   RELOC_JMP_TBL,
    287   /* reputedly for shared libraries somehow */
    288   RELOC_SEGOFF16,
    289   RELOC_GLOB_DAT,
    290   RELOC_JMP_SLOT,
    291   RELOC_RELATIVE,
    292 
    293   RELOC_11,
    294   RELOC_WDISP2_14,
    295   RELOC_WDISP19,
    296   RELOC_HHI22,			/* data[0:21] = (addend + sv) >> 42     */
    297   RELOC_HLO10,			/* data[0:9] = (addend + sv) >> 32      */
    298 
    299   /* 29K relocation types */
    300   RELOC_JUMPTARG,
    301   RELOC_CONST,
    302   RELOC_CONSTH,
    303 
    304   NO_RELOC
    305   };
    306 
    307 
    308 struct reloc_internal {
    309   bfd_vma r_address;		/* offset of of data to relocate 	*/
    310   long	r_index;		/* symbol table index of symbol 	*/
    311   enum reloc_type r_type;	/* relocation type			*/
    312   bfd_vma r_addend;		/* datum addend				*/
    313 };
    314 
    315 #endif				/* __A_OUT_ADOBE_H__ */
    316