Well this is PDP 11/40 assembly language, which is defined in the manual.
Let's break it down, line by line:
.globl _idle # define a global symbol called idle
_idle: # this is the label for the global symbol
mov PS,-(sp) # push processor state onto stack
bic $340,PS # clear priority level bits - effectively enable all interrupts
wait # wait for an interrupt
mov (sp)+,PS # pop processor state from stack
rts pc # return from function
The -(sp)
and (sp)+
should be read as the equivalent to the C/C++
operators --sp
and sp++
.
So, it effectively saves the state, Clears the priority level bits and then waits for an interrupt. Once the interrupt arrives it restores the state and goes back to work.
Please see the section [2.3.2 Processor Status Word] in the manual for the definition of the content of the PS register.
Now, the wait
operation will be interrupted for a variety of reasons, not the least of which is the real-time clock interrupt, so it gets woken up periodically to do some more work.
When you look at the source, there are two places where the idle()
routine is called - one from the panic handler, in an infinite loop, and the next in the swtch
, which swaps between processes and when it doesn't find a runnable process enters the idle routine.