;-*- Mode:LISP; Base:8; readtable: ZL -*-

(LOCALITY A-MEM)
a-abrt-1	(0)
a-abrt-2	(0)
a-abrt-tem	(0)
a-abrt-vma	(0)
a-abrt-md	(0)
a-abrt-flag	(1)	; if LSB set, illop on time out or parity error
(LOCALITY I-MEM)

;; Since this can be entered from any random place, can't
;; trash *any* registers except a-abrt-... defined here.
nubus-abort-handler
	((a-abrt-tem) m-tem)	;save M-TEM
	((a-abrt-vma) vma)	;save VMA
	((a-abrt-md) md)	;save MD
	;; read status bits
	((vma-start-read-unmapped) (a-constant #xf4ffc014))
	(no-op)
	(jump-if-bit-set (byte-field 1 14.) md abort-handler-timeout)
	(jump-if-bit-set (byte-field 1 15.) md abort-handler-parity-error)
	;fall in for 0
	((md) ldb (byte 2 6.) md)
	(jump-equal md (a-constant 1) abort-handler-parity-error)
	(jump-equal md (a-constant 2) abort-handler-timeout)
        ;fall in for 3 "try again later" (or 0, "no error", but we shouldn't be here)
	;try cycle again

Exit-Abort-Handler
		; reverse the two return address on the US
	((a-abrt-1) micro-stack-data-pop)
	((a-abrt-2) micro-stack-data-pop)
	((micro-stack-data-push) a-abrt-1)
	((micro-stack-data-push) a-abrt-2)
	((m-tem) a-main-dispatch)
	(jump-not-equal m-tem a-abrt-1 Exit-Abort-Handler-0)
	((vma-start-read) ldb (byte-field 31. 1) LC)	; do instruction fetch

Exit-Abort-Handler-0
	((vma) a-abrt-vma)	; restore VMA
	(jump-if-bit-set-xct-next (byte-field 1 19.) micro-stack-data Exit-Abort-Handler-1)
       ((m-tem) a-abrt-tem)	;restore M-TEM
	(popj-xct-next)		; use both pc's
       (popj-xct-next)

Exit-Abort-Handler-1		; 1st pc no-op'ed, throw it away
	((m-garbage) micro-stack-data-pop)
	(popj)

abort-handler-timeout
abort-handler-parity-error
	((md) a-abrt-flag)
	(call-if-bit-set (byte-field 1 0) md ILLOP)
	((vma-start-read-unmapped) (a-constant #xf4ffc014))
	(no-op)
	((vma) m-minus-one)
	(jump Exit-Abort-Handler)
