| 1 | /* tc-sh.c -- Assemble code for the Hitachi Super-H |
| 2 | Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
| 3 | Free Software Foundation, Inc. |
| 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 | /* Written By Steve Chamberlain <sac@cygnus.com> */ |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include "as.h" |
| 26 | #include "bfd.h" |
| 27 | #include "subsegs.h" |
| 28 | #define DEFINE_TABLE |
| 29 | #include "opcodes/sh-opc.h" |
| 30 | #include "safe-ctype.h" |
| 31 | #include "struc-symbol.h" |
| 32 | |
| 33 | #ifdef OBJ_ELF |
| 34 | #include "elf/sh.h" |
| 35 | #endif |
| 36 | |
| 37 | #include "dwarf2dbg.h" |
| 38 | |
| 39 | typedef struct |
| 40 | { |
| 41 | sh_arg_type type; |
| 42 | int reg; |
| 43 | expressionS immediate; |
| 44 | } |
| 45 | sh_operand_info; |
| 46 | |
| 47 | const char comment_chars[] = "!"; |
| 48 | const char line_separator_chars[] = ";"; |
| 49 | const char line_comment_chars[] = "!#"; |
| 50 | |
| 51 | static void s_uses PARAMS ((int)); |
| 52 | |
| 53 | static void sh_count_relocs PARAMS ((bfd *, segT, PTR)); |
| 54 | static void sh_frob_section PARAMS ((bfd *, segT, PTR)); |
| 55 | |
| 56 | static void s_uacons PARAMS ((int)); |
| 57 | static sh_opcode_info *find_cooked_opcode PARAMS ((char **)); |
| 58 | static unsigned int assemble_ppi PARAMS ((char *, sh_opcode_info *)); |
| 59 | static void little PARAMS ((int)); |
| 60 | static void big PARAMS ((int)); |
| 61 | static int parse_reg PARAMS ((char *, int *, int *)); |
| 62 | static symbolS *dot PARAMS ((void)); |
| 63 | static char *parse_exp PARAMS ((char *, sh_operand_info *)); |
| 64 | static char *parse_at PARAMS ((char *, sh_operand_info *)); |
| 65 | static void get_operand PARAMS ((char **, sh_operand_info *)); |
| 66 | static char *get_operands |
| 67 | PARAMS ((sh_opcode_info *, char *, sh_operand_info *)); |
| 68 | static sh_opcode_info *get_specific |
| 69 | PARAMS ((sh_opcode_info *, sh_operand_info *)); |
| 70 | static void insert PARAMS ((char *, int, int, sh_operand_info *)); |
| 71 | static void build_relax PARAMS ((sh_opcode_info *, sh_operand_info *)); |
| 72 | static char *insert_loop_bounds PARAMS ((char *, sh_operand_info *)); |
| 73 | static unsigned int build_Mytes |
| 74 | PARAMS ((sh_opcode_info *, sh_operand_info *)); |
| 75 | |
| 76 | #ifdef OBJ_ELF |
| 77 | static void sh_elf_cons PARAMS ((int)); |
| 78 | |
| 79 | inline static int sh_PIC_related_p PARAMS ((symbolS *)); |
| 80 | static int sh_check_fixup PARAMS ((expressionS *, bfd_reloc_code_real_type *)); |
| 81 | inline static char *sh_end_of_match PARAMS ((char *, char *)); |
| 82 | |
| 83 | symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
| 84 | #endif |
| 85 | |
| 86 | static void |
| 87 | big (ignore) |
| 88 | int ignore ATTRIBUTE_UNUSED; |
| 89 | { |
| 90 | if (! target_big_endian) |
| 91 | as_bad (_("directive .big encountered when option -big required")); |
| 92 | |
| 93 | /* Stop further messages. */ |
| 94 | target_big_endian = 1; |
| 95 | } |
| 96 | |
| 97 | static void |
| 98 | little (ignore) |
| 99 | int ignore ATTRIBUTE_UNUSED; |
| 100 | { |
| 101 | if (target_big_endian) |
| 102 | as_bad (_("directive .little encountered when option -little required")); |
| 103 | |
| 104 | /* Stop further messages. */ |
| 105 | target_big_endian = 0; |
| 106 | } |
| 107 | |
| 108 | /* This table describes all the machine specific pseudo-ops the assembler |
| 109 | has to support. The fields are: |
| 110 | pseudo-op name without dot |
| 111 | function to call to execute this pseudo-op |
| 112 | Integer arg to pass to the function. */ |
| 113 | |
| 114 | const pseudo_typeS md_pseudo_table[] = |
| 115 | { |
| 116 | #ifdef OBJ_ELF |
| 117 | {"long", sh_elf_cons, 4}, |
| 118 | {"int", sh_elf_cons, 4}, |
| 119 | {"word", sh_elf_cons, 2}, |
| 120 | {"short", sh_elf_cons, 2}, |
| 121 | #else |
| 122 | {"int", cons, 4}, |
| 123 | {"word", cons, 2}, |
| 124 | #endif /* OBJ_ELF */ |
| 125 | {"big", big, 0}, |
| 126 | {"form", listing_psize, 0}, |
| 127 | {"little", little, 0}, |
| 128 | {"heading", listing_title, 0}, |
| 129 | {"import", s_ignore, 0}, |
| 130 | {"page", listing_eject, 0}, |
| 131 | {"program", s_ignore, 0}, |
| 132 | {"uses", s_uses, 0}, |
| 133 | {"uaword", s_uacons, 2}, |
| 134 | {"ualong", s_uacons, 4}, |
| 135 | {"uaquad", s_uacons, 8}, |
| 136 | {"2byte", s_uacons, 2}, |
| 137 | {"4byte", s_uacons, 4}, |
| 138 | {"8byte", s_uacons, 8}, |
| 139 | #ifdef BFD_ASSEMBLER |
| 140 | {"file", dwarf2_directive_file, 0 }, |
| 141 | {"loc", dwarf2_directive_loc, 0 }, |
| 142 | #endif |
| 143 | {0, 0, 0} |
| 144 | }; |
| 145 | |
| 146 | /*int md_reloc_size; */ |
| 147 | |
| 148 | int sh_relax; /* set if -relax seen */ |
| 149 | |
| 150 | /* Whether -small was seen. */ |
| 151 | |
| 152 | int sh_small; |
| 153 | |
| 154 | /* Whether -dsp was seen. */ |
| 155 | |
| 156 | static int sh_dsp; |
| 157 | |
| 158 | /* The bit mask of architectures that could |
| 159 | accomodate the insns seen so far. */ |
| 160 | static int valid_arch; |
| 161 | |
| 162 | const char EXP_CHARS[] = "eE"; |
| 163 | |
| 164 | /* Chars that mean this number is a floating point constant. */ |
| 165 | /* As in 0f12.456 */ |
| 166 | /* or 0d1.2345e12 */ |
| 167 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; |
| 168 | |
| 169 | #define C(a,b) ENCODE_RELAX(a,b) |
| 170 | |
| 171 | #define ENCODE_RELAX(what,length) (((what) << 4) + (length)) |
| 172 | #define GET_WHAT(x) ((x>>4)) |
| 173 | |
| 174 | /* These are the three types of relaxable instrction. */ |
| 175 | #define COND_JUMP 1 |
| 176 | #define COND_JUMP_DELAY 2 |
| 177 | #define UNCOND_JUMP 3 |
| 178 | #define END 4 |
| 179 | |
| 180 | #define UNDEF_DISP 0 |
| 181 | #define COND8 1 |
| 182 | #define COND12 2 |
| 183 | #define COND32 3 |
| 184 | #define UNDEF_WORD_DISP 4 |
| 185 | |
| 186 | #define UNCOND12 1 |
| 187 | #define UNCOND32 2 |
| 188 | |
| 189 | /* Branch displacements are from the address of the branch plus |
| 190 | four, thus all minimum and maximum values have 4 added to them. */ |
| 191 | #define COND8_F 258 |
| 192 | #define COND8_M -252 |
| 193 | #define COND8_LENGTH 2 |
| 194 | |
| 195 | /* There is one extra instruction before the branch, so we must add |
| 196 | two more bytes to account for it. */ |
| 197 | #define COND12_F 4100 |
| 198 | #define COND12_M -4090 |
| 199 | #define COND12_LENGTH 6 |
| 200 | |
| 201 | #define COND12_DELAY_LENGTH 4 |
| 202 | |
| 203 | /* ??? The minimum and maximum values are wrong, but this does not matter |
| 204 | since this relocation type is not supported yet. */ |
| 205 | #define COND32_F (1<<30) |
| 206 | #define COND32_M -(1<<30) |
| 207 | #define COND32_LENGTH 14 |
| 208 | |
| 209 | #define UNCOND12_F 4098 |
| 210 | #define UNCOND12_M -4092 |
| 211 | #define UNCOND12_LENGTH 2 |
| 212 | |
| 213 | /* ??? The minimum and maximum values are wrong, but this does not matter |
| 214 | since this relocation type is not supported yet. */ |
| 215 | #define UNCOND32_F (1<<30) |
| 216 | #define UNCOND32_M -(1<<30) |
| 217 | #define UNCOND32_LENGTH 14 |
| 218 | |
| 219 | #define EMPTY { 0, 0, 0, 0 } |
| 220 | |
| 221 | const relax_typeS md_relax_table[C (END, 0)] = { |
| 222 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, |
| 223 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, |
| 224 | |
| 225 | EMPTY, |
| 226 | /* C (COND_JUMP, COND8) */ |
| 227 | { COND8_F, COND8_M, COND8_LENGTH, C (COND_JUMP, COND12) }, |
| 228 | /* C (COND_JUMP, COND12) */ |
| 229 | { COND12_F, COND12_M, COND12_LENGTH, C (COND_JUMP, COND32), }, |
| 230 | /* C (COND_JUMP, COND32) */ |
| 231 | { COND32_F, COND32_M, COND32_LENGTH, 0, }, |
| 232 | /* C (COND_JUMP, UNDEF_WORD_DISP) */ |
| 233 | { 0, 0, COND32_LENGTH, 0, }, |
| 234 | EMPTY, EMPTY, EMPTY, |
| 235 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, |
| 236 | |
| 237 | EMPTY, |
| 238 | /* C (COND_JUMP_DELAY, COND8) */ |
| 239 | { COND8_F, COND8_M, COND8_LENGTH, C (COND_JUMP_DELAY, COND12) }, |
| 240 | /* C (COND_JUMP_DELAY, COND12) */ |
| 241 | { COND12_F, COND12_M, COND12_DELAY_LENGTH, C (COND_JUMP_DELAY, COND32), }, |
| 242 | /* C (COND_JUMP_DELAY, COND32) */ |
| 243 | { COND32_F, COND32_M, COND32_LENGTH, 0, }, |
| 244 | /* C (COND_JUMP_DELAY, UNDEF_WORD_DISP) */ |
| 245 | { 0, 0, COND32_LENGTH, 0, }, |
| 246 | EMPTY, EMPTY, EMPTY, |
| 247 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, |
| 248 | |
| 249 | EMPTY, |
| 250 | /* C (UNCOND_JUMP, UNCOND12) */ |
| 251 | { UNCOND12_F, UNCOND12_M, UNCOND12_LENGTH, C (UNCOND_JUMP, UNCOND32), }, |
| 252 | /* C (UNCOND_JUMP, UNCOND32) */ |
| 253 | { UNCOND32_F, UNCOND32_M, UNCOND32_LENGTH, 0, }, |
| 254 | EMPTY, |
| 255 | /* C (UNCOND_JUMP, UNDEF_WORD_DISP) */ |
| 256 | { 0, 0, UNCOND32_LENGTH, 0, }, |
| 257 | EMPTY, EMPTY, EMPTY, |
| 258 | EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, |
| 259 | }; |
| 260 | |
| 261 | #undef EMPTY |
| 262 | |
| 263 | static struct hash_control *opcode_hash_control; /* Opcode mnemonics */ |
| 264 | |
| 265 | \f |
| 266 | #ifdef OBJ_ELF |
| 267 | /* Determinet whether the symbol needs any kind of PIC relocation. */ |
| 268 | |
| 269 | inline static int |
| 270 | sh_PIC_related_p (sym) |
| 271 | symbolS *sym; |
| 272 | { |
| 273 | expressionS *exp; |
| 274 | |
| 275 | if (! sym) |
| 276 | return 0; |
| 277 | |
| 278 | if (sym == GOT_symbol) |
| 279 | return 1; |
| 280 | |
| 281 | exp = symbol_get_value_expression (sym); |
| 282 | |
| 283 | return (exp->X_op == O_PIC_reloc |
| 284 | || sh_PIC_related_p (exp->X_add_symbol) |
| 285 | || sh_PIC_related_p (exp->X_op_symbol)); |
| 286 | } |
| 287 | |
| 288 | /* Determine the relocation type to be used to represent the |
| 289 | expression, that may be rearranged. */ |
| 290 | |
| 291 | static int |
| 292 | sh_check_fixup (main_exp, r_type_p) |
| 293 | expressionS *main_exp; |
| 294 | bfd_reloc_code_real_type *r_type_p; |
| 295 | { |
| 296 | expressionS *exp = main_exp; |
| 297 | |
| 298 | /* This is here for backward-compatibility only. GCC used to generated: |
| 299 | |
| 300 | f@PLT + . - (.LPCS# + 2) |
| 301 | |
| 302 | but we'd rather be able to handle this as a PIC-related reference |
| 303 | plus/minus a symbol. However, gas' parser gives us: |
| 304 | |
| 305 | O_subtract (O_add (f@PLT, .), .LPCS#+2) |
| 306 | |
| 307 | so we attempt to transform this into: |
| 308 | |
| 309 | O_subtract (f@PLT, O_subtract (.LPCS#+2, .)) |
| 310 | |
| 311 | which we can handle simply below. */ |
| 312 | if (exp->X_op == O_subtract) |
| 313 | { |
| 314 | if (sh_PIC_related_p (exp->X_op_symbol)) |
| 315 | return 1; |
| 316 | |
| 317 | exp = symbol_get_value_expression (exp->X_add_symbol); |
| 318 | |
| 319 | if (exp && sh_PIC_related_p (exp->X_op_symbol)) |
| 320 | return 1; |
| 321 | |
| 322 | if (exp && exp->X_op == O_add |
| 323 | && sh_PIC_related_p (exp->X_add_symbol)) |
| 324 | { |
| 325 | symbolS *sym = exp->X_add_symbol; |
| 326 | |
| 327 | exp->X_op = O_subtract; |
| 328 | exp->X_add_symbol = main_exp->X_op_symbol; |
| 329 | |
| 330 | main_exp->X_op_symbol = main_exp->X_add_symbol; |
| 331 | main_exp->X_add_symbol = sym; |
| 332 | |
| 333 | main_exp->X_add_number += exp->X_add_number; |
| 334 | exp->X_add_number = 0; |
| 335 | } |
| 336 | |
| 337 | exp = main_exp; |
| 338 | } |
| 339 | else if (exp->X_op == O_add && sh_PIC_related_p (exp->X_op_symbol)) |
| 340 | return 1; |
| 341 | |
| 342 | if (exp->X_op == O_symbol || exp->X_op == O_add || exp->X_op == O_subtract) |
| 343 | { |
| 344 | if (exp->X_add_symbol && exp->X_add_symbol == GOT_symbol) |
| 345 | { |
| 346 | *r_type_p = BFD_RELOC_SH_GOTPC; |
| 347 | return 0; |
| 348 | } |
| 349 | exp = symbol_get_value_expression (exp->X_add_symbol); |
| 350 | if (! exp) |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | if (exp->X_op == O_PIC_reloc) |
| 355 | { |
| 356 | *r_type_p = exp->X_md; |
| 357 | if (exp == main_exp) |
| 358 | exp->X_op = O_symbol; |
| 359 | else |
| 360 | { |
| 361 | main_exp->X_add_symbol = exp->X_add_symbol; |
| 362 | main_exp->X_add_number += exp->X_add_number; |
| 363 | } |
| 364 | } |
| 365 | else |
| 366 | return (sh_PIC_related_p (exp->X_add_symbol) |
| 367 | || sh_PIC_related_p (exp->X_op_symbol)); |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | /* Add expression EXP of SIZE bytes to offset OFF of fragment FRAG. */ |
| 373 | |
| 374 | void |
| 375 | sh_cons_fix_new (frag, off, size, exp) |
| 376 | fragS *frag; |
| 377 | int off, size; |
| 378 | expressionS *exp; |
| 379 | { |
| 380 | bfd_reloc_code_real_type r_type = BFD_RELOC_UNUSED; |
| 381 | |
| 382 | if (sh_check_fixup (exp, &r_type)) |
| 383 | as_bad (_("Invalid PIC expression.")); |
| 384 | |
| 385 | if (r_type == BFD_RELOC_UNUSED) |
| 386 | switch (size) |
| 387 | { |
| 388 | case 1: |
| 389 | r_type = BFD_RELOC_8; |
| 390 | break; |
| 391 | |
| 392 | case 2: |
| 393 | r_type = BFD_RELOC_16; |
| 394 | break; |
| 395 | |
| 396 | case 4: |
| 397 | r_type = BFD_RELOC_32; |
| 398 | break; |
| 399 | |
| 400 | default: |
| 401 | goto error; |
| 402 | } |
| 403 | else if (size != 4) |
| 404 | { |
| 405 | error: |
| 406 | as_bad (_("unsupported BFD relocation size %u"), size); |
| 407 | r_type = BFD_RELOC_UNUSED; |
| 408 | } |
| 409 | |
| 410 | fix_new_exp (frag, off, size, exp, 0, r_type); |
| 411 | } |
| 412 | |
| 413 | /* The regular cons() function, that reads constants, doesn't support |
| 414 | suffixes such as @GOT, @GOTOFF and @PLT, that generate |
| 415 | machine-specific relocation types. So we must define it here. */ |
| 416 | /* Clobbers input_line_pointer, checks end-of-line. */ |
| 417 | static void |
| 418 | sh_elf_cons (nbytes) |
| 419 | register int nbytes; /* 1=.byte, 2=.word, 4=.long */ |
| 420 | { |
| 421 | expressionS exp; |
| 422 | |
| 423 | if (is_it_end_of_statement ()) |
| 424 | { |
| 425 | demand_empty_rest_of_line (); |
| 426 | return; |
| 427 | } |
| 428 | |
| 429 | do |
| 430 | { |
| 431 | expression (&exp); |
| 432 | emit_expr (&exp, (unsigned int) nbytes); |
| 433 | } |
| 434 | while (*input_line_pointer++ == ','); |
| 435 | |
| 436 | input_line_pointer--; /* Put terminator back into stream. */ |
| 437 | if (*input_line_pointer == '#' || *input_line_pointer == '!') |
| 438 | { |
| 439 | while (! is_end_of_line[(unsigned char) *input_line_pointer++]); |
| 440 | } |
| 441 | else |
| 442 | demand_empty_rest_of_line (); |
| 443 | } |
| 444 | #endif /* OBJ_ELF */ |
| 445 | |
| 446 | \f |
| 447 | /* This function is called once, at assembler startup time. This should |
| 448 | set up all the tables, etc that the MD part of the assembler needs. */ |
| 449 | |
| 450 | void |
| 451 | md_begin () |
| 452 | { |
| 453 | sh_opcode_info *opcode; |
| 454 | char *prev_name = ""; |
| 455 | int target_arch; |
| 456 | |
| 457 | target_arch = arch_sh1_up & ~(sh_dsp ? arch_sh3e_up : arch_sh_dsp_up); |
| 458 | valid_arch = target_arch; |
| 459 | |
| 460 | opcode_hash_control = hash_new (); |
| 461 | |
| 462 | /* Insert unique names into hash table. */ |
| 463 | for (opcode = sh_table; opcode->name; opcode++) |
| 464 | { |
| 465 | if (strcmp (prev_name, opcode->name)) |
| 466 | { |
| 467 | if (! (opcode->arch & target_arch)) |
| 468 | continue; |
| 469 | prev_name = opcode->name; |
| 470 | hash_insert (opcode_hash_control, opcode->name, (char *) opcode); |
| 471 | } |
| 472 | else |
| 473 | { |
| 474 | /* Make all the opcodes with the same name point to the same |
| 475 | string. */ |
| 476 | opcode->name = prev_name; |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | static int reg_m; |
| 482 | static int reg_n; |
| 483 | static int reg_x, reg_y; |
| 484 | static int reg_efg; |
| 485 | static int reg_b; |
| 486 | |
| 487 | #define IDENT_CHAR(c) (ISALNUM (c) || (c) == '_') |
| 488 | |
| 489 | /* Try to parse a reg name. Return the number of chars consumed. */ |
| 490 | |
| 491 | static int |
| 492 | parse_reg (src, mode, reg) |
| 493 | char *src; |
| 494 | int *mode; |
| 495 | int *reg; |
| 496 | { |
| 497 | char l0 = TOLOWER (src[0]); |
| 498 | char l1 = l0 ? TOLOWER (src[1]) : 0; |
| 499 | |
| 500 | /* We use ! IDENT_CHAR for the next character after the register name, to |
| 501 | make sure that we won't accidentally recognize a symbol name such as |
| 502 | 'sram' or sr_ram as being a reference to the register 'sr'. */ |
| 503 | |
| 504 | if (l0 == 'r') |
| 505 | { |
| 506 | if (l1 == '1') |
| 507 | { |
| 508 | if (src[2] >= '0' && src[2] <= '5' |
| 509 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 510 | { |
| 511 | *mode = A_REG_N; |
| 512 | *reg = 10 + src[2] - '0'; |
| 513 | return 3; |
| 514 | } |
| 515 | } |
| 516 | if (l1 >= '0' && l1 <= '9' |
| 517 | && ! IDENT_CHAR ((unsigned char) src[2])) |
| 518 | { |
| 519 | *mode = A_REG_N; |
| 520 | *reg = (l1 - '0'); |
| 521 | return 2; |
| 522 | } |
| 523 | if (l1 >= '0' && l1 <= '7' && strncasecmp (&src[2], "_bank", 5) == 0 |
| 524 | && ! IDENT_CHAR ((unsigned char) src[7])) |
| 525 | { |
| 526 | *mode = A_REG_B; |
| 527 | *reg = (l1 - '0'); |
| 528 | return 7; |
| 529 | } |
| 530 | |
| 531 | if (l1 == 'e' && ! IDENT_CHAR ((unsigned char) src[2])) |
| 532 | { |
| 533 | *mode = A_RE; |
| 534 | return 2; |
| 535 | } |
| 536 | if (l1 == 's' && ! IDENT_CHAR ((unsigned char) src[2])) |
| 537 | { |
| 538 | *mode = A_RS; |
| 539 | return 2; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | if (l0 == 'a') |
| 544 | { |
| 545 | if (l1 == '0') |
| 546 | { |
| 547 | if (! IDENT_CHAR ((unsigned char) src[2])) |
| 548 | { |
| 549 | *mode = DSP_REG_N; |
| 550 | *reg = A_A0_NUM; |
| 551 | return 2; |
| 552 | } |
| 553 | if (TOLOWER (src[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src[3])) |
| 554 | { |
| 555 | *mode = DSP_REG_N; |
| 556 | *reg = A_A0G_NUM; |
| 557 | return 3; |
| 558 | } |
| 559 | } |
| 560 | if (l1 == '1') |
| 561 | { |
| 562 | if (! IDENT_CHAR ((unsigned char) src[2])) |
| 563 | { |
| 564 | *mode = DSP_REG_N; |
| 565 | *reg = A_A1_NUM; |
| 566 | return 2; |
| 567 | } |
| 568 | if (TOLOWER (src[2]) == 'g' && ! IDENT_CHAR ((unsigned char) src[3])) |
| 569 | { |
| 570 | *mode = DSP_REG_N; |
| 571 | *reg = A_A1G_NUM; |
| 572 | return 3; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | if (l1 == 'x' && src[2] >= '0' && src[2] <= '1' |
| 577 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 578 | { |
| 579 | *mode = A_REG_N; |
| 580 | *reg = 4 + (l1 - '0'); |
| 581 | return 3; |
| 582 | } |
| 583 | if (l1 == 'y' && src[2] >= '0' && src[2] <= '1' |
| 584 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 585 | { |
| 586 | *mode = A_REG_N; |
| 587 | *reg = 6 + (l1 - '0'); |
| 588 | return 3; |
| 589 | } |
| 590 | if (l1 == 's' && src[2] >= '0' && src[2] <= '3' |
| 591 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 592 | { |
| 593 | int n = l1 - '0'; |
| 594 | |
| 595 | *mode = A_REG_N; |
| 596 | *reg = n | ((~n & 2) << 1); |
| 597 | return 3; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | if (l0 == 'i' && l1 && ! IDENT_CHAR ((unsigned char) src[2])) |
| 602 | { |
| 603 | if (l1 == 's') |
| 604 | { |
| 605 | *mode = A_REG_N; |
| 606 | *reg = 8; |
| 607 | return 2; |
| 608 | } |
| 609 | if (l1 == 'x') |
| 610 | { |
| 611 | *mode = A_REG_N; |
| 612 | *reg = 8; |
| 613 | return 2; |
| 614 | } |
| 615 | if (l1 == 'y') |
| 616 | { |
| 617 | *mode = A_REG_N; |
| 618 | *reg = 9; |
| 619 | return 2; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | if (l0 == 'x' && l1 >= '0' && l1 <= '1' |
| 624 | && ! IDENT_CHAR ((unsigned char) src[2])) |
| 625 | { |
| 626 | *mode = DSP_REG_N; |
| 627 | *reg = A_X0_NUM + l1 - '0'; |
| 628 | return 2; |
| 629 | } |
| 630 | |
| 631 | if (l0 == 'y' && l1 >= '0' && l1 <= '1' |
| 632 | && ! IDENT_CHAR ((unsigned char) src[2])) |
| 633 | { |
| 634 | *mode = DSP_REG_N; |
| 635 | *reg = A_Y0_NUM + l1 - '0'; |
| 636 | return 2; |
| 637 | } |
| 638 | |
| 639 | if (l0 == 'm' && l1 >= '0' && l1 <= '1' |
| 640 | && ! IDENT_CHAR ((unsigned char) src[2])) |
| 641 | { |
| 642 | *mode = DSP_REG_N; |
| 643 | *reg = l1 == '0' ? A_M0_NUM : A_M1_NUM; |
| 644 | return 2; |
| 645 | } |
| 646 | |
| 647 | if (l0 == 's' |
| 648 | && l1 == 's' |
| 649 | && TOLOWER (src[2]) == 'r' && ! IDENT_CHAR ((unsigned char) src[3])) |
| 650 | { |
| 651 | *mode = A_SSR; |
| 652 | return 3; |
| 653 | } |
| 654 | |
| 655 | if (l0 == 's' && l1 == 'p' && TOLOWER (src[2]) == 'c' |
| 656 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 657 | { |
| 658 | *mode = A_SPC; |
| 659 | return 3; |
| 660 | } |
| 661 | |
| 662 | if (l0 == 's' && l1 == 'g' && TOLOWER (src[2]) == 'r' |
| 663 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 664 | { |
| 665 | *mode = A_SGR; |
| 666 | return 3; |
| 667 | } |
| 668 | |
| 669 | if (l0 == 'd' && l1 == 's' && TOLOWER (src[2]) == 'r' |
| 670 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 671 | { |
| 672 | *mode = A_DSR; |
| 673 | return 3; |
| 674 | } |
| 675 | |
| 676 | if (l0 == 'd' && l1 == 'b' && TOLOWER (src[2]) == 'r' |
| 677 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 678 | { |
| 679 | *mode = A_DBR; |
| 680 | return 3; |
| 681 | } |
| 682 | |
| 683 | if (l0 == 's' && l1 == 'r' && ! IDENT_CHAR ((unsigned char) src[2])) |
| 684 | { |
| 685 | *mode = A_SR; |
| 686 | return 2; |
| 687 | } |
| 688 | |
| 689 | if (l0 == 's' && l1 == 'p' && ! IDENT_CHAR ((unsigned char) src[2])) |
| 690 | { |
| 691 | *mode = A_REG_N; |
| 692 | *reg = 15; |
| 693 | return 2; |
| 694 | } |
| 695 | |
| 696 | if (l0 == 'p' && l1 == 'r' && ! IDENT_CHAR ((unsigned char) src[2])) |
| 697 | { |
| 698 | *mode = A_PR; |
| 699 | return 2; |
| 700 | } |
| 701 | if (l0 == 'p' && l1 == 'c' && ! IDENT_CHAR ((unsigned char) src[2])) |
| 702 | { |
| 703 | /* Don't use A_DISP_PC here - that would accept stuff like 'mova pc,r0' |
| 704 | and use an uninitialized immediate. */ |
| 705 | *mode = A_PC; |
| 706 | return 2; |
| 707 | } |
| 708 | if (l0 == 'g' && l1 == 'b' && TOLOWER (src[2]) == 'r' |
| 709 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 710 | { |
| 711 | *mode = A_GBR; |
| 712 | return 3; |
| 713 | } |
| 714 | if (l0 == 'v' && l1 == 'b' && TOLOWER (src[2]) == 'r' |
| 715 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 716 | { |
| 717 | *mode = A_VBR; |
| 718 | return 3; |
| 719 | } |
| 720 | |
| 721 | if (l0 == 'm' && l1 == 'a' && TOLOWER (src[2]) == 'c' |
| 722 | && ! IDENT_CHAR ((unsigned char) src[4])) |
| 723 | { |
| 724 | if (TOLOWER (src[3]) == 'l') |
| 725 | { |
| 726 | *mode = A_MACL; |
| 727 | return 4; |
| 728 | } |
| 729 | if (TOLOWER (src[3]) == 'h') |
| 730 | { |
| 731 | *mode = A_MACH; |
| 732 | return 4; |
| 733 | } |
| 734 | } |
| 735 | if (l0 == 'm' && l1 == 'o' && TOLOWER (src[2]) == 'd' |
| 736 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 737 | { |
| 738 | *mode = A_MOD; |
| 739 | return 3; |
| 740 | } |
| 741 | if (l0 == 'f' && l1 == 'r') |
| 742 | { |
| 743 | if (src[2] == '1') |
| 744 | { |
| 745 | if (src[3] >= '0' && src[3] <= '5' |
| 746 | && ! IDENT_CHAR ((unsigned char) src[4])) |
| 747 | { |
| 748 | *mode = F_REG_N; |
| 749 | *reg = 10 + src[3] - '0'; |
| 750 | return 4; |
| 751 | } |
| 752 | } |
| 753 | if (src[2] >= '0' && src[2] <= '9' |
| 754 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 755 | { |
| 756 | *mode = F_REG_N; |
| 757 | *reg = (src[2] - '0'); |
| 758 | return 3; |
| 759 | } |
| 760 | } |
| 761 | if (l0 == 'd' && l1 == 'r') |
| 762 | { |
| 763 | if (src[2] == '1') |
| 764 | { |
| 765 | if (src[3] >= '0' && src[3] <= '4' && ! ((src[3] - '0') & 1) |
| 766 | && ! IDENT_CHAR ((unsigned char) src[4])) |
| 767 | { |
| 768 | *mode = D_REG_N; |
| 769 | *reg = 10 + src[3] - '0'; |
| 770 | return 4; |
| 771 | } |
| 772 | } |
| 773 | if (src[2] >= '0' && src[2] <= '8' && ! ((src[2] - '0') & 1) |
| 774 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 775 | { |
| 776 | *mode = D_REG_N; |
| 777 | *reg = (src[2] - '0'); |
| 778 | return 3; |
| 779 | } |
| 780 | } |
| 781 | if (l0 == 'x' && l1 == 'd') |
| 782 | { |
| 783 | if (src[2] == '1') |
| 784 | { |
| 785 | if (src[3] >= '0' && src[3] <= '4' && ! ((src[3] - '0') & 1) |
| 786 | && ! IDENT_CHAR ((unsigned char) src[4])) |
| 787 | { |
| 788 | *mode = X_REG_N; |
| 789 | *reg = 11 + src[3] - '0'; |
| 790 | return 4; |
| 791 | } |
| 792 | } |
| 793 | if (src[2] >= '0' && src[2] <= '8' && ! ((src[2] - '0') & 1) |
| 794 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 795 | { |
| 796 | *mode = X_REG_N; |
| 797 | *reg = (src[2] - '0') + 1; |
| 798 | return 3; |
| 799 | } |
| 800 | } |
| 801 | if (l0 == 'f' && l1 == 'v') |
| 802 | { |
| 803 | if (src[2] == '1'&& src[3] == '2' && ! IDENT_CHAR ((unsigned char) src[4])) |
| 804 | { |
| 805 | *mode = V_REG_N; |
| 806 | *reg = 12; |
| 807 | return 4; |
| 808 | } |
| 809 | if ((src[2] == '0' || src[2] == '4' || src[2] == '8') |
| 810 | && ! IDENT_CHAR ((unsigned char) src[3])) |
| 811 | { |
| 812 | *mode = V_REG_N; |
| 813 | *reg = (src[2] - '0'); |
| 814 | return 3; |
| 815 | } |
| 816 | } |
| 817 | if (l0 == 'f' && l1 == 'p' && TOLOWER (src[2]) == 'u' |
| 818 | && TOLOWER (src[3]) == 'l' |
| 819 | && ! IDENT_CHAR ((unsigned char) src[4])) |
| 820 | { |
| 821 | *mode = FPUL_N; |
| 822 | return 4; |
| 823 | } |
| 824 | |
| 825 | if (l0 == 'f' && l1 == 'p' && TOLOWER (src[2]) == 's' |
| 826 | && TOLOWER (src[3]) == 'c' |
| 827 | && TOLOWER (src[4]) == 'r' && ! IDENT_CHAR ((unsigned char) src[5])) |
| 828 | { |
| 829 | *mode = FPSCR_N; |
| 830 | return 5; |
| 831 | } |
| 832 | |
| 833 | if (l0 == 'x' && l1 == 'm' && TOLOWER (src[2]) == 't' |
| 834 | && TOLOWER (src[3]) == 'r' |
| 835 | && TOLOWER (src[4]) == 'x' && ! IDENT_CHAR ((unsigned char) src[5])) |
| 836 | { |
| 837 | *mode = XMTRX_M4; |
| 838 | return 5; |
| 839 | } |
| 840 | |
| 841 | return 0; |
| 842 | } |
| 843 | |
| 844 | static symbolS * |
| 845 | dot () |
| 846 | { |
| 847 | const char *fake; |
| 848 | |
| 849 | /* JF: '.' is pseudo symbol with value of current location |
| 850 | in current segment. */ |
| 851 | fake = FAKE_LABEL_NAME; |
| 852 | return symbol_new (fake, |
| 853 | now_seg, |
| 854 | (valueT) frag_now_fix (), |
| 855 | frag_now); |
| 856 | } |
| 857 | |
| 858 | static char * |
| 859 | parse_exp (s, op) |
| 860 | char *s; |
| 861 | sh_operand_info *op; |
| 862 | { |
| 863 | char *save; |
| 864 | char *new; |
| 865 | |
| 866 | save = input_line_pointer; |
| 867 | input_line_pointer = s; |
| 868 | expression (&op->immediate); |
| 869 | if (op->immediate.X_op == O_absent) |
| 870 | as_bad (_("missing operand")); |
| 871 | #ifdef OBJ_ELF |
| 872 | else if (op->immediate.X_op == O_PIC_reloc |
| 873 | || sh_PIC_related_p (op->immediate.X_add_symbol) |
| 874 | || sh_PIC_related_p (op->immediate.X_op_symbol)) |
| 875 | as_bad (_("misplaced PIC operand")); |
| 876 | #endif |
| 877 | new = input_line_pointer; |
| 878 | input_line_pointer = save; |
| 879 | return new; |
| 880 | } |
| 881 | |
| 882 | /* The many forms of operand: |
| 883 | |
| 884 | Rn Register direct |
| 885 | @Rn Register indirect |
| 886 | @Rn+ Autoincrement |
| 887 | @-Rn Autodecrement |
| 888 | @(disp:4,Rn) |
| 889 | @(disp:8,GBR) |
| 890 | @(disp:8,PC) |
| 891 | |
| 892 | @(R0,Rn) |
| 893 | @(R0,GBR) |
| 894 | |
| 895 | disp:8 |
| 896 | disp:12 |
| 897 | #imm8 |
| 898 | pr, gbr, vbr, macl, mach |
| 899 | */ |
| 900 | |
| 901 | static char * |
| 902 | parse_at (src, op) |
| 903 | char *src; |
| 904 | sh_operand_info *op; |
| 905 | { |
| 906 | int len; |
| 907 | int mode; |
| 908 | src++; |
| 909 | if (src[0] == '-') |
| 910 | { |
| 911 | /* Must be predecrement. */ |
| 912 | src++; |
| 913 | |
| 914 | len = parse_reg (src, &mode, &(op->reg)); |
| 915 | if (mode != A_REG_N) |
| 916 | as_bad (_("illegal register after @-")); |
| 917 | |
| 918 | op->type = A_DEC_N; |
| 919 | src += len; |
| 920 | } |
| 921 | else if (src[0] == '(') |
| 922 | { |
| 923 | /* Could be @(disp, rn), @(disp, gbr), @(disp, pc), @(r0, gbr) or |
| 924 | @(r0, rn). */ |
| 925 | src++; |
| 926 | len = parse_reg (src, &mode, &(op->reg)); |
| 927 | if (len && mode == A_REG_N) |
| 928 | { |
| 929 | src += len; |
| 930 | if (op->reg != 0) |
| 931 | { |
| 932 | as_bad (_("must be @(r0,...)")); |
| 933 | } |
| 934 | if (src[0] == ',') |
| 935 | { |
| 936 | src++; |
| 937 | /* Now can be rn or gbr. */ |
| 938 | len = parse_reg (src, &mode, &(op->reg)); |
| 939 | } |
| 940 | else |
| 941 | { |
| 942 | len = 0; |
| 943 | } |
| 944 | if (len) |
| 945 | { |
| 946 | if (mode == A_GBR) |
| 947 | { |
| 948 | op->type = A_R0_GBR; |
| 949 | } |
| 950 | else if (mode == A_REG_N) |
| 951 | { |
| 952 | op->type = A_IND_R0_REG_N; |
| 953 | } |
| 954 | else |
| 955 | { |
| 956 | as_bad (_("syntax error in @(r0,...)")); |
| 957 | } |
| 958 | } |
| 959 | else |
| 960 | { |
| 961 | as_bad (_("syntax error in @(r0...)")); |
| 962 | } |
| 963 | } |
| 964 | else |
| 965 | { |
| 966 | /* Must be an @(disp,.. thing). */ |
| 967 | src = parse_exp (src, op); |
| 968 | if (src[0] == ',') |
| 969 | src++; |
| 970 | /* Now can be rn, gbr or pc. */ |
| 971 | len = parse_reg (src, &mode, &op->reg); |
| 972 | if (len) |
| 973 | { |
| 974 | if (mode == A_REG_N) |
| 975 | { |
| 976 | op->type = A_DISP_REG_N; |
| 977 | } |
| 978 | else if (mode == A_GBR) |
| 979 | { |
| 980 | op->type = A_DISP_GBR; |
| 981 | } |
| 982 | else if (mode == A_PC) |
| 983 | { |
| 984 | op->type = A_DISP_PC_ABS; |
| 985 | /* Such operands don't get corrected for PC==.+4, so |
| 986 | make the correction here. */ |
| 987 | op->immediate.X_add_number -= 4; |
| 988 | } |
| 989 | else |
| 990 | { |
| 991 | as_bad (_("syntax error in @(disp,[Rn, gbr, pc])")); |
| 992 | } |
| 993 | } |
| 994 | else |
| 995 | { |
| 996 | as_bad (_("syntax error in @(disp,[Rn, gbr, pc])")); |
| 997 | } |
| 998 | } |
| 999 | src += len; |
| 1000 | if (src[0] != ')') |
| 1001 | as_bad (_("expecting )")); |
| 1002 | else |
| 1003 | src++; |
| 1004 | } |
| 1005 | else |
| 1006 | { |
| 1007 | src += parse_reg (src, &mode, &(op->reg)); |
| 1008 | if (mode != A_REG_N) |
| 1009 | as_bad (_("illegal register after @")); |
| 1010 | |
| 1011 | if (src[0] == '+') |
| 1012 | { |
| 1013 | char l0, l1; |
| 1014 | |
| 1015 | src++; |
| 1016 | l0 = TOLOWER (src[0]); |
| 1017 | l1 = TOLOWER (src[1]); |
| 1018 | |
| 1019 | if ((l0 == 'r' && l1 == '8') |
| 1020 | || (l0 == 'i' && (l1 == 'x' || l1 == 's'))) |
| 1021 | { |
| 1022 | src += 2; |
| 1023 | op->type = A_PMOD_N; |
| 1024 | } |
| 1025 | else if ( (l0 == 'r' && l1 == '9') |
| 1026 | || (l0 == 'i' && l1 == 'y')) |
| 1027 | { |
| 1028 | src += 2; |
| 1029 | op->type = A_PMODY_N; |
| 1030 | } |
| 1031 | else |
| 1032 | op->type = A_INC_N; |
| 1033 | } |
| 1034 | else |
| 1035 | op->type = A_IND_N; |
| 1036 | } |
| 1037 | return src; |
| 1038 | } |
| 1039 | |
| 1040 | static void |
| 1041 | get_operand (ptr, op) |
| 1042 | char **ptr; |
| 1043 | sh_operand_info *op; |
| 1044 | { |
| 1045 | char *src = *ptr; |
| 1046 | int mode = -1; |
| 1047 | unsigned int len; |
| 1048 | |
| 1049 | if (src[0] == '#') |
| 1050 | { |
| 1051 | src++; |
| 1052 | *ptr = parse_exp (src, op); |
| 1053 | op->type = A_IMM; |
| 1054 | return; |
| 1055 | } |
| 1056 | |
| 1057 | else if (src[0] == '@') |
| 1058 | { |
| 1059 | *ptr = parse_at (src, op); |
| 1060 | return; |
| 1061 | } |
| 1062 | len = parse_reg (src, &mode, &(op->reg)); |
| 1063 | if (len) |
| 1064 | { |
| 1065 | *ptr = src + len; |
| 1066 | op->type = mode; |
| 1067 | return; |
| 1068 | } |
| 1069 | else |
| 1070 | { |
| 1071 | /* Not a reg, the only thing left is a displacement. */ |
| 1072 | *ptr = parse_exp (src, op); |
| 1073 | op->type = A_DISP_PC; |
| 1074 | return; |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | static char * |
| 1079 | get_operands (info, args, operand) |
| 1080 | sh_opcode_info *info; |
| 1081 | char *args; |
| 1082 | sh_operand_info *operand; |
| 1083 | { |
| 1084 | char *ptr = args; |
| 1085 | if (info->arg[0]) |
| 1086 | { |
| 1087 | /* The pre-processor will eliminate whitespace in front of '@' |
| 1088 | after the first argument; we may be called multiple times |
| 1089 | from assemble_ppi, so don't insist on finding whitespace here. */ |
| 1090 | if (*ptr == ' ') |
| 1091 | ptr++; |
| 1092 | |
| 1093 | get_operand (&ptr, operand + 0); |
| 1094 | if (info->arg[1]) |
| 1095 | { |
| 1096 | if (*ptr == ',') |
| 1097 | { |
| 1098 | ptr++; |
| 1099 | } |
| 1100 | get_operand (&ptr, operand + 1); |
| 1101 | /* ??? Hack: psha/pshl have a varying operand number depending on |
| 1102 | the type of the first operand. We handle this by having the |
| 1103 | three-operand version first and reducing the number of operands |
| 1104 | parsed to two if we see that the first operand is an immediate. |
| 1105 | This works because no insn with three operands has an immediate |
| 1106 | as first operand. */ |
| 1107 | if (info->arg[2] && operand[0].type != A_IMM) |
| 1108 | { |
| 1109 | if (*ptr == ',') |
| 1110 | { |
| 1111 | ptr++; |
| 1112 | } |
| 1113 | get_operand (&ptr, operand + 2); |
| 1114 | } |
| 1115 | else |
| 1116 | { |
| 1117 | operand[2].type = 0; |
| 1118 | } |
| 1119 | } |
| 1120 | else |
| 1121 | { |
| 1122 | operand[1].type = 0; |
| 1123 | operand[2].type = 0; |
| 1124 | } |
| 1125 | } |
| 1126 | else |
| 1127 | { |
| 1128 | operand[0].type = 0; |
| 1129 | operand[1].type = 0; |
| 1130 | operand[2].type = 0; |
| 1131 | } |
| 1132 | return ptr; |
| 1133 | } |
| 1134 | |
| 1135 | /* Passed a pointer to a list of opcodes which use different |
| 1136 | addressing modes, return the opcode which matches the opcodes |
| 1137 | provided. */ |
| 1138 | |
| 1139 | static sh_opcode_info * |
| 1140 | get_specific (opcode, operands) |
| 1141 | sh_opcode_info *opcode; |
| 1142 | sh_operand_info *operands; |
| 1143 | { |
| 1144 | sh_opcode_info *this_try = opcode; |
| 1145 | char *name = opcode->name; |
| 1146 | int n = 0; |
| 1147 | |
| 1148 | while (opcode->name) |
| 1149 | { |
| 1150 | this_try = opcode++; |
| 1151 | if (this_try->name != name) |
| 1152 | { |
| 1153 | /* We've looked so far down the table that we've run out of |
| 1154 | opcodes with the same name. */ |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | /* Look at both operands needed by the opcodes and provided by |
| 1159 | the user - since an arg test will often fail on the same arg |
| 1160 | again and again, we'll try and test the last failing arg the |
| 1161 | first on each opcode try. */ |
| 1162 | for (n = 0; this_try->arg[n]; n++) |
| 1163 | { |
| 1164 | sh_operand_info *user = operands + n; |
| 1165 | sh_arg_type arg = this_try->arg[n]; |
| 1166 | |
| 1167 | switch (arg) |
| 1168 | { |
| 1169 | case A_DISP_PC: |
| 1170 | if (user->type == A_DISP_PC_ABS) |
| 1171 | break; |
| 1172 | /* Fall through. */ |
| 1173 | case A_IMM: |
| 1174 | case A_BDISP12: |
| 1175 | case A_BDISP8: |
| 1176 | case A_DISP_GBR: |
| 1177 | case A_MACH: |
| 1178 | case A_PR: |
| 1179 | case A_MACL: |
| 1180 | if (user->type != arg) |
| 1181 | goto fail; |
| 1182 | break; |
| 1183 | case A_R0: |
| 1184 | /* opcode needs r0 */ |
| 1185 | if (user->type != A_REG_N || user->reg != 0) |
| 1186 | goto fail; |
| 1187 | break; |
| 1188 | case A_R0_GBR: |
| 1189 | if (user->type != A_R0_GBR || user->reg != 0) |
| 1190 | goto fail; |
| 1191 | break; |
| 1192 | case F_FR0: |
| 1193 | if (user->type != F_REG_N || user->reg != 0) |
| 1194 | goto fail; |
| 1195 | break; |
| 1196 | |
| 1197 | case A_REG_N: |
| 1198 | case A_INC_N: |
| 1199 | case A_DEC_N: |
| 1200 | case A_IND_N: |
| 1201 | case A_IND_R0_REG_N: |
| 1202 | case A_DISP_REG_N: |
| 1203 | case F_REG_N: |
| 1204 | case D_REG_N: |
| 1205 | case X_REG_N: |
| 1206 | case V_REG_N: |
| 1207 | case FPUL_N: |
| 1208 | case FPSCR_N: |
| 1209 | case A_PMOD_N: |
| 1210 | case A_PMODY_N: |
| 1211 | case DSP_REG_N: |
| 1212 | /* Opcode needs rn */ |
| 1213 | if (user->type != arg) |
| 1214 | goto fail; |
| 1215 | reg_n = user->reg; |
| 1216 | break; |
| 1217 | case DX_REG_N: |
| 1218 | if (user->type != D_REG_N && user->type != X_REG_N) |
| 1219 | goto fail; |
| 1220 | reg_n = user->reg; |
| 1221 | break; |
| 1222 | case A_GBR: |
| 1223 | case A_SR: |
| 1224 | case A_VBR: |
| 1225 | case A_DSR: |
| 1226 | case A_MOD: |
| 1227 | case A_RE: |
| 1228 | case A_RS: |
| 1229 | case A_SSR: |
| 1230 | case A_SPC: |
| 1231 | case A_SGR: |
| 1232 | case A_DBR: |
| 1233 | if (user->type != arg) |
| 1234 | goto fail; |
| 1235 | break; |
| 1236 | |
| 1237 | case A_REG_B: |
| 1238 | if (user->type != arg) |
| 1239 | goto fail; |
| 1240 | reg_b = user->reg; |
| 1241 | break; |
| 1242 | |
| 1243 | case A_REG_M: |
| 1244 | case A_INC_M: |
| 1245 | case A_DEC_M: |
| 1246 | case A_IND_M: |
| 1247 | case A_IND_R0_REG_M: |
| 1248 | case A_DISP_REG_M: |
| 1249 | case DSP_REG_M: |
| 1250 | /* Opcode needs rn */ |
| 1251 | if (user->type != arg - A_REG_M + A_REG_N) |
| 1252 | goto fail; |
| 1253 | reg_m = user->reg; |
| 1254 | break; |
| 1255 | |
| 1256 | case DSP_REG_X: |
| 1257 | if (user->type != DSP_REG_N) |
| 1258 | goto fail; |
| 1259 | switch (user->reg) |
| 1260 | { |
| 1261 | case A_X0_NUM: |
| 1262 | reg_x = 0; |
| 1263 | break; |
| 1264 | case A_X1_NUM: |
| 1265 | reg_x = 1; |
| 1266 | break; |
| 1267 | case A_A0_NUM: |
| 1268 | reg_x = 2; |
| 1269 | break; |
| 1270 | case A_A1_NUM: |
| 1271 | reg_x = 3; |
| 1272 | break; |
| 1273 | default: |
| 1274 | goto fail; |
| 1275 | } |
| 1276 | break; |
| 1277 | |
| 1278 | case DSP_REG_Y: |
| 1279 | if (user->type != DSP_REG_N) |
| 1280 | goto fail; |
| 1281 | switch (user->reg) |
| 1282 | { |
| 1283 | case A_Y0_NUM: |
| 1284 | reg_y = 0; |
| 1285 | break; |
| 1286 | case A_Y1_NUM: |
| 1287 | reg_y = 1; |
| 1288 | break; |
| 1289 | case A_M0_NUM: |
| 1290 | reg_y = 2; |
| 1291 | break; |
| 1292 | case A_M1_NUM: |
| 1293 | reg_y = 3; |
| 1294 | break; |
| 1295 | default: |
| 1296 | goto fail; |
| 1297 | } |
| 1298 | break; |
| 1299 | |
| 1300 | case DSP_REG_E: |
| 1301 | if (user->type != DSP_REG_N) |
| 1302 | goto fail; |
| 1303 | switch (user->reg) |
| 1304 | { |
| 1305 | case A_X0_NUM: |
| 1306 | reg_efg = 0 << 10; |
| 1307 | break; |
| 1308 | case A_X1_NUM: |
| 1309 | reg_efg = 1 << 10; |
| 1310 | break; |
| 1311 | case A_Y0_NUM: |
| 1312 | reg_efg = 2 << 10; |
| 1313 | break; |
| 1314 | case A_A1_NUM: |
| 1315 | reg_efg = 3 << 10; |
| 1316 | break; |
| 1317 | default: |
| 1318 | goto fail; |
| 1319 | } |
| 1320 | break; |
| 1321 | |
| 1322 | case DSP_REG_F: |
| 1323 | if (user->type != DSP_REG_N) |
| 1324 | goto fail; |
| 1325 | switch (user->reg) |
| 1326 | { |
| 1327 | case A_Y0_NUM: |
| 1328 | reg_efg |= 0 << 8; |
| 1329 | break; |
| 1330 | case A_Y1_NUM: |
| 1331 | reg_efg |= 1 << 8; |
| 1332 | break; |
| 1333 | case A_X0_NUM: |
| 1334 | reg_efg |= 2 << 8; |
| 1335 | break; |
| 1336 | case A_A1_NUM: |
| 1337 | reg_efg |= 3 << 8; |
| 1338 | break; |
| 1339 | default: |
| 1340 | goto fail; |
| 1341 | } |
| 1342 | break; |
| 1343 | |
| 1344 | case DSP_REG_G: |
| 1345 | if (user->type != DSP_REG_N) |
| 1346 | goto fail; |
| 1347 | switch (user->reg) |
| 1348 | { |
| 1349 | case A_M0_NUM: |
| 1350 | reg_efg |= 0 << 2; |
| 1351 | break; |
| 1352 | case A_M1_NUM: |
| 1353 | reg_efg |= 1 << 2; |
| 1354 | break; |
| 1355 | case A_A0_NUM: |
| 1356 | reg_efg |= 2 << 2; |
| 1357 | break; |
| 1358 | case A_A1_NUM: |
| 1359 | reg_efg |= 3 << 2; |
| 1360 | break; |
| 1361 | default: |
| 1362 | goto fail; |
| 1363 | } |
| 1364 | break; |
| 1365 | |
| 1366 | case A_A0: |
| 1367 | if (user->type != DSP_REG_N || user->reg != A_A0_NUM) |
| 1368 | goto fail; |
| 1369 | break; |
| 1370 | case A_X0: |
| 1371 | if (user->type != DSP_REG_N || user->reg != A_X0_NUM) |
| 1372 | goto fail; |
| 1373 | break; |
| 1374 | case A_X1: |
| 1375 | if (user->type != DSP_REG_N || user->reg != A_X1_NUM) |
| 1376 | goto fail; |
| 1377 | break; |
| 1378 | case A_Y0: |
| 1379 | if (user->type != DSP_REG_N || user->reg != A_Y0_NUM) |
| 1380 | goto fail; |
| 1381 | break; |
| 1382 | case A_Y1: |
| 1383 | if (user->type != DSP_REG_N || user->reg != A_Y1_NUM) |
| 1384 | goto fail; |
| 1385 | break; |
| 1386 | |
| 1387 | case F_REG_M: |
| 1388 | case D_REG_M: |
| 1389 | case X_REG_M: |
| 1390 | case V_REG_M: |
| 1391 | case FPUL_M: |
| 1392 | case FPSCR_M: |
| 1393 | /* Opcode needs rn */ |
| 1394 | if (user->type != arg - F_REG_M + F_REG_N) |
| 1395 | goto fail; |
| 1396 | reg_m = user->reg; |
| 1397 | break; |
| 1398 | case DX_REG_M: |
| 1399 | if (user->type != D_REG_N && user->type != X_REG_N) |
| 1400 | goto fail; |
| 1401 | reg_m = user->reg; |
| 1402 | break; |
| 1403 | case XMTRX_M4: |
| 1404 | if (user->type != XMTRX_M4) |
| 1405 | goto fail; |
| 1406 | reg_m = 4; |
| 1407 | break; |
| 1408 | |
| 1409 | default: |
| 1410 | printf (_("unhandled %d\n"), arg); |
| 1411 | goto fail; |
| 1412 | } |
| 1413 | } |
| 1414 | if ( !(valid_arch & this_try->arch)) |
| 1415 | goto fail; |
| 1416 | valid_arch &= this_try->arch; |
| 1417 | return this_try; |
| 1418 | fail: |
| 1419 | ; |
| 1420 | } |
| 1421 | |
| 1422 | return 0; |
| 1423 | } |
| 1424 | |
| 1425 | static void |
| 1426 | insert (where, how, pcrel, op) |
| 1427 | char *where; |
| 1428 | int how; |
| 1429 | int pcrel; |
| 1430 | sh_operand_info *op; |
| 1431 | { |
| 1432 | fix_new_exp (frag_now, |
| 1433 | where - frag_now->fr_literal, |
| 1434 | 2, |
| 1435 | &op->immediate, |
| 1436 | pcrel, |
| 1437 | how); |
| 1438 | } |
| 1439 | |
| 1440 | static void |
| 1441 | build_relax (opcode, op) |
| 1442 | sh_opcode_info *opcode; |
| 1443 | sh_operand_info *op; |
| 1444 | { |
| 1445 | int high_byte = target_big_endian ? 0 : 1; |
| 1446 | char *p; |
| 1447 | |
| 1448 | if (opcode->arg[0] == A_BDISP8) |
| 1449 | { |
| 1450 | int what = (opcode->nibbles[1] & 4) ? COND_JUMP_DELAY : COND_JUMP; |
| 1451 | p = frag_var (rs_machine_dependent, |
| 1452 | md_relax_table[C (what, COND32)].rlx_length, |
| 1453 | md_relax_table[C (what, COND8)].rlx_length, |
| 1454 | C (what, 0), |
| 1455 | op->immediate.X_add_symbol, |
| 1456 | op->immediate.X_add_number, |
| 1457 | 0); |
| 1458 | p[high_byte] = (opcode->nibbles[0] << 4) | (opcode->nibbles[1]); |
| 1459 | } |
| 1460 | else if (opcode->arg[0] == A_BDISP12) |
| 1461 | { |
| 1462 | p = frag_var (rs_machine_dependent, |
| 1463 | md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length, |
| 1464 | md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length, |
| 1465 | C (UNCOND_JUMP, 0), |
| 1466 | op->immediate.X_add_symbol, |
| 1467 | op->immediate.X_add_number, |
| 1468 | 0); |
| 1469 | p[high_byte] = (opcode->nibbles[0] << 4); |
| 1470 | } |
| 1471 | |
| 1472 | } |
| 1473 | |
| 1474 | /* Insert ldrs & ldre with fancy relocations that relaxation can recognize. */ |
| 1475 | |
| 1476 | static char * |
| 1477 | insert_loop_bounds (output, operand) |
| 1478 | char *output; |
| 1479 | sh_operand_info *operand; |
| 1480 | { |
| 1481 | char *name; |
| 1482 | symbolS *end_sym; |
| 1483 | |
| 1484 | /* Since the low byte of the opcode will be overwritten by the reloc, we |
| 1485 | can just stash the high byte into both bytes and ignore endianness. */ |
| 1486 | output[0] = 0x8c; |
| 1487 | output[1] = 0x8c; |
| 1488 | insert (output, BFD_RELOC_SH_LOOP_START, 1, operand); |
| 1489 | insert (output, BFD_RELOC_SH_LOOP_END, 1, operand + 1); |
| 1490 | |
| 1491 | if (sh_relax) |
| 1492 | { |
| 1493 | static int count = 0; |
| 1494 | |
| 1495 | /* If the last loop insn is a two-byte-insn, it is in danger of being |
| 1496 | swapped with the insn after it. To prevent this, create a new |
| 1497 | symbol - complete with SH_LABEL reloc - after the last loop insn. |
| 1498 | If the last loop insn is four bytes long, the symbol will be |
| 1499 | right in the middle, but four byte insns are not swapped anyways. */ |
| 1500 | /* A REPEAT takes 6 bytes. The SH has a 32 bit address space. |
| 1501 | Hence a 9 digit number should be enough to count all REPEATs. */ |
| 1502 | name = alloca (11); |
| 1503 | sprintf (name, "_R%x", count++ & 0x3fffffff); |
| 1504 | end_sym = symbol_new (name, undefined_section, 0, &zero_address_frag); |
| 1505 | /* Make this a local symbol. */ |
| 1506 | #ifdef OBJ_COFF |
| 1507 | SF_SET_LOCAL (end_sym); |
| 1508 | #endif /* OBJ_COFF */ |
| 1509 | symbol_table_insert (end_sym); |
| 1510 | end_sym->sy_value = operand[1].immediate; |
| 1511 | end_sym->sy_value.X_add_number += 2; |
| 1512 | fix_new (frag_now, frag_now_fix (), 2, end_sym, 0, 1, BFD_RELOC_SH_LABEL); |
| 1513 | } |
| 1514 | |
| 1515 | output = frag_more (2); |
| 1516 | output[0] = 0x8e; |
| 1517 | output[1] = 0x8e; |
| 1518 | insert (output, BFD_RELOC_SH_LOOP_START, 1, operand); |
| 1519 | insert (output, BFD_RELOC_SH_LOOP_END, 1, operand + 1); |
| 1520 | |
| 1521 | return frag_more (2); |
| 1522 | } |
| 1523 | |
| 1524 | /* Now we know what sort of opcodes it is, let's build the bytes. */ |
| 1525 | |
| 1526 | static unsigned int |
| 1527 | build_Mytes (opcode, operand) |
| 1528 | sh_opcode_info *opcode; |
| 1529 | sh_operand_info *operand; |
| 1530 | { |
| 1531 | int index; |
| 1532 | char nbuf[4]; |
| 1533 | char *output = frag_more (2); |
| 1534 | unsigned int size = 2; |
| 1535 | int low_byte = target_big_endian ? 1 : 0; |
| 1536 | nbuf[0] = 0; |
| 1537 | nbuf[1] = 0; |
| 1538 | nbuf[2] = 0; |
| 1539 | nbuf[3] = 0; |
| 1540 | |
| 1541 | for (index = 0; index < 4; index++) |
| 1542 | { |
| 1543 | sh_nibble_type i = opcode->nibbles[index]; |
| 1544 | if (i < 16) |
| 1545 | { |
| 1546 | nbuf[index] = i; |
| 1547 | } |
| 1548 | else |
| 1549 | { |
| 1550 | switch (i) |
| 1551 | { |
| 1552 | case REG_N: |
| 1553 | nbuf[index] = reg_n; |
| 1554 | break; |
| 1555 | case REG_M: |
| 1556 | nbuf[index] = reg_m; |
| 1557 | break; |
| 1558 | case SDT_REG_N: |
| 1559 | if (reg_n < 2 || reg_n > 5) |
| 1560 | as_bad (_("Invalid register: 'r%d'"), reg_n); |
| 1561 | nbuf[index] = (reg_n & 3) | 4; |
| 1562 | break; |
| 1563 | case REG_NM: |
| 1564 | nbuf[index] = reg_n | (reg_m >> 2); |
| 1565 | break; |
| 1566 | case REG_B: |
| 1567 | nbuf[index] = reg_b | 0x08; |
| 1568 | break; |
| 1569 | case IMM0_4BY4: |
| 1570 | insert (output + low_byte, BFD_RELOC_SH_IMM4BY4, 0, operand); |
| 1571 | break; |
| 1572 | case IMM0_4BY2: |
| 1573 | insert (output + low_byte, BFD_RELOC_SH_IMM4BY2, 0, operand); |
| 1574 | break; |
| 1575 | case IMM0_4: |
| 1576 | insert (output + low_byte, BFD_RELOC_SH_IMM4, 0, operand); |
| 1577 | break; |
| 1578 | case IMM1_4BY4: |
| 1579 | insert (output + low_byte, BFD_RELOC_SH_IMM4BY4, 0, operand + 1); |
| 1580 | break; |
| 1581 | case IMM1_4BY2: |
| 1582 | insert (output + low_byte, BFD_RELOC_SH_IMM4BY2, 0, operand + 1); |
| 1583 | break; |
| 1584 | case IMM1_4: |
| 1585 | insert (output + low_byte, BFD_RELOC_SH_IMM4, 0, operand + 1); |
| 1586 | break; |
| 1587 | case IMM0_8BY4: |
| 1588 | insert (output + low_byte, BFD_RELOC_SH_IMM8BY4, 0, operand); |
| 1589 | break; |
| 1590 | case IMM0_8BY2: |
| 1591 | insert (output + low_byte, BFD_RELOC_SH_IMM8BY2, 0, operand); |
| 1592 | break; |
| 1593 | case IMM0_8: |
| 1594 | insert (output + low_byte, BFD_RELOC_SH_IMM8, 0, operand); |
| 1595 | break; |
| 1596 | case IMM1_8BY4: |
| 1597 | insert (output + low_byte, BFD_RELOC_SH_IMM8BY4, 0, operand + 1); |
| 1598 | break; |
| 1599 | case IMM1_8BY2: |
| 1600 | insert (output + low_byte, BFD_RELOC_SH_IMM8BY2, 0, operand + 1); |
| 1601 | break; |
| 1602 | case IMM1_8: |
| 1603 | insert (output + low_byte, BFD_RELOC_SH_IMM8, 0, operand + 1); |
| 1604 | break; |
| 1605 | case PCRELIMM_8BY4: |
| 1606 | insert (output, BFD_RELOC_SH_PCRELIMM8BY4, |
| 1607 | operand->type != A_DISP_PC_ABS, operand); |
| 1608 | break; |
| 1609 | case PCRELIMM_8BY2: |
| 1610 | insert (output, BFD_RELOC_SH_PCRELIMM8BY2, |
| 1611 | operand->type != A_DISP_PC_ABS, operand); |
| 1612 | break; |
| 1613 | case REPEAT: |
| 1614 | output = insert_loop_bounds (output, operand); |
| 1615 | nbuf[index] = opcode->nibbles[3]; |
| 1616 | operand += 2; |
| 1617 | break; |
| 1618 | default: |
| 1619 | printf (_("failed for %d\n"), i); |
| 1620 | } |
| 1621 | } |
| 1622 | } |
| 1623 | if (!target_big_endian) |
| 1624 | { |
| 1625 | output[1] = (nbuf[0] << 4) | (nbuf[1]); |
| 1626 | output[0] = (nbuf[2] << 4) | (nbuf[3]); |
| 1627 | } |
| 1628 | else |
| 1629 | { |
| 1630 | output[0] = (nbuf[0] << 4) | (nbuf[1]); |
| 1631 | output[1] = (nbuf[2] << 4) | (nbuf[3]); |
| 1632 | } |
| 1633 | return size; |
| 1634 | } |
| 1635 | |
| 1636 | /* Find an opcode at the start of *STR_P in the hash table, and set |
| 1637 | *STR_P to the first character after the last one read. */ |
| 1638 | |
| 1639 | static sh_opcode_info * |
| 1640 | find_cooked_opcode (str_p) |
| 1641 | char **str_p; |
| 1642 | { |
| 1643 | char *str = *str_p; |
| 1644 | unsigned char *op_start; |
| 1645 | unsigned char *op_end; |
| 1646 | char name[20]; |
| 1647 | int nlen = 0; |
| 1648 | |
| 1649 | /* Drop leading whitespace. */ |
| 1650 | while (*str == ' ') |
| 1651 | str++; |
| 1652 | |
| 1653 | /* Find the op code end. |
| 1654 | The pre-processor will eliminate whitespace in front of |
| 1655 | any '@' after the first argument; we may be called from |
| 1656 | assemble_ppi, so the opcode might be terminated by an '@'. */ |
| 1657 | for (op_start = op_end = (unsigned char *) (str); |
| 1658 | *op_end |
| 1659 | && nlen < 20 |
| 1660 | && !is_end_of_line[*op_end] && *op_end != ' ' && *op_end != '@'; |
| 1661 | op_end++) |
| 1662 | { |
| 1663 | unsigned char c = op_start[nlen]; |
| 1664 | |
| 1665 | /* The machine independent code will convert CMP/EQ into cmp/EQ |
| 1666 | because it thinks the '/' is the end of the symbol. Moreover, |
| 1667 | all but the first sub-insn is a parallel processing insn won't |
| 1668 | be capitalized. Instead of hacking up the machine independent |
| 1669 | code, we just deal with it here. */ |
| 1670 | c = TOLOWER (c); |
| 1671 | name[nlen] = c; |
| 1672 | nlen++; |
| 1673 | } |
| 1674 | |
| 1675 | name[nlen] = 0; |
| 1676 | *str_p = op_end; |
| 1677 | |
| 1678 | if (nlen == 0) |
| 1679 | as_bad (_("can't find opcode ")); |
| 1680 | |
| 1681 | return (sh_opcode_info *) hash_find (opcode_hash_control, name); |
| 1682 | } |
| 1683 | |
| 1684 | /* Assemble a parallel processing insn. */ |
| 1685 | #define DDT_BASE 0xf000 /* Base value for double data transfer insns */ |
| 1686 | |
| 1687 | static unsigned int |
| 1688 | assemble_ppi (op_end, opcode) |
| 1689 | char *op_end; |
| 1690 | sh_opcode_info *opcode; |
| 1691 | { |
| 1692 | int movx = 0; |
| 1693 | int movy = 0; |
| 1694 | int cond = 0; |
| 1695 | int field_b = 0; |
| 1696 | char *output; |
| 1697 | int move_code; |
| 1698 | unsigned int size; |
| 1699 | |
| 1700 | /* Some insn ignore one or more register fields, e.g. psts machl,a0. |
| 1701 | Make sure we encode a defined insn pattern. */ |
| 1702 | reg_x = 0; |
| 1703 | reg_y = 0; |
| 1704 | |
| 1705 | for (;;) |
| 1706 | { |
| 1707 | sh_operand_info operand[3]; |
| 1708 | |
| 1709 | if (opcode->arg[0] != A_END) |
| 1710 | op_end = get_operands (opcode, op_end, operand); |
| 1711 | opcode = get_specific (opcode, operand); |
| 1712 | if (opcode == 0) |
| 1713 | { |
| 1714 | /* Couldn't find an opcode which matched the operands. */ |
| 1715 | char *where = frag_more (2); |
| 1716 | size = 2; |
| 1717 | |
| 1718 | where[0] = 0x0; |
| 1719 | where[1] = 0x0; |
| 1720 | as_bad (_("invalid operands for opcode")); |
| 1721 | return size; |
| 1722 | } |
| 1723 | |
| 1724 | if (opcode->nibbles[0] != PPI) |
| 1725 | as_bad (_("insn can't be combined with parallel processing insn")); |
| 1726 | |
| 1727 | switch (opcode->nibbles[1]) |
| 1728 | { |
| 1729 | |
| 1730 | case NOPX: |
| 1731 | if (movx) |
| 1732 | as_bad (_("multiple movx specifications")); |
| 1733 | movx = DDT_BASE; |
| 1734 | break; |
| 1735 | case NOPY: |
| 1736 | if (movy) |
| 1737 | as_bad (_("multiple movy specifications")); |
| 1738 | movy = DDT_BASE; |
| 1739 | break; |
| 1740 | |
| 1741 | case MOVX: |
| 1742 | if (movx) |
| 1743 | as_bad (_("multiple movx specifications")); |
| 1744 | if (reg_n < 4 || reg_n > 5) |
| 1745 | as_bad (_("invalid movx address register")); |
| 1746 | if (opcode->nibbles[2] & 8) |
| 1747 | { |
| 1748 | if (reg_m == A_A1_NUM) |
| 1749 | movx = 1 << 7; |
| 1750 | else if (reg_m != A_A0_NUM) |
| 1751 | as_bad (_("invalid movx dsp register")); |
| 1752 | } |
| 1753 | else |
| 1754 | { |
| 1755 | if (reg_x > 1) |
| 1756 | as_bad (_("invalid movx dsp register")); |
| 1757 | movx = reg_x << 7; |
| 1758 | } |
| 1759 | movx += ((reg_n - 4) << 9) + (opcode->nibbles[2] << 2) + DDT_BASE; |
| 1760 | break; |
| 1761 | |
| 1762 | case MOVY: |
| 1763 | if (movy) |
| 1764 | as_bad (_("multiple movy specifications")); |
| 1765 | if (opcode->nibbles[2] & 8) |
| 1766 | { |
| 1767 | /* Bit 3 in nibbles[2] is intended for bit 4 of the opcode, |
| 1768 | so add 8 more. */ |
| 1769 | movy = 8; |
| 1770 | if (reg_m == A_A1_NUM) |
| 1771 | movy += 1 << 6; |
| 1772 | else if (reg_m != A_A0_NUM) |
| 1773 | as_bad (_("invalid movy dsp register")); |
| 1774 | } |
| 1775 | else |
| 1776 | { |
| 1777 | if (reg_y > 1) |
| 1778 | as_bad (_("invalid movy dsp register")); |
| 1779 | movy = reg_y << 6; |
| 1780 | } |
| 1781 | if (reg_n < 6 || reg_n > 7) |
| 1782 | as_bad (_("invalid movy address register")); |
| 1783 | movy += ((reg_n - 6) << 8) + opcode->nibbles[2] + DDT_BASE; |
| 1784 | break; |
| 1785 | |
| 1786 | case PSH: |
| 1787 | if (operand[0].immediate.X_op != O_constant) |
| 1788 | as_bad (_("dsp immediate shift value not constant")); |
| 1789 | field_b = ((opcode->nibbles[2] << 12) |
| 1790 | | (operand[0].immediate.X_add_number & 127) << 4 |
| 1791 | | reg_n); |
| 1792 | break; |
| 1793 | case PPI3: |
| 1794 | if (field_b) |
| 1795 | as_bad (_("multiple parallel processing specifications")); |
| 1796 | field_b = ((opcode->nibbles[2] << 12) + (opcode->nibbles[3] << 8) |
| 1797 | + (reg_x << 6) + (reg_y << 4) + reg_n); |
| 1798 | break; |
| 1799 | case PDC: |
| 1800 | if (cond) |
| 1801 | as_bad (_("multiple condition specifications")); |
| 1802 | cond = opcode->nibbles[2] << 8; |
| 1803 | if (*op_end) |
| 1804 | goto skip_cond_check; |
| 1805 | break; |
| 1806 | case PPIC: |
| 1807 | if (field_b) |
| 1808 | as_bad (_("multiple parallel processing specifications")); |
| 1809 | field_b = ((opcode->nibbles[2] << 12) + (opcode->nibbles[3] << 8) |
| 1810 | + cond + (reg_x << 6) + (reg_y << 4) + reg_n); |
| 1811 | cond = 0; |
| 1812 | break; |
| 1813 | case PMUL: |
| 1814 | if (field_b) |
| 1815 | { |
| 1816 | if ((field_b & 0xef00) != 0xa100) |
| 1817 | as_bad (_("insn cannot be combined with pmuls")); |
| 1818 | field_b -= 0x8100; |
| 1819 | switch (field_b & 0xf) |
| 1820 | { |
| 1821 | case A_X0_NUM: |
| 1822 | field_b += 0 - A_X0_NUM; |
| 1823 | break; |
| 1824 | case A_Y0_NUM: |
| 1825 | field_b += 1 - A_Y0_NUM; |
| 1826 | break; |
| 1827 | case A_A0_NUM: |
| 1828 | field_b += 2 - A_A0_NUM; |
| 1829 | break; |
| 1830 | case A_A1_NUM: |
| 1831 | field_b += 3 - A_A1_NUM; |
| 1832 | break; |
| 1833 | default: |
| 1834 | as_bad (_("bad padd / psub pmuls output operand")); |
| 1835 | } |
| 1836 | } |
| 1837 | field_b += 0x4000 + reg_efg; |
| 1838 | break; |
| 1839 | default: |
| 1840 | abort (); |
| 1841 | } |
| 1842 | if (cond) |
| 1843 | { |
| 1844 | as_bad (_("condition not followed by conditionalizable insn")); |
| 1845 | cond = 0; |
| 1846 | } |
| 1847 | if (! *op_end) |
| 1848 | break; |
| 1849 | skip_cond_check: |
| 1850 | opcode = find_cooked_opcode (&op_end); |
| 1851 | if (opcode == NULL) |
| 1852 | { |
| 1853 | (as_bad |
| 1854 | (_("unrecognized characters at end of parallel processing insn"))); |
| 1855 | break; |
| 1856 | } |
| 1857 | } |
| 1858 | |
| 1859 | move_code = movx | movy; |
| 1860 | if (field_b) |
| 1861 | { |
| 1862 | /* Parallel processing insn. */ |
| 1863 | unsigned long ppi_code = (movx | movy | 0xf800) << 16 | field_b; |
| 1864 | |
| 1865 | output = frag_more (4); |
| 1866 | size = 4; |
| 1867 | if (! target_big_endian) |
| 1868 | { |
| 1869 | output[3] = ppi_code >> 8; |
| 1870 | output[2] = ppi_code; |
| 1871 | } |
| 1872 | else |
| 1873 | { |
| 1874 | output[2] = ppi_code >> 8; |
| 1875 | output[3] = ppi_code; |
| 1876 | } |
| 1877 | move_code |= 0xf800; |
| 1878 | } |
| 1879 | else |
| 1880 | { |
| 1881 | /* Just a double data transfer. */ |
| 1882 | output = frag_more (2); |
| 1883 | size = 2; |
| 1884 | } |
| 1885 | if (! target_big_endian) |
| 1886 | { |
| 1887 | output[1] = move_code >> 8; |
| 1888 | output[0] = move_code; |
| 1889 | } |
| 1890 | else |
| 1891 | { |
| 1892 | output[0] = move_code >> 8; |
| 1893 | output[1] = move_code; |
| 1894 | } |
| 1895 | return size; |
| 1896 | } |
| 1897 | |
| 1898 | /* This is the guts of the machine-dependent assembler. STR points to a |
| 1899 | machine dependent instruction. This function is supposed to emit |
| 1900 | the frags/bytes it assembles to. */ |
| 1901 | |
| 1902 | void |
| 1903 | md_assemble (str) |
| 1904 | char *str; |
| 1905 | { |
| 1906 | unsigned char *op_end; |
| 1907 | sh_operand_info operand[3]; |
| 1908 | sh_opcode_info *opcode; |
| 1909 | unsigned int size = 0; |
| 1910 | |
| 1911 | opcode = find_cooked_opcode (&str); |
| 1912 | op_end = str; |
| 1913 | |
| 1914 | if (opcode == NULL) |
| 1915 | { |
| 1916 | as_bad (_("unknown opcode")); |
| 1917 | return; |
| 1918 | } |
| 1919 | |
| 1920 | if (sh_relax |
| 1921 | && ! seg_info (now_seg)->tc_segment_info_data.in_code) |
| 1922 | { |
| 1923 | /* Output a CODE reloc to tell the linker that the following |
| 1924 | bytes are instructions, not data. */ |
| 1925 | fix_new (frag_now, frag_now_fix (), 2, &abs_symbol, 0, 0, |
| 1926 | BFD_RELOC_SH_CODE); |
| 1927 | seg_info (now_seg)->tc_segment_info_data.in_code = 1; |
| 1928 | } |
| 1929 | |
| 1930 | if (opcode->nibbles[0] == PPI) |
| 1931 | { |
| 1932 | size = assemble_ppi (op_end, opcode); |
| 1933 | } |
| 1934 | else |
| 1935 | { |
| 1936 | if (opcode->arg[0] == A_BDISP12 |
| 1937 | || opcode->arg[0] == A_BDISP8) |
| 1938 | { |
| 1939 | parse_exp (op_end + 1, &operand[0]); |
| 1940 | build_relax (opcode, &operand[0]); |
| 1941 | } |
| 1942 | else |
| 1943 | { |
| 1944 | if (opcode->arg[0] == A_END) |
| 1945 | { |
| 1946 | /* Ignore trailing whitespace. If there is any, it has already |
| 1947 | been compressed to a single space. */ |
| 1948 | if (*op_end == ' ') |
| 1949 | op_end++; |
| 1950 | } |
| 1951 | else |
| 1952 | { |
| 1953 | op_end = get_operands (opcode, op_end, operand); |
| 1954 | } |
| 1955 | opcode = get_specific (opcode, operand); |
| 1956 | |
| 1957 | if (opcode == 0) |
| 1958 | { |
| 1959 | /* Couldn't find an opcode which matched the operands. */ |
| 1960 | char *where = frag_more (2); |
| 1961 | size = 2; |
| 1962 | |
| 1963 | where[0] = 0x0; |
| 1964 | where[1] = 0x0; |
| 1965 | as_bad (_("invalid operands for opcode")); |
| 1966 | } |
| 1967 | else |
| 1968 | { |
| 1969 | if (*op_end) |
| 1970 | as_bad (_("excess operands: '%s'"), op_end); |
| 1971 | |
| 1972 | size = build_Mytes (opcode, operand); |
| 1973 | } |
| 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | #ifdef BFD_ASSEMBLER |
| 1978 | dwarf2_emit_insn (size); |
| 1979 | #endif |
| 1980 | } |
| 1981 | |
| 1982 | /* This routine is called each time a label definition is seen. It |
| 1983 | emits a BFD_RELOC_SH_LABEL reloc if necessary. */ |
| 1984 | |
| 1985 | void |
| 1986 | sh_frob_label () |
| 1987 | { |
| 1988 | static fragS *last_label_frag; |
| 1989 | static int last_label_offset; |
| 1990 | |
| 1991 | if (sh_relax |
| 1992 | && seg_info (now_seg)->tc_segment_info_data.in_code) |
| 1993 | { |
| 1994 | int offset; |
| 1995 | |
| 1996 | offset = frag_now_fix (); |
| 1997 | if (frag_now != last_label_frag |
| 1998 | || offset != last_label_offset) |
| 1999 | { |
| 2000 | fix_new (frag_now, offset, 2, &abs_symbol, 0, 0, BFD_RELOC_SH_LABEL); |
| 2001 | last_label_frag = frag_now; |
| 2002 | last_label_offset = offset; |
| 2003 | } |
| 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | /* This routine is called when the assembler is about to output some |
| 2008 | data. It emits a BFD_RELOC_SH_DATA reloc if necessary. */ |
| 2009 | |
| 2010 | void |
| 2011 | sh_flush_pending_output () |
| 2012 | { |
| 2013 | if (sh_relax |
| 2014 | && seg_info (now_seg)->tc_segment_info_data.in_code) |
| 2015 | { |
| 2016 | fix_new (frag_now, frag_now_fix (), 2, &abs_symbol, 0, 0, |
| 2017 | BFD_RELOC_SH_DATA); |
| 2018 | seg_info (now_seg)->tc_segment_info_data.in_code = 0; |
| 2019 | } |
| 2020 | } |
| 2021 | |
| 2022 | symbolS * |
| 2023 | md_undefined_symbol (name) |
| 2024 | char *name ATTRIBUTE_UNUSED; |
| 2025 | { |
| 2026 | return 0; |
| 2027 | } |
| 2028 | |
| 2029 | #ifdef OBJ_COFF |
| 2030 | #ifndef BFD_ASSEMBLER |
| 2031 | |
| 2032 | void |
| 2033 | tc_crawl_symbol_chain (headers) |
| 2034 | object_headers *headers; |
| 2035 | { |
| 2036 | printf (_("call to tc_crawl_symbol_chain \n")); |
| 2037 | } |
| 2038 | |
| 2039 | void |
| 2040 | tc_headers_hook (headers) |
| 2041 | object_headers *headers; |
| 2042 | { |
| 2043 | printf (_("call to tc_headers_hook \n")); |
| 2044 | } |
| 2045 | |
| 2046 | #endif |
| 2047 | #endif |
| 2048 | |
| 2049 | /* Various routines to kill one day. */ |
| 2050 | /* Equal to MAX_PRECISION in atof-ieee.c. */ |
| 2051 | #define MAX_LITTLENUMS 6 |
| 2052 | |
| 2053 | /* Turn a string in input_line_pointer into a floating point constant |
| 2054 | of type TYPE, and store the appropriate bytes in *LITP. The number |
| 2055 | of LITTLENUMS emitted is stored in *SIZEP . An error message is |
| 2056 | returned, or NULL on OK. */ |
| 2057 | |
| 2058 | char * |
| 2059 | md_atof (type, litP, sizeP) |
| 2060 | int type; |
| 2061 | char *litP; |
| 2062 | int *sizeP; |
| 2063 | { |
| 2064 | int prec; |
| 2065 | LITTLENUM_TYPE words[4]; |
| 2066 | char *t; |
| 2067 | int i; |
| 2068 | |
| 2069 | switch (type) |
| 2070 | { |
| 2071 | case 'f': |
| 2072 | prec = 2; |
| 2073 | break; |
| 2074 | |
| 2075 | case 'd': |
| 2076 | prec = 4; |
| 2077 | break; |
| 2078 | |
| 2079 | default: |
| 2080 | *sizeP = 0; |
| 2081 | return _("bad call to md_atof"); |
| 2082 | } |
| 2083 | |
| 2084 | t = atof_ieee (input_line_pointer, type, words); |
| 2085 | if (t) |
| 2086 | input_line_pointer = t; |
| 2087 | |
| 2088 | *sizeP = prec * 2; |
| 2089 | |
| 2090 | if (! target_big_endian) |
| 2091 | { |
| 2092 | for (i = prec - 1; i >= 0; i--) |
| 2093 | { |
| 2094 | md_number_to_chars (litP, (valueT) words[i], 2); |
| 2095 | litP += 2; |
| 2096 | } |
| 2097 | } |
| 2098 | else |
| 2099 | { |
| 2100 | for (i = 0; i < prec; i++) |
| 2101 | { |
| 2102 | md_number_to_chars (litP, (valueT) words[i], 2); |
| 2103 | litP += 2; |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | return NULL; |
| 2108 | } |
| 2109 | |
| 2110 | /* Handle the .uses pseudo-op. This pseudo-op is used just before a |
| 2111 | call instruction. It refers to a label of the instruction which |
| 2112 | loads the register which the call uses. We use it to generate a |
| 2113 | special reloc for the linker. */ |
| 2114 | |
| 2115 | static void |
| 2116 | s_uses (ignore) |
| 2117 | int ignore ATTRIBUTE_UNUSED; |
| 2118 | { |
| 2119 | expressionS ex; |
| 2120 | |
| 2121 | if (! sh_relax) |
| 2122 | as_warn (_(".uses pseudo-op seen when not relaxing")); |
| 2123 | |
| 2124 | expression (&ex); |
| 2125 | |
| 2126 | if (ex.X_op != O_symbol || ex.X_add_number != 0) |
| 2127 | { |
| 2128 | as_bad (_("bad .uses format")); |
| 2129 | ignore_rest_of_line (); |
| 2130 | return; |
| 2131 | } |
| 2132 | |
| 2133 | fix_new_exp (frag_now, frag_now_fix (), 2, &ex, 1, BFD_RELOC_SH_USES); |
| 2134 | |
| 2135 | demand_empty_rest_of_line (); |
| 2136 | } |
| 2137 | \f |
| 2138 | CONST char *md_shortopts = ""; |
| 2139 | struct option md_longopts[] = |
| 2140 | { |
| 2141 | #define OPTION_RELAX (OPTION_MD_BASE) |
| 2142 | #define OPTION_BIG (OPTION_MD_BASE + 1) |
| 2143 | #define OPTION_LITTLE (OPTION_BIG + 1) |
| 2144 | #define OPTION_SMALL (OPTION_LITTLE + 1) |
| 2145 | #define OPTION_DSP (OPTION_SMALL + 1) |
| 2146 | |
| 2147 | {"relax", no_argument, NULL, OPTION_RELAX}, |
| 2148 | {"big", no_argument, NULL, OPTION_BIG}, |
| 2149 | {"little", no_argument, NULL, OPTION_LITTLE}, |
| 2150 | {"small", no_argument, NULL, OPTION_SMALL}, |
| 2151 | {"dsp", no_argument, NULL, OPTION_DSP}, |
| 2152 | {NULL, no_argument, NULL, 0} |
| 2153 | }; |
| 2154 | size_t md_longopts_size = sizeof (md_longopts); |
| 2155 | |
| 2156 | int |
| 2157 | md_parse_option (c, arg) |
| 2158 | int c; |
| 2159 | char *arg ATTRIBUTE_UNUSED; |
| 2160 | { |
| 2161 | switch (c) |
| 2162 | { |
| 2163 | case OPTION_RELAX: |
| 2164 | sh_relax = 1; |
| 2165 | break; |
| 2166 | |
| 2167 | case OPTION_BIG: |
| 2168 | target_big_endian = 1; |
| 2169 | break; |
| 2170 | |
| 2171 | case OPTION_LITTLE: |
| 2172 | target_big_endian = 0; |
| 2173 | break; |
| 2174 | |
| 2175 | case OPTION_SMALL: |
| 2176 | sh_small = 1; |
| 2177 | break; |
| 2178 | |
| 2179 | case OPTION_DSP: |
| 2180 | sh_dsp = 1; |
| 2181 | break; |
| 2182 | |
| 2183 | default: |
| 2184 | return 0; |
| 2185 | } |
| 2186 | |
| 2187 | return 1; |
| 2188 | } |
| 2189 | |
| 2190 | void |
| 2191 | md_show_usage (stream) |
| 2192 | FILE *stream; |
| 2193 | { |
| 2194 | fprintf (stream, _("\ |
| 2195 | SH options:\n\ |
| 2196 | -little generate little endian code\n\ |
| 2197 | -big generate big endian code\n\ |
| 2198 | -relax alter jump instructions for long displacements\n\ |
| 2199 | -small align sections to 4 byte boundaries, not 16\n\ |
| 2200 | -dsp enable sh-dsp insns, and disable sh3e / sh4 insns.\n")); |
| 2201 | } |
| 2202 | \f |
| 2203 | /* This struct is used to pass arguments to sh_count_relocs through |
| 2204 | bfd_map_over_sections. */ |
| 2205 | |
| 2206 | struct sh_count_relocs |
| 2207 | { |
| 2208 | /* Symbol we are looking for. */ |
| 2209 | symbolS *sym; |
| 2210 | /* Count of relocs found. */ |
| 2211 | int count; |
| 2212 | }; |
| 2213 | |
| 2214 | /* Count the number of fixups in a section which refer to a particular |
| 2215 | symbol. When using BFD_ASSEMBLER, this is called via |
| 2216 | bfd_map_over_sections. */ |
| 2217 | |
| 2218 | static void |
| 2219 | sh_count_relocs (abfd, sec, data) |
| 2220 | bfd *abfd ATTRIBUTE_UNUSED; |
| 2221 | segT sec; |
| 2222 | PTR data; |
| 2223 | { |
| 2224 | struct sh_count_relocs *info = (struct sh_count_relocs *) data; |
| 2225 | segment_info_type *seginfo; |
| 2226 | symbolS *sym; |
| 2227 | fixS *fix; |
| 2228 | |
| 2229 | seginfo = seg_info (sec); |
| 2230 | if (seginfo == NULL) |
| 2231 | return; |
| 2232 | |
| 2233 | sym = info->sym; |
| 2234 | for (fix = seginfo->fix_root; fix != NULL; fix = fix->fx_next) |
| 2235 | { |
| 2236 | if (fix->fx_addsy == sym) |
| 2237 | { |
| 2238 | ++info->count; |
| 2239 | fix->fx_tcbit = 1; |
| 2240 | } |
| 2241 | } |
| 2242 | } |
| 2243 | |
| 2244 | /* Handle the count relocs for a particular section. When using |
| 2245 | BFD_ASSEMBLER, this is called via bfd_map_over_sections. */ |
| 2246 | |
| 2247 | static void |
| 2248 | sh_frob_section (abfd, sec, ignore) |
| 2249 | bfd *abfd ATTRIBUTE_UNUSED; |
| 2250 | segT sec; |
| 2251 | PTR ignore ATTRIBUTE_UNUSED; |
| 2252 | { |
| 2253 | segment_info_type *seginfo; |
| 2254 | fixS *fix; |
| 2255 | |
| 2256 | seginfo = seg_info (sec); |
| 2257 | if (seginfo == NULL) |
| 2258 | return; |
| 2259 | |
| 2260 | for (fix = seginfo->fix_root; fix != NULL; fix = fix->fx_next) |
| 2261 | { |
| 2262 | symbolS *sym; |
| 2263 | bfd_vma val; |
| 2264 | fixS *fscan; |
| 2265 | struct sh_count_relocs info; |
| 2266 | |
| 2267 | if (fix->fx_r_type != BFD_RELOC_SH_USES) |
| 2268 | continue; |
| 2269 | |
| 2270 | /* The BFD_RELOC_SH_USES reloc should refer to a defined local |
| 2271 | symbol in the same section. */ |
| 2272 | sym = fix->fx_addsy; |
| 2273 | if (sym == NULL |
| 2274 | || fix->fx_subsy != NULL |
| 2275 | || fix->fx_addnumber != 0 |
| 2276 | || S_GET_SEGMENT (sym) != sec |
| 2277 | #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF) |
| 2278 | || S_GET_STORAGE_CLASS (sym) == C_EXT |
| 2279 | #endif |
| 2280 | || S_IS_EXTERNAL (sym)) |
| 2281 | { |
| 2282 | as_warn_where (fix->fx_file, fix->fx_line, |
| 2283 | _(".uses does not refer to a local symbol in the same section")); |
| 2284 | continue; |
| 2285 | } |
| 2286 | |
| 2287 | /* Look through the fixups again, this time looking for one |
| 2288 | at the same location as sym. */ |
| 2289 | val = S_GET_VALUE (sym); |
| 2290 | for (fscan = seginfo->fix_root; |
| 2291 | fscan != NULL; |
| 2292 | fscan = fscan->fx_next) |
| 2293 | if (val == fscan->fx_frag->fr_address + fscan->fx_where |
| 2294 | && fscan->fx_r_type != BFD_RELOC_SH_ALIGN |
| 2295 | && fscan->fx_r_type != BFD_RELOC_SH_CODE |
| 2296 | && fscan->fx_r_type != BFD_RELOC_SH_DATA |
| 2297 | && fscan->fx_r_type != BFD_RELOC_SH_LABEL) |
| 2298 | break; |
| 2299 | if (fscan == NULL) |
| 2300 | { |
| 2301 | as_warn_where (fix->fx_file, fix->fx_line, |
| 2302 | _("can't find fixup pointed to by .uses")); |
| 2303 | continue; |
| 2304 | } |
| 2305 | |
| 2306 | if (fscan->fx_tcbit) |
| 2307 | { |
| 2308 | /* We've already done this one. */ |
| 2309 | continue; |
| 2310 | } |
| 2311 | |
| 2312 | /* The variable fscan should also be a fixup to a local symbol |
| 2313 | in the same section. */ |
| 2314 | sym = fscan->fx_addsy; |
| 2315 | if (sym == NULL |
| 2316 | || fscan->fx_subsy != NULL |
| 2317 | || fscan->fx_addnumber != 0 |
| 2318 | || S_GET_SEGMENT (sym) != sec |
| 2319 | #if ! defined (BFD_ASSEMBLER) && defined (OBJ_COFF) |
| 2320 | || S_GET_STORAGE_CLASS (sym) == C_EXT |
| 2321 | #endif |
| 2322 | || S_IS_EXTERNAL (sym)) |
| 2323 | { |
| 2324 | as_warn_where (fix->fx_file, fix->fx_line, |
| 2325 | _(".uses target does not refer to a local symbol in the same section")); |
| 2326 | continue; |
| 2327 | } |
| 2328 | |
| 2329 | /* Now we look through all the fixups of all the sections, |
| 2330 | counting the number of times we find a reference to sym. */ |
| 2331 | info.sym = sym; |
| 2332 | info.count = 0; |
| 2333 | #ifdef BFD_ASSEMBLER |
| 2334 | bfd_map_over_sections (stdoutput, sh_count_relocs, (PTR) &info); |
| 2335 | #else |
| 2336 | { |
| 2337 | int iscan; |
| 2338 | |
| 2339 | for (iscan = SEG_E0; iscan < SEG_UNKNOWN; iscan++) |
| 2340 | sh_count_relocs ((bfd *) NULL, iscan, (PTR) &info); |
| 2341 | } |
| 2342 | #endif |
| 2343 | |
| 2344 | if (info.count < 1) |
| 2345 | abort (); |
| 2346 | |
| 2347 | /* Generate a BFD_RELOC_SH_COUNT fixup at the location of sym. |
| 2348 | We have already adjusted the value of sym to include the |
| 2349 | fragment address, so we undo that adjustment here. */ |
| 2350 | subseg_change (sec, 0); |
| 2351 | fix_new (fscan->fx_frag, |
| 2352 | S_GET_VALUE (sym) - fscan->fx_frag->fr_address, |
| 2353 | 4, &abs_symbol, info.count, 0, BFD_RELOC_SH_COUNT); |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | /* This function is called after the symbol table has been completed, |
| 2358 | but before the relocs or section contents have been written out. |
| 2359 | If we have seen any .uses pseudo-ops, they point to an instruction |
| 2360 | which loads a register with the address of a function. We look |
| 2361 | through the fixups to find where the function address is being |
| 2362 | loaded from. We then generate a COUNT reloc giving the number of |
| 2363 | times that function address is referred to. The linker uses this |
| 2364 | information when doing relaxing, to decide when it can eliminate |
| 2365 | the stored function address entirely. */ |
| 2366 | |
| 2367 | void |
| 2368 | sh_frob_file () |
| 2369 | { |
| 2370 | if (! sh_relax) |
| 2371 | return; |
| 2372 | |
| 2373 | #ifdef BFD_ASSEMBLER |
| 2374 | bfd_map_over_sections (stdoutput, sh_frob_section, (PTR) NULL); |
| 2375 | #else |
| 2376 | { |
| 2377 | int iseg; |
| 2378 | |
| 2379 | for (iseg = SEG_E0; iseg < SEG_UNKNOWN; iseg++) |
| 2380 | sh_frob_section ((bfd *) NULL, iseg, (PTR) NULL); |
| 2381 | } |
| 2382 | #endif |
| 2383 | } |
| 2384 | |
| 2385 | /* Called after relaxing. Set the correct sizes of the fragments, and |
| 2386 | create relocs so that md_apply_fix3 will fill in the correct values. */ |
| 2387 | |
| 2388 | void |
| 2389 | md_convert_frag (headers, seg, fragP) |
| 2390 | #ifdef BFD_ASSEMBLER |
| 2391 | bfd *headers ATTRIBUTE_UNUSED; |
| 2392 | #else |
| 2393 | object_headers *headers; |
| 2394 | #endif |
| 2395 | segT seg; |
| 2396 | fragS *fragP; |
| 2397 | { |
| 2398 | int donerelax = 0; |
| 2399 | |
| 2400 | switch (fragP->fr_subtype) |
| 2401 | { |
| 2402 | case C (COND_JUMP, COND8): |
| 2403 | case C (COND_JUMP_DELAY, COND8): |
| 2404 | subseg_change (seg, 0); |
| 2405 | fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset, |
| 2406 | 1, BFD_RELOC_SH_PCDISP8BY2); |
| 2407 | fragP->fr_fix += 2; |
| 2408 | fragP->fr_var = 0; |
| 2409 | break; |
| 2410 | |
| 2411 | case C (UNCOND_JUMP, UNCOND12): |
| 2412 | subseg_change (seg, 0); |
| 2413 | fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset, |
| 2414 | 1, BFD_RELOC_SH_PCDISP12BY2); |
| 2415 | fragP->fr_fix += 2; |
| 2416 | fragP->fr_var = 0; |
| 2417 | break; |
| 2418 | |
| 2419 | case C (UNCOND_JUMP, UNCOND32): |
| 2420 | case C (UNCOND_JUMP, UNDEF_WORD_DISP): |
| 2421 | if (fragP->fr_symbol == NULL) |
| 2422 | as_bad_where (fragP->fr_file, fragP->fr_line, |
| 2423 | _("displacement overflows 12-bit field")); |
| 2424 | else if (S_IS_DEFINED (fragP->fr_symbol)) |
| 2425 | as_bad_where (fragP->fr_file, fragP->fr_line, |
| 2426 | _("displacement to defined symbol %s overflows 12-bit field"), |
| 2427 | S_GET_NAME (fragP->fr_symbol)); |
| 2428 | else |
| 2429 | as_bad_where (fragP->fr_file, fragP->fr_line, |
| 2430 | _("displacement to undefined symbol %s overflows 12-bit field"), |
| 2431 | S_GET_NAME (fragP->fr_symbol)); |
| 2432 | /* Stabilize this frag, so we don't trip an assert. */ |
| 2433 | fragP->fr_fix += fragP->fr_var; |
| 2434 | fragP->fr_var = 0; |
| 2435 | break; |
| 2436 | |
| 2437 | case C (COND_JUMP, COND12): |
| 2438 | case C (COND_JUMP_DELAY, COND12): |
| 2439 | /* A bcond won't fit, so turn it into a b!cond; bra disp; nop. */ |
| 2440 | /* I found that a relax failure for gcc.c-torture/execute/930628-1.c |
| 2441 | was due to gas incorrectly relaxing an out-of-range conditional |
| 2442 | branch with delay slot. It turned: |
| 2443 | bf.s L6 (slot mov.l r12,@(44,r0)) |
| 2444 | into: |
| 2445 | |
| 2446 | 2c: 8f 01 a0 8b bf.s 32 <_main+32> (slot bra L6) |
| 2447 | 30: 00 09 nop |
| 2448 | 32: 10 cb mov.l r12,@(44,r0) |
| 2449 | Therefore, branches with delay slots have to be handled |
| 2450 | differently from ones without delay slots. */ |
| 2451 | { |
| 2452 | unsigned char *buffer = |
| 2453 | (unsigned char *) (fragP->fr_fix + fragP->fr_literal); |
| 2454 | int highbyte = target_big_endian ? 0 : 1; |
| 2455 | int lowbyte = target_big_endian ? 1 : 0; |
| 2456 | int delay = fragP->fr_subtype == C (COND_JUMP_DELAY, COND12); |
| 2457 | |
| 2458 | /* Toggle the true/false bit of the bcond. */ |
| 2459 | buffer[highbyte] ^= 0x2; |
| 2460 | |
| 2461 | /* If this is a delayed branch, we may not put the bra in the |
| 2462 | slot. So we change it to a non-delayed branch, like that: |
| 2463 | b! cond slot_label; bra disp; slot_label: slot_insn |
| 2464 | ??? We should try if swapping the conditional branch and |
| 2465 | its delay-slot insn already makes the branch reach. */ |
| 2466 | |
| 2467 | /* Build a relocation to six / four bytes farther on. */ |
| 2468 | subseg_change (seg, 0); |
| 2469 | fix_new (fragP, fragP->fr_fix, 2, |
| 2470 | #ifdef BFD_ASSEMBLER |
| 2471 | section_symbol (seg), |
| 2472 | #else |
| 2473 | seg_info (seg)->dot, |
| 2474 | #endif |
| 2475 | fragP->fr_address + fragP->fr_fix + (delay ? 4 : 6), |
| 2476 | 1, BFD_RELOC_SH_PCDISP8BY2); |
| 2477 | |
| 2478 | /* Set up a jump instruction. */ |
| 2479 | buffer[highbyte + 2] = 0xa0; |
| 2480 | buffer[lowbyte + 2] = 0; |
| 2481 | fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol, |
| 2482 | fragP->fr_offset, 1, BFD_RELOC_SH_PCDISP12BY2); |
| 2483 | |
| 2484 | if (delay) |
| 2485 | { |
| 2486 | buffer[highbyte] &= ~0x4; /* Removes delay slot from branch. */ |
| 2487 | fragP->fr_fix += 4; |
| 2488 | } |
| 2489 | else |
| 2490 | { |
| 2491 | /* Fill in a NOP instruction. */ |
| 2492 | buffer[highbyte + 4] = 0x0; |
| 2493 | buffer[lowbyte + 4] = 0x9; |
| 2494 | |
| 2495 | fragP->fr_fix += 6; |
| 2496 | } |
| 2497 | fragP->fr_var = 0; |
| 2498 | donerelax = 1; |
| 2499 | } |
| 2500 | break; |
| 2501 | |
| 2502 | case C (COND_JUMP, COND32): |
| 2503 | case C (COND_JUMP_DELAY, COND32): |
| 2504 | case C (COND_JUMP, UNDEF_WORD_DISP): |
| 2505 | case C (COND_JUMP_DELAY, UNDEF_WORD_DISP): |
| 2506 | if (fragP->fr_symbol == NULL) |
| 2507 | as_bad_where (fragP->fr_file, fragP->fr_line, |
| 2508 | _("displacement overflows 8-bit field")); |
| 2509 | else if (S_IS_DEFINED (fragP->fr_symbol)) |
| 2510 | as_bad_where (fragP->fr_file, fragP->fr_line, |
| 2511 | _("displacement to defined symbol %s overflows 8-bit field"), |
| 2512 | S_GET_NAME (fragP->fr_symbol)); |
| 2513 | else |
| 2514 | as_bad_where (fragP->fr_file, fragP->fr_line, |
| 2515 | _("displacement to undefined symbol %s overflows 8-bit field "), |
| 2516 | S_GET_NAME (fragP->fr_symbol)); |
| 2517 | /* Stabilize this frag, so we don't trip an assert. */ |
| 2518 | fragP->fr_fix += fragP->fr_var; |
| 2519 | fragP->fr_var = 0; |
| 2520 | break; |
| 2521 | |
| 2522 | default: |
| 2523 | abort (); |
| 2524 | } |
| 2525 | |
| 2526 | if (donerelax && !sh_relax) |
| 2527 | as_warn_where (fragP->fr_file, fragP->fr_line, |
| 2528 | _("overflow in branch to %s; converted into longer instruction sequence"), |
| 2529 | (fragP->fr_symbol != NULL |
| 2530 | ? S_GET_NAME (fragP->fr_symbol) |
| 2531 | : "")); |
| 2532 | } |
| 2533 | |
| 2534 | valueT |
| 2535 | md_section_align (seg, size) |
| 2536 | segT seg ATTRIBUTE_UNUSED; |
| 2537 | valueT size; |
| 2538 | { |
| 2539 | #ifdef BFD_ASSEMBLER |
| 2540 | #ifdef OBJ_ELF |
| 2541 | return size; |
| 2542 | #else /* ! OBJ_ELF */ |
| 2543 | return ((size + (1 << bfd_get_section_alignment (stdoutput, seg)) - 1) |
| 2544 | & (-1 << bfd_get_section_alignment (stdoutput, seg))); |
| 2545 | #endif /* ! OBJ_ELF */ |
| 2546 | #else /* ! BFD_ASSEMBLER */ |
| 2547 | return ((size + (1 << section_alignment[(int) seg]) - 1) |
| 2548 | & (-1 << section_alignment[(int) seg])); |
| 2549 | #endif /* ! BFD_ASSEMBLER */ |
| 2550 | } |
| 2551 | |
| 2552 | /* This static variable is set by s_uacons to tell sh_cons_align that |
| 2553 | the expession does not need to be aligned. */ |
| 2554 | |
| 2555 | static int sh_no_align_cons = 0; |
| 2556 | |
| 2557 | /* This handles the unaligned space allocation pseudo-ops, such as |
| 2558 | .uaword. .uaword is just like .word, but the value does not need |
| 2559 | to be aligned. */ |
| 2560 | |
| 2561 | static void |
| 2562 | s_uacons (bytes) |
| 2563 | int bytes; |
| 2564 | { |
| 2565 | /* Tell sh_cons_align not to align this value. */ |
| 2566 | sh_no_align_cons = 1; |
| 2567 | cons (bytes); |
| 2568 | } |
| 2569 | |
| 2570 | /* If a .word, et. al., pseud-op is seen, warn if the value is not |
| 2571 | aligned correctly. Note that this can cause warnings to be issued |
| 2572 | when assembling initialized structured which were declared with the |
| 2573 | packed attribute. FIXME: Perhaps we should require an option to |
| 2574 | enable this warning? */ |
| 2575 | |
| 2576 | void |
| 2577 | sh_cons_align (nbytes) |
| 2578 | int nbytes; |
| 2579 | { |
| 2580 | int nalign; |
| 2581 | char *p; |
| 2582 | |
| 2583 | if (sh_no_align_cons) |
| 2584 | { |
| 2585 | /* This is an unaligned pseudo-op. */ |
| 2586 | sh_no_align_cons = 0; |
| 2587 | return; |
| 2588 | } |
| 2589 | |
| 2590 | nalign = 0; |
| 2591 | while ((nbytes & 1) == 0) |
| 2592 | { |
| 2593 | ++nalign; |
| 2594 | nbytes >>= 1; |
| 2595 | } |
| 2596 | |
| 2597 | if (nalign == 0) |
| 2598 | return; |
| 2599 | |
| 2600 | if (now_seg == absolute_section) |
| 2601 | { |
| 2602 | if ((abs_section_offset & ((1 << nalign) - 1)) != 0) |
| 2603 | as_warn (_("misaligned data")); |
| 2604 | return; |
| 2605 | } |
| 2606 | |
| 2607 | p = frag_var (rs_align_test, 1, 1, (relax_substateT) 0, |
| 2608 | (symbolS *) NULL, (offsetT) nalign, (char *) NULL); |
| 2609 | |
| 2610 | record_alignment (now_seg, nalign); |
| 2611 | } |
| 2612 | |
| 2613 | /* When relaxing, we need to output a reloc for any .align directive |
| 2614 | that requests alignment to a four byte boundary or larger. This is |
| 2615 | also where we check for misaligned data. */ |
| 2616 | |
| 2617 | void |
| 2618 | sh_handle_align (frag) |
| 2619 | fragS *frag; |
| 2620 | { |
| 2621 | int bytes = frag->fr_next->fr_address - frag->fr_address - frag->fr_fix; |
| 2622 | |
| 2623 | if (frag->fr_type == rs_align_code) |
| 2624 | { |
| 2625 | static const unsigned char big_nop_pattern[] = { 0x00, 0x09 }; |
| 2626 | static const unsigned char little_nop_pattern[] = { 0x09, 0x00 }; |
| 2627 | |
| 2628 | char *p = frag->fr_literal + frag->fr_fix; |
| 2629 | |
| 2630 | if (bytes & 1) |
| 2631 | { |
| 2632 | *p++ = 0; |
| 2633 | bytes--; |
| 2634 | frag->fr_fix += 1; |
| 2635 | } |
| 2636 | |
| 2637 | if (target_big_endian) |
| 2638 | { |
| 2639 | memcpy (p, big_nop_pattern, sizeof big_nop_pattern); |
| 2640 | frag->fr_var = sizeof big_nop_pattern; |
| 2641 | } |
| 2642 | else |
| 2643 | { |
| 2644 | memcpy (p, little_nop_pattern, sizeof little_nop_pattern); |
| 2645 | frag->fr_var = sizeof little_nop_pattern; |
| 2646 | } |
| 2647 | } |
| 2648 | else if (frag->fr_type == rs_align_test) |
| 2649 | { |
| 2650 | if (bytes != 0) |
| 2651 | as_warn_where (frag->fr_file, frag->fr_line, _("misaligned data")); |
| 2652 | } |
| 2653 | |
| 2654 | if (sh_relax |
| 2655 | && (frag->fr_type == rs_align |
| 2656 | || frag->fr_type == rs_align_code) |
| 2657 | && frag->fr_address + frag->fr_fix > 0 |
| 2658 | && frag->fr_offset > 1 |
| 2659 | && now_seg != bss_section) |
| 2660 | fix_new (frag, frag->fr_fix, 2, &abs_symbol, frag->fr_offset, 0, |
| 2661 | BFD_RELOC_SH_ALIGN); |
| 2662 | } |
| 2663 | |
| 2664 | /* This macro decides whether a particular reloc is an entry in a |
| 2665 | switch table. It is used when relaxing, because the linker needs |
| 2666 | to know about all such entries so that it can adjust them if |
| 2667 | necessary. */ |
| 2668 | |
| 2669 | #ifdef BFD_ASSEMBLER |
| 2670 | #define SWITCH_TABLE_CONS(fix) (0) |
| 2671 | #else |
| 2672 | #define SWITCH_TABLE_CONS(fix) \ |
| 2673 | ((fix)->fx_r_type == 0 \ |
| 2674 | && ((fix)->fx_size == 2 \ |
| 2675 | || (fix)->fx_size == 1 \ |
| 2676 | || (fix)->fx_size == 4)) |
| 2677 | #endif |
| 2678 | |
| 2679 | #define SWITCH_TABLE(fix) \ |
| 2680 | ((fix)->fx_addsy != NULL \ |
| 2681 | && (fix)->fx_subsy != NULL \ |
| 2682 | && S_GET_SEGMENT ((fix)->fx_addsy) == text_section \ |
| 2683 | && S_GET_SEGMENT ((fix)->fx_subsy) == text_section \ |
| 2684 | && ((fix)->fx_r_type == BFD_RELOC_32 \ |
| 2685 | || (fix)->fx_r_type == BFD_RELOC_16 \ |
| 2686 | || (fix)->fx_r_type == BFD_RELOC_8 \ |
| 2687 | || SWITCH_TABLE_CONS (fix))) |
| 2688 | |
| 2689 | /* See whether we need to force a relocation into the output file. |
| 2690 | This is used to force out switch and PC relative relocations when |
| 2691 | relaxing. */ |
| 2692 | |
| 2693 | int |
| 2694 | sh_force_relocation (fix) |
| 2695 | fixS *fix; |
| 2696 | { |
| 2697 | |
| 2698 | if (fix->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
| 2699 | || fix->fx_r_type == BFD_RELOC_VTABLE_ENTRY |
| 2700 | || fix->fx_r_type == BFD_RELOC_SH_LOOP_START |
| 2701 | || fix->fx_r_type == BFD_RELOC_SH_LOOP_END) |
| 2702 | return 1; |
| 2703 | |
| 2704 | if (! sh_relax) |
| 2705 | return 0; |
| 2706 | |
| 2707 | return (fix->fx_pcrel |
| 2708 | || SWITCH_TABLE (fix) |
| 2709 | || fix->fx_r_type == BFD_RELOC_SH_COUNT |
| 2710 | || fix->fx_r_type == BFD_RELOC_SH_ALIGN |
| 2711 | || fix->fx_r_type == BFD_RELOC_SH_CODE |
| 2712 | || fix->fx_r_type == BFD_RELOC_SH_DATA |
| 2713 | || fix->fx_r_type == BFD_RELOC_SH_LABEL); |
| 2714 | } |
| 2715 | |
| 2716 | #ifdef OBJ_ELF |
| 2717 | boolean |
| 2718 | sh_fix_adjustable (fixP) |
| 2719 | fixS *fixP; |
| 2720 | { |
| 2721 | |
| 2722 | if (fixP->fx_addsy == NULL) |
| 2723 | return 1; |
| 2724 | |
| 2725 | if (fixP->fx_r_type == BFD_RELOC_SH_PCDISP8BY2 |
| 2726 | || fixP->fx_r_type == BFD_RELOC_SH_PCDISP12BY2 |
| 2727 | || fixP->fx_r_type == BFD_RELOC_SH_PCRELIMM8BY2 |
| 2728 | || fixP->fx_r_type == BFD_RELOC_SH_PCRELIMM8BY4 |
| 2729 | || fixP->fx_r_type == BFD_RELOC_8_PCREL |
| 2730 | || fixP->fx_r_type == BFD_RELOC_SH_SWITCH16 |
| 2731 | || fixP->fx_r_type == BFD_RELOC_SH_SWITCH32) |
| 2732 | return 1; |
| 2733 | |
| 2734 | if (! TC_RELOC_RTSYM_LOC_FIXUP (fixP) |
| 2735 | || fixP->fx_r_type == BFD_RELOC_RVA) |
| 2736 | return 0; |
| 2737 | |
| 2738 | /* We need the symbol name for the VTABLE entries */ |
| 2739 | if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
| 2740 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) |
| 2741 | return 0; |
| 2742 | |
| 2743 | return 1; |
| 2744 | } |
| 2745 | |
| 2746 | void |
| 2747 | sh_elf_final_processing () |
| 2748 | { |
| 2749 | int val; |
| 2750 | |
| 2751 | /* Set file-specific flags to indicate if this code needs |
| 2752 | a processor with the sh-dsp / sh3e ISA to execute. */ |
| 2753 | if (valid_arch & arch_sh1) |
| 2754 | val = EF_SH1; |
| 2755 | else if (valid_arch & arch_sh2) |
| 2756 | val = EF_SH2; |
| 2757 | else if (valid_arch & arch_sh_dsp) |
| 2758 | val = EF_SH_DSP; |
| 2759 | else if (valid_arch & arch_sh3) |
| 2760 | val = EF_SH3; |
| 2761 | else if (valid_arch & arch_sh3_dsp) |
| 2762 | val = EF_SH_DSP; |
| 2763 | else if (valid_arch & arch_sh3e) |
| 2764 | val = EF_SH3E; |
| 2765 | else if (valid_arch & arch_sh4) |
| 2766 | val = EF_SH4; |
| 2767 | else |
| 2768 | abort (); |
| 2769 | |
| 2770 | elf_elfheader (stdoutput)->e_flags &= ~EF_SH_MACH_MASK; |
| 2771 | elf_elfheader (stdoutput)->e_flags |= val; |
| 2772 | } |
| 2773 | #endif |
| 2774 | |
| 2775 | /* Apply a fixup to the object file. */ |
| 2776 | |
| 2777 | void |
| 2778 | md_apply_fix3 (fixP, valP, seg) |
| 2779 | fixS * fixP; |
| 2780 | valueT * valP; |
| 2781 | segT seg ATTRIBUTE_UNUSED; |
| 2782 | { |
| 2783 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; |
| 2784 | int lowbyte = target_big_endian ? 1 : 0; |
| 2785 | int highbyte = target_big_endian ? 0 : 1; |
| 2786 | long val = * (long *) valP; |
| 2787 | long max, min; |
| 2788 | int shift; |
| 2789 | |
| 2790 | #ifdef BFD_ASSEMBLER |
| 2791 | /* A difference between two symbols, the second of which is in the |
| 2792 | current section, is transformed in a PC-relative relocation to |
| 2793 | the other symbol. We have to adjust the relocation type here. */ |
| 2794 | if (fixP->fx_pcrel) |
| 2795 | { |
| 2796 | switch (fixP->fx_r_type) |
| 2797 | { |
| 2798 | default: |
| 2799 | break; |
| 2800 | |
| 2801 | case BFD_RELOC_32: |
| 2802 | fixP->fx_r_type = BFD_RELOC_32_PCREL; |
| 2803 | break; |
| 2804 | |
| 2805 | /* Currently, we only support 32-bit PCREL relocations. |
| 2806 | We'd need a new reloc type to handle 16_PCREL, and |
| 2807 | 8_PCREL is already taken for R_SH_SWITCH8, which |
| 2808 | apparently does something completely different than what |
| 2809 | we need. FIXME. */ |
| 2810 | case BFD_RELOC_16: |
| 2811 | bfd_set_error (bfd_error_bad_value); |
| 2812 | return; |
| 2813 | |
| 2814 | case BFD_RELOC_8: |
| 2815 | bfd_set_error (bfd_error_bad_value); |
| 2816 | return; |
| 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | /* The function adjust_reloc_syms won't convert a reloc against a weak |
| 2821 | symbol into a reloc against a section, but bfd_install_relocation |
| 2822 | will screw up if the symbol is defined, so we have to adjust val here |
| 2823 | to avoid the screw up later. |
| 2824 | |
| 2825 | For ordinary relocs, this does not happen for ELF, since for ELF, |
| 2826 | bfd_install_relocation uses the "special function" field of the |
| 2827 | howto, and does not execute the code that needs to be undone, as long |
| 2828 | as the special function does not return bfd_reloc_continue. |
| 2829 | It can happen for GOT- and PLT-type relocs the way they are |
| 2830 | described in elf32-sh.c as they use bfd_elf_generic_reloc, but it |
| 2831 | doesn't matter here since those relocs don't use VAL; see below. */ |
| 2832 | if (OUTPUT_FLAVOR != bfd_target_elf_flavour |
| 2833 | && fixP->fx_addsy != NULL |
| 2834 | && S_IS_WEAK (fixP->fx_addsy)) |
| 2835 | val -= S_GET_VALUE (fixP->fx_addsy); |
| 2836 | #endif |
| 2837 | |
| 2838 | #ifndef BFD_ASSEMBLER |
| 2839 | if (fixP->fx_r_type == 0) |
| 2840 | { |
| 2841 | if (fixP->fx_size == 2) |
| 2842 | fixP->fx_r_type = BFD_RELOC_16; |
| 2843 | else if (fixP->fx_size == 4) |
| 2844 | fixP->fx_r_type = BFD_RELOC_32; |
| 2845 | else if (fixP->fx_size == 1) |
| 2846 | fixP->fx_r_type = BFD_RELOC_8; |
| 2847 | else |
| 2848 | abort (); |
| 2849 | } |
| 2850 | #endif |
| 2851 | |
| 2852 | max = min = 0; |
| 2853 | shift = 0; |
| 2854 | switch (fixP->fx_r_type) |
| 2855 | { |
| 2856 | case BFD_RELOC_SH_IMM4: |
| 2857 | max = 0xf; |
| 2858 | *buf = (*buf & 0xf0) | (val & 0xf); |
| 2859 | break; |
| 2860 | |
| 2861 | case BFD_RELOC_SH_IMM4BY2: |
| 2862 | max = 0xf; |
| 2863 | shift = 1; |
| 2864 | *buf = (*buf & 0xf0) | ((val >> 1) & 0xf); |
| 2865 | break; |
| 2866 | |
| 2867 | case BFD_RELOC_SH_IMM4BY4: |
| 2868 | max = 0xf; |
| 2869 | shift = 2; |
| 2870 | *buf = (*buf & 0xf0) | ((val >> 2) & 0xf); |
| 2871 | break; |
| 2872 | |
| 2873 | case BFD_RELOC_SH_IMM8BY2: |
| 2874 | max = 0xff; |
| 2875 | shift = 1; |
| 2876 | *buf = val >> 1; |
| 2877 | break; |
| 2878 | |
| 2879 | case BFD_RELOC_SH_IMM8BY4: |
| 2880 | max = 0xff; |
| 2881 | shift = 2; |
| 2882 | *buf = val >> 2; |
| 2883 | break; |
| 2884 | |
| 2885 | case BFD_RELOC_8: |
| 2886 | case BFD_RELOC_SH_IMM8: |
| 2887 | /* Sometimes the 8 bit value is sign extended (e.g., add) and |
| 2888 | sometimes it is not (e.g., and). We permit any 8 bit value. |
| 2889 | Note that adding further restrictions may invalidate |
| 2890 | reasonable looking assembly code, such as ``and -0x1,r0''. */ |
| 2891 | max = 0xff; |
| 2892 | min = -0xff; |
| 2893 | *buf++ = val; |
| 2894 | break; |
| 2895 | |
| 2896 | case BFD_RELOC_SH_PCRELIMM8BY4: |
| 2897 | /* The lower two bits of the PC are cleared before the |
| 2898 | displacement is added in. We can assume that the destination |
| 2899 | is on a 4 byte bounday. If this instruction is also on a 4 |
| 2900 | byte boundary, then we want |
| 2901 | (target - here) / 4 |
| 2902 | and target - here is a multiple of 4. |
| 2903 | Otherwise, we are on a 2 byte boundary, and we want |
| 2904 | (target - (here - 2)) / 4 |
| 2905 | and target - here is not a multiple of 4. Computing |
| 2906 | (target - (here - 2)) / 4 == (target - here + 2) / 4 |
| 2907 | works for both cases, since in the first case the addition of |
| 2908 | 2 will be removed by the division. target - here is in the |
| 2909 | variable val. */ |
| 2910 | val = (val + 2) / 4; |
| 2911 | if (val & ~0xff) |
| 2912 | as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far")); |
| 2913 | buf[lowbyte] = val; |
| 2914 | break; |
| 2915 | |
| 2916 | case BFD_RELOC_SH_PCRELIMM8BY2: |
| 2917 | val /= 2; |
| 2918 | if (val & ~0xff) |
| 2919 | as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far")); |
| 2920 | buf[lowbyte] = val; |
| 2921 | break; |
| 2922 | |
| 2923 | case BFD_RELOC_SH_PCDISP8BY2: |
| 2924 | val /= 2; |
| 2925 | if (val < -0x80 || val > 0x7f) |
| 2926 | as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far")); |
| 2927 | buf[lowbyte] = val; |
| 2928 | break; |
| 2929 | |
| 2930 | case BFD_RELOC_SH_PCDISP12BY2: |
| 2931 | val /= 2; |
| 2932 | if (val < -0x800 || val > 0x7ff) |
| 2933 | as_bad_where (fixP->fx_file, fixP->fx_line, _("pcrel too far")); |
| 2934 | buf[lowbyte] = val & 0xff; |
| 2935 | buf[highbyte] |= (val >> 8) & 0xf; |
| 2936 | break; |
| 2937 | |
| 2938 | case BFD_RELOC_32: |
| 2939 | case BFD_RELOC_32_PCREL: |
| 2940 | md_number_to_chars (buf, val, 4); |
| 2941 | break; |
| 2942 | |
| 2943 | case BFD_RELOC_16: |
| 2944 | md_number_to_chars (buf, val, 2); |
| 2945 | break; |
| 2946 | |
| 2947 | case BFD_RELOC_SH_USES: |
| 2948 | /* Pass the value into sh_coff_reloc_mangle. */ |
| 2949 | fixP->fx_addnumber = val; |
| 2950 | break; |
| 2951 | |
| 2952 | case BFD_RELOC_SH_COUNT: |
| 2953 | case BFD_RELOC_SH_ALIGN: |
| 2954 | case BFD_RELOC_SH_CODE: |
| 2955 | case BFD_RELOC_SH_DATA: |
| 2956 | case BFD_RELOC_SH_LABEL: |
| 2957 | /* Nothing to do here. */ |
| 2958 | break; |
| 2959 | |
| 2960 | case BFD_RELOC_SH_LOOP_START: |
| 2961 | case BFD_RELOC_SH_LOOP_END: |
| 2962 | |
| 2963 | case BFD_RELOC_VTABLE_INHERIT: |
| 2964 | case BFD_RELOC_VTABLE_ENTRY: |
| 2965 | fixP->fx_done = 0; |
| 2966 | return; |
| 2967 | |
| 2968 | #ifdef OBJ_ELF |
| 2969 | case BFD_RELOC_32_PLT_PCREL: |
| 2970 | /* Make the jump instruction point to the address of the operand. At |
| 2971 | runtime we merely add the offset to the actual PLT entry. */ |
| 2972 | * valP = 0xfffffffc; |
| 2973 | val = fixP->fx_addnumber; |
| 2974 | if (fixP->fx_subsy) |
| 2975 | val -= S_GET_VALUE (fixP->fx_subsy); |
| 2976 | md_number_to_chars (buf, val, 4); |
| 2977 | break; |
| 2978 | |
| 2979 | case BFD_RELOC_SH_GOTPC: |
| 2980 | /* This is tough to explain. We end up with this one if we have |
| 2981 | operands that look like "_GLOBAL_OFFSET_TABLE_+[.-.L284]". |
| 2982 | The goal here is to obtain the absolute address of the GOT, |
| 2983 | and it is strongly preferable from a performance point of |
| 2984 | view to avoid using a runtime relocation for this. There are |
| 2985 | cases where you have something like: |
| 2986 | |
| 2987 | .long _GLOBAL_OFFSET_TABLE_+[.-.L66] |
| 2988 | |
| 2989 | and here no correction would be required. Internally in the |
| 2990 | assembler we treat operands of this form as not being pcrel |
| 2991 | since the '.' is explicitly mentioned, and I wonder whether |
| 2992 | it would simplify matters to do it this way. Who knows. In |
| 2993 | earlier versions of the PIC patches, the pcrel_adjust field |
| 2994 | was used to store the correction, but since the expression is |
| 2995 | not pcrel, I felt it would be confusing to do it this way. */ |
| 2996 | * valP -= 1; |
| 2997 | md_number_to_chars (buf, val, 4); |
| 2998 | break; |
| 2999 | |
| 3000 | case BFD_RELOC_32_GOT_PCREL: |
| 3001 | * valP = 0; /* Fully resolved at runtime. No addend. */ |
| 3002 | md_number_to_chars (buf, 0, 4); |
| 3003 | break; |
| 3004 | |
| 3005 | case BFD_RELOC_32_GOTOFF: |
| 3006 | md_number_to_chars (buf, val, 4); |
| 3007 | break; |
| 3008 | #endif |
| 3009 | |
| 3010 | default: |
| 3011 | abort (); |
| 3012 | } |
| 3013 | |
| 3014 | if (shift != 0) |
| 3015 | { |
| 3016 | if ((val & ((1 << shift) - 1)) != 0) |
| 3017 | as_bad_where (fixP->fx_file, fixP->fx_line, _("misaligned offset")); |
| 3018 | if (val >= 0) |
| 3019 | val >>= shift; |
| 3020 | else |
| 3021 | val = ((val >> shift) |
| 3022 | | ((long) -1 & ~ ((long) -1 >> shift))); |
| 3023 | } |
| 3024 | if (max != 0 && (val < min || val > max)) |
| 3025 | as_bad_where (fixP->fx_file, fixP->fx_line, _("offset out of range")); |
| 3026 | |
| 3027 | if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0) |
| 3028 | fixP->fx_done = 1; |
| 3029 | } |
| 3030 | |
| 3031 | /* Called just before address relaxation. Return the length |
| 3032 | by which a fragment must grow to reach it's destination. */ |
| 3033 | |
| 3034 | int |
| 3035 | md_estimate_size_before_relax (fragP, segment_type) |
| 3036 | register fragS *fragP; |
| 3037 | register segT segment_type; |
| 3038 | { |
| 3039 | int what; |
| 3040 | |
| 3041 | switch (fragP->fr_subtype) |
| 3042 | { |
| 3043 | default: |
| 3044 | abort (); |
| 3045 | |
| 3046 | case C (UNCOND_JUMP, UNDEF_DISP): |
| 3047 | /* Used to be a branch to somewhere which was unknown. */ |
| 3048 | if (!fragP->fr_symbol) |
| 3049 | { |
| 3050 | fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12); |
| 3051 | } |
| 3052 | else if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type) |
| 3053 | { |
| 3054 | fragP->fr_subtype = C (UNCOND_JUMP, UNCOND12); |
| 3055 | } |
| 3056 | else |
| 3057 | { |
| 3058 | fragP->fr_subtype = C (UNCOND_JUMP, UNDEF_WORD_DISP); |
| 3059 | } |
| 3060 | break; |
| 3061 | |
| 3062 | case C (COND_JUMP, UNDEF_DISP): |
| 3063 | case C (COND_JUMP_DELAY, UNDEF_DISP): |
| 3064 | what = GET_WHAT (fragP->fr_subtype); |
| 3065 | /* Used to be a branch to somewhere which was unknown. */ |
| 3066 | if (fragP->fr_symbol |
| 3067 | && S_GET_SEGMENT (fragP->fr_symbol) == segment_type) |
| 3068 | { |
| 3069 | /* Got a symbol and it's defined in this segment, become byte |
| 3070 | sized - maybe it will fix up. */ |
| 3071 | fragP->fr_subtype = C (what, COND8); |
| 3072 | } |
| 3073 | else if (fragP->fr_symbol) |
| 3074 | { |
| 3075 | /* Its got a segment, but its not ours, so it will always be long. */ |
| 3076 | fragP->fr_subtype = C (what, UNDEF_WORD_DISP); |
| 3077 | } |
| 3078 | else |
| 3079 | { |
| 3080 | /* We know the abs value. */ |
| 3081 | fragP->fr_subtype = C (what, COND8); |
| 3082 | } |
| 3083 | break; |
| 3084 | |
| 3085 | case C (UNCOND_JUMP, UNCOND12): |
| 3086 | case C (UNCOND_JUMP, UNCOND32): |
| 3087 | case C (UNCOND_JUMP, UNDEF_WORD_DISP): |
| 3088 | case C (COND_JUMP, COND8): |
| 3089 | case C (COND_JUMP, COND12): |
| 3090 | case C (COND_JUMP, COND32): |
| 3091 | case C (COND_JUMP, UNDEF_WORD_DISP): |
| 3092 | case C (COND_JUMP_DELAY, COND8): |
| 3093 | case C (COND_JUMP_DELAY, COND12): |
| 3094 | case C (COND_JUMP_DELAY, COND32): |
| 3095 | case C (COND_JUMP_DELAY, UNDEF_WORD_DISP): |
| 3096 | /* When relaxing a section for the second time, we don't need to |
| 3097 | do anything besides return the current size. */ |
| 3098 | break; |
| 3099 | } |
| 3100 | |
| 3101 | fragP->fr_var = md_relax_table[fragP->fr_subtype].rlx_length; |
| 3102 | return fragP->fr_var; |
| 3103 | } |
| 3104 | |
| 3105 | /* Put number into target byte order. */ |
| 3106 | |
| 3107 | void |
| 3108 | md_number_to_chars (ptr, use, nbytes) |
| 3109 | char *ptr; |
| 3110 | valueT use; |
| 3111 | int nbytes; |
| 3112 | { |
| 3113 | if (! target_big_endian) |
| 3114 | number_to_chars_littleendian (ptr, use, nbytes); |
| 3115 | else |
| 3116 | number_to_chars_bigendian (ptr, use, nbytes); |
| 3117 | } |
| 3118 | |
| 3119 | long |
| 3120 | md_pcrel_from_section (fixP, sec) |
| 3121 | fixS *fixP; |
| 3122 | segT sec; |
| 3123 | { |
| 3124 | if (fixP->fx_addsy != (symbolS *) NULL |
| 3125 | && (! S_IS_DEFINED (fixP->fx_addsy) |
| 3126 | || S_IS_EXTERN (fixP->fx_addsy) |
| 3127 | || S_IS_WEAK (fixP->fx_addsy) |
| 3128 | || S_GET_SEGMENT (fixP->fx_addsy) != sec)) |
| 3129 | { |
| 3130 | /* The symbol is undefined (or is defined but not in this section, |
| 3131 | or we're not sure about it being the final definition). Let the |
| 3132 | linker figure it out. We need to adjust the subtraction of a |
| 3133 | symbol to the position of the relocated data, though. */ |
| 3134 | return fixP->fx_subsy ? fixP->fx_where + fixP->fx_frag->fr_address : 0; |
| 3135 | } |
| 3136 | |
| 3137 | return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address + 2; |
| 3138 | } |
| 3139 | |
| 3140 | #ifdef OBJ_COFF |
| 3141 | |
| 3142 | int |
| 3143 | tc_coff_sizemachdep (frag) |
| 3144 | fragS *frag; |
| 3145 | { |
| 3146 | return md_relax_table[frag->fr_subtype].rlx_length; |
| 3147 | } |
| 3148 | |
| 3149 | #endif /* OBJ_COFF */ |
| 3150 | |
| 3151 | #ifndef BFD_ASSEMBLER |
| 3152 | #ifdef OBJ_COFF |
| 3153 | |
| 3154 | /* Map BFD relocs to SH COFF relocs. */ |
| 3155 | |
| 3156 | struct reloc_map |
| 3157 | { |
| 3158 | bfd_reloc_code_real_type bfd_reloc; |
| 3159 | int sh_reloc; |
| 3160 | }; |
| 3161 | |
| 3162 | static const struct reloc_map coff_reloc_map[] = |
| 3163 | { |
| 3164 | { BFD_RELOC_32, R_SH_IMM32 }, |
| 3165 | { BFD_RELOC_16, R_SH_IMM16 }, |
| 3166 | { BFD_RELOC_8, R_SH_IMM8 }, |
| 3167 | { BFD_RELOC_SH_PCDISP8BY2, R_SH_PCDISP8BY2 }, |
| 3168 | { BFD_RELOC_SH_PCDISP12BY2, R_SH_PCDISP }, |
| 3169 | { BFD_RELOC_SH_IMM4, R_SH_IMM4 }, |
| 3170 | { BFD_RELOC_SH_IMM4BY2, R_SH_IMM4BY2 }, |
| 3171 | { BFD_RELOC_SH_IMM4BY4, R_SH_IMM4BY4 }, |
| 3172 | { BFD_RELOC_SH_IMM8, R_SH_IMM8 }, |
| 3173 | { BFD_RELOC_SH_IMM8BY2, R_SH_IMM8BY2 }, |
| 3174 | { BFD_RELOC_SH_IMM8BY4, R_SH_IMM8BY4 }, |
| 3175 | { BFD_RELOC_SH_PCRELIMM8BY2, R_SH_PCRELIMM8BY2 }, |
| 3176 | { BFD_RELOC_SH_PCRELIMM8BY4, R_SH_PCRELIMM8BY4 }, |
| 3177 | { BFD_RELOC_8_PCREL, R_SH_SWITCH8 }, |
| 3178 | { BFD_RELOC_SH_SWITCH16, R_SH_SWITCH16 }, |
| 3179 | { BFD_RELOC_SH_SWITCH32, R_SH_SWITCH32 }, |
| 3180 | { BFD_RELOC_SH_USES, R_SH_USES }, |
| 3181 | { BFD_RELOC_SH_COUNT, R_SH_COUNT }, |
| 3182 | { BFD_RELOC_SH_ALIGN, R_SH_ALIGN }, |
| 3183 | { BFD_RELOC_SH_CODE, R_SH_CODE }, |
| 3184 | { BFD_RELOC_SH_DATA, R_SH_DATA }, |
| 3185 | { BFD_RELOC_SH_LABEL, R_SH_LABEL }, |
| 3186 | { BFD_RELOC_UNUSED, 0 } |
| 3187 | }; |
| 3188 | |
| 3189 | /* Adjust a reloc for the SH. This is similar to the generic code, |
| 3190 | but does some minor tweaking. */ |
| 3191 | |
| 3192 | void |
| 3193 | sh_coff_reloc_mangle (seg, fix, intr, paddr) |
| 3194 | segment_info_type *seg; |
| 3195 | fixS *fix; |
| 3196 | struct internal_reloc *intr; |
| 3197 | unsigned int paddr; |
| 3198 | { |
| 3199 | symbolS *symbol_ptr = fix->fx_addsy; |
| 3200 | symbolS *dot; |
| 3201 | |
| 3202 | intr->r_vaddr = paddr + fix->fx_frag->fr_address + fix->fx_where; |
| 3203 | |
| 3204 | if (! SWITCH_TABLE (fix)) |
| 3205 | { |
| 3206 | const struct reloc_map *rm; |
| 3207 | |
| 3208 | for (rm = coff_reloc_map; rm->bfd_reloc != BFD_RELOC_UNUSED; rm++) |
| 3209 | if (rm->bfd_reloc == (bfd_reloc_code_real_type) fix->fx_r_type) |
| 3210 | break; |
| 3211 | if (rm->bfd_reloc == BFD_RELOC_UNUSED) |
| 3212 | as_bad_where (fix->fx_file, fix->fx_line, |
| 3213 | _("Can not represent %s relocation in this object file format"), |
| 3214 | bfd_get_reloc_code_name (fix->fx_r_type)); |
| 3215 | intr->r_type = rm->sh_reloc; |
| 3216 | intr->r_offset = 0; |
| 3217 | } |
| 3218 | else |
| 3219 | { |
| 3220 | know (sh_relax); |
| 3221 | |
| 3222 | if (fix->fx_r_type == BFD_RELOC_16) |
| 3223 | intr->r_type = R_SH_SWITCH16; |
| 3224 | else if (fix->fx_r_type == BFD_RELOC_8) |
| 3225 | intr->r_type = R_SH_SWITCH8; |
| 3226 | else if (fix->fx_r_type == BFD_RELOC_32) |
| 3227 | intr->r_type = R_SH_SWITCH32; |
| 3228 | else |
| 3229 | abort (); |
| 3230 | |
| 3231 | /* For a switch reloc, we set r_offset to the difference between |
| 3232 | the reloc address and the subtrahend. When the linker is |
| 3233 | doing relaxing, it can use the determine the starting and |
| 3234 | ending points of the switch difference expression. */ |
| 3235 | intr->r_offset = intr->r_vaddr - S_GET_VALUE (fix->fx_subsy); |
| 3236 | } |
| 3237 | |
| 3238 | /* PC relative relocs are always against the current section. */ |
| 3239 | if (symbol_ptr == NULL) |
| 3240 | { |
| 3241 | switch (fix->fx_r_type) |
| 3242 | { |
| 3243 | case BFD_RELOC_SH_PCRELIMM8BY2: |
| 3244 | case BFD_RELOC_SH_PCRELIMM8BY4: |
| 3245 | case BFD_RELOC_SH_PCDISP8BY2: |
| 3246 | case BFD_RELOC_SH_PCDISP12BY2: |
| 3247 | case BFD_RELOC_SH_USES: |
| 3248 | symbol_ptr = seg->dot; |
| 3249 | break; |
| 3250 | default: |
| 3251 | break; |
| 3252 | } |
| 3253 | } |
| 3254 | |
| 3255 | if (fix->fx_r_type == BFD_RELOC_SH_USES) |
| 3256 | { |
| 3257 | /* We can't store the offset in the object file, since this |
| 3258 | reloc does not take up any space, so we store it in r_offset. |
| 3259 | The fx_addnumber field was set in md_apply_fix3. */ |
| 3260 | intr->r_offset = fix->fx_addnumber; |
| 3261 | } |
| 3262 | else if (fix->fx_r_type == BFD_RELOC_SH_COUNT) |
| 3263 | { |
| 3264 | /* We can't store the count in the object file, since this reloc |
| 3265 | does not take up any space, so we store it in r_offset. The |
| 3266 | fx_offset field was set when the fixup was created in |
| 3267 | sh_coff_frob_file. */ |
| 3268 | intr->r_offset = fix->fx_offset; |
| 3269 | /* This reloc is always absolute. */ |
| 3270 | symbol_ptr = NULL; |
| 3271 | } |
| 3272 | else if (fix->fx_r_type == BFD_RELOC_SH_ALIGN) |
| 3273 | { |
| 3274 | /* Store the alignment in the r_offset field. */ |
| 3275 | intr->r_offset = fix->fx_offset; |
| 3276 | /* This reloc is always absolute. */ |
| 3277 | symbol_ptr = NULL; |
| 3278 | } |
| 3279 | else if (fix->fx_r_type == BFD_RELOC_SH_CODE |
| 3280 | || fix->fx_r_type == BFD_RELOC_SH_DATA |
| 3281 | || fix->fx_r_type == BFD_RELOC_SH_LABEL) |
| 3282 | { |
| 3283 | /* These relocs are always absolute. */ |
| 3284 | symbol_ptr = NULL; |
| 3285 | } |
| 3286 | |
| 3287 | /* Turn the segment of the symbol into an offset. */ |
| 3288 | if (symbol_ptr != NULL) |
| 3289 | { |
| 3290 | dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot; |
| 3291 | if (dot != NULL) |
| 3292 | intr->r_symndx = dot->sy_number; |
| 3293 | else |
| 3294 | intr->r_symndx = symbol_ptr->sy_number; |
| 3295 | } |
| 3296 | else |
| 3297 | intr->r_symndx = -1; |
| 3298 | } |
| 3299 | |
| 3300 | #endif /* OBJ_COFF */ |
| 3301 | #endif /* ! BFD_ASSEMBLER */ |
| 3302 | |
| 3303 | #ifdef BFD_ASSEMBLER |
| 3304 | |
| 3305 | /* Create a reloc. */ |
| 3306 | |
| 3307 | arelent * |
| 3308 | tc_gen_reloc (section, fixp) |
| 3309 | asection *section ATTRIBUTE_UNUSED; |
| 3310 | fixS *fixp; |
| 3311 | { |
| 3312 | arelent *rel; |
| 3313 | bfd_reloc_code_real_type r_type; |
| 3314 | |
| 3315 | rel = (arelent *) xmalloc (sizeof (arelent)); |
| 3316 | rel->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
| 3317 | *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
| 3318 | rel->address = fixp->fx_frag->fr_address + fixp->fx_where; |
| 3319 | |
| 3320 | if (fixp->fx_subsy |
| 3321 | && S_GET_SEGMENT (fixp->fx_subsy) == absolute_section) |
| 3322 | { |
| 3323 | fixp->fx_addnumber -= S_GET_VALUE (fixp->fx_subsy); |
| 3324 | fixp->fx_subsy = 0; |
| 3325 | } |
| 3326 | |
| 3327 | r_type = fixp->fx_r_type; |
| 3328 | |
| 3329 | if (SWITCH_TABLE (fixp)) |
| 3330 | { |
| 3331 | rel->addend = rel->address - S_GET_VALUE (fixp->fx_subsy); |
| 3332 | if (r_type == BFD_RELOC_16) |
| 3333 | r_type = BFD_RELOC_SH_SWITCH16; |
| 3334 | else if (r_type == BFD_RELOC_8) |
| 3335 | r_type = BFD_RELOC_8_PCREL; |
| 3336 | else if (r_type == BFD_RELOC_32) |
| 3337 | r_type = BFD_RELOC_SH_SWITCH32; |
| 3338 | else |
| 3339 | abort (); |
| 3340 | } |
| 3341 | else if (r_type == BFD_RELOC_SH_USES) |
| 3342 | rel->addend = fixp->fx_addnumber; |
| 3343 | else if (r_type == BFD_RELOC_SH_COUNT) |
| 3344 | rel->addend = fixp->fx_offset; |
| 3345 | else if (r_type == BFD_RELOC_SH_ALIGN) |
| 3346 | rel->addend = fixp->fx_offset; |
| 3347 | else if (r_type == BFD_RELOC_VTABLE_INHERIT |
| 3348 | || r_type == BFD_RELOC_VTABLE_ENTRY) |
| 3349 | rel->addend = fixp->fx_offset; |
| 3350 | else if (r_type == BFD_RELOC_SH_LOOP_START |
| 3351 | || r_type == BFD_RELOC_SH_LOOP_END) |
| 3352 | rel->addend = fixp->fx_offset; |
| 3353 | else if (r_type == BFD_RELOC_SH_LABEL && fixp->fx_pcrel) |
| 3354 | { |
| 3355 | rel->addend = 0; |
| 3356 | rel->address = rel->addend = fixp->fx_offset; |
| 3357 | } |
| 3358 | else if (fixp->fx_pcrel) |
| 3359 | rel->addend = fixp->fx_addnumber; |
| 3360 | else if (r_type == BFD_RELOC_32 || r_type == BFD_RELOC_32_GOTOFF) |
| 3361 | rel->addend = fixp->fx_addnumber; |
| 3362 | else |
| 3363 | rel->addend = 0; |
| 3364 | |
| 3365 | rel->howto = bfd_reloc_type_lookup (stdoutput, r_type); |
| 3366 | if (rel->howto == NULL || fixp->fx_subsy) |
| 3367 | { |
| 3368 | as_bad_where (fixp->fx_file, fixp->fx_line, |
| 3369 | _("Cannot represent relocation type %s"), |
| 3370 | bfd_get_reloc_code_name (r_type)); |
| 3371 | /* Set howto to a garbage value so that we can keep going. */ |
| 3372 | rel->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32); |
| 3373 | assert (rel->howto != NULL); |
| 3374 | } |
| 3375 | |
| 3376 | return rel; |
| 3377 | } |
| 3378 | |
| 3379 | #ifdef OBJ_ELF |
| 3380 | inline static char * |
| 3381 | sh_end_of_match (cont, what) |
| 3382 | char *cont, *what; |
| 3383 | { |
| 3384 | int len = strlen (what); |
| 3385 | |
| 3386 | if (strncasecmp (cont, what, strlen (what)) == 0 |
| 3387 | && ! is_part_of_name (cont[len])) |
| 3388 | return cont + len; |
| 3389 | |
| 3390 | return NULL; |
| 3391 | } |
| 3392 | |
| 3393 | int |
| 3394 | sh_parse_name (name, exprP, nextcharP) |
| 3395 | char const *name; |
| 3396 | expressionS *exprP; |
| 3397 | char *nextcharP; |
| 3398 | { |
| 3399 | char *next = input_line_pointer; |
| 3400 | char *next_end; |
| 3401 | int reloc_type; |
| 3402 | segT segment; |
| 3403 | |
| 3404 | exprP->X_op_symbol = NULL; |
| 3405 | |
| 3406 | if (strcmp (name, GLOBAL_OFFSET_TABLE_NAME) == 0) |
| 3407 | { |
| 3408 | if (! GOT_symbol) |
| 3409 | GOT_symbol = symbol_find_or_make (name); |
| 3410 | |
| 3411 | exprP->X_add_symbol = GOT_symbol; |
| 3412 | no_suffix: |
| 3413 | /* If we have an absolute symbol or a reg, then we know its |
| 3414 | value now. */ |
| 3415 | segment = S_GET_SEGMENT (exprP->X_add_symbol); |
| 3416 | if (segment == absolute_section) |
| 3417 | { |
| 3418 | exprP->X_op = O_constant; |
| 3419 | exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol); |
| 3420 | exprP->X_add_symbol = NULL; |
| 3421 | } |
| 3422 | else if (segment == reg_section) |
| 3423 | { |
| 3424 | exprP->X_op = O_register; |
| 3425 | exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol); |
| 3426 | exprP->X_add_symbol = NULL; |
| 3427 | } |
| 3428 | else |
| 3429 | { |
| 3430 | exprP->X_op = O_symbol; |
| 3431 | exprP->X_add_number = 0; |
| 3432 | } |
| 3433 | |
| 3434 | return 1; |
| 3435 | } |
| 3436 | |
| 3437 | exprP->X_add_symbol = symbol_find_or_make (name); |
| 3438 | |
| 3439 | if (*nextcharP != '@') |
| 3440 | goto no_suffix; |
| 3441 | else if ((next_end = sh_end_of_match (next + 1, "GOTOFF"))) |
| 3442 | reloc_type = BFD_RELOC_32_GOTOFF; |
| 3443 | else if ((next_end = sh_end_of_match (next + 1, "GOT"))) |
| 3444 | reloc_type = BFD_RELOC_32_GOT_PCREL; |
| 3445 | else if ((next_end = sh_end_of_match (next + 1, "PLT"))) |
| 3446 | reloc_type = BFD_RELOC_32_PLT_PCREL; |
| 3447 | else |
| 3448 | goto no_suffix; |
| 3449 | |
| 3450 | *input_line_pointer = *nextcharP; |
| 3451 | input_line_pointer = next_end; |
| 3452 | *nextcharP = *input_line_pointer; |
| 3453 | *input_line_pointer = '\0'; |
| 3454 | |
| 3455 | exprP->X_op = O_PIC_reloc; |
| 3456 | exprP->X_add_number = 0; |
| 3457 | exprP->X_md = reloc_type; |
| 3458 | |
| 3459 | return 1; |
| 3460 | } |
| 3461 | #endif |
| 3462 | #endif /* BFD_ASSEMBLER */ |