home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / gas / config / aout_gnu.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  14KB  |  456 lines

  1. /* This file is aout_gnu.h
  2.  
  3.    Copyright (C) 1987-1992 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GAS, the GNU Assembler.
  6.  
  7.    GAS is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 2, or (at your option)
  10.    any later version.
  11.  
  12.    GAS is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with GAS; see the file COPYING.  If not, write to
  19.    the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  20.  
  21. #ifndef __A_OUT_GNU_H__
  22. #define __A_OUT_GNU_H__
  23.  
  24. /* There are two main flavours of a.out, one which uses the standard
  25.    relocations, and one which uses extended relocations.
  26.  
  27.    Today, the extended reloc uses are
  28.    TC_SPARC, TC_A29K
  29.  
  30.    each must define the enum reloc_type
  31.  
  32. */
  33.  
  34. #define USE_EXTENDED_RELOC (defined(TC_SPARC) || defined(TC_A29K))
  35.  
  36. #if defined(TC_SPARC) || defined(TC_A29K)
  37. enum reloc_type
  38.   {
  39.     RELOC_8, RELOC_16, RELOC_32,/* simple relocations */
  40.     RELOC_DISP8, RELOC_DISP16, RELOC_DISP32,    /* pc-rel displacement */
  41.     RELOC_WDISP30, RELOC_WDISP22,
  42.     RELOC_HI22, RELOC_22,
  43.     RELOC_13, RELOC_LO10,
  44.     RELOC_SFA_BASE, RELOC_SFA_OFF13,
  45.     RELOC_BASE10, RELOC_BASE13, RELOC_BASE22,    /* P.I.C. (base-relative) */
  46.     RELOC_PC10, RELOC_PC22,    /* for some sort of pc-rel P.I.C. (?) */
  47.     RELOC_JMP_TBL,        /* P.I.C. jump table */
  48.     RELOC_SEGOFF16,        /* reputedly for shared libraries somehow */
  49.     RELOC_GLOB_DAT, RELOC_JMP_SLOT, RELOC_RELATIVE,
  50.     RELOC_10, RELOC_11,
  51.     RELOC_WDISP2_14,
  52.     RELOC_WDISP19,
  53.     RELOC_HHI22,
  54.     RELOC_HLO10,
  55.  
  56.     /* 29K relocation types */
  57.     RELOC_JUMPTARG, RELOC_CONST, RELOC_CONSTH,
  58.  
  59.     RELOC_WDISP14, RELOC_WDISP21,
  60.  
  61.     NO_RELOC
  62.   };
  63.  
  64. #endif /* TC_SPARC or TC_A29K */
  65.  
  66.  
  67. #define __GNU_EXEC_MACROS__
  68.  
  69. #ifndef __STRUCT_EXEC_OVERRIDE__
  70.  
  71. /* This is the layout on disk of a Unix V7, Berkeley, SunOS, Vax Ultrix
  72.    "struct exec".  Don't assume that on this machine, the "struct exec"
  73.    will lay out the same sizes or alignments.  */
  74.  
  75. struct exec_bytes
  76.   {
  77.     unsigned char a_info[4];
  78.     unsigned char a_text[4];
  79.     unsigned char a_data[4];
  80.     unsigned char a_bss[4];
  81.     unsigned char a_syms[4];
  82.     unsigned char a_entry[4];
  83.     unsigned char a_trsize[4];
  84.     unsigned char a_drsize[4];
  85.   };
  86.  
  87. /* How big the "struct exec" is on disk */
  88. #define    EXEC_BYTES_SIZE    (8 * 4)
  89.  
  90. /* This is the layout in memory of a "struct exec" while we process it.  */
  91.  
  92. struct exec
  93. {
  94.   unsigned long a_info;        /* Use macros N_MAGIC, etc for access */
  95.   unsigned a_text;        /* length of text, in bytes */
  96.   unsigned a_data;        /* length of data, in bytes */
  97.   unsigned a_bss;        /* length of uninitialized data area for file, in bytes */
  98.   unsigned a_syms;        /* length of symbol table data in file, in bytes */
  99.   unsigned a_entry;        /* start address */
  100.   unsigned a_trsize;        /* length of relocation info for text, in bytes */
  101.   unsigned a_drsize;        /* length of relocation info for data, in bytes */
  102. };
  103.  
  104. #endif /* __STRUCT_EXEC_OVERRIDE__ */
  105.  
  106. /* these go in the N_MACHTYPE field */
  107. /* These symbols could be defined by code from Suns...punt 'em */
  108. #undef M_UNKNOWN
  109. #undef M_68010
  110. #undef M_68020
  111. #undef M_SPARC
  112. enum machine_type
  113.   {
  114.     M_UNKNOWN = 0,
  115.     M_68010 = 1,
  116.     M_68020 = 2,
  117.     M_SPARC = 3,
  118.     /* skip a bunch so we don't run into any of sun's numbers */
  119.     M_386 = 100,
  120.     M_29K = 101,
  121.     M_RS6000 = 102,        /* IBM RS/6000 */
  122.     /* HP/BSD formats */
  123.     M_HP200 = 200,        /* hp200 (68010) BSD binary */
  124.     M_HP300 = 300,        /* hp300 (68020+68881) BSD binary */
  125.     M_HPUX23 = 0x020C        /* hp200/300 HPUX binary */
  126.   };
  127.  
  128. #define N_MAGIC(exec) ((exec).a_info & 0xffff)
  129. #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
  130. #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
  131. #define N_SET_INFO(exec, magic, type, flags) \
  132.     ((exec).a_info = ((magic) & 0xffff) \
  133.      | (((int)(type) & 0xff) << 16) \
  134.      | (((flags) & 0xff) << 24))
  135. #define N_SET_MAGIC(exec, magic) \
  136.     ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
  137.  
  138. #define N_SET_MACHTYPE(exec, machtype) \
  139.     ((exec).a_info = \
  140.      ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
  141.  
  142. #define N_SET_FLAGS(exec, flags) \
  143.     ((exec).a_info = \
  144.      ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
  145.  
  146. /* Code indicating object file or impure executable.  */
  147. #ifndef OMAGIC
  148. #define OMAGIC 0407
  149. #endif
  150. /* Code indicating pure executable.  */
  151. #define NMAGIC 0410
  152. /* Code indicating demand-paged executable.  */
  153. #define ZMAGIC 0413
  154.  
  155. /* Virtual Address of text segment from the a.out file.  For OMAGIC,
  156.    (almost always "unlinked .o's" these days), should be zero.
  157.    For linked files, should reflect reality if we know it.  */
  158.  
  159. #ifndef N_TXTADDR
  160. #define N_TXTADDR(x)    (N_MAGIC(x)==OMAGIC? 0 : TEXT_START_ADDR)
  161. #endif
  162.  
  163. #ifndef N_BADMAG
  164. #define N_BADMAG(x)      (N_MAGIC(x) != OMAGIC        \
  165.                && N_MAGIC(x) != NMAGIC        \
  166.                && N_MAGIC(x) != ZMAGIC)
  167. #endif
  168.  
  169. /* By default, segment size is constant.  But on some machines, it can
  170.    be a function of the a.out header (e.g. machine type).  */
  171. #ifndef    N_SEGSIZE
  172. #define    N_SEGSIZE(x)    SEGMENT_SIZE
  173. #endif
  174.  
  175. /* This complexity is for encapsulated COFF support */
  176. #ifndef _N_HDROFF
  177. #define _N_HDROFF(x)    (N_SEGSIZE(x) - sizeof (struct exec))
  178. #endif
  179.  
  180. #ifndef N_TXTOFF
  181. #define N_TXTOFF(x)    (N_MAGIC(x) == ZMAGIC ?    \
  182.              _N_HDROFF((x)) + sizeof (struct exec) :    \
  183.              sizeof (struct exec))
  184. #endif
  185.  
  186.  
  187. #ifndef N_DATOFF
  188. #define N_DATOFF(x)    ( N_TXTOFF(x) + (x).a_text )
  189. #endif
  190.  
  191. #ifndef N_TRELOFF
  192. #define N_TRELOFF(x)    ( N_DATOFF(x) + (x).a_data )
  193. #endif
  194.  
  195. #ifndef N_DRELOFF
  196. #define N_DRELOFF(x)    ( N_TRELOFF(x) + (x).a_trsize )
  197. #endif
  198.  
  199. #ifndef N_SYMOFF
  200. #define N_SYMOFF(x)    ( N_DRELOFF(x) + (x).a_drsize )
  201. #endif
  202.  
  203. #ifndef N_STROFF
  204. #define N_STROFF(x)    ( N_SYMOFF(x) + (x).a_syms )
  205. #endif
  206.  
  207. /* Address of text segment in memory after it is loaded.  */
  208. #ifndef N_TXTADDR
  209. #define    N_TXTADDR(x)    0
  210. #endif
  211.  
  212. #ifndef N_DATADDR
  213. #define N_DATADDR(x) \
  214.     (N_MAGIC(x)==OMAGIC? (N_TXTADDR(x)+(x).a_text) \
  215.      :  (N_SEGSIZE(x) + ((N_TXTADDR(x)+(x).a_text-1) & ~(N_SEGSIZE(x)-1))))
  216. #endif
  217.  
  218. /* Address of bss segment in memory after it is loaded.  */
  219. #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
  220.  
  221. struct nlist
  222.   {
  223.     union
  224.       {
  225.     char *n_name;
  226.     struct nlist *n_next;
  227.     long n_strx;
  228.       }
  229.     n_un;
  230.     unsigned char n_type;
  231.     char n_other;
  232.     short n_desc;
  233.     unsigned long n_value;
  234.   };
  235.  
  236. #define N_UNDF 0
  237. #define N_ABS 2
  238. #define N_TEXT 4
  239. #define N_DATA 6
  240. #define N_BSS 8
  241. #define    N_COMM    0x12        /* common (visible in shared lib commons) */
  242. #define N_FN 0x1F        /* File name of a .o file */
  243.  
  244. /* Note: N_EXT can only usefully be OR-ed with N_UNDF, N_ABS, N_TEXT,
  245.    N_DATA, or N_BSS.  When the low-order bit of other types is set,
  246.    (e.g. N_WARNING versus N_FN), they are two different types.  */
  247. #define N_EXT 1
  248. #define N_TYPE 036
  249. #define N_STAB 0340
  250.  
  251. /* The following type indicates the definition of a symbol as being
  252.    an indirect reference to another symbol.  The other symbol
  253.    appears as an undefined reference, immediately following this symbol.
  254.  
  255.    Indirection is asymmetrical.  The other symbol's value will be used
  256.    to satisfy requests for the indirect symbol, but not vice versa.
  257.    If the other symbol does not have a definition, libraries will
  258.    be searched to find a definition.  */
  259.  
  260. #define N_INDR 0xa
  261.  
  262. /* The following symbols refer to set elements.
  263.    All the N_SET[ATDB] symbols with the same name form one set.
  264.    Space is allocated for the set in the text section, and each set
  265.    element's value is stored into one word of the space.
  266.    The first word of the space is the length of the set (number of elements).
  267.  
  268.    The address of the set is made into an N_SETV symbol
  269.    whose name is the same as the name of the set.
  270.    This symbol acts like a N_DATA global symbol
  271.    in that it can satisfy undefined external references.  */
  272.  
  273. /* These appear as input to LD, in a .o file.  */
  274. #define    N_SETA    0x14        /* Absolute set element symbol */
  275. #define    N_SETT    0x16        /* Text set element symbol */
  276. #define    N_SETD    0x18        /* Data set element symbol */
  277. #define    N_SETB    0x1A        /* Bss set element symbol */
  278.  
  279. /* This is output from LD.  */
  280. #define N_SETV    0x1C        /* Pointer to set vector in data area.  */
  281.  
  282. /* Warning symbol. The text gives a warning message, the next symbol
  283.    in the table will be undefined. When the symbol is referenced, the
  284.    message is printed.  */
  285.  
  286. #define    N_WARNING 0x1e
  287.  
  288. /* Weak symbols.  These are a GNU extension to the a.out format.  The
  289.    semantics are those of ELF weak symbols.  Weak symbols are always
  290.    externally visible.  The N_WEAK? values are squeezed into the
  291.    available slots.  The value of a N_WEAKU symbol is 0.  The values
  292.    of the other types are the definitions.  */
  293. #define N_WEAKU    0x0d        /* Weak undefined symbol.  */
  294. #define N_WEAKA 0x0e        /* Weak absolute symbol.  */
  295. #define N_WEAKT 0x0f        /* Weak text symbol.  */
  296. #define N_WEAKD 0x10        /* Weak data symbol.  */
  297. #define N_WEAKB 0x11        /* Weak bss symbol.  */
  298.  
  299. /* This structure describes a single relocation to be performed.
  300.    The text-relocation section of the file is a vector of these structures,
  301.    all of which apply to the text section.
  302.    Likewise, the data-relocation section applies to the data section.  */
  303.  
  304. /* The following enum and struct were borrowed from SunOS's
  305.    /usr/include/sun4/a.out.h  and extended to handle
  306.    other machines.  It is currently used on SPARC and AMD 29000.
  307.  
  308.    reloc_ext_bytes is how it looks on disk.  reloc_info_extended is
  309.    how we might process it on a native host.  */
  310. #if USE_EXTENDED_RELOC
  311.  
  312. struct reloc_ext_bytes
  313.   {
  314.     unsigned char r_address[4];
  315.     unsigned char r_index[3];
  316.     unsigned char r_bits[1];
  317.     unsigned char r_addend[4];
  318.   };
  319.  
  320.  
  321. #define    RELOC_EXT_BITS_EXTERN_BIG    0x80
  322. #define    RELOC_EXT_BITS_EXTERN_LITTLE    0x01
  323.  
  324. #define    RELOC_EXT_BITS_TYPE_BIG        0x1F
  325. #define    RELOC_EXT_BITS_TYPE_SH_BIG    0
  326. #define    RELOC_EXT_BITS_TYPE_LITTLE    0xF8
  327. #define    RELOC_EXT_BITS_TYPE_SH_LITTLE    3
  328.  
  329. #define    RELOC_EXT_SIZE    12    /* Bytes per relocation entry */
  330.  
  331. struct reloc_info_extended
  332. {
  333.   unsigned long r_address;
  334.   unsigned int r_index:24;
  335. # define    r_symbolnum  r_index
  336.   unsigned r_extern:1;
  337.   unsigned:2;
  338.   /*  RS/6000 compiler does not support enum bitfield
  339.         enum reloc_type r_type:5; */
  340.   enum reloc_type r_type;
  341.   long int r_addend;
  342. };
  343.  
  344. #else
  345.  
  346. /* The standard, old-fashioned, Berkeley compatible relocation struct */
  347.  
  348.  
  349.  
  350. #ifdef TC_I860
  351. /* NOTE: three bits max, see struct reloc_info_i860.r_type */
  352. enum i860_reloc_type
  353.   {
  354.     NO_RELOC = 0, BRADDR, LOW0, LOW1, LOW2, LOW3, LOW4, SPLIT0, SPLIT1, SPLIT2, RELOC_32,
  355.   };
  356.  
  357. typedef enum i860_reloc_type reloc_type;
  358.  
  359. /* NOTE: two bits max, see reloc_info_i860.r_type */
  360. enum highlow_type
  361.   {
  362.     NO_SPEC = 0, PAIR, HIGH, HIGHADJ,
  363.   };
  364.  
  365.  
  366. struct reloc_info_i860
  367. {
  368.   unsigned long r_address;
  369.   /*
  370.      * Using bit fields here is a bad idea because the order is not portable. :-(
  371.      */
  372.   unsigned int r_symbolnum:24;
  373.   unsigned int r_pcrel:1;
  374.   unsigned int r_extern:1;
  375.   /* combining the two field simplifies the argument passing in "new_fix()" */
  376.   /* and is compatible with the existing Sparc #ifdef's */
  377.   /* r_type:  highlow_type - bits 5,4; reloc_type - bits 3-0 */
  378.   unsigned int r_type:6;
  379.   long r_addend;
  380. };
  381.  
  382. #endif /* TC_I860 */
  383.  
  384.  
  385. struct reloc_std_bytes
  386.   {
  387.     unsigned char r_address[4];
  388.     unsigned char r_index[3];
  389.     unsigned char r_bits[1];
  390.   };
  391.  
  392. #define    RELOC_STD_BITS_PCREL_BIG    0x80
  393. #define    RELOC_STD_BITS_PCREL_LITTLE    0x01
  394.  
  395. #define    RELOC_STD_BITS_LENGTH_BIG    0x60
  396. #define    RELOC_STD_BITS_LENGTH_SH_BIG    5    /* To shift to units place */
  397. #define    RELOC_STD_BITS_LENGTH_LITTLE    0x06
  398. #define    RELOC_STD_BITS_LENGTH_SH_LITTLE    1
  399.  
  400. #define    RELOC_STD_BITS_EXTERN_BIG    0x10
  401. #define    RELOC_STD_BITS_EXTERN_LITTLE    0x08
  402.  
  403. #define    RELOC_STD_BITS_BASEREL_BIG    0x08
  404. #define    RELOC_STD_BITS_BASEREL_LITTLE    0x08
  405.  
  406. #define    RELOC_STD_BITS_JMPTABLE_BIG    0x04
  407. #define    RELOC_STD_BITS_JMPTABLE_LITTLE    0x04
  408.  
  409. #define    RELOC_STD_BITS_RELATIVE_BIG    0x02
  410. #define    RELOC_STD_BITS_RELATIVE_LITTLE    0x02
  411.  
  412. #define    RELOC_STD_SIZE    8    /* Bytes per relocation entry */
  413.  
  414. #endif /* USE_EXTENDED_RELOC */
  415.  
  416. #ifndef CUSTOM_RELOC_FORMAT
  417. struct relocation_info
  418. {
  419.   /* Address (within segment) to be relocated.  */
  420.   int r_address;
  421.   /* The meaning of r_symbolnum depends on r_extern.  */
  422.   unsigned int r_symbolnum:24;
  423.   /* Nonzero means value is a pc-relative offset
  424.        and it should be relocated for changes in its own address
  425.        as well as for changes in the symbol or section specified.  */
  426.   unsigned int r_pcrel:1;
  427.   /* Length (as exponent of 2) of the field to be relocated.
  428.        Thus, a value of 2 indicates 1<<2 bytes.  */
  429.   unsigned int r_length:2;
  430.   /* 1 => relocate with value of symbol.
  431.        r_symbolnum is the index of the symbol
  432.        in file's the symbol table.
  433.        0 => relocate with the address of a segment.
  434.        r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
  435.        (the N_EXT bit may be set also, but signifies nothing).  */
  436.   unsigned int r_extern:1;
  437.   /* The next three bits are for SunOS shared libraries, and seem to
  438.        be undocumented.  */
  439. #ifdef TC_NS32K
  440.   unsigned int r_bsr:1;
  441.   unsigned int r_disp:2;
  442. #else
  443.   unsigned int r_baserel:1;    /* Linkage table relative */
  444.   unsigned int r_jmptable:1;    /* pc-relative to jump table */
  445.   unsigned int r_relative:1;    /* "relative relocation" */
  446. #endif /* TC_NS32K */
  447.   /* unused */
  448.   unsigned int r_pad:1;        /* Padding -- set to zero */
  449. };
  450.  
  451. #endif /* CUSTOM_RELOC_FORMAT */
  452.  
  453. #endif /* __A_OUT_GNU_H__ */
  454.  
  455. /* end of aout_gnu.h */
  456.