2065b626cc7d7bca8aead3a392ebf9f29e6aa7bf
[platform/upstream/binutils.git] / include / coff / sh.h
1 /*** coff information for Hitachi SH */
2
3 /********************** FILE HEADER **********************/
4
5 struct external_filehdr {
6         char f_magic[2];        /* magic number                 */
7         char f_nscns[2];        /* number of sections           */
8         char f_timdat[4];       /* time & date stamp            */
9         char f_symptr[4];       /* file pointer to symtab       */
10         char f_nsyms[4];        /* number of symtab entries     */
11         char f_opthdr[2];       /* sizeof(optional hdr)         */
12         char f_flags[2];        /* flags                        */
13 };
14
15
16
17 #define SH_ARCH_MAGIC_BIG       0x0500
18 #define SH_ARCH_MAGIC_LITTLE    0x0550  /* Little endian SH */
19 #define SH_ARCH_MAGIC_WINCE     0x01a2  /* Windows CE - little endian */
20
21
22 #define SHBADMAG(x) \
23  (((x).f_magic!=SH_ARCH_MAGIC_BIG) && \
24   ((x).f_magic!=SH_ARCH_MAGIC_WINCE) && \
25   ((x).f_magic!=SH_ARCH_MAGIC_LITTLE))
26
27 #define FILHDR  struct external_filehdr
28 #define FILHSZ  20
29
30
31 /********************** AOUT "OPTIONAL HEADER" **********************/
32
33
34 typedef struct 
35 {
36   char  magic[2];               /* type of file                         */
37   char  vstamp[2];              /* version stamp                        */
38   char  tsize[4];               /* text size in bytes, padded to FW bdry*/
39   char  dsize[4];               /* initialized data "  "                */
40   char  bsize[4];               /* uninitialized data "   "             */
41   char  entry[4];               /* entry pt.                            */
42   char  text_start[4];          /* base of text used for this file */
43   char  data_start[4];          /* base of data used for this file */
44 }
45 AOUTHDR;
46
47
48 #define AOUTHDRSZ 28
49 #define AOUTSZ 28
50
51
52
53 /* Define some NT default values.  */
54 /*  #define NT_IMAGE_BASE        0x400000 moved to internal.h */
55 #define NT_SECTION_ALIGNMENT 0x1000
56 #define NT_FILE_ALIGNMENT    0x200
57 #define NT_DEF_RESERVE       0x100000
58 #define NT_DEF_COMMIT        0x1000
59
60 /********************** SECTION HEADER **********************/
61
62
63 struct external_scnhdr {
64         char            s_name[8];      /* section name                 */
65         char            s_paddr[4];     /* physical address, aliased s_nlib */
66         char            s_vaddr[4];     /* virtual address              */
67         char            s_size[4];      /* section size                 */
68         char            s_scnptr[4];    /* file ptr to raw data for section */
69         char            s_relptr[4];    /* file ptr to relocation       */
70         char            s_lnnoptr[4];   /* file ptr to line numbers     */
71         char            s_nreloc[2];    /* number of relocation entries */
72         char            s_nlnno[2];     /* number of line number entries*/
73         char            s_flags[4];     /* flags                        */
74 };
75
76 /*
77  * names of "special" sections
78  */
79 #define _TEXT   ".text"
80 #define _DATA   ".data"
81 #define _BSS    ".bss"
82
83
84 #define SCNHDR  struct external_scnhdr
85 #define SCNHSZ  40
86
87
88 /********************** LINE NUMBERS **********************/
89
90 /* 1 line number entry for every "breakpointable" source line in a section.
91  * Line numbers are grouped on a per function basis; first entry in a function
92  * grouping will have l_lnno = 0 and in place of physical address will be the
93  * symbol table index of the function name.
94  */
95 struct external_lineno {
96         union {
97                 char l_symndx[4];       /* function name symbol index, iff l_lnno == 0*/
98                 char l_paddr[4];        /* (physical) address of line number    */
99         } l_addr;
100 #ifdef COFF_WITH_PE
101         char l_lnno[2]; /* line number          */
102 #else
103         char l_lnno[4]; /* line number          */
104 #endif
105 };
106
107 #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) (ext->l_lnno));
108 #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_32(abfd,val,  (bfd_byte *) (ext->l_lnno));
109
110 #define LINENO  struct external_lineno
111 #ifdef COFF_WITH_PE
112 #define LINESZ  6
113 #undef GET_LINENO_LNNO
114 #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
115 #undef PUT_LINENO_LNNO
116 #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val,  (bfd_byte *) (ext->l_lnno));
117 #else
118 #define LINESZ  8
119 #endif
120
121
122 /********************** SYMBOLS **********************/
123
124 #define E_SYMNMLEN      8       /* # characters in a symbol name        */
125 #define E_FILNMLEN      14      /* # characters in a file name          */
126 #define E_DIMNUM        4       /* # array dimensions in auxiliary entry */
127
128 struct external_syment 
129 {
130   union {
131     char e_name[E_SYMNMLEN];
132     struct {
133       char e_zeroes[4];
134       char e_offset[4];
135     } e;
136   } e;
137   char e_value[4];
138   char e_scnum[2];
139   char e_type[2];
140   char e_sclass[1];
141   char e_numaux[1];
142 };
143
144
145
146 #define N_BTMASK        (017)
147 #define N_TMASK         (060)
148 #define N_BTSHFT        (4)
149 #define N_TSHIFT        (2)
150   
151
152 union external_auxent {
153         struct {
154                 char x_tagndx[4];       /* str, un, or enum tag indx */
155                 union {
156                         struct {
157                             char  x_lnno[2]; /* declaration line number */
158                             char  x_size[2]; /* str/union/array size */
159                         } x_lnsz;
160                         char x_fsize[4];        /* size of function */
161                 } x_misc;
162                 union {
163                         struct {                /* if ISFCN, tag, or .bb */
164                             char x_lnnoptr[4];  /* ptr to fcn line # */
165                             char x_endndx[4];   /* entry ndx past block end */
166                         } x_fcn;
167                         struct {                /* if ISARY, up to 4 dimen. */
168                             char x_dimen[E_DIMNUM][2];
169                         } x_ary;
170                 } x_fcnary;
171                 char x_tvndx[2];                /* tv index */
172         } x_sym;
173
174         union {
175                 char x_fname[E_FILNMLEN];
176                 struct {
177                         char x_zeroes[4];
178                         char x_offset[4];
179                 } x_n;
180         } x_file;
181
182         struct {
183                 char x_scnlen[4];                       /* section length */
184                 char x_nreloc[2];       /* # relocation entries */
185                 char x_nlinno[2];       /* # line numbers */
186                 char x_checksum[4];     /* section COMDAT checksum */
187                 char x_associated[2];   /* COMDAT associated section index */
188                 char x_comdat[1];       /* COMDAT selection number */
189         } x_scn;
190
191         struct {
192                 char x_tvfill[4];       /* tv fill value */
193                 char x_tvlen[2];        /* length of .tv */
194                 char x_tvran[2][2];     /* tv range */
195         } x_tv;         /* info about .tv section (in auxent of symbol .tv)) */
196
197
198 };
199
200 #define SYMENT  struct external_syment
201 #define SYMESZ  18      
202 #define AUXENT  union external_auxent
203 #define AUXESZ  18
204
205
206
207 /********************** RELOCATION DIRECTIVES **********************/
208
209 /* The external reloc has an offset field, because some of the reloc
210    types on the h8 don't have room in the instruction for the entire
211    offset - eg the strange jump and high page addressing modes */
212
213 #ifndef COFF_WITH_PE
214 struct external_reloc {
215   char r_vaddr[4];
216   char r_symndx[4];
217   char r_offset[4];
218   char r_type[2];
219   char r_stuff[2];
220 };
221 #else
222 struct external_reloc {
223   char r_vaddr[4];
224   char r_symndx[4];
225   char r_type[2];
226 };
227 #endif
228
229
230 #define RELOC struct external_reloc
231 #ifdef COFF_WITH_PE
232 #define RELSZ 10
233 #else
234 #define RELSZ 16
235 #endif
236
237 /* SH relocation types.  Not all of these are actually used.  */
238
239 #define R_SH_UNUSED     0               /* only used internally */
240 #define R_SH_IMM32CE    2               /* 32 bit immediate for WinCE */
241 #define R_SH_PCREL8     3               /*  8 bit pcrel         */
242 #define R_SH_PCREL16    4               /* 16 bit pcrel         */
243 #define R_SH_HIGH8      5               /* high 8 bits of 24 bit address */
244 #define R_SH_LOW16      7               /* low 16 bits of 24 bit immediate */
245 #define R_SH_IMM24      6               /* 24 bit immediate */
246 #define R_SH_PCDISP8BY4 9               /* PC rel 8 bits *4 +ve */
247 #define R_SH_PCDISP8BY2 10              /* PC rel 8 bits *2 +ve */
248 #define R_SH_PCDISP8    11              /* 8 bit branch */
249 #define R_SH_PCDISP     12              /* 12 bit branch */
250 #define R_SH_IMM32      14              /* 32 bit immediate */
251 #define R_SH_IMM8       16              /* 8 bit immediate */
252 #define R_SH_IMAGEBASE  16              /* Windows CE */
253 #define R_SH_IMM8BY2    17              /* 8 bit immediate *2 */
254 #define R_SH_IMM8BY4    18              /* 8 bit immediate *4 */
255 #define R_SH_IMM4       19              /* 4 bit immediate */
256 #define R_SH_IMM4BY2    20              /* 4 bit immediate *2 */
257 #define R_SH_IMM4BY4    21              /* 4 bit immediate *4 */
258 #define R_SH_PCRELIMM8BY2   22          /* PC rel 8 bits *2 unsigned */
259 #define R_SH_PCRELIMM8BY4   23          /* PC rel 8 bits *4 unsigned */
260 #define R_SH_IMM16      24              /* 16 bit immediate */
261
262 /* The switch table reloc types are used for relaxing.  They are
263    generated for expressions such as
264      .word L1 - L2
265    The r_offset field holds the difference between the reloc address
266    and L2.  */
267 #define R_SH_SWITCH8    33              /* 8 bit switch table entry */
268 #define R_SH_SWITCH16   25              /* 16 bit switch table entry */
269 #define R_SH_SWITCH32   26              /* 32 bit switch table entry */
270
271 /* The USES reloc type is used for relaxing.  The compiler will
272    generate .uses pseudo-ops when it finds a function call which it
273    can relax.  The r_offset field of the USES reloc holds the PC
274    relative offset to the instruction which loads the register used in
275    the function call.  */
276 #define R_SH_USES       27              /* .uses pseudo-op */
277
278 /* The COUNT reloc type is used for relaxing.  The assembler will
279    generate COUNT relocs for addresses referred to by the register
280    loads associated with USES relocs.  The r_offset field of the COUNT
281    reloc holds the number of times the address is referenced in the
282    object file.  */
283 #define R_SH_COUNT      28              /* Count of constant pool uses */
284
285 /* The ALIGN reloc type is used for relaxing.  The r_offset field is
286    the power of two to which subsequent portions of the object file
287    must be aligned.  */
288 #define R_SH_ALIGN      29              /* .align pseudo-op */
289
290 /* The CODE and DATA reloc types are used for aligning load and store
291    instructions.  The assembler will generate a CODE reloc before a
292    block of instructions.  It will generate a DATA reloc before data.
293    A section should be processed assuming it contains data, unless a
294    CODE reloc is seen.  The only relevant pieces of information in the
295    CODE and DATA relocs are the section and the address.  The symbol
296    and offset are meaningless.  */
297 #define R_SH_CODE       30              /* start of code */
298 #define R_SH_DATA       31              /* start of data */
299
300 /* The LABEL reloc type is used for aligning load and store
301    instructions.  The assembler will generate a LABEL reloc for each
302    label within a block of instructions.  This permits the linker to
303    avoid swapping instructions which are the targets of branches.  */
304 #define R_SH_LABEL      32              /* label */
305
306 /* NB: R_SH_SWITCH8 is 33 */