{Bdbinit.mc
Last edited: Purcell,      9-Feb-85 12:25:24  {%%} disabled mapinit
Last edited: don,      6-Feb-85  8:58:38 cleaned up a little -- no changes
Last edited: Purcell,     6-Feb-85  0:08:13 stall
Last edited: Purcell,    3-Feb-85 20:17:16  interface real page stays at 3 {%4}.
by cal 11-Jan-85 14:36:07
changed MAR's to Map's where appropriate  1-Feb-85 10:28:48
}

Reserve[0F6F]; Reserve[0F78]; Reserve[0F7F,0FFF];	{Kernel}

SetTask[0];

StartAddress[Germ];

Set[labelPageLow, 10];	{low 16 bits of file page number}
Set[bigVMrefFlg, 75'b];
Set[vmSizeLoc, 100'b];
RegDef[topPage, U, 0D];
RegDef[uVMFileSize, U, 6A];

Germ:
	, CANCELBR[StartDBInit,0F],	c1, at[0,2,Germ];
	, CANCELBR[StartDBInit,0F],	c1, at[1,2,Germ];
StartDBInit:
	Rx ← 41,	c2;
	DCtl ← Rx LRot0,	c3;
	
	ClrIntErr, c1;
	IOPCtl ← 1,	c2;
	Rx ← 040{wait 2 sec},	c3;
	
{Rx major, Q minor  }
bLp:	Noop, BRANCH[$, bL2],	c1;
	Noop, GOTO[bJn],	c2;
bL2:	Rx ← Rx  - 1, ZeroBr,	c2;
bJn:	Q ← Q - 1, ZeroBr, BRANCH[bLp, bStallDone],	c3;

bBurdock:
	IOPCtl ← 1, CANCELBR[$, 0F],	c1;
	Rx ← 41,	c2;
	DCtl ← Rx LRot0, TOSH ← 0,	c3;

bStallDone: CANCELBR[$],

	rhRx ← 0, Rx ← 0,	c1;
	Q ← 0FF + 1,	c2;
	TT ← 60{Vacant},	c3;

initMap:	{init 32mb map to vacant}
	Map ← [rhRx, Rx], BRANCH[$, initfixrh],	c1;
{%%}	{MDR ← TT{Vacant}},	c2;
	Rx ← Rx + Q, CarryBr, GOTO[initMap],	c3;
	
initfixrh:
	Rx ← rhRx + 1, PgCarryBr, LOOPHOLE[byteTiming],	c2;
	rhRx ← Rx LRot0, BRANCH[initMap, $],	c3;

{%B}{***32MB:  I/O Page back where Mesa wanted it!!!}
	Rx ← ~0FF,	c1;
	TOS ← 2{%B 5},		c2;		
	rhRx ← 0,	c3;

{Map[IOPageVp=0FF] ← 2 }

	Map← [rhRx, Rx],	c1;
{%%}	{MDR ← TOS,}	c2;
	,	c3;

{update Interface page and interpret FPTOVP}

LIa:	rhTOSH← 0,	c1;
	TOSH← 0FF+1,	c2; {base address of IOCB page}
	PV ← labelPageLow, c3;
{%M	MAR ← [{rDrh}rhTOSH, {rE}PV+0], c1;
	, c2;
	{rE}PV ← MD, c3;  {read number of pages xferred}
	
	uVMFileSize ← {rE}PV, c1;
	, c2;
	, c3;
%M}{pretend for now 16K pages or 8MB VM/ sysout}
	PV ← 40, c1;
	PV ← PV LRot8, c2;
	uVMFileSize ← {rE}PV, c3;

{Map[InterfacePageVp] ← 3}
	rhTT ← {6'b}INTERFACEspace, CANCELBR[$, 1],	c1;
	TT ← {0'b}INTERFACEbasePage,	c2;
	TT ← TT LRot8,	c3;

	Rx ← {3%M}{6}3{%4}{real interface page},	c1;
	Rx{300} ← Rx LRot8,	c2;
{	LVM
	{rBrh}rhRx ← {rB}Rx ← {rB}Rx + 030{dirty},	c3;
}
	rhRx ← 0C0, Rx ← Rx + 0C0{dirty},	c3;

LIb:	Map{InterfacePage} ← [rhTT,TT],	c1;
	MDR ← Rx{3C0},	c2;
	,	c3;
      

	MAR← [rhRx, 15'b{MachineType} + 0],	c1;
	MDR ← 6{\DANDELION},	c2;
	Q ← uVMFileSize,	c3;
					{**32MB: Say we can do big VM refs (will put real switch in later)}
LIc:	MAR ← [rhRx, bigVMrefFlg + 0], c1;
	MDR ← 1 {true}, c2;
	, c3;
	
	MAR ← [rhRx, vmSizeLoc + 0], c1;
	MDR ← Q, c2;
	, c3;

{%M	Q ← topPage{virtual},	c1;
	Q ← Q + 40,{ map not included}{topPage was measured as if map were 32KB}	c2;
	Q{NRealPages} ← Q + 0FF{+1}{bank 0 was not incl but},	c3;
%M}
	TT ← 09,	c1;
	TT ← TT LRot8,	c2;
	Q ← TT - 1,	c3;{faking size of real mem at 1.5 mb-gap or 1.0 mb + gap}
{%M}
LId:	MAR← [{rBrh}rhRx, 70'b{NRealPages} + 0],	c1;
	MDR ← Q{NRealPages} {← topPage}{rC{C00}},	c2;
	Noop,	c3;

{interpret FPTOVP setup}{assume FPTOVP doesn't cross segment}
{for i{acR} ← {{501'b=141h}}{201h}IOPage+1 to MaxRealPage{rC}	}
{	unless FPTOVP[i-1]=none{-1}	}
{	do MAP[FPTOVP[i-1]]:vp ← i	}

	MAR← [rhRx, 73'b{FPTOVPStart} + 0],	c1;
	,	c2;
	TT{F2Vpage} ← MD,	c3;

Set[fpvpPageOff, Add[IOPageHigh, 1{file1=real2}]];
Set[IOPagePage, Rshift[IOPage, 8]];

{%B offset 3{dbGap} seg's}
	TOS ← 3{dbGap}, c1;
	TOS ← TOS LRot8, c2;
	TT ← TT + TOS, c3;
{%B}


LIe:	TT{F2VrealPage+IOPageHigh} ← TT + fpvpPageOff,	c1;
	rhTT ← TT ← TT LRot8,	c2;
	TT ← TT and ~0FF,	c3;

	TT{F2V+IOPagePage} ← TT + IOPagePage,	c1;
	,	c2;
	rhRx ← 1{MapSpace}, c3;

	TOS ← IOPageHigh, c1;		{***32MB:  Count = 201H now}
	TOS ← TOS LRot8, c2;
	TOS ← TOS + IOPagePage +1, c3;

{interpret FPTOVP Loop 	}
{acR:	FPTOVP[i-1] ptr 	}
{rB:	FPTOVP[i-1]:vp	}
{rC:	i ← {{501'b=141h}}{201h}IOPage+1		}
{Q:	NRealPages= C00		}
{rBrh:	10000{Map}	}

{spin2:	GOTO[spin2],	c*;}{%%%}

f2vLp:	MAR← TT ← [rhTT, TT + 0],	c1;
		c2;
	Rx{vp} ← MD,	c3;

{%B}	Ybus ← Rx + 1, CarryBr{=1?},	c1;
	BRANCH[$, none],	c2;
	rhRx ← Rx ← Rx LRot8,	c3;

	,	c1;
	TOS ← TOS LRot8, XRefBr,	c2;
	Ybus ← TOS + 0F, NibCarryBr{nondisplay bank?}, BRANCH[$, fvMod],	c3;

{%B}	Map← [rhRx, Rx], BRANCH[fvNo, $],	c1;
{%%}	{MDR ← TOS{i},} GOTO[none],	c2;
fvNo:	Noop, GOTO[none],	c2;

fvMod:	Map← [rhRx, Rx], BRANCH[fvMNo, $],	c1;
{%%}	{MDR ← TOS{i} + 70}{move over flags to "dp" bit}, GOTO[none],	c2;
fvMNo:	Noop, GOTO[none],	c2;
none:	TOS ← TOS LRot8, CANCELBR[$, 1],	c3;

	TOS ← TOS + 1,	c1;
	Ybus ← TOS xor Q{NRealPages}, ZeroBr,	c2;
	TT ← TT + 1, BRANCH[f2vLp, $],	c3;

{%B}	Rx ← ~0FF,	c1;
	TOS ← 2{%B 5},		c2;		{***32MB:  I/O Page back where Mesa wanted it!!!}
	rhRx ← 0,	c3;

{Map[IOPageVp=0FF] ← 2 }

	Map← [rhRx, Rx],	c1;
{%%}	{MDR ← TOS},	c2;
	,	c3;

	{start u register init here}
LIf:	Rx{182} ← 0C1 LRot1,	c1;
	Rx ← Rx LRot1,	c2;
	uPcBreak ← Rx{304},	c3;

	,	c1;
	Q ← rhRx,	c2;
	UGsave ← Q,	c3;

	Rx ← VALspace,	c1;
	uValHigh ← Rx,	c2;
	{stackP ← 0,}	c3;

	Rx ← Rx xor ~Rx,	c1;
	unboundPvar ← Rx,	c2;
	unboundFvar ← Rx,	c3;

	uStkLimO ← Rx,	c1;
	uWP ← 0,	c2;
	uWDC ← 0{uWDC inited by mesaInit},	c3;

	Rx ←  ~0FD,	c1;
	Rx ← Rx LRot8,	c2;
	uBfResidualRhmask ← Rx{2FF},	c3;

	Rx ←  0A0,	c1;
	Rx ← Rx LRot8,	c2;
	uFreeStackBlock ← Rx{0A000},	c3;

	Rx ←  0FF + 1,	c1;
	uFxNoPushReturn ← Rx{100h},	c2;
	Rx ←  LShift1(Rx + Rx), SE←0,	c3;

	uFxInCall ← Rx{400h},	c1;
	Rx ←  7F,	c2;
	u7F ← Rx{7F},	c3;

	Rx ←  ~0FF,	c1;{OK}
	u0FF ← ~Rx{~0FF},	c2;
	uFF00 ←  Q ← Rx{~0FF},	c3;

	Rx ← Q{0FF00} or 1,	c1;
	Rx ← Rx LRot8,	c2;
	u1FF ← Rx{1FF},	c3;

	Rx ← Q{0FF00} or 3,	c1;
	Rx ← Rx LRot8,	c2;
	uTT3FF ← Rx{3FF},	c3;

	Rx ← Q{0FF00} or 3,	c1;
	Rx ← Rx LRot8,	c2;
	u3FF ← Rx{3FF},	c3;

	Rx ← Q{0FF00} or 0F,	c1;
	Rx ← Rx LRot8,	c2;
	u0FFF ← Rx{0FFF},	c3;

	Rx ← Q{0FF00} or 1F,	c1;
	Rx ← Rx LRot8,	c2;
	u1FFF ← Rx{1FFF},	c3;

	Rx ← Q{0FF00} or 3F,	c1;
	Rx ← Rx LRot8,	c2;
	uTT3FFF ← Rx{3FFF},	c3;

	Rx ← Q{0FF00} or 3F,	c1;
	Rx ← Rx LRot8,	c2;
	u3FFF ← Rx{3FFF},	c3;

	Rx ← Q{0FF00} or 7F,	c1;
	Rx ← Rx LRot8,	c2;
	u7FFF ← Rx{7FFF},	c3;

	Rx ← Q{0FF00} or 7,	c1;
	Rx ← Rx LRot8,	c2;
	u7FF ← Rx{7FF},	c3;

	,	c1;
	Rx ← Rx xor 1,	c2;
	u7FE ← Rx{7FF},	c3;

	Rx ← 0,	c1;
	uLispOptions ← Rx,	c2;
	c3;

	Rx ← 80,	c1;
	Rx ←  Rx LRot8,	c2;
	uBFmark ← Rx{8000},	c3;

{compliance: using uSTACKspace with duplicated high byte for bind ptr}

	Rx ← STACKspace,	c1;
	Rx ← Rx LRot8,	c2;
	Rx ← Rx or STACKspace,	c3;

	Noop,	c1;
	uSTACKspace ← Rx,	c2;
	Rx ← 0C0,	c3;

	Rx ←  Rx LRot8,	c1;
	Noop,	c2;
	uFXmark ← Rx{C000},	c3;

	Set[UFNTablePageHalf, Rshift[UFNTablebase, 9]];
	Rx ←  UFNTablePageHalf,	c1;
	Rx ←  Rx LRot8,	c2;
	uUFNTableBaseHalf ← Rx, GOTO[dbinitthru],	c3;

	{ E N D }