1 /* Basic coff information for the PowerPC
2    Based on coff/rs6000.h, coff/i386.h and others.
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    Initial release: Kim Knuttila (krk@cygnus.com)  */
21 
22 /********************** FILE HEADER **********************/
23 
24 struct external_filehdr {
25   char f_magic[2];	/* magic number			*/
26   char f_nscns[2];	/* number of sections		*/
27   char f_timdat[4];	/* time & date stamp		*/
28   char f_symptr[4];	/* file pointer to symtab	*/
29   char f_nsyms[4];	/* number of symtab entries	*/
30   char f_opthdr[2];	/* sizeof(optional hdr)		*/
31   char f_flags[2];	/* flags			*/
32 };
33 
34 #define	FILHDR	struct external_filehdr
35 #define	FILHSZ	20
36 
37 /* Bits for f_flags:
38  *	F_RELFLG	relocation info stripped from file
39  *	F_EXEC		file is executable (no unresolved external references)
40  *	F_LNNO		line numbers stripped from file
41  *	F_LSYMS		local symbols stripped from file
42  *	F_AR32WR	file has byte ordering of an AR32WR machine (e.g. vax)
43  */
44 
45 #define F_RELFLG	(0x0001)
46 #define F_EXEC		(0x0002)
47 #define F_LNNO		(0x0004)
48 #define F_LSYMS		(0x0008)
49 
50 /* extra NT defines */
51 #define PPCMAGIC       0760         /* peeked on aa PowerPC Windows NT box */
52 #define DOSMAGIC       0x5a4d       /* from arm.h, i386.h */
53 #define NT_SIGNATURE   0x00004550   /* from arm.h, i386.h */
54 
55 /* from winnt.h */
56 #define IMAGE_NT_OPTIONAL_HDR_MAGIC        0x10b
57 
58 #define PPCBADMAG(x) ((x).f_magic != PPCMAGIC)
59 
60 /********************** AOUT "OPTIONAL HEADER" **********************/
61 
62 typedef struct
63 {
64   char 	magic[2];		/* type of file				*/
65   char	vstamp[2];		/* version stamp			*/
66   char	tsize[4];		/* text size in bytes, padded to FW bdry*/
67   char	dsize[4];		/* initialized data "  "		*/
68   char	bsize[4];		/* uninitialized data "   "		*/
69   char	entry[4];		/* entry pt.				*/
70   char 	text_start[4];		/* base of text used for this file */
71   char 	data_start[4];		/* base of data used for this file */
72 }
73 AOUTHDR;
74 
75 #define AOUTSZ 28
76 #define AOUTHDRSZ 28
77 
78 /********************** SECTION HEADER **********************/
79 
80 struct external_scnhdr {
81   char		s_name[8];	/* section name			    */
82   char		s_paddr[4];	/* physical address, aliased s_nlib */
83   char		s_vaddr[4];	/* virtual address	            */
84   char		s_size[4];	/* section size			    */
85   char		s_scnptr[4];	/* file ptr to raw data for section */
86   char		s_relptr[4];	/* file ptr to relocation	    */
87   char		s_lnnoptr[4];	/* file ptr to line numbers	    */
88   char		s_nreloc[2];	/* number of relocation entries	    */
89   char		s_nlnno[2];	/* number of line number entries    */
90   char		s_flags[4];	/* flags			    */
91 };
92 
93 #define	SCNHDR	struct external_scnhdr
94 #define	SCNHSZ	40
95 
96 /*
97  * names of "special" sections
98  */
99 #define _TEXT	".text"
100 #define _DATA	".data"
101 #define _BSS	".bss"
102 #define _COMMENT ".comment"
103 #define _LIB ".lib"
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  */
112 struct 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 #define	LINENO	struct external_lineno
121 #define	LINESZ	6
122 
123 /********************** SYMBOLS **********************/
124 
125 #define E_SYMNMLEN	8     /* # characters in a symbol name       */
126 
127 /* Allow the file name length to be overridden in the including file   */
128 #ifndef E_FILNMLEN
129 #define E_FILNMLEN	14
130 #endif
131 
132 #define E_DIMNUM	4     /* # array dimensions in auxiliary entry */
133 
134 struct external_syment
135 {
136   union {
137     char e_name[E_SYMNMLEN];
138     struct {
139       char e_zeroes[4];
140       char e_offset[4];
141     } e;
142   } e;
143   char e_value[4];
144   char e_scnum[2];
145   char e_type[2];
146   char e_sclass[1];
147   char e_numaux[1];
148 };
149 
150 #define	SYMENT	struct external_syment
151 #define	SYMESZ	18
152 
153 #define N_BTMASK	(0xf)
154 #define N_TMASK		(0x30)
155 #define N_BTSHFT	(4)
156 #define N_TSHIFT	(2)
157 
158 union external_auxent {
159   struct {
160     char x_tagndx[4];	           /* str, un, or enum tag indx       */
161     union {
162       struct {
163 	char  x_lnno[2];           /* declaration line number         */
164 	char  x_size[2];           /* str/union/array size            */
165       } x_lnsz;
166       char x_fsize[4];	           /* size of function                */
167     } x_misc;
168     union {
169       struct {		           /* if ISFCN, tag, or .bb           */
170 	char x_lnnoptr[4];         /* ptr to fcn line #               */
171 	char x_endndx[4];	   /* entry ndx past block end        */
172       } x_fcn;
173       struct {		           /* if ISARY, up to 4 dimen.        */
174 	char x_dimen[E_DIMNUM][2];
175       } x_ary;
176     } x_fcnary;
177     char x_tvndx[2];		   /* tv index                        */
178   } x_sym;
179 
180   union {
181     char x_fname[E_FILNMLEN];
182     struct {
183       char x_zeroes[4];
184       char x_offset[4];
185     } x_n;
186   } x_file;
187 
188   struct {
189     char x_scnlen[4];	           /* section length                  */
190     char x_nreloc[2];	           /* # relocation entries            */
191     char x_nlinno[2];	           /* # line numbers                  */
192     char x_checksum[4];		   /* section COMDAT checksum	      */
193     char x_associated[2];	   /* COMDAT associated section index */
194     char x_comdat[1];		   /* COMDAT selection number	      */
195   } x_scn;
196 };
197 
198 #define	AUXENT	union external_auxent
199 #define	AUXESZ	18
200 
201 #define _ETEXT	"etext"
202 
203 /********************** RELOCATION DIRECTIVES **********************/
204 
205 struct external_reloc {
206   char r_vaddr[4];
207   char r_symndx[4];
208   char r_type[2];
209 };
210 
211 #define RELOC struct external_reloc
212 #define RELSZ 10
213 
214