; IfsVMemA.asm -- IFS VMem assembly code
; Copyright Xerox Corporation 1982
; Last modified September 17, 1982  1:41 PM by Taft

; Derived from VMem package, by P. Deutsch
;   VMEMA.ASM - actual mapping done in microcode
;   last modified June 14, 1976  2:36 PM

	.EXTN	MAPTRAP
;
	.ENT	REHASHMAP
	.ENT	VRR,VWR,VRR1,VWR1,VRR2,VWR2,VRRP,VWRP
;
	.DUSR	RDREF = 74400
	.DUSR	WTREF = 75000
	.DUSR	SWAT = 77400
;
	getframe = 370
	return = 366
;
	.ZREL
VRR:	VRRX
VWR:	VWRX
VRR1:	VRR1X
VWR1:	VWR1X
VRR2:	VRR2X
VWR2:	VWR2X
VRRP:	VRRPX
VWRP:	VWRPX
;
	.SREL
REHASHMAP:REMAP
;
	.NREL
;
;  ROUTINES TO DO SOFTWARE MAPPING
;  IF THERE IS A FAULT, A BCPL ROUTINE 'MAPTRAP' IS CALLED
;  IF THERE IS NO FAULT, NO BCPL STACK SPACE IS USED
;
MAPTR:	0	; save hashmap ptr
MPTRP:	MAPTRAP
;
VRRX:	STA	3,1,2
	MOV	0,3
	LDA	0,0,3
	LDA	1,1,3
	JMP	DOAR1
;
VRRPX:	LDA	1,RMSK
	AND	0,1
	SUBS	1,0
	MOVS	1,1
	JMP	VRR2X
VRR1X:	MOV	0,1
	SUB	0,0
VRR2X:	STA	3,1,2	;SAVE RETURN
DOAR1:	RDREF		;microcode instruction
	JMP	NOTINRD	;MISSING PAGE ON READ
	MOV	3,0
	LDA	3,1,2
	JMP	1,3	;RETURN WITH CORE ADDR. IN AC0
NOTINRD:STA	3,MAPTR
	LDA	3,RMSK
	AND	3,0
	JSR	@getframe
	  7
	SWAT
	SUB	1,1	;READ REF
MTRAP:	STA	1,6,2
	LDA	0,5,2
	LDA	3,LMSK
	AND	0,3
	LDA	0,4,2
	ADDS	3,0	; form hash key
	LDA	3,MAPTR
	STA	3,3,2
	JSRII	MPTRP
	3
	LDA	0,4,2
	LDA	1,5,2
	LDA	3,6,2
	LDA	2,0,2	; get rid of frame
	MOV	3,3,SZR
	JMP	DOAW1
	JMP	DOAR1
;
VWRX:	STA	3,1,2
	MOV	0,3
	LDA	0,0,3
	LDA	1,1,3
	JMP	DOAW1
;
VWRPX:	LDA	1,RMSK
	AND	0,1
	SUBS	1,0
	MOVS	1,1
	JMP	VWR2X
VWR1X:	MOV	0,1
	SUB	0,0
VWR2X:	STA	3,1,2
DOAW1:	WTREF		;microcode instruction
	JMP	WFAULT	;NOT IN OR NOT DIRTY
	MOV	3,0
	LDA	3,1,2
	JMP	1,3
WFAULT:	STA	3,MAPTR
	LDA	3,RMSK
	AND	3,0
	JSR	@getframe
	  7
	SWAT
	ADC	1,1	;WRITE REF
	JMP	MTRAP
;
LMSK:	177400
RMSK:	377
;
; COMPUTE HASH INDEX FOR NEW PAGE WHEN
; RECONSTRUCTING HASH TABLE AFTER PAGE FAULT
;
REMAP:	STA	3,1,2
	LDA	1,RMSK
	ANDS	0,1
	LDA	3,LMSK
	ANDS	3,0
DORM1:	RDREF			;AC0,AC1 HAS VIRTUAL ADDR
	MOV	3,0,SKP	; NO SKIP, HASHMAP PTR IN AC3
	SUB	0,0	; SKIP, ENTRY ALREADY PRESENT
	LDA	3,1,2
	JMP	1,3		;RETURNS POINTER TO EMPTY ENTRY
;
	.END