This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


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

[PATCH]: Fix 68HC12 movb disassembly


Hi!

The 68HC12 disassembler was incorrectly disassembling instructions of
the form:

	movb	#12, global

I've committed the opcodes patch in binutils branch and mainline to fix that.
I also committed a gas test verify this case.

	Stephane

2001-11-01  Stephane Carrez  <Stephane.Carrez@worldnet.fr>

	* m68hc11-dis.c (print_insn): Fix disassembly of movb with a
	constant as source.

2001-11-01  Stephane Carrez  <Stephane.Carrez@worldnet.fr>

	* gas/m68hc11/opers12.s: Add test for disassembler bug with movb
	instruction.
	* gas/m68hc11/opers12.d: Likewise.
	* gas/m68hc11/opers12-dwarf2.d: Likewise.
Index: opcodes/m68hc11-dis.c
===================================================================
RCS file: /cvs/src/src/opcodes/m68hc11-dis.c,v
retrieving revision 1.3
diff -u -p -r1.3 m68hc11-dis.c
--- m68hc11-dis.c	2001/08/28 16:27:55	1.3
+++ m68hc11-dis.c	2001/11/01 09:44:55
@@ -366,15 +366,36 @@ print_insn (memaddr, info, arch)
 	  (*info->fprintf_func) (info->stream, "\t");
 	}
 
-      /* The movb and movw must be handled in a special way...  */
-      offset = 0;
-      if (format & (M6812_OP_IDX_P2 | M6812_OP_IND16_P2))
-	{
-	  if ((format & M6812_OP_IDX_P2)
-	      && (format & (M6811_OP_IMM8 | M6811_OP_IMM16 | M6811_OP_IND16)))
-	    offset = 1;
-	}
+      /* The movb and movw must be handled in a special way...
+         The source constant 'ii' is not always at the same place.
+         This is the same for the destination for the post-indexed byte.
+         The 'offset' is used to do the appropriate correction.
+
+                                   offset          offset
+                              for constant     for destination
+         movb   18 OB ii hh ll       0          0
+                18 08 xb ii          1          -1
+                18 0C hh ll hh ll    0          0
+                18 09 xb hh ll       1          -1
+                18 0D xb hh ll       0          0
+                18 0A xb xb          0          0
+
+         movw   18 03 jj kk hh ll    0          0
+                18 00 xb jj kk       1          -1
+                18 04 hh ll hh ll    0          0
+                18 01 xb hh ll       1          -1
+                18 05 xb hh ll       0          0
+                18 02 xb xb          0          0
+
+         After the source operand is read, the position 'pos' is incremented
+         this explains the negative offset for destination.
 
+         movb/movw above are the only instructions with this matching
+         format.  */
+      offset = ((format & M6812_OP_IDX_P2)
+                && (format & (M6811_OP_IMM8 | M6811_OP_IMM16 |
+                              M6811_OP_IND16)));
+
       /* Operand with one more byte: - immediate, offset,
          direct-low address.  */
       if (format &
@@ -387,7 +408,10 @@ print_insn (memaddr, info, arch)
 	    }
 
 	  pos++;
-	  offset = -1;
+
+          /* This movb/movw is special (see above).  */
+          offset = -offset;
+
 	  if (format & M6811_OP_IMM8)
 	    {
 	      (*info->fprintf_func) (info->stream, "#%d", (int) buffer[0]);
Index: gas/testsuite/gas/m68hc11/opers12-dwarf2.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/m68hc11/opers12-dwarf2.d,v
retrieving revision 1.1
diff -u -p -r1.1 opers12-dwarf2.d
--- opers12-dwarf2.d	2001/01/11 19:48:41	1.1
+++ opers12-dwarf2.d	2001/11/01 09:44:55
@@ -214,3 +214,28 @@ t2:
  10f:	1b fa 00 ff 	leas	255,PC
 	leas	max9b,pc
  113:	1b fa 00 00 	leas	0,PC
+
+;;
+;; Disassembler bug with movb
+;;
+	movb	#23,0x2345
+ 117:	18 0b 17 23 	movb	#23, 2345 <max9b\+0x2246>
+ 11b:	45 
+	movb	#40,12,sp
+ 11c:	18 08 8c 28 	movb	#40, 12,SP
+	movb	#39,3,\+sp
+ 120:	18 08 a2 27 	movb	#39, 3,\+SP
+	movb	#20,14,sp
+ 124:	18 08 8e 14 	movb	#20, 14,SP
+	movw	#0x3210,0x3456
+ 128:	18 03 32 10 	movw	#3210 <bb\+0xa10>, 3456 <bb\+0xc56>
+ 12c:	34 56 
+	movw	#0x4040,12,sp
+ 12e:	18 00 8c 40 	movw	#4040 <bb\+0x1840>, 12,SP
+ 132:	40 
+	movw	#0x3900,3,\+sp
+ 133:	18 00 a2 39 	movw	#3900 <bb\+0x1100>, 3,\+SP
+ 137:	00 
+	movw	#0x2000,14,sp
+ 138:	18 00 8e 20 	movw	#2000 <max9b\+0x1f01>, 14,SP
+ 13c:	00 
Index: gas/testsuite/gas/m68hc11/opers12.d
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/m68hc11/opers12.d,v
retrieving revision 1.3
diff -u -p -r1.3 opers12.d
--- opers12.d	2001/01/11 20:19:17	1.3
+++ opers12.d	2001/11/01 09:44:55
@@ -88,3 +88,11 @@ Disassembly of section .text:
 0+10b <t2\+0x16> leas	0,PC
 0+10f <t2\+0x1a> leas	255,PC
 0+113 <t2\+0x1e> leas	0,PC
+0+117 <t2\+0x22> movb	#23, 0+2345 <max9b\+0x2246>
+0+11c <t2\+0x27> movb	#40, 12,SP
+0+120 <t2\+0x2b> movb	#39, 3,\+SP
+0+124 <t2\+0x2f> movb	#20, 14,SP
+0+128 <t2\+0x33> movw	#0+3210 <bb\+0xa10>, 0+3456 <bb\+0xc56>
+0+12e <t2\+0x39> movw	#0+4040 <bb\+0x1840>, 12,SP
+0+133 <t2\+0x3e> movw	#0+3900 <bb\+0x1100>, 3,\+SP
+0+138 <t2\+0x43> movw	#0+2000 <max9b\+0x1f01>, 14,SP
Index: gas/testsuite/gas/m68hc11/opers12.s
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/m68hc11/opers12.s,v
retrieving revision 1.3
diff -u -p -r1.3 opers12.s
--- opers12.s	2001/01/11 20:19:17	1.3
+++ opers12.s	2001/11/01 09:44:55
@@ -100,6 +100,19 @@ t2:
 	leas	min9b,pc
 	leas	max9b,pc
 
+;;
+;; Disassembler bug with movb
+;;
+	movb	#23,0x2345
+	movb	#40,12,sp
+	movb	#39,3,+sp
+	movb	#20,14,sp
+	movw	#0x3210,0x3456
+	movw	#0x4040,12,sp
+	movw	#0x3900,3,+sp
+	movw	#0x2000,14,sp
+#	movb	#111,start
+
 titi = 10
 toto = 100
 min5b= -15

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