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 Dec 18 15:35:25 2008  
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 MarkupRich Markup):

You are not logged in

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


Thu Dec 18 15:35:25 2008, 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 Mar 1 22:18:44 2009arcanumStatusNone=>Fixed
      Percent Complete70%=>100%
      Fixed ReleaseNone=>1.6.6
    Sun Mar 1 20:54:30 2009arcanumPercent Complete30%=>70%
    Sat Feb 28 16:38:03 2009arcanumSeverity3 - Normal=>5 - Blocker
    Fri Feb 27 00:22:36 2009arcanumPriority5 - Normal=>9 - Immediate
      Percent Complete0%=>30%
      Assigned toNone=>arcanum

    Back to the top

    Powered by Savane 3.1-cleanup1