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

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

Re: [avr-gcc-list] Basic inline asm question


From: cavanus
Subject: Re: [avr-gcc-list] Basic inline asm question
Date: Wed, 30 Nov 2005 17:51:25 -0200

Thanks people,

In ethernut source code I find the undocumented asm "i" constraint
that that do this:


extern u_char _irq_stack[];
extern u_char _irq_SPL;
extern u_char _irq_SPH;
extern u_char _irq_nesting;

#define _SwitchToIrqStack       \
   asm volatile ("push r24" "\n\t"                             // save
r24 to current stack  \
                 "in r24,__SREG__" "\n\t"                      // load
SREG into r24  \
                 "push r24" "\n\t"                             // and
push it to current stack  \
                 "lds r24, _irq_nesting" "\n\t"                // load
_irq_nesting in r24  \
                 "tst r24" "\n\t"                              // test
for zero  \
                 "brne no_switch1" "\n\t"                      // jump
to no_switch1 if
not zero  \
                 "in r24, __SP_L__" "\n\t"                     // load
SP_L into r24  \
                 "sts _irq_SPL, r24" "\n\t"                    // and
save it to _irq_SPL  \
                 "in r24, __SP_H__" "\n\t"                     // load
SP_H into r24  \
                 "sts _irq_SPH, r24" "\n\t");                  // and
save it to _irq_SPH  \
   asm volatile ("ldi r24, lo8(%0)" "\n\t"                     // load
lo addr of begin
of irqstack to r24  \
                 "out __SP_L__, r24" "\n\t"                    //
write it to SP_L  \
                 "ldi r24, hi8(%0)" "\n\t"                     // load
hi addr of begin
of irqstack to r24  \
                 "out __SP_H__, r24" "\n\t"                    //
write it to SP_H  \
                 "lds r24, _irq_nesting" "\n\t"                // load
_irq_nesting to r24  \
                 "no_switch1:" "\n\t"                          // jump label  \
                 "inc r24" "\n\t"                              //
increment r24  \
                 "sts _irq_nesting, r24" "\n\t"                // save
it back to
_irq_nesting  \
                 ::                                    \
                 "i" (_irq_stack+IRQSTACK_SIZE-1));




reply via email to

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