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