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). */
7 /********************** FILE HEADER **********************/
9 struct 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) */
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 */
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 */
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 */
33 #error "TI_TARGET_ID needs to be defined for your CPU"
36 /* Which bfd_arch to use... */
37 #ifndef TICOFF_TARGET_ARCH
38 #error "TICOFF_TARGET_ARCH needs to be defined for your CPU"
41 /* Default to COFF2 for file output */
42 #ifndef TICOFF_DEFAULT_MAGIC
43 #define TICOFF_DEFAULT_MAGIC TICOFF2MAGIC
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
50 #define OCTETS_PER_BYTE (1<<OCTETS_PER_BYTE_POWER)
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
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)
66 #define COFF0_P(ABFD) (bfd_coff_filhsz(ABFD) == FILHSZ_V0)
67 #define COFF2_P(ABFD) (bfd_coff_scnhsz(ABFD) != SCNHSZ_V01)
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)
73 /* we need to read/write an extra field in the coff file header */
75 #ifndef COFF_ADJUST_FILEHDR_IN_POST
76 #define COFF_ADJUST_FILEHDR_IN_POST(abfd,src,dst) \
77 do { ((struct internal_filehdr *)(dst))->f_target_id = \
78 bfd_h_get_16(abfd, (bfd_byte *)(((FILHDR *)(src))->f_target_id)); \
79 /*((struct internal_filehdr *)(dst))->f_flags |= F_LDPAGE;*/ \
83 #ifndef COFF_ADJUST_FILEHDR_OUT_POST
84 #define COFF_ADJUST_FILEHDR_OUT_POST(abfd,src,dst) \
85 do { bfd_h_put_16(abfd, ((struct internal_filehdr *)(src))->f_target_id, \
86 (bfd_byte *)(((FILHDR *)(dst))->f_target_id)); \
90 #define FILHDR struct external_filehdr
92 #define FILHSZ_V0 20 /* COFF0 omits target_id field */
94 /* File header flags */
95 #define F_RELFLG (0x0001)
96 #define F_EXEC (0x0002)
97 #define F_LNNO (0x0004)
98 /* F_LSYMS needs to be redefined in your source file */
99 #define F_LSYMS_TICOFF (0x0010) /* normal COFF is 0x8 */
101 #define F_10 0x00 /* file built for TMS320C1x devices */
102 #define F_20 0x10 /* file built for TMS320C2x devices */
103 #define F_25 0x20 /* file built for TMS320C2x/C5x devices */
104 #define F_LENDIAN 0x0100 /* 16 bits/word, LSB first */
105 #define F_SYMMERGE 0x1000 /* duplicate symbols were removed */
107 /********************** OPTIONAL HEADER **********************/
112 char magic
[2]; /* type of file (0x108) */
113 char vstamp
[2]; /* version stamp */
114 char tsize
[4]; /* text size in bytes, padded to FW bdry*/
115 char dsize
[4]; /* initialized data " " */
116 char bsize
[4]; /* uninitialized data " " */
117 char entry
[4]; /* entry pt. */
118 char text_start
[4]; /* base of text used for this file */
119 char data_start
[4]; /* base of data used for this file */
128 /********************** SECTION HEADER **********************/
130 struct external_scnhdr_v01
{
131 char s_name
[8]; /* section name */
132 char s_paddr
[4]; /* physical address, aliased s_nlib */
133 char s_vaddr
[4]; /* virtual address */
134 char s_size
[4]; /* section size (in WORDS) */
135 char s_scnptr
[4]; /* file ptr to raw data for section */
136 char s_relptr
[4]; /* file ptr to relocation */
137 char s_lnnoptr
[4]; /* file ptr to line numbers */
138 char s_nreloc
[2]; /* number of relocation entries */
139 char s_nlnno
[2]; /* number of line number entries*/
140 char s_flags
[2]; /* flags */
141 char s_reserved
[1]; /* reserved */
142 char s_page
[1]; /* section page number (LOAD) */
146 struct external_scnhdr
{
147 char s_name
[8]; /* section name */
148 char s_paddr
[4]; /* physical address, aliased s_nlib */
149 char s_vaddr
[4]; /* virtual address */
150 char s_size
[4]; /* section size (in WORDS) */
151 char s_scnptr
[4]; /* file ptr to raw data for section */
152 char s_relptr
[4]; /* file ptr to relocation */
153 char s_lnnoptr
[4]; /* file ptr to line numbers */
154 char s_nreloc
[4]; /* number of relocation entries */
155 char s_nlnno
[4]; /* number of line number entries*/
156 char s_flags
[4]; /* flags */
157 char s_reserved
[2]; /* reserved */
158 char s_page
[2]; /* section page number (LOAD) */
162 * Special section flags
164 /* recognized load pages */
165 #define PG_PROG 0x0 /* PROG page */
166 #define PG_DATA 0x1 /* DATA page */
168 /* TI COFF defines these flags;
169 STYP_CLINK: the section should be excluded from the final
170 linker output if there are no references found to any symbol in the section
171 STYP_BLOCK: the section should be blocked, i.e. if the section would cross
172 a page boundary, it is started at a page boundary instead.
173 TI COFF puts the section alignment power of two in the section flags
174 e.g. 2**N is alignment, flags |= (N & 0xF) << 8
176 #define STYP_CLINK (0x4000)
177 #define STYP_BLOCK (0x1000)
178 #define STYP_ALIGN (0x0F00) /* TI COFF stores section alignment here */
180 #define SCNHDR_V01 struct external_scnhdr_v01
181 #define SCNHDR struct external_scnhdr
182 #define SCNHSZ_V01 40 /* for v0 and v1 */
185 /* COFF2 changes the offsets and sizes of these fields
186 Assume we're dealing with the COFF2 scnhdr structure, and adjust
189 #define GET_SCNHDR_NRELOC(ABFD,PTR) \
190 (COFF2_P(ABFD) ? bfd_h_get_32 (ABFD,PTR) : bfd_h_get_16 (ABFD, PTR))
191 #define PUT_SCNHDR_NRELOC(ABFD,VAL,PTR) \
192 (COFF2_P(ABFD) ? bfd_h_put_32 (ABFD,VAL,PTR) : bfd_h_put_16 (ABFD,VAL,PTR))
193 #define GET_SCNHDR_NLNNO(ABFD,PTR) \
194 (COFF2_P(ABFD) ? bfd_h_get_32 (ABFD,PTR) : bfd_h_get_16 (ABFD, (PTR)-2))
195 #define PUT_SCNHDR_NLNNO(ABFD,VAL,PTR) \
196 (COFF2_P(ABFD) ? bfd_h_put_32 (ABFD,VAL,PTR) : bfd_h_put_16 (ABFD,VAL,(PTR)-2))
197 #define GET_SCNHDR_FLAGS(ABFD,PTR) \
198 (COFF2_P(ABFD) ? bfd_h_get_32 (ABFD,PTR) : bfd_h_get_16 (ABFD, (PTR)-4))
199 #define PUT_SCNHDR_FLAGS(ABFD,VAL,PTR) \
200 (COFF2_P(ABFD) ? bfd_h_put_32 (ABFD,VAL,PTR) : bfd_h_put_16 (ABFD,VAL,(PTR)-4))
201 #define GET_SCNHDR_PAGE(ABFD,PTR) \
202 (COFF2_P(ABFD) ? bfd_h_get_16 (ABFD,PTR) : bfd_h_get_8 (ABFD, (PTR)-7))
203 /* on output, make sure that the "reserved" field is zero */
204 #define PUT_SCNHDR_PAGE(ABFD,VAL,PTR) \
205 (COFF2_P(ABFD) ? bfd_h_put_16 (ABFD,VAL,PTR) : \
206 bfd_h_put_8 (ABFD,VAL,(PTR)-7), bfd_h_put_8 (ABFD, 0, (PTR)-8))
208 /* TI COFF stores section size as number of bytes (address units, not octets),
209 so adjust to be number of octets, which is what BFD expects */
210 #define GET_SCNHDR_SIZE(ABFD,SZP) \
211 (bfd_h_get_32(ABFD,SZP)*bfd_octets_per_byte(ABFD))
212 #define PUT_SCNHDR_SIZE(ABFD,SZ,SZP) \
213 bfd_h_put_32(ABFD,(SZ)/bfd_octets_per_byte(ABFD),SZP)
216 #define COFF_ADJUST_SCNHDR_IN_POST(ABFD,EXT,INT) \
217 do { ((struct internal_scnhdr *)(INT))->s_page = \
218 GET_SCNHDR_PAGE(ABFD,(bfd_byte *)((SCNHDR *)(EXT))->s_page); \
222 /* The line number and reloc overflow checking in coff_swap_scnhdr_out in
223 coffswap.h doesn't use PUT_X for s_nlnno and s_nreloc.
224 Due to different sized v0/v1/v2 section headers, we have to re-write these
228 #define COFF_ADJUST_SCNHDR_OUT_POST(ABFD,INT,EXT) \
230 PUT_SCNHDR_NLNNO(ABFD,((struct internal_scnhdr *)(INT))->s_nlnno,\
231 (bfd_byte *)((SCNHDR *)(EXT))->s_nlnno); \
232 PUT_SCNHDR_NRELOC(ABFD,((struct internal_scnhdr *)(INT))->s_nreloc,\
233 (bfd_byte *)((SCNHDR *)(EXT))->s_nreloc); \
234 PUT_SCNHDR_FLAGS(ABFD,((struct internal_scnhdr *)(INT))->s_flags, \
235 (bfd_byte *)((SCNHDR *)(EXT))->s_flags); \
236 /*PUT_SCNHDR_PAGE(ABFD,((struct internal_scnhdr *)(INT))->s_page, \
237 (bfd_byte *)((SCNHDR *)(EXT))->s_page);*/ \
242 the first GDB port requires flags in its remote memory access commands to
243 distinguish between data/prog space. hopefully we can make this go away
244 eventually. stuff the page in the upper bits of a 32-bit address, since
245 the c5x family only uses 16 or 23 bits.
247 c2x, c5x and most c54x devices have 16-bit addresses, but the c548 has
248 23-bit program addresses. make sure the page flags don't interfere
249 These flags are used by GDB to identify the destination page for
253 #define LONG_ADDRESSES 1
254 #define PG_SHIFT (LONG_ADDRESSES ? 30 : 16)
255 #define ADDR_MASK (((unsigned long) 1 << PG_SHIFT) - 1)
256 #define PG_MASK ((unsigned long) 3 << PG_SHIFT)
257 #define PG_TO_FLAG(p) ((p) << PG_SHIFT)
258 #define FLAG_TO_PG(f) (((f) & PG_MASK) >> PG_SHIFT)
261 * names of "special" sections
263 #define _TEXT ".text"
264 #define _DATA ".data"
266 #define _CINIT ".cinit" /* initialized C data */
267 #define _SCONST ".const" /* constants */
268 #define _SWITCH ".switch" /* switch tables */
269 #define _STACK ".stack" /* C stack */
270 #define _SYSMEM ".sysmem" /* used for malloc et al. syscalls */
272 /********************** LINE NUMBERS **********************/
274 /* 1 line number entry for every "breakpointable" source line in a section.
275 * Line numbers are grouped on a per function basis; first entry in a function
276 * grouping will have l_lnno = 0 and in place of physical address will be the
277 * symbol table index of the function name.
279 struct external_lineno
{
281 char l_symndx
[4]; /* function name symbol index, iff l_lnno == 0*/
282 char l_paddr
[4]; /* (physical) address of line number */
284 char l_lnno
[2]; /* line number */
287 #define LINENO struct external_lineno
291 /********************** SYMBOLS **********************/
293 /* NOTE: this is what a local label looks like in assembly source; what it
294 looks like in COFF output is undefined */
295 #define TICOFF_LOCAL_LABEL_P(NAME) \
296 ((NAME[0] == '$' && NAME[1] >= '0' && NAME[1] <= '9' && NAME[2] == '\0') \
297 || NAME[strlen(NAME)-1] == '?')
299 #define E_SYMNMLEN 8 /* # characters in a symbol name */
300 #define E_FILNMLEN 14 /* # characters in a file name */
301 #define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
303 struct external_syment
306 char e_name
[E_SYMNMLEN
];
320 #define N_BTMASK (017)
321 #define N_TMASK (060)
326 union external_auxent
{
328 char x_tagndx
[4]; /* str, un, or enum tag indx */
331 char x_lnno
[2]; /* declaration line number */
332 char x_size
[2]; /* str/union/array size */
334 char x_fsize
[4]; /* size of function */
337 struct { /* if ISFCN, tag, or .bb */
338 char x_lnnoptr
[4]; /* ptr to fcn line # */
339 char x_endndx
[4]; /* entry ndx past block end */
341 struct { /* if ISARY, up to 4 dimen. */
342 char x_dimen
[E_DIMNUM
][2];
345 char x_tvndx
[2]; /* tv index */
349 char x_fname
[E_FILNMLEN
];
357 char x_scnlen
[4]; /* section length */
358 char x_nreloc
[2]; /* # relocation entries */
359 char x_nlinno
[2]; /* # line numbers */
363 char x_tvfill
[4]; /* tv fill value */
364 char x_tvlen
[2]; /* length of .tv */
365 char x_tvran
[2][2]; /* tv range */
366 } x_tv
; /* info about .tv section (in auxent of symbol .tv)) */
371 #define SYMENT struct external_syment
373 #define AUXENT union external_auxent
376 /* section lengths are in target bytes (not host bytes) */
377 #define GET_SCN_SCNLEN(ABFD,EXT) \
378 (bfd_h_get_32(ABFD,(bfd_byte *)(EXT)->x_scn.x_scnlen)*bfd_octets_per_byte(ABFD))
379 #define PUT_SCN_SCNLEN(ABFD,INT,EXT) \
380 bfd_h_put_32(ABFD,(INT)/bfd_octets_per_byte(ABFD),\
381 (bfd_byte *)(EXT)->x_scn.x_scnlen)
383 /* lnsz size is in bits in COFF file, in bytes in BFD */
384 #define GET_LNSZ_SIZE(abfd, ext) \
385 (bfd_h_get_16(abfd, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_size) / \
386 (class != C_FIELD ? 8 : 1))
388 #define PUT_LNSZ_SIZE(abfd, in, ext) \
389 bfd_h_put_16(abfd, ((class != C_FIELD) ? (in)*8 : (in)), \
390 (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
392 /* TI COFF stores offsets for MOS and MOU in bits; BFD expects bytes */
393 #define COFF_ADJUST_SYM_IN_POST(ABFD,EXT,INT) \
394 do { struct internal_syment *dst = (struct internal_syment *)(INT); \
395 if (dst->n_sclass == C_MOS || dst->n_sclass == C_MOU) dst->n_value /= 8; \
398 #define COFF_ADJUST_SYM_OUT_POST(ABFD,INT,EXT) \
399 do { struct internal_syment *src = (struct internal_syment *)(INT); \
400 SYMENT *dst = (SYMENT *)(EXT); \
401 if(src->n_sclass == C_MOU || src->n_sclass == C_MOS) \
402 bfd_h_put_32(abfd,src->n_value * 8,(bfd_byte *)dst->e_value); \
405 /* Detect section-relative absolute symbols so they get flagged with a sym
408 #define SECTION_RELATIVE_ABSOLUTE_SYMBOL_P(RELOC,SECT) \
409 ((*(RELOC)->sym_ptr_ptr)->section->output_section == (SECT) \
410 && (RELOC)->howto->name[0] == 'A')
412 /********************** RELOCATION DIRECTIVES **********************/
414 struct external_reloc_v0
{
421 struct external_reloc
{
424 char r_reserved
[2]; /* extended pmad byte for COFF2 */
428 #define RELOC struct external_reloc
429 #define RELSZ_V0 10 /* FIXME -- coffcode.h needs fixing */
430 #define RELSZ 12 /* for COFF1/2 */
432 /* various relocation types. */
433 #define R_ABS 0x0000 /* no relocation */
434 #define R_REL13 0x002A /* 13-bit direct reference (???) */
435 #define R_PARTLS7 0x0028 /* 7 LSBs of an address */
436 #define R_PARTMS9 0x0029 /* 9MSBs of an address */
437 #define R_EXTWORD 0x002B /* 23-bit direct reference */
438 #define R_EXTWORD16 0x002C /* 16-bit direct reference to 23-bit addr*/
439 #define R_EXTWORDMS7 0x002D /* upper 7 bits of 23-bit address */
441 #endif /* COFF_TI_H */
This page took 0.039139 seconds and 4 git commands to generate.