//
// VMEMINIT -- initialize VMEM
// last edited August 1, 1977  1:48 PM
//
// Copyright Xerox Corporation 1979

	get "vmem.d"

external	// entry procedures
[	InitializeVmem	// (hashmap, hashmapsize, Bptab, lclist, llclist[, statbase, statproc, nobufsproc])
]


external	// procedures
[		// O.S.
	DefaultArgs
	FalsePredicate
	TruePredicate
	CallSwat
	SetBlock; Zero
		// VMEM
	defaultNoBufsProc
	LockOnly; LockZero
		// VMEMA
	REHASHMAP
]

external	// statics
[		// VMEM
	@HASHMAP; @HASHMAPSIZE; @HASHMAPMASK
	@HASHMAPSIZE2
	@HASHMAP1
	@HASHMAPTOP
	MAPSTATBASE
	@MapStatPtr
	MapStatProc
	NoBufsProc
	@Bpt; @BptLast
	EMPTYXX
	NAXX
	LockedCells; EndLockedCells; LastLockedCell
]


let InitializeVmem(HM, HMSIZE, BPTAB, LCL, LLCL, MSBASE, MSPROC, NBPROC; numargs n) be
[	DefaultArgs(lv n, -5, 0, FalsePredicate, defaultNoBufsProc)
	if (HMSIZE & (HMSIZE-1)) ne 0 then
	   CallSwat("Bad HMAPSIZE -- InitializeVmem")
	HASHMAP, HASHMAPSIZE = HM+(HM&1), HMSIZE
	HASHMAPMASK = HASHMAPSIZE-2
	HASHMAPSIZE2 = HMSIZE rshift 1
	HASHMAP1 = HASHMAP+HMflagOffset
	HASHMAPTOP = HASHMAP+HASHMAPSIZE
	MAPSTATBASE = MSBASE+(MSBASE&1)
	MapStatPtr = MAPSTATBASE
	MapStatProc = MSPROC
	NoBufsProc = NBPROC
	Bpt, LockedCells, EndLockedCells =
	  BPTAB, LCL, LCL+(LLCL & not 1)-LCsize
	LastLockedCell = LCL
	Zero(HASHMAP, HASHMAPSIZE)
	let dummypage(vp, bits) = valof
	 [ let hp = REHASHMAP(vp)
	   hp>>HM.NKEY = not vp
	   hp>>HM.FLAGWD = bits
	   resultis (hp-HASHMAP) lshift 7
	 ]
	EMPTYXX = dummypage(EmptyVP, CLEANbit+NOTREFbit+DUMMYbit)
	NAXX = dummypage(NaVP, CLEANbit+NOTREFbit+DUMMYbit)
	SetBlock(Bpt, NAXX, BptSize)
	@Bpt = 0
	LockOnly = FalsePredicate
	LockZero = TruePredicate
]