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

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

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


From: Tvrtko A. Ursulin
Subject: Re: [avr-gcc-list] Not naked but "topless" functions?
Date: Fri, 11 Oct 2002 09:38:29 +0200

> > 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 did not write this assembly, it is compiler generated. That is, this is 
default function prologue. I didn't copy-paste here "push"-ing of registers 
because the question was how to ommit that and keep this part of rpologue. 

So my concernes were justified you say? This code is not safe?

> >  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 any (maybe precious ?) register.

I don't understand why not use "sei".

I don't understand this default prologue at all...



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



reply via email to

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