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