This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[patch] sim/h8300/compile.c


Hi,

Attached is a patch for sim/h8300/compile.c.  It fixes a bug that
causes the following insns to be incorrectly distinguished.

0b 50 inc.w #1,r0
0b d0 inc.w #2,r0
0b 70 inc.l #1,er0
0b f0 inc.l #2,er0
0b 00 adds  #1,er0
0b 80 adds  #2,er0
0b 90 adds  #4,er0

The register operands have nothing to do with the bug.  As you can see
from the above, the third nibble is very important to distinguish adds
from inc.[wl].

When the opcode interpreter looks at each nibble, "looking_for" has
"DBIT" in case of inc.[wl] and "KBIT" in case of adds.

Here is what the first half of the patch does.

When you're looking for "DBIT", you can distinguish inc.w from inc.l
by looking at the lower three bits of the third nibble.  Since the
only possible third nibbles when looking for "DBIT" are 5 and 7, the
third nibbles for adds (0, 8, and 9) get rejected.  That is why I am
ANDing with 7 instead of 5.

Here is what the second half of the patch does.

Now, when looking for "KBIT", the only possible third nibbles are 0,
8, and 9.  All other values must be rejected.  Thus, I have "default:
goto fail;".

The same story applies to dec.w, dec.l, and subs. The only difference
is that the first nibble is 1 instead of 0.  Just read the above
replacing inc with dec and adds with subs.

Thanks,

Kazu Hirata

===File ~/gnu/gdb/ChangeLog-compile.c=======================
2000-06-15  Kazu Hirata  <kazu@hxi.com>

	* compile.c (decode): Distinguish inc/dec.[wl] and adds/subs
	correctly.

============================================================

===File ~/gnu/gdb/compile.patch=============================
Index: compile.c
===================================================================
RCS file: /cvs/src/src/sim/h8300/compile.c,v
retrieving revision 1.3
diff -u -r1.3 compile.c
--- compile.c	2000/06/13 20:32:01	1.3
+++ compile.c	2000/06/16 03:57:35
@@ -220,7 +220,10 @@
 
 	      if (looking_for & DBIT)
 		{
-		  if ((looking_for & 5) != (thisnib & 5))
+		  /* Exclude adds/subs by looking at bit 0 and 2, and
+                     make sure the operand size, either w or l,
+                     matches by looking at bit 1.  */
+		  if ((looking_for & 7) != (thisnib & 7))
 		    goto fail;
 
 		  abs = (thisnib & 0x8) ? 2 : 1;
@@ -293,6 +296,8 @@
 		    case 0:
 		      abs = 1;
 		      break;
+		    default:
+		      goto fail;
 		    }
 		}
 	      else if (looking_for & L_8)
============================================================


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]