1
2
3/********************** FILE HEADER **********************/
4
5struct external_filehdr {
6	char f_magic[2];	/* magic number			*/
7	char f_nscns[2];	/* number of sections		*/
8	char f_timdat[4];	/* time & date stamp		*/
9	char f_symptr[4];	/* file pointer to symtab	*/
10	char f_nsyms[4];	/* number of symtab entries	*/
11	char f_opthdr[2];	/* sizeof(optional hdr)		*/
12	char f_flags[2];	/* flags			*/
13};
14
15        /* IBM RS/6000 */
16#define U802WRMAGIC     0730    /* writeable text segments **chh**      */
17#define U802ROMAGIC     0735    /* readonly sharable text segments      */
18#define U802TOCMAGIC    0737    /* readonly text segments and TOC       */
19
20#define BADMAG(x)	\
21	((x).f_magic != U802ROMAGIC && (x).f_magic != U802WRMAGIC && \
22	 (x).f_magic != U802TOCMAGIC)
23
24#define	FILHDR	struct external_filehdr
25#define	FILHSZ	20
26
27
28/********************** AOUT "OPTIONAL HEADER" **********************/
29
30
31typedef struct
32{
33  unsigned char	magic[2];	/* type of file			*/
34  unsigned char	vstamp[2];	/* version stamp		*/
35  unsigned char	tsize[4];	/* text size in bytes, padded to FW bdry */
36  unsigned char	dsize[4];	/* initialized data "  "	*/
37  unsigned char	bsize[4];	/* uninitialized data "   "	*/
38  unsigned char	entry[4];	/* entry pt.			*/
39  unsigned char	text_start[4];	/* base of text used for this file */
40  unsigned char	data_start[4];	/* base of data used for this file */
41  unsigned char	o_toc[4];	/* address of TOC */
42  unsigned char	o_snentry[2];	/* section number of entry point */
43  unsigned char	o_sntext[2];	/* section number of .text section */
44  unsigned char	o_sndata[2];	/* section number of .data section */
45  unsigned char	o_sntoc[2];	/* section number of TOC */
46  unsigned char	o_snloader[2];	/* section number of .loader section */
47  unsigned char	o_snbss[2];	/* section number of .bss section */
48  unsigned char	o_algntext[2];	/* .text alignment */
49  unsigned char	o_algndata[2];	/* .data alignment */
50  unsigned char	o_modtype[2];	/* module type (??) */
51  unsigned char o_cputype[2];	/* cpu type */
52  unsigned char	o_maxstack[4];	/* max stack size (??) */
53  unsigned char o_maxdata[4];	/* max data size (??) */
54  unsigned char	o_resv2[12];	/* reserved */
55}
56AOUTHDR;
57
58#define AOUTSZ 72
59#define SMALL_AOUTSZ (28)
60#define AOUTHDRSZ 72
61
62#define	RS6K_AOUTHDR_OMAGIC	0x0107	/* old: text & data writeable */
63#define	RS6K_AOUTHDR_NMAGIC	0x0108	/* new: text r/o, data r/w */
64#define	RS6K_AOUTHDR_ZMAGIC	0x010B	/* paged: text r/o, both page-aligned */
65
66
67/********************** SECTION HEADER **********************/
68
69
70struct external_scnhdr {
71	char		s_name[8];	/* section name			*/
72	char		s_paddr[4];	/* physical address, aliased s_nlib */
73	char		s_vaddr[4];	/* virtual address		*/
74	char		s_size[4];	/* section size			*/
75	char		s_scnptr[4];	/* file ptr to raw data for section */
76	char		s_relptr[4];	/* file ptr to relocation	*/
77	char		s_lnnoptr[4];	/* file ptr to line numbers	*/
78	char		s_nreloc[2];	/* number of relocation entries	*/
79	char		s_nlnno[2];	/* number of line number entries*/
80	char		s_flags[4];	/* flags			*/
81};
82
83/*
84 * names of "special" sections
85 */
86#define _TEXT	".text"
87#define _DATA	".data"
88#define _BSS	".bss"
89#define _PAD	".pad"
90#define _LOADER	".loader"
91
92#define	SCNHDR	struct external_scnhdr
93#define	SCNHSZ	40
94
95/* XCOFF uses a special .loader section with type STYP_LOADER.  */
96#define STYP_LOADER 0x1000
97
98/* XCOFF uses a special .debug section with type STYP_DEBUG.  */
99#define STYP_DEBUG 0x2000
100
101/* XCOFF handles line number or relocation overflow by creating
102   another section header with STYP_OVRFLO set.  */
103#define STYP_OVRFLO 0x8000
104
105/********************** LINE NUMBERS **********************/
106
107/* 1 line number entry for every "breakpointable" source line in a section.
108 * Line numbers are grouped on a per function basis; first entry in a function
109 * grouping will have l_lnno = 0 and in place of physical address will be the
110 * symbol table index of the function name.
111 */
112struct external_lineno {
113	union {
114		char l_symndx[4];	/* function name symbol index, iff l_lnno == 0*/
115		char l_paddr[4];	/* (physical) address of line number	*/
116	} l_addr;
117	char l_lnno[2];	/* line number		*/
118};
119
120
121#define	LINENO	struct external_lineno
122#define	LINESZ	6
123
124
125/********************** SYMBOLS **********************/
126
127#define E_SYMNMLEN	8	/* # characters in a symbol name	*/
128#define E_FILNMLEN	14	/* # characters in a file name		*/
129#define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
130
131struct external_syment
132{
133  union {
134    char e_name[E_SYMNMLEN];
135    struct {
136      char e_zeroes[4];
137      char e_offset[4];
138    } e;
139  } e;
140  char e_value[4];
141  char e_scnum[2];
142  char e_type[2];
143  char e_sclass[1];
144  char e_numaux[1];
145};
146
147
148
149#define N_BTMASK	(017)
150#define N_TMASK		(060)
151#define N_BTSHFT	(4)
152#define N_TSHIFT	(2)
153
154
155union external_auxent {
156	struct {
157		char x_tagndx[4];	/* str, un, or enum tag indx */
158		union {
159			struct {
160			    char  x_lnno[2]; /* declaration line number */
161			    char  x_size[2]; /* str/union/array size */
162			} x_lnsz;
163			char x_fsize[4];	/* size of function */
164		} x_misc;
165		union {
166			struct {		/* if ISFCN, tag, or .bb */
167			    char x_lnnoptr[4];	/* ptr to fcn line # */
168			    char x_endndx[4];	/* entry ndx past block end */
169			} x_fcn;
170			struct {		/* if ISARY, up to 4 dimen. */
171			    char x_dimen[E_DIMNUM][2];
172			} x_ary;
173		} x_fcnary;
174		char x_tvndx[2];		/* tv index */
175	} x_sym;
176
177	union {
178		char x_fname[E_FILNMLEN];
179		struct {
180			char x_zeroes[4];
181			char x_offset[4];
182		} x_n;
183	} x_file;
184
185	struct {
186		char x_scnlen[4];			/* section length */
187		char x_nreloc[2];	/* # relocation entries */
188		char x_nlinno[2];	/* # line numbers */
189	} x_scn;
190
191        struct {
192		char x_tvfill[4];	/* tv fill value */
193		char x_tvlen[2];	/* length of .tv */
194		char x_tvran[2][2];	/* tv range */
195	} x_tv;		/* info about .tv section (in auxent of symbol .tv)) */
196
197	struct {
198		unsigned char x_scnlen[4];
199		unsigned char x_parmhash[4];
200		unsigned char x_snhash[2];
201		unsigned char x_smtyp[1];
202		unsigned char x_smclas[1];
203		unsigned char x_stab[4];
204		unsigned char x_snstab[2];
205	} x_csect;
206
207};
208
209#define	SYMENT	struct external_syment
210#define	SYMESZ	18
211#define	AUXENT	union external_auxent
212#define	AUXESZ	18
213#define DBXMASK 0x80		/* for dbx storage mask */
214#define SYMNAME_IN_DEBUG(symptr) ((symptr)->n_sclass & DBXMASK)
215
216
217
218/********************** RELOCATION DIRECTIVES **********************/
219
220
221struct external_reloc {
222  char r_vaddr[4];
223  char r_symndx[4];
224  char r_size[1];
225  char r_type[1];
226};
227
228
229#define RELOC struct external_reloc
230#define RELSZ 10
231
232#define DEFAULT_DATA_SECTION_ALIGNMENT 4
233#define DEFAULT_BSS_SECTION_ALIGNMENT 4
234#define DEFAULT_TEXT_SECTION_ALIGNMENT 4
235/* For new sections we havn't heard of before */
236#define DEFAULT_SECTION_ALIGNMENT 4
237