avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Function Pointers on AT90USB1287 and ATmega2561


From: Peter LaDow
Subject: Re: [avr-gcc-list] Function Pointers on AT90USB1287 and ATmega2561
Date: Fri, 22 Feb 2008 08:16:37 -0800
User-agent: Thunderbird 2.0.0.9 (Windows/20071031)

Stu Bell wrote:
> You are right about the far pointer, at least on the 2560/2561.  For
> normal functions, the gcc linker creates a "trampoline" in the lower 64K
> word (128K byte) space of flash.  This is a table of EIJMP (3-byte jump)
> pointers to routines in high (> 128K byte) flash.   Once there, RJMP
> seems to be used, which avoids specification of a 3-byte address. 

Ah.  That sounds like the piece I was missing.  However, since this is
created a link time, it doesn't work for function pointers.  That is,
you cannot setup a function pointer to the trampoline code.

> You are absolutely right, though, that function pointers in the current
> gcc are 2-byte pointers.

Ok.  I thought perhaps there was something I was missing since the AVR
LIBC documentation says "function pointers are word addresses, to allow
addressing the whole 128K program memory space on the ATmega devices
with > 64 KB of flash ROM."

> I'm using FreeRTOS, and have done as you -- I've placed all my
> pointer-refererenced routines in low (< 128K) memory.  So far, I've had
> little problem with the RTOS getting confused, other than needing to
> define my task stacks with 3 byte pointers, and defining the context
> switch functions to save/restore the extension bit.  Since I've defined
> all of my task routines to be in bottom memory, I can easily push an
> extra 0 byte on the task stack at initialization time, and I'm done.

I made similar changes in uC/OS-II.  My post to the mailing list was to
find out if there was an option to use something larger than a 16-bit
function pointer.  But that appears to not be the case.

> In the short term, I think you will need to keep all of your
> pointer-referenced functions in low memory, even if all they do is then
> call the real function in high memory.

That's a good way to do it.  To keep the code generic, I could define my
own "trampoline" functions in low memory and use function pointers to
those.  This then frees me from worrying about where things may get put
into flash (except my "trampoline" functions) and having shorted
function pointers.  Now my tasks can live anywhere without a problem.

> One final comment about your last paragraph.  AVR instructions are
> addressed by the 16-bit word, not by the 8-bit byte.  So, a 16-bit PC
> can address 64 K *words*, or 128 K *bytes*.  It's only in the m2560/2561
> with 256 K bytes of Flash do you run into trouble.

Right.  Though I did say words not bytes.  The AVR LIBC documentation
says "with > 64 KB of flash ROM".  Sounds like that needs to be updated,
especially if function pointers cannot address code beyond 64K words.
Though that may not be what they meant.

But I do find it strange that the AT90USB1287 uses a 3 byte PC for
call/ret and reti, thought it only has 128K of flash.

Thanks,
Pete





reply via email to

[Prev in Thread] Current Thread [Next in Thread]