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