Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStanislav Yakovlev2014-03-13 02:13:43 +0000
committerEugene Tarassov2014-03-13 17:32:09 +0000
commitb499238272e9d68b67bc1757aab256802f05f6cb (patch)
tree4835be1612e47d2881660f91fe1c0d8b603a4dae
parent6120844e2bbbd327d583c901b9504dbd1bef42b1 (diff)
downloadorg.eclipse.tcf.agent-b499238272e9d68b67bc1757aab256802f05f6cb.tar.gz
org.eclipse.tcf.agent-b499238272e9d68b67bc1757aab256802f05f6cb.tar.xz
org.eclipse.tcf.agent-b499238272e9d68b67bc1757aab256802f05f6cb.zip
TCF Agent: PowerPC disassembler: added pretty printing facilities
Borrowed from ARM disassembler with minimal changes. Signed-off-by: Stanislav Yakovlev <stas.yakovlev@gmail.com>
-rw-r--r--agent/machine/powerpc/tcf/disassembler-powerpc.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/agent/machine/powerpc/tcf/disassembler-powerpc.c b/agent/machine/powerpc/tcf/disassembler-powerpc.c
index bbd5f9a8..35ec6db0 100644
--- a/agent/machine/powerpc/tcf/disassembler-powerpc.c
+++ b/agent/machine/powerpc/tcf/disassembler-powerpc.c
@@ -18,6 +18,38 @@
#include <machine/powerpc/tcf/disassembler-powerpc.h>
static char buf[128];
+static size_t buf_pos = 0;
+
+static void add_char(char ch) {
+ if (buf_pos >= sizeof(buf) - 1) return;
+ buf[buf_pos++] = ch;
+ if (ch == ' ') while (buf_pos < 8) buf[buf_pos++] = ch;
+}
+
+static void add_str(const char * s) {
+ while (*s) add_char(*s++);
+}
+
+static void add_dec_uint8(uint8_t n) {
+ char buf[32];
+
+ snprintf(buf, sizeof(buf), "%u", (unsigned int)n);
+ add_str(buf);
+}
+
+static void add_dec_int16(int16_t n) {
+ char buf[32];
+
+ snprintf(buf, sizeof(buf), "%d", (int)n);
+ add_str(buf);
+}
+
+static void add_hex_uint16(uint16_t n) {
+ char buf[32];
+
+ snprintf(buf, sizeof(buf), "0x%.4x", (unsigned int)n);
+ add_str(buf);
+}
DisassemblyResult * disassemble_powerpc(uint8_t * code,
ContextAddress addr, ContextAddress size, DisassemblerParams * params) {
@@ -27,6 +59,7 @@ DisassemblyResult * disassemble_powerpc(uint8_t * code,
if (size < 4) return NULL;
memset(&dr, 0, sizeof(dr));
dr.size = 4;
+ buf_pos = 0;
instr = code[0];
instr <<= 8;

Back to the top