Bug 2454 - incorrect syntax in avr disassembly
Summary: incorrect syntax in avr disassembly
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.16
: P1 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-13 15:40 UTC by hochstein
Modified: 2006-04-12 13:11 UTC (History)
1 user (show)

See Also:
Host: avr
Target: avr
Build: i686-pc-linux
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description hochstein 2006-03-13 15:40:36 UTC
The disassembly for call and jmp looks like this:

     43a:	0e 94 7e 0e 	call	0x1cfc <__divmodhi4>

This causes problems since the "<identifier>" part is not correct assembler
syntax. It should read like this:

     43a:	0e 94 7e 0e 	call	0x1cfc	; <__divmodhi4>

The following patch solves the problem for me:

diff -ubr binutils-2.16/opcodes/avr-dis.c binutils-2.16-patched/opcodes/avr-dis.
--- binutils-2.16/opcodes/avr-dis.c     Thu Mar  3 12:49:47 2005
+++ binutils-2.16-patched/opcodes/avr-dis.c     Mon Mar 13 15:54:06 2006
@@ -142,7 +142,8 @@
     case 'h':
       *sym = 1;
       *sym_addr = ((((insn & 1) | ((insn & 0x1f0) >> 3)) << 16) | insn2) * 2;
-      sprintf (buf, "0x");
+      sprintf (buf, "0x%x", *sym_addr);
+      sprintf (comment, "0x");
       break;
       
     case 'L':

-----
Comment 1 Ben Elliston 2006-04-04 01:54:31 UTC
This patch suggests that you are trying to make the disassembler's output
suitable for input back into the assembler, correct?  This is not normally
something that the disassembler strives for.

What are you trying to do?
Comment 2 hochstein 2006-04-04 06:53:37 UTC
Why not strive for it if it can be done easily?

I use avrora (http://compilers.cs.ucla.edu/avrora/) to simulate the AVR program
before writing it onto the real device. This simulator reads the input from
objdump and expects correct syntax. The call/jmp mnemonics are the only ones
which cause it to stumble.
Comment 3 Nick Clifton 2006-04-07 14:48:33 UTC
Subject: Re:  New: incorrect syntax in avr disassembly

Hi hochstein,

> The disassembly for call and jmp looks like this:
> 
>      43a:	0e 94 7e 0e 	call	0x1cfc <__divmodhi4>
> 
> This causes problems since the "<identifier>" part is not correct assembler
> syntax. It should read like this:
> 
>      43a:	0e 94 7e 0e 	call	0x1cfc	; <__divmodhi4>
> 

Do you have a *small* test case to reproduce this behaviour ?

Also - have you tried the current sources in the mainline binutils CVS 
repository ?  I think that they may already have the desired behaviour.

Cheers
   Nick
Comment 4 hochstein 2006-04-11 13:31:31 UTC
Here comes the test case:

        call __divmodhi4
        .org 0x1cfc
__divmodhi4:
        nop

I compile the above program 

$ avr-as -I/usr/include/avr -mmcu=atmega32 -o call-test.o call-test.asm
$ avr-gcc -mmcu=atmega32 -nostdlib -o call-test call-test.o

and then dump it

$ avr-objdump -zD call-test

The output is

       0:       0e 94 7e 0e     call    0x1cfc <__divmodhi4>
       ...

I also tried the sources from CVS but they do not resolve the problem.
Comment 5 Nick Clifton 2006-04-12 13:11:43 UTC
Thank you.  I am now able to reproduce the bug and I have approved your patch. 
it does not quite perform as you say, since the hexadecimal form of the address
is displayed twice:

       0:       0e 94 7e 0e     call    0x1cfc  ; 0x1cfc <__divmodhi4>

But this is not too big of a problem, and fixing it would mean altering the
generic sources in objdump.c.  

I have checked your patch in alogn with this ChangeLog entry.

Cheers
  Nick

opcodes/ChangeLog
2006-04-12   Hochstein  <hochstein@algo.informatik.tu-darmstadt.de>

	PR binutils/2454
	* avr-dis.c (avr_operand): Arrange for a comment to appear before
	the symolic form of an address, so that the output of objdump -d
	can be reassembled.