[comp.arch] 29000 traps

rpw3@rigden.wpd.sgi.com (Rob Warnock) (05/04/90)

In article <UaCr2km00Vs8MMK257@andrew.cmu.edu> zs01+@andrew.cmu.edu
(Zalman Stern) writes:
+---------------
| By the way, what on the 29k is emulated other than floating point
| (and TLB reload)?
+---------------

Am29000 register stack-cache spill/fill is done with ASSERT instructions
(ASGE, etc.) comparing the current stack to the upper/lower limits of the
register file, which cause traps if the assertions is not met. The trap
handler then copies registers to/from the stack in memory and generally
adjusts things so that the assertion is now true, and dismisses.

As a side note, if the trap handler needs to leave "freeze mode" (the zeroth-
level interrupt mode on a 29k), usually in order to execute some instruction
that is not possible in freeze mode (such as load-multiple), and the trap is
one which can be emulated in user mode, it can be cheaper to "trampoline" to
a user-mode handler than do all the context saves/restores/C_environment_setup
needed to execute the trap handler in the kernel. The spill/fill handlers in
fact run in user mode. The trampoline-to-user hook is very cheap, only five
instructions as I recall.

In both Unix ports to the 29k, the facility was added to allow a user program
to establish a trap handler for any unused trap. One of the args to the ASxx
opcodes (and the EMULATE opcode) is the trap vector number to use. So it is
easy and inexpensive to have user-mode "interpreters" for hypothetical or
unimplemented "instructions".

This is not new. Circa 1970, the venerable PDP-10 had many Unimplemented
User Operations (UUOs), normally used to trap to the O/S for systems calls.
Actually, for half of those "unused" opcodes the hardware did a trap-to-user
without ever entering kernel mode. The Fortran compiler/run-time used some
of these to implement Fortran I/O as "opcodes". For example:

	1	FORMAT('Answers: '3I)
		WRITE(6,1) I, J, K(M,N)

would generate something like this (sorry if it's slightly misremembered):

		jrst	$f00002
	$f00001	asciz	/'Answers: '3I/
	$f00002	fio.	3,$f00001	; "fio." is (say) opcode 053, a UUO.
					; The "3" in the AC field says 3 args.
		fdata.	1,I		; Another UUO. The "1" says "int".
		fdata.	1,J
		move	t1,M		; Ordinary code intermixed to do
		subi	t1,1		;   subscripting.
		muli	t1,$f00003	; Row size of K.
		add	t1,N
		fdata.	1,-1(t1)	; Hardware resolves last indexing step.
		fend.			; Another UUO. says "doit".

A useful property was that the hardware did the usual effective address
computation -- (optional) indexing then (optional) indirecting (possibly
multi-level) -- before presenting the UUO (with the address field modified
to reflect the effective address) to the kernel or user trap handler. Neat!

-Rob


-----
Rob Warnock, MS-9U/510		rpw3@sgi.com		rpw3@pei.com
Silicon Graphics, Inc.		(415)335-1673		Protocol Engines, Inc.
2011 N. Shoreline Blvd.
Mountain View, CA  94039-7311