INSERT[D0LANG];
NOMIDASINIT;
TITLE[d0wrttpc];
*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[STACK4,64];

RV[RW0,63];
RV[STACK3,63];

RV[RW1,62];
RV[STACK2,62];

RV[STACK1,61];
MC[pStk1,361]; *pointer to stack1
RV[STACK0,60];


*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];

*d0wrttpc overlay
*Used by Midas to write TPC for any task.

*In order to write X into TPC[T], we must execute a call instruction at location X-1 (with
*properly suppressed carries), while executing in task T.
*Midas helps by putting the instruction in the right place, and loading Stack0 with 
*a pointer to it.  We notify to the instruction, which does a callp back to page 17.
*we then notify task 17 at NextCom.

*These instructions are here to be used as a table in d0mrw:
	LoadPage[17], at[100];
	CallP[RetLoc], at[101];  *this is the instruction Midas plants..
	goto[.], at[102];


OverlayArea:
	RTMP ← pStk1, at[7500];
	Stkp ← RTMP, at[7501];
	Stack1 ← 177400c, at[7502];
	Stack1 ← (Stack1) + (4c), at[7503]; *Stack1 points to task 17, location NextCom (7404)
	APC&APCTask ← Stack0, at[7504];
	return, FF1@[5], FF2@[17], at[7505]; *this is a loadpage[17], but we must trick MicroD

*The magic instruction set up by Midas does:
*	callp[RetLoc];

RetLoc:	APC&APCTask ← Stack, at[7506]; *Notify to task 17, location NextCom
	return, at[7507]; 


	END;