1 /* ECOFF support on Alpha machines.
2    coff/ecoff.h must be included before this file.
3 
4    Copyright 2001 Free Software Foundation, Inc.
5 
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19 
20 /********************** FILE HEADER **********************/
21 
22 struct external_filehdr
23 {
24   unsigned char f_magic[2];	/* magic number			*/
25   unsigned char f_nscns[2];	/* number of sections		*/
26   unsigned char f_timdat[4];	/* time & date stamp		*/
27   unsigned char f_symptr[8];	/* file pointer to symtab	*/
28   unsigned char f_nsyms[4];	/* number of symtab entries	*/
29   unsigned char f_opthdr[2];	/* sizeof(optional hdr)		*/
30   unsigned char f_flags[2];	/* flags			*/
31 };
32 
33 /* Magic numbers are defined in coff/ecoff.h.  */
34 #define ALPHA_ECOFF_BADMAG(x) \
35   ((x).f_magic != ALPHA_MAGIC && (x).f_magic != ALPHA_MAGIC_BSD)
36 
37 /* The object type is encoded in the f_flags.  */
38 #define F_ALPHA_OBJECT_TYPE_MASK	0x3000
39 #define F_ALPHA_NO_SHARED		0x1000
40 #define F_ALPHA_SHARABLE		0x2000
41 #define F_ALPHA_CALL_SHARED		0x3000
42 
43 #define	FILHDR	struct external_filehdr
44 #define	FILHSZ	24
45 
46 /********************** AOUT "OPTIONAL HEADER" **********************/
47 
48 typedef struct external_aouthdr
49 {
50   unsigned char magic[2];	/* type of file				*/
51   unsigned char	vstamp[2];	/* version stamp			*/
52   unsigned char bldrev[2];	/* ?? */
53   unsigned char padding[2];	/* pad to quadword boundary		*/
54   unsigned char	tsize[8];	/* text size in bytes			*/
55   unsigned char	dsize[8];	/* initialized data "  "		*/
56   unsigned char	bsize[8];	/* uninitialized data "   "		*/
57   unsigned char	entry[8];	/* entry pt.				*/
58   unsigned char text_start[8];	/* base of text used for this file */
59   unsigned char data_start[8];	/* base of data used for this file */
60   unsigned char bss_start[8];	/* base of bss used for this file */
61   unsigned char gprmask[4];	/* bitmask of general registers used */
62   unsigned char fprmask[4];	/* bitmask of floating point registers used */
63   unsigned char gp_value[8];	/* value for gp register */
64 } AOUTHDR;
65 
66 /* compute size of a header */
67 
68 #define AOUTSZ 80
69 #define AOUTHDRSZ 80
70 
71 /********************** SECTION HEADER **********************/
72 
73 struct external_scnhdr
74 {
75   unsigned char	s_name[8];	/* section name			*/
76   unsigned char	s_paddr[8];	/* physical address, aliased s_nlib */
77   unsigned char	s_vaddr[8];	/* virtual address		*/
78   unsigned char	s_size[8];	/* section size			*/
79   unsigned char	s_scnptr[8];	/* file ptr to raw data for section */
80   unsigned char	s_relptr[8];	/* file ptr to relocation	*/
81   unsigned char	s_lnnoptr[8];	/* file ptr to line numbers	*/
82   unsigned char	s_nreloc[2];	/* number of relocation entries	*/
83   unsigned char	s_nlnno[2];	/* number of line number entries*/
84   unsigned char	s_flags[4];	/* flags			*/
85 };
86 
87 #define	SCNHDR	struct external_scnhdr
88 #define	SCNHSZ	64
89 
90 /********************** RELOCATION DIRECTIVES **********************/
91 
92 struct external_reloc
93 {
94   unsigned char r_vaddr[8];
95   unsigned char r_symndx[4];
96   unsigned char r_bits[4];
97 };
98 
99 #define RELOC struct external_reloc
100 #define RELSZ 16
101 
102 /* Constants to unpack the r_bits field.  The Alpha seems to always be
103    little endian, so I haven't bothered to define big endian variants
104    of these.  */
105 
106 #define RELOC_BITS0_TYPE_LITTLE			0xff
107 #define RELOC_BITS0_TYPE_SH_LITTLE		0
108 
109 #define RELOC_BITS1_EXTERN_LITTLE		0x01
110 
111 #define RELOC_BITS1_OFFSET_LITTLE		0x7e
112 #define RELOC_BITS1_OFFSET_SH_LITTLE		1
113 
114 #define RELOC_BITS1_RESERVED_LITTLE		0x80
115 #define RELOC_BITS1_RESERVED_SH_LITTLE		7
116 #define RELOC_BITS2_RESERVED_LITTLE		0xff
117 #define RELOC_BITS2_RESERVED_SH_LEFT_LITTLE	1
118 #define RELOC_BITS3_RESERVED_LITTLE		0x03
119 #define RELOC_BITS3_RESERVED_SH_LEFT_LITTLE	9
120 
121 #define RELOC_BITS3_SIZE_LITTLE			0xfc
122 #define RELOC_BITS3_SIZE_SH_LITTLE		2
123 
124 /* The r_type field in a reloc is one of the following values.  */
125 #define ALPHA_R_IGNORE		0
126 #define ALPHA_R_REFLONG		1
127 #define ALPHA_R_REFQUAD		2
128 #define ALPHA_R_GPREL32		3
129 #define ALPHA_R_LITERAL		4
130 #define ALPHA_R_LITUSE		5
131 #define ALPHA_R_GPDISP		6
132 #define ALPHA_R_BRADDR		7
133 #define ALPHA_R_HINT		8
134 #define ALPHA_R_SREL16		9
135 #define ALPHA_R_SREL32	       10
136 #define ALPHA_R_SREL64	       11
137 #define ALPHA_R_OP_PUSH	       12
138 #define ALPHA_R_OP_STORE       13
139 #define ALPHA_R_OP_PSUB	       14
140 #define ALPHA_R_OP_PRSHIFT     15
141 #define ALPHA_R_GPVALUE	       16
142 #define ALPHA_R_GPRELHIGH      17
143 #define ALPHA_R_GPRELLOW       18
144 #define ALPHA_R_IMMED          19
145 
146 /* Overloaded reloc value used by Net- and OpenBSD.  */
147 #define ALPHA_R_LITERALSLEAZY  17
148 
149 /* With ALPHA_R_LITUSE, the r_size field is one of the following values.  */
150 #define ALPHA_R_LU_BASE         1
151 #define ALPHA_R_LU_BYTOFF       2
152 #define ALPHA_R_LU_JSR          3
153 
154 /* With ALPHA_R_IMMED, the r_size field is one of the following values.  */
155 #define ALPHA_R_IMMED_GP_16     1
156 #define ALPHA_R_IMMED_GP_HI32   2
157 #define ALPHA_R_IMMED_SCN_HI32  3
158 #define ALPHA_R_IMMED_BR_HI32   4
159 #define ALPHA_R_IMMED_LO32      5
160 
161 /********************** SYMBOLIC INFORMATION **********************/
162 
163 /* Written by John Gilmore.  */
164 
165 /* ECOFF uses COFF-like section structures, but its own symbol format.
166    This file defines the symbol format in fields whose size and alignment
167    will not vary on different host systems.  */
168 
169 /* File header as a set of bytes */
170 
171 struct hdr_ext
172 {
173 	unsigned char 	h_magic[2];
174 	unsigned char	h_vstamp[2];
175 	unsigned char	h_ilineMax[4];
176 	unsigned char	h_idnMax[4];
177 	unsigned char	h_ipdMax[4];
178 	unsigned char	h_isymMax[4];
179 	unsigned char	h_ioptMax[4];
180 	unsigned char	h_iauxMax[4];
181 	unsigned char	h_issMax[4];
182 	unsigned char	h_issExtMax[4];
183 	unsigned char	h_ifdMax[4];
184 	unsigned char	h_crfd[4];
185 	unsigned char	h_iextMax[4];
186 	unsigned char	h_cbLine[8];
187 	unsigned char	h_cbLineOffset[8];
188 	unsigned char	h_cbDnOffset[8];
189 	unsigned char	h_cbPdOffset[8];
190 	unsigned char	h_cbSymOffset[8];
191 	unsigned char	h_cbOptOffset[8];
192 	unsigned char	h_cbAuxOffset[8];
193 	unsigned char	h_cbSsOffset[8];
194 	unsigned char	h_cbSsExtOffset[8];
195 	unsigned char	h_cbFdOffset[8];
196 	unsigned char	h_cbRfdOffset[8];
197 	unsigned char	h_cbExtOffset[8];
198 };
199 
200 /* File descriptor external record */
201 
202 struct fdr_ext
203 {
204 	unsigned char	f_adr[8];
205 	unsigned char	f_cbLineOffset[8];
206 	unsigned char	f_cbLine[8];
207 	unsigned char	f_cbSs[8];
208 	unsigned char	f_rss[4];
209 	unsigned char	f_issBase[4];
210 	unsigned char	f_isymBase[4];
211 	unsigned char	f_csym[4];
212 	unsigned char	f_ilineBase[4];
213 	unsigned char	f_cline[4];
214 	unsigned char	f_ioptBase[4];
215 	unsigned char	f_copt[4];
216 	unsigned char	f_ipdFirst[4];
217 	unsigned char	f_cpd[4];
218 	unsigned char	f_iauxBase[4];
219 	unsigned char	f_caux[4];
220 	unsigned char	f_rfdBase[4];
221 	unsigned char	f_crfd[4];
222 	unsigned char	f_bits1[1];
223 	unsigned char	f_bits2[3];
224 	unsigned char	f_padding[4];
225 };
226 
227 #define	FDR_BITS1_LANG_BIG		0xF8
228 #define	FDR_BITS1_LANG_SH_BIG		3
229 #define	FDR_BITS1_LANG_LITTLE		0x1F
230 #define	FDR_BITS1_LANG_SH_LITTLE	0
231 
232 #define	FDR_BITS1_FMERGE_BIG		0x04
233 #define	FDR_BITS1_FMERGE_LITTLE		0x20
234 
235 #define	FDR_BITS1_FREADIN_BIG		0x02
236 #define	FDR_BITS1_FREADIN_LITTLE	0x40
237 
238 #define	FDR_BITS1_FBIGENDIAN_BIG	0x01
239 #define	FDR_BITS1_FBIGENDIAN_LITTLE	0x80
240 
241 #define	FDR_BITS2_GLEVEL_BIG		0xC0
242 #define	FDR_BITS2_GLEVEL_SH_BIG		6
243 #define	FDR_BITS2_GLEVEL_LITTLE		0x03
244 #define	FDR_BITS2_GLEVEL_SH_LITTLE	0
245 
246 /* We ignore the `reserved' field in bits2. */
247 
248 /* Procedure descriptor external record */
249 
250 struct pdr_ext {
251 	unsigned char	p_adr[8];
252 	unsigned char	p_cbLineOffset[8];
253 	unsigned char	p_isym[4];
254 	unsigned char	p_iline[4];
255 	unsigned char	p_regmask[4];
256 	unsigned char	p_regoffset[4];
257 	unsigned char	p_iopt[4];
258 	unsigned char	p_fregmask[4];
259 	unsigned char	p_fregoffset[4];
260 	unsigned char	p_frameoffset[4];
261 	unsigned char	p_lnLow[4];
262 	unsigned char	p_lnHigh[4];
263 	unsigned char	p_gp_prologue[1];
264 	unsigned char	p_bits1[1];
265 	unsigned char	p_bits2[1];
266 	unsigned char	p_localoff[1];
267 	unsigned char	p_framereg[2];
268 	unsigned char	p_pcreg[2];
269 };
270 
271 #define PDR_BITS1_GP_USED_BIG		0x80
272 #define PDR_BITS1_REG_FRAME_BIG		0x40
273 #define PDR_BITS1_PROF_BIG		0x20
274 #define PDR_BITS1_RESERVED_BIG		0x1f
275 #define PDR_BITS1_RESERVED_SH_LEFT_BIG	8
276 #define PDR_BITS2_RESERVED_BIG		0xff
277 #define PDR_BITS2_RESERVED_SH_BIG	0
278 
279 #define PDR_BITS1_GP_USED_LITTLE	0x01
280 #define PDR_BITS1_REG_FRAME_LITTLE	0x02
281 #define PDR_BITS1_PROF_LITTLE		0x04
282 #define PDR_BITS1_RESERVED_LITTLE	0xf8
283 #define PDR_BITS1_RESERVED_SH_LITTLE	3
284 #define PDR_BITS2_RESERVED_LITTLE	0xff
285 #define PDR_BITS2_RESERVED_SH_LEFT_LITTLE 5
286 
287 /* Line numbers */
288 
289 struct line_ext {
290 	unsigned char	l_line[4];
291 };
292 
293 /* Symbol external record */
294 
295 struct sym_ext {
296 	unsigned char	s_value[8];
297 	unsigned char	s_iss[4];
298 	unsigned char	s_bits1[1];
299 	unsigned char	s_bits2[1];
300 	unsigned char	s_bits3[1];
301 	unsigned char	s_bits4[1];
302 };
303 
304 #define	SYM_BITS1_ST_BIG		0xFC
305 #define	SYM_BITS1_ST_SH_BIG		2
306 #define	SYM_BITS1_ST_LITTLE		0x3F
307 #define	SYM_BITS1_ST_SH_LITTLE		0
308 
309 #define	SYM_BITS1_SC_BIG		0x03
310 #define	SYM_BITS1_SC_SH_LEFT_BIG	3
311 #define	SYM_BITS1_SC_LITTLE		0xC0
312 #define	SYM_BITS1_SC_SH_LITTLE		6
313 
314 #define	SYM_BITS2_SC_BIG		0xE0
315 #define	SYM_BITS2_SC_SH_BIG		5
316 #define	SYM_BITS2_SC_LITTLE		0x07
317 #define	SYM_BITS2_SC_SH_LEFT_LITTLE	2
318 
319 #define	SYM_BITS2_RESERVED_BIG		0x10
320 #define	SYM_BITS2_RESERVED_LITTLE	0x08
321 
322 #define	SYM_BITS2_INDEX_BIG		0x0F
323 #define	SYM_BITS2_INDEX_SH_LEFT_BIG	16
324 #define	SYM_BITS2_INDEX_LITTLE		0xF0
325 #define	SYM_BITS2_INDEX_SH_LITTLE	4
326 
327 #define	SYM_BITS3_INDEX_SH_LEFT_BIG	8
328 #define	SYM_BITS3_INDEX_SH_LEFT_LITTLE	4
329 
330 #define	SYM_BITS4_INDEX_SH_LEFT_BIG	0
331 #define	SYM_BITS4_INDEX_SH_LEFT_LITTLE	12
332 
333 /* External symbol external record */
334 
335 struct ext_ext {
336 	struct	sym_ext es_asym;
337 	unsigned char	es_bits1[1];
338 	unsigned char	es_bits2[3];
339 	unsigned char	es_ifd[4];
340 };
341 
342 #define	EXT_BITS1_JMPTBL_BIG		0x80
343 #define	EXT_BITS1_JMPTBL_LITTLE		0x01
344 
345 #define	EXT_BITS1_COBOL_MAIN_BIG	0x40
346 #define	EXT_BITS1_COBOL_MAIN_LITTLE	0x02
347 
348 #define	EXT_BITS1_WEAKEXT_BIG		0x20
349 #define	EXT_BITS1_WEAKEXT_LITTLE	0x04
350 
351 /* Dense numbers external record */
352 
353 struct dnr_ext {
354 	unsigned char	d_rfd[4];
355 	unsigned char	d_index[4];
356 };
357 
358 /* Relative file descriptor */
359 
360 struct rfd_ext {
361   unsigned char	rfd[4];
362 };
363 
364 /* Optimizer symbol external record */
365 
366 struct opt_ext {
367   unsigned char o_bits1[1];
368   unsigned char o_bits2[1];
369   unsigned char o_bits3[1];
370   unsigned char o_bits4[1];
371   struct rndx_ext o_rndx;
372   unsigned char o_offset[4];
373 };
374 
375 #define OPT_BITS2_VALUE_SH_LEFT_BIG	16
376 #define OPT_BITS2_VALUE_SH_LEFT_LITTLE	0
377 
378 #define OPT_BITS3_VALUE_SH_LEFT_BIG	8
379 #define OPT_BITS3_VALUE_SH_LEFT_LITTLE	8
380 
381 #define OPT_BITS4_VALUE_SH_LEFT_BIG	0
382 #define OPT_BITS4_VALUE_SH_LEFT_LITTLE	16
383