1 #ifndef __A_OUT_GNU_H__
2 #define __A_OUT_GNU_H__
3 
4 #include <bits/a.out.h>
5 
6 #define __GNU_EXEC_MACROS__
7 
8 /*
9  * OSF/1 ECOFF header structs.  ECOFF files consist of:
10  *      - a file header (struct filehdr),
11  *      - an a.out header (struct aouthdr),
12  *      - one or more section headers (struct scnhdr).
13  *        The filhdr's "f_nscns" field contains the
14  *        number of section headers.
15  */
16 
17 struct filehdr
18 {
19   /* OSF/1 "file" header */
20   unsigned short f_magic, f_nscns;
21   unsigned int   f_timdat;
22   unsigned long  f_symptr;
23   unsigned int   f_nsyms;
24   unsigned short f_opthdr, f_flags;
25 };
26 
27 struct aouthdr
28 {
29   unsigned long info;		/* After that it looks quite normal..  */
30   unsigned long tsize;
31   unsigned long dsize;
32   unsigned long bsize;
33   unsigned long entry;
34   unsigned long text_start;	/* With a few additions that actually make sense.  */
35   unsigned long data_start;
36   unsigned long bss_start;
37   unsigned int  gprmask, fprmask; /* Bitmask of general & floating point regs used in binary.  */
38   unsigned long gpvalue;
39 };
40 
41 struct scnhdr
42 {
43   char           s_name[8];
44   unsigned long  s_paddr;
45   unsigned long  s_vaddr;
46   unsigned long  s_size;
47   unsigned long  s_scnptr;
48   unsigned long  s_relptr;
49   unsigned long  s_lnnoptr;
50   unsigned short s_nreloc;
51   unsigned short s_nlnno;
52   unsigned int   s_flags;
53 };
54 
55 struct exec
56 {
57   /* OSF/1 "file" header */
58   struct filehdr fh;
59   struct aouthdr ah;
60 };
61 
62 #define a_info		ah.info
63 #define a_text		ah.tsize
64 #define a_data		ah.dsize
65 #define a_bss		ah.bsize
66 #define a_entry		ah.entry
67 #define a_textstart	ah.text_start
68 #define a_datastart	ah.data_start
69 #define a_bssstart	ah.bss_start
70 #define a_gprmask	ah.gprmask
71 #define a_fprmask	ah.fprmask
72 #define a_gpvalue	ah.gpvalue
73 
74 
75 #define AOUTHSZ		sizeof (struct aouthdr)
76 #define SCNHSZ		sizeof (struct scnhdr)
77 #define SCNROUND	16
78 
79 enum machine_type
80 {
81   M_OLDSUN2 = 0,
82   M_68010 = 1,
83   M_68020 = 2,
84   M_SPARC = 3,
85   M_386 = 100,
86   M_MIPS1 = 151,
87   M_MIPS2 = 152
88 };
89 
90 #define N_MAGIC(exec)	((exec).a_info & 0xffff)
91 #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
92 #define N_FLAGS(exec)	(((exec).a_info >> 24) & 0xff)
93 #define N_SET_INFO(exec, magic, type, flags) \
94   ((exec).a_info = ((magic) & 0xffff)					\
95    | (((int)(type) & 0xff) << 16)					\
96    | (((flags) & 0xff) << 24))
97 #define N_SET_MAGIC(exec, magic) \
98   ((exec).a_info = ((exec).a_info & 0xffff0000) | ((magic) & 0xffff))
99 #define N_SET_MACHTYPE(exec, machtype) \
100   ((exec).a_info =							\
101    ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
102 #define N_SET_FLAGS(exec, flags) \
103   ((exec).a_info =							\
104    ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
105 
106 /* Code indicating object file or impure executable.  */
107 #define OMAGIC 0407
108 /* Code indicating pure executable.  */
109 #define NMAGIC 0410
110 /* Code indicating demand-paged executable.  */
111 #define ZMAGIC 0413
112 /* This indicates a demand-paged executable with the header in the text.
113    The first page is unmapped to help trap NULL pointer references.  */
114 #define QMAGIC 0314
115 /* Code indicating core file.  */
116 #define CMAGIC 0421
117 
118 #define N_TRSIZE(x)	0
119 #define N_DRSIZE(x)	0
120 #define N_SYMSIZE(x)	0
121 #define N_BADMAG(x) \
122   (N_MAGIC(x) != OMAGIC	&& N_MAGIC(x) != NMAGIC				\
123    && N_MAGIC(x) != ZMAGIC && N_MAGIC(x) != QMAGIC)
124 #define _N_HDROFF(x)	(1024 - sizeof (struct exec))
125 #define N_TXTOFF(x) \
126   ((long) N_MAGIC(x) == ZMAGIC ? 0					\
127    : ((sizeof (struct exec) + (x).fh.f_nscns * SCNHSZ + SCNROUND - 1)	\
128       & ~(SCNROUND - 1)))
129 
130 #define N_DATOFF(x)	(N_TXTOFF(x) + (x).a_text)
131 #define N_TRELOFF(x)	(N_DATOFF(x) + (x).a_data)
132 #define N_DRELOFF(x)	(N_TRELOFF(x) + N_TRSIZE(x))
133 #define N_SYMOFF(x)	(N_DRELOFF(x) + N_DRSIZE(x))
134 #define N_STROFF(x)	(N_SYMOFF(x) + N_SYMSIZE(x))
135 
136 /* Address of text segment in memory after it is loaded.  */
137 #define N_TXTADDR(x)	((x).a_textstart)
138 
139 /* Address of data segment in memory after it is loaded.  */
140 #define SEGMENT_SIZE	1024
141 
142 #define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
143 #define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
144 
145 #define N_DATADDR(x)	((x).a_datastart)
146 #define N_BSSADDR(x)	((x).a_bssstart)
147 
148 #if !defined (N_NLIST_DECLARED)
149 struct nlist
150 {
151   union
152     {
153       char *n_name;
154       struct nlist *n_next;
155       long n_strx;
156     } n_un;
157   unsigned char n_type;
158   char n_other;
159   short n_desc;
160   unsigned long n_value;
161 };
162 #endif /* no N_NLIST_DECLARED.  */
163 
164 #define N_UNDF	0
165 #define N_ABS	2
166 #define N_TEXT	4
167 #define N_DATA	6
168 #define N_BSS	8
169 #define N_FN	15
170 #define N_EXT	1
171 #define N_TYPE	036
172 #define N_STAB	0340
173 #define N_INDR	0xa
174 #define	N_SETA	0x14	/* Absolute set element symbol.  */
175 #define	N_SETT	0x16	/* Text set element symbol.  */
176 #define	N_SETD	0x18	/* Data set element symbol.  */
177 #define	N_SETB	0x1A	/* Bss set element symbol.  */
178 #define N_SETV	0x1C	/* Pointer to set vector in data area.  */
179 
180 #if !defined (N_RELOCATION_INFO_DECLARED)
181 /* This structure describes a single relocation to be performed.
182    The text-relocation section of the file is a vector of these structures,
183    all of which apply to the text section.
184    Likewise, the data-relocation section applies to the data section.  */
185 
186 struct relocation_info
187 {
188   int r_address;
189   unsigned int r_symbolnum:24;
190   unsigned int r_pcrel:1;
191   unsigned int r_length:2;
192   unsigned int r_extern:1;
193   unsigned int r_pad:4;
194 };
195 #endif /* no N_RELOCATION_INFO_DECLARED.  */
196 
197 #endif /* __A_OUT_GNU_H__ */
198