Commit | Line | Data |
---|---|---|
93fbbb04 | 1 | /* tc-xstormy16.c -- Assembler for the Sanyo XSTORMY16. |
b90efa5b | 2 | Copyright (C) 2000-2015 Free Software Foundation, Inc. |
93fbbb04 GK |
3 | |
4 | This file is part of GAS, the GNU Assembler. | |
5 | ||
6 | GAS is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 8 | the Free Software Foundation; either version 3, or (at your option) |
93fbbb04 GK |
9 | any later version. |
10 | ||
11 | GAS is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GAS; see the file COPYING. If not, write to | |
4b4da160 NC |
18 | the Free Software Foundation, 51 Franklin Street - Fifth Floor, |
19 | Boston, MA 02110-1301, USA. */ | |
93fbbb04 | 20 | |
93fbbb04 | 21 | #include "as.h" |
5d6255fe | 22 | #include "subsegs.h" |
93fbbb04 GK |
23 | #include "symcat.h" |
24 | #include "opcodes/xstormy16-desc.h" | |
25 | #include "opcodes/xstormy16-opc.h" | |
26 | #include "cgen.h" | |
27 | ||
28 | /* Structure to hold all of the different components describing | |
29 | an individual instruction. */ | |
30 | typedef struct | |
31 | { | |
32 | const CGEN_INSN * insn; | |
33 | const CGEN_INSN * orig_insn; | |
34 | CGEN_FIELDS fields; | |
35 | #if CGEN_INT_INSN_P | |
36 | CGEN_INSN_INT buffer [1]; | |
37 | #define INSN_VALUE(buf) (*(buf)) | |
38 | #else | |
39 | unsigned char buffer [CGEN_MAX_INSN_SIZE]; | |
40 | #define INSN_VALUE(buf) (buf) | |
41 | #endif | |
42 | char * addr; | |
43 | fragS * frag; | |
44 | int num_fixups; | |
45 | fixS * fixups [GAS_CGEN_MAX_FIXUPS]; | |
46 | int indices [MAX_OPERAND_INSTANCES]; | |
47 | } | |
48 | xstormy16_insn; | |
49 | ||
50 | const char comment_chars[] = ";"; | |
51 | const char line_comment_chars[] = "#"; | |
52 | const char line_separator_chars[] = "|"; | |
53 | const char EXP_CHARS[] = "eE"; | |
54 | const char FLT_CHARS[] = "dD"; | |
55 | ||
56 | #define O_fptr_symbol (O_max + 1) | |
57 | \f | |
58 | #define XSTORMY16_SHORTOPTS "" | |
59 | const char * md_shortopts = XSTORMY16_SHORTOPTS; | |
60 | ||
61 | struct option md_longopts[] = | |
62 | { | |
63 | {NULL, no_argument, NULL, 0} | |
64 | }; | |
65 | size_t md_longopts_size = sizeof (md_longopts); | |
66 | ||
67 | int | |
ea1562b3 NC |
68 | md_parse_option (int c ATTRIBUTE_UNUSED, |
69 | char * arg ATTRIBUTE_UNUSED) | |
93fbbb04 GK |
70 | { |
71 | return 0; | |
72 | } | |
73 | ||
74 | void | |
ea1562b3 | 75 | md_show_usage (FILE * stream) |
93fbbb04 GK |
76 | { |
77 | fprintf (stream, _(" XSTORMY16 specific command line options:\n")); | |
5d6255fe | 78 | } |
93fbbb04 GK |
79 | |
80 | /* The target specific pseudo-ops which we support. */ | |
81 | const pseudo_typeS md_pseudo_table[] = | |
82 | { | |
83 | { "word", cons, 4 }, | |
84 | { NULL, NULL, 0 } | |
85 | }; | |
86 | ||
87 | \f | |
88 | void | |
ea1562b3 | 89 | md_begin (void) |
93fbbb04 GK |
90 | { |
91 | /* Initialize the `cgen' interface. */ | |
5d6255fe | 92 | |
93fbbb04 GK |
93 | /* Set the machine number and endian. */ |
94 | gas_cgen_cpu_desc = xstormy16_cgen_cpu_open (CGEN_CPU_OPEN_MACHS, 0, | |
95 | CGEN_CPU_OPEN_ENDIAN, | |
96 | CGEN_ENDIAN_LITTLE, | |
97 | CGEN_CPU_OPEN_END); | |
98 | xstormy16_cgen_init_asm (gas_cgen_cpu_desc); | |
99 | ||
100 | /* This is a callback from cgen to gas to parse operands. */ | |
101 | cgen_set_parse_operand_fn (gas_cgen_cpu_desc, gas_cgen_parse_operand); | |
102 | } | |
103 | ||
e66c629e NC |
104 | static bfd_boolean skipping_fptr = FALSE; |
105 | ||
93fbbb04 | 106 | void |
ea1562b3 | 107 | md_assemble (char * str) |
93fbbb04 GK |
108 | { |
109 | xstormy16_insn insn; | |
110 | char * errmsg; | |
111 | ||
e66c629e NC |
112 | /* Make sure that if we had an erroneous input line which triggered |
113 | the skipping_fptr boolean that it does not affect following lines. */ | |
114 | skipping_fptr = FALSE; | |
115 | ||
93fbbb04 GK |
116 | /* Initialize GAS's cgen interface for a new instruction. */ |
117 | gas_cgen_init_parse (); | |
118 | ||
119 | insn.insn = xstormy16_cgen_assemble_insn | |
120 | (gas_cgen_cpu_desc, str, & insn.fields, insn.buffer, & errmsg); | |
5d6255fe | 121 | |
93fbbb04 GK |
122 | if (!insn.insn) |
123 | { | |
20203fb9 | 124 | as_bad ("%s", errmsg); |
93fbbb04 GK |
125 | return; |
126 | } | |
127 | ||
128 | /* Doesn't really matter what we pass for RELAX_P here. */ | |
129 | gas_cgen_finish_insn (insn.insn, insn.buffer, | |
130 | CGEN_FIELDS_BITSIZE (& insn.fields), 0, NULL); | |
131 | } | |
132 | ||
5d6255fe | 133 | void |
ea1562b3 | 134 | md_operand (expressionS * e) |
93fbbb04 GK |
135 | { |
136 | if (*input_line_pointer != '@') | |
137 | return; | |
138 | ||
f53e95c7 | 139 | if (strncmp (input_line_pointer + 1, "fptr", 4) == 0) |
93fbbb04 GK |
140 | { |
141 | input_line_pointer += 5; | |
142 | SKIP_WHITESPACE (); | |
143 | if (*input_line_pointer != '(') | |
144 | { | |
20203fb9 | 145 | as_bad (_("Expected '('")); |
93fbbb04 GK |
146 | goto err; |
147 | } | |
148 | input_line_pointer++; | |
149 | ||
150 | expression (e); | |
151 | ||
152 | if (*input_line_pointer != ')') | |
153 | { | |
20203fb9 | 154 | as_bad (_("Missing ')'")); |
93fbbb04 GK |
155 | goto err; |
156 | } | |
157 | input_line_pointer++; | |
e66c629e | 158 | SKIP_WHITESPACE (); |
93fbbb04 GK |
159 | |
160 | if (e->X_op != O_symbol) | |
20203fb9 | 161 | as_bad (_("Not a symbolic expression")); |
e66c629e NC |
162 | else if (* input_line_pointer == '-') |
163 | /* We are computing the difference of two function pointers | |
164 | like this: | |
165 | ||
166 | .hword @fptr (foo) - @fptr (bar) | |
167 | ||
168 | In this situation we do not want to generate O_fptr_symbol | |
169 | operands because the result is an absolute value, not a | |
170 | function pointer. | |
171 | ||
172 | We need to make the check here, rather than when the fixup | |
173 | is generated as the function names (foo & bar in the above | |
174 | example) might be local symbols and we want the expression | |
175 | to be evaluated now. This kind of thing can happen when | |
176 | gcc is generating computed gotos. */ | |
177 | skipping_fptr = TRUE; | |
178 | else if (skipping_fptr) | |
179 | skipping_fptr = FALSE; | |
93fbbb04 GK |
180 | else |
181 | e->X_op = O_fptr_symbol; | |
182 | } | |
183 | ||
184 | return; | |
185 | err: | |
186 | ignore_rest_of_line (); | |
187 | } | |
188 | ||
189 | /* Called while parsing data to create a fixup. | |
190 | Create BFD_RELOC_XSTORMY16_FPTR16 relocations. */ | |
191 | ||
192 | void | |
ea1562b3 NC |
193 | xstormy16_cons_fix_new (fragS *f, |
194 | int where, | |
195 | int nbytes, | |
62ebcb5c AM |
196 | expressionS *exp, |
197 | bfd_reloc_code_real_type code) | |
93fbbb04 | 198 | { |
93fbbb04 GK |
199 | if (exp->X_op == O_fptr_symbol) |
200 | { | |
87e62348 | 201 | switch (nbytes) |
93fbbb04 | 202 | { |
87e62348 NC |
203 | case 4: |
204 | /* This can happen when gcc is generating debug output. | |
205 | For example it can create a stab with the address of | |
206 | a function: | |
207 | ||
208 | .stabs "foo:F(0,21)",36,0,0,@fptr(foo) | |
209 | ||
210 | Since this does not involve switching code pages, we | |
211 | just allow the reloc to be generated without any | |
212 | @fptr behaviour. */ | |
213 | exp->X_op = O_symbol; | |
214 | code = BFD_RELOC_32; | |
215 | break; | |
ea1562b3 | 216 | |
87e62348 NC |
217 | case 2: |
218 | exp->X_op = O_symbol; | |
219 | code = BFD_RELOC_XSTORMY16_FPTR16; | |
220 | break; | |
ea1562b3 | 221 | |
87e62348 | 222 | default: |
20203fb9 | 223 | as_bad (_("unsupported fptr fixup size %d"), nbytes); |
93fbbb04 GK |
224 | return; |
225 | } | |
93fbbb04 GK |
226 | } |
227 | else if (nbytes == 1) | |
228 | code = BFD_RELOC_8; | |
229 | else if (nbytes == 2) | |
230 | code = BFD_RELOC_16; | |
231 | else if (nbytes == 4) | |
232 | code = BFD_RELOC_32; | |
233 | else | |
234 | { | |
20203fb9 | 235 | as_bad (_("unsupported fixup size %d"), nbytes); |
93fbbb04 GK |
236 | return; |
237 | } | |
238 | ||
87975d2a | 239 | fix_new_exp (f, where, nbytes, exp, 0, code); |
93fbbb04 GK |
240 | } |
241 | ||
5d6255fe | 242 | /* Called while parsing an instruction to create a fixup. |
93fbbb04 GK |
243 | Create BFD_RELOC_XSTORMY16_FPTR16 relocations. */ |
244 | ||
245 | fixS * | |
ea1562b3 NC |
246 | xstormy16_cgen_record_fixup_exp (fragS * frag, |
247 | int where, | |
248 | const CGEN_INSN * insn, | |
249 | int length, | |
250 | const CGEN_OPERAND * operand, | |
251 | int opinfo, | |
252 | expressionS * exp) | |
93fbbb04 GK |
253 | { |
254 | fixS *fixP; | |
255 | operatorT op = exp->X_op; | |
5d6255fe | 256 | |
93fbbb04 GK |
257 | if (op == O_fptr_symbol) |
258 | exp->X_op = O_symbol; | |
259 | ||
260 | fixP = gas_cgen_record_fixup_exp (frag, where, insn, length, | |
261 | operand, opinfo, exp); | |
262 | ||
263 | if (op == O_fptr_symbol) | |
264 | { | |
265 | if (operand->type != XSTORMY16_OPERAND_IMM16) | |
20203fb9 | 266 | as_bad (_("unsupported fptr fixup")); |
93fbbb04 GK |
267 | else |
268 | { | |
269 | fixP->fx_r_type = BFD_RELOC_XSTORMY16_FPTR16; | |
270 | fixP->fx_where += 2; | |
271 | } | |
272 | } | |
273 | ||
274 | return fixP; | |
275 | } | |
276 | ||
277 | valueT | |
ea1562b3 | 278 | md_section_align (segT segment, valueT size) |
93fbbb04 GK |
279 | { |
280 | int align = bfd_get_section_alignment (stdoutput, segment); | |
ea1562b3 | 281 | |
93fbbb04 GK |
282 | return ((size + (1 << align) - 1) & (-1 << align)); |
283 | } | |
284 | ||
285 | symbolS * | |
ea1562b3 | 286 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) |
93fbbb04 GK |
287 | { |
288 | return 0; | |
289 | } | |
290 | \f | |
291 | /* Return an initial guess of the length by which a fragment must grow to | |
292 | hold a branch to reach its destination. | |
293 | Also updates fr_type/fr_subtype as necessary. | |
294 | ||
295 | Called just before doing relaxation. | |
296 | Any symbol that is now undefined will not become defined. | |
297 | The guess for fr_var is ACTUALLY the growth beyond fr_fix. | |
298 | Whatever we do to grow fr_fix or fr_var contributes to our returned value. | |
299 | Although it may not be explicit in the frag, pretend fr_var starts with a | |
300 | 0 value. */ | |
301 | ||
302 | int | |
ea1562b3 NC |
303 | md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED, |
304 | segT segment ATTRIBUTE_UNUSED) | |
93fbbb04 GK |
305 | { |
306 | /* No assembler relaxation is defined (or necessary) for this port. */ | |
307 | abort (); | |
5d6255fe | 308 | } |
93fbbb04 GK |
309 | |
310 | /* *fragP has been relaxed to its final size, and now needs to have | |
311 | the bytes inside it modified to conform to the new size. | |
312 | ||
313 | Called after relaxation is finished. | |
314 | fragP->fr_type == rs_machine_dependent. | |
315 | fragP->fr_subtype is the subtype of what the address relaxed to. */ | |
316 | ||
317 | void | |
ea1562b3 NC |
318 | md_convert_frag (bfd * abfd ATTRIBUTE_UNUSED, |
319 | segT sec ATTRIBUTE_UNUSED, | |
320 | fragS * fragP ATTRIBUTE_UNUSED) | |
93fbbb04 GK |
321 | { |
322 | /* No assembler relaxation is defined (or necessary) for this port. */ | |
323 | abort (); | |
324 | } | |
325 | \f | |
326 | /* Functions concerning relocs. */ | |
327 | ||
328 | /* The location from which a PC relative jump should be calculated, | |
329 | given a PC relative reloc. */ | |
330 | ||
331 | long | |
ea1562b3 | 332 | md_pcrel_from_section (fixS * fixP, segT sec) |
93fbbb04 | 333 | { |
f17c130b AM |
334 | if ((fixP->fx_addsy != (symbolS *) NULL |
335 | && (! S_IS_DEFINED (fixP->fx_addsy) | |
336 | || S_GET_SEGMENT (fixP->fx_addsy) != sec)) | |
337 | || xstormy16_force_relocation (fixP)) | |
ceb41009 NC |
338 | /* The symbol is undefined, |
339 | or it is defined but not in this section, | |
340 | or the relocation will be relative to this symbol not the section symbol. | |
341 | Let the linker figure it out. */ | |
342 | return 0; | |
93fbbb04 GK |
343 | |
344 | return fixP->fx_frag->fr_address + fixP->fx_where; | |
345 | } | |
346 | ||
347 | /* Return the bfd reloc type for OPERAND of INSN at fixup FIXP. | |
348 | Returns BFD_RELOC_NONE if no reloc type can be found. | |
349 | *FIXP may be modified if desired. */ | |
350 | ||
351 | bfd_reloc_code_real_type | |
ea1562b3 NC |
352 | md_cgen_lookup_reloc (const CGEN_INSN * insn ATTRIBUTE_UNUSED, |
353 | const CGEN_OPERAND * operand, | |
354 | fixS * fixP) | |
93fbbb04 GK |
355 | { |
356 | switch (operand->type) | |
357 | { | |
358 | case XSTORMY16_OPERAND_IMM2: | |
359 | case XSTORMY16_OPERAND_IMM3: | |
360 | case XSTORMY16_OPERAND_IMM3B: | |
361 | case XSTORMY16_OPERAND_IMM4: | |
93fbbb04 GK |
362 | case XSTORMY16_OPERAND_HMEM8: |
363 | return BFD_RELOC_NONE; | |
5d6255fe | 364 | |
8f46beda DD |
365 | case XSTORMY16_OPERAND_IMM12: |
366 | fixP->fx_where += 2; | |
367 | return BFD_RELOC_XSTORMY16_12; | |
368 | ||
93fbbb04 GK |
369 | case XSTORMY16_OPERAND_IMM8: |
370 | case XSTORMY16_OPERAND_LMEM8: | |
371 | return fixP->fx_pcrel ? BFD_RELOC_8_PCREL : BFD_RELOC_8; | |
5d6255fe | 372 | |
93fbbb04 | 373 | case XSTORMY16_OPERAND_IMM16: |
9bb76eb8 | 374 | /* This might have been processed at parse time. */ |
93fbbb04 | 375 | fixP->fx_where += 2; |
9bb76eb8 DD |
376 | if (fixP->fx_cgen.opinfo && fixP->fx_cgen.opinfo != BFD_RELOC_NONE) |
377 | return fixP->fx_cgen.opinfo; | |
93fbbb04 GK |
378 | return fixP->fx_pcrel ? BFD_RELOC_16_PCREL : BFD_RELOC_16; |
379 | ||
380 | case XSTORMY16_OPERAND_ABS24: | |
381 | return BFD_RELOC_XSTORMY16_24; | |
382 | ||
93fbbb04 | 383 | case XSTORMY16_OPERAND_REL8_4: |
2d10acd2 DD |
384 | fixP->fx_addnumber -= 2; |
385 | case XSTORMY16_OPERAND_REL8_2: | |
386 | fixP->fx_addnumber -= 2; | |
93fbbb04 GK |
387 | fixP->fx_pcrel = 1; |
388 | return BFD_RELOC_8_PCREL; | |
389 | ||
390 | case XSTORMY16_OPERAND_REL12: | |
391 | fixP->fx_where += 2; | |
5d6255fe | 392 | /* Fall through... */ |
93fbbb04 | 393 | case XSTORMY16_OPERAND_REL12A: |
2d10acd2 | 394 | fixP->fx_addnumber -= 2; |
93fbbb04 GK |
395 | fixP->fx_pcrel = 1; |
396 | return BFD_RELOC_XSTORMY16_REL_12; | |
397 | ||
398 | default : /* avoid -Wall warning */ | |
399 | abort (); | |
400 | } | |
401 | } | |
402 | ||
403 | /* See whether we need to force a relocation into the output file. | |
404 | This is used to force out switch and PC relative relocations when | |
405 | relaxing. */ | |
406 | ||
407 | int | |
ea1562b3 | 408 | xstormy16_force_relocation (fixS * fix) |
93fbbb04 | 409 | { |
ae6063d4 AM |
410 | if (fix->fx_r_type == BFD_RELOC_XSTORMY16_FPTR16) |
411 | return 1; | |
a161fe53 | 412 | |
ae6063d4 | 413 | return generic_force_reloc (fix); |
93fbbb04 GK |
414 | } |
415 | ||
416 | /* Return true if a relocation against a symbol may be replaced with | |
417 | a relocation against section+offset. */ | |
418 | ||
b34976b6 | 419 | bfd_boolean |
ea1562b3 | 420 | xstormy16_fix_adjustable (fixS * fixP) |
93fbbb04 | 421 | { |
1f7fd478 | 422 | /* We need the symbol name for the VTABLE entries. */ |
a161fe53 | 423 | if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
1f7fd478 | 424 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) |
ea1562b3 | 425 | return FALSE; |
1f7fd478 | 426 | |
a161fe53 | 427 | if (fixP->fx_r_type == BFD_RELOC_XSTORMY16_FPTR16) |
ea1562b3 | 428 | return FALSE; |
a161fe53 | 429 | |
ea1562b3 | 430 | return TRUE; |
93fbbb04 GK |
431 | } |
432 | ||
55cf6793 | 433 | /* This is a copy of gas_cgen_md_apply_fix, with some enhancements to |
93fbbb04 GK |
434 | do various things that would not be valid for all ports. */ |
435 | ||
436 | void | |
55cf6793 | 437 | xstormy16_md_apply_fix (fixS * fixP, |
ea1562b3 NC |
438 | valueT * valueP, |
439 | segT seg ATTRIBUTE_UNUSED) | |
93fbbb04 GK |
440 | { |
441 | char *where = fixP->fx_frag->fr_literal + fixP->fx_where; | |
a161fe53 | 442 | valueT value = *valueP; |
93fbbb04 GK |
443 | /* Canonical name, since used a lot. */ |
444 | CGEN_CPU_DESC cd = gas_cgen_cpu_desc; | |
445 | ||
2d10acd2 DD |
446 | /* md_cgen_lookup_reloc() will adjust this to compensate for where |
447 | in the opcode the relocation happens, for pcrel relocations. We | |
448 | have no other way of keeping track of what this offset needs to | |
449 | be. */ | |
450 | fixP->fx_addnumber = 0; | |
451 | ||
93fbbb04 GK |
452 | /* This port has pc-relative relocs and DIFF_EXPR_OK defined, so |
453 | it must deal with turning a BFD_RELOC_{8,16,32,64} into a | |
454 | BFD_RELOC_*_PCREL for the case of | |
455 | ||
ea1562b3 | 456 | .word something-. */ |
93fbbb04 GK |
457 | if (fixP->fx_pcrel) |
458 | switch (fixP->fx_r_type) | |
459 | { | |
460 | case BFD_RELOC_8: | |
461 | fixP->fx_r_type = BFD_RELOC_8_PCREL; | |
462 | break; | |
463 | case BFD_RELOC_16: | |
464 | fixP->fx_r_type = BFD_RELOC_16_PCREL; | |
465 | break; | |
466 | case BFD_RELOC_32: | |
467 | fixP->fx_r_type = BFD_RELOC_32_PCREL; | |
468 | break; | |
469 | case BFD_RELOC_64: | |
470 | fixP->fx_r_type = BFD_RELOC_64_PCREL; | |
471 | break; | |
472 | default: | |
473 | break; | |
474 | } | |
5d6255fe | 475 | |
93fbbb04 | 476 | if (fixP->fx_addsy == (symbolS *) NULL) |
a161fe53 AM |
477 | fixP->fx_done = 1; |
478 | ||
479 | /* We don't actually support subtracting a symbol. */ | |
480 | if (fixP->fx_subsy != (symbolS *) NULL) | |
481 | as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex")); | |
93fbbb04 GK |
482 | |
483 | if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED) | |
484 | { | |
485 | int opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED; | |
486 | const CGEN_OPERAND *operand = cgen_operand_lookup_by_num (cd, opindex); | |
487 | const char *errmsg; | |
488 | bfd_reloc_code_real_type reloc_type; | |
489 | CGEN_FIELDS *fields = alloca (CGEN_CPU_SIZEOF_FIELDS (cd)); | |
490 | const CGEN_INSN *insn = fixP->fx_cgen.insn; | |
491 | ||
492 | /* If the reloc has been fully resolved finish the operand here. */ | |
493 | /* FIXME: This duplicates the capabilities of code in BFD. */ | |
494 | if (fixP->fx_done) | |
495 | { | |
496 | CGEN_CPU_SET_FIELDS_BITSIZE (cd) (fields, CGEN_INSN_BITSIZE (insn)); | |
497 | CGEN_CPU_SET_VMA_OPERAND (cd) (cd, opindex, fields, (bfd_vma) value); | |
498 | ||
499 | #if CGEN_INT_INSN_P | |
500 | { | |
501 | CGEN_INSN_INT insn_value = | |
2132e3a3 AM |
502 | cgen_get_insn_value (cd, (unsigned char *) where, |
503 | CGEN_INSN_BITSIZE (insn)); | |
93fbbb04 GK |
504 | |
505 | /* ??? 0 is passed for `pc'. */ | |
506 | errmsg = CGEN_CPU_INSERT_OPERAND (cd) (cd, opindex, fields, | |
507 | &insn_value, (bfd_vma) 0); | |
2132e3a3 AM |
508 | cgen_put_insn_value (cd, (unsigned char *) where, |
509 | CGEN_INSN_BITSIZE (insn), insn_value); | |
93fbbb04 GK |
510 | } |
511 | #else | |
512 | /* ??? 0 is passed for `pc'. */ | |
2132e3a3 AM |
513 | errmsg = CGEN_CPU_INSERT_OPERAND (cd) (cd, opindex, fields, |
514 | (unsigned char *) where, | |
93fbbb04 GK |
515 | (bfd_vma) 0); |
516 | #endif | |
517 | if (errmsg) | |
518 | as_bad_where (fixP->fx_file, fixP->fx_line, "%s", errmsg); | |
519 | } | |
520 | ||
521 | if (fixP->fx_done) | |
1f7fd478 | 522 | return; |
93fbbb04 GK |
523 | |
524 | /* The operand isn't fully resolved. Determine a BFD reloc value | |
525 | based on the operand information and leave it to | |
526 | bfd_install_relocation. Note that this doesn't work when | |
b34976b6 | 527 | !partial_inplace. */ |
93fbbb04 GK |
528 | |
529 | reloc_type = md_cgen_lookup_reloc (insn, operand, fixP); | |
530 | if (reloc_type != BFD_RELOC_NONE) | |
ea1562b3 | 531 | fixP->fx_r_type = reloc_type; |
93fbbb04 GK |
532 | else |
533 | { | |
534 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
535 | _("unresolved expression that must be resolved")); | |
536 | fixP->fx_done = 1; | |
1f7fd478 | 537 | return; |
93fbbb04 GK |
538 | } |
539 | } | |
540 | else if (fixP->fx_done) | |
541 | { | |
542 | /* We're finished with this fixup. Install it because | |
543 | bfd_install_relocation won't be called to do it. */ | |
544 | switch (fixP->fx_r_type) | |
545 | { | |
546 | case BFD_RELOC_8: | |
547 | md_number_to_chars (where, value, 1); | |
548 | break; | |
549 | case BFD_RELOC_16: | |
550 | md_number_to_chars (where, value, 2); | |
551 | break; | |
552 | case BFD_RELOC_32: | |
553 | md_number_to_chars (where, value, 4); | |
554 | break; | |
555 | case BFD_RELOC_64: | |
556 | md_number_to_chars (where, value, 8); | |
557 | break; | |
558 | default: | |
559 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
560 | _("internal error: can't install fix for reloc type %d (`%s')"), | |
561 | fixP->fx_r_type, bfd_get_reloc_code_name (fixP->fx_r_type)); | |
562 | break; | |
563 | } | |
564 | } | |
565 | else | |
566 | { | |
567 | /* bfd_install_relocation will be called to finish things up. */ | |
568 | } | |
569 | ||
570 | /* This is a RELA port. Thus, it does not need to store a | |
571 | value if it is going to make a reloc. What's more, when | |
572 | assembling a line like | |
5d6255fe | 573 | |
93fbbb04 | 574 | .byte global-0x7f00 |
5d6255fe | 575 | |
93fbbb04 GK |
576 | we'll get a spurious error message if we try to stuff 0x7f00 into |
577 | the byte. */ | |
578 | if (! fixP->fx_done) | |
579 | *valueP = 0; | |
580 | ||
581 | /* Tuck `value' away for use by tc_gen_reloc. | |
582 | See the comment describing fx_addnumber in write.h. | |
ceb41009 NC |
583 | This field is misnamed (or misused :-). */ |
584 | fixP->fx_addnumber += value; | |
93fbbb04 GK |
585 | } |
586 | ||
587 | \f | |
588 | /* Write a value out to the object file, using the appropriate endianness. */ | |
589 | ||
590 | void | |
ea1562b3 | 591 | md_number_to_chars (char * buf, valueT val, int n) |
93fbbb04 GK |
592 | { |
593 | number_to_chars_littleendian (buf, val, n); | |
594 | } | |
595 | ||
93fbbb04 | 596 | char * |
ea1562b3 | 597 | md_atof (int type, char * litP, int * sizeP) |
93fbbb04 | 598 | { |
499ac353 | 599 | return ieee_md_atof (type, litP, sizeP, FALSE); |
93fbbb04 | 600 | } |