	.title	Traps - Common trap abend module
	.enabl	lc
	.nlist	me,bex,cnd
 
	.mcall	qiow$,dir$,exst$s,svtk$
 
	.GLOBL	TRPTAB,TRPRTN,TS

;	The SST vector table can be declared in two different ways.
;
;		1) Either dynamically through an executive directive, or
;		2) At task-build time through the task-build options list.
 
;	The most prevolent method is to use the following TKB sequence in
;	the options list.
;
;	program,program/-sp=program
;	TKB>/
;	Enter Options:
;	TKB>LIBR=SYSRES:RO
;	TKB>TSKV=TRPTAB:9
;	TKB>GBLPAT=segnam:TS:stacksize
;	TKB>//

	.IF	DF	D$$YM
;	Declare the SST vector table

;sstb:	svtk$	trptab,trpsiz		; Set trap SST vector address
	.ENDC 
;	Define the SST vector table

trptab:	.word	trprtn
	.word	trprtn
	.word	trprtn			
	.word	trprtn
	.word	trprtn
	.word	trprtn
	.word	trprtn
	.word	trprtn
	.word	trprtn

	.IF	DF	D$$YM 
;	trpsiz=<.-trptab>/2
	.ENDC 

BUF:	.BLKW	150.				; Buffer to build message in
 
WRITE:	QIOW$	IO.WVB,5,1,100,,,<BUF,0,40>	; DPB to perform I/O to
 
TS:	.BLKW	10.				; Crashing register save area
 
TRPDMP:	.ASCII	"Abend -- Aborting due to error%N"	; Error message
	.ASCII	"Crashing SP = %P%N"
	.ASCII	"Crashing PC = %P%N"
	.ASCII	"Crashing PS = %P%N"
	.ASCII	"%9SR0 = %P%N"
	.ASCII	"%9SR1 = %P%N"
	.ASCII	"%9SR2 = %P%N"
	.ASCII	"%9SR3 = %P%N"
	.ASCII	"%9SR4 = %P%N"
	.ASCIZ	"%9SR5 = %P"

	.even
	.IF	DF	D$$YM
	.GLOBL	TVINIT

TVINIT:	DIR$	#SSTB			; Declare the vector table
	MOV	SP,TS			; Declare Top of Stack
	RETURN				; Return to calling proc.
	.endc

$EXIT:	EXST$S	#EX$SEV			; Common exit point
 
TRPRTN:	MOV	SP,TS+2			; Save current SP
	BMI	12$			; Neg, then don't pop stack
	MOV	(SP)+,TS+4		; Save old PC and
	MOV	(SP)+,TS+6		;    the PSW
12$:	MOV	TS,SP			; Restore stack pointer
	MOV	R0,TS+10		; Save registers
	MOV	R1,TS+12		; when crash occured
	MOV	R2,TS+14		; ...
	MOV	R3,TS+16		; ...
	MOV	R4,TS+20		; ...
	MOV	R5,TS+22		; ...
 
;	Now set up the abend message in the buffer.

	MOV	#BUF,R0			; Point to destination area
	MOV	#TRPDMP,R1		; Point to format string
	MOV	#TS+2,R2		; Point to paramter list
	CALL	$EDMSG			; Format the message
 
	MOV	R1,WRITE+Q.IOPL+2	; Set message length 
	DIR$	#WRITE			; Output to user

	JMP	$EXIT			; Go exit

	.END
