bugAVR C Runtime Library - Bugs: bug #25120, pgm_read_*_far() functions cause...


bug #25120: pgm_read_*_far() functions cause incorrect usage of the Z pointer for RAM access in ATxmega series

Submitted by:  Luke Morrison <lfmorrison>
Submitted on:  Thu 18 Dec 2008 03:35:25 PM UTC  
Category: HeaderSeverity: 5 - Blocker
Priority: 9 - ImmediateItem Group: Header files
Status: FixedPercent Complete: 100%
Assigned to: Eric Weddington <arcanum>Open/Closed: Closed
Release: AnyFixed Release: 1.6.6

Add a New Comment(Rich Markup)

You are not logged in

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


Thu 18 Dec 2008 03:35:25 PM UTC, original submission:

The pgm_read_*_far() functions manipulate the RAMPZ register but do not restore it when they are finished.

This behavior is usually safe for any part with 64 KiB or less of data memory address space, because the RAMPZ register is only ever used in relation to the ELPM instruction. Saving and restoring the RAMPZ register would normally be an unnecessary waste of cycles and Flash in such circumstances.

However, with the ATxmega series of devices, the RAMPZ register is also used every time any indirect data memory access happens through the Z pointer via the normal LD and ST instructions. As soon as one of the pgm_read_far() functions is invoked, the RAMPZ register will be left in a modified state, rendering any subsequent compiler-generated indirect access of data memory through the Z pointer invalid. This also makes pgm_read_far() interrupt-unsafe on such devices.

Possible fixes include:
1) Modify the pgm_read_*_far() functions to save and restore the RAMPZ register if the functions are used in a device which also uses RAMPZ as part of its normal indirect data access.
2) Modify GCC so that it never uses the Z pointer to indirectly access data memory on a device which also uses RAMPZ as part of its normal indirect data access.
3) Modify GCC to set the RAMPZ register appropriately (initially this might mean simply zeroing it) every time it begins accessing data memory through the Z pointer on a device which uses also RAMPZ as part of its normal indirect data access.

Luke Morrison <lfmorrison>


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

Attach File(s):

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by arcanum (Updated the item)
  • -unavailable- added by lfmorrison (Submitted the item)

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



    Follow 9 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 01 Mar 2009 10:18:44 PM UTCarcanumStatusNone=>Fixed
      Percent Complete70%=>100%
      Fixed ReleaseNone=>1.6.6
    Sun 01 Mar 2009 08:54:30 PM UTCarcanumPercent Complete30%=>70%
    Sat 28 Feb 2009 04:38:03 PM UTCarcanumSeverity3 - Normal=>5 - Blocker
    Fri 27 Feb 2009 12:22:36 AM UTCarcanumPriority5 - Normal=>9 - Immediate
      Percent Complete0%=>30%
      Assigned toNone=>arcanum

    Back to the top

    Powered by Savane 3.1-cleanup1