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

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

Re: [avr-gcc-list] Releasing an installer of avrgcc3.2 on AVRfreaks.net


From: Marek Michalkiewicz
Subject: Re: [avr-gcc-list] Releasing an installer of avrgcc3.2 on AVRfreaks.net
Date: Wed, 26 Jun 2002 11:12:19 +0200 (CEST)

> On the watchdog, my problem was that the divisor value was not loaded,
> the change fixed it.

OK, but writing the same value twice is not exactly what is recommended
by the datasheet.  So even if it works now (good to know), it is not
guaranteed to work in future devices...

> On issue 3. I cannot recall exactly whether it was R28 or R29. All I
> remember is that R28/29 is used as a frame pointer for the local
> variables and that the stack got messed up completely because at some
> stage one of the registers got used for something else.

Yes, that's exactly the bug I fixed.

> void (*funcptr)(void);
> 
> void foo(void)
> {
>   funcptr = (void *)0xfc00;
>   funcptr();
> }
> 
> funcptr is global, correct value is loaded, the call goes to the right
> address.
> 
> - - - - - - - - -
> 
> However:
> 
> void foo(void)
> {
>  void (*funcptr)(void);
>   funcptr = (void *)0xfc00;
>   funcptr();
> }
> 
> Results in address / 2 being loaded!

Thanks for explaining this.  Tried it with current CVS - both examples
result in calling the same address 0x7ffc00, which is also wrong
(problem with sign-extension of pointers) but ATmega128 will probably
truncate it to 0x1fc00 (ignore the high bits).

In such corner cases, it may be best to use explicit "asm" clobbering
all call-used registers, like this (specify the byte address!):

        asm volatile (
                "call 0x1f800"
                : /* no outputs */
                : /* no inputs */
                : "r18", "r19", "r20", "r21", "r22", "r23",
                  "r24", "r25", "r26", "r27", "r30", "r31"
        );

Looks a bit ugly, but uses no SRAM, and does exactly what you mean
(if it never returns, you can use "jmp" instead of "call", and remove
the clobbers) independent of GCC version...

Marek

avr-gcc-list at http://avr1.org



reply via email to

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