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