* ser-mingw.c (pipe_windows_open)
[deliverable/binutils-gdb.git] / gas / cgen.c
CommitLineData
252b5132 1/* GAS interface for targets using CGEN: Cpu tools GENerator.
ebd1c875
AM
2 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006 Free Software Foundation, Inc.
252b5132 4
2ab1486e 5 This file is part of GAS, the GNU Assembler.
252b5132 6
2ab1486e
NC
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.
252b5132 11
2ab1486e
NC
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.
252b5132 16
2ab1486e
NC
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 the Free Software
4b4da160 19 Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
252b5132
RH
20
21#include <setjmp.h>
ebd1c875 22#include "as.h"
252b5132
RH
23#include "symcat.h"
24#include "cgen-desc.h"
252b5132
RH
25#include "subsegs.h"
26#include "cgen.h"
272d76e0 27#include "dwarf2dbg.h"
252b5132 28
73ee5e4c 29static void queue_fixup (int, int, expressionS *);
0609eb57 30
252b5132
RH
31/* Opcode table descriptor, must be set by md_begin. */
32
33CGEN_CPU_DESC gas_cgen_cpu_desc;
34
35/* Callback to insert a register into the symbol table.
36 A target may choose to let GAS parse the registers.
37 ??? Not currently used. */
38
39void
40cgen_asm_record_register (name, number)
542d6675 41 char *name;
252b5132
RH
42 int number;
43{
44 /* Use symbol_create here instead of symbol_new so we don't try to
45 output registers into the object file's symbol table. */
46 symbol_table_insert (symbol_create (name, reg_section,
542d6675 47 number, &zero_address_frag));
252b5132
RH
48}
49
50/* We need to keep a list of fixups. We can't simply generate them as
51 we go, because that would require us to first create the frag, and
52 that would screw up references to ``.''.
53
54 This is used by cpu's with simple operands. It keeps knowledge of what
55 an `expressionS' is and what a `fixup' is out of CGEN which for the time
56 being is preferable.
57
58 OPINDEX is the index in the operand table.
59 OPINFO is something the caller chooses to help in reloc determination. */
60
2ab1486e
NC
61struct fixup
62{
252b5132
RH
63 int opindex;
64 int opinfo;
65 expressionS exp;
66};
67
542d6675 68static struct fixup fixups[GAS_CGEN_MAX_FIXUPS];
252b5132
RH
69static int num_fixups;
70
71/* Prepare to parse an instruction.
72 ??? May wish to make this static and delete calls in md_assemble. */
73
74void
75gas_cgen_init_parse ()
76{
77 num_fixups = 0;
78}
79
80/* Queue a fixup. */
81
82static void
83queue_fixup (opindex, opinfo, expP)
84 int opindex;
eabed1c0 85 int opinfo;
252b5132
RH
86 expressionS * expP;
87{
88 /* We need to generate a fixup for this expression. */
89 if (num_fixups >= GAS_CGEN_MAX_FIXUPS)
90 as_fatal (_("too many fixups"));
30a2b4ef 91 fixups[num_fixups].exp = *expP;
252b5132
RH
92 fixups[num_fixups].opindex = opindex;
93 fixups[num_fixups].opinfo = opinfo;
94 ++ num_fixups;
95}
96
002de68b
JH
97/* The following functions allow fixup chains to be stored, retrieved,
98 and swapped. They are a generalization of a pre-existing scheme
99 for storing, restoring and swapping fixup chains that was used by
100 the m32r port. The functionality is essentially the same, only
101 instead of only being able to store a single fixup chain, an entire
102 array of fixup chains can be stored. It is the user's responsibility
103 to keep track of how many fixup chains have been stored and which
104 elements of the array they are in.
105
d1a6c242
KH
106 The algorithms used are the same as in the old scheme. Other than the
107 "array-ness" of the whole thing, the functionality is identical to the
002de68b
JH
108 old scheme.
109
110 gas_cgen_initialize_saved_fixups_array():
111 Sets num_fixups_in_chain to 0 for each element. Call this from
112 md_begin() if you plan to use these functions and you want the
2ab1486e 113 fixup count in each element to be set to 0 initially. This is
002de68b
JH
114 not necessary, but it's included just in case. It performs
115 the same function for each element in the array of fixup chains
116 that gas_init_parse() performs for the current fixups.
117
118 gas_cgen_save_fixups (element):
119 element - element number of the array you wish to store the fixups
120 to. No mechanism is built in for tracking what element
121 was last stored to.
122
123 gas_cgen_restore_fixups (element):
124 element - element number of the array you wish to restore the fixups
125 from.
126
127 gas_cgen_swap_fixups(int element):
128 element - swap the current fixups with those in this element number.
129*/
130
2ab1486e
NC
131struct saved_fixups
132{
232431a0
NC
133 struct fixup fixup_chain[GAS_CGEN_MAX_FIXUPS];
134 int num_fixups_in_chain;
002de68b 135};
252b5132 136
002de68b 137static struct saved_fixups stored_fixups[MAX_SAVED_FIXUP_CHAINS];
252b5132 138
232431a0 139void
002de68b 140gas_cgen_initialize_saved_fixups_array ()
252b5132 141{
232431a0
NC
142 int i = 0;
143
144 while (i < MAX_SAVED_FIXUP_CHAINS)
145 stored_fixups[i++].num_fixups_in_chain = 0;
252b5132
RH
146}
147
232431a0
NC
148void
149gas_cgen_save_fixups (i)
150 int i;
252b5132 151{
232431a0
NC
152 if (i < 0 || i >= MAX_SAVED_FIXUP_CHAINS)
153 {
154 as_fatal ("index into stored_fixups[] out of bounds");
155 return;
156 }
157
158 stored_fixups[i].num_fixups_in_chain = num_fixups;
159 memcpy (stored_fixups[i].fixup_chain, fixups,
160 sizeof (fixups[0]) * num_fixups);
161 num_fixups = 0;
252b5132
RH
162}
163
232431a0
NC
164void
165gas_cgen_restore_fixups (i)
166 int i;
252b5132 167{
232431a0
NC
168 if (i < 0 || i >= MAX_SAVED_FIXUP_CHAINS)
169 {
170 as_fatal ("index into stored_fixups[] out of bounds");
171 return;
172 }
173
174 num_fixups = stored_fixups[i].num_fixups_in_chain;
d1a6c242 175 memcpy (fixups, stored_fixups[i].fixup_chain,
232431a0
NC
176 (sizeof (stored_fixups[i].fixup_chain[0])) * num_fixups);
177 stored_fixups[i].num_fixups_in_chain = 0;
002de68b 178}
252b5132 179
232431a0
NC
180void
181gas_cgen_swap_fixups (i)
182 int i;
002de68b 183{
232431a0
NC
184 if (i < 0 || i >= MAX_SAVED_FIXUP_CHAINS)
185 {
186 as_fatal ("index into stored_fixups[] out of bounds");
187 return;
188 }
189
190 if (num_fixups == 0)
191 gas_cgen_restore_fixups (i);
192
193 else if (stored_fixups[i].num_fixups_in_chain == 0)
194 gas_cgen_save_fixups (i);
195
196 else
197 {
198 int tmp;
199 struct fixup tmp_fixup;
200
201 tmp = stored_fixups[i].num_fixups_in_chain;
202 stored_fixups[i].num_fixups_in_chain = num_fixups;
203 num_fixups = tmp;
204
205 for (tmp = GAS_CGEN_MAX_FIXUPS; tmp--;)
206 {
207 tmp_fixup = stored_fixups[i].fixup_chain [tmp];
208 stored_fixups[i].fixup_chain[tmp] = fixups [tmp];
209 fixups [tmp] = tmp_fixup;
210 }
252b5132
RH
211 }
212}
213
214/* Default routine to record a fixup.
215 This is a cover function to fix_new.
216 It exists because we record INSN with the fixup.
217
218 FRAG and WHERE are their respective arguments to fix_new_exp.
219 LENGTH is in bits.
220 OPINFO is something the caller chooses to help in reloc determination.
221
222 At this point we do not use a bfd_reloc_code_real_type for
223 operands residing in the insn, but instead just use the
224 operand index. This lets us easily handle fixups for any
55cf6793 225 operand type. We pick a BFD reloc type in md_apply_fix. */
252b5132
RH
226
227fixS *
228gas_cgen_record_fixup (frag, where, insn, length, operand, opinfo, symbol, offset)
229 fragS * frag;
230 int where;
231 const CGEN_INSN * insn;
232 int length;
233 const CGEN_OPERAND * operand;
234 int opinfo;
235 symbolS * symbol;
236 offsetT offset;
237{
542d6675 238 fixS *fixP;
252b5132
RH
239
240 /* It may seem strange to use operand->attrs and not insn->attrs here,
241 but it is the operand that has a pc relative relocation. */
252b5132
RH
242 fixP = fix_new (frag, where, length / 8, symbol, offset,
243 CGEN_OPERAND_ATTR_VALUE (operand, CGEN_OPERAND_PCREL_ADDR),
244 (bfd_reloc_code_real_type)
245 ((int) BFD_RELOC_UNUSED
246 + (int) operand->type));
247 fixP->fx_cgen.insn = insn;
248 fixP->fx_cgen.opinfo = opinfo;
249
250 return fixP;
251}
252
253/* Default routine to record a fixup given an expression.
254 This is a cover function to fix_new_exp.
255 It exists because we record INSN with the fixup.
256
257 FRAG and WHERE are their respective arguments to fix_new_exp.
258 LENGTH is in bits.
259 OPINFO is something the caller chooses to help in reloc determination.
260
261 At this point we do not use a bfd_reloc_code_real_type for
262 operands residing in the insn, but instead just use the
263 operand index. This lets us easily handle fixups for any
55cf6793 264 operand type. We pick a BFD reloc type in md_apply_fix. */
252b5132
RH
265
266fixS *
267gas_cgen_record_fixup_exp (frag, where, insn, length, operand, opinfo, exp)
268 fragS * frag;
269 int where;
270 const CGEN_INSN * insn;
271 int length;
272 const CGEN_OPERAND * operand;
273 int opinfo;
274 expressionS * exp;
275{
542d6675 276 fixS *fixP;
252b5132
RH
277
278 /* It may seem strange to use operand->attrs and not insn->attrs here,
279 but it is the operand that has a pc relative relocation. */
252b5132
RH
280 fixP = fix_new_exp (frag, where, length / 8, exp,
281 CGEN_OPERAND_ATTR_VALUE (operand, CGEN_OPERAND_PCREL_ADDR),
282 (bfd_reloc_code_real_type)
283 ((int) BFD_RELOC_UNUSED
284 + (int) operand->type));
285 fixP->fx_cgen.insn = insn;
286 fixP->fx_cgen.opinfo = opinfo;
287
288 return fixP;
289}
290
291/* Used for communication between the next two procedures. */
292static jmp_buf expr_jmp_buf;
680d2857 293static int expr_jmp_buf_p;
252b5132
RH
294
295/* Callback for cgen interface. Parse the expression at *STRP.
296 The result is an error message or NULL for success (in which case
297 *STRP is advanced past the parsed text).
298 WANT is an indication of what the caller is looking for.
299 If WANT == CGEN_ASM_PARSE_INIT the caller is beginning to try to match
300 a table entry with the insn, reset the queued fixups counter.
301 An enum cgen_parse_operand_result is stored in RESULTP.
302 OPINDEX is the operand's table entry index.
303 OPINFO is something the caller chooses to help in reloc determination.
304 The resulting value is stored in VALUEP. */
305
306const char *
307gas_cgen_parse_operand (cd, want, strP, opindex, opinfo, resultP, valueP)
eabed1c0 308 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
252b5132 309 enum cgen_parse_operand_type want;
542d6675 310 const char **strP;
252b5132
RH
311 int opindex;
312 int opinfo;
542d6675
KH
313 enum cgen_parse_operand_result *resultP;
314 bfd_vma *valueP;
252b5132
RH
315{
316#ifdef __STDC__
317 /* These are volatile to survive the setjmp. */
318 char * volatile hold;
319 enum cgen_parse_operand_result * volatile resultP_1;
199fea98 320 volatile int opinfo_1;
252b5132 321#else
542d6675
KH
322 static char *hold;
323 static enum cgen_parse_operand_result *resultP_1;
199fea98 324 int opinfo_1;
252b5132 325#endif
0609eb57 326 const char *errmsg;
252b5132
RH
327 expressionS exp;
328
329 if (want == CGEN_PARSE_OPERAND_INIT)
330 {
331 gas_cgen_init_parse ();
332 return NULL;
333 }
334
335 resultP_1 = resultP;
336 hold = input_line_pointer;
542d6675 337 input_line_pointer = (char *) *strP;
199fea98 338 opinfo_1 = opinfo;
252b5132
RH
339
340 /* We rely on md_operand to longjmp back to us.
341 This is done via gas_cgen_md_operand. */
342 if (setjmp (expr_jmp_buf) != 0)
343 {
680d2857 344 expr_jmp_buf_p = 0;
252b5132 345 input_line_pointer = (char *) hold;
542d6675 346 *resultP_1 = CGEN_PARSE_OPERAND_RESULT_ERROR;
232431a0 347 return _("illegal operand");
252b5132
RH
348 }
349
680d2857 350 expr_jmp_buf_p = 1;
542d6675 351 expression (&exp);
680d2857 352 expr_jmp_buf_p = 0;
0609eb57 353 errmsg = NULL;
252b5132 354
542d6675 355 *strP = input_line_pointer;
252b5132
RH
356 input_line_pointer = hold;
357
097f809a 358#ifdef TC_CGEN_PARSE_FIX_EXP
3d063691 359 opinfo_1 = TC_CGEN_PARSE_FIX_EXP (opinfo_1, & exp);
097f809a
NC
360#endif
361
252b5132
RH
362 /* FIXME: Need to check `want'. */
363
364 switch (exp.X_op)
365 {
542d6675 366 case O_illegal:
252b5132 367 errmsg = _("illegal operand");
542d6675 368 *resultP = CGEN_PARSE_OPERAND_RESULT_ERROR;
252b5132 369 break;
542d6675 370 case O_absent:
252b5132 371 errmsg = _("missing operand");
542d6675 372 *resultP = CGEN_PARSE_OPERAND_RESULT_ERROR;
252b5132 373 break;
542d6675 374 case O_constant:
90219bd0
AO
375 if (want == CGEN_PARSE_OPERAND_SYMBOLIC)
376 goto de_fault;
542d6675
KH
377 *valueP = exp.X_add_number;
378 *resultP = CGEN_PARSE_OPERAND_RESULT_NUMBER;
252b5132 379 break;
542d6675
KH
380 case O_register:
381 *valueP = exp.X_add_number;
382 *resultP = CGEN_PARSE_OPERAND_RESULT_REGISTER;
252b5132 383 break;
90219bd0 384 de_fault:
542d6675 385 default:
199fea98 386 queue_fixup (opindex, opinfo_1, &exp);
542d6675
KH
387 *valueP = 0;
388 *resultP = CGEN_PARSE_OPERAND_RESULT_QUEUED;
252b5132
RH
389 break;
390 }
391
392 return errmsg;
393}
394
395/* md_operand handler to catch unrecognized expressions and halt the
396 parsing process so the next entry can be tried.
397
398 ??? This could be done differently by adding code to `expression'. */
399
400void
401gas_cgen_md_operand (expressionP)
542d6675 402 expressionS *expressionP ATTRIBUTE_UNUSED;
252b5132 403{
680d2857
FCE
404 /* Don't longjmp if we're not called from within cgen_parse_operand(). */
405 if (expr_jmp_buf_p)
406 longjmp (expr_jmp_buf, 1);
252b5132
RH
407}
408
409/* Finish assembling instruction INSN.
410 BUF contains what we've built up so far.
411 LENGTH is the size of the insn in bits.
412 RELAX_P is non-zero if relaxable insns should be emitted as such.
413 Otherwise they're emitted in non-relaxable forms.
414 The "result" is stored in RESULT if non-NULL. */
415
416void
417gas_cgen_finish_insn (insn, buf, length, relax_p, result)
542d6675 418 const CGEN_INSN *insn;
252b5132
RH
419 CGEN_INSN_BYTES_PTR buf;
420 unsigned int length;
421 int relax_p;
542d6675 422 finished_insnS *result;
252b5132
RH
423{
424 int i;
425 int relax_operand;
542d6675 426 char *f;
252b5132
RH
427 unsigned int byte_len = length / 8;
428
429 /* ??? Target foo issues various warnings here, so one might want to provide
430 a hook here. However, our caller is defined in tc-foo.c so there
431 shouldn't be a need for a hook. */
432
433 /* Write out the instruction.
434 It is important to fetch enough space in one call to `frag_more'.
435 We use (f - frag_now->fr_literal) to compute where we are and we
436 don't want frag_now to change between calls.
437
438 Relaxable instructions: We need to ensure we allocate enough
439 space for the largest insn. */
440
b11dcf4e 441 if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED))
542d6675
KH
442 /* These currently shouldn't get here. */
443 abort ();
252b5132
RH
444
445 /* Is there a relaxable insn with the relaxable operand needing a fixup? */
446
447 relax_operand = -1;
448 if (relax_p && CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXABLE))
449 {
450 /* Scan the fixups for the operand affected by relaxing
451 (i.e. the branch address). */
452
542d6675 453 for (i = 0; i < num_fixups; ++i)
252b5132
RH
454 {
455 if (CGEN_OPERAND_ATTR_VALUE (cgen_operand_lookup_by_num (gas_cgen_cpu_desc, fixups[i].opindex),
456 CGEN_OPERAND_RELAX))
457 {
458 relax_operand = i;
459 break;
460 }
461 }
462 }
463
464 if (relax_operand != -1)
465 {
466 int max_len;
542d6675 467 fragS *old_frag;
2289f85d
AM
468 expressionS *exp;
469 symbolS *sym;
470 offsetT off;
252b5132
RH
471
472#ifdef TC_CGEN_MAX_RELAX
473 max_len = TC_CGEN_MAX_RELAX (insn, byte_len);
474#else
475 max_len = CGEN_MAX_INSN_SIZE;
476#endif
477 /* Ensure variable part and fixed part are in same fragment. */
478 /* FIXME: Having to do this seems like a hack. */
479 frag_grow (max_len);
480
481 /* Allocate space for the fixed part. */
482 f = frag_more (byte_len);
483
484 /* Create a relaxable fragment for this instruction. */
485 old_frag = frag_now;
486
2289f85d
AM
487 exp = &fixups[relax_operand].exp;
488 sym = exp->X_add_symbol;
489 off = exp->X_add_number;
490 if (exp->X_op != O_constant && exp->X_op != O_symbol)
491 {
492 /* Handle complex expressions. */
493 sym = make_expr_symbol (exp);
494 off = 0;
495 }
496
252b5132
RH
497 frag_var (rs_machine_dependent,
498 max_len - byte_len /* max chars */,
499 0 /* variable part already allocated */,
500 /* FIXME: When we machine generate the relax table,
501 machine generate a macro to compute subtype. */
502 1 /* subtype */,
2289f85d
AM
503 sym,
504 off,
252b5132
RH
505 f);
506
507 /* Record the operand number with the fragment so md_convert_frag
508 can use gas_cgen_md_record_fixup to record the appropriate reloc. */
509 old_frag->fr_cgen.insn = insn;
510 old_frag->fr_cgen.opindex = fixups[relax_operand].opindex;
511 old_frag->fr_cgen.opinfo = fixups[relax_operand].opinfo;
512 if (result)
513 result->frag = old_frag;
514 }
515 else
516 {
517 f = frag_more (byte_len);
518 if (result)
519 result->frag = frag_now;
520 }
521
522 /* If we're recording insns as numbers (rather than a string of bytes),
523 target byte order handling is deferred until now. */
524#if CGEN_INT_INSN_P
2132e3a3 525 cgen_put_insn_value (gas_cgen_cpu_desc, (unsigned char *) f, length, *buf);
252b5132
RH
526#else
527 memcpy (f, buf, byte_len);
528#endif
529
272d76e0
FCE
530 /* Emit DWARF2 debugging information. */
531 dwarf2_emit_insn (byte_len);
532
252b5132
RH
533 /* Create any fixups. */
534 for (i = 0; i < num_fixups; ++i)
535 {
536 fixS *fixP;
537 const CGEN_OPERAND *operand =
538 cgen_operand_lookup_by_num (gas_cgen_cpu_desc, fixups[i].opindex);
539
540 /* Don't create fixups for these. That's done during relaxation.
b11dcf4e 541 We don't need to test for CGEN_INSN_RELAXED as they can't get here
252b5132
RH
542 (see above). */
543 if (relax_p
544 && CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXABLE)
545 && CGEN_OPERAND_ATTR_VALUE (operand, CGEN_OPERAND_RELAX))
546 continue;
547
548#ifndef md_cgen_record_fixup_exp
549#define md_cgen_record_fixup_exp gas_cgen_record_fixup_exp
550#endif
551
542d6675
KH
552 fixP = md_cgen_record_fixup_exp (frag_now, f - frag_now->fr_literal,
553 insn, length, operand,
554 fixups[i].opinfo,
555 &fixups[i].exp);
556 if (result)
557 result->fixups[i] = fixP;
252b5132
RH
558 }
559
560 if (result)
561 {
562 result->num_fixups = num_fixups;
563 result->addr = f;
564 }
565}
566
567/* Apply a fixup to the object code. This is called for all the
568 fixups we generated by the call to fix_new_exp, above. In the call
569 above we used a reloc code which was the largest legal reloc code
570 plus the operand index. Here we undo that to recover the operand
571 index. At this point all symbol values should be fully resolved,
572 and we attempt to completely resolve the reloc. If we can not do
573 that, we determine the correct reloc code and put it back in the fixup. */
574
575/* FIXME: This function handles some of the fixups and bfd_install_relocation
576 handles the rest. bfd_install_relocation (or some other bfd function)
577 should handle them all. */
578
94f592af 579void
55cf6793 580gas_cgen_md_apply_fix (fixP, valP, seg)
252b5132 581 fixS * fixP;
94f592af 582 valueT * valP;
eabed1c0 583 segT seg ATTRIBUTE_UNUSED;
252b5132 584{
542d6675 585 char *where = fixP->fx_frag->fr_literal + fixP->fx_where;
94f592af 586 valueT value = * valP;
542d6675 587 /* Canonical name, since used a lot. */
252b5132 588 CGEN_CPU_DESC cd = gas_cgen_cpu_desc;
542d6675 589
252b5132 590 if (fixP->fx_addsy == (symbolS *) NULL)
94f592af
NC
591 fixP->fx_done = 1;
592
a161fe53
AM
593 /* We don't actually support subtracting a symbol. */
594 if (fixP->fx_subsy != (symbolS *) NULL)
595 as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
252b5132
RH
596
597 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
598 {
599 int opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
600 const CGEN_OPERAND *operand = cgen_operand_lookup_by_num (cd, opindex);
601 const char *errmsg;
602 bfd_reloc_code_real_type reloc_type;
603 CGEN_FIELDS *fields = alloca (CGEN_CPU_SIZEOF_FIELDS (cd));
604 const CGEN_INSN *insn = fixP->fx_cgen.insn;
605
606 /* If the reloc has been fully resolved finish the operand here. */
607 /* FIXME: This duplicates the capabilities of code in BFD. */
608 if (fixP->fx_done
609 /* FIXME: If partial_inplace isn't set bfd_install_relocation won't
610 finish the job. Testing for pcrel is a temporary hack. */
611 || fixP->fx_pcrel)
612 {
613 CGEN_CPU_SET_FIELDS_BITSIZE (cd) (fields, CGEN_INSN_BITSIZE (insn));
614 CGEN_CPU_SET_VMA_OPERAND (cd) (cd, opindex, fields, (bfd_vma) value);
615
616#if CGEN_INT_INSN_P
617 {
618 CGEN_INSN_INT insn_value =
2132e3a3
AM
619 cgen_get_insn_value (cd, (unsigned char *) where,
620 CGEN_INSN_BITSIZE (insn));
252b5132 621
542d6675 622 /* ??? 0 is passed for `pc'. */
252b5132
RH
623 errmsg = CGEN_CPU_INSERT_OPERAND (cd) (cd, opindex, fields,
624 &insn_value, (bfd_vma) 0);
2132e3a3
AM
625 cgen_put_insn_value (cd, (unsigned char *) where,
626 CGEN_INSN_BITSIZE (insn), insn_value);
252b5132
RH
627 }
628#else
542d6675 629 /* ??? 0 is passed for `pc'. */
2132e3a3
AM
630 errmsg = CGEN_CPU_INSERT_OPERAND (cd) (cd, opindex, fields,
631 (unsigned char *) where,
542d6675 632 (bfd_vma) 0);
252b5132
RH
633#endif
634 if (errmsg)
635 as_bad_where (fixP->fx_file, fixP->fx_line, "%s", errmsg);
636 }
637
638 if (fixP->fx_done)
94f592af 639 return;
252b5132
RH
640
641 /* The operand isn't fully resolved. Determine a BFD reloc value
642 based on the operand information and leave it to
643 bfd_install_relocation. Note that this doesn't work when
644 partial_inplace == false. */
645
646 reloc_type = md_cgen_lookup_reloc (insn, operand, fixP);
94f592af 647
252b5132 648 if (reloc_type != BFD_RELOC_NONE)
94f592af 649 fixP->fx_r_type = reloc_type;
252b5132
RH
650 else
651 {
652 as_bad_where (fixP->fx_file, fixP->fx_line,
653 _("unresolved expression that must be resolved"));
654 fixP->fx_done = 1;
94f592af 655 return;
252b5132
RH
656 }
657 }
658 else if (fixP->fx_done)
659 {
660 /* We're finished with this fixup. Install it because
661 bfd_install_relocation won't be called to do it. */
662 switch (fixP->fx_r_type)
663 {
664 case BFD_RELOC_8:
665 md_number_to_chars (where, value, 1);
666 break;
667 case BFD_RELOC_16:
668 md_number_to_chars (where, value, 2);
669 break;
670 case BFD_RELOC_32:
671 md_number_to_chars (where, value, 4);
672 break;
363c574f
MG
673 case BFD_RELOC_64:
674 md_number_to_chars (where, value, 8);
675 break;
252b5132
RH
676 default:
677 as_bad_where (fixP->fx_file, fixP->fx_line,
678 _("internal error: can't install fix for reloc type %d (`%s')"),
679 fixP->fx_r_type, bfd_get_reloc_code_name (fixP->fx_r_type));
680 break;
681 }
682 }
232431a0
NC
683 /* else
684 bfd_install_relocation will be called to finish things up. */
252b5132
RH
685
686 /* Tuck `value' away for use by tc_gen_reloc.
687 See the comment describing fx_addnumber in write.h.
688 This field is misnamed (or misused :-). */
689 fixP->fx_addnumber = value;
252b5132
RH
690}
691
692/* Translate internal representation of relocation info to BFD target format.
693
694 FIXME: To what extent can we get all relevant targets to use this? */
695
696arelent *
697gas_cgen_tc_gen_reloc (section, fixP)
eabed1c0 698 asection * section ATTRIBUTE_UNUSED;
252b5132
RH
699 fixS * fixP;
700{
542d6675 701 arelent *reloc;
252b5132
RH
702
703 reloc = (arelent *) xmalloc (sizeof (arelent));
704
705 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
706 if (reloc->howto == (reloc_howto_type *) NULL)
707 {
708 as_bad_where (fixP->fx_file, fixP->fx_line,
aaa4f6d9 709 _("relocation is not supported"));
252b5132
RH
710 return NULL;
711 }
712
713 assert (!fixP->fx_pcrel == !reloc->howto->pc_relative);
714
080e41e6
ILT
715 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
716 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
252b5132 717
542d6675
KH
718 /* Use fx_offset for these cases. */
719 if (fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY
252b5132 720 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT)
542d6675 721 reloc->addend = fixP->fx_offset;
252b5132 722 else
542d6675 723 reloc->addend = fixP->fx_addnumber;
252b5132
RH
724
725 reloc->address = fixP->fx_frag->fr_address + fixP->fx_where;
726 return reloc;
727}
9cc92a36
NC
728
729/* Perform any cgen specific initialisation.
730 Called after gas_cgen_cpu_desc has been created. */
731
732void
733gas_cgen_begin ()
734{
735 if (flag_signed_overflow_ok)
736 cgen_set_signed_overflow_ok (gas_cgen_cpu_desc);
737 else
738 cgen_clear_signed_overflow_ok (gas_cgen_cpu_desc);
739}
This page took 0.33258 seconds and 4 git commands to generate.