4.7.2.4 Os_main/os_task Attribute

On AVR, functions with the OS_main or OS_task attribute do not save/restore any call-saved register in their prologue/epilogue.

The OS_main attribute can be used when there is guarantee that interrupts are disabled at the time when the function is entered. This saves resources when the stack pointer has to be changed to set up a frame for local variables.

The OS_task attribute can be used when there is no guarantee that interrupts are disabled at that time when the function is entered like for, e.g. task functions in a multi-threading operating system. In that case, changing the stack pointer register is guarded by save/clear/restore of the global interrupt enable flag.

The differences to the naked function attribute are:

  • naked functions do not have a return instruction whereas OS_main and OS_task functions have a ret or reti return instruction.
  • naked functions do not set up a frame for local variables or a frame pointer whereas OS_main and OS_task do this as needed.