Hello,

I am working on a small OS for the msp430 and I have implemented two assembler 
routines to disable (EnterMonitor) and restore (LeaveMonitor) interrupts. The 
EnterMonitor() routine saves the current SR register on stack and disables the 
interrupt. The LeaveMonitor() restores the interrupt status by popping it from 
stack. (in a way like the RETI instruction does) This LeaveMonitor() function 
does not enable the interrupts when interrupts were disabled before calling the 
EnterMonitor() function.
Now, this implementation only works when it is used in a function without local 
variables on stack ... because the compiler does not know that when 
EnterMonitor() is called, the SP is decreased by one word.
Does someone have a suggestion on how to solve this problem?


static void __attribute__( (naked) )
EnterMonitor
(
  void
)

{
  asm volatile( "\t MOV  R2, R15          ; Copy the contents of the   \n"\
                "\t DINT                  ; status register to R15 and \n"\
                "\t NOP                   ; disable the interrupts.    \n"\
                "\t POP  R14              ; Get the return address     \n"\
                "\t PUSH R15              ; and push the SR value to   \n"\
                "\t BR   R14              ; stack and return.          \n" );
}

static void __attribute__( (naked) )
LeaveMonitor
(
  void
)

{
  asm volatile( "\t POP  R14              ; Get the return address and \n"\
                "\t POP  R15              ; the contents of the status \n"\
                "\t MOV  R15, R2          ; register from stack and    \n"\
                "\t BR   R14              ; return to caller.          \n" );
}


I have also worked with a ICC7700 compiler that knew the "monitor" keyword:

char monitor foo( void )
{
  char a;  
  a = 3;
  return a;
}

The prologue of the function was a push operation of the status register and a 
disable interrupts instruction. The epilogue restored the old status and this 
way also restored the interrupt status.
Does gcc also supports this kind of function?


Sipke


Reply via email to