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