Google
 

Trailing-Edge - PDP-10 Archives - de-10-omona-v-mc9 - common.mac
There are 22 other files named common.mac in the archive. Click here to see a list.
TITLE COMMON - MONITOR COMMON DATA AREA AND CONFIGURATION DEFINITION - V271253
SUBTTL PART 6 COMMON.MAC - T. HASTINGS/PH/TWE/DAL/EVS  04 DEC 78
	SEARCH	F,S
	HIORG==:MONORG
	$RELOC
	$ABS






;COPYRIGHT (C) 1973,1974,1975,1976,1977,1978 BY
;DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS.
;
;
;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED
;ONLY  IN  ACCORDANCE  WITH  THE  TERMS  OF  SUCH LICENSE AND WITH THE
;INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR ANY  OTHER
;COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
;OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF THE  SOFTWARE  IS  HEREBY
;TRANSFERRED.
;
;THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT  NOTICE
;AND  SHOULD  NOT  BE  CONSTRUED  AS A COMMITMENT BY DIGITAL EQUIPMENT
;CORPORATION.
;
;DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY  OF  ITS
;SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.
XP VCOMMN,271253
				;PUT VERSION NUMBER IN GLOB AND LOADER STORAGE MAP
V1088==3			;1088 LIR VERSION NUMBER



REPEAT 0, <
;THE COMMON SUBPROGRAM CONSISTS OF 6 FILES ASSEMBLED TOGETHER AS ONE SUBPROGRAM
	1. F.MAC -- FEATURE TESTS (OUTPUT OF MONGEN).
	2. S.MAC - THE USUAL SYSTEM SYMBOL DEFINITIONS ASSEMBLED WITH
	EVERY	MONITOR SUBPROGRAM
	3. HDWCNF.MAC -- HARDWARE CONFIGURATION
	4. TTYCNF.MAC -- TERMINAL CONFIGURATION
	5. REMCNF.MAC -- REMOTE CONFIGURATION
	6. COMMON.MAC - THE REST OF THIS PROGRAM WHICH IS THE SAME SOURCE FOR
	ALL	CONFIGURATIONS.  HOWEVER, THE ASSEMBLIES ARE CONDITIONED BY
	SYMBOLS	AND MACROS DEFINED IN 2.

	THE	FOLLOWING SYMBOLS AND TABLES ARE GENERATED BELOW:

	A. MONITOR STARTUP LOCATIONS (400-407), HENCE LOAD THIS FIRST.
	B. JOB TABLES - LENGTH DEPENDENT ON MAXIMUM NUMBER OF JOBS ALLOWED
	C. ALL VARIABLE STORAGE NOT ASSOCIATED WITH A PARTICULAR DEVICE
	D. COMMON SUBROUTETURNS
	E. COMMON BYTE POINTERS
	F. TABLE OF SERVICE ROUTINE INTERRUPT LOCS TO BE LINKED BY ONCE ONLY CODE
	G. TABLE OF DEVICE DATA BLOCK ADDRESSES AND NUMBER TO BE USED BY ONCE TO
		LINK THEM TOGETHER AND GENERATE MULTIPLE COPIES.
	H. ASSIGNMENT OF PI CHANNELS
	I. PI CHANNEL SAVE AND RESTORE ROUTINES
	J. UUO TRAP LOCATIONS 40/41, 60/61
	K. APR INTERRUPT LOCATIONS CPU0,1, KA10/KI10
	L. SYSTEM CRASH STOP CONI'S.
	NOTE:  SEE COMDEV FOR DEVICE DEPENDENT CODE, DATA, AND SYMBOLS


LEVEL D DISK SERVICE PARAMETERS:

	ALL	SYMBOLS ANAS ONATIONS ARE IN A SEPARATE FILE CALLED
	COMMOD.MAC WHICH IS ALSO ASSEMBLED WITH S AND CONFIG (BUT NOT WITH FEATURS FILES).
	THE	SEPARATE FILE IS FOR TWO REASONS:
	1.  ANTICIPATING MULTIPROCESSING SYSTEMS WHICH SHARE DISKS AND 1 16K MEMORY
	(THE DATA MUST BE IN THE COMMON MEMORY)
	2.  ELIMINATE THE NEED TO ASSEMBLE COMMOD IF NOT A DISK SYSTEM
	(COMMOD.MAC TAKES LOTS OF CORE FOR ITS COMPLICATED MACROS)


THE FOLLOWING EQUATES ARE GENERATED FOR REMOTE
COMMUNICATIONS PROGRAM SETUP:
	LOCSTA	- THE STATION NUMBER OF THE (PDP10) CENTRAL SITE

		 COMMUNICATIONS SOFTWARE
>
IFE FTNET,<IFN M.NET,<PRINTX ?ASSEMBLE SOURCES WITH FTNET=-1
			M.NET==0>>
IFN M.NET,<
	XP	LOCSTA,OURNNM	;DEFINE THE LOCAL NODE NUMBER
>;END OF IFN M.NET

IFE M.NET,<
IFNDEF LOCSTA,<	XP	LOCSTA,0>	;NO, NETWORK DEFINE LOCAL NODE=0
>;END OF IFN M.NET

IFN	M.TTY-50,<
	PRINTX	?Wrong version of MONGEN was used to
	PRINTX	? make TTYCNF.MAC go back and use version
	PRINTX	? 50 of MONGEN
	PASS2
	END
>
IFN FTEMRT,<IFE M.KL10,<PRINTX ? CPU MUST BE A KL10 TO SELECT EBOX/MBOX RUNTIME>>
SUBTTL CONVERT MONGEN SYMBOLS
REPEAT 0,<

;THIS SECTION CONVERTS NEW MONGEN SYMBOLS TO OLD MONGEN SYMBOLS
;SO THAT THE REST OF COMMON AND MONITOR CAN STILL USE THE OLD
;SYMBOLS.  THIS WAS DONE RATHER THAN CONVERTING ALL OF THE
;MONITOR TO NEW SYMBOLS FOR TWO REASONS:
; 1.  IT IS EASIER AND FASTER AND LESS LIKELY TO INTRODUCE BUGS, AND
; 2.  IT ALLOWS CUSTOMERS TO USE OLD MONGEN WITH A MINIMUM
;OF TROUBLE: ONLY A FEW EXTRA SYMBOLS MUST BE DEFINED.
;THE MONITOR WILL PROBABLY BE CONVERTED TO THE NEW MONGEN SYMBOLS
;AFTER THE 5.04 RELEASE.  THE ORDER HERE PARALLELS THE OLD
;MONGEN ORDER.

>

DEFINE TEMPM(TYPE),<
IRP TYPE,<
IFN M.'TYPE'10,<ZZ==ZZ+1>
>>
	ZZ==0
	TEMPM	<KA,KI,KL>
IFE ZZ,<
IFDEF M.KA10,<
	PRINTX	?USE MONGEN WITH KL10 SUPPORT
	END
>
	PRINTX	?NONE OF M.KA10, M.KL10 OR M.KI10 SET NON-ZERO
	END
>
IFN ZZ-1,<
	PRINTX	?MORE THAN 1 CPU TYPE SELECTED
>

DEFINE	TEMPM(A,B),<
IFN M.'A'10,< IFE FT'A'10,<
	PRINTX	? A'10 SELECTED BUT FT'A'10 IS ZERO
>>
IFN M.'A'10,<
IRP B,<
IFN FT'B'10,<
	PRINTX	? A'10 SELECTED BUT FT'B'10 IS NOT ZERO
>>>
>
	TEMPM(KA,<KI,KL>)
	TEMPM(KI,<KA,KL>)
	TEMPM(KL,<KA,KI>)
XP SYS40N,0		;NEW MONGEN MAKES SWAPPING SYSTEMS ONLY
XP SYS50N,1
XP DSKN,1
XP LOGINN,1

XP APRSN,M.C0SN		;APR SERIAL NUMBER (REALLY PROCESSOR 0)
XP APR0SN,M.C0SN	;PROCESSOR 0 SERIAL NUMBER
XP APR1SN,M.C1SN	;PROCESSOR 1 SERIAL NUMBER
XP CP0P6N,0		;PROCESSOR 0 IS NOT A PDP 6
XP CP1P6N,0		;PROCESSOR 1 IS NOT A PDP 6
XP CP0KAN,M.KA10	;PROCESSOR 0 MAY BE A PDP 10
XP CP1KAN,M.KA10	;PROCESSOR 1 MAY BE A PDP 10
XP CP0KIN,M.KI10	;PROCESSOR 0 MAY BE A KI10
XP CP1KIN,M.KI10	;PROCESSOR 1 MAY BE A KI10
XP CP0KLN,M.KL10	;PROCESSOR 0 MAY BE A KL10
XP CP1KLN,M.KL10	;PROCESSOR 1 MAY BE A KL10
XP CPUN,M.CPU		;NUMBER OF PROCESSORS

XP LEVDN,1		;NEW MONGEN MAKES ONLY LEVEL D DISK SERVICE
XP LEVCN,0
XP CHNN,M.CHN		;NUMBER OF DATA CHANNELS FOR DISKS
	DEFINE	CALLF(CHN),<
XP	C'CHN'FHN,M.C'CHN'FH
>	;END MACRO DEFINITION

	DEFINE CHMFH(CHN),<
	CALLF	(\CHN)
>	;END MACRO DEFINITION

	DEFINE	CALLS(CHN),<
XP	C'CHN'FSN,M.C'CHN'FS
>

	DEFINE	CHMFS(CHN),<
	CALLS	(\CHN)
>	;END MACRO DEFINITION


	DEFINE	CALLR(CHN),<
XP	C'CHN'RPN,M.C'CHN'RP
>
	DEFINE	CHMRP(CHN),<
	CALLR	(\CHN)
>

	DEFINE	CALLD(CHN),<
XP	C'CHN'DPN,M.C'CHN'DP
>	;END MACRO DEFINITION

	DEFINE CHMDP(CHN),<
	CALLD	(\CHN)
>	;END MACRO DEFINITION

	DEFINE	CALLM(CHN),<
XP	C'CHN'MDN,0
>
	DEFINE	CHMMF(CHN),<
	CALLM	(\CHN)
>
ZZ==0
ZZF==0
ZZS==0
ZZD==0
ZZR==0

REPEAT CHNN,<
	CHMFH	(ZZ)
	CHMFS	(ZZ)
	CHMRP	(ZZ)
	CHMDP	(ZZ)
	CHMMF	(ZZ)
ZZ==ZZ+1
>

	DEFINE	UNFH(KON,LIST),<
ZZCNT==0
IRP LIST,<
	IFE ZZCNT-KON,<
	XP FH'LIST'UN,M.FH'LIST
	>	;END IFE
ZZCNT==ZZCNT+1
>	;END IRP
>	;END MACRO DEFINITION

REPEAT M.RC10,<
	UNFH	(ZZF,<A,B,C,D,E,F,G,H>)
ZZF==ZZF+1
>

	DEFINE	UNFS(KON,LIST),<
ZZCNT==0
IRP	LIST,<
	IFE ZZCNT-KON,<
	XP	FS'LIST'UN,M.FS'LIST
	>	;END IFE
ZZCNT==ZZCNT+1
>	;END IRP
>	;END MACRO DEFINITION

REPEAT	M.RH1S,<
	UNFS	(ZZS,<A,B,C,D,E,F,G,H>)
ZZS==ZZS+1
>


	DEFINE	UNRP(KON,LIST),<
ZZCNT==0
IRP	LIST,<
	IFE ZZCNT-KON,<
	XP	RP'LIST'UN,M.RP'LIST
	>	;END IFE
ZZCNT==ZZCNT+1
>	;END	IRP
>	;END MACRO DEFINITION
REPEAT M.RH1P,<
	UNRP	(ZZR,<A,B,C,D,E,F,G,H>)
ZZR==ZZR+1
>


	DEFINE	UNDP(KON,LIST),<
ZZCNT==0
IRP LIST,<
	IFE ZZCNT-KON,<
	XP DP'LIST'UN,M.DP'LIST
	>	;END IFE
ZZCNT==ZZCNT+1
>	;END IRP
>	;END MACRO DEFINITION

REPEAT	M.RP10,<
	UNDP	(ZZD,<A,B,C,D,E,F,G,H>)
ZZD==ZZD+1
>

XP RD10N,M.RC10
XP RH10NS,M.RH1S
XP RH10NP,M.RHP4
XP RP10N,M.RP10
XP RA10N,0		;NO MDF

	DEFINE	SYSDEV,<
	SIXBIT	/DSK/
>
XP JOBN,M.JOB+1


IFG	JOBN-^D512,<XP JOBN,^D512
		PRINTX %NUMBER OF JOBS REDUCED TO MAX=511>
XP COREN,M.CORE
XP PDP10N,M.KA10!M.KI10!M.KL10
XP PDP6N,MD.P6
XP KT10AN,MD.2RR
XP SEGN,MD.SEG
XP DDTN,MD.DDT

XP EDITN,0

XP PTRN,M.PTR
XP PTPN,M.PTP
XP PLTN,M.PLT
XP LPTN,M.LPT
XP DLPTN,M.DLPT
XP DCDRN,M.DCDR
XP MOVIEN,MD.MOV
XP CDRN,M.CDR
XP CR10N,MD.C10
XP CPFN,M.CDP
XP CDPN,M.CDP
XP VBCN,M.VBXC
	IFN	FTXTC,<
XP XTCN,M.XTC
>
	IFE	FTXTC,<
	IFN	M.XTC,<
PRINTX	?NO DA28 SUPPORT WITH FTXTC=0
PRINTX	?PROCEEDING ASSUMING NO DA28
XP M.XTC,0
XP M.XTL,0
>
XP XTCN,0
>
	IFE	M.XTC,<
XP M.XTL,0
XP XTTDSP,CPOPJ
XP XTKLDB,CPOPJ
XP XTUUO,CPOPJ
XP XTCTTY,CPOPJ2
XP XTCIOS,CPOPJ
XP XTCSEC,CPOPJ
>

IFN FTDAS78,<
XP M78LM,-M.D78L		;NEG # OF LINES
>	;END IFN FTDAS78

XP DISN,M.DIS
XP PENN,M.DIS
XP T340N,M.340
XP TVP10N,M.VP10
XP T30N,0		;NO TYPE 30
;DEFINE ALL DL10 SYMBOLS

	DLX.CK(1)		;MACRO DEFINED IN S.MAC

IFN FTTYPE!DLX.44,<
IFE FTTYPE,<
	PRINTX	?DEFINING A DC44 REQUIRES FTTYPE TO BE ON
	PRINTX	?M.DC44 HAS BEEN TURNED OFF
PDP11N=PDP11N-DLX.44
M.DC44=0			;NUMBER OF MONGEN

DLX.44=0			;ACTUAL NUMBER
>
IFN DLX.44,<EXTERN TYPSER,D76INT>>  ;END OF IFN FTTYPE!DLX.44

IFE DLX.44,<
	XP	INITRT,CPOPJ
	XP	DATDON,CPOPJ
	XP	DATREL,CPOPJ
	XP	DATCOP,CPOPJ
	XP	TYPSTS,CPOPJ
	XP	D44DWN,CPOPJ
>	;END OF IFE DLX.44

IFN FTDAS78!DLX.78,<
IFE FTDAS78,<
	PRINTX	?DEFINING A DAS78 REQUIRES FTDAS78 TO BE ON
PDP11N=PDP11N-DLX.78
DLX.78=0			;ACTUAL NUMBER
>
IFN DLX.78,<EXTERN D78INT>>	;END OF IFN FTDAS78!DLX.78

IFE DLX.78,<
	XP	CALL78,CPOPJ
	XP	D78SEC,CPOPJ
	XP	D78MIN,CPOPJ
>

IFE <DLX.78 - PDP11N>,<
XP	CALL11,CPOPJ
XP	D76MIN,CPOPJ
XP	DLXSEC,CPOPJ
>

IFN DLX.76,<EXTERNAL D76INT>
IFE PDP11N,<
	XP	D76MIN,CPOPJ
	XP	CALL11,CPOPJ
	XP	D76SIL,CPOPJ
	XP	DLXSEC,CPOPJ
>
IFE <DLX.78-PDP11N>,<DLXWIN=0>

DEFINE TDMAC(KON,LIST),<
ZZCNT==0
IRP LIST,<
	IFE ZZCNT-KON,<
	XP DT'LIST'N,M.DT'LIST'
	>	;END IFE
ZZCNT==ZZCNT+1
>	;END IRP
>	;END MACRO DEFINITION

ZZ==0

REPEAT M.TD10,<
	TDMAC (ZZ,<A,B>)
ZZ==ZZ+1
>
IFNDEF M.DTA, <M.DTA==0>
IFNDEF DTAN, <DTAN==0>
IFNDEF M.DTB, <M.DTB==0>
IFNDEF DTBN, <DTBN==0>
XP DTCN,MD.DTC

IFNDEF M.TM10,<XP M.TM10,0>
IFNDEF M.TC10,<XP M.TC10,0>
IFNDEF M.TX01,<XP M.TX01,0>
IFNDEF M.TM02,<XP M.TM02,0>
XP TAPN,M.TM10+M.TC10+M.TX01+M.TM02
IFNDEF MTCN,<MTCN==0>

IFG TAPN,<
DEFINE KONMAC <		;MACRO FOR LOOPING THROU TAPE CONTROLLERS
	..KON==0
	REPEAT TAPN,<
	  TAPMAC(\..KON)
	  ..KON==..KON+1>
>

DEFINE TAPMAC (X) <
	IFE M.MT'X'T,<TM10A==TM10A+1>	;COUNT TM10A CONTROLLERS
	IFE <M.MT'X'T-K.TMB>,<TM10B==TM10B+1> ;COUNT TM10B CONTROLLERS
	IFE <M.MT'X'T-K.TC1>,<TC10C==TC10C+1>
	IFE <M.MT'X'T-K.TX1>,<DX10N==DX10N+1>	;COUNT OF DX10 CHLS
	IFE <M.MT'X'T-K.TM2>,<TM02N==TM02N+1>
	XP MT'X'N,M.MT'X	;# OF UNITS / CONTROLLER
>

TC10C==0
TM10A==0	;INIT VALUES
TM10B==0
DX10N==0
TM02N==0

	KONMAC			;PERFORM GOOD STUFF

>	;;; END IFG TAPN

IFNDEF TM10A,<TM10A==0>
IFNDEF TM10B,<TM10B==0>
IFNDEF DX10N,<DX10N==0>
IFNDEF TC10C,<TC10C==0>
IFNDEF TM02N,<TM02N==0>
XP PTYN,M.PTY

XP TEMPN,M.TMP
IFN M.TMP,<
XP TMPN,MD.TWJ
XP TMPLN,MD.TLJ
>

XP SYSCN,M.SYSC
XP LOKN,M.LOK
XP CMNN,M.MGC
XP RTTRPN,M.RTD
XP HPQN,M.HPQ

XP	M.CTY1,0		;DEFINE M.CTY1 FOR CONVENIENCE
IFN FTMS,<IFG CPUN-1,<IFN FTCTY1,<XP M.CTY1,1>>>	;NOT REALLY CHANGABLE BY MONGEN
XP M.TLTL,M.TLTL+M.XTL		;REDEFINE FOR XTC LINES
XP TTD28N,M.XTL
IFG M.CTY1 ,<XP CT1LIN,M.TLTL+M.RTTY>	;CPU1 CTY (CTY1)
IFE M.CTY1,<XP CT1LIN,-1>;	;IF DON'T WANT CTY1 MAKE SURE CT1LIN IS ILLEGAL
ZZZ==0
XP TCONLN,M.TLTL+M.RTTY+M.CTY1	;LINE NUMBER FOR CTY (NOT ON SCANNER)

XP CTYLIN,TCONLN

				;  M.CTY1=1 MEANS WANT CTY1(CPU1-CTY)

	DEFINE	OPRL(LINE),<
IFIDN <LINE> <CTY>,<SIXBIT /CTY/>
IFIDN <LINE> <CTY1>,<SIXBIT /CTY1/>
IFDIF <LINE> <CTY>,<IFDIF <LINE><CTY1>,<SIXBIT /TTY'LINE/>>
>

	DEFINE CALLM(NAME,LINE),<
NAME'LINE==1
>

	DEFINE TTYMAC(TYPE),<
	XLIST

	DEFINE L(A,B),<
IFB <B>,<IFIDN <A> <CTY>,<
	ZZLINE==CTYLIN
	ZZBEG==CTYLIN
	ZZEND==CTYLIN
>	;END IFIDN
	IFIDN <A> <CTY1>,<
	IFE M.CTY1,<PRINTX %CTY1 IN TTYCNF WHEN FTCTY1 OR FTMS=0>
	IFN M.CTY1,<
	ZZLINE==CT1LIN
	ZZBEG==CT1LIN
	ZZEND==CT1LIN
>>	;END IFN M.CTY1 END IFIDN
	IFDIF <A> <CTY>,<
	IFDIF <A> <CTY1>,<
	ZZLINE==A
	ZZBEG==A
	ZZEND==A
>>	;END IFDIF IFDIF
>	;END IFB
IFNB <B>,<ZZLINE==A
	ZZBEG==A
	ZZEND==B
>	;END IFNB
REPEAT ZZEND-ZZBEG+1,<
	CALLM	(TYPE,\ZZLINE)
ZZLINE==ZZLINE+1
>>	;END REPEAT AND DEFINITION OF L
	MAC'TYPE
	LIST
>	;END DEFINITION OF TTYMAC
	TTYMAC DSD
	TTYMAC TAB
	TTYMAC RMT
	TTYMAC LCP
	TTYMAC HLF
	TTYMAC SLV
	TTYMAC FRM
	TTYMAC INI
	DEFINE	CALLM(NAME,LINE,VALUE),<
NAME'LINE==VALUE
>

	DEFINE	TTYMAC(TYPE),<
	XLIST

	DEFINE	L(M,N,P),<
IFIDN <M> <CTY>,<
	ZZBEG==CTYLIN
	ZZLINE==CTYLIN
>
IFIDN <M> <CTY1>,<
	ZZBEG==CT1LIN
	ZZLINE==CT1LIN
>
IFDIF <M> <CTY>,<
IFDIF <M> <CTY1>,<
	ZZBEG==M
	ZZLINE==M
>>
IFB <P>,<
	ZZEND==ZZBEG
	ZZVAL==N
>
IFNB <P>,<
	ZZEND==N
	ZZVAL==P
>

REPEAT ZZEND-ZZBEG+1,<
	CALLM	(TYPE,\ZZLINE,ZZVAL)
ZZLINE==ZZLINE+1
>>	;END REPEAT AND DEFINITION OF L
	MAC'TYPE
	LIST
>	;END DEFINITION OF TTYMAC

	TTYMAC	FLC

DEFINE	DSASOC,<
	XLIST

	DEFINE	L(M,N,P),<
IFIDN <M> <CTY>,<
	ZZBEG==CTYLIN
	ZZDATA==CTYLIN
>
IFIDN <M> <CTY1>,<
	ZZBEG==CT1LIN
	ZZDATA==CT1LIN
>
IFDIF <M> <CTY>,<
IFDIF <M> <CTY1>,<
	ZZBEG==M
	ZZDATA==M
>>
IFB <P>,<
	ZZEND==ZZBEG
	ZZLINE==N
>
IFNB <P>,<
	ZZEND==N
	ZZLINE==P
>

REPEAT ZZEND-ZZBEG+1,<
	GENLIN	(\ZZDATA,ZZLINE)
ZZDATA==ZZDATA+1
ZZLINE==ZZLINE+1
>>	;END REPEAT AND DEFINITION OF L

	MACCR0
	LIST
>	;END DEFINITION OF DSASOC
SUBTTL DEFAULT SYMBOLS
;THE FOLLOWING STANDARD SYMBOLS CAN BE SUPERSEDED BY A CUSTOMER HAVING
; PREVIOUSLY DEFINED THEM ON THE HDWGEN.MAC FILE USING THE MONGEN PROGRAM....
;**********************************************************************
;ADD NEW SYMBOLS AT END SO EASY TO UPDATE MONGEN APPENDIX	      *
;SYMBOLS SHOULD APPEAR HERE IN COMMON (AND NOT IN COMDEV, OR COMMOD)  *
; UNLESS THEY REFER TO NON-DISK DEVICES OR DISKS RESPECTIVELY.        *
; IF A SYMBOL IS IN COMDEV OR COMMOD, IT SHOULD NOT APPEAR HERE.      *
;**********************************************************************
IFNDEF XPANDN,<XP XPANDN,0>	;FORCE NO EXPANSION OF MACROS
				; UNLESS XPANDN IS DEFINED NON-ZERO WITH MONGEN

IFNDEF APRSN, <XP APRSN,0>	;SERIAL NUMBER OF ARITHMETIC PROCESSOR

				;STANDARD MAG TAPE DENSITY
IFNDEF STDENS, <XP STDENS,5>	;STANDARD = 6250 BPI
				;STDENS,D
				;D=1 (200 BPI), OR D=2 (556 BPI), OR D=3 (800 BPI)

				;NUMBER OF CLOCK TICKS (JIFFIES) PER SECOND
IFNDEF JIFSEC, <XP JIFSEC,M.TPS> ;STANDARD == 60 JIFFIES PER SECOND

XP JIFSC2,JIFSEC/2		;NUMBER OF JIFFIES IN A HALF SECOND (FOR ROUNDING)
XP JIFMIN,JIFSEC*^D60		;NUMBER OF JIFFIES PER MINUTE
JIF2SC==^D2*JIFSEC

QQTTY1==:M.TPS/^D7		;SEVENTH SECOND FOR TTIOWS & PQ1
QQRUN1==:QQTTY1

				;NUMBER OF TIMES TO TRY ON DECTAPE ERRORS
IFNDEF DTTRY, <XP DTTRY,4>	;STANDARD == 4 TRIES

				;NUMBER OF NANO-SECONDS PER MEMORY CYCLE
IFNDEF NSPMEM, <XP NSPMEM,^D1000>	;STANDARD == 1000 NANO-SECONDS PER MEMORY CYCLE

IFNDEF TTXTRA <TTXTRA==0>	;NUMBER OF EXTRA TTY DDBS FOR SLAVE LINES
				; AND THE LIKE
				;FREE CORE ALLOCATION REQUIREMENTS FOR DISK 
				; DEVICE DATA BLOCKS AND ACCESS TABLE ENTRIES.

IFN M.KI10!M.KL10,<IFNDEF EPL4WD,<XP EPL4WD,^D19>>
				;4 WORDS LONGER FOR KI/KL (MAPIO)
IFNDEF EPL4WD,<XP EPL4WD,^D17>	;NO OF 4 WORD BLOCKS IN EXTENDED EXEC PUSH DOWN
			; LIST IE MAX SIZE/4 OF EXEC PD LIST
			; SHOULD BE INCREASED USING MONGEN IF ERROR IN JOB
			; EXEC PDL OVERFLOW ERRORS OCCUR, SEE EPOCNT,EPOREC
XP CORSIZ,4		;NO. OF WORDS IN MONITOR FREE CORE BLOCKS
XP EPLLEN,EPL4WD*CORSIZ	;+NO. OF WORDS IN EXTENDED EXEC PUSHDOWN LIST
XP MEPLEN,-EPLLEN	;-NO. OF WORDS IN EXTENDED EXEC PUSHDOWN LIST
IFN DSKN,<
IFN FTDSMC,<
IFNDEF MINCOR, <XP MINCOR,^D55*JOBN ;SMALL CORE ASSUMES 1.5 OPEN FILES PER JOB>
>
IFNDEF MINCOR, <XP MINCOR,JOBN*<^D72+EPLLEN>> ;ASSUME 2DDBS PLUS AN
				;EPL PER JOB
IFL MINCOR-6*^D140,<
XP MINCOR,6*^D140>>		; BUT PUT FLOOR UNDER MINCOR IF JOBN .LT. 6
IFE DSKN,<IFNDEF MINCOR,<XP MINCOR,EPLLEN*JOBN  ;ENOUGH WORDS FOR EACH JOB TO
				;HAVE AN EXTENDED PD LIST (10/40)
>>
IFNDEF LOGSIZ, <IFN M.KI10!M.KL10,<XP LOGSIZ,^D28>
IFN M.KA10,<XP LOGSIZ,^D14>>	;STANDARD == 14K (CURRENT SIZE OF LOGIN CUSP)
				;MINIMUM AMOUNT OF VIRTUAL CORE WHICH CAN REMAIN AND
				; STILL LET THE SYSTEM PERMIT LOG-INS.  MUST BE
				; AT LEAST AS BIG AS LOGIN CUSP IN K.
XP BLKSPK,^D3			;# OF PLACES TO SHIFT LEFT TO CONVERT BLOCKS TO K
XP MBKSPK,-BLKSPK		;# OF PLACES TO SHIFT RIGHT TO CONVERT K TO BLOCKS

IFNDEF INDPPN,<XP INDPPN,0>	;NON-ZERO IF CUSTOMER WANTS PROGRAMMER NOS
				; IN PROJECT X TO BE INDEPENDENT OF THOSE IN PROJECT Y

IF1,<
IFNDEF SYSSEG,<XP SYSSEG,-1>	;MINUS ONE FOR FAST GETSEG FROM SYS
				; WITH SOMEWHAT DIFFERENT BEHAVIOR
				; WHEN SHR FILES ARE SUPERCEDED
IFDEF	SYSSEG,<IFN	<SYSSEG+1>,<XP SYSSEG,0>>
XP SYSSEG,SS.SYS&SYSSEG		;SYSSEG=0 OR SS.SYS
INTERN SYSSEG
>

IFNDEF CTYDCR,<XP CTYDCR,^D18>	;DELAY FOR CR ON CTY DURING ONCE
IFNDEF CTYDLF,<XP CTYDLF,^D8>	;DELAY FOR LF ON CTY DURING ONCE
IFNDEF RLDTIM,<XP RLDTIM,^D112>  ;TIME TO AUTO-RELOAD
IFNDEF	MINMAX,<XP MINMAX,^D1024*^D12> ;SMALLEST LEGAL CORMAX
;NOTE--IN ORDER TO RESERVE PI-CHANNELS FOR
;NON-STANDARD USAGE, FOR EACH CHANNEL (SAY N)
;DEFINE SYMBOL UNIQN==1 VIA MONGEN.  FOR
;EXAMPLE, TO RESERVE CHANNEL 4, DEFINE
;UNIQ4==1.

;MOST OF THE SLAVE PROCESSOR CHANNELS ARE BUSIED OUT TO PREVENT CORE
;FROM BEING WASTED FOR CHANNEL SAVE ROUTINES

IFNDEF CPTOS,<XP CPTOS,0>	;CPTOS EQUAL TO ZERO MAKES CPU0 TRAP TO 40-61, CPU1 TO 140-161
				;CPTOS NON-ZERO MAKES CPU0 TRAP TO 140-161, CPU1 TO 40-61

IFNDEF SFC0,<XP	SFC0,^D20>	;CPU0 SCHEDULER FAIRNESS COUNT.  PICK A JOB OUT OF
				;PQ2 INSTEAD OF PQ1 IF 'SFC0' PICKS IN A ROW HAVE COME FROM PQ1 AND NULL JOB DID NOT RUN.

IFNDEF SFC1,<XP	SFC1,^D20>	;CPU1 SCHEDULER FAIRNESS COUNT
				;PICK THIS MANY JOBS TO RUN ON CPU0.  WHICH
				; CAME FROM CPU1 UUOS BEFORE PICKING OTHER JOBS

IFNDEF IFC0,<XP IFC0,^D5>	;SWAPPER FAIRNESS COUNT MAXIMUM


IFNDEF UFC0,<XP	UFC0,^D10>	;UUO FAIRNESS COUNTER MAXIMUM

IFNDEF UFC1,<XP	UFC1,^D10>	;UUO FAIRNESS COUNTER FOR SLAVE
				;PICK UFC1 JOBS TO RUN ON CPU1
				;WHICH CAME FROM CPU0 AND JUST FINISHED
				;A UUO
IFNDEF MEMITL,<XP MEMITL,^D4>	;NUMBER OF WAYS MEMORY CAN BE INTERLEAVED
IFNDEF PAVJSP,<XP PAVJSP,^D20>	;PREDICTED AVERAGE JOB SIZE IN PAGES

IFNDEF	MLACTS,<XP MLACTS,^D39>  ;MAXIMUM LENGTH OF THE ACCOUNT STRING
				; IF NOT DEFINED, 39 CHARACTERS
IFNDEF SCHEDN,<SCHEDN==0>	;SCHEDULE VALUE
SCHEDN==SCHEDN&777777		;ONLY A RIGHT HALF NUMBER
IFG	MLACTS-^D39,<XP MLACTS,^D39>  ;MAXIMUM LENGTH IS 39 CHARACTERS
XP ACTSTL,MLACTS/^D5+1		;LENGTH OF ACCOUNT STRING IN WORDS
IFE FTACCT,<
XP ACTSTL,0
>
XP MACTSL,-ACTSTL
XP MAXACS,^D8		;MAX LENGTH OF ACCOUNT STRING
IFNDEF M.CBAT,<XP M.CBAT,^D10>	;NO. OF BAD ADDRESSES IN PER CPU BAD
				; ADDRESS TABLE FOR MEMORY PARITY RECORDING
IFNDEF M.BMAX,<XP M.BMAX,^D13>	;MAX. NO. OF SIMULTANEOUS BATCH JOB STREAM'S
				; INITIATES LOC BATMAX, CHECKED BY BATCON
IFNDEF M.BMIN,<XP M.BMIN,0>	;MIN. NO. OF GUARRANTEED BATCH JOBS
IFNDEF M.EXE,<XP M.EXE,1>	;SYMBOL WHICH DETERMINES TYPE OF FILE
				; CREATED ON "SAVE".  IF OFF, NORMAL (SAV,HGH,
				; LOW,..), IF ON AN EXE FILE IS CREATED
IFNDEF M.JMAX,<XP M.JMAX,M.JOB-M.BMIN>	;MAX. NO. OF SIMULTANEOUS INTERACTIVE JOBS
IFNDEF M.WCH,<XP M.WCH,JW.WMT>	;WATCH BITS USED TO SET INITIAL
				; WATCHING. SINCE LOGIN SETS JBTWCH
				; THIS IS USEFUL ONLY FOR LINES WHICH
				; DON'T NEED LOGIN - INITIA.
				;200000 = TIME OF DAY STARTED TO WAIT
				;100000 = RUN TIME
				;40000 = WAIT TIME
				;20000 = BLOCKS READ
				;10000 = BLOCKS WRITTEN
				;4000 = VERSION NOS.
				;2000 = MTA STATISTICS
IFNDEF M.CMCT,<XP M.CMCT,^D32>	;NO. OF CALLS TO CHKTAL ROUTINE
				; BEFORE DOING 5 M.S. OF OVERHEAD
				; CHECKING CORE TABLES. I.E. ONLY
				; EVERY 32 TIME IS OVERHEAD PERFORMED
				;THIS REDUCES CPU TIME FOR
				; CORE, GETSEG, RUN UUOS
				; SYMBOL CANNOT EXCEED 262,000.
IFNDEF M.EBPS,<XP M.EBPS,^D12500000> ;DEFAULT # EBOX TICKS PER SECOND
					  ; (ACCT METER COUNTS AT 1/2 SYSTEM CLOCK RATE)
					  ; SYSTEM CLOCK RATE IS 25MHZ

IFNDEF M.MBPS,<XP M.MBPS,^D9750000> ;DEFAULT MBOX REFS/SECOND
				     ; THIS NUMBER WAS EXPERIMENTALLY
				     ; DETERMINED AT A CPU CLOCK RATE
				     ; OF 25MHZ SUCH THAT THE CPU TIME
				     ; OF A JRST . MATCHED ELAPSED TIME.
				     ; JRST . WAS ASSUMED TO BE A BEST CASE CONDITION.

				     ; THIS TERM MAKES EBOX/MBOX RUNTIME
				     ; PER REAL TIME UNIT DEPENDENT ON
				     ; CACHE HIT RATE, ALTHOUGH INSTRUCTIONS
				     ; PER E/MBOX RUNTIME UNIT SHOULD REMAIN CONSTANT.

IFNDEF M.EMRT,<XP M.EMRT,0>		;DEFAULT IS REGULAR RUNTIME
IFNDEF M.XPI,<XP M.XPI,0>		;AND INCLUDE PI TIME IN USER RUNTIME
IFNDEF M.ITA,<XP M.ITA,0>		;DEFAULT IS TO USE INTERVAL TIMER
IFE	LOKN,<XP EVBN,^D256-RHWEVM-PAGTBL-MEMTBL>	;NUMBER OF HALF WORDS IN THE EXEC MAP
IFN	LOKN,<IFNDEF EVBN,<XP EVBN,^D128>>	; AVAILABLE FOR MAPPING BUFFERS AND IOWDS
IFL EVBN-PAGTBL-MEMTBL,<XP EVBN,PAGTBL+MEMTBL>
IFL ^D256-EVBN-RHWEVM,<PRINTX<EVBN DEFINE TOO LARGE>
	XP EVBN,^D256-RHWEVM
>
XP EVLN,^D256-RHWEVM-EVBN		;NUMBER OF HALF WORDS IN THE EXEC MAP AVAILABLE
				; FOR LOCKING IN EVM
IFNDEF M.XFFA,<XP M.XFFA,0>	;DO FILE ACCESS PROTACTION CHECKING ON [1,2] AND JACCT

IFN FTNSCHED,<
	ND	M.CLSN,^D16	;DEFAULT NUMBER OF CPU CLASSES FOR SCHEDULER
	ND	M.CLSS,1	;DEFAULT SCHEDULER IS CLASS SYSTEM SCHEDULER.
				; IF THIS MONGEN SYMBOL IS DEFINED
				; TO BE ZERO, THEN THE SCHEDULER WILL
				; RUN IN WMU MODE.

	ND	M.DCLS,0	;DEFAULT SCHEDULER CLASS FOR NEW JOBS.
				; CAN OBTAIN THIS FROM GETTAB OR SCHED UUO
IFG M.DCLS-M.CLSN,<PRINTX VALUE OF M.DCLS EXCEEDS M.CLSN.
			M.DCLS==M.CLSN-1>

>;END IFN FTNSCHED

IFE FTNSCHED,<
	ND	M.CLSN,0
	ND	M.DCLS,0	;SO IT STILL APPEARS IN GETTAB.
>;END IFE FTNSCHED

IFN FT2SEGMON,<
IFN M.KA10,<
PRINTX	?TURN OFF FT2SEGMON FOR KA10 MONITORS
>
IFN M.KI10!M.KL10,<
IFNDEF	.TEXT,<PRINTX MONITOR MUST BE ASSEMBLED WITH MACRO V50 OR LATER>
REPEAT 0,<
MONORG==:MONORG
.TEXT	"NUL:FOO/SET:.HIGH.:MONORG"
>;END REPEAT 0
>>
;THESE SYMBOLS DEFINE THE VALUES OF VERSION FROM MONGEN

AXXWHO==2
IFNDEF	A00CVN,<IFNDEF A00CLH,<AXXWHO=0>>
ND	A00CVN,0		;CUSTOMER VERSION NUMBER (36-BITS)
ND	A00MVN,603		;MAJOR VERSION OF MONITOR--UPDATED AT
				;  START OF DEVELOPMENT CYCLE (9-BITS)
ND	A00SVN,1		;SOUP NUMBER--UPDATED AT START
				;  OF EACH SOUP DEVELOPMENT CYCLE (6-BITS)
ND	A00MCO,^D8270		;HIGHEST MCO IN THIS LOAD (27-BITS)
ND	A00CLH,0		;CUSTOMER LH (%CNVER) (18-BITS)
ND	A00DLN,0		;DEC LOAD NUMBER (9-BITS)
				; SET TO ZERO FOR ANY RELEASE, ELSE
				; 1-7 IF SOUP, 10-77 IF DEVELOPMENT
ND	A00WHO,AXXWHO		;DEC LAST EDITED (3-BITS)

AXXVER==< BYTE (18) A00CLH (12) A00MVN-IFE A00SVN,<IFN A00DLN,<1>> (6) IFE A00SVN,<A00DLN>>

ND	A00VER,AXXVER		;DEFINES %CNVER

AXXDVN== BYTE (3) A00WHO (9) A00MVN (6) A00SVN (18) A00MCO


;DEFINE DEFAULT VALUE OF DEBUGF TO STOP ON STOPCD'S DURING FIELD-TEST,
; BUT NOT TO STOP IN RELEASED VERSIONS OF MONITOR.
IFNDEF DEFDEB,<DEFDEB==0+IFN A00DLN,<320000000000>>

;ADD NEW MONGEN SYMBOLS HERE (SEE ALSO COMDEV FOR MONGEN SYMBOLS)
SUBTTL COMPUTE SPECIAL SYMBOLS
;DEFINE PARAMETERS THAT SPECIFY SIZE OF CORTAB, NUMBER OF BITS PER
;ENTRY, AND BYTE POINTERS FOR CORE ALLOCATION ROUTINES

INTERNAL CTNMCI,CTNBSA,CTNBPW,CTNXMI

CTNBPE==1	;NUMBER OF BITS PER ENTRY IN CORTAB
		;MUST EVENLY DIVIDE 36 AND BE 1 OR A POWER OF TWO
CTNMCI==1	;PUT THIS IN CORTAB TO INDICATE A BLOCK IN USE BY MONITOR
CTNXMI==3	;PUT THIS IN CORTAB TO INDICATE A BLOCK OF NON-EXISTANT MEMORY

INTERNAL FTLOCK

IFN FTLOCK!FTMEMNXM,<IFN LOKN!FTMEMNXM,<
CTNBPE==2	;NEED TWO BITS PER ENTRY TO MINIMIZE FRAGMENTATION IF LOCK UUO
CTNMCI==2	;INDICATES CORE IN USE BY MONITOR,LOCKED JOB OR NON-EXISTANT
>
>
CTNBPW==^D36/CTNBPE
		;NUMBER OF BYTES/WORD
IFN M.KI10!M.KL10,<
CTNBPE==0	;0 BITS PER ENTRY IF KI10 (SINCE TABLE DOESN'T EXIST)
CTNBPW==0
>

Z1==0
Z2==CTNBPE

	XLIST
REPEAT Z2/2,<
Z2==Z2/2
IFN Z2,<Z1==Z1+1>
>
	LIST

CTNBSA==Z1	;THE LARGEST POWER OF TWO IN CTNBPE
;PERFORM TRANSLATION FROM HARDWARE TO SOFTWARE DESIGNATION
; FOR ALL DISK SYMBOLS

IFN DSKN,<
	FHDN==RD10N
	FSDN==RH10NS
	RPXN==RH10NP
	DPCN==RP10N
	MDFN==RA10N
>
IFE DSKN, <
	FHDN==0
	FSDN==0
	RPXN==0
	DPCN==0
	MDFN==0
>

ALLKON=FHDN+FSDN+RPXN+DPCN+MDFN+TM10B+TC10C+TM02N  ;ALLKON = THE TOTAL # OF KONTROLLERS IN THE SYSTEM
				; IF YOU ADD ANOTHER KONTROLLER TYPE YOU MUST
				; INCLUDE THE # OF KONTROLLERS OF THAT TYPE HERE

;DEFINE THE PARAMETERS WHICH CONTROL THE TYPE OF SYSTEM

XP FTDISK,-DSKN			;10/40D OR 10/50S
XP FTSWAP,-SYS50N		;10/50S
XP FTLOGIN,-DSKN		;PUT FTLOGIN IN SO LOADER WILL COMPLAIN
				; IF DIFFERENT IN OTHER FILES
;SET JOBVER TO SYSTEM VERSION

	LOC	136
	A00CVN			;(136) CUSTOMER
	AXXDVN			;(137) DEC


;***SINCE MONITOR CANNOT SUPPORT MORE THAN 127 JOBS (NOT COUNTING NULL JOB).
;***CUT JOBN DOWN TO LE 128 COUNTING NULL JOB


IFG KT10AN,<SEGN=JOBN+SEGN>
IFE FT22BIT,<IFL ^D256-M.NKC,<
PRINTX	?WITH MORE THAN 256K OF CORE, THE MONITOR MUST BE
PRINTX	ASSEMBLED WITH FT22BIT=1
>>

IFN M.KL10,<
	;SYMBOLS SPECIAL TO KL10

XP EBCPT,10000		;KL10 EBOX CLOCK DOES THIS MANY COUNTS PER EBOX TICK
XP MBCPT,10000		; MBOX CLOCK DOES THIS MANY COUNTS PER MBOX TICK
>;END IFN M.KL10
SUBTTL ABSOLUTE LOCATIONS IN LOWER MEMORY

	CURJOB=:20		;LH=SLAVE CURRENT JOB NO.
				;RH=MASTER CURRENT JOB NO.
				;OPERATOR SETS SWITCHES TO FOLLOW ON MASTER
				;MASTER AND SLAVE REFERENCE THIS EACH CLOCK TICK.
	CLKDDT=:21		;JUMP TO EDDT IF DEBUG SET AND THIS NON-ZERO
	BOOTWD=:22		;CHANNEL ADR. PAIR FOR BOOTS (LEVEL D BOOTS STRAP)
	BOOTCL==22
	CRSDTM=:24		;CRASH DATE,,TIME(SECS)
	CRSWHY=:25		;CRASH CHECKSUM (24+25),,REASON(S..XXX)
	MLCPTL=:26		;LOWER CORE MEM PARITY TEST LOCATIONS FOR
				; SETTING UP DF+10
	MLCPT1=:MLCPTL+1	; COMMAND LIST TO WRITE BAD PARITY (PARTST USES)
	CRSHWD=:30		;NORMALLY THIS WORD WILL BE 0.  IF IT IS ACCIDENTALLY
				; OR PURPOSEFULLY OVERWRITTEN THE MONITOR WILL
				; ATTEMPT TO SAVE THE AC'S AND THE STATE OF
				; ALL DEVICES, THEN HALT.   [A LA 407 RESTART]
	MLCPEW=:31		;MONITOR LOWER CORE PARITY ERROR WORD
				; PARTST WRITES BAD PARITY HERE TO TEST
				; MEM PARITY ANALYSIS
	DDTUSY=:32		;POINTER TO UNDERFINED SYMBOL TABLE
	LIGHTS=:33		;DISPLAY PERFORMANCE DATA HERE (METER.UUO)
				; FOR OBSERVATION VIA LIGHTS OR XT10 CHART RECORDER
;35 IS RESERVED

	DDTSYM=:36		;CONTAINS ADDRESS OF POINTER TO EXEC DDT SYMBOL TABLE
	SYSSNP=:37		;WHEN DEPOSITED NON-ZERO, PRINTS SNAP SHOT OF SYSTEM
				; ON LPT (SEE MOVIE SUBPROGRAM)
	FORTY=:40		;PLACE WHERE UUOS ARE STORED ON TRAP
	SIXTY=:60		;PLACE WHERE UNIMPLEMENTED INSTRUCTIONS ARE
				; STORED ON TRAP (PDP10 ONLY)
IFN M.KI10,<
ARSLOC=:70
>
	ONCPDL=:NULPDL+1	;PUSH DOWN LIST FOR ONCE ONLY CODE
				; USES EXEC LOCS 62 THRU 137
;NULL PDL AND ERROR PDL USE UP TO 140
;DATA STARTING AT 140:
	LOC	136
	A00CVN			;(136) CUSTOMER
	AXXDVN			;(137) DEC


	COMORG=140		;ORIGIN OF COMMON IS 140
	LOC	COMORG		;MAKE LISTING BE SAME AS LOADING SO IT WILL BE EASY
				; TO EXAMINE SYSTEM LOCATIONS WITH CONSOLE SWITCHES
				; WITHOUT NEEDING A STORAGE MAP

	SYSDSP=400		;FIRST STARTING LOCATION OF MONITOR

;LOWER CORE FROM 140 UP THRU 410 (START LOCATIONS):

;SECOND CPU PI CHANNEL INTERRUPT LOCATIONS:

IFN M.KA10,<
IFG <CPUN-1>,<			;HAVE SECOND CPU IN THIS CONFIGURATION?
FORTY1::HALT	SYSDSP		;UUO FOR SECOND CPU STORED HERE ON TRAP
	JSR	UUO140		;JSR TO UUO HANDLER FOR SECOND CPU
	JSR	CH11		;PI 1 FOR SECOND CPU, ETC
	JSR	PIERR##
	JSR	CH12
	JSR	PIERR##
	JSR	CH13
	JSR	PIERR##
	JSR	CH14
	JSR	PIERR##
	JSR	CH15
	JSR	PIERR##
	JSR	CH16
	JSR	PIERR##
	JSR	CH17
	JSR	PIERR##
SIXTY1::0			;ILLEGAL INSTRUCTIONS STORED HERE
	JSR	UUO160
>>
IFN M.KI10,<			;DEFINE KI10 EXEC PAGE MAP

INTERN	.EPMP,.EPPM

.EPMP=0
.EPIL==:.EPMP+40
.EPPM==.EPMP+200

	LOC	.EPPM

DEFINE X,<
	XWD	PM.ACC+PM.WRT+ZZ,PM.ACC+PM.WRT+ZZ+1
ZZ==ZZ+2
>
ZZ==400
;GENERATE 1:1 EXEC PAGE MAP
XLIST
REPEAT 200,<X>
LIST

.EPMPE==426

	LOC	.EPMPE
>	;END IFN M.KI10

IFN M.KL10,<		;DEFINE KL10 EXEC PROCESS TABLE

	OPDEF	MUUO	[0]

.EPMP==:1000			;WHERE EXEC PROCESS TABLE (FORMERLY
				; EXEC PAGE MAP PAGE) IS

	LOC	.EPMP+0
RH2IOC::BLOCK	40		;LOGOUT AREAS FOR RH20'S

;	LOC	.EPMP+40
.EPIL::	BLOCK	1		;WHERE LOCAL UUO'S GO

	LOC	.EPMP+60
RH2ZRO::0			;LOCS USED BY RH20 FOR ZERO-FILL
	0
	0
	0

	LOC	.EPMP+140		;START OF DTE0 HARDWARE LOCATIONS

DTEEBP::BLOCK	1		;TO 11 BYTE POINTER
DTETBP::BLOCK	1		;TO 10 BYTE POINTER
DTEII::BLOCK	1		;DTE0 INTERRUPT INSTRUCTION
DTEUNS::BLOCK	1		;UNUSED LOCATION
DTEEPW::BLOCK	1		;EXAMINE PROTECTION WORD
DTEERW::BLOCK	1		;EXAMINE RELOCATION WORD
DTEDPW::BLOCK	1		;DEPOSIT PROTECTION WORD
DTEDRW::BLOCK	1		;DEPOSIT RELOCATION WORD

	LOC	.EPMP+200
.EPPM::	BLOCK	^D128		;EXEC PAGE MAP FOR EXEC VIRTUAL ADDRESSES
				; 400000 AND UP

	LOC	.EPMP+421		;EXEC TRAPS

.EPAOV:	JFCL			;ARITHME5IC TRAP
	MUUO	SEPDLO##	;PUSH DOWN OVERFLOW TRAP
	JSR	TRP3PC		;TRAP 3 TRAP
.EPRH1:	BLOCK	4		;HALT STATUS AREA (OBSOLETE?)

CPUSKP==.-.EPMP
	CAIA
	CAI

	LOC	.EPMP+440		;DTE AREA

.EPSTD:	JRST	DEBUG##		;DIAGNOSTIC START
.EPDDT:	XCT	SYSDDT		;DDT START
.EPSTL:	XCT	SYSCRH		;LOADER START ADDRESS (BOOTS)
.EPSTM:	XCT	SYSDSP		;START MONITOR

DTEDBG::			;START OF DTE COMMUNICATIONS AREA
DTEFLG::	0
DTECLK::	0
DTECI::		0
DTET11::	0
DTEF11::	0
DTECMD::	0
DTESEQ::	0
DTEOPR::	0
DTECC::		0
DTEMTD::	0
DTEMTI::
DTEDND::	0		;END OF DTE DATA CLEARED AT SYSINI


	LOC	.EPMP+507
.EPR1E:	BLOCK	1		;LAST WORD OF FIRST HARDWARE RESERVED REGION
.EPHTB::BLOCK	1		;HIGH ORDER TIME BASE WORD
.EPLTB::BLOCK	1		;LOW ORDER TIME BASE WORD
.EPHPA::BLOCK	1		;HIGH ORDER PERFORMANCE COUNTER WORD
.EPLPA::BLOCK	1		;LOW ORDER PERFORMANCE COUNTER WORD
.EPTII::JRST	4,		;INTERVAL TIMER VECTOR INTERRUPT INSTRUCTION
.EPRH2:				;START OF 2ND RESERVED FOR HARDWARE AREA
	LOC	.EPMP+577
.EPR2E:	BLOCK	1		;LAST LOC OF 2ND RESERVED FOR HARDWARE AREA

.EPLM::BLOCK	^D112		;PAGE MAP FOR LOWER 112K OF EXEC SPACE

	LOC	.EPMP+760
.EPRCU:				;RESERVED FOR CHANNEL USE

	LOC	.EPMP+777
.EPMPE::			;LAST LOCATION IN KL EPT
;DEFINE IMPORTANT SYMBOLS, GENERATE EXEC PAGE MAPS


DEFINE X,<
	XWD	PM.ACC+PM.WRT+PM.CSH+ZZ,PM.ACC+PM.WRT+PM.CSH+ZZ+1
	ZZ==ZZ+2
>

	LOC	.EPLM		;GENERATE 1:1 MAP FOR  LOWER EXEC 112K

	ZZ==0
	;REPEAT ^D112,<X>	;THIS IS WHATS XLISTED
	XLIST
	REPEAT ^D112,<X>
	LIST

	LOC	.EPPM		;GENERATE 1:1 MAP FOR UPPER EXEC 128K

	ZZ==400
	;REPEAT ^D128,<X>	;WHAT'S XLISTED
	XLIST
	REPEAT ^D128,<X>
	LIST

$SCP0==:.ESKPC+CPUSKP
$SCP1==:$SCP0+1
NLUPMP==2000

.E1MP==:2000
.E1PM==:.E1MP+200
.E1IL==:.E1MP+40
.E1LM==:.E1MP+600

IFG <CPUN-1>,<
.E1OFS==:.E1MP-.EPMP		;OFFSET FROM CPU0'S MAP TO CPU1'S MAP
.E12OF==:2*.E1OFS

	LOC	.E1IL

FORTY1::0
	JSR	SPLUPC
	JSR	CH11
	JSR	PIERR##
	JSR	CH12
	JSR	PIERR##
	JSR	CH13
	JSR	PIERR##
	JSR	CH14
	JSR	PIERR##
	JSR	CH15
	JSR	PIERR##
	JSR	CH16
	JSR	PIERR##
	JSR	CH17
	JSR	PIERR##
	LOC	.E1MP+140	;START OF DTE0 HARDWARE LOCATIONS

DT1EBP::BLOCK	1		;TO 11 BYTE POINTER
DT1TBP::BLOCK	1		;TO 10 BYTE POINTER
DT1II::BLOCK	1		;DTE0 INTERRUPT INSTRUCTION
DT1UNS::BLOCK	1		;UNUSED LOCATION
DT1EPW::BLOCK	1		;EXAMINE PROTECTION WORD
DT1ERW::BLOCK	1		;EXAMINE RELOCATION WORD
DT1DPW::BLOCK	1		;DEPOSIT PROTECTION WORD
DT1DRW::BLOCK	1		;DEPOSIT RELOCATION WORD
	LOC	.E1PM
	BLOCK	^D128

	LOC	.E1MP+421

.E1AOV:	JFCL
	MUUO	SEPDLO##
	JSR	SPT3PC

	LOC	.E1MP+CPUSKP
	CAI
	CAIA
	LOC	.E1MP+440	;DTE AREA

.E1STD:	HALT	.		;DIAGNOSTIC START
.E1DDT:	XCT	SYSDDT		;DDT START
.E1STL:	XCT	SYSCRH		;LOADER START ADDRESS (BOOTS)
.E1STM:	XCT	SYSDSP		;START MONITOR

DT1DBG::			;START OF DTE COMMUNICATIONS AREA
DT1FLG::	0
DT1CLK::	0
DT1CI::		0
DT1T11::	0
DT1F11::	0
DT1CMD::	0
DT1SEQ::	0
DT1OPR::	0
DT1CC::		0
DT1MTD::	0
DT1MTI::
DT1DND::	0		;END OF DTE DATA CLEARED AT SYSINI

	LOC	.E1MP+507
.E1R1E:	BLOCK	1		;LAST WORD OF FIRST HARDWARE RESERVED REGION
.E1HTB::BLOCK	1		;HIGH ORDER TIME BASE WORD
.E1LTB::BLOCK	1		;LOW ORDER TIME BASE WORD
.E1HPA::BLOCK	1		;HIGH ORDER PERFORMANCE COUNTER WORD
.E1LPA::BLOCK	1		;LOW ORDER PERFORMANCE COUNTER WORD
.E1TII::JRST	4,		;INTERVAL TIMER VECTOR INTERRUPT INSTRUCTION

NLUPMP==3000

SPLUPC:	0
	HALT	.
SPT3PC:	0
	HALT	.

.E1ND==.
E1MPA==<.E1MP/1000>
DEFINE X,<
	XWD	PM.ACC+PM.WRT+PM.CSH+ZZ,PM.ACC+PM.WRT+PM.CSH+ZZ+1
	ZZ==ZZ+2
>

	LOC	.E1LM		;GENERATE 1:1 MAP FOR  LOWER EXEC 112K

	ZZ==0
	;REPEAT ^D112,<X>	;THIS IS WHATS XLISTED
	XLIST
	REPEAT ^D112,<X>
	LIST

	LOC	.E1PM		;GENERATE 1:1 MAP FOR UPPER EXEC 128K

	ZZ==400
	;REPEAT ^D128,<X>	;WHAT'S XLISTED
	XLIST
	REPEAT ^D128,<X>
	LIST
>;END IFG <CPUN-1>
> ;END IFN M.KL10
IFN M.KA10!M.KI10,<
;NULL JOB FOR CPU 0 DUMP AC AREA:

NU0DAC::BLOCK	20
	XP NU0DAT,NU0DAC-20	;FAKE ORIGIN OF NULL JOB DATA AREA

;NULL JOB FOR CPU 1 DUMP AC AREA:
IFG <CPUN-1>,<		;HAVE SECOND CPU?

NU1DAC::BLOCK	20		;PLACE TO STORE ACS
	XP NU1DAT,NU1DAC-20	;FAKE ORIGIN OF NULL JOB DATA AREA
>


;LOWER CORE CHANNEL PAIRS FOR EACH CONTROLLER IN SYSTEM

IFN ./2*2-.,<0>			;MAKE SURE DF10 LOCATIONS START IN AN EVEN LOC.
				; IN LOW CORE (LESS 1000)
LOCOCW::BLOCK	ALLKON*2	;CHANNEL ADR PAIRS FOR ALL CONTROLLERS IN SYSTEM.
				; EVEN IF ON THE SAME DF10 CHANNEL.
IFN <./4*4-.>,<EXP 0,0>		;DX10 LOCATIONS MUST START AT AN EVEN 4 WD LOC.
LOCODW::BLOCK	4*DX10N		;4 WORDS EACH DX10

IFN M.KI10,<
ACBLK1:	BLOCK	20		;AC BLOCK 1 ON A CRASH
>
ERPDLL==40
ERRPDL::BLOCK	ERPDLL		;PUSH DOWN LIST FOR ERROR IN NULL JOB
ERRPLL==:-ERPDLL+1		;LENGTH OF ERROR PDL

;ERROR PDL LIST FOR SECOND CPU:
IFG <CPUN-1>,<		;HAVE SECOND CPU?
ER1PDL:	BLOCK	-ERRPLL		;SAME LENGTH AS FOR CPU0
	XP ERRPD1,.-ER1PDL		;ORGIN IS NEVER USED
>


;FREE CORE FOR 4 WORD BLOCKS:

XP FREORG,<<.-1>/4*4+4>		;MAKE ORIGIN OF FREE LOW CORE AN EVEN MULTIPLE OF 4.
	LOC	FREORG

>;END M.KA10!M.KI10
SUBTTL INITIALIZATION DISPATCH TABLE, STARTING AT LOCATION 400
;ROUTINE "ONCE" IS ONCE ONLY CODE. IT CONVERTS THE DATE
;AND SETS UP I/O SERVICE CHAIN,

EXTERNAL SYSINI,NULJOB,ONCE,JSR2
INTERNAL SYSDSP,SYSDDT,SYSINA,SYSCRH,CRASHX,SYSIN2,SYSDSA

	LOC	SYSDSP		;ORIGIN START LOCATIONS TO 400

SYSDSP:

IFE FTMS,<
SYSTRT:
>
IFN FTMS,<
	JRST	SYSTRT		;INITIALIZE SYSTEM VARIABLES IF CPU0
>
IFE FTMS,<
SYSDSA:	JRST	SYSINI		;INITIALIZE SYSTEM VARIABLES
>
SYSDDT:	IFG	DDTN, <		;IF EXEC DDT IS LOADED.....
EXTERNAL PATSYM
	JRST	PATSYM		;PATCH SYMBOL TABLE POINTER, THEN ENTER EXEC DDT
>
	IFE	DDTN, <
	JFCL
>
	JRST	(<GOBACK>_^D18)
SYSINA:	JRST	SYSINI		;INITIALIZE SYSTEM VARIABLES ALWAYS
	JEN	NULJB1		;ERROR RECOVERY
	JSR	ONCE		;DO ONCE ONLY CODE OVER AGAIN
SYSIN2:	JRST	PATSYS##	;BYPASS ONCE ONLY OPERATOR DIALOGUE
				;(IN CASE CONSOLE TTY DOWN)
CRASHX:				;HERE WHEN 30 DEPOSITED NON-ZERO
				; TO TAKE CRASH AT APR PI LEVEL
CP0CRS:				;HERE ON CPU0 TO TAKE CRASH
SYSCRH:	JRST	ENDSTS		;MONITOR CRASH AND RELOAD LOCATION
				; PATCHED TO SYSTOP BY ONCE ONLY AFTER DATE AND TIME
				; BUT BEFORE LONG DIALOG (SO CAN TAKE CRASH
				; OF ONCE ONLY).  SYSTOP PATCHES BACK TO ENDSTS
				; AFTER SAVING STATE OF MONITOR ONCE.
				; 407 CAN ALSO BE USED WHEN DEBUGGING MONITOR WITH DOT
				; TO GET BACK TO BOOTS TO DUMP LOAD.

;START ABSOLUTE LOCATIONS HER TO BE PUBLISHED FOR USERS( UP TO 417)

	INTERN	ABSTAB
	EXTERN	NUMTAB

ABSTAB:	EXP	NUMTAB		;(410) ABSOLUTE LOCATION OF GETAB TABLE TABLE.
				; USED TO BE LOC 151. NEEDED TO DO GETTAB UUO
				; SIMULATION ON A CRASHED MONITOR.
				;(417) CUSTOMER'S WORD
	LOC	420		;SKIP RESERVED SPACE
IFN M.KI10,<			;DEFINE KI10 USER PAGE MAP PAGE
INTERN	NLUPMP,NUPMPL,NUPMPP
.EPPFT==420

	LOC	.EPMP+.EPPFT
OPDEF	MUUO	[0]
;EXEC TRAPS

	MUUO	SEILM##		;PAGE FAULT TRAP
	JFCL			;ARITHMETIC TRAP
	MUUO	SEPDLO##	;PUSH DOWN OVERFLOW TRAP
	JSR	TRP3PC		;TRAP 3 TRAP

CPUSKP=.-.EPMP
$SCP0==:.ESKPC+CPUSKP
$SCP1==:$SCP0+1
	CAIA
	CAI

NLUPMP==1000

.E1MP==:1000
.E1PM==:.E1MP+200
.E1IL==:.E1MP+40

IFG <CPUN-1>,<
.E1OFS==:.E1MP-.EPMP		;OFFSET FROM CPU0'S MAP TO CPU1'S MAP
.E12OF==:2*.E1OFS

	LOC	.E1IL

FORTY1::0
	JSR	SPLUPC
	JSR	CH11
	JSR	PIERR##
	JSR	CH12
	JSR	PIERR##
	JSR	CH13
	JSR	PIERR##
	JSR	CH14
	JSR	PIERR##
	JSR	CH15
	JSR	PIERR##
	JSR	CH16
	JSR	PIERR##
	JSR	CH17
	JSR	PIERR##
	LOC	.E1PM
DEFINE	X,<
	XWD	PM.ACC+PM.WRT+ZZ,PM.ACC+PM.WRT+ZZ+1
ZZ==ZZ+2
>
ZZ==400
ZZ==400;GENERATE 1:1 EXEC MAP FOR CPU1
XLIST
REPEAT 200,<X>
LIST

	LOC	.E1MP+.EPPFT

	MUUO	SEILM##
	JFCL
	MUUO	SEPDLO##
	JSR	SPT3PC

	LOC	.E1MP+CPUSKP
	CAI
	CAIA

NLUPMP==2000

SPLUPC:	0
	HALT	.
SPT3PC:	0
	HALT	.

.E1ND==.
E1MPA==<.E1MP/1000>
>

	LOC	NLUPMP
DEFINE X<
	XWD	PM.ACC+PM.WRT+ZZ,PM.ACC+PM.WRT+ZZ+1
ZZ==ZZ+2
>

NUPPPM==NLUPMP+400

	LOC	NUPPPM
ZZ==340
;GENERATE THE EXEC PER PROCESS MAP
XLIST
REPEAT 20,<X>
LIST
;USER TRAPS
	MUUO	SEILM##		;PAGE FAULT TRAP
	JFCL	SAROVF##	;ARITHMETIC TRAP
	MUUO	SEPDLO##	;PUSH DOWN LIST OVERFLOW TRAP
	JFCL			;TRAP 3 TRAP

EXP	0			;MUUO STORED HERE
EXP	0			;MUUO PC STORED HERE
EXP	0			;EXEC PAGE FAIL WORD
EXP	0			;USER PAGE FAIL WORD
EXP	IC.UOU+MUUO		;KERNAL NO TRAP MUUO NEW PC
EXP	IC.UOU+KTUUO		;KERNAL TRAP MUUO NEW PC
EXP	IC.UOU+SNTUUO		;SUPERVISOR NO TRAP MUUO NEW PC
EXP	IC.UOU+STUUO		;SUPERVISOR TRAP MUUO NEW PC
EXP	IC.UOU+MUUO		;CONCEALED NO TRAP MUUO NEW PC
EXP	IC.UOU+CTUUO		;CONCEALED TRAP MUUO NEW PC
EXP	IC.UOU+MUUO		;PUBLIC NO TRAP MUUO NEW PC
EXP	IC.UOU+PTUUO		;PUBLIC TRAP MUUO NEW PC
NUPMPL==.-NLUPMP
> ;END KI10 CASE
IFN M.KL10,<			;DEFINE KL10 USER PROCESS TABLE
INTERN	NLUPMP,NUPMPL,NUPMPP
	LOC	NLUPMP
DEFINE X<
	XWD	PM.ACC+PM.WRT+ZZ,PM.ACC+PM.WRT+ZZ+1
ZZ==ZZ+2
>

NUPPPM==NLUPMP+400

	LOC	NUPPPM
ZZ==340
;GENERATE THE EXEC PER PROCESS MAP
XLIST
REPEAT 20,<X>
LIST
;USER TRAPS
	EXP	0		;PAGE FAIL WORD (USER OR EXEC)
	JFCL	SAROVF##	;ARITHMETIC TRAP
	MUUO	SEPDLO##	;PUSH DOWN LIST OVERFLOW TRAP
	JFCL			;TRAP 3 TRAP

EXP	0			;MUUO STORED HERE
EXP	0			;MUUO PC STORED HERE
EXP	0			;PROCESS CONTEXT WORD
EXP	0			;UNUSED
EXP	IC.UOU+MUUO		;KERNAL NO TRAP MUUO NEW PC
EXP	IC.UOU+KTUUO		;KERNAL TRAP MUUO NEW PC
EXP	IC.UOU+SNTUUO		;SUPERVISOR NO TRAP MUUO NEW PC
EXP	IC.UOU+STUUO		;SUPERVISOR TRAP MUUO NEW PC
EXP	IC.UOU+MUUO		;CONCEALED NO TRAP MUUO NEW PC
EXP	IC.UOU+CTUUO		;CONCEALED TRAP MUUO NEW PC
EXP	IC.UOU+MUUO		;PUBLIC NO TRAP MUUO NEW PC
EXP	IC.UOU+PTUUO		;PUBLIC TRAP MUUO NEW PC
	LOC	NLUPMP+.LMPFW	;GET TO PAGE FAIL WORD

EXP	0			;PAGE FAIL WORD
EXP	0			;PAGE FAIL OLD PC
EXP	IC.UOU+SEILM##		;PAGE FAIL NEW PC
EXP	0			;UNUSED
NUPMPL==.-NLUPMP
;HARDWARE LOCATIONS
;504 - 507 EBOX/MBOX METERS
;510 - 577 RESERVED
NULASW==NLUPMP+600		;FIRST LOC AVAIL TO SOFTWARE
LOC	NULASW
> ;END OF IFN M.KL10
IFN M.KL10!M.KI10,<
KTUUO:	JRST	@.UPMP+.UPMUO	;DISPATCH TO KERNAL MODE TRAP HANDLER
SNTUUO:	HALT	.		;NOT IMPLEMENTED
STUUO:	HALT	.		;NOT IMPLEMENTED
CNTUUO:	HALT	.		;NOT IMPLEMENTED
CTUUO:	JRST	@.UPMP+.UPMUO	;DISPATCH TO USER MODE TRAP HANDLER
PNTUUO:	JRST	@.UPMP+.UPMUO	;DISPATCH TO USER MODE TRAP HANDLER
PTUUO:	JRST	@.UPMP+.UPMUO	;DISPATCH TO USER MODE TRAP HANDLER
LUUOPC::0			;JSR HERE ON A LUUO IN EXEC MODE
	EXCH	T1,LUUOPC
	MOVEM	T1,UUO0
	JRST	UUOERR##
TRP3PC:	0			;JSR HERE ON A TRAP 3 IN EXEC MODE
	HALT	.
SKPPIU::SKIPGE	T1
IFN M.KL10,<
KLRELC==.
	LOC	420
LOCODW::BLOCK	4*DX10N		;4 WORDS EACH DX10
LOCODE==:.-1			;END OF THAT AREA
	IFN ./2*2-.,<0>		;MAKE SURE THEY START ON EVEN LOCATION
LOCOCW::BLOCK	ALLKON*2	;ICCW PAIRS
	LOCOCE==:.-1

;NULL JOB FOR CPU 0 DUMP AC AREA:

NU0DAC::BLOCK	20
	XP NU0DAT,NU0DAC-20	;FAKE ORIGIN OF NULL JOB DATA AREA

;NULL JOB FOR CPU 1 DUMP AC AREA:
IFG <CPUN-1>,<		;HAVE SECOND CPU?

NU1DAC::BLOCK	20		;PLACE TO STORE ACS
	XP NU1DAT,NU1DAC-20	;FAKE ORIGIN OF NULL JOB DATA AREA
>

	XP	FREORG,<<.-1>/4*4+4>
	LOC	FREORG
	BLOCK	13*4
	XP	LEN1,<<.-FREORG+1>/4>
ACBLK1:	BLOCK	20		;AC BLOCK 1 ON A CRASH
ACBLK2:	BLOCK	20		;AC BLOCK 2
ACBLK3:	BLOCK	20		;AC BLOCK 3



ERPDLL==43
ERRPDL::BLOCK	ERPDLL		;PUSH DOWN LIST FOR ERROR IN NULL JOB
ERRPLL==:-ERPDLL+1		;LENGTH OF ERROR PDL

;ERROR PDL LIST FOR SECOND CPU:
IFG <CPUN-1>,<		;HAVE SECOND CPU?
ER1PDL:	BLOCK	-ERRPLL		;SAME LENGTH AS FOR CPU0
	XP ERRPD1,.-ER1PDL		;ORGIN IS NEVER USED
>

	LOC	KLRELC
>;END IFN M.KL10

.EPMPP==:.EPMP/PAGSIZ
MONORG==:MONORG
EVTABL==^D256/^D36+1
EVMPTR::XWD	-EVTABL,EVBTAB
PAGPTR::0
IFN FTVM,<
ALPHA==1			;FRACTIONAL PART OF TIME CONSTANT
EXPON==^D10			;NEGATIVE EXPONENT OF TIME CONSTANT
.GTVM::
SWPCNT::0			;(0)
SCNCNT::-1			;(1)
SPRCNT::0			;(2) COUNT OF SWAPS + PAGE OPERATIONS IN PROGRESS
				;  (SQREQ IS ONLY SWAPS)
SLECNT::0			;(3) TOTAL NUMBER OF SWPLST ENTRIES
VMTOTL::0			;(4) TOTAL AMOUNT OF VM CURRENTLY IN USE
VMCMAX::0			;(5) MAX ALLOWABLE VALUE OF VMTOTL
VMRMAX::1			;(6) OBSOLETE
VMCNST::ALPHA			;(7) CONSTANT USED TO COMPUTE SWAPPING RATE
VMQJOB::0			;(10) OBSOLETE
JBRMAX::RTUPS/^D10		;(11) OBSOLETE
LSFTIM::0			;(12) TIME OF LAST FAULT
SYSVCT::0			;(13) TOTAL NUMBER OF PAGE FAULTS (SYSTEM WIDE)
				;LH=NUMBER OF FAULTS WHEN PAGE NOT IN WS
				;RH=NUMBER WHEN PAGE IS IN WORKING SET, PM.ACC=0
	EXP	SWPLST		;(14) LCTN OF SWAP TABLE #1
	EXP	SW2LST		;(15) LCTN OF SWAP TABLE #2
	EXP	SW3LST		;(16) LCTN OF SWAP TABLE #3
VMCEXP::EXPON			;(17) TIME CONSTANT EXPONENT
VMCDIF::EXPON-ALPHA		;(20)
MAXINT::777777			;(21) MAX INTERVAL FOR FAULT-RATE CALCULATION (ABOUT 8 SEC. BETWEEN FAULTS)
IPCCNT::0			;(22) COUNT OF IPCF PAGES BEING SWAPPED OUT
	EXP	.UPJOB		;(23) OFFSET OF JOB NUMBER IN UPMP
	EXP	.UPREL		;(24) OFFSET OF END OF LOW SEG IN UPMP
GTVMXL==:<.-.GTVM-1>B26		;MAXIMUM ENTRY IN GETTAB
JBTVRT::BLOCK	JOBN		;PER-JOB PAGING RATES
SWPLST::BLOCK	JOBN+SEGN
SW2LST::BLOCK	JOBN+SEGN	;PARALLEL SWPLST TABLE FOR USE BY FILSER
SW3LST::BLOCK	JOBN+SEGN	;PARALLEL SWPLST TABLE FOR ADDITIONAL INFO
				; LH=C(SWPOUT) FOR SCHED1, RH=JOB NUMBER
>
EVBMAX::EVBN
EVBTAB::BLOCK	EVTABL
NUPMPP==NLUPMP/1000
NUPMPA==<NUPMPP>B17
EPMPA==<.EPMP/1000>
.UPMPE==.
IFN M.KI10,<
LEN1==<FREORG!777-FREORG+1>/4
>;END IFN M.KI10
LEN2==0
IFG CPUN-1,<
LEN2==<NLUPMP-.E1ND+1>/4
>
NPAGUC==^D512
IFL <2*M.NKC-^D512>,<NPAGUC==2*M.NKC>
IFL <M.CHN-2>,<XTR4WD=0>
IFNDEF XTR4WD,<XTR4WD==<<NPAGUC+3>/4-<LEN1+LEN2>>>
IFN M.KI10!M.KL10,<
LTINIT::
IFG LEN1,<
	XWD	LEN1,FREORG
>
IFN M.KI10,<
IFG LEN2,<
	XWD	LEN2,<<.E1ND+3>/4>*4
>
>
IFG XTR4WD,<
	XWD	XTR4WD,X4WORG
>
>	0
XP X4WORG,<<.-1>/4*4+4>
	LOC	X4WORG
IFG XTR4WD,<
	BLOCK	4*XTR4WD
>
IOWNUM==.-FREORG
XP CHKSHF,CPOPJ
XP UPMPSZ,1
XP KIINC,1
XP BLTINS,0
>	;END IFN M.KI10!M.KL10

IFLE <CPUN-1>,<NU1PDL==:NULPDL>
IFN M.KA10,<
XP KIINC,0			;NO KI10 INITIALIZATION NECESSARY
XP .EPIL,MPTRAP
XP .E1IL,SPTRAP
XP GTIEVM,CPOPJ
XP GTOEVM,CPOPJ
XP MAPUSR,CPOPJ
XP SETCNA,CPOPJ
XP SVEUB,CPOPJ
XP RTNEVM,CPOPJ
XP SAVEUB,CPOPJ
XP MAPDEV,CPOPJ
XP MAPIO,CPOPJ1
XP GTEVBF,CPOPJ1
XP ADVEVM,CPOPJ
XP GIVEVM,CPOPJ
XP SETMAP,SETREL##
XP SETRLH,SETREL##
XP NEWHGH,CPOPJ
XP RTNIOW,CPOPJ
XP MAPUEI,CPOPJ
XP TSTREL,CPOPJ
XP UPMPSZ,0
XP SVEUF,CPOPJ
XP GETCHK,CPOPJ
XP RTEVM,CPOPJ
XP RTEVMI,CPOPJ
XP RTEVMO,CPOPJ
XP MAPJD,CPOPJ
XP MAPWRD,CPOPJ
XP SAVUAC,CPOPJ
XP RESUAC,CPOPJ
XP RSTEVM,CPOPJ
XP UVACKS,CPOPJ
XP MAPHGH,CPOPJ
XP COMUBR,CPOPJ
XP PAGTAB,0
XP EVMPTR,0
XP EVBMAX,0
XP JBTUPM,0
XP NUPMPP,0
XP NLUPMP,0
XP LUUOPC,0
XP PAGPTR,0
XP .EPPM,P4
XP .E1PM,P4
XP EPMPA,0
XP E1MPA,0
XP SETBRK,COMERA##
XP SETABR,CPOPJ
XP CLRBRK,CPOPJ
RMEVM::	JRST	WSCHD1##
JBYHSS::POINT	8,.CPDTO(P4),16
RTIEVM::HLLZS	DEVIAD(F)
	POPJ	P,
RTOEVM::HLLZS	DEVOAD(F)
	POPJ	P,
SKPPIU::SKIPN	T1
>
XP UPMSZW,PAGSIZ*UPMPSZ
IFN FT22BIT,<
FLG256::0
>
	SUBTTL	COMMON MEMORY FOR PDP10/PDP11

;NOTE: TO AVOID WASTING SPACE BEFORE THE FIRST DL10 WINDOW
;  THE VALUE OF "XTR4WD" ON THE LAST PAGE CAN BE ADJUSTED.

DLXFST::

IFN	PDP11N,<
;;THIS MACRO BUILDS THE DL10 MAP FOR A GIVEN PORT.
DEFINE	BLDM76(PORT),<
	XLIST

;;COMPUTE THE SIZE OF THE MAP
	DEFINE	WORD(A,B),<A==ZZ	;;DEFINE THE OFFSET
	XP DLX'A,ZZ			;DEFINE GLOBAL SYMBOL
	ZZ==ZZ+1>
	DEFINE	DATA(A,B),<A==ZZ	;;DEFINE THE OFFSET
	XP DLX'A,ZZ			;DEFINE GLOBAL SYMBOL
	ZZ==ZZ+1>
	DEFINE	PNTR(A,B),<A==ZZ	;;DEFINE THE OFFSET
	XP DLX'A,ZZ			;DEFINE GLOBAL SYMBOL
	ZZ==ZZ+1>
	DEFINE	BLK(A,B),<ZZ==ZZ+B>

;;SIZE OF TO -10 AND TO -11 QUEUES
	TTBS'PORT==<<M.D7'PORT'N!7>+1>*2
	TEBS'PORT==<<M.D7'PORT'N*2>!17>+21

;;EXPAND MAP76 TO SEE HOW BIG IT IS
	ZZ==0
	MAP76(PORT)
REPEAT ^D18,<ZZ==ZZ!<ZZ_<-1>>>

	ZZ==ZZ!<<DLX8K*777>!77>  ;MUST BE BIG ENOUGH
IFN M.DC75,<ZZ=ZZ!177>		;MIN OF 128 WORDS IF MAY BE DC75
	LIST
	LOC	.!ZZ		;ONE IN FRONT OF WINDOW
	ZZ==ZZ_<-<6+<3*DLX8K>>>	;SIZE OF BLOCK
IFN ZZ&777760 <PRINTX ?DL10 MAPPED AREA IS TOO LARGE.>
	XP M7'PORT'BAM,ZZ	;DL10 WINDOW MASK
	ZZ=ZZ*4			;SHIFT TO PROPER PLACE
	ZZ=ZZ+<PORT&3>		;MASK OUT OVEERFLOW IN PORT

;;NOW LAY OUT THE MAP FOR REAL
DEFINE	WORD(SYM),<
M7'PORT''SYM::	0
>

DEFINE	DATA(SYM,THING),<
IF2,< IFNDEF THING,<EXTERNAL THING>>
M7'PORT''SYM::	THING
>

DEFINE PNTR(SYM,PLACE),<
IF2,< IFNDEF PLACE,<EXTERNAL PLACE>>
M7'PORT''SYM::	<61B5>+PLACE
>

DEFINE BLK(SYM,SIZE),<
M7'PORT''SYM::	BLOCK	SIZE
>

	PAGE
.DL'PORT'BS==.+1		;BASE OF THIS DL10 WINDOW
DLBA'PORT::	EXP	<.DL'PORT'BS>!ZZ	;FOR CONO DLB
DC76'PORT'M::	;;FIRST ADDRESS IN COMMON MEMORY
	MAP76(PORT)

> ;END DEFINITION OF BLDM76

	SUBTTL	DAS78 COMMON MEMORY FOR PDP10/PDP11

IFN	XPANDN,<LALL>			;EXPAND LISTING IF WANTED FROM MONGEN
	ZZD78L==0			;LINE NUMBER CONCATENATOR

;THIS MACRO DEFINES THE INTERPROCESSER
;WINDOW USED BETWEEN THE PDP10 AND THE PDP11.
;
DEFINE MAP78(PORT),<

	Q78SYM	<.DL'PORT'BS>;			;;FOR WINDOW MAP TABLE
	Q78SYM	<M8'PORT'KII>;			;BEGINNING WINDOW ADDRESS

	PHASE	0

IFN FTKI10!FTKL10,<
	Q78DAT	M78KII,<JSR	D80'PORT'KI>	;TELLS KI WHERE TO GO
>;END IFN FTKI10!FTKL10
IFN FTKA10,<
	Q78DAT	M78KII,<0>			;KA DOESN'T COME HERE
>;END IFN FTKA10
	Q78WRD	<M78ESA>,			;
	Q78WRD	<M78WNU>,			;
	Q78WRD	<M78NAM>,			;PROGRAM NAME (DAS78 IN SIXBIT)
	Q78WRD	<M78EPN>,			;
	Q78WRD	<M78OK>,			;PDP11 ALIVE INDICATOR.  INCREMENTED
						; BY 10 ONCE A SECOND. SET 0 BY 11.
						;  IF .LT. 2, 11 IS ALIVE
	Q78WRD	<M78HLT>,			;11 TO 10 STOP CODE
	Q78WRD	<M78DWN>,			;1=UP, 0=DOWN & TELL OPR, -1=DOWN
						; AND QUITE
	Q78WRD	<M78UPT>,			;
	Q78WRD	<M78GLB>,			;GLOBAL STATUS WORD
	Q78WRD	<M78MOD>,			;MODIFICATION NUMBER
	Q78WRD	<M78XXI>,			;10 TO 11 ACTIVTY INDICATOR
	Q78WRD	<M78XIX>,			;11 TO 10 ACTIVITY INDICATOR
	Q78WRD	<M78ALI>,			;PDP10 ALIVE INDICATOR.  INCREMENTED
						; BY 11 ONCE A SECOND.  SET -1 BY 10.
						;  IF .LE.1, 10 IS ALIVE.
	Q78WRD	<M7810S>,			;STATUS OF 10.	0 INITIALLY
						;1 STARTED INITIALIZATION
						;-1 RUNNING
	Q78WRD	<M7811S>,			;STATUS OF 11.	0 INITIALLY
						;1 STARTED INITIALIZATION
						;-1 RUNNING
	Q78WRD	<M78ADR>,			;ADDRESS FOR LOAD/STORE IN 11 CORE
	Q78WRD	<M78DTA>,			;CONTENTS OF CONTENTS OF M78ADR.
	Q78DAT	M78NLI,<M.'PORT'D78>		;NUMBER OF LINES ON THIS PORT

	Q78SYM	<M78WIN>;			;BEGINNING OF WINDOW FOR EACH LINE
	DEPHASE
;THIS IS THE BEGINNING OF THE WINDOW SLOTS AND
;THERE IS ONE FOR EACH LINE
;
REPEAT	<M.'PORT'D78>,<
	Q78SYM	<WS8L>,\<ZZD78L>;		;BEGINNING OF WINDOW SLOT
	PHASE	0
	Q78SYM	<SUBW78>;	;FIRST ADDR IN SUB WINDOW
	Q78WRD	<WS8LS0>,	;GENERAL LINE STATUS (OWNED BY 10 FOR CALL78 UUO)
	Q78WRD	<WS8LS1>,	;2ND LINE STATUS WORD
	Q78WRD	<WS8MSZ>,	;MESSAGE SIZE
	Q78WRD	<WS8RSZ>,	;RECORD SIZE
	WS8SET==:<.-SUBW78>	;NUMBER OF WORDS WE ALLOW
				; THE CALL78 TO SET
	Q78WRD	<WS810S>,	;STATUS OWNED BY THE PDP10
	Q78WRD	<WS811S>,	;STATUS OWNED BY THE PDP11
	Q78WRD	<WS8ICC>,	;INPUT TO 10 CHARACTER COUNT
	Q78WRD	<WS8IBP>,	;INPUT TO 10 BYTE POINTER
	Q78WRD	<WS8OCC>,	;OUTPUT FROM 10 CHARACTER COUNT
	Q78WRD	<WS8OBP>,	;OUTPUT FROM 10 BYTE POINTER
	M78SIZ==:<.-SUBW78>	;WINDOW SLOT SIZE
	Q78INC	<ZZD78L>,<1>;	;NEXT LINE NUMBER
	DEPHASE

>	;END REPEAT
>;END MAP78

;THIS MACRO USES THE "MAP78" MACRO TO ACTUALLY BUILD THE
;THE WINDOW.  IT CALLS "MAP78" TO FIRST CALCULATE THE WINDOW
;SIZE AND THEN IT CALLS "MAP78" AGAIN TO ACTUALLY BUILD THE
;THE DAS78 WINDOW.
;
DEFINE	BLD78	(PORT),<

IFN <M.'PORT'D78>,<			;ONLY BUILD IF THERE IS LINES ON PORT

;THESE MACRO'S ARE USED FOR COMPUTING THE SIZE OF THE MAP
;
DEFINE	Q78BLK(A),<
	ZZD78A==ZZD78A+A>
;
DEFINE Q78WRD(A),<
	ZZD78A==ZZD78A+1>
;
DEFINE	Q78DAT(A,B),<
	ZZD78A==ZZD78A+1>
;
DEFINE	Q78SYM(A,B),<
	;A>
DEFINE	Q78INC(A,B),<
	;A==A+B>
;END OF MACRO'S THAT DETERMINE MAP SIZE

	ZZD78A==0			;START WITH 0

IFNDEF	M78FPO,<M78FPO==:PORT>		;FIRST PORT INUSE BY DAS78.
	M78HPO==:PORT			;FIGURE HIGHEST DAS78 PORT.
;CALL MAP78 TO CALCULATE WINDOW SIZE
;
	MAP78	PORT

	ZZD78A==<ZZD78A-1>		;ADJUST TO LAST USED LOCATION

REPEAT ^D18,<ZZD78A==ZZD78A!<ZZD78A_<-1>>>

	ZZD78A==<ZZD78A!<<M78M8K*777>!77>>	;MAKE BIGGER IF 8K DL10

IFN	<.&ZZD78A>,<
	LOC	<.!ZZD78A>+1
>;END IFN <.&ZZD78A>

	ZZD78A==<ZZD78A_<-<6+<3*M78M8K>>>>	;SIZE OF BLOCK
	M8'PORT'END==<<<<ZZD78A+1>_<M78M8K*3>>*^D64>+.-1>

IFN	<ZZD78A&777760>,<PRINTX ?DAS78 DL10 MAPPED AREA TOO LARGE.>
	M8'PORT'BAM==<ZZD78A*4>		;SHIFT TO CORRECT PLACE FOR BASE ADR MASK
DEFINE	Q78BLK(A),<
	BLOCK	A>

DEFINE	Q78WRD(A),<
	A::!Z>

DEFINE	Q78DAT(A,B),<
	A::!B>

DEFINE	Q78SYM(A,B),<
	A'B::>
DEFINE	Q78INC(A,B),<
	A==A+B>
;CALL MAP78 NOW TO ACTUALLY BUILD THE WINDOW
;
	MAP78	PORT

	M78NUM==:<-<M78HPO-M78FPO+1>>	;MINUS NUMBER OF POSSIBLE PDP11'S


	LOC	<M8'PORT'END>+1

>;END OF IFN M'PORT'D78
>;END OF DEFINITION OF BLD78

;NOW ACTUALLY CALCULATE WINDOW SIZE AND
;BUILD THE WINDOW.
;
	DEFINE	MAPIT(P)
<	IFN	TP.DL'P,<
	IFN	M.'P'D78,<
	BLD78(P)		;;DAS78 OPTION
>
	IFE	M.'P'D78,<
	BLDM76(P)		;;DC44 DC76 OR DC75 MAP
>>	;END OF IFN TP.DL'P
>	;END OF MAPIT

ZZZ=0			;FIRST PORT
	REPEAT	10,<
	IFLE	<ZZZ-3>,<
IFNDEF	DLX08K,<DLX08K==0	;;ASSUME JUMPERED FOR 1K MAXIMAL>
IFN	DLX08K,<DLX08K==1	;;FORCE TO 1 IF NOT ZERO>
DLX8K==DLX08K			;;USED BY BLDM76
M78M8K==DLX08K			;;FOR BLD78
>
	IFG	<ZZZ-3>,<
IFNDEF	DLX18K,<DLX18K==0	;;ASSUME JUMPERED FOR 1K MAXIMAL>
IFN	DLX18K,<DLX18K==1	;;FORCE TO 1 IF NOT ZERO>
DLX8K==DLX18K			;;USED BY BLDM76
M78M8K==DLX18K			;;FOR BLD78
>
	MAPIT(\ZZZ)	;GET THE RIGHT MAP OR NOTHING
ZZZ=ZZZ+1
>

;THIS MACRO BUILDS A TABLE WHICH CONTAINS THE
;WINDOW ADDRESS IN THE (RH)
;AND FOR A DAS78 PORT  A POINTER TO A
;TABLE IN THE (LH) WHICH CONTAINS THE DDB ADDRESSES
;FOR EACH LINE.
;
DEFINE	B78BAT	(PORT),<
	IFN	TP.DL'PORT,<
IFN	M.'PORT'D78,<	M8'PORT'DDB,,.DL'PORT'BS>
IFE	M.'PORT'D78,<	Z	>
>
	IFE	TP.DL'PORT,<	Z	>
>;END OF DEFINITION OF B78BAT
;
DEFINE	BLXBAT(PORT),<
	IFN	TP.DL'PORT,<
IFE	M.'PORT'D78,<	DL'PORT'BAS>
IFN	M.'PORT'D78,<	Z	>
>
	IFE	TP.DL'PORT,<	Z	>
>	;END OF BLXBAT DEFINITION
	$HIGH
DLXBAT::BLXBAT	\0
	BLXBAT	\1
	BLXBAT	\2
	BLXBAT	\3
	BLXBAT	\4
	BLXBAT	\5
	BLXBAT	\6
	BLXBAT	\7

	$ABS

IFN M.DAS78,<

	$HIGH

ZZD78A==0
M78BAT::
	REPEAT	<M78HPO+1>,<
	B78BAT	\ZZD78A
	ZZD78A==ZZD78A+1
>	;END REPEAT
	$ABS

;THIS MACRO BUILDS A TABLE WHICH IS FILLED
;AT "SYSINI" TIME WITH THE DDB ADDRESSES FOR EACH
;LINE.  THE (LH) POINTS TO THE INPUT DDB, AND
;THE (RH) POINTS TO THE OUTPUT DDB.
;
DEFINE	B78DDB	(PORT),<
IFDEF M8'PORT'KII,<M8'PORT'DDB::BLOCK	M.'PORT'D78>
>;END OF B78DDB DEFINITION
;
ZZD78A==0
M78DDB::
	REPEAT	<M78HPO+1>,<
	B78DDB	\ZZD78A
	ZZD78A==ZZD78A+1
>	;END REPEAT
;THIS MACRO BUILDS A TABLE WHICH CONTAINS
;THE LAST USED LOCATION IN THE WINDOW FOR EACH PORT
;IF THERE IS NO DAS78 ON THAT PORT A 0 IS
;INSERTED.
;
DEFINE	B78END	(PORT),<
IFNDEF M8'PORT'END,<	Z>
IFDEF	M8'PORT'END,<	M8'PORT'END>
>;END DEFINE B78END
;
	$HIGH
ZZD78A==0
M78END::
	REPEAT	<M78HPO+1>,<
	B78END	\ZZD78A
	ZZD78A==ZZD78A+1
>	;END REPEAT


;TABLE OF NUMBER OF LINES ON EACH DAS78 PDP11
;
DEFINE	B78LIN(LIN),<
	M.'LIN'D78
>	;END DEFINE B78LIN
ZZD78A==0
M78LIN::
	REPEAT	<M78HPO+1>,<
	B78LIN	\ZZD78A
	ZZD78A==ZZD78A+1
>	;END REPEAT

	$ABS

;TABLE OF NAMES PUT HERE BY THE PDP-11
;THROUGH A POINTER IN THE WINDOW.
;
D78NAM::BLOCK	<M78HPO+1>
>	;END IFN M.DAS78
	$ABS

	PURGE	ZZD78A,ZZD78L

>	;END OF IFN PDP11N

DLXLST::

SUBTTL CPU DATA BLOCK(S):

REPEAT 0,<

EACH CPU HAS ITS OWN DATA BLOCK, KNOWN AS A CDB.
IT IS USUALLY INDEXED BY AC P4, WHEN REFERENCED AT APR OR CLK INTERRUPT
LEVEL ROUTINES (SEE APRINT, CLOCK1, SCHED1, ERRCON MODULES).
THE REST OF THE MONITOR ONLY REFERENCES THE CDB FOR THE MASTER CPU.
IN THESE CASES IT WILL USUALLY USE THE OLD 6 CHAR NAME.
MANY LOCATION IN THE CDB PERTAIN ONLY TO THE MASTER CPU. HOWEVER,
FOR GENERALITY AND FUTURE EXPANSION TO A MASTER/MASTER SYSTEM, INSTEAD
OF MASTER/SLAVE, THEY ARE INCLUDED IN CDB(WITH OLD NAMES
AND NO P4).  A FEW LOCATIONS ARE REALLY SYSTEM PARAMETERS(EG CORTAL),
RATHER THAN CPU PARAMETERS.  HOWEVER, THEY WERE IN THE MIDDLE OF A
GETTAB(NSWTBL) AND SO COULD NOT BE SEPARATED OUT WITHOUT INVALIDATING
SOME PROGRAMS.

RULE:	ANY SYMBOL DIFINED AS .CP??? WILL ALWAYS INDEX BY P4.  OLD
SYMBOLS AND .C0??? AND .C1??? SYMBOLS ARE NEVER INDEXED BY P4, SINCE
THEY ARE ABSOLUTE WITH RESPECT TO THE ORGIN OF THE MONITOR.

PRINCIPLE:	THE FOLLOWING MACROS ONLY GENERATE INTERN SYMBOLS WHICH ARE
ACTUALLY USED.  THIS MINIMIZES THE NO. OF SYMBOLS AND IS A USEFUL
DOCUMENTATION TOOL.  IN OTHER WORDS A LOCATION WILL ONLY HAVE AN OLD
SYMBOL, OR A NEW .CP??? SYMBOLS, OR .CP??? AND .C0??? AS NEEDED.
FOR DEBUGGING WITH DDT, THE ABSOLUTE SYMBOLS FOR CPU0 AND CPU1 ARE
ALWAYS GENERATED AT LEAST AS LOCAL SYMBOLS.
>

REPEAT 0,<

PRINCIPLE:	WHEN ADDING CONSTANTS OR VARIABLES TO COMMON,
GREAT CARE MUST BE EXERCISED IN DECIDING WHETHER TO PUT IT
IN THE CDB OR IN A SYSTEM DEPENDENT TABLE(.SYTBL).
IF THE CONTENTS COULD EVER BECOME CPU DEPENDENT IN THE FUTURE, BE
SURE TO PUT IT IN THE CDB INSTEAD OF .SYTBL.  IF A MISTAKE IS MADE,
THE LOCATION WILL HAVE TO APPEAR IN THE CDBS AS WELL AS
.SYTBL IN ORDER TO INSURE COMPATIBLITY.

;DEFINE CONSTANTS AREA IN CDB
;EACH 'C' MACRO GENERATES A CONSTANT FOR CPU0
;AND A CONSTANT FOR CPU1.
;THE CALL IF OF FORM:
;	C <XXX,CP0,CP1,CONST0,CONST1>
;WHERE:	XXX IS THREE LETTER SUFFICE FOR LOC.SYMBOL
;	CP0 IS EITHER NULL (IE ,,) OR "CPO"
;	CP1 IS EITHER NULL (IE ,,) OR "CP1"
;	CONST0 IS THE CONSTANT VALUE FOR CDB 0
;	CONST1 IS THE CONSTANT VALUE FOR CDB 1
>
;DEFINE C MACRO TO GENERATE CONSTANTS FOR BEGINNING OF CDB FOR CPU 0:
;DEFINE FOR CPU 1 BELOW, JUST BEFORE SECOND CALL OF CPUCON
;ALWAYS DEFINE ABSOLUTE SYMBOLS AS EITHER INTERN OR LOCAL
; INTERN IF USED, LOCAL IF USED ONLY FOR DEBUGGING WITH DDT.


	DEFINE C(XXX,ABS0,ABS1,CONST0,CONST1)<
	IFIDN <ABS0> <CP0>,<INTERN .C0'XXX>	;INTERN IF USED
	.C0'XXX: CONST0		;ABS SYMBOL AND THE CONSTANT.
	XP .CP'XXX,.-1-.C0CDB>	;RELATIVE SYMBOL FOR INDEXING WITH P4


;DEFINE V MACRO TO GENERATE VARIABLES FOR END OF CDB
;THESE VARIABLES ARE CLEARED AT SYSTEM STARTUP AND 403 RESTART
;V MACRO DEFINES VARIABLES FOR ALL CDBS IN ONE CALL

	DEFINE	V(XXX,ABS0,ABS1,OLDSYM,LENGTH)<
	IFNB <XXX>,<XP .CP'XXX,<LOC-.C0CDB>>	;RELATIVE SYMBOL FOR CPU 0
	IFIDN <ABS0> <CP0>,<XPP .C0'XXX,LOC>	;ABS SYMBOL FOR CPU 0 IF USED
	IFB <ABS0>,<XPL .C0'XXX,LOC>	;LOCAL SYM FOR CPU0 FOR DDT IF NOT USED
	IFNB <OLDSYM>,<XPP OLDSYM,LOC>	;OLD ABS. SYMBOL FOR CPU 0 ONLY

	IFG <CPUN-1>,<IFIDN <ABS1> <CP1>,<
	XPP .C1'XXX,<LOC-.C0CDB+.C1CDB>>	;ABS SYMBOL FOR CPU1
	IFB <ABS1>,<XPL .C1'XXX,<LOC-.C0CDB+.C1CDB>>> ;LOCAL SYM FOR CPU1

	IFNB <LENGTH>,<LOC==LOC+LENGTH>	;INCREMENT LOC COUNTER
	IFB <LENGTH>,<LOC==LOC+1>>	;INCREMENT BY 1 AS DEFAULT

;DEFINE ENTIRE CDB CONSTANT AREA AS ONE MACRO(CDBCON) WHICH CALLS
;C MACRO FOR EACH CONSTANT.

;NOTE: ; MUST APPEAR IMMEDIATELY AFTER ) IN MACRO CALL, ELSE NO COMMENT.

DEFINE	CDBCON (N)	<

;CONSTANTS IN GETTAB UUO.(NOT CLEARED AT STARTUP OR 143 RESTART)
C	(CDB,CP0,CP1,<XWD .C1CDB,0>,0);	;(0) LH=ADR. OF NEXT CDB, RH=0
C	(ASN,CP0,CP1,APR0SN,APR1SN); 	;(1) APR SERIAL NO.
C	(OK,CP0,CP1,1,1);		;(2) THIS CPU RUNNING OK.
					;IF GREATER THAN 0, THIS CPU HAS STOPPED
					;RUNNING CORRECTLY.  CONTENTS ARE NO. OF
					;JIFFIES CPU HAS BEEN STOPPED.
IFN M.KI10!M.KL10,<
C0TOS==.EPMP
C1TOS==.E1MP
>
C	(TOS,CP0,,C0TOS,C1TOS);		;(3)CONTAINS TRAP OFF SET (0 OR 100)
					; NEEDED FOR TWO CPUS INTERRUPT LOCATIONS
					; DEFAULT VALUES FOR .C0TOS==0,.C1TOS==100.
					; MONGEN ALLOWS CHANGE.

C	(LOG,,,<SIXBIT/CPU0/>,<SIXBIT/CPU1/>)	;(4) LOGICAL CPU NAME (CPUN)
IFN	CP0P6N,<C0.PHY==<SIXBIT/CP60/>>	;PDP-6?
IFN	CP0KAN,<C0.PHY==<SIXBIT/CPA0/>>	;KA10?
IFN	CP0KIN,<C0.PHY==<SIXBIT/CPI0/>>	;KI10?
IFN	CP0KLN,<C0.PHY==<SIXBIT/CPL0/>>	;KL10?
IFN	CP1P6N,<C1.PHY==<SIXBIT/CP61/>>
IFN	CP1KAN,<C1.PHY==<SIXBIT/CPA1/>>
IFN	CP1KIN,<C1.PHY==<SIXBIT/CPI1/>>
IFN	CP1KLN,<C1.PHY==<SIXBIT/CPL1/>>
C	(PHY,,,C0.PHY,C1.PHY)		;(5) PHYSICAL CPU NAME (CPXN)
				; DISTINGUISH BETWEEN KA10 AND KI10
IFN	CP0P6N,<C0.TYP==CT.P6>	;PDP-6?
IFN	CP0KAN,<C0.TYP==CT.KA>	;PDP-6 KA10?
IFN	CP0KIN,<C0.TYP==CT.KI>	;PDP-6 KI10?
IFN	CP0KLN,<C0.TYP==CT.KL>	;PDP-6 KL10?
IFN	CP1P6N,<C1.TYP==CT.P6>
IFN	CP1KAN,<C1.TYP==CT.KA>
IFN	CP1KLN,<C1.TYP==CT.KL>
IFN	CP1KIN,<C1.TYP==CT.KI>	;(6) TYPE OF PROCESSOR RH DEC, LH CUSTOMERS
C	(TYP,CP0,CP1,C0.TYP,C1.TYP)	;1=PDP-6, 2=KA10, 3=KI10.
IFE FTMEMPAR,<XP .CPBAT,.CPVBG>	;NO. SUB TABLE IF NO MEM PARITY
IFE FTMEMPAR,<XP M.CBAT,1>	;MAX IS 0
.XX==<M.CBAT-1>B8+.CPBAT-.CPVBG	;DEFINE BITS 0-8 = MAX. REL. ENTRY
				; RH=REL ADR IN VAR CDB GETTAB
C	(MPT,,,<.XX>,<.XX>)
				;(7) POINTER TO BAD ADR SUB-TABLE.
				; BITS 0-8 LENGTH OF SUB-TABLE
				; RH=REL. ADR. OF SUB-TABLE (IN CDB VARIABLE AREA)
				; (SEE .CPBAT)

C	(RTC,,,C0RTC##,C1RTC##); ;(10) REAL TIME CLOCK (DK10) DDB

C	(RTD,,,C0RTD##,C1RTD##);	;(11) DK10 DDB IF HI PREC. TIME ACCT.
				;   0 IF LOW PREC. (APR CLOCK)

IFE FTMEMPAR,<XP .CPLPA,.CPVBG>	;NO. SUB-TABLE IF NO MEM PARITY
IFE FTMEMPAR,<XP .CPPRL,1>	;MAX IS 0
.XX==<.CPPRL-1>B8+.CPLPA-.CPVBG	;DEFINE BITS 0-8 = MAX. REL. ENTRY
				; RH = REL ADR IN VAR CDB GETTAB
C	(PAR,,,<.XX>,<.XX>)
				;(12) REL PTR AND LENGTH TO PARITY
				; SUB-TABLE IN VARIABLE GETTAB. 0 IF FEATURE
				; NOT PRESENT

IFE FTRSP,<XP .CPAOR,.CPVBG>	;NO SUB-TABLE IF NO RESPONSE STUFF
IFE FTRSP,<XP .CPRSL,1>		;MAX IS 0
.XX==<.CPRSL-1>B8+.CPAOR-.CPVBG	;DEFINE BITS 0-8 = MAX REL. ENTRY,
				; RH = REL ADR IN VAR. CDB. GETTAB
C	(RSP,,,<.XX>,<.XX>)
				;(13) REL PTR AND LENGTH TO RESPONSE
				; SUB-TABLE IN VARIABLE GETTAB.
				; 0 IF FEATURE NOT PRESENT
C	(DKX,,,<M.RT0>,<M.RT1>)	;(14) NUMBER OF DK10'S ON THIS CPU

IFN M.KL10,<.XX==M.EBPS>
IFN M.KA10!M.KI10,<.XX==0>

C	(EBS,,,<.XX>,<.XX>)	;(15)EBOX TICKS PER SECOND

IFN M.KL10,<.XX==M.MBPS>
IFN M.KA10!M.KI10,<.XX==0>

C	(MBS,,,<.XX>,<.XX>)	;(16)MBOX TICKS PER SECOND
IFE FTMEMPAR&FTMEMNXM,<XP .CPLNA,.CPVBG>  ;NO SUBTABLE IF NO MEM PAR OR MEMNXM
IFE FTMEMPAR&FTMEMNXM,<XP .CPNML,1>	;MAX IS 0
.XX==<.CPNML-1>B8+.CPLNA-.CPVBG	;DEFINE BITS 0-8 LENGTH.
C(NMT,,,<.XX>,<.XX>)		;(17) POINTER TO NXM SUBTABLE

;ADD CONSTANTS TO BE PUBLISHED ABOVE HERE:

;UNPUBLISHED CONSTANTS:
C	(OK1,CP0,CP1,.C1OK,.C0OK);	;CONTAINS ADR OF OTHER CPU
					; OK WORD. SEE .CPOK ABOVE.
IFN FTSWAP,<
C	(SCN,CP0,CP1,SSCAN,SSCAN1);	;CONTAINS ADR. OF SCHEDULER RUN QUEUE SCAN LIST
>
IFN FTNSCHED,<
C	(SST,CP0,CP1,SSSCAN,SSSCN1);	;ADDR. OF SUBQUEUE SCHEDULING SCAN TABLE
>
C	(NPD,CP0,CP1,<XWD MNULPD,NULPDL>,<XWD MNU1PD,NU1PDL>); ;CONTAINS NULL PDL PTR
C	(EPD,,,<XWD ERRPLL,ERRPDL>,<XWD ERRPLL,ER1PDL>); ;CONTAINS ERR PDL PTR
					; ERROR IN NULL JOB
C	(NJD,CP0,CP1,NU0DAT,NU1DAT);	;CONTAINS ADR OF NULL JOB DATA AREA.  OFFSET BY 20
					; USED TO SAVE ACS IN 20-37.
IFN FTTLIM,<
C	(TLE,,,MTIMLM##,STIMLM##);	;CONTAINS ADR OF ROUT TO PRINT TIME LIMIT EXCEEDED
>
					; ON USER CONSOLE OR RESCHEDULE BACK ON MASTER
C	(NXJ,,,NXTJOB##,NXTJB1##);	;CONTAINS ADR. OF SCHEDULER, REQUEUER
C	(RUA,,,CIP8A##,SCIP8A##);	;CONTAINS ADR. OF ROUT. TO RESTORE USER ACS
					; AND DISMISS CLK INTERRUPT
C	(SCH,,,MSCHED,SSCHED##);CONTAINS ADR. OF JOB PICKING SCHEDULER



;APR DEPENDENT CONSO AND CONO BITS
;DEFINED HERE AS CONSTANTS SO CAN HANDLE DIFFERENT CPUS IN SAME DUAL CPU SYSTEM
;IE A PDP-6 AND KA10, OR A KA10 AND A KI10.

C	(NAP,CP0,,A0.NOT,A1.NOT);	;CONTAINS ALL PIS IN PROGRESS EXCEPT APR PI
					; ON THIS CPU. (NOT APR PI)
IFN M.KI10!M.KL10&FTMEMPAR,<
C	(APP,,,A0.APP,A1.APP);	;APR PI IN PROGRESS
>
A0.XXX==AP.POV!AP.ILM!AP.NXM!XP.CLK!AP.AOV!UE.PEF!UE.NXM	;TEMP SYMBOL FOR PDP-6 AND KA10 CONSO BITS
					; USER CAN ENABLE FOR.
A1.XXX==AP.POV!AP.ILM!AP.NXM!XP.CLK!AP.AOV!UE.PEF!UE.NXM	;TEMP SYMBOL FOR PDP-6 AND KA10 CONSO BITS
					; USER CAN ENABLE FOR.
IFN CP0KIN,<
A0.XXX==IP.TTO+IP.PAR+IP.PWF+XP.CLK+IP.ABK+IP.NXM+UE.PEF+UE.NXM
>
IFN CP1KIN,<
A1.XXX==IP.TTO+IP.PAR+IP.PWF+XP.CLK+IP.ABK+IP.NXM+UE.PEF+UE.NXM
>
IFN CP0KLN,<
A0.XXX==LP.PAR+LP.PWF+LP.NXM
>
IFN CP1KLN,<
A1.XXX==LP.PAR+LP.PWF+LP.NXM
>
C	(FO1,,,<A0.XXX+A0.FOV>,<A1.XXX+A1.FOV>);	;USER ENABLED BITS ON THIS CPU
					; INCLUDE FOV IF KA10, NOT IF PDP-6
					; AND USER MEM PARITY ENABLE
C	(FO2,,,<AP.AOV+A0.FOV>,<AP.AOV+A1.FOV>);	;APR XOR MASK TO ENABLE/DISABLE AOV,FOV
					; DEPENDING ON PDP-6 VS KA10.
A0.XXX=AP0CHN
IFN CP0KIN,<A0.XXX=A0.XXX+AP0CHN_3>
IFG <CPUN-1>,<
A1.XXX=AP1CHN
IFN CP1KIN,<A1.XXX=A1.XXX+AP1CHN_3>
>
C	(API,CP0,CP1,<A0.XXX>,<A1.XXX>);	;APR PI CHANNEL FOR THIS CPU
AP.XXX==AP.DFO+AP.DAO	;TEMP SYMBOL TO DISABLE FOV AND AOV
C	(DUI,,,<AP.XXX+AP0CHN>,<AP.XXX+AP1CHN>);	;DISABLE OPTIONAL USER
					; INTERRUPTS + APR PI CHAN

C	(CHL,,,<EXP AP0CHL>,<EXP AP1CHL>);	;ADDRESS OF INTERRUPT PC FOR APR LEVEL
A0.XXX==AP.POV+AP.ILM+AP.NXM+XP.CLK	;TEMP SYMBOL FOR PDP-6 AND KA10 CONSO BITS
A1.XXX==AP.POV+AP.ILM+AP.NXM+XP.CLK	;TEMP SYMBOL FOR PDP-6 AND KA10 CONSO BITS
IFN CP0KIN,<
A0.XXX==IP.TTO+IP.PAR+IP.PWF+XP.CLK+IP.NXM
>
IFN CP1KIN,<
A1.XXX==IP.TTO+IP.PAR+IP.PWF+XP.CLK+IP.NXM
>
IFN CP0KLN,<
A0.XXX==LP.PAR+LP.PWF+LP.SBE+LP.NXM+LP.IOF+LP.CDP+LP.ADP
>
IFN CP1KLN,<
A1.XXX==LP.PAR+LP.PWF+LP.SBE+LP.NXM+LP.IOF+LP.CDP+LP.ADP
>
C	(CON,,,A0.XXX,A1.XXX);	;APR CONSO MASK

A0.XXX==AP.ILM
A1.XXX==AP.ILM
IFN CP0KIN,<A0.XXX==0>
IFN CP1KIN,<A1.XXX==0>
IFN CP0KLN,<A0.XXX==0>
IFN CP1KLN,<A1.XXX==0>

C	(ILM,CP0,CP1,A0.XXX,A1.XXX);	;ILL MEM REF MASK

A0.XXX==AP.NXM+AP.POV
A1.XXX==AP.NXM+AP.POV
IFN CP0KIN,<A0.XXX==IP.NXM>
IFN CP1KIN,<A1.XXX==IP.NXM>
IFN CP0KLN,<A0.XXX==LP.NXM>
IFN CP1KLN,<A1.XXX==LP.NXM>

C	(EME,,,A0.XXX,A1.XXX);	;EXEC MODE ERROR MASK

A0.XXX==AP.POV+AP.ABK+AP.ILM+XP.CLK+AP.NXM
A1.XXX==AP.POV+AP.ABK+AP.ILM+XP.CLK+AP.NXM
IFN CP0KIN,<A0.XXX==IP.NXM+XP.CLK+IP.TTO+IP.PAR+IP.PWF+IP.IOF>
IFN CP1KIN,<A1.XXX==IP.NXM+XP.CLK+IP.TTO+IP.PAR+IP.PWF+IP.IOF>
IFN CP0KLN,<A0.XXX=LP.NXM+LP.SBE+LP.PAR+LP.PWF+LP.IOF+LP.CDP+LP.ADP+LP.CSD>
IFN CP1KLN,<A1.XXX=LP.NXM+LP.SBE+LP.PAR+LP.PWF+LP.IOF+LP.CDP+LP.ADP+LP.CSD>

C	(EEB,,,A0.XXX,A1.XXX);	;EXEC ENABLED BITS

A0.XXX==AP.CMP+AP.CAO+AP.CPO+AP.CFO
A1.XXX==AP.CMP+AP.CAO+AP.CPO+AP.CFO
IFE FTMEMNXM,<
A0.XXX==A0.XXX+AP.CNM
A1.XXX==A1.XXX+AP.CNM
>
IFN CP0KIN,<A0.XXX==IP.CTE+IP.CAE+IP.ECI+IP.CIO>
IFN CP1KIN,<A1.XXX==IP.CTE+IP.CAE+IP.ECI+IP.CIO>
IFN CP0KIN,<IFE FTMEMNXM,<
A0.XXX==A0.XXX+IP.CNM>>
IFN CP1KIN,<IFE FTMEMNXM,<
A1.XXX==A1.XXX+IP.CNM>>
IFN CP0KLN,<A0.XXX==LP.CSF+LP.NXM+LP.PAR+LP.IOF+LP.PWF+LP.SBE+LP.CDP+LP.ADP>
IFN CP1KLN,<A1.XXX==LP.CSF+LP.NXM+LP.PAR+LP.IOF+LP.PWF+LP.SBE+LP.CDP+LP.ADP>

C	(IEF,,,A0.XXX,A1.XXX);	;MASK TO CLEAR ALL INTERRUPTING APR ERROR FLAGS
				; EXCEPT MEM PARITY AND CLOCK
				; (AND SWEEP DONE ON THE KL)



;ENTRIES FOR KA10 - KI10 - KL10 CPU DIFFERENCES


DEFINE KAI(M)<
	IFN CP'M'KAN,<KA>
	IFN CP'M'KIN,<KI>
	IFN CP'M'KLN,<KL>
>


DEFINE KA<CONSZ PI,PI.PWF>
DEFINE KI<CONSZ APR,IP.PWF+IP.IOF>
DEFINE KL<CONSZ APR,LP.PWF+LP.IOF+LP.SBE>

C	(NPE,,,<KAI(\N)>,<KAI(\N)>);

DEFINE KA<CONSZ PI,PI.PAR>
DEFINE KI<CONSZ APR,IP.PAR>
DEFINE KL<CONSZ APR,LP.PAR>

C	(MPE,,,<KAI(\N)>,<KAI(\N)>);	;TEST FOR MEMORY PARITY ERROR


DEFINE KA<CONI APR,JOBCNI##(R)>
DEFINE KI<PUSHJ P,[PUSH P,T1
	CONI APR,T1
	TRZE T1,IP.NXM
	TRO T1,AP.NXM
	MOVEM T1,JOBCNI##(R)
	JRST TPOPJ]>
DEFINE KL,<PUSHJ P,[PUSH P,T1
	CONI APR,T1
	TRNN T1,LP.NXM
	TDZA T1,T1
	MOVEI T1,AP.NXM
	SKIPE	.CPTIM(P4)
	TRO	T1,XP.CLK
	MOVEM T1,JOBCNI##(R)
	JRST TPOPJ]>

C	(UEH,,,<KAI(\N)>,<KAI(\N)>);

DEFINE	KA<CONI APR,.CPAEF(P4)>
DEFINE	KI<PUSHJ P,[PUSH P,T1
	 CONI APR,T1
	 TRZE T1,IP.NXM
	 TRO T1,AP.NXM
	 MOVEM T1,.CPAEF(P4)
	 JRST TPOPJ]>
DEFINE KL,<PUSHJ P,[PUSH P,T1
	CONI APR,T1
	TRNN T1,LP.NXM
	TDZA T1,T1
	MOVEI	T1,AP.NXM
	MOVEM T1,.CPAEF(P4)
	JRST TPOPJ]>

DEFINE KL,<PUSHJ P,[PUSH P,T1
	CONI APR,T1
	TRNN T1,LP.NXM
	TDZA T1,T1
	MOVEI	T1,AP.NXM
	MOVEM T1,.CPAEF(P4)
	JRST TPOPJ]>

C	(EEH,,,<KAI(\N)>,<KAI(\N)>);


DEFINE KA,<CONO APR,XP.CCF>
DEFINE KI,<CONO APR,XP.CCF>
DEFINE KL,<SETZM .CPTIM(P4)>

C	(CCF,,,<KAI(\N)>,<KAI(\N)>)	;CLEAR CLOCK FLAG INSTRUCTION
DEFINE KA,<CONSO APR,XP.CLK>
DEFINE KI,<CONSO APR,XP.CLK>
DEFINE KL,<SKIPN .CPTIM(P4)>

C	(HCT,,,<KAI(\N)>,<KAI(\N)>)	;HAS CLOCK TICKED? (SKIP IF YES)

DEFINE KA,<CONSO APR,@.CPCN1(P4)>
DEFINE KI,<CONSO APR,@.CPCN1(P4)>
DEFINE KL,<PUSHJ P,[PUSH P,T1
	MOVE	T1,.CPCN1(P4)
	TRNE	T1,XP.CLK	;SKIP IF USER ENABLED FOR CLOCK AND
	SKIPN	.CPTIM(P4)	;CLOCK HAS TICKED
	CAIA			;CONDITION NOT MET
	JRST	TPOPJ1		;CONDITION IS MET
	ANDI	T1,LP.NXM	;CLEAR OUT ALL BUT NXM
	CONSO	APR,(T1)	;IS THAT SET?
	JRST	TPOPJ		;NO, NON-SKIP
	JRST	TPOPJ1		;YES,OK
]>

C	(IUE,,,<KAI(\N)>,<KAI(\N)>)	;IS USER ENABLED?(FOR PRESENT COND.)
					; SKIP IF YES

IFN FTMEMPAR,<			;MEMORY PARITY ANALYSIS?
DEFINE KA<EXP CPAMPI##>
DEFINE KI<EXP CPIMPI##>
DEFINE KL<EXP CPLMPI##>

C	(MPI,,,<KAI(\N)>,<KAI(\N)>);	;LH=0, RH=ADDRESS OF CPUN
				; PARITY SWEEP LOOP INSTURCTION WHICH PICKS
				; UP MEMORY. USED BY APR PI INTERRUPT TO
				; CHECK FOR EXPECTED BAD PARITY IN SWEEP

CP.PP0==CP.PP5			;USE CPU5 REQUEST TO PRINT BIT FOR CPU0
DEFINE KA<EXP CP.PXX+CP.PS'N'+CP.PP'N'+CPAMPS##>  ;ADR OF KA MEM PAR SWEEP ROUTINE + REQUEST BITS
DEFINE KI<EXP CP.PXX+CP.PS'N'+CP.PP'N'+CPIMPS##>  ;ADR OF KI MEM PAR SWEEP ROUTINE + REQUEST BITS
DEFINE KL<EXP CP.PXX+CP.PS'N'+CP.PP'N'+CPLMPS##>

C	(MPS,,,<KAI(\N)>,<KAI(\N)>);	;
				; ADR. OF PAR SWEEP SUBROUTINE IN KASER
				; OR KISER. LH=BITS TO REQUEST SWEEP
				; BY THIS CPU, BITS 13-17=0.
				; CPU1 REQUEST CPU0 TO PRINT PAR ERRS
				; SEE S.MAC FOR DEFN OF CP. SYMBOLS
IFN FTMEMNXM,<
DEFINE KA<EXP AP.NXM>
DEFINE KI<EXP IP.NXM>
DEFINE KL<EXP LP.CSF+LP.NXM>

C	(NXM,,,<KAI(\N)>,<KAI(\N)>);

DEFINE KA<EXP CPANXF##>
DEFINE KI<EXP CPINXF##>
DEFINE KL<EXP CPLNXF##>

C	(NMF,,,<KAI(\N)>,<KAI(\N)>);NXM FIXUP ROUTINE
>;END FTMEMNXM
>				;END FTMEMPAR
C	(RDB,,,.C1DBL,.C0DBL);	;POINTER TO OTHER CPU'S DOORBELL
IFN M.KI10!M.KL10,<
C	(SMU,,,UUOSY1##,MUUO1);	;POINTER TO EXEC MODE MUUO HANDLER
C	(UMU,,,UUOSY1##,UUOUSP##);  ;POINTER TO USER MODE MUUO HANDLER
C	(SPD,,,CK0SPD##,CK1SPD##);	;ADDRESS TO TRANSFER TO WHEN THE DOORBELL RINGS
>
IFN M.KI10,<
C	(EBR,CP0,CP1,PG.LEB+PG.EAT+EPMPA,PG.LEB+PG.EAT+E1MPA);
>
IFN M.KL10,<
C	(EBR,CP0,CP1,LG.TEN+EPMPA,LG.TEN+E1MPA);
>
				;EXEC BASE REGISTER ON THIS CPU

IFN M.KL10,<
C	(DTN,,,M.0DTE,M.1DTE)	;;NUMBER OF DTES ON THIS CPU
>;END IFN M.KL10
C	(CAC,CP0,CP1,0,0)	;DEFINE CRASH AC'S IN CPU DATA BLOCK
BLOCK	17
C	(CPI,CP0,CP1,0,0)	;PI STATUS
C	(TRP,CP0,CP1,0,0)	;MUUO DURING CRASH
C	(RTT,CP0,CP1,0,0)	;RTTRP IN PROGRESS FLAG (DEFINED
				; HERE BECAUSE IT MUST BE 0 DURING ONCE-ONLY)
IFN FTKL10!FTKI10&FTSET,<
C	(APR,CP0,CP1,0,0)	;APR STATUS
>
;CDB CONSTANTS FOR KL10 ERROR REPORTING/RECOVERY
IFN M.KL10,<
C	(SPR,,,<CONO APR,LP.SSF+LP.PAR+AP0CHN>,<CONO APR,LP.SSF+LP.PAR+AP1CHN>)
	;INSTRUCTION TO CAUSE PARITY ERROR INTERRUPT
C	(CPR,,,<CONO APR,LP.CSF+LP.PAR+LP.SBE+AP0CHN>,<CONO APR,LP.CSF+LP.PAR+LP.SBE+AP1CHN>)
	;INSTRUCTION TO CLEAR PARITY ERROR FLAG(ALSO CLEARS SBUS ERROR-ON FOR SOME PARITY)
C	(SB0,,,<100000,,0>,<100000,,0>)	;DO SBDIAG 0 HERE ON ERRORS
C	(S0A,,,<0>,<0>)			;ANSWER RETURNED HERE
C	(SB1,,,<100000,,1>,<100000,,1>)	;SBDIAG FN 1 DONE HERE
C	(S1A,,,<0>,<0>)			;ANSWER RETURNED HERE


>;END IFN M.KL10

IFE <CPUN-N-1>,<		;IF 1 CPU SYS, CALL WHEN N=0, IF 2 CPU SYS,
				; CALL WHEN N=1.
	INTERN	SYSBEG,SYSBG2
SYSBEG:				;FIRST LOCATION TO CLEAR WHEN SYSTEM STARTUP
				; OR RESTARTED AT 403.  MAKE LAST CPU VARIABLE AREA
XP SYSBG1,SYSBEG+1		;FIRST LOC+1

SYSBG2:				;DEFINE FIRST LOCATION FOR ASSEMBLING
				; ONCE ONLY CODE WHICH SITS IN VARIABLE
				; AREA AND CLOBBERS THE REAL ONCE ONLY.
>
>	;END CDBCON - CDB CONSTANTS MACRO.

;GENERATE CDB
;GENERATE CONSTANTS FOR BEGINNING OF CPU 0 CDB BY CALLING CPUCON
; MACRO WITH CMACRO DEFINED FOR CPU0.
; THEN GENERATE VARIABLES FOR BOTH CPU 0 AND CPU 1.
; FINALLY REDEFINE C MACRO FOR CPU1 AND CALL CPUCON MACRO AGAIN.

	INTERN .C0CDB

IFN XPANDN,<LALL>	;LIST MACRO EXPANSIONS IF XPANDN IS
			; NONZERO (MONGEN CAN DEFINE)

.C0CDB:	CDBCON (0)		;GENERATE CONSTANTS
CRSHAC==:.C0CAC
CRSHPI=.C0CPI
TRPFLG==:.C0RTT
.CPCLN==.-.C0CDB		;LENGTH OF CONSTANTS AREA
XP .CPPCL,<<.C0OK1-.C0CDB>B26>	;PUBLISHED CPU DEPENDANT CONSTATNS LENGTH
				;SHIFTED LEFT 9 BITS FOR GETTAB TABLE
;VARIABLES AREA FOR CPU 0 CDB (ALSO DEFINED SYMBOLS FOR CPU 1)

;OLD NSWTBL GETTAB
;HAS SOME VARIABLES WHICH ARE SYSTEM RATHER THAN CPU DEPENDENT.
;HOWEVER FOR COMPATIBILITY, THEY ARE KEPT TOGETHER.
;.SYTBL HAS NEW SYSTEM VARIABLES DEFINED AFTER 5.03 RELEASE
XP NSWTBL,.-10		;GETTAB TABLE NO 12. VARIABLES PERTAINING
			; TO SWAPPING AND NON-SWAPPING SYSTEMS.
			; FIRST 10 LOCATION NO LONGER USED.
			;THE NUMBERS IN () ARE FOR NEW CPU DEPENDENT
			; GETTAB TABLE .GTC0V.

LOC==.			;START LOC AT ABS. BEG OF VARIABLE AREA
			; LOC USED IN V MACRO AS A LOCATION COUNTER
V	(VBG,CP0,CP1,,0) ;BEGINNING OF VARIABLE AREA FOR CPU 0

V	(,,,CORMAX);	;(0)(REALLY SYSTEM VAR.) MAXIMUM CORE REQUEST+1 (IE LARGEST REL. ADR,+1)
			; CAN BE RESTRICTED TO LESS THAN ALL OF USER CORE
			; BY BUILD AND/OR ONCE
V	(,,,CORLST);	;(1)(REALLY SYSTEM VAR.) 1 BIT BYTE POINTER TO LAST FREE
			; BLOCK POSSIBLE SET BY SYSINI ON 143 STARTUP
V	(,,,CORTAL);	;(2)(REALLY SYSTEM VAR.) TOTAL NUMBER OF
			; FREE+DORMANT+IDLE CORE BLKS LEFT
V	(,,,SHFWAT);	;(4)(REALLY SYSTEM VAR.) JOB NUMBER SHUFFLER
			 ;HAS TEMPORARILY STOPPED FOR ITS I/O DEVICES TO 
			; BECOME INACTIVE BEFORE SHUFFLING
V	(,,,HOLEF);	;(3)(REALLY SYSTEM VAR.) ABSOLUTE ADDRESS OF
			; LOWEST HOLE IN CORE, 0=NONE
V	(UPT,CP0,CP1,UPTIME);	;(5) UPTIME FOR THIS CPU. NO OF CLOCK TICKS
			; SINCE SYSTEM LOADED OR RESTARTED AT 143
V	(,,,SHFWRD);	;(6)(REALLY SYSTEM VAR.) TOTAL NUMBER OF WORDS
			; SHUFFLED BY SYSTEM
V	(,,,STUSER);	;(7)(REALLY SYSTEM VAR.) JOB CURRENTLY USING THE
			; SYSTEM TAPE NEEDED SO CONTROL C WILL NOT TIE
			; UP SYSTEM TAPE
V	(,,,HIGHJB);	;(10)(REALLY SYSTEM VAR.) HIGHEST JOB NUMBER 
			; CURRENTLY ASSIGNED
V	(,,,CLRWRD);	;(11)(REALLY SYSTEM VAR.) TOTAL NUMBER OF WORDS
			; CLEARED BY 'CLRCOR' RTN.
V	(LST,,,LSTWRD);	;(12)LOST TIME ON THIS CPU.  TOTAL NUMBER OF
			; CLOCK TICKS WHEN NULL JOB RAN BUT OTHER JOBS
			; WANTED TO RUN AND COULD NOT DO SO BECAUSE: ---
			;  1. SWAPPED OUT OR ON WAY IN OR OUT
			;  2. MONITOR WAITING FOR I/O TO STOP SO IT
			;     CAN SHUFFLE OR SWAP
			;  3. JOB BEING SWAPPED OUT BECAUSE IT IS
			;     EXPANDING CORE
V	(,,,MEMSIZ);	;(13)(REALLY SYSTEM VAR.) SIZE OF PHYSICAL MEMORY
			; IN WORDS (=FIRST NON EXIST WORD) SET BY SYSINI ON
			; 143 RESTARTS UNLESS SYMBOLS SAVED BY PATCHING
			; SYSLIM SMALLER.
V	(TPE);		;(14)TOTAL PARITY ERROR WORDS IN MEMORY DETECTED ON
			; DURING ALL CPU SWEEP WHILE PROCESSOR WAS IN EXEC OR USER MODE.  IF
			; SYSTEM HALTS, THIS LOC IS ALREADY UPDATED
V	(SPE);		;(15)TOTAL NON-REPRODUCING PARITY ERRORS IN MEMORY.
			; DETECTED ON THIS CPU.  IE ONES WHICH DID NOT
			; REOCCUR WHEN SAME CPU SWEPT THRU CORE.
			; CAN BE READ-PAUSE-WRITE WHICH REWRITES MEMORY
			; SO STILL A PARITY ERROR
			; OR CHANNEL DETECTED PARITY WHICH APR SWEEP DID
			; NOT FIND - SEE .CPPCS
V	(MPC,CP0,CP1);	;(16)MEMORY PARITY CONTINUES FOR THIS CPU.
			; COUNT OF NUMBER OF TIMES OPERATOR PUSHED CONTINUE
			; AFTER SERIOUS MEMORY PARITY HALT
			; LH = -1 IF SERIOUS ERROR ON THIS BAD PARITY (MUST HALT)
			; LH CLEARED ON CONTINUE OR STARTUP.
V	(MPA,CP0,CP1);	;(17)MEMORY PARITY ADDRESS FOR THIS CPU.
			; FIRST BAD PHYSICAL MEMORY ADDRESS FOUND WHEN
			; WHEN MONITOR SWEPT THRU CORE AFTER PROCESSOR
			; DETECTED FIRST BAD PARITY
V	(MPW,CP0,CP1);	;(20)MEMORY PARITY WORD FOR THIS CPU.
			; CONTENTS OF FIRST BAD WORD FOUND BY MONITOR WHEN
			; MONITOR SWEPT THRU CORE AFTER FIRST PARITY
V	(MPP,CP0,CP1);	;(21)MEMORY PARITY PC FOR THIS CPU.
			; PC OF LAST MEM PARITY (NOT COUNTING SWEEP THRU CORE)
V	(,,,EPOCNT);	;(22)(REALLY SYSTEM VAR)
			; # OF PDL OVF'S AT UUO LEVEL IN EXEC MODE NOT
			; RECOVERED
V	(,,,EPOREC);	;(23)(REALLY SYSTEM VAR) # OF PDL OVF'S AT
			; UUO LEVEL IN EXEC MODE RECOVERED
V	(,,,MAXMAX);	;(24)(REALLY SYSTEM VAR) HIGHEST LEGAL VALUE OF CORMAX
V	(,,,SYSKTM);	;(25)(REALLY SYSTEM VAR) COUNT-DOWN TIMER FOR SET
			; KSYS COMMAND
V	(,,,CORMIN);	;(26)(REALLY SYSTEM VAR) LOWER BOUND ON CORMAX,
			; LOKCON WILL NEVER ALLOW CORMAX TO BECOME
			; SMALLER THAN THE CONTENTS OF THIS LOCATION
V	(ABC,CP0,CP1);	;(27)ADDRESS BREAK COUNT ON THIS CPU.
V	(ABA,CP0,CP1);	;(30)ADDRESS BREAK ADDRESS ON THIS CPU.
			; STORAGE FOR DATA SWITCHES ON ADDRESS BREAK
			; INSERT NEW LOCATIONS HERE WHICH ARE OF INTEREST
			; TO USERS IN NON-SWAP AND SWAP SYSTEMS
V	(LJR);		;(31)LAST JOB RUN ON THIS CPU.  JOB IS COPIED
			; TO .CPLJR WHENEVER JOB IS CHANGED (INCLUDING TO 
			; NULL JOB) - FTTRACK COND.
V	(ODA,,,,3)	; OBSOLETE (MOVED TO RESPONSE SUBTABLE)
XP NSWMXL,<<LOC-NSWTBL-1>B26>	;MAX. NSWTBL ENTRY SHIFTED LEFT 9 BITS.
			; NEW ENTRIES ARE ADDED BEYOND END OF NSWTBL END.
			; SO NSWTBL IS NO LONGER ACTIVE.  INSTEAD
			; CPU DEPENDENT GETTAB .GTC0V SHOULD BE USED.
V	(STS,CP0,CP1,STOPTS);	;(35)STOP TIME SHARING ON THIS CPU.
			; CONTAINS JOB NO. WHICH DID TRPSET UUO.
V	(RUN,CP0,CP1);	;(36)OPERATOR CONTROLLED SCHEDULING FOR THIS CPU
			; AS SET BY PRIVILEGED .STRUN
			; FUNCTION OF SETUUO.  (SEE OPSER :SET RUN COMMAND).
			; SIGN BIT=0 MEANS RUN JOBS ON THIS CPU.
			; SIGN BIT=1 MEANS DO NOT RUN JOBS ON THIS CPU.
			; EXCEPT UUOS ON MASTER.  REST OF BITS
			; RESERVED FOR FUTURE SCHEDULING PARAMETERS.
			; RESET TO 0 ON 143 RESTART
V	(NUL);		;(37) CONTAINS THE NULL TIME FOR THIS CPU
			;IN JIFFIES
V	(EDI);		;(40) NO. OF EXEC. DON'T CARE
			; INTERRUPTS. IE USER ENABLED APR
			; INTERRUPTS WHICH MONITORS CAUSES (AOV,FOV)
			; LH = EXEC PC SO WE CAN FIX
			; INEFFICIENT CODE
V	(JOB,CP0,CP1,JOB);	;(41) CURRENT JOB ON THIS CPU. REFERENCED
			; AS BOTH .CPJOB(P4) AND JUST JOB THROUGHOUT MONITOR.
			;MAKE AVAILABLE FOR SNOOPY
V	(OHT);		;(42) CONTAINS THE OVERHEAD TIME
			; FOR THIS CPU IN JIFFIES.
			; INCLUDES CLOCK QUEUE PROCESSING, SHORT COMMAND PROCESSING,
			; SWAPPING & SCHEDULING DECISIONS, SOFTWARE CONTEXT SWITCHING
			; DOES NOT INCLUDE UUO EXECUTION
			; SINCE THAT IS NOT REALLY OVERHEAD
V	(EVM,CP0);	;(43) THE MAXIMUM AMOUNT OF EXEC VIRTUAL
			; ADDRESS SPACE ALLOWED TO BE USED FOR
			; MAPPING USER SEGMENTS IN EXEC MODE
			; BY THE LOCK UUO.

V	(EVU,CP0,CP1);	;(44) THE TOTAL AMOUNT OF EXEC VIRTUAL
			; ADDRESS SPACE CURRENTLY BEING USED
			; TO MAP USER SEGMENTS.
V	(LLC,CP0,CP1);	;(45) LOCK LOOP COUNT. NO. OF TIMES
			; THIS CPU HAS LOOPED
			; WAITING FOR OTHER CPU
V	(TUC,CP0,CP1);	;(46) TOTAL NO. OF UUOS FROM
			; EXEC AND USER MODE ON THIS CPU
			; SINCE SYSTEM WAS STARTED.
			; INCLUDES TRAPS TO 60 EXCEPT UJEN.
			; (DO NOT COUNT TRAPS ON CPU1 ON CPU0 ALSO)
V	(TJC);		;(47) TOTAL JOB CONTEXT-SWITCHES
			; COUNT FOR THIS CPU INCLUDING
			; NULLJOB SINCE SYSTEM WAS
			; STARTED. COUNT ONE EACH TIME
			; NEW JOB IS DIFFERENT FROM OLD ONE
V	(TNE)		;(50) TOTAL NXM'S THIS CPU
V	(SNE)		;(51) TOTAL NON-REPRODUCIBLE NXM'S THIS CPU
V	(NJA)		;(52) TOTAL JOBS CRASHED THIS NXM
V	(MNA,CP0,CP1)	;(53) FIRST ADDRESS FOUND WITH NXM
V	(EBJ,CP0,CP1);	;(54)EBOX TICKS/JIFFY (ONCE COMPUTED)
V	(MBJ,CP0,CP1);	;(55)MBOX TICK/JIFFY
V	(PBA,CP0,CP1);	;(56)PHYSICAL ADDR WITH BAD PARITY ON LAST AR/ARX
			;  PARITY TRAP
V	(TBD,CP0,CP1);	;(57)CONTENTS OF BAD WORD ON LAST AR/ARX
			;  PARITY TRAP
V	(TGD,CP0,CP1);	;(60)GOOD CONTENTS OF WORD AFTER WE RECOVERED
			; AR/ARX PARITY TRAP
V	(NPT,CP0,CP1);	;(61)TOTAL NUMBER OF AR/ARX PARITY TRAPS
V	(AER,CP0,CP1);	;(62)RESULTS OF RDERA ON STRANGE APR INT
V	(PEF,CP0,CP1);	;(63)RESULTS OF CONI APR, ON PARITY INT
V	(PSB,CP0,CP1,,4);	;(64-67)RESULTS OF SBDIAG'S ON PARITY INT
V	(PPC,CP0,CP1);	;(70)PC ON LAST AR/ARX PARITY TRAP
V	(PFW,CP0,CP1);	;(71)PAGE FAIL WORD ON LAST AR/ARX PARITY TRAP
V	(HPT);		;(72)NUMBER OF HARD AR/ARX PARITY TRAPS
V	(SPT);		;(73)NUMBER OF SOFT AR/ARX TRAPS
V	(PTP);		;(74)NUMBER OF PAGE TABLE PARITY TRAPS
V	(CSN);		;(75)NUMBER OF CACHE SWEEPS STARTED (CACHE SWEEP SERIAL NUMBER)
V	(CLN);		;(76)NUMBER OF TIMES SCHEDULER SKIPPED OVER A JOB BECAUSE CACHE
			; SWEEP HAD TO BE DONE FIRST
V	(CLT);		;(77)AMOUNT OF TIME IN JIFFIES THAT CPU RAN NULL JOB BECAUSE OF STATE OF CACHE
V	(CSD);		;(100)CACHE - SWAPPER DELAY COUNT-INCREMENT ON 1088
			; SYSTEMS IF SWAPPER HAS TO WAIT FOR ANOTHER CPU
			; TO SWEEP ITS CACHE BEFORE IT CAN START I/O
V	(CRN);		;(101)CACHE SWEEP REQUEST SWEEP COUNT (SIC)
			; COMMANDING THIS VALUE TO .CPCSD+.CPCLN (NUMBER
			; OF SWEEP REQUESTS MADE) WILL INDICATE TO WHAT EXTENT
			; THE REQUEST SCHEME IS A BOTTLENECK

V	(CEC,CP0,CP1);	;(102)COUNT OF NON-RECOVERABLE AR/ARX
			; PARITY ERRORS WHICH INVOLVED CACHE.  AFTER 3
			; SUCH FAILURES CACHE IS TURNED OFF IN TRAP
			; ROUTINE WITH APPROPRIATE MESSAGE TO OPERATOR.
V	(PTR,CP0,CP1);	;(103)RETRY WORD FOR AR/ARX PARITY TRAP
			; ROUTINE.  INCLUDES STATUS FLAGS IN LH AND
			; RETRY COUNT IN RH.
V	(TSD,CP0,CP1);	;(104)AR/ARX TRAP ROUTINE HAS ALREADY
			; SAVED APR.ERA.SB DIAGS ETC FOR ERROR REPORTING.
			; WON'T BE DONT AGAIN AT APR INTERRUPT
V	(REP,CP0,CP1);	;(105)USED BY PARITY/NXM RECOVERY ROUTINES
			; TO DETERMINE WHICH TYPE ERRORS SHOULD BE LISTED.
			; IF SWEEP IS AT APR LEVEL, CH7 LEVEL ALWAYS
			; REPORTED NXM ERROR REGARDLESS OF WHY THE SWEEP WAS DONE.

;**********************************************************************
;PUT NEW PUBLISHED VARIABLES ABOVE HERE
;**********************************************************************
;PUT NEW PUBLISHED SUB-TABLES BELOW HERE (SO LAST BUT STILL
;**********************************************************************
; INSIDE LEGAL RANGE OF VARIABLE GETTAB FOR THIS CDB
;**********************************************************************

;MORE RESPONSE DATA IN 4 WORD BLOCKS: SUM, NO. OF RESPONSES, SUM OF SQUARES
;THIS IS A CDB SUB-TABLE. IT IS CONDITIONALLY ASSEMBLED.
;USER PROGRAMS CAN ACCESS AFTER GETTING REL. POSITION FROM .CPRSP IN
; CPU CONSTANTS TABLE
IFN FTRSP,<			;RESPONSE FEATURE?
;INDICIES INTO 3 WORD BLOCKS:
XP RSPAXR,0			;ACCUMULATE SUM OF RESPONSE
XP RSPNXR,1			;NO. OF RESPONSES
XP RSPHXR,2			;SUM OF SQUARES OF RESPONSE(HIGH ORDER HALF)
XP RSPLXR,3			;SUM OF SQUARES OF RESPONSE(LOW ORDER HALF)
V	(AOR,CP0)		;(R0) ACCUMULATED TTY OUTPUT UUO RESPONSE.
				; TOTAL NO. OF JIFFIES USERS HAVE SPENT WAITING
				; FOR THEIR JOBS TO DO A TTY OUTPUT UUO
				; AFTER TYPING INPUT (COMMAND OR USER TTY)
				; SEE JBTRSP, RSPTOR - CPU0 ONLY
V	(NOR)			;(R1) NO. OF TTY OUTPUT UUO RESPONSES
V	(HOR)			;(R2) SUM OF SQUARES OF TTY OUTPUT UUO RESPONSES
				; HIGH ORDER WORD
V	(LOR)			;(R3) SUM OF SQUARES OF TTY OUTPUT UUO RESPONSES
				; LOW ORDER WORD

V	(AIR,CP0)		;(R4) ACCUMMULATED TTY INPUT UUO RESPONSES.
				; TOTAL NO. OF JIFFIES USERS SPENT WAITING
				; FOR THEIR JOBS TO DO A TTY INPUT UUO
				; AFTER TYPING INPUT (COMMAND OR USER TTY)
				; SEE JBTRSP, RSPTIR - CPU0 ONLY
V	(NIR)			;(R5) NO. OF TTY INPUT UUO RESPONSES
V	(HIR)			;(R6) SUM OF SQUARES OF TTY INPUT UUO RSPS
				; HIGH ORDER WORD
V	(LIR)			;(R7) SUM OF SQUARES OF TTY INPUT UUO RSPS
				; LOW ORDER WORD
V	(ARR)			;(R10) ACCUMMULATED CPU QUANTUM REQUE RESPONSES
				; TOTAL NO. OF JIFFIES USERS SPENT WAITING
				; FOR THEIR JOBS TO EXCEED CPU QUANTUM
				; AFTER TYPING INPUT (COMMAND OR USER TTY)
				; SEE JBTRSP, RSPREC - EITHER CPU
V	(NRR)			;(R11) NO. OF CPU QUANTUM REQUEUE RESPONSES
V	(HRR)			;(R12) SUM OF SQUARES OF CPU QUANT. REQUEUE RSPS
				; HIGH ORDER WORD
V	(LRR)			;(R13) SUM OF SQUARES OF CPU QUANT. REQUEUE RSPS
				; LOW ORDER WORD

V	(AXR)			;(R14) ACCUMMULATED RESPONSE TERMINATED BY
				; FIRST OF ABOVE 3 EVENTS (TTY OUTPUT
				; UUO, TTY INPUT UUO, OR CPU QUANTUM REQUE)
				; SEE JBTRSP, RSPREC
V	(NXR)			;(R15) NO. OF SUCH RESPONSES
V	(HXR)			;(R16) SUM OF SQUARES OF ANY OF ABOVE
				; HIGH ORDER WORD
V	(LXR)			;(R17) SUM OF SQUARES OF ANY OF ABOVE
				; LOW ORDER WORD

V	(ACR)			;(R20) ACCUMMULATED CPU RESPONSE
				; ON THIS CPU.  TOTAL # OF JIFFIES
				; USERS HAVE SPENT WAITING FOR THIS CPU
V	(NCR)			;(R21) NUMBER OF CPU RESPONSES ON THIS CPU.
V	(SCR)			;(R22) HIGH ORDER WORD OF SQUARE OF 
				; CPU RESPONSES
V	(SCL)			;(R23) LOW ORDER WORD
XP	.CPRSL,LOC-.C0AOR	;SUB-TABLE LENGTH
>				;END FTRSP

;THIS IS A CDB SUB-TABLE. IT IS CONDITIONALLY ASSEMBLED.
;USER PROG CAN BE ACCESS AFTER GETTING REL. POS	4LTITION FROM .CPPAR
; IN CPU CONSTANTS TABLE.
IFN FTMEMPAR,<			;MEMORY PARITY FEATURE?

;MORE MEMORY PARITY ANALYSIS LOCATIONS
V	(LPA);			;(R0) LAST (HIGHEST) BAD MEM PARITY ADDRESS ON LAST
				; SWEEP OF MEMORY. USED TO TELL OPERATOR RANGE OF BAD
V	(MPR);			;(R1) REL. ADR (NOT VIRTUAL) IN HIGH OR LOW SEG OF
				; LAST MEM PAR ERROR
V	(PTS);			;(R2) NO. OF PARITY ERROR THIS (LAST) SWEEP OF CORE
				; SET TO 0 AT BEG OF SWEEP
V	(PSC);			;(R3) NO. OF PARITY SWEEPS BY MONITOR
				; (CP.TPE HAS TOTAL NO. OF BAD WORDS ON ALL SWEEPS)
V	(UEP);			;(R4) NO. OF USER ENABLED PARITY ERRORS
V	(PAA);			;(R5) AND OF BAD ADDRESSES THIS (LAST) MEM PAR SWEEP
V	(PAC);			;(R6) AND OF BAD CONTENTS THIS (LAST) MEM PAR SWEEP
V	(POA);			;(R7) OR OF BAD ADDRESSES THIS (LAST) MEM PAR SWEEP
V	(POC);			;(R10) OR OF BAD CONTENTS THIS (LAST) MEM PAR SWEEP
V	(PCS);			;(R11) NO. OF SPURIOUS PARITY ERRORS (APR SWEEP
				; FOUND NO BAD PARITY BUT CHANNEL HAD REQUESTED
				; SWEEP RATHER THAN PROCESSOR. THIS INDICATES A
				; CHANNEL MEMORY PORT PROBLEM
	XP	.CPPRL,LOC-.C0LPA	;SUB-TABLE LENGTH

;THIS IS A CDB SUB-TABLE. IT IS CONDITIONALLY ASSEMBLED.
;USER PROG CAN ACCESS AFTER GETTING REL. POSITION FROM .CPPAR
; IN CPU CONSTANTS TABLE.

V	(BAT,,,,M.CBAT);	;(R0) TABLE OF BAD ADDRESSES ON LAST
				; MEMORY PARITY SWEEP. NOT
				; CLEARED, SO NUMBER OF VALID ENTRIES
				; KEPT IN .CPPTS (# PARITIES THIS SWEEP)
IFN FTMEMNXM,<
;MEMORY NXM SUBTABLE, POINTED
; TO BY .CPNMT
V	(LNA)			;(R0) LAST NXM ADDRESS
V	(MNR)			;(R1) LAST NXM RELATIVE ADDRESS
V	(NTS)			;(R2) NUMBER OF NXM'S FOUND THIS SWEEP
V	(NSC)			;(R3) NUMBER OF NXM SWEEPS DONE
V	(UEN)			;(R4) NUMBER OF USER ENABLED NXM'S
V	(NAA)			;(R5) LOGICAL AND OF BAD ADDRESSES
V	(NOA)			;(R6) INCLOSIVE OR OF BAD ADDRESSES
V	(NCS)			;(R7) NUMBER OF SPURIOUS CHANNEL NXM'S
XP	.CPNML,LOC-.C0LNA		;NXM SUBTABLE LENGTH
>;END FTMEMNXM
>	;END OF MEM PARITY DATA


;***********************************************************************
;INSERT NEW SUB TABLES JUST ABOVE HERE - SO AT END OF VARIABLE TABLE
;INSERT NEW VARIABLES A FEW PAGES BACK - SO NEXT TO OTHER VARIABLES
;***********************************************************************
XP .CPPVL,<<LOC-.C0VBG>B26>	;PUBLISHED CPU DEPENDANT VARIABLE LENGTH
				;SHIFTED LEFT 9 BITS FOR GETTAB TABLE ENTRIES
;UNPUBLISHED CPU DEPENDENT VARIABLES:
;PROTECTED JOB INFORMATION.  COPIED FROM JOB DATA AREA INTO MONITOR
; EACH TIME A JOB RUNS.
V	(,,,JOBDAT,0);	;LOC OF CURRENT JOBS JOB DATA AREA
			; SAVE AS JBTDAT AND AC R
V	(ADR,CP0,CP1,JOBADR);	;XWD PROTECTION, RELOCATION FOR CURRENT
			; JOB SAME AS JBTADR(JOB) AND AC R
V	(REL,CP0,,USRREL);	;LH==0, RH CONTAINS CONTENTS OF PROTECTION REGISTER
			; LOW ORDER BITS==1777,IE THIS IS HIGHEST REL.
			; LOC IN CURRENT USER AREA (USED FOR ADDRESS 
			; CHECKING)
V	(SAV,CP0,CP1,USRSAV);	;TEMPORARY FOR UUO HANDLER (IMPURE ROUTINE!)
IFE FTVM,<
V	(PRT,,,USRPRT,0);	;FIRST LOCATION OF PROTECTED JOB DATA
V	(EPL,,,USREPL);	;RH=EXEC CORE ADR. FOR EXTENDED PUSH DOWN LIST
			; CREATED WHEN MONITOR HAS A PDL OVF
			;RH=0 IF NO FREE CORE ASSIGNED
			; CORE IS RETURNED ON UUO RETURN TO USER,
			; CALL RESET CORE 0 OR KJOB UUO
V	(PR1,,,USRPR1,0);	;FIRST LOCATION+1
V	(HCU,,,USRHCU);	;HIGHEST USER I/O CHANNEL IN USE
			; 0 MEANS EITHER NONE OR CHANNEL 0 IN USE
			; LH=-1 DURING GET OF LOW OR HIGH SEG OR SAVE
			; OF HIGH SEGMENT, LH=-2 DURING SAVE OF LOW
			; SEGMENT AS FLAG THAT CORE IS COMPRESSED.  SETREL
			; ROUTINE DOESN'T STORE INTO JOBHRL (115)
			; WHEN THIS IS NEGATIVE.  ONLY CHANNEL ASSIGNMENTS
			; IN USE ARE COPIED INTO MONITOR WHEN JOB RUNS
>	;END IFE FTVM
V	(PC,CP0,CP1,USRPC);	;JOB PC WHEN SCHEDULER IS CALLED
IFE FTVM,<
V	(DDT,,,USRDDT);	;RH==STARTING ADDRESS OF USER DDT, LH UNUSED
V	(JDA,,,USRJDA,20);	;RH==JOB DEVICE ASSIGNMENTS (DDB ADDRESSES)
			; LH==UUO'S DONE SO FAR FOR THIS CHANNEL (SEE S.MAC)
			; 0 MEANS NO DEVICE INITIALIZED ON THIS CHANNEL
>	;END IFE FTVM
IFN FTVM,<
XP USRPRT,JOBPRT##+.JDAT
XP USRPR1,JOBPR1##+.JDAT
XP USRHCU,JOBHCU##+.JDAT
XP USRPC,JOBPC##+.JDAT
XP USRDDT,USRPC+1	;THIS DEPENDS ON JOBDDT-JOBPC=1
XP USRJDA,JOBJDA##+.JDAT
>	;END IFN FTVM
XP USRLO,USRJDA	;FIR LOC CLEARED BY SETUSR ROUTINE
			; ON A CALL RESET. - ALSO CLEARS USRHCU
XP USRLO1,USRLO+1	;FIRST LOC+1
XP USRHI,USRJDA+17	;LAST LOC CLEARED BY SETUSR ROUTINE
V	(XTM);		;TIME OF LAST SWITCH FROM MONITOR CYCLE TO USER JOB
			; OR VICE VERSA IN (SECONDS*RTCSEC)
V	(LS2);		;ADDITIONAL LOST TIME, IN JIFFIES*RTCSEC, BEYOND LAST JIFFY
V	(NL2);		;ADDITIONAL NULL TIME, IN JIFFIES*RTCSEC, BEYOND LAST JIFFY
V	(OH2);		;ADDITIONAL OVERHEAD TIME, IN JIFFIES*RTCSEC,
			; BEYOND LAST JIFFY--SEE OHT ABOVE (53)
;SCHEDULER FLAGS:
V	(CKF,CP0,CP1,CLKFLG);	;NON-ZERO WHEN CLK INTERRUPT (PI7) REQUESTED
			; FOR ANY REASON ON THIS CPU.  THIS LOCATION
			; TAKES THE PLACE OF A HARDWARE INTERRUPT
			; FLAG ON PDP-6 AND KA10S.
V	(TMF,CP0,CP1,TIMEF);	;NON-ZERO WHEN APR CLOCK TICKED ON THIS CPU.
			; SET SO CLK INTERRUPT ROUTINES WILL KNOW
			; ANOTHER JIFFY HAS PASTED.  SET BY APRINT,
			; TESTED AND CLEARED BY CLKINT MODULE.
V	(SCF,CP0,CP1);	;NON-ZERO AS A FLAG TO CLK ROUTINE TO FORCE
			; RESCHEDULING, ON THIS CPU, EVEN THOUGH
			; ITS CURRENT JOB IS IN EXEC MODE.  CAN HAPPEN
			; ON MONITOR DETECTED ERRORS.


V	(RTF,CP0,CP1);	;NON-ZERO ON REAL TIME RESCHEDULE REQUIRED
			; ON THIS CPU.
IFN FTVM!FTMS,<
V	(ISF,CP0,CP1)	;NON-ZERO IF IN THE SCHEDULAR
>
V	(SUD);		;SCAN USED FOR THIS SCHEDULING SCAN
IFN FTHPQ!FTNSCHED,<
V	(HQU,CP0)	;NON-ZERO IF CURRENT JOB ON THIS CPU DID A HPQ UUO
			;OR A SCHED. UUO TO CHANGE HIS CLASS
			; TO FORCE RESCHEDULING TO THE NEW Q
>
V	(PLT);		;POTENTIALLY LOST (WASTED) CLOCK TICK ON
			; THIS CPU IF NON-ZERO.
			;NON-ZERO WHEN SCHEDULER SEES THAT THERE ARE
			; JOBS WHICH ARE POTENTIALLY RUNABLE ON THIS CPU
			; BUT HAS TO RUN NULL JOB.
			;0 WHEN IT FINDS A REAL JOB TO RUN OR
			; NULL JOB IS ONLY JOB WHICH WANTS TO RUN ON THIS CPU.
			; .CPLST INCREMENTED EVERY JIFFY IF THIS FLAG
			; IS NON-ZERO AND PREVIOUS JOB WAS NULL JOB.
IFN FTKL10&FTMS,<
V	(CLF);		;POTENTIAL CACHE LOST TIME FLAG (SEE .CPCLN)
V	(CL2);		;LOW ORDER CACHE LOST TIME IN RTUPS UNITS
V	(CSR);		;CACHE SWEEP REQUEST FLAG FOR THISCPU
			; IF IT IS .GE. CURRENT SWEEP SERIAL NUMBER FOR 
			; THIS CPU, MUST SWEEP AT CH7 LEVEL FOR ANOTHER CPU
>;END IFN FTKL10&FTMS
V	(AEF,CP0,CP1);	;APR ERROR FLAG ON THIS CPU.  CONTAINS APR
			; CONI IF NULL JOB WAS CURRENT JOB ON THIS
			; CPU WHEN APR ERROR OCCURRED SO COULD NOT
			; STORE IN JOB DATA AREA.
			; LEFT HALF USED FOR MEMORY PARITY CONTROL
			; TO REQUEST PARITY SWEEPS AND PRINTING. SEE .CPMPS FOR
			; BIT DEFINITIONS.
V	(SAC);		;SAVED COPY OF .CPAEF
V	(APC,CP0,CP1);	;APR ERROR PC ON THIS CPU WHEN ERROR WHILE
			; NULL JOB WAS CURRENT JOB ON THIS CPU.
V	(NJE,CP0);	;ERROR IN NULL JOB HAS OCCURRED IF NON-ZERO
V	(PUC,CP0,CP1);		;PENDING UUO COUNT ON THIS CPU.
			; NO. OF JOBS WHICH HAVE DONE A UUO
			; BUT NEED TO BE RUN ON OTHER CPU.
V	(LJU,CP0,CP1);	;LAST JOB WHICH DID UUO ON THIS CPU.
			; SAVES SCAN TIME
V	(UFC);		;UUO FAIRNESS COUNT. THE NUMBER OF SLAVE UUOS
			;THAT HAVE BEEN DONE WITHOUT DOING A MASTER UUO.
			;IF COUNT EXCEEDS MAX THEN DO A NORMAL SCHEDULE
V	(SFC);		;SCHEDULER FAIRNESS COUNT. COUNT OF THE NUMBER
			;OF SCANS OF THE PRIMARY SCAN TABLE WITHOUT GETTING
			;TO THE LOWER QUEUES IN THE TABLE.  IF THE COUNT
			;EXCEEDS THE MAXIMUM, THE SCAN USES THE SECONDARY TABLE

V	(SQF);		;NON-ZERO IF CURRENT JOB WAS TAKEN FROM SUBQUEUES
IFN FTKL10,<
V	(IPI,CP0,CP1);	;INTERVAL TIMER PI ASSIGNMENT ON KL10
>

;PROCESSOR DEPENDENT (KA10) VARIABLES FOR APR INTERRUPTS

V	(CN1,CP0,CP1);	;CONTAINS CONSO MASK FOR APR INTERRUPTS,
			; THE USER WANTS TO HANDLE HIMSELF.  MOVE TO
			; PDB IN FUTURE.
V	(DTO,CP0,CP1,KT10A);	;LAST DATAO OUT TO SET HARDWARE RELOCATION
			; AND PROTECTION FOR THIS CPU.
V	(LUC,CP0,CP1);	;LAST USER CONO TO APR FOR A NON-REAL TIME JOB
			; USED TO RESTORE APR AFTER A REAL TIME TRAP.
V	(SCD,CP0,CP1);	;SCHEDULER INTERLOCK LEVEL
			;USED BY CPLOCK AND CPUNLK MACROS
V	(SP,CP0,CP1);	;PLACE TO SAVE P ON APR INTERRUPT FOR THIS CPU.
V	(S17,CP0,CP1);	;PLACE TO SAVE AC 17 ON CLK INTERRUPT

;MEMORY PARITY ANALYSIS VARIABLES
IFN FTMEMPAR,<			;MEMORY PARITY ANALYSIS
V	(A00,,,,17);		;FIRST WORD TO STORE AC0 ON
				; PAR SWEEP ON APR PI (USUALLY NOT
				; DONE EXCEPT FOR SERIOUS ERROR)
V	(A17);			;LAST WORD TO STORE AC17 ON
				; PAR SWEEP AT APR PI.
V	(LPP);			;LAST MEM PARITY PC - USED TO DETECT
				; PI DISMISS LOOPS. CLEARED AT END
				; OF PI 7 SWEEP OF MEMORY
V	(LSB,CP0);		;LAST SEG (HI OR LOW) WHICH IS (WAS) BLTED
				; USED TO DETECT BAD PARITY DURING BLT

>				;END FTMEMPAR - MEM PAR ANALYSIS
DBLLOC==LOC-.C0CDB		;REMEMBER REL LOC OF DOORBELL - SO CAN FORWARD REF

V	(DBL,CP0,CP1);		;DOORBELL CPU0 SETS .C1DBL
				; TO WAKE UP CPU1 AND VICE VERSA
IFN M.KL10,<
V	(TCT,CP0,CP1);		;TRIAD COUNTER FOR 60HZ LEAP JIFFIES
V	(PJB,CP0,CP1);		;# OF JOB WHO OWNS PERFORMANCE METER
				; 0 IF FREE
V	(MJB,CP0,CP1);		;MEASURED JOB (JOB ENABLE OF PERF. UUO)
				; -2 = NULL JOB, 0 = DON'T CARE
V	(MJ1,CP0,CP1);		;JOB ENABLE CONDITION SET ONLY WHEN
				; METER IS RUNNING. (SEE KLSER)
V	(PMR,CP0,CP1);		;NONZERO MEANS PERFORMANCE METER IS
				; RUNNING.
V	(PAE,CP0,CP1);		;USED TO STORE PERFORMANCE ANALYSIS
				; ENABLES
V	(PRQ,CP0,CP1);		;SEMAPHORE USED IN TESTING AND GIVING
				; METER AWAY
V	(APS,CP0,CP1);		;NON ZERO MEANS ACCT + PERF METERS SHOULD BE KEPT IN SYNC
V	(MM0);			;"VIRTUAL PERF METER'S" HIGH ORDER MEM REF COUNT
V	(MM1);			;LOW ORDER
V	(TIM,CP0,CP1);		;CLOCK INTERRUPT FLAG FOR KL10S
;LOCATIONS USED BY CPU HARDWARE ERROR RECOVERY
V	(PSP,CP0,CP1);		;PARITY/NXM SWEEP IN PROGRESS ON THIS CPU
V	(PTH,CP0,CP1);		;AR/ARX TRAP HAPPENED DURING PARITY SWEEP
V	(PTF,CP0,CP1);		;COUNT OF PAGE TABLE PARITY TRAPS BETWEEN CLOCK
				;  TICKS--USED TO CRASH SYSTEM IF TO HIGH
				;  REINITIALIZED EVERY JIFFY
V	(PWF,,,,60);		;POWER FAIL SAVE AREAS
>;END IFN M.KL10
;END OF VARIABLES FOR CDBS.  ADD MORE HERE

.CPVLN==LOC-.C0VBG	;LENGTH OF VARIABLE AREA
	INTERN .C0VAR,.C0EVA
.C0VAR:	BLOCK	.CPVLN		;ALLOCATE SPACE FOR VARIABLE AREA
.C0EVA==,.-1		;END OF VARIABLE AREA CLEARED BY SLVINI
.CPLEN==.-.C0CDB		;LENGTH OF CDB FOR CPU 0

;NOW GENERATE CDB 1
;ALWAYS GENERATE ABSOLUTE SYMBOL AS EITHER INTERN OR LOCAL
;LOCAL IF NOT USED EXCEPT FOR DEBUGGING WITH DDT

IFG <CPUN-1>,<

	DEFINE C(XXX,ABS0,ABS1,CONST0,CONST1)<
	IFIDN <ABS1> <CP1>,<INTERN .C1'XXX> ;INTERN IF USED
	.C1'XXX: CONST1	;ABS SYMBOL AND THE CONSTANT.

	XP .CP'XXX,.-1-.C1CDB>	;RELATIVE SYMBOL FOR INDEXING WITH P4

.C1CDB:	CDBCON (1)		;GENERATE CONSTANTS FOR CPU 1
SCRASH=.C1CAC
PI1STS=.C1CPI
	BLOCK .CPVLN	;ALLOCATE SPACE FOR CPU 1 VARIABLES
.C1DBL==.C1CDB+DBLLOC		;DEFINE DOORBELL ON PASS 1 SO .C0RDB CAN
				; FORWARD REFERENCE TO IT ON PASS 2
>		;END IFG CPUN-1

;NOW GENERATE REFERENCES FOR GETTAB TABLES 55 THRU 70
;WILL GENERATE A ZERO WORD FOR INDIRECT REFERENCES TO NON EXISTANT CDB'S
DEFINE CPUGTB(A,B)<
IFG <CPUN-A>,<XP ITMC'B'C,.CPPCL
	XP ITMC'B'V,.CPPVL>
IFLE <CPUN-A>,<XP ITMC'B'C,0	;MAKE LENGTH 0 SO ERROR RETURN
	XP ITMC'B'V,0		;MAKE LENGTH 0 SO ERROR RETURN
	INTERN	.C'B'CDB,.C'B'VBG
	.C'B'CDB:		;DEFINE ADR TO BE A WORD CONTAINING 0.
	.C'B'VBG:
>>
ZZ==0
REPEAT 6,<
	CPUGTB(ZZ,\ZZ)
ZZ==ZZ+1
>
IFLE <CPUN-5>,<EXP 0>		;GETTABS FOR NON-EXISTANT CDB'S GET THEIR DATA HERE
;SYSTEM WIDE VARIABLES:
; CLEARED AT SYSTEM STARTUP

;GETTAB FOR SYSTEM WIDE VARIABLES (AS OPPOSED TO PER CPU DATA)
; GETTAB TABLE NO(RH) IS .GTSYS=51

	INTERN SYSTBL,SYSERR,CMNOTF

SYSTBL:			;GETTAB TABLE NO. 51.  ( .GTSYS = 51
SYSERR:	0		;(0) TOTAL NUMBER OF HARDWARE AND SOFTWARE ERRORS
			; DETECTED BY THE MONITOR AND ENTERED IN DAEMON
			; ERROR LOG FILE INCLUDING DAEMON ERRORS.
			; INCLUDES HARD AND SOFT ERRORS
			; HARD ERROR WITH 80 RETRIES ONLY COUNTS AS 1 ERROR IN SYSERR.
CMNOTF:	0		;(1) NUMBER OF TIMES SCNSER WAS CALLED TO
			; FIND A COMMAND BECAUSE COMCNT WAS
			; NON-ZERO AND NO COMMAND WAS FOUND
DELCNT::0		; (2) DISABLED ERROR LOGGING COUNT
			; INCREMENT INSTEAD OF SYSERR IF USER HAS DISABLED
			; ERROR LOGGING IN OPEN UUO
%SYSPC::0		;(3) LH = THREE LETTER SIXBIT CODE OF LAST STOPCD
			;    RH = ADDRESS + 1 OF LAST STOPCD
%SYNDS::0		;(4) NUMBER OF DEBUG STOPCD'S.
%SYNJS::0		;(5) NUMBER OF STOPCD'S WHICH CAUSED A JOB TO BE
			;    STOPED.
COMTOT::0		;(6) NUMBER OF COMMANDS PROCESSED
			; (DELAYED COMMANDS ARE COUNTED ONCE WHEN PROCESSED)

%SYSJN::0		;(7)JOB# OF JOB ON LAST STOPCD
%SYSTN::0		;(10)TTY NAME FOR LAST STOPCD
%SYSPN::0		;(11)PROGRAM NAME FOR LAST STOPCD
%SYSUU::0		;(12)UUO ON LAST STOPCD
%SYSUP::0		;(13)USER'S PC ON LAST STOPCD
%SYSPP::0		;(14)USER'S PPN ON LAST STOPCD
XP SYSMXL,<<.-SYSTBL-1>B26>	;MAX. ENTRY



;UNPUBLISHED SYSTEM VARIABLES:




;OTHER SYSTEM DATA STORAGE

	INTERNAL COMCNT,NFCNT,HNGMIN
	INTERNAL FTTRPSET,FTSLEEP,FTTIME,FTSWAP,FT2REL,FTDISK
	INTERNAL HNGTIM,CIPWT,CIPWTM

COMCNT:	0			;NUMBER OF COMMANDS TYPED-IN BUT NOT DECODED
				;SET BY SCNSER, DECREMENTED BY COMCON
IFN FTMS,<
COMJOB::0			;JOB NUMBER OF JOB CURRENTLY EXECUTING
				; A COMMAND USED TO AVOID JOBSTS UUO RACE
>
NFCNT:	0			;COUNT OF TIMES COMCNT NON-ZERO,
				;BUT NO WAITING COMMANDS
HNGTIM:	0			;HUNG DEVICE TIME COUNT CHECK FOR HUNG I/O
				;DEVICES WHEN THIS GOES NEGATIVE (ONCE PER HNGSEC)
HNGMIN:	0			;DO ONCE PER MINUTE FUNCTIONS WHEN THIS
				;FLAG COUNTS NEGATIVE
				; SCHEDULER SCANS ALL JOBS EVERY
				; MINUTE TO SEE IF QJOB HAS BEEN COUNTED
				; DOWN TOO FAR.  MORE LIKELY IN DUAL CPU SYS.

	SLJOBN=0		;NUMBER OF JOBS IF NO SLEEP FEATURE
	IFN	FTSLEEP, <SLJOBN=JOBN>	;LEAVE ONE ENTRY PER JOB
CIPWT:	BLOCK	2*SLJOBN+3	;CLOCK REQUEST QUEUE
				; LH-MONITOR ADDRESS TO PUSHJ TO AT CLOCK LEVEL
				; WHEN BITS 24-35 COUNT DOWN TO ZERO
				; BITS 18-23 ARE DATA SET IN AC T1 WHEN PUSHJ DONE
				; BITS 24-35 ARE NUMBER OF CLK TICKS LEFT TO GO
	CIPWTM==CIPWT-1		;FIRST LOC-1 OF CLOCK QUEUE

CHKCNT::0			;NO. OF CALLS TO CHKTAL TO CHECK CORE
				; BEFORE ACTUALLY DOING THE OVERHEAD.
				; RESET TO M.CMCT WHEN COUNTS TO 0.

TIMINT::0			;TIME INTERVAL (IN TICKS) SINCE LAST TIME AT
				; CLOCK LEVEL (TIME-TIMLST)

DATREM::0			;LAST REMAINDER IN UPDATING "DATE" (SMITHSONIAN DATE)

SCDTIM::0			;TIME (IN TICKS) OF NEXT MICRO
				;SCHEDULING INTERVAL

;STORAGE FOR VARIOUS CORE ALLOCATION FUNCTIONS AND OTHER NON-SWAPPING DATA

	INTERN	CORTAB,FTTRACK,HOLES,FTLOCK

IFN M.KA10,<XP	PAGSIZ,2000	;BASIC UNIT OF CORE IN WORDS>
IFN M.KI10!M.KL10,<XP	PAGSIZ,1000>

	XP	PG.BDY,PAGSIZ-1	;MASK TO MAKE CORE REQUEST AN EVEN MULTIPLE
				;OF THE BASIC UNIT MINUS ONE
	XP	MPGSIZ,-PAGSIZ
IFN M.KA10,<XP	P2WLSH,12	;SHIFT AMOUNT TO CONVERT # OF PAGES TO
				;# OF WORDS>
IFN M.KI10!M.KL10,<XP	P2WLSH,11>
	XP	W2PLSH,-P2WLSH	;SHIFT AMOUNT TO CONVERT # OF WORDS TO #
				;PAGES
	XP	K2WLSH,12	;SHIFT AMOUNT TO CONVERT # OF K TO # OF WORDS
	XP	W2KLSH,-12	;SHIFT AMOUNT TO CONVERT # OF WORDS TO # OF K
IFN M.KA10,<XP	CRSIZ,8		;SIZE OF BYTE TO GET # OF PAGES-1 IN LOW OR HIGH SEG.
	XP	CRPOS,7		;POSITION OF BYTE>
IFN M.KI10!M.KL10,<XP	CRSIZ,9
	XP	CRPOS,8>
IFN M.KA10,<XP P2KLSH,0>	;SHIFT AMOUNT TO CONVERT # OF PAGES TO # OF K
IFN M.KI10!M.KL10,<XP P2KLSH,-1>
IFN M.KA10,<XP K2PLSH,0>	;SHIFT AMOUNT TO CONVERT # OF K TO # OF PAGES
IFN M.KI10!M.KL10,<XP K2PLSH,1>
XP BLKSPP,BLKSPK-K2PLSH		;SHIFT AMOUNT TO CALCULATE # OF BLOCKS/PAGE
XP PP256K,^D512/<<PAGSIZ>_-^D9>



;CORE ALLOCATION DATA NOT AVAILABLE VIA GETTAB
IFN FTTRACK, <INTERNAL LASCOR	; (FOR DEBUGGING ONLY)
LASCOR:	0			;LAST JOB OR HIGH SEG TO CALL CORE ROUTINES
>
			; BEFORE HALT.  USED TO DETECT SWEEP THRU CORE
;CALCULATE MOD(CORBLK,CTNBPW)

	XP	CORBLK,<^D256*^D1024>/PAGSIZ	;NUMBER OF BYTES IN CORTAB
	XP	COR256,CORBLK			;NUMBER OF PAGES (K) IN 256K

IFN M.KI10!M.KL10,<IFN FT22BIT,<
XP CORBLK,<^D16*CORBLK>
>>
RZ==0
Z1==CORBLK
Z2==CTNBPW
Z1==Z1-IFN Z2,<Z2*<Z1/Z2>>
IFN Z1,<RZ==1>
IFN M.KI10!M.KL10,<
CORTAB:	BLOCK	0
>
IFN M.KA10,<

CORTAB:	BLOCK	CORBLK/CTNBPW+RZ
>
	INTERNAL CTBMXL
CTBMXL==<.-CORTAB-1>B26		;MAXIMUM ENTRY FOR GETTAB SHIFTED LEFT 9

HOLES:	0			;SIZE OF THE LOWEST HOLE IN MEMORY

IFN FTLOCK,<
INTERNAL LOCK,LOKREL,CORMIN,LASLOK
LOCK:	0			;JOB#,,HIGH SEGMENT# OR
				;0,,JOB# IF NO HIGH SEGMENT
				;OF JOB CURRENTLY BEING LOCKED IN CORE

LOKREL:	0			;DESIRED PROTECTION,,RELOCATION
				;FOR JOB CURRENTLY BEING LOCKED
LASLOK:	0			;JOB # OF LAST JOB LOCKED

IFN SYS50N,<
INTERNAL HOLEF1,HOLTOP
HOLEF1:	0			;ADDRESS OF THE BOTTOM OF THE LARGEST CONTIGIOUS HOLE
				;THAT CAN BE MADE IN CORE IF EVERYTHING
				;SWAPPABLE IS SWAPPED
				;(INITIALIZED TO SYSSIZ ON 143 RESTART)

IFN LOKN,<
HOLTOP:	0			;ADDRESS+1 OF THE TOP OF THE ABOVE HOLE
				;(INITIALIZED TO MEMSIZ ON 143 RESTART)
>
IFE LOKN,<HOLTOP==MAXMAX>
>
>

IFN <M.KI10!M.KL10>&<FTMONL!FTMOFFL>,<
MOFLPG::0			;FLAG FOR SETTING MEMORY ON OR OFF LINE
>
IFN FTMS,<
RESOUR::0			;COUNT OF THE NUMBER OF JOBS WAITING
				; FOR A SHARABLE RESOURCE
>
;DATA LOCATIONS PRESENT ONLY IN SWAPPING SYSTEMS

	IFG	SYS50N, <	;SWAPPING SYSTEM ?
	INTERNAL SWPTBL,SWPMXL,BIGHOL,FINISH,FORCE,FIT,SWPERC,VIRTAL
	INTERNAL MAXJBN,SUMCOR

SWPTBL:!			;FIRST LOCATION OF MONITOR DATA STORAGE
				; RETURNED BY GETTAB UUO (THESE LOCATIONS
				; PRESENT ONLY IN SWAP SYSTEMS)
				; OCTAL NUMBERS IN () CORRESPOND TO GETTAB ARG
				;THIS IS DOCUMENTED AS GETTAB TABLE NUMBER 13
BIGHOL:	0			;(0) CURRENT BIGGEST HOLE IN CORE (1K BLOCKS)
FINISH:	0			;(1) IF +, THEN JOB NUMBER OF JOB BEING SWAPPED IN,
				;IF -, THEN JOB NUMBER OF JOB BEING SWAPPED OUT
FORCE:	0			;(2) JOB NUMBER BEING FORCED TO SWAP OUT
FIT:	0			;(3) JOB NUMBER WAITING TO BE FITTED INTO CORE
VIRTAL:	0			;(4) NUMBER OF FREE 1K BLOCKS OF SWAPPING SPACE LEFT
				; (COUNTING DORMANT SEGMENTS AS IF FREE).
				; PRINTED WITH CORE COMMAND (NO ARG) OR ERROR
				; USUALLY THE SAME AS THE AMOUNT OF VIRTUAL CORE
				; LEFT IN SYSTEM, EXCEPT WHILE R,RUN,KJOB,GET
				; COMMAND ARE WAITING TO BE SWAPPED IN, BECAUSE
				; THE OLD DISK SPACE HAS NOT BEEN RETURNED YET,
				; BUT VIRTUAL CORE IS ONLY 140 WORDS FOR SWAPIN
SWPERC:	0			;(5) LH= NUMBER OF SWAPPER READ OR WRITE FAILURES
				; RH= ERROR BITS (BITS 18-23) + NUMBER OF K OF
				; IOCHNX=IO CHANNEL SWAP NON-EX MEM - BIT 23
				; IOCHMP=IO CHANNEL SWAP OUT MEMORY PARITY - BIT 22
				; BITS 18-22 = IOIMPM (SOFTWARE CHECKSUM),
				; IODERR, IODTER, IOBKTL
				; DISCARDED SWAPPING SPACE
SWAPIN::0			;(6) IF THE SYSTEM HAS FTPDBS TURNED ON,
				;     THIS WORD IS -1 WHEN A SWAPIN IS
				;     IN PROGRESS AND ZERO WHEN A SWAP OUT
				;     IS IN PROGRESS. IF FINISH IS ZERO
				;     THEN NO SWAP IS IN PROGRESS. IF FTPDBS
				;     IS OFF THIS WORD IS ALWAYS ZERO.



				;INSERT NEW LOCATIONS HERE WHICH ARE OF INTEREST
				; TO USER PROGS IN SWAPPING SYSTEMS
SWPMXL==<.-SWPTBL-1>B26	;MAXIMUM ENTRY FOR GETTAB SHIFTED LEFT 9
;MORE SWAPPING SYSTEM LOCATIONS (NOT RETURNED BY GETTAB)

MAXJBN:	0			;NUMBER OF JOB TO SWAP OUT
SUMCOR:	0			;TEMPORARY STORAGE CELL USED BY SWAPPER FOR SUM OF
				; CORE NEEDED FOR SWAP IN
FITLOW::0			;NUMBER OF JOB BEING FIT (NEVER HI-SEG)
IFN FT2REL, <
	INTERNAL SWPIN,SWPOUT
SWPIN:	0			;JOB NUMBER BEING SWAPPED IN IF IT HAS A HIGH SEG
SWPOUT:	0			;JOB NUMBER BEING SWAPPED OUT IF IT HAS A HIGH SEG
				; (USED TO REMEMBER THE JOB NUMBER DURING HIGH SEG SWAP)
>
	INTERNAL FTTRACK
IFN FTTRACK, <			;ONLY FOR DEBUGGING
	INTERNAL LASIN,LASOUT
LASIN:	0			;LAST JOB OR HIGH SEG SWAPPED IN
LASOUT:	0			;LAST JOB OR HIGH SEG SWAPPED OUT
>


IFN FTRSP,<
SWPNU2::0			;JIFFY REMAINDER FOR SWAP NULL TIME
SWPLS2::0			;JIFFY REMAINDER FOR SWAP LOST TIME
SWPPLT::0			;POTENTIAL LOST TIME FLAG FOR SWAPPER
				;TO TELL CLOCK1 TO COUNT SOME LOST TIME
				;(HAVE JOB TO SWAP IN BUT SWAPPER IDLE)
SWPNUF::0			;NULL CYCLE FOR SWAPPER (AGAIN, SO CLOCK1
				;CAN COUNT NULL TIME FOR SWAPPER)
>;END IFN FTRSP

IFN FTNSCHED,<
SCDSTS::0			;TIME OF LAST SETTING OF PRIMARY PERCENTAGES
CNTSTS::0			;COUNT OF CPU CLASSES WITH NON-ZERO QUOTA
TOTSTS::0			;TOTAL OF ALL SUBCLASS PERCENTAGES
				;MUST BE EITHER 100% OR ZERO
MAXQTA::0			;NUMBER OF HIGHEST CLASS WITH A SECONDARY QUOTA
CNTQTA::0			;COUNT OF CLASSES WITH NON-ZERO SECONDARY QUOTAS
TOTQTA::0			;TOTAL OF ALL SECONDARY SUBCLASS PERCENTAGES
				;NOMINALLY 100% BUT CAN BE ANY NON-NEGATIVE #
>;END OF IFN FTNSCHED
>;END OF IFG SYS50N


IFN FTNSCHED,<
;TABLES INDEXED BY CLASS NUMBER

CLSSTS::BLOCK	M.CLSN		;BITS IN LH, QUOTA (NUMBER FROM 0 TO 100) IN RH

CLSQTA::BLOCK	M.CLSN		;SECONDARY CLASS QUOTAS (ZERO FOR FIXED QUOTA)
				;USED FOR SCHEDULING AND SWAPPING IF THE
				;PRIMARY CLASS IS NOT THERE

CLSRTM::BLOCK	M.CLSN		;RUNTIME FOR CLASSES SINCE ANY CHANGE IN CLSSTS
				;(PQ2 TIME ONLY)

CLSMXL==:<M.CLSN-1>B26		;MAXIMUM LENGTH OF PER CLASS TABLES FOR GETTAB
>;END IFN FTNSCHED
SUBTTL MONITOR TABLES WITH ONE ENTRY PER JOB

	INTERNAL JBTSTS,JBTSPS,JBTADR,JBTDAT,JBTSGN,JBTNAM,JBTPRG
	INTERNAL JOBMAX,JBTMAX,MJBTMX,MJOBN,JBTAD1,JOBMXL,JBTMXL
	INTERNAL FTTIME,FTKCT,FTPRV,JBTST2

	JOBMAX==JOBN-1		;MAXIMUM LEGAL JOB NUMBER
	JOBMXL==<JOBMAX>B26	;HIGHEST JOB NUMBERSHIFTED LEFT 9 (FOR GETTAB UUO)
	MJOBN==-JOBN		;NEGATIVE NUMBERS OF JOBS (COUNTING NULL JOB)
	JBTMAX==JOBN+SEGN-1	;HIGHEST INDEX IN JBT TABLES
	MJBTMX==-JBTMAX		;MINUS JBTMAX FOR AOBJN POINTER
	JBTMXL==<JBTMAX>B26	;HIGHEST JBT ENTRY SHIFTED LEFT 9 (FOR GETTAB UUO)
JBTSTS:	BLOCK	JOBN+SEGN	;JOB AND HIGH SEG STATUS WORD
				;THIS IS DOCEMENTED AS GETTAB TABLE NUMBER 0
				;LH==STATUS BITS (SEE S.MAC FOR DESCRIPTION)
				;BITS 18-23=EXTENDED JOB STATUS BITS
	JBSSPR==^D9			;SIZE OF ACCES PRIV FOR HIGH SEG
	JBNSPR==^D17			;BYTE PTR. POS.
				;RH=IN CORE COUNT FOR HIGH SEGS

JBTST2::BLOCK	JOBN		;SECOND WORD OF JOB STATUS. USED BY SCHEDULER
				;  AND EVENT WAIT INFO

IFN M.KL10*<CPUN-1>,<;IF KL10 SYSTEM WITH MORE THAN ONE CPU
JBTST3::BLOCK	JOBN		;18-35 = CPU DATA BLOCK ADDR OF LAST
				; CPU JOB RAN ON.  CLEARED WHEN
				; JOB GIVES UP ALL PHYSICAL CORE, OR
				; DOES RUN, GET, ETC.

JBTCSN::BLOCK	JOBN		;36 BIT SWEEP SERIAL NUMBER, TAKEN FROM
				; CPU WHOSE CDB ADDRESS IS IN JBTST3
>;END IFN M.KL10*<CPUN-1>

IFN FTNSCHED,<
JBTSCD::BLOCK	JOBN		;SCHEDULER WORD CONTAINING EACH JOB'S 
				;CLASS AND TYPE.
>;END IFN FTNSCHED

JBTSPS:	IFG	<CPUN-1>,<	;MULTI-PROCESSING SYSTEM?
	BLOCK	JOBN		;SECOND PROCESSOR STATUS BITS BOTH HALVES (PREFIX=.SP)
				;RH=GETTAB BITS FOR 6 CPU'S.
				;LH=UNPUBLISHED BITS
				;SEE S.MAC FOR DEFINITIONS.
	XP	ITMSPS,JOBMXL	;LH SYMBOL FOR GETTAB UUO
>
	IFLE	<CPUN-1>,<	;SINGLE-PROCESSOR SYSTEM?
	0			;DUMMY ENTRY
	XP	ITMSPS,0	;DON'T ALLOW ANY REFERENCE IF NOT 2 CPU SYSTEM
>

IFN FTPDBS,<
	BLOCK	JOBN		;PDB ADDRESS IN A PDB SWAPPING SYSTEM
>
JBTADR:	BLOCK	JOBN+SEGN	;JOB AND HIGH SEG CORE ASSIGNMENT
				; LH==PROTECTION (LENGTH-1)
				; RH==RELOCATION (ABSOLUTE LOCATION IN CORE)
				; DURING BLT OF LOW OR HIGH SEG, THIS WORD
				; CONTAINS THE SOURCE RELOCATION
				;THIS IS DOCUMENTED AS GETTAB TABLE NUMBER 1
	JBTAD1==JBTADR+1	;ADDRESS OF JOB 1 (USED BY SYSMAK)
	JBTDAT==JBTADR		;RH==ADDRESS OF JOB DATA AREA
				;SAME AS JBTADR (R==R)
JBTSGN:	IFG	SEGN, <
	BLOCK	JOBN		;RH=SEGMENT NUMBER OF HIGH SEGMENT THIS JOB
				; IS USING IN CORE OR ON DISK
				; 0 MEANS JOB DOES NOT HAVE HIGH SEG
				;LH=USER DEPENDENT HIGH SEG STATUS BITS (SEE S.MAC)
				;THIS IS DOCUMENTED AS GETTAB TABLE NUMBER 14
>
	IFE	SEGN, <
	0			;SINGLE-ENTRY NULL JBTSGN TABLE....
	XP	ITMSGN,JOBMXL	;LH SYMBOL FOR GETTAB UUO SO THAT JBTSGN IS
				; UNDEFINED, I.E., MAKE INDEXING BY J BE 0, BUT
				; ALLOW REFERENCES UP TO JOBMXL.
>


	IFG	DSKN, <		;DISK SYSTEM ?
	INTERNAL JBTPPN,JBTPPN
JBTPPN:				;HIGH SEGMENT DIRECTORY NAME IF , 0 IF DTA,MTA
JBTPPN:	BLOCK	JOBN+SEGN	;XWD PROJECT NUMBER, PROGRAMMER NUMBER
				;THIS IS DOCUMENTED AT GETTAB TABLE NUMBER 2
>
	IFG	SEGN, <		;REENTRANT MONITOR CAPABILITY?
	INTERN	JBTDEV
JBTDEV==.-JOBN		;JUST HIGH HALF (NO ENTRIES FOR LOW SEGS)
	BLOCK	SEGN		;HIGH SEGMENT PHYSICAL DEVICE NAME
			; OR FILE STRUCTURE NUMBER(DSKA,DSKB,DTAN,MTAN)
>
IFE	SEGN,<
JBTDEV==JBTSGN-JOBN		;USE THE DUMMY ENTRY IN JBTSGN
	XP	ITMDEV,JBTMXL	;LH SYMBOL FOR GETTAB UUO SO THAT JBTDEV IS
				;UNDEFINED, IE. MAKE INDEXING BYITEM BE 0
>

	INTERN	FTTMP		;FOR LOADER TO COMPLAIN
IFNDEF	FTTMP,<FTTMP==-DSKN>	;BY DEFAULT, COMES WITH DISKS

IFN FTTMP, <INTERNAL JBTTMP,ITMTMP
	IFG	TEMPN, <
;TABLE USED BY TEMPORARY FILE STORAGE UUO WHICH
; KEEPS SHORT FILES (CCL) IN CORE TO SPEED UP SYSTEM.
; (ESPECIALLY USEFUL ON BIG SYSTEMS WITH SLOW DISKS.)

JBTTMP:	BLOCK	JOBN		;ONE ENTRY PER JOB, FREE SPACE FOR NULL JOB.
				; EACH ENTRY HAS THE FORM   XWD <QUOTA>,<LINK>
	ITMTMP==JOBMXL>
	IFE	TEMPN,<JBTTMP:0
	ITMTMP==JOBMXL
>>
	IFG	SYS50N, <	;SWAPPING SYSTEM ?
	INTERNAL JBTSWP,JBTCHK
IFN FTPDBS,<
	BLOCK	JOBN		;DISK ADDRESS OF PDB.
>
JBTSWP:	BLOCK	JOBN+SEGN	; DISK ADDRESS WHILE SWAPPED OUT
				;BIT 0=1 IF SEGMENT IS FRAGMENTED
				;BITS 1-17 DISK ADDRESS IF NOT FRAGMENTED
				;FOR LEVEL D,
				;  BITS 3-5=INDEX OF UNIT IN SWPTAB (JBYSUN)
				;  BITS 6-17=1ST LOGICAL K ON UNIT (JBYLKN)
				;  BITS 1-17 CORE ADR OF FRAGMENT TABLE IF FRAGMENTED
				; BITS19-26:==OUTCORE IMAGE SIZE
				; BITS28-35:==INCORE IMAGE SIZE
				; FOR HIGH SEG, LH ALWAYS DISK ADDRESS
IFN FTPDBS,<
	BLOCK	JOBN		;CHECK SUM FOR SWAPPED OUT PDB
>
JBTCHK:	BLOCK	JOBN+SEGN	;CHECK SUM FOR SWAPPED OUT JOB DATA AREA OR
				; SAME AREA FOR HIGH SEG

>
JBTNAM:				;NAME OF HIGH SEGMENT (FILE IT WAS INITIALIZED FROM)
JBTPRG:	BLOCK	JOBN+SEGN	;NAME OF FILE USED IN LAST R,RUN,GET, ETC
				; USED BY SYSTAT PROGRAM, AND AS DEFAULT FOR 
				;  THESE COMMANDS

IFN	FTWATCH,<		;WATCH SYSTEM RESPONSE DATA
	INTERN	JBTWCH
JBTWCH:	BLOCK	JOBN		;BITS 1-5 = ENABLE BITS - SEE S.MAC
				;BITS 13-35 = TIME OF DAY IN JIFFIES USER
				;STARTED TO WAIT FOR RESPONSE FROM SYSTEM
				;REST UNUSED
>
IFN	FTRSP,<		;USER TTY INPUT RESPONSE TIMES
	INTERN	JBTRSP
JBTRSP:	BLOCK	JOBN		;UP TIME AT WHICH USER BEGAN TO WAIT
			; FOR SYSTEM RESPONSE.
			; SET WHEN USER JOB COMES OUT OF TTY INPUT WAIT
			; OR TYPES A COMMAND WHICH RUNS A JOB.
			;HIGH ORDER BITS SET TO 0 WHEN USER STARTS TO WAIT
			; SET TO ONE AS EACH OF SEVERAL TYPES OF RESPONSE
			; TERMINATION CONDITIONS OCCUR.
			; SEE S.MAC FOR BITS OF FORM JR.R??
			; SEE CPU DATA BLOCK (ACR, ADR, AIR, ARR, AXR)
			; FOR DESCRIPTION OF TYPES OF RESPONSES GATHERED
JBTRQT::BLOCK	JOBN	;'RUN QUEUE TIME' ACCUM. TIME (JIFFIES) THAT JOB
			; HAS SPENT IN ONE OF THE RUN QUEUES (INCLUDING SWAPPED)
>
	INTERN	FTSPL		;FOR LOADER TO COMPLAIN
IFNDEF	FTSPL,<FTSPL==-DSKN>	;BY DEFAULT, COMES WITH DISKS

IFN FTSPL!FTDPRI,<
	INTERN	JBTSPL		;SPOOLING CONTROL WORD
JBTSPL:	BLOCK	JOBN		;LH=INPUT FILE NAME COUNTER
				;BITS 27-35 - WHAT DEVICES BEING SPOOLED
				; (SEE S.MAC FOR DEF'NS)
				;BITS 24-26 = DSK PRIORITY FOR JOB
				; (SEE JBXPRI IN COMMOD)
>
IFN FTTLIM,<
	INTERN	JBTLIM
JBTLIM:	BLOCK	JOBN		;TIME LIMIT, ETC. FOR JOB
				; (SEE S.MAC FOR LAYOUT)
>

IFE FTPDBS,<
	INTERN	JBTPDB
JBTPDB:	BLOCK	JOBN		;ADDRESS OF PDB
>
IFN FTKI10!FTKL10,<IFN M.KI10!M.KL10,<
	INTERN JBTUPM,JBTHSA
JBTHSA:
JBTUPM:	BLOCK	JOBN+SEGN	;ADDRESS OF THE UPMP>>
IFN FTWATCH,<
;PC TABLE
JBTPC::BLOCK JOBN		;RH - USER MODE PC
				;LH - RESERVED FOR BITS TO IMPROVE ^C RESPONSE
				;     IN 6.02
>;END FTWATCH
IFN FTNET,<
	INTERNAL JBTLOC
JBTLOC:	BLOCK	JOBN		;JOB LOCATION TABLE
				;JBTLOC+0 IS CENTRAL SITE STATION NUMBER
>	;IFN FTNET

IFN M.PSI,<
JBTPIA::BLOCK	JOBN		;LH HOLDS FLAGS (BITS 13-17 =0)
				;RH IS POINTER TO PROGRAM INTERRUPT
				;   TABLE.
>
IFE M.PSI,<
XP JBTPIA,777000		;CAUSE NXM IF REFERENCED
>
JBTJLT::BLOCK	JOBN		;JOB "LOGIN" TIME IN INTERNAL FORMAT

JBTJRQ::BLOCK	JOBN		;LINKED LIST OF JOBS WAITING TO REQUE
	IFN	FTPRV, <
	INTERNAL JBTPRV
JBTPRV:	BLOCK	JOBN		;PRIVILEGE BITS FOR JOB SET BY LOGIN
>
	IFG	SYS50N, <
;THE FOLLOWING ARE USED TO CREATE MXQUE
;THE MAXIMUM QUEUE SIZE, USED BY SWAPPING SCHEDULER (SCHED)
	INTERN	FTDISK		;FOR LOADER TO COMPLAIN
	FTDISK=-DSKN		;DEFINE FEATURE SWITCH FTDISK, SINCE IT APPEARS
				; IN THE QUEUES MACRO (WHICH IS DEFINED IN S.MAC)
	XP	MXQUE,0

	DEFINE	X	<MXQUE==MXQUE+1;>
	QUEUES
	RWAITS
DEFINE	X	(A)

		<A'Z==MXQUE
		MXQUE==MXQUE+1;>
	CODES
		MXQUE==MXQUE+3	;LEAVE SPACE FOR PQ1,PQ2, AND CMMQ


	IFG	HPQN,<MXQUE=MXQUE+HPQN>
			;LEAVE SPACE FOR HIGH PRIORITY QUEUES
	INTERNAL JBTCQ,JBCQM1,JBCQP1,JBCQMN,NCNULQ



XP	MXQUE2,<2*MXQUE>	;SIZE OF DOUBLE SET OF HEADERS
	BLOCK	MXQUE2		;ROOM FOR DOUBLE SET OF HEADERS
JBTCQ:	BLOCK	JOBN		;JBTQ SUBDIVIDED INTO INCORE/SWAPPED OUT
	JBCQM1==JBTCQ-1		;JBTCQ-1
	JBCQP1==JBTCQ+1		;JBTCQ+1
	NCNULQ==NULZ+MXQUE	;NUMBER OF NULQ IN NO-CORE HEADER
	JBCQMN==JBTCQ-NCNULQ	;NUL QUE HEADER

	JBCQOH==:JBTCQ-MXQUE	;WHAT TO INDEX TO GET SWAPPED OUT QUE HEADER

IFN FTNSCHED,<
	BLOCK	2*M.CLSN	;HEADERS FOR PQ2 CORE/NO-CORE SUBQUEUES
JBTCSQ::BLOCK	JOBN		;SAME AS JBTCQ BUT FOR PQ2 SUBQUEUES
	JBCSOH==:JBTCSQ-M.CLSN	;SWAPPED OUT SUB-QUE HEADER
>;END OF IFN FTNSCHED

JBTBBQ::BLOCK	1		;HEADER FOR BACKGROUND BATCH JUST INPUT QUEUE
JBTJIQ::BLOCK	1		;HEADER FOR PQ2 JUST INPUT QUEUE
JBTJIL::BLOCK	JOBN		;LIST OF PQ2 JOBS JUST INPUT FROM SWAPPER
	BBQ==:JBTJIL-JBTBBQ	;OFFSET FOR JBTBBQ
	MBBQ==:-BBQ		;NEGATIVE OFFSET
	JIQ==:JBTJIL-JBTJIQ	;OFFSET FOR JBTJIQ

JBTOBQ::BLOCK	1		;HEADER FOR BB OUTPUT SCAN LIST
JBTOLQ::BLOCK	1		;HEADER FOR PQ2 OUTPUT SCAN LIST
JBTOLS::BLOCK	JOBN		;LIST OF PQ2 JOBS IN ORDER TO BE SCANNED FOR OUTPUT
	OBQ==:JBTOLS-JBTOBQ	;OFFSET FOR JBTOBQ
	MOBQ==:-OBQ		;NEGATIVE OFFSET
	OLQ==:JBTOLS-JBTOLQ	;OFFSET FOR JBTOLQ
>;END OF IFG SYS50N
;DATA STRUCTURE CLEARED ON SYSTEM STARTUP AND ON 143 RESTART

	INTERN	TTYTAB,PTYTAB,SYSEND

;TTYTAB IS A TABLE OF CONTROLLING (ATTACHED) TTY'S FOR EACH JOB,
;INDEXED BY JOB NUMBER. IF C(TTYTAB)=0 THEN THERE IS NO SUCH JOB.
;OTHERWISE, RH(TTYTAB(N)) IS CONTROLLING DDB FOR JOB N.

;THERE IS ALWAYS A TTY DDB FOR EVERY JOB, EVEN THOUGH NO TTY
; NEED BE ATTACHED.  THUS UUOS LOOK THROUGH TTYTAB(N) FOR A DDB,
; SINCE UUO'S COME FROM JOBS.  COMMANDS LOOK THROUGH LINTAB(LINENUMBER)
; TO THE LDB, SINCE COMMANDS COME FROM TTY'S (LINES).
; IF THE JOB IS DETACHED, THE LINKS FROM LDB TO DDB AND VICE VERSA
; ARE ZEROED (RH OF DDBLDB AND LDBDDB).
TTYTAB:	BLOCK	JOBN

PTYTAB:	BLOCK	PTYN		;ADDRESSES OF THE DDBS OF
				;DEVICES PTYN (NOT TTYN LINKED BY PTY)

IFN FTDIAL,<
TTYDDA::BLOCK	1		;TTY DIALLER DATA ADDRESS, 4 WORD BLOCK
DSDUNI::BLOCK	1		;TTY NUMBER USING DIALLER CODE
>

XPNMSZ==<JOBN/^D32>+1		;SIZE OF BIT MAP
XPNMAP::BLOCK	XPNMSZ		;BIT MAP FOR JOBS WAITING TO EXPAND
				;ONE BIT PER JOB INCLUDING JOB ZERO
XP XPNMPT,-XPNMSZ		;AOBJN POINTER TO TABLE
	SYSEND==.-1		;END OF CLEARED STORAGE ON RESTART
SUBTTL ONCE ONLY CODE TO CREATE DEVICE DATA BLOCKS

	LOC	SYSBG2		;PUT IN SYSTEM DATA AREA SO NOT TO TAKE
				; VALUABLE SPACE.  THIS AREA IS CLEARED
				; BY SYSINI AFTER IT HAS BEEN EXECUTED

;CNTDB- ROUTINE TO INCREASE SIZE OF MONITOR FOR MULTIPLE DEVICE DATA BLOCKS
; BOTH DISK AND OTHER DEVICES (DTA,MTA,SCN,PTY)
; CALL:  JSP T1,CNTDB  (FROM LONG ONCE DIALOG)
;
;LINKDB- ROUTINE TO CREATE MULTIPLE DEVICE DATA BLOCKS (EXCEPT DISK)
; AND LINK THEM. THESE ARE STORED ON TOP OF ONCE ONLY CODE
;CALL:  JRST LINKDB (FROM LINKSR)
;BOTH ROUTINES UPDATE  SYSSIZ AS MORE DDB SPACE IS CONSUMED

	INTERNAL LINKDB,CNTDB,DDBNUM
	EXTERNAL LINKSR

LINKDB:!SETOM DESONC		;PERMIT DESTRUCTION OF ONCE ONLY CODE
	SKIPA	T1,LINKSR	;GET JSR PC OF CALLER OF LINKSR IN ONCE
CNTDB:!	SETZM DESONC		;PREVENT DESTRUCTION OF ONCE ONLY CODE
				;SO THAT E.G. SAT TABLES MAY BE SCANNED
	HRRM	T1, LINKED	;STORE EXIT FROM THIS ROUTINE (ONCE ONLY CODE WILL
				; BE OVERLAYED BY MULTIPLE DEVICE DATA
				; BLOCK GENERATION)
IFN LEVDN,<EXTERN HICORE,TABSTR,STRNAM,QUESTR
;THIS CODE COMPUTES WHERE THE STR DATA BLOCKS ETC. MUST GO & HOW MUCH CORE THEY TAKE UP

	MOVEI	T1,SYSINI##	;BEGINNING OF SYSINI
	SKIPE	DESONC		;SKIP IF NOT DESTROYING ONCE
	CAMG	T1,SYSSIZ	;SKIP IF SYSINI WILL BE CLOBBERED
	JRST	NOMOVE		;NO, SYSINI IS SAFE, NO NEED TO MOVE IT
	HRRZ	T2,INIFRE	;DESTINATION=FIRST FREE LOCATION ABOVE MONITOR
	CAMGE	T2,HICORE	;SKIP IF END OF MONITOR PAST DISK STUFF
	MOVE	T2,HICORE	;NO, USE THAT INSTEAD
	MOVE	T1,T2
	HRLI	T1,SYSINI	;SOURCE=BEGINNING OF SYSINI
	BLT	T1,ENDSYL##(T2)	;MOVE SYSINI TO SAFE PLACE
	HRRM	T2,SYSDSA	;STORE NEW LOCATION OF SYSINI
	SUBI	T2,SYSINI	;T2=NEW SYSINI - OLD=CHANGE
	MOVEI	T3,DIFUSY##	;OFFSET FOR FIRST UNIT IN SYSTEM
NXKUPA:!HLRZ	T1,UNISYS##(T3)	;NEXT UNIT (NEXT CONTROLLER)
	JUMPE	T1,EFUPA	;NO MORE
	HRRZ	T3,UNIKON##(T1)	;ADDR OF CONTROLLER DATA BLOCK
	ADDM	T2,KONUPA##(T3)	;PATCH LOCATION OF UPA ROUTINE (IN SYSINI)
	SKIPA	T3,T1		;T3=ADDR OF FIRST UNIT
NKUUPA:!MOVE	T3,T4		;T3=ADDR OF NEXT UNIT
	HLRZ	T4,UNIKON##(T3)	;NEXT UNIT ON THIS CONTROLLER OR BEFORE THIS UNIT
	CAMLE	T4,T1		;SKIP IF BACK TO FIRST UNIT
	JRST	NKUUPA		;TRY NEXT UNIT
	JRST	NXKUPA		;FIX NEXT CONTROLLER
EFUPA:!	HRRZ	T1,LINKED	;EXIT FROM RUN SUBROUTINE
	CAIL	T1,SYSINI	;SKIP IF NOT TO SYSINI
	CAILE	T1,ENDSYS##
	JRST	NOMOVE
	ADDM	T2,LINKED	;NEW RETURN IN SYSINI

NOMOVE:!
	MOVE	T1,SYSSIZ	;SIZE OF MONITOR SO FAR (SYSMAK, EXEC DDT OR NOT)
	MOVE	T2,T1		;GET A COPY OF SYSSIZ FOR MAKING THE BLT PTR.
	HRL	T2,DDSTAR	;SETUP THE SOURCE ADR.
	ADD	T1,HICORE	;NOW COMPUTE THE FINAL DESTINATION ADR. +1
	SUB	T1,DDSTAR
	MOVEM	T1,SYSSIZ
	SKIPE	DESONC		;DON'T BLT HIGH CORE STUFF IF NOT OK TO DESTROY ONCE
	BLT	T2,-1(T1)	;OVERLAY ONCE STUFF WITH STR DATA BLOCKS ETC.
	SKIPN	T1,QUESTR##	;GET PRESET STR NAME
	JRST	NOQSTR		;NONE SELECTED
	MOVE	T2,STRAOB##	;SEE IF IT EXISTS
	CAME	T1,@TABSTR##(T2)  ;STRNAM IS FIRST WORD
	AOBJN	T2,.-1		;LOOK AT ALL STRS
	JUMPL	T2,QSTROK	;JUMP IF MATCH
NOQSTR:!MOVE	T1,TABST0##	;ADR. OF FASTEST FILE STRUCTURE
	MOVE	T1,STRNAM(T1)	;FILE STRUCTURE NAME
	MOVEM	T1,QUESTR	;STORE FOR QUEUEING CUSPS GETTAB UUO
>

QSTROK:!MOVSI	T1,INTNUM	;NEG NUMBER OF ENTRIES IN TABLE
	MOVEI	F,DEVLST-DEVSER	;MAKE DEVLST LOOK LIKE DEVSER IN A DDB
	SETZB	U,S		;START WITH NO PROTOTYPE DDB
				;S FOR FLAGS
LOOP:!	LDB T2,PINTDB		;GET DDB ENTRY
	JUMPE	T2,NEXT		;0 MEANS NO DOB FOR DEVICE
	HLRZ	M,DEVNAM(T2)	;GET NEW GENERIC
	HLRZ	J,DEVNAM(U)	;GET PREVIOUS GENERIC
	CAME	T2,U		;IS NEW DDB BEING USED
	TRO	S,1		;YES - SET NO-COPY FLAG SO THAT
				;THIS DDB WILL BE USED ONCE
	CAME	M,J		;SAME DDB AS LAST ENTRY
	MOVEI	P3,0		;NO- RESET DEVICE NUMBER
	HRRZ	U,T2		;UPDATE PROTO PTR
	PUSHJ	P,DDBLNK	;GO LINK DDB'S,ETC. FOR ONE INTTAB ENTRY


NEXT:!	AOBJN T1,.+1		;MOVE BY TWOS
	AOBJN	T1,LOOP		;ANY MORE DEVICES
	MOVEI	T1,0		;NO, FLAG END OF DEVICE DATA BLOCK CHAIN WITH 0 LINK
	SKIPE	DESONC		;OK TO DESTROY ONCE ?
	HRLM	T1,DEVSER(F)	;YES, STORE 0 IN CASE LAST DDB IS MULTIPLE
IFG	XTCN,<
	MOVEI	F,XKB0##	;GET LOC OF FIRST KDB
XKBLP:	MOVEI	T1,1B33		;WANT TO READ
	XCT	XTCCNO##(F)	;  DA28 FEATURE REG
	XCT	XTSDTI##(F)	;READ FEATURES
	JUMPE	T1,XKBNUL	;NOT THERE
	ANDI	T1,17		;WANT ONLY NUMBER OF UNITS
	MOVEI	T2,XKBUDB##(F)	;GET ADDRESS OF UDB TABLE
	MOVE	T3,SYSSIZ	;GET CURRENT CORE ALLOCATION
XUBLP:	SKIPN	DESONC		;WRITING OVER ONCE?
	JRST	XUBALC		;NO, ONLY ALLOCATE
	MOVEM	T3,0(T2)	;SAVE UDB ADDRESS
	HRL	T4,T3		;BUILD BLT WORD
	HRRI	T4,1(T3)	;  TO ZERO UDB
	SETZM	0(T3)
	BLT	T4,XUBSIZ##-1(T3) ;ZERO IT
	MOVEM	F,XUBKDB##(T3)	;LINK UDB TO KDB
	MOVE	T4,T2
	SUBI	T4,XKBUDB##(F)	;CALCULATE UNIT NUMBER
	MOVEM	T4,XUBUNO##(T3)	;STORE IN XUB
	ADDI	T4,2120		;CONVERT TO SIXBIT
	TRZN	T4,10
	LSH	T4,6
	LSH	T4,6		;POSITION IN WORD
	MOVEM	T4,XUBNAM##(T3)	;MOVE INTO UNIT NAME
	MOVE	T4,XKBNAM##(F)	;PICK UP KNOTROLLER NAME
	HLLM	T4,XUBNAM##(T3)	;FILL IN REST OF UNIT NAME
XUBALC:	ADDI	T3,XUBSIZ##	;BUMP ALLOCATION
	MOVEM	T3,SYSSIZ	;AND SAVE IT
	AOS	T2		;BUMP UDB TABLE POINTER
	SOJGE	T1,XUBLP	;LOOP IF MORE UNITS
XKBNUL:	HRRZ	F,XKBKDB##(F)	;NO, GET ADDR OF NEXT KDB
	JUMPN	F,XKBLP		;LOOP IF IT IS THERE
	MOVEI	T1,1000		;SPACE FOR DDB'S
	ADDB	T1,SYSSIZ	; ..
>
IFN FTTMP, <IFG TEMPN, <
	MOVE	T1,SYSSIZ	;SET UP PARAMETERS FOR TMPINI
	HRLI	T1,TMPSZ
	MOVEM	T1,TMPTAB	;FREE DATA SPACE,ADDRESS OF TABLE
	HRLZI	T1,TMPSZJ
	HRRI	T1,TMPBKS
	MOVEM	T1,TMPTAB+1	;USER QUOTA,NUMBER OF BLOCKS IN AREA
	MOVEI	T1,TMPSZT	;UPDATE SYSSIZ
	ADDB	T1,SYSSIZ		>>

EXTERN LDBLEN,SCNLDB,LDPLNO	;SCNSER GLOBALS

;FOLLOWING CODE ALLOCATES SPACE FOR THE LINE DATA BLOCKS AND FOR CHARACTER LISTS

	MOVE	T1,SYSSIZ	;GET CURRENT SIZE
	TRO	T1,3		;ROUND UP TO EVEN 4TH WORD...
	AOS	T1		;...FOR CHUNK END TEST
	MOVEM	T1,SYSSIZ	;& REMEMBER
	HRRM	T1,TTCLST	;SAVE AS FIRST CHARACTER CHUNK ADDR
	HLRZ	T1,TTCLST	;COMPUTE SPACE NEEDED
	IMULI	T1,TTCHKS##	;FOR CHARACTER LIST
	ADDM	T1,SYSSIZ	;AND UPDATE SYSTEM SIZE
	MOVEI	J,0		;MAKE THE LDB'S
LNKTTL:!MOVE U,SYSSIZ	;ADDRESS FOR AN LDB
	MOVEI	T1,LDBLEN	;LENGTH OF PROTOTYPE LDB
	ADDB	T1,SYSSIZ	;UPDATE SYSTEM SIZE
	SKIPN	DESONC		;OK TO MAKE THE LDB?
	JRST	LNKTT1		;NO. SKIP THIS FOR NOW
	HRLI	U,SCNLDB	;GET THE ADR OF THE PROTO LDB
	PUSH	P,U
	BLT	U,-1(T1)	;COPY THE LDB
	POP	P,U
	HRRM	U,LINTAB##(J)	;AND SAVE ITS ADDRESS
	DPB	J,LDPLNO	;STORE PHYSICAL LINE NUMBER IN LDB
DEFINE	TTDSPX(DSP,ADDON,CLEVER,STA,X),<
	LINENO==LINENO+ADDON
IFN	ADDON,<
IF2,< IFNDEF DSP,< EXTERNAL DSP;MAKE SURE IT IS EXTERNALED IF NOT HERE>>
	MOVEI	T1,DSP		;ASSUME THIS FRONT END
IFIDN <CLEVER>,<Y>,<
	TLO	T1,LILCFE##	;SET THE BIT FOR DC76
>
IFN FTKL10,<
IFDIF <CLEVER>,<RSX20F>,<
	MOVEI	T3,0		;FOR NON-RSX20F TERMINALS, T3 IS 0
>
IFIDN <CLEVER>,<RSX20F>,<
	SETO	T3,		;T3 MUST BE NON-ZERO FOR RSX-20F LINES
>
>
IFN M.DC75!M.D87S,<
IFE STA-LOCSTA,<
	MOVEI	T2,0		;NOT A REMOTE STATION TTY
>
IFN STA-LOCSTA,<
	SETO	T2,		;SET A FLAG FOR REMOTE LDB
>>
	CAIG	J,LINENO-1	;IS IT THIS LINE?
	JRST	LNKTT2		;YES--SET LDBISR AND LDBREM
>>
	LINENO==0
	DC10N0==10*M.TTG0
	DC10N1==10*M.TTG1
	TTDSPX(DL0DSP,DC10N0,N,\LOCSTA,)
	TTDSPX(DL1DSP,DC10N1,N,\LOCSTA,)
	TTDSPX(CC0DSP,M.68L0,N,\LOCSTA,)
	TTDSPX(CC1DSP,M.68L1,N,\LOCSTA,)
	TTDSPX(DC760D,M.D70N,Y,\LOCSTA,)
	TTDSPX(DC761D,M.D71N,Y,\LOCSTA,)
	TTDSPX(DC762D,M.D72N,Y,\LOCSTA,)
	TTDSPX(DC763D,M.D73N,Y,\LOCSTA,)
	TTDSPX(DC764D,M.D74N,Y,\LOCSTA)
	TTDSPX(DC765D,M.D75N,Y,\LOCSTA)
	TTDSPX(DC766D,M.D76N,Y,\LOCSTA)
	TTDSPX(DC767D,M.D77N,Y,\LOCSTA)
	TTDSPX(TTDDSP,M.TTDN,RSX20F,\LOCSTA,)
IFN M.DC75!M.D87S,<
	TTDSPX(REMDSP,M.RTTY,N,37777,)
>
	IFN	FTXTC,<
	IFN	M.XTL,<
	TTDSPX(XTTDSP,M.XTL,N,\LOCSTA)
>>		;END OF FTXTC & M.XTL
	TTDSPX(CTYDSP,M.CTY1,N,\LOCSTA,)
IFN LINENO-TCONLN,<PRINTX ?TTDSPX IS IN ERROR>
	TTDSPX(CTYDSP,1,N,\LOCSTA,)	;THE CTY
	MOVEI	T1,ERRDSP##	;PTY LINE
IFN M.DC75!M.D87S,<
	MOVEI	T2,0		;NOT ON REMOTE STATION
>
IFN FTKL10,<
	MOVEI	T3,0		;PTY'S AREN'T RSX20F LINES
>
LNKTT2:!TLO	T1,T1		;SET UP INDEX FOR @LDBISR(U)
	MOVEM	T1,LDBISR##(U)	;STORE AWAY
IFN FTKL10,<
	SKIPN	T3		;RSX-20F LINE?
	JRST	LNKTT3		;NO--IGNORE SET UP
	MOVSI	T1,-RSXATN##	;YES--MAKE AOBJN POINTER
	CAML	J,TTDLOM##(T1)	;LINE NUMBER IN THIS TTD GROUP?
	AOBJN	T1,.-1		;NO--LOOP IF MORE
	JUMPGE	T1,LNKTT3	;SHOULDN'T HAPPEN, BUT ...
	HRRZM	T1,LDBSS2##(U)	;SAVE CPU#,,DTE# INDEX IN LDB
LNKTT3:
>
IFN M.DC75!M.D87S,<
	MOVEI	T3,LDRREM##	;REMOTE STATION BIT
	SKIPE	T2		;AT A REMOTE STATION?
	IORM	T3,LDBDCH##(U)	;YES, SET BIT.
>
LNKTT1:!CAIGE	J,TTPLEN##-1	;MADE ENOUGH LDB'S?
	AOJA	J,LNKTTL	;NO. MAKE ANOTHER ONE
	MOVE	T1,SYSSIZ	;GET SYSTEM SIZE INTO T1
IFN LEVDN,<
	ADDI	T1,CRWDM1##	;MAKE SURE 4 WORD BLOCKS HAVE BOTTOM 2 BITS = 0
	TRZ	T1,CRWDM1##
	HRLZM	T1,SYSCOR##	;SAVE ADR. OF 1ST. PERMANENT 4 WORD BLOCK IN SYSCOR
	MOVE	T2,CORNUM##	;GET # OF BLOCKS TO BE GENERATED
	ADDI	T1,CORWDS##	;COMPUTE ADR. OF NEXT BLOCK
	SKIPE	DESONC		;OK TO DESTROY ONCE ONLY CODE?
	HRLZM	T1,DIFLNK##(T1)	;YES - SAVE ADR. OF NEXT BLOCK IN THIS BLOCK
	SOJG	T2,.-3		;FINISHED YET?
	SKIPE	DESONC		;OK TO DESTROY ONCE ONLY CODE?
	SETZM	DIFLNK##(T1)	;YES - ZERO LINK IN LAST BLOCK TO SIGNAL END OF LIST
>	;END OF DSKN CONDITIONAL
	HRRM	T1,FREPTR	;SAVE ADR. OF BIT TABLE OF ALLOCATABLE 4 WORD BLOCKS
	MOVEM	T1,LOCORE	;SAVE POINTER TO 1ST. 4 WORD BLOCK
IFE FTPDBS,<
	MOVEI	T2,<<3*JOBN+3>/4>*4	;3/4 TIMES NUMBER OF JOB
	IMULI	T2,PDB4WD	;TIMES CORE FOR A PDB
	ADDI	T1,MINCOR(T2)	;MIN REQUIRED FOR DISK DDBS OR 10/40 EXTENDED PD LIST
>
IFN FTPDBS,<
	ADDI	T1,MINCOR	;ADD DDB SPACE
>
	IORI	T1,PG.BDY	;FORCE TO 1K BOUNDARY
	ADDI	T1,1
	MOVEM	T1,SYSSIZ	;STORE SIZE OF MONITOR (FIRST FREE LOC)
	MOVEM	T1,INIFRE	;STORE START OF FREE SPACE FOR SYSINI
IFN M.KI10!M.KL10,<
IFN FT22BIT,<
IFN FTMONL,<
	MOVE	T2,NWCORE
	CAMG	T2,FLG256
	MOVE	T2,FLG256
	MOVSS	T2
>
IFE FTMONL,<
	MOVS	T2,FLG256	;GET HIGHEST EXISTING ADDRESS +1
>
	SKIPE	T2		;IF ZERO, MACHINE HAS .LE. 256K OF CORE
	TLZE	T2,-1		;CHECK IF EXACTLY A MULTIPLE OF 256K
	ADDI	T2,1		;NO, 1 MORE PAGE REQUIRED FOR PAGTAB
	LSH	T2,P2WLSH+IFN FTVM,<1>  ;NUMBER OF WORDS REQUIRED FOR PAGTAB AND MEMTAB
>
IFE FT22BIT,<
	MOVEI	T2,1_<<P2WLSH>+<IFN FTVM,<1>>>  ;1 PAGE PER TABLE IS REQUIRED
>
	ADDM	T2,INIFRE	;STORE THAT AS WERE TO MOVE SYSINI
>
	SUB	T1,LOCORE	;FORM LENGTH OF EXCESS CORE
	IDIVI	T1,^D144	;MUST BE MULTIPLE OF 144. WORDS (LEVEL C:SEE DDBTAB)
				;SIZE OF BIT TABLE IS NOW IN T1
	CAMGE	T2,T1		;IF REMAINDER IS .LT. BIT TABLE LENGTH DECREMENT LENGTH
	SUBI	T1,1		; SO SPACE WILL NOT BE ALLOCATED BEYOND 1K BOUNDRY
	ADDM	T1,LOCORE	;MAKE LOCORE POINT TO 1ST. 4 WORD BLOCK 
	MOVN	T1,T1		; -N
	HRLM	T1,FREPTR	;STORE USEABLE LENGTH OF DDBTAB

LINKED:!JRST .			;RETURN TO SYSINI
INIFRE:!BLOCK	1		;CONTAINS ADDR OF FREE SPACE FOR SYSINI
;DDB LINK AND CREATION SUBROUTINES

DDBLNK:!CAIN M,(SIXBIT/DSK/)	;IS THIS A DSK DDB?
	JRST	DDBLDS		;YES - DO EXTRA SPECIAL STUFF
	LDB	P2,PINTNO	;NUMBER OF DDB'S TO CREATE
	TRZN	S,1		;SKIP COPY IF NO-COPY FLAG SET ON CALL
MULDDB:!PUSHJ P,DDBCOP		;GO COPY A DDB
	SKIPE	DESONC		;SKIP IF UNABLE TO WRITE
	HRLM	T2,DEVSER(F)	;CHAIN TO PREVIOUS DDB
	HRRZ	F,T2		;UPDATE DDB PTR
IFN	FTTYPE,<IFN M.DC44,<

;THE NEXT CODE IS EXECUTED ONLY FOR DC44 FRONT DEVICE DDB'S
;ALL THIS DDB ' S ARE DEFINED IN A CONSECUTIVE AREA IN INTTAB
;DURING THE LINKAGE OF THE DDB'S T3 WILL BE USED TO HOLD
;THE ACCUMALATED FRONT END DEVICE NUMBER
;NOTE: CURRENTLY ONLY DDBLDS USES T3,WHICH WILL NEVER BE ENTERED
	MOVEI	T2,INTTAB(T1)	;GET ADDRESS OF TABLE ENTRY
	CAIL	T2,DC4FST	;LARGER THAN START OF DC44 DEVICE SECTION
	CAIL	T2,DC4LST	; AND LESS THAN THE END
	JRST	NODC44		;NO, IT IS NO FRONT END DEVICE
	TRON	S,4		;IS THIS THE FIRST DC44 DEVICE
	SETZ	T3,		;IF SO ZERO COUNTER
	SKIPE	DESONC		;SAVE ONCE
	HRRM	T3,DEVCTR(F)	;STORE DC44 LINE NUMBER
	MOVEM	F,DC40TB##(T3)	;AND STORE DDB ADDRESS IN CORRESPONDENCE TABLE
	ADDI	T3,1		;SAVE FOR NEXT ONE
NODC44:
>>	;;END OF IFN FTTYPE AND M.DC44 CONDITIONS

	SKIPN	P3		;IF THIS IS DEV 0
	LDB	P1,PUNIT	;RESET UNIT NUMBER FROM DDB
				;(PTY'S, FOR EXAMPLE, START AT #1)
	SKIPE	DESONC		;SKIP IF UNABLE TO WRITE
	SKIPN	DEVNAM(F)	;DO NOT MAKE FUNNY NAMES
	SKIPA			;CON NOT WRITE OR NULL NAME
	PUSHJ	P,DDBFIX	;MAKE DDB UNIQUE
	AOS	P3		;INCREMENT # OF DEVNAM
	AOS	P1		;INCREMENT UNIT #
	SOJG	P2,MULDDB	;DO NEXT DDB TILL DONE
	POPJ	P,0		;THEN RETURN

DDBLDS:!TRNE S,2		;HAVE WE BEEN HERE BEFORE
	POPJ	P,0		;YES - RETURN WITHOUT DOING ANYTHING
	TRO	S,2		;SET TRAP FOR ONCE ONLY
IFN SYS50N,<
	EXTERN	SWPDDB		;SWAPPING SYSTEM?
	MOVEI	T3,SWPDDB	;ADR. OF SWAPPING DDB
	SKIPE	DESONC		;SKIP IF NOT ABLE TO DESTROY ONCE ONLY
	HRLM	T3,DEVSER(F)	;LINK PREVIOUS DDB TO SWPDDB
	MOVEI	F,SWPDDB	;UPDATE DDB PTR TO SWPDDB
				; THUS SWPDDB COMES BEFORE DSKDDB
				; IN DEVICE CHAIN.  NEED IN CHAIN FOR
				; HUNG TIMEOUT.
>
	SKIPE	DESONC		;SKIP IF UNABLE TO WRITE
	HRLM	T2,DEVSER(F)	;LINK DDB TO LAST
	HRRZ	F,T2		;UPDATE DDB PTR
	POPJ	P,0		;AND RETURN

;SUBROUTINE TO COPY DDB PROTOTYPE AND UPDATE SYSSIZ

DDBCOP:!HRRZ T2,SYSSIZ	;IS PTR TO NEW DDB
	HRL	T2,U		;SOURCE OF COPY IS PROTOTYPE
	LDB	M,PINTSZ	;GET SIZE OF DDB
	ADDB	M,SYSSIZ	;UPDATE SYSSIZ AND GET END OF DDB+1
	PUSH	P,T2		;SAVE BLT AC
	SKIPE	DESONC		;SKIP IF UNABLE TO WRITE
	BLT	T2,-1(M)	;COPY DDB
	JRST	T2POPJ		;RESTORE T2 AND RETURN
;SUBROUTINE TO FIX UP EACH DDB TO BE UNIQUE
;THIS ROUTINE (1) UPDATES PUNIT
;		(2) UPDATES THE DEVNAM FIELD TO BE UNIQUE
;		(3) PUTS IN THE CORRECT STATION NUMBER
;		(4) DOES ODDS AND ENDS ON A DEVICE DEPENDANT BASIS
;			SUCH AS:
;				FOR DTA - PUTS IN DIR PTR

DDBFIX:!DPB	P1,PUNIT	;PUT IN UNIT NUMBER
IFE FTGSRC!FTNET,<
	LDB	R,PINTNO	;NUMBER OF DDB'S BEING CREATED
	SOJLE	R,DDBFI1	;JUMP IF ONLY 1, DON'T CHANGE ITS NAME
>
	MOVE	R,PHYNAM	;BYTE POINTER TO NEWLY CREATED
				; DDB PHYSICAL NAME
	LDB	T2,PDVTYP	;GET THE DEVICE TYPE
	CAIE	T2,.TYTTY/.TYEST  ;IS IT A TTY
	CAIN	T2,.TYPTY/.TYEST  ; OR PTY
	JRST	DDBFI0		;YES, IGNORE STATION NUMBER IN DEV NAME
	LDB	J,PINTST	;GET THE STATION NUMBER
	LSH	J,3		;SHIFT FOR THE UNIT
	IORM	P1,J		;INSERT THE STATION NUMBER
	JRST	DDBFI4		;CONVERT THE NAME
DDBFI0:!MOVE	J,P3		;MAKE COPY OF UNIT NUMBER
	TRNN	J,700		;UNIT NUMBER 100 OR MORE?
	JRST	DDBFI2		;NO
DDBFI4:!LDB	T2,[POINT 3,J,29]
	ADDI	T2,20
	IDPB	T2,R		;PUY IN 00B NAM
	TRZ	J,700		;CLEAR HIGH ORDER
	JRST	DDBFI3		;AND PROCEED
DDBFI2:!TRNN	J,70		;IS IT 10 OR MORE ?
	JRST	SMALL		;NO
DDBFI3:!ROT	J,-3		;YES, CONVERT HIGH ORDER OCTAL DIGIT TO
	ADDI	J,20		;SIXBIT
	IDPB	J,R		;AND STORE
	TRZ	J,-1		;CLEAR OUT HIGH ORDER DIGIT
	ROT	J,3		;MOVE LOW ORDER DIGIT BACK
SMALL:!	ADDI	J,20		;CONVERT LOW ORDER DIGIT IN SIXBIT
	IDPB	J,R		;AND STORE IN PHYSICAL NAME
DDBFI1:!LDB	T2,PINTST	;GET STATION NUMBER
	DPB	T2,PDVSTA	;AND PUT IN DDB
IFN M.DTA!M.DTB,<
	CAIE	T2,LOCSTA	;IS THIS FOR LOCAL STATION
>
	POPJ	P,0		;AND RETURN

IFN M.DTA!M.DTB,<
FIXLOC:!MOVE	T2,DEVMOD(F)	;GET DEV CHR
	MOVEI	J,DTADIR##(F)	;ADDRESS OF DIR BLOCK ID DTA
	TLNE	T2,DVDTA	;IS IT A DTA
	MOVEM	J,DLOC##(F)	;YES -  PUT IN PTR TO DIR
	POPJ	P,0		;AND RETURN
>

;XCT'D FROM ONCE TO SEE IF ALL CPUS HAVE DK10S
;	XCT	CKDK10##
;	---			;HERE IF NO
;	---			;HERE IF YES

CKDK==SKIPA			;ASSUME YES
IFE M.RT0,<CKDK==JFCL>		;NO IF NONE ON CPU0
IFG CPUN-1,<IFE M.RT1,<CKDK==JFCL>>	;NO IF NONE ON CPU1
CKDK10::CKDK
IFN FTTMP, <IFG TEMPN, <

	EXTERNAL TMPTAB

;MORE PARAMETERS FOR TEMPORARY IN-CORE FILE STORAGE FOR SHORT (CCL) FILES

IFE TMPN, <TMPNX==JOBN*^D20>	;IF SIZE OF SPACE NOT SET, DEFAULT VALUE
IFN TMPN, <TMPNX==TMPN>
TMPBKS==<TMPNX+TMPBL>/<TMPBL+1>	;NUMBER OF BLOCKS (LINKED LIST) IN AREA
TMPSZ==TMPBKS*TMPBL		;NUMBER OF DATA WORDS AVAILABLE
TMPSZT==TMPBKS*<TMPBL+1>		;TOTAL TABLE LENGTH (ROUNDED)
IFE TMPLN, <TMPBKJ==<TMPBKS*2/JOBN>> ;USER SPACE QUOTA. DEFAULT VALUE
IFN TMPLN, <TMPBKJ==<<TMPLN+TMPBL>/<TMPBL+1>>> ; MONGEN SPECIFIED, ROUND
TMPSZJ==TMPBKJ*TMPBL		;QUOTA OF DATA WORDS PER USER

>>

DESONC:!0			;FLAG =0 IF CALLED BY JSP T1,CNTDB
				; (DO NOT DESTROY ONCE)
				; FLAG NON-ZERO IF CALLED BY JRST LINKDB
				; (OK TO DESTROY ONCE CODE)
DDBNUM:!POINT 11,INTTAB(T1),11	;POINTER TO DDB NUMBER
PHYNAM:!POINT 6,DEVNAM(F),17	;BYTE POINTER TO DB PHYSICAL NAME
PINTNO=DDBNUM
PINTIN:!POINT 18,INTTAB(T1),35	;PTR TO INTERUPT FIELD 
PINTCH::!POINT 3,INTTAB(T1),PIAPOS	;PTR TO CHANNEL FIELD
PIAPOS==^D17	;PLACE IN INTTAB ENTRY WHERE PIA IS HELD
PINTDB:!POINT 18,INTTAB+1(T1),35	;PTR TO DDB ADDR FIELD
PINTST:!POINT 6,INTTAB+1(T1),8	;PTR TO STATION NUMBER FIELD -- SEE ALSO SYCHK: %IDB2
PINTSZ:!POINT 9,INTTAB+1(T1),17	;PTR TO DDB SIZE FIELD


IFN LEVDN,<INTERN DDSTAR
DDSTAR:!Z		;STARTING ADDR OF STR DATA BLOCKS ETC. IN HIGH CORE
			;(USED BY ONCMOD AND REFSTR)
>
	INTERN	SYSCKI
SYSCKI:
IFE SYSCN,<JFCL>		;"XCT"ED BY SYSINI
IFN SYSCN,<EXTERN SYSCHK	;CAUSE SYSCHK TO BE LOADED
	JSR	SYSCHK		;"XCT"ED BY SYSINI
>
SUBTTL MACROS TO DEFINE PI CHANNELS
;;MACROS TO DEFINE PI CHANNEL NUMBER AND GENERATE INTERRUPT CHAINING
;; INFORMATION FOR ONCE SO IT CAN LINK THE DEVICE INTERRUPT SERVICE
;; ROUTINES AND THE DEVICE DATA BLOCKS


;;TABLE INTTAB IS GENERATED WITH PAIRS OF ENTRIES FOR EACH DEVICE
;;FIRST WORD: BIT 0==1 IF DECTAPE, BITS 1-11==NUMBER OF DDBS
;;	RH IS ADDRESS OF CONSO FOR SKIP CHAIN
;;SECOND WORD: BIT 0, FLAG SAYING DEVICE IS ON CPU1, BITS 1-3 PIA,
;;	BITS 4-8 STATION #,9-17 DDB SIZE AND RH IS DDB ADDRESS
;;
;;MACRO FOR DEVICES WHICH ARE ALWAYS PRESENT (AND WHICH DO NOT USE A
;; CHANNEL SAVE ROUTINE AND HAVE NO DDB)  EXAMPLES ARE APR, CTY, PEN, CLK...

DEFINE SPAXGINT (DEV,PI) <
	DEV'N==1
	ASGINT DEV,PI
>


DEFINE ASGIN1 (DEV,PI) <
		DEV'CHL==CH'PI
		INTERNAL DEV'CHL
>

DEFINE SPASGINT (DEV,PI) <
	DEV'N==1
	ASGINT DEV,PI
>

DEFINE ASGINT (DEV,PI) <
	EXTERNAL DEV'INT		;;INTERRUPT SERVICE CONSO INSTRUCTION
	IFG	DEV'N, <IFG PI, <
	IFE	<PI-.CH>, <.CHAS==1	;;CHANNEL PI IN USE.
>
	INTERNAL DEV'CHN
		DEV'CHN==PI&7
		DEV'CH1==PI		;DEFINE THIS FOR USE AFTER CHAN DEFINITIONS
		XWD PI,DEV'INT	;;GENERATE INTERRUPT ENTRY POINT FOR ONCE
		XWD CP1PI,0
	ASGIN1	DEV,\PI
>>
>


;;MACRO FOR OPTIONAL DEVICES WHICH ALWAYS USE A CHANNEL SAVE ROUTINE
;; (EXAMPLES: CDR, DSK, PTR, ETC.  ALSO PTY WITH 0 PI)

DEFINE SPASGDDB (DEV,PI,NUM) <
	DEV'N==NUM
	NOSAV==1
	ASGSAV	DEV,PI
>
;MACRO TO GENERATE INTTAB ENTRY FOR SAVE ROUTINE BUT NO DDB
;  ASGSVE & ASGSVI
DEFINE ASGSVE (DEV,PI) <

	.CHAS==1
	DEV'CHN==PI&7
	INTERNAL DEV'CHN
	DEV'CH1==PI
	DEV'HAC==13

	ASGSV2	DEV,\PI;
IFDIF	<DEV><SCN><
IF2 < IFNDEF DEV'INT,<EXTERN DEV'INT>> ;DEFINE AS EXTERN IF NOT IN COMMON
		XWD PI,DEV'INT
		XWD CP1PI,0

>>
DEFINE ASGSAV (DEV,PI) <
	IFG	DEV'N, <
	ASGSV1	DEV,\PI
	>>

;;MACRO FOR:	1. COMPLETION OF THE DEFINITION REQUIRED FOR THOSE
;;		   DEVICES INVOKING THE ASGSAV MACRO
;;		2. DEFINE SYMBOLS FOR DISK (DEV'N=0)

DEFINE ASGSV1 (DEV,PI) <
IFG DEV'N,<			;0 IF DISK - DO NOT DECLARE FH0DDB EXTERN
IF2, < IFNDEF DEV'DDB, <EXTERNAL DEV'DDB>>	;;DEVICE DATA BLOCK ADDRESS
>
	IFG	PI, <
	IFE	<PI-.CH>, <.CHAS==1	;;CHANNEL PI IN USE.
>
		DEV'CHN==PI&7		;;DEFINE DEVICE CHANNEL NUMBER
		INTERNAL DEV'CHN	;;DECLARE INTERNAL - ONLY IF DEVICE WANTED
		DEV'CH1==PI		;;USED AFTER CH'PI DEFINITIONS
IFE NOSAV,<
	ASGSV2	DEV,PI
>
>

	DTBIT==0			;;ASSUME THIS DEV IS NOT A DECTAPE
	IFIDN	<DEV> <DTA> <DTBIT==1>	;;IS IT PDP10 DECTAPES?
	IFIDN	<DEV> <DTB> <DTBIT==1>	;;
	IFIDN	<DEV> <DTC> <DTBIT==1>	;; OR PDP-6 DECTAPES?

IFIDN <DEV><SCN><	SCNN*100,,0
	LOCSTA*1000+SCNDDS##,,SCNDDB##>
IFDIF <DEV><SCN><
IFG PI, <
IF2, < IFNDEF DEV'INT, <EXTERNAL DEV'INT>>	;;INTERRUPT SERVICE CONSO INSTRUCTION
>

	IFE	PI, <
		XWD DEV'N*100+0,0	;;NO PI CHANNEL FOR THIS DEVICE
	>
	IFG	PI, <
		XWD DTBIT*400000+DEV'N*100+PI,DEV'INT	;;FIRST WORD OF INTTAB ENTRY
		IFE DEV'N,<IFNDEF FTCMBTH,<EXTERNAL DEV'INT>> ;;LEVEL D DISK IN COMMOD
	>

	IFG	DEV'N-1,<
		XWD CP1PI!<LOCSTA*1000>+DEV'DDS##,DEV'DDB	;;MULTIPLE DEVICE SECOND WORD OF INTTAB ENTRY
	>
	IFE	DEV'N-1, <
		XWD CP1PI!<LOCSTA*1000>,DEV'DDB		;;SINGLE DEVICE SECOND WORD OF INTTAB ENTRY
	>
	IFE	DEV'N,<		;HERE IF DISK (SEE MULASG)
		XWD CP1PI!<LOCSTA*1000>,DSKDDB
		IFNDEF FTCMBTH,<EXTERNAL DSKDDB>
		IF1,<IFNDEF DSKCHN,<DSKCHN==DEV'CHN>>
		DEFBIT DEV
		DSKPIF==DSKPIF!DEV'BIT ;;KEEP LOG. OR OF PI OFF BIT FOR DSK CONTROLLERS
		DSKPIN==DSKPIN!DEV'BIT ;;AND FOR PI ON
	>
> ;;END IFDIF ABOVE
>		;;END ASGSV1 DEFINITION
;;MACRO'S TO ALLOW GENERATION OF MULTIPLE INTTAB ENTRIES FOR MULTIPLE
;; DEVICES SUCH AS LINE-PRINTERS

DEFINE MULASG (DEV,DE,PI,DSKFL) <
	IFG	DEV'N, <
		ZZ==0
		REPEAT DEV'N, <
			DEVASG DE,\ZZ,PI,DSKFL
			ZZ==ZZ+1
		>
	>
>

DEFINE DEVASG (DE,X,PI,DSKFL) <
	IFE	DSKFL,<DE'X'N==1>	;;DSKFL=1 IF NOT LEVEL D DISK
	IFN	DSKFL,<DE'X'N==0>	;;DSKFL=ZERO IF LEVEL D DISK
	ASGSV1	DE'X,\PI
>


;;MACROS TO CONTROL ASSIGNMENT OF PI CHANNELS TO DEVICES

DEFINE NEXTCH <	.CH==.CH+1	;;START ASSIGNING TO NEXT LOWER CHANNEL
.CHAS==0
NEXTCU \.CH	
>
DEFINE NEXTCQ <	IFN .CHAS, <NEXTCH>>	;;START ASSIGNING TO NEXT LOWER CHANNEL IF
					;; CURRENT CHANNEL HAS BEEN USED.
DEFINE NEXTCU (N) < IFDEF UNIQ'N, < IFN UNIQ'N, <NEXTCH>>	;;TO SKIP OVER ANY
					;; SPECIALLY SPECIFIED CHANNELS (RECURSIVELY!)
		IFDEF RTCH'N,<IFN RTCH'N,<NEXTCH>>>	;IF RTCH'N IS DEFINED
					;DURING MONGEN, THAT CHANNEL WILL BE FREE FOR RT DEVICES

DEFINE DEFBIT (DEV) <
	DEV'BIT==1
	REPEAT	7-DEV'CHN, <DEV'BIT==DEV'BIT*2>
>

DEFINE UNIQDEF(N)
<	UNIQ'N==1
IFDEF	RTCH'N,<IFN RTCH'N,<
	PRINTX	?PI CHAN N CAN NOT BE RESERVED FOR REAL-TIME
	PRINTX	?IT IS NEEDED FOR BLKI/BLKO
>>>





DEFINE	MULINT,	(DEV,DE,PI) <
	IFG	DEV'N,<
		ZZ==0
		REPEAT DEV'N,<
		MULFLG	DE,\ZZ,\PI
		ZZ==ZZ+1
		>
	>
>


DEFINE	MULFLG,	(DE,X,PI) <
	ASGSVE	DE'X,\PI
>

;;INITIALLY ASSUME NO PI CHANNEL SAVE ROUTINES NEEDED

	USED1==0
	USED2==0
	USED3==0
	USED4==0
	USED5==0
	USED6==0
	USED7==0
	USED11==0
	USED12==0
	USED13==0
	USED14==0
	USED15==0
	USED16==0
	USED17==0
;MACRO TO ALLOW GENERATION OF CHANNEL SAVE ROUTINES ONLY

DEFINE SPASGSAV (DEV,PI,%ACNUM) <
	HIAC'PI==%ACNUM
	DEV'HAC==%ACNUM
INTERNAL HIAC'PI,DEV'HAC

	ASGSV2	DEV,PI
>

DEFINE ASGSV2 (DEV,PI) <
		USED'PI==1		;SET FLAG SO THAT A CHANNEL SAVE
					; ROUTINE WILL BE GENERATED FOR
					; THIS PI CHANNEL

	IFDEF	SAV'PI, <	;WAIT TILL CHANNEL SAVE ROUTINES
					; ARE DEFINED BELOW (IN PASS 2)

		DEV'SAV==SAV'PI		;CHANNEL AC SAVE ROUTINE LOCATION
		DEV'RET==RET'PI		;CHANNEL AC RESTORE ROUTINE LOCATION
					; (USUALLY POPJ USED)
		DEV'CHL==CH'PI		;LOCATION WHERE INTERRUPT PC IS STORED
		DEV'SAC==SVAC'PI	;STARTING CHANNEL SAVE LOCATION FOR AC'S
		DEV'PDP==C'PI'PDP	;LOCATION WHERE P STORED
		DEV'PD1==C'PI'PD1	;PUSHDOWN LIST
		DEV'JEN==C'PI'JEN	;LOCATION WHERE INT. IS DISMISSED
		INTERN DEV'SAV, DEV'RET, DEV'CHL, DEV'SAC,DEV'PDP,DEV'JEN
>>
;NOW GENERATE THE TABLE FOR ONCE AND DEFINE PI CHANNEL ASSIGNMENTS

	INTERNAL INTTAB,INTTB1,INTNUM,SCNN,CTYN,DSKPIF,DSKPIN

		CTYN==1		;ALWAYS ONE CTY
IFN M.NET,<
		NETN==1		;ONLY ONE DDB
>
		SCNN==JOBN+TTXTRA	;NUMBER OF SCN DDB
				; ONE FOR EACH JOB + NULL JOB (EXTRA ONE)
		AP0N==1		;ALWAYS AN APR
		CK0N==1		;ALWAYS LOWEST PRIORITY CLOCK

IFG <CPUN-1>,<	AP1N==1		;SLAVE PROCESSOR EXISTS
		CK1N==1	;SO DOES ITS CLOCK OR SCHEDULER CHANNEL
>
IFE <CPUN-1>,<	AP1N==0	;SLAVE DOES NOT EXIST
		CK1N==0	;NOR DOES ITS CLOCK LEVEL
>

	DSKPIN==2000	;SET PI ON BIT - WILL ALSO HAVE PI ON FOR DISK CONTOLLERS
	DSKPIF==1000	;AND FOR PI OFF


CP1PI==0		;ON CPU0
INTTAB:!		;TABLE OF DATA FOR DEFINING PI CHAN AND NUMBER OF DOB
	NOSAV==0	;DO NOT SUPPRESS GENERATION OF SAVE ROUTINES
	INTTB1==INTTAB+1
;PTY AND SCN MUST BE THE FIRST TWO ENTRIES IN INTTAB
	ASGSAV	PTY,0		;NO PI CHANNEL FOR PTY
	ASGSAV	SCN,0
IFN M.MSG,<			;IF WE WANT MSGSER
IFE FTMSGSER,<
PRINTX	?PLEASE ASSEMBLE WITH FTMSGSER =-1
>
	EXTERNAL MSGSER		;FORCE IT TO BE LOADED
	XWD	0,0		;NO DDB ON NO PI CHANNELS
	XWD	0,MPXDDB##	;BUT WE WOULD LIKE TO BE PUT ON THE CHAIN
>

.CHAS==0
.CH==0
NEXTCH		;BEGIN AT CHANNEL 1

;THE FOLLOWING DEVICES MUST HAVE A UNIQUE, HIGH PRIORITY
; CHANNEL FOR BLOCK I/O TRANSFERS.

;NOTE THAT THE PDP-6 DECTAPE AND MAGTAPE SHARE A
; 136 DATA CONTROL IF BOTH ARE PRESENT.

;PDP-6 OR PDP10 MAGTAPE BLKI/BLKO PI CHANNEL:

IFNDEF MTDCHN,< IFG TM10A,<
	XP MTDCHN,.CH
	UNIQDEF(\.CH)
	NEXTCH>>

IFNDEF DCTCHN,< IFG MTCN,<
	XP DCTCHN,.CH
	UNIQDEF(\.CH)
	NEXTCH>>

;PDP-6 DECTAPE BLKI/BLKO PI CHANNEL:

IFNDEF DCTCHN,< IFG DTCN,<
	XP DCTCHN,.CH
	UNIQDEF(\.CH)
	NEXTCH>>

IFNDEF BLKMXC, <BLKMXC==.CH>	;REMEMBER THIS CHANNEL ON PASS 1
.CH==BLKMXC			;ON PASS 2, SKIP OVER BLKI CHANNELS
;THE FOLLOWING ARE GROUPED ON A HIGH PRIORITY CHANNEL, BUT DO NOT
; WRITE INTO THE INTERRUPT LOCATIONS

IFG M.DTA, <	SPAXGINT	DAD,.CH>
IFG M.DTB, <	SPAXGINT	DBD,.CH>

NEXTCQ

;THE FOLLOWING ARE GROUPED ON A CHANNEL FOR HIGH-PRIORITY DEVICES
IFG M.RT0,<			;REAL TIME CLOCK (DK10)
	ASGSVE	RT0,.CH
>
	ASGSAV	CDP,.CH
	MULASG	CDR,CR,.CH,0
	MULASG	DCDR,FC,0,0	;TAKE CARE OF RSX-20F CARD READERS ALSO
	ASGSVE	AP0,.CH

NEXTCQ

;THE FOLLOWING ARE MEDIUM-PRIORITY DEVICES, AS A GROUP
	ASGSVE	SCN,.CH
IFN M.NET,<
	EXTERNAL	COMNET,NETSER
	ASGSVE	NET,.CH
	XP	NETBIT,1_<7-NETCHN>
	XP	NETIIP,1_<7-NETCHN+^D8>	;INTERRUPT IN PROCESS
	XP	REQNET,PI.IIO+NETBIT	;CONO PI,REQDXX REQUEST INTERRUPT
	XP	CLRNET,II.CPP+NETBIT	;CONO PI,CLRDXX CLEAR INTERRUPT
>
IFN	M.TTG0,<
	ASGSVE	DL0,.CH
>
IFN	M.TTG1,<
	ASGSVE	DL1,.CH
>
IFN	M.68L0,<
	ASGSVE	CC0,.CH
>
IFN	M.68L1,<
	ASGSVE	CC1,.CH
>
IFN	PDP11N,<
	ASGSVE		DLX,.CH

	XXIN==	M.D78L		;NUMBER OF LINES
	ASGSAV	XXI,.CH

	XXON==	M.D78L		;NUMBER OF LINES
	ASGSAV	XXO,0		;JUST GENERATE DDB'S
>	;END OF IFN PDP11N

IFN M.CTY1,<			;PSEUDO DEVICE FOR CTY1
;MUST BE SAME PI LEVEL AS SCN SO CAN CALL SCNSER
	ASGSVE	ST1,.CH
XP ST1PIA,.CH
>

	ASGSAV	PTR,.CH
	MULINT	CDR,CF,.CH
	MULASG	LPT,LP,.CH,0
	MULASG	DLPT,FL,0,0	;TAKE CARE OF RSX-20F LINEPRINTERS
	ASGSAV	DTA,.CH
	ASGSAV	DTB,.CH
	ASGSAV	DTC,.CH
IFG TAPN,<
DEFINE TAPMAC (X) <
	ASGSAV	(MT'X,.CH)
>

	KONMAC			;GENERATE TAPE CHL INFO

>	;;;	END IFG TAPN

	ASGSAV	MTC,.CH
IFN M.KA10!M.KI10,<
	ASGINT	CTY,.CH
>;END IFN M.KA10!M.KI10

IFN M.KL10,<
	XP	SPCPI,.CH	;SECONDARY PROTOCOL PI ASSIGNMENT
	XP	PPCPI,.CH	;PRIMARY PROTOCOL PI ASSIGNMENT
	XP	DTECHL,SCNCHL	;PLACE TO STORE PC
>;END IFN M.KL10


NEXTCQ
;THE FOLLOWING ARE LOWER-PRIORITY DEVICES, AS A GROUP
;FIRST ARE THE VARIOUS TYPES OF DISK CONTROLLERS....

IFN LEVDN,<
	MULASG	FHD,FH,.CH,1
	MULASG	FSD,FS,.CH,1
	MULASG	RPX,RP,.CH,1
	MULASG	DPC,DP,.CH,1
	MULASG	MDF,MD,.CH,1
>	;END CONDITIONAL ON LEVDN

	IFN	FTXTC,<
	IFN	M.XTC,<
	MULASG	XTC,XT,.CH,0
	XP XTCBIT,1_<7-XT0CHN>
>>
	ASGSAV	PEN,.CH
	ASGSAV	PTP,.CH
IFN CDPN,<
	ASGSVE	CPF,.CH
>;END IFN CDPN
	MULASG	PLT,PL,.CH,0



	ASGSAV	VBC,.CH

NEXTCQ


;THE DISPLAY GETS ITS OWN LOW-PRIORITY CHANNEL
	ASGSAV	DIS,.CH

NEXTCQ
IFN M.NET,<
	ASGSAV	NET,0		;TO GENERATE A DDB AT THE END OF THE LIST
>
;LAST IS THE SCHEDULER, ON CHANNEL 7 BY ITSELF

IFG <.CH-7>, <	PRINTX ?NOT ENOUGH PI'S TO SERVICE THIS CONFIGURATION.
		PRINTX ?SUGGEST EDITING COMMON TO PUT MORE DEVICES ON
		PRINTX ? A SINGLE CHANNEL
>

.CH==7
	ASGINT	CK0,.CH
IFG CPUN-1,<
;NOW GENERATE SLAVE PROCESSOR CHANNELS
;START .CH AT 11   SLAVE CHANNELS ARE 11 - 17

.CHAS==0
.CH==10
CP1PI==400000	;ON CPU1
NEXTCH		;START AT 11

IFNDEF BLKMC1,<BLKMC1==.CH>

.CH==BLKMC1	;SKIP OVER CHANNELS USED FOR BLKI/O'S

IFG M.RT1,<	;REAL TIME CLOCK (DK10)
	ASGSVE RT1,.CH
>

	ASGSVE	AP1,.CH

NEXTCQ

;MEDIUM PRIORITY DEVICES

IFN M.KA10!M.KI10,<
IFG M.CTY1,<	;CTY1

	SPASGINT CT1,.CH
>
>;END IFN M.KA10!M.KI10
IFN M.KL10,<
IFG M.CTY1,<
	XP CT1CHN,.CH&7		;PI CHANNEL FOR CTY1 ON KL10
>;END IFG M.CTY1
>;END IFN M.KL10

IFG <.CH-17>, <	PRINTX ;NOT ENOUGH PI'S TO SERVICE THIS CONFIGURATION.
		PRINTX ;SUGGEST EDITING COMMON TO PUT MORE DEVICES ON
		PRINTX ; A SINGLE CHANNEL
>

.CH==17		;PUT SCHEDULER LEVEL ON CHANNEL 17

	ASGINT	CK1,.CH
CP1PI==0	;RESET TO CPU0 FOR OTHER DEVICES
>		;END OF IFG CPUN-1 CONDITIONAL

	IFN	FTTYPE,<
;DEFINE DC44 FRONT END DEVICES:
;1 PA611R READERS
;2 PC-11 READERS
;3 PA611P PUNCHES
;4 LPC11 TYPESET INTERFACES
;5 PC-11 PUNCHES
;6 WTY WIRE SERVICE LINES

	DEFINE	BLDDEV(N1,N2,N3)
<	IFN N3,<
	EXTERN	N1,N2
	XWD	N3*100,0
	XWD	LOCSTA*1000+N1,N2
>>	;END OF BLDDEV MACRO
	DEFINE	GENTAB(PORT,LIST)
<	IFN	TYPNU'PORT,<
	IRP	LIST
<IFNDEF LIST'PORT'N,<
	LIST'PORT'N==0>
	BLDDEV	LIST'PORT'DS,LIST'PORT'DD,LIST'PORT'N		;;NO PI CHANNEL
>	;;END OF IRP LIST
>	;;END OF IFN TYPNU
>	;;END OF GENTAB MACRO

	IFN	M.DC44,<
ZZZ=0
DC4FST:	REPEAT	8,<
	GENTAB	(\ZZZ,<PAR,PCR,PAP,LPC,PCP,WTY>)
ZZZ=ZZZ+1
>	;;END OF REPEAT LOOP
DC4LST:
>	;;END OF IFN M.DC44
>	;;END OF IFN FTTYPE

	SPCINT
				;GENERATE ANY SPECIAL DEVICES CUSTOMER IS SUPPLYING
				; WHICH DO NOT USE A CHANNEL SAVE ROUTINE AND HAVE
				; NO DEVICE DATA BLOCK
	SPCDDB
				;GENERATE ANY SPECIAL DEVICES CUSTOMER IS SUPPLYING
				;WHICH HAVE MULTIPLE DEVICE DATA BLOCKS (0 MEANS NONE)
	SPCSAV
				;GENERATE ANY SPECIAL DEVICES CUSTOMER IS SUPPLYING
				; WHICH DO NEED A CHANNEL SAVE ROUTINE

;END OF THE ASSIGNMENT TABLE

	INTNUM==INTTAB-.	;-LENGTH OF INTERRUPT CHANNEL ASSIGNMENT TABLE
SUBTTL NON-ZEROED DATA BASE
	IFLE	.-SYSEND, <LOC SYSEND+1>
				; SET LOC UP TO SYSEND+1, UNLESS ONCE ONLY CODE
				; IS BIGGER

;SPECIAL DEVICE SYMBOLS WHICH INVOLVE PI ASSIGNMENTS
; GOAL: MINIMIZE NO. OF SYMBOLS DEFINED HERE:
;
;    MAGTAPE PI SYMBOLS
IFG TAPN,<		;ANY MAGTAPES?

IFG TM10A+TM10B,<
	IFNDEF MTDCHN,<XP MTDCHN,0>
	XP MTAFLG,MT0CHN*10
	XP MTBOTH,MTAFLG
IFG TM10A,<
	XP MTBOTH,MTBOTH+MTDCHN
IFE M.KA10,<
	XP MTALOC,.EPMP+2*MTDCHN+40
>
IFN M.KA10,<
	XP MTALOC,2*MTDCHN+40
>
>>

    XP TAPCHN,MT0CHN
    XP TAPBIT,<1_<7-MT0CHN>>
> ;END IFG TAPN

;    DECTAPE PI SYMBOLS

IFN M.DTA!M.DTB,<
	XP DTBOTH,DADCHN*10+DTACHN	;2ND DECTAPE PI
	XP DTTURN,300200+DTBOTH
>

;	CDR PI ASSIGNMENTS
IFG M.CDR,<
	XP CRFCHN,CF0CHN
	XP CDRCHN,CR0CHN
>
;    LINE PRINTER PI SYMBOLS
DEFINE	FLAGS(N)<
	XP LP'N'BTH,LP'N'CHN*11
>
ZZ==0

REPEAT M.LPT,<
	FLAGS	\ZZ
ZZ==ZZ+1
>

;SCANNER PI SYMBOLS
	FSNCHN==SCNCHN*101	;PI FOR 630 FULL DUPLEX SCANNER
	XP SCNBIT,<1_<7-SCNCHN>>	;PI BIT TO TURN SCN PI ON/OFF
	XP SCNON,2000+SCNBIT	;CONO PI, TURNS SCANNER PI ON
	XP SCNOFF,1000+SCNBIT	;CONO PI, TURNS SCANNER PI OFF

;REMOTE SOFTWARE PI SYMBOLS


;    DISPLAY PI SYMBOLS
IFG M.DIS,<			;DISPLAY
IFE M.KA10,<
	XP DISBLK,.EPMP+40+2*DISCHN	;BLKI/BLKO LOCATION
>
IFN M.KA10,<
	XP DISBLK,40+2*DISCHN	;BLKI/BLKO LOCATION
>
	XP PENPIA,PENCHN*10	;PEN PI ASSIGNMENT FOR CONO
	XP DISBTH,DISCHN+PENPIA	;BOTH DIS AND PEN PIS FOR CONO
XP DISBIT,1
REPEAT	7-DISCHN,<XP DISBIT,DISBIT*2>
>

;SYSTEM CONSTANTS AND PARAMETERS

INTERNAL CNFTBL,CNFMXL,CONFIG,SYSTAP,SYSDAT,MEMNSP,FREPTR,LOCORE
INTERNAL OPRLDB,TTFREE,TTFREN,TTCLST,LINSAV,LINPTR,DLSRWD,CCIRWD
INTERNAL LASPOK,LASPUC,WHYCOD,TICSEC,TICMIN,NULJPC,RTCUPS

IFN FTMODM,<
	INTERNAL DSCPTR
>

CNFTBL:				;FIRST LOCATION OF MONITOR DATA STORAGE
				; RETURNED BE GETTAB UUO (THESE LOCATIONS
				; NOT CLEARED BY SYSINI)
				; CNFTBL IS GETTAB TABLE 11 (RH OF AC)
				; OCTAL NUMBERS IN () CORRESPOND TO GETTAB UUO AC'S LH
CONFIG:	SYSNAM
				;(0-4) NAME OF SYSTEM, IN ASCII
	LOC	CONFIG+5	;ALWAYS LEAVE 5 WORDS (24 CHARS)
				; SO GETTAB UUO WILL BE CONSTANT
SYSDAT:	SYSDAT
				;(5,6) GENERATE SYSTEM DATE
	LOC	SYSDAT+2	;ALWAYS LEAVE 2 WORDS SO GETTAB CONSTANT
SYSTAP:	SYSDEV
				;(7) NAME OF SYSTEM DEVICE, IN SIXBIT

;LOCATIONS SETUP BY ONCE ONLY OPERATOR DIALOGUE AND NEVER RESET ON RESTARTS

INTERNAL TIME,THSDAT,SYSSIZ,DEVOPR,DEVLST,SEGPTR,TWOREG,STATES,SERIAL,STBPTR,SEGPT1

TIME:	0			;(10) TIME OF DAY IN JIFFIES (60TH OR 50THS OF A SEC)
THSDAT:	0			;(11) TODAY'S DATE ((Y-1964)*12+(M-1))*31+(D-1)
SYSSIZ:	EXP	PAT##		;(12) SIZE OF MONITOR (FIRST LOC NOT USED)
DEVOPR:				;(13) SIXBIT PHYSICAL NAME OF OPERATORS CONSOLE
IFNDEF OPRLIN,<SIXBIT /CTY/>	;AT THE CENTRAL (PDP10) SITE
IFDEF OPRLIN,<OPRLIN;>;		; (IF THIS LOCATION CONTAINS 0, NONE HAS
				;  BEEN DESIGNATED)
				;PUBLIC LOGICAL NAME "OPR" WILL BE THIS DEVICE.
				; ALSO UNEXPLAINED MONITOR ERROR MESSAGES
				; WILL BE TYPED ON TTY OPR
DEVLST:	XWD	0,0		;(14) LH CONTAINS ADDRESS OF FIRST DEVICE DATA BLOCK
				; ONCE ONLY CODE LINKS DEVICE DATA BLOCKS
SEGPTR:	XWD	-SEGN,JOBN	;(15) AOBJN POINTER TO 1ST HIGH SEG IN JBTXXX TABLES
				; LH= - NUMBER OF HIGH SEGS,  RH= 1ST HIGH SEG NUMBER
TWOREG:	0			;(16) FLAG TO INDICATE WHETHER BOTH HARDWARE AND
				; SOFTWARE HAVE 2 RELOC REG CAPACITY
				; NON-ZERO IF BOTH DO, 0 IF EITHER OR BOTH DO NOT
				; SET BY ONCE ONLY CODE

;STATES WORD LH BITS:
	ZZ==0
	IFG	DSKN, <ZZ==ZZ!ST.DSK>	;1 IF DISK SYSTEM (ANALOGOUS TO FTDISK)
	IFG	SYS50N, <ZZ==ZZ!ST.SWP>	;1 IF SWAPPING SYSTEM (ANALOGOUS TO FTSWAP)
	IFG	LOGINN, <ZZ==ZZ!ST.LOG>	;1 IF LOGIN (ANALOGOUS TO FTLOGIN)
	ZZ==ZZ!ST.FTT			;1 FOR TTCALL, FULL DUPLEX
	IFN	FTPRV, <ZZ==ZZ!ST.PRV>	;1 IF PRIVILEGE FEATURE INCLUDED
	IFN	FT2REL, <ZZ==ZZ!ST.TWR>	;1 IF REENTRANT SOFTWARE
	IFN	LEVDN,<ZZ==ZZ!2B9>	;1 IF LEVEL D DISK SOFTWARE (ST.TDS)
	IFN	INDPPN,<ZZ==ZZ!ST.IND>	;1 IF INDEPENDENT PROJ-PROG NUMBERS
	ZZ==ZZ!ST.IMG			;1 FOR IMAGE, 8-BIT SCNSER
	IFG	CPUN-1,<ZZ==ZZ!ST.DUL>	;1 IF DUAL CPU SYSTEM
IFN FTDMRB,<ZZ==ZZ!ST.MRB>	;1 IF MULTIPLE RIBS

IFG	M.RTCA,<ZZ==ZZ!ST.HPT>	;1 IF HIGH PREC.TIME ACCT.
IFG	M.RTCO,<ZZ==ZZ!ST.EMO>	;1 IF EXCLUDE MON.OVERHED FROM USER RUN
IFG	M.RTX,<ZZ==ZZ!ST.RTC>	;1 IF MONITOR HAS REAL TIME CLOCK
	ZZ==ZZ!ST.MBF		;1 IF MONITOR BUILT TO HANDLE FOROTS

;STATES WORD RH BITS(INDICATE OPERATIONAL STATE OF SYSTEM):
;PATCHED BY SCHED COMMAND

		;1B35(ST.NLG) = NO LOGIN(EXCEPT FROM OPR)
		;1B34(ST.NRL) = NO LOGINS FROM REMOTE TTYS. DONT
		; ANSWER RINGING DATA SETS. "REMOTE" BIT IN
		; LINTAB IS SET BY MONGEN
		;1B33(ST.BON) = NO LOGINS EXCEPT BATCH JOBS EXCEPT FROM OPR
		;1B29(ST.ASS)=1 NO ASSIGN/INIT DEVICES
		;1B28(ST.NSP)=1 IF ANY JOB CAN UNSPOOL DEVICES
		;1B27(ST.NOP)=1 NO OPERATOR
		;1B26(ST.DDL)=1 NO DOWN LINE LOAD OF REMOTE DC71,DC72,DAS80'S

STATES:	EXP	ZZ!SCHEDN	;(17) BITS WHICH DEFINE TYPE OF SYSTEM IN LH
				; RH PATCHED BY MONITOR COMMAND TO
				; INDICATE OPERATIONAL STATE OF SYSTEM
SERIAL:	EXP	APRSN		;(20) SERIAL NUMBER OF CENTRAL PROCESSOR (APR)
MEMNSP:	EXP	NSPMEM		;(21) NANO-SEC PER MEMORY CYCLE
PTYCNF:	XWD	PTYOFS##,PTYN	;(22) PTY PARAMETERS FOR BATCH
FREPTR:	0			;(23) AOBJN WORD POINTING TO USE BIT MAP OF
				; MONITOR 4-WORD CORE BLOCKS. SET BY ONCE ONLY CODE
				; NEVER CHANGED WHILE MONITOR RUNS.
LOCORE:	0			;(24) LH=0, RH=ABS. ADR. IN MONITOR OF FIRST WORD OF
				; MONITOR TO BE ALLOCATED IN 4-WORD CHUNKS.
				; SET BY ONCE ONLY CODE AND NEVER CHANGED WHILE
				; MONITOR RUNS.
STBPTR:
	EXP	0		;(25) POINTER NOT USED WITH NETWORKS
OPRLDB:	0			;(26) LDB OF OPR TELETYPE
TTFREE:	0			;(27) FILLED IN AT ONCE TIME BY FREE LIST ADR
TTCLST:	XWD	TTCHKN##,0	;(30) NUMBER OF TTY CHUNKS, ADDRESS OF FIRST ONE
TTFREN:	0			;(31) NUMBER OF FREE TTY CHUNKS AT THE MOMENT
LINSAV:	0			;(32) POINTER TO CURRENT TTY SEEN BY COMMAND DECODER
LINPTR:	XWD MTTYLN##,LINTAB##	;(33) POINTER TO EXAMINE TTY LINE TABLE,
				; INCLUDING REMOTES
MONVER:	EXP	A00VER		;(34) VERSION OF MONITOR (LH FOR CUSTOMER)
IFN FTMODM,<
DSCPTR:	XWD MDSLN##,DSCTAB##	;(35) POINTER TO DATASET CONTROL TABLE
>
IFE FTMODM,<0>
DLSRWD:	0			;(36) LAST RECEIVE INTERRUPT FROM DC10
CCIRWD:	0			;(37) LAST RECEIVE INTERRUPT FROM 680
SEGPT1:	EXP	JOBN		;(40) LAST DORMANT SEG NUMBER THROWN AWAY
				; TO FREE UP A SEG NUMBER.
LASPOK:	0			;(41) CONTAINS ADR. OF LAST LOCATION CHANGED
				; IN MONITOR BY A SUCCESSFUL POKE UUO.  (NOT CLEARED
				; ON 403 RESTART SINCE CHANGE IS STILL VALID
LASPUC:	0			;(42) RH=COUNT OF NUMBER OF SUCCESSFUL POKE UUOS
				; SINCE SYSTEM WAS LOADED.
				; LH=JOB NO. OF LAST JOB WHICH
				; SUCCEEDED IN CHANGING MONITOR VIA POKE
				; THE TWO ABOVE LOCATIONS ARE USEFUL
				; IN CRASH ANALYSIS AND FOR DAEMON LOGGING
WHYCOD:	0			;(43) CONTAINS SIXBIT UNABBREVIATED OPERATOR ANSWER
				; FOR WHY RELOAD ONCE ONLY QUESTION.  SEE ONCE (WHYTAB)
				; FOR A LIST OF POSSIBLE CODES.  0 MEANS FTWHY=0 SO NO
				; QUESTION
TICSEC:	JIFSEC			;(44) CONTAINS NUMBER OF TICKS PER SECOND
				; SET AT ONCE ONLY TIME BY MEASURING LINE
				; FREQUENCY (50 OR 60 HERTZ)
IFE FTPDBS,<
PDBPTR:	XWD	0,JBTPDB	;(45) RH=POINTER TO TABLE OF PDB'S FOR JOBS
				; LH=0 FOR FUTURE EXPANSION
>
IFN FTPDBS,<
PDBPTR:	XWD	-JOBN,JBTADR-JOBN ;(45) RH=POINTER TO PDB'S
				; LH=-JOBN AS A FLAG
>
RTCUPS:	0			;(46) RESOLUTION (UNITS/SEC.) OF CLOCK
				; USED FOR RUN TIME ACCT.
				; SET & CHANGED BY SETIME
SYSCHN::XWD	CHN0CB##,0	;(47) LH=ADR OF FIRST CHANNEL (DF10) DATA BLOCK, RH=UNUSED
			;LOGMAX...BATMIN CHANGED WITH SETUUO
			;  ENFORCED BY LOGIN (MONITOR ONLY STORES THESE
			;  NUMBERS FOR LOGIN)
LOGMAX::M.JMAX			;(50) MAX.# JOBS ALLOWED TO BE LOGGED IN
BATMAX::M.BMAX			;(51) MAX.# BATCH JOBS ALLOWED
BATMIN::M.BMIN			;(52) MIN.# BATCH JOBS GARENTEED (RESERVED)
DATE::	0			;(53) DATE TIME IN NEW FORMAT
				; LH = DAYS SINCE NOV. 17, 1858,
				; RH = FRACTION OF A DAY (GMT)
LOGNUM::0			;(54) NUMBER JOBS CURRENTLY LOGGED IN
BATNUM::0			;(55) NUMBER BATCH JOBS CURRENTLY LOGGED IN.
LOCYER::0		;(56) LOCAL YEAR
LOCMON::0		;(57) LOCAL MONTH (1,2,...,12)
LOCDAY::0		;(60) LOCAL DAY OF MONTH (1,2,3,...)
LOCHOR::0		;(61) LOCAL HOUR (MIDNIGHT=0)
LOCMIN::0		;(62) LOCAL MINUTE (0,1,...,59)
LOCSEC::0		;(63) LOCAL SECOND (0,1,...,59)

GMTDIF::0			;(64) DIFFERENCE BETWEEN LOCAL AND GMT TIME.
			; IN SAME UNITS AS DATE --
			; E.G. DATE + GMTDIF = LOCAL DATE-TIME
			; (LH = DAY, RH = FRACT. OF DAY)
DEBUGF::DEFDEB		;(65) DEBUGGING STATES WORD - SIGN BIT=1 IF SYSTEM PROG IS
			; DEBUGGING MONITOR (SPEED UP ONCE ONLY)
			; BIT1=1 TO RELOAD ON DEBUG STOPCD'S
			; BIT2=1 TO RELOAD ON STOPCD'S WHICH ONLY
			; AFFECT 1 JOB
			; BIT3=1 TO DISABLE AUTO-RELOADS
			; BIT4=1 TO STOP SYSTEM IF CPU1 HALTS
FRUSED::0		;(66) AMOUNT OF FREE CORE IN USE
			; (FTRSP CONDITIONAL)
RCCMAX::0		;(67) NUMBER OF BYTES IN TTY CHUNKS
CNFCVN:	A00CVN		;(70) CUSTOMER VERSION (=C(136))
CNFDVN:	AXXDVN		;(71) DEC VERSION (=C(137))
CNFCHN::EXP	M.CHN	;(72) NUMBER OF DF10 DATA CHANS.
CNFRTD::EXP	M.RTD	;(73) NUMBER OF REAL TIME DEVICES
CNFHPQ::EXP	M.HPQ	;(74) NUMBER OF HPQ'S
CNFLDB::EXP	DDBLDB##  ;(75) WORD IN TTY DDB WHICH POINTS TO LDB
CNFMVO::EXP	^D510*4*M.PSI  ;(76)MAX. VECTOR OFFSET FOR PISYS. UUO
CNFMIP::0		;(77)MAX. PRIORITY FOR PSISER
IFG TAPN,<
CNFMTA::XWD	TUBRID##,MT0DDB##  ;(100) POINTER TO FIRST MTA DDB AND INDEX
				   ; OF START OF DAEMON INFORMATION
>
IFE TAPN,<
CNFMTA::0
>

CNFET1:	EXP	JOBDAC##+T1	;(101) EXEC AC1 IN USER'S ADDRESS SPACE
CNFLSD:	EXP	DEVLSD		;(102) LENGTH OF SHORT DDB
CNFLLD:	EXP	DEVLLD		;(103) LENGTH OF LONG DDB
CNFLDD:	EXP	DDBLEN##	;(104) LENGTH OF DISK DDB
CNFEXM:	EXP	JOBEXM##	;(105) WORD IN JOBDAT WHICH HOLDS ADDRESS OF
				;      LAST EXAMINE OR DEPOSIT.

	ZZ==0
IFN M.KI10!M.KL10,<ZZ==ZZ!1B35>	;BIT 35=1 IF SWAP SPACE ALLOCATED IN PAGES
IFN M.TM10,<ZZ==ZZ!1B34>	;BIT 34=1 IF MTA ERROR REPORTING
IFN FTVM,<ZZ==ZZ!1B33>		;BIT 33=1 IF VM MONITOR
IFN M.IPCF,<ZZ==ZZ!1B32>	;BIT 32=1 IF IPCSER IS LOADED
IFN M.PSI,<ZZ==ZZ!1B31>		;BIT 31=1 IF PSISER IS LOADED
IFN M.MSG,<ZZ==ZZ!1B30>		;BIT 30=1 IF MSGSER IS LOADED
ZZ==ZZ!1B29			;BIT 29=1 IF NON-SUPER ENTER
				; IS SUPPORTED
IFN FTNSCHED,<ZZ==ZZ!1B28>	;BIT 28=1 IF NEW SCHEDULER IS PRESENT
IFN M.EQDQ,<ZZ==ZZ!1B27>	;BIT 27 IF ENQ/DEQ IS LOADED
IF2, <ZZ==ZZ!<<ZGAL>B26>>	;BIT 26=1 IF MONITOR CONTAINS GALAXY-10 FEATURES
ZZ==ZZ!1B25			;BIT 25=1 MONITOR SUPPORTS MASSBUS ERROR REPORTING
ZZ==ZZ!1B24			;BIT 24=1 IF NEW TAPSER
ZZ==ZZ!1B23			;BIT 23=1 IF NEW ERROR REPORTING
ZZ==ZZ!1B22			;BIT 22=1 IF MONITOR SUPPORT MORE THAN 127 JOBS.
IFN  M.EXE,<ZZ==ZZ!1B21>	;BIT 21=1 IF "SAVE" COMMAND PRODUCES EXE FILE
IFN M.EMRT,<ZZ==ZZ!ST%EMR>	;BIT 20=1 IF EBOX/MBOX RUNTIME IS IN EFFECT (KL ONLY)
IFN M.XPI,<ZZ==ZZ!ST%XPI>	;BIT 19=1 IF PI TIME IS EXCLUDED FROM USER
				; RUNTIME (KL ONLY)
ZZ==ZZ!1B18			;BIT 18=1 IF FULL 6CHAR DEVICE NAMES
IFN M.ITA,<ZZ==ZZ!ST%ITA>	;BIT 17=1 IF INTERVAL TIMER ON KL10 IS AVAILABLE
ZZ==ZZ!1B15			;BIT 15=1 MONITOR SUPPORTS 6.03 ERROR REPORTING
CNFST2::EXP	ZZ		;(106) FLAG BITS DEFINED ABOVE
PISYMN:EXP	M.PSI*C$MIN	;(107) MINIMUM CONDITION FOR PISYS.UUO
	ZZ==0
IFN M.PSI,<ZZ==PITSIZ##>
PITLEN:EXP	ZZ		;(110)LENGTH OF PI TABLE
CNFPIA::EXP	JBTPIA		;(111)ADDRESS OF JBTPIA
%CNMNT:	BYTE	(1)0(17)0(6)1(6)0(6)0	;(112) TYPE OF MONITOR
					;    (1)=STRANGE
					;    (17)=RESERVED TO DEC
					;    (6)=TYPE:	1=TOPS-10
					;		2=I.T.S.
					;		3=TENEX
					;		REST RESERVED TO DEC
					;    (6)=SUBTYPE (RESERVED TO DEC)
					;    (6)=RESERVED TO CUSTOMERS

IFN M.CDR,<
CR0DDB,,CDRCNT##		;(113)OFFSET TO CARD COUNT FOR CDR
>
IFE M.CDR,<
	EXP	0
>
IFN M.CDP,<
CDPDDB##,,CDPCTO##		;(114)OFFSET TO CARD COUNT FOR CDP
>
IFE M.CDP,<
	EXP	0
>
EXP	PAGSIZ			;(115)BASIC UNIT OF CORE ALLOCATION
EXP	MINMAX			;(116)MIN VALUE FOR CORMAX
EXP	M.CLSN			;(117)NUMBER OF SCHEDULER CLASSES
EXP	0			;(120)EXPONENTIAL FACTOR USED IN COMPUTING USER TIME
SYSORG::	0		;(121)
SYSLEN::	0		;(122)
NWCORE::2000*M.NKC		;(123)NUMBER OF WORDS OF CORE
NXMPTR::0			;(124)AOBJN POINTER TO NXMTAB USED TO SCAN FOR ZEROES
IFN M.NET,<
	EXP	NETNDB##	;(125)POINTER TO THE FIRST NODE BLOCK
>
IFE M.NET,<
	EXP	0		;(125)NO POINTER IF NO NETWORKS
>
IFG TAPN,<
CNFTKB:	EXP	TKBCDB##	;(126)POINTER FROM KDB TO CDB FOR MAGTAPES
>
IFLE TAPN,<
CNFTKB:	EXP	0		;(126)IF NO MAGTAPES
>
IFN FTACCT,<
	EXP	DDCOFS##	;(127)OFFSET INTO TTY DDB'S WHERE CHARACTER
				; COUNTS ARE STORED
>
IFE FTACCT,<
	0			;(127)NOT IMPLEMENTED
>
HNGLST::XWD	0,0		;(130)LH IS ADDRESS OF FIRST DEVICE WHICH SHOULD BE
				; CHECKED TO SEE IF IT IS HUNG
EXP	BOOTXT			;(131) ADDRESS OF RELOAD CCL TEXT
IFG TAPN,<
EXP	TUBDDB##		;(132) OFFSET OF DDB PTR'S IN TUB
CNFMTK::EXP	MT0KDB##	;(133) 1ST MTA KDB IN SYS
>
IFE TAPN,<
	Z
CNFMTK::EXP	0
>
;----------------------------------
;INSERT HERE ANY NEW LOCATIONS OF INTEREST WHICH ARE SET UP BY ONCE ONLY CODE.
; OR ARE CONSTANTS WHICH ARE NOT CLEARED AT STARTUP
;-------------------------------------
CNFMXL==<.-CNFTBL-1>B26		;MAXIMUM ENTRY IN CNFTBL FOR GETTAB UUO
IFE M.NET,<IFN FTNET+FTCMSR,<
	.NTMXL==:0		;THIS LETS UUOCON'S GETTABS
NETGTT::0			; LOAD WITHOUT UNDEFINED GLOBALS
>>

TICMIN:	JIFMIN			;NUMBER OF TICKS PER MINUTE (CALCULATED BY ONCE)
TIMLST::0			;VALUE OF "TIME" LAST TIME AT CLOCK LEVEL
				; USED FOR ALL TIMING FUNCTIONS, E.G.,
				; MAINTAINING CLOCK QUEUE AND SMITHSONIAN DATE
IFN M.KA10,<
NULJPC:	EXP	XC.USR+2	;PC FOR THE NULJOB
>
IFN M.KI10,<
NULJPC:	EXP	XC.USR+IC.LIP+2	;PC FOR THE NULL JOB (NULL JOB RUN IN
				; PUBLIC USER MODE)
> ;END FTKI10
IFN FTKL10,<
NULJPC::EXP	XC.USR+IC.LIP+1	;PC FOR THE NULL JOB
>
IFN FTKI10!FTKL10,<
LOWLOC::0
LOWLEN==<IOWNUM+^D143>/^D144
LOWPTR::XWD	-LOWLEN,LOWTAB
LOWTAB:	BLOCK	LOWLEN
> ;END FTKI10!FTKL10
NXMTBL==:<CORBLK+^D35>/^D36
NXMTAB::BLOCK	NXMTBL		;TABLE USED TO RECORD WHICH PAGES OF MEMORY EXIST
CORLIM::EXP	USRLIM
IFN M.TM02&FTKL10,<
TT2IVO::XWD	744000,40+2*TAPCHN	;INTERRUPT LOC FOR TM02 ON RH20
>
;GETTAB TABLE OF QUEUE CODES FOR JOBS - TABLE(RH)=25
;MUST BE A SEPARATE TABLE SINCE THE NUMBER OF ENTRIES VARIES ACCORDING
;TO THE CONFIGURATION

;ENTRIES ARE 2 SIXBIT CHARACTERS, THREE PER WORD
;STATE CODE 0 IS LEFT THIRD, 1 IS MIDDLE THIRD, 2 IS RIGHT THIRD OF FIRST WORD
;STATE CODE 3 IS LEFT THIRD OF SECOND WORD, ETC.

INTERN STSTBL,STSMXL

STSTBL:

DEFINE X(A,B,C)
<	IFE ZZ-ZZ/3*3-0,
	<	  XX==   <SIXBIT /A/&7777B11>B35>
	IFE	ZZ-ZZ/3*3-1,
	<	  XX==XX!<SIXBIT /A/&7777B11>B47>
	IFE	ZZ-ZZ/3*3-2,
	<	  XX==XX!<SIXBIT /A/&7777B11>B59
	  EXP XX>
ZZ==ZZ+1
>

ZZ==0
	QUEUES
	RWAITS
	CODES
	IFN	ZZ-ZZ/3*3-0,<
	  EXP XX>

STSMXL==<.-STSTBL-1>B26		;MAX ENTRY IN STSTBL FOR GETTAB UUO
IFG DSKN, <

INTERNAL ODPTBL,ODPMXL,SWPHGH,K4SWAP,PROT,PROT0

ODPTBL:!			;FIRST LOCATION IN MONITOR DATA AREA FOR DISK-
				; RELATED LOCATIONS WHICH ARE NOT SET TO 0 WHEN 
				; THE SYSTEM IS STARTED UP.
				; ODPTBL IS GETTAB UUO TABLE NUMBER 15.

SWPHGH:	0			;(0) HIGHEST LOGICAL BLOCK # ASSIGNED FOR SWAPPING.
				; SPACE IS ASSIGNED FROM HIGHEST BLOCK # DOWNWARDS.
K4SWAP:	0			;(1) # OF K OF DISK WORDS SET ASIDE FOR SWAPPING.
				; ASSIGNED AT ONCE ONLY REFRESH TIME.

IFE SYS50N, <KXFTIM==0
SEEKTM==0			;DEFAULT VALUES FOR 10/40 DISK SYSTEM.>
IFN LEVDN,<KXFTIM==0		;SET PROTECT TIMES TO 0
SEEKTM==0			;ONCE ONLY CODE MUST SET PROT,PROT0
				;DEPENDING ON FASTEST UNIT USED FOR SWAPPING
>
PROT:	EXP	0		;(2) IN-CORE PROTECT TIME PARAMETER TO BE
				; MULTIPLIED BY <K-1> OF CORE IN JOB.
PROT0:	EXP	0		;(3) IN-CORE PROTECT TIME PARAMETER TO 
				; BE ADDED TO ABOVE RESULT.
PROT1::	EXP	0		;(4) SWAPPABLE CYCLING TIME
				; DUE TO TIME SLICE EXPIRATION.
PROTM::	EXP	0		;(5) MAXIMUM IN-CORE PROTECT TIME.


	;INSERT HERE ANY NEW LOCATIONS OF INTEREST WHICH ARE SET UP BY
	; ONCE ONLY CODE AND WHICH PERTAIN ONLY TO DISK SYSTEMS.

ODPMXL==<.-ODPTBL-1>B26		;MAXIMUM ENTRY IN ODPTBL FOR GETTAB UUO

;DISK LOCATIONS NOT IN GETTAB

INTERN REFLAG

REFLAG:	Z			;FLAG LOCATION TO INDICATE WHETHER ANY REFRESHING
				; OCCURRED AND TO CONTAIN THE [PROJ,PROG]
				; NUMBERS FOR AUTOMATIC LOG-IN FOLLOWING REFRESH.

>	;END IFG DISKN CONDITIONAL
;MORE DATA LOCATIONS SETUP AT ASSEMBLY TIME OR ONCE ONLY TIME
; BUT NOT OF INTEREST TO USER PROGRAMS

	INTERNAL XJBPFI,PMONTB,MONTAB,MIDNIT

	EXTERNAL JOBPFI

	$HIGH
XJBPFI:	XWD	JOBPFI,0	; JOBPFI==HIGHEST LOC, IN USER JOB DATA AREA
				; PROTECTED FROM I/O
;MONTH TABLE FOR DAYTIME COMMAND PRINTING

PMONTB:	POINT	6,MONTAB(T1),5	;POINTER TO NUMBER OF DAYS IN MONTH
MONTAB:	EXP	^D30B5+"Jan"
	EXP	^D27B5+"Feb"
	EXP	^D30B5+"Mar"
	EXP	^D29B5+"Apr"
	EXP	^D30B5+"May"
	EXP	^D29B5+"Jun"
	EXP	^D30B5+"Jul"
	EXP	^D30B5+"Aug"
	EXP	^D29B5+"Sep"
	EXP	^D30B5+"Oct"
	EXP	^D29B5+"Nov"
	EXP	^D30B5+"Dec"
MIDNIT:	EXP	0		;NO OF JIFFIES TILL MIDNIGHT (CALCULATED BY ONCE)
	$ABS
;TABLE OF SCHEDULER STATISTICS (CAN BE USED TO HELP TUNE SYSTEM)

.GTSST::!			;SCHEDULER STATISTICS TABLE - #115


FORCFC::0			;(0)COUNT OF TIMES SCHEDULER RAN A JOB
				;OUT OF ORDER SO THAT IT WOULD RELEASE
				;A SHARABLE RESOURCE IN ORDER THAT IT
				;COULD BE SWAPPED OUT.

UNWNDC::0			;(1)COUNT OF TIMES SCHEDULER RAN A JOB
				;OUT OF ORDER BECAUSE ANOTHER JOB HAS BEEN
				;SELECTED THAT NEEDS A SHARABLE DISK
				;RESOURCE THE FIRST JOB OWNED

SWPNUL::0			;(2)SWAPPER NULL TIME (TIME WHEN SWAPPING
				;LOGIC COULD NOT FIND ANYTHING TO DO.)

SWPLOS::0			;(3)SWAPPER LOST TIME (TIME THAT SWAPPER
				;WANTED TO SWAP A JOB IN BUT COULDN'T

RQCNT::0			;(4)NUMBER OF PHYSICAL REQUEUES SINCE 
				;SYSTEM STARTUP

MCUINT::0			;(5)INTERVAL AT WHICH MINIMUM CORE
				;USAGE FUNCTION IS CALCULATED.
				;ZERO MEANS DO NOT CALCULATE

SCDINT::0			;(6)MICRO SCHEDULING INTERVAL. ZERO
				;MEANS RUN ROUND ROBIN IGNORING CLASSES.

AVJSIZ::0			;(7)AVERAGE JOB SIZE COMPUTED ONCE A MINUTE

TOTRTC::0			;(10)TOTAL RUNTIME GIVEN TO ALL SUBCLASSES
				;DOES NOT INCLUDE ANY PQ1 OR HPQ TIME

SCDEXF::0			;(11)EXPONENTIAL FACTOR USED FOR COMPUTING
				;EXPONENTIALLY AVERAGED RUNTIME FOR
				;CPU CLASSES

UTMEAR::0			;(12)EXPONENTIALLY AVERAGED USER TIME USED
				;FOR THE ENFORCEMENT OF QUOTAS

RTCTOT::0			;(13)TOTAL USER RUNTIME SINCE LAST
				;SCHED UUO SET CLASS PARAMETERS

DEFCLS::M.DCLS		;(14)DEFAULT CLASS FOR NEW JOBS

SCDJIL::0			;(15)PERCENT OF TIME SCHEDULER SCANS
				;JUST SWAPPED IN QUEUE BEFORE SUBQUEUES

SCDSWP::0			;(16)MINIMUM NUMBER OF TICKS
				;SWAPPER SCANS THE SAME PRIMARY SUBQUEUE

BBSUBQ::0			;(17)BACKGROUND BATCH SUBQUEUE

SCDBBS::0			;(20)NUMBER OF TICKS BETWEEN
				;BACKGROUND BATCH SWAPS

SCDIOF::0			;(21)PERCENT OF TIME THAT SWAPPER SCANS PQ2
				;INCORE CHAIN BEFORE OUTCORE CHAIN

SCDSET::0			;(22)FLAG = 0 IF RUNNING ROUND ROBIN
				;= DATE/TIME WHEN CLASS RUNTIME TABLE
				;INITIALIZED IF RUNNING IN CLASS MODE.

RRFLAG::0			;(23)FLAG = 0 IF RUNNING ROUND ROBIN SCHEDULER.
				;= CNTSTS IF CLASS SCHEDULING

SCDCOR::0			;(24)TIME TO WAIT AFTER SWAPPING OUT
				;A RUNNABLE JOB BEFORE SETTING CORSCD FLAG

SSDMXL==:<.-.GTSST-1>B26	;MAXIMUM LENGTH OF TABLE FOR GETTABS
;IPCF COMMON DATA

IFN FTIPCF,<
IFN M.IPCF,<

IFNDEF M.PIDN,<XP M.PIDN,JOBN*2>
XP MIDMXL,<<M.PIDN>B26>		;FOR GETTAB

PIDMSK==JOBN
IFG <M.PIDN-JOBN>,<PIDMSK==M.PIDN>  ;MAX (JOBN,M.PIDN)
PIDMSK==<1B<^L<PIDMSK>-1>>-1	;MAKE INTO MASK
%IPCLS==:^D36-^L<PIDMSK>	;DEFINE NUMBER OF BITS IN MASK
%IPMPL==:12			;MAXIMUM PACKET LENGTH
PIDTAB::XWD	IPCPID,0	;INITIALLY IPCPID IN TABLE
	XWD	SYSPID,0
	XP	%IPCNS,2	;NO. OF SYSTEM PROCESSES
	XLIST
	REPEAT <M.PIDN-1>,<Z>	;REMAINDER OF TABLE ZERO
	LIST

IPCPID:	Z			;.EPIPC
	Z			;.EPIPA
	XWD	200000,-1	;.EPIPQ
	EXP	IPCFPR##	;.EPADR
SYSPID:	Z
	Z
	XWD	200000,-1
	EXP	IPCSPR##
INFMSG::BLOCK	2		;BUILD MSGS TO INFO
IFN FTFDAE,<
FILMSG::BLOCK	12
>

EXTERNAL IPCSER			;LOAD UUO HANDLER

IPCTAB::			;MISCELLANEOUS IPCF DATA
%CNIPL::EXP	%IPMPL		;(0) MAX PACKET LENGTH
%CNIPI::Z			;(1) MID OF SYS:INFO (0=NONE)
%CNIPQ::XWD 200000,002005	;(2) DEFAULT QUOTA
%CNIPS::Z			;(3) TOTAL PACKETS SENT
%CNIIP::Z			;(4) NUMBER OF PACKETS OUTSTANDING
%IPCFP::XWD	IPCPID,0	;(5) PID OF [SYSTEM] IPCC
%IPCPM::	PIDMSK		;(6) MASK FOR PID
%IPCMP::	M.PIDN		;(7) LENGTH OF PID TABLE
%IPCNP::	2		;(10) CURRENT NUMBER OF PID'S
%IPCTP::	2		;(11) TOTAL PID'S SINCE RELOAD
%CNPIC::Z			;(12) NUMBER OF IPCF PAGES CURRENTLY IN CORE
%IPCSP::XWD	SYSPID,1	;(13) PID OF [SYSTEM]GOPHER

IPCMXL==:<.-IPCTAB-1>B26	;FOR GETTAB
.GTSID::			;SPECIAL PID TABLE
%SIIPC::XWD	IPCPID,0	;(0) IPCC
%SIINF::Z			;(1) [SYSTEM] INFO
%SIQSR::Z			;(2) [SYSTEM] QUASAR
%SIMDA::Z			;(3) MOUNT DEV ALLOCOTOR
%SITLP::Z			;(4) MAGTAPE LABELING PROCESS
%SIFDA::Z			;(5) FILE DAEMON
%SIMDC::Z			;(6) MOUNTABLE DEV CO-ORDINATOR
%SIACT::Z			;(7) [SYSTEM]ACCOUNTING
%SIOPR::Z			;(10) OPERATOR INTERFACE PROCESS
%SISEL::Z			;(11) SYSTEM ERROR LOGGER
SIDMXL==:<.-.GTSID-1>B26	;SIZE FOR GETTTAB
SIDJOB::BLOCK	<SIDMXL/1000>+1
MDAJOB=:SIDJOB+<%SIMDA-.GTSID>
FDAJOB=:SIDJOB+<%SIFDA-.GTSID>
MDCJOB=:SIDJOB+<%SIMDC-.GTSID>
ACTJOB=:SIDJOB+<%SIACT-.GTSID>
>>
IFE FTIPCF,<
IFN M.IPCF,<

PRINTX ? PLEASE ASSEMBLE SOURCES WITH FTIPCF=-1
>>

IFE M.IPCF,<

XP UIPCFR,CPOPJ			;MAKE IPCF UUOS LOOK UNIMPLEMENTED
XP UIPCFS,CPOPJ
XP UIPCFQ,CPOPJ
XP IPCFRS,CPOPJ			;DO NOTHING ON RESET UUO

XP IPCLGO,CPOPJ			;DO NOTHING ON LOGOUT UUO
XP MIDMXL,0			;MAKE GETTABS FAIL
XP IPCMXL,0
XP PIDTAB,0
XP IPCTAB,0
XP SIDMXL,0
XP .GTSID,0
XP .IPCTL,0			;NO MESSAGE CODE FOR TAPE LABELING
XP FILMSG,0
XP .IPCFP,0
XP .IPCFD,0

XP SPBMAX,0
XP SPBCOR,0
FDAJOB::
MDAJOB::
MDCJOB::
%CNPIC::
%SIFDA::
%SIIPC::
%SIINF::
%SIQSR::
%SIMDA::
%SITLP::Z			;ALL THOSE WHO DO SKIPE %SIXXX

XP STRSIG,CPOPJ			;MAKE IPCF CALL FOR PSISER
XP SENDSN,CPOPJ			;MAKE IPCF CALL FOR TAPUUO
XP QSRSPL,CPOPJ			;MAKE IPCF CALL FOR FILUUO
XP SENDSP,CPOPJ
XP SNDMDC,CPOPJ
XP QSRLGI,CPOPJ
>
;36 BITS 1 PER WORD
	$HIGH
BITTBL::
SALL
	ZZ==1B0
REPEAT ^D36,<
	EXP ZZ
	ZZ==ZZ_<-1>
>
XALL
	$ABS
;ENQUEUE/DEQUEUE COMMON DATA


IFE FTEQDQ,<
HSHTAB==:0			;DEFINE FOR SYSINI
>
IFN FTEQDQ,<
IFN M.EQDQ,<
HSHLEN==:2*JOBMAX		;SIZE OF HASH TABLE
HSHTAB::	BLOCK HSHLEN


EXTERNAL QUESER			;LOAD THE UUO HANDLER


.EQTAB::
%ENQML:: EXP EQMXCH##		;MAXIMUM CHARACTER SIZE OF STRING
%ENQNQ:: Z			;NUMBER OF ACTIVE QUEUES
%ENQTE:: Z			;TOTAL NUMBER OF ENQ'S SINCE RELOAD
%ENQTD:: Z			;TOTAL NUMBER OF DEQ'S SINCE RELOAD
%ENQNP:: Z			;NUMBER OF ACTIVE POOLED RESOURCES
%ENQDF:: EXP ^D20			;DEFAULT ENQ QUOTA

ENQMXL==:<.-.EQTAB-1>B26	;FOR GETTAB

>>;END OF IFN FTEQDQ CONDITIONAL


IFE M.EQDQ,<
XP	ENQ,CPOPJ
XP	DEQ,CPOPJ
XP	ENQC,CPOPJ		;MAKE ALL OF THESE GIVE ERROR RETURNS
XP	ENQRST,CPOPJ		;RESET
XP	ENQCLS,CPOPJ1		;CLOSE
XP	ENQMXL,0
XP	ENQTAB,0
XP	.EQTAB,0
XP	HSHTAB,0
XP	HSHLEN,0
>;END OF IFE M.EQDQ CONDITIONAL


IFE FTEQDQ,<
IFN M.EQDQ,<

PRINTX	?PLEASE ASSEMBLE SOURCES WITH FTEQDQ=-1

>>
;TABLE OF MAPPINGS FROM 2-CHARACTER DEVIDE NAMES
; TO 3-CHARACTER NAMES. EACH 2-CHAR NAME IS IN
; RIGHT OF WORD AND 3-CHAR EQUIVALENT IS
; IN LEFT HALF.
;

	$HIGH
SPCTAB::XWD	'LPT','LP '	;LINE PRINTER
	XWD	'CDP','CP '	;CARD PUNCH
	XWD	'CDR','CR '	;CARD READER
	XWD	'PTP','PP '	;PAPER-TAPE PUNCH
	XWD	'PTR','PR '	;PAPER-TAPE READER
	XWD	'SYS','SY '	;SYSTEM DEVICE
	XWD	'TTY','TT '	;TELETYPE

STEND==:.
STLEN==:STEND-SPCTAB
	$ABS
;TABLE OF GENERIC DEVICE NAMES USED TO SPEED UP
; GENERIC DEVICE SEARCH
;
;THE LEFT HALF OF EACH WORD IS THE SIXBIT GENERIC DEVICE NAME.
;THE RIGHT HALF IS A PTR TO THE 1ST DDB OF THAT TYPE OF DEVICE.
;SINCE THE DDB'S ARE SORTED BY SYSINI, THIS REDUCES THE AMOUNT
; OF TIME NEEDED TO SEARCH FOR A PARTICULAR DEVICE NAME.

DEFINE GNRIC(DEV),<
	IFNDEF M.R'DEV,<M.R'DEV==0>	;DEFINE REMOTE DEVICES
	IFNDEF M.D'DEV,<M.D'DEV==0>	;DEFINE RSX-20F DEVICES
	IFN M.'DEV+M.R'DEV+M.D'DEV,<
	XLIST
	SIXBIT	/DEV/
	LIST
	>>

DEFINE TGNRIC (X),<<SIXBIT /MTA/>+X_^D18>
DEFINE TCOUNT (X) <IFE M.MT'X'T-4,<
	TAPCNT==TAPCNT+M.MT'X'U-1
>>
TAPCNT==TAPN
..KON==0
REPEAT TAPN,<TCOUNT(\..KON)
	     ..KON==..KON+1>

GENTAB::
	GNRIC(DTA)	;DECTAPE (MUST PRECEDE DTB)
	GNRIC(DTB)	;"
IFG TAPN,<
	..KON==0
	REPEAT TAPCNT,<TGNRIC (\..KON)
		     ..KON==..KON+1>
	>
	GNRIC(LPT)	;LINE PRINTER
	GNRIC(PTP)	;PAPER-TAPE PUNCH
	GNRIC(PTR)	;  "     "  READER
	GNRIC(PLT)	;PLOTTER
	GNRIC(PTY)	;PSEUDO-TTY
	GNRIC(CDP)	;CARD PUNCH
	GNRIC(CDR)	;CARD READER
IFN FTDAS78,<
	GNRIC(XXI)	;XXI DEVICE
	GNRIC(XXO)	;XXO DEVICE
>	;END IFN FTDAS78

GTLEN==:GTEND-GENTAB
GTEND::
	$ABS
;GALAXY-10 PARAMETERS

DEFINE GPARM(Z1),<
IFE Z1,<
ZGAL==0
>>
IFE FTGALAXY,<
ZGAL==0
>

IFN FTGALAXY,<
ZGAL==1
GPARM(M.IPCF)
GPARM(M.PSI)
GPARM(FTVM)
GPARM(M.PTY)
GPARM(FTSPL)
GPARM(FT5UUO)
	IFN	FTIPCF,<
	IFN	M.IPCF,<
IFG ^D10-%IPMPL,<ZGAL==0>



QSRMSG::BLOCK	^D11		;BLOCK TO BUILD MESSAGES
	BLOCK	^D11		;SPACE FOR SPOOLING PARAMETER BLOCK
>>
>

;DEFINE IPCF SYMBOLS IF NOT AROUND
IFE FTIPCF,<
	XP	QSRSPL,CPOPJ
>

ISGALX::0
	$HIGH
IFN FTSPL,<
;TABLE FOR SPOOLING DEVICES
	INTERNAL	SPLTAB,SPLTOP,SPLNAM,SPLBIT,SPLLEN
SPLNAM==0			;NAME OF SPOOLING DEVICE
SPLBIT==2			;SPOOLING BIT
SPLLEN==DEVMOD+1		;LENGTH OF EACH ENTRY
;NOTE THAT WORD 1 (DEVCHR) MUST BE 0
SPLTAB:	SIXBIT	.LPT.
	0
	XWD	.TYLPT/.TYEST,.SPLPT
	0			;NO REAL DEVSER
LPTMOD==1_A+1_AL+1_I
	XWD	DVOUT+DVLPT,ASSCON!ASSPRG!LPTMOD
	SIXBIT	.PLT.
	0
	XWD	.TYPLT/.TYEST,.SPPLT
	0
	XWD	DVOUT,ASSCON!ASSPRG!14403
	SIXBIT	.CDP.
	0
	XWD	.TYCDP/.TYEST,.SPCDP
	0
	XWD	DVOUT+DVCDR,ASSCON!ASSPRG!14403
	SIXBIT	.PTP.
	0
	XWD	.TYPTP/.TYEST,.SPPTP
	0
	XWD	DVOUT+DVPTP,ASSCON!ASSPRG!14403
	SIXBIT	.CDR.
	0
	XWD	.TYCDR/.TYEST,.SPCDR
	0
SPLTOP:	XWD	DVIN+DVCDR,ASSCON!ASSPRG!14403
>
	$ABS

	$ABS
IFN FTMS,<
IFN M.KA10,<
SYSTRT:	SKPCPU	(0)		;SKIP IF THIS IS CPU0
	JRST	SPRINI		;CPU1, GO START IT GOING
	JSP	T1,TWOCHK	;CHECK IF THIS IS REALLY THE
				; SECOND PROCESSOR WITH THE TRAP
				; OFFSP7 SWITCH SET WRONG
>
IFN M.KI10!M.KL10,<
SYSTRT:	JSP	T4,SYSTR0	;SEE WHICH CPU THIS IS AND SETUP THE EBR
	  JRST	SYSINI		;CPU0
IFG <CPUN-1>,<
	JRST	SPRINI		;CPU1
>
;SUBROUTINE TO SEE WHICH CPU THIS IS (CALLED ON SYSTEM
; STARTUP AND POWER FAIL AUTO-RESTART)
;CALLING SEQUENCE:
;	JSP	T4,SYSTR0
;	RETURN HERE IF CPU0
;	RETURN HERE IF CPU1
SYSTR0:	TLO	T4,(IC.UOU)	;TURN USRIOT FOR THE RETURN
IFN M.KI10,<
	MOVSI	T1,NUPMPP(PG.LUB)

	DATAO	PAG,T1		;SET UBR TO NULL JOBS UPMP SO THAT MUUOS
				; AND PAGE FAULTS DURING INITIALIZATION
				; GET TO DIE
	CONI	PAG,T1		;READ THIS CPU'S SERIAL NUMBER
	LSH	T1,-^D26	;RIGHT ADJUST IT
>
IFN M.KL10,<
	BLKI	APR,T1		;READ APR SERIAL #
	ANDI	T1,7777		;JUST SERIAL # BITS
	CONO	APR,LP.CSF!LP.CSD
	DATAI	CCA,		;INVALIDATE CACHE, NOT VALIDATING CORE
	CONSO	APR,LP.CSD
	JRST	.-1
	CONO	APR,LP.CSF!LP.CSD
>

IFG <CPUN-1>,<
IFN M.KI10,<
	MOVE	T2,BOOTWD	;DOES BOOTWD CONTAIN AN IOWD?
	TLCE	T2,777600	;OR A GOTO WORD?
	TLNN	T2,774000
	JRST	SYSTR1		;YES, AN OLD VERSION OF BOOTS SO LOOK AT S.W.S/N
>
	MOVE	T2,BOOTWD
IFN M.KI10,<
	LSH	T2,-^D26	;GET S/N OF CPU WHICH BOOTS WAS EXECUTED ON
>
IFN M.KL10,<
	ANDI	T2,7777		;CLEAR ALL BUT SERIAL NUMBER
>
	CAME	T1,T2		;SAME AS THE CURRENT CPU?
	AOJA	T4,SYSTR4	;NO, THIS MUST BE CPU1
>
	MOVEM	T1,.C0ASN	;YES, CPU0
	MOVEM	T1,SERIAL	;STORE FOR SECOND GETTAB
IFG <CPUN-1>,<
IFN M.KI10,<
	JRST	SYSTR2		;SETUP SKPCPU0
SYSTR1:	CAME	T1,.C0ASN	;IS THIS CPU CPU0? (HARDWARE AND MONGEN
				; SERIAL NUMBERS AGREE)?
	AOJA	T4,SYSTR3	;NO, SEE IF CPU1
>
>
SYSTR2:	MOVEI	T1,.EPMP/PAGSIZ+PM.ACC
	HRRM	T1,.EPMP+.MSKPC	;MAP SKPCP0
IFN M.KI10,<
	DATAO	PAG,.C0EBR	;SETUP THE EXEC BASE REGISTER SO SKPCP0 AND
				; SKPCP1 WILL AS APPROPRIATE
>
IFN M.KL10,<
	CONO	PAG,@.C0EBR
	DATAO	PAG,[LG.LUB+LG.IAM+NLUPMP/PAGSIZ] ;SETUP UBR TO
				; NULL JOB'S UPT SO THAT MUUO'S, ACCOUNTING
				; METERS, EXEC PAGE FAILS DURING ONCE ONLY
				; WORK CORRECTLY. INHIBIT ACCOUNTING STORE
	MOVEI	T1,PM.ACC+PM.WRT+NUPMPP  ;SET UP NULL JOB'S MAPPING
	HRLM	T1,NLUPMP+.MUPMP  ;FOR .UPMP ADDRESSES DURING SYSINI
>
	JRSTF	@T4		;DO CPU0 INITIALIZATION
IFG <CPUN-1>,<
SYSTR3:
	CAME	T1,.C1ASN	;IS THIS CPU1?
	HALT	.		;WHO KNOWS WHAT TO DO NOW
SYSTR4:	MOVEM	T1,.C1ASN	;STORE CPU1'S S/N
	MOVEI	T1,.E1MP/PAGSIZ+PM.ACC
	HRRM	T1,.E1MP+.MSKPC	;MAP SKPCP1
IFN M.KI10,<
	DATAO	PAG,.C1EBR	;SETUP EBR SO SKPCP0 WON'T SKIP AND SKPCP1 WILL
				;CAUSE THE MAPPING TO BE IN EFFECT
>
IFN M.KL10,<
	CONO	PAG,@.C1EBR	; ..
	DATAO	PAG,[LG.LUB+LG.IAM+NLUPMP/PAGSIZ] ;SETUP UBR TO
				; NULL JOB'S UPT SO THAT MUUO'S, ACCOUNTING
				; METERS, EXEC PAGE FAILS DURING ONCE ONLY
				; WORK CORRECTLY. INHIBIT ACCOUNTING STORE
>
	JRSTF	@T4		;DO CPU1 INITIALIZATION
>>
SYSDSA:	JRST	SYSINI		;CPU0, GO INITIALIZE SYSTEM VARIABLES
>
SUBTTL STOP PROCEDURE WHEN SHUTTING DOWN SYSTEM
;BECAUSE OF CATOSTROPHIC FAILURE OR ANY OTHER REASON
;TRANSFER HERE FROM LOC 407 OR DEPOSIT NON-ZERO IN 30

;PROCEDURE TO SAVE CRASHED MONITOR ON DECTAPE FOR LATER DEBUGGING UNDER TIME SHARING
;OPERATOR SHOULD:
;  1. PUSH STOP AND HOLD IT DOWN
;  2. PUSH CONTINUE (APR PI IN PROGRESS SHOULD COME ON)
;		THIS PUTS MACHINE INTO EXEC MODE AND STORES PC OC CRASH
;  3. LETUP ON STOP
;  4. SET ADDRESS SWITCHES TO 407
;  5. PUSH START (DO NOT PUSH I/O RESET AS IT WILL CLEAR DEVICES)
;  6. LIGHTS WILL HAVE TTY LINE NO. IN LH(-1 IF NONE), CURRENT JOB NO. IN RH.
;     WILL STOP WITH P.C.=10.

INTERNAL APRSTS,PISTS,SYSTOP,TTYSTS,PTRSTS,TMCSTS
IFN M.KA10!M.KI10,<
INTERNAL CCISTS,SWTSTS
>
INTERNAL PTPSTS,DLSSTS,DTSSTS,PLTSTS,TMSSTS,DSKSTS,DSKDTI
INTERNAL DPCSTS,DPCDTI,DP4STS,DP4DTI,FH2STS,FH2DTI,DP2STS,DP2DTI
	INTERNAL DP3STS,DP3DTI,DS1STS,DSXSTS,ENDSTS
	EXTERNAL CTYTYP		;DEFINED IN SYSINI TO BE 403 RESTART CODE
				;SO MONITOR CANNOT BE RESTARTED AT 403 AFTER
				;BEING STARTED AT 407.
FHD2==174	;DEVICE CODE FOR SECOND FIXED HEAD CONTROLLER
DPC==250		;DISK PACK CONTROL - NOT IN MACRO.SVE FOR SPMON
DPC2==254	;DEVICE CODE FOR SECOND DISK PACK CONTROLLER
BOOTLN==1000	;NO OF WORDS (MAX) IN BOOTS CODE (BLOCK 4-7)

	EXTERN	TTYSRC,LDPLNO

SYSTOP:
IFG CPUN-1<			;TWO CPUS IN THIS CONFIG?
IFN M.KA10,<
	SKPCPU	(0)		;CPU0?
	JRST	CP1CRS##	;NO, SAVE STATE OF CPU1
>
IFN M.KI10,<
	MOVEM	17,TEMP17	;SAVE 17 IN NON-DESTRUCTABLE DATA
	CONI	PAG,17		;READ CPU SERIAL NUMBERS
	LSH	17,-^D26	;RIGHT JUSTIFY IT
	CAME	17,.C0ASN	;CPU0?
	JRST	[MOVE 17,TEMP17	;NO, SAVE STATE OF CPU1
		 JRST CP1CRS]
	MOVE	17,TEMP17	;RESTORE AC 17
>
IFN M.KL10,<
	MOVEM	17,TEMP17	;SAVE 17
	APRID	17		;READ CPU SERIAL #
	ANDI	17,7777		;JUST SERIAL # BITS
	CAME	17,.C0ASN	;IS THIS THE MASTER
	JRST	[MOVE 17,TEMP17	;NO--RESTORE 17
		 JRST CP1CRS]	;SAVE CPU1
	MOVE	17,TEMP17	;RESTORE 17
>
>
	MOVEM	17,CRSHAC+17	;SAVE ALL ACS
	MOVEI	17,CRSHAC	;SOURCE==0, DESTINATION==CRSHAC
	BLT	17,CRSHAC+16	;SO DDT CAN LOOK AT SAVED CRASH LATER
				;THIS CLOBBERS SYSINI, SO MONITOR CANNOT
				;  BE RESTARTED AT 403


;GETTAB TABLE 44
;DTE20 DEVICE CODES FROM DTEPRM.MAC

	DTE0==200
	DTE1==204
	DTE2==210
	DTE3==214


REBOOT::
	MOVEI	17,ENDSTS	;PATCH CRASH PROCEDURE SO IT
	HRRM	17,SYSCRH	;  WILL SAVE STATUS ONLY ONCE
APRSTS:	CONI	APR,.		;(0) STORE APR STATUS HERE
PISTS:	CONI	PI,.		;(1) STORE PI STATUS HERE
IFN M.KA10!M.KI10,<
SWTSTS:	DATAI	APR,.		;(2) STORE CONSOLE SWITCHES HERE
>
IFN M.KI10,<
PAGSTS:	CONI	PAG,.
EUBSTS:	DATAI	PAG,.
>
IFN M.KL10,<
VERSTS:	BLKI	APR,.		;VARIOUS ECO AND MICROCODE VERSION #S
UPTSTS:	DATAI	PAG,.		;ADDRESS OF UPT
EPTSTS:	CONI	PAG,.		;ADDRESS OF EPT
TIMSTS:	CONI	TIM,.		;INTERVAL TIMER STATUS
MTRSTS:	CONI	MTR,.		;METER STATUS
DTESTS:
DT0STS:	CONI	DTE0,.		;DTE STATUS
DT1STS:	CONI	DTE1,.
DT2STS:	CONI	DTE2,.
DT3STS:	CONI	DTE3,.
ERASTS:	RDERA	.		;ERROR REGISTER
ABKSTS:	DATAI	APR,.		;ADDRESS BREAK CONDITIONS
>
TTYSTS:	CONI	TTY,.
PTRSTS:	CONI	PTR,.
PTPSTS:	CONI	PTP,.
DLSSTS:	CONI	DLS,.
XP DAS,324
DTSSTS:	CONI	DAS,.
CRASTS:	CONI	CR,.
LPASTS:	CONI	LPT,.
PLTSTS:	CONI	PLT,.
TMSSTS:	CONI	TMS,.
TMCSTS:	CONI	TMC,.
DX10==220
DX1STS:	CONI	DX10,.
IFN M.KA10!M.KI10,<
CCISTS:	CONI	CCI,.
>
DSKSTS:	CONI	DSK,.
DSKDTI:	DATAI	DSK,.
FH2STS:	CONI	FHD2,.
FH2DTI:	DATAI	FHD2,.
FSD==270
FSD2==274
FSD3==360
FSDSTS::CONI	FSD,.
FSDDTI::DATAI	FSD,.
FS2STS::CONI	FSD2,.
FS2DTI::DATAI	FSD2,.
FS3STS::CONI	FSD3,.
FS3DTI::DATAI	FSD3,.
RH2==540
RH22==544
RH23==550
RH2STS:CONI	RH2,.
RH2ST2::CONI	RH22,.
RH3STS::CONI	RH23,.
DPCSTS:	CONI	DPC,.
DPCDTI:	DATAI	DPC,.
DP2STS:	CONI	DPC2,.
DP2DTI:	DATAI	DPC2,.
DP3STS:	CONI	DPC3,.
DP3DTI:	DATAI	DPC3,.
DP4STS:	CONI	DPC4,.
DP4DTI:	DATAI	DPC4,.
DS1STS:	CONI	310,.		;DS10
DSXSTS:	CONI	314,.		;DS10X
XP DAC,320
DTCSTS:	CONI	DAC,.
XP DBS,334
D2SSTS:	CONI	DBS,.		;2ND TD10
XP DBC,330
D2CSTS:	CONI	DBC,.
DS2STS:	CONI	,.
DSYSTS:	CONI	,.
DLC=64
DLC2=164
DLB=60
DLB2=160
DLCSTS:	CONI	DLC,.
DLCDTI:	DATAI	DLC,.
	DATAO	DLB,[0]
DLBSTS:	CONI	DLB,.
DLBDTI:	DATAI	DLB,.
DLC2TS:	CONI	DLC2,.
DLC2TI:	DATAI	DLC2,.
	DATAO	DLB2,[0]
DLB2TS:	CONI	DLB2,.
DLB2TI:	DATAI	DLB2,.

CDPSTS:	CONI	CDP,.
XP CDR2,154
CRBSTS:	CONI	CDR2,.		;CDR1
XP LPT2,234
LPBSTS:	CONI	LPT2,.		;LPT1
XP LPT3,230
LPCSTS:	CONI	LPT3,.		;LPT2
XP PLT2,144
PLBSTS:	CONI	PLT2,.		;PLT1
DPC3=260
DPC4=264
INTERNAL LENSTS
LENSTS==<.-APRSTS-1>B26

IFN M.KI10,<			;IS THIS A KI?
	DATAO	PAG,[1B0+1B2+1B18+1B22]  ;SET TO BLOCK 1
	JRSTF	@[IC.UOU!.+1]	;MAKE XCT WORK RIGHT
	MOVEI	T1,ACBLK1	;WHERE TO PUT THE ACS
	EXCTUX	<BLT T1,ACBLK1+17>  ;SAVE THEM
	MOVEI	T1,1B18
	DATAO	PAG,T1		;CLEAR TRAP ENABLE
>
IFN M.KL10,<
	CONO	PI,PIOFF	;TURN OFF PI
	CONO	PAG,0		;TURN OFF PAGING AND CACHE
	SWPUA			;SWEEP CACHE
	CONSZ	APR,LP.CSB	;WAIT UNTIL DONE
	JRST	.-1		; ..
				;LEAVE PI OFF SINCE IT WILL BE SMASHED SOON ANYWAY
	DATAO	PAG,[LG.LAB+11B11]  ;SET EXEC USING BLOCK 1
	MOVEM	17,ACBLK1+17	;SAVE THE AC'S IN THE
	MOVEI	17,ACBLK1	; USUAL MANNER
	BLT	17,ACBLK1+16	; ..
	DATAO	PAG,[LG.LAB+21B11]  ;SELECT AC BLOCK 2
	MOVEM	17,ACBLK2+17
	MOVEI	17,ACBLK2
	BLT	17,ACBLK2+16	;SAVE IT
	DATAO	PAG,[LG.LAB+31B11]  ;SELECT AC BLOCK 3
	MOVEM	17,ACBLK3+17
	MOVEI	17,ACBLK3
	BLT	17,ACBLK3+16	;SAVE THAT TOO
	DATAO	PAG,[LG.LAB+00B11]  ;RESET BACK TO BLOCK 0
	JSR	ZAPRH2		;MAKE SURE RH20 IS IN A GOOD STATE
>
				;HERE BEFORE DATE AND TIME TYPED ON A 407 START
				;ALSO HERE ON SUBSEQUENT 407 STARTS AFTER FIRST ONE
ENDSTS::CONO	APR,AP0RST	;RESET SYSTEM
	CONO	PI,011577	;WIPEOUT PI-SYSTEM

;CALL TO METINI REMOVED SO METER POINTS WILL BE PRESERVED IN
;THE CRASH DUMP--THIS REQUIRES THAT NONE OF THE ROUTINES
;CALLED BELOW (E.G. GETZ) SHOULD CONTAIN METER POINTS.
;IFN FTMETR,<IFG M.METR,<
;	JSR	METINI##	;RELEASE ALL METER POINTS
;>>
IFN DPCN & FTBOOTRD!RPXN & FTBOOTRD,<
				;DOES THIS SYSTEM HAVE DISK PACKS?
	MOVEI	P,SYSPDL##	;SETUP P TO SPARE AREA
IFN M.KL10,<
	MOVEI	T1,PM.ACC+PM.WRT+NUPMPP
	HRLM	T1,NLUPMP+.MUPMP	;SINCE SUNXMT NEEDS A UPT SETUP
	DATAO	PAG,[LG.LUB+LG.IAM+NLUPMP/PAGSIZ]
	CONO	PAG,LG.TEN+.EPMP/PAGSIZ ;TURN ON PAGING
>
BNXMTS::PUSHJ	P,SUNXMT##	;SETUP NXMTAB PATCHED OUT IF SYSTEM HAS
				; BEEN STARTED (PATCHED TO JFCL AFTER START)
IFN M.KI10,<
	DATAO	PAG,[EXP PG.LUB+PG.LEB+0] ;CLEAR TRAP ENABLE SO LOW 256K
				; WILL BE UNMAPPED
>
IFN M.KL10,<
	CONO	PAG,0		;TURN OFF TRAP ENABLE
>
	MOVEI	T1,BOOTCL	;SETUP LOWER CORE TO POINT TO CHANNEL
	HRRZM	T1,BOOTWD	; COMMAND LIST (MAKE SURE IN CASE
				; LOWER CORE WIPED OUT).  START UNIT 0, READ (LHT)
IFN M.KI10!M.KL10&FT22BIT,<
	MOVEI	T1,200000	;PAGE 8191
	MOVEI	T2,NXMTAB+343	;STARTING WORD IN BIT MAP
	HRLOI	P2,17		;4096K-1
	PUSHJ	P,FINDHI	;FIND THE HIGHEST EXISTANT PAGE
	MOVE	P1,P2		;VIRTUAL ADDRESS-1 OF HIGHEST PAGE
	MOVE	P3,P2		;PHYSICAL ADDRESS-1 OF HIGHEST PAGE
	TLNN	P2,-1		;MORE THAN 256K?
	JRST	BNXMT1		;NO, USE PHYSICAL ADDRESSES
>
IFN M.KA10,<
	MOVSI	T1,40000	;256K
	MOVEI	T2,NXMTAB+7	;STARTING WORD IN BIT MAP
>
IFN M.KI10!M.KL10,<
	MOVSI	T1,2000		;PAGE 511
	MOVEI	T2,NXMTAB+16	;STARTING WORD IN BIT MAP
>
	MOVEI	P2,777777
	PUSHJ	P,FINDHI	;FIND HIGHEST EXISTANT PAGE OR K
IFN M.KA10,<
	ADDI	P2,1000		;BOOTS IS 512 WORDS LONG
	MOVE	P1,P2		;ADDRESS-1 OF WHERE BOOTS WILL GO
>
IFE M.KA10!FT22BIT,<
	MOVE	P1,P2		;ADDRESS-1 OF WHERE BOOTS WILL GO
>
IFN M.KI10!M.KL10&FT22BIT,<
	EXCH	P2,P3		;P2=P.A.,P3=P.A..LT.256K
>
BNXMT1:
	MOVSI	T1,-BTBLEN
KONLUP:	MOVE	T3,P2		;ASSUME BOOTS CAN BE READ INTO HIGHEST PHYSICAL PAGE
IFN M.KI10!M.KL10&FT22BIT,<
	XCT	KONCNI(T1)	;CONI DEV,T4
	XCT	SKP22B(T1)	;SKIP IF A DF10C IN 22 BIT MODE
	SKIPA	T3,P3		;ITS NOT, READ BOOTS INTO 256K OR BELOW
	TLOA	T3,-BOOTLN_4	;IT IS, READ BOOTS INTO THE TOP OF CORE
>
	TLO	T3,-BOOTLN	;WORD COUNT 18 BIT STYLE
	MOVEM	T3,BOOTCL	;STORE IOWD
	MOVSI	T2,-10
UNILUP:	CONO	APR,AP0RST	;CLEAR THE WORLD
	SETZM	BOOTCL+1	;TERMINATE THE READ
	MOVE	T4,BTABLE(T1)
	PUSHJ	P,@0(T4)	;START THE READ
	MOVEI	T3,40000
	XCT	1(T4)		;WAIT TILL DONE
	SOJG	T3,.-1
IFN M.KI10!M.KL10&FT22BIT,<
	MOVE	P1,BOOTCL
IFN M.RH2P,<
	SUBI	P1,1
>
	LSH	P1,W2PLSH	;PHYSICAL PAGE BOOTS WAS READ INTO
	MOVEI	P1,PM.ACC+PM.WRT+1(P1)
	HRRM	P1,.EPPM+177	;MAKE IT ADDRESSABLE
	MOVEI	P1,776777	;VIRTUAL ADDRESS OF BOOTS
IFN M.KI10,<
	DATAO	PAG,.C0EBR	;CAUSE MAPPING TO BE IN EFFECT
>
IFN M.KL10,<
	CONO	PAG,LG.TEN+.EPMP/PAGSIZ
>
>
	MOVE	S,BOOTFI
	CAMN	S,1(P1)		;READ BOOTS?
	JUMPG	T3,UNICHK	;YES, IF DIDN'T TIME OUT
UNINXT:	AOBJN	T2,UNILUP	;NO, TRY NEXT UNIT
	AOBJN	T1,KONLUP	;TRY NEXT KONTROLLER
>
	MOVE	10,.+1
	STOPCD	10,HALT,BNF,	;++BOOTS NOT FOUND
IFN FTBOOTRD,<
UNICHK:	XCT	2(T4)		;BOOTS WAS READ, ANY DEVICE ERROR?
	JRST	UNINXT		;YES, TRY NEXT UNIT
				;ALL OK, FALL INTO BOOTYP
BOOTYP:
IFN FTKL10,<
	PUSHJ	P,ENTSPC##	;ENTER SECONDARY PROTOCOL
>	;END IFN FTKL10
	MOVEI	T1,BOOTMS	;ADR OF MESSAGE SO OPER WILL
				;KNOW HE IS TALKING TO BOOTS
				;RATHER THAN A LOOP IN MONITOR
	PUSHJ	P,CTYTYP	;TYPE ON CTY (RESPECTS T2)
	MOVE	T1,[POINT 7,BOOTXT]	;POINTER TO TEXT
	MOVSI	T2,(DF.NAR)	;WANT AUTO RELOAD?
	TDNN	T2,DEBUGF	;SKIP IF NEVER WANT AUTO RELOAD
	SKIPG	ARFLAG		;SKIP IF .GT. 5 MIN UPTIME
	MOVEI	T1,0		;NO RELOAD--CLEAR POINTER
IFN FTKI10,<
	CONI	APR,T2		;READ SENSE SWITCHES
	TLNN	T2,(IP.SS5)	;IHIBIT AUTO-RELOAD IF SS5 IS SET
>
	SKIPGE	SYSKTM		;KSYS?
	MOVEI	T1,0		;YES, NO AUTOS
	MOVEM	T1,1000(P1)	;STORE FOR BOOTS
	MOVE	T1,LOCYER	;GET YEAR
	SUBI	T1,^D1970	;SUBTRACT BASE
	JUMPL	T1,BOOTST	;DON'T STORE IF BAD
	LSH	T1,5		;SHIFT OVER
	IOR	T1,LOCDAY	;ADD IN DAY
	LSH	T1,4		;AND
	IOR	T1,LOCMON	;MONTH
	HRLZM	T1,CRSDTM	;SAVE FOR ONCE AFTER RELOAD
	MOVE	T2,TIME		;GET TIME IN JIFFIES
	IDIV	T2,TICSEC	;CONVERT TO SECONDS TO FIT
	ADDI	T2,RLDTIM
	HRRM	T2,CRSDTM	;SAVE FOR ONCE AFTER RELOAD
	ADD	T1,T2		;COMPUTE CHECKSUM
	ADDI	T1,507601	;INCLUDE WHY FROM DIE ROUTINE
	HRLM	T1,CRSWHY	;SAVE CHECKSUM FOR ONCE AFTER
				; RELOAD SO IT CAN DEFEND AGAINST
				; JUNK OR NON-MONITOR PREDECESSORS.
BOOTST:
IFN M.KI10!M.KL10,<
	MOVE	P1,BOOTCL	;WHERE BOOTS WAS READ
	TLNE	P1,17		; ABOVE 256K?
	SKIPA	P1,[776777]	;YES
IFN M.KI10,<
	DATAO	PAG,[PG.LEB+0]	;NO, TURN OFF PAGING
>
IFN M.KL10,<
	CONO	PAG,0
IFN M.RH2P,<
	TRNN	P1,777		;IF READ FROM RH2P
	SUBI	P1,1		; ADDR IS 1 TOO HIGH
>
>
>
	JRST	1(P1)		;GO START UP BOOTS.

BOOTMS:	ASCIZ	/
BOOTS
/

IFN DPCN,<
DPREAD:	MOVEI	T3,40(T2)
	ROT	T3,-6		;SEEK CYL 0
	XCT	3(T4)
	MOVEI	T3,^D100000
	SOJG	T3,.		;WAIT HALF A SECOND
	MOVEI	T3,(T2)
	ROT	T3,-6		;READ
	HRRI	T3,BOOTWD+45000	;DISABLE ERROR STOP
	XCT	3(T4)
	POPJ	P,		;AND RETURN
>
IFN RPXN,<
RPREAD:	MOVSI	T3,124000(T2)
	XCT	3(T4)		;DESIRED CYL = 0
	TDC	T3,[170000,,4]
	XCT	3(T4)		;DESIRED SECTOR = 4
	TDC	T3,[450000,,200075!BOOTWD_6]
	XCT	3(T4)		;READ, DXES
	POPJ	P,		; AND RETURN
RPCHEK:	MOVSI	T3,10000(T2)
	XCT	3(T4)		;DATAO STATUS
	IMULI	1
	XCT	4(T4)		;DATAI STATUS
	XCT	5(T4)		;CONSO
	TRNN	T3,40000	;ERR ON?
	AOS	(P)		;GOOD RETURN
	XCT	6(T4)		;CLEAR DONE, ERROR
	POPJ	P,		; AND RETURN
;STILL IN IFN RPXN
IFN M.RH2P,<
RH2RED:	XCT	6(T4)		;MASSBUS ENABLE
	MOVSI	T3,010000(T2)
	XCT	3(T4)
	IMULI	P,1		;READ STATUS REGISTER
	IMULI	P,1
	XCT	4(T4)
	ANDI	T3,10700
	CAIE	T3,10700	;DRIVE OK?
	POPJ	P,		;NO, DONT ATTEMPT TO READ
	MOVE	T3,BOOTCL
	TLNE	T3,100000
	TLC	T3,-BOOTLN_4	;TURN INTO RH20-STYLE IOWD
	TLO	T3,BOOTLN_4!400000
	TRNE	T3,777
	ADDI	T3,1		;RH20S LIKE ADDR, NOT ADDR-1
	MOVEM	T3,BOOTCL
	MOVE	U,[200000,,BOOTCL] ;INITIAL JUMP
	EXCH	U,(F)		;WHERE CHAN EXPECTS IT
	DMOVE	J,1(F)	;SAVE LOGOUT AREA (IN CASE NO PACK UP)
	MOVSI	T3,124400(T2)	;DESIRED CYL=0
	XCT	3(T4)
	TDC	T3,[170000,,4]	;DESIRED SECTOR =4
	XCT	3(T4)
	TDC	T3,[742000,,200075!<<<-BOOTLN/200>&1777>_6>]
	XCT	3(T4)		;START THE READ
	MOVEM	U,(F)		;RESTORE ICWA
	DMOVEM	J,1(F)	;RESTORE LOGOUT AREA
	POPJ	P,
>;END IFN M.RH2P
>;END IFN RPXN

IFN FTKL10,<
;SUBROUTINE TO GET THE RH20S BACK INTO A KNOWN STATE
ZAPRH2::0
	MOVEI	T1,540/4
	MOVE	T2,[CONO 540,(T3)]
ZPRH21:	DPB	T1,[POINT 7,T2,9]
	MOVEI	T3,2000		;MASSBUS INIT
	XCT	T2
	MOVEI	T3,20		;STOP
	XCT	T2
	MOVEI	T3,10		;CLEAR DONE
	XCT	T2
	CAIGE	T1,574/4
	AOJA	T1,ZPRH21	;LOOP FOR ALL RH20'S
	JRST	@ZAPRH2
>
;SUBROUTINE TO FIND THE HIGHEST ZERO BIT IN A TABLE
; CALL WITH T1=STARTING BIT POSITIONS, T2=STARTING WORD
; WITHIN THE TABLE, P2=THE ADDRESS REPRESENTED BY THE
; STARTING WORD NUMBER AND BIT POSITION. RETURNS
; P2=ADDRESS WHICH REPRESENTS THE FIRST ZERO FOUND IN THE TABLE
FINDHI:	SUBI	P2,PAGSIZ
	TDNN	T1,(T2)
	POPJ	P,
	SKIPGE	T1
	SUBI	T2,1
	ROT	T1,1
	JRST	FINDHI
BTABLE:
IFN RPXN,<
	EXP	RPINST
	EXP	R2INST		;ALWAYS 2 - FSD0 MIGHT BE AN RS04
IFN M.RH2P,<
	EXP	RH2INST
	EXP	RH2IN2
>
>
IFN DPCN,<
	EXP	DPINST
IFG DPCN-1,<
	EXP	D2INST
>>
BTBLEN==.-BTABLE
IFN DPCN,<
DPINST:	EXP	DPREAD
	CONSO	DPC,10
	CONSZ	DPC,377720
	DATAO	DPC,T3
IFG DPCN-1,<
D2INST:	EXP	DPREAD
	CONSO	DPC2,10
	CONSZ	DPC2,377720
	DATAO	DPC2,T3
>>
IFN RPXN,<
RPINST:	EXP	RPREAD
	CONSO	FSD,10
	PUSHJ	P,RPCHEK
	DATAO	FSD,T3
	DATAI	FSD,T3
	CONSO	FSD,736320
	JFCL
R2INST:	EXP	RPREAD
	CONSO	FSD2,10
	PUSHJ	P,RPCHEK
	DATAO	FSD2,T3
	DATAI	FSD2,T3
	CONSO	FSD2,736320
	JFCL

IFN M.RH2P,<
RH2INST:EXP	RH2RED
	CONSO	RH2,10
	PUSHJ	P,RPCHEK
	DATAO	RH2,T3
	DATAI	RH2,T3
	CONSO	RH2,515000
	CONO	RH2,5410
RH2IN2:	EXP	RH2RED
	CONSO	RH22,10
	PUSHJ	P,RPCHEK
	DATAO	RH22,T3
	DATAI	RH22,T3
	CONSO	RH22,515000
	CONO	RH22,5410
>
>

IFN M.KI10!M.KL10&FT22BIT,<
KONCNI:
IFN RPXN,<
	CONI	FSD,T4
	CONI	FSD2,T4
IFN M.RH2P,<
	MOVEI	F,.EPMP		;EPT+0 FOR 1ST RH20
	MOVEI	F,.EPMP+4	;EPT+4 FOR 2ND RH20
>
>
IFN DPCN,<
	CONI	DPC,T4
IFG DPCN-1,<
	CONI	DPC2,T4
>>
SKP22B:
IFN RPXN,<
	TLNN	T4,4000
	TLNN	T4,4000
IFN M.RH2P,<
	SKIPA			;RH20'S ARE ALWAYS 22-BIT
	SKIPA
>
>
IFN DPCN,<
	TLNN	T4,20
IFG DPCN-1,<
	TLNN	T4,20
>>
>
BOOTFI:	CONO	200000		;BOOTS FIRST INSTRUCTION
NXUNIT:	XWD	10000,0		;INCREMENT TO NEXT UNIT IN DATAO DPC,
ARFLAG::-5			;TESTED TO SEE IF AUTO RELOAD NEEDED
				; COUNTED UP ONE EVERY 60 SEC.

;THIS BLOCK MAY BE OVERWRITTEN BY ONCE
IFN M.KA10!M.KI10,<
BOOTXT::
>
IFN M.KL10,<
ZZ1==.
>
IFE FTEXE,<
	ASCIZ	"/D SYSTEM.SAV[1,4] "
>
IFN FTEXE,<
	ASCIZ	"/D SYSTEM.EXE[1,4] "
>
IFN M.KA10!M.KI10,<
	BLOCK	BOOTXT+10-.	;LEAVE ROOM FOR "/D DEVICE:FILNAM.EXT[PROJCT,PROGRM] "
>
IFN M.KL10,<
	BLOCK	ZZ1+10-.
ZZZ==.-1
IFN	<ZZ1&MPGSIZ-ZZZ&MPGSIZ>,<
	LOC	ZZZ&MPGSIZ
BOOTXT::
IFE FTEXE,<
	ASCIZ	"/D SYSTEM.SAV[1,4] "
>
IFN FTEXE,<
	ASCIZ	"/D SYSTEM.EXE[1,4] "
>
	BLOCK	BOOTXT+10-.
>
IFE	<ZZ1&MPGSIZ-ZZZ&MPGSIZ>,<BOOTXT==:ZZ1>>
>	;END CONDITIONAL ON FTBOOTRD

TEMP17:	0		;PLACE TO SAVE IF 17
			; WHILE PATCHING CRASH DISPATCH
	$ABS
	LIT		;FORCE INITIALIZATION AND READ BOOTS LITERALS
			; INTO THE LOW SEGMENT
SUBTTL COMMON SUBROUTINES
;ERROR RECOVERY - TRY TO START NULL JOB
	$HIGH

	INTERNAL NULJB1
NULJB1:	MOVEI	P4,.C0CDB	;SET UP CDB INDEX REGISTER
IFG CPUN-1,<
	SKPCPU	(0)		;SKIP IF MASTER, P4 IS ALREADY SET UP
	MOVEI	P4,.C1CDB	;THIS IS SLAVE SO GET SLAVE CDB
>
	SETZB	J,.CPJOB(P4)	;ZERO J AND JOB NUMBER FOR NULJOB
	JRST	NULJOB		;GO RESTORE NULL JOB




;COMMON SUBROUTINE RETURNS

	INTERNAL CPOPJ,CPOPJ1,DPOPJ,TPOPJ,TPOPJ1,CPOPJ2,T3POPJ,T4POPJ,MPOPJ,ONPOPJ
	INTERNAL T2POPJ,JPOPJ1,IPOPJ1,JPOPJ,IPOPJ,CORLIM,T2POJ1
	INTERNAL FTTIME,FTSWAP,FTSLEEP,FTKCT,FT2REL,FTPRV
CPOPJ2:	AOS	(P)		;DOUBLE SKIP SUBROUTINE RETURN
CPOPJ1:	AOSA	(P)		;SKIP SUBROUTINE RETURN
DPOPJ:	MOVEM	S,DEVIOS(F)	;DEPOSIT I/O STATUS WORD IN DDB
CPOPJ:	POPJ	P,

TPOPJ1:	AOS	-1(P)		;RESTORE T1 THEN SKIP RETURN
TPOPJ:	POP	P,T1		;RESTORE T1
	POPJ	P,		;AND RETURN
JPOPJ1:				;DUPLICATE NAME (PREFERRED)
IPOPJ1:	AOS	-1(P)		;SET FOR SKIP RETURN
JPOPJ:				;DUPLICATE NAME (PREFERRED)
IPOPJ:	POP	P,J		;RESTORE J (USUALLY JOB OR HIGH SEG NUMBER)
	POPJ	P,
T2POJ1:	AOS	-1(P)
T2POPJ:	POP	P,T2		;RESTORE T2
	POPJ	P,
MPOPJ:	POP	P,M
	POPJ	P,
WPOPJX::CAIA			;NETSER PUSHES THIS ADDR ON THE STACK THEN
WPOPJ1::AOS	-1(P)		; EVENTUALLY DOES A CPOPJ1 RETURN
WPOPJ::	POP	P,W
	POPJ	P,
T3POPJ:	POP	P,T3
	POPJ	P,
T4POPJ:	POP	P,T4
	POPJ	P,
ONPOPJ:	CONO	PI,PION
	POPJ	P,

	INTERNAL LPOPJ,LPOPJ1,UPOPJ,UPOPJ1,FUPOPJ,FUPOJ1

FUPOJ1:	POP	P,F
UPOPJ1:
LPOPJ1:	AOSA	-1(P)		;SKIP AND RESTORE LINE
FUPOPJ:	POP	P,F
UPOPJ:
LPOPJ:	POP	P,U		;RESTORE LINE AND RETURN
	POPJ	P,0		;RETURN
FPOPJ1::AOS	-1(P)
FPOPJ::POP	P,F		;RESTORE F
	POPJ	P,0		;RETURN

;GENERATE AND/OR STORE UUO ERROR CODES
	ERCALC(ECDMAX)
	$ABS
IFE FTREAS,<
REASSI::JRST	UUOERR##
> ;END FTREASSIGN
IFE FT2REL,<
USPY::				;DUMMY ENTRY FOR SPY UUO
> ;END FT2REL

IFE FTTMP,<
TMPUUO::			;DUMMY TMPUUO
> ;END FTTMP

IFE FT5UUO,<			;DUMMY UUO'S
DEVPPU::
ACCCHK::
TRMNO::
TRMOP::
> ;END FT5UUO

IFE FTDSEK,<
UUOSEK::
> ;END FTDSEK

IFE FTMETR,<
METER::				;DUMMY METER UUO
>

IFE M.MSG,<
	XP	MPXACT,CPOPJ1
	XP	CHKMPX,CPOPJ1
LGLMPX::
MPXIOS::
TSTMPX::
CLRST::
ERLST::
SENSE::
CONECT::
DEVUDX::
MOVHDR::
MSGBFE::
MSGOUT::
ZAPMPX::
MPXIOD::
MPXDIS::
MPXWAT::
>
	POPJ	P,		;THE NULL UUO
;SUBROUTINES TO SAVE AND RESTORE PRESERVED ACS
;SAVEN IS CALLED AT THE BEGINNING OF A SUBROUTINE
;FOR CONVENIENCE NO MATCHING SUB IS NEEDED TO BE CALLED
;TO RESTORE THIS ACS.
;INSTEAD AN EXTRA RETURN IS PUT ON STACK
;5 CHAR NAME INDICATES IT VIOLATES
;SUBROUTINE CALLING CONVENTIONS
;CALL:	PUSHJ	P,SAVEN
;	RETURN	HERE IMMEDIATELY WITH EXTRA RETURN ON STACK
;	RESPECTS ALL ACS

;NOTE:	THIS CODE USES 1 LOC BEYOND END OF STACK BUT THEN PUSHES ON TOP OF IT
;SO GET OVERFLOW INTERUPT IF TOO FULL.  OK TO DO 1(P) SINCE THIS WORD WRITTEN ON OVERFLOW
INTERN	SAVE1,SAVE2,SAVE3,SAVE4

	$HIGH
SAVE1:	EXCH	P1,(P)		;SAVE P1, GET CALLER PC
	MOVEM	P1,1(P)		;SAVE CALLER PC ONE BEYOND END
	MOVE	P1,(P)		;RESTORE P1
	PUSHJ	P,@1(P)		;GO BACK TO CALLER, OVERWRITE CALLER PC WITH .+1
	  JRST	RES1
	AOS	-1(P)
	JRST	RES1

SAVE2:	EXCH	P1,(P)		;SAVE P1, GET CALLER PC
	PUSH	P,P2
	MOVEM	P1,1(P)		;SAVE CALLER PC ONE BEYOND END
	MOVE	P1,-1(P)	;RESTORE P1
	PUSHJ	P,@1(P)		;GO BACK TO CALLER, OVERWRITE CALLER PC WITH .+1
	  JRST	RES2
	AOS	-2(P)
	JRST	RES2

SAVE3:	EXCH	P1,(P)		;SAVE P1, GET CALLER PC
	PUSH	P,P2
	PUSH	P,P3
	MOVEM	P1,1(P)		;SAVE CALLER PC ONE BEYOND END
	MOVE	P1,-2(P)	;RESTORE P1
	PUSHJ	P,@1(P)		;GO BACK TO CALLER, OVERWRITE CALLER PC WITH .+1
	  JRST	RES3
	AOS	-3(P)
	JRST	RES3
SAVE4:	EXCH	P1,(P)		;SAVE P1, GET CALLER PC
	PUSH	P,P2
	PUSH	P,P3
	PUSH	P,P4
	MOVEM	P1,1(P)		;SAVE CALLER PC ONE BEYOND END
	MOVE	P1,-3(P)	;RESTORE P1
	PUSHJ	P,@1(P)		;GO BACK TO CALLER, OVERWRITE CALLER PC WITH .+1
	  JRST	RES4
	AOS	-4(P)
RES4:	POP	P,P4
RES3:	POP	P,P3
RES2:	POP	P,P2
RES1:	POP	P,P1
	POPJ	P,
;SUBROUTINE TO SAVE AND RESTORE TEMP ACS
;CALLED BY PUSHJ P,SAVT   RETURN EITHER CPOPJ OR CPOPJ1 WHEN THROUGH
SAVT::	EXCH	T4,(P)		;SAVE T4, GET RETURN ADR.
	PUSH	P,T3		;SAVE T3
	PUSH	P,T2		;AND T2
	PUSH	P,T1		;AND T1
	MOVEM	T4,1(P)		;STORE PC
	MOVE	T4,-3(P)	;RESTORE T4
	PUSHJ	P,@1(P)		;RETURN TO CALLER
	  SKIPA			;POPJ RETURN
	AOS	-4(P)		;CPOPJ1 - SET SKIP RETURN
	POP	P,T1		;RESTORE T1
	POP	P,T2		;RESTORE T3 ACS
	POP	P,T3
	POP	P,T4
	POPJ	P,		;AND RETURN

;SUBROUTINE TO SAVE AND RESTORE R
SAVR::	EXCH	R,(P)
	MOVEM	R,1(P)
	MOVE	R,(P)
	PUSHJ	P,@1(P)
	  CAIA
	AOS	-1(P)
	POP	P,R
	POPJ	P,

;SUBROUTINE TO RETURN FROM DDT

GOBACK=:<JRST .>
	SKIPL	DIEWRD##
	JRST	DIECON##
	JRST	CLKDDR
IFN TM10B!FTDISK,<		;TM10B OR DISK?
;ROUTINE TO COMPUTE THE NUMBER OF WORDS DESCRIBED IN AN IOLIST
;ENTER WITH T1=ADDR OF THE INITIAL CONTROL WORD
; AND WITH P1=LOC OF CHANNEL DATA BLOCK
;EXIT WITH T1=NUMBER OF GOOD WORDS TRNSFERRED
INTERN	WRDCNT
WRDCNT:	PUSHJ	P,SAVE4		;SAVE P1,P2
	MOVEI	P3,-1		;SET UP MASK
IFN FT22BIT,<
	MOVEI	P2,0		;ASSUME 18-BIT CHAN
	SKIPGE	T2,CHB22B##(P1)	;IS IT?
	MOVEI	P2,1		;NO, SET FOR 22-BIT
IFN FTKL10&FT22BIT,<
	TLNE	T2,CP.RH2##	;RH20?
	HRROI	P2,2		;YES, SPECIAL STUFF
>
	ASH	P3,@ASH22B(P2)	;SHIFT MASK
>
	SETZ	P1,		;P1 WILL ACCUMULATE WRDCNT
IFE FT22BIT,<
	HRRZ	T2,1(T1)	;LOC+1 OF LAST GOOD DATA WORD
	HLRZ	T3,1(T1)	;LAST IOWD +1
>
IFN FT22BIT,<
	LDB	T3,CNTPT1(P2)	;L(IOWD)+1
>
	CAILE	T3,20		;IS IOWD LOC LEGAL?
	CAMLE	T3,SYSSIZ
	JRST	WRDCN5		;NO, WORD-COUNT=0
IFN FTKL10,<
>
IFE FT22BIT,<
	SKIPGE	-1(T3)		;LAST IOWD A GOTO (MTASBX)?
	JRST	WRDCN0		;NO, REAL IOWD
>
IFN FT22BIT,<
	LDB	T2,CNTPT2(P2)
	JUMPN	T2,WRDCN0
>
	MOVE	T3,T1		;YES, GET START OF LIST
WRDCNA:
IFE FT22BIT,<
	SKIPG	(T3)		;NEXT IOWD A GO-TO?
	JRST	WRDCNB		;NO, REAL IOWD OR 0
>
IFN FT22BIT,<
	LDB	T2,CNTPT3(P2)
	JUMPN	T2,WRDCNB
	SKIPN	(T3)
	JRST	WRDCNC
>
	MOVE	T3,(T3)		;YES, GET ITS ADDRESS
IFN FTKL10,<
>
	JRST	WRDCNA		;  AND TEST IT
WRDCNB:
IFE FT22BIT,<
	SKIPN	(T3)		;REAL IOWD?
	JRST	WRDCNC		;NO, TERMINATOR
>
	MOVE	T4,T3		;YES, SAVE LOC OF REAL IOWD IN T4
	AOJA	T3,WRDCNA	; AND TEST NEXT
WRDCNC:	AOS	T3,T4		;END - T3=L(LAST IOWD)+1
WRDCN0:
IFE FT22BIT,<
	HRRZ	T4,-1(T3)	;INITIAL ADR OF IOWD
>
IFN FT22BIT,<
	LDB	T4,ADRPT2(P2)
	LDB	T2,ADRPT1(P2)	;LOC+1 OF GOOD DATA WRD
IFN FTKL10,<
	JUMPL	P2,[CAMLE T4,T2	;RH20 ADR IS 1 HIGHER
		    JRST WRDCN5	; SO EQUALS IS OK
		    MOVE P4,2(T1)  ;SAVE ENDING CHAN DATA FOR TEST
		    LDB T3,CNTPT2(P2)  ;WORDCOUNT
		    ADD T4,T3	;+N FOR RH20
		    JRST WRDCND]  ;CARRY ON
>
>
	CAML	T4,T2		;IS LAST DATA WRD IN BOUNDS?
	JRST	WRDCN5		;NO, ASSUME THAT IOWD IS NG
	HLRO	T3,-1(T3)	;MAYBE
IFN FT22BIT,<
	ASH	T3,@ASH22B(P2)	;WORD COUNT
>
	SUB	T4,T3		;LAST GOOD ADR IN IOWD+1
WRDCND:	CAMGE	T4,T2		;IS WORD IN BOUNDS?
	JRST	WRDCN5		;NO
IFE FT22BIT,<
	HRRZ	T1,(T1)		;LOC OF 1ST IOWD
>
IFN FT22BIT,<
	LDB	T1,ADRPT3(P2)
>
IFN FTKL10,<
>
WRDCN1:	SKIPN	(T1)		;IS THERE AN IOWD?
	JRST	WRDCN5		;NO, THE DF10 LIED!
IFN FTKL10&FT22BIT,<
	JUMPL	P2,[CAMN P4,(T1)  ;THIS IOWD WHAT THE RH20 STORED?
		    JRST WRDCNF	;YES. THE LAST IOWD IS LAST IT DID
		    LDB T4,[POINT 11,(T1),13]
		MOVNS	T4	;11 BITS OF NEGATIVE WDCNT
		JRST	WRDCNE]
>
	HLRO	T4,(T1)		;WDCNT OF IOWD
IFE FT22BIT,<
	HRRZ	T3,(T1)		;1ST ADR OF IOWD(-1)
>
IFN FT22BIT,<
	ASH	T4,@ASH22B(P2)	;WORD COUNT
WRDCNE:	LDB	T3,ADRPT3(P2)	;1ST ADDR OF IOWD -1
>
	TRNN	T4,(P3)		;IF RH 14 BITS=0
	JRST	WRDCN3		; ITS A CHAN JUMP
	CAMG	T2,T3		;GOOD DATA WD IN THIS IOWD?
	JUMPN	T3,WRDCN2	;YES, COUNT THE DATA AND STEP TO NEXT
	SUB	T3,T4		;MAYBE. ADR OF TOP WD IN IOWD
	CAMG	T2,T3		;LAST GOOD DATA IN IOWD?
	JRST	WRDCN4		;YES
WRDCN2:	SUB	P1,T4		;THIS IOWD IS GOOD. COUNT # OF WDS
	AOJA	T1,WRDCN1	;AND GO TEST NEXT IOWD
WRDCN3:	JUMPE	T3,WRDCN5	;DF10 BLEW IT IF THIS THE END OF THE LIST
	MOVE	T1,T3		;CHAN JUMP - SET T1 TO ADR
IFN FTKL10,<
>
	JRST	WRDCN1		;OF IOWD AND TEST IT


;HERE WITH T1=LOC OF BAD IOWD,  P1=NO OF WDS IN PREVIOUS IOWDS
WRDCN4:
IFE FT22BIT,<
	HRRZ	T3,(T1)		;1ST ADR IN THIS IOWD
>
IFN FT22BIT,<
	LDB	T3,ADRPT3(P2)
>
	SUB	T2,T3		;NO OF GOOD DATA WDS IN IOWD
	ADD	P1,T2		;P1=TOTAL GOOD WORDCOUNT
WRDCNF:	SKIPA	T1,P1		;FINAL ANSWER IS IN T1
WRDCN5:	SETZ	T1,		;NO GOOD - RETURN 0
;STILL IN M.TMB!FTDISK CONDITIONAL
	POPJ	P,		;RETURN WITH ANSWER

IFN FT22BIT,<

ADRPT1::POINT	18,1(T1),35
	POINT	22,1(T1),35
	POINT	22,2(T1),35
ADRPT2::POINT	18,-1(T3),35
	POINT	22,-1(T3),35
	POINT	22,-1(T3),35
ADRPT3::POINT	18,(T1),35
	POINT	22,(T1),35
	POINT	22,(T1),35
CNTPT1::POINT	18,1(T1),17
	POINT	14,1(T1),13
	POINT	22,1(T1),35
MSK22B::XWD	0,-1
	XWD	17,-1
	XWD	17,-1
WDCPNT::POINT	18,0(P1),17
	POINT	14,0(P1),13
	POINT	14,0(P1),13
	POINT	14,0(P1),13
CNTPT2::POINT	18,-1(T3),17
	POINT	14,-1(T3),13
	POINT	11,-1(T3),13
CNTPT3:	POINT	18,(T3),17
	POINT	14,(T3),13
	POINT	11,(T3),13
ADRPT4::POINT	18,T1,17
	POINT	14,T1,13
ASH22B::0
	0,,-4
	0,,-7
>
;SUBROUTINE TO STORE CHANNEL DATA ON ALL HARD AND SOFT ERRORS
;CALL:	MOVE	F,DEVICE DATA BLOCK ADR
;	MOVE	U,UNIT DATA BLOCK ADR
;	MOVEI	P1,CHANNEL DATA BLOCK ADDRESS(CHN'N'CB)
;	MOVEI	T1,LOWER CORE ADR OF TWO WORD(DF10) CHANNEL CONTROL WORD PAIR
;	PUSHJ	P,CHNNXM,MPE, OR DPE(NXM, MEMORY PARITY, DAT PARITY ERROR)
;	ALWAYS RETURN - P1,F,U PRESERVED

;FIRST ADR WHICH CAN GET MEM PARITY OR NXM WHICH IS NOT SERIOUS
; CHECKED BY APR LEVEL INTERRUPT CODE ON PARITY INTERRUPT
; CHNIN1 THRU CHNIN2
CHNIN1::

;SUBROUTINE FOR NXM
CHNNXM::AOS	.CHNXM(P1)	;INCREMENT NO. OF NXMS
				; FALL INTO COMMON SUB.
				; DO NOT COPY DATA LOCS, ELSE GET NXM STOP

;SUBROUTINE TO STORE DATA COMMON FOR MPE, NXM, AND DPE
;CALL:	SAME AS CHNXXX
;	PUSHJ	P,CHNCD0
;	RETURNS WITH T1 = FINAL CONTROL WORD STORED BY DF10

CHNCD0:	IFN FT22BIT,<
IFN FTKL10,<
	MOVE	T3,CHB22B##(P1)	;IF AN RH20
	TLNN	T3,CP.RH2##	; LEAVE T3 NEGATIVE
>
	LDB	T3,[POINT 2,CHB22B##(P1),1] ;GET CHL BYTE
>
	MOVE	T2,0(T1)	;INITIAL CTRL WORD
	MOVEM	T2,.CHICW(P1)	;SAVE IN CDB FOR F.S.
IFN FTKL10,<
	JUMPL	T3,[HRRZ T2,1(T1)  ;IF AN RH20
		    MOVE T1,2(T1) ; GET L(LAST IOWD)
		    JRST CHNCDA]  ; GET FINAL CTRL WD
>
	MOVE	T1,1(T1)	;FINAL CTRL WORD IF DF10
IFN FT22BIT,<
	CAIE	T3,3		;SEE IF DX10
	JRST	CHNCDA		;NO - PROCEED
	MOVE	T1,P3		;YES - GET DAC
	DPB	P2,[POINT 14,T1,13] ;AND CPC (14BITS ENUF)
CHNCDA:>
	MOVEM	T1,.CHFCW(P1)	;SAVE FOR FIELD SERVICE
				; AND RETURN AS VALUE TO CALLER
IFN FTKL10,<
	JUMPL	T3,CHNCDB	;T2 ALREADY SET UP IF RH20
>
	HLRZ	T2,T1		;ADR OF ALST CONTROL WORD
IFN FT22BIT,<
	SKIPGE	CHB22B##(P1)	;22-BIT CHAN
	LSH	T2,-4		;YES, ONLY 14 BITS ARE CNTRL WD LOC
>
CHNCDB:	CAIL	T2,2		;IS FIRST SOURCE ABOVE LOC 0?
	CAML	T2,MEMSIZ	;YES, IS LAST SOURCE ADR IN BOUNDS?
	JRST	CHNCD1		;NO, DO NOT BLT - ELSE GET NXM
	MOVSI	T2,-2(T2)	;2 WORDS BEFORE LAST CONTROL WORD
	HRRI	T2,.CHCW2(P1)	;DEST = CHANNEL DATA BLOCK
	BLT	T2,.CHCW0(P1)	;MOVE 3 COMMAND LIST WORDS TO CHN DATA BLOCK
CHNCD1:	MOVE	T2,CHNTCW##(P1)	;GET EXPECTED TERM CNTL WD
	MOVEM	T2,.CHTCW(P1)	;SAVE FOR F.S.
	PJRST	CHNCD2		;STORE DDB ADR AND UNIT ADR AND RETURN

;SUBROUTINE FOR MEMORY PARITY
CHNMPE::AOSA	.CHMPE(P1)	;INCREMENT NO OF MEM PARITY ERRORS
				; SKIP INTO COMMON CODE

;SUBROUTINE FOR DATA PARITY ON DISK
CHNDPE::AOS	.CHDPE(P1)	;INCREMENT NO. OF DATA PARITY ERRORS
	PUSHJ	P,CHNCD0	;SAVE F, U, AND CONTROL WORDS IN CHN BLK
IFE FT22BIT,<TLZ T1,-1>		;CLEAR LH OF FINIAL CONTROL WORD
IFN FT22BIT,<
	SKIPGE	CHB22B##(P1)	;CHANNEL IN 22 BIT MODE?
	TLZA	T1,777760	;YES, DONT CLEAR OUT EXTRA BITS
	TLZ	T1,-1		;NO, JUST 18 BIT ADDRESS
>;END IFN FT22BIT
	CAIL	T1,2		;IS LAST DATA ADR ABOVE 0?
	CAML	T1,MEMSIZ	;YES, IS IT IN BOUNDS?
	JRST	CHNCD2		;NO, SKIP BLT -  ELSE GET NXM STOP
IFN FTKA10,<
	MOVSI	T2,-2(T1)	;LAST DATA WORD ADR-2 AS BLT SOURCE
	HRRI	T2,.CHDW2(P1)	;BLT DEST ADR IN CHN DATA BLOCK
	BLT	T2,.CHDW0(P1)	;MOVE 3 DATA WORDS - MAY GET PAR INT
>
IFN FTKI10!FTKL10,<
	PUSHJ	P,SAVE4		;SAVE P1-P4
	PUSH	P,T1		;SAVE TERMINATION WORD
	MOVEI	P4,.C0CDB	;GET CPU0 CDB
IFN FTMS,<
	SKPCPU	(0)		;CHECK CPU1
	MOVEI	P4,.C1CDB	;YES - USE THIS INSTEAD
>
	PUSHJ	P,MAPLOC##	;GET EVA SLOT
	EXCH	T1,0(P)		;GET TERMINATION WORD BACK / SAVE PNTR
	MOVEI	T3,.ERPIL(T3)	;ADJUST EVA
IFE FT22BIT,<MOVEI T2,-2(T1)>	;GET STARTING ADDRS
IFN FT22BIT,<LDB T2,[POINT 22,T1,35]>
	MOVEI	P2,.CHDW2(P1)	;PLACE TO STORE DATA WORDS
	HRLI	P2,-3		;MAKE AOBJN PNTR

CHNCDL:	LDB	P3,[POINT 13,T2,26] ;GET PAGE #
	IORI	P3,PM.ACC+PM.WRT ;ACCESS BITS
	DPB	P3,0(P)		;MAP THIS PAGE
	CLRPGT	(P4)		;CLEAR ASSOC MEM SO WE WILL USE
				;  THIS NEW ENTRY
	DPB	T2,[POINT 9,T3,35] ;SET LINE # IN PAGE
	MOVE	P3,0(T3)	;FETCH DATA WORD
	MOVEM	P3,0(P2)	;STASH IN CDB
	ADDI	T2,1		;ADVANCE TO NEXT LOC
	AOBJN	P2,CHNCDL	;LOOP TILL DONE
	POP	P,T2		;PRUNE PDL
	MOVEI	T2,^D50		;WAIT FOR MEM PAR INTERUPT ON
	SOJG	T2,.		;KI10 TO HAPPEN IF ANY
>
;COMMON EXIT TO BOTH ROUTINES - SAVE F AND U FOR FIELD SERVICE
CHNCD2:	HRRM	U,.CHLUE(P1)	;SAVE UNIT DATA BLOCK ADR
	HRRM	F,.CHLDE(P1)	;SAVE DEVICE DATA BLOCK ADR WITH ERR
;LAST ADR CHECKED BY APR ON PARITY INTERRUPT FOR PC IN RANGE OF BLTS
CHNIN2::POPJ	P,		;RETURN
>		;END M.TMB!FTDISK CONDITIONAL
	$ABS
IFN FTDAEM,<
IFNDEF	ERPTMX,<ERPTMX==:^D40>	;LENGTH OF BLOCK FOR ERRORS

ERPTBK::BLOCK	ERPTMX		;BLOCK FOR ERRPT. UUO
ESVIDX::EXP	0		;POINTER FOR STORING IN ERPTBK
EPKIDX::EXP	0		;POINTER FOR PICKING UP FROM ERPTBK
ERRLAP::EXP	0		;COUNTER FOR OVERFLOWS OF ERPTBK (LOST ERRORS)
>
	$HIGH
;SUBROUTINE TO LOAD UP J WITH CURRENT JOB#
;CALL WITH:
;	PUSHJ	P,CPUJOB##
;	RETURN HERE WITH J LOADED
CPUJOB::  IFG <CPUN-1>,<
	SKPCPU(0)		;SKIP IF CPU0
	SKIPA	J,.C1JOB	;SET UP CPU1'S JOB
>
	MOVE	J,.C0JOB	;CPU0'S JOB
	POPJ	P,0		;RETURN

;SUBROUTINE TO SETUP P4 TO POINT TO THIS CPU'S CDB
;CALL WITH:
;	PUSHJ	P,CPUCDB##
;	RETURN	HERE,P4 SETUP
CPUCDB::MOVEI	P4,.C0CDB	;ASSUME CPU0
IFG 	<CPUN-1>,<
	 SKPCPU	(0)		;IS IT CPU0?
	 MOVEI	P4,.C1CDB	;NO, CPU1'S CDB
>
	POPJ	P,		;RETURN

;SUBROUTINE TO SETUP P4 TO POINT AT THE CDB FOR THE CURRENT
; CPU AND TO SETUP J TO CONTAIN THE JOB NUMBER OF THE JOB
; CURRENTLY RUNNING ON THAT CPU
;CALL WITH:
;	PUSHJ	P,CPUSET##
;	RETURN	HERE,P4 AND J SETUPN
CPUSET::PUSHJ	P,CPUCDB	;SETUP P4
	MOVE	J,.CPJOB(P4)	;AND J
	POPJ	P,		;AND RETURN

;SUBROUTINE TO SAVE P4 AND SET IT UP TO POINT TO AT
;THE CDB FOR THE CURRENT CPU
;CALL WITH:
;	PUSHJ	P,SCPCDB##
;RESTORES P4 ON A POPJ FROM THE CALLING SUBROUTINE
SCPCDB::EXCH	P4,(P)		;SAVE P4, GET PC OF THE CALL
	PUSH	P,.+3		;WHERE TO RETURN ON CALLERS POPJ
	PUSH	P,P4		;RETURN TO CALLER ON POPJ FROM CPUCDB
	PJRST	CPUCDB		;SETUP P4 AND RETURN TO CALLER
	CAIA	.		;NON-SKIP RETURN
	AOS	-1(P)		;SKIP RETURN
	POP	P,P4		;RESTORE P4
	POPJ	P,		;RETURN
SUBTTL SYSTEM BYTE POINTERS

	INTERNAL PUUOAC,PIOMOD,PJOBN,PUNIT,PJBSTS,PDVTIM,PDVCNT,PCORSZ,COREP,CORE2P
	INTERNAL IADPTR,PDYQNT,PDYIPT,PDVSTA,PBUFSZ,JBYEWT

PUUOAC:	POINT	4,M,12		;UUO AC FIELD
PIOMOD:	POINT	4,S,35		;MODE BITS
XP PJBNLH,001100		;LEFT HALF OF "POINT 9,XXX,35"
PJOBN:	POINT	9,DEVJOB(F),35	;DEVICE JOB ASSIGNMENT
PUNIT:	POINT	9,DEVJOB(F),26	;DEVICE UNIT NUMBER
PJBSTS:	POINT	JWSIZ,JBTSTS(J),JWPOS	;JOB WAIT STATE (QUEUE) CODE
				;IN JOB STATUS WORD
PJBST2::POINT	JS.SIZ,JBTST2(J),JS.POS	; JOB QUEUE NUMBER (NOT STATE CODE)
PJ2ST1::POINT	JS.SIZ,JBTST2(T1),JS.POS ;SAME AS PJBST2 FOR IDX T1
JBYEWT:	POINT	ESLPSZ,JBTST2(J),ESLPBP	;EVENT WAIT REASON
JBYICC::POINT ICCSIZ,JBTSTS(J),ICCPOS  ;POINTER TO HIGH
				; SEGMENT IN CORE COUNT
PDVSTA:	POINT	6,DEVSTA(F),35	;STATION NUMBER OF DEVICE
PBUFSZ:	POINT	12,DEVCHR(F),35	;BUFFER SIZE
PDVTIM:	POINT	3,DEVCHR(F),9	;CODE FOR TIME DEVICE MAY
					;BE ACTIVE BEFORE BEING DECLARED
					;HUNG. N MEANS 2^N-1 SECONDS
PDVCNT:	POINT	7,DEVCHR(F),16	;COUNTED DOWN EACH SECOND,
				;1 TO 0 TRANSITION MEANS HUNG DEVICE
IADPTR:	POINT	2,DEVIAD(F),2	;COUNT OF NUMBER OF USER CHANNELS INITED
				; ON THIS DEVICE (DECTAPE ONLY)
IFN FTSPL,<
	INTERNAL DEYSPL
DEYSPL:	POINT	8,DEVSPL(F),17	;SPOOL BIT ASSOCIATED WITH DEVICE
>
IFN FT5UUO,<
	INTERN DEYTYP
DEYTYP:	POINT	8,DEVTYP(F),9	;POINTER TO DEVICE-TYPE BIT (+.TYVAR & .TYRAS)
>
IFN M.PSI,< ;IF WE LOAD PSISER
PDVIVO::POINT	9,DEVESE(F),17	;INTERRUPT VECTOR OFFSER
PDVPSI::POINT	36,DEVPSI(F),35	;BITS CLEARED ON RESET
> ;END IFN M.PSI
PDVTYP::POINT	6,DEVTYP(F),9	;JUST DEVICE TYPE
PCORSZ:	POINT	CRSIZ,JBTADR(J),CRPOS	;BYTE POINTER TO LOW OR HIGH SEG CORE SIZE-1

	$ABS
CORE2P:	POINT	CTNBPE,CORTAB	;BYTE POINTER TO CORE ALLOCATION TABLE
	$HIGH

COREP:	POINT	CTNBPE,CORTAB	;CTNBPE BIT POINTER TO CORE ALLOCATION TABLE
PDYQT2::POINT	PDSQNT,.PDQNT(T2),PDNQNT
PDYQNT:	POINT	PDSQNT,.PDQNT(W),PDNQNT ;POINTER TO QUANTUM RUN TIME FOR JOB
PDYIPT:	POINT	PDSIPT,.PDIPT(W),PDNIPT ;POINTER TO INCORE PROTECT TIME
PDYIP2::POINT	PDSIPT,.PDIPT(T1),PDNIPT ;POINTER TO INCORE PROTECT TIME
PDYDPT::POINT	9,.PDDFL(W),8	;DEFAULT PROTECTION
IFN FTFDAE,<
PDYFSP::POINT	9,.PDDFL(W),26	;FILE DAEMON SUPPLIED PROTECTION
>
IFN FTKI10!FTKL10,<
	INTERNAL PIEVM,PIEVMS,POEVM,POEVMS,PDEVM,PDEVMS
PIEVM:	POINT	9,DEVEVM(F),8	;VIRTUAL PAGE NUMBER OF STARTING PAGE IN THE
				; EXEC MAP ALLOCATED TO THIS DEVICE FOR BUFFERED INPUT
PIEVMS:	POINT	9,DEVEVM(F),17	;NUMBER OF PAGES IN THE EXEC MAP ALLOCATED TO
				; THIS DEVICE FOR BUFFERED INPUT
POEVM:	POINT	9,DEVEVM(F),26	;VIRTUAL PAGE NUMBER OF STARTING PAGE IN THE
				; EXEC MAP ALLOCATED TO THIS DEVICE FOR BUFFERED OUTPUT
POEVMS:	POINT	9,DEVEVM(F),35	;NUMBER OF PAGES IN THE EXEC MAP ALLOCATED TO
				; THIS DEVICE FOR BUFFERED OUTPUT
	XP	PDEVM,POEVM	;VIRTUAL PAGE NUMBER OF STARTING PAGE IN THE EXEC
				; MAP ALLOCATED TO THIS DEVICE FOR DUMP I/O
	XP	PDEVMS,POEVMS	;NUMBER OF PAGES IN THE EXEC MAP ALLOCATED TO
				; THIS DEVICE FOR DUMP I/O
>	;END IFN FTKI10!FTKL10
PDVESE::POINT	9,DEVESE(F),35	;EXTENDED ERROR STATUS
	IFG	SYS50N, <	;SWAPPING SYSTEM ?
	INTERNAL IMGIN,IMGOUT,IMGINT,OUTMSK,INMSK,INLEFT
	INMSK==000777		;RH MASK TO IMGIN
	INLEFT==12		;NUMBER OF BITS TO SHIFT TO LEFT JUSTIFY IN RH

IMGIN:	POINT	9,JBTSWP(J),35	;BYTE POINTER FOR # 1K BLOCKS OF CORE
				;WHEN JOB OR HIGH SEG NEXT SWAPPED IN
				;NON-ZERO ONLY WHEN SWAPPED OUT
IMGOUT:	POINT	9,JBTSWP(J),26	;BYTE POINTER FOR # 1K BLOCK OF DISK
				;WHEN JOB OR HIGH SEG HAS IMAGE ON DISK
				;ZERO MEANS NO DISK SPACE ALLOCATED
	OUTMSK==777000		;RH MASK TO IMGOUT. USED TO TEST FOR 0
				; (IE NO DISK SPACE)
IMGINT:	POINT	9,JBTSWP(F),35	;POINTER TO INCORE IMAGE
IMGIP3::POINT	9,JBTSWP(P3),35
>

IFN FT2REL,<INTERN JBYSPR
JBYSPR:	POINT	JBSSPR,JBTSTS(J),JBNSPR	;HIGH SEG ACCESS PRIVILEGES
>

IFG SYS50N,<			;SWAPPING SYSTEM?
IFN LEVDN,<INTERN JBYSUN,JBYLKN
JBYSUN:	POINT	3,JBTSWP(J),4
JBYLKN:	POINT	13,JBTSWP(J),17
>	;END CONDITIONAL ON LEVDN
>	;END OF CONDITIONAL ON 10/50S
IFN FTWATCH,<		;WATCH JOB STATISTICS FEATURE?
	INTERN	JBYWCH
JBYWCH:	POINT	23,JBTWCH(J),35	;BYTE POINTER TO TIME OF DAY STARTED WAITING
				;END FT WATCH
>
IFN FTTLIM,<INTERN JBYLCR,JBYLTM
JBYLCR:	POINT	9,JBTLIM(J),^L<JB.LCR>+8 ;CORE LIMIT POINTER
JBYLTM:	POINT	36-^L<JB.LTM>,JBTLIM(J),35 ;TIME LIMIT POINTER
>
IFN FTNSCHED,<
JBYCLS::POINT 5,JBTSCD(J),17	;POINTER TO CLASS FOR JOB.
JBYCL1::POINT 5,JBTSCD(T1),17	;DITTO FOR IDX T1
JBYCL4::POINT 5,JBTSCD(T4),17	;DITTO FOR IDX T4
>;END IFN FTNSCHED

INTERN PDVIAD,PDVOAD
PDVIAD:	POINT 22,DEVIAD(F),35	;POINTER FOR STORING EVA OF CURRENT INPUT BUFFER
PDVOAD:	POINT 22,DEVOAD(F),35	;POINTER FOR STORING EVA OF CURRENT
				; OUTPUT BUFFER
IFN FTKI10!FTKL10,<

IFN M.KI10!M.KL10,<INTERN JBYLSA,JBYHSA,JBYHSO,JBYLSS,JBYHSS

JBYLSA:	POINT 13,.UPMP+400,35	;POINTER TO PHYSICAL PAGE NO. OF FIRST PAGE
				; OF THIS LOW SEGMENT
JBYHSA:	POINT 13,JBTHSA(J),35	;POINTER TO PHYSICAL PAGE NO. OF FIRST PAGE
				; OF THIS HIGH SEGMENT
JBYHSO:	POINT	9,JBTUPM(J),8	;VIRTUAL PAGE NUMBER OF HIGH SEGMENT ORIGIN
JBYLSS:	POINT 9,JBTUPM(J),17	;NO. OF PAGES-1 IN THE LOW SEGMENT THE
				; LAST TIME THE MAP WAS SET UP
JBYHSS:	POINT 9,JBTUPM(J),8	;NO. OF PAGES-1 IN THE HIGH SEGMENT THE
				; LAST TIME THE MAP WAS SET UP
>>	;IFN FTKI10!FTKL10 & M.KI10!M.KL10
IFN FTACCT,<
LSTBAS::POINT	7,.PDACS+ACTSTL-1(W),34  ;LAST BYTE IN ACCOUNT STRING
>
	$ABS
IFN FTKL10,<IFG CPUN,<
	LOC	<.+777>&777000
>>
CSHFIR==:.
MNULPD=:-110+1			;LENGTH OF KL10 NULL PDL, MUST BE LONGER
				; THAN KA'S JUST AS KI10 NULL PDL IS.

NULPDL::BLOCK	-MNULPD		;PUT KL10 NULL PDL HERE SO IT WON'T MASH
				; DTE LOCATIONS IN THE EPT, WHICH
				;START AT 140

IFG <CPUN-1>,<

	MNU1PD==MNULPD
NU1PDL::BLOCK	-MNU1PD		;MAKE SLAVE NULPDL BE SAME AS MASTER
>
SUBTTL PI CHANNEL SAVE/RESTORE
;DEFINE PI CHANNEL SAVE AND RESTORE ROUTINES IF A DEVICE IS ON THE CHANNEL

	PDL==111		;LENGTH OF INTERRUPT PI PUSH DOWN LIST

DEFINE CHAN (PI)<
	XLIST
	IFNDEF	HIAC'PI,<HIGHAC==13>
	IFDEF	HIAC'PI,<
	IFGE	HIAC'PI-10,<HIGHAC==HIAC'PI>
	IFL	HIAC'PI-13,<HIGHAC==13>
>	;IFDEF
	IFG	RTTRPN,<HIACBL==17>
	IFE	RTTRPN,<HIACBL==HIGHAC>
	INTERNAL SAV'PI,RET'PI,CH'PI,C'PI'JEN,C'PI'PDP,HIGHAC,SVAC'PI,C'PI'PD1
CH'PI:	0		;PC STORED HERE BY JSR ON INTERRUPT TO CHANNEL PI
	JEN	@CH'PI		;LAST INSTRUCTION ON CONSO DEV, CHAIN

DEFINE FSTCHN,<
ZZS==0
IFN M.KL10,<
IFE <PI-SCNCHN>,<ZZS==2>	;USE EXEC AC BLOCK 2 ON SCANNER CHANNEL
IFE <PI-DSKCHN>,<ZZS==3>	;USE EXEC AC BLOCK 3 ON DSK CHANNEL
>
>

;CHAN DEFINITION CON'T ON NEXT PAGE
;CONTINUE CHAN DEFINITION

;HERE FROM AN INTERRUPT ROUTINE WHICH HAS FOUND ITS DEVICE NEEDS SERVICE
;SAVE ACS 0 THRU HIGHAC, CALLED BY JSR, SETS UP P TO PUSH DOWN LIST FOR THIS PI
	FSTCHN		;ZZS NON-ZERO IF SCANNER OR DSK PI SAVE ROUTINE

SAV'PI:	0		;CALLED BY JSR
IFN M.KL10,<
	DATAI	PAG,SVPG'PI	;REMEMBER OLD AC BLOCK #
	EXECAC	(ZZS)	;SET EXEC AC BLOCK
	XLIST
>
IFE ZZS,<
	MOVEM	HIGHAC,SVAC'PI+HIGHAC	;SAVE AC HIGHAC
IFN M.KI10!M.KL10,<
IFL PI-11,<IFG RTTRPN,<
	SKIPN	HIGHAC,TRPFLG	;ALWAYS SAVE ACS IF RTTRP IS IN PROGRESS
>>
	MOVE	HIGHAC,CH'PI	;GET INTERRUPT PC
	TLNE	HIGHAC,(XC.USR)	;WAS THE INTERRUPT OUT OF EXEC MODE
	JRST	SAV'PI'A	;NO, DON'T NEED TO SAVE AC'S
>
	MOVEI	HIGHAC,SVAC'PI	;SETUP TO SAVE 0 THRU HIGHAC-1
	BLT	HIGHAC,SVAC'PI+HIGHAC-1	;SAVE ACS
>
SAV'PI'A:	MOVE	P,C'PI'PDP	;SETUP PUSH DOWN POINTER
IFN M.KI10!M.KL10,<
	MOVSI	(IC.UOU)	;TURN ON USER IOT SO XCT PAGED WILL
	HLLM	SAV'PI		; REFERENCE USER RATHER THAN EXEC VIRTUAL MEMORY
>	;END IFN M.KI10!M.KL10
	JRST	2,@SAV'PI	;RETURN TO CALLER AND PROCESS INTERRUPT

;HERE FROM INTERRUPT ROUTINE WHEN IT HAS FINISHED SERVICING INTERRUPT
;RESTORE ACS AND DISMISS INTERRUPT
;USUALLY TRANSFERRED TO BY POPJ P,

	$HIGH
RET'PI:
IFE ZZS,<
IFN M.KI10,<
IFL PI-11,<IFG RTTRPN,<
	SKIPN	HIGHAC,TRPFLG	;RESTORE SAVED ACS IF RTTRP IS IN PROGRESS
>>
	MOVE	HIGHAC,CH'PI	;GET INTERRUPT PC
	TLNE	HIGHAC,(XC.USR)	;WAS THE INTERRUPT OUT OF USER MODE
	JEN	@CH'PI		;YES, AC'S WEREN'T SAVED
>
IFN M.KL10,<
IFL PI-11,<IFG RTTRPN,<
	SKIPN	HIGHAC,TRPFLG	;RESTORE SAVED ACS IF RTTRP IS IN PROGRESS
>>
	MOVE	HIGHAC,CH'PI	;GET INTERRUPT PC
	TLNE	HIGHAC,(XC.USR)	;WAS THE INTERRUPT OUT OF USER MODE?
	JRST	CH'PI'XIT	;YES--AC'S WERE NOT SAVED
>
	MOVSI HIGHAC,SVAC'PI	;RESTORE ACS 0 THRU HIGHAC
	BLT	HIGHAC,HIGHAC
>
IFN M.KL10,<
CH'PI'XIT:
	DATAO	PAG,SVPG'PI	;RESTORE OLD AC BLOCK #
>
C'PI'JEN:	JEN @CH'PI		;DISMISS INTERRUPT ON THIS PI CHANNEL
	$ABS

IFG RTTRPN,<
IFN M.KA10,<
		RTPOPN==6
>	;END IFN M.KA10
IFN M.KI10,<
		RTPOPN==24
>	;END IFN M.KI10
IFN M.KL10,<
	RTPOPN==27
>	;END IFN M.KL10
		RETPD'PI==C'PI'PD1+RTPOPN
		RTOFST==CHD'PI-CHND'PI

CHND'PI:	HRROI P,RETPD'PI
		IFLE PI-AP0CHN,<JSP J,DSMAPR>
		IFG  PI-AP0CHN,<JSP J,DISMIS>
RTRT'PI:	MOVSI 17,SVAC'PI	;RESTORE AL OF THE AC'S
		BLT 17,17
IFN M.KL10,<
		DATAO PAG,SVPG'PI	;RESTORE AC BLOCK
>	;END IFN M.KL10
		JEN @CH'PI		;DISMISS

RTSV'PI:	0			;COME HERE TO SAVE ALL AC'S
IFN M.KL10,<
		DATAI PAG,SVPG'PI	;SAVE AC BLOCK
		EXECAC			;SET EXEC AC BLOCK
>	;END IFN M.KL10
		MOVEM 17,SVAC'PI+17	;SAVE 17
		MOVEI 17,SVAC'PI	;SET UP BLT POINTER
		BLT 17,SVAC'PI+16	;SAVE THE AC'S
		MOVE P,C'PI'PDP		;SET UP P POINTER
IFN M.KI10!M.KL10,<
		MOVSI (IC.UOU)		;TURN ON USER IOT SO PAGED XCT
		HLLM RTSV'PI		; WILL REFERENCE USER VIRTUAL
>	;END IFN M.KI10!M.KL10
		JRST 2,@RTSV'PI		;RETURN TO CALLER

CHD'PI:		EXP ENBSTD
		Z	;STORAGE LOCATION FOR PROTECTION-RELOCATION VALUE.
		Z	;STORAGE LOCATION FOR APR ENABLE BITS.
>	;IFG RTTRPN

IFN M.KL10,<
SVPG'PI:	BLOCK	1
IFE ZZS-2,<SVSCPG==SVPG'PI>
>
SVAC'PI:	BLOCK HIACBL+1	;PLACE TO SAVE ACS 0 THRU HIGHAC
C'PI'PDP:	XWD -PDL+1,.+1		;INITIAL PUSH DOWN POINTER
C'PI'PD1:	EXP RET'PI	;FIRST WORD ON LIST,
				; POPJ WILL RETURN TO DISMISS INTERRUPT
	BLOCK	PDL-1		;PUSHDOWN LIST SPACE
	LIST
>	;END OF CHAN DEFINITION

;SET USED'N TO BE NON-ZERO FOR ALL CHANNELS
;THAT NEED CHANNEL SAVE ROUTINES
;THIS INCLUDES ALL CHANNELS WHICH RTTRP MAY USE
IFG RTTRPN,<
	DEFINE	SETUSED(PI)
	<CUSD'PI==USED'PI
	IFE USED'PI,<IFDEF UNIQ'PI,<IFE UNIQ'PI,<USED'PI=-1>>
IFN M.DTA,<
IFE PI-DADCHN,<CUSD'PI==1	;DON'T ALLOW FAST BLOCK MODE ON DTA DATA CHN
>>
					IFNDEF UNIQ'PI,<USED'PI=-1>>
>	;DEFINE SETUSED

	ZZ=1
	REPEAT	6,<XLIST
	SETUSED(\ZZ)
		ZZ=ZZ+1
	LIST>

IFG CPUN-1,<	;MORE THAN ONE CPU?
	ZZ==11
	REPEAT 6,<XLIST
	SETUSED(\ZZ)
		ZZ==ZZ+1
	LIST>

>	;END CPUN CONDITIONAL
>	;IFG RTTRPN
;GENERATE THE CHANNEL SAVE ROUTINE ONLY FOR PI WHICH NEED THEM (ASGSAV MACRO USED)

	IFN	USED1, <CHAN 1>
	IFN	USED2, <CHAN 2>
	IFN	USED3, <CHAN 3>
	IFN	USED4, <CHAN 4>
	IFN	USED5, <CHAN 5>
	IFN	USED6, <CHAN 6>
	IFN	USED7, <CHAN 7>
	IFN	USED11,<CHAN 11>
	IFN	USED12,<CHAN 12>
	IFN	USED13,<CHAN 13>
	IFN	USED14,<CHAN 14>
	IFN	USED15,<CHAN 15>
	IFN	USED16,<CHAN 16>
	IFN	USED17,<CHAN 17>



;GENERATE NULL CHANNEL SAVE ROUTINES FOR THOSE CHANNELS NOT USED

DEFINE NULL (PI)<
	XLIST
	INTERNAL CH'PI
CH'PI:	0
	JEN	@CH'PI
	LIST
>

	IFE	USED1, <NULL 1>
	IFE	USED2, <NULL 2>
	IFE	USED3, <NULL 3>
	IFE	USED4, <NULL 4>
	IFE	USED5, <NULL 5>
	IFE	USED6, <NULL 6>
	IFE	USED7, <NULL 7>
	IFE	USED11,<NULL 11>
	IFE	USED12,<NULL 12>
	IFE	USED13,<NULL 13>
	IFE	USED14,<NULL 14>
	IFE	USED15,<NULL 15>
	IFE	USED16,<NULL 16>
	IFE	USED17,<NULL 17>

IFN FTKL10,<IFG CPUN,<
	LOC	<.+777>&777000
>>
CSHLAS==:.-1
;NOW DEFINE DURING PASS 1 A FEW NECESSARY SYMBOLS 

	DEFINE DEFCHL(A,B)
<	A'CHL==CH'B>

DEFCHL (<AP0>,\AP0CH1)
DEFCHL (<CK0>,\CK0CH1)
IFG <CPUN-1>,<
	DEFCHL (<AP1>,\AP1CH1)
	DEFCHL (<CK1>,\CK1CH1)
>

	SUBTTL	DAS78 INTERRUPTS TO HERE
DLXFS1::	;DON'T CACHE FROM HERE TO DLXLS1

	IFN	PDP11N,<

IFN	XPANDN,<LALL>			;EXPAND LISTING IF WANTED FROM MONGEN


	ZZD78A==0

;INTERRUPT ROUTINE FOR EACH DAS78

DEFINE	EACH78(PORTN),<
IFN	M.'PORTN'D78,<

IFLE	PORTN-3,<DLBD78=60
	DLCD78=64>			;FIRST DL10
IFG	PORTN-3,<DLBD78=160
	DLCD78=164>			;SECOND DL10

IFN	FTKI10!FTKL10,<			;KI-10 ONLY FEATURE
	$HIGH
IFG	PORTN,<JRST D80'PORTN'KA>
	$ABS
D80'PORTN'KI:	Z			;DL10 FORCES JSR TO HERE
	JRSTF	@[IC.UOU+<D80'PORTN'IN>]  ;LET EXECUTE WORK CORRECTLY
	$HIGH
D80'PORTN'IN:
	CONO	DLCD78,1B19+1B<32-<3*<PORTN&3>>>+XXICHN	;TURN OFF INTERRUPT
IFE FTKL10,<
	MOVEM	13,XXISAC+13		;SAVE 0-13 AC'S
	MOVEI	13,XXISAC		;
	BLT	13,XXISAC+12		;
>;END IFE FTKL10
IFN FTKL10,<
	DATAI	PAG,SVSCPG
	EXECAC	(2)
>;END IFN FTKL10
	MOVE	P,XXIPDP		;SETUP PUSH DOWN POINTER
	SKIPE	J,M78BT+PORTN		;SET J TO POINT TO WINDOW FOR PORT PORTN
	  PUSHJ	P,D78KII##		;GO TO DAS78 INTERRUPT SERVICE ROUTINE
IFE FTKL10,<
	MOVSI	13,XXISAC		;RESTORE 0-13 AC'S
	BLT	13,13			;
>;END IFE FTKL10
IFN FTKL10,<
	DATAO	PAG,SVSCPG		;RESTORE AC BLOCK
>;END IFN FTKL10
	JEN	@D80'PORTN'KI		;RETURN TO INTERRUPTED CODE.
>;END IFN FTKI10!FTKL10.

	$HIGH
IFNDEF	DLXSCC,<
DLXSCC:
>	;END IFNDEF DLXSCC
D80'PORTN'KA:	CONSO	DLCD78,1B<32-<3*<PORTN&3>>>	;IS THIS PDP11 INTERRUPTING?
	JRST	DLX'PORTN'NX		;TRY THE NEXT ONE
	CONSO	DLCD78,1B31_<<PORTN&3>*3>	;PORT PORTN ENABLED?
	JRST	.-2			;NO, IGNORE.
	CONO	DLCD78,1B19+1B<32-<3*<PORTN&3>>>+XXICHN	;TURN OFF INTERRUPT
	JSR	XXISAV			;SAVE THE AC'S
	SKIPE	J,M78BT+PORTN		;LOAD BASE ADDRESS
	  PUSHJ	P,D78KII##		;GO TO INTERUPT SERVICE ROUTINE
	POPJ	P,			;RESTORE REGS AND EXIT.

;BASE TABLE FOR DAS78 DL10
;
M80'PORTN'BT:
	PHASE	0
M78CPE::!CONO	DLCD78,XXICHN+<1B31_<<PORTN&3>*3>>	;CLEAR PORT ENABLE FOR PORT PORTN
M78I10::!CONSO	DLCD78,1B32_<<PORTN&3>*3>		;SEE IF PDP11 PORTN SET 10 INT
M78I11::!CONO	DLCD78,1B19+1B20+XXICHN+<1B30_<<PORTN&3>*3>>	;SET PDP11 INTERRUPT ON PORTN
M78SWA::!CONO	DLBD78,M8'PORTN'KII!M8'PORTN'BAM!<PORTN&3>	;LOAD ADDRESS FOR PORT PORTN
M78ENP::!CONO	DLCD78,1B20+XXICHN+<1B31_<<PORTN&3>*3>>	;ENABLE PORT PORTN
M78CPI::!CONSO	DLCD78,7			;SEE IF PIA ASSIGNED
M78SPI::!CONO	DLCD78,XXICHN			;GIVE PI CHN ASSIGNMENT
M78PNO::!PORTN,,.DL'PORTN'BS			;;PORT##,,WINDOW
IFN M.PSI,<
M78PSI::!DATAO	DLCD78,[200001,,0]	;KA STYLE INTERRUPTS 
>					; SO PSISER CAN FIND THE PC
IFE M.PSI,<
M78PSI::!JFCL
>
M78SER::!DATAO	DLBD78,[<PORTN&3>_^D<35-5>]  ;PUT PORT NUMBER IN THE "R" REGISTER
M78GWA::!CONI	DLBD78,T1	;GET BASE ADDRESS
	DEPHASE

DLX'PORTN'NX::
	$ABS

>;END IFN M.'PORTN'D78
>;END DEFINE EACH78

;INTERRUPT ROUTINE FOR EACH PDP11
DEFINE	EACH76(N)<

IFLE N-3,<DLX=DLC
	DLBX=DLB>		;FIRST DL10
IFG N-3,<DLX=DLC2
	DLBX=DLB2>		;SECOND DL10
DLCX=DLX
IFN	M.KI10!M.KL10,<		;KI10 ONLY FEATURE
	$HIGH
IFG	N,<JRST D70'N'KA>
	$ABS
D70'N'KI:	Z		;DL10 FORCES JSR TO HERE
	JRSTF	@[IC.UOU+<D70'N'IN>]  ;;LET EXECUTE WORK CORRECTLY
	$HIGH
D70'N'IN:CONO	DLX,1B19+1B<32-<3*<N&3>>>+SCNCHN ;TURN OFF INTERRUPT
IFE M.KL10,<
	MOVEM	DLXHAC,SCNSAC+DLXHAC  ;SAVE THE ACS
	MOVEI	DLXHAC,SCNSAC	; ..
	BLT	DLXHAC,SCNSAC+DLXHAC-1
>
IFN M.KL10,<
	DATAI	PAG,SVSCPG	;SAVE AC SETTINGS
	EXECAC	(2)		;USE AC BLOCK 2, PREVIOUS = 1
	XLIST
>
	MOVE	P,SCNPDP	;SET UP PUSH DOWN POINTER
	SKIPE	W,DLXBAT+N	;SET UP BASE ADDRESS
	XCT	DLXINI(W)	;TAKE ACTION FOR THIS INTERRUPT
IFE M.KL10,<
	MOVSI	DLXHAC,SCNSAC	;RESTORE THE ACS
	BLT	DLXHAC,DLXHAC	; ..
>
IFN M.KL10,<
	DATAO	PAG,SVSCPG	;RESTORE AC BLOCK
>
	JEN	@D70'N'KI	;RETURN TO INTERRUPTED CODE

>	;END IFN M.KI10!M.KL10
	$HIGH
IFNDEF DLXSCC,<
DLXSCC::
>
D70'N'KA:CONSO	DLX,1B<32-<3*<N&3>>>;IS THIS -11 INTERUPTING?
	JRST	DLX'N'NX	;NO--TRY THE NEXT ONE
	CONSO	DLX,1B31_<<N&3>*3> ;PORT ENABLED?
	JRST	.-2		;NO, IGNORE.
	CONO	DLX,1B19+1B<32-<3*<N&3>>>+SCNCHN ;TURN OFF INTERRUPT
	JSR	SCNSAV		;SAVE THE ACS
	SKIPE	W,DLXBAT+N	;LOAD BASE REGISTER
	XCT	DLXINI(W)	;DO INTERRUPT THING
	POPJ	P,		;RESTORE REGS AND EXIT

	IFN M.DC76,<
DC76'N'D::JRST	[PUSHJ P,SETJ'N	;SET UP J AS BASE ADDRESS
		 PJRST D76TYP##];CALL TYPEOUT ROUTINE
	JRST	[PUSHJ P,SETJ'N
		 PJRST D76DSC##];MODEM CONTROL
	POPJ	P,		;NO PI CHANNEL TO CHECK ON
	POPJ	P,0		;NO INIT
	JRST	[PUSHJ P,SETJ'N
		 PJRST D76CHP##];CHANGE HARDWARE PARAMETERS
	JRST	[PUSHJ P,SETJ'N
		 PJRST D76LPC##];LINE PARAMETER CONTROL

	JRST	[PUSHJ P,SETJ'N
		PJRST D76ELE##]  ;SET ELEMENT
	POPJ	P,		;REMOTE STATION STUFF
	JRST	[PUSHJ P,SETJ'N
		 PJRST D76OFL##]

SETJ'N:	EXCH	J,(P)		;SAVE J
	MOVEM	J,1(P)		;SAVE RETURN ADDRESS
	MOVE	J,DLXBAT+N	;POINT TO BASE OF MAP
	MOVE	J,DLXWIN(J)	; ..
	PUSHJ	P,@1(P)		;DO FUNCTION
	  PJRST	IPOPJ		;RETURN
	PJRST	IPOPJ1		;ALLOW CPOPJ1
>	;IFN	M.DC76
	$ABS


;BASE TABLE FOR DL10.  CONTAINS WINDOW ADDRESS AND OTHER THINGS

DL'N'BAS:	PHASE	0
DLXWIN::!EXP	.DL'N'BS	;WINDOW
DLXNMT::!0			;NAME OF PDP11 PGM
DLXINI::!JFCL			;DO THIS ON INTERRUPT
DLXMSK::!EXP	777777700007!<70_<<N&3>*3>> ;"AND" OUT OTHER PDP11 BITS
DLXSWA::!CONO	DLBX,DC76'N'M+<M7'N'BAM>_2+<N&3>
				;SET UP WINDOW ADDRESS
DLXENB::!CONO	DLX,1B19+1B20+<1B31_<<N&3>*3>>+SCNCHN
				;ENABLE WINDOW AND INTERRUPTS.
DLXCAL::!0			;POINTER TO CAL11. UUO TABLE
DLXCEU::!0			;CAL11. USER'S JOB NUMBER
DLXPRG::!JFCL			;DO THIS WHEN PDP11 GOES DOWN
DLXCLR::!CONO	DLX,1B19+<70_<<N&3>*3>>+SCNCHN ;CLEAR PORT ENB
DLXCNI::!CONI	DLX,T1		;READ DL10 CONDITIONS
DLXI11::!CONO	DLX,1B19+1B20+<1B30_<<N&3>*3>>+SCNCHN
				;INTERRUPT THE PDP11
IFN	M.PSI&<M.KI10!M.KL10>,<
DLXDAO::!DATAO	DLX,T1		;KA10 STYLE INTERRUPTS SO PSISER CAN
				; FIND THE PC
>;END	IFN	M.PSI
DLXTYP::!EXP	TP.DL'N
IFN	M.'N'D85	<
DLXPRE::PUSHJ	P,D85PRE##
>;END	IFN	M.'N'D85
IFE	M.'N'D85	<
DLXPRE::JFCL
>;END	IFN	M.'N'D85
				;INTERRUPT THE PDP11
IFN M.'N'D85,<
DLXFEK::D8'N'FEK##		;ADDRESS OF ASSOCIATED FEK
>	;END OF IFN M.'N'D85

	DEPHASE

$HIGH
DLX'N'NX:
$ABS
	XALL
>
	DEFINE	MEAC76(N)
<	IFN	TP.DL'N,<
	IFE	M.'N'D78,<
	EACH76(N)
>
	IFN	M.'N'D78,<
	EACH78(N)
>>>
ZZZ=0
	REPEAT	10,<
	MEAC76(\ZZZ)
	ZZZ==ZZZ+1
>

	$HIGH
	JRST	DLXINT+1	;CONSO CHAIN FALLS OUT HERE
	$ABS
XXIINT:
DLXINT:	JRST	DLXSCC		;LOOK AT EACH -11
	JRST	.+1		;LOOK AT OTHER DEVICES
IFN M.DAS78,<
	DEFINE	B78BT(N),<
	IFNDEF	M80'N'BT,<	Z	>
	IFDEF	M80'N'BT,<M80'N'BT>>
	$HIGH
M78BT::
ZZZ=0
	REPEAT	<M78HPO+1>,<
	B78BT(\ZZZ)
	ZZZ=ZZZ+1>
>;END IFN M.DAS78
	$ABS
>	;END OF IFN PDP11N
DLXLS1::	;DON'T CACHE FROM DLXFS1 TO HERE
SUBTTL UUO AND ILL. INST. HANDLERS
IFN M.KA10,<
;HERE ON TRAPS TO LOC 60/61 - UNIMPLEMENTED INSTRUCTIONS (PDP10 ONLY)
;OPCODE AND EFFECTIVE ADDRESS STORED IN SIXTY AND 61 EXECUTED (JSR UUO2)
;OP CODE 100 (UJEN) IS USED TO DISMISS USER MODE INTERRUPTS FOR REAL TIME OPERATION
;USED IN CONJUNCTION WITH TRPSET UUOWHICH IS SOON TO BE REPLACED
;WITH SOME KNAVE-PROOF REAL TIME UUOS.  THIS CODE IS HERE ONLY
;BECAUSE MANUAL DESCRIBES TRPSET AND TRPJEN UUOS.
;TRPJEN HAS BEEN REPLACED WITH OPCODE 100 (UJEN).
;CALL:	UGEN U			;WHERE U CONTAINS PC STORED BY INTERRUPT JSR

	INTERNAL UUO2

UUO2:	0			;USER PC STORE HERE BY JSR
	EXCH	T1,UUO2		;GET USER PC, SAVE T1
IFN FTTRPSET, <
	TLNN	T1,UIOMOD	;USER I/O MODE ON ?
	JRST	UUOER2		;NO, TREAT AS AN ILLEGAL INSTRUCTION AND PRINT MESS.
	HLL	T1,MPTRP2	;YES, GET UNIMPLEMENTED OPCODE WHICH TRAPPED
	TLNE	T1,677777	;IS IT OPCODE 100 (UJEN)?
	JRST	UUOER1		;NO, TREAT AS ILLEGAL INSTRUCTION
	MOVE	T1,.C0DTO	;YES, GET RELOCATION FOR JOB ON THIS CPU
				; (NULL JOB MAYBE RUNNING, BUT IT DOESN'T CHANGE DTO
	ANDI	T1,776000	;MASK OUT ALL BUT RELOCATION BITS
	ADD	T1,MPTRP2	;ADD EFFECTIVE ADR. OF UJEN
	MOVE	T1,(T1)		;GET PC STORED BY INTERRUPT JSR
	EXCH	T1,UUO2		;RESTORE T1, AND STORE PC
	JEN	@UUO2		;DISMISS INTERRUPT

UUOER1:	HRLI	T1,USRMOD!UIOMOD	;SET USER MODE AND USER I/O MODE BACK ON
>
UUOER2:	MOVEM	T1,UUO0		;STORE PC AS IF AN ILLEGAL INSTR. HAD OCCURRED
	MOVE	T1,MPTRP2	;GET INSTRUCTION EXECUTED
	MOVEM	T1,MPTRAP	;MAKE IT LOOK LIKE AN ILLEGAL INSTRUCTION
				; TRAPPED TO 40
	SKIPA	T1,UUO2		;RETORE T1 AND FALL INTO REGULAR UUO HANDLER

;HERE ON TRAPS ON CPU0 - OPCODES 0,40-77 (0-77 ON PDP-6)
; USUALLY FROM LOC 40/41 UNLESS CPTOS DEFINED NON-ZERO WITH MONGEN
; TO REVERSE THE OFFSETS

	INTERNAL UUO0
	EXTERNAL UUOSY1

UUO0:	0			;JSR HERE FROM LOC 41
	MOVEM	17,USRSAV	;SAVE 17
	AOS	.C0TUC		;INCR TOTAL UUO COUNT FOR CPU0
				; (INCLUDE TRAPS TO 60 EXCEPT UJEN)
	MOVE	17,UUO0		;GET PROCESSOR FLAGS
	TLNN	17,USRMOD	;IS UUO FROM MONITOR ?
	JRST	UUOSY1		;YES, DO NOT SAVE ACS
	SKIPN	17,JOBADR	;IS THERE A JOB DATA AREA ?
	JRST	UUORSC		;NO, MUST BE UUO DURING NULL JOB
IFE PDP10N, <			;FOR PDP-6 OPCODES 1-37
	EXCH	T1,MPTRAP	;SAVE T1, PICK UP UUO
	TLNN	T1,740000	;IS THIS SYSTEM UUO ?
	TLNN	T1,077000	;NO, IS IT 0 UUO ?
	JRST	UUOSYS		;YES
	MOVEM	T1,40(17)	;STORE UUO IN USER'S 40
	HRRZ	T1,41(17)	;PICK UP ADR OF USER'S JSR
	JUMPE	T1,UUOSYS	;IF ADDRESS=0,ILLEGAL USER UUO
	HLL	T1,UUO0		;USER PD FLAGS (RESTORED ON RETURN)
	MOVEI	17,(T1)		;17 NOW HAS REL.ADR+1 OF USER JSR
	CAML	17,USRREL	;IS EFFECTIVE ADDRESS IN BOUNDS ?
	JRST	UUOSY0		;ERROR, JSR EFF. ADDR. OUTSIDE USER AREA
	HRRI	T1,1(T1)	;YES, INCREMENT PC.
	EXCH	T1,UUO0		;SET UP RETURN TO USER IN UUO0
				; PICKUP USERS FLAGS,PC
	ADD	17,JOBADR	;MAKE REL. ADDRESS INTO ABSOLUTE ADDRESS
	MOVEM	T1,(17)		;STORE FLAGS AND PC LIKE JSR
	MOVE	T1,MPTRAP	;RESTORE T1
	MOVE	17,USRSAV	;RESTORE 17
	JRST	2,@UUO0		;RETURN TO USER (RESTORING FLAGS)

UUOSY0:	MOVE	17,JOBADR	;SETUP 17 FOR LOW SEGMENT RELOCATION
UUOSYS:	EXCH	T1,MPTRAP	;RESTORE USERS AC(T1) AND USER'S UUO (FORTY)
>
UUOUSR:	MOVEM	16,16(17)	;STORE AC16 IN USER16
	MOVEI	16,(17)		;SETUP BLT POINTER
	BLT	16,15(17)	;MOVE REAL ACS TO USER AREA
	MOVE	T1,.C0SAV	;MOVE USER'S 17 TO USERS AREA
	MOVEM	T1,17(17)
	MOVE	R,17		;LOAD UP PUSH DOWN POINTER TO USER'S AREA
	MOVEI	F,0		;INDICATE NO DDB IN CASE THIS IS AN ILLEGAL
				; UUO. (JOB OWNS NO DISK RESOURCES)
	MOVSI	P,MJOBPD##	;LOAD UP PUSH DOWN AC AND
	HRRI	P,JOBPDL##(R)	; MAKE ABSOLUTE RATHER THAN RELATIVE
	JRST	UUOSY1		;GO DISPATCH ON THE UUO

	INTERN	UMPRET
UMPRET:	POP	P,UUO0		;USER RETURN ADDRESS
	MOVSI	17,JOBAC##(R)	;RESTORE ALL USER ACS
	BLT	17,17
	JEN	@UUO0		;RESTORE FLAGS AND RETURN TO USER
				; DISMISS INTERRUPT ONLY ON REAL TIME UUOS
				; IN ALL OTHER CASES NO INTERRUPT
				; IN PROGRESS
UUORSC:	MOVE	17,WAKINS##	;IS THIS A WAKE UUO FROM THE NULL JOB
	CAME	17,MPTRAP
	JRST	UUONLJ

UUORS1:	MOVEI	17,NU0DAC	;SAVE NULL JOB AC'S
	BLT	17,NU0DAC+16	; IN NULL JOB DATA AREA
	MOVE	17,USRSAV	;GET AC 17
	MOVEM	17,NU0DAC+17	;SAVE AWAY
	MOVE	17,UUO0		;PICK UP PC
	MOVEM	17,.C0PC	;SAVE FOR FUTURE RETURN
	SETZM	.C0DBL		;CLEAR DOORBELL FLAG
	JRST	CK0SPD##	;GO RESCHEDULE
UUONLJ:	EXCH	P,PIEPDL##	;SETUP P
	STOPCD	.+1,DEBUG,UNJ,	;++UUO FROM NULL JOB
IFG <CPUN-1>,<
	SKPCPU	(0)		;CPU0?
	JRST	UUO1R1		;NO, DO CPU1 CONTINUE
>
	JRST	UUORS1		;CONTINUE

;CPU1 TRAPS HERE WHENEVER A UUO FROM SPTRP2 IS DONE
; UNIMPLEMENTED OPCODES, UJEN
; USUALLY FROM 160/161 UNLESS CPTOS HAS BEEN DEFINED
; NON-ZERO TO SWITCH CPU OFFSETS
IFG <CPUN-1>,<
	INTERNAL UUOSP2

UUOSP2:	0			;USER PC STORE HERE BY JSR
	EXCH	T1,UUOSP2	;GET USER PC, SAVE T1
IFN FTTRPSET, <
	TLNN	T1,UIOMOD	;USER I/O MODE ON ?
	JRST	UUOER4		;NO, TREAT AS AN ILLEGAL INSTRUCTION AND PRINT MESS.
	HLL	T1,SPTRP2	;YES, GET UNIMPLEMENTED OPCODE WHICH TRAPPED
	TLNE	T1,677777	;IS IT OPCODE 100 (UJEN)?
	JRST	UUOER3		;NO, TREAT AS ILLEGAL INSTRUCTION
	MOVE	T1,.C1DTO	;YES, XWD PROTECTION, RELOCATION FOR CURRENT JOB ON CPU1
				; (NULL JOB DOES NOT CHANGE THIS WHEN IT RUNS)
	ANDI	T1,776000	;MASK OUT ALL BUT RELOCATION
	ADD	T1,SPTRP2	;ADD EFFECTIVE ADDRESS OF UJEN
	MOVE	T1,(T1)		;GET PC STORED BY INTERRUPT JSR
	EXCH	T1,UUOSP2	;RESTORE T1, AND STORE PC
	JEN	@UUOSP2		;DISMISS INTERRUPT

UUOER3:	HRLI	T1,USRMOD!UIOMOD	;SET USER MODE AND USER I/O MODE BACK ON
>
UUOER4:	MOVEM	T1,UUOSP0		;STORE PC AS IF AN ILLEGAL INSTR. HAD OCCURRED
	MOVE	T1,SPTRP2	;GET INSTRUCTION EXECUTED
	MOVEM	T1,SPTRAP	;MAKE IT LOOK LIKE AN ILLEGAL INSTRUCTION
				; TRAPPED TO 40
	SKIPA	T1,UUOSP2	;RETORE T1 AND FALL INTO REGULAR UUO HANDLER

>
;CPU1 TRAPS HERE ON TO-MONITOR UUOS
; USUALLY FROM 140/141 UNLESS CPTOS HAS BEEN DEFINED
; NON-ZERO WITH MONGEN TO REVERSE CPU OFFSETS
IFG <CPUN-1>,<
	INTERNAL UUOSP0
	EXTERNAL UUOUSP

UUOSP0:	0			;JSR HERE FROM LOC 41 OR 141
	MOVEM	17,.C1SAV	;SAVE 17
	AOS	.C1TUC		;INCR TOTAL UUO COUNT ON CPU1
				; (INCLUDE TRAP FROM 160 EXCEPT UJEN)
	MOVE	17,UUOSP0	;GET PROCESSOR FLAGS
	TLNE	17,USRMOD	;IS UUO FROM MONITOR ?
	SKIPN	17,.C1ADR	;IS THERE A JOB DATA AREA ?
	JRST	UUO1RS		;NO, MUST BE UUO DURING NULL JOB
IFE PDP10N, <			;FOR PDP-6 OPCODES 1-37
	EXCH	T1,SPTRAP	;SAVE T1, PICK UP UUO
	TLNN	T1,740000	;IS THIS SYSTEM UUO ?
	TLNN	T1,077000	;NO, IS IT 0 UUO ?
	JRST	UUOSY3		;YES
	MOVEM	T1,40(17)	;STORE UUO IN USER'S 40
	HRRZ	T1,41(17)	;PICK UP ADR OF USER'S JSR
	JUMPE	T1,UUOSY3	;IF ADDRESS=0,ILLEGAL USER UUO
	HLL	T1,UUOSP0		;USER PD FLAGS (RESTORED ON RETURN)
	MOVEI	17,(T1)		;17 NOW HAS REL.ADR+1 OF USER JSR
	CAML	17,.C1REL	;IS EFFECTIVE ADDRESS IN BOUNDS ?
	JRST	UUOSY2		;ERROR, JSR EFF. ADDR. OUTSIDE USER AREA
	HRRI	T1,1(T1)	;YES, INCREMENT PC.
	EXCH	T1,UUOSP0		;SET UP RETURN TO USER IN UUOSP0
				; PICKUP USERS FLAGS,PC
	ADD	17,.C1ADR	;MAKE REL. ADDRESS INTO ABSOLUTE ADDRESS
	MOVEM	T1,(17)		;STORE FLAGS AND PC LIKE JSR
	MOVE	T1,SPTRAP	;RESTORE T1
	MOVE	17,.C1SAV	;RESTORE 17
	JRST	2,@UUOSP0		;RETURN TO USER (RESTORING FLAGS)

UUOSY2:	MOVE	17,.C1ADR	;SETUP 17 FOR LOW SEGMENT RELOCATION
UUOSY3:	EXCH	T1,SPTRAP	;RESTORE USERS AC(T1) AND USER'S UUO (FORTY1)
>
UUOUS0:	MOVEM	16,16(17)	;STORE AC 16 IN USER 16
	MOVEI	16,(17)		;SETUP BLT POINTER
	BLT	16,15(17)	;MOVE REAL ACS TO USER AREA
	MOVE	T1,.C1SAV	;MOVE USER'S 17 TO USERS AREA
	MOVEM	T1,17(17)
	MOVE	R,17		;LOAD UP PUSH DOWN POINTER TO USER'S AREA
	MOVSI	P,MJOBPD##	;LOAD UP PUSH DOWN AC AND
	HRRI	P,JOBPDL##(R)	; MAKE ABSOLUTE RATHER THAN RELATIVE
	JRST	UUOUSP		;GO DISPATCH ON THE UUO

	INTERN USPRET
USPRET:	POP	P,UUOSP0	;USER RETURN ADDRESS
	MOVSI	17,JOBAC##(R)	;RESTORE ALL USER ACS
	BLT	17,17
	JEN	@UUOSP0		;RESTORE FLAGS AND RETURN TO USER
				; DISMISS INTERRUPT ONLY ON REAL TIME USERS
				; IN ALL OTHER CASES NO INTERRUPT
				; IN PROGRESS
UUO1RS:	MOVE	17,WAKINS##	;IS THIS A WAKE UUO
	CAME	17,SPTRAP	;FROM NULL JOB?
	JRST	UUONLJ

UUO1R1:	MOVEI	17,NU1DAC	;SAVE NULL JOB AC'S
	BLT	17,NU1DAC+16	;IN CPU1 NULL JOB DATA AREA
	MOVE	17,.C1SAV	;GET ORIGINAL AC 17
	MOVEM	17,NU1DAC+17	;SAVE IT
	MOVE	17,UUOSP0	;GET PC
	MOVEM	17,.C1PC	;SAVE IT FOR RETURN
	SETZM	.C1DBL		;CLEAR DOORBELL FLAG
	JRST	CK1SPD##	;GO RESCHEDULE


>

>	;END OF IFN M.KA10 CONDITIONAL
	$HIGH
;MUUOS ON THE KI10 COME HERE

IFN M.KI10!M.KL10,<

UUO0==:.UPMP+.UPMUP
UUO2==:.UPMP+.UPMUP
UUOSP0==:.UPMP+.UPMUP
UUOSP2==:.UPMP+.UPMUP
MPTRAP==:.UPMP+.UPMUO
SPTRAP==:.UPMP+.UPMUO
MPTRP2==:.EPMP+60
SPTRP2==:.E1MP+60
UUO40==:0
UUO60==:0

MUUO:	EXECAC			;SET UP EXEC UUO AC BLOCK
	MOVEI	P4,.C0CDB	;ASSUME THIS UUO WAS EXECUTED ON CPU0
IFN FTMS,<
	SKPCPU	(0)		;WAS IT?
	MOVEI	P4,.C1CDB	;NO, POINT TO CPU1 CDB
>
	AOS	.CPTUC(P4)	;ACCUMULATE THE NUMBER OF UUOS ON THIS CPU
	MOVE	T1,.UPMP+.UPMUP	;GET THE MUUO PC
	TLNN	T1,(XC.USR)	;WAS THE MUUO DONE IN USER MODE?
	JRST	@.CPSMU(P4)	;NO, DISPATCH TO EXEC MODE MUUO HANDLER
	SKIPN	R,.CPADR(P4)	;IS THERE A JOB DATA AREA FOR THE JOB DOING THE UUO?
	JRST	MUUO1		;NO, MUST BE THE DOORBELL OR ERROR IN THE
				; NULL JOB
	MOVE	P,[XWD MJOBPD##,.JDAT+JOBPDL##]
	MOVEI	F,0		;FLAG NO DDB IN CASE ILLEGAL UUO
	MOVE	J,.CPJOB(P4)	;JOB NUMBER OF CURRENT JOB
	JRST	@.CPUMU(P4)	;DISPATCH TO THIS CPU'S MUUO HANDLER
MUUO1:	MOVE	T1,WAKINS##	;DOORBELL CALLI
	CAME	T1,MPTRAP	;WAS THIS THE DOORBELL UUO ISSUED BY THE NULL JOB?
	STOPCD	.+1,DEBUG,UNJ,	;NO, ILLEGAL NULL JOB UUO
MUUO1A:	MOVE	T1,.UPMP+.UPMUP	;GET THE NULL JOB WAKEUP PC
	MOVEM	T1,.CPPC(P4)	;STORE IT AS THE CURRENT PC FOR THIS CPU
	SETZM	.CPDBL(P4)	;GET YOUR PAWS OFF THE BUTTON
	JRST	@.CPSPD(P4)	;DISPATCH TO THE SCHEDULAR SINCE SOME
				; JOB IS POSSIBLY NOW RUNNABLE ON THIS CPU

UMPRET::			;HERE ON RETURN FROM MUUO PROCESSING ON CPU0
USPRET::POP	P,.UPMP+.UPMUP	;RESTORE THE MUUO PC
	USERAC			;RESET USER AC BLOCK
	JEN	@.UPMP+.UPMUP	;DISMISS TO THE USER


>	;END IFN M.KI10!M.KL10
;DEFINE MACRO TO CALL KA OR KI CODE FOR EACH CPU
DEFINE KAI(N)<
	IFN CP'N'KAN,<KA(N)>
	IFN CP'N'KIN,<KI(N)>
	IFN CP'N'KLN,<KL(N)>
>				;END KAI MACRO DEF

;MACROS TO SAVE AND RESTORE  AC BLOCKS FOR KL10 POWER FAIL RESTART
	DEFINE	SAVE(X,Y),<
	EXECAC	(X)
	MOVEM	17,Y+17
	MOVEI	17,Y
	BLT	17,Y+16
>
	DEFINE	RESTOR(X,Y),<
	EXECAC	(X)
	MOVSI	17,Y
	BLT	17,16
	MOVE	17,Y+17
>
	IFN M.KL10,<
APRCLK::				;PLACE FOR PDP-11 APR CLOCK TO GO TO
	IFG CPUN-1,<
	SKPCPU	(0)
	JRST	AP1IN2
>
	JRST	AP0IN2
>	;END IFN M.KL10
;DEFINE KA10 APR INTERRUPT HANDLER - N=0 FOR CPU0, 1 FOR CPU1
; IT CALLS CPU INDEPENDENT CODE AS SOON AS POSSIBLE
DEFINE KA(N)<
		INTERN	AP'N'INT	;PUT IN STORAGE MAP
		IFG N,<EXTERN CP'N'CRS>	;CRASH ROUTINE


;HERE ON APR CHANNEL INTERRUPT
AP'N'INT: JRST	AP'N'IN1	;ASSUME INT FOR APR OR PI DEVICE
AP'N'NXT: JRST	.-1		;PRESERVE FORM OF DEVICE CONSO CHAIN
				; THIS LOC PATCHED TO NEXT DEVICE AT STARTUP
AP'N'IN1:
IFG N,<	SKIPG	.C0OK>		;CPU0 STOPPED?
	SKIPE	CRSHWD		;NO, OPER DEPOSITED 30 NON-ZERO?
	JRST	CP'N'CRS	;YES, TAKE CRASH DUMP OF MONITOR
				; OR LOOPIN CPU1 ACS UNTIL CPU0 IS UP AGAIN
IFE N,<	SKIPN	CLKDDT		;SEE IF EDDT WANTED
	JRST	CLKDDR		;NO--PROCEED
	SETZM	CLKDDT		;YES--CLEAR FLAG
	XCT	SYSDDT		;GO TO EDDT IF POSSIBLE
CLKDDR::>
;BACK HERE FROM CPU1 WHEN CPU0 BACK UP
AP'N'BCK::CONSO	PI,PI.PAR!PI.PWF ;PARITY OR POWER FAILURE?
	CONSZ	APR,AP.ABK	;NO, ADDRESS BREAK?
	JRST	AP'N'UNS	;YES, GO PROCESS UNUSUAL INTERRUPTS
;HERE TO TEST FOR USUAL APR FLAGS THE MONITOR AND USER ARE ENABLED FOR
AP'N'CON: CONSO	APR,@.C'N'CON	;ANY APR INTERRUPTS FOR MONITOR OR USER?
	JRST	AP'N'NXT	;NO, GO TRY NEXT DEVICE ON PI CHANNEL CHAIN
AP'N'IN2: MOVEM	P,.C'N'SP	;SAVE AC P
	MOVE	P,AP'N'PDP	;SET TO PD LIST FOR THIS CPU
	PUSH	P,P4		;SAVE P4
IFE N,<
IFG CPUN-1,<
	MOVSI	P4,(DF.CP1)	;DO WE CARE IF CPU1
	TDNN	P4,DEBUGF	; HALTED?
	JRST	CPU1OK		;NO--DON'T LOOK
	SKIPE	CP1HLT##	;DID IT STOP?
	PUSHJ	P,CP1TYP##	;++TYPE CPU1 STOPCD STUFF
CPU1OK:
>>
	MOVEI	P4,.C'N'CDB	;SET TO CPU DATA BLOCK FOR THIS CPU
	PUSHJ	P,APRSUB##	;GO PROCESS INTERRUPT

IFE ZZ,<IFN M.CTY1,<		;IF THIS IS CPU0 & WANT CTY1:
	SKIPE	ST1IRP##	;GENERATE PSEUDO INTERRUPT
	CONO	PI,REQST1	;  TO SCNSER IF ST1IRP NOT 0
>>

	MOVE	P4,(P)		;RESTORE P4
AP'N'EPF: MOVE	P,.C'N'SP	;RESTORE P
AP'N'EXT: CONO	APR,AP'N'CHN	;SET APR PI
	JEN	@AP'N'CHL	;DISMISS INTERRUPT
IFE FTMEMPAR,<...PAR==PI.PAR>	;MEM PAR IS FATAL IF NO ANALYSIS FEATURE
IFN FTMEMPAR,<...PAR==0>	;NOT FATAL
;HERE TO TEST FOR UNUSUAL INTERRUPT CONDITIONS
AP'N'UNS:CONSZ	PI,PI.PWF!...PAR  ;POWER FAIL (OR MEM PAR IF NO ANALYSIS)?
	JRST	AP'N'PWF	; SO OPERATOR WILL SEE IT.  CLEAR ON CONTINUE
IFN FTMEMPAR,<
	CONSZ	PI,PI.PAR	;MEM PARITY?
	JRST	AP'N'IN2	;YES, GO PROCESS INTERRUPT
>
	AOS	.C'N'ABC	;NO, MUST BE ADDRESS BREAK, KEEP COUNT
	DATAI	APR,.C'N'ABA	;READ IN SWITCHES TO DETERMINE ADDRESS TO DISPLAY
	DATAO	PI,@.C'N'ABA	;DISPLAY CONTENTS OF EFFECTIVE ADDRESS
				; USING ALL EXEC AC.
	CONO	APR,AP.CAB!AP.NXM  ;CLEAR ADR. BREAK AND NON-EX MEM
				; (IN CASE SYSTEM PROGRAMMER ERROR)
	JRST	AP'N'EXT	;DISMISS INTERRUPT
AP'N'PWF: MOVEM	P,.C'N'SP	;SAVE P
	MOVE	P,AP'N'PDP	;SET UP P
IFE FTMEMPAR,<
	CONSZ	PI,PI.PAR	;IF NO PARITY ERROR RECOVERY,
	STOPCD	APRCPF,DEBUG,C'N'P, ; THEN PARITY ERROR GETS STOPCD
>
	CONI	PI,1(P)		;SAVE PI STATUS
	CONO	PI,1177		;CLEAR PI SYSTEM
	MOVEM	17,21(P)	;SAVE
	MOVEI	17,2(P)		; THE
	BLT	17,20(P)	;  REGISTERS
	CONO	PI,PI.CPF	;CLEAR THE POWER FAIL FLAG
IFE N,<
	MOVE	17,[JRST APRRES] ;SET CONTINUE ADDRESS
	EXCH	17,ARSLOC
	MOVEM	17,22(P)
>
	HALT	ARSLOC		;WAIT, RECOVER ON CONTINUE
>				;END KA MACRO

IFN M.KA10,<
ARSLOC==70

APRRES:
IFG <CPUN-1>,<
	SKPCPU	(0)		;CPU0?
	JRST	AP1RES		;NO, RESTORE CPU1
>
	MOVE	P,AP0PDP	;RESTORE PUSH DOWN POINTER
	MOVE	17,22(P)	;RESTORE RESTART LOCATION
	MOVEM	17,ARSLOC
IFG <CPUN-1>,<
	SKIPA
AP1RES:	MOVE	P,AP1PDP
>
	MOVSI	17,2(P)		;RESTORE THE REGS
	BLT	17,16
	MOVEI	17,177
	AND	17,1(P)
	TRO	17,PI.EPE+PI.TNP+PI.ON
	CONO	PI,(17)		;RESTORE THE PI SYSTEM
	CONO	APR,AP.ECI	;ENABLE CLOCK INTERRUPTS
	MOVE	17,21(P)	;RESTORE 17
APRCPF:	CONO	PI,PI.CPE	;CLEAR PARITY ERROR
IFG <CPUN-1>,<
	SKPCPU	(0)		;GO TO PROPER DISMISS ROUTINE
	JRST	AP1EPF
>
	JRST	AP0EPF
>
;DEFINE KI10 APR INTERRUPT HANDLER
; IT CALLS CPU INDEPENDENT CODE AS SOON AS POSSIBLE

DEFINE	KI(N)<
	INTERN AP'N'INT			;PUT IN STORAGE MAP
	IFG N,<EXTERN CP'N'CRS>		;CRASH ROUTINE

;HERE ON OPERATOR CONTINUE AFTER POWER FAILURE, IO PAGE FAIL, WATCH DOG TIMER RUNOUT,
; OR (MEM PAR IF FTMEMPAR=0)
AP'N'CPF: CONO	PI,II.CPF!XI.CPE  ;CLEAR POWER FAIL, PAR ERR
	CONO	APR,IP.CTE!IP.CAE!IP.ECI!IP.CIO!IP.CNM  ;CLEAR TIMEOUT ENABLE,
				;CLEAR AUTO RESTART ENABLE, ENABLE CLOCK INT., CLEAR
				; IO PAGE FAIL, CLEAR NON EX MEM

;HERE ON APR CHANNEL INTERRUPT
AP'N'INT: CONSO	APR,@.C'N'CON	;INTERRUPT FOR APR (MONITOR OR USER ENABLED)
	JRST	.-1		;NO, TRY NEXT DEVICE ON THIS PI CHANNEL
IFG N,<SKIPG .C0OK>
	SKIPE	CRSHWD		;OPER DEPOSITED 30 NON-ZERO?
	JRST	CP'N'CRS	;YES, TAKE CRASH DUMP OF MONITOR
AP'N'BCK::CONSZ	APR,IP.TTO!IP.PAR!IP.PWF!IP.ABK!IP.IOF  ;TIMER TIMEOUT,
				; MEM PAR, POWER FAIL, ADDRESS BREAK, IO PAGE FAIL?
	JRST	AP'N'UNS	;YES, GO PROCESS UNUSUAL INTERRUPTS
AP'N'IN2: MOVEM	P,.C'N'SP	;SAVE AC P
IFE N,<	CONI	APR,P		;GET SENSE SWITCHES
	TLNN	P,(IP.SS6)	;SEE IF 6 SET
	SKIPE	CLKDDT		;OR 21 NON-ZERO
	JRST	.+2		;YES--GO TO EDDT
	JRST	CLKDDR		;NO--PRECEED
	SETZM	CLKDDT		;CLEAR FLAG
	XCT	SYSDDT		;GO TO EDDT IFPOSSIBLE
CLKDDR::>
	MOVE	P,AP'N'PDP	;SET TO PD LIST FOR THIS CPU
	PUSH	P,P4		;SAVE P4
IFE N,<
IFG CPUN-1,<
	MOVSI	P4,(DF.CP1)	;DO WE CARE ABOUT
	TDNN	P4,DEBUGF	; STOPCD'S ON CPU1
	JRST	CPU1OK		;NO--CONTINUE BELOW
	SKIPE	CP1HLT##	;YES-- DID CPU1 HALT
	PUSHJ	P,CP1TYP##
CPU1OK:
>>
	MOVEI	P4,.C'N'CDB	;SET TO CPU DATA BLOCK FOR THIS CPU
	PUSHJ	P,APRSUB##	;GO PROCESS INTERRUPT
IFE ZZ,<IFN M.CTY1,<
	SKIPE	ST1IRP##	;GENERATE PSUEDO INTERRUPT
	CONO	PI,REQST1	; TO SCNSER IF ST1IRP NOT 0
>>
	MOVE	P4,(P)		;RESTORE P4
AP'N'EPF:MOVE	P,.C'N'SP	;RESTORE P
AP'N'EXT: CONO	APR,AP'N'CHN+AP'N'CHN_3  ;SET APR PI AND ERROR PI
	JEN	@AP'N'CHL	;DISMISS INTERRUPT

;HERE TO PROCESS UNUSUAL INTERRUPTS
IFE FTMEMPAR,<...PAR==IP.PAR>	;TEST FOR MEM PAR AS FATAL IF NO ANALYSIS FEATURE
IFN FTMEMPAR,<...PAR==0>	;PAR NOT FATAL
AP'N'UNS: CONSZ	APR,IP.PWF	;POWER FAIL?
	JRST	AP'N'PWF	;YES, GO SETUP FOR AUTO-RESTART
	CONSZ	APR,IP.TTO!IP.IOF!...PAR  ;TIMER RUNOUT, POWER FAIL,
				; IO PAGE FAIL (MEM PAR - IF NO ANALYSIS)
	STOPCD	AP'N'CPF,DEBUG,C'N'P,	;++CPU N POWER-FAILURE
IFN FTMEMPAR,<			;MEMORY PARITY ANALYSIS?
	CONSZ	APR,IP.PAR	;NO, PARITY?
	JRST	AP'N'IN2	;YES, GO PROCESS
>
	AOS	.C'N'ABC	;NO, MUST BE ADDRESS BREAK
	DATAI	APR,.C'N'ABA	;READIN SWITCHES TO DETERMINE ADDRESS TO DISPLAY
	DATAO	PI,@.C'N'ABA	;DISPLAY CONTENTS OF EFFECTIVE ADDRESS
				; USING ALL EXEC ACS
	CONO	APR,IP.CAB!IP.NXM  ;CLEAR ADDRESS BREAK AND NON EX MEM
				; (IN CASE OF SYSTEM PROGRAMMER ERROR)
	JRST	AP'N'EXT	;DISMISS INTERRUPT
AP'N'PWF:MOVEM	P,.C'N'SP	;SAVE P
	MOVE	P,AP'N'PDP	;USE PDL TO SAVE STATE
	CONI	PI,1(P)		;STATE OF THE PI SYSTEM
	CONO	PI,1177		;NO MORE PIS
	DATAI	PAG,2(P)		;EUBR
	MOVEM	17,22(P)	;SAVE EXEC'S ACS
	MOVEI	17,3(P)
	BLT	17,21(P)
	MOVEI	17,23(P)	;SAVE USER'S ACS
	JRSTF	@[IC.UOU+.+1]	;TURN USER IOT ON SO SAVING USER ACS WORKS
	MOVSI	16,17777
	TDNN	16,2(P)		;UPM ZERO?
	TDZA	16,16		;YES, DON'T SAVE AC'S
	MOVSI	16,(PG.LUB)	;NO, SET UP FOR RESTORE
	IORM	16,2(P)		;REMEMBER FOR RESTORE
	SKIPE	16		;DON'T SAVE AC'S IF NO USER
	EXCTUX	<BLT 17,42(P)>
	CONO	APR,IP.SAE	;ENABLE AUTO-RESTART
	CONO	PI,II.CPF	;CLEAR POWER FAIL
	MOVEI	17,400000	;ABOUT 200 MILLISECONDS
	SOJG	17,.		;WAIT AWHILE
	JRST	APRRES		;POWER DIDN'T REALLY FAIL, RESTORE STATE AND CONTINUE
AP'N'RES:MOVE	P,AP'N'PDP	;WHERE SAVED STATE IS
	MOVE	17,2(P)
	DATAO	PAG,17		;RESTORE THE UBR
	MOVSI	17,23(P)	;RESTORE USER'S ACS
	SKIPGE	2(P)		;DON'T RESTORE IF NO USER
	EXCTXU	<BLT 17,17>
	MOVSI	17,3(P)		;RESTORE EXEC'S ACS
	BLT	17,16
	MOVE	P,AP'N'PDP
	MOVEI	17,177
	AND	17,1(P)
	TRO	17,PI.EPE+PI.TNP+PI.ON
	CONO	PI,(17)		;RESTORE THE PI SYSTEM
	CONO	APR,IP.CTE!IP.SAE!IP.ECI!IP.CIO!IP.CNM
	MOVE	17,22(P)
	JRST	AP'N'EPF	;DISMISS
>				;END KI MACRO

;HERE ON AUTO-RESTART AFTER POWER IS RESTORED FOLLOWING POWER
; FAILURE
	$ABS
	$ABS
IFN M.KI10!M.KL10,<
APRRES::
IFE FTMS,<
IFN M.KI10,<
	DATAO	PAG,.C0EBR	;SETUP THE EBR
	JRSTF	@[IC.UOU+.+1]	;TURN ON USER IOT SO SAVING AC WORKS
>
IFN M.KL10,<
	CONO	PAG,@.C0EBR
>
>
IFN FTMS,<
	JSP	T4,SYSTR0	;SEE WHICH CPU THIS IS AND SETUP THE EBR
>
	JRST	AP0RES		;CPU0, RESTORE CPU0'S STATE
IFG <CPUN-1>,<
	JRST	AP1RES		;CPU1
>>
	$HIGH
;DEFINE KL10 APR INTERRUPT HANDLER
; IT CALLS CPU INDEPENDENT CODE AS SOON AS POSSIBLE

DEFINE	KL(N)<
	INTERN AP'N'INT			;PUT IN STORAGE MAP
	IFG N,<EXTERN CP'N'CRS>		;CRASH ROUTINE

;HERE ON OPERATOR CONTINUE AFTER POWER FAILURE, IO PAGE FAIL, WATCH DOG TIMER RUNOUT,
; OR (MEM PAR IF FTMEMPAR=0)
AP'N'CPF: CONO	APR,LP.CSF+LP.SBE+LP.NXM+LP.PAR+LP.IOF+LP.PWF
				;CLEAR AUTO RESTART ENABLE, ENABLE CLOCK INT., CLEAR
				; IO PAGE FAIL, CLEAR NON EX MEM

;HERE ON APR CHANNEL INTERRUPT
AP'N'INT: CONSO	APR,@.C'N'CON	;INTERRUPT FOR APR (MONITOR OR USER ENABLED)
	JRST	.-1		;NO, TRY NEXT DEVICE ON THIS PI CHANNEL
	CONSZ	APR,LP.NXM!LP.CDP!LP.ADP!LP.SBE!LP.PAR!LP.PWF!LP.IOF  ;TIMER TIMEOUT,
				; MEM PAR, POWER FAIL, ADDRESS BREAK, IO PAGE FAIL?
	JRST	AP'N'UNS	;YES, GO PROCESS UNUSUAL INTERRUPTS
IFG CPUN,<
	CONSO	APR,LP.CSD
	JRST	AP'N'IN2
	CONO	APR,LP.CSF+LP.CSD+AP'N'CHN
	AOS	.C'N'CSN
IFN N,<SETOM .C0DBL>
IFE N,<SETOM .C1DBL>
	JEN	@AP'N'CHL
>
AP'N'IN2::MOVEM	P,.C'N'SP	;SAVE AC P
AP'N'CLK:
IFE N,<	SKIPN	CLKDDT		;IS 21 NON-ZERO
	JRST	CLKDDR		;NO--PRECEED
	SETZM	CLKDDT		;CLEAR FLAG
	XCT	SYSDDT		;GO TO EDDT IFPOSSIBLE
CLKDDR::>
	MOVE	P,AP'N'PDP	;SET TO PD LIST FOR THIS CPU
	PUSH	P,P4		;SAVE P4
IFE N,<
IFG CPUN-1,<
	MOVSI	P4,(DF.CP1)	;DO WE CARE ABOUT
	TDNN	P4,DEBUGF	; STOPCD'S ON CPU1
	JRST	CPU1OK		;NO--CONTINUE BELOW
	SKIPE	CP1HLT##	;YES-- DID CPU1 HALT
	PUSHJ	P,CP1TYP##	;YES-- TYPE INFO ON CPU0
CPU1OK:
>>
	MOVEI	P4,.C'N'CDB	;SET TO CPU DATA BLOCK FOR THIS CPU
	PUSHJ	P,APRSUB##	;GO PROCESS INTERRUPT
IFE ZZ,<IFN M.CTY1,<
	SKIPE	ST1IRP##	;GENERATE PSUEDO INTERRUPT
	CONO	PI,REQST1	; TO SCNSER IF ST1IRP NOT 0
>>
	MOVE	P4,(P)		;RESTORE P4
AP'N'EPF:MOVE	P,.C'N'SP	;RESTORE P
AP'N'EXT: CONO	APR,AP'N'CHN  ;SET APR PI
	JEN	@AP'N'CHL	;DISMISS INTERRUPT

;HERE TO PROCESS UNUSUAL INTERRUPTS
IFE FTMEMPAR,<...PAR==LP.PAR>	;TEST FOR MEM PAR AS FATAL IF NO ANALYSIS FEATURE
IFN FTMEMPAR,<...PAR==0>	;PAR NOT FATAL
AP'N'UNS: CONSZ	APR,LP.PWF	;POWER FAIL?
	JRST	AP'N'PWF	;YES, GO SETUP FOR AUTO-RESTART
	CONSZ	APR,LP.ADP!LP.CDP	;NXM,ADDR PAR, CACHE DIR PAR?
	JRST	AP'N'NHT	;GO DO DIAG INST'S AND HALT
	CONSZ	APR,LP.NXM	;NXM?
	JRST	AP'N'NXM	;YES, DO SPECIAL STUFF ON KL
	CONSZ	APR,LP.IOF!...PAR  ;TIMER RUNOUT, POWER FAIL,
				; IO PAGE FAIL (MEM PAR - IF NO ANALYSIS)
	STOPCD	AP'N'CPF,DEBUG,C'N'P,	;++CPU N POWER-FAILURE
IFN FTMEMPAR,<			;MEMORY PARITY ANALYSIS?
	CONSZ	APR,LP.PAR	;NO, PARITY?
	JRST	AP'N'IN2	;YES, GO PROCESS
>
	CONSZ	APR,LP.SBE	;SBUS ERROR?
	JRST	AP'N'NHT	;YES, JUST DO DIAG INST'S AND HALT
	JRST	AP'N'EXT	;DISMISS INTERRUPT
;HERE ON NXM - CLEAR MB PARITY ERROR AND SBUS ERROR, SWEEP CACHE
AP'N'NXM: CONO	APR,LP.CSF!LP.PAR!LP.SBE  ;CLEAR ALL BUT INTERESTING STUFF
	SWPUA			;SWEEP THE CACHE SINCE NXM LEAVES
				; BAD PARITY IN CACHE
	CONSZ	APR,LP.CSB	;WAIT FOR FINISH
	JRST	.-1
	JRST	AP'N'IN2	;GO DO A NXM THING

;HERE TO HALT ON APR ERROR CONDITION--DO SBDIAG AND RDERA FIRST
AP'N'NHT: RDERA	.C'N'AER	;READ ERA INTO CPU DATA BLOCK
	CONI	APR,.C'N'AEF	;SAVE CONI APR,
	SBDIAG	.C'N'SB0	;GET SBDIAG FUNCTIONS 1+2
	SBDIAG	.C'N'SB1	;
	SWPUA			;CACHE SWEEPS SO WE CAN SEE DATA
	CONSZ	APR,LP.CSB
	JRST	.-1
	CONSZ	APR,LP.SBE	;SBUS ERROR?
	JRST	AP'N'NH1	;YES, STOPCD SBE
	CONSZ	APR,LP.CDP	;CACHE DIR. PAR.?
	JRST	AP'N'NH2	;YES, STOPCD CDP
				;MUST BE ADDR PARITY ERROR
	STOPCD	(.,STOP,AD'N)	;++ADDR. PARITY ERROR
AP'N'NH1:STOPCD	(.,STOP,SB'N)	;++SBUS ERROR ALONE
AP'N'NH2:STOPCD	(.,STOP,CD'N)	;++CACHE DIRECTORY PARITY ERROR



;KL10 INTERVAL TIMER INTERRUPT HANDLER
	$ABS

TM'N'INT::0
IFN FT2SEGMON,<
	JRST	TM'N'IN0
	$HIGH
TM'N'IN0:
>
IFG N,<SKIPG .C0OK>
	SKIPE	CRSHWD		;OPR DEPOSIT 30 NON-ZERO?
	JRST	CP'N'CRS	;YES, TAKE CRASH DUMP
AP'N'BCK::MOVEM	P,.C'N'SP	;SAVE P
	MOVE	P,TM'N'INT	;STORE PC
	MOVEM	P,@.C'N'CHL	;SAVE AT APR PI CHANNEL JSR ADDRESS
	MOVSI	P,(ST.CYC)	;50 HZ POWER?
	TDNE	P,STATES	;SKIP IF NO
	JRST	[MOVEI	P,^D2000 ;50HZ, SO SETUP 20000 USECS
		 JRST	TM'N'IN1] ;AND SET THAT AS NEW INTERVAL
	MOVEI	P,^D1666	;60HZ, SO ASSUME LEAP JIFFY
	AOSG	.C'N'TCT	;COUNT TRIAD COUNTER (-1,0,1)
	AOJA	P,TM'N'IN1	;NOT LEAP TICK UNLESS TRIAD COUNT IS 1
	SETCMM	.C'N'TCT	;COUNT REACHED 1, SET BACK TO -2
TM'N'IN1:	CONO	TIM,TO.CTD!TO.SIT(P)	;SET INTERVAL OF TIMER AGAIN
	SETOM	.C'N'TIM	;SOFTWARE CLOCK FLAG FOR KL'S
	JRST	AP'N'CLK	;GO JOIN MAIN STREAM OF EVENTS
	DEFINE	SAVE(X,Y),<
	EXECAC	(X)
	MOVEM	17,Y+17
	MOVEI	17,Y
	BLT	17,Y+16
>

	DEFINE	RESTOR(X,Y),<
	EXECAC	(X)
	MOVSI	17,Y
	BLT	17,16
	MOVE	17,Y+17
>
	XP	ARSLOC,70
AP'N'PWF:	CONI	PI,AP'N'PD1+1	;-;SAVE STATE OF PI SYS
	CONO	PI,PIOFF	;TURN OFF INTERRUPTS
	MOVEM	P,.C'N'SP	;-;SAVE P
	MOVE	P,.C'N'EBR	;-;GET CURRENT EBR
	ANDI	P,-1-<LG.CSL!LG.CSW>	;-;TURN OFF CACHE
	CONO	PAG,(P)		;-;
	SWPUA			;SWEEP CACHE
	CONSZ	APR,LP.CSB
	JRST	.-1
	DATAI	PAG,AP'N'PD1+2	;-;SAVE UBR, CURRENT, PREVIOUS AC BLKS
	CONI	MTR,AP'N'PD1+3
	MOVE	P,.C'N'SP
	SAVE	(0,.C'N'CAC)		;-;SAVE BLOCK 0 IN CRASH AC'S
	SAVE	(1,.C'N'PWF)
	SAVE	(2,.C'N'PWF+20)	;-;
	SAVE	(3,.C'N'PWF+40)	;-;
	IFE	N,<			;-;
	MOVEI	P,AP'N'PD1+4		;-;GET A STACK
	PUSHJ	P,DTEPWF##		;-;TELL F.E. WE HAVE A POWER FAILURE
>
	MOVEI	17,400000
	SOJG	17,.		;MAKE SURE POWER HAS FAILED
	JRST	APRRES		;IT HASN'T
AP'N'RES:SWPIA			;CLEAR OUT CACHE
	CONSZ	APR,LP.CSB
	JRST	.-1
	CONO	PAG,@.C'N'EBR	;-;;TURN ON CACHE, TRAP ENABLE
	MOVE	P,AP'N'PD1+1	;-;GET CONI PI WORD
	ANDI	P,377		;-;JUST SYS ON, OFF AND CHANNELS
	CONO	PI,PI.TNP(P)	;-;TURN ON CHANNELS AND SYS, IF
	MOVE	P,AP'N'PD1+3
	CONO	MTR,MO.LAC(P)
	IFE	N,<		;-;
	MOVEI	P,AP'N'PD1+4	;-;GET A STACK
	MOVE	F,DTEMAS##	;-;
	PUSHJ	P,DTERLD##	;-;
	JSR	ZAPRH2		;-;PUT RH20'S BACK TOGETHER
	>			;-;
	RESTOR	(0,.C'N'CAC)	;-;
	RESTOR	(1,.C'N'PWF)	;-;
	RESTOR	(2,.C'N'PWF+20)	;-;
	RESTOR	(3,.C'N'PWF+40)	;-;
	CONO	TIM,TO.CTD!TO.CIT!TO.SIT!^D1667	;-;
	DATAO	PAG,AP'N'PD1+2	;-;
	CONO	APR,AP'N'NUL	;CLEAR POWER FAIL, ENABLE FOR GOOD STUFF
	JRST	AP'N'EXT	;-;BYE.
> ;END KL10 MACRO
;GENERATE APR INTERRUPT CODE DEPENDING ON CPUN AND KA VS KI
ZZ==0
REPEAT CPUN,<				;NO OF CPUS IN SYSTEM
	KAI(\ZZ)			;GENERATE INTERRUPT CODE
	ZZ==ZZ+1			;STEP TO NEXT CPU NUMBER
>
	$ABS
SUBTTL EXTERNS TO FORCE LIBRARY LOADING
;GENERATE EXTERNAL GLOBALS TO CAUSE LOADING OF PROPER ROUTINES FROM
; MONITOR LIBRARY TAPE IF THERE IS ONE


;ALWAYS LOAD CLOCK1,COMCON,CORE1,ERRCON,JOBDAT,ONCE,PATCH,UUOCON,DATMAN,
; AND EITHER KASER OR KISER

IFN FTVM,<
EXTERNAL VMSER,VMDTJB
>
IFE FTVM,<
EXTERNAL DATJOB
>IFN M.KA10,<
EXTERNAL KASER
>
IFN M.KI10,<
EXTERNAL KISER
>
IFN M.KL10,<
EXTERNAL KLSER,DTESER,TTDINT,FEDSER
>
EXTERNAL CLOCK1,COMCON,CORE1,ERRCON,ONCE,PATCH,UUOCON,DATMAN

;LOAD FILE SERVICE ROUTINES, REFRESHER & ONCMOD (EXTRA ONCE ONLY CODE) FOR LEVEL D
;LEVEL D ALSO REQUIRES COMMOD, WHICH IS A SEPARATE FILE OF DISK PARAMETERS
;UNLESS SYMBOL FTCMBTH IS DEFINED, IN WHICH CASE THEY ARE HERE IN COMMON
	IFN	LEVDN,<EXTERNAL FILFND,FILIO,FILUUO,ONCMOD,REFSTR
		IFNDEF FTCMBTH,<EXTERN COMMOD>>

;LOAD DDT
	IFG	DDTN, <EXTERNAL DDTX>
	IFE	DDTN, <
		XP DDTEND,0	;ONCE REFERENCES END OF DDT
		XP DDTX,0	; AND ALSO ITS ENTRY POINT.
		XP $1B,0	; AND ALSO BREAKPOINTS
		>

;LOAD SCHEDULER FOR NON-SWAPPING OR SWAPPING SYSTEM
	IFG	SYS40N, <EXTERNAL XCKCSS>	;CLKCSS
	IFG	SYS50N, <EXTERNAL SCHED	;SCHED
		IFN LEVDN,<EXTERNAL SWPSER	;IO HANDLER FOR LEVEL D SWAPPER>>

;LOAD EITHER SEGCON (2 REG SOFTWARE) OR NULSEG (1 REG SOFTWARE)
; UNLESS USER HAS EDITTED F WITH FT2REL=0 SO ALL PUSHJ'S
; TO SEGCON (NULSEG) ARE REMOVED

IFN FT2REL, <
	IFG	KT10AN, <EXTERNAL SEGCON>
	IFE	KT10AN, <EXTERNAL NULSEG>
>
;SATISFY GLOBAL NEEDED FOR USER MODE ONCE ONLY - NEVER CALLED BY EXEC MONITOR
	XP	USRCPY,CPOPJ
SUBTTL METCON LINKAGE AND TABLES
;LOAD OR FAKE METCON DEPENDING ON FTMETR & M.METR

IFN FTMETR,<
IFG M.METR,<
;-----------THIS CODE IF ASSEMBLE (F.MAC) = YES; LOAD (MONGEN) = YES

EXTERN	METCON		;LOAD METCON MODULE

>	;IFG M.METR

IFE M.METR,<
;-----------THIS CODE IF ASSEMBLE = YES; LOAD = NO

INTERN	METINI,METREL,METER,MPDPAR,MPDPRA	;FAKE METCON GLOBALS
METINI:	0
	JRST	@METINI
METREL==CPOPJ
METER==CPOPJ		;ERROR RETURN TO METER. UUO
MPDPRA==0
MPDPAR==0

		;FAKE MPTAB
DEFINE METERP (N)<
MP'N=:[0]
>
RADIX 10
SALL
METERP 1
METERP 2
METERP 3
METERP 4
METERP 5
RADIX 8

>	;IFE M.METR
>	;IFN FTMETR
	$HIGH
IFN M.KA10!M.KI10,<
SUBTTL DK10 SERVICE ROUTINE
;-------REAL TIME CLOCK (DK10) SERVICE
;	MUST FOLLOW METER-POINT DEFINITION SO MEP3 DEFINED

SUBTTL REAL TIME CLOCK (DK10)
IFN M.RT0!M.RT1,<		;MONGEN COND. ASSEMBLY

;-------INITILIZATION FOR RTC

;ON SYSTEM RESTART (E.G. AFTER CRASH) RTCINI MUST BE CALLED AFTER METINI
;   SINCE THE RTC SERVICE ROUTINE CONTAINS METER POINTS
;
;	MOVE	F,DDBADDR
;	JSR	RTCINI(F)

;-------INTERRUPT SERVICE (PURE PART)
;	F ADDRESSES DDB, T1 IS SAVED

RTCINT::MOVE	T1,RTCPRD##(F)	;GET PERIOD
	XCT	RTCSNO##(F)	;OVERFLOW?
	MOVSI	T1,1		;YES PERIOD=2^18
	ADDM	T1,RTCTIM##(F)	;UPDATE TIME
	JRST	RTCXIT##(F)	;CLEAR IRP. & EXIT

>		;IFN M.RTC
;INITIALIZATION FOR TIME ACCOUNTING
;  TIME (TIME OF DAY) MUST HAVE BEEN SET UP
;  STATES BIT ST.HPT DETERMINES WHETHER DK10 OR APR CLOCK IS USED.

;
;	MOVE	P4,CDBADDR
;	PUSHJ	P,SETIME
;	---			;RETURN-DESTROYS F,T1,T2

SETIME::
IFN M.RTC,<
	MOVSI	T1,(ST.HPT)	;HIGH PRECISION TIME?
	TDNN	T1,STATES	;   (BIT DETERMINED BY MONGEN)
	JRST	SETIM6		;NO-INIT. FOR APR CLOCK
	SKIPN	F,.CPRTC(P4)	;YES-IS THERE A DK10 DDB
	JRST	SETIM6		;NO MONGEN & ONCE SHOULD CATCH THIS!!
	MOVEM	F,.CPRTD(P4)	;YES-SET UP DDB ADDRESS
	MOVEI	T1,^D100000	;SET UNITS/SEC
	MOVEM	T1,RTCUPS
	PUSHJ	P,GETIMI	;SET DK10 TIME
	MOVEM	T1,RTCTIM##(F)
	MOVEM	T1,.CPXTM(P4)	; & CDB INTERVAL COUNTER
	JSR	RTCINI##(F)	;START THE CLOCK
	POPJ	P,

SETIM6:	ANDCAM	T1,STATES	;CLEAR HIGH PREC. TIME IN STATES
	SETZM	.CPRTD(P4)	;DDB ADDR=0 FOR APR CLOCK
	MOVE	T1,TICSEC	;UNITS/SEC=LINE FREQ.
	MOVEM	T1,RTCUPS
	PUSHJ	P,GETIMI	;SET CDB INTERVAL COUNTER
	MOVEM	T1,.CPXTM(P4)
	POPJ	P,

>				;IFN M.RTC

IFE M.RTC,<
	PUSHJ	P,GETIMI
	MOVEM	T1,.CPXTM(P4)
	POPJ	P,
>				;IFE M.RTC
;RETURN T1=TIME OF DAY IN 'RTUPS' UNITS/SEC.
;  DESTROYS T2,F
;  REQUIRES P4 TO BE SETUP
;  GETIME MUST BE INITIALIZED WITH SETIME BEFORE USE

RTUPS=:	^D100000		;RESOLUTION (UNITS/SEC) OF TIME RETURNED BY GETIME
				; INDEPENDENT OF CLOCK USED
				;NOTE - RUNTIM UUO (JOBTIM: IN UUOCON) DEPENDS ON
				; RTUPS BEING AN INTEGRAL MULTIPLE OF ^D100000

IFN RTUPS-<RTUPS/^D100000>*^D100000,<
PRINTX	%GETIME:  JOBTIM requires RTUPS to be multiple of OF ^D100000>
RTUPS3==: RTUPS/^D1000		;FOR USE IN JOBTIM: ROUTINE
RTUPS5==: RTUPS/^D100000
GETIME::

;-------CODE FOR DK10 (100KHZ) TIME ACCOUNTING-------

IFN M.RTC,<

	SKIPN	F,.CPRTD(P4)	;GET DK10 DDB ADDR.
	JRST	GETIM6		;0 MEANS USE APR CLOCK
GETIM2:	XCT	RTCSON##(F)	;IS DK10 ON?
	JSR	RTCINI(F)	;NO - START IT

GETIM3:	MOVE	T2,RTCTIM(F)	;GET TIME (AT LAST IRP.)
	XCT	RTCDAI##(F)	;GET CURRENT TIME
	ADD	T1,T2		;ADD HI & LOW ORDERS.
	CAME	T2,RTCTIM(F)	;WAS I INTERRUPTED?
	JRST	GETIM3		;YES - TRY AGAIN
	CAMGE	T1,RTCLGT(F)	;DON'T RETURN A TIME LESS
	MOVE	T1,RTCLGT(F)	;  THAN THE LAST ONE
	MOVEM	T1,RTCLGT(F)	;  & REMEMBER THIS ONE AS LAST ONE
	POPJ	P,

>	;IFN M.RTC

;-------CODE FOR APR CLOCK (60/50 HZ) TIME ACCOUNTING-------

GETIMI:				;CALLED BY SETIME TO INIT STUFF
GETIM6:	MOVE T1,TIME
	MULI	T1,RTUPS	;CONVERT TO RTUPS UNITS
	DIV	T1,TICSEC
	POPJ P,

RTCMAX::RTUPS*^D3600*^D24	;WRAPAROUND TIME (MIDNIGHT)


;HERE FROM CLOCK1 AT MIDNIGHT

INTERN	RTCDAY

IFN M.RTC,<
RTCDAY::MOVN	T1,RTCMAX	;RESET DK10 TIMES
	CONO	PI,PIOFF
IFN M.RT0,<
	SKIPN	F,.C0RTD
	JRST	RTCDA1
	ADDM	T1,RTCTIM##(F)
	ADDM	T1,RTCLGT##(F)
IFN M.METR,<ADDM T1,LASTM>
>
RTCDA1:
IFN M.RT1,<
	SKIPN	F,.C1RTD
	JRST	RTCDA2
	ADDM	T1,RTCTIM(F)
	ADDM	T1,RTCLGT(F)
>
RTCDA2:	CONO	PI,PION
	POPJ	P,
>	;IFN M.RTC


IFE M.RTC,<RTCDAY==CPOPJ>

;FAST GETIME FOR METER.UUO (RT0 ONLY I.E. ONLY CPU0 SHOULD USE THIS)
;	USES ONLY T1,T3

IFN M.METR,<
IFN M.RT0,<
METIME::MOVE	T3,RT0TIM##
	RT0DTI##,,T1		;DATAI RT0,T1
	ADD	T1,T3
	CAME	T3,RT0TIM##
	JRST	METIME
	CAMGE	T1,LASTM	;DON'T RETURN A TIME
	MOVE	T1,LASTM	;LESS THAN LAST ONE
	MOVEM	T1,LASTM	;+ REMEMBER THIS ONE AS LAST ONE
	POPJ	P,

	$ABS
LASTM:	0			;LAST TIME FOR METIME
>				;IFN M.RT0

IFE M.RT0,<METIME==:CPOPJ>
>				;IFN M.METR
>;END IFN M.KA10!M.KI10
IFN M.KL10,<
SUBTTL KL10 TIME BASE ROUTINES

;THESE ROUTINES PERFORM THE SAME FUNCTIONS AS THE DK10 ROUTINES DO
; FOR THE KA10 AND KI10. THEY ALSO INITIALIZE THE ACCOUNTING METERS.

;ROUTINE TO SETUP INITIAL TIME BASE VALUE, CALLED BY SYSINI AFTER ONCE
; COMPUTES DATE BY CALLING SUDATE

SETIME::MOVE	T1,DATE		;GET UNIVERSAL DATE/TIME
	MULI	T1,^D86400	;GET SECONDS SINCE NOV 17,1858
	ASHC	T1,^D17		;PUT BINARY POINT AFTER BIT
				; 35 OF T1 YIELDING
				; SECONDS SINCE NOV 17, 1858
				; IN T1
	MUL	T1,[RTUPS*^D10]	;CONVERT TO 1 USEC UNITS FOR TIME BASE
	ASHC	T1,<^D35-TB.LTP>;ACCOUNT FOR COUNTS/TICK
	CONO	MTR,MO.TOF!MO.CTB ;TURN OFF TIME BASE, CLEAR IT.
	MOVE	T3,.CPTOS(P4)	;ADDRESS OF THIS PROCESSOR'S EPT
	DMOVEM	T1,.EPHTB(T3)	;STORE UNIVERSAL DATE TIME BASE (RUNS OUT IN 5028
	MOVEI	T2,MO.LAC!MO.AO!MO.AEN!MO.AIP ;INITIALIZE ACCOUNTING
	MOVEI	T1,ST%XPI	;CHECK IF PI TIME IS EXCLUDED
	TDNE	T1,CNFST2	;SKIP IF IT IS NOT EXCLUDED
	TRZ	T2,MO.AIP	;IT IS, DO NOT INCLUDE
	CONO	MTR,MO.TON(T2)	;TURN TIME BASE ON, DO GOOD STUFF
	PUSHJ	P,GETIME	;GET TIME SO WE CAN
	MOVEM	T1,.CPXTM(P4)	;SET UP THE FIRST LAST TIME


RTUPS==:^D100000	;RESOLUTION OF ACCOUNTING
RTUPS3==:RTUPS/^D1000		;FOR USE IN JOBTIM: ROUTINE
RTUPS5==:RTUPS/^D100000

;GET TIME OF DAY IN RTUPS UNITS/SECOND
; USES ACS T1-T4

GETIME::SETZB	T1,T2		;CLEAR T1,T2 FOR DDIV
	RDTIME	T3		;GET UNIVERSAL TIME IN TIME BASE UNITS
	ASHC	T3,<TB.LTP-^D35>	;ACCOUNT FOR COUNT/TIME BASE TICK
	DDIV	T1,RTCMTT	;DIVIDE BY RTCMAX*10, YIELDING UNIVERSAL
				; DATE IN T1,T2 AND USECS SINCE MIDNITE IN T3,T4
	DIVI	T3,^D10		;CONVERT TO RTUPS UNITS (10 USECS)
	MOVE	T1,T3			;AND GET FINAL ANSWER IN T1
	POPJ	P,		;RETURN

RTCMAX::RTUPS*^D3600*^D24	;RTUPS UNITS/DAY
RTCMTT:	EXP	2,203565660000	;RTUPS*^D3600*^D24*^D10 (MICROSECS/DAY)
RTCDAY==:CPOPJ

IFN M.METR,<
METIME::PUSH	P,T2		;FOR METER UUO
	PUSHJ	P,GETIME
	JRST	T2POPJ
>;END IFN M.METR
IFE M.METR,<
	METIME==:CPOPJ		;IN CASE NO METER UUO
>;END IFE M.METR

>;END IFN M.KL10
	$ABS
	$ABS
SUBTTL PROCESSOR STUFF
;EITHER LOAD TMPUUO ROUTINE OR DEFINE TMPINI AND TMPUUO HERE IN COMMON.
; IF USER HAS EDITED S WITH FTTMP=0 DON'T BOTHER

IFN FTTMP, <
IFG TEMPN, < INTERN TMPINC
	TMPINC==1
	EXTERNAL TMPUUO>	;LOAD UUO HANDLER FOR TEMORARY IN-CORE FILES.
IFE TEMPN, < INTERNAL TMPUUO,TMPINC,TMPTAB ;IF TMPCOR UUO IS NOT IMPLEMENTED....
	TMPUUO==CPOPJ			; FAKE NORMAL RETURN.
	TMPTAB==0
	TMPINC==0			;DON'T CALL INITIALIZATION ROUTINE
	>>
IFN FTPI,<
IFN M.PSI,<
	EXTERNAL PSISER		;CAUSE PSISER TO BE LOADED
>>

;MAKE SURE THAT PROPER VERSION OF FEATURE SWITCH FILES WERE USED TO ASSEMBLE
;THE REST OF THE MONITOR
;THE LOADER WILL PRINT MUL. DEF. GLOBAL IF A MISTAKE HAS BEEN MADE


IFG KT10AN, < IFE FT2REL, <PRINTX ;FT2REL MUST BE -1 WHEN 2 RELOC. REGISTERS EXIST
>
	XP	FT2REL,-1>	;IF FT2REL WAS 0, MACRO WILL GIVE PHASE ERRORS.

;DUAL PROCESSOR SYSTEM ROUTINE GETS LOADED HERE

IFG <CPUN-1>,<
	EXTERNAL CP1SER		;FORCE LOADER TO LOAD CPU#1 SERVICE ROUTINE
	XP CP1INC,1		;CALL CP1INT IN SYSINI
>

IFE CPUN-1,<			;IF ONLY ONE CPU, FAKE INTERNS FOR SYSINI
				; SO NO UNDEFINED GLOBALS.
	XP	.C1OK,0
	XP	.C1SCD,0
	XP	SPTRAP,0
	XP	DEDTIM,0
	XP	CP1INC,0
	XP	CP1PAR,CPOPJ
	XP	CP1CHK,CPOPJ
	XP	CP1CJP,CPOPJ
;ALSO FACK FOR ERRCON NEVER USED IF CPUN=1
	XP	CP0EUB,0
	XP	CP0UPT,0
>
COMONF==-1		;THIS IS COMMON.MAC BEING ASSEMBLED
			;SETTING THIS FLAG NON-ZERO WILL CAUSE S.MAC TO
			;MAKE SKPCP0 AND SKPCP1 TO BE INTERNAL
IFN FTMS,<		;MULTI-PROCESSING FEATURE?
;FOLLOWING TWO INSTR. ARE XCTED USING SKPCPU MACRO (SEE S.MAC)
	INTERN $SCP0,$SCP1

IFN M.KA10,<
$SCP0:	CONSZ	APR,AP.TOS	;SKIP IF THIS IS CPU 0
$SCP1:	CONSO	APR,AP.TOS	;SKIP IF THIS IS CPU 1
>
>
IFN FTKI10!FTKL10,<
;FOLLOWING INSTRUCTIONS ARE EXECUTED USINE SKPCPU MACR0
INTERN $SCPA,$SCPI,ISKCPA,ISKCPI

DEFINE	SKPXXX	(A,B),<
IRP A,<
$SCP'A::
>
	B
>

IFN M.KA10,<
	SKPXXX	<I,L,IL,LI>,<JFCL>
	SKPXXX	<A,AI,IA,AL,LA>,<SKIPA>
>
IFN M.KI10,<
	SKPXXX	<A,L,AL,LA>,<CAI>
	SKPXXX	<I,IL,LI,AI,IA>,<CAIA>
>
IFN M.KL10,<
	SKPXXX	<A,I,AI,IA>,<CAI>
	SKPXXX	<L,LI,IL,AL,LA>,<CAIA>
>
ISKCPA:	JFCL			;SKIP IF THIS CPU IS A KA10
ISKCPI:	SKIPA			;SKIP IF THIS CPU IS A KA10
>
IFN M.PSI,<
IFE FTPI,<
	PRINTX	?ASSEMBLE WITH FTPI==-1
>
OKSGNL::SKIPN	JBTPIA(J)	;SKIP IF USER WANTS TO HAVE INTERRUPTS
				; GRANTED
NOPISK::SKIPGE	JBTPIA(J)	;SKIP IF USER IS NOT ENABLED FOR TRAPS
> ;END M.PSI
IFE M.PSI,<
;DUMMY CODE
PSIIVA::MOVEI	T1,0
	POPJ	P,
PSIERR==:CPOPJ2
OKSGNL::CAI			;NEVER SKIP SINCE USER NEVER READY
NOPISK::CAIA			;SKIP IF USER IS NOT ENABLED FOR TRAPS
USREIJ::			;USER INDUCED ERROR
PSIHNG::
PSISIG::AOS	(P)		;SIGNAL AN INTERRUPT
PSIKSY::
CLRPSI::			;CLEAR PENDING TRAPS
DEBRK::				;DEBRK. UUO
PIINI::				;PIINI. UUO
PIRST::				;PIRST. UUO
PISAVE::			;PISAV. UUO
PISYS::				;PISYS. UUO
ANYUUO::			;EVERY UUO
PSIIOD::			;CALL TO SETIOD
PSIIDN::			;END OF INPUT UUO
PSITST::
PSIODN::			;END OF OUTPUT UUO
PSIDWN::
PSIONL::
EXTEIJ::			;EXTERNAL ERROR IN JOB
APPSI::
APRPSI::			;SET TRAP INSTRUCTIONS
PSINTC::
PSIDVB::
	POPJ	P,0		;DUMMY ROUTINE
	XP	IBKISW,0
	XP	PITWJB,0
>
	IFE	COREN, <COREN==^D256_K2PLSH  ;NO RESTRICTION IF 0 TYPED>
	XP	USRLIM,COREN	;DEFINE GLOBAL RESTRICTING MAXIMUM SIZE OF
					; CORE FOR ANY SINGLE USER
					; ONCE ONLY CODE CAN ALTER THIS VALUE
					; (PATCH RH CORLIM IN SYSINI)



;NOTE: THESE SYMBOLS WILL GO AWAY SOON SO THAT AP.??? SYMBOLS
; WILL BE USED INSTEAD AS DEFINED IN S.MAC
;APR AND PI BITS
	INTERN	PION,PIOFF,REQCLK,PICLK,AP0RST,NXM,CLKBIT,AP0NUL

;APR BITS FOR BOTH PDP-6 AND KA10


	CLKBIT==1
	REPEAT	7-CK0CHN, <CLKBIT==CLKBIT*2>
	PION==200		;CONO PI,PION TURNS PI SYSTEM ON
	PIOFF==400		;TURN IT OFF
	REQCLK==PI.IIO+CLKBIT	;REQUEST INTERRUPT ON LOW PRIORITY CLK CHANNEL
	PICLK==PION+REQCLK	;TURN ON PI,REQUEST INTERRUPT ON CLK CHANNEL
	ZZ==1
	REPEAT 7-SCNCHN,<ZZ==ZZ*2>
	REQCTY==:PI.IIO+ZZ	;FOR KL10 CTY, MUST INTERRUPT ON SCANNER PI BY HAND
	CLRCTY==:II.CPP+ZZ	;CLEAR PSEUDO-CTY INTERRUPT (KL10)

	CLRPIS==:211577		;CLEAR THE PI SYSTEM
IFN M.KL10,<CLRPIS==:11577>
	AP0NUL==433550+AP0CHN	;RESET APR FOR NULL JOB
				; CLEAR EVERYTHING BUT DON'T I/O RESET
IFN CP0KIN,<AP0NUL==IP.CTE+IP.CAE+IP.ECI+XP.CCF+IP.CAB+IP.CIO+IP.CNM+AP0CHN_3+AP0CHN>
IFN CP0KLN,<AP0NUL==LP.ESF!LP.CSF+LP.SBE+LP.NXM+LP.PAR+LP.IOF+LP.PWF+LP.CDP+LP.ADP+LP.CSD+AP0CHN>
	AP0RST==AP0NUL+200000	;RESET APR FOR SYSINI (I/O RESET TOO)
	NXM==10000		;NON-EX MEM (APR STATUS WORD)
IFN M.KI10,<NXM==IP.NXM>
IFN M.KL10,<NXM==LP.NXM>
;NOW HARDWARE BITS WHICH DEPEND ON SOFTWARE CONFIGURATION:

	XP XI.RQC,REQCLK	;CONO PI.XI.RQC REQUESTS CLK INTERRUPT
	XP II.CCI,II.CPP+CLKBIT
IFN M.KA10,<XP XC.UOU,0>
IFN M.KI10!M.KL10,<XP XC.UOU,UIOMOD>

IFN M.CTY1,<			;CTY1 PSEUDO DEVICE (ST1)
	ST1PI==1B<28+ST1PIA>	;CONO PI BIT FOR ST1
	XP REQST1,PI.IIO+ST1PI	;REQUEST INTERRUPT
	XP CLRST1,II.CPP+ST1PI	;CLEAR INTERRUPT (KI10)
>

IFE M.CTY1,<
IFN FTMS,<IFN FTCTY1,<		;DEFAULT CTY1 SYMBOLS FOR SINGLE CPU SYSTEMS
INTERN	CT1TYO			;ROUTINE IN CP1SER CALLED BY SCNSER
CT1TYO==CPOPJ
>>
>	;IFE M.CTY1


;DEFINE APR SYMBOLS FOR PDP-6 VS KA10 FOR CPU 0

	IFG	CP0KAN, <A0.FOV==100	;FLOATING OVERFLOW CAN BE ENABLED ON PDP10
				; FOR USER TRAPPING ON CPU 0>
IFE CP0P6N,<
	XP PIPROG,77400		;PI STATUS REGISTER
				;ONES IF ANY PI'S IN PROGRESS
				;DO NOT DEFINE IF PDP-6 SO UNDEFINED
				;GLOBAL WILL BE CLUE TO PDP-6 USER
				;TO CHANGE CODE
	A0.NOT==PIPROG-<400_<7-AP0CHN>>	;DEFINE ALL PI IN PROGRESS FLAGS EXCEPT
				; APR FOR HALT TEST IN APRINT.
	A0.APP==1_<7-AP0CHN+13>	;CPU0 APR PI IN PROGRESS
	A0.NOC==:PIPROG-<400_<7-CK0CHN>> ;PI-IN-PROG EXCEPT CLOCK
	>	;END IFE CP0P6N

IFN CP0P6N!CP0KIN!CP0KLN, <A0.FOV==000	;PC CHANGE CANNOT BE ENABLED ON PDP-6, BEACUSE
				; IT MAKES MONITOR TRAP ALSO>

;DEFINE APR SYMBOLS FOR PDP-6 VS PDP10 FOR CPU 1:

IFDEF CP1KAN,<
	IFG CP1KAN,<A1.FOV==100>		;PDP10 HAS FOV
IFG <CPUN-1>,<IFE CP1P6N,<	A1.NOT==PIPROG-<400_<7-AP1CHN>>
				A1.APP==1_<7-AP1CHN+13>>>

	IFN CP1P6N!CP1KIN!CP1KLN,<A1.FOV==000>	;PC CHANGE CANNOT BE ENABLED
				; ON PDP 6, CPU 1 BECAUSE IT MAKES MONITOR
				; TRAP ALSO.
>

IFG <CPUN-1>,<
	INTERNAL AP1RST,AP1NUL

	AP1NUL==433550+AP1CHN
IFN CP1KIN,<AP1NUL==IP.CTE+IP.CAE+IP.ECI+XP.CCF+IP.CAB+IP.CIO+IP.CNM+AP1CHN_3+AP1CHN>
IFN CP1KLN,<AP1NUL==LP.ESF!LP.CSF!LP.SBE!LP.NXM!LP.PAR!LP.IOF!LP.PWF+LP.CSD+AP1CHN>
	AP1RST==AP1NUL+200000
>;END IFG <CPUN>-1
IFN M.KA10,<
IFE CPTOS,<			;REGULAR SETTINGS FOR TRAP OFF-SETS?
	XP	C0TOS,0		;MASTER OFFSET =0
	XP	C1TOS,100	;SLAVE OFFSET = 100
	XP	MPTRAP,40	;MASTER TRAPS TO 40-61
	XP	MPTRP2,60
	XP	UUO40,UUO0	;MASTER UUO HANDLER
	XP	UUO60,UUO2
IFG CPUN-1,<			;MORE THAN 1 CPU?
	XP	UUO140,UUOSP0	;SLAVE UUO ENTRY POINT
	XP	UUO160,UUOSP2
	XP	SPTRAP,140	;SLAVE TRAPS TO 140-161
	XP	SPTRP2,160
>				;END CPUN-1
>				;END CPTOS

IFN CPTOS,<			;REVERSED SETTINGS FOR TRAP OFF-SETS?
IFE <CPUN-1>,<			;ONLY ONE CPU
PRINTX	?;TRAP OFFSET SWITCH CANNOT BE SET ON A SINGLE PROCESSOR SYSTEM
>
	XP	C0TOS,100	;MASTER OFFSET = 100
	XP	C1TOS,0		;SLAVE OFFSET = 0
	XP	MPTRAP,140	;MASTER TRAPS TO 140-161
	XP	MPTRP2,160
	XP	SPTRAP,40	;SLAVE TRAPS TO 40-61
	XP	SPTRP2,60
	XP	UUO40,UUOSP0	;SLAVE UUO ENTRY POINT
	XP	UUO60,UUOSP2
	XP	UUO140,UUO0	;MASTER UUO ENTRY POINT
	XP	UUO160,UUO2
>>
;IF THERE IS ONLY ONE CPU IN THIS SYSTEM DEFINE ALL NECESSARY GLOBALS

IFG <CPUN-1><
	EXTERNAL SPRINI,MSCHED,TWOCHK
>

IFE <CPUN-1>,<			;NO SECOND CPU?
	EXTERNAL SCHEDJ

IFN M.KA10,<	XP	USPRET,UMPRET>
	XP	UXITMP,CPOPJ1
	XP	USPXIT,CPOPJ
	XP	MSTUUO,CPOPJ
	XP	CP0RC,CPOPJ1
	XP	CP1AC,CPOPJ1
	XP	SPSTOP,CPOPJ1
	XP	DPXST,CPOPJ
	XP	CLRJSP,CPOPJ
	XP	SETJSP,CPOPJ
	XP	ALLJSP,CPOPJ
	XP	ANYRUN,CPOPJ1
	XP	SLVCHK,CPOPJ
	XP	MSCHED,SCHEDJ
	XP	DXRUN,CPOPJ1
IFN FTMEMPAR,<	XP	SLVPAR,PARSWP##>
	XP	SVTYPE,CPOPJ
	XP	SPTYPE,CPOPJ
	XP	CSPTLE,CPOPJ1
	XP	LOKSCD,CPOPJ
	XP	ULKSCD,CPOPJ
	XP	CHKCPU,CPOPJ1
	XP	.C1OK,.C0OK
	XP	CLRCCB,CPOPJ
	XP	CPUCMD,CPOPJ
	XP	SETCPU,CPOPJ
	XP	SETCRN,CPOPJ1
	XP	CRESET,CPOPJ
	XP	CPUTRP,CPOPJ1
	XP	CP1APE,CPOPJ
	XP	CPSCHK,CPOPJ1
	XP	MSRQT,CPOPJ
	XP	MSIPUC,CPOPJ
	XP	.C1DBL,.C0DBL
	XP	.C1APC,.C0APC
	XP	.C1AEF,.C0AEF
	XP	MAPUEC,CPOPJ
	XP	MAPUC,CPOPJ
	XP	CP1DIE,CPOPJ	;CPU1 DEATH
	XP	CP1SBP,CPOPJ
	XP	ONCPU0,CPOPJ
	XP	OTHCPU,CPOPJ1
	XP	CP1STP,CPOPJ1
	XP	MRNBL,SCHDJ1##
	XP	SCDSS1,CPOPJ

IFN FTMS,<
	INTERNAL SVMES,.C1STS,.C1PUC,SPRINI,SPTRAP,TWOCHK,ONCCHK
		;LOCATIONS IN SLAVE CDB WHICH ARE CHECKED INDIVIDUALLY BY MASTER:
;FOLLOWING LOC ALWAYS ZERO (SINCE NO CPU1)
SPTRAP==0
CP1HLT::
SVMES:				;SLAVE MESSAGE CHECKED IN CLOCK1
.C1STS:				;SLAVE STOP TS WORD CHECKED IN UUOCON
.C1PUC:	0			;SLAVE UUO COUNT CHECKED IN UUOCON
TWOMAS::
SPRINI:	HALT	.		;TRIED TO START SLAVE ON A SYSTEM BUILT FOR 1 CPU
TWOCHK:	JRST	(T1)		;GIVE OR RETURN
ONCCHK:	0			;CHECK FOR TWO CPU0'S

IFN M.KL10,<
	XP CLCSN,CPOPJ		;IF CP1SER NOT LOADED AND KL10
	XP SETCSN,CPOPJ
	XP SETCSJ,CPOPJ
	XP CSREQS,CPOPJ
	XP SCDCSH,CPOPJ1
	XP SWPCSH,CPOPJ1
	XP CTXSWP,CPOPJ
	XP CLRCSH,CPOPJ
	XP CKCP1C,CPOPJ
	XP CHKSWS,CPOPJ
DT1CMD::
DT1MTD::0
>;END IFN M.KL10

>	;END IFN FTMS
>	;END IFE CPUN-1

;INTERNAL HERE FOR 10/40N, MUST BE SAME AS IN COMMOD

INTERN	FNCEXC,FNCRED,FNCALL,FNCDLL,FNCAPP,FNCUPD,FNCCRE,FNCSUP
INTERN	FNCTRN,FNCCAT,FNCDEL,FNCCNM,FNCCPR
	FNCEXC==1		;EXECUTE ONLY
	FNCRED==2		;READ
	FNCALL==3		;ALLOCATE
	FNCDLL==4		;DEALLOCATE
	FNCAPP==5		;APPEND
	FNCUPD==6		;UPDATE
	FNCCRE==7		;CREATE
	FNCSUP==10		;SUPERSEDE
	FNCTRN==11		;TRUNCATE
	FNCCAT==12		;CHANGE ATTRIBUTES(EXCEPT PRIVILEGE,NAME,DIR)
	FNCDEL==13		;DELETE
	FNCCNM==14		;CHANGE NAME
	FNCCPR==15		;CHANGE PRIVILEGE
SUBTTL	REAL TIME TRAPPING

	INTERNAL	CLRRTD,JBTRTD,ITMRTD
IFN FTRTTRP,<
IFG RTTRPN,<

	INTERNAL RTBLK,RTTRPN,MRTRPN,RTOFST,RTBSIZ,CHNTAB,DSMTAB,RTINIC
	EXTERNAL RTTRP


IFN M.KA10,<

RTMUUO==:MPTRAP

	;TRPGO IS ENTERED FROM THE CHANNEL SAVE ROUTINE DURING A
	;REAL TIME DEVICE INTERRUPT.  LOC 40, 41, 60, 61, AND TRPFLG ARE SAVED.
	;THE NEW USERS PROTECTION RELOCATION REGISTER AND APR ENABLE BITS
	;ARE SET UP AND THE DISMIS INSTRUCTIONS ARE LOADED.  AFTER SAVING
	;THE STATE OF THE MACHINE, CONTROL IS TRANSFERED TO THE USER IN USER MODE.

TRPGO::	PUSH	P,MPTRAP	;SAVE LOCATIONS 40 AND 41
	PUSH	P,MPTRAP+1
	PUSH	P,MPTRP2	;SAVE LOCATIONS 60 AND 61
	PUSH	P,MPTRP2+1
	PUSH	P,TRPFLG	;SAVE LOWER LEVEL USER STATUS
	PUSH	P,.C0CON
	CONI	APR,1(P)	;READ CURRENT APR STATUS
	CONO	APR,440		;DISABLE APR FOR FLOATING AND ARITHMETIC OVERFLOWS
	HRROM	J,TRPFLG	;SET UP CURRENT PI LEVEL INDEX
	MOVEI	T1,@ENBTB1##(J)
	TRO	T1,AP.POV+AP.NXM+AP.ILM+XP.CLK+AP.ABK
	MOVEM	T1,.C0CON	;SET UP FOR POSSIBLE APR INTERRUPT
	CONO	APR,@ENBTB1##(J)	;LOAD UP NEW USER ENABLE BITS
	DATAO	APR,RELTB1##(J)	;SET UP NEW PROTECTION-RELOCATION
	MOVE	T1,[JSP P4,UUOHND##]
	MOVEM	T1,MPTRAP+1	;SET UP UUO TRAP INSTRUCTION
	MOVE	T1,DISMT1##(J)	;GET DISMISSAL INSTRUCTION
	MOVEM	T1,MPTRP2+1	;SET UP FAST DISMISS  INSTRUCTION
	JRST	2,@TRPTB1##(J)	;JUMP TO USER TRAP ADDRESS IN USER MODE

	;DISMIS IS ENTERED FROM THE CHANNEL DISMISS ROUTINE
	;BY A JSP J,DISMIS.  THE STATE OF THE MACHINE IS RESTORED AND
	;THE ROUTINE RETURNS TO THE CHANNEL DISMISS ROUTINE TO RESTORE
	;THE AC'S AND DISMISS THE INTERRUPT.

DSMAPR:	MOVE	T1,1(P)		;GET OLD APR STATUS
	TRZE	T1,200000	;PDL OVERFLOW SET?
	TRO	T1,400000	;YES, SET PROPER BIT
	ANDI	T1,430110	;CLEAR OUT ALL UNWANTED BITS
	TRC	T1,430110	;COMPLEMENT BITS
	CONO	APR,(T1)	;CLEAR OUT ALL BUT ORIGINAL ERRORS
DISMIS:	CONO	APR,440		;DISABLE APR FOR FOV AND AROV
	POP	P,.C0CON
	POP	P,TRPFLG	;RESTORE OLD TRPFLG
	POP	P,MPTRP2+1	;RESTORE OLD 61
	POP	P,MPTRP2
	POP	P,MPTRAP+1	;RESTORE 41 AND 40
	POP	P,MPTRAP
	SKIPE	T1,TRPFLG	;ANY  LOWER LEVEL INTERRUPTS IN PROGRESS
	JRST	DISMS1		;YES, GO RETURN TO IT
	DATAO	APR,.C0DTO	;PUT BACK PROPER USER REL-PROTECTION
	CONO	APR,@.C0LUC	;RESTORE APR ENABLE BITS
	JRST	(J)		;GO RESTORE AC'S AND DISMISS

DISMS1:	DATAO	APR,RELTB1##(T1)	;RESTORE RELOC-PROT OF INTERRUPT LEVEL USER
	CONO	APR,@ENBTB1(T1)	;AND THE PROPER ENABLE BITS
	JRST	(J)		;GO RESTORE AC'S AND DISMISS
>	;END IFN M.KA10
	$HIGH
IFN M.KI10!M.KL10,<

RTMUUO==:.UPMP+.UPMUO

;TRPGO IS ENTERED FROM THE CHANNEL SAVE ROUTINE DURING A REAL TIME DEVICE
; INTERRUPT. RELAVENT LOCATIONS FROM THE USER PAGE MAP PAGE, TRPFLG, AND
; LOCATION 61 ARE SAVED. THE REAL TIME USER'S UPMP AND TRAP LOCATIONS ARE
; SETUP AND CONTROL IS TRANSFERRED TO THE USER'S INTERRUPT ROUTINE IN USER
; MODE.

TRPGO::
IFN M.KI10,<
	DATAI	PAG,1(P)	;SAVE THE CURRENT CONTENTS OF THE USER BASE
				; REGISTER ON THE STACK
>
	DATAO	PAG,RELTB1##(J)	;SETUP THE INTERRUPT LEVEL USER'S BASE REGISTER
	ADD	P,[XWD 22,22]	;OFFSET THE STACK FOR SAVING BACKGROUND
				; CONTEXT OF THE INTERRUPT LEVEL USER
	MOVSI	T1,.UPMP+.UPPFT	;STARTING AT THE PAGE FAULT TRAP INSTRUCTION
	HRRI	T1,-20(P)	; THROUGH THE PUBLIC TRAP NEW MUUO PC
	BLT	T1,(P)		; SAVE THE BACKGROUNG UPMP
	MOVE	T1,[XWD RTTUPM,.UPMP+.UPPFT]
	BLT	T1,.UPMP+437	;SETUP THE INTERRUPT LEVEL UPMP
IFN M.KL10,<
	PUSH	P,.UPMP+.LMPFW	;SAVE PAGE FAIL WORD
	PUSH	P,.UPMP+.LMPFP	; AND OLD P.F. PC
	PUSH	P,.UPMP+.LMPFN	; AND NEW P.F. PC
	MOVE	T1,[IC.UOU+RTTILM]  ;WHERE TO GO ON ILM
	MOVEM	T1,.UPMP+.LMPFN	;STORE THAT
>
	HRRI	T1,RTTAOF	;ADDRESS OF INTERRUPT LEVEL ARITHMETIC
				; EXCEPTION PROCESSING ROUTINE
IFN M.KI10,<HLL T1,-17(P)>	;USERS ARITHMETIC ENABLE (JFCL OR MUUO)
IFN M.KL10,<HLL T1,-22(P)>
	MOVEM	T1,.UPMP+.UPAOT	;ENABLE OR DISABLE INTERRUPT LEVEL ARITHMETIC
				; TRAPPING
	PUSH	P,MPTRP2+1	;SAVE 61
	PUSH	P,TRPFLG	;AND LOWER LEVEL TRPFLG
	HRLI	J,400000	;MAKE TRPFLG NEGATIVE, USER MODE OFF
				; FOR CHN TEST ON WHETHER TO SAVE ACS
	MOVEM	J,TRPFLG	;SETUP TRPFLG FOR THIS INTERRUPT LEVEL USER
	MOVE	T1,DISMT1##(J)	;GET THE DISMISS INSTRUCTION FOR THIS INTERRUPT
				; LEVEL
	MOVEM	T1,MPTRP2+1	;STORE IT IN 61
	JRST	2,@TRPTB1##(J)	;ENTER THE USER'S INTERRUPT ROUTINE IN USER MODE

;DISMIS IS ENTERED FROM THE CHANNEL DISMISS ROUTINE BY A JSP J,DISMIS.
; THE STATE OF THE MACHINE IS RESTORED AND THE ROUTINE RETURNS TO THE
; CHANNEL DISMISS ROUTINE TO RESTORE THE AC'S AND DISMISS THE INTERRUPT.

DSMAPR:
DISMIS:
	POP	P,TRPFLG	;RESTORE LOWER LEVEL TRPFLG
	POP	P,MPTRP2+1	;RESTORE 61
IFN M.KL10,<
	POP	P,.UPMP+.LMPFN	;RESTORE NEW P.F. PC
	POP	P,.UPMP+.LMPFP	;RESTORE OLD P.F. PC
	POP	P,.UPMP+.LMPFW	;RESTORE P.F. WORD
>
	SUB	P,[XWD 20,20]	;SET STACK OFFSET FOR RESTORING BACKGROUND
				; UPMP
	MOVSI	T1,(P)		; ..
	HRRI	T1,.UPMP+.UPPFT	;STARTING AT PAGE FAULT TRAP INSTRUCTION
	BLT	T1,.UPMP+437	; RESTORE UPMP THROUGH PUBLIC TRAP NEW MUUO PC
IFN M.KI10,<
	MOVE	T1,[EXP PG.LUB+PG.LEB]
	IORM	T1,-1(P)	;SET TO RESTORE BACKGROUND UBR AND EBR
	DATAO	PAG,-1(P)	;RESTORE BASE REGISTERS
>
	JRST	(J)		;RESTORE AC'S AND DISMISS THE INTERRUPT

;INTERRUPT LEVEL USER PAGE MAP PAGE

RTTUPM:	RTTILM
	RTTAOF
	RTTPOF
	JFCL
	0
	0
	0
	0
	EXP	IC.UOU+MUUO
	EXP	IC.UOU+KTUUO
	EXP	IC.UOU+SNTUUO
	EXP	IC.UOU+CTUUO
	EXP	IC.UOU+RTCNTU
	EXP	IC.UOU+CTUUO
	EXP	IC.UOU+RTPNTU
	EXP	IC.UOU+PTUUO

;HERE ON A UUO AT INTERRUPT LEVEL

RTCNTU:RTPNTU:
	MOVE	17,.UPMP+.UPMUP	;AC 17 = MUUO PC
	JRST	UUOHND##	;DISPATCH TO THE UUO HANDLER


;HERE ON AN ARITHMETIC EXCEPTION AT INTERRUPT LEVEL

RTTAOF:	SKIPL	TRPFLG		;INTERRUPT IN PROGRESS?
	JRST	MPTRP2+1	;NO, JUST DISMISS
	MOVEM	T1,.JDAT+.JBCNI##
	MOVEI	T1,AP.AOV+AP.FOV;REASON FOR THE TRAP
	JRST	ERRGO		;JOIN COMMON CODE

;HERE ON A PUSH DOWN LIST OVERFLOW AT INTERRUPT LEVEL

RTTPOF:	SKIPL	TRPFLG		;INTERRUPT IN PROGRESS?
	JRST	MPTRP2+1	;NO, JUST DISMISS
	MOVEM	T1,.JDAT+.JBCNI##
	MOVEI	T1,AP.POV	;TELL USER THE REASON FOR THE TRAP
	JRST	ERRGO		;JOIN COMMON CODE

;HERE ON AN ILLEGAL MEMORY REFERENCE (PAGE FAULT) AT INTERRUPT LEVEL

RTTILM:	SKIPL	TRPFLG		;INTERRUPT IN PROGRESS?
	JRST	MPTRP2+1	;NO, JUST DISMISS
	MOVEM	T1,.JDAT+.JBCNI##
IFN M.KL10,<
	MOVE	T1,.UPMP+.LMPFP	;GET PF OLD PC
	MOVEM	T1,.UPMP+.UPMUP	;STORE IT IN A COMPATABLE PLACE
>
	MOVEI	T1,AP.ILM	;TELL USER THE REASON FOR THE TRAP
ERRGO:	EXCH	J,TRPFLG	;GET INDEX INTO REAL TIME BLOCK
	EXCH	T1,.JDAT+.JBCNI##
	EXCH	T1,.UPMP+.UPMUP	;GET THE TRAP PC
	EXCTXU	<MOVEM T1,@APRTB1##(J)>
	HRR	T1,APRTB1##(J)	;ADDRESS OF THE USER'S TRAP HANDLING ROUTINE
	HRRI	T1,1(T1)	;CLEAR ALL FLAGS WHICH COULD CAUSE A TRAP
	TLZ	T1,(XC.OVF+XC.FOV+XC.TRP+XC.FUF+XC.NDV)
	EXCH	T1,.UPMP+.UPMUP	;RESTORE T1 AND STORE PC
	EXCH	J,TRPFLG	;RESTORE J AND TRPFLG
	JRSTF	@.UPMP+.UPMUP	;AND ENTER USER'S TRAP HANDLING ROUTINE

>	;END IFN M.KI10!M.KL10
	$ABS
	RTINIC==1			;FLAG SYSINI TO CALL INITIALIZATION ROUTINE

IF1,<	CHNTAB:	BLOCK 6
	DSMTAB:	BLOCK 6>

IF2,<
	ZZ==1

	DEFINE	BLDTB1(ZZ)
	<IFNDEF UNIQ'ZZ,<BLDTB2(ZZ)>
	IFDEF	UNIQ'ZZ,<IFE UNIQ'ZZ,<BLDTB2(ZZ)>
				IFN UNIQ'ZZ,<EXP 0>>>

	DEFINE	BLDTB2(ZZ)
	<IFN CUSD'ZZ,<EXP CH'ZZ>
	IFE	CUSD'ZZ,<XWD 400001,CH'ZZ>>

	DEFINE	BLDTB3(ZZ)
	<IFDEF CHND'ZZ,<XWD RTSV'ZZ,CHND'ZZ>
	IFNDEF	CHND'ZZ,<EXP 0>>

REPEAT 6,<
	BLDTB1(\ZZ)
	ZZ==ZZ+1>

	ZZ==1

REPEAT 6,<
	BLDTB3(\ZZ)
	ZZ==ZZ+1>
>
ENBSTD==470550+AP0CHN

MRTRPN==-RTTRPN
RTBSIZ==20
RTBLK:	BLOCK	RTTRPN*RTBSIZ
>>
IFE FTRTTRP,<IFN RTTRPN,<
PRINTX ;PLEASE ASSEMBLE SOURCES WITH FTRTTRP=-1
>>
IFN FTRTTRP,<IFE RTTRPN,<
INTERN CHAINT,RTBLK,RTLINK,SAV41,SAV61,CHNTAB,RTBSIZ,BLKENB,RTINIC
CHAINT==CPOPJ
RTBLK==CPOPJ
RTLINK==CPOPJ
SAV41==CPOPJ
SAV61==CPOPJ
CHNTAB==CPOPJ
RTBSIZ==CPOPJ
BLKENB==CPOPJ
RTINIC==0			;FLAG SYSINI NOT TO CALL INITIALIZATION ROUTINE
>>
	;CREATE JBTRTD TABLE ONLY IF THERE ARE REAL TIME DEVICES OR
	;HIGH PRIORITY QUEUES OR THE HIBERNATE-WAKE FEATURE.
	;LH(JBTRTD) = REAL TIME STATUS BITS FOR HPQ AND HIBERNATE-WAKE
	;RH(JBTRTD) = COUNT OF REAL TIME DEVICES OWNED BY EACH JOB

ZZ=0
IFN FTRTTRP,<IFG RTTRPN,<ZZ==ZZ+1>>
IFN SYS50N,<IFN FTHPQ,<IFG HPQN,<ZZ==ZZ+1>>>
IFN FTHIBWAK,<ZZ==ZZ+1>

IFG ZZ,<JBTRTD: BLOCK JOBN
ITMRTD==JOBMXL
CLRRTD:	SETZM	JBTRTD(J)
>

IFLE ZZ,<JBTRTD:	0		;FOR GETTAB
ITMRTD==JOBMXL
CLRRTD:	JFCL
>


;JBTRTD BIT DEFINITIONS

;BITS 27-35	ARE THE COUNT OF THE NUMBER OF REAL TIME DEVICES OWNED BY THIS JOB

;BITS 23-26	ARE TEMPORARY HPQ (SHARABLE DEVICE OWNER)

;BITS 15-17	ARE THE HIBERNATE PROTECTION CODE FOR THIS JOB

;BIT 14		IS TTY INPUT ACTIVITY ENABLE - CHARACTER MODE
;BIT 13		IS TTY INPUT ACTIVITY ENABLE - LINE MODE

;BIT 12		IS PTY ACTIVITY ENABLE

;BIT 11		IS I/O ACTIVITY ENABLE

;BIT 10 IF HIBER UUO AC IS AN ALIAS FOR IPCACE IN JBTRTD
;BIT 10		IS THE WAKE BIT - THIS BIT IS SET TO WAKE THE JOB UP BY HIBER

;BITS 6-9	ARE THE CURRENT HIGH PRIORITY QUEUE POSITION OF THIS JOB

;BITS 2-5	ARE THE CONSOLE COMMAND SETTING OF HPQ FOR THIS JOB

;BIT 1 IS IPCF EVENT ENABLE
;BIT 0 IS ONLY AN EXEC PROCESS CAN WAKE THE JOB
;BIT 0 OF HIBER UUO AC ARG IS 1 IF JOB IS TO BE SWAPPED IMMEDIATELY
;BUT NEVER STORED IN JBTRTD
	INTERN	TTIALE,TTIACE,TTILCE,PTYWUE,IOACE,WAKEB,HBRSWP,MONHBR

TTIALE==20		;TTY INPUT ACTIVITY - LINE MODE
TTIACE==10		;TTYINPUT ACTIVITY - CHARACTER MODE
TTILCE==TTIALE!TTIACE	;TTY INPUT - LINE AND CHARACTER MODE ENABLE
PTYWUE==40		;PTY WAKE UP ENABLE BIT
IOACE==100		;I/O ACTIVITY ENABLE BIT
WAKEB==200		;WAKE UP BIT

IFN FTIPCF,<
	INTERN	IPCACE,IPCUUB
	IPCACE==200000	;IPC EVENT ENABLE
	IPCUUB==200	;USERS ARG FOR IPC ACTIVITY
>
MONHBR==400000		;ONLY THE MONITOR CAN WAKE THIS JOB
			; (STORED IN JBTRTD)
HBRSWP==400000		;SWAP ME OUT IMMEDIATELY
			; (NOT STORED IN JBTRTD)

IFN FTHIBWAK,<
	INTERNAL HIBPRT
HIBPRT:	POINT	7,JBTRTD(J),17	;HIBERNATE PROTECTION CODE
>

IFN FTHPQ,<
	INTERNAL HPQPNT, HPQSPT, HPQMSK, HPQPN2
HPQPNT:	POINT	4,JBTRTD(J),9	;CURRENT HIGH PRIORITY QUEUE
HPQPN2:	POINT	4,JBTRTD(R),9
HPQPT1::POINT	4,JBTRTD(T1),9
HPQPT2::POINT	4,JBTRTD(T2),9
HPQSPT:	POINT	4,JBTRTD(J),5	;HIGH PRIORITY QUEUE SET BY CONSOLE COMMAND
HPQPN3::POINT	4,JBTRTD(T3),9
HPQMSK==170000			;BIT FIELD OF CONSOLE COMMAND HPQ
>
IFE FTHPQ,<
XP HPQMSK,0			;NO MASK IF NO HIGH PRIORITY QUEUE
>
	$HIGH
IFE RTTRPN,<
	INTERNAL RTTRP,RTREL

IFN FTRTTRP,<
	INTERNAL APRCHK
	EXTERNAL APRCK0

APRCHK:	SETZM	.CPRTT(P4)
	JRST	APRCK0
>				;IFN FTRTTRP

RTREL==CPOPJ
RTTRP==CPOPJ
>


IFE FTLOCK,<
INTERN	LOKJOB,UNLOK.
LOKJOB==CPOPJ
UNLOK.==CPOPJ
IFN LOKN,<
PRINTX ;PLEASE ASSEMBLE SOURCES WITH FTLOCK=-1
>>

IFN LOKN,<
IFN M.KA10,<
EXTERNAL KALOCK			;GENERATE GLOBAL TO CAUSE LOADING OF KALOCK
XP LOKEVC,CPOPJ1
>
IFN M.KI10!M.KL10,<
EXTERNAL KILOCK			;GENERATE GLOBAL TO CAUSE LOADING OF KILOCK
INTERN PDLPNO
IFE FTVM,<
PDLPNO==.JDAT/PAGSIZ
>
IFN FTVM,<
PDLPNO==.UPMP/PAGSIZ
>
>
INTERN LOKINC
LOKINC==1			;FLAG SYSINI TO CALL INITIALIZATION ROUTINE
>
IFN FTLOCK,<

	IFE	LOKN,<
	INTERNAL LOCK0,LOKJOB,UNLOCK,SETLPR,LOKINC,UNLOKH,UNLOK.,LOKSWP,LOKHGH
	INTERNAL LOKINS,LOKCHK,LOKEVC,EVLPTR

	EXTERNAL STOTAC
LOKJOB:	MOVEI	T1,0		;ERROR CODE 0 MEANS NOT IMPLEMENTED
	JRST	STOTAC
UNLOCK:	MOVSI	T1,NSHF!NSWP
	ANDCAM	T1,JBTSTS(J)
	UNLOK.:
LOCK0:!
IFN FTMOFFL,<
CKMOL::
NEWCMX::
CKLJB::
MEMOFL::
>
UNLOKH:	POPJ	P,
LOKCHK==CPOPJ1
IFN M.KI10!M.KL10,<
LOKEVC==CPOPJ
>
IFN M.KA10,<
LOKEVC==CPOPJ1
>
SETLPR==CPOPJ1
LOKHGH==CPOPJ1
LOKSWP==CPOPJ1
LOKINC==0			;FLAG SYSINI NOT TO CALL INITIALIZATION ROUTINE
EVLPTR==0
LOKINS==0			;EXEC PC ON MEM TRAP IF NO LOCK BLT
>
IFNDEF CMNN,<CMNN==0>
INTERNAL LOKASK,LOKMAX
LOKASK==LOKN
LOKMAX==CMNN

IFE CMNN,<LOKMAX==-1>
>
SUBTTL HIGH PRIORITY QUEUE UUO

IFN SYS40N,<HPQN==0>		;NO HIGH-PRIORITY QUEUE IN 10/40 SYSTEMS.
IFNDEF HPQN,<HPQN==5>		;DEFAULT VALUE IS 5 HP QUEUES
IFN SYS50N,<
IFN FTHPQ,<IFG HPQN,<
	INTERNAL HPQ,JBTRTD,HPQSET,HPQCMD
	EXTERN	REQUE,DECIN1,COMERA

HPQ:	PUSHJ	P,HPQST1	;CHECK HPQ LEGALITY
	JRST	RTM1##		;NO, GIVE ERROR RETURN
	JUMPE	T2,CPOPJ1	;IF NO PRIVILEGES DONT RESCHEDULE
	CONO	PI,PIOFF
	SKIPN	.C0RTF		;IS THERE A FORCED SCHEDULE BEING DONE
	SETOM	.C0RTF		;NO, SO START ONE
	CONO	PI,PION
	SETOM	.C0HQU		;FLAG HPQ UUO DONE SO SCHEDULER WILL
				; REQUEUE CURRENT JOB TO NEW HPQ
	JRST	CPOPJ1		;SKIP RETURN TO USER

	IFN	FTPRV,<

HPQPRV:	POINT	4,JBTPRV(J),3+^L<PVHPQ>-^D18	;MAXIMUM HPQ ATTAINABLE BY THIS JOB
>

IFE FTPRV,<
HPQSET:HPQST1:
>
IFN FTPRV,<
HPQSET:	TDZA	T2,T2		;SKIP JACCT TEST
HPQST1:	MOVSI	T2,JACCT	;SET FOR JACCT TEST
	TDNE	T2,JBTSTS(J)	;IF JACCT
	SKIPA	T2,[HPQN]	;ASSUME HIGH
	LDB	T2,HPQPRV
	CAMLE	T1,T2		;IS THIS JOB PROVILEGED ENOUGH?
	POPJ	P,		;NO, GIVE ERROR RETURN
>
	SKIPL	T1		;CORRECT FORMAT
	CAILE	T1,HPQN		;AND SMALL ENOUGH
	POPJ	P,		;NO, FAIL
	DPB	T1,HPQPNT	;YES, STORE NEW HPQ VALUE
	JRST	CPOPJ1		;GIVE SUCCESSFUL RETURN

HPQCMD:	PUSHJ	P,DECIN1	;PICK UP HPQ VALUE IN T2
	JRST	.+2		;NO ARGUMENT, ASSUME 0
	PJRST	COMERA		;ILLEGAL ARGUMENT
	MOVE	T1,T2		;
	PUSHJ	P,HPQSET	;GO CHECK HPQ LEGALITY
	PJRST	PRIERR##	;NOT LEGAL!
	DPB	T1,HPQSPT	;STORE THIS NEW VALUE
	POPJ	P,		;RETURN

>>>

IFE HPQN,<
	INTERNAL HPQ,HPQCMD
	HPQ==CPOPJ

EXTERNAL	COMERA
HPQCMD:	PJRST	COMERA
>

IFN SYS50N,<
IFE FTHPQ,<IFG HPQN,<
PRINTX? ;PLEASE ASSEMBLE SOURCES WITH FTHPQ = -1
>>>
	$ABS
SUBTTL	PROCESS DATA BLOCK
;PDB
;PROTOTYPE PROCESS DATA BLOCK
;THIS DESCRIBES THE FORMAT OF A PDB, AND IS THE PDB FOR THE NULL JOB
; IF PDBS ARE SWAPPED. IT IS THE PROTOTYPE PDB IF PDBS ARE BUILT
; IN CORE.


PDBPRO::PHASE	0
IFN FTPDBS,< ;NEEDED ONLY FOR SWAPPING CHECKSUM
.PDCHK:!BLOCK	1			;WORD USED FOR DEBUGGING.
					;(LH) TIME OF DAY IN JIFFIES
					;     (MOD 2**18) WHEN PDB WAS
					;     CREATED.
					;(RH) LDB OF CREATING PROCESS.
					;THIS WORD IS STORED IN CORE
					; IN THE JBTCHK TABLE WHEN THE
					; PDB IS SWAPPED OUT.
> ;END FTPDBS
.PDBEG:!BLOCK	1
XP	.PDIPT,.PDBEG		;IN CORE PROTECT TIME -- NUMBER OF
				; JIFFIES BEFORE JOB CAN BE SWAPPED OUT.

XP	.PDQNT,.PDBEG		;QUANTUM RUN TIME -- JIFFIES UNTIL
				; JOB SHOULD GO TO DIFFERENT RUN QUEUE

IFN FTCNO,<
.PDCNO::!BLOCK	1		;USER'S CHARGE NUMBER
>

IFN FTKCT,<
.PDKCT::!BLOCK	1		;PRODUCT OF CORE LENGTH (IN K) * NUMBER OF CLOCK TICKS
				; PROGRAM USED CPU.  USED FOR TIME ACCOUNTING.
>

IFN FTUNAME,<
.PDNM1::!BLOCK	1		;FIRST HALF OF USER'S NAME IN SIXBIT
.PDNM2::!BLOCK	1		;SECOND HALF OF USER'S NAME
>

IFN FTTIME,<
.PDRTM::!BLOCK	1		;TOTAL RUNTIME SINCE LAST RUNTIME OR KJOB
				;NULL TIME FOR TOTAL SYSTEM IS KEPT FOR JOB 0
				;COUNTED BY BOTH CPU'S
				;SEE .CPNUL FOR INDIVIDUAL NULL TIME
.PDTTM::!BLOCK	1		;TOTAL RUNTIME SINCE LAST KJOB IN JIFFIES
.PDTT2::!BLOCK	1		;ADDITIONAL RUNTIME IN JIFFIES *10^-5
IFN FTKL10,<
.PDEBT::!BLOCK	1		;(KL10) TOTAL EBOX TIME USED IN JIFFIES
.PDEB2::!BLOCK	1		;REMAINDER IN EBOX COUNTS
.PDMBT::!BLOCK	1		;(KL10) TOTAL MBOX TIME USED IN JIFFIES
.PDMB2::!BLOCK	1		;REMAINDER IN MBOX COUNTS

>;END IFN FTKL10
>
IFN FTSET,<
.PDPGM::!BLOCK	1		;PROGRAM TO RUN ON CONTROL-C OR

				; RUN COMMAND
>
IFN FTKI10!FTKL10,<
.PDABS::!BLOCK	1		;ADDRESS BREAK SETTINGS (ZERO IF USER IS
				; NOT ENABLED FOR ADDRESS BREAK).  1B0=1
				; IF BREAKING ON INSTRUCTION FETCH, 1B1=1
				; IF BREAKING ON DATA FETCH, 1B2=1 IF
				; BREAKING ON A WRITE, 1B6 (USER PAGING)
				; ALWAYS A 1, BIT 18-35=BREAK
				; ADDRESS
>
IFN FTVM,<
.PDCVL::!BLOCK	1		;CVPL,,CPPL
.PDMVL::!BLOCK	1		;MVPL,,MPPL
>
IFN FTHSLN,<
.PDDVL::!BLOCK	1		;POINTER TO TABLE OF POINTERS TO DDBS
				;  OWNED BY THIS JOB AND HAVING
				;  LOGICAL NAMES, OR ZERO IF NO
				;  SUCH DDBS, OR -1 IF TOO MANY TO
				;  FIT IN THE TABLE.
>
IFN FTIPCF,<
;NOTE THAT THE FOLLOWING 3 ITEMS MUST REMAIN IN THE ORDER
; .PDIPC, .PDIPA, .PDIPQ - THE SAME ORDER AS .EPIPC,.EPIPA,.EPIPQ

.PDIPC::!BLOCK	1		;LH=POINTER TO FIRST PACKET
				;RH=SEND AND RECEIVE COUNTERS
.PDIPA::!BLOCK	1		;IPCF STATISTICS
.PDIPQ::!BLOCK	1		;FLAGS AND QUOTAS
.PDIPI::!BLOCK	1		;MID OF THIS JOB'S SYS:INFO
>
IFN FTEQDQ,<
.PDEQJ::!BLOCK	1		;LH=0
				;RH=POINTER TO JOB QUEUE
.PDEQQ::!BLOCK	1		;LH=FLAGS
				;RH=ENQ QUOTA
;FLAGS IN LEFT HALF OF PDEQQ:
EQ.HBS==:(1B0)			;THE QUOTA HAS BEEN SET
>
IFN FTSTR,<
.PDJSL::!BLOCK	<.SLWDJ>	;JOB SEARCH LIST
.PDJSE==:.			;FIRST WORD PAST SEARCH LIST
>
.PDNET==:.			;LEFT HALF IS THE ADDRESS OF A DDB WHICH
				; HAS AN ACTIVE CONNECT/DISCONNECT IN PROCESS.
.PDSCX::!BLOCK	1		;RIGHT HALF WORD IS ADDRESS OF JOB'S SAVED CONTEXT
IFN FTIPCF,<
.PDEPA::!BLOCK	1		;RIGHT HALF IS ADDRESS OF PACKET SENT IN RESPONSE TO AN
				; EXEC PSUEDO-PROCESS IPCF MESSAGE
>
IFN FTDHIA,<
.PDDIA::!BLOCK	1		;LOC OF DIAG. DDB FOR JOB
>
.PDSTR::!BLOCK	1		;STR PROGRAM CAME FROM
.PDNAM::!BLOCK	1		;NAME OF THE PROGRAM
.PDDIR::!BLOCK	1		;DIRECTORY PROGRAM CAME FROM
IFN FTSET,<
.PDDFL::!BLOCK	1		;WORD CONTAINING USER DEFINED DEFAULTS
				; 0-8 = DEFAULT FILE PROTECTION (MUST BE HIGH 9 BITS)
				; 1B9 IS NON-ZERO IF DEFAULT PROTECTION WAS SPECIFIED
				; 1B10 IS NON-ZERO IF FILE DAEMON SPECIFIED PROTECTION
				; 18-26 = FILE DAEMON SUPPLIED PROTECTION
				; (MUST BE HIGH 9 BIT OF RH)
>
IFN FTACCT,<
.PDACS::!BLOCK	ACTSTL		;ACCOUNT STRING
IFN FTVM&FTKCT,<
.PDVKC::!BLOCK	1		;VIRTUAL TIME-CORE INTEGRAL
>
.PDUUC::!BLOCK	1		;COUNT OF UUOS DONE BY THIS JOB
>
IFN FTHPQ,<
.PDHZF::!BLOCK	1		;ORIGINAL VALUE OF TIMER IF FIT WAS ZEROED
				; BY HPQ JOB
>
IFN FTPSCD,<
.PDPST::!BLOCK	1		;NEGATIVE OF TIME SWAPPED OUT JOB REQUEUED
				; TO PQ1 OR CMQ. USED TO GAIN RESPONSE MEASURE
>
.PDLEN==:.-.PDBEG		;LENGTH OF A PDB IN WORDS
PDBWDS==:.PDLEN!1777		;SIZE OF PDB IN WORDS ROUNDED UP TO
				; A PAGE BOUNDARY. THE WHOLE PROTO
				; PDB WILL MOVE TO COMMON FOR KI-10
				; NEEDS.
PDBPGS==:PDBWDS/1777		;SIZE OF PDB IN PAGES.
PDB4WD==:<.PDLEN+3>/4		;NUMBER OF 4 WORD BLOCKS REQUIRED FOR A PDB
.PDLE4==:4*PDB4WD		;LENGTH INCLUDING SPARE WORDS AT END OF LAST BLOCK

	BLOCK	.PDLE4-.PDLEN	;DEFINE UNUSED WORDS FOR PATCHING
	DEPHASE
IFN FTPDBS,< ;IF WE SWAP PDB'S WE NEED GETTAB BUFFER


PDIOWD::IOWD	.PDLEN,PDBUFF	;POINTER TO PDB BUFFER FOR GETTABS

PDBUFF::BLOCK	.PDLEN		;MONITOR BUFFER FOR REDPDB
> ;END FTPDBS
	SUBTTL SCHEDULER QUEUE DEFINITIONS
	;(10/40 SCHEDULER QUEUES ARE LOCATED IN CLKCSS)

IFN SYS50N,<
INTERNAL FTCHECK,FTMONP
IFN FTCHECK+FTMONP,<
EXTERNAL AVALTB
DEFINE X(A,B,C),<
EXTERNAL A'AVAL
INTERNAL A'Q
A'Q==ZZ
ZZ=ZZ+1
>
	ZZ=0
	QUEUES
	LOC=ZZ
>
IFE FTCHECK+FTMONP,<

;SHARABLE DEVICE JUST BECOME AVAILABLE
;APPROPRIATE ENTRY IS SET NON-ZERO WHEN SCHEDULER SHOULD LOOK
;AT THAT QUEUE TO FIND A JOB TO RUN

DEFINE X(A,B,C)
<INTERNAL A'Q
A'Q==ZZ
ZZ==ZZ+1>
ZZ==0
QUEUES
DEFINE X(A,B,C)
<INTERNAL A'AVAL,A'Q
A'Q==.-AVALTB+ZZ
A'AVAL:	0
>

INTERNAL AVALTB,AVTBMQ

AVALTB:	RWAITS	;GENERATE THE AVAL FLAGS
LOC=.-AVALTB+ZZ
>
XP AVTBMQ,AVALTB-ZZ
;TABLE CONTAINING JOB NUMBER OF THE OWNER OF A
; SHARABLE RESOURCE.  THE RIGHT HALF WORD CONTAINS
; THE JOB NUMBER OF THE JOB THAT CURRENTLY
; OWNS THE RESOURCE OR ZERO IF THE RESOURCE IS
; AVAILABLE.  THE LEFT HALF WORD CONTAINS THE JOB
; NUMBER OF THE LAST JOB WHICH GAVE UP THE RESOURCE.
; THIS TABLE IS USEFUL FOR DEBUGGING AND REQUIRED
; SO THAT IN THE EVENT OF CATASTROPIC ERROR, E.G.,
; SWAP READ ERROR, THE RESOURCE MAY BE FREED UP.

DEFINE X(A,B,C)
<	ZZ==ZZ+1>

ZZ==0
	QUEUES

DEFINE X(A,B,C)
<INTERNAL A'USER
A'USER:	0
>
INTERNAL USRTAB
USRTAB:	RWAITS
XP USTBMQ,USRTAB-ZZ

	INTERNAL PQ1,PQ2,CMQ
;DEFINE STATE CODES WHICH DO NOT HAVE AVAL AND REQ FLAGS


DEFINE X(A,B,C)
<INTERNAL A'Q
A'Q==LOC
LOC==LOC+1
>
	CODES

XP MXCODE,LOC-1	;MAX. JOB STATE CODE
CMQ==LOC		;COMMAND DELAY QUEUE
		;**** ANY QUEUES GREATER THAN CMQ MUST BE PROCESSOR QUEUES ****
LOC=LOC+1
PQ1==LOC
LOC=LOC+1
PQ2==LOC
LOC=LOC+1

DEFINE HPQCOD(A)
<	INTERNAL HPQ'A
	HPQ'A==LOC
	LOC==LOC+1>
IFG HPQN,<ZZ==1
	REPEAT	HPQN,<HPQCOD(\ZZ)
		ZZ==ZZ+1
			>
			>

;DEFINE SYMBOLS FOR PQ2 SUBQUEUES. SQ0=-1, SQ1=-2, ETC.
; USED FOR NEGATIVE INDICES TO JBTSQ.

	DEFINE CLSGEN(A)
	<SQ'A==:A+1>

	ZZ==0
	REPEAT	M.CLSN,<
	CLSGEN(\ZZ)
	ZZ==ZZ+1>
	$HIGH
;PUT JOB DOWN A Q IF EXCEEDS QUANT. TIME
QRQTAB::XWD	PQ2,-PQ2	;FROM PQ1
	XWD	PQ2,-PQ2	;FROM PQ2
QTTAB::
DEFINE HPQTTB(A)
<	XWD HPQ'A,-HPQ'A>
IFG HPQN,<ZZ==1
	REPEAT	HPQN,<HPQTTB(\ZZ)
		ZZ==ZZ+1
			>
			>
XP QRQTBL,QRQTAB-PQ1		;TABLE MINUS OFFSET

	$ABS
; BASE QUANTA FOR QUEUES
QADTAB::QQRUN1			;PQ1
RNQUNT::<3*JIFSEC>/4		;PQ2
QQSTAB::
DEFINE HPQJIF(A)
<	EXP JIFY'A>
IFG HPQN,<ZZ==0
	REPEAT	HPQN,<ZZZ==HPQN-ZZ
	HPQJIF(\ZZZ)
		ZZ==ZZ+1
			>
			>

DEFINE JIFDEF(A)
	<JIFY'A==A*2>
	ZZ==1
REPEAT HPQN,<JIFDEF(\ZZ)
	ZZ==ZZ+1>
XP QADTBL,QADTAB-PQ1		;TABLE MINUS PQ1
; MULTIPLIER TABLE FOR RUN QUANTA BY QUEUES
QRANGE:: ^D45		;RANGE IN K BETWEEN SMALLEST AND LARGEST QUANTUM
			;  RUN TIME ASSIGNMENT

; ENTRIES ARE RANGE IN TICKS BETWEEN SMALLEST QUANTUM TO ASSIGN (QADTAB)
;  AND LARGEST QUANTUM TO ASSIGN (QMXTAB)
QMLTAB::0			;PQ1
	<3*JIFSEC>/4		;PQ2
REPEAT	HPQN,<
	0			;NO MULTIPLIER FOR HPQS
>
XP QMLTBL,QMLTAB-PQ1		;TABLE MINUS PQ1

;MAXIMUM ALLOWABLE RUN QUANTA FOR QUEUES
QMXTAB::QQRUN1			;PQ1
	<JIFSEC*3>/2		;PQ2
IFG HPQN,<ZZ==0
	REPEAT	HPQN,<ZZZ==HPQN-ZZ
	HPQJIF(\ZZZ)
		ZZ==ZZ+1
			>
			>
XP QMXTBL,QMXTAB-PQ1		;TABLE MINUS PQ1
IFN FTSWAP,<
INTERNAL ISCAN,OSCAN,SSCAN,ISTMXL,OSTMXL,SSTMXL
EXTERNAL QFOR,QBAK
EXTERNAL IQFOR,IQFOR1,IQBAK,IQBAK1
EXTERNAL OQFOR,OQFOR1,OQBAK,OQBAK1
EXTERNAL FOQFOR,IGFOR,OLFOR,IRRFOR
IFN FTNSCHED,<
EXTERNAL SQFOR,FSQFOR,BQFOR,ISSFOR,IBBFOR,OSSFOR
>


ISCAN:	;SCAN FOR INPUT - GETTAB TABLE 45

DEFINE HPQSCN(A)
<	XWD -HPQ'A,QFOR>
IFG HPQN,<ZZ==0
	REPEAT	HPQN,<ZZZ=HPQN-ZZ
		HPQSCN(\ZZZ)
		ZZ==ZZ+1
			>
			>

	XWD	-CMQ,QFOR	;MONITOR COMMAND WHICH NEEDS CORE IMAGE IN CORE
	XWD	-PQ1,IQFOR	;GET PEOPLE WHO GETSEGED FIRST
	XWD	-PQ2,IGFOR	;BUT JUST THOSE WITH QUANTA LEFT
FISCAN::XWD	-PQ1,OQFOR
IFE FTNSCHED,<
	XWD	-PQ2,FOQFOR	;FAIRNESS HERE
>
IFN FTNSCHED,<
	XWD	-PQ2,FSQFOR	;FAIRNESS HERE
>
	XWD	-PQ2,IQFOR
IFN FTNSCHED,<
	XWD	-PQ2,BQFOR
>
ISTMXL==<.-ISCAN-1>B26	;MAKE ENTRY IN GETTAB FOR INPUT SWAP SCAN LIST
IFN FTPATT,<
	Z		;PATCH SPACE
	Z
>
	Z		;FINAL ZERO TO FLAG END
ISCAN1::		;ALTERNATE INPUT SCAN
IFG HPQN,<ZZ==0
	REPEAT	HPQN,<ZZZ=HPQN-ZZ
		HPQSCN(\ZZZ)
		ZZ==ZZ+1
>
>

	XWD	-CMQ,QFOR	;MONITOR COMMAND WHICH NEEDS CORE IMAGE IN CORE
IFE FTNSCHED,<
	XWD	-PQ2,FOQFOR
>
IFN FTNSCHED,<
	XWD	-PQ2,FSQFOR
>
	XWD	-PQ1,OQFOR
	XWD	-PQ2,IGFOR
	XWD	-PQ1,IQFOR
	XWD	-PQ2,IQFOR
IFN FTNSCHED,<
	XWD	-PQ2,BQFOR
>
IFN FTPATT,<
	Z		;PATCH SPACE
	Z
>
	Z		;FINAL ZERO TO FLAG END
	INTERNAL SSCN,MFC,FSCN
	SSCN=-3		;SECONDARY SCAN TABLE ADDRESS
	EXP	SSCAN1
	MFC=-2		;MAXIMUM FAIRNESS COUNT 
	EXP	SFC0
	FSCN=-1		;ENTRY IN SCAN TABLE OF FIRST FAIR LOCATION
	EXP	FSCAN
SSCAN:			;SCHEDULER SCAN LIST - GETTAB TABLE 47
DEFINE HPQSCN(A)
<	XWD -HPQ'A,IQFOR>
IFG HPQN,<ZZ=0
	REPEAT	HPQN,<ZZZ=HPQN-ZZ
		HPQSCN(\ZZZ)
		ZZ=ZZ+1
>
>

	XWD	-PQ1,IQFOR	;SCHEDULER'S SCAN FOR NEXT JOB TO RUN
FSCAN::
IFE FTNSCHED,<
	XWD	-PQ2,IRRFOR
>
IFN FTNSCHED,<
	XWD	-PQ2,ISSFOR
	XWD	-PQ2,IBBFOR
>
SSTMXL==<.-SSCAN-1>B26	;MAX ENTRY FOR GETTAB

IFN FTPATT,<
	Z		;FOR PATCHING
	Z
>
	Z		;FINAL ZERO TO FLAG END
IFG CPUN,<
Q1SCAN::
ZZ==0
REPEAT HPQN,<ZZZ==HPQN-ZZ
	     HPQSCN(\ZZZ)
	     ZZ==ZZ+1
>
	XWD	-PQ1,QFOR
	Z
>;END IFG CPUN
;SLAVE PROCESSOR SCAN TABLE FOR CPU SCHEDULING


	EXP	SSCAN		;SECONDARY SCAN TABLE FOR SLAVE
	EXP	SFC1		;MAXIMUM FAIRNESS COUNT
	EXP	FSCAN1		;ENTRY POINT IN SCAN TABLE OF FIRST FAIR TABLE
SSCAN1:

	IFG HPQN,<
		ZZ==0
		REPEAT HPQN,<ZZZ=HPQN-ZZ
			HPQSCN(\ZZZ)
			ZZ==ZZ+1
				>
				>

IFE FTNSCHED,<
	XWD	-PQ2,IRRFOR
>
IFN FTNSCHED,<
	XWD	-PQ2,ISSFOR
>
FSCAN1:	XWD	-PQ1,IQFOR	;IF NO JOBS TRY PQ1
IFN FTNSCHED,<
	XWD	-PQ2,IBBFOR
>
IFN FTPATT,<
	Z		;FOR PATCHING
	Z
>
	0
LSCAN::				;SCAN FOR LOST TIME
DEFINE HPQSCN(A)
<	XWD -HPQ'A,OQFOR>
IFG HPQN,<
	ZZ==0
	REPEAT HPQN,<ZZZ=HPQN-ZZ
		HPQSCN(\ZZZ)
		ZZ==ZZ+1
			>
		>
	XWD	-PQ1,OQFOR	;PQ1 NO CORE FORWARD
IFE FTNSCHED,<
	XWD	-PQ2,OQFOR	;PQ2 NO CORE FORWARD
>
IFN FTNSCHED,<
	XWD	-PQ2,OSSFOR	;PQ2 NO CORE SUB QUEUES FORWARD
				;INCLUDES NO CORE BACKGROUND BATCH ALSO
>
	0
;NOTE - FOR BEST RESULTS OSCAN SHOULD BE IN
; REVERSE ORDER OF ISCAN, ELSE SCHEDULER BINDS

OSCAN:	;SCAN FOR OUTPUT - GETTAB TABLE 46
	XWD	-STOPQ,IQFOR	;UNRUNABLE JOBS FIRST
	XWD	-SLPQ,IQFOR
	XWD	-EWQ,IQFOR	;EVENT WAITERS
IFN FTDAEM,<	XWD	-JDCQ,IQBAK1>
	XWD	-TIOWQ,IQFOR	;TTY IOW
IFN FTDAEM,<	XWD	-JDCQ,IQFOR1>
OTHQUE==.-1
PQ2QUE:	XWD	-PQ2,OLFOR	;INCLUDES -PQ2,IQBAK AS SUBCASE
PQ1QUE:	XWD	-PQ1,IQBAK
CMQUE:	XWD	-CMQ,IQBAK

DEFINE HPQSCN(A)
<HPQU'A:	XWD -HPQ'A,IQBAK>
IFG HPQN,<ZZ=1
	REPEAT	HPQN,<HPQSCN(\ZZ)
		ZZ=ZZ+1
			>
			>

OSTMXL==<.-OSCAN-1>B26		;MAX. ENTRY IN GETTABS
IFN FTPATT,<
	Z			;PATCH SPACE
	Z
>
	Z			;FINAL ZERO TO FLAG END


; TABLE OF WHAT QUE ENTRY IS LAST TO SCAN FOR SWAP OUT
OSCANT::OTHQUE			;WHERE TO STOP IF NOT CMQ OR PROCESSOR QUEUE
	CMQUE			;WHERE TO STOP IF CMQ
	PQ1QUE			;WHERE TO STOP IF PQ1
	PQ2QUE			;WHERE TO STOP IF PQ2
	DEFINE HPQSTP(A)
<	HPQU'A>
IFG HPQN,<
	ZZ=1
	REPEAT HPQN,<HPQSTP(\ZZ)
		ZZ=ZZ+1
>
>
>
OSCNTQ=:OSCANT+1-CMQ		;MAKE AN INDEX INTO STOP TABLE
>				;END 10/50 QUEUE DEFINITIONS
; SPECIAL SCAN TABLE FOR DECREMENTING IN CORE PROTECT TIMES
; PROCESSOR QUEUES MUST BE IN REVERSE ORDER SO THAT REQUEING
; DUE TO EXPIRATION OF ICPT DOES NOT PUT JOB WHERE WE WILL SEE
; IT AGAIN (QUEUES ARE ALSO SCANNED IN REVERSE)
; MUST ALSO CONTAIN ANY OTHER PHYSICAL QUEUE WHICH IS ALLOWED TO
;  RETAIN ICPT. CURRENTLY THIS IS ONLY SLP AND EW.

DCSCAN::EXP	-EWQ		;EVENT WAIT QUEUE
	EXP	-SLPQ		;SLEEP QUEUE
	EXP	-PQ2		;PQ2
	EXP	-PQ1		;PQ1
	DEFINE HPQSCN(A)
<	EXP	-HPQ'A>
IFG HPQN,<
ZZ==1
	REPEAT HPQN,<HPQSCN(\ZZ)
		ZZ==ZZ+1
>
>
IFN FTPATT,<
	0
	0
>
	0
$ABS
IFN FTNSCHED,<
;SUBQUEUE INPUT SCAN TABLE
;
;FOR GENERATING PRIMARY SCAN TABLE, ENTRIES CONTAIN:
; PRIORITY COUNTER IN LEFT HALF,
; SUBCLASS NUMBER IN RIGHT HALF.
;
;FOR GENERATING SECONDARY INPUT SCAN, ENTRIES CONTAIN:
; MINUS SUBQUEUE NUMBER IN LEFT HALF,
; SECONDARY QUOTA IN RIGHT HALF.

SQSCAN::BLOCK	M.CLSN

SQCNT::	0			;COUNTER OF LOCATIONS LEFT IN PRIMARY SCAN TABLE
SQPNT::	0			;POINTER TO CURRENT LOC IN PRIMARY SCAN TABLE
SQSUM::	0			;SUM OF SECONDARY PERCENTS
SQSAVJ::0			;NUMBER OF CLASS ALREADY SCANNED
SCNJIL::0			;TIME TO STOP SCANNING JBTJIL
SCNSWP::0			;# TICS SAME PRIMARY SUBQUEUE HAS BEEN SCANNED
SCNBBS::0			;TIME TO SWAP NEXT BB JOB
BBFIT::	0			;NON-ZERO IF BACKGROUND BATCH JOB BEING FIT
BBFLAG::0			;NON-ZERO IF BACKGROUND BATCH QUEUE BEING SCANNED

>;END IFN FTNSCHED
SEED::	377775			;SEED FOR RANDOM NUMBER
$HIGH
IFN FTNSCHED,<
$ABS
;SUBQUEUE SCAN TABLE FOR CPU0
;
;ENTRIES CONTAIN:
; MINUS SUBQUEUE NUMBER.
; TABLE TERMINATES WITH A ZERO.

SSSCAN::BLOCK	M.CLSN
	0			;ZERO TERMINATES TABLE
SSCNT::	0			;COUNTER OF ENTRIES LEFT IN PRIMARY SCAN TABLE
SSPNT::	0			;POINTER TO PRIMARY SCAN TABLE FOR CPU0
SSSUM::	0			;SUM OF SECONDARY PERCENTS


IFN FTMS,<
;SUBQUEUE SCAN TABLE FOR CPU1

SSSCN1::BLOCK	M.CLSN
	0			;ZERO TERMINATES TABLE
SSPNT1::0			;POINTER TO PRIMARY SCAN TABLE FOR CPU1
>

$HIGH
>;END IFN FTNSCHED
IFN FTNSCHED,<
$ABS
;PRIMARY SCAN TABLE

;STORED AS 101 5BIT ENTRIES, ONE FOR EACH PERCENT OF THE SYSTEM RESOURCES.
; ENTRY 101 IS A DUPLICATE OF ENTRY 1.

PSQTAB::BLOCK	^D15		;ROOM FOR 101 ENTRIES

$HIGH
>;END IFN FTNSCHED
SUBTTL MINIMUM CORE USAGE DATA TABLES

;TABLE OF INDICES TO FIRST POSITION ON TABLES BELOW FOR VARIOUS KONTROLLER TYPES
TYPTAB::EXP	FRSTDR##	;TYPE 0 (DR) FUTURE DRUM, IF ANY
	EXP	FRSTFH##	;TYPE 1 (FH) BURROUGHS DISK OR BRYANT DRUM
	EXP	FRSTDP##	;TYPE 2 (DP) RP10 KONTROLLER RP01, RP02, RP03 DRIVES
	EXP	FRSTMD##	;TYPE 3 (MD) BRYANT MASS DISK
	EXP	FRSTFS##	;TYPE 4 (FS) RH10/RS04
	EXP	FRSTRP##	;TYPE 5 (OH) RH10/RP04

;TABLES COMPUTED BY ONCMOD
;UNITS ARE MICROSECONDS

;AVERAGE TIME PER PAGE (K) TABLE COMPUTED BY ONCMOD

MCUATP:: Z			;FUTURE DRUM
	Z			;DITTO
	Z			;RD10
	Z			;RM10B
	Z			;RP01
	Z			;RP02
	Z			;RP03
	Z			;DUAL POSITIONER MD10
	Z			;SINGLE POSITIONER MD10
	Z			;RS04
	Z			;RP04
	Z			;RP06

;AVERAGE LATENCY TIME TABLE COMPUTED BY ONCMOD

MCUALT:: Z			;FUTURE DRUM
	Z			;DITTO
	Z			;RD10
	Z			;RM10B
	Z			;RP01
	Z			;RP02
	Z			;RP03
	Z			;DUAL POSITIONER MD10
	Z			;SINGLE POS. MD10
	Z			;RS04
	Z			;RP04
	Z			;RP06

	$LIT		;GENERATE ALL LITERALS BEFORE RELOC
IFN FT2SEGMON,<
	LOLOC==ABSLOC-COMORG
>
	$LOW
IFE FT2SEGMON,<
	RELOC	.-COMORG
>
IFNDEF	FTCMBTH,<END	SYSTRT>	;END UNLESS ASSEMBLING COMMONS TOGETHER