OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [include/] [coff/] [ti.h] - Blame information for rev 1765

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.