BFD and include/coff support for tic54x target.
[binutils.git] / include / coff / ti.h
blob06a315b8a7f79b2a6b4c0f45a6e3ad2683717509
1 /*** COFF information for generic Texas Instruments COFF flavour */
3 /********************** FILE HEADER **********************/
5 struct 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 char f_target_id[2]; /* magic no. (TI COFF-specific) */
16 /* COFF0 has magic number in f_magic, and omits f_target_id from the file
17 header; for later versions, f_magic is 0xC1 for COFF1 and 0xC2 for COFF2
18 and the target-specific magic number is found in f_target_id */
20 #define TICOFF0MAGIC TI_TARGET_ID
21 #define TICOFF1MAGIC 0x00C1
22 #define TICOFF2MAGIC 0x00C2
23 #define TICOFF_AOUT_MAGIC 0x0108 /* magic number in optional header */
24 #define TICOFF 1 /* customize coffcode.h */
26 /* The target_id field changes depending on the particular CPU target */
27 /* for COFF0, the target id appeared in f_magic, where COFFX magic is now */
28 #ifndef TI_TARGET_ID
29 #error "TI_TARGET_ID needs to be defined for your CPU"
30 #endif
32 /* Which bfd_arch to use... */
33 #ifndef TICOFF_TARGET_ARCH
34 #error "TICOFF_TARGET_ARCH needs to be defined for your CPU"
35 #endif
37 /* Default to COFF2 for file output */
38 #ifndef TICOFF_DEFAULT_MAGIC
39 #define TICOFF_DEFAULT_MAGIC TICOFF2MAGIC
40 #endif
42 /* This value is made available in the rare case where a bfd is unavailable */
43 #ifndef OCTETS_PER_BYTE_POWER
44 #warn OCTETS_PER_BYTE_POWER not defined for this CPU, it will default to 0
45 #else
46 #define OCTETS_PER_BYTE (1<<OCTETS_PER_BYTE_POWER)
47 #endif
49 /* default alignment is on a byte (not octet!) boundary */
50 #ifndef COFF_DEFAULT_SECTION_ALIGNMENT_POWER
51 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 0
52 #endif
54 /* TI COFF encodes the section alignment in the section header flags */
55 #define COFF_ALIGN_IN_SECTION_HEADER 1
56 #define COFF_ALIGN_IN_S_FLAGS 1
57 /* requires a power-of-two argument */
58 #define COFF_ENCODE_ALIGNMENT(S,X) ((S).s_flags |= (((unsigned)(X)&0xF)<<8))
59 /* result is a power of two */
60 #define COFF_DECODE_ALIGNMENT(X) (((X)>>8)&0xF)
62 #define COFF0_P(ABFD) (bfd_coff_filhsz(ABFD) == FILHSZ_V0)
63 #define COFF2_P(ABFD) (bfd_coff_scnhsz(ABFD) != SCNHSZ_V01)
65 #define COFF0_BADMAG(x) ((x).f_magic != TICOFF0MAGIC)
66 #define COFF1_BADMAG(x) ((x).f_magic != TICOFF1MAGIC || (x).f_target_id != TI_TARGET_ID)
67 #define COFF2_BADMAG(x) ((x).f_magic != TICOFF2MAGIC || (x).f_target_id != TI_TARGET_ID)
69 /* we need to read/write an extra field in the coff file header */
70 #ifndef COFF_ADJUST_FILEHDR_IN_POST
71 #define COFF_ADJUST_FILEHDR_IN_POST(abfd,src,dst) \
72 do { ((struct internal_filehdr *)(dst))->f_target_id = \
73 bfd_h_get_16(abfd, (bfd_byte *)(((FILHDR *)(src))->f_target_id)); \
74 ((struct internal_filehdr *)(dst))->f_flags |= F_LDPAGE; \
75 } while(0)
76 #endif
78 #ifndef COFF_ADJUST_FILEHDR_OUT_POST
79 #define COFF_ADJUST_FILEHDR_OUT_POST(abfd,src,dst) \
80 do { bfd_h_put_16(abfd, ((struct internal_filehdr *)(src))->f_target_id, \
81 (bfd_byte *)(((FILHDR *)(dst))->f_target_id)); \
82 } while(0)
83 #endif
85 #define FILHDR struct external_filehdr
86 #define FILHSZ 22
87 #define FILHSZ_V0 20 /* COFF0 omits target_id field */
89 /* File header flags */
90 #define F_RELFLG (0x0001)
91 #define F_EXEC (0x0002)
92 #define F_LNNO (0x0004)
93 /* F_LSYMS needs to be redefined in your source file */
94 #define F_LSYMS_TICOFF (0x0010) /* normal COFF is 0x8 */
96 #define F_10 0x00 /* file built for TMS320C1x devices */
97 #define F_20 0x10 /* file built for TMS320C2x devices */
98 #define F_25 0x20 /* file built for TMS320C2x/C5x devices */
99 #define F_LENDIAN 0x0100 /* 16 bits/word, LSB first */
100 #define F_SYMMERGE 0x1000 /* duplicate symbols were removed */
102 /********************** OPTIONAL HEADER **********************/
105 typedef struct
107 char magic[2]; /* type of file (0x108) */
108 char vstamp[2]; /* version stamp */
109 char tsize[4]; /* text size in bytes, padded to FW bdry*/
110 char dsize[4]; /* initialized data " " */
111 char bsize[4]; /* uninitialized data " " */
112 char entry[4]; /* entry pt. */
113 char text_start[4]; /* base of text used for this file */
114 char data_start[4]; /* base of data used for this file */
116 AOUTHDR;
119 #define AOUTHDRSZ 28
120 #define AOUTSZ 28
123 /********************** SECTION HEADER **********************/
124 /* COFF0, COFF1 */
125 struct external_scnhdr_v01 {
126 char s_name[8]; /* section name */
127 char s_paddr[4]; /* physical address, aliased s_nlib */
128 char s_vaddr[4]; /* virtual address */
129 char s_size[4]; /* section size (in WORDS) */
130 char s_scnptr[4]; /* file ptr to raw data for section */
131 char s_relptr[4]; /* file ptr to relocation */
132 char s_lnnoptr[4]; /* file ptr to line numbers */
133 char s_nreloc[2]; /* number of relocation entries */
134 char s_nlnno[2]; /* number of line number entries*/
135 char s_flags[2]; /* flags */
136 char s_reserved[1]; /* reserved */
137 char s_page[1]; /* section page number (LOAD) */
140 /* COFF2 */
141 struct external_scnhdr {
142 char s_name[8]; /* section name */
143 char s_paddr[4]; /* physical address, aliased s_nlib */
144 char s_vaddr[4]; /* virtual address */
145 char s_size[4]; /* section size (in WORDS) */
146 char s_scnptr[4]; /* file ptr to raw data for section */
147 char s_relptr[4]; /* file ptr to relocation */
148 char s_lnnoptr[4]; /* file ptr to line numbers */
149 char s_nreloc[4]; /* number of relocation entries */
150 char s_nlnno[4]; /* number of line number entries*/
151 char s_flags[4]; /* flags */
152 char s_reserved[2]; /* reserved */
153 char s_page[2]; /* section page number (LOAD) */
157 * Special section flags
158 * TI COFF puts the section alignment power of two in the section flags
159 * e.g. 2**N is alignment, flags |= (N & 0xF) << 8
161 /* recognized load pages */
162 #define PG_PROG 0x0 /* PROG page */
163 #define PG_DATA 0x1 /* DATA page */
165 /* TI COFF defines these flags;
166 STYP_CLINK: the section should be excluded from the final
167 linker output if there are no references found to any symbol in the section
168 STYP_BLOCK: the section should be blocked, i.e. if the section would cross
169 a page boundary, it is started at a page boundary instead.
171 #define STYP_CLINK (0x4000)
172 #define STYP_BLOCK (0x1000)
173 #define STYP_ALIGN (0x0F00) /* TI COFF stores section alignment here */
175 #define SCNHDR_V01 struct external_scnhdr_v01
176 #define SCNHDR struct external_scnhdr
177 #define SCNHSZ_V01 40 /* for v0 and v1 */
178 #define SCNHSZ 48
180 /* COFF2 changes the offsets and sizes of these fields
181 Assume we're dealing with the COFF2 scnhdr structure, and adjust
182 accordingly
184 #define GET_SCNHDR_NRELOC(ABFD,PTR) \
185 (COFF2_P(ABFD) ? bfd_h_get_32 (ABFD,PTR) : bfd_h_get_16 (ABFD, PTR))
186 #define PUT_SCNHDR_NRELOC(ABFD,VAL,PTR) \
187 (COFF2_P(ABFD) ? bfd_h_put_32 (ABFD,VAL,PTR) : bfd_h_put_16 (ABFD,VAL,PTR))
188 #define GET_SCNHDR_NLNNO(ABFD,PTR) \
189 (COFF2_P(ABFD) ? bfd_h_get_32 (ABFD,PTR) : bfd_h_get_16 (ABFD, (PTR)-2))
190 #define PUT_SCNHDR_NLNNO(ABFD,VAL,PTR) \
191 (COFF2_P(ABFD) ? bfd_h_put_32 (ABFD,VAL,PTR) : bfd_h_put_16 (ABFD,VAL,(PTR)-2))
192 #define GET_SCNHDR_FLAGS(ABFD,PTR) \
193 (COFF2_P(ABFD) ? bfd_h_get_32 (ABFD,PTR) : bfd_h_get_16 (ABFD, (PTR)-4))
194 #define PUT_SCNHDR_FLAGS(ABFD,VAL,PTR) \
195 (COFF2_P(ABFD) ? bfd_h_put_32 (ABFD,VAL,PTR) : bfd_h_put_16 (ABFD,VAL,(PTR)-4))
196 #define GET_SCNHDR_PAGE(ABFD,PTR) \
197 (COFF2_P(ABFD) ? bfd_h_get_16 (ABFD,PTR) : bfd_h_get_8 (ABFD, (PTR)-7))
198 /* on output, make sure that the "reserved" field is zero */
199 #define PUT_SCNHDR_PAGE(ABFD,VAL,PTR) \
200 (COFF2_P(ABFD) ? bfd_h_put_16 (ABFD,VAL,PTR) : \
201 bfd_h_put_8 (ABFD,VAL,(PTR)-7), bfd_h_put_8 (ABFD, 0, (PTR)-8))
203 /* TI COFF stores section size as number of bytes (address units, not octets),
204 so adjust to be number of octets, which is what BFD expects */
205 #define GET_SCNHDR_SIZE(ABFD,SZP) \
206 (bfd_h_get_32(ABFD,SZP)*bfd_octets_per_byte(ABFD))
207 #define PUT_SCNHDR_SIZE(ABFD,SZ,SZP) \
208 bfd_h_put_32(ABFD,(SZ)/bfd_octets_per_byte(ABFD),SZP)
210 #define COFF_ADJUST_SCNHDR_IN_POST(ABFD,EXT,INT) \
211 do { ((struct internal_scnhdr *)(INT))->s_page = \
212 GET_SCNHDR_PAGE(ABFD,(bfd_byte *)((SCNHDR *)(EXT))->s_page); \
213 } while(0)
215 /* The line number and reloc overflow checking in coff_swap_scnhdr_out in
216 coffswap.h doesn't use PUT_X for s_nlnno and s_nreloc.
217 Due to different sized v0/v1/v2 section headers, we have to re-write these
218 fields.
220 #define COFF_ADJUST_SCNHDR_OUT_POST(ABFD,INT,EXT) \
221 do { \
222 PUT_SCNHDR_NLNNO(ABFD,((struct internal_scnhdr *)(INT))->s_nlnno,\
223 (bfd_byte *)((SCNHDR *)(EXT))->s_nlnno); \
224 PUT_SCNHDR_NRELOC(ABFD,((struct internal_scnhdr *)(INT))->s_nreloc,\
225 (bfd_byte *)((SCNHDR *)(EXT))->s_nreloc); \
226 PUT_SCNHDR_FLAGS(ABFD,((struct internal_scnhdr *)(INT))->s_flags, \
227 (bfd_byte *)((SCNHDR *)(EXT))->s_flags); \
228 PUT_SCNHDR_PAGE(ABFD,((struct internal_scnhdr *)(INT))->s_page, \
229 (bfd_byte *)((SCNHDR *)(EXT))->s_page); \
230 } while(0)
232 /* page macros
234 the first GDB port requires flags in its remote memory access commands to
235 distinguish between data/prog space. hopefully we can make this go away
236 eventually. stuff the page in the upper bits of a 32-bit address, since
237 the c5x family only uses 16 or 23 bits.
239 c2x, c5x and most c54x devices have 16-bit addresses, but the c548 has
240 23-bit program addresses. make sure the page flags don't interfere
244 #define LONG_ADDRESSES 1
245 #define PG_SHIFT (LONG_ADDRESSES ? 30 : 16)
246 #define ADDR_MASK ((1ul<<PG_SHIFT)-1)/* 16 or 24-bit addresses */
247 #define PG_MASK (3ul<<PG_SHIFT)
248 #define PG_TO_FLAG(p) ((p)<<PG_SHIFT)
249 #define FLAG_TO_PG(f) (((f)&PG_MASK)>>PG_SHIFT)
252 * names of "special" sections
254 #define _TEXT ".text"
255 #define _DATA ".data"
256 #define _BSS ".bss"
257 #define _CINIT ".cinit" /* initialized C data */
258 #define _SCONST ".const" /* constants */
259 #define _SWITCH ".switch" /* switch tables */
260 #define _STACK ".stack" /* C stack */
261 #define _SYSMEM ".sysmem" /* used for malloc et al. syscalls */
263 /********************** LINE NUMBERS **********************/
265 /* 1 line number entry for every "breakpointable" source line in a section.
266 * Line numbers are grouped on a per function basis; first entry in a function
267 * grouping will have l_lnno = 0 and in place of physical address will be the
268 * symbol table index of the function name.
270 struct external_lineno {
271 union {
272 char l_symndx[4]; /* function name symbol index, iff l_lnno == 0*/
273 char l_paddr[4]; /* (physical) address of line number */
274 } l_addr;
275 char l_lnno[2]; /* line number */
278 #define LINENO struct external_lineno
279 #define LINESZ 6
282 /********************** SYMBOLS **********************/
284 /* NOTE: this is what a local label looks like in assembly source; what it
285 looks like in COFF output is undefined */
286 #define TICOFF_LOCAL_LABEL_P(NAME) \
287 ((NAME[0] == '$' && NAME[1] >= '0' && NAME[1] <= '9' && NAME[2] == '\0') \
288 || NAME[strlen(NAME)-1] == '?')
290 #define E_SYMNMLEN 8 /* # characters in a symbol name */
291 #define E_FILNMLEN 14 /* # characters in a file name */
292 #define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
294 struct external_syment
296 union {
297 char e_name[E_SYMNMLEN];
298 struct {
299 char e_zeroes[4];
300 char e_offset[4];
301 } e;
302 } e;
303 char e_value[4];
304 char e_scnum[2];
305 char e_type[2];
306 char e_sclass[1];
307 char e_numaux[1];
311 #define N_BTMASK (017)
312 #define N_TMASK (060)
313 #define N_BTSHFT (4)
314 #define N_TSHIFT (2)
317 union external_auxent {
318 struct {
319 char x_tagndx[4]; /* str, un, or enum tag indx */
320 union {
321 struct {
322 char x_lnno[2]; /* declaration line number */
323 char x_size[2]; /* str/union/array size */
324 } x_lnsz;
325 char x_fsize[4]; /* size of function */
326 } x_misc;
327 union {
328 struct { /* if ISFCN, tag, or .bb */
329 char x_lnnoptr[4]; /* ptr to fcn line # */
330 char x_endndx[4]; /* entry ndx past block end */
331 } x_fcn;
332 struct { /* if ISARY, up to 4 dimen. */
333 char x_dimen[E_DIMNUM][2];
334 } x_ary;
335 } x_fcnary;
336 char x_tvndx[2]; /* tv index */
337 } x_sym;
339 union {
340 char x_fname[E_FILNMLEN];
341 struct {
342 char x_zeroes[4];
343 char x_offset[4];
344 } x_n;
345 } x_file;
347 struct {
348 char x_scnlen[4]; /* section length */
349 char x_nreloc[2]; /* # relocation entries */
350 char x_nlinno[2]; /* # line numbers */
351 } x_scn;
353 struct {
354 char x_tvfill[4]; /* tv fill value */
355 char x_tvlen[2]; /* length of .tv */
356 char x_tvran[2][2]; /* tv range */
357 } x_tv; /* info about .tv section (in auxent of symbol .tv)) */
362 #define SYMENT struct external_syment
363 #define SYMESZ 18
364 #define AUXENT union external_auxent
365 #define AUXESZ 18
367 /* section lengths are in target bytes (not host bytes) */
368 #define GET_SCN_SCNLEN(ABFD,EXT) \
369 (bfd_h_get_32(ABFD,(bfd_byte *)(EXT)->x_scn.x_scnlen)*bfd_octets_per_byte(ABFD))
370 #define PUT_SCN_SCNLEN(ABFD,INT,EXT) \
371 bfd_h_put_32(ABFD,(INT)/bfd_octets_per_byte(ABFD),\
372 (bfd_byte *)(EXT)->x_scn.x_scnlen)
374 /* lnsz size is in bits in COFF file, in bytes in BFD */
375 #define GET_LNSZ_SIZE(abfd, ext) \
376 (bfd_h_get_16(abfd, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_size) / \
377 (class != C_FIELD ? 8 : 1))
379 #define PUT_LNSZ_SIZE(abfd, in, ext) \
380 bfd_h_put_16(abfd, ((class != C_FIELD) ? (in)*8 : (in)), \
381 (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
383 /* TI COFF stores offsets for MOS and MOU in bits; BFD expects bytes */
384 #define COFF_ADJUST_SYM_IN_POST(ABFD,EXT,INT) \
385 do { struct internal_syment *dst = (struct internal_syment *)(INT); \
386 if (dst->n_sclass == C_MOS || dst->n_sclass == C_MOU) dst->n_value /= 8; \
387 } while (0)
389 #define COFF_ADJUST_SYM_OUT_POST(ABFD,INT,EXT) \
390 do { struct internal_syment *src = (struct internal_syment *)(INT); \
391 SYMENT *dst = (SYMENT *)(EXT); \
392 if(src->n_sclass == C_MOU || src->n_sclass == C_MOS) \
393 bfd_h_put_32(abfd,src->n_value * 8,(bfd_byte *)dst->e_value); \
394 } while (0)
396 /* detect section-relative absolute symbols so they get flagged with a sym
397 index of -1
399 #define SECTION_RELATIVE_ABSOLUTE_SYMBOL_P(RELOC,SECT) \
400 ((*(RELOC)->sym_ptr_ptr)->section->output_section == (SECT) \
401 && (RELOC)->howto->name[0] == 'A')
403 /********************** RELOCATION DIRECTIVES **********************/
405 struct external_reloc_v0 {
406 char r_vaddr[4];
407 char r_symndx[2];
408 char r_reserved[2];
409 char r_type[2];
412 struct external_reloc {
413 char r_vaddr[4];
414 char r_symndx[4];
415 char r_reserved[2]; /* extended pmad byte for COFF2 */
416 char r_type[2];
419 #define RELOC struct external_reloc
420 #define RELSZ_V0 10 /* FIXME -- coffcode.h needs fixing */
421 #define RELSZ 12 /* for COFF1/2 */
423 /* various relocation types. */
424 #define R_ABS 0x0000 /* no relocation */
425 #define R_REL13 0x002A /* 13-bit direct reference (???) */
426 #define R_PARTLS7 0x0028 /* 7 LSBs of an address */
427 #define R_PARTMS9 0x0029 /* 9MSBs of an address */
428 #define R_EXTWORD 0x002B /* 23-bit direct reference */
429 #define R_EXTWORD16 0x002C /* 16-bit direct reference to 23-bit addr*/
430 #define R_EXTWORDMS7 0x002D /* upper 7 bits of 23-bit address */
431 /*EOF*/