Using progmem on the reduced Tiny core?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Using progmem on the reduced Tiny core?

Georg-Johann Lay-2
Currently progmem attribute works the same way on the reduced core (no LPM, 16
GPRs) and on the ordinary cores (with LPM, 32 GPRs).

As we have a linearized memory model on reduced core and flash memory is
visible in the RAM address range (starting at 0x4000), it would make sense if
the compiler added that offset.

Attached is a tentative patch that adds this feature to avr-gcc together with a
small test program that demonstrates some use cases.

If this does not break anything (e.g. because the current practice is to use
progmem together with hand-crafted offsets and / or inline assembly) and the
feedback is positive, I would propose the change to gcc-patches.

Johann

gcc/
        * doc/extend.texi (AVR Variable Attributes) [progmem]: Add
        documentation how it works on reduced Tiny cores.
        * avr.c (AVR_SYMBOL_FLAG_TINY_PM): New macro.
        (avr_address_tiny_pm_p): New static function.
        (avr_print_operand_address) [AVR_TINY]: Add AVR_TINY_PM_OFFSET
        if the address is in progmem.
        (avr_assemble_integer): Same.
        (avr_encode_section_info) [AVR_TINY]: Set AVR_SYMBOL_FLAG_TINY_PM
        for symbol_ref in progmem.
        * avr.h (AVR_TINY_PM_OFFSET): New macro.
        * avr-c.c (avr_cpu_cpp_builtins): Use it instead of magic 0x4000
        when built-in def'ing __AVR_TINY_PM_BASE_ADDRESS__.

_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list

tiny-progmem.diff (4K) Download Attachment
ptiny.c (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using progmem on the reduced Tiny core?

Georg-Johann Lay-2
On 13.07.2016 19:10, Georg-Johann Lay wrote:
> Currently progmem attribute works the same way on the reduced core (no LPM, 16
> GPRs) and on the ordinary cores (with LPM, 32 GPRs).
>
> As we have a linearized memory model on reduced core and flash memory is
> visible in the RAM address range (starting at 0x4000), it would make sense if
> the compiler added that offset.

...same question arises for the __flash address space:

It's currently accepted for rTiny but generates nonsensical code:  No offset is
added to symbols and LPM instructions are generated or a silly libcall.

We could handle __flash but there is no benefit for the user, instead it makes
things more complicated because qualified pointers would have to be passed
around.  And it would make the avr backend even more complicated.

Actually progmem makes much more sense here because it is about handling of
symbols and their values and about different code needed to access flash vs. RAM.


> Attached is a tentative patch that adds this feature to avr-gcc together with a
> small test program that demonstrates some use cases.
>
> If this does not break anything (e.g. because the current practice is to use
> progmem together with hand-crafted offsets and / or inline assembly) and the
> feedback is positive, I would propose the change to gcc-patches.
>
> Johann
>
> gcc/
>     * doc/extend.texi (AVR Variable Attributes) [progmem]: Add
>     documentation how it works on reduced Tiny cores.
>     * avr.c (AVR_SYMBOL_FLAG_TINY_PM): New macro.
>     (avr_address_tiny_pm_p): New static function.
>     (avr_print_operand_address) [AVR_TINY]: Add AVR_TINY_PM_OFFSET
>     if the address is in progmem.
>     (avr_assemble_integer): Same.
>     (avr_encode_section_info) [AVR_TINY]: Set AVR_SYMBOL_FLAG_TINY_PM
>     for symbol_ref in progmem.
>     * avr.h (AVR_TINY_PM_OFFSET): New macro.
>     * avr-c.c (avr_cpu_cpp_builtins): Use it instead of magic 0x4000
>     when built-in def'ing __AVR_TINY_PM_BASE_ADDRESS__.


_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using progmem on the reduced Tiny core?

Erik Christiansen-2
In reply to this post by Georg-Johann Lay-2
On 13.07.16 19:10, Georg-Johann Lay wrote:
> As we have a linearized memory model on reduced core and flash memory
> is visible in the RAM address range (starting at 0x4000), it would
> make sense if the compiler added that offset.
>
> Attached is a tentative patch that adds this feature to avr-gcc
> together with a small test program that demonstrates some use cases.

Thanks for all the work on avr-gcc, and the examples.
(I'm not sure it'll tempt this old dog away from programming avr_tiny
exclusively in assembler, but it's grand to see toolchain improvements.)

Erik

_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Loading...