[En-Nut-Discussion] Hints for 2561 Applications

Dusan Ferbas dferbas at etech.cz
Fri Aug 8 23:18:12 CEST 2008


Hi developers,

because it was painfull for us, I want to share our experience. We 
still have a problem when calling a bootloader API from application, 
so maybe someone knows more about register saving and clobbering.
We used 
http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_reg_usage and 
still we miss something.

1. New avr-gcc generates eicall instructions, but does not seed EIND 
register (bits 23:16 of PC). So all functions, targeted by eicall 
should reside in lower half of flash.
Browse *.lst for "eicall". Typically these are callback functions and 
functions in an array. Both are dereferencing function pointers.
There is currently no easy solution, because I've been told, that 
internally, avr-gcc compiler uses 16 bit pointers.
Does it makes sense that linker is aware of more bits ?

So to achieve this, add to your function declaration
((section(".lowtext.func"))), where func is your function name.
If you are not using LDFLAGS += -Wl,--gc-sections, you can stay with 
".lowtext" for all your functions.


2. Thread entry point has to reside in lower half of flash.
This is because NutThreadCreate seeds ..._pcex with 0. There should 
be bits 23:16, but there is no way, as argument "void (*fn) (void *)" 
is passed as 2 8 bit registers (16 bits).
This can be fulfilled by adding an additional argument, but this will 
be usefull only for AVR architecture. Probably we should wait for far pointer.

Second possibility is to use default linker script (avr6.x), where 
.lowtext* section is used.
So you can have e.g.
THREAD(telnet, arg) __attribute__ ((section(".lowtext.telnet")))

As this is fine for application threads, it is not for Nut/OS 
threads. But those are same for all applications. For these I suggest 
to add their modules into a linker script.
If you put your application into a library, then you can expect, that 
all Nut/OS threads will be placed in lower half of flash.

P.S. We used WinAVR-20071221 (gcc 4.2.2) as it produces smaller 
images (pre gcc 4.3.x).


Dusan 




More information about the En-Nut-Discussion mailing list