[Top][All Lists]

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

RE: [avr-gcc-list] Why is there 1200 bytes of zeroes in my code?

From: Stu Bell
Subject: RE: [avr-gcc-list] Why is there 1200 bytes of zeroes in my code?
Date: Wed, 21 Mar 2007 20:08:04 -0600

Simply put, the mega2560 has a 17-bit program counter.  The basic jumps and calls in the AVR are 16-bits.  So, from a routine in the bottom “page”,

how do you call a routine in the upper page?


There are EIJMP and EICALL commands that will do this sort of thing.  But if the compiler makes EVERY call or jump an EICALL or EIJMP, then practically every jump or call will have an extra byte of code, and it’s usually worthless.


This is even nastier since the compiler does not know where the linker is going to place the code.  So, unless you have the linker resolve the calls by replacing EICALL and EIJMP with CALL and JMP (and ALL of the other headaches that go with that), we need a mechanism to allow the compiler to generate what is essentially a “local” call that will end up in the “high” page of flash.


Enter the trampoline.  What happens is that the linker creates a table of jump points and links the local calls to the jump table.  I’m not sure of the gcc implementation, but I would do:


  0:  EIJMP <high_memory_function_0>


  1:  EIJMP <high_memory_function_1>


and so on.  When the system does a CALL, it stores 3 bytes on the stack and calls the jump table.  The EIJMP will jump to the high-memory function and happiness occurs. The high-memory function will deal with things, and when it returns the 3-byte address points back at the lower-page routine.


I.E.  It’s a big trampoline.  Get it? ;-)


Hope this helps (AND I hope I have the concept right).

Best regards,

Stu Bell
DataPlay (DPHI, Inc.)

From: address@hidden [mailto:address@hidden On Behalf Of larry barello
Sent: Wednesday, March 21, 2007 9:33 AM
To: address@hidden
Subject: RE: [avr-gcc-list] Why is there 1200 bytes of zeroes in my code?


For those of us in the dark, what are “trampolines” in the context of GCC?


From: address@hidden [mailto:address@hidden On Behalf Of Stu Bell
Sent: Tuesday, March 20, 2007 4:06 PM
To: address@hidden
Subject: [avr-gcc-list] Why is there 1200 bytes of zeroes in my code?



So why does the linker put .init0 at 0x25a4 when there is nothing between that and .trampolines at 0x20f4?  I understand the need for the trampolines, but my code is currently less than the split point where I would need them.  Is there a way to control this?


Thanks for any help!


reply via email to

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