1 /* coff information for TI TMS320C80 (MVP)
2 
3    Copyright 2001 Free Software Foundation, Inc.
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18 
19 /********************** FILE HEADER **********************/
20 
21 struct external_filehdr {
22 	char f_magic[2];	/* magic number			*/
23 	char f_nscns[2];	/* number of sections		*/
24 	char f_timdat[4];	/* time & date stamp		*/
25 	char f_symptr[4];	/* file pointer to symtab	*/
26 	char f_nsyms[4];	/* number of symtab entries	*/
27 	char f_opthdr[2];	/* sizeof(optional hdr)		*/
28 	char f_flags[2];	/* flags			*/
29 	char f_target_id[2];	/* target id (TIc80 specific)	*/
30 };
31 
32 #define	TIC80_ARCH_MAGIC	0x0C1	/* Goes in the file header magic number field */
33 #define TIC80_TARGET_ID		0x95	/* Goes in the target id field */
34 
35 #define TIC80BADMAG(x) ((x).f_magic != TIC80_ARCH_MAGIC)
36 
37 #define	FILHDR	struct external_filehdr
38 #define	FILHSZ	22
39 
40 
41 /********************** AOUT "OPTIONAL HEADER" **********************/
42 
43 
44 typedef struct
45 {
46   char 	magic[2];		/* type of file				*/
47   char	vstamp[2];		/* version stamp			*/
48   char	tsize[4];		/* text size in bytes, padded to FW bdry*/
49   char	dsize[4];		/* initialized data "  "		*/
50   char	bsize[4];		/* uninitialized data "   "		*/
51   char	entry[4];		/* entry pt.				*/
52   char 	text_start[4];		/* base of text used for this file */
53   char 	data_start[4];		/* base of data used for this file */
54 }
55 AOUTHDR;
56 
57 #define TIC80_AOUTHDR_MAGIC	0x108	/* Goes in the optional file header magic number field */
58 
59 #define AOUTHDRSZ 28
60 #define AOUTSZ 28
61 
62 
63 
64 
65 /********************** SECTION HEADER **********************/
66 
67 
68 struct external_scnhdr {
69 	char		s_name[8];	/* section name			*/
70 	char		s_paddr[4];	/* physical address, aliased s_nlib */
71 	char		s_vaddr[4];	/* virtual address		*/
72 	char		s_size[4];	/* section size			*/
73 	char		s_scnptr[4];	/* file ptr to raw data for section */
74 	char		s_relptr[4];	/* file ptr to relocation	*/
75 	char		s_lnnoptr[4];	/* file ptr to line numbers	*/
76 	char		s_nreloc[2];	/* number of relocation entries	*/
77 	char		s_nlnno[2];	/* number of line number entries*/
78 	char		s_flags[2];	/* flags			*/
79 	char		s_reserved[1];	/* reserved (TIc80 specific)	*/
80 	char		s_mempage[1];	/* memory page number (TIc80)	*/
81 };
82 
83 /*
84  * names of "special" sections
85  */
86 #define _TEXT	".text"
87 #define _DATA	".data"
88 #define _BSS	".bss"
89 #define _CINIT	".cinit"
90 #define _CONST	".const"
91 #define _SWITCH	".switch"
92 #define _STACK	".stack"
93 #define _SYSMEM	".sysmem"
94 
95 
96 #define	SCNHDR	struct external_scnhdr
97 #define	SCNHSZ	40
98 
99 
100 /********************** LINE NUMBERS **********************/
101 
102 /* 1 line number entry for every "breakpointable" source line in a section.
103  * Line numbers are grouped on a per function basis; first entry in a function
104  * grouping will have l_lnno = 0 and in place of physical address will be the
105  * symbol table index of the function name.
106  */
107 struct external_lineno {
108 	union {
109 		char l_symndx[4];	/* function name symbol index, iff l_lnno == 0*/
110 		char l_paddr[4];	/* (physical) address of line number	*/
111 	} l_addr;
112 	char l_lnno[2];			/* line number	*/
113 };
114 
115 #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
116 #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val,  (bfd_byte *) (ext->l_lnno));
117 
118 #define	LINENO	struct external_lineno
119 #define	LINESZ	6
120 
121 
122 /********************** SYMBOLS **********************/
123 
124 #define E_SYMNMLEN	8	/* # characters in a symbol name	*/
125 #define E_FILNMLEN	14	/* # characters in a file name		*/
126 #define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
127 
128 struct external_syment
129 {
130   union {
131     char e_name[E_SYMNMLEN];
132     struct {
133       char e_zeroes[4];
134       char e_offset[4];
135     } e;
136   } e;
137   char e_value[4];
138   char e_scnum[2];
139   char e_type[2];
140   char e_sclass[1];
141   char e_numaux[1];
142 };
143 
144 
145 
146 #define N_BTMASK	(017)
147 #define N_TMASK		(060)
148 #define N_BTSHFT	(4)
149 #define N_TSHIFT	(2)
150 
151 /* FIXME - need to correlate with TIc80 Code Generation Tools User's Guide, CG:A-25 */
152 union external_auxent {
153 	struct {
154 		char x_tagndx[4];	/* str, un, or enum tag indx */
155 		union {
156 			struct {
157 			    char  x_lnno[2]; /* declaration line number */
158 			    char  x_size[2]; /* str/union/array size */
159 			} x_lnsz;
160 			char x_fsize[4];	/* size of function */
161 		} x_misc;
162 		union {
163 			struct {		/* if ISFCN, tag, or .bb */
164 			    char x_lnnoptr[4];	/* ptr to fcn line # */
165 			    char x_endndx[4];	/* entry ndx past block end */
166 			} x_fcn;
167 			struct {		/* if ISARY, up to 4 dimen. */
168 			    char x_dimen[E_DIMNUM][2];
169 			} x_ary;
170 		} x_fcnary;
171 		char x_tvndx[2];		/* tv index */
172 	} x_sym;
173 
174 	union {
175 		char x_fname[E_FILNMLEN];
176 		struct {
177 			char x_zeroes[4];
178 			char x_offset[4];
179 		} x_n;
180 	} x_file;
181 
182 	struct {
183 		char x_scnlen[4];			/* section length */
184 		char x_nreloc[2];	/* # relocation entries */
185 		char x_nlinno[2];	/* # line numbers */
186 	} x_scn;
187 
188         struct {
189 		char x_tvfill[4];	/* tv fill value */
190 		char x_tvlen[2];	/* length of .tv */
191 		char x_tvran[2][2];	/* tv range */
192 	} x_tv;		/* info about .tv section (in auxent of symbol .tv)) */
193 
194 
195 };
196 
197 #define	SYMENT	struct external_syment
198 #define	SYMESZ	18
199 #define	AUXENT	union external_auxent
200 #define	AUXESZ	18
201 
202 
203 
204 /********************** RELOCATION DIRECTIVES **********************/
205 
206 /* The external reloc has an offset field, because some of the reloc
207    types on the h8 don't have room in the instruction for the entire
208    offset - eg the strange jump and high page addressing modes */
209 
210 struct external_reloc {
211   char r_vaddr[4];
212   char r_symndx[4];
213   char r_reserved[2];
214   char r_type[2];
215 };
216 
217 
218 #define RELOC struct external_reloc
219 #define RELSZ 12
220 
221 /* TIc80 relocation types. */
222 
223 #define R_ABS		0x00		/* Absolute address - no relocation */
224 #define R_RELLONGX	0x11		/* PP: 32 bits, direct */
225 #define R_PPBASE	0x34		/* PP: Global base address type */
226 #define R_PPLBASE	0x35		/* PP: Local base address type */
227 #define R_PP15		0x38		/* PP: Global 15 bit offset */
228 #define R_PP15W		0x39		/* PP: Global 15 bit offset divided by 4 */
229 #define R_PP15H		0x3A		/* PP: Global 15 bit offset divided by 2 */
230 #define R_PP16B		0x3B		/* PP: Global 16 bit offset for bytes */
231 #define R_PPL15		0x3C		/* PP: Local 15 bit offset */
232 #define R_PPL15W	0x3D		/* PP: Local 15 bit offset divided by 4 */
233 #define R_PPL15H	0x3E		/* PP: Local 15 bit offset divided by 2 */
234 #define R_PPL16B	0x3F		/* PP: Local 16 bit offset for bytes */
235 #define R_PPN15		0x40		/* PP: Global 15 bit negative offset */
236 #define R_PPN15W	0x41		/* PP: Global 15 bit negative offset divided by 4 */
237 #define R_PPN15H	0x42		/* PP: Global 15 bit negative offset divided by 2 */
238 #define R_PPN16B	0x43		/* PP: Global 16 bit negative byte offset */
239 #define R_PPLN15	0x44		/* PP: Local 15 bit negative offset */
240 #define R_PPLN15W	0x45		/* PP: Local 15 bit negative offset divided by 4 */
241 #define R_PPLN15H	0x46		/* PP: Local 15 bit negative offset divided by 2 */
242 #define R_PPLN16B	0x47		/* PP: Local 16 bit negative byte offset */
243 #define R_MPPCR15W	0x4E		/* MP: 15 bit PC-relative divided by 4 */
244 #define R_MPPCR		0x4F		/* MP: 32 bit PC-relative divided by 4 */
245