{
 File name:  Protected.mc
 Description: Protected microcode for Initial,
 Last Edited: bj, 10-Mar-86 22:52:36
}

{
	Copyright (C) 1980, 1981 by Xerox Corporation.  All rights reserved.
}

Set[OverlayStart, Add[ProtectFence, 1]];

Reserve[OverlayStart, 0FFF];

{
	Phase0Protected (Protected.mc, IOPBoot.mc) resides in 0 - 00FF
	Phase0 (Phase0.mc, DiskBootDLion.mc, EtherBootDLion.mc) resides in 0100 - 0FDF
	The BootKernel resides in 0FE0 - 0FFF
	Part of the BootKernel that can be overlaid resides in 0FD8 - 0FDF
}

SetTask[0];

{
	clobber only rC before going to external fault handler
}

Trap:		rC ← RRot1 ErrnIBnStkp, ClrIntErr, CANCELBR[$, 0F]		,c1, at[0];
		[] ← passTraps, ZeroBr						,c2;
		BRANCH[$, Trap1]						,c3;
		
		GOTOABS[ErrorHandlerLoc]					,c1; {pass the trap on}
Trap1:		acR ← bootTrap, GOTO[catchAll2]					,c1;
catchAll1:	Noop								,c1, at[Maintenance1Loc];
catchAll2:	Noop								,c2, at[Maintenance2Loc];
catchAll3:	rB ← 0, rBrh ← 0						,c3, at[Maintenance3Loc];

		MAR ← [rBrh, rB+1]						,c1;
		MDR ← acR and 0FF, CANCELBR[$, 0]				,c2;
		IOPCtl ← IOPInMode						,c3; {enable IOP}

infinite:	GOTO[infinite]							,c*, at[IdleLoc];

SetTask[1];  StartAddress[Refresh];

{
	We come here once per line, or every 28.8 usec. 
	That means 34,722 times per second
}

Refresh:	rJ ← rJ - 1, ZeroBr, Refresh, CANCELBR[$, 0F]			,c1; {Decrement clock low}
		BRANCH[NoCarry, RefCarry]					,c2;
RefCarry:	rG ← rG - 1, GOTO[TestTimeout]					,c3; {Decrement clock high}
NoCarry:	Noop								,c3;

TestTimeout:	Ybus ← rJ or rG, ZeroBr, Refresh				,c1;
		rN ← 1, BRANCH[$, Timeout]					,c2;
		ClrDPRq, GOTO[Refresh]						,c3;
Timeout:	uTimeout ← rN, ClrDPRq, GOTO[Refresh]				,c3;

{eof...}