//
// Print VMEM state
// last edited June 1, 1977  4:20 PM
//
// Copyright Xerox Corporation 1979

	get "vmem.d"

external	// entry procedures
[	PrintVmemState	// (st)
]


external	// procedures used
[		// O.S.
	Puts; Wns; Wos; Wss
]

external	// statics used
[		// VMEM
	@Bpt
	@HASHMAP
]


let PrintVmemState(st) be
[		// Print state of memory, by address
	let n = 0
	for i = 1 to 377b do
	 [ if VmemHptr(i)>>HM.NKEY eq (not NaVP) loop
	   if (n&3) eq 0 then Puts(st, $*N)
	   PrintVmemPage(st, i)
	   n = n+1
	 ]
	Wss(st, "*NNumber of pages = ")
	Wns(st, n, 0, 8)
	Puts(st, $*N)
		// Print BPT chain
	let n, tn = 0, @Bpt
	while (tn ne 0) & (n ne 400b) do
	 [ if (n&3) eq 0 then Puts(st, $*N)
	   PrintVmemPage(st, tn)
	   tn = (Bpt+tn)>>BPT.NEXT
	   n = n+1
	 ]
	Puts(st, $*N)
]

and PrintVmemPage(st, i) be
[	Wns(st, i, 4, 8)
	let hp = VmemHptr(i)
	Puts(st, $*S)
	Wos(st, not hp>>HM.NKEY)
	Puts(st, $*S)
	Puts(st, selecton hp>>HM.FLAGWD&GROUPbits into
	 [ case NFPGbit: $L
	   case NLPGbit: $F
	   case NFPGbit+NLPGbit: $I
	   default: $*S
	 ])
	Puts(st, (hp>>HM.DUMMY? $X, $*S))
	Puts(st, (hp>>HM.NOTREF? $*S, $R))
	Puts(st, (hp>>HM.CLEAN? $*S, $D))
	Puts(st, (hp>>HM.WGROUP? $W, $*S))
]

and VmemHptr(i) = HASHMAP+(Bpt+i)>>BPT.HASHX*2