[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Bug Report: Function Pointers
From: |
Peter Bosscha |
Subject: |
[avr-gcc-list] Bug Report: Function Pointers |
Date: |
Wed, 13 Mar 2002 07:34:44 +0200 |
Hi,
I wrote a bootloader for MEGA128 and needed to call a function in the
boot section using (o horror of horrors !) an absolute address.
Working on win32, I'm using the latest AVRFREAKS distribution.
I found the following somewhat weird behaviour:
1.
If I define the following inside my function that does the call:
void myfunc(void)
{
void (*funcptr)(word sig1, word sig2);
funcptr = (void *)0xf800;
funcptr(0x55aa,0xf00f); // Jump into the boot sector
}
the following incorrect result in the listing file is (edited for
brevity):
3980 0bcc 0E94 007C call 63488
Note that the address 7c00 (half of 0xf800) is used.
2.
By just putting the function pointer outside my function, correct
behaviour results.
The function pointer becomes an address in RAM and the compiler uses
the icall (Z register) instead of call.
void (*funcptr)(word sig1, word sig2);
void myfunc(void)
{
funcptr = (void *)0xf800;
funcptr(0x55aa,0xf00f); // Jump into the boot sector
}
resulting output (again edited for brevity):
3914 0b8a 80E0 ldi r24,lo8(63488)
3915 0b8c 98EF ldi r25,hi8(63488)
3916 0b8e 9093 0000 sts (funcptr)+1,r25
3917 0b92 8093 0000 sts funcptr,r24
3981 0bd0 E091 0000 lds r30,funcptr
3982 0bd4 F091 0000 lds r31,(funcptr)+1
3983 0bd8 6FE0 ldi r22,lo8(61455)
3984 0bda 70EF ldi r23,hi8(61455)
3985 0bdc 8AEA ldi r24,lo8(21930)
3986 0bde 95E5 ldi r25,hi8(21930)
3987 0be0 0995 icall
Lesson:
Don't put function pointers to absolute addresses inside your function.
Unfortunately this does waste 2 bytes in ram.
Since hardly anyone uses this sort of stuff I think it's not a very
serious problem, be warned anyway ..
Regards,
Peter Bosscha
avr-gcc-list at http://avr1.org
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-gcc-list] Bug Report: Function Pointers,
Peter Bosscha <=