| 1 | /* tc-xstormy16.c -- Assembler for the Sanyo XSTORMY16. |
| 2 | Copyright (C) 2000, 2001, 2002 Free Software Foundation. |
| 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" |
| 23 | #include "subsegs.h" |
| 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")); |
| 81 | } |
| 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. */ |
| 95 | |
| 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 | |
| 107 | void |
| 108 | md_assemble (str) |
| 109 | char * str; |
| 110 | { |
| 111 | xstormy16_insn insn; |
| 112 | char * errmsg; |
| 113 | |
| 114 | /* Initialize GAS's cgen interface for a new instruction. */ |
| 115 | gas_cgen_init_parse (); |
| 116 | |
| 117 | insn.insn = xstormy16_cgen_assemble_insn |
| 118 | (gas_cgen_cpu_desc, str, & insn.fields, insn.buffer, & errmsg); |
| 119 | |
| 120 | if (!insn.insn) |
| 121 | { |
| 122 | as_bad (errmsg); |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | /* Doesn't really matter what we pass for RELAX_P here. */ |
| 127 | gas_cgen_finish_insn (insn.insn, insn.buffer, |
| 128 | CGEN_FIELDS_BITSIZE (& insn.fields), 0, NULL); |
| 129 | } |
| 130 | |
| 131 | void |
| 132 | md_operand (e) |
| 133 | expressionS * e; |
| 134 | { |
| 135 | if (*input_line_pointer != '@') |
| 136 | return; |
| 137 | |
| 138 | if (strncmp (input_line_pointer+1, "fptr", 4) == 0) |
| 139 | { |
| 140 | input_line_pointer += 5; |
| 141 | SKIP_WHITESPACE (); |
| 142 | if (*input_line_pointer != '(') |
| 143 | { |
| 144 | as_bad ("Expected '('"); |
| 145 | goto err; |
| 146 | } |
| 147 | input_line_pointer++; |
| 148 | |
| 149 | expression (e); |
| 150 | |
| 151 | if (*input_line_pointer != ')') |
| 152 | { |
| 153 | as_bad ("Missing ')'"); |
| 154 | goto err; |
| 155 | } |
| 156 | input_line_pointer++; |
| 157 | |
| 158 | if (e->X_op != O_symbol) |
| 159 | as_bad ("Not a symbolic expression"); |
| 160 | else |
| 161 | e->X_op = O_fptr_symbol; |
| 162 | } |
| 163 | |
| 164 | return; |
| 165 | err: |
| 166 | ignore_rest_of_line (); |
| 167 | } |
| 168 | |
| 169 | /* Called while parsing data to create a fixup. |
| 170 | Create BFD_RELOC_XSTORMY16_FPTR16 relocations. */ |
| 171 | |
| 172 | void |
| 173 | xstormy16_cons_fix_new (f, where, nbytes, exp) |
| 174 | fragS *f; |
| 175 | int where; |
| 176 | int nbytes; |
| 177 | expressionS *exp; |
| 178 | { |
| 179 | bfd_reloc_code_real_type code; |
| 180 | fixS *fix; |
| 181 | |
| 182 | if (exp->X_op == O_fptr_symbol) |
| 183 | { |
| 184 | if (nbytes != 2) |
| 185 | { |
| 186 | as_bad ("unsupported fptr fixup size %d", nbytes); |
| 187 | return; |
| 188 | } |
| 189 | exp->X_op = O_symbol; |
| 190 | code = BFD_RELOC_XSTORMY16_FPTR16; |
| 191 | } |
| 192 | else if (nbytes == 1) |
| 193 | code = BFD_RELOC_8; |
| 194 | else if (nbytes == 2) |
| 195 | code = BFD_RELOC_16; |
| 196 | else if (nbytes == 4) |
| 197 | code = BFD_RELOC_32; |
| 198 | else |
| 199 | { |
| 200 | as_bad ("unsupported fixup size %d", nbytes); |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | fix = fix_new_exp (f, where, nbytes, exp, 0, code); |
| 205 | } |
| 206 | |
| 207 | /* Called while parsing an instruction to create a fixup. |
| 208 | Create BFD_RELOC_XSTORMY16_FPTR16 relocations. */ |
| 209 | |
| 210 | fixS * |
| 211 | xstormy16_cgen_record_fixup_exp (frag, where, insn, length, operand, opinfo, exp) |
| 212 | fragS * frag; |
| 213 | int where; |
| 214 | const CGEN_INSN * insn; |
| 215 | int length; |
| 216 | const CGEN_OPERAND * operand; |
| 217 | int opinfo; |
| 218 | expressionS * exp; |
| 219 | { |
| 220 | fixS *fixP; |
| 221 | operatorT op = exp->X_op; |
| 222 | |
| 223 | if (op == O_fptr_symbol) |
| 224 | exp->X_op = O_symbol; |
| 225 | |
| 226 | fixP = gas_cgen_record_fixup_exp (frag, where, insn, length, |
| 227 | operand, opinfo, exp); |
| 228 | |
| 229 | if (op == O_fptr_symbol) |
| 230 | { |
| 231 | if (operand->type != XSTORMY16_OPERAND_IMM16) |
| 232 | as_bad ("unsupported fptr fixup"); |
| 233 | else |
| 234 | { |
| 235 | fixP->fx_r_type = BFD_RELOC_XSTORMY16_FPTR16; |
| 236 | fixP->fx_where += 2; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | return fixP; |
| 241 | } |
| 242 | |
| 243 | valueT |
| 244 | md_section_align (segment, size) |
| 245 | segT segment; |
| 246 | valueT size; |
| 247 | { |
| 248 | int align = bfd_get_section_alignment (stdoutput, segment); |
| 249 | return ((size + (1 << align) - 1) & (-1 << align)); |
| 250 | } |
| 251 | |
| 252 | symbolS * |
| 253 | md_undefined_symbol (name) |
| 254 | char * name ATTRIBUTE_UNUSED; |
| 255 | { |
| 256 | return 0; |
| 257 | } |
| 258 | \f |
| 259 | /* Return an initial guess of the length by which a fragment must grow to |
| 260 | hold a branch to reach its destination. |
| 261 | Also updates fr_type/fr_subtype as necessary. |
| 262 | |
| 263 | Called just before doing relaxation. |
| 264 | Any symbol that is now undefined will not become defined. |
| 265 | The guess for fr_var is ACTUALLY the growth beyond fr_fix. |
| 266 | Whatever we do to grow fr_fix or fr_var contributes to our returned value. |
| 267 | Although it may not be explicit in the frag, pretend fr_var starts with a |
| 268 | 0 value. */ |
| 269 | |
| 270 | int |
| 271 | md_estimate_size_before_relax (fragP, segment) |
| 272 | fragS * fragP ATTRIBUTE_UNUSED; |
| 273 | segT segment ATTRIBUTE_UNUSED; |
| 274 | { |
| 275 | /* No assembler relaxation is defined (or necessary) for this port. */ |
| 276 | abort (); |
| 277 | } |
| 278 | |
| 279 | /* *fragP has been relaxed to its final size, and now needs to have |
| 280 | the bytes inside it modified to conform to the new size. |
| 281 | |
| 282 | Called after relaxation is finished. |
| 283 | fragP->fr_type == rs_machine_dependent. |
| 284 | fragP->fr_subtype is the subtype of what the address relaxed to. */ |
| 285 | |
| 286 | void |
| 287 | md_convert_frag (abfd, sec, fragP) |
| 288 | bfd * abfd ATTRIBUTE_UNUSED; |
| 289 | segT sec ATTRIBUTE_UNUSED; |
| 290 | fragS * fragP ATTRIBUTE_UNUSED; |
| 291 | { |
| 292 | /* No assembler relaxation is defined (or necessary) for this port. */ |
| 293 | abort (); |
| 294 | } |
| 295 | \f |
| 296 | /* Functions concerning relocs. */ |
| 297 | |
| 298 | /* The location from which a PC relative jump should be calculated, |
| 299 | given a PC relative reloc. */ |
| 300 | |
| 301 | long |
| 302 | md_pcrel_from_section (fixP, sec) |
| 303 | fixS * fixP; |
| 304 | segT sec; |
| 305 | { |
| 306 | if (fixP->fx_addsy != (symbolS *) NULL |
| 307 | && (! S_IS_DEFINED (fixP->fx_addsy) |
| 308 | || S_GET_SEGMENT (fixP->fx_addsy) != sec)) |
| 309 | { |
| 310 | /* The symbol is undefined (or is defined but not in this section). |
| 311 | Let the linker figure it out. */ |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | return fixP->fx_frag->fr_address + fixP->fx_where; |
| 316 | } |
| 317 | |
| 318 | /* Return the bfd reloc type for OPERAND of INSN at fixup FIXP. |
| 319 | Returns BFD_RELOC_NONE if no reloc type can be found. |
| 320 | *FIXP may be modified if desired. */ |
| 321 | |
| 322 | bfd_reloc_code_real_type |
| 323 | md_cgen_lookup_reloc (insn, operand, fixP) |
| 324 | const CGEN_INSN * insn ATTRIBUTE_UNUSED; |
| 325 | const CGEN_OPERAND * operand; |
| 326 | fixS * fixP; |
| 327 | { |
| 328 | switch (operand->type) |
| 329 | { |
| 330 | case XSTORMY16_OPERAND_IMM2: |
| 331 | case XSTORMY16_OPERAND_IMM3: |
| 332 | case XSTORMY16_OPERAND_IMM3B: |
| 333 | case XSTORMY16_OPERAND_IMM4: |
| 334 | case XSTORMY16_OPERAND_IMM12: |
| 335 | case XSTORMY16_OPERAND_HMEM8: |
| 336 | return BFD_RELOC_NONE; |
| 337 | |
| 338 | case XSTORMY16_OPERAND_IMM8: |
| 339 | case XSTORMY16_OPERAND_LMEM8: |
| 340 | return fixP->fx_pcrel ? BFD_RELOC_8_PCREL : BFD_RELOC_8; |
| 341 | |
| 342 | case XSTORMY16_OPERAND_IMM16: |
| 343 | fixP->fx_where += 2; |
| 344 | return fixP->fx_pcrel ? BFD_RELOC_16_PCREL : BFD_RELOC_16; |
| 345 | |
| 346 | case XSTORMY16_OPERAND_ABS24: |
| 347 | return BFD_RELOC_XSTORMY16_24; |
| 348 | |
| 349 | case XSTORMY16_OPERAND_REL8_2: |
| 350 | case XSTORMY16_OPERAND_REL8_4: |
| 351 | fixP->fx_pcrel = 1; |
| 352 | return BFD_RELOC_8_PCREL; |
| 353 | |
| 354 | case XSTORMY16_OPERAND_REL12: |
| 355 | fixP->fx_where += 2; |
| 356 | /* Fall through... */ |
| 357 | case XSTORMY16_OPERAND_REL12A: |
| 358 | fixP->fx_pcrel = 1; |
| 359 | return BFD_RELOC_XSTORMY16_REL_12; |
| 360 | |
| 361 | default : /* avoid -Wall warning */ |
| 362 | abort (); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | /* See whether we need to force a relocation into the output file. |
| 367 | This is used to force out switch and PC relative relocations when |
| 368 | relaxing. */ |
| 369 | |
| 370 | int |
| 371 | xstormy16_force_relocation (fix) |
| 372 | fixS * fix; |
| 373 | { |
| 374 | switch (fix->fx_r_type) |
| 375 | { |
| 376 | case BFD_RELOC_XSTORMY16_FPTR16: |
| 377 | case BFD_RELOC_VTABLE_INHERIT: |
| 378 | case BFD_RELOC_VTABLE_ENTRY: |
| 379 | return 1; |
| 380 | |
| 381 | default: |
| 382 | return 0; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | /* Return true if a relocation against a symbol may be replaced with |
| 387 | a relocation against section+offset. */ |
| 388 | |
| 389 | boolean |
| 390 | xstormy16_fix_adjustable (fixP) |
| 391 | fixS * fixP; |
| 392 | { |
| 393 | if (fixP->fx_addsy == NULL) |
| 394 | return 1; |
| 395 | |
| 396 | /* Prevent all adjustments to global symbols. */ |
| 397 | if (S_IS_EXTERN (fixP->fx_addsy)) |
| 398 | return 0; |
| 399 | |
| 400 | if (S_IS_WEAK (fixP->fx_addsy)) |
| 401 | return 0; |
| 402 | |
| 403 | /* We need the symbol name for the VTABLE entries. */ |
| 404 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
| 405 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) |
| 406 | return 0; |
| 407 | |
| 408 | return ! xstormy16_force_relocation (fixP); |
| 409 | } |
| 410 | |
| 411 | /* This is a copy of gas_cgen_md_apply_fix3, with some enhancements to |
| 412 | do various things that would not be valid for all ports. */ |
| 413 | |
| 414 | void |
| 415 | xstormy16_md_apply_fix3 (fixP, valueP, seg) |
| 416 | fixS * fixP; |
| 417 | valueT * valueP; |
| 418 | segT seg ATTRIBUTE_UNUSED; |
| 419 | { |
| 420 | char *where = fixP->fx_frag->fr_literal + fixP->fx_where; |
| 421 | valueT value; |
| 422 | /* Canonical name, since used a lot. */ |
| 423 | CGEN_CPU_DESC cd = gas_cgen_cpu_desc; |
| 424 | |
| 425 | /* This port has pc-relative relocs and DIFF_EXPR_OK defined, so |
| 426 | it must deal with turning a BFD_RELOC_{8,16,32,64} into a |
| 427 | BFD_RELOC_*_PCREL for the case of |
| 428 | |
| 429 | .word something-. |
| 430 | */ |
| 431 | if (fixP->fx_pcrel) |
| 432 | switch (fixP->fx_r_type) |
| 433 | { |
| 434 | case BFD_RELOC_8: |
| 435 | fixP->fx_r_type = BFD_RELOC_8_PCREL; |
| 436 | break; |
| 437 | case BFD_RELOC_16: |
| 438 | fixP->fx_r_type = BFD_RELOC_16_PCREL; |
| 439 | break; |
| 440 | case BFD_RELOC_32: |
| 441 | fixP->fx_r_type = BFD_RELOC_32_PCREL; |
| 442 | break; |
| 443 | case BFD_RELOC_64: |
| 444 | fixP->fx_r_type = BFD_RELOC_64_PCREL; |
| 445 | break; |
| 446 | default: |
| 447 | break; |
| 448 | } |
| 449 | |
| 450 | /* FIXME FIXME FIXME: The value we are passed in *valuep includes |
| 451 | the symbol values. Since we are using BFD_ASSEMBLER, if we are |
| 452 | doing this relocation the code in write.c is going to call |
| 453 | bfd_install_relocation, which is also going to use the symbol |
| 454 | value. That means that if the reloc is fully resolved we want to |
| 455 | use *valuep since bfd_install_relocation is not being used. |
| 456 | However, if the reloc is not fully resolved we do not want to use |
| 457 | *valuep, and must use fx_offset instead. However, if the reloc |
| 458 | is PC relative, we do want to use *valuep since it includes the |
| 459 | result of md_pcrel_from. This is confusing. */ |
| 460 | |
| 461 | if (fixP->fx_addsy == (symbolS *) NULL) |
| 462 | { |
| 463 | value = *valueP; |
| 464 | fixP->fx_done = 1; |
| 465 | } |
| 466 | else if (fixP->fx_pcrel) |
| 467 | value = *valueP; |
| 468 | else |
| 469 | { |
| 470 | value = fixP->fx_offset; |
| 471 | if (fixP->fx_subsy != (symbolS *) NULL) |
| 472 | { |
| 473 | if (S_GET_SEGMENT (fixP->fx_subsy) == absolute_section) |
| 474 | value -= S_GET_VALUE (fixP->fx_subsy); |
| 475 | else |
| 476 | { |
| 477 | /* We don't actually support subtracting a symbol. */ |
| 478 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 479 | _("expression too complex")); |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED) |
| 485 | { |
| 486 | int opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED; |
| 487 | const CGEN_OPERAND *operand = cgen_operand_lookup_by_num (cd, opindex); |
| 488 | const char *errmsg; |
| 489 | bfd_reloc_code_real_type reloc_type; |
| 490 | CGEN_FIELDS *fields = alloca (CGEN_CPU_SIZEOF_FIELDS (cd)); |
| 491 | const CGEN_INSN *insn = fixP->fx_cgen.insn; |
| 492 | |
| 493 | /* If the reloc has been fully resolved finish the operand here. */ |
| 494 | /* FIXME: This duplicates the capabilities of code in BFD. */ |
| 495 | if (fixP->fx_done) |
| 496 | { |
| 497 | CGEN_CPU_SET_FIELDS_BITSIZE (cd) (fields, CGEN_INSN_BITSIZE (insn)); |
| 498 | CGEN_CPU_SET_VMA_OPERAND (cd) (cd, opindex, fields, (bfd_vma) value); |
| 499 | |
| 500 | #if CGEN_INT_INSN_P |
| 501 | { |
| 502 | CGEN_INSN_INT insn_value = |
| 503 | cgen_get_insn_value (cd, where, CGEN_INSN_BITSIZE (insn)); |
| 504 | |
| 505 | /* ??? 0 is passed for `pc'. */ |
| 506 | errmsg = CGEN_CPU_INSERT_OPERAND (cd) (cd, opindex, fields, |
| 507 | &insn_value, (bfd_vma) 0); |
| 508 | cgen_put_insn_value (cd, where, CGEN_INSN_BITSIZE (insn), |
| 509 | insn_value); |
| 510 | } |
| 511 | #else |
| 512 | /* ??? 0 is passed for `pc'. */ |
| 513 | errmsg = CGEN_CPU_INSERT_OPERAND (cd) (cd, opindex, fields, where, |
| 514 | (bfd_vma) 0); |
| 515 | #endif |
| 516 | if (errmsg) |
| 517 | as_bad_where (fixP->fx_file, fixP->fx_line, "%s", errmsg); |
| 518 | } |
| 519 | |
| 520 | if (fixP->fx_done) |
| 521 | return; |
| 522 | |
| 523 | /* The operand isn't fully resolved. Determine a BFD reloc value |
| 524 | based on the operand information and leave it to |
| 525 | bfd_install_relocation. Note that this doesn't work when |
| 526 | partial_inplace == false. */ |
| 527 | |
| 528 | reloc_type = md_cgen_lookup_reloc (insn, operand, fixP); |
| 529 | if (reloc_type != BFD_RELOC_NONE) |
| 530 | { |
| 531 | fixP->fx_r_type = reloc_type; |
| 532 | } |
| 533 | else |
| 534 | { |
| 535 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 536 | _("unresolved expression that must be resolved")); |
| 537 | fixP->fx_done = 1; |
| 538 | return; |
| 539 | } |
| 540 | } |
| 541 | else if (fixP->fx_done) |
| 542 | { |
| 543 | /* We're finished with this fixup. Install it because |
| 544 | bfd_install_relocation won't be called to do it. */ |
| 545 | switch (fixP->fx_r_type) |
| 546 | { |
| 547 | case BFD_RELOC_8: |
| 548 | md_number_to_chars (where, value, 1); |
| 549 | break; |
| 550 | case BFD_RELOC_16: |
| 551 | md_number_to_chars (where, value, 2); |
| 552 | break; |
| 553 | case BFD_RELOC_32: |
| 554 | md_number_to_chars (where, value, 4); |
| 555 | break; |
| 556 | case BFD_RELOC_64: |
| 557 | md_number_to_chars (where, value, 8); |
| 558 | break; |
| 559 | default: |
| 560 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 561 | _("internal error: can't install fix for reloc type %d (`%s')"), |
| 562 | fixP->fx_r_type, bfd_get_reloc_code_name (fixP->fx_r_type)); |
| 563 | break; |
| 564 | } |
| 565 | } |
| 566 | else |
| 567 | { |
| 568 | /* bfd_install_relocation will be called to finish things up. */ |
| 569 | } |
| 570 | |
| 571 | /* This is a RELA port. Thus, it does not need to store a |
| 572 | value if it is going to make a reloc. What's more, when |
| 573 | assembling a line like |
| 574 | |
| 575 | .byte global-0x7f00 |
| 576 | |
| 577 | we'll get a spurious error message if we try to stuff 0x7f00 into |
| 578 | the byte. */ |
| 579 | if (! fixP->fx_done) |
| 580 | *valueP = 0; |
| 581 | |
| 582 | /* Tuck `value' away for use by tc_gen_reloc. |
| 583 | See the comment describing fx_addnumber in write.h. |
| 584 | This field is misnamed (or misused :-). */ |
| 585 | fixP->fx_addnumber = value; |
| 586 | } |
| 587 | |
| 588 | \f |
| 589 | /* Write a value out to the object file, using the appropriate endianness. */ |
| 590 | |
| 591 | void |
| 592 | md_number_to_chars (buf, val, n) |
| 593 | char * buf; |
| 594 | valueT val; |
| 595 | int n; |
| 596 | { |
| 597 | number_to_chars_littleendian (buf, val, n); |
| 598 | } |
| 599 | |
| 600 | /* Turn a string in input_line_pointer into a floating point constant of type |
| 601 | type, and store the appropriate bytes in *litP. The number of LITTLENUMS |
| 602 | emitted is stored in *sizeP . An error message is returned, or NULL on OK. |
| 603 | */ |
| 604 | |
| 605 | /* Equal to MAX_PRECISION in atof-ieee.c */ |
| 606 | #define MAX_LITTLENUMS 6 |
| 607 | |
| 608 | char * |
| 609 | md_atof (type, litP, sizeP) |
| 610 | char type; |
| 611 | char * litP; |
| 612 | int * sizeP; |
| 613 | { |
| 614 | int prec; |
| 615 | LITTLENUM_TYPE words [MAX_LITTLENUMS]; |
| 616 | LITTLENUM_TYPE *wordP; |
| 617 | char * t; |
| 618 | |
| 619 | switch (type) |
| 620 | { |
| 621 | case 'f': |
| 622 | case 'F': |
| 623 | prec = 2; |
| 624 | break; |
| 625 | |
| 626 | case 'd': |
| 627 | case 'D': |
| 628 | prec = 4; |
| 629 | break; |
| 630 | |
| 631 | /* FIXME: Some targets allow other format chars for bigger sizes here. */ |
| 632 | |
| 633 | default: |
| 634 | * sizeP = 0; |
| 635 | return _("Bad call to md_atof()"); |
| 636 | } |
| 637 | |
| 638 | t = atof_ieee (input_line_pointer, type, words); |
| 639 | if (t) |
| 640 | input_line_pointer = t; |
| 641 | * sizeP = prec * sizeof (LITTLENUM_TYPE); |
| 642 | |
| 643 | *sizeP = prec * sizeof (LITTLENUM_TYPE); |
| 644 | /* This loops outputs the LITTLENUMs in REVERSE order; in accord with |
| 645 | the littleendianness of the processor. */ |
| 646 | for (wordP = words + prec - 1; prec--;) |
| 647 | { |
| 648 | md_number_to_chars (litP, (valueT) (*wordP--), sizeof (LITTLENUM_TYPE)); |
| 649 | litP += sizeof (LITTLENUM_TYPE); |
| 650 | } |
| 651 | |
| 652 | return 0; |
| 653 | } |