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

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

Re: [avr-gcc-list] Function pointer problem


From: gouy yann
Subject: Re: [avr-gcc-list] Function pointer problem
Date: Sat, 2 Oct 2004 19:35:14 +0200 (CEST)

Hello,

the value is correct.

instructions are 2-byte aligned.
thus to allow the program counter to access more code,
it stores the address "divided by 2".

as 0x8f is exactly the half of 0x11e, the generated
address is correct.

concerning the optimisation done by GCC, it seems
perfectly correct as what you do is to call
code_test(1).

regards.
    Yann


 --- Thomas Olsson <address@hidden> a écrit : 
> Hi,
> 
> I hope someone can help with this. I have been
> through most of the internet
> looking for an answer, but I haven't found anything
> matching the problem.
> 
> Basically, I want function pointers to work
> correctly. It's not the old
> "function pointer in progmem" problem, since these
> are stored in RAM.
> 
> The function itself is obviously in progmem, but GCC
> seems to be confused
> about this, and whenever the function pointer is
> assigned to something, it
> uses some other address instead. I haven't been able
> to find out what the
> wrong address points at, but it sure isn't the
> function in progmem.
> 
> Here is a simplified way to produce the problem:
> 
> - - - cut - - -
> void (*code)(byte arg);
> 
> void code_test(char arg)
> {
> }
> 
> void code_init(void)
> {
>   code = code_test;
>   code(1);
> }
> 
> - - - cut - - -
> 
> This produces the following code:
> 
> 0000011e <code_test>:
>  11e: 08 95           ret
> 
> 00000120 <code_init>:
>  120: 8f e8           ldi     r24, 0x8F       ; 143
>  122: 90 e0           ldi     r25, 0x00       ; 0
>  124: 90 93 19 01     sts     0x0119, r25
>  128: 80 93 18 01     sts     0x0118, r24
>  12c: 81 e0           ldi     r24, 0x01       ; 1
>  12e: 0e 94 8f 00     call    0x11e
>  132: 08 95           ret
> 
> As you can see, GCC has discovered that "code" is
> constant, so it calls the
> right address (0x11e). But the value stored in the
> pointer is 0x8f, which
> is the problem (in the real code, it would not be a
> constant, and 0x8f
> would be indirectly called instead).
> 
> I have already tried nearly all combinations of:
> * Storing the function pointer, the implicit
> function pointer, and the
>   address of either.
> * With and without various typedefs.
> * Casting to void *, int, and more.
> * Variations with and without
> __attribute__((__progmem__)) in all sorts of
>   weird places.
> * -O1, -O2 and no -O
> 
> It always produces the wrong address, I have not
> been able to change that
> at all.
> 
> For the record, this is GCC-avr 3.4.1.
> 
> Thanks in advance for any suggestions,
> Thomas.
> 
> -- 
>       9876543210  Magic tab-o-meter.  
> http://www.armware.dk/
>          ^
> 
> 
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list
>  

=====



        

        
                
Vous manquez d’espace pour stocker vos mails ? 
Yahoo! Mail vous offre GRATUITEMENT 100 Mo !
Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/

Le nouveau Yahoo! Messenger est arrivé ! Découvrez toutes les nouveautés pour 
dialoguer instantanément avec vos amis. A télécharger gratuitement sur 
http://fr.messenger.yahoo.com


reply via email to

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