[linux-unicore] [RFC binutils/opcodes 2/3] Assemble function for Unicore32.

  • From: LIU Zhiyou <liuzhiyou.cs@xxxxxxxxx>
  • To: linux-unicore@xxxxxxxxxxxxx
  • Date: Tue, 25 Dec 2012 23:56:01 +0800

It may be too naive when handling endian problem and not using
binutils-predefined data type. It just uses to show how it does
disassemble in the current design.

Signed-off-by: LIU Zhiyou <liuzhiyou.cs@xxxxxxxxx>
---
 opcodes/unicore32-dis.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
 create mode 100644 opcodes/unicore32-dis.c

diff --git a/opcodes/unicore32-dis.c b/opcodes/unicore32-dis.c
new file mode 100644
index 0000000..dc90f47
--- /dev/null
+++ b/opcodes/unicore32-dis.c
@@ -0,0 +1,70 @@
+/* Assemble and disassemble functions for UniCore32 processor
+   Copyright 2007, 2008, 2009, 2012  Free Software Foundation, Inc.
+   Contributed by LIU Zhiyou (liuzhiyou.cs@xxxxxxxxx).
+
+   This file is part of GAS, GDB and the GNU binutils.
+
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by the
+   Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+   more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include "sysdep.h"
+#include "opcode/unicore32.h"
+
+#define ILLEGAL  "illegal"
+
+/* Retrieve a single word from a given memory address.  */
+static unsigned long
+get_word_at (bfd_vma memaddr, struct disassemble_info *info)
+{
+    bfd_byte buffer[4];
+    int status;
+    unsigned long insn = 0;
+
+    status = info->read_memory_func (memaddr, buffer, 4, info);
+
+    if (status == 0)
+        insn = (unsigned long) bfd_getl32 (buffer);
+
+    return insn;
+}
+
+int
+print_insn_unicore32 (bfd_vma memaddr, struct disassemble_info *info)
+{
+    unsigned long raw = get_word_at(memaddr, info);
+  
+    int ninst_type = sizeof(inst_types)/sizeof(inst_type);
+    int i = 0, j;
+    for (i = 0; i < ninst_type; i++) 
+        if ((inst_types[i].mask & raw) == inst_types[i].expect) {
+            /* Initialize */
+            inst ainst; 
+            ainst.raw = raw;
+            ainst.type = inst_types+i;
+            for (j = 0; j < MAX_ARG && ainst.type.args[j].init; j++)
+                ainst.type.args[j].init(&ainst, ainst.args+j);
+            
+            /* Disassembler */
+            ainst.type.print(&ainst, info);
+            for (j = 0; j < MAX_ARG && ainst.type.args[j].init; j++) {
+                info->fprintf_func(info->stream, " ");
+                ainst.type.args[j].print_arg(&ainst, &ainst.args[j], info);
+            }
+            return 0;
+        }
+
+    /* No match found.  */
+    info->fprintf_func (info->stream,"%s ",ILLEGAL);
+    return 2;
+}
-- 
1.8.0.2


Other related posts:

  • » [linux-unicore] [RFC binutils/opcodes 2/3] Assemble function for Unicore32. - LIU Zhiyou