1 /* Motorola MCore support for BFD.
2    Copyright (C) 1999 Free Software Foundation, Inc.
3 
4 This file is part of BFD, the Binary File Descriptor library.
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19 
20 /* This file holds definitions specific to the MCore COFF/PE ABI. */
21 
22 #ifndef _COFF_MORE_H
23 #define _COFF_MORE_H
24 
25 
26 #define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
27 
28 #define IMAGE_REL_MCORE_ABSOLUTE          	0x0000
29 #define IMAGE_REL_MCORE_ADDR32            	0x0001
30 #define IMAGE_REL_MCORE_PCREL_IMM8BY4		0x0002
31 #define IMAGE_REL_MCORE_PCREL_IMM11BY2		0x0003
32 #define IMAGE_REL_MCORE_PCREL_IMM4BY2		0x0004
33 #define IMAGE_REL_MCORE_PCREL_32		0x0005
34 #define IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2	0x0006
35 #define IMAGE_REL_MCORE_RVA			0x0007
36 
37 #define PEMCORE
38 
39 typedef struct
40 {
41   char 	magic      [2];		/* type of file				*/
42   char	vstamp     [2];		/* version stamp			*/
43   char	tsize      [4];		/* text size in bytes, padded to FW bdry*/
44   char	dsize      [4];		/* initialized data "  "		*/
45   char	bsize      [4];		/* uninitialized data "   "		*/
46   char	entry      [4];		/* entry pt.				*/
47   char 	text_start [4];		/* base of text used for this file */
48   char 	data_start [4];		/* base of data used for this file */
49 }
50 AOUTHDR;
51 
52 #define AOUTSZ 28
53 #define AOUTHDRSZ 28
54 
55 #define OMAGIC          0404    /* object files, eg as output */
56 #define ZMAGIC          0413    /* demand load format, eg normal ld output */
57 #define STMAGIC		0401	/* target shlib */
58 #define SHMAGIC		0443	/* host   shlib */
59 
60 /* From winnt.h */
61 #define IMAGE_NT_OPTIONAL_HDR_MAGIC        0x10b
62 
63 
64 /* Define some NT default values. */
65 #define NT_SECTION_ALIGNMENT 0x1000
66 #define NT_FILE_ALIGNMENT    0x200
67 #define NT_DEF_RESERVE       0x100000
68 #define NT_DEF_COMMIT        0x1000
69 
70 
71 struct external_reloc
72 {
73   char r_vaddr  [4];
74   char r_symndx [4];
75   char r_type   [2];
76   char r_offset [4];
77 };
78 
79 #define RELOC struct external_reloc
80 #define RELSZ 14
81 
82 #define	MCOREMAGIC	0xb00  /* I just made this up */
83 
84 #define MCOREBADMAG(x) (((x).f_magic!= MCOREMAGIC))
85 
86 struct external_filehdr
87 {
88   char f_magic  [2];	/* magic number			*/
89   char f_nscns  [2];	/* number of sections		*/
90   char f_timdat [4];	/* time & date stamp		*/
91   char f_symptr [4];	/* file pointer to symtab	*/
92   char f_nsyms  [4];	/* number of symtab entries	*/
93   char f_opthdr [2];	/* sizeof(optional hdr)		*/
94   char f_flags  [2];	/* flags			*/
95 };
96 
97 #define	FILHDR	struct external_filehdr
98 #define	FILHSZ	20
99 
100 
101 #define E_SYMNMLEN	8	/* # characters in a symbol name	*/
102 #define E_FILNMLEN	14	/* # characters in a file name		*/
103 #define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
104 
105 struct external_syment
106 {
107   union
108   {
109     char e_name [E_SYMNMLEN];
110     struct
111     {
112       char e_zeroes [4];
113       char e_offset [4];
114     } e;
115   } e;
116 
117   char e_value  [4];
118   char e_scnum  [2];
119   char e_type   [2];
120   char e_sclass [1];
121   char e_numaux [1];
122 };
123 
124 #define N_BTMASK	0xf
125 #define N_TMASK		0x30
126 #define N_BTSHFT	4
127 #define N_TSHIFT	2
128 
129 union external_auxent
130 {
131   struct
132   {
133     char x_tagndx [4];		/* str, un, or enum tag indx */
134 
135     union
136     {
137       struct
138       {
139 	char  x_lnno [2]; 	/* declaration line number */
140 	char  x_size [2]; 	/* str/union/array size */
141       } x_lnsz;
142 
143       char x_fsize [4];		/* size of function */
144 
145     } x_misc;
146 
147     union
148     {
149       struct 			/* if ISFCN, tag, or .bb */
150       {
151 	char x_lnnoptr [4];	/* ptr to fcn line # */
152 	char x_endndx  [4];	/* entry ndx past block end */
153       } x_fcn;
154 
155       struct 			/* if ISARY, up to 4 dimen. */
156       {
157 	char x_dimen [E_DIMNUM][2];
158       } x_ary;
159 
160     } x_fcnary;
161 
162     char x_tvndx [2];		/* tv index */
163 
164   } x_sym;
165 
166   union
167   {
168     char x_fname [E_FILNMLEN];
169 
170     struct
171     {
172       char x_zeroes [4];
173       char x_offset [4];
174     } x_n;
175 
176   } x_file;
177 
178   struct
179   {
180     char x_scnlen     [4];	/* section length */
181     char x_nreloc     [2];	/* # relocation entries */
182     char x_nlinno     [2];	/* # line numbers */
183     char x_checksum   [4];	/* section COMDAT checksum */
184     char x_associated [2];	/* COMDAT associated section index */
185     char x_comdat     [1];	/* COMDAT selection number */
186   } x_scn;
187 
188   struct
189   {
190     char x_tvfill [4];		/* tv fill value */
191     char x_tvlen  [2];		/* length of .tv */
192     char x_tvran  [2][2];	/* tv range */
193   } x_tv;			/* info about .tv section (in auxent of symbol .tv)) */
194 };
195 
196 #define	SYMENT	struct external_syment
197 #define	SYMESZ	18
198 #define	AUXENT	union external_auxent
199 #define	AUXESZ	18
200 
201 /* 1 line number entry for every "breakpointable" source line in a section.
202    Line numbers are grouped on a per function basis; first entry in a function
203    grouping will have l_lnno = 0 and in place of physical address will be the
204    symbol table index of the function name.  */
205 struct external_lineno
206 {
207   union
208   {
209     char l_symndx [4];	/* function name symbol index, iff l_lnno == 0*/
210     char l_paddr  [4];	/* (physical) address of line number	*/
211   } l_addr;
212 
213   char l_lnno [2];	/* line number		*/
214 };
215 
216 #define	LINENO	struct external_lineno
217 #define	LINESZ	6
218 
219 #define GET_LINENO_LNNO(abfd, ext)     bfd_h_get_32 (abfd, (bfd_byte *) (ext->l_lnno));
220 #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_32 (abfd, val, (bfd_byte *) (ext->l_lnno));
221 
222 struct external_scnhdr
223 {
224   char	s_name    [8];	/* section name			*/
225   char	s_paddr   [4];	/* physical address, aliased s_nlib */
226   char	s_vaddr   [4];	/* virtual address		*/
227   char	s_size    [4];	/* section size			*/
228   char	s_scnptr  [4];	/* file ptr to raw data for section */
229   char	s_relptr  [4];	/* file ptr to relocation	*/
230   char	s_lnnoptr [4];	/* file ptr to line numbers	*/
231   char	s_nreloc  [2];	/* number of relocation entries	*/
232   char	s_nlnno   [2];	/* number of line number entries*/
233   char	s_flags   [4];	/* flags			*/
234 };
235 
236 #define	SCNHDR	struct external_scnhdr
237 #define	SCNHSZ	40
238 
239 /* Names of "special" sections.  */
240 #define _TEXT	".text"
241 #define _DATA	".data"
242 #define _BSS	".bss"
243 
244 
245 
246 #endif /* __COFF_MCORE_H */
247