
243
Chapter 5 Operating System Issues
process of a synchronous context switch. In a synchronous context switch, the
currently executing user task voluntarily gives up the processor to enable another
task to start execution. This is normally done via a system call. Because of the C
calling rules, the procedure which makes the system call cannot itself be a leaf
function. This means that the
lr1
value of the procedure making the system call
always contains a valid pointer to the top of the current activation record. If the
library routine implementing the system call does not lower the register stack (in
practical terms –– it is a small leaf procedure), the current
lr1
value is a valid pointer
to the top of the activation record.
At first glance it seems the large number of internal registers must result in an
expensive context save and restore time penalty. Further study shows that this is not
the case.
Much of the time required to complete a context switch is associated with
moving data between external memory and internal registers. However, a significant
portion of the time is associated with supervisor overhead activities.
When saving the context of the current process all the registers holding data
relevant to the current task must have their contents copied to the external data
memory save area.
A 29K processor contains a number of special purpose registers. There are eight
user task accessible special registers,
sr128–sr135
, used to support certain
instruction type execution. Assuming the exiting–task (the one that is being saved)
was written in C and the system call library code does not contain any explicit
move–to–special–register instructions, there is no need to save the registers as any
instructions requiring the support of special registers would have completed by the
time of the context switch system call. The AMD C calling convention does not
support preservation of these special registers across a procedure call.
Of the 15 supervisor–mode only accessible special registers (
sr0–sr14
), three
registers are allocated to controlling access to external data memory (the channel
registers). Because at the time of a synchronous context switch there is no
outstanding data memory access activity, these registers also need not be saved. This
is only true if an instruction causing a trap is used to issue the system call and there is
no outstanding data memory access DERR pending. The Am29000 processor
serializes (completes) all channel activity before trap handler code commences. For
more detail on the DERR pending issue, see the
Optimization
section which follows.
On entering the system call procedure, the 25 global registers used by the calling
procedure no longer contain essential data. This means that they need not be saved.
The register stack support registers and the relevant global supervisor registers must
be saved.
Additionally four global registers (
gr112–gr115
) reserved for the user (not
affected by the compiler) must be saved if any application program uses them. If
these registers are not being used on a per–User basis, but shared between all Users