[binutils-gdb] FT32: improve disassembly readability

James Bowman jamesbowman@sourceware.org
Thu Aug 31 02:53:00 GMT 2017


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=59e8523bf8f92db8371d3a10bd7e4d7fe03d417d

commit 59e8523bf8f92db8371d3a10bd7e4d7fe03d417d
Author: James Bowman <jamesb@excamera.com>
Date:   Wed Aug 30 19:51:49 2017 -0700

    FT32: improve disassembly readability
    
    For opcode fields that are not addresses, display as
    integers instead of using print_address_func.
    
    opcodes/ChangeLog:
    
    2017-08-31  James Bowman  <james.bowman@ftdichip.com>
    
    	* ft32-dis.c (print_insn_ft32): Correct display of non-address
    	fields.

Diff:
---
 opcodes/ChangeLog  |  5 +++++
 opcodes/ft32-dis.c | 19 ++++++++++++-------
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index e252089..1dc3a7b 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,3 +1,8 @@
+2017-08-31  James Bowman  <james.bowman@ftdichip.com>
+
+	* ft32-dis.c (print_insn_ft32): Correct display of non-address
+	fields.
+
 2017-08-23  Alexander Fedotov <alexander.fedotov@nxp.com>
 	    Edmar Wienskoski <edmar.wienskoski@nxp.com>
 
diff --git a/opcodes/ft32-dis.c b/opcodes/ft32-dis.c
index 0384073..93339a1 100644
--- a/opcodes/ft32-dis.c
+++ b/opcodes/ft32-dis.c
@@ -32,6 +32,13 @@ extern const ft32_opc_info_t ft32_opc_info[128];
 static fprintf_ftype fpr;
 static void *stream;
 
+static int
+sign_extend(int bit, int value)
+{
+  int onebit = (1 << bit);
+  return (value & (onebit - 1)) - (value & onebit);
+}
+
 int
 print_insn_ft32 (bfd_vma addr, struct disassemble_info *info)
 {
@@ -118,7 +125,7 @@ print_insn_ft32 (bfd_vma addr, struct disassemble_info *info)
               case  FT32_FLD_RIMM:
                 imm = (iword >> FT32_FLD_RIMM_BIT) & ((1 << FT32_FLD_RIMM_SIZ) - 1);
                 if (imm & 0x400)
-                  info->print_address_func ((bfd_vma) imm & 0x3ff, info);
+                  fpr(stream, "%d", sign_extend(9, imm));
                 else
                   fpr(stream, "$r%d", imm & 0x1f);
                 break;
@@ -127,7 +134,7 @@ print_insn_ft32 (bfd_vma addr, struct disassemble_info *info)
                 break;
               case  FT32_FLD_K20:
                 imm = iword & ((1 << FT32_FLD_K20_SIZ) - 1);
-                info->print_address_func ((bfd_vma) imm, info);
+                fpr(stream, "%d", sign_extend(19, imm));
                 break;
               case  FT32_FLD_PA:
                 imm = (iword & ((1 << FT32_FLD_PA_SIZ) - 1)) << 2;
@@ -135,17 +142,15 @@ print_insn_ft32 (bfd_vma addr, struct disassemble_info *info)
                 break;
               case  FT32_FLD_AA:
                 imm = iword & ((1 << FT32_FLD_AA_SIZ) - 1);
-                info->print_address_func ((bfd_vma) imm, info);
-                break;
+                info->print_address_func ((1 << 23) | (bfd_vma) imm, info);
                 break;
               case  FT32_FLD_K16:
                 imm = iword & ((1 << FT32_FLD_K16_SIZ) - 1);
-                info->print_address_func ((bfd_vma) imm, info);
+                fpr(stream, "%d", imm);
                 break;
               case  FT32_FLD_K8:
                 imm = iword & ((1 << FT32_FLD_K8_SIZ) - 1);
-                info->print_address_func ((bfd_vma) imm, info);
-                break;
+                fpr(stream, "%d", sign_extend(7, imm));
                 break;
               case  FT32_FLD_R_D_POST:
                 fpr(stream, "$r%d", (iword >> FT32_FLD_R_D_BIT) & 0x1f);



More information about the Binutils-cvs mailing list