[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] LPM instructionsin optimized code causes unintended b

From: Wouter van Gulik
Subject: Re: [avr-libc-dev] LPM instructionsin optimized code causes unintended behavior in execution
Date: Fri, 18 Jun 2010 10:49:03 +0200
User-agent: Thunderbird (Windows/20100228)

Weddington, Eric schreef:
-----Original Message-----
From: Weddington, Eric Sent: Thursday, June 17, 2010 9:15 PM
To: 'Wouter van Gulik'; address@hidden
Subject: RE: [avr-libc-dev] LPM instructionsin optimized code causes unintended behavior in execution

As a matter of fact.... (checking code and instruction set)

The code you have in the bug report shows:
5808:       f4 91           lpm     r31, Z+

Take a long hard look at the hex instruction. Reverse the bytes: 91 F4

The LPM instruction in the instruction set document (page 91) shows this is Form 2 (ii) of the LPM instruction which is "LPM, r, Z", which is without the plus sign. Therefore this is not undefined. You've just rediscovered a different bug in binutils.

I forgot: Technically the bug cannot be pushed up to the binutils folks, 
because IIRC this is in the XMEGA patch to binutils. All of the XMEGA patches 
have not been submitted upstream yet, though we are planning on doing so. It 
*was* on the WinAVR bug list, but now it's on an internal list.

So the patch breaks this? Because it is also broken for an atmega16 (compiled with WinAvr2010)

Anyway here you have a simple testcase.

Compile the file using:
avr-gcc --save-temps -Os main.c -mmcu=atmega16
and disassemble:
avr-objdump -h -S -z a.out > dump.lss

volatile char x,y;

void foo(void) { x++; }

int main(void)
         case 0x00: foo(); break;
         case 0x01: foo(); break;
         case 0x02: foo(); break;
         case 0x03: foo(); break;
         case 0x04: foo(); break;
         case 0x05: foo(); break;
         case 0x06: foo(); break;
         case 0x07: foo(); break;
         case 0x08: foo(); break;
         case 0x09: foo(); break;
         case 0x0A: foo(); break;
         case 0x0B: foo(); break;
         case 0x0C: foo(); break;
         case 0x0D: foo(); break;
         case 0x0E: foo(); break;
         case 0x0F: foo(); break;
         case 0x10: foo(); break;
         case 0x11: foo(); break;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]