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