	.title	CACHE -- 11/70 Cache status reporter
	.IDENT	"V1.0"
	.nlist	ME,BEX,CND
	.enabl	lc
 	.sbttl	Author's Credits
 
;	Author:		Henry R. Tumblin
 
;	Date:		Nov. 21,1978
 
;	Version:	1.0

;	For:		Systems/Diagnostics
 
;	Module Name:	CACHE
 
;	Machine/System:	PDP-11/70 IAS V2.0
 
;	Type/Language:	Main/Assembler(MACRO-11)
 
;	Residence:	DB0:[1,20]CACHE.MAC
 
;	Build File:	CACHE.CMD
 
;	Abstract:	This program reports on the current status
;			of the PDP-11/70 Control and Memory System
;			Error(MSE) registers. This program is
;			only intended to run on an 11/70
 
;	Edits:	
 
;	Date	By	Reason
;   ----------	-----	--------------------------------------------
;	None

	.SBTTL	Tell the assembler which libmacs to use
 
	.mcall	qiow$,print,inh0,exit$s,C$C,DIR$,GTSK$
 
	.MACRO	MES,BIT,MES
 
	.PSECT	BMES
	.MS.=.
	.BYTE	LF,HT,40,40
	.ASCII	"MES"
	.BYTE	CR
	.MSZ.=.-.MS.
	.PSECT	BTAB
	.WORD	^B<BIT>,.MS.,.MSZ.	; MASK,Message @,Message length
	.PSECT
	.ENDM	MES
 
	C$C
 
	CTRLRG=177746			; Address of control register
					; on the external page
 
	MSEREG=177744			; Address of Memory system
					; error register on the
					; external page


	.SBTTL	Message table

	.PSECT	BMES,D,RO,REL
	.PSECT	BTAB,D,RO,REL
BTBLE:	
	.PSECT
 
MES	<0000000000000000>,<No errors detected within control register>
MES	<0000000000000001>,<Traps disabled>
MES	<0000000000000010>,<Unibus traps disabled>
MES	<0000000000000100>,<Forcing miss, cache group 0>
MES	<0000000000001000>,<Forcing miss, cache group 1>
MES	<0000000000010000>,<Forcing replacement by cache group 0>
MES	<0000000000100000>,<Forcing replacement by cache group 1>
 
CONREG:	.BLKW	1			; Buffer to store control register
 
CTRMES:	.ASCII	<LF><LF>"CACHE   --  Control register contains "
CTRVAL:	.BLKB	6
	.ASCII	<CR><LF>"	Decode of this value reveals that the "
	.ASCII	<CR><LF>"	processor is currently "
	CMESZ=.-CTRMES
 
	.EVEN

	.sbttl	MSE Register error messages

	.PSECT	BTAB
BTBL2:
	.PSECT
MES	<0000000000000000>,<No errors detected within MSE register>
MES	<0000000000000001>,<Main memory timeout>
MES	<0000000000000010>,<Main memory address parity error>
MES	<0000000000000100>,<Main memory even word>
MES	<0000000000001000>,<Main memory odd word>
MES	<0000000000010000>,<Address memory group 0>
MES	<0000000000100000>,<Address memory group 1>
MES	<0000000001000000>,<Data memory group 0>
MES	<0000000010000000>,<Data memory group 1>
MES	<0000000100000000>,<Error in maintenance>
MES	<0000001000000000>,<CPU Unibus abort>
MES	<0000010000000000>,<Unibus error>
MES	<0000100000000000>,<CPU Error>
MES	<0001000000000000>,<Unibus multiple parity error>
MES	<0010000000000000>,<Unibus parity error>
MES	<0100000000000000>,<CPU abort after error>
MES	<1000000000000000>,<CPU abort>

MSEMES:	.ASCII	<LF><LF>"CACHE   --  "
	.ASCII	"Memory System Error Register contains "
MSEVAL:	.BLKB	6
	.ASCII	<CR><LF>"	Decode of this value reveals that the "
	.ASCII	<CR><LF>"	processor has detected "
	MSESZ=.-MSEMES

	.even

MSER:	.BLKW	1			; Buffer to store Memory System
					; Error Register
 

	.sbttl	DPB's and other buffers

WRITE:	QIOW$	IO.WVB,1,2,50,,,<0,0,0>	; TT write DPB
 
TSKBUF:	.BLKW	16.			; Get task data buffer
 
GTSK:	GTSK$	TSKBUF			; Get task DPB
 
BADUSR:	.BYTE	CR,LF,HT,BEL
	.ASCII	" Sorry, only [1,*] users can use this utility"
	.BYTE	CR,LF
	BDUSSZ=.-BADUSR

	.sbttl	Start mainline code
	.PSECT	CACCOD,I,RO,REL
 
START:	DIR$	#GTSK			; This is for priv. users only
	CMPB	#1,TSKBUF+G.TSGC	; Are they within [1,*]?
	BEQ	5$			; EQ - then go on
	PRINT	#BADUSR,#BDUSSZ		; Else print bad user message
	JMP	EXIT			; And exit gracefully(always)

5$:	INH0				; Inhibit task switching
	MOV	@#CTRLRG,CONREG		; Get the contents of the control reg
	MOV	@#MSEREG,MSER		; And the memory system error reg
	CALL	..ENB0			; Enable task switching

	MOV	#CTRVAL,R0		; Set up for display
	MOV	CONREG,R1		; Set value to convert
	MOV	#1,R2			; No zero suppress
	CALL	$CBOMG			; Convert to ASCII
	PRINT	#CTRMES,#CMESZ		; Print message

	TST	CONREG			; Any errors here?
	BNE	10$			; NE - then something
	PRINT	BTBLE+2,BTBLE+4		; Print no error message
	BR	EXIT			; and leave

10$:	MOV	#6,R1			; Set count
	MOV	#BTBLE+6,R0		; Set pointer to message table
	CALL	CHKR			; go test the status

	MOV	#MSEVAL,R0		; Set up for display
	MOV	MSER,R1 		; Set value to convert
	MOV	#1,R2			; No zero suppress
	CALL	$CBOMG			; Convert to ASCII
	PRINT	#MSEMES,#MSESZ		; Print message
 
	TST	MSER			; Any errors here??
	BNE	40$			; NE - then check errors
	PRINT	BTBL2+2,BTBL2+4		; Print all ok message
	BR	EXIT			; And exit normally

40$:	MOV	#16.,R1			; Set count
	MOV	#BTBL2+6,R0		; Set table pointer
	CALL	CHKR			; And display
 
EXIT:	EXIT$S				; All thru, so exit

	.sbttl	Mask test subroutine

CHKR:	BIT	CONREG,(R0)+		; Test to see if bit set
	BEQ	20$			; EQ - then bit not set
	PRINT	(R0),2(R0)		; Else print a message
20$:	ADD	#4,R0			; Point to next entry
	SOB	R1,CHKR			; Loop until thru
	RETURN

	.END	START
