diff options
author | Kuan-Lin Chen <kuanlinchentw@gmail.com> | 2015-01-29 15:49:02 +0800 |
---|---|---|
committer | Kuan-Lin Chen <kuanlinchentw@gmail.com> | 2015-01-29 16:29:42 +0800 |
commit | ea16498d5a740e2888feb2f8bce92d9565baf244 (patch) | |
tree | 6011e41ba6f6daf9eb0258ae19ad385ebfde5a6d /gas/config/tc-nds32.c | |
parent | 3d7ad9b42685b426329370cdb8bebc9cda6d8911 (diff) | |
download | gdb-ea16498d5a740e2888feb2f8bce92d9565baf244.zip gdb-ea16498d5a740e2888feb2f8bce92d9565baf244.tar.gz gdb-ea16498d5a740e2888feb2f8bce92d9565baf244.tar.bz2 |
NDS32: Set branch instruction to relaxable.
Relaxable fragments can be relaxed when there are alignment requirements.
Besides, insert a dummy fragment in the final to make sure that all
alignment is traversed. Finally, convert these fragments
in md_convert_frag with relax_table.
Diffstat (limited to 'gas/config/tc-nds32.c')
-rw-r--r-- | gas/config/tc-nds32.c | 426 |
1 files changed, 265 insertions, 161 deletions
diff --git a/gas/config/tc-nds32.c b/gas/config/tc-nds32.c index bf537b2..06e419d 100644 --- a/gas/config/tc-nds32.c +++ b/gas/config/tc-nds32.c @@ -140,19 +140,19 @@ static relax_info_t relax_table[] = {4, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { @@ -221,25 +221,25 @@ static relax_info_t relax_table[] = {4, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGCALL5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGCALL6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, {4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR}, @@ -306,25 +306,25 @@ static relax_info_t relax_table[] = {4, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGCALL5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGCALL6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, {4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR}, @@ -371,19 +371,19 @@ static relax_info_t relax_table[] = {2, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 2, 0, BFD_RELOC_NDS32_9_PCREL}, + {0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { @@ -432,19 +432,19 @@ static relax_info_t relax_table[] = {2, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 2, 0, BFD_RELOC_NDS32_9_PCREL}, + {0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { @@ -513,28 +513,28 @@ static relax_info_t relax_table[] = {4, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 4, NDS32_INSN16 , BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, @@ -602,25 +602,25 @@ static relax_info_t relax_table[] = {4, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, {4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR}, @@ -687,28 +687,28 @@ static relax_info_t relax_table[] = {4, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 4, NDS32_INSN16 , BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, @@ -776,25 +776,25 @@ static relax_info_t relax_table[] = {4, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, {4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR}, @@ -861,25 +861,25 @@ static relax_info_t relax_table[] = {4, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, {4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR}, @@ -946,25 +946,25 @@ static relax_info_t relax_table[] = {4, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, {4, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_PTR}, @@ -1038,33 +1038,33 @@ static relax_info_t relax_table[] = {4, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 4, 0, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_ABS, BFD_RELOC_NDS32_EMPTY}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, @@ -1139,32 +1139,32 @@ static relax_info_t relax_table[] = {4, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 4, 0, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, @@ -1232,27 +1232,27 @@ static relax_info_t relax_table[] = {2, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 2, 0, BFD_RELOC_NDS32_9_PCREL}, + {0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, @@ -1320,27 +1320,27 @@ static relax_info_t relax_table[] = {2, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 2, 0, BFD_RELOC_NDS32_9_PCREL}, + {0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, @@ -1390,27 +1390,27 @@ static relax_info_t relax_table[] = {2, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 2, 0, BFD_RELOC_NDS32_9_PCREL}, + {0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, @@ -1460,27 +1460,27 @@ static relax_info_t relax_table[] = {2, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 2, 0, BFD_RELOC_NDS32_9_PCREL}, + {0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, 0, BFD_RELOC_NDS32_17_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_17_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, @@ -1549,31 +1549,31 @@ static relax_info_t relax_table[] = {2, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 2, 0, BFD_RELOC_NDS32_9_PCREL}, + {0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, @@ -1642,31 +1642,31 @@ static relax_info_t relax_table[] = {2, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 2, 0, BFD_RELOC_NDS32_9_PCREL}, + {0, 2, NDS32_PCREL, BFD_RELOC_NDS32_9_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { - {0, 4, 0, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP5}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {4, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_15_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP6}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, @@ -1742,27 +1742,27 @@ static relax_info_t relax_table[] = {4, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 4, 0, BFD_RELOC_NDS32_WORD_9_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP7}, - {4, 4, 0, BFD_RELOC_NDS32_15_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_WORD_9_PCREL}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_WORD_9_PCREL}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_WORD_9_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, {8, 4, 0, BFD_RELOC_NDS32_LO12S0_ORI}, {12, 4, NDS32_INSN16, BFD_RELOC_NDS32_INSN16}, @@ -1832,27 +1832,27 @@ static relax_info_t relax_table[] = {4, 4, 4, 4, 4}, /* relax_branch_isize */ { { - {0, 4, 0, BFD_RELOC_NDS32_WORD_9_PCREL}, + {0, 4, NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S256 */ { {0, 4, NDS32_INSN16 | NDS32_HINT, BFD_RELOC_NDS32_INSN16}, {0, 4, NDS32_PTR | NDS32_HINT, BFD_RELOC_NDS32_LONGJUMP7}, - {4, 4, 0, BFD_RELOC_NDS32_15_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_15_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_WORD_9_PCREL}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S64K */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_WORD_9_PCREL}, - {4, 4, 0, BFD_RELOC_NDS32_25_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL}, + {4, 4, NDS32_PCREL, BFD_RELOC_NDS32_25_PCREL}, {0, 0, 0, 0} }, /* BR_RANGE_S16M */ { - {0, 4, NDS32_CREATE_LABEL, BFD_RELOC_NDS32_WORD_9_PCREL}, + {0, 4, NDS32_CREATE_LABEL | NDS32_PCREL, BFD_RELOC_NDS32_WORD_9_PCREL}, {4, 4, 0, BFD_RELOC_NDS32_HI20}, {8, 4, 0, BFD_RELOC_NDS32_LO12S0_ORI}, {12, 4, NDS32_INSN16, BFD_RELOC_NDS32_INSN16}, @@ -2139,7 +2139,9 @@ static struct hash_control *nds32_pseudo_opcode_hash = NULL; static int builtin_isreg (const char *s, const char *x ATTRIBUTE_UNUSED) { - return s[0] == '$'; + if (s [0] == '$' && hash_find (nds32_gprs_hash, (s + 1))) + return 1; + return 0; } static int @@ -2591,16 +2593,18 @@ do_pseudo_move (int argc ATTRIBUTE_UNUSED, char *argv[], int pv ATTRIBUTE_UNUSED { expressionS exp; - parse_expression (argv[1], &exp); - if (builtin_isreg (argv[1], NULL)) do_pseudo_move_reg_internal (argv[0], argv[1]); - else if (exp.X_op == O_constant) - /* move $rt, imm -> li $rt, imm */ - do_pseudo_li_internal (argv[0], exp.X_add_number); else - /* l.w $rt, var -> l.w $rt, var */ - do_pseudo_ls_bhw (argc, argv, 2); + { + parse_expression (argv[1], &exp); + if (exp.X_op == O_constant) + /* move $rt, imm -> li $rt, imm */ + do_pseudo_li_internal (argv[0], exp.X_add_number); + else + /* l.w $rt, var -> l.w $rt, var */ + do_pseudo_ls_bhw (argc, argv, 2); + } } static void @@ -3891,6 +3895,7 @@ nds32_pre_do_align (int n, char *fill, int len, int max) { if (subseg_text_p (now_seg)) { + dwarf2_emit_insn (0); fragP = frag_now; frag_align_code (n, max); @@ -4922,6 +4927,7 @@ nds32_elf_append_relax_relocs (const char *key ATTRIBUTE_UNUSED, void *value) unsigned int ptr_offset, hint_count, relax_code_size, count = 0; uint32_t *code_seq, code_insn; char *where; + int pcrel; if (!relocs_pattern) return; @@ -5002,6 +5008,7 @@ nds32_elf_append_relax_relocs (const char *key ATTRIBUTE_UNUSED, void *value) { /* Set the real instruction size in element. */ fixup_size = pattern_now->opcode->isize; + pcrel = ((fixup_now->ramp & NDS32_PCREL) != 0) ? 1 : 0; if (fixup_now->ramp & NDS32_FIX) { /* Convert original relocation. */ @@ -5075,8 +5082,8 @@ nds32_elf_append_relax_relocs (const char *key ATTRIBUTE_UNUSED, void *value) if (fixup_size != 0) { - fixP = fix_new_exp (fragP, where - fragP->fr_literal, - fixup_size, &exp, 0, fixup_now->r_type); + fixP = fix_new_exp (fragP, where - fragP->fr_literal, fixup_size, + &exp, pcrel, fixup_now->r_type); fixP->fx_addnumber = fixP->fx_offset; } fixup_now++; @@ -5170,6 +5177,7 @@ md_assemble (char *str) label_exist = 0; insn.info = (expressionS *) alloca (sizeof (expressionS)); + asm_desc.result = NASM_OK; nds32_assemble (&asm_desc, &insn, str); switch (asm_desc.result) @@ -5181,7 +5189,7 @@ md_assemble (char *str) as_bad (_("Incorrect syntax, %s."), str); return; case NASM_ERR_OPERAND: - as_bad (_("Unrecognized operand, %s."), str); + as_bad (_("Unrecognized operand/register, %s."), str); return; case NASM_ERR_OUT_OF_RANGE: as_bad (_("Operand out of range, %s."), str); @@ -5247,18 +5255,28 @@ md_assemble (char *str) return; /* md_convert_frag will insert relocations. */ } - else if (!fld && !relaxing && enable_16bit && (optimize || optimize_for_space) - && ((!verbatim && insn.opcode->isize == 4 + else if (!relaxing && enable_16bit && (optimize || optimize_for_space) + && ((!fld && !verbatim && insn.opcode->isize == 4 && nds32_convert_32_to_16 (stdoutput, insn.insn, &insn_16, NULL)) || (insn.opcode->isize == 2 && nds32_convert_16_to_32 (stdoutput, insn.insn, NULL)))) { /* Record this one is relaxable. */ + pexp = insn.info; dwarf2_emit_insn (0); - out = frag_var (rs_machine_dependent, - 4, /* Max size is 32-bit instruction. */ - 0, /* VAR is un-used. */ - 0, NULL, 0, NULL); + if (fld) + { + out = frag_var (rs_machine_dependent, + 4, /* Max size is 32-bit instruction. */ + 0, /* VAR is un-used. */ + 0, pexp->X_add_symbol, pexp->X_add_number, 0); + fragP->tc_frag_data.flag |= NDS32_FRAG_RELAXABLE_BRANCH; + } + else + out = frag_var (rs_machine_dependent, + 4, /* Max size is 32-bit instruction. */ + 0, /* VAR is un-used. */ + 0, NULL, 0, NULL); fragP->tc_frag_data.flag |= NDS32_FRAG_RELAXABLE; fragP->tc_frag_data.opcode = insn.opcode; fragP->tc_frag_data.insn = insn.insn; @@ -5292,7 +5310,10 @@ md_assemble (char *str) exp.X_op = O_symbol; exp.X_add_symbol = abs_section_sym; exp.X_add_number = 0; - fixP = fix_new_exp (fragP, 0, 0, &exp, 0, BFD_RELOC_NDS32_LABEL); + fixP = fix_new_exp (fragP, fragP->fr_fix - 4, 0, &exp, + 0, BFD_RELOC_NDS32_LABEL); + if (!verbatim) + fragP->tc_frag_data.flag = NDS32_FRAG_ALIGN; } } else @@ -5638,6 +5659,22 @@ invalid_prev_frag (fragS * fragP, fragS **prev_frag) } frag_t = frag_t->fr_next; } + + if (fragP->tc_frag_data.flag & NDS32_FRAG_ALIGN) + { + address = fragP->fr_address; + addressT offset = nds32_get_align (address, 2); + if (offset & 0x2) + { + /* If there is label on the prev_frag, check if it is aligned. */ + if (!((*prev_frag)->tc_frag_data.flag & NDS32_FRAG_LABEL) + || (((*prev_frag)->fr_address + (*prev_frag)->fr_fix - 2 ) + & 0x2) == 0) + nds32_adjust_relaxable_frag (*prev_frag, fragP); + } + *prev_frag = NULL; + return; + } } /* md_relax_frag */ @@ -5723,7 +5760,6 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec, fragS *fragP) enum nds32_br_range branch_range_type = fragP->fr_subtype; struct nds32_opcode *opcode = fragP->tc_frag_data.opcode; uint32_t origin_insn = fragP->tc_frag_data.insn; - int backup_endian; relax_info_t *relax_info; char *fr_buffer; int fr_where; @@ -5734,7 +5770,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec, fragS *fragP) uint32_t *code_seq; uint32_t insn; int code_size, insn_size, offset, fixup_size; - int buf_offset; + int buf_offset, pcrel; int i, k; uint16_t insn_16; nds32_relax_fixup_info_t fixup_info[MAX_RELAX_FIX]; @@ -5750,10 +5786,48 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec, fragS *fragP) if (opcode == NULL) return; - /* Relax the insntruction. */ - if (fragP->tc_frag_data.flag & NDS32_FRAG_RELAXED) + if (fragP->tc_frag_data.flag & NDS32_FRAG_RELAXABLE_BRANCH) + { + relax_info = hash_find (nds32_relax_info_hash, opcode->opcode); + + if (relax_info == NULL) + return; + + i = BR_RANGE_S256; + while (i < BR_RANGE_NUM + && relax_info->relax_code_size[i] + != (fragP->tc_frag_data.flag & NDS32_FRAG_RELAXED ? 4 : 2)) + i++; + + if (i >= BR_RANGE_NUM) + as_bad ("Internal error: Cannot find relocation of" + "relaxable branch."); + + exp.X_op = O_symbol; + exp.X_add_symbol = branch_symbol; + exp.X_add_number = branch_offset; + pcrel = ((relax_info->relax_fixup[i][0].ramp & NDS32_PCREL) != 0) ? 1 : 0; + fr_where = fragP->fr_fix - 2; + fixP = fix_new_exp (fragP, fr_where, relax_info->relax_fixup[i][0].size, + &exp, pcrel, relax_info->relax_fixup[i][0].r_type); + fixP->fx_addnumber = fixP->fx_offset; + + if (fragP->tc_frag_data.flag & NDS32_FRAG_RELAXED) + { + insn_16 = fragP->tc_frag_data.insn; + nds32_convert_16_to_32 (stdoutput, insn_16, &insn); + fr_buffer = fragP->fr_literal + fr_where; + fragP->fr_fix += 2; + exp.X_op = O_symbol; + exp.X_add_symbol = abs_section_sym; + exp.X_add_number = 0; + fix_new_exp (fragP, fr_where, 4, + &exp, 0, BFD_RELOC_NDS32_INSN16); + number_to_chars_bigendian (fr_buffer, insn, 4); + } + } + else if (fragP->tc_frag_data.flag & NDS32_FRAG_RELAXED) { - expressionS exp_t; if (fragP->tc_frag_data.opcode->isize == 2) { insn_16 = fragP->tc_frag_data.insn; @@ -5764,14 +5838,14 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec, fragS *fragP) fragP->fr_fix += 2; fr_where = fragP->fr_fix - 4; fr_buffer = fragP->fr_literal + fr_where; - exp_t.X_op = O_symbol; - exp_t.X_add_symbol = abs_section_sym; - exp_t.X_add_number = 0; - fix_new_exp (fragP, fr_where, 4, &exp_t, 0, + exp.X_op = O_symbol; + exp.X_add_symbol = abs_section_sym; + exp.X_add_number = 0; + fix_new_exp (fragP, fr_where, 4, &exp, 0, BFD_RELOC_NDS32_INSN16); number_to_chars_bigendian (fr_buffer, insn, 4); } - else + else if (fragP->tc_frag_data.flag & NDS32_FRAG_BRANCH) { /* Branch instruction adjust and append relocations. */ relax_info = hash_find (nds32_relax_info_hash, opcode->opcode); @@ -5779,9 +5853,6 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec, fragS *fragP) if (relax_info == NULL) return; - backup_endian = target_big_endian; - target_big_endian = 1; - fr_where = fragP->fr_fix - opcode->isize; fr_buffer = fragP->fr_literal + fr_where; @@ -5835,7 +5906,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec, fragS *fragP) && relax_info->relax_fixup[branch_range_type][k].offset < offset) k++; - md_number_to_chars (fr_buffer + buf_offset, insn, insn_size); + number_to_chars_bigendian (fr_buffer + buf_offset, insn, insn_size); buf_offset += insn_size; offset += insn_size; @@ -5848,6 +5919,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec, fragS *fragP) for (i = 0; fixup_info[i].size != 0; i++) { fixup_size = fixup_info[i].size; + pcrel = ((fixup_info[i].ramp & NDS32_PCREL) != 0) ? 1 : 0; if ((fixup_info[i].ramp & NDS32_CREATE_LABEL) != 0) { @@ -5885,14 +5957,13 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec, fragS *fragP) if (fixup_info[i].r_type != 0) { fixP = fix_new_exp (fragP, fr_where + fixup_info[i].offset, - fixup_size, &exp, 0, fixup_info[i].r_type); + fixup_size, &exp, pcrel, + fixup_info[i].r_type); fixP->fx_addnumber = fixP->fx_offset; } } fragP->fr_fix = fr_where + buf_offset; - - target_big_endian = backup_endian; } } @@ -6157,9 +6228,42 @@ nds32_elf_analysis_relax_hint (void) hash_traverse (nds32_hint_hash, nds32_elf_append_relax_relocs); } +static void +nds32_elf_insert_final_frag (void) +{ + struct frchain *frchainP; + asection *s; + fragS *fragP; + + if (!optimize) + return; + + for (s = stdoutput->sections; s; s = s->next) + { + segment_info_type *seginfo = seg_info (s); + if (!seginfo) + continue; + + for (frchainP = seginfo->frchainP; frchainP != NULL; + frchainP = frchainP->frch_next) + { + subseg_set (s, frchainP->frch_subseg); + + if (subseg_text_p (now_seg)) + { + fragP = frag_now; + frag_var (rs_machine_dependent, 2, /* Max size. */ + 0, /* VAR is un-used. */ 0, NULL, 0, NULL); + fragP->tc_frag_data.flag |= NDS32_FRAG_FINAL; + } + } + } +} + void md_end (void) { + nds32_elf_insert_final_frag (); nds32_elf_analysis_relax_hint (); bfd_map_over_sections (stdoutput, nds32_insert_leb128_fixes, NULL); } |