[Top][All Lists]

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

Re: [avr-gcc-list] Not naked but "topless" functions?

From: a . doesschate
Subject: Re: [avr-gcc-list] Not naked but "topless" functions?
Date: Fri, 11 Oct 2002 09:24:04 +0200
User-agent: Mutt/

On Thu, Oct 10, 2002 at 11:07:52PM +0200, Tvrtko A. Ursulin wrote:
> Hello everyone!
> More questions...
> I need to write functions that dont push/pop registers on stack. But if I use 
> __attribute__((naked)) then compiler omits code that adjusts stack pointer 
> also. That is ok if my function uses less than available registers, but if 
> not... trouble.
> My functions should adjust stack like this:
>  14e:   cd b7           in      r28, 0x3d       ; 61
>  150:   de b7           in      r29, 0x3e       ; 62
>  152:   25 97           sbiw    r28, 0x05       ; 5
>  154:   0f b6           in      r0, 0x3f        ; 63

If I am not mistaken you should be VERY careful doing this. If an interrupt
will be executed here then r0 would be changed if this interrupt will use
r0 and willnot restore r0.

I used the 68HC11 and this one automatically preserves all registers including
the condition code register (= SREG in AVR) when an interrupt occurred. It took
me some time why my AVR application (completely written in assembly) didnot
function correctly.
Reading the docs again it was mentioned separately that software also had to
preserve the SREG.

>  156:   f8 94           cli
>  158:   de bf           out     0x3e, r29       ; 62
>  15a:   0f be           out     0x3f, r0        ; 63
>  15c:   cd bf           out     0x3d, r28       ; 61
> This is taken from function which uses 5 stack variables, hence sbiw r28,0x05.
> Btw, what does in/cli/out of SREG in default function prolog do? If it is 
> supposed to ensure no interrupt occurs while manipulating SP, why "out 
> 0x3f,r0" (enable interrupts right?) is not the last instruction? 

Also here if I am not mistaken : restoring an interrupt this way doesnot waste 
(maybe precious ?) register.

> Thanks!
> avr-gcc-list at http://avr1.org


* choose GNU/Linux : GNU/Linux is Freedom *


Armand ten Doesschate
Welschapsedijk 141
5652 XL Eindhoven
the Netherlands
tel : (++31) 40 2571 274
e-mail : address@hidden
avr-gcc-list at http://avr1.org

reply via email to

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