bugAVR C Runtime Library - Bugs: bug #25778, Writing to SP loads the stack...

 
 

bug #25778: Writing to SP loads the stack pointer improperly

Submitted by:  Fred Hansen <bldrcowboy>
Submitted on:  Fri 06 Mar 2009 04:50:36 PM UTC  
 
Category: NoneSeverity: 5 - Blocker
Priority: 9 - ImmediateItem Group: None
Status: FixedPercent Complete: 100%
Assigned to: Eric Weddington <arcanum>Open/Closed: Closed
Release: 1.6.4Fixed Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Sat 07 Mar 2009 05:32:28 AM UTC, comment #2:

Fixed in the xmega patch to GCC.

Eric Weddington <arcanum>
Project AdministratorIn charge of this item.
Fri 06 Mar 2009 08:53:01 PM UTC, comment #1:

This is a GCC problem, not with avr-libc.

I'm rebuilding now with a fixed patch, and will test soon.

Eric Weddington <arcanum>
Project AdministratorIn charge of this item.
Fri 06 Mar 2009 04:50:36 PM UTC, original submission:

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

Fred Hansen <bldrcowboy>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #17600:  SPBugExample.c added by bldrcowboy (1KiB - application/octet-stream)
file #17601:  SPBugExample.lst added by bldrcowboy (2KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by arcanum (Posted a comment)
  • -unavailable- added by bldrcowboy (Submitted the item)
  •  

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 10 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 07 Mar 2009 05:32:28 AM UTCarcanumStatusNone=>Fixed
      Percent Complete30%=>100%
      Open/ClosedOpen=>Closed
    Fri 06 Mar 2009 08:53:01 PM UTCarcanumCategoryLibrary=>None
      Severity3 - Normal=>5 - Blocker
      Priority5 - Normal=>9 - Immediate
      Percent Complete0%=>30%
      Assigned toNone=>arcanum
    Fri 06 Mar 2009 04:50:36 PM UTCbldrcowboyAttached File-=>Added SPBugExample.c, #17600
      Attached File-=>Added SPBugExample.lst, #17601

    Back to the top


    Powered by Savane 3.1-cleanup1