Re: [avr-gcc-list] Using current avr-gcc for target ATmega2561
From:
Martijn van Balen
Subject:
Re: [avr-gcc-list] Using current avr-gcc for target ATmega2561
Date:
Tue, 11 Oct 2005 13:10:32 +0200
On 2005-10-03 17:26:10 Martijn van Balen
wrote:
>
> "What needs to be done (tasks)
> (1) Align functions (and labels?) to 4-byte boundaries
so that gcc can continue to use 16-bit values to represent function pointers.
> (2) Take into account, that these devices store three
bytes on the stack for each function call"
>
> I can easily avoid (1) by using <128Kbyte flash from C. But I cannot
figure out what problem is solved by (2).
> Indirect jumps can be done by IJMP/ICALL, no need to push addresses
yourself. Before diving into avr.md
> and other files, could anybody point my in the right direction ?
>
To answer my own question, at least one problem is the addressing of function
parameters that were put on
the stack. I spend some time browsing
the gcc source code and finally found at least one
function in .../gcc/config/avr/avr.c
that needs knowledge of the size of the program counter:
int
initial_elimination_offset (int from,
int to)
{
if (from == FRAME_POINTER_REGNUM
&& to == STACK_POINTER_REGNUM)
return 0;
else
{
int offset = frame_pointer_needed
? 2 : 0;
After a small experiment, I concluded
that replacing the last 2 with a 3 indeed solves
the problem with the function parameters.
So for now, I can use my patched compiler
to generate mega2561 code.
What I want to ask to the guru's is:
do you agree ? Or do I need to patch more to
get a useful compiler ?
Kind regards,
Martijn.
/*
* Test program, generate assembly
with 'cc1 tst.c'
*
* p6 is passed through the stack
*
*/
char f(long p1, long p2, long p3, long
p4, char p5, char p6)
{
return p6;
}