[Top][All Lists]
[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: |
Thu, 21 Feb 2008 23:37:33 -0800 |
>From: "Weddington, Eric" <address@hidden>
>> From:
>> address@hidden
>> [mailto:address@hidden
>> org] On Behalf Of Peter LaDow
>> Sent: Thursday, February 21, 2008 6:52 PM
>> To: address@hidden
>> Subject: [avr-gcc-list] Function Pointers on AT90USB1287 and
>> ATmega2561
>>
>> The AT90USB1287 and ATmega2561 push/pop 3 byte PC's with
>> call/ret and reti.
>
>AFAIK, that is incorrect. Only the ATmega2561 has a 3 byte PC. The
>AT90USB1287 does not.
Direct from the AT90USB1287 datasheet (version 7593D-AVR-07/06):
The Stack Pointer is decremented by one when data is pushed onto the Stack
with the PUSH instruction, and it is decremented by three when the return
address is pushed onto the Stack with subroutine call or interrupt. The
Stack Pointer is incremented by one when data is popped from the Stack with
the POP instruction, and it is incremented by three when data is popped from
the Stack with return from subroutine RET or return from interrupt RETI.
>> However, function pointers on these parts
>> seem to be 2 bytes.
>>
>
>What platform are you compiling on? (Linux, FreeBSD, Windows, Mac OS X,
>Solaris, other)
Linux. Specifically:
$ uname -a
Linux shaggy 2.6.23.14-107.fc8 #1 SMP Mon Jan 14 21:37:30 EST 2008 i686 i686
i386 GNU/Linux
>Did you build the toolchain yourself?
Yep. :)
>If yes, did you include the mega256x patch?
This, I admin, I don't know, but I think so. I downloaded all the patches
from
http://www.freebsd.org/cgi/cvsweb.cgi/ports/devel/avr-gcc/files/#dirlist and
applied them all, including patch-zz-atmega256x. In the patch, I see a
comment: "3-Byte PC".
I don't know if this info helps, but here the info:
$ avr-ld --version
GNU ld (GNU Binutils) 2.18 + coff-avr-patch (20050630)
Copyright 2007 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later
version.
This program has absolutely no warranty.
$ avr-gcc --version
avr-gcc (GCC) 4.2.1
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
And avr-libc v1.6.1.
But here is what the stack looks like when I assume a 2 byte PC in
os_cpu_c.c
262 ret ; Start task
Current language: auto; currently asm
(gdb) p $sp
$1 = (void *) 0x800288
(gdb) x /4xb $sp
0x800288 <test_task_stack+126>: 0x01 0x06 0x00 0x00
(gdb) p /x $pc
$2 = 0xe18
(gdb) nexti
0x00000c00 in OSInit () at ../ucos/src/os_core.c:1257
1257 pevent1->OSEventName[0] = '?'; /*
Unknown name */
Current language: auto; currently c
(gdb) p $sp
$3 = (void *) 0x80028a
(gdb) p /x $pc
$4 = 0xc00
And assuming a 3 byte PC in os_cpu_c.c:
Breakpoint 1, OSStartHighRdy () at ../ucos/src/os_cpu_a.S:262
262 ret ; Start task
Current language: auto; currently asm
(gdb) p $sp
$1 = (void *) 0x800287
(gdb) x /4xb $sp
0x800287 <test_task_stack+125>: 0x00 0x01 0x06 0x00
(gdb) p /x $pc
$2 = 0xe18
(gdb) nexti
test_task (data=0x800000) at src/tasks.c:56
56 {
Current language: auto; currently c
(gdb) p $sp
$3 = (void *) 0x800289
(gdb) p /x $pc
$4 = 0x20c
Note that the latter has the leading 0x00 on the stack, and that the PC is
correct for the return address.
Pete