INSERT[D0LANG];
NOMIDASINIT;
TITLE[d0go3];
*last edited by CT June 10, 1979
SETTASK[17];

RV[REFR,77];	*memory refresh address

*The following registers hold the volatile state of the processor on a fault: 
RV[RXALU,76];	*ALU result and SALUF
RV[RXAPC,75];	*APCTask&APC
RV[RXCTASK,74];	*CTASK.NCIA
RV[RXPPB,73];	*Page,Parity,BootReason
RV[RXSTK,72];	*Stackpointer

RV[RTMP,71];	*temporary

*The following registers are used for D0-Midas communication (RTMP is also used):
RV[RWSTAT,70];	*status register
RV[RDATA,67];	*holds data

*FFault determines how faults will be treated when programs are running.  If it is
*zero, all faults will be reported to Midas.  If FFault is nonzero, the kernel will
*send control through location 120 when a fault occurs and PARITY # 0 (faults with
*PARITY = 0 are breakpoints).
RV[FFAULT,66];

*Registers between 360 and 367 are used by the Midas overlays.  The following 
*registers, used by WriteMI,  are also in this range.
RV[RADDR,65];
RV[RCNT,64];
RV[RW0,63];
RV[RW1,62];



*Constants for Recv and Send
MC[RecvByte,12];
MC[RecvWord,16];
MC[SendByte,21];
MC[SendWord,25];

*The following are at fixed locations in Kernel.mc:
UserFault:	Return, AT[120];
NextCom:	Return, AT[7404];
Send:	Return, AT[7460];
Recv:	Return, AT[7464];

*d0go overlay
*Midas has set up all the volatile registers...
OverlayArea:
	CALL[Recv], RWSTAT ← RecvWord, AT[7500]; *get starting task and address
	Stkp ← RXSTK, AT[7501]; *Restore the stackpointer
	T ← RXALU, AT[7502];
	APCTASK&APC ← RDATA, AT[7503];
	RETURN, RESTORE, A ← RXAPC, LU ← T, AT[7504];

*Get here when the processor stops due to a fault (breakpoint or error).
* First check if this is a breakpoint (PARITY = 0).
BPEntry:
	lu ← ldf[RXPPB, 4, 4], AT[7505];
	dblgoto[ChkFF,Break, ALU#0], AT[7506];
	nop, AT[7507];
Break:
	RDATA ← 40000C, goto[SendMsg], AT[7510]; *we have a breakpoint - send #100 to Midas
ChkFF:
	lu ← FFAULT, dblgoto[UserFaultStart,MidasFault,R<0], AT[7511];
MidasFault:
	RDATA ← 40400c, goto[SendMsg], AT[7512];
UserFaultStart:
	LoadPage[0], AT[7513];
	gotop[UserFault], AT[7514];
SendMsg:	RWSTAT ← SendByte, Call[Send], AT[7515];
	goto[NextCom], AT[7516];

	END;