sh.h revision 33965
133965Sjdp/*** coff information for Hitachi SH */
233965Sjdp
333965Sjdp/********************** FILE HEADER **********************/
433965Sjdp
533965Sjdpstruct external_filehdr {
633965Sjdp	char f_magic[2];	/* magic number			*/
733965Sjdp	char f_nscns[2];	/* number of sections		*/
833965Sjdp	char f_timdat[4];	/* time & date stamp		*/
933965Sjdp	char f_symptr[4];	/* file pointer to symtab	*/
1033965Sjdp	char f_nsyms[4];	/* number of symtab entries	*/
1133965Sjdp	char f_opthdr[2];	/* sizeof(optional hdr)		*/
1233965Sjdp	char f_flags[2];	/* flags			*/
1333965Sjdp};
1433965Sjdp
1533965Sjdp
1633965Sjdp
1733965Sjdp#define	SH_ARCH_MAGIC_BIG	0x0500
1833965Sjdp#define	SH_ARCH_MAGIC_LITTLE	0x0550  /* Little endian SH */
1933965Sjdp
2033965Sjdp
2133965Sjdp#define SHBADMAG(x) \
2233965Sjdp (((x).f_magic!=SH_ARCH_MAGIC_BIG) && \
2333965Sjdp  ((x).f_magic!=SH_ARCH_MAGIC_LITTLE))
2433965Sjdp
2533965Sjdp#define	FILHDR	struct external_filehdr
2633965Sjdp#define	FILHSZ	20
2733965Sjdp
2833965Sjdp
2933965Sjdp/********************** AOUT "OPTIONAL HEADER" **********************/
3033965Sjdp
3133965Sjdp
3233965Sjdptypedef struct
3333965Sjdp{
3433965Sjdp  char 	magic[2];		/* type of file				*/
3533965Sjdp  char	vstamp[2];		/* version stamp			*/
3633965Sjdp  char	tsize[4];		/* text size in bytes, padded to FW bdry*/
3733965Sjdp  char	dsize[4];		/* initialized data "  "		*/
3833965Sjdp  char	bsize[4];		/* uninitialized data "   "		*/
3933965Sjdp  char	entry[4];		/* entry pt.				*/
4033965Sjdp  char 	text_start[4];		/* base of text used for this file */
4133965Sjdp  char 	data_start[4];		/* base of data used for this file */
4233965Sjdp}
4333965SjdpAOUTHDR;
4433965Sjdp
4533965Sjdp
4633965Sjdp#define AOUTHDRSZ 28
4733965Sjdp#define AOUTSZ 28
4833965Sjdp
4933965Sjdp
5033965Sjdp
5133965Sjdp
5233965Sjdp/********************** SECTION HEADER **********************/
5333965Sjdp
5433965Sjdp
5533965Sjdpstruct external_scnhdr {
5633965Sjdp	char		s_name[8];	/* section name			*/
5733965Sjdp	char		s_paddr[4];	/* physical address, aliased s_nlib */
5833965Sjdp	char		s_vaddr[4];	/* virtual address		*/
5933965Sjdp	char		s_size[4];	/* section size			*/
6033965Sjdp	char		s_scnptr[4];	/* file ptr to raw data for section */
6133965Sjdp	char		s_relptr[4];	/* file ptr to relocation	*/
6233965Sjdp	char		s_lnnoptr[4];	/* file ptr to line numbers	*/
6333965Sjdp	char		s_nreloc[2];	/* number of relocation entries	*/
6433965Sjdp	char		s_nlnno[2];	/* number of line number entries*/
6533965Sjdp	char		s_flags[4];	/* flags			*/
6633965Sjdp};
6733965Sjdp
6833965Sjdp/*
6933965Sjdp * names of "special" sections
7033965Sjdp */
7133965Sjdp#define _TEXT	".text"
7233965Sjdp#define _DATA	".data"
7333965Sjdp#define _BSS	".bss"
7433965Sjdp
7533965Sjdp
7633965Sjdp#define	SCNHDR	struct external_scnhdr
7733965Sjdp#define	SCNHSZ	40
7833965Sjdp
7933965Sjdp
8033965Sjdp/********************** LINE NUMBERS **********************/
8133965Sjdp
8233965Sjdp/* 1 line number entry for every "breakpointable" source line in a section.
8333965Sjdp * Line numbers are grouped on a per function basis; first entry in a function
8433965Sjdp * grouping will have l_lnno = 0 and in place of physical address will be the
8533965Sjdp * symbol table index of the function name.
8633965Sjdp */
8733965Sjdpstruct external_lineno {
8833965Sjdp	union {
8933965Sjdp		char l_symndx[4];	/* function name symbol index, iff l_lnno == 0*/
9033965Sjdp		char l_paddr[4];	/* (physical) address of line number	*/
9133965Sjdp	} l_addr;
9233965Sjdp	char l_lnno[4];	/* line number		*/
9333965Sjdp};
9433965Sjdp
9533965Sjdp#define GET_LINENO_LNNO(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) (ext->l_lnno));
9633965Sjdp#define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_32(abfd,val,  (bfd_byte *) (ext->l_lnno));
9733965Sjdp
9833965Sjdp#define	LINENO	struct external_lineno
9933965Sjdp#define	LINESZ	8
10033965Sjdp
10133965Sjdp
10233965Sjdp/********************** SYMBOLS **********************/
10333965Sjdp
10433965Sjdp#define E_SYMNMLEN	8	/* # characters in a symbol name	*/
10533965Sjdp#define E_FILNMLEN	14	/* # characters in a file name		*/
10633965Sjdp#define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
10733965Sjdp
10833965Sjdpstruct external_syment
10933965Sjdp{
11033965Sjdp  union {
11133965Sjdp    char e_name[E_SYMNMLEN];
11233965Sjdp    struct {
11333965Sjdp      char e_zeroes[4];
11433965Sjdp      char e_offset[4];
11533965Sjdp    } e;
11633965Sjdp  } e;
11733965Sjdp  char e_value[4];
11833965Sjdp  char e_scnum[2];
11933965Sjdp  char e_type[2];
12033965Sjdp  char e_sclass[1];
12133965Sjdp  char e_numaux[1];
12233965Sjdp};
12333965Sjdp
12433965Sjdp
12533965Sjdp
12633965Sjdp#define N_BTMASK	(017)
12733965Sjdp#define N_TMASK		(060)
12833965Sjdp#define N_BTSHFT	(4)
12933965Sjdp#define N_TSHIFT	(2)
13033965Sjdp
13133965Sjdp
13233965Sjdpunion external_auxent {
13333965Sjdp	struct {
13433965Sjdp		char x_tagndx[4];	/* str, un, or enum tag indx */
13533965Sjdp		union {
13633965Sjdp			struct {
13733965Sjdp			    char  x_lnno[2]; /* declaration line number */
13833965Sjdp			    char  x_size[2]; /* str/union/array size */
13933965Sjdp			} x_lnsz;
14033965Sjdp			char x_fsize[4];	/* size of function */
14133965Sjdp		} x_misc;
14233965Sjdp		union {
14333965Sjdp			struct {		/* if ISFCN, tag, or .bb */
14433965Sjdp			    char x_lnnoptr[4];	/* ptr to fcn line # */
14533965Sjdp			    char x_endndx[4];	/* entry ndx past block end */
14633965Sjdp			} x_fcn;
14733965Sjdp			struct {		/* if ISARY, up to 4 dimen. */
14833965Sjdp			    char x_dimen[E_DIMNUM][2];
14933965Sjdp			} x_ary;
15033965Sjdp		} x_fcnary;
15133965Sjdp		char x_tvndx[2];		/* tv index */
15233965Sjdp	} x_sym;
15333965Sjdp
15433965Sjdp	union {
15533965Sjdp		char x_fname[E_FILNMLEN];
15633965Sjdp		struct {
15733965Sjdp			char x_zeroes[4];
15833965Sjdp			char x_offset[4];
15933965Sjdp		} x_n;
16033965Sjdp	} x_file;
16133965Sjdp
16233965Sjdp	struct {
16333965Sjdp		char x_scnlen[4];			/* section length */
16433965Sjdp		char x_nreloc[2];	/* # relocation entries */
16533965Sjdp		char x_nlinno[2];	/* # line numbers */
16633965Sjdp	} x_scn;
16733965Sjdp
16833965Sjdp        struct {
16933965Sjdp		char x_tvfill[4];	/* tv fill value */
17033965Sjdp		char x_tvlen[2];	/* length of .tv */
17133965Sjdp		char x_tvran[2][2];	/* tv range */
17233965Sjdp	} x_tv;		/* info about .tv section (in auxent of symbol .tv)) */
17333965Sjdp
17433965Sjdp
17533965Sjdp};
17633965Sjdp
17733965Sjdp#define	SYMENT	struct external_syment
17833965Sjdp#define	SYMESZ	18
17933965Sjdp#define	AUXENT	union external_auxent
18033965Sjdp#define	AUXESZ	18
18133965Sjdp
18233965Sjdp
18333965Sjdp
18433965Sjdp/********************** RELOCATION DIRECTIVES **********************/
18533965Sjdp
18633965Sjdp/* The external reloc has an offset field, because some of the reloc
18733965Sjdp   types on the h8 don't have room in the instruction for the entire
18833965Sjdp   offset - eg the strange jump and high page addressing modes */
18933965Sjdp
19033965Sjdpstruct external_reloc {
19133965Sjdp  char r_vaddr[4];
19233965Sjdp  char r_symndx[4];
19333965Sjdp  char r_offset[4];
19433965Sjdp  char r_type[2];
19533965Sjdp  char r_stuff[2];
19633965Sjdp};
19733965Sjdp
19833965Sjdp
19933965Sjdp#define RELOC struct external_reloc
20033965Sjdp#define RELSZ 16
20133965Sjdp
20233965Sjdp/* SH relocation types.  Not all of these are actually used.  */
20333965Sjdp
20433965Sjdp#define R_SH_UNUSED	0		/* only used internally */
20533965Sjdp#define R_SH_PCREL8 	3		/*  8 bit pcrel 	*/
20633965Sjdp#define R_SH_PCREL16 	4		/* 16 bit pcrel 	*/
20733965Sjdp#define R_SH_HIGH8  	5		/* high 8 bits of 24 bit address */
20833965Sjdp#define R_SH_LOW16 	7		/* low 16 bits of 24 bit immediate */
20933965Sjdp#define R_SH_IMM24	6		/* 24 bit immediate */
21033965Sjdp#define R_SH_PCDISP8BY4	9  		/* PC rel 8 bits *4 +ve */
21133965Sjdp#define R_SH_PCDISP8BY2	10  		/* PC rel 8 bits *2 +ve */
21233965Sjdp#define R_SH_PCDISP8    11  		/* 8 bit branch */
21333965Sjdp#define R_SH_PCDISP     12  		/* 12 bit branch */
21433965Sjdp#define R_SH_IMM32      14    		/* 32 bit immediate */
21533965Sjdp#define R_SH_IMM8   	16		/* 8 bit immediate */
21633965Sjdp#define R_SH_IMM8BY2    17		/* 8 bit immediate *2 */
21733965Sjdp#define R_SH_IMM8BY4    18		/* 8 bit immediate *4 */
21833965Sjdp#define R_SH_IMM4   	19		/* 4 bit immediate */
21933965Sjdp#define R_SH_IMM4BY2    20		/* 4 bit immediate *2 */
22033965Sjdp#define R_SH_IMM4BY4    21		/* 4 bit immediate *4 */
22133965Sjdp#define R_SH_PCRELIMM8BY2   22		/* PC rel 8 bits *2 unsigned */
22233965Sjdp#define R_SH_PCRELIMM8BY4   23		/* PC rel 8 bits *4 unsigned */
22333965Sjdp#define R_SH_IMM16      24    		/* 16 bit immediate */
22433965Sjdp
22533965Sjdp/* The switch table reloc types are used for relaxing.  They are
22633965Sjdp   generated for expressions such as
22733965Sjdp     .word L1 - L2
22833965Sjdp   The r_offset field holds the difference between the reloc address
22933965Sjdp   and L2.  */
23033965Sjdp#define R_SH_SWITCH16	25		/* 16 bit switch table entry */
23133965Sjdp#define R_SH_SWITCH32	26		/* 32 bit switch table entry */
23233965Sjdp
23333965Sjdp/* The USES reloc type is used for relaxing.  The compiler will
23433965Sjdp   generate .uses pseudo-ops when it finds a function call which it
23533965Sjdp   can relax.  The r_offset field of the USES reloc holds the PC
23633965Sjdp   relative offset to the instruction which loads the register used in
23733965Sjdp   the function call.  */
23833965Sjdp#define R_SH_USES	27		/* .uses pseudo-op */
23933965Sjdp
24033965Sjdp/* The COUNT reloc type is used for relaxing.  The assembler will
24133965Sjdp   generate COUNT relocs for addresses referred to by the register
24233965Sjdp   loads associated with USES relocs.  The r_offset field of the COUNT
24333965Sjdp   reloc holds the number of times the address is referenced in the
24433965Sjdp   object file.  */
24533965Sjdp#define R_SH_COUNT	28		/* Count of constant pool uses */
24633965Sjdp
24733965Sjdp/* The ALIGN reloc type is used for relaxing.  The r_offset field is
24833965Sjdp   the power of two to which subsequent portions of the object file
24933965Sjdp   must be aligned.  */
25033965Sjdp#define R_SH_ALIGN	29		/* .align pseudo-op */
25133965Sjdp
25233965Sjdp/* The CODE and DATA reloc types are used for aligning load and store
25333965Sjdp   instructions.  The assembler will generate a CODE reloc before a
25433965Sjdp   block of instructions.  It will generate a DATA reloc before data.
25533965Sjdp   A section should be processed assuming it contains data, unless a
25633965Sjdp   CODE reloc is seen.  The only relevant pieces of information in the
25733965Sjdp   CODE and DATA relocs are the section and the address.  The symbol
25833965Sjdp   and offset are meaningless.  */
25933965Sjdp#define R_SH_CODE	30		/* start of code */
26033965Sjdp#define R_SH_DATA	31		/* start of data */
26133965Sjdp
26233965Sjdp/* The LABEL reloc type is used for aligning load and store
26333965Sjdp   instructions.  The assembler will generate a LABEL reloc for each
26433965Sjdp   label within a block of instructions.  This permits the linker to
26533965Sjdp   avoid swapping instructions which are the targets of branches.  */
26633965Sjdp#define R_SH_LABEL	32		/* label */
267