1*3d8817e4Smiod /* IBM RS/6000 "XCOFF" file definitions for BFD.
2*3d8817e4Smiod    Copyright (C) 1990, 1991, 2001 Free Software Foundation, Inc.
3*3d8817e4Smiod    FIXME: Can someone provide a transliteration of this name into ASCII?
4*3d8817e4Smiod    Using the following chars caused a compiler warning on HIUX (so I replaced
5*3d8817e4Smiod    them with octal escapes), and isn't useful without an understanding of what
6*3d8817e4Smiod    character set it is.
7*3d8817e4Smiod    Written by Mimi Ph\373\364ng-Th\345o V\365 of IBM
8*3d8817e4Smiod    and John Gilmore of Cygnus Support.  */
9*3d8817e4Smiod 
10*3d8817e4Smiod /********************** FILE HEADER **********************/
11*3d8817e4Smiod 
12*3d8817e4Smiod struct external_filehdr {
13*3d8817e4Smiod 	char f_magic[2];	/* magic number			*/
14*3d8817e4Smiod 	char f_nscns[2];	/* number of sections		*/
15*3d8817e4Smiod 	char f_timdat[4];	/* time & date stamp		*/
16*3d8817e4Smiod 	char f_symptr[4];	/* file pointer to symtab	*/
17*3d8817e4Smiod 	char f_nsyms[4];	/* number of symtab entries	*/
18*3d8817e4Smiod 	char f_opthdr[2];	/* sizeof(optional hdr)		*/
19*3d8817e4Smiod 	char f_flags[2];	/* flags			*/
20*3d8817e4Smiod };
21*3d8817e4Smiod 
22*3d8817e4Smiod         /* IBM RS/6000 */
23*3d8817e4Smiod #define U802WRMAGIC     0730    /* writeable text segments **chh**      */
24*3d8817e4Smiod #define U802ROMAGIC     0735    /* readonly sharable text segments      */
25*3d8817e4Smiod #define U802TOCMAGIC    0737    /* readonly text segments and TOC       */
26*3d8817e4Smiod 
27*3d8817e4Smiod #define BADMAG(x)	\
28*3d8817e4Smiod 	((x).f_magic != U802ROMAGIC && (x).f_magic != U802WRMAGIC && \
29*3d8817e4Smiod 	 (x).f_magic != U802TOCMAGIC)
30*3d8817e4Smiod 
31*3d8817e4Smiod #define	FILHDR	struct external_filehdr
32*3d8817e4Smiod #define	FILHSZ	20
33*3d8817e4Smiod 
34*3d8817e4Smiod 
35*3d8817e4Smiod /********************** AOUT "OPTIONAL HEADER" **********************/
36*3d8817e4Smiod 
37*3d8817e4Smiod 
38*3d8817e4Smiod typedef struct
39*3d8817e4Smiod {
40*3d8817e4Smiod   unsigned char	magic[2];	/* type of file			*/
41*3d8817e4Smiod   unsigned char	vstamp[2];	/* version stamp		*/
42*3d8817e4Smiod   unsigned char	tsize[4];	/* text size in bytes, padded to FW bdry */
43*3d8817e4Smiod   unsigned char	dsize[4];	/* initialized data "  "	*/
44*3d8817e4Smiod   unsigned char	bsize[4];	/* uninitialized data "   "	*/
45*3d8817e4Smiod   unsigned char	entry[4];	/* entry pt.			*/
46*3d8817e4Smiod   unsigned char	text_start[4];	/* base of text used for this file */
47*3d8817e4Smiod   unsigned char	data_start[4];	/* base of data used for this file */
48*3d8817e4Smiod   unsigned char	o_toc[4];	/* address of TOC */
49*3d8817e4Smiod   unsigned char	o_snentry[2];	/* section number of entry point */
50*3d8817e4Smiod   unsigned char	o_sntext[2];	/* section number of .text section */
51*3d8817e4Smiod   unsigned char	o_sndata[2];	/* section number of .data section */
52*3d8817e4Smiod   unsigned char	o_sntoc[2];	/* section number of TOC */
53*3d8817e4Smiod   unsigned char	o_snloader[2];	/* section number of .loader section */
54*3d8817e4Smiod   unsigned char	o_snbss[2];	/* section number of .bss section */
55*3d8817e4Smiod   unsigned char	o_algntext[2];	/* .text alignment */
56*3d8817e4Smiod   unsigned char	o_algndata[2];	/* .data alignment */
57*3d8817e4Smiod   unsigned char	o_modtype[2];	/* module type (??) */
58*3d8817e4Smiod   unsigned char o_cputype[2];	/* cpu type */
59*3d8817e4Smiod   unsigned char	o_maxstack[4];	/* max stack size (??) */
60*3d8817e4Smiod   unsigned char o_maxdata[4];	/* max data size (??) */
61*3d8817e4Smiod   unsigned char	o_resv2[12];	/* reserved */
62*3d8817e4Smiod }
63*3d8817e4Smiod AOUTHDR;
64*3d8817e4Smiod 
65*3d8817e4Smiod #define AOUTSZ 72
66*3d8817e4Smiod #define SMALL_AOUTSZ (28)
67*3d8817e4Smiod #define AOUTHDRSZ 72
68*3d8817e4Smiod 
69*3d8817e4Smiod /********************** SECTION HEADER **********************/
70*3d8817e4Smiod 
71*3d8817e4Smiod 
72*3d8817e4Smiod struct external_scnhdr {
73*3d8817e4Smiod 	char		s_name[8];	/* section name			*/
74*3d8817e4Smiod 	char		s_paddr[4];	/* physical address, aliased s_nlib */
75*3d8817e4Smiod 	char		s_vaddr[4];	/* virtual address		*/
76*3d8817e4Smiod 	char		s_size[4];	/* section size			*/
77*3d8817e4Smiod 	char		s_scnptr[4];	/* file ptr to raw data for section */
78*3d8817e4Smiod 	char		s_relptr[4];	/* file ptr to relocation	*/
79*3d8817e4Smiod 	char		s_lnnoptr[4];	/* file ptr to line numbers	*/
80*3d8817e4Smiod 	char		s_nreloc[2];	/* number of relocation entries	*/
81*3d8817e4Smiod 	char		s_nlnno[2];	/* number of line number entries*/
82*3d8817e4Smiod 	char		s_flags[4];	/* flags			*/
83*3d8817e4Smiod };
84*3d8817e4Smiod 
85*3d8817e4Smiod #define	SCNHDR	struct external_scnhdr
86*3d8817e4Smiod #define	SCNHSZ	40
87*3d8817e4Smiod 
88*3d8817e4Smiod /********************** LINE NUMBERS **********************/
89*3d8817e4Smiod 
90*3d8817e4Smiod /* 1 line number entry for every "breakpointable" source line in a section.
91*3d8817e4Smiod  * Line numbers are grouped on a per function basis; first entry in a function
92*3d8817e4Smiod  * grouping will have l_lnno = 0 and in place of physical address will be the
93*3d8817e4Smiod  * symbol table index of the function name.
94*3d8817e4Smiod  */
95*3d8817e4Smiod struct external_lineno {
96*3d8817e4Smiod 	union {
97*3d8817e4Smiod 		char l_symndx[4];	/* function name symbol index, iff l_lnno == 0*/
98*3d8817e4Smiod 		char l_paddr[4];	/* (physical) address of line number	*/
99*3d8817e4Smiod 	} l_addr;
100*3d8817e4Smiod 	char l_lnno[2];	/* line number		*/
101*3d8817e4Smiod };
102*3d8817e4Smiod 
103*3d8817e4Smiod 
104*3d8817e4Smiod #define	LINENO	struct external_lineno
105*3d8817e4Smiod #define	LINESZ	6
106*3d8817e4Smiod 
107*3d8817e4Smiod 
108*3d8817e4Smiod /********************** SYMBOLS **********************/
109*3d8817e4Smiod 
110*3d8817e4Smiod #define E_SYMNMLEN	8	/* # characters in a symbol name	*/
111*3d8817e4Smiod #define E_FILNMLEN	14	/* # characters in a file name		*/
112*3d8817e4Smiod #define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
113*3d8817e4Smiod 
114*3d8817e4Smiod struct external_syment
115*3d8817e4Smiod {
116*3d8817e4Smiod   union {
117*3d8817e4Smiod     char e_name[E_SYMNMLEN];
118*3d8817e4Smiod     struct {
119*3d8817e4Smiod       char e_zeroes[4];
120*3d8817e4Smiod       char e_offset[4];
121*3d8817e4Smiod     } e;
122*3d8817e4Smiod   } e;
123*3d8817e4Smiod   char e_value[4];
124*3d8817e4Smiod   char e_scnum[2];
125*3d8817e4Smiod   char e_type[2];
126*3d8817e4Smiod   char e_sclass[1];
127*3d8817e4Smiod   char e_numaux[1];
128*3d8817e4Smiod };
129*3d8817e4Smiod 
130*3d8817e4Smiod 
131*3d8817e4Smiod 
132*3d8817e4Smiod #define N_BTMASK	(017)
133*3d8817e4Smiod #define N_TMASK		(060)
134*3d8817e4Smiod #define N_BTSHFT	(4)
135*3d8817e4Smiod #define N_TSHIFT	(2)
136*3d8817e4Smiod 
137*3d8817e4Smiod 
138*3d8817e4Smiod union external_auxent {
139*3d8817e4Smiod 	struct {
140*3d8817e4Smiod 		char x_tagndx[4];	/* str, un, or enum tag indx */
141*3d8817e4Smiod 		union {
142*3d8817e4Smiod 			struct {
143*3d8817e4Smiod 			    char  x_lnno[2]; /* declaration line number */
144*3d8817e4Smiod 			    char  x_size[2]; /* str/union/array size */
145*3d8817e4Smiod 			} x_lnsz;
146*3d8817e4Smiod 			char x_fsize[4];	/* size of function */
147*3d8817e4Smiod 		} x_misc;
148*3d8817e4Smiod 		union {
149*3d8817e4Smiod 			struct {		/* if ISFCN, tag, or .bb */
150*3d8817e4Smiod 			    char x_lnnoptr[4];	/* ptr to fcn line # */
151*3d8817e4Smiod 			    char x_endndx[4];	/* entry ndx past block end */
152*3d8817e4Smiod 			} x_fcn;
153*3d8817e4Smiod 			struct {		/* if ISARY, up to 4 dimen. */
154*3d8817e4Smiod 			    char x_dimen[E_DIMNUM][2];
155*3d8817e4Smiod 			} x_ary;
156*3d8817e4Smiod 		} x_fcnary;
157*3d8817e4Smiod 		char x_tvndx[2];		/* tv index */
158*3d8817e4Smiod 	} x_sym;
159*3d8817e4Smiod 
160*3d8817e4Smiod 	union {
161*3d8817e4Smiod 		char x_fname[E_FILNMLEN];
162*3d8817e4Smiod 		struct {
163*3d8817e4Smiod 			char x_zeroes[4];
164*3d8817e4Smiod 			char x_offset[4];
165*3d8817e4Smiod 		} x_n;
166*3d8817e4Smiod 	} x_file;
167*3d8817e4Smiod 
168*3d8817e4Smiod 	struct {
169*3d8817e4Smiod 		char x_scnlen[4];			/* section length */
170*3d8817e4Smiod 		char x_nreloc[2];	/* # relocation entries */
171*3d8817e4Smiod 		char x_nlinno[2];	/* # line numbers */
172*3d8817e4Smiod 	} x_scn;
173*3d8817e4Smiod 
174*3d8817e4Smiod         struct {
175*3d8817e4Smiod 		char x_tvfill[4];	/* tv fill value */
176*3d8817e4Smiod 		char x_tvlen[2];	/* length of .tv */
177*3d8817e4Smiod 		char x_tvran[2][2];	/* tv range */
178*3d8817e4Smiod 	} x_tv;		/* info about .tv section (in auxent of symbol .tv)) */
179*3d8817e4Smiod 
180*3d8817e4Smiod 	struct {
181*3d8817e4Smiod 		unsigned char x_scnlen[4];
182*3d8817e4Smiod 		unsigned char x_parmhash[4];
183*3d8817e4Smiod 		unsigned char x_snhash[2];
184*3d8817e4Smiod 		unsigned char x_smtyp[1];
185*3d8817e4Smiod 		unsigned char x_smclas[1];
186*3d8817e4Smiod 		unsigned char x_stab[4];
187*3d8817e4Smiod 		unsigned char x_snstab[2];
188*3d8817e4Smiod 	} x_csect;
189*3d8817e4Smiod 
190*3d8817e4Smiod };
191*3d8817e4Smiod 
192*3d8817e4Smiod #define	SYMENT	struct external_syment
193*3d8817e4Smiod #define	SYMESZ	18
194*3d8817e4Smiod #define	AUXENT	union external_auxent
195*3d8817e4Smiod #define	AUXESZ	18
196*3d8817e4Smiod #define DBXMASK 0x80		/* for dbx storage mask */
197*3d8817e4Smiod #define SYMNAME_IN_DEBUG(symptr) ((symptr)->n_sclass & DBXMASK)
198*3d8817e4Smiod 
199*3d8817e4Smiod 
200*3d8817e4Smiod 
201*3d8817e4Smiod /********************** RELOCATION DIRECTIVES **********************/
202*3d8817e4Smiod 
203*3d8817e4Smiod 
204*3d8817e4Smiod struct external_reloc {
205*3d8817e4Smiod   char r_vaddr[4];
206*3d8817e4Smiod   char r_symndx[4];
207*3d8817e4Smiod   char r_size[1];
208*3d8817e4Smiod   char r_type[1];
209*3d8817e4Smiod };
210*3d8817e4Smiod 
211*3d8817e4Smiod 
212*3d8817e4Smiod #define RELOC struct external_reloc
213*3d8817e4Smiod #define RELSZ 10
214*3d8817e4Smiod 
215*3d8817e4Smiod #define DEFAULT_DATA_SECTION_ALIGNMENT 4
216*3d8817e4Smiod #define DEFAULT_BSS_SECTION_ALIGNMENT 4
217*3d8817e4Smiod #define DEFAULT_TEXT_SECTION_ALIGNMENT 4
218*3d8817e4Smiod /* For new sections we havn't heard of before */
219*3d8817e4Smiod #define DEFAULT_SECTION_ALIGNMENT 4
220*3d8817e4Smiod 
221*3d8817e4Smiod /* The ldhdr structure.  This appears at the start of the .loader
222*3d8817e4Smiod    section.  */
223*3d8817e4Smiod 
224*3d8817e4Smiod struct external_ldhdr
225*3d8817e4Smiod {
226*3d8817e4Smiod   bfd_byte l_version[4];
227*3d8817e4Smiod   bfd_byte l_nsyms[4];
228*3d8817e4Smiod   bfd_byte l_nreloc[4];
229*3d8817e4Smiod   bfd_byte l_istlen[4];
230*3d8817e4Smiod   bfd_byte l_nimpid[4];
231*3d8817e4Smiod   bfd_byte l_impoff[4];
232*3d8817e4Smiod   bfd_byte l_stlen[4];
233*3d8817e4Smiod   bfd_byte l_stoff[4];
234*3d8817e4Smiod };
235*3d8817e4Smiod 
236*3d8817e4Smiod #define LDHDRSZ (8 * 4)
237*3d8817e4Smiod 
238*3d8817e4Smiod struct external_ldsym
239*3d8817e4Smiod {
240*3d8817e4Smiod   union
241*3d8817e4Smiod     {
242*3d8817e4Smiod       bfd_byte _l_name[SYMNMLEN];
243*3d8817e4Smiod       struct
244*3d8817e4Smiod 	{
245*3d8817e4Smiod 	  bfd_byte _l_zeroes[4];
246*3d8817e4Smiod 	  bfd_byte _l_offset[4];
247*3d8817e4Smiod 	} _l_l;
248*3d8817e4Smiod     } _l;
249*3d8817e4Smiod   bfd_byte l_value[4];
250*3d8817e4Smiod   bfd_byte l_scnum[2];
251*3d8817e4Smiod   bfd_byte l_smtype[1];
252*3d8817e4Smiod   bfd_byte l_smclas[1];
253*3d8817e4Smiod   bfd_byte l_ifile[4];
254*3d8817e4Smiod   bfd_byte l_parm[4];
255*3d8817e4Smiod };
256*3d8817e4Smiod 
257*3d8817e4Smiod #define LDSYMSZ (8 + 3 * 4 + 2 + 2)
258*3d8817e4Smiod 
259*3d8817e4Smiod struct external_ldrel
260*3d8817e4Smiod {
261*3d8817e4Smiod   bfd_byte l_vaddr[4];
262*3d8817e4Smiod   bfd_byte l_symndx[4];
263*3d8817e4Smiod   bfd_byte l_rtype[2];
264*3d8817e4Smiod   bfd_byte l_rsecnm[2];
265*3d8817e4Smiod };
266*3d8817e4Smiod 
267*3d8817e4Smiod #define LDRELSZ (2 * 4 + 2 * 2)
268