This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
[patch] h8 disassembler/simulator unification
- To: gdb-patches at sourceware dot cygnus dot com
- Subject: [patch] h8 disassembler/simulator unification
- From: Kazu Hirata <kazu at hxi dot com>
Hi,
Attached is a patch that sort of unifies H8/300[HS] disassembler and
simulator. All it does is to fix formatting.
The real purpose of submitting the "formatting-only" patch is to
reduce white-space differences between bfd_h8_disassemble () in
opcodes/h8300-dis.c and compile () in sim/h8300/compile.c so that I
can use "diff" to compare the above two functions without seeing
meaningless differences like white-space differences.
The reason for wanting to compare them is because there is a chain of
bugs in the simulator. That is, fixing one breaks another thing, and
fixing that breaks yet another thing. At a grance, the cause seems to
come from the fact that the opcode-interpretation part of compile.c
has not kept up with that of h8300-dis.c.
So, if you could, please apply the patch below so that people can
confortably work on the real bug fix. I'll post a bug report
separately.
Thanks,
Kazu Hirata
===File ~/h8300-hms/gdb/ChangeLog-h8300-dis=================
2000-06-04 Kazu Hirata <kazu@hxi.com>
* h8300-dis.c: Fix formatting.
============================================================
===File ~/h8300-hms/gdb/ChangeLog-compile===================
2000-06-04 Kazu Hirata <kazu@hxi.com>
* compile.c: Fix formatting.
============================================================
===File ~/h8300-hms/gdb/h8-unify.patch======================
Index: opcodes/h8300-dis.c
===================================================================
RCS file: /cvs/src/src/opcodes/h8300-dis.c,v
retrieving revision 1.5
diff -u -r1.5 h8300-dis.c
--- h8300-dis.c 2000/06/02 18:09:28 1.5
+++ h8300-dis.c 2000/06/04 17:06:21
@@ -23,7 +23,6 @@
#include "dis-asm.h"
#include "opintl.h"
-
/* Run through the opcodes and sort them into order to make them easy
to disassemble. */
static void
@@ -41,7 +40,7 @@
n1 = (int) p->data.nib[0];
else
n1 = 0;
-
+
if ((int) p->data.nib[1] < 16)
n2 = (int) p->data.nib[1];
else
@@ -50,16 +49,15 @@
/* Just make sure there are an even number of nibbles in it, and
that the count is the same as the length. */
for (i = 0; p->data.nib[i] != E; i++)
- /*EMPTY*/;
-
+ ;
+
if (i & 1)
abort ();
-
+
p->length = i / 2;
}
}
-
unsigned int
bfd_h8_disassemble (addr, info, mode)
bfd_vma addr;
@@ -109,9 +107,9 @@
info->memory_error_func (status, addr, info);
return -1;
}
-
+
for (l = 2; status == 0 && l < 10; l += 2)
- status = info->read_memory_func (addr + l, data+l, 2, info);
+ status = info->read_memory_func (addr + l, data + l, 2, info);
/* Find the exact opcode/arg combo. */
while (q->name)
@@ -120,14 +118,14 @@
unsigned int len = 0;
nib = q->data.nib;
-
+
while (1)
{
op_type looking_for = *nib;
int thisnib = data[len >> 1];
-
+
thisnib = (len & 1) ? (thisnib & 0xf) : ((thisnib >> 4) & 0xf);
-
+
if (looking_for < 16 && looking_for >= 0)
{
if (looking_for != thisnib)
@@ -137,17 +135,17 @@
{
if ((int) looking_for & (int) B31)
{
- if (! (((int) thisnib & 0x8) != 0))
+ if (!(((int) thisnib & 0x8) != 0))
goto fail;
-
+
looking_for = (op_type) ((int) looking_for & ~(int) B31);
}
-
+
if ((int) looking_for & (int) B30)
{
if (!(((int) thisnib & 0x8) == 0))
goto fail;
-
+
looking_for = (op_type) ((int) looking_for & ~(int) B30);
}
@@ -155,7 +153,7 @@
{
if ((looking_for & 2) != (thisnib & 2))
goto fail;
-
+
abs = (thisnib & 0x8) ? 2 : 1;
}
else if (looking_for & (REG | IND | INC | DEC))
@@ -181,18 +179,18 @@
else if (looking_for & L_32)
{
int i = len >> 1;
-
+
abs = (data[i] << 24)
| (data[i + 1] << 16)
| (data[i + 2] << 8)
- | (data[i+ 3]);
+ | (data[i + 3]);
plen = 32;
}
else if (looking_for & L_24)
{
int i = len >> 1;
-
+
abs = (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]);
plen = 24;
}
@@ -245,10 +243,10 @@
for (i = 0; i < q->length; i++)
fprintf (stream, "%02x ", data[i]);
-
+
for (; i < 6; i++)
fprintf (stream, " ");
-
+
fprintf (stream, "%s\t", q->name);
/* Gross. Disgusting. */
@@ -282,7 +280,7 @@
while (*args != E)
{
int x = *args;
-
+
if (hadone)
fprintf (stream, ",");
@@ -301,7 +299,7 @@
else if (x & REG)
{
int rn = (x & DST) ? rd : rs;
-
+
switch (x & SIZE)
{
case L_8:
@@ -351,20 +349,22 @@
{
abs += 2;
fprintf (stream,
- ".%s%d (%x)", (short) abs > 0 ? "+" : "",
+ ".%s%d (%x)",
+ (short) abs > 0 ? "+" : "",
(short) abs, addr + (short) abs + 2);
}
else
{
fprintf (stream,
- ".%s%d (%x)", (char) abs > 0 ? "+" : "",
+ ".%s%d (%x)",
+ (char) abs > 0 ? "+" : "",
(char) abs, addr + (char) abs + 2);
}
}
else if (x & DISP)
{
fprintf (stream, "@(0x%x:%d,%s)",
- abs,plen, pregnames[rdisp]);
+ abs, plen, pregnames[rdisp]);
}
else if (x & CCR)
{
@@ -377,23 +377,23 @@
else
/* xgettext:c-format */
fprintf (stream, _("Hmmmm %x"), x);
-
+
hadone = 1;
args++;
}
}
-
+
return q->length;
}
else
/* xgettext:c-format */
fprintf (stream, _("Don't understand %x \n"), looking_for);
}
-
+
len++;
nib++;
}
-
+
fail:
q++;
}
Index: sim/h8300/compile.c
===================================================================
RCS file: /cvs/src/src/sim/h8300/compile.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 compile.c
--- compile.c 1999/04/26 18:32:21 1.1.1.2
+++ compile.c 2000/06/04 17:06:23
@@ -181,7 +181,7 @@
int size = 0;
dst->dst.type = -1;
dst->src.type = -1;
- /* Find the exact opcode/arg combo */
+ /* Find the exact opcode/arg combo. */
while (q->name)
{
op_type *nib;
@@ -207,40 +207,37 @@
{
if (!(((int) thisnib & 0x8) != 0))
goto fail;
- looking_for = (op_type) ((int) looking_for & ~(int)
- B31);
+
+ looking_for = (op_type) ((int) looking_for & ~(int) B31);
thisnib &= 0x7;
}
+
if ((int) looking_for & (int) B30)
{
if (!(((int) thisnib & 0x8) == 0))
goto fail;
+
looking_for = (op_type) ((int) looking_for & ~(int) B30);
}
+
if (looking_for & DBIT)
{
if ((looking_for & 5) != (thisnib & 5))
goto fail;
+
abs = (thisnib & 0x8) ? 2 : 1;
}
else if (looking_for & (REG | IND | INC | DEC))
{
if (looking_for & REG)
{
- /*
- * Can work out size from the
- * register
- */
+ /* Can work out size from the register. */
size = bitfrom (looking_for);
}
if (looking_for & SRC)
- {
- rs = thisnib;
- }
+ rs = thisnib;
else
- {
- rd = thisnib;
- }
+ rd = thisnib;
}
else if (looking_for & L_16)
{
@@ -253,10 +250,7 @@
}
else if (looking_for & ABSJMP)
{
- abs =
- (data[1] << 16)
- | (data[2] << 8)
- | (data[3]);
+ abs = (data[1] << 16) | (data[2] << 8) | (data[3]);
}
else if (looking_for & MEMIND)
{
@@ -265,6 +259,7 @@
else if (looking_for & L_32)
{
int i = len >> 1;
+
abs = (data[i] << 24)
| (data[i + 1] << 16)
| (data[i + 2] << 8)
@@ -275,12 +270,13 @@
else if (looking_for & L_24)
{
int i = len >> 1;
+
abs = (data[i] << 16) | (data[i + 1] << 8) | (data[i + 2]);
plen = 24;
}
else if (looking_for & IGNORE)
{
- /* nothing to do */
+ ;
}
else if (looking_for & DISPREG)
{
@@ -330,7 +326,7 @@
{
dst->op = q;
- /* Fill in the args */
+ /* Fill in the args. */
{
op_type *args = q->args.nib;
int hadone = 0;
@@ -342,15 +338,11 @@
ea_type *p;
if (x & DST)
- {
- p = &(dst->dst);
- }
+ p = &(dst->dst);
else
- {
- p = &(dst->src);
- }
+ p = &(dst->src);
- if (x & (L_3))
+ if (x & L_3)
{
p->type = X (OP_IMM, size);
p->literal = bit;
@@ -362,8 +354,8 @@
}
else if (x & REG)
{
- /* Reset the size, some
- ops (like mul) have two sizes */
+ /* Reset the size, some ops (like mul)
+ have two sizes. */
size = bitfrom (x);
p->type = X (OP_REG, size);
@@ -425,12 +417,9 @@
}
}
- /*
- * But a jmp or a jsr gets
- * automagically lvalued, since we
- * branch to their address not their
- * contents
- */
+ /* But a jmp or a jsr gets automagically lvalued,
+ since we branch to their address not their
+ contents. */
if (q->how == O (O_JSR, SB)
|| q->how == O (O_JMP, SB))
{
@@ -457,9 +446,7 @@
return;
}
else
- {
- printf ("Dont understand %x \n", looking_for);
- }
+ printf ("Dont understand %x \n", looking_for);
}
len++;
@@ -470,9 +457,9 @@
q++;
}
+ /* Fell off the end. */
dst->opcode = O (O_ILL, SB);
}
-
static void
compile (pc)
============================================================