
131
Chapter 2 Applications Programming
2.5.3 Using Signals to Deal with Interrupts
Some C language interrupt handlers will not be able to run in Freeze mode.; be-
cause (as described in section 2.5) they are unsuitable leaf routines, or are not leaf
routines and thus require use of the register stack. In this case the signal trampoline
code described in section 4.4 and Appendix B must be used. The trampoline code is
called by the Freeze mode interrupt handler after critical registers have been saved on
the memory stack. The C language handler is called by the trampoline code after the
register stack is prepared for further use. Note that interrupts can occur at times when
the register stack condition is not immediately usable by a C language handler.
The signal mechanism works by
registering
a signal handler function address
for use when a particular signal number occurs. This is done with the library routine
signal()
. Signals are normally generated by abnormal events and the
signal()
routine
allows the operating system to call a user supplied routine which will be called to deal
with the event. The
signal()
function uses the
signal
HIF service to supply the address
of a library routine (
sigcode
) which will be called for all signals generated. (Note,
only the
signal
,
settrap
and
sigret
–type subset of HIF services are required.) The li-
brary routine is then responsible for calling the appropriate C handler from a table of
handlers indexed by the signal number. When
signal()
is used a table entry is
constructed for the indicated signal.
signal(sig_number, func)
sig_number;
(*func)(sig_number);
int
void
A signal can only be generated for an interrupt if the code vectored to by the in-
terrupt calls the shared library routine known as the
trampoline
code. It is known as
the trampoline code because signals
bounce
from this code to the registered signal
handler. To ensure that the trampoline code is called when an interrupt occurs, the
Freeze mode code vectored to by the interrupt must pass execution to the trampoline
code, indicating the signal which has occurred. The
signal_associate
macro shown
below can be used to install the Freeze Mode code and associate a signal number with
the interrupt or trap hardware number.
.reg
.reg
it0,gr64;freeze mode interrupt
it1,gr65;temporary registers
.macro signal_associate, trap_number, sig_number
sub
asgeu
add
add
const
const
const
gr1,gr1,4*4
V_SPILL,gr1,rab ;check for stack spill
lr1,gr121,0
;save gr121
lr0,gr96,0
;save gr96
gr121,290
;HIF 2.0 SETTRAP service
lr2,trap_number ;trap number, macro parameter
lr3,$1
;trap handler address
;get lr0–lr3 space