avr-libc-dev
[Top][All Lists]
Advanced

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

[avr-libc-dev] [bug #25778] Writing to SP loads the stack pointer improp


From: Fred Hansen
Subject: [avr-libc-dev] [bug #25778] Writing to SP loads the stack pointer improperly
Date: Fri, 06 Mar 2009 16:50:38 +0000
User-agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; .NET CLR 1.1.4322; .NET CLR 2.0.50727)

URL:
  <http://savannah.nongnu.org/bugs/?25778>

                 Summary: Writing to SP loads the stack pointer improperly
                 Project: AVR C Runtime Library
            Submitted by: bldrcowboy
            Submitted on: Fri 06 Mar 2009 04:50:36 PM GMT
                Category: Library
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: None
                  Status: None
        Percent Complete: 0%
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 1.6.4
           Fixed Release: None

    _______________________________________________________

Details:

The attached list file shows an quick example of the bug. I'm loading the
stack pointer at the beginning of a naked routine (used in the boot loader) by
writing to the global SP with the statement:
    SP = RAMEND;

If you look at the assembly code it loads the bytes into the stack pointer in
the wrong order:
  35 0006 8FEF                  ldi r24,lo8(16383)
  36 0008 9FE3                  ldi r25,hi8(16383)
  37 000a 9DBF                  out 61-0,r25
  38 000c 8EBF                  out (61)+1-0,r24
r424 contains the low byte of RAMEND (which is 0x3FFF) but it's loaded into
the IO register 62 which is the upper byte of the stack pointer. r25 has the
high byte and is loaded into the load byte. 

The quick workaround that I've been using is to load the bytes explicitly:
    SPL = RAMEND & 0xFF;
    SPH = (RAMEND >> 8) & 0xFF;

I'm compiling for an XMega128A1. I'm using WinAVR 20081205. 

The command line that performed this compile is:
avr-gcc -c -mmcu=atxmega128a1 -I. -gdwarf-2 -DF_CPU=29491200UL
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall
-Wstrict-prototypes -Wundef -Wa,-adhlns=obj/.\Boot\SPBugExample.lst -I.
-I.\FreeRTOS -I.\Boot -I.\Cmd -I.\Util -I.\Ctrl -std=gnu99 -fgnu89-inline -Os
-MMD -MP -MF .dep/SPBugExample.o.d ./.\Boot\SPBugExample.c -o
obj/.\Boot\SPBugExample.o



    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Fri 06 Mar 2009 04:50:36 PM GMT  Name: SPBugExample.c  Size: 1kB   By:
bldrcowboy

<http://savannah.nongnu.org/bugs/download.php?file_id=17600>
-------------------------------------------------------
Date: Fri 06 Mar 2009 04:50:36 PM GMT  Name: SPBugExample.lst  Size: 2kB  
By: bldrcowboy

<http://savannah.nongnu.org/bugs/download.php?file_id=17601>

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?25778>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/





reply via email to

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