xref: /openbsd-src/gnu/usr.bin/binutils-2.17/include/coff/ti.h (revision 3d8817e467ea46cf4772788d6804dd293abfb01a)
1*3d8817e4Smiod /* COFF information for TI COFF support.  Definitions in this file should be
2*3d8817e4Smiod    customized in a target-specific file, and then this file included (see
3*3d8817e4Smiod    tic54x.h for an example).
4*3d8817e4Smiod 
5*3d8817e4Smiod    Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
6*3d8817e4Smiod 
7*3d8817e4Smiod    This program is free software; you can redistribute it and/or modify
8*3d8817e4Smiod    it under the terms of the GNU General Public License as published by
9*3d8817e4Smiod    the Free Software Foundation; either version 2 of the License, or
10*3d8817e4Smiod    (at your option) any later version.
11*3d8817e4Smiod 
12*3d8817e4Smiod    This program is distributed in the hope that it will be useful,
13*3d8817e4Smiod    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*3d8817e4Smiod    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*3d8817e4Smiod    GNU General Public License for more details.
16*3d8817e4Smiod 
17*3d8817e4Smiod    You should have received a copy of the GNU General Public License
18*3d8817e4Smiod    along with this program; if not, write to the Free Software
19*3d8817e4Smiod    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
20*3d8817e4Smiod #ifndef COFF_TI_H
21*3d8817e4Smiod #define COFF_TI_H
22*3d8817e4Smiod 
23*3d8817e4Smiod /* Note "coff/external.h is not used because TI adds extra fields to the structures.  */
24*3d8817e4Smiod 
25*3d8817e4Smiod /********************** FILE HEADER **********************/
26*3d8817e4Smiod 
27*3d8817e4Smiod struct external_filehdr
28*3d8817e4Smiod   {
29*3d8817e4Smiod     char f_magic[2];	/* magic number			*/
30*3d8817e4Smiod     char f_nscns[2];	/* number of sections		*/
31*3d8817e4Smiod     char f_timdat[4];	/* time & date stamp		*/
32*3d8817e4Smiod     char f_symptr[4];	/* file pointer to symtab	*/
33*3d8817e4Smiod     char f_nsyms[4];	/* number of symtab entries	*/
34*3d8817e4Smiod     char f_opthdr[2];	/* sizeof(optional hdr)		*/
35*3d8817e4Smiod     char f_flags[2];	/* flags			*/
36*3d8817e4Smiod     char f_target_id[2];    /* magic no. (TI COFF-specific) */
37*3d8817e4Smiod   };
38*3d8817e4Smiod 
39*3d8817e4Smiod /* COFF0 has magic number in f_magic, and omits f_target_id from the file
40*3d8817e4Smiod    header; for later versions, f_magic is 0xC1 for COFF1 and 0xC2 for COFF2
41*3d8817e4Smiod    and the target-specific magic number is found in f_target_id */
42*3d8817e4Smiod 
43*3d8817e4Smiod #define TICOFF0MAGIC    TI_TARGET_ID
44*3d8817e4Smiod #define TICOFF1MAGIC    0x00C1
45*3d8817e4Smiod #define TICOFF2MAGIC    0x00C2
46*3d8817e4Smiod #define TICOFF_AOUT_MAGIC    0x0108 /* magic number in optional header */
47*3d8817e4Smiod #define TICOFF          1 /* customize coffcode.h */
48*3d8817e4Smiod 
49*3d8817e4Smiod /* The target_id field changes depending on the particular CPU target */
50*3d8817e4Smiod /* for COFF0, the target id appeared in f_magic, where COFFX magic is now */
51*3d8817e4Smiod #ifndef TI_TARGET_ID
52*3d8817e4Smiod #error "TI_TARGET_ID needs to be defined for your CPU"
53*3d8817e4Smiod #endif
54*3d8817e4Smiod 
55*3d8817e4Smiod /* Which bfd_arch to use... */
56*3d8817e4Smiod #ifndef TICOFF_TARGET_ARCH
57*3d8817e4Smiod #error "TICOFF_TARGET_ARCH needs to be defined for your CPU"
58*3d8817e4Smiod #endif
59*3d8817e4Smiod 
60*3d8817e4Smiod #ifndef TICOFF_TARGET_MACHINE_GET
61*3d8817e4Smiod #define TICOFF_TARGET_MACHINE_GET(FLAGS) 0
62*3d8817e4Smiod #endif
63*3d8817e4Smiod 
64*3d8817e4Smiod #ifndef TICOFF_TARGET_MACHINE_SET
65*3d8817e4Smiod #define TICOFF_TARGET_MACHINE_SET(FLAGSP, MACHINE)
66*3d8817e4Smiod #endif
67*3d8817e4Smiod 
68*3d8817e4Smiod /* Default to COFF2 for file output */
69*3d8817e4Smiod #ifndef TICOFF_DEFAULT_MAGIC
70*3d8817e4Smiod #define TICOFF_DEFAULT_MAGIC TICOFF2MAGIC
71*3d8817e4Smiod #endif
72*3d8817e4Smiod 
73*3d8817e4Smiod /* This value is made available in the rare case where a bfd is unavailable */
74*3d8817e4Smiod #ifndef OCTETS_PER_BYTE_POWER
75*3d8817e4Smiod #error "OCTETS_PER_BYTE_POWER not defined for this CPU"
76*3d8817e4Smiod #else
77*3d8817e4Smiod #define OCTETS_PER_BYTE (1<<OCTETS_PER_BYTE_POWER)
78*3d8817e4Smiod #endif
79*3d8817e4Smiod 
80*3d8817e4Smiod /* default alignment is on a byte (not octet!) boundary */
81*3d8817e4Smiod #ifndef COFF_DEFAULT_SECTION_ALIGNMENT_POWER
82*3d8817e4Smiod #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 0
83*3d8817e4Smiod #endif
84*3d8817e4Smiod 
85*3d8817e4Smiod /* TI COFF encodes the section alignment in the section header flags */
86*3d8817e4Smiod #define COFF_ALIGN_IN_SECTION_HEADER 1
87*3d8817e4Smiod #define COFF_ALIGN_IN_S_FLAGS 1
88*3d8817e4Smiod /* requires a power-of-two argument */
89*3d8817e4Smiod #define COFF_ENCODE_ALIGNMENT(S,X) ((S).s_flags |= (((unsigned)(X)&0xF)<<8))
90*3d8817e4Smiod /* result is a power of two */
91*3d8817e4Smiod #define COFF_DECODE_ALIGNMENT(X) (((X)>>8)&0xF)
92*3d8817e4Smiod 
93*3d8817e4Smiod #define COFF0_P(ABFD) (bfd_coff_filhsz(ABFD) == FILHSZ_V0)
94*3d8817e4Smiod #define COFF2_P(ABFD) (bfd_coff_scnhsz(ABFD) != SCNHSZ_V01)
95*3d8817e4Smiod 
96*3d8817e4Smiod #define COFF0_BADMAG(x) ((x).f_magic != TICOFF0MAGIC)
97*3d8817e4Smiod #define COFF1_BADMAG(x) ((x).f_magic != TICOFF1MAGIC || (x).f_target_id != TI_TARGET_ID)
98*3d8817e4Smiod #define COFF2_BADMAG(x) ((x).f_magic != TICOFF2MAGIC || (x).f_target_id != TI_TARGET_ID)
99*3d8817e4Smiod 
100*3d8817e4Smiod /* we need to read/write an extra field in the coff file header */
101*3d8817e4Smiod #ifndef COFF_ADJUST_FILEHDR_IN_POST
102*3d8817e4Smiod #define COFF_ADJUST_FILEHDR_IN_POST(abfd, src, dst) \
103*3d8817e4Smiod   do									\
104*3d8817e4Smiod     {									\
105*3d8817e4Smiod       ((struct internal_filehdr *)(dst))->f_target_id =			\
106*3d8817e4Smiod 	H_GET_16 (abfd, ((FILHDR *)(src))->f_target_id);		\
107*3d8817e4Smiod     }									\
108*3d8817e4Smiod   while (0)
109*3d8817e4Smiod #endif
110*3d8817e4Smiod 
111*3d8817e4Smiod #ifndef COFF_ADJUST_FILEHDR_OUT_POST
112*3d8817e4Smiod #define COFF_ADJUST_FILEHDR_OUT_POST(abfd, src, dst) \
113*3d8817e4Smiod   do									\
114*3d8817e4Smiod     {									\
115*3d8817e4Smiod       H_PUT_16 (abfd, ((struct internal_filehdr *)(src))->f_target_id,	\
116*3d8817e4Smiod 	       ((FILHDR *)(dst))->f_target_id);				\
117*3d8817e4Smiod     }									\
118*3d8817e4Smiod   while (0)
119*3d8817e4Smiod #endif
120*3d8817e4Smiod 
121*3d8817e4Smiod #define	FILHDR	struct external_filehdr
122*3d8817e4Smiod #define	FILHSZ	22
123*3d8817e4Smiod #define FILHSZ_V0 20                /* COFF0 omits target_id field */
124*3d8817e4Smiod 
125*3d8817e4Smiod /* File header flags */
126*3d8817e4Smiod #define	F_RELFLG	(0x0001)
127*3d8817e4Smiod #define	F_EXEC		(0x0002)
128*3d8817e4Smiod #define	F_LNNO		(0x0004)
129*3d8817e4Smiod #define F_VERS          (0x0010) /* TMS320C4x code */
130*3d8817e4Smiod /* F_LSYMS needs to be redefined in your source file */
131*3d8817e4Smiod #define	F_LSYMS_TICOFF	(0x0010) /* normal COFF is 0x8 */
132*3d8817e4Smiod 
133*3d8817e4Smiod #define F_10            0x00    /* file built for TMS320C1x devices */
134*3d8817e4Smiod #define F_20            0x10    /* file built for TMS320C2x devices */
135*3d8817e4Smiod #define F_25            0x20    /* file built for TMS320C2x/C5x devices */
136*3d8817e4Smiod #define F_LENDIAN       0x0100  /* 16 bits/word, LSB first */
137*3d8817e4Smiod #define F_SYMMERGE      0x1000  /* duplicate symbols were removed */
138*3d8817e4Smiod 
139*3d8817e4Smiod /********************** OPTIONAL HEADER **********************/
140*3d8817e4Smiod 
141*3d8817e4Smiod 
142*3d8817e4Smiod typedef struct
143*3d8817e4Smiod {
144*3d8817e4Smiod   char 	magic[2];		/* type of file (0x108) 		*/
145*3d8817e4Smiod   char	vstamp[2];		/* version stamp			*/
146*3d8817e4Smiod   char	tsize[4];		/* text size in bytes, padded to FW bdry*/
147*3d8817e4Smiod   char	dsize[4];		/* initialized data "  "		*/
148*3d8817e4Smiod   char	bsize[4];		/* uninitialized data "   "		*/
149*3d8817e4Smiod   char	entry[4];		/* entry pt.				*/
150*3d8817e4Smiod   char 	text_start[4];		/* base of text used for this file */
151*3d8817e4Smiod   char 	data_start[4];		/* base of data used for this file */
152*3d8817e4Smiod }
153*3d8817e4Smiod AOUTHDR;
154*3d8817e4Smiod 
155*3d8817e4Smiod 
156*3d8817e4Smiod #define AOUTHDRSZ 28
157*3d8817e4Smiod #define AOUTSZ 28
158*3d8817e4Smiod 
159*3d8817e4Smiod 
160*3d8817e4Smiod /********************** SECTION HEADER **********************/
161*3d8817e4Smiod /* COFF0, COFF1 */
162*3d8817e4Smiod struct external_scnhdr_v01 {
163*3d8817e4Smiod 	char		s_name[8];	/* section name			*/
164*3d8817e4Smiod 	char		s_paddr[4];	/* physical address, aliased s_nlib */
165*3d8817e4Smiod 	char		s_vaddr[4];	/* virtual address		*/
166*3d8817e4Smiod 	char		s_size[4];	/* section size (in WORDS)      */
167*3d8817e4Smiod 	char		s_scnptr[4];	/* file ptr to raw data for section */
168*3d8817e4Smiod 	char		s_relptr[4];	/* file ptr to relocation	*/
169*3d8817e4Smiod 	char		s_lnnoptr[4];	/* file ptr to line numbers	*/
170*3d8817e4Smiod 	char		s_nreloc[2];	/* number of relocation entries	*/
171*3d8817e4Smiod 	char		s_nlnno[2];	/* number of line number entries*/
172*3d8817e4Smiod 	char		s_flags[2];	/* flags			*/
173*3d8817e4Smiod         char            s_reserved[1];  /* reserved                     */
174*3d8817e4Smiod         char            s_page[1];      /* section page number (LOAD)   */
175*3d8817e4Smiod };
176*3d8817e4Smiod 
177*3d8817e4Smiod /* COFF2 */
178*3d8817e4Smiod struct external_scnhdr {
179*3d8817e4Smiod 	char		s_name[8];	/* section name			*/
180*3d8817e4Smiod 	char		s_paddr[4];	/* physical address, aliased s_nlib */
181*3d8817e4Smiod 	char		s_vaddr[4];	/* virtual address		*/
182*3d8817e4Smiod 	char		s_size[4];	/* section size (in WORDS)      */
183*3d8817e4Smiod 	char		s_scnptr[4];	/* file ptr to raw data for section */
184*3d8817e4Smiod 	char		s_relptr[4];	/* file ptr to relocation	*/
185*3d8817e4Smiod 	char		s_lnnoptr[4];	/* file ptr to line numbers	*/
186*3d8817e4Smiod 	char		s_nreloc[4];	/* number of relocation entries	*/
187*3d8817e4Smiod 	char		s_nlnno[4];	/* number of line number entries*/
188*3d8817e4Smiod 	char		s_flags[4];	/* flags			*/
189*3d8817e4Smiod         char            s_reserved[2];  /* reserved                     */
190*3d8817e4Smiod         char            s_page[2];      /* section page number (LOAD)   */
191*3d8817e4Smiod };
192*3d8817e4Smiod 
193*3d8817e4Smiod /*
194*3d8817e4Smiod  * Special section flags
195*3d8817e4Smiod  */
196*3d8817e4Smiod 
197*3d8817e4Smiod /* TI COFF defines these flags;
198*3d8817e4Smiod    STYP_CLINK: the section should be excluded from the final
199*3d8817e4Smiod    linker output if there are no references found to any symbol in the section
200*3d8817e4Smiod    STYP_BLOCK: the section should be blocked, i.e. if the section would cross
201*3d8817e4Smiod    a page boundary, it is started at a page boundary instead.
202*3d8817e4Smiod    TI COFF puts the section alignment power of two in the section flags
203*3d8817e4Smiod    e.g. 2**N is alignment, flags |= (N & 0xF) << 8
204*3d8817e4Smiod */
205*3d8817e4Smiod #define STYP_CLINK      (0x4000)
206*3d8817e4Smiod #define STYP_BLOCK      (0x1000)
207*3d8817e4Smiod #define STYP_ALIGN      (0x0F00) /* TI COFF stores section alignment here */
208*3d8817e4Smiod 
209*3d8817e4Smiod #define	SCNHDR_V01 struct external_scnhdr_v01
210*3d8817e4Smiod #define SCNHDR struct external_scnhdr
211*3d8817e4Smiod #define	SCNHSZ_V01 40                  /* for v0 and v1 */
212*3d8817e4Smiod #define SCNHSZ 48
213*3d8817e4Smiod 
214*3d8817e4Smiod /* COFF2 changes the offsets and sizes of these fields
215*3d8817e4Smiod    Assume we're dealing with the COFF2 scnhdr structure, and adjust
216*3d8817e4Smiod    accordingly
217*3d8817e4Smiod  */
218*3d8817e4Smiod #define GET_SCNHDR_NRELOC(ABFD, LOC) \
219*3d8817e4Smiod   (COFF2_P (ABFD) ? H_GET_32 (ABFD, LOC) : H_GET_16 (ABFD, LOC))
220*3d8817e4Smiod #define PUT_SCNHDR_NRELOC(ABFD, VAL, LOC) \
221*3d8817e4Smiod   (COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, LOC))
222*3d8817e4Smiod #define GET_SCNHDR_NLNNO(ABFD, LOC) \
223*3d8817e4Smiod   (COFF2_P (ABFD) ? H_GET_32 (ABFD, LOC) : H_GET_16 (ABFD, (LOC) - 2))
224*3d8817e4Smiod #define PUT_SCNHDR_NLNNO(ABFD, VAL, LOC) \
225*3d8817e4Smiod   (COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, (LOC) - 2))
226*3d8817e4Smiod #define GET_SCNHDR_FLAGS(ABFD, LOC) \
227*3d8817e4Smiod   (COFF2_P (ABFD) ? H_GET_32 (ABFD, LOC) : H_GET_16 (ABFD, (LOC) - 4))
228*3d8817e4Smiod #define PUT_SCNHDR_FLAGS(ABFD, VAL, LOC) \
229*3d8817e4Smiod   (COFF2_P (ABFD) ? H_PUT_32 (ABFD, VAL, LOC) : H_PUT_16 (ABFD, VAL, (LOC) - 4))
230*3d8817e4Smiod #define GET_SCNHDR_PAGE(ABFD, LOC) \
231*3d8817e4Smiod   (COFF2_P (ABFD) ? H_GET_16 (ABFD, LOC) : (unsigned) H_GET_8 (ABFD, (LOC) - 7))
232*3d8817e4Smiod /* on output, make sure that the "reserved" field is zero */
233*3d8817e4Smiod #define PUT_SCNHDR_PAGE(ABFD, VAL, LOC) \
234*3d8817e4Smiod   (COFF2_P (ABFD) \
235*3d8817e4Smiod    ? H_PUT_16 (ABFD, VAL, LOC) \
236*3d8817e4Smiod    : H_PUT_8 (ABFD, VAL, (LOC) - 7), H_PUT_8 (ABFD, 0, (LOC) - 8))
237*3d8817e4Smiod 
238*3d8817e4Smiod /* TI COFF stores section size as number of bytes (address units, not octets),
239*3d8817e4Smiod    so adjust to be number of octets, which is what BFD expects */
240*3d8817e4Smiod #define GET_SCNHDR_SIZE(ABFD, SZP) \
241*3d8817e4Smiod   (H_GET_32 (ABFD, SZP) * bfd_octets_per_byte (ABFD))
242*3d8817e4Smiod #define PUT_SCNHDR_SIZE(ABFD, SZ, SZP) \
243*3d8817e4Smiod   H_PUT_32 (ABFD, (SZ) / bfd_octets_per_byte (ABFD), SZP)
244*3d8817e4Smiod 
245*3d8817e4Smiod #define COFF_ADJUST_SCNHDR_IN_POST(ABFD, EXT, INT) \
246*3d8817e4Smiod   do									\
247*3d8817e4Smiod     {									\
248*3d8817e4Smiod       ((struct internal_scnhdr *)(INT))->s_page =			\
249*3d8817e4Smiod 	GET_SCNHDR_PAGE (ABFD, ((SCNHDR *)(EXT))->s_page);		\
250*3d8817e4Smiod     }									\
251*3d8817e4Smiod    while (0)
252*3d8817e4Smiod 
253*3d8817e4Smiod /* The line number and reloc overflow checking in coff_swap_scnhdr_out in
254*3d8817e4Smiod    coffswap.h doesn't use PUT_X for s_nlnno and s_nreloc.
255*3d8817e4Smiod    Due to different sized v0/v1/v2 section headers, we have to re-write these
256*3d8817e4Smiod    fields.
257*3d8817e4Smiod  */
258*3d8817e4Smiod #define COFF_ADJUST_SCNHDR_OUT_POST(ABFD, INT, EXT) \
259*3d8817e4Smiod   do									   \
260*3d8817e4Smiod     {									   \
261*3d8817e4Smiod       PUT_SCNHDR_NLNNO (ABFD, ((struct internal_scnhdr *)(INT))->s_nlnno,  \
262*3d8817e4Smiod 			((SCNHDR *)(EXT))->s_nlnno);			   \
263*3d8817e4Smiod       PUT_SCNHDR_NRELOC (ABFD, ((struct internal_scnhdr *)(INT))->s_nreloc,\
264*3d8817e4Smiod 			 ((SCNHDR *)(EXT))->s_nreloc);			   \
265*3d8817e4Smiod       PUT_SCNHDR_FLAGS (ABFD, ((struct internal_scnhdr *)(INT))->s_flags,  \
266*3d8817e4Smiod 			((SCNHDR *)(EXT))->s_flags);			   \
267*3d8817e4Smiod       PUT_SCNHDR_PAGE (ABFD, ((struct internal_scnhdr *)(INT))->s_page,    \
268*3d8817e4Smiod 		       ((SCNHDR *)(EXT))->s_page);			   \
269*3d8817e4Smiod     }									   \
270*3d8817e4Smiod    while (0)
271*3d8817e4Smiod 
272*3d8817e4Smiod /*
273*3d8817e4Smiod  * names of "special" sections
274*3d8817e4Smiod  */
275*3d8817e4Smiod #define _TEXT	".text"
276*3d8817e4Smiod #define _DATA	".data"
277*3d8817e4Smiod #define _BSS	".bss"
278*3d8817e4Smiod #define _CINIT  ".cinit"            /* initialized C data */
279*3d8817e4Smiod #define _SCONST  ".const"           /* constants */
280*3d8817e4Smiod #define _SWITCH ".switch"           /* switch tables */
281*3d8817e4Smiod #define _STACK  ".stack"            /* C stack */
282*3d8817e4Smiod #define _SYSMEM ".sysmem"           /* used for malloc et al. syscalls */
283*3d8817e4Smiod 
284*3d8817e4Smiod /********************** LINE NUMBERS **********************/
285*3d8817e4Smiod 
286*3d8817e4Smiod /* 1 line number entry for every "breakpointable" source line in a section.
287*3d8817e4Smiod  * Line numbers are grouped on a per function basis; first entry in a function
288*3d8817e4Smiod  * grouping will have l_lnno = 0 and in place of physical address will be the
289*3d8817e4Smiod  * symbol table index of the function name.
290*3d8817e4Smiod  */
291*3d8817e4Smiod struct external_lineno {
292*3d8817e4Smiod   union {
293*3d8817e4Smiod     char l_symndx[4];	/* function name symbol index, iff l_lnno == 0*/
294*3d8817e4Smiod     char l_paddr[4];	/* (physical) address of line number	*/
295*3d8817e4Smiod   } l_addr;
296*3d8817e4Smiod   char l_lnno[2];	/* line number		*/
297*3d8817e4Smiod };
298*3d8817e4Smiod 
299*3d8817e4Smiod #define	LINENO	struct external_lineno
300*3d8817e4Smiod #define	LINESZ	6
301*3d8817e4Smiod 
302*3d8817e4Smiod 
303*3d8817e4Smiod /********************** SYMBOLS **********************/
304*3d8817e4Smiod 
305*3d8817e4Smiod /* NOTE: this is what a local label looks like in assembly source; what it
306*3d8817e4Smiod    looks like in COFF output is undefined */
307*3d8817e4Smiod #define TICOFF_LOCAL_LABEL_P(NAME) \
308*3d8817e4Smiod ((NAME[0] == '$' && NAME[1] >= '0' && NAME[1] <= '9' && NAME[2] == '\0') \
309*3d8817e4Smiod  || NAME[strlen(NAME)-1] == '?')
310*3d8817e4Smiod 
311*3d8817e4Smiod #define E_SYMNMLEN	8	/* # characters in a symbol name	*/
312*3d8817e4Smiod #define E_FILNMLEN	14	/* # characters in a file name		*/
313*3d8817e4Smiod #define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
314*3d8817e4Smiod 
315*3d8817e4Smiod struct external_syment
316*3d8817e4Smiod {
317*3d8817e4Smiod   union {
318*3d8817e4Smiod     char e_name[E_SYMNMLEN];
319*3d8817e4Smiod     struct {
320*3d8817e4Smiod       char e_zeroes[4];
321*3d8817e4Smiod       char e_offset[4];
322*3d8817e4Smiod     } e;
323*3d8817e4Smiod   } e;
324*3d8817e4Smiod   char e_value[4];
325*3d8817e4Smiod   char e_scnum[2];
326*3d8817e4Smiod   char e_type[2];
327*3d8817e4Smiod   char e_sclass[1];
328*3d8817e4Smiod   char e_numaux[1];
329*3d8817e4Smiod };
330*3d8817e4Smiod 
331*3d8817e4Smiod 
332*3d8817e4Smiod #define N_BTMASK	(017)
333*3d8817e4Smiod #define N_TMASK		(060)
334*3d8817e4Smiod #define N_BTSHFT	(4)
335*3d8817e4Smiod #define N_TSHIFT	(2)
336*3d8817e4Smiod 
337*3d8817e4Smiod 
338*3d8817e4Smiod union external_auxent {
339*3d8817e4Smiod   struct {
340*3d8817e4Smiod 	char x_tagndx[4];	/* str, un, or enum tag indx */
341*3d8817e4Smiod 	union {
342*3d8817e4Smiod 	  struct {
343*3d8817e4Smiod 		char  x_lnno[2]; /* declaration line number */
344*3d8817e4Smiod 		char  x_size[2]; /* str/union/array size */
345*3d8817e4Smiod 	  } x_lnsz;
346*3d8817e4Smiod 	  char x_fsize[4];	/* size of function */
347*3d8817e4Smiod 	} x_misc;
348*3d8817e4Smiod 	union {
349*3d8817e4Smiod 	  struct {		/* if ISFCN, tag, or .bb */
350*3d8817e4Smiod 		char x_lnnoptr[4];	/* ptr to fcn line # */
351*3d8817e4Smiod 		char x_endndx[4];	/* entry ndx past block end */
352*3d8817e4Smiod 	  } x_fcn;
353*3d8817e4Smiod 	  struct {		/* if ISARY, up to 4 dimen. */
354*3d8817e4Smiod 		char x_dimen[E_DIMNUM][2];
355*3d8817e4Smiod 	  } x_ary;
356*3d8817e4Smiod 	} x_fcnary;
357*3d8817e4Smiod 	char x_tvndx[2];		/* tv index */
358*3d8817e4Smiod   } x_sym;
359*3d8817e4Smiod 
360*3d8817e4Smiod   union {
361*3d8817e4Smiod 	char x_fname[E_FILNMLEN];
362*3d8817e4Smiod 	struct {
363*3d8817e4Smiod 	  char x_zeroes[4];
364*3d8817e4Smiod 	  char x_offset[4];
365*3d8817e4Smiod 	} x_n;
366*3d8817e4Smiod   } x_file;
367*3d8817e4Smiod 
368*3d8817e4Smiod   struct {
369*3d8817e4Smiod 	char x_scnlen[4];			/* section length */
370*3d8817e4Smiod 	char x_nreloc[2];	/* # relocation entries */
371*3d8817e4Smiod 	char x_nlinno[2];	/* # line numbers */
372*3d8817e4Smiod   } x_scn;
373*3d8817e4Smiod 
374*3d8817e4Smiod   struct {
375*3d8817e4Smiod 	char x_tvfill[4];	/* tv fill value */
376*3d8817e4Smiod 	char x_tvlen[2];	/* length of .tv */
377*3d8817e4Smiod 	char x_tvran[2][2];	/* tv range */
378*3d8817e4Smiod   } x_tv;		/* info about .tv section (in auxent of symbol .tv)) */
379*3d8817e4Smiod 
380*3d8817e4Smiod 
381*3d8817e4Smiod };
382*3d8817e4Smiod 
383*3d8817e4Smiod #define	SYMENT	struct external_syment
384*3d8817e4Smiod #define	SYMESZ	18
385*3d8817e4Smiod #define	AUXENT	union external_auxent
386*3d8817e4Smiod #define	AUXESZ	18
387*3d8817e4Smiod 
388*3d8817e4Smiod /* section lengths are in target bytes (not host bytes) */
389*3d8817e4Smiod #define GET_SCN_SCNLEN(ABFD, EXT) \
390*3d8817e4Smiod   (H_GET_32 (ABFD, (EXT)->x_scn.x_scnlen) * bfd_octets_per_byte (ABFD))
391*3d8817e4Smiod #define PUT_SCN_SCNLEN(ABFD, INT, EXT) \
392*3d8817e4Smiod   H_PUT_32 (ABFD, (INT) / bfd_octets_per_byte (ABFD), (EXT)->x_scn.x_scnlen)
393*3d8817e4Smiod 
394*3d8817e4Smiod /* lnsz size is in bits in COFF file, in bytes in BFD */
395*3d8817e4Smiod #define GET_LNSZ_SIZE(abfd, ext) \
396*3d8817e4Smiod  (H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size) / (class != C_FIELD ? 8 : 1))
397*3d8817e4Smiod 
398*3d8817e4Smiod #define PUT_LNSZ_SIZE(abfd, in, ext) \
399*3d8817e4Smiod   H_PUT_16 (abfd, ((class != C_FIELD) ? (in) * 8 : (in)), \
400*3d8817e4Smiod 	   ext->x_sym.x_misc.x_lnsz.x_size)
401*3d8817e4Smiod 
402*3d8817e4Smiod /* TI COFF stores offsets for MOS and MOU in bits; BFD expects bytes
403*3d8817e4Smiod    Also put the load page flag of the section into the symbol value if it's an
404*3d8817e4Smiod    address.  */
405*3d8817e4Smiod #ifndef NEEDS_PAGE
406*3d8817e4Smiod #define NEEDS_PAGE(X) 0
407*3d8817e4Smiod #define PAGE_MASK 0
408*3d8817e4Smiod #endif
409*3d8817e4Smiod #define COFF_ADJUST_SYM_IN_POST(ABFD, EXT, INT) \
410*3d8817e4Smiod   do									\
411*3d8817e4Smiod     {									\
412*3d8817e4Smiod       struct internal_syment *dst = (struct internal_syment *)(INT);	\
413*3d8817e4Smiod       if (dst->n_sclass == C_MOS || dst->n_sclass == C_MOU)		\
414*3d8817e4Smiod 	dst->n_value /= 8;						\
415*3d8817e4Smiod       else if (NEEDS_PAGE (dst->n_sclass)) {                            \
416*3d8817e4Smiod         asection *scn = coff_section_from_bfd_index (abfd, dst->n_scnum); \
417*3d8817e4Smiod         dst->n_value |= (scn->lma & PAGE_MASK);                         \
418*3d8817e4Smiod       }									\
419*3d8817e4Smiod     }									\
420*3d8817e4Smiod    while (0)
421*3d8817e4Smiod 
422*3d8817e4Smiod #define COFF_ADJUST_SYM_OUT_POST(ABFD, INT, EXT) \
423*3d8817e4Smiod   do									\
424*3d8817e4Smiod     {									\
425*3d8817e4Smiod        struct internal_syment *src = (struct internal_syment *)(INT);	\
426*3d8817e4Smiod        SYMENT *dst = (SYMENT *)(EXT);					\
427*3d8817e4Smiod        if (src->n_sclass == C_MOU || src->n_sclass == C_MOS)		\
428*3d8817e4Smiod 	 H_PUT_32 (abfd, src->n_value * 8, dst->e_value);		\
429*3d8817e4Smiod        else if (NEEDS_PAGE (src->n_sclass)) {                           \
430*3d8817e4Smiod          H_PUT_32 (abfd, src->n_value &= ~PAGE_MASK, dst->e_value);     \
431*3d8817e4Smiod        }								\
432*3d8817e4Smiod     }									\
433*3d8817e4Smiod    while (0)
434*3d8817e4Smiod 
435*3d8817e4Smiod /* Detect section-relative absolute symbols so they get flagged with a sym
436*3d8817e4Smiod    index of -1.
437*3d8817e4Smiod */
438*3d8817e4Smiod #define SECTION_RELATIVE_ABSOLUTE_SYMBOL_P(RELOC, SECT) \
439*3d8817e4Smiod   ((*(RELOC)->sym_ptr_ptr)->section->output_section == (SECT) \
440*3d8817e4Smiod    && (RELOC)->howto->name[0] == 'A')
441*3d8817e4Smiod 
442*3d8817e4Smiod /********************** RELOCATION DIRECTIVES **********************/
443*3d8817e4Smiod 
444*3d8817e4Smiod struct external_reloc_v0
445*3d8817e4Smiod {
446*3d8817e4Smiod   char r_vaddr[4];
447*3d8817e4Smiod   char r_symndx[2];
448*3d8817e4Smiod   char r_reserved[2];
449*3d8817e4Smiod   char r_type[2];
450*3d8817e4Smiod };
451*3d8817e4Smiod 
452*3d8817e4Smiod struct external_reloc
453*3d8817e4Smiod {
454*3d8817e4Smiod   char r_vaddr[4];
455*3d8817e4Smiod   char r_symndx[4];
456*3d8817e4Smiod   char r_reserved[2]; /* extended pmad byte for COFF2 */
457*3d8817e4Smiod   char r_type[2];
458*3d8817e4Smiod };
459*3d8817e4Smiod 
460*3d8817e4Smiod #define RELOC struct external_reloc
461*3d8817e4Smiod #define RELSZ_V0 10                 /* FIXME -- coffcode.h needs fixing */
462*3d8817e4Smiod #define RELSZ 12                    /* for COFF1/2 */
463*3d8817e4Smiod 
464*3d8817e4Smiod /* various relocation types.  */
465*3d8817e4Smiod #define R_ABS     0x0000            /* no relocation */
466*3d8817e4Smiod #define R_REL13   0x002A            /* 13-bit direct reference (???) */
467*3d8817e4Smiod #define R_PARTLS7 0x0028            /* 7 LSBs of an address */
468*3d8817e4Smiod #define R_PARTMS9 0x0029            /* 9MSBs of an address */
469*3d8817e4Smiod #define R_EXTWORD 0x002B            /* 23-bit direct reference */
470*3d8817e4Smiod #define R_EXTWORD16 0x002C          /* 16-bit direct reference to 23-bit addr*/
471*3d8817e4Smiod #define R_EXTWORDMS7 0x002D         /* upper 7 bits of 23-bit address */
472*3d8817e4Smiod 
473*3d8817e4Smiod #endif /* COFF_TI_H */
474