1/* COFF specification for OpenRISC 1000.
2   Copyright (C) 1993-2000, 2002 Free Software Foundation, Inc.
3   Contributed by David Wood @ New York University.
4   Modified by Johan Rydberg, <johan.rydberg@netinsight.se>
5
6   This file is part of BFD, the Binary File Descriptor library.
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2 of the License, or
11   (at your option) any later version.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with this program; if not, write to the Free Software
20   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
21
22#ifndef OR32
23# define OR32
24#endif
25
26/* File Header and related definitions.  */
27struct 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};
37
38#define FILHDR  struct external_filehdr
39#define FILHSZ	20
40
41/* Magic numbers for OpenRISC 1000. As it is know we use the
42   numbers for Am29000.
43
44   (AT&T will assign the "real" magic number).  */
45#define SIPFBOMAGIC     0572    /* Am29000 (Byte 0 is MSB).  */
46#define SIPRBOMAGIC     0573    /* Am29000 (Byte 0 is LSB).  */
47
48#define OR32_MAGIC_BIG 		SIPFBOMAGIC
49#define OR32_MAGIC_LITTLE	SIPRBOMAGIC
50#define OR32BADMAG(x)     (((x).f_magic!=OR32_MAGIC_BIG) && \
51			                      ((x).f_magic!=OR32_MAGIC_LITTLE))
52
53#define OMAGIC OR32_MAGIC_BIG
54
55/* Optional (a.out) header.  */
56typedef	struct external_aouthdr
57{
58  char  magic[2];         /* type of file                     */
59  char  vstamp[2];	  /* version stamp                    */
60  char  tsize[4];	  /* text size in bytes, padded to FW bdry */
61  char  dsize[4];	  /* initialized data "  "            */
62  char  bsize[4];	  /* uninitialized data "   "         */
63  char  entry[4];	  /* entry pt.                        */
64  char  text_start[4];	  /* base of text used for this file  */
65  char  data_start[4];	  /* base of data used for this file  */
66} AOUTHDR;
67
68#define AOUTSZ      28
69#define AOUTHDRSZ   28
70
71/* aouthdr magic numbers.  */
72#define NMAGIC    0410	  /* separate i/d executable.  */
73#define SHMAGIC   0406	  /* NYU/Ultra3 shared data executable
74                             (writable text).  */
75
76#define _ETEXT   	"_etext"
77
78/* Section header and related definitions.  */
79struct external_scnhdr
80{
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#define	SCNHDR	struct external_scnhdr
94#define	SCNHSZ	40
95
96/* Names of "special" sections:  */
97#define _TEXT   ".text"
98#define _DATA   ".data"
99#define _BSS    ".bss"
100#define _LIT    ".lit"
101
102/* Section types - with additional section type for global
103   registers which will be relocatable for the OpenRISC 1000.
104
105   In instances where it is necessary for a linker to produce an
106   output file which contains text or data not based at virtual
107   address 0, e.g. for a ROM, then the linker should accept
108   address base information as command input and use PAD sections
109   to skip over unused addresses.  */
110#define	STYP_BSSREG 0x1200	/* Global register area (like STYP_INFO) */
111#define STYP_ENVIR  0x2200	/* Environment (like STYP_INFO) */
112#define STYP_ABS    0x4000	/* Absolute (allocated, not reloc, loaded) */
113
114/* Relocation information declaration and related definitions:  */
115struct external_reloc
116{
117  char r_vaddr[4];    /* (virtual) address of reference */
118  char r_symndx[4];   /* index into symbol table */
119  char r_type[2];     /* relocation type */
120};
121
122#define	RELOC		struct external_reloc
123#define	RELSZ		10		/* sizeof (RELOC) */
124
125/* Relocation types for the OpenRISC 1000: */
126
127#define	R_ABS     0     /* reference is absolute */
128#define	R_IREL    030	/* instruction relative (jmp/call) */
129#define	R_IABS    031	/* instruction absolute (jmp/call) */
130#define	R_ILOHALF 032	/* instruction low half  (const)  */
131#define	R_IHIHALF 033	/* instruction high half (consth) part 1 */
132#define	R_IHCONST 034	/* instruction high half (consth) part 2 */
133                        /* constant offset of R_IHIHALF relocation */
134#define	R_BYTE    035	/* relocatable byte value */
135#define R_HWORD   036	/* relocatable halfword value */
136#define R_WORD    037	/* relocatable word value */
137
138#define	R_IGLBLRC 040	/* instruction global register RC */
139#define	R_IGLBLRA 041	/* instruction global register RA */
140#define	R_IGLBLRB 042	/* instruction global register RB */
141
142/*
143  NOTE:
144  All the "I" forms refer to 29000 instruction formats.  The linker is
145  expected to know how the numeric information is split and/or aligned
146  within the instruction word(s).  R_BYTE works for instructions, too.
147
148  If the parameter to a CONSTH instruction is a relocatable type, two
149  relocation records are written.  The first has an r_type of R_IHIHALF
150  (33 octal) and a normal r_vaddr and r_symndx.  The second relocation
151  record has an r_type of R_IHCONST (34 octal), a normal r_vaddr (which
152  is redundant), and an r_symndx containing the 32-bit constant offset
153  to the relocation instead of the actual symbol table index.  This
154  second record is always written, even if the constant offset is zero.
155  The constant fields of the instruction are set to zero.  */
156
157/* Line number entry declaration and related definitions:  */
158struct external_lineno
159{
160  union
161  {
162    char l_symndx[4];  /* function name symbol index, iff l_lnno == 0*/
163    char l_paddr[4];   /* (physical) address of line number    */
164  }
165  l_addr;
166
167  char l_lnno[2];      /* line number	  */
168};
169
170#define	LINENO		struct external_lineno
171#define	LINESZ		6		  /* sizeof (LINENO) */
172
173/* Symbol entry declaration and related definitions:  */
174#define	E_SYMNMLEN	8	  /* Number of characters in a symbol name */
175
176struct external_syment
177{
178  union
179  {
180    char e_name[E_SYMNMLEN];
181    struct
182    {
183      char e_zeroes[4];
184      char e_offset[4];
185    }
186    e;
187  }
188  e;
189
190  char e_value[4];
191  char e_scnum[2];
192  char e_type[2];
193  char e_sclass[1];
194  char e_numaux[1];
195};
196
197#define	SYMENT	struct external_syment
198#define	SYMESZ 	18
199
200/* Storage class definitions - new classes for global registers:  */
201#define C_GLBLREG	19		/* global register */
202#define C_EXTREG	20		/* external global register */
203#define	C_DEFREG	21		/* ext. def. of global register */
204
205/* Derived symbol mask/shifts:  */
206#define N_BTMASK	(0xf)
207#define N_BTSHFT	(4)
208#define N_TMASK		(0x30)
209#define N_TSHIFT	(2)
210
211/* Auxiliary symbol table entry declaration and related
212   definitions.  */
213#define E_FILNMLEN  14  /* # characters in a file name	  */
214#define E_DIMNUM    4   /* # array dimensions in auxiliary entry */
215
216union external_auxent
217{
218  struct
219  {
220    char x_tagndx[4];       /* str, un, or enum tag indx */
221    union
222    {
223      struct
224      {
225	char  x_lnno[2];    /* declaration line number */
226        char  x_size[2];    /* str/union/array size */
227      }
228      x_lnsz;
229
230      char x_fsize[4];      /* size of function */
231    }
232    x_misc;
233
234    union
235    {
236      struct 		          /* if ISFCN, tag, or .bb */
237      {
238	char x_lnnoptr[4];  /* ptr to fcn line # */
239        char x_endndx[4];   /* entry ndx past block end */
240      }
241      x_fcn;
242
243      struct   	          /* if ISARY, up to 4 dimen. */
244      {
245	char x_dimen[E_DIMNUM][2];
246      }
247      x_ary;
248    }
249    x_fcnary;
250
251    char x_tvndx[2];        /* tv index */
252  }
253  x_sym;
254
255  union
256  {
257    char x_fname[E_FILNMLEN];
258
259    struct
260    {
261      char x_zeroes[4];
262      char x_offset[4];
263    }
264    x_n;
265  }
266  x_file;
267
268  struct
269  {
270    char x_scnlen[4];       /* section length */
271    char x_nreloc[2];       /* # relocation entries */
272    char x_nlinno[2];       /* # line numbers */
273  }
274  x_scn;
275
276  struct
277  {
278    char x_tvfill[4];       /* tv fill value */
279    char x_tvlen[2];        /* length of .tv */
280    char x_tvran[2][2];     /* tv range */
281  }
282  x_tv;                   /* info about .tv section
283			     (in auxent of symbol .tv)) */
284};
285
286#define	AUXENT		union external_auxent
287#define	AUXESZ		18
288