* config/tc-openrisc.c (openrisc_relax_frag): Delete unused function.
[deliverable/binutils-gdb.git] / gas / config / tc-openrisc.c
1 /* tc-openrisc.c -- Assembler for the OpenRISC family.
2 Copyright 2001, 2002, 2003, 2005 Free Software Foundation.
3 Contributed by Johan Rydberg, jrydberg@opencores.org
4
5 This file is part of GAS, the GNU Assembler.
6
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include <stdio.h>
23 #include "as.h"
24 #include "subsegs.h"
25 #include "symcat.h"
26 #include "opcodes/openrisc-desc.h"
27 #include "opcodes/openrisc-opc.h"
28 #include "cgen.h"
29
30 /* Structure to hold all of the different components describing
31 an individual instruction. */
32 typedef struct openrisc_insn openrisc_insn;
33
34 struct openrisc_insn
35 {
36 const CGEN_INSN * insn;
37 const CGEN_INSN * orig_insn;
38 CGEN_FIELDS fields;
39 #if CGEN_INT_INSN_P
40 CGEN_INSN_INT buffer [1];
41 #define INSN_VALUE(buf) (*(buf))
42 #else
43 unsigned char buffer [CGEN_MAX_INSN_SIZE];
44 #define INSN_VALUE(buf) (buf)
45 #endif
46 char * addr;
47 fragS * frag;
48 int num_fixups;
49 fixS * fixups [GAS_CGEN_MAX_FIXUPS];
50 int indices [MAX_OPERAND_INSTANCES];
51 };
52
53
54 const char comment_chars[] = "#";
55 const char line_comment_chars[] = "#";
56 const char line_separator_chars[] = ";";
57 const char EXP_CHARS[] = "eE";
58 const char FLT_CHARS[] = "dD";
59
60 \f
61 #define OPENRISC_SHORTOPTS "m:"
62 const char * md_shortopts = OPENRISC_SHORTOPTS;
63
64 struct option md_longopts[] =
65 {
66 {NULL, no_argument, NULL, 0}
67 };
68 size_t md_longopts_size = sizeof (md_longopts);
69
70 unsigned long openrisc_machine = 0; /* default */
71
72 int
73 md_parse_option (c, arg)
74 int c ATTRIBUTE_UNUSED;
75 char * arg ATTRIBUTE_UNUSED;
76 {
77 return 0;
78 }
79
80 void
81 md_show_usage (stream)
82 FILE * stream ATTRIBUTE_UNUSED;
83 {
84 }
85
86 static void ignore_pseudo PARAMS ((int));
87
88 static void
89 ignore_pseudo (val)
90 int val ATTRIBUTE_UNUSED;
91 {
92 discard_rest_of_line ();
93 }
94
95 const char openrisc_comment_chars [] = ";#";
96
97 /* The target specific pseudo-ops which we support. */
98 const pseudo_typeS md_pseudo_table[] =
99 {
100 { "word", cons, 4 },
101 { "proc", ignore_pseudo, 0 },
102 { "endproc", ignore_pseudo, 0 },
103 { NULL, NULL, 0 }
104 };
105
106
107 \f
108 void
109 md_begin ()
110 {
111 /* Initialize the `cgen' interface. */
112
113 /* Set the machine number and endian. */
114 gas_cgen_cpu_desc = openrisc_cgen_cpu_open (CGEN_CPU_OPEN_MACHS, 0,
115 CGEN_CPU_OPEN_ENDIAN,
116 CGEN_ENDIAN_BIG,
117 CGEN_CPU_OPEN_END);
118 openrisc_cgen_init_asm (gas_cgen_cpu_desc);
119
120 /* This is a callback from cgen to gas to parse operands. */
121 cgen_set_parse_operand_fn (gas_cgen_cpu_desc, gas_cgen_parse_operand);
122 }
123
124 void
125 md_assemble (str)
126 char * str;
127 {
128 static int last_insn_had_delay_slot = 0;
129 openrisc_insn insn;
130 char * errmsg;
131
132 /* Initialize GAS's cgen interface for a new instruction. */
133 gas_cgen_init_parse ();
134
135 insn.insn = openrisc_cgen_assemble_insn
136 (gas_cgen_cpu_desc, str, & insn.fields, insn.buffer, & errmsg);
137
138 if (!insn.insn)
139 {
140 as_bad (errmsg);
141 return;
142 }
143
144 /* Doesn't really matter what we pass for RELAX_P here. */
145 gas_cgen_finish_insn (insn.insn, insn.buffer,
146 CGEN_FIELDS_BITSIZE (& insn.fields), 1, NULL);
147
148 last_insn_had_delay_slot
149 = CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_DELAY_SLOT);
150 }
151
152
153 /* The syntax in the manual says constants begin with '#'.
154 We just ignore it. */
155
156 void
157 md_operand (expressionP)
158 expressionS * expressionP;
159 {
160 if (* input_line_pointer == '#')
161 {
162 input_line_pointer ++;
163 expression (expressionP);
164 }
165 }
166
167 valueT
168 md_section_align (segment, size)
169 segT segment;
170 valueT size;
171 {
172 int align = bfd_get_section_alignment (stdoutput, segment);
173 return ((size + (1 << align) - 1) & (-1 << align));
174 }
175
176 symbolS *
177 md_undefined_symbol (name)
178 char * name ATTRIBUTE_UNUSED;
179 {
180 return 0;
181 }
182
183 \f
184 /* Interface to relax_segment. */
185
186 /* FIXME: Look through this. */
187
188 const relax_typeS md_relax_table[] =
189 {
190 /* The fields are:
191 1) most positive reach of this state,
192 2) most negative reach of this state,
193 3) how many bytes this mode will add to the size of the current frag
194 4) which index into the table to try if we can't fit into this one. */
195
196 /* The first entry must be unused because an `rlx_more' value of zero ends
197 each list. */
198 {1, 1, 0, 0},
199
200 /* The displacement used by GAS is from the end of the 2 byte insn,
201 so we subtract 2 from the following. */
202 /* 16 bit insn, 8 bit disp -> 10 bit range.
203 This doesn't handle a branch in the right slot at the border:
204 the "& -4" isn't taken into account. It's not important enough to
205 complicate things over it, so we subtract an extra 2 (or + 2 in -ve
206 case). */
207 {511 - 2 - 2, -512 - 2 + 2, 0, 2 },
208 /* 32 bit insn, 24 bit disp -> 26 bit range. */
209 {0x2000000 - 1 - 2, -0x2000000 - 2, 2, 0 },
210 /* Same thing, but with leading nop for alignment. */
211 {0x2000000 - 1 - 2, -0x2000000 - 2, 4, 0 }
212 };
213
214 /* Return an initial guess of the length by which a fragment must grow to
215 hold a branch to reach its destination.
216 Also updates fr_type/fr_subtype as necessary.
217
218 Called just before doing relaxation.
219 Any symbol that is now undefined will not become defined.
220 The guess for fr_var is ACTUALLY the growth beyond fr_fix.
221 Whatever we do to grow fr_fix or fr_var contributes to our returned value.
222 Although it may not be explicit in the frag, pretend fr_var starts with a
223 0 value. */
224
225 int
226 md_estimate_size_before_relax (fragP, segment)
227 fragS * fragP;
228 segT segment;
229 {
230 /* The only thing we have to handle here are symbols outside of the
231 current segment. They may be undefined or in a different segment in
232 which case linker scripts may place them anywhere.
233 However, we can't finish the fragment here and emit the reloc as insn
234 alignment requirements may move the insn about. */
235
236 if (S_GET_SEGMENT (fragP->fr_symbol) != segment)
237 {
238 /* The symbol is undefined in this segment.
239 Change the relaxation subtype to the max allowable and leave
240 all further handling to md_convert_frag. */
241 fragP->fr_subtype = 2;
242
243 {
244 const CGEN_INSN * insn;
245 int i;
246
247 /* Update the recorded insn.
248 Fortunately we don't have to look very far.
249 FIXME: Change this to record in the instruction the next higher
250 relaxable insn to use. */
251 for (i = 0, insn = fragP->fr_cgen.insn; i < 4; i++, insn++)
252 {
253 if ((strcmp (CGEN_INSN_MNEMONIC (insn),
254 CGEN_INSN_MNEMONIC (fragP->fr_cgen.insn))
255 == 0)
256 && CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED))
257 break;
258 }
259 if (i == 4)
260 abort ();
261
262 fragP->fr_cgen.insn = insn;
263 return 2;
264 }
265 }
266
267 return md_relax_table[fragP->fr_subtype].rlx_length;
268 }
269
270 /* *fragP has been relaxed to its final size, and now needs to have
271 the bytes inside it modified to conform to the new size.
272
273 Called after relaxation is finished.
274 fragP->fr_type == rs_machine_dependent.
275 fragP->fr_subtype is the subtype of what the address relaxed to. */
276
277 void
278 md_convert_frag (abfd, sec, fragP)
279 bfd * abfd ATTRIBUTE_UNUSED;
280 segT sec ATTRIBUTE_UNUSED;
281 fragS * fragP ATTRIBUTE_UNUSED;
282 {
283 /* FIXME */
284 }
285
286 \f
287 /* Functions concerning relocs. */
288
289 /* The location from which a PC relative jump should be calculated,
290 given a PC relative reloc. */
291
292 long
293 md_pcrel_from_section (fixP, sec)
294 fixS * fixP;
295 segT sec;
296 {
297 if (fixP->fx_addsy != (symbolS *) NULL
298 && (! S_IS_DEFINED (fixP->fx_addsy)
299 || S_GET_SEGMENT (fixP->fx_addsy) != sec))
300 {
301 /* The symbol is undefined (or is defined but not in this section).
302 Let the linker figure it out. */
303 return 0;
304 }
305
306 return (fixP->fx_frag->fr_address + fixP->fx_where) & ~1;
307 }
308
309
310 /* Return the bfd reloc type for OPERAND of INSN at fixup FIXP.
311 Returns BFD_RELOC_NONE if no reloc type can be found.
312 *FIXP may be modified if desired. */
313
314 bfd_reloc_code_real_type
315 md_cgen_lookup_reloc (insn, operand, fixP)
316 const CGEN_INSN * insn ATTRIBUTE_UNUSED;
317 const CGEN_OPERAND * operand;
318 fixS * fixP;
319 {
320 bfd_reloc_code_real_type type;
321
322 switch (operand->type)
323 {
324 case OPENRISC_OPERAND_ABS_26:
325 fixP->fx_pcrel = 0;
326 type = BFD_RELOC_OPENRISC_ABS_26;
327 goto emit;
328 case OPENRISC_OPERAND_DISP_26:
329 fixP->fx_pcrel = 1;
330 type = BFD_RELOC_OPENRISC_REL_26;
331 goto emit;
332
333 case OPENRISC_OPERAND_HI16:
334 type = BFD_RELOC_HI16;
335 goto emit;
336
337 case OPENRISC_OPERAND_LO16:
338 type = BFD_RELOC_LO16;
339 goto emit;
340
341 emit:
342 return type;
343
344 default : /* avoid -Wall warning */
345 break;
346 }
347
348 return BFD_RELOC_NONE;
349 }
350 \f
351 /* Write a value out to the object file, using the appropriate endianness. */
352
353 void
354 md_number_to_chars (buf, val, n)
355 char * buf;
356 valueT val;
357 int n;
358 {
359 number_to_chars_bigendian (buf, val, n);
360 }
361
362 /* Turn a string in input_line_pointer into a floating point constant of type
363 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
364 emitted is stored in *sizeP . An error message is returned, or NULL on OK.
365 */
366
367 /* Equal to MAX_PRECISION in atof-ieee.c */
368 #define MAX_LITTLENUMS 6
369
370 char *
371 md_atof (type, litP, sizeP)
372 char type;
373 char * litP;
374 int * sizeP;
375 {
376 int i;
377 int prec;
378 LITTLENUM_TYPE words [MAX_LITTLENUMS];
379 char * t;
380
381 switch (type)
382 {
383 case 'f':
384 case 'F':
385 case 's':
386 case 'S':
387 prec = 2;
388 break;
389
390 case 'd':
391 case 'D':
392 case 'r':
393 case 'R':
394 prec = 4;
395 break;
396
397 /* FIXME: Some targets allow other format chars for bigger sizes here. */
398
399 default:
400 * sizeP = 0;
401 return _("Bad call to md_atof()");
402 }
403
404 t = atof_ieee (input_line_pointer, type, words);
405 if (t)
406 input_line_pointer = t;
407 * sizeP = prec * sizeof (LITTLENUM_TYPE);
408
409 for (i = 0; i < prec; i++)
410 {
411 md_number_to_chars (litP, (valueT) words[i],
412 sizeof (LITTLENUM_TYPE));
413 litP += sizeof (LITTLENUM_TYPE);
414 }
415
416 return 0;
417 }
418
419 bfd_boolean
420 openrisc_fix_adjustable (fixP)
421 fixS * fixP;
422 {
423 /* We need the symbol name for the VTABLE entries */
424 if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
425 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
426 return 0;
427
428 return 1;
429 }
430
431
432
This page took 0.038097 seconds and 5 git commands to generate.