Changeset 1973 for binutils/trunk/gas/config/tc-rl78.c
- Timestamp:
- Feb 6, 2017, 1:00:00 PM (8 years ago)
- Location:
- binutils/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
binutils/trunk ¶
-
Property svn:mergeinfo
set to
/binutils/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
TabularUnified binutils/trunk/gas/config/tc-rl78.c ¶
r970 r1973 1 1 /* tc-rl78.c -- Assembler for the Renesas RL78 2 Copyright (C) 2011-201 4Free Software Foundation, Inc.2 Copyright (C) 2011-2016 Free Software Foundation, Inc. 3 3 4 4 This file is part of GAS, the GNU Assembler. … … 103 103 rl78_linkrelax_branch (void) 104 104 { 105 rl78_relax (RL78_RELAX_BRANCH, 0); 105 106 rl78_bytes.link_relax |= RL78_RELAXA_BRA; 106 107 } … … 131 132 132 133 int 133 rl78_has_prefix ( )134 rl78_has_prefix (void) 134 135 { 135 136 return rl78_bytes.n_prefix; … … 281 282 { 282 283 OPTION_RELAX = OPTION_MD_BASE, 284 OPTION_NORELAX, 283 285 OPTION_G10, 286 OPTION_G13, 287 OPTION_G14, 284 288 OPTION_32BIT_DOUBLES, 285 289 OPTION_64BIT_DOUBLES, … … 293 297 { 294 298 {"relax", no_argument, NULL, OPTION_RELAX}, 299 {"norelax", no_argument, NULL, OPTION_NORELAX}, 295 300 {"mg10", no_argument, NULL, OPTION_G10}, 301 {"mg13", no_argument, NULL, OPTION_G13}, 302 {"mg14", no_argument, NULL, OPTION_G14}, 303 {"mrl78", no_argument, NULL, OPTION_G14}, 296 304 {"m32bit-doubles", no_argument, NULL, OPTION_32BIT_DOUBLES}, 297 305 {"m64bit-doubles", no_argument, NULL, OPTION_64BIT_DOUBLES}, … … 301 309 302 310 int 303 md_parse_option (int c, c har * arg ATTRIBUTE_UNUSED)311 md_parse_option (int c, const char * arg ATTRIBUTE_UNUSED) 304 312 { 305 313 switch (c) … … 308 316 linkrelax = 1; 309 317 return 1; 318 case OPTION_NORELAX: 319 linkrelax = 0; 320 return 1; 310 321 311 322 case OPTION_G10: 323 elf_flags &= ~ E_FLAG_RL78_CPU_MASK; 312 324 elf_flags |= E_FLAG_RL78_G10; 325 return 1; 326 327 case OPTION_G13: 328 elf_flags &= ~ E_FLAG_RL78_CPU_MASK; 329 elf_flags |= E_FLAG_RL78_G13; 330 return 1; 331 332 case OPTION_G14: 333 elf_flags &= ~ E_FLAG_RL78_CPU_MASK; 334 elf_flags |= E_FLAG_RL78_G14; 313 335 return 1; 314 336 … … 324 346 } 325 347 326 void 327 md_show_usage (FILE * stream ATTRIBUTE_UNUSED) 348 int 349 rl78_isa_g10 (void) 350 { 351 return (elf_flags & E_FLAG_RL78_CPU_MASK) == E_FLAG_RL78_G10; 352 } 353 354 int 355 rl78_isa_g13 (void) 356 { 357 return (elf_flags & E_FLAG_RL78_CPU_MASK) == E_FLAG_RL78_G13; 358 } 359 360 int 361 rl78_isa_g14 (void) 362 { 363 return (elf_flags & E_FLAG_RL78_CPU_MASK) == E_FLAG_RL78_G14; 364 } 365 366 void 367 md_show_usage (FILE * stream) 328 368 { 329 369 fprintf (stream, _(" RL78 specific command line options:\n")); 370 fprintf (stream, _(" --mrelax Enable link time relaxation\n")); 330 371 fprintf (stream, _(" --mg10 Enable support for G10 variant\n")); 372 fprintf (stream, _(" --mg13 Selects the G13 core.\n")); 373 fprintf (stream, _(" --mg14 Selects the G14 core [default]\n")); 374 fprintf (stream, _(" --mrl78 Alias for --mg14\n")); 331 375 fprintf (stream, _(" --m32bit-doubles [default]\n")); 332 fprintf (stream, _(" --m64bit-doubles \n"));376 fprintf (stream, _(" --m64bit-doubles Source code uses 64-bit doubles\n")); 333 377 } 334 378 … … 365 409 }; 366 410 411 static symbolS * rl78_abs_sym = NULL; 412 367 413 void 368 414 md_begin (void) 369 415 { 416 rl78_abs_sym = symbol_make ("__rl78_abs__"); 370 417 } 371 418 … … 390 437 391 438 static void 392 require_end_of_expr (c har *fname)439 require_end_of_expr (const char *fname) 393 440 { 394 441 while (* input_line_pointer == ' ' … … 408 455 static struct 409 456 { 410 c har * fname;457 const char * fname; 411 458 int reloc; 412 459 } … … 456 503 if (rl78_bytes.n_relax || rl78_bytes.link_relax) 457 504 { 458 fragP->tc_frag_data = malloc (sizeof (rl78_bytesT));505 fragP->tc_frag_data = XNEW (rl78_bytesT); 459 506 memcpy (fragP->tc_frag_data, & rl78_bytes, sizeof (rl78_bytesT)); 460 507 } … … 487 534 } 488 535 489 c har *536 const char * 490 537 md_atof (int type, char * litP, int * sizeP) 491 538 { … … 644 691 case BFD_RELOC_RL78_HI16: 645 692 if (size != 2) 646 as_bad (_("%%hi16/%%lo16 only applies to .short or .hword")); 647 type = exp->X_md; 693 { 694 /* Fixups to assembler generated expressions do not use %hi or %lo. */ 695 if (frag->fr_file) 696 as_bad (_("%%hi16/%%lo16 only applies to .short or .hword")); 697 } 698 else 699 type = exp->X_md; 648 700 break; 649 701 case BFD_RELOC_RL78_HI8: 650 702 if (size != 1) 651 as_bad (_("%%hi8 only applies to .byte")); 652 type = exp->X_md; 703 { 704 /* Fixups to assembler generated expressions do not use %hi or %lo. */ 705 if (frag->fr_file) 706 as_bad (_("%%hi8 only applies to .byte")); 707 } 708 else 709 type = exp->X_md; 653 710 break; 654 711 default: … … 708 765 OT_bt_es, 709 766 OT_bc, 710 OT_bh 767 OT_bh, 768 OT_sk, 769 OT_call, 770 OT_br, 711 771 } op_type_T; 712 772 … … 731 791 732 792 static op_type_T 733 rl78_opcode_type (char * op) 734 { 793 rl78_opcode_type (char * ops) 794 { 795 unsigned char *op = (unsigned char *)ops; 796 735 797 if (op[0] == 0x31 736 798 && ((op[1] & 0x0f) == 0x05 … … 755 817 && (op[1] & 0xef) == 0xc3) 756 818 return OT_bh; 819 820 if (op[0] == 0x61 821 && (op[1] & 0xcf) == 0xc8) 822 return OT_sk; 823 824 if (op[0] == 0x61 825 && (op[1] & 0xef) == 0xe3) 826 return OT_sk; 827 828 if (op[0] == 0xfc) 829 return OT_call; 830 831 if ((op[0] & 0xec) == 0xec) 832 return OT_br; 757 833 758 834 return OT_other; … … 806 882 value is the difference between fr_fix and the actual size. We 807 883 compute the total size in rl78_relax_frag and store it in fr_subtype, 808 so we only need to subtract fx_fix and return it. */884 so we only need to subtract fx_fix and return it. */ 809 885 810 886 int … … 852 928 & sym_addr)) 853 929 { 930 /* If we don't expect the linker to do relaxing, don't emit 931 expanded opcodes that only the linker will relax. */ 932 if (!linkrelax) 933 return newsize - oldsize; 934 854 935 /* If we don't, we must use the maximum size for the linker. */ 855 936 switch (fragP->tc_frag_data->relax[ri].type) … … 871 952 newsize = 6; 872 953 break; 873 case OT_other: 954 case OT_sk: 955 newsize = 2; 956 break; 957 default: 874 958 newsize = oldsize; 875 959 break; … … 918 1002 newsize = 6; 919 1003 break; 920 case OT_other: 1004 case OT_sk: 1005 newsize = 2; 1006 break; 1007 default: 921 1008 newsize = oldsize; 922 1009 break; … … 943 1030 tprintf (" -> new %d old %d delta %d\n", newsize, oldsize, newsize-oldsize); 944 1031 return newsize - oldsize; 945 946 1032 } 1033 947 1034 /* This lets us test for the opcode type and the desired size in a 948 1035 switch statement. */ … … 978 1065 be the frag address. */ 979 1066 mypc = fragP->fr_address + (fragP->fr_opcode - fragP->fr_literal); 980 tprintf ("\033[32mmypc: 0x%x\033[0m\n", (int)mypc);1067 tprintf ("\033[32mmypc: 0x%x\033[0m\n", (int)mypc); 981 1068 982 1069 /* Try to get the target address. If we fail here, we just use the 983 1070 largest format. */ 984 1071 if (rl78_frag_fix_value (fragP, segment, 0, & addr0, 985 fragP->tc_frag_data->relax[ri].type != RL78_RELAX_BRANCH, 0))1072 fragP->tc_frag_data->relax[ri].type != RL78_RELAX_BRANCH, 0)) 986 1073 { 987 1074 /* We don't know the target address. */ … … 1013 1100 disp -= 3; 1014 1101 op[2] = disp; 1102 reloc_type = keep_reloc ? BFD_RELOC_8_PCREL : BFD_RELOC_NONE; 1015 1103 break; 1016 1104 … … 1030 1118 disp -= 4; 1031 1119 op[3] = disp; 1120 reloc_type = keep_reloc ? BFD_RELOC_8_PCREL : BFD_RELOC_NONE; 1032 1121 break; 1033 1122 … … 1047 1136 disp -= 4; 1048 1137 op[3] = disp; 1138 reloc_type = keep_reloc ? BFD_RELOC_8_PCREL : BFD_RELOC_NONE; 1049 1139 break; 1050 1140 … … 1064 1154 disp -= 2; 1065 1155 op[1] = disp; 1156 reloc_type = keep_reloc ? BFD_RELOC_8_PCREL : BFD_RELOC_NONE; 1066 1157 break; 1067 1158 … … 1081 1172 disp -= 3; 1082 1173 op[2] = disp; 1174 reloc_type = keep_reloc ? BFD_RELOC_8_PCREL : BFD_RELOC_NONE; 1083 1175 break; 1084 1176 … … 1095 1187 break; 1096 1188 1189 case OPCODE (OT_sk, 2): /* SK<cond> - no change */ 1190 reloc_type = keep_reloc ? BFD_RELOC_16_PCREL : BFD_RELOC_NONE; 1191 break; 1192 1097 1193 default: 1098 fprintf(stderr, "Missed case %d %d at 0x%lx\n", 1099 rl78_opcode_type (fragP->fr_opcode), fragP->fr_subtype, mypc); 1100 abort (); 1101 1194 reloc_type = fix ? fix->fx_r_type : BFD_RELOC_NONE; 1195 break; 1102 1196 } 1103 1197 break; … … 1167 1261 } 1168 1262 1263 if (fixp->fx_r_type == BFD_RELOC_RL78_RELAX && !linkrelax) 1264 { 1265 reloc[0] = NULL; 1266 return reloc; 1267 } 1268 1169 1269 if (fixp->fx_subsy 1170 1270 && S_GET_SEGMENT (fixp->fx_subsy) == absolute_section) … … 1174 1274 } 1175 1275 1176 reloc[0] = (arelent *) xmalloc (sizeof (arelent));1177 reloc[0]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));1276 reloc[0] = XNEW (arelent); 1277 reloc[0]->sym_ptr_ptr = XNEW (asymbol *); 1178 1278 * reloc[0]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); 1179 1279 reloc[0]->address = fixp->fx_frag->fr_address + fixp->fx_where; … … 1187 1287 1188 1288 #define OPX(REL,SYM,ADD) \ 1189 reloc[rp] = (arelent *) xmalloc (sizeof (arelent)); \1190 reloc[rp]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); \1289 reloc[rp] = XNEW (arelent); \ 1290 reloc[rp]->sym_ptr_ptr = XNEW (asymbol *); \ 1191 1291 reloc[rp]->howto = bfd_reloc_type_lookup (stdoutput, REL); \ 1192 1292 reloc[rp]->addend = ADD; \ … … 1195 1295 reloc[++rp] = NULL 1196 1296 #define OPSYM(SYM) OPX(BFD_RELOC_RL78_SYM, SYM, 0) 1197 #define OPIMM(IMM) OPX(BFD_RELOC_RL78_SYM, abs_symbol.bsym, IMM) 1297 1298 /* FIXME: We cannot do the normal thing for an immediate value reloc, 1299 ie creating a RL78_SYM reloc in the *ABS* section with an offset 1300 equal to the immediate value we want to store. This fails because 1301 the reloc processing in bfd_perform_relocation and bfd_install_relocation 1302 will short circuit such relocs and never pass them on to the special 1303 reloc processing code. So instead we create a RL78_SYM reloc against 1304 the __rl78_abs__ symbol and arrange for the linker scripts to place 1305 this symbol at address 0. */ 1306 #define OPIMM(IMM) OPX (BFD_RELOC_RL78_SYM, symbol_get_bfdsym (rl78_abs_sym), IMM) 1307 1198 1308 #define OP(OP) OPX(BFD_RELOC_RL78_##OP, *reloc[0]->sym_ptr_ptr, 0) 1199 1309 #define SYM0() reloc[0]->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_RL78_SYM) … … 1318 1428 unsigned long val; 1319 1429 1430 /* We always defer overflow checks for these to the linker, as it 1431 needs to do PLT stuff. */ 1432 if (f->fx_r_type == BFD_RELOC_RL78_CODE) 1433 f->fx_no_overflow = 1; 1434 1320 1435 if (f->fx_addsy && S_FORCE_RELOC (f->fx_addsy, 1)) 1321 1436 return; … … 1326 1441 val = (unsigned long) * t; 1327 1442 1443 if (f->fx_addsy == NULL) 1444 f->fx_done = 1; 1445 1328 1446 switch (f->fx_r_type) 1329 1447 { … … 1332 1450 1333 1451 case BFD_RELOC_RL78_RELAX: 1334 f->fx_done = 1;1452 f->fx_done = 0; 1335 1453 break; 1336 1454 … … 1342 1460 /* Fall through. */ 1343 1461 case BFD_RELOC_8: 1462 case BFD_RELOC_RL78_SADDR: /* We need to store the 8 LSB, but this works. */ 1344 1463 op[0] = val; 1345 1464 break; … … 1402 1521 } 1403 1522 1404 if (f->fx_addsy == NULL)1405 f->fx_done = 1;1406 1523 } 1407 1524 … … 1410 1527 { 1411 1528 int align = bfd_get_section_alignment (stdoutput, segment); 1412 return ((size + (1 << align) - 1) & (-1 << align));1413 } 1529 return ((size + (1 << align) - 1) & -(1 << align)); 1530 }
Note:
See TracChangeset
for help on using the changeset viewer.