1 /*
2 *
3 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
38 /**************************************************************************/
39 /* COFF.H - Definition of COFF structures and definitions. */
40 /* */
41 /* This file defines all standard COFF definitions, used by any program */
42 /* which reads or writes COFF files. */
43 /* */
44 /* HISTORY */
45 /* --/--/83 - Original (lost in the mists of time) */
46 /* --/--/91 - Tektronics relocation entry kludge */
47 /* 01/07/94 RET - Reworked file header and relocation entries, add */
48 /* COFF version support. (Removed Tek kludge) */
49 /* 12/24/95 TMS - Reworked section header structures for COFF 2 */
50 /* */
51 /**************************************************************************/
52 #ifndef COFF_H
53 #define COFF_H
55 #if defined(TOOL_ASSEMBLER)
56 #error The COFF submodule should no longer be used by the assembler; use TICOFF04
57 #endif
59 /*------------------------------------------------------------------------*/
60 /* COFF VERSION FLAGS */
61 /*------------------------------------------------------------------------*/
62 #if !defined(COFF_VERSION_0) && \
63 !defined(COFF_VERSION_1) && \
64 !defined(COFF_VERSION_2)
65 #define COFF_VERSION_0 0
66 #define COFF_VERSION_1 0
67 #define COFF_VERSION_2 1
68 #endif
70 #ifndef COFF_VERSION_0
71 #define COFF_VERSION_0 0
72 #endif
74 #ifndef COFF_VERSION_1
75 #define COFF_VERSION_1 0
76 #endif
78 #ifndef COFF_VERSION_2
79 #define COFF_VERSION_2 0
80 #endif
82 /*------------------------------------------------------------------------*/
83 /* COFF MAGIC NUMBERS */
84 /*------------------------------------------------------------------------*/
85 #define COFF_MAGIC_0 0xc0 /* ORIGINAL VERSION OF COFF */
86 #define COFF_MAGIC_1 0xc1
87 #define COFF_MAGIC_2 0xc2
89 /*------------------------------------------------------------------------*/
90 /* COFF TARGET ID's (FORMERLY MAGIC NUMBERS) */
91 /* NOTE!!! DEFINE THE MACRO "MAGIC" TO BE ONE OF THESE MACROS. */
92 /*------------------------------------------------------------------------*/
93 #define MAGIC_340 0x90
94 #define MAGIC_370 0x91
95 #define MAGIC_DSP 0x92
96 #define MAGIC_C30 0x93
97 #define MAGIC_380 0x94
98 #define MAGIC_MVP 0x95
99 #define MAGIC_C16 0x96
100 #define MAGIC_ARM 0x97
101 #define MAGIC_LEAD 0x98
102 #define MAGIC_C60 0x99
103 #define MAGIC_C8P 0x9a
104 #define MAGIC_unused1 0x9b
105 #define MAGIC_LEAD3 0x9c
106 #define MAGIC_ANKOOR 0x9d
107 #define MAGIC_unused 0x9e
108 #define MAGIC_TARANTULA 0x9f
109 #define MAGIC_MSP 0xA0
110 #define MAGIC_LEAD3_R35 0xA1
112 #define MAGIC_MIN 0x90 /* MINIMUM VALID MAGIC NUMBER */
113 #define MAGIC_MAX 0xA1 /* MAXIMUM VALID MAGIC NUMBER */
115 /*------------------------------------------------------------------------*/
116 /* Macros to recognize magic numbers */
117 /* NOTE: ISMAGIC() is now a target-specific macro defined in coff_trg.h */
118 /*------------------------------------------------------------------------*/
119 #define ISCOFF(x) (ISCOFF_0(x)||ISCOFF_1(x)||ISCOFF_2(x)||ISMAGIC(x))
120 #define BADMAGIC(x) (((unsigned short)(x) & 0x8080) && !ISMAGIC(x))
122 #define ISEXE(x) ((x >> 1) & 0x0001)
124 #if COFF_VERSION_2
125 #define ISCOFF_0(x) ((unsigned short)(x) == COFF_MAGIC_0)
126 #define ISCOFF_1(x) ((unsigned short)(x) == COFF_MAGIC_1)
127 #define ISCOFF_2(x) ((unsigned short)(x) == COFF_MAGIC_2)
128 #elif COFF_VERSION_1
129 #define ISCOFF_0(x) ((unsigned short)(x) == COFF_MAGIC_0)
130 #define ISCOFF_1(x) ((unsigned short)(x) == COFF_MAGIC_1)
131 #define ISCOFF_2(x) FALSE
132 #else
133 #define ISCOFF_0(x) FALSE
134 #define ISCOFF_1(x) FALSE
135 #define ISCOFF_2(x) FALSE
136 #endif
138 #define ISMAGIC_ANY(x) (((unsigned short)(x)) >= MAGIC_MIN && \
139 ((unsigned short)(x)) <= MAGIC_MAX)
140 #define ISCOFF_ANY(x) (ISCOFF_0(x) || ISCOFF_1(x) || \
141 ISCOFF_2(x) || ISMAGIC_ANY(x))
143 #include "coffdefs.h"
145 /*------------------------------------------------------------------------*/
146 /* COFF FILE HEADER */
147 /*------------------------------------------------------------------------*/
148 struct filehdr
149 {
150 unsigned short f_magic; /* magic number */
151 unsigned short f_nscns; /* number of sections */
152 unsigned int f_timdat; /* time & date stamp */
153 unsigned int f_symptr; /* file pointer to symtab */
154 unsigned int f_nsyms; /* number of symtab entries */
155 unsigned short f_opthdr; /* sizeof(optional hdr) */
156 unsigned short f_flags; /* flags */
157 unsigned short f_target_id; /* target architecture id */
158 };
160 #define FILHDR struct filehdr
161 #define FILHSZ (COFF_VERSION_0 ? 20 : 22)
162 #define FILHSZ_IN(version) (version >= COFF_MAGIC_1 ? 22 : 20)
164 /*------------------------------------------------------------------------*/
165 /* File header flags */
166 /*------------------------------------------------------------------------*/
167 #define F_RELFLG 0x01 /* relocation info stripped from file */
168 #define F_EXEC 0x02 /* file is executable (no unresolved refs) */
169 #define F_LNNO 0x04 /* line nunbers stripped from file */
170 #define F_LSYMS 0x08 /* local symbols stripped from file */
172 /*------------------------------------------------------------------------*/
173 /* Target device identification flags (bits 4-7 in file header flags) */
174 /*------------------------------------------------------------------------*/
175 #define F_VERS0 0x0 /* 0th generation CPU */
176 #define F_VERS1 0x10 /* 1st generation CPU */
177 #define F_VERS2 0x20 /* 2nd generation CPU */
178 #define F_VERS3 0x40 /* 3rd generation CPU */
179 #define F_VERS4 0x80 /* 4th generation CPU */
180 #define F_VERSION (F_VERS1 | F_VERS2 | F_VERS3 | F_VERS4)
182 /*------------------------------------------------------------------------*/
183 /* Target device raw data byte ordering flags (bits 8-9) */
184 /*------------------------------------------------------------------------*/
185 #define F_LITTLE 0x100 /* object code is LSB first */
186 #define F_BIG 0x200 /* object code is MSB first */
187 #define F_BYTE_ORDER (F_LITTLE | F_BIG)
189 #define F_SYMMERGE 0x1000 /* Tags, etc were merged - no duplicates */
191 #define F_ICODE 0x2000 /* This file contains embedded I-Code */
193 \f
194 /*------------------------------------------------------------------------*/
195 /* OPTIONAL FILE HEADER */
196 /*------------------------------------------------------------------------*/
197 typedef struct aouthdr
198 {
199 short magic; /* optional file header magic number */
200 short vstamp; /* version stamp */
201 int tsize; /* text size in bytes, padded to FW bdry*/
202 int dsize; /* initialized data " " */
203 int bsize; /* uninitialized data " " */
204 int entrypt; /* entry pt. */
205 int text_start; /* base of text used for this file */
206 int data_start; /* base of data used for this file */
207 } AOUTHDR;
209 #define AOUTSZ sizeof(AOUTHDR)
210 #define AOUT1MAGIC 0x108
212 \f
213 /*------------------------------------------------------------------------*/
214 /* COMMON ARCHIVE FILE STRUCTURES */
215 /* */
216 /* ARCHIVE File Organization: */
217 /* +---------------------------------------------+ */
218 /* | ARCHIVE_MAGIC_STRING | */
219 /* +---------------------------------------------+ */
220 /* | ARCHIVE_FILE_MEMBER_1 | */
221 /* +- - - - - - - - - - - - - - - - - - - - - - -+ */
222 /* | Archive File Header "ar_hdr" | */
223 /* | Contents (Ext symbol direct, text file) | */
224 /* +---------------------------------------------+ */
225 /* | ARCHIVE_FILE_MEMBER_2 | */
226 /* +- - - - - - - - - - - - - - - - - - - - - - -+ */
227 /* | Archive File Header "ar_hdr" | */
228 /* | Contents (long file member name table) | */
229 /* +---------------------------------------------+ */
230 /* | ARCHIVE_FILE_MEMBER_3 | */
231 /* +- - - - - - - - - - - - - - - - - - - - - - -+ */
232 /* | Archive File Header "ar_hdr" | */
233 /* | Contents (.o or text file) | */
234 /* +---------------------------------------------+ */
235 /* | . . . | */
236 /* | . . . | */
237 /* | . . . | */
238 /* +---------------------------------------------+ */
239 /* | ARCHIVE_FILE_MEMBER_n | */
240 /* +- - - - - - - - - - - - - - - - - - - - - - -+ */
241 /* | Archive File Header "ar_hdr" | */
242 /* | Contents (.o or text file) | */
243 /* +---------------------------------------------+ */
244 /* */
245 /*------------------------------------------------------------------------*/
247 #define ARMAG "!<arch>\n"
248 #define SARMAG 8
249 #define ARFMAG "`\n"
250 #define ARFMAG_SIZE 2
252 struct ar_hdr /* archive file member header - printable ascii */
253 {
254 char ar_name[16]; /* file member name - `/' terminated */
255 char ar_date[12]; /* file member date - decimal */
256 char ar_offset[6]; /* file member offset - decimal */
257 char ar_gid[6]; /* file member group id - decimal */
258 char ar_mode[8]; /* file member mode - octal */
259 char ar_size[10]; /* file member size - decimal */
260 char ar_fmag[2]; /* ARFMAG - string to end header */
261 };
263 #define ARHDR struct ar_hdr
264 #define ARHSZ sizeof(ARHDR)
265 #define AR_HDR_SZ sizeof(ARHDR)
266 #define AR_FNAME_SIZE 16
267 #define MAGIC_LONGFILENAME 1
268 #define LONGFILENAME "<filenames>"
269 #define SYMDIRNAME "/ "
271 \f
272 /*------------------------------------------------------------------------*/
273 /* SECTION HEADER */
274 /*------------------------------------------------------------------------*/
275 #define SYMNMLEN 8 /* Number of characters in a symbol name */
277 /*------------------------------------------------------------------------*/
278 /* THE OLD COFF VERSION TYPE DEFINITION FOR SECTION HEADERS TO PROVIDE */
279 /* BACKWARDS COMPATIBILITY FOR COFF-DEPENDENT TOOLS THAT SUPPORT COFF 2. */
280 /*------------------------------------------------------------------------*/
281 struct o_scnhdr
282 {
283 char os_name[8]; /* section name */
284 int os_paddr; /* physical address */
285 int os_vaddr; /* virtual address */
286 int os_size; /* section size */
287 int os_scnptr; /* file ptr to raw data for scn */
288 int os_relptr; /* file ptr to relocation */
289 int os_lnnoptr; /* file ptr to line numbers */
290 unsigned short os_nreloc; /* number of relocation entries */
291 unsigned short os_nlnno; /* number of line number entries */
292 unsigned short os_flags; /* flags */
293 char os_reserved; /* reserved byte */
294 unsigned char os_page; /* memory page id */
295 };
297 /*------------------------------------------------------------------------*/
298 /* THE NEW COFF VERSION TYPE DEFINITION FOR SECTION HEADERS. THIS */
299 /* REVISION ALLOWS FOR UNRESTRICTED SECTION NAME LENGTH. */
300 /*------------------------------------------------------------------------*/
301 struct scnhdr
302 {
303 union
304 {
305 char _s_name[SYMNMLEN]; /* old COFF version name fld */
306 struct
307 {
308 int _s_zeroes; /* new == 0 */
309 int _s_offset; /* offset into string table */
310 } _s_s;
311 char *_s_nptr[2]; /* allows for overlaying */
312 } _s;
314 int s_paddr; /* physical address */
315 int s_vaddr; /* virtual address */
316 int s_size; /* section size */
317 int s_scnptr; /* file ptr to raw data for section */
318 int s_relptr; /* file ptr to relocation */
319 int s_lnnoptr; /* file ptr to line numbers */
320 unsigned int s_nreloc; /* number of relocation entries */
321 unsigned int s_nlnno; /* number of line number entries */
322 unsigned int s_flags; /* flags */
323 unsigned char s_mwidth; /* memory width in bits */
324 /* (0 == target memory width) */
325 unsigned char s_reserved; /* reserved byte */
326 unsigned short s_page; /* memory page id */
327 };
329 #define s_name _s._s_name
330 #define s_nptr _s._s_nptr[1]
331 #define s_zeroes _s._s_s._s_zeroes
332 #define s_offset _s._s_s._s_offset
334 #define O_SCNHDR struct o_scnhdr
335 #define SCNHDR struct scnhdr
336 #define O_SCNHSZ sizeof(O_SCNHDR)
337 #define SCNHSZ sizeof(SCNHDR)
338 #define SCNHSZ_IN(version) (version == COFF_MAGIC_2 ? SCNHSZ : O_SCNHSZ)
340 /*------------------------------------------------------------------------*/
341 /* Define constants for names of "special" sections */
342 /*------------------------------------------------------------------------*/
343 #define _TEXT ".text"
344 #define _DATA ".data"
345 #define _BSS ".bss"
346 #define _REG ".reg"
347 #define _BINIT ".binit"
348 #define _CINIT ".cinit"
349 #define _PINIT ".pinit"
350 #define _ICODE ".icode"
352 #define _OVLY_PREFIX ".ovly:"
354 #define IS_DWARF_SECTION(name) (!strncmp(name, ".debug_", 7))
356 /*------------------------------------------------------------------------*/
357 /* Bits 0-8 of s_flags are used as a section "type" */
358 /*------------------------------------------------------------------------*/
359 #define STYP_REG 0x00 /* "regular" : allocated, relocated, loaded */
360 #define STYP_DSECT 0x01 /* "dummy" : !allocated, relocated, !loaded */
361 #define STYP_NOLOAD 0x02 /* "noload" : allocated, relocated, !loaded */
362 #define STYP_XXX1 0x04 /* not used - was STYP_GROUP */
363 #define STYP_XXX2 0x08 /* not used - was STYP_PAD */
364 #define STYP_COPY 0x10 /* "copy" : used for C init tables -
365 not allocated, relocated,
366 loaded; reloc & lineno
367 entries processed normally */
368 #define STYP_TEXT 0x20 /* section contains text only */
369 #define STYP_DATA 0x40 /* section contains data only */
370 #define STYP_BSS 0x80 /* section contains bss only */
372 /*------------------------------------------------------------------------*/
373 /* Bits 8-11 specify an alignment. The alignment is (2 ** x), where x is */
374 /* is the encoded value */
375 /*------------------------------------------------------------------------*/
376 #define ALIGN_MASK 0xF00 /* mask for alignment factor */
377 #define ALIGN_SIZE(s_flag) (1 << (((unsigned)s_flag & ALIGN_MASK) >> 8))
378 #define ALIGN_GET(header) (((header).s_flags & ALIGN_MASK) >> 8)
379 #define ALIGN_SET(header,amt) (header).s_flags = \
380 (((header).s_flags & ~ALIGN_MASK) | ((amt << 8) & ALIGN_MASK))
382 /*------------------------------------------------------------------------*/
383 /* bit 12-31 */
384 /*------------------------------------------------------------------------*/
385 #define STYP_BLOCK 0x01000 /* use alignment as blocking factor */
386 #define STYP_PASS 0x02000 /* Pass section through unchanged */
387 #define STYP_CLINK 0x04000 /* Conditionally link section */
389 #define STYP_VECTOR 0x08000 /* section contains vector table */
390 /* (Used in addition to STYP_TEXT) */
392 #define STYP_PADDED 0x10000 /* section HAS BEEN padded. Do not pad */
393 /* again if partial linking. */
394 #define STYP_ICODE 0x20000 /* section has ICODE associated with it */
396 #define STYP_LGT 0x40000 /* linker generated table section */
397 #define STYP_COMMON 0x80000 /* comdat section - remove duplicates */
399 #define STYP_BASIC_MASK 0xFF /* basic section types */
400 #define STYP_TIEXT_MASK 0xFF000 /* TI section type extensions */
402 /*------------------------------------------------------------------------*/
403 /* A mask for all the flags we support - anything else is garbage. */
404 /*------------------------------------------------------------------------*/
405 #define STYP_KNOWN_MASK (ALIGN_MASK | STYP_BASIC_MASK | STYP_TIEXT_MASK)
407 \f
408 /*------------------------------------------------------------------------*/
409 /* RELOCATION ENTRIES */
410 /* WE SUPPORT TWO TYPES OF RELOCATION ENTRIES: */
411 /* 1) OLD STYLE, WITH 16 BIT SYMBOL TABLE INDEX. */
412 /* 2) NEW STYLE, WITH 32 BIT SYMBOL TABLE INDEX. */
413 /* FOR ANY GIVEN INPUT FILE, THE FILE HEADER FLAG "F_RELOC_12" INDICATES */
414 /* THE TYPE OF RELOCATION ENTRY IN THE FILE. */
415 /* THE TARGET-SPECIFIC FLAG RELOC_ENTRY_12 DETERMINES WHETHER THE NEW */
416 /* STYLE IS SUPPORTED ON A GIVEN TARGET. */
417 /*------------------------------------------------------------------------*/
418 typedef struct reloc_old
419 {
420 int r_vaddr; /* (virtual) address of reference */
422 union {
423 struct {
424 unsigned char _offset; /* bit offset of rel fld */
425 unsigned char _fieldsz; /* size of rel fld */
426 unsigned char _wordsz; /* # bytes containing rel fld */
427 unsigned char _dum1;
429 unsigned short _type;
430 } _r_field;
432 struct {
433 unsigned int _spc; /* section relative PC */
434 unsigned short _type; /* relocation type */
435 } _r_spc;
437 struct {
438 unsigned int _uval; /* constant value */
439 unsigned short _type; /* relocation type */
440 } _r_uval;
442 struct {
443 short _symndx; /* 32-bit sym tbl index */
444 unsigned short _disp; /* extra addr encode data */
445 unsigned short _type; /* relocation type */
446 } _r_sym;
447 } _u_reloc;
448 } RELOC_OLD;
450 /*------------------------------------------------------------------------*/
451 /* MAKE SURE THE RELOCATION STRUCTURE IS TIGHTLY PACKED TO AVOID HOST */
452 /* ALIGNMENT MECHANISMS. */
453 /*------------------------------------------------------------------------*/
454 typedef struct reloc
455 {
456 int r_vaddr; /* (virtual) address of reference */
458 union {
459 struct {
460 unsigned char _offset; /* bit offset of rel fld */
461 unsigned char _fieldsz; /* size of rel fld */
462 unsigned char _wordsz; /* # bytes containing rel fld */
463 unsigned char _dum1;
464 unsigned short _dum2;
466 unsigned short _type;
467 } _r_field;
469 struct {
470 unsigned int _spc; /* section relative PC */
471 unsigned short _dum;
472 unsigned short _type; /* relocation type */
473 } _r_spc;
475 struct {
476 unsigned int _uval; /* constant value */
477 unsigned short _dum;
478 unsigned short _type; /* relocation type */
479 } _r_uval;
481 struct {
482 int _symndx; /* 32-bit sym tbl index */
483 unsigned short _disp; /* extra addr encode data */
484 unsigned short _type; /* relocation type */
485 } _r_sym;
486 } _u_reloc;
487 } RELOC;
489 #define RELSZ (COFF_VERSION_0 ? 10 : 12)
490 #define RELSZ_IN(version) ((version >= COFF_MAGIC_1) ? 12 : 10)
492 /*------------------------------------------------------------------------*/
493 /* Macros for accessing fields in relocation entry data structure. */
494 /*------------------------------------------------------------------------*/
495 #define r_offset _u_reloc._r_field._offset
496 #define r_fieldsz _u_reloc._r_field._fieldsz
497 #define r_wordsz _u_reloc._r_field._wordsz
499 #define r_spc _u_reloc._r_spc._spc
500 #define r_uval _u_reloc._r_uval._uval
502 #define r_symndx _u_reloc._r_sym._symndx
503 #define r_disp _u_reloc._r_sym._disp
504 #define r_type _u_reloc._r_sym._type
506 /*------------------------------------------------------------------------*/
507 /* define all relocation types */
508 /*------------------------------------------------------------------------*/
509 #define R_ABS 0x0 /* absolute address - no relocation */
510 #define R_DIR16 0x1 /* UNUSED */
511 #define R_REL16 0x2 /* UNUSED */
512 #define R_DIR24 0x4 /* UNUSED */
513 #define R_REL24 0x5 /* 24 bits, direct */
514 #define R_DIR32 0x6 /* UNUSED */
515 #define R_RRRELREG 0xe /* RR: 8 bit relocatable register */
517 #define R_RELBYTE 0xf /* 8 bits, direct */
518 #define R_RELWORD 0x10 /* 16 bits, direct */
519 #define R_RELLONG 0x11 /* 32 bits, direct */
520 #define R_PCRBYTE 0x12 /* 8 bits, PC-relative */
521 #define R_PCRWORD 0x13 /* 16 bits, PC-relative */
522 #define R_PCRLONG 0x14 /* 32 bits, PC-relative */
523 /* (See unsigned (LD3) versions below.) */
524 #define R_PCR24 0x15 /* 24 bits, PC-relative */
525 #define R_PCR23H 0x16 /* 23 bits, PC-rel in halfwords(x>>1) */
526 #define R_PCR24W 0x17 /* 24 bits, PC-rel in words (x >> 2) */
527 #define R_OCRLONG 0x18 /* GSP: 32 bits, one's compl direct */
528 #define R_GSPPCR16 0x19 /* GSP: 16 bits, PC relative (in words) */
529 #define R_GSPOPR32 0x1a /* GSP: 32 bits, direct big-endian */
530 #define R_GSPPCA16 0x1b /* GSP: same as GSPPCR16, but PC const */
531 #define R_OCBD32 0x1c /* GSP: 32 bits, 1's compl,big-endian */
532 #define R_RRNREG 0x1d /* RR: 8 bit reloc. reg. w/ neg off */
533 #define R_PARTLS16 0x20 /* Brahma: 16 bit offset of 24 bit addr */
534 #define R_PARTMS8 0x21 /* Brahma: 8 bit page of 24 bit addr */
535 #define R_PARTLS7 0x28 /* DSP: 7 bit offset of 16 bit addr */
536 #define R_PARTMS9 0x29 /* DSP: 9 bit page of 16 bit addr */
537 #define R_REL13 0x2a /* DSP: 13 bits, direct */
538 #define R_REL23 0x2b /* DSP,C54X: 23 bits, direct (ext addr) */
539 #define R_RELXPC 0x2c /* DSP,C54X: 16 bits, relative to XPC */
540 #define R_HIEXT 0x2d /* C54X: Hi word of extended prog addr */
541 #define R_HIWORD 0x31 /* RR: 8 bit reloc. hi byte of word */
542 #define R_LABCOD 0x32 /* C16 16-bit code address relocation */
544 #define R_PPBASE 0x34 /* PP: Global Base address type */
545 #define R_PPLBASE 0x35 /* PP: Local Base address type */
546 #define R_PP15 0x38 /* PP: Global 15 bit offset */
547 #define R_PP15W 0x39 /* PP: Global 15 bit offset / 4 */
548 #define R_PP15H 0x3a /* PP: Global 15 bit offset / 2 */
549 #define R_PP16B 0x3b /* PP: Global 16 bit offset for bytes */
550 #define R_PPL15 0x3c /* PP: Local 15 bit offset */
551 #define R_PPL15W 0x3d /* PP: Local 15 bit offset divided by 4 */
552 #define R_PPL15H 0x3e /* PP: Local 15 bit offset divided by 2 */
553 #define R_PPL16B 0x3f /* PP: Local 16 bit offset for bytes */
554 #define R_PPN15 0x40 /* PP: Global 15 bit neg offset */
555 #define R_PPN15W 0x41 /* PP: Global 15 bit neg offset / 4 */
556 #define R_PPN15H 0x42 /* PP: Global 15 bit neg offset / 2 */
557 #define R_PPN16B 0x43 /* PP: Global 16 bit neg byte offset */
558 #define R_PPLN15 0x44 /* PP: Local 15 bit neg offset */
559 #define R_PPLN15W 0x45 /* PP: Local 15 bit neg offset / 4 */
560 #define R_PPLN15H 0x46 /* PP: Local 15 bit neg offset / 2 */
561 #define R_PPLN16B 0x47 /* PP: Local 16 bit neg byte offset */
563 #define R_MPPCR 0x4f /* MP: 32-bit PC-relative / 4 */
565 #define R_C60BASE 0x50 /* C60: Data Page Pointer Based Offset */
566 #define R_C60DIR15 0x51 /* C60: LD/ST long Displacement */
567 #define R_C60PCR21 0x52 /* C60: 21-bit PC Relative */
568 #define R_C60PCR10 0x53 /* C60: 10-bit PC Relative */
569 #define R_C60LO16 0x54 /* C60: MVK Low Half Register */
570 #define R_C60HI16 0x55 /* C60: MVKH/MVKLH High Half Register */
571 #define R_C60SECT 0x56 /* C60: Section-Based Offset */
572 #define R_C60S16 0x57 /* C60: Signed 16-bit */
573 #define R_C60PCR7 0x70 /* C60: 7-bit PC Relative */
574 #define R_C60PCR12 0x71 /* C60: 12-bit PC Relative */
575 #define R_C60PCR12H 0x72 /* C60: 12-bit PC Relative (Half) */
576 #define R_C60PCR7J 0x73 /* C60: 7-bit PC Relative (-BNOP) */
577 #define R_C60PCR8J 0x74 /* C60: 8-bit PC Relative (-BNOP) */
578 #define R_C60PCR10J 0x75 /* C60: 10-bit PC Relative (-CALLP) */
579 #define R_C60ALIGN 0x76 /* C60: Alignment info for compressor */
580 #define R_C60FPHEAD 0x77 /* C60: Explicit assembly directive */
581 #define R_C60NOCMP 0x100 /* C60: Don't compress this code scn */
583 #define R_C8PHIBYTE 0x58 /* C8+: High byte of 24-bit address. */
584 #define R_C8PMIDBYTE 0x59 /* C8+: Middle byte of 24-bit address. */
585 #define R_C8PVECADR 0x5a /* C8+: Vector address (0xFFnnnn) */
586 #define R_C8PADR24 0x5b /* C8+: 24-bit address (rev byte order) */
588 #define R_PARTLS6 0x5d /* ANKOOR: 6 bit offset of 22 bit addr */
589 #define R_PARTMID10 0x5e /* ANKOOR: Middle 10 bits of 22 bit addr*/
590 #define R_REL22 0x5f /* ANKOOR: 22 bits, direct */
591 #define R_PARTMS6 0x60 /* ANKOOR: Upper 6 bits of 22 bit addr */
592 #define R_PARTMS16 0x61 /* ANKOOR: Upper 16 bits of 22 bit addr */
593 #define R_ANKPCR16 0x62 /* ANKOOR: PC relative 16 bit */
594 #define R_ANKPCR8 0x63 /* ANKOOR: PC relatvie 8 bit */
595 #define R_ANKPTR 0x64 /* ANKOOR: 22 bit pointer */
596 #define R_ANKHI16 0x65 /* ANKOOR: HI 16 bits of address + data */
597 #define R_ANKLOPTR 0x66 /* ANKOOR: Pointer to low 64K */
598 #define R_ANKNWORD 0x67 /* ANKOOR: 16 bit negated relocation */
599 #define R_ANKNBYTE 0x68 /* ANKOOR: 8 bit negated relocation */
600 #define R_ANKHIBYTE 0x69 /* ANKOOR: High byte of a word */
601 #define R_REL13_SE16 0x6a /* MANTRA: 13 bit sign extend to 16 bit */
603 #define R_LD3_DMA 0x78 /* LEAD3: 7 most sig bits of a byte, */
604 /* unsigned value; used in DMA address */
605 /* */
606 /* 5432109876543210 */
607 /* xxxxxxxxFFFFFFFx */
609 #define R_LD3_MDP 0x7a /* LEAD3: 7 bits spanning two bytes, */
610 /* unsigned value; used as MDP reg value*/
611 /* */
612 /* 321098765432109876543210 */
613 /* xxxxxxxxxxxxxFFFFFFFxxxx */
615 #define R_LD3_PDP 0x7b /* LEAD3: 9 bits spanning two bytes, */
616 /* unsigned value; used as PDP reg value*/
617 /* */
618 /* 321098765432109876543210 */
619 /* xxxxxxxxxxxFFFFFFFFFxxxx */
621 #define R_LD3_REL23 0x7c /* LEAD3: 23 bit unsigned value in a */
622 /* 24-bit-wide field */
625 #define R_TARBASE 0x80 /* TARANTULA: Data Page Pointer Based Off */
626 #define R_TARDIR12 0x81 /* TARANTULA: LD/ST long Displacement */
627 #define R_TARLO16 0x82 /* TARANTULA: MVK Low Half Register */
628 #define R_TARHI16 0x83 /* TARANTULA: MVKH/MVKLH High Half Reg */
629 #define R_TARSECT 0x84 /* TARANTULA: Section-based offset */
631 #define R_LD3_k8 0x88 /* LD3: Unsigned 8 bit, direct */
632 #define R_LD3_k16 0x89 /* LD3: Unsigned 16 bit, direct */
633 #define R_LD3_K8 0x8a /* LD3: Signed 8 bit, direct */
634 #define R_LD3_K16 0x8b /* LD3: Signed 16 bit, direct */
636 #define R_LD3_l8 0x8c /* LD3: Unsigned 8 bit, PC-relative */
637 #define R_LD3_l16 0x8d /* LD3: Unsigned 16 bit, PC-relative */
638 #define R_LD3_L8 0x8e /* LD3: Signed 8 bit, PC-relative */
639 #define R_LD3_L16 0x8f /* LD3: Signed 16 bit, PC-relative */
641 #define R_LD3_k4 0x90 /* LD3: Unsigned 4 bit shift immediate */
642 #define R_LD3_k5 0x91 /* LD3: Unsigned 5 bit shift immediate */
643 #define R_LD3_K5 0x92 /* LD3: Signed 5 bit shift immediate */
644 #define R_LD3_k6 0x93 /* LD3: Unsigned 6 bit immediate */
645 #define R_LD3_k12 0x94 /* LD3: Unsigned 12 bit immediate */
646 #define R_LD3_ABS16 0x95 /* LD3: abs16(addr) truncated k16 */
648 #define R_NONE 0x96 /* Encode dependencies between sections */
650 #define R_MSP_PCR20_SRC 0x97 /* MSP: PC-rel 20-bit src ext encoding */
651 #define R_MSP_PCR20_DST 0x98 /* MSP: PC-rel 20-bit dst ext encoding */
652 #define R_MSP_PCR20_ODST 0x99 /* MSP: PC-rel 20-bit offset dst ext enc */
653 #define R_MSP_EXT20_SRC 0x9A /* MSP: Relative 20-bit src ext encoding */
654 #define R_MSP_EXT20_DST 0x9B /* MSP: Relative 20-bit dst ext encoding */
655 #define R_MSP_EXT20_ODST 0x9C /* MSP: Rel 20-bit offset dst ext encoding */
656 #define R_MSP_REL20_SRC 0x9D /* MSP: Relative 20-bit src opnd */
657 #define R_MSP_REL20_DST 0x9E /* MSP: Relative 20-bit dst opnd */
658 #define R_MSP_PCR16 0x9F /* MSP: PC-rel 16-bit encoding */
659 #define R_MSP_PCR20_CALL 0xA0 /* MSP: PC-rel 20-bit call operand */
660 #define R_MSP_REL16 0xA1 /* MSP: Relative 16-bit (20bit MSPx device)*/
662 #define R_T2_PCR24H 0xA2 /* THUMB2: 24 bits, PC-rel in halfwords(x>>1) */
663 #define R_T2_PCR20H 0xA3 /* THUMB2: 20 bits, PC-rel in halfwords(x>>1) */
665 #define R_LD3_ABS24 0xA4 /* C55x+: LD_R_ABS, ST_R_ABS -- *(#k24) */
666 #define R_LD3_SP_K9 0xA5 /* C55x+: SP += K9 w/ K9 encoded as (K9 >> 1) */
667 \f
668 /*---------------------------------------------------------------------------*/
669 /* GENERIC relocation types for complex relocation expressions. */
670 /* *** NOTE: This range of relocation types exists above 0x4000 *** */
671 /* *** NOTE: Top bit of relocation type field used as SEGVALUE flag *** */
672 /*---------------------------------------------------------------------------*/
673 #define RE_ADD 0x4000 /* Operator Instructions: + */
674 #define RE_SUB 0x4001 /* - */
675 #define RE_NEG 0x4002 /* unary - */
676 #define RE_MPY 0x4003 /* * */
677 #define RE_DIV 0x4004 /* / */
678 #define RE_MOD 0x4005 /* % */
680 #define RE_SR 0x4006 /* >>u */
681 #define RE_ASR 0x4007 /* >>s */
682 #define RE_SL 0x4008 /* << */
684 #define RE_AND 0x4009 /* & */
685 #define RE_OR 0x400a /* | */
686 #define RE_XOR 0x400b /* ^ */
687 #define RE_NOTB 0x400c /* ~ */
689 #define RE_ULDFLD 0x400d /* unsigned relocation field load */
690 #define RE_SLDFLD 0x400e /* signed relocation field load */
691 #define RE_USTFLD 0x400f /* unsigned relocation field store */
692 #define RE_SSTFLD 0x4010 /* signed relocation field store */
693 #define RE_XSTFLD 0x4016 /* signedness is irrelevant */
695 #define RE_PUSH 0x4011 /* push symbol on the stack */
696 #define RE_PUSHSV 0xc011 /* push symbol: SEGVALUE flag set */
697 #define RE_PUSHSK 0x4012 /* push signed constant on the stack */
698 #define RE_PUSHUK 0x4013 /* push unsigned constant on the stack */
699 #define RE_PUSHPC 0x4014 /* push current section PC on the stack */
700 #define RE_DUP 0x4015 /* duplicate tos and push copy */
702 /*---------------------------------------------------------------------------*/
703 /* Other useful generic relocation types */
704 /*---------------------------------------------------------------------------*/
705 #define RM_FIRST_MARKER 0x5000 /* First non-relocatable type marker */
706 #define RM_RANGE 0x5000 /* Raw data marker - no relocation */
707 #define RM_OBJ 0x5001 /* Raw data marker - no relocation */
708 #define RM_DWARF_LENGTH 0x5002 /* Raw data marker - no relocation */
709 #define RM_LAST_MARKER 0x5002 /* Last non-relocatable type marker */
711 /*---------------------------------------------------------------------------*/
712 /* Macro to determine whether relocation entry has a symbol on the section's */
713 /* symbol list. Operator relocation types do not. */
714 /*---------------------------------------------------------------------------*/
715 #define isunary(x) ((x) == RE_NEG || (x) == RE_NOTB)
716 #define isbinary(x) (ismathrel(x) && !isunary(x))
717 #define issymrel(x) ((x) == RM_OBJ || (x) == RE_PUSH || \
718 (x) == RE_PUSHSV || (x) < 0x4000)
719 #define ismathrel(x) ((x) >= RE_ADD && (x) <= RE_NOTB)
720 #define ispushrel(x) (((x) >= RE_PUSH && (x) <= RE_PUSHPC) || ((x) == RE_DUP))
721 #define isldfldrel(x) ((x) == RE_ULDFLD || (x) == RE_SLDFLD)
722 #define isstfldrel(x) ((x) == RE_USTFLD || (x) == RE_SSTFLD || (x) == RE_XSTFLD )
723 #define ismarker(x) ((x) >= RM_FIRST_MARKER && (x) <= RM_LAST_MARKER)
725 /*---------------------------------------------------------------------------*/
726 /* Macro to determine if current relocation entry is a field instruction. */
727 /*---------------------------------------------------------------------------*/
728 #define isfldrel(x) (((x) >= RE_ULDFLD && (x) <= RE_SSTFLD) || ((x) == RE_XSTFLD))
730 \f
731 /*------------------------------------------------------------------------*/
732 /* LINE NUMBER ENTRIES */
733 /*------------------------------------------------------------------------*/
734 struct lineno
735 {
736 union
737 {
738 int l_symndx; /* sym index of fcn name iff l_lnno == 0 */
739 int l_paddr; /* (physical) address of line number */
740 } l_addr;
741 unsigned short l_lnno; /* line number */
742 };
744 #define LINENO struct lineno
745 #define LINESZ 6 /* sizeof(LINENO) */
747 \f
748 /*------------------------------------------------------------------------*/
749 /* SYMBOL TABLE ENTRIES */
750 /*------------------------------------------------------------------------*/
752 #define FILNMLEN 14 /* Number of characters in a file name */
753 #define DIMNUM 4 /* Number of array dimensions in aux entry */
755 typedef unsigned short DSTYPE;
757 struct syment
758 {
759 union
760 {
761 char _n_name[SYMNMLEN]; /* old COFF version */
762 struct
763 {
764 int _n_zeroes; /* new == 0 */
765 int _n_offset; /* offset into string table */
766 } _n_n;
767 const char *_n_nptr[2]; /* allows for overlaying */
768 } _n;
770 int n_value; /* value of symbol */
771 short n_scnum; /* section number */
772 DSTYPE n_type; /* type and derived type */
773 char n_sclass; /* storage class */
774 char n_numaux; /* number of aux. entries */
775 };
777 #define n_name _n._n_name
778 #define n_nptr _n._n_nptr[1]
779 #define n_zeroes _n._n_n._n_zeroes
780 #define n_offset _n._n_n._n_offset
782 /*------------------------------------------------------------------------*/
783 /* Relocatable symbols have a section number of the */
784 /* section in which they are defined. Otherwise, section */
785 /* numbers have the following meanings: */
786 /*------------------------------------------------------------------------*/
787 #define N_UNDEF 0 /* undefined symbol */
788 #define N_ABS -1 /* value of symbol is absolute */
789 #define N_DEBUG -2 /* special debugging symbol */
791 \f
792 /*------------------------------------------------------------------------*/
793 /* AUXILIARY SYMBOL ENTRY */
794 /*------------------------------------------------------------------------*/
795 #define SPACE(len, name) char name[len]
797 union auxent
798 {
799 struct
800 {
801 SPACE(4, _0_3);
802 int x_fsize; /* size of struct in bits. */
803 SPACE(4, _8_11);
804 int x_endndx; /* ptr to next sym beyond .eos */
805 SPACE(2, _16_17);
806 } x_tag;
808 struct
809 {
810 int x_tagndx; /* ptr to beginning of struct */
811 int x_fsize; /* size of struct in bits. */
812 SPACE(10, _8_17);
813 } x_eos;
815 struct
816 {
817 int x_tagndx; /* ptr to tag for function */
818 int x_fsize; /* size of function in bytes */
819 int x_lnnoptr; /* file ptr to fcn line # */
820 int x_endndx; /* ptr to next sym beyond .ef */
821 SPACE(2, _16_17);
822 } x_func;
824 struct
825 {
826 int x_regmask; /* Mask of regs use by func */
827 unsigned short x_lnno; /* line number of block begin */
828 unsigned short x_lcnt; /* # line number entries in func */
829 int x_framesize; /* size of func local vars */
830 int x_endndx; /* ptr to next sym beyond .eb */
831 SPACE(2, _16_17);
832 } x_block;
834 struct
835 {
836 int x_tagndx; /* ptr to tag for array type */
837 int x_fsize; /* Size of array in bits. */
838 unsigned short x_dimen[DIMNUM];
839 SPACE(2, _16_17);
840 } x_array;
842 struct
843 {
844 int x_tagndx; /* str, un, or enum tag indx */
845 int x_fsize; /* Size of symbol */
846 SPACE(10, _10_17);
847 } x_sym;
849 struct
850 {
851 char x_fname[FILNMLEN];
852 } x_file;
854 struct
855 {
856 int x_scnlen; /* section length */
857 unsigned short x_nreloc; /* number of reloc entries */
858 unsigned short x_nlinno; /* number of line numbers */
859 SPACE(8, _10_17);
860 } x_scn;
861 };
863 #define SYMENT struct syment
864 #define SYMESZ 18 /* sizeof(SYMENT) */
866 #define AUXENT union auxent
867 #define AUXESZ 18 /* sizeof(AUXENT) */
869 /*------------------------------------------------------------------------*/
870 /* NAMES OF "SPECIAL" SYMBOLS */
871 /*------------------------------------------------------------------------*/
872 #define _BF ".bf"
873 #define _EF ".ef"
874 #define _STEXT ".text"
875 #define _ETEXT "etext"
876 #define _SDATA ".data"
877 #define _EDATA "edata"
878 #define _SBSS ".bss"
879 #define _END "end"
880 #define _C_ARGS ".args"
881 #define _BINITPTR "binit"
882 #define _CINITPTR "cinit"
883 #define _PINITPTR "pinit"
884 #define _ASM_SRC_NAME "$ASM$" /* SPECIAL SYMBOL FOR ASSY SRC DEBUG */
886 /*------------------------------------------------------------------------*/
887 /* HIGH LEVEL LANGUAGE ACCESSIBLE VERSIONS OF THE ABOVE SPECIAL SYMBOLS. */
888 /*------------------------------------------------------------------------*/
889 #define _STEXT_HLL "___text__"
890 #define _ETEXT_HLL "___etext__"
891 #define _SDATA_HLL "___data__"
892 #define _EDATA_HLL "___edata__"
893 #define _SBSS_HLL "___bss__"
894 #define _END_HLL "___end__"
895 #define _C_ARGSPTR_HLL "___c_args__"
896 #define _BINITPTR_HLL "___binit__"
897 #define _CINITPTR_HLL "___cinit__"
898 #define _PINITPTR_HLL "___pinit__"
900 /*------------------------------------------------------------------------*/
901 /* ENTRY POINT SYMBOLS */
902 /*------------------------------------------------------------------------*/
903 #define _START "_start"
904 #define _MAIN "_main"
906 /*------------------------------------------------------------------------*/
907 /* SYMBOLS USED FOR C++ LOWERING */
908 /*------------------------------------------------------------------------*/
909 #define _TYPEINFO_ID_PREFIX "__TID_" /* Unique type id for RTTI */
910 #define _TEMPLATE_MANGLED_ROOT "__tm__" /* mangled name root for */
911 /* template symbols. */
912 #define _TEMPLATE_SIGNATURES "__pt__" /* when distinct_template_ */
913 /* signatures is FALSE, */
914 /* template name is mangled*/
915 /* with this string. */
916 #define _PARTIAL_SPEC "__ps__" /* for the first argument */
917 /* list of a partial */
918 /* specialization, this */
919 /* string is used to mangle*/
920 /* the name. */
921 #endif