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