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