zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

a.out.h (6891B) - Raw


      1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
      2 #ifndef __A_OUT_GNU_H__
      3 #define __A_OUT_GNU_H__
      4 
      5 #define __GNU_EXEC_MACROS__
      6 
      7 #ifndef __STRUCT_EXEC_OVERRIDE__
      8 
      9 #include <asm/a.out.h>
     10 
     11 #endif /* __STRUCT_EXEC_OVERRIDE__ */
     12 
     13 #ifndef __ASSEMBLY__
     14 
     15 /* these go in the N_MACHTYPE field */
     16 enum machine_type {
     17 #if defined (M_OLDSUN2)
     18   M__OLDSUN2 = M_OLDSUN2,
     19 #else
     20   M_OLDSUN2 = 0,
     21 #endif
     22 #if defined (M_68010)
     23   M__68010 = M_68010,
     24 #else
     25   M_68010 = 1,
     26 #endif
     27 #if defined (M_68020)
     28   M__68020 = M_68020,
     29 #else
     30   M_68020 = 2,
     31 #endif
     32 #if defined (M_SPARC)
     33   M__SPARC = M_SPARC,
     34 #else
     35   M_SPARC = 3,
     36 #endif
     37   /* skip a bunch so we don't run into any of sun's numbers */
     38   M_386 = 100,
     39   M_MIPS1 = 151,	/* MIPS R3000/R3000 binary */
     40   M_MIPS2 = 152		/* MIPS R6000/R4000 binary */
     41 };
     42 
     43 #if !defined (N_MAGIC)
     44 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
     45 #endif
     46 #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
     47 #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
     48 #define N_SET_INFO(exec, magic, type, flags) \
     49 	((exec).a_info = ((magic) & 0xffff) \
     50 	 | (((int)(type) & 0xff) << 16) \
     51 	 | (((flags) & 0xff) << 24))
     52 #define N_SET_MAGIC(exec, magic) \
     53 	((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
     54 
     55 #define N_SET_MACHTYPE(exec, machtype) \
     56 	((exec).a_info = \
     57 	 ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
     58 
     59 #define N_SET_FLAGS(exec, flags) \
     60 	((exec).a_info = \
     61 	 ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
     62 
     63 /* Code indicating object file or impure executable.  */
     64 #define OMAGIC 0407
     65 /* Code indicating pure executable.  */
     66 #define NMAGIC 0410
     67 /* Code indicating demand-paged executable.  */
     68 #define ZMAGIC 0413
     69 /* This indicates a demand-paged executable with the header in the text. 
     70    The first page is unmapped to help trap NULL pointer references */
     71 #define QMAGIC 0314
     72 
     73 /* Code indicating core file.  */
     74 #define CMAGIC 0421
     75 
     76 #if !defined (N_BADMAG)
     77 #define N_BADMAG(x)	  (N_MAGIC(x) != OMAGIC		\
     78 			&& N_MAGIC(x) != NMAGIC		\
     79   			&& N_MAGIC(x) != ZMAGIC \
     80 		        && N_MAGIC(x) != QMAGIC)
     81 #endif
     82 
     83 #define _N_HDROFF(x) (1024 - sizeof (struct exec))
     84 
     85 #if !defined (N_TXTOFF)
     86 #define N_TXTOFF(x) \
     87  (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : \
     88   (N_MAGIC(x) == QMAGIC ? 0 : sizeof (struct exec)))
     89 #endif
     90 
     91 #if !defined (N_DATOFF)
     92 #define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
     93 #endif
     94 
     95 #if !defined (N_TRELOFF)
     96 #define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
     97 #endif
     98 
     99 #if !defined (N_DRELOFF)
    100 #define N_DRELOFF(x) (N_TRELOFF(x) + N_TRSIZE(x))
    101 #endif
    102 
    103 #if !defined (N_SYMOFF)
    104 #define N_SYMOFF(x) (N_DRELOFF(x) + N_DRSIZE(x))
    105 #endif
    106 
    107 #if !defined (N_STROFF)
    108 #define N_STROFF(x) (N_SYMOFF(x) + N_SYMSIZE(x))
    109 #endif
    110 
    111 /* Address of text segment in memory after it is loaded.  */
    112 #if !defined (N_TXTADDR)
    113 #define N_TXTADDR(x) (N_MAGIC(x) == QMAGIC ? PAGE_SIZE : 0)
    114 #endif
    115 
    116 /* Address of data segment in memory after it is loaded. */
    117 #include <unistd.h>
    118 #if defined(__i386__) || defined(__mc68000__)
    119 #define SEGMENT_SIZE	1024
    120 #else
    121 #ifndef SEGMENT_SIZE
    122 #define SEGMENT_SIZE   getpagesize()
    123 #endif
    124 #endif
    125 
    126 #define _N_SEGMENT_ROUND(x) ALIGN(x, SEGMENT_SIZE)
    127 
    128 #define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
    129 
    130 #ifndef N_DATADDR
    131 #define N_DATADDR(x) \
    132     (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \
    133      : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
    134 #endif
    135 
    136 /* Address of bss segment in memory after it is loaded.  */
    137 #if !defined (N_BSSADDR)
    138 #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
    139 #endif
    140 
    141 #if !defined (N_NLIST_DECLARED)
    142 struct nlist {
    143   union {
    144     char *n_name;
    145     struct nlist *n_next;
    146     long n_strx;
    147   } n_un;
    148   unsigned char n_type;
    149   char n_other;
    150   short n_desc;
    151   unsigned long n_value;
    152 };
    153 #endif /* no N_NLIST_DECLARED.  */
    154 
    155 #if !defined (N_UNDF)
    156 #define N_UNDF 0
    157 #endif
    158 #if !defined (N_ABS)
    159 #define N_ABS 2
    160 #endif
    161 #if !defined (N_TEXT)
    162 #define N_TEXT 4
    163 #endif
    164 #if !defined (N_DATA)
    165 #define N_DATA 6
    166 #endif
    167 #if !defined (N_BSS)
    168 #define N_BSS 8
    169 #endif
    170 #if !defined (N_FN)
    171 #define N_FN 15
    172 #endif
    173 
    174 #if !defined (N_EXT)
    175 #define N_EXT 1
    176 #endif
    177 #if !defined (N_TYPE)
    178 #define N_TYPE 036
    179 #endif
    180 #if !defined (N_STAB)
    181 #define N_STAB 0340
    182 #endif
    183 
    184 /* The following type indicates the definition of a symbol as being
    185    an indirect reference to another symbol.  The other symbol
    186    appears as an undefined reference, immediately following this symbol.
    187 
    188    Indirection is asymmetrical.  The other symbol's value will be used
    189    to satisfy requests for the indirect symbol, but not vice versa.
    190    If the other symbol does not have a definition, libraries will
    191    be searched to find a definition.  */
    192 #define N_INDR 0xa
    193 
    194 /* The following symbols refer to set elements.
    195    All the N_SET[ATDB] symbols with the same name form one set.
    196    Space is allocated for the set in the text section, and each set
    197    element's value is stored into one word of the space.
    198    The first word of the space is the length of the set (number of elements).
    199 
    200    The address of the set is made into an N_SETV symbol
    201    whose name is the same as the name of the set.
    202    This symbol acts like a N_DATA global symbol
    203    in that it can satisfy undefined external references.  */
    204 
    205 /* These appear as input to LD, in a .o file.  */
    206 #define	N_SETA	0x14		/* Absolute set element symbol */
    207 #define	N_SETT	0x16		/* Text set element symbol */
    208 #define	N_SETD	0x18		/* Data set element symbol */
    209 #define	N_SETB	0x1A		/* Bss set element symbol */
    210 
    211 /* This is output from LD.  */
    212 #define N_SETV	0x1C		/* Pointer to set vector in data area.  */
    213 
    214 #if !defined (N_RELOCATION_INFO_DECLARED)
    215 /* This structure describes a single relocation to be performed.
    216    The text-relocation section of the file is a vector of these structures,
    217    all of which apply to the text section.
    218    Likewise, the data-relocation section applies to the data section.  */
    219 
    220 struct relocation_info
    221 {
    222   /* Address (within segment) to be relocated.  */
    223   int r_address;
    224   /* The meaning of r_symbolnum depends on r_extern.  */
    225   unsigned int r_symbolnum:24;
    226   /* Nonzero means value is a pc-relative offset
    227      and it should be relocated for changes in its own address
    228      as well as for changes in the symbol or section specified.  */
    229   unsigned int r_pcrel:1;
    230   /* Length (as exponent of 2) of the field to be relocated.
    231      Thus, a value of 2 indicates 1<<2 bytes.  */
    232   unsigned int r_length:2;
    233   /* 1 => relocate with value of symbol.
    234           r_symbolnum is the index of the symbol
    235 	  in file's the symbol table.
    236      0 => relocate with the address of a segment.
    237           r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
    238 	  (the N_EXT bit may be set also, but signifies nothing).  */
    239   unsigned int r_extern:1;
    240   /* Four bits that aren't used, but when writing an object file
    241      it is desirable to clear them.  */
    242   unsigned int r_pad:4;
    243 };
    244 #endif /* no N_RELOCATION_INFO_DECLARED.  */
    245 
    246 #endif /*__ASSEMBLY__ */
    247 #endif /* __A_OUT_GNU_H__ */