| From f82b24b2685d0cde8f8fdd0a1dcffe7b76b2027c Mon Sep 17 00:00:00 2001 |
| From: Nagaraju Mekala <nmekala@xilix.com> |
| Date: Sun, 30 Sep 2018 16:31:26 +0530 |
| Subject: [PATCH 16/40] MB-X initial commit code cleanup is needed. |
| |
| --- |
| bfd/bfd-in2.h | 10 +++ |
| bfd/elf32-microblaze.c | 63 +++++++++++++++++- |
| bfd/elf64-microblaze.c | 59 +++++++++++++++++ |
| bfd/libbfd.h | 2 + |
| bfd/reloc.c | 12 ++++ |
| include/elf/microblaze.h | 2 + |
| opcodes/microblaze-opc.h | 4 +- |
| opcodes/microblaze-opcm.h | 4 +- |
| 9 files changed, 243 insertions(+), 40 deletions(-) |
| |
| diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h |
| index 52c81b10b6d..c6738960bb2 100644 |
| --- a/bfd/bfd-in2.h |
| +++ b/bfd/bfd-in2.h |
| @@ -5373,11 +5373,21 @@ value in two words (with an imm instruction). No relocation is |
| done here - only used for relaxing */ |
| BFD_RELOC_MICROBLAZE_64_NONE, |
| |
| +/* This is a 64 bit reloc that stores the 32 bit pc relative |
| +value in two words (with an imml instruction). No relocation is |
| +done here - only used for relaxing */ |
| + BFD_RELOC_MICROBLAZE_64, |
| + |
| /* This is a 64 bit reloc that stores the 32 bit pc relative |
| value in two words (with an imm instruction). The relocation is |
| PC-relative GOT offset */ |
| BFD_RELOC_MICROBLAZE_64_GOTPC, |
| |
| +/* This is a 64 bit reloc that stores the 32 bit pc relative |
| +value in two words (with an imml instruction). The relocation is |
| +PC-relative GOT offset */ |
| + BFD_RELOC_MICROBLAZE_64_GPC, |
| + |
| /* This is a 64 bit reloc that stores the 32 bit pc relative |
| value in two words (with an imm instruction). The relocation is |
| GOT offset */ |
| diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c |
| index cb7271f5017..a31b407cfbf 100644 |
| --- a/bfd/elf32-microblaze.c |
| +++ b/bfd/elf32-microblaze.c |
| @@ -116,6 +116,20 @@ static reloc_howto_type microblaze_elf_howto_raw[] = |
| 0x0000ffff, /* Dest Mask. */ |
| TRUE), /* PC relative offset? */ |
| |
| + HOWTO (R_MICROBLAZE_IMML_64, /* Type. */ |
| + 0, /* Rightshift. */ |
| + 2, /* Size (0 = byte, 1 = short, 2 = long). */ |
| + 16, /* Bitsize. */ |
| + TRUE, /* PC_relative. */ |
| + 0, /* Bitpos. */ |
| + complain_overflow_dont, /* Complain on overflow. */ |
| + bfd_elf_generic_reloc,/* Special Function. */ |
| + "R_MICROBLAZE_IMML_64", /* Name. */ |
| + FALSE, /* Partial Inplace. */ |
| + 0, /* Source Mask. */ |
| + 0x0000ffff, /* Dest Mask. */ |
| + FALSE), /* PC relative offset? */ |
| + |
| /* A 64 bit relocation. Table entry not really used. */ |
| HOWTO (R_MICROBLAZE_64, /* Type. */ |
| 0, /* Rightshift. */ |
| @@ -280,6 +294,21 @@ static reloc_howto_type microblaze_elf_howto_raw[] = |
| 0x0000ffff, /* Dest Mask. */ |
| TRUE), /* PC relative offset? */ |
| |
| + /* A 64 bit GOTPC relocation. Table-entry not really used. */ |
| + HOWTO (R_MICROBLAZE_GPC_64, /* Type. */ |
| + 0, /* Rightshift. */ |
| + 2, /* Size (0 = byte, 1 = short, 2 = long). */ |
| + 16, /* Bitsize. */ |
| + TRUE, /* PC_relative. */ |
| + 0, /* Bitpos. */ |
| + complain_overflow_dont, /* Complain on overflow. */ |
| + bfd_elf_generic_reloc, /* Special Function. */ |
| + "R_MICROBLAZE_GPC_64", /* Name. */ |
| + FALSE, /* Partial Inplace. */ |
| + 0, /* Source Mask. */ |
| + 0x0000ffff, /* Dest Mask. */ |
| + TRUE), /* PC relative offset? */ |
| + |
| /* A 64 bit GOT relocation. Table-entry not really used. */ |
| HOWTO (R_MICROBLAZE_GOT_64, /* Type. */ |
| 0, /* Rightshift. */ |
| @@ -619,9 +648,15 @@ microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, |
| case BFD_RELOC_VTABLE_ENTRY: |
| microblaze_reloc = R_MICROBLAZE_GNU_VTENTRY; |
| break; |
| + case BFD_RELOC_MICROBLAZE_64: |
| + microblaze_reloc = R_MICROBLAZE_IMML_64; |
| + break; |
| case BFD_RELOC_MICROBLAZE_64_GOTPC: |
| microblaze_reloc = R_MICROBLAZE_GOTPC_64; |
| break; |
| + case BFD_RELOC_MICROBLAZE_64_GPC: |
| + microblaze_reloc = R_MICROBLAZE_GPC_64; |
| + break; |
| case BFD_RELOC_MICROBLAZE_64_GOT: |
| microblaze_reloc = R_MICROBLAZE_GOT_64; |
| break; |
| @@ -1933,6 +1968,28 @@ microblaze_elf_relax_section (bfd *abfd, |
| irel->r_addend -= calc_fixup (irel->r_addend, 0, sec); |
| } |
| break; |
| + case R_MICROBLAZE_IMML_64: |
| + { |
| + /* This was a PC-relative instruction that was |
| + completely resolved. */ |
| + int sfix, efix; |
| + unsigned int val; |
| + bfd_vma target_address; |
| + target_address = irel->r_addend + irel->r_offset; |
| + sfix = calc_fixup (irel->r_offset, 0, sec); |
| + efix = calc_fixup (target_address, 0, sec); |
| + |
| + /* Validate the in-band val. */ |
| + val = bfd_get_32 (abfd, contents + irel->r_offset); |
| + if (val != irel->r_addend && ELF64_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) { |
| + fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend); |
| + } |
| + irel->r_addend -= (efix - sfix); |
| + /* Should use HOWTO. */ |
| + microblaze_bfd_write_imm_value_64 (abfd, contents + irel->r_offset, |
| + irel->r_addend); |
| + } |
| + break; |
| case R_MICROBLAZE_NONE: |
| case R_MICROBLAZE_32_NONE: |
| { |
| @@ -2038,9 +2095,9 @@ microblaze_elf_relax_section (bfd *abfd, |
| microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset, |
| irelscan->r_addend); |
| } |
| - if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32) |
| - { |
| - isym = isymbuf + ELF32_R_SYM (irelscan->r_info); |
| + if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32) |
| + { |
| + isym = isymbuf + ELF32_R_SYM (irelscan->r_info); |
| |
| /* Look at the reloc only if the value has been resolved. */ |
| if (isym->st_shndx == shndx |
| diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c |
| index fa4b95e47e0..d55700fc513 100644 |
| --- a/bfd/elf64-microblaze.c |
| +++ b/bfd/elf64-microblaze.c |
| @@ -116,6 +116,21 @@ static reloc_howto_type microblaze_elf_howto_raw[] = |
| 0x0000ffff, /* Dest Mask. */ |
| TRUE), /* PC relative offset? */ |
| |
| + /* A 64 bit relocation. Table entry not really used. */ |
| + HOWTO (R_MICROBLAZE_IMML_64, /* Type. */ |
| + 0, /* Rightshift. */ |
| + 4, /* Size (0 = byte, 1 = short, 2 = long). */ |
| + 64, /* Bitsize. */ |
| + TRUE, /* PC_relative. */ |
| + 0, /* Bitpos. */ |
| + complain_overflow_dont, /* Complain on overflow. */ |
| + bfd_elf_generic_reloc,/* Special Function. */ |
| + "R_MICROBLAZE_IMML_64", /* Name. */ |
| + FALSE, /* Partial Inplace. */ |
| + 0, /* Source Mask. */ |
| + 0x0000ffff, /* Dest Mask. */ |
| + TRUE), /* PC relative offset? */ |
| + |
| /* A 64 bit relocation. Table entry not really used. */ |
| HOWTO (R_MICROBLAZE_64, /* Type. */ |
| 0, /* Rightshift. */ |
| @@ -265,6 +280,21 @@ static reloc_howto_type microblaze_elf_howto_raw[] = |
| 0x0000ffff, /* Dest Mask. */ |
| TRUE), /* PC relative offset? */ |
| |
| + /* A 64 bit GOTPC relocation. Table-entry not really used. */ |
| + HOWTO (R_MICROBLAZE_GPC_64, /* Type. */ |
| + 0, /* Rightshift. */ |
| + 2, /* Size (0 = byte, 1 = short, 2 = long). */ |
| + 16, /* Bitsize. */ |
| + TRUE, /* PC_relative. */ |
| + 0, /* Bitpos. */ |
| + complain_overflow_dont, /* Complain on overflow. */ |
| + bfd_elf_generic_reloc, /* Special Function. */ |
| + "R_MICROBLAZE_GPC_64", /* Name. */ |
| + FALSE, /* Partial Inplace. */ |
| + 0, /* Source Mask. */ |
| + 0x0000ffff, /* Dest Mask. */ |
| + TRUE), /* PC relative offset? */ |
| + |
| /* A 64 bit GOT relocation. Table-entry not really used. */ |
| HOWTO (R_MICROBLAZE_GOT_64, /* Type. */ |
| 0, /* Rightshift. */ |
| @@ -589,9 +619,15 @@ microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, |
| case BFD_RELOC_VTABLE_ENTRY: |
| microblaze_reloc = R_MICROBLAZE_GNU_VTENTRY; |
| break; |
| + case BFD_RELOC_MICROBLAZE_64: |
| + microblaze_reloc = R_MICROBLAZE_IMML_64; |
| + break; |
| case BFD_RELOC_MICROBLAZE_64_GOTPC: |
| microblaze_reloc = R_MICROBLAZE_GOTPC_64; |
| break; |
| + case BFD_RELOC_MICROBLAZE_64_GPC: |
| + microblaze_reloc = R_MICROBLAZE_GPC_64; |
| + break; |
| case BFD_RELOC_MICROBLAZE_64_GOT: |
| microblaze_reloc = R_MICROBLAZE_GOT_64; |
| break; |
| @@ -1162,6 +1198,7 @@ microblaze_elf_relocate_section (bfd *output_bfd, |
| break; /* Do nothing. */ |
| |
| case (int) R_MICROBLAZE_GOTPC_64: |
| + case (int) R_MICROBLAZE_GPC_64: |
| relocation = htab->sgotplt->output_section->vma |
| + htab->sgotplt->output_offset; |
| relocation -= (input_section->output_section->vma |
| @@ -1863,6 +1900,28 @@ microblaze_elf_relax_section (bfd *abfd, |
| irel->r_addend -= calc_fixup (irel->r_addend, 0, sec); |
| } |
| break; |
| + case R_MICROBLAZE_IMML_64: |
| + { |
| + /* This was a PC-relative instruction that was |
| + completely resolved. */ |
| + int sfix, efix; |
| + unsigned int val; |
| + bfd_vma target_address; |
| + target_address = irel->r_addend + irel->r_offset; |
| + sfix = calc_fixup (irel->r_offset, 0, sec); |
| + efix = calc_fixup (target_address, 0, sec); |
| + |
| + /* Validate the in-band val. */ |
| + val = bfd_get_32 (abfd, contents + irel->r_offset); |
| + if (val != irel->r_addend && ELF64_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) { |
| + fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend); |
| + } |
| + irel->r_addend -= (efix - sfix); |
| + /* Should use HOWTO. */ |
| + microblaze_bfd_write_imm_value_64 (abfd, contents + irel->r_offset, |
| + irel->r_addend); |
| + } |
| + break; |
| case R_MICROBLAZE_NONE: |
| case R_MICROBLAZE_32_NONE: |
| { |
| diff --git a/bfd/libbfd.h b/bfd/libbfd.h |
| index a01891f3423..4e71991273e 100644 |
| --- a/bfd/libbfd.h |
| +++ b/bfd/libbfd.h |
| @@ -2905,7 +2905,9 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", |
| "BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM", |
| "BFD_RELOC_MICROBLAZE_32_NONE", |
| "BFD_RELOC_MICROBLAZE_64_NONE", |
| + "BFD_RELOC_MICROBLAZE_64", |
| "BFD_RELOC_MICROBLAZE_64_GOTPC", |
| + "BFD_RELOC_MICROBLAZE_64_GPC", |
| "BFD_RELOC_MICROBLAZE_64_GOT", |
| "BFD_RELOC_MICROBLAZE_64_PLT", |
| "BFD_RELOC_MICROBLAZE_64_GOTOFF", |
| diff --git a/bfd/reloc.c b/bfd/reloc.c |
| index 78f13180c71..8b3cc604738 100644 |
| --- a/bfd/reloc.c |
| +++ b/bfd/reloc.c |
| @@ -6814,12 +6814,24 @@ ENUMDOC |
| done here - only used for relaxing |
| ENUM |
| BFD_RELOC_MICROBLAZE_64_NONE |
| +ENUMDOC |
| + This is a 32 bit reloc that stores the 32 bit pc relative |
| + value in two words (with an imml instruction). No relocation is |
| + done here - only used for relaxing |
| +ENUM |
| + BFD_RELOC_MICROBLAZE_64 |
| ENUMDOC |
| This is a 64 bit reloc that stores the 32 bit pc relative |
| value in two words (with an imm instruction). No relocation is |
| done here - only used for relaxing |
| ENUM |
| BFD_RELOC_MICROBLAZE_64_GOTPC |
| +ENUMDOC |
| + This is a 64 bit reloc that stores the 32 bit pc relative |
| + value in two words (with an imml instruction). No relocation is |
| + done here - only used for relaxing |
| +ENUM |
| + BFD_RELOC_MICROBLAZE_64_GPC |
| ENUMDOC |
| This is a 64 bit reloc that stores the 32 bit pc relative |
| value in two words (with an imm instruction). The relocation is |
| diff --git a/include/elf/microblaze.h b/include/elf/microblaze.h |
| index 0dba2c0f44f..030eb99a1a0 100644 |
| --- a/include/elf/microblaze.h |
| +++ b/include/elf/microblaze.h |
| @@ -62,6 +62,8 @@ START_RELOC_NUMBERS (elf_microblaze_reloc_type) |
| RELOC_NUMBER (R_MICROBLAZE_TEXTREL_64, 31) /* TEXT Entry offset 64-bit. */ |
| RELOC_NUMBER (R_MICROBLAZE_TEXTREL_32_LO, 32) /* TEXT Entry offset 32-bit. */ |
| RELOC_NUMBER (R_MICROBLAZE_32_NONE, 33) |
| + RELOC_NUMBER (R_MICROBLAZE_IMML_64, 34) |
| + RELOC_NUMBER (R_MICROBLAZE_GPC_64, 35) /* GOT entry offset. */ |
| END_RELOC_NUMBERS (R_MICROBLAZE_max) |
| |
| /* Global base address names. */ |
| diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h |
| index 28dc991c430..46263bc7e16 100644 |
| --- a/opcodes/microblaze-opc.h |
| +++ b/opcodes/microblaze-opc.h |
| @@ -538,8 +538,8 @@ struct op_code_struct |
| {"llr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC8000300, OPCODE_MASK_H4, llr, memory_load_inst }, |
| {"sl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000100, OPCODE_MASK_H4, sl, memory_store_inst }, |
| {"slr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000300, OPCODE_MASK_H4, slr, memory_store_inst }, |
| - {"lli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE8000000, OPCODE_MASK_H, invalid_inst, memory_load_inst }, /* Identical to 32-bit */ |
| - {"sli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xF8000000, OPCODE_MASK_H, invalid_inst, memory_store_inst }, /* Identical to 32-bit */ |
| + {"lli", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xEC000000, OPCODE_MASK_H, invalid_inst, memory_load_inst }, /* Identical to 32-bit */ |
| + {"sli", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xFC000000, OPCODE_MASK_H, invalid_inst, memory_store_inst }, /* Identical to 32-bit */ |
| {"lla", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x30000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* lla translates to addlik */ |
| {"dadd", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000400, OPCODE_MASK_H4, dadd, arithmetic_inst }, |
| {"drsub", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000480, OPCODE_MASK_H4, drsub, arithmetic_inst }, |
| diff --git a/opcodes/microblaze-opcm.h b/opcodes/microblaze-opcm.h |
| index ad475a4af15..ee01cdb7d9b 100644 |
| --- a/opcodes/microblaze-opcm.h |
| +++ b/opcodes/microblaze-opcm.h |
| @@ -40,8 +40,8 @@ enum microblaze_instr |
| imm, rtsd, rtid, rtbd, rted, bri, brid, brlid, brai, braid, bralid, |
| brki, beqi, beqid, bnei, bneid, blti, bltid, blei, bleid, bgti, |
| bgtid, bgei, bgeid, lbu, lbuea, lbur, lhu, lhuea, lhur, lw, lwea, lwr, lwx, |
| - sb, sbea, sbr, sh, shea, shr, sw, swea, swr, swx, lbui, lhui, lwi, |
| - sbi, shi, swi, msrset, msrclr, tuqula, mbi_fadd, frsub, mbi_fmul, mbi_fdiv, |
| + sb, sbea, sbr, sh, shea, shr, sw, swea, swr, swx, lbui, lhui, lwi, lli, |
| + sbi, shi, sli, swi, msrset, msrclr, tuqula, mbi_fadd, frsub, mbi_fmul, mbi_fdiv, |
| fcmp_lt, fcmp_eq, fcmp_le, fcmp_gt, fcmp_ne, fcmp_ge, fcmp_un, flt, |
| fint, fsqrt, |
| tget, tcget, tnget, tncget, tput, tcput, tnput, tncput, |
| -- |
| 2.17.1 |
| |