![](http://datasheet.mmic.net.cn/370000/ST20GP1_datasheet_16733510/ST20GP1_27.png)
ST20-GP1
27/116
4.6.4
Trap handlers and trapped processes can be set up and examined via the ldtraph, sttraph
ldtrapped and sttrapped instructions. Table 4.8 describes the instructions that may be used when
dealing with traps.
Trap instructions
The first four instructions transfer data to/from the trap handler structures or trapped process
structures from/to an area in memory. In these instructions
Areg
contains the trap group code (see
Table 4.4) and
Breg
points to the 4 word area of memory used as the source or destination of the
transfer. In addition
Creg
contains the priority of the handler to be installed/examined in the case of
ldtraph or sttraph. ldtrappedand sttrappedapply only to the current priority.
If the LoadTraptrap is enabled then ldtraphand ldtrappeddo not perform the transfer but set the
LoadTrap
trap flag. If the StoreTrap trap is enabled then sttraphand sttrappeddo not perform the
transfer but set the
StoreTrap
trap flag.
The trap enable masks are encoded by an array of bits (see Table 4.5) which are set to indicate
which traps are enabled. This array of bits is stored in the lower half-word of the
Enables
register.
There is an
Enables
register for each priority. Traps are enabled or disabled by loading a mask into
Areg
with bits set to indicate which traps are to be affected and the priority to affect in
Breg
.
Executing trapenbORs the mask supplied in
Areg
with the trap enables mask in the
Enables
register for the priority in
Breg
. Executing trapdisnegates the mask supplied in
Areg
and ANDs it
with the trap enables mask in the
Enables
register for the priority in
Breg
. Both instructions return
the previous value of the trap enables mask in
Areg
.
4.6.5
There are various restrictions that must be placed on trap handlers to ensure that they work
correctly.
1
Trap handlers must not deschedule or timeslice. Trap handlers alter the
Enables
masks,
therefore they must not allow other processes to execute until they have completed.
Restrictions on trap handlers
2
Trap handlers must have their
Enable
masks set to mask all traps in their trap group to
avoid the possibility of a trap handler trapping to itself.
Trap handlers must terminate via the tret (trap return) instruction. The only exception to this
is that a scheduler kernel may use restartto return to a previously shadowed process.
3
Instruction
Meaning
Use
ldtraph
load trap handler
load the trap handler from memory to the trap handler descriptor
sttraph
store trap handler
store an existing trap handler descriptor to memory
ldtrapped
load trapped
load replacement trapped process status from memory
sttrapped
store trapped
store trapped process status to memory
trapenb
trap enable
enable traps
trapdis
trap disable
disable traps
tret
trap return
used to return from a trap handler
causeerror
cause error
program can simulate the occurrence of an error
Table 4.7 Instructions which may be used when dealing with traps