
254
Evaluating and Programming the 29K RISC Family
The code shown above determines the region of cache registers currently in use
and stores them out onto the top of the user’s User mode register stack. This operation
can be postponed. The interrupt handler will use the register cache in conjunction
with the Supervisor mode register stack. If the interrupt handler runs to completion
and no context switch occurs, then the cache need not be saved. If a context switch
does occur then the cache will be saved on the top of the user’s Supervisor mode
register stack. This means some User mode data contained in the cache may be
temporary saved on the the Supervisor stack; however, this is not a problem.
The previous code determines the region of the cache currently in use, it does
not bring the stack into a valid condition. The code following the label
R_fixup:
in
the
User Mode Signals
section (section 5.5) does bring the stack into a valid
condition, and can be used to replace the code shown above. Once the stack support
registers are restored to a valid state, the
stack–cut–across
method described in the
later
User System Calls
section (section 5.7) can be used to
attach
the cache to the
Supervisor mode stack. By this method the storing of cache data can be prevented and
any unused portion of the cache is made immediately available to the interrupt
service routine.
5.5
PROCESSING SIGNALS IN USER MODE
Asynchronous context switches often occur because an interrupt has occurred
and must be processed by a handler function developed in C. A technique often
overlooked in real–time applications is using a signal handler to process the interrupt.
This often avoids much of the supervisor overheads associated with a context switch.
Additionally, a context switch requires the instruction cache to be flushed. Signal
handlers run in the context of the interrupted User mode process, this avoids the need
to flush the cache.
It is not necessary to store the contents of the local register file. After signal
support code has fixed–up the stack management support registers, the C level
handler code can continue to use the register stack as if the interrupted procedure had
executed a call to the handler function. In as little as 5.5 micro seconds from the time
of receiving the interrupt, the Am29000 can be executing the interrupt handler code
which was written in C.
Unlike asynchronous context switching, the interrupted context can not be
saved in the PCB. To do so would be convenient if a context switch was possible after
the signal handler had finished executing. The PCB structure would be already
updated. However, a further interrupt may occur during the C level signal handler
execution, which may itself result in an immediate context switch and require the use
of the PCB data save area. Additionally, the signal handler may do a
longjmp
to a
setjmp
which occurred in User mode code before the signal handler started
executing. For this reason the context information is placed on the User’s memory
stack pointed to by
msp
.