1*5f210c2aSfgsch /* `a.out.adobe' differences from standard a.out files 2*5f210c2aSfgsch 3*5f210c2aSfgsch Copyright 2001 Free Software Foundation, Inc. 4*5f210c2aSfgsch 5*5f210c2aSfgsch This program is free software; you can redistribute it and/or modify 6*5f210c2aSfgsch it under the terms of the GNU General Public License as published by 7*5f210c2aSfgsch the Free Software Foundation; either version 2 of the License, or 8*5f210c2aSfgsch (at your option) any later version. 9*5f210c2aSfgsch 10*5f210c2aSfgsch This program is distributed in the hope that it will be useful, 11*5f210c2aSfgsch but WITHOUT ANY WARRANTY; without even the implied warranty of 12*5f210c2aSfgsch MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*5f210c2aSfgsch GNU General Public License for more details. 14*5f210c2aSfgsch 15*5f210c2aSfgsch You should have received a copy of the GNU General Public License 16*5f210c2aSfgsch along with this program; if not, write to the Free Software 17*5f210c2aSfgsch Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 182159047fSniklas 192159047fSniklas #ifndef __A_OUT_ADOBE_H__ 202159047fSniklas #define __A_OUT_ADOBE_H__ 212159047fSniklas 222159047fSniklas #define BYTES_IN_WORD 4 232159047fSniklas 242159047fSniklas /* Struct external_exec is the same. */ 252159047fSniklas 262159047fSniklas /* This is the layout on disk of the 32-bit or 64-bit exec header. */ 272159047fSniklas 282159047fSniklas struct external_exec 292159047fSniklas { 302159047fSniklas bfd_byte e_info[4]; /* magic number and stuff */ 312159047fSniklas bfd_byte e_text[BYTES_IN_WORD]; /* length of text section in bytes */ 322159047fSniklas bfd_byte e_data[BYTES_IN_WORD]; /* length of data section in bytes */ 332159047fSniklas bfd_byte e_bss[BYTES_IN_WORD]; /* length of bss area in bytes */ 342159047fSniklas bfd_byte e_syms[BYTES_IN_WORD]; /* length of symbol table in bytes */ 352159047fSniklas bfd_byte e_entry[BYTES_IN_WORD]; /* start address */ 362159047fSniklas bfd_byte e_trsize[BYTES_IN_WORD]; /* length of text relocation info */ 372159047fSniklas bfd_byte e_drsize[BYTES_IN_WORD]; /* length of data relocation info */ 382159047fSniklas }; 392159047fSniklas 402159047fSniklas #define EXEC_BYTES_SIZE (4 + BYTES_IN_WORD * 7) 412159047fSniklas 422159047fSniklas /* Magic numbers for a.out files */ 432159047fSniklas 442159047fSniklas #undef ZMAGIC 452159047fSniklas #define ZMAGIC 0xAD0BE /* Cute, eh? */ 462159047fSniklas #undef OMAGIC 472159047fSniklas #undef NMAGIC 482159047fSniklas 492159047fSniklas #define N_BADMAG(x) ((x).a_info != ZMAGIC) 502159047fSniklas 512159047fSniklas /* By default, segment size is constant. But some machines override this 522159047fSniklas to be a function of the a.out header (e.g. machine type). */ 532159047fSniklas #ifndef N_SEGSIZE 542159047fSniklas #define N_SEGSIZE(x) SEGMENT_SIZE 552159047fSniklas #endif 562159047fSniklas #undef N_SEGSIZE /* FIXMEXXXX */ 572159047fSniklas 582159047fSniklas /* Segment information for the a.out.Adobe format is specified after the 592159047fSniklas file header. It contains N segment descriptors, followed by one with 602159047fSniklas a type of zero. 612159047fSniklas 622159047fSniklas The actual text of the segments starts at N_TXTOFF in the file, 632159047fSniklas regardless of how many or how few segment headers there are. */ 642159047fSniklas 652159047fSniklas struct external_segdesc { 662159047fSniklas unsigned char e_type[1]; 672159047fSniklas unsigned char e_size[3]; 682159047fSniklas unsigned char e_virtbase[4]; 692159047fSniklas unsigned char e_filebase[4]; 702159047fSniklas }; 712159047fSniklas 722159047fSniklas struct internal_segdesc { 732159047fSniklas unsigned int a_type:8; /* Segment type N_TEXT, N_DATA, 0 */ 742159047fSniklas unsigned int a_size:24; /* Segment size */ 752159047fSniklas bfd_vma a_virtbase; /* Virtual address */ 762159047fSniklas unsigned int a_filebase; /* Base address in object file */ 772159047fSniklas }; 782159047fSniklas 792159047fSniklas #define N_TXTADDR(x) \ 802159047fSniklas 812159047fSniklas /* This is documented to be at 1024, but appears to really be at 2048. 822159047fSniklas FIXME?! */ 832159047fSniklas #define N_TXTOFF(x) 2048 842159047fSniklas 852159047fSniklas #define N_TXTSIZE(x) ((x).a_text) 862159047fSniklas 872159047fSniklas #define N_DATADDR(x) 882159047fSniklas 892159047fSniklas #define N_BSSADDR(x) 902159047fSniklas 912159047fSniklas /* Offsets of the various portions of the file after the text segment. */ 922159047fSniklas 932159047fSniklas #define N_DATOFF(x) ( N_TXTOFF(x) + N_TXTSIZE(x) ) 942159047fSniklas #define N_TRELOFF(x) ( N_DATOFF(x) + (x).a_data ) 952159047fSniklas #define N_DRELOFF(x) ( N_TRELOFF(x) + (x).a_trsize ) 962159047fSniklas #define N_SYMOFF(x) ( N_DRELOFF(x) + (x).a_drsize ) 972159047fSniklas #define N_STROFF(x) ( N_SYMOFF(x) + (x).a_syms ) 982159047fSniklas 992159047fSniklas /* Symbols */ 1002159047fSniklas struct external_nlist { 1012159047fSniklas bfd_byte e_strx[BYTES_IN_WORD]; /* index into string table of name */ 1022159047fSniklas bfd_byte e_type[1]; /* type of symbol */ 1032159047fSniklas bfd_byte e_other[1]; /* misc info (usually empty) */ 1042159047fSniklas bfd_byte e_desc[2]; /* description field */ 1052159047fSniklas bfd_byte e_value[BYTES_IN_WORD]; /* value of symbol */ 1062159047fSniklas }; 1072159047fSniklas 1082159047fSniklas #define EXTERNAL_NLIST_SIZE (BYTES_IN_WORD+4+BYTES_IN_WORD) 1092159047fSniklas 1102159047fSniklas struct internal_nlist { 1112159047fSniklas unsigned long n_strx; /* index into string table of name */ 1122159047fSniklas unsigned char n_type; /* type of symbol */ 1132159047fSniklas unsigned char n_other; /* misc info (usually empty) */ 1142159047fSniklas unsigned short n_desc; /* description field */ 1152159047fSniklas bfd_vma n_value; /* value of symbol */ 1162159047fSniklas }; 1172159047fSniklas 1182159047fSniklas /* The n_type field is the symbol type, containing: */ 1192159047fSniklas 1202159047fSniklas #define N_UNDF 0 /* Undefined symbol */ 1212159047fSniklas #define N_ABS 2 /* Absolute symbol -- defined at particular addr */ 1222159047fSniklas #define N_TEXT 4 /* Text sym -- defined at offset in text seg */ 1232159047fSniklas #define N_DATA 6 /* Data sym -- defined at offset in data seg */ 1242159047fSniklas #define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg */ 1252159047fSniklas #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink) */ 1262159047fSniklas #define N_FN 0x1f /* File name of .o file */ 1272159047fSniklas #define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh) */ 1282159047fSniklas /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT, 1292159047fSniklas N_DATA, or N_BSS. When the low-order bit of other types is set, 1302159047fSniklas (e.g. N_WARNING versus N_FN), they are two different types. */ 1312159047fSniklas #define N_EXT 1 /* External symbol (as opposed to local-to-this-file) */ 1322159047fSniklas #define N_TYPE 0x1e 1332159047fSniklas #define N_STAB 0xe0 /* If any of these bits are on, it's a debug symbol */ 1342159047fSniklas 1352159047fSniklas #define N_INDR 0x0a 1362159047fSniklas 1372159047fSniklas /* The following symbols refer to set elements. 1382159047fSniklas All the N_SET[ATDB] symbols with the same name form one set. 1392159047fSniklas Space is allocated for the set in the text section, and each set 1402159047fSniklas elements value is stored into one word of the space. 1412159047fSniklas The first word of the space is the length of the set (number of elements). 1422159047fSniklas 1432159047fSniklas The address of the set is made into an N_SETV symbol 1442159047fSniklas whose name is the same as the name of the set. 1452159047fSniklas This symbol acts like a N_DATA global symbol 1462159047fSniklas in that it can satisfy undefined external references. */ 1472159047fSniklas 1482159047fSniklas /* These appear as input to LD, in a .o file. */ 1492159047fSniklas #define N_SETA 0x14 /* Absolute set element symbol */ 1502159047fSniklas #define N_SETT 0x16 /* Text set element symbol */ 1512159047fSniklas #define N_SETD 0x18 /* Data set element symbol */ 1522159047fSniklas #define N_SETB 0x1A /* Bss set element symbol */ 1532159047fSniklas 1542159047fSniklas /* This is output from LD. */ 1552159047fSniklas #define N_SETV 0x1C /* Pointer to set vector in data area. */ 1562159047fSniklas 1572159047fSniklas /* Warning symbol. The text gives a warning message, the next symbol 1582159047fSniklas in the table will be undefined. When the symbol is referenced, the 1592159047fSniklas message is printed. */ 1602159047fSniklas 1612159047fSniklas #define N_WARNING 0x1e 1622159047fSniklas 1632159047fSniklas /* Relocations 1642159047fSniklas 1652159047fSniklas There are two types of relocation flavours for a.out systems, 1662159047fSniklas standard and extended. The standard form is used on systems where the 1672159047fSniklas instruction has room for all the bits of an offset to the operand, whilst 1682159047fSniklas the extended form is used when an address operand has to be split over n 1692159047fSniklas instructions. Eg, on the 68k, each move instruction can reference 1702159047fSniklas the target with a displacement of 16 or 32 bits. On the sparc, move 1712159047fSniklas instructions use an offset of 14 bits, so the offset is stored in 1722159047fSniklas the reloc field, and the data in the section is ignored. 1732159047fSniklas */ 1742159047fSniklas 1752159047fSniklas /* This structure describes a single relocation to be performed. 1762159047fSniklas The text-relocation section of the file is a vector of these structures, 1772159047fSniklas all of which apply to the text section. 1782159047fSniklas Likewise, the data-relocation section applies to the data section. */ 1792159047fSniklas 1802159047fSniklas struct reloc_std_external { 1812159047fSniklas bfd_byte r_address[BYTES_IN_WORD]; /* offset of of data to relocate */ 1822159047fSniklas bfd_byte r_index[3]; /* symbol table index of symbol */ 1832159047fSniklas bfd_byte r_type[1]; /* relocation type */ 1842159047fSniklas }; 1852159047fSniklas 1862159047fSniklas #define RELOC_STD_BITS_PCREL_BIG 0x80 1872159047fSniklas #define RELOC_STD_BITS_PCREL_LITTLE 0x01 1882159047fSniklas 1892159047fSniklas #define RELOC_STD_BITS_LENGTH_BIG 0x60 1902159047fSniklas #define RELOC_STD_BITS_LENGTH_SH_BIG 5 /* To shift to units place */ 1912159047fSniklas #define RELOC_STD_BITS_LENGTH_LITTLE 0x06 1922159047fSniklas #define RELOC_STD_BITS_LENGTH_SH_LITTLE 1 1932159047fSniklas 1942159047fSniklas #define RELOC_STD_BITS_EXTERN_BIG 0x10 1952159047fSniklas #define RELOC_STD_BITS_EXTERN_LITTLE 0x08 1962159047fSniklas 1972159047fSniklas #define RELOC_STD_BITS_BASEREL_BIG 0x08 1982159047fSniklas #define RELOC_STD_BITS_BASEREL_LITTLE 0x08 1992159047fSniklas 2002159047fSniklas #define RELOC_STD_BITS_JMPTABLE_BIG 0x04 2012159047fSniklas #define RELOC_STD_BITS_JMPTABLE_LITTLE 0x04 2022159047fSniklas 2032159047fSniklas #define RELOC_STD_BITS_RELATIVE_BIG 0x02 2042159047fSniklas #define RELOC_STD_BITS_RELATIVE_LITTLE 0x02 2052159047fSniklas 2062159047fSniklas #define RELOC_STD_SIZE (BYTES_IN_WORD + 3 + 1) /* Bytes per relocation entry */ 2072159047fSniklas 2082159047fSniklas struct reloc_std_internal 2092159047fSniklas { 2102159047fSniklas bfd_vma r_address; /* Address (within segment) to be relocated. */ 2112159047fSniklas /* The meaning of r_symbolnum depends on r_extern. */ 2122159047fSniklas unsigned int r_symbolnum:24; 2132159047fSniklas /* Nonzero means value is a pc-relative offset 2142159047fSniklas and it should be relocated for changes in its own address 2152159047fSniklas as well as for changes in the symbol or section specified. */ 2162159047fSniklas unsigned int r_pcrel:1; 2172159047fSniklas /* Length (as exponent of 2) of the field to be relocated. 2182159047fSniklas Thus, a value of 2 indicates 1<<2 bytes. */ 2192159047fSniklas unsigned int r_length:2; 2202159047fSniklas /* 1 => relocate with value of symbol. 2212159047fSniklas r_symbolnum is the index of the symbol 2222159047fSniklas in files the symbol table. 2232159047fSniklas 0 => relocate with the address of a segment. 2242159047fSniklas r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS 2252159047fSniklas (the N_EXT bit may be set also, but signifies nothing). */ 2262159047fSniklas unsigned int r_extern:1; 2272159047fSniklas /* The next three bits are for SunOS shared libraries, and seem to 2282159047fSniklas be undocumented. */ 2292159047fSniklas unsigned int r_baserel:1; /* Linkage table relative */ 2302159047fSniklas unsigned int r_jmptable:1; /* pc-relative to jump table */ 2312159047fSniklas unsigned int r_relative:1; /* "relative relocation" */ 2322159047fSniklas /* unused */ 2332159047fSniklas unsigned int r_pad:1; /* Padding -- set to zero */ 2342159047fSniklas }; 2352159047fSniklas 2362159047fSniklas 2372159047fSniklas /* EXTENDED RELOCS */ 2382159047fSniklas 2392159047fSniklas struct reloc_ext_external { 2402159047fSniklas bfd_byte r_address[BYTES_IN_WORD]; /* offset of of data to relocate */ 2412159047fSniklas bfd_byte r_index[3]; /* symbol table index of symbol */ 2422159047fSniklas bfd_byte r_type[1]; /* relocation type */ 2432159047fSniklas bfd_byte r_addend[BYTES_IN_WORD]; /* datum addend */ 2442159047fSniklas }; 2452159047fSniklas 2462159047fSniklas #define RELOC_EXT_BITS_EXTERN_BIG 0x80 2472159047fSniklas #define RELOC_EXT_BITS_EXTERN_LITTLE 0x01 2482159047fSniklas 2492159047fSniklas #define RELOC_EXT_BITS_TYPE_BIG 0x1F 2502159047fSniklas #define RELOC_EXT_BITS_TYPE_SH_BIG 0 2512159047fSniklas #define RELOC_EXT_BITS_TYPE_LITTLE 0xF8 2522159047fSniklas #define RELOC_EXT_BITS_TYPE_SH_LITTLE 3 2532159047fSniklas 2542159047fSniklas /* Bytes per relocation entry */ 2552159047fSniklas #define RELOC_EXT_SIZE (BYTES_IN_WORD + 3 + 1 + BYTES_IN_WORD) 2562159047fSniklas 2572159047fSniklas enum reloc_type 2582159047fSniklas { 2592159047fSniklas /* simple relocations */ 2602159047fSniklas RELOC_8, /* data[0:7] = addend + sv */ 2612159047fSniklas RELOC_16, /* data[0:15] = addend + sv */ 2622159047fSniklas RELOC_32, /* data[0:31] = addend + sv */ 2632159047fSniklas /* pc-rel displacement */ 2642159047fSniklas RELOC_DISP8, /* data[0:7] = addend - pc + sv */ 2652159047fSniklas RELOC_DISP16, /* data[0:15] = addend - pc + sv */ 2662159047fSniklas RELOC_DISP32, /* data[0:31] = addend - pc + sv */ 2672159047fSniklas /* Special */ 2682159047fSniklas RELOC_WDISP30, /* data[0:29] = (addend + sv - pc)>>2 */ 2692159047fSniklas RELOC_WDISP22, /* data[0:21] = (addend + sv - pc)>>2 */ 2702159047fSniklas RELOC_HI22, /* data[0:21] = (addend + sv)>>10 */ 2712159047fSniklas RELOC_22, /* data[0:21] = (addend + sv) */ 2722159047fSniklas RELOC_13, /* data[0:12] = (addend + sv) */ 2732159047fSniklas RELOC_LO10, /* data[0:9] = (addend + sv) */ 2742159047fSniklas RELOC_SFA_BASE, 2752159047fSniklas RELOC_SFA_OFF13, 2762159047fSniklas /* P.I.C. (base-relative) */ 2772159047fSniklas RELOC_BASE10, /* Not sure - maybe we can do this the */ 2782159047fSniklas RELOC_BASE13, /* right way now */ 2792159047fSniklas RELOC_BASE22, 2802159047fSniklas /* for some sort of pc-rel P.I.C. (?) */ 2812159047fSniklas RELOC_PC10, 2822159047fSniklas RELOC_PC22, 2832159047fSniklas /* P.I.C. jump table */ 2842159047fSniklas RELOC_JMP_TBL, 2852159047fSniklas /* reputedly for shared libraries somehow */ 2862159047fSniklas RELOC_SEGOFF16, 2872159047fSniklas RELOC_GLOB_DAT, 2882159047fSniklas RELOC_JMP_SLOT, 2892159047fSniklas RELOC_RELATIVE, 2902159047fSniklas 2912159047fSniklas RELOC_11, 2922159047fSniklas RELOC_WDISP2_14, 2932159047fSniklas RELOC_WDISP19, 2942159047fSniklas RELOC_HHI22, /* data[0:21] = (addend + sv) >> 42 */ 2952159047fSniklas RELOC_HLO10, /* data[0:9] = (addend + sv) >> 32 */ 2962159047fSniklas 2972159047fSniklas /* 29K relocation types */ 2982159047fSniklas RELOC_JUMPTARG, 2992159047fSniklas RELOC_CONST, 3002159047fSniklas RELOC_CONSTH, 3012159047fSniklas 3022159047fSniklas NO_RELOC 3032159047fSniklas }; 3042159047fSniklas 3052159047fSniklas 3062159047fSniklas struct reloc_internal { 3072159047fSniklas bfd_vma r_address; /* offset of of data to relocate */ 3082159047fSniklas long r_index; /* symbol table index of symbol */ 3092159047fSniklas enum reloc_type r_type; /* relocation type */ 3102159047fSniklas bfd_vma r_addend; /* datum addend */ 3112159047fSniklas }; 3122159047fSniklas 3132159047fSniklas #endif /* __A_OUT_ADOBE_H__ */ 314