[comp.sys.nsc.32k] The SVC instruction

darylm@illian.UUCP (Daryl V. McDaniel) (08/10/88)

In a previous article the question, "Why doesn't the SVC instruction
advance the program counter ...", was asked.  Here are my views on this
subject.

The SVC instruction is one of three instructions in a class called
"Explicit Trap Instructions" and have the effect of causing deliberate
traps.  Each of the instructions, (BPT, FLAG, and SVC), have their own
entry in the interrupt/trap vector table.

These three software traps are then treated exactly the same as all other
traps (FPU, ILL, DVZ).  I am specifically ignoring the TRC trap since it is
handled as a special case.  The return address pushed by any trap except
TRC is the address of the first byte of the instruction during which the
trap occurred.

With the exception of the SVC trap, it is easy to see that the trap service
routine would want easy access to the instruction that caused the trap.  If
the ILL trap, for instance, were only given the address of the following
instruction it would have a difficult time determining what instruction
actually caused the trap.  It is not always possible to scan backwards
through an in-memory NS32000 procedure and determine the instructions and
where they begin.

Since we don't want to treat SVC the same way we do TRC then it would
require that a third special case be added to the trap handling sequence in
order to advance the PC to point to the byte following the SVC.
This is not an economical thing to do in terms of increased functionality
vs increased silicon usage.

Traps do not disable interrupts, as they are not associated with external
events.  Thus, SVC should not be used to implement atomic operations.

One way I have seen the SVC instruction used is as a 1-byte prefix to a user
defined instruction.  For example

	SVC			;Supervisory Call
	.BYTE	23		;  Op-code for puts
	.DWORD	BUFFADDR	;  Address of null-terminated string

could be a user defined instruction that is the equivalent of the C
language "puts" function.

The most popular method seems to consist of pushing the arguments on the
stack in the same manner as a procedure call.  A byte uniquely identifying
the operation to be performed is then loaded into a register and SVC
executed.

Of course, it is the responsibility of the trap handler to adjust the
return address to point to the instruction to be executed after the RETT.
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
Daryl V. McDaniel
Micronetics			USENET:	...tektronix!nosun!illian!darylm
4730 S.W. 182nd Ave.		 TELEX:	WUI 6972206
Aloha, OR   97007		 PHONE:	(503) 224-7056