Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-01 - 43,50035/common.mun
There are no other files named common.mun in the archive.
TITLE COMMON - MONITOR COMMON DATA AREA AND CONFIGURATION DEFINITION - V437
SUBTTL PART 3 COMMON.MAC - T. HASTINGS/RCC  TS  03 JUN 69
XP VCOMMN,437
		;PUT VERSION NUMBER IN GLOB AND LOADER STORAGE MAP

REPEAT 0,<

;THE COMMON SUBPROGRAM CONSISTS OF 3 FILES ASSEMBLED TOGETHER AS ONE SUBPROGRAM:
  1. S.MAC - THE USUAL SYSTEM SYMBOL DEFINTIONS ASSEMBLED WITH EVERY MONITOR SUBPROGRAM
  2. CONFIG.MAC - THE CONFIGURATION DEFINTION FILE GENERATED BY THE
	CONFIGURATION CONFIG PROGRAM OR BY AND EDITOR(SEE ABOVE)
  3. COMMON.MAC - THE REST OF THIS PROGRAM WHICH IS THE SAME
	SOURCE FOR ALL CONFIGURATIONS.
	HOWEVER, THE ASSEMBLIES ARE CONDITIONED BY MACROS DEFINED IN 2.
	THE FOLLOWING SYMBOLS AND TABLES ARE GENERATED:

	A. MONITOR STARTUP LOCATIONS(140-147), HENCE LOAD THIS FIRST.
	B. JOB TABLES - LENGTH DEPENDENT ON MAX. NO. OF JOBS ALLOWED
	C. ALL VARIABLE STORAGE NOT ASSOCIATED WITH A PARTICULAR DEVICE
	D. COMMON SUBROUTINE RETURNS
	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. SYSTEM CRASH STOP CONI'S.
>
;THE FOLLOWING STANDARD SYMBOLS CAN BE SUPERCEDED BY A CUSTOMER
;HAVING PREVIOUSLY DEFINED THEM ON THE CONFIG.MAC FILE USING
;MONGEN PROGRAM

IFNDEF LISTSN, <LISTSN==1>	;FORCE S.MAC TO BE LISTED WITH COMMON FILE ONLY
			;UNLESS 'LISTSN' DEFINED TO BE 0 WITH MONGEN
IFNDEF APRSN,<APRSN==0>	;SERIAL NUMBER OF APR

;STANDARD MAG TAPE DENSITY(556 BPI),PARITY(ODD-BINARY)
	INTERN STDENS		;STANDARD MAG TAPE DENSITY(556 BPI),PARITY(ODD-BINARY)
	IFNDEF STDENS,<STDENS==2>	;STAND.== BINARY AT 556 BPI
				;STDENS==D+P WHERE D AND P ARE:
				;D==1(200 BPI);D==2(556 BPI);D==3(800 BPI)
				;P==0(ODD-BINARY PARITY);P==4(EVEN-BCD PARITY)
	INTERN JIFSEC			;NO. OF CLOCK TICKS(JIFFIES) PER SECOND
	IFNDEF JIFSEC,<JIFSEC==^D60>	;STAND.==60 JIFFIES PER SEC.
	XP HNGSEC,2*JIFSEC

	INTERN DTTRY			;NO. OF TIMES TO TRY ON DECTAPE ERRORS
	IFNDEF DTTRY,<DTTRY==4>		;STAND.==4 TRIES

	INTERN MTSIZ			;SIZE OF MAGTPAE RECORDS(DATA WORDS IN BUFFER+1)
	IFNDEF MTSIZ,<MTSIZ==^D128>	;STAND.==128 WORDS PER BUFFER

	IFNDEF ECMN,<ECMN==2>	;DEFAULT VALUE = 2

	INTERN LPTSIZ			;SIZE OF LPT BUFFER(NO. OF DATA WORDS+2)
	IFNDEF LPTSIZ,<LPTSIZ==^D24+2>	;STAND.==24 WORDS PER LPT BUFFER

	INTERN BLKQNT			;MAX. NO OF CONSECUTIVE DECTAPE BLOCK SEARCHED BEFORE
			; RESCHEDULING IF ANOTHER JOB IS WAITING TO USE CONTROL
	IFNDEF BLKQNT,<BLKQNT==^D50>	;STAND.==50 DT BLOCKS SEARCHED(3 SECS.)

	INTERN NSPMEM			;NO. OF NANO-SECONDS PER MEMORY CYCLE
	IFNDEF NSPMEM,<NSPMEM==^D1760>	;STAND.==1760 NANO-SECONDS PER MEMORY CYCLE

INTERN JIFSC2,JIFMIN,WDPJIF
	JIFSC2==JIFSEC/2		;HALF NO. OF JIFFIES IN A SEC (FOR ROUNDING)
	JIFMIN==JIFSEC*^D60		;NO. OF JIFFIES PER MINUTE
	WDPJIF==^D100000/NSPMEM*^D5000/JIFSEC ;NO. OF WORDS MOVED
	IFNDEF MINCOR,<MINCOR==^D54*JOBN>	;DISK DDB AND ACCESS ENTRY
				; ALLOCATION REQUIREMENTS IN FREE CORE
				;USED TO EXPAND SIZE OF MONITOR AT ONCE ONLY TIME

				;32 WORDS/DDB AND 4 WORDS/ACCESS ENTRY = 36 WORDS
				;ASSUME 1.5 OPEN FILES/JOB


INTERN	LOGSIZ
IFNDEF	LOGSIZ, <LOGSIZ==2>	;MINSIZ OF VIRTUAL CORE LEFT
				;AND STILL ALLOW LOGIN.  MUST BE
				;AT LEAST AS BIG AS LOGIN CUSP IN K.
				;(STANDARD = 2K)
;SYSTEM INITIALIZATION DISPATCH TABLE, STARTING AT LOCATION 140
;THIS SUBROUTINE MUST BE LOADED FIRST
;ROUTINE "ONCE" IS ONCE ONLY CODE. IT CONVERTS THE DATE
;AND SETS UP IO SERVICE CHAIN,

	EXTERN SYSINI,SYSMAK,NULJOB,ONCE,JSR2
	INTERN SYSDSP,SYSDDT

	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: JRST SYSINI		;INITIALIZE SYSTEM VARIABLES ONCE ONLY
SYSDDT:
IFG DDTN,<		;EXEC DDT TO BE LOADED?
	EXTERN PATSYM
	JRST PATSYM		;YES, EXEC DDT(PATCH SYMBOL TABLE POINTER FIRST)

>
IFE DDTN,<
	HALT .		;NO, EXEC DDT
>
	JRST SYSMAK		;MAKE NEW SYSTEM
	JRST SYSINI		;INITIALIZE SYSTEM VARIABLES ALWAYS
	JEN NULJB1		;ERROR RECOVERY
	JSR ONCE		;DO ONCE ONLY CODE OVER AGAIN
	JRST JSR2		;BYPASS ONCE ONLY OPERATOR DIALOGUE
				;(IN CASE CONSOLE TTY DOWN)
SYSCRS:	JRST SYSTOP		;STOP MONITOR IN CASE OF DISASTER
;SYSTEM DATA STORAGE

;SPECIAL ABSOLUTE LOCATIONS IN LOWER MEMORY

	INTERN SYSSNP,FORTY,NULDAT,SIXTY,NULPDL,ERRPDL,KT10A,RCXIOC,RCXCCW,DDTSYM
	INTERN T30SYM,RAXIOC,RAXCCW,CRSHWD

	RAXIOC=26		;XWD 0,ADDRESS FOR RA10 DATA CHANNEL
				; MUST BE EVEN AND .LT. 777
	RAXCCW=RAXIOC+1		;XWD CONTROL WORD ADDRESS,DATA ADDRESS
				; STORED ON CHANNEL TERMINATION
	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.
				;[A LA 147 RESTART]
	KT10A=33		;COPY OF CONTENTS OF RELOCATION AND PROTECTION
				; DONE BY DTATO APR
				; NEEDED BECAUSE KT10A MOD DOES NOT COME WITH
				; LIGHTS FOR 2ND REG.
	RCXIOC=34		;INITIAL CONTROL WORD FOR DATA CHANNEL
				; (TRANSFERS CHANNE TO SEQUENCE OF IOWD'S IN DSKINT)
				; MUST BE IN EVEN LOC IN FIRST 1K OF MEMORY
	RCXCCW=RCXIOC+1		;CHANNEL STORES FINAL CONTROL WORD
				; HERE ON TERMINATION
	SYSSNP=37		;WHEN DEPOSITED NON-ZERO,PRINTS SNAP SHOT OF SYSTEM
				; ON LPT SEE LPSNAP SUBPROGRAM
	DDTSYM=36		;CONTAINS ADR. OF POINTER TO EXEC DDT SYMBOL TABLE
	FORTY=40		;PLACE WHERE UUOS ARE STORED ON TRAP
	NULDAT=42		;JOB DATA AREA FOR NULL JOB(USES EXEC
				; 62 THRU 101 20-36 FOR DUMP ACS)
				; AND ABOVE FOR PUSHDOWN LIST
	SIXTY=60		;PLACE WHERE UNIMPLEMETNED INSTR. ARE STORED ON
				; TRAP(PDP-10 ONLY)
	NULPDL=101		;PUSH DOWN LIST FOR NULL JOB
				; USES EXEC LOCS 102 THRU 137
				; USED FOR RESCHEDULING WHEN CURRENT JOB
				; GOES INTO IO WAIT
	ERRPDL=120		;PUSH DOWN LIST FOR ERROR IN NULL JOB
	T30SYM=131		;PLACE IN 10/30 JOB DATA AREA WHERE SYMBOL TABLE
				; POINTER IS STORED BY REGULAR 10/30 LOADER
				; (MOVED TO DDTSYM BY ONCE)
;PROTECTED JOB DATA STORAGE AND OTHER LOCATIONS SET EACH TIME
;A NEW JOB IS RUN(SEE APRSER-CLKINT)
	INTERN SYSBEG,SYSBG1,SYSEND

SYSBEG:				;FIRST LOCATION CLEARED ON 143 RESTART(SEE SYSINI)
XP SYSBG1,SYSBEG+1

	INTERN JOB,JOBADR,JOBDAT,USRREL,USRSAV

JOB:	0			;CURRENT JOB RUNNING AT UUO LEVEL
JOBDAT:				;LOC OF CURRENT JOBS JOB DATA AREA
				; SAME AS JBTDAT AND AC JDAT
JOBADR:	0			;XWD PROTECTION,RELOCATION FOR CURRENT JOB
				;SAME AS JBTADR(JOB) AND AC PROG
USRREL:	0			;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)
USRSAV:	0			;TEMPORARY FOR UUO HANDLER(IMPURE ROUTINE!)

;LOCATIONS COPIED FROM JOB DATA AREA INTO MONITOR WHEN A JOB RUNS
;THIS PREVENTS THE USER FROM CLOBBERING THEM AND MAKES IT
;EASIER FOR THE MONITOR TO LOCATE THESE QUANTITIES WHEN IT
;NEEDS TO FOR THE CURRENT JOB
;CONTENTS ARE COPIED BACK WHEN JOB BECOMES INACTIVE (SEE CLOCK)
;COMPARE WITH JOB DATA AREA (SEE JOBDAT)
;THE FOLLOWING LOCATION MUST BE IN SAME ORDER AS JOBDAT

	INTERN USRPRT,USRPR1,USRPC,USRDDT,USRHCU,USRSAV,USRJDA,USRLO,USRLO1,USRHI

USRPRT:				;FIRST LOC. OF PROTECTED JOB DATA
	USRPR1==USRPRT+1	;FIRST LOC.+1

USRHCU:	0			;HIGHEST USER IO CHANNEL IN USE
				;0 MEANS EITHER NONE OR CHAN. 0 IN USE
				;LH=-1 DURING GET OF LOW OR HIGH SEG OR SAVE OF HIGH SEG
				;SETREL ROUTINE DOESN'T STORE IN JOBHRL(115) WHEN NEG.
				;LH=-2 DURING SAVE OF LOW SEG AS FLAG THAT CORE
				; IS COMPRESSED
				;ONLY CHAN. ASSIGNMENTS IN USE ARE COPIED INTO
				;MONITOR WHEN JOB RUNS
USRPC:	0			;JOB PC WHEN SCHEDULER IS CALLED
USRDDT:	0			;RH==STARTING ADR. OF USER DDT,LH UNUSED
USRJDA:	BLOCK	20		;RH==JOB DEVICE ASSIGNMENTS (DEVICE DATA
				; BLOCK ADDRESSES)
				; LH==UUOS DONE SO FAR FOR THIS CHANNEL(SEE SYSPAR)
				; 0 MEANS NO DEVICE INITIALIZED ON THIS CHANNEL
	USRLO==USRJDA		;FIRST LOC CLEARED BY SETUSR ROUTINE
				;ON A CALL [SIXBIT /RESET/]
				;ALSO CLEARS USRHCU
	USRLO1==USRLO+1		;FIRST LOC+1
	USRHI==.-1		;LAST LOC CLEARED BY SETUSR ROUT.
;OTHER SYSTEM DATA STORAGE

	INTERN COMCNT,CLKFLG,TIMEF,APRERR,APRPC,SCHEDF
	INTERN CORLST,CORTAL,HOLEF,SHFWAT
	INTERN FTTRPSET,FTSLEEP,FTTIME,FTSWAP,FT2REL,FTDISK
	INTERN HNGTIM,CIPWT,CIPWTM,NULERR,POTLST

COMCNT:	0			;NUMBER OF COMMANDS TYPED-IN BUT NOT DECODED
				;SET BY SCNSER, DECREMENTED BY COMCON
HNGTIM:	0			;HUNG DEVICE TIME COUNT CHECK FOR HUNG IO
				;DEVICES WHEN THIS GOES TO ZERO (ONCE A SECOND)
CLKFLG:	0			;NON-ZERO WHEN CLK INTERRUPT FORCED FOR ANY REASON
TIMEF:	0			;NON-ZERO FOR CLOCK INTERRUPT ON APR
				;SET BY APRSER, TESTED AND CLEARED BY CLK ROUTINE
APRERR:	0			;APR ERROR BITS ON NON-EX MEM, ETC.
				;SET BY APRSER, CLEARED BY CLK ROUTINE(CLOCK)
APRPC:	0			;PC WHEN APR ERROR DETECTED
SCHEDF:	0			;FORCED RESCHEDULING FLAG FOR CLK ROUTINE
				;USED TO FORCE RESCHEDULING WHEN JOB IS IN EXEC MODE
NULERR:	0			;SET NON-ZERO IF MONITOR DETECTS ERROR WHILE
				; NULL JOB IS RUNNING
POTLST:	0			;-1 WHEN SCHEDULER SEES THAT THERE ARE
				;JOBS WHICH ARE POTENTIALLY RUNABLE 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. 'LSTWRD' IS INCREMENTED EVERY JIFFY
				;IF THIS FLAG IS -1 AND PREVIOUS JOB WAS NULL JOB
	IFN	FTTRPSET,<
	INTERN STOPTS
STOPTS:	0			;STOP TIME SHARING OTHER USERS BECAUSE JOB 1 DID
				;A TRPSET UUO WITH NON-ZERO AC(IE SET LOWER CORE
				; PI TRAP LOCATION. ALSO STOP CORE SHUFFLING
>
	SLJOBN=0		;NO. OF JOBS IF NO SLEEP FEATURE
	IFN FTSLEEP,<SLJOBN=JOBN>	;LEAVE ONE ENTRY PER JOB
CIPWT:	BLOCK 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 TAC WHEN PUSHJ DONE
				; BITS 24-35 ARE NO. OF CLK TICKS LEFT TO GO
	CIPWTM=CIPWT-1		;FIRST LOC-1 OF CLOCK QUEUE
IFN	ECMN,<			;IF PDP-8'S ARE ATTACHED TO THE SYSTEM
INTERN TIMSKP,TRPFLG,UUOTRA,IRQUE,IRQU1,IRQU2
TIMSKP:	EXP 0
TRPFLG:	EXP 0
UUOTRA:	EXP 0
IRQUE:	EXP 0
IRQU1:	EXP 0
IRQU2:	BLOCK ECMN
>
;STORAGE FOR VARIOUS CORE ALLOCATION FUNCTIONS

	INTERN NSWTBL,NSWMXL,CORTAB,CORMAX,CORLST,CORTAL,SHFWAT
	INTERN UPTIME,SHFWRD,STUSER,HIGHJB,CLRWRD,LSTWRD,FTTRACK


NSWTBL:				;FIRST LOCATION OF MONITOR DATA STORAGE
				; RETURNED BY GETTAB UUO(THESE LOCATIONS
				; PRESENT IN NON-SWAPPING SYSTEMS TOO)
				; OCTAL NOS. IN () CORRESPOND TO GETTAB ARG
CORTAB: BLOCK 10		;(0-7)BIT=1 IF CORRESPONDING K OF CORE IN USE BY
				; ACTIVE,IDLE, OR DORMANT HIGH OR LOW SEGS OR NON-EX
	XP CORBLK,^D256
				;NUMBER OF BITS IN CORE TABLE
CORMAX:	0			;(10)MAX. CORE REQUEST+1(IE LARGEST REL. ADR,+1)
				; CAN BE RESTRICTED TO LESS THAN ALL OF USER CORE
				; BY BUILD AND/OR ONCE
CORLST:	0			;(11)1 BIT BYTE POINTER TO LAST FREE BLOCK POSSIBLE
				; SET BY SYSINI ON 143 STARTUP
CORTAL:	0			;(12)TOTAL NO. OF FREE+DORMANT+IDLE CORE BLOCKS LEFT
SHFWAT:	0			;(13)JOB NO. SHUFFLER HAS TEMPORARILY STOPPED
				;UNTIL ITS IO DEVICES BECOME INACTIVE, BEFORE SHUFFLING
HOLEF:	0			;(14)ABS. ADDRESS OF JOB ABOVE LOWEST HOLE, 0 IF NO JOB.
UPTIME:	0			;(15)NO. OF CLOCK TICKS SINCE SYSTEM LOADED OR
				; RESTARTED AT 143
SHFWRD:	0			;(16)TOT. NO. OF WORDS SHUFFLED BY SYSTEM
STUSER:	0			;(17)JOB CURRENTLY USING THE SYSTEM TAPE
				; NEEDED SO CONTROL C WILL NOT TIE UP SYSTEM TAPE
HIGHJB:	0			;(20)HIGHEST JOB NUMBER CURRENTLY ASSIGNED

CLRWRD:	0			;(21) TOTAL NO. OF WORDS CLEARED BY "CLRCOR" RTNE.
LSTWRD:	0			;(22) TOTAL NO. OF CLOCK TICKS WHEN NULL
				;JOB RAN BUT OTHER JOBS WANTED TO RUN, BUT
				;COULD NOT BE BECAUSE:-
				;  1. SWAPPED OUT OR ON WAY IN OR OUT
				;  2. MONITOR WAITING FOR IO TO STOP SO
				;      CAN SHUFFLE OR SWAP
				;  3. JOB BEING SWAPPED OUT BECAUSE
				;      EXPANDING CORE
 
				;INSERT NEW LOCATIONS HERE WHICH ARE OF INTEREST
				; TO USERS IN NON-SWAP AND SWAP SYSTEMS
NSWMXL=<.-NSWTBL-1>B26	;MAX. ENTRY FOR GETTAB SHIFTED LEFT 9

;CORE ALLOCATION DATA NOT AVAILABLE VIA GETTAB
IFN FTTRACK,<INTERN LASCOR
LASCOR:	0		;LAST JOB OR HIGH SEG TO CALL CORE ROUTINES
			; (FOR DEBUGGING ONLY)>
;DATA LOCATIONS PRESENT ONLY IN SWAPPING SYSTEMS

	IFG SYS50N,<			;SWAPPING SYSTEM?
	INTERN SWPTBL,SWPMXL,BIGHOL,FINISH,FORCE,FIT,SWPERC,VIRTAL
	INTERN FULCNT,MAXSIZ,MAXJBN,SUMCOR
SWPTBL:				;FIRST LOCATION OF MONITOR DATA STORAGE
				; RETURNED BY GETTAB UUO(THESE LOCATIONS
				; PRESENT ONLY IN SWAP SYSTEMS)
				; OCTAL NOS. IN () CORRESPOND TO GETTAB ARG
BIGHOL:	0			;(0)CURRENT BIGGEST HOLE IN CORE (1K BLOCKS)
FINISH:	0			;(1)+JOBNO OF JOB BEING SWAPPED IN,
				;-JOBNO OF JOB BEING SWAPPED OUT
FORCE:	0			;(2)JOBNO BEING FORCED TO SWAP OUT
FIT:	0			;(3)JOBNO WAITING TO BE FITTED INTO CORE
VIRTAL:	0			;(4)NO. 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= NO. OF SWAPPER READ OR WRITE FAILURES
				; RH= ERROR BITS (BITS 18-21) + NO. OF K OF
				; DISCARDED SWAPPING SPACE



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

FULCNT:	0			;PRINT DISK IS FULL EVERY 30 SECONDS
MAXSIZ:	0			;SIZE OF LARGEST JOB WHICH MIGHT BE SWAPPED OUT
MAXJBN:	0			;NUMBER OF THAT JOB
SUMCOR:	0			;TEMP USED BY SWAPPER FOR SUM OF CORE NEEDED FOR SWAP IN
	IFN FT2REL,<
	INTERN SWPIN,SWPOUT
SWPIN:	0			;JOB NO. BEING SWAPPED IN IF IT HAS A HIGH SEG
				; USED TO REMEMBER THE JOB NUMBER DURING HIGH SEG SWAP
SWPOUT:	0		;JOB NO. BEING SWAPPED OUT IF IT HASA HIGH SEG
				; USED TO REMEMBER THE JOB NUMBER DURING HIGH SEG SWAP
>
	INTERN FTTRACK
IFN FTTRACK,<
	INTERN LASOUT,LASIN

LASOUT:	0		;LAST JOB OR HIGH SEG SWAPPED OUT
LASIN:	0		;LAST JOB OR HIGH SEG SWAPPED IN
			; ABOVE TWO FOR DEBUGGING ONLY
>
>

;DEFINE BLOCK FOR BIT TABLE DENOTING 4. WORD BLOCKS AVAILABLE (=0), IN USE(=1)
; USE MULTIPLES OF 4*36. WORDS SO THE TABLE WILL HAVE A MULTIPLE OF 36. BITS
; ADD 7 WORDS TO ACCOMODATE A POSSIBLE 1K BEYOND MINCOR AMOUNT

IFG DSKN, <
INTERNAL DDBTAB,MINCOR

DDBTAB:	BLOCK <MINCOR/^D144>+1+7
>
;MONITOR TABLES WITH ONE ENTRY PER JOB

	INTERN JBTSTS,JBTADR,JBTDAT,JBTNAM,JBTPRG
	INTERN JOBMAX,JBTMAX,MJOBN,JBTAD1,JOBMXL,JBTMXL
	INTERN FTTIME,FTKCT,FTPRV

	JOBMAX==JOBN-1		;MAX. LEGAL JOB NUMBER
	JOBMXL==<JOBMAX>B26	;HIGHEST JOB NO.SHIFTED LEFT 9(FOR GETTAB UUO)
	MJOBN==-JOBN		;NEG. NOS. OF JOBS(COUNTING NULL JOB)
	IFG KT10AN,<SEGN==JOBN+SEGN> ;IF ANY HIGH SEGMENTS,
				; MUST HAVE AT LEAST AS MANY AS JOBS
	JBTMAX==JOBN+SEGN-1	;HIGHEST INDEX IN JBT TABLES
	JBTMXL=<JBTMAX>B26	;HIGHEST JBT ENTRY SHIFTED LEFT 9(FOR GETTAB UUO)
JBTSTS:	BLOCK JOBN+SEGN		;JOB AND HIGH SEG STATUS WORD
				;LH==STATUS BITS(SEE S.MAC FOR DESC.)
				;RH==QUANTUM RUN TIME LEFT(SEE CLKCSS) FOR LOW SEGS
				;RH=IN CORE COUNT FOR HIGH SEGS
JBTADR:	BLOCK JOBN+SEGN		;JOB AND HIGH SEG CORE ASSIGNMENT
				; LH==PROTECTION,(LENGTH-1)RH==RELOCATION
				; (ABS. LOC. IN CORE)
	JBTAD1==JBTADR+1	;ADR. OF JOB 1(USED BY SYSMAK)
	JBTDAT==JBTADR		;RH==ADDRESS OF JOB DATA AREA
				;SAME AS JBTADR(JDAT==PROG)
	INTERN JBTSGN
JBTSGN:	IFG SEGN, <
	BLOCK JOBN		;SEGMENT NUMBER OF HIGH SEGMENT THIS JOB
				; IS USING IN CORE OR DISK
				; 0 MEANS JOB DOES NOT HAVE HIGH SEG
				; LH=USER DEPENDENT HIGH SEG STATUS BITS
				; (SEE S.MAC)
	XP ITMSGN,ITEM+JOBMXL	;LH SYSMBOL FOR GETTAB UUO
>
	IFE SEGN, <
	0
	XP ITMSGN,JOBMXL	;LH SYMBOL FOR GETTAB UUO
				;SO THAT JBTSGN IS UNDEFINED
				;I.E. MAKE INDEXING BY ITEM BE 0
				;      BUT ALLOW REFERENCES UP TO JOBMXL
>
	IFG DSKN,<		;DISK SYSTEM?
	INTERN PRJPRG,JBTDIR
JBTDIR:				;HIGH SEGMENT DIRECTORY NAME(DSK) OR PHYSICAL
				; DEVICE NAME(DTA,MTA)
PRJPRG:	BLOCK JOBN+SEGN		;XWD PROJECT NO.,PROGRAMMER NO.
>
	IFE DSKN,<IFG SEGN,<	;REENTRANT MONITOR WITHOUT DISK?
	INTERN JBTDIR
	JBTDIR=.-JOBN		;INDEX BY HIGH SEG NUMBER
	BLOCK SEGN		;HIGH SEGMENT PHYSICAL DEVICE NAME(DTA,MTA)
>>
	IFN FTTIME,<
	INTERN RTIME,TTIME
RTIME:	BLOCK JOBN		;TOT. RUN TIME SINCE LAST IJOB OR RUNTIME
TTIME:	BLOCK JOBN		;TOT. RUN TIME SINCE LAST IJOB
>
	IFG SYS50N,<		;SWAPPING SYSTEM?
	INTERN JBTSWP,JBTCHK
JBTSWP:	BLOCK JOBN+SEGN		;LH:==PROTECT TIME WHILE JOB IS IN CORE.
				; DISK ADDRESS WHILE SWAPPED OUT
				; BITS18-26:==OUTCORE IMAGE SIZE
				; BITS27-35:==INCORE IMAGE SIZE
				; FOR HIGH SEG, LH ALWAYS DISK ADDRESS
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
	IFN FTKCT,<
	INTERN JBTKCT
JBTKCT:	BLOCK JOBN		;PRODUCT OF CORE LENGTH(IN K) TIMES NO. OF JIFFIES
				; PROGRAM USED CPU. USED FOR TIME ACCOUNTING.
>
	IFN FTPRV,<
	INTERN JBTPRV
JBTPRV:	BLOCK JOBN		;PRIVELEGE BITS FOR JOB SET BY LOGIN
>
	IFG DSKN,<
	INTERN MQUEUE,MQTOP

MQUEUE:	BLOCK JOBN		;DISK MONITOR IO QUEUE
	MQTOP=.			;LAST LOC+1 OF MONITOR QUEUE
>
	IFG SYS50N,<
;THE FOLLOWING ARE USED TO CREATE MXQUE
;THE MAXIMUM QUEUE SIZE, USED BY SWAPPING SCHEDULER(SCHED)
	FTDISK==-DSKN		;DEFINE FEATURE SWITCH FTDISK,SINCE IT APPEARS
				; IN MACRO QUEUES
				; WHICH IS DEFINED IN S.MAC
	XP	MXQUE,0

	LALL			;LIST QUEUE DEFINITIONS FOR ALL TO SEE

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

		<A'Z==MXQUE
	INTERN A'Z
		MXQUE==MXQUE+1>
	CODES
		MXQUE==MXQUE+3

	XALL			;BACK TO NORMAL MACRO EXPANSION

	INTERN JBTQ,JBTQM1,JBTQP1,JBTQMN
	BLOCK MXQUE		;NO. OF QUEUES FOR SWAPPING SCHEDULER
JBTQ:	BLOCK JOBN		;ONE ENTRY PER JOB,
					; LH=PREVIOUS JOB, RH=NEXT JOB IN QUEUE
				; NEGATIVE MENAS THIS IS FIRST (LH) OR LAST (RH)
				; JOB IN QUEUE
	JBTQM1==JBTQ-1			;JBTQ-1
	JBTQP1==JBTQ+1			;JBTQ+1
	JBTQMN==JBTQ-NULZ		;J1
>
;TTY TRANSLATOR TABLE
;INDEXED BY TTY LINE NUMBER, CONTAINS TTY DDB ADDRESS IN RH
;(ASSIGNED WHEN FIRST CHARACTER TYPED ON TTY BY SCNSER
	;BIT 0==1 IF COMMAND TYPED BUT NOT PROCESSED
	;BITS 6-11==JOB NUMBER TTY IS ATTACHED TO
	;BITS 12-17==NEXT LINE NUMBER IN TALK RING OR ITS SELF IF NOT TALKING

	INTERN TTYTAB,PTYTAB,TPYTAB,TCONLN,MLTTYL,MTTYLN,TTPLEN,TTMODL,TTPMXL


TTYTAB: BLOCK HGHLIN+1+1	;NO OF TTYS PLUS CTY
IFN ECMN,<BLOCK ECMN>
	TPYTAB==.-1		;ADDRESS OF LAST ENTRY
	TCONLN==.-1-TTYTAB	;LINE NUMBER OF CTY
	BLOCK PTYN		;PSEUDO TTY TRANSLATOR TABLE
				; THIS IS FOR THE LINKED TTY LINES,
				; NOT THE DEVICE "PTYN"'S DDB
	TTPLEN==.-TTYTAB	;LENGTH OF ENTIRE TABLE
	TTPMXL==<TTPLEN-1>B26	;HIGHEST ENTRY IN TTYTAB SHIFTED LEFT 9(FOR GETTAB UUO)

	MLTTYL==-JOBN		;NEG, NO OF TTY DDBS (ONE FOR EACH JOB, PLUS 1 EXTRA
				; SO JOB CAPACITY EXCEEDED MESSAGE CAN BE TYPED
	MTTYLN==-TTPLEN		;NEG, LENGTH OF ENTIRE TRANSLATOR TABLE

PTYTAB:	BLOCK PTYN+1		;ADDRESSES OF THE DDBS FOR DEVICE PTYN
				; NOT THE LINKED TTY LINES. SEE TPYTAB.
;LAST LOCATION CLEARED BY SYSINI ON 143 RESTART
	SYSEND==.-1
;ONCE ONLY CODE TO CREATE DEVICE DATA BLOCKS

	LOC SYSBEG		;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 TAC,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

	INTERN LINKDB,CNTDB
	EXTERN LINKSR

LINKDB:	SETOM DESONC		;PERMIT DESTRUCTION OF ONCE ONLY CODE
	SKIPA TAC,LINKSR		;GET JSRPC 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 TAC, LINKED	;STORE EXIT FROM THIS ROUTINE (ONCE ONLY CODE WILL
				; BE OVERLAYED BY MULTIPLE DEVICE DATA
				; BLOCK GENERATION)
	MOVSI TAC,INTNUM	;NEG NO. OF ENTRIES IN TABLE
	MOVEI DEVDAT,DEVLST-DEVSER	;MAKE DEVLST LOOK LIKE DEVSER IN A DOB
LOOP:	MOVE TAC1,INTTB1(TAC)	;GET NEXT DEVICE DATA BLOCK ADDRESS
	JUMPE TAC1,NEXT		;0 MEANS NO DOB FOR DEVICE
	SKIPE DESONC		;OK TO DESTROY ONCE ONLY CODE?
	HRLM TAC1,DEVSER(DEVDAT)	;YES, STORE IN PREVIOUS DEVICE DATA BLOCK
	HRRZ DEVDAT,TAC1	;MAKE DEVDAT POINT TO CURRENT DOB
	LDB UUO,DDBNUM		;GET NO. OF DDB'S
	SOJLE UUO,NEXT		;ONE OR LESS?
	HRRZ JBUF,DEVDAT	;NO, CREATE MULTIPLE COPIES OF DOB
				; SAVE ORIGINAL IN JBUF
	MOVEI AC3,1		;STARTING WITH DEV1,DEV2,DEV77
	LDB AC1,PUNIT		;START UNIT NUMBER FROM
				; ASSEMBLE DEVICE DATA BLOCK
				; PTY STARTS UNIT NO. AT 1 INSTEAD OF 0
				; ALTHOUGH DEVICE NAMES ARE PTY0,PTY1,ETC.
MULDDB:	HRRZ TAC1,SYSSIZ	;ADR. OF NEXT DDB IS AT END OF MONITOR
	SKIPE DESONC		;OK TO DESTROY ONCE ONLY CODE?
	HRLM TAC1,DEVSER(DEVDAT) ;YES,MAKE PREVIOUS DDB POINT TO ONE ABOUT TO BE CREATED
	HRL DEVDAT,JBUF		;SOURCE ADDRESS TO LH
	HRR DEVDAT,TAC1		;DESTINATION ADDRESS TO RH
	HLRZ AC2,INTTB1(TAC)	;LENGTH OF DEVICE DATA BLOCK
	ADDB AC2,SYSSIZ		;LAST LOCATION+1 AFTER MOVE
	SKIPN DESONC		;OK TO DESTROY ONCE?
	JRST JUSTCT		;NO, JUST COUNT DDB SPACE
	BLT DEVDAT,-1(AC2)	;MOVE ORIGINAL TO FREE STORAGE
	SKIPL INTTAB(TAC)	;IS THIS DECTAPE(ANY OF 3 SERVICES)?
	JRST NOTDTA		;NO
	HRRZ AC2,DEVDAT		;YES,DESTINATION
	SUBI AC2,(JBUF)		;-SOURCE=DISTANCE MOVED
	ADDM AC2,14(DEVDAT)	;INCREMENT POINTER TO DIRECTORY BLOCK
				; (SORRY ABOUT NO SYMBOL)
NOTDTA:	MOVE PROG,PHYNAM	;BYTE POINTER TO NEWLY CREATED
				; DDB PHYSICAL NAME
	MOVE ITEM,AC3		;MAKE COPY OF UNIT NO.
	TRNN ITEM,70		;IS IT 10 OR MORE?
	JRST SMALL		;NO
	ROT ITEM,-3		;YES, CONVERT HIGH ORDER OCTAL DIGIT TO
	ADDI ITEM,20		;SIXBIT
	IDPB ITEM,PROG		;AND STORE
	TRZ ITEM,-1		;CLEAR OUT HIGH ORDER DIGIT
	ROT ITEM,3		;MOVE LOW ORDER DIGIT BACK
SMALL:	ADDI ITEM,20		;CONVERT LOW ORDER DIGIT IN SIXBIT
	IDPB ITEM,PROG		;AND STORE IN PHYSICAL NAME
	ADDI AC1,1		;INCREMENT BINARY UNIT NUMBER
	DPB AC1,PUNIT		;STORE UNIT NUMBER
JUSTCT:	CAIGE AC3,(UUO)		;COMPARE WITH HIGHEST DEVICE NUMBER
	AOJA AC3,MULDDB		;DO ANOTHER COPY
NEXT:	AOBJN TAC,.+1		;MOVE BY TWOS
	AOBJN TAC,LOOP		;ANY MORE DEVICES
	MOVEI TAC,0		;NO, FLAG END OF DEVICE DATA BLOCK CHAIN WITH 0 LINK
	SKIPE DESONC		;OK TO DESTROY ONCE?
	HRLM TAC,DEVSER(DEVDAT)	;YES, STORE 0 IN CASE LAST DDB IS MULTIPLE
IFG DSKN,<
	EXTERN LOCORE,CRINIT
	MOVE TAC,SYSSIZ		;SIZE OF MONITOR SO FAR(SYSMAK,EXEC DDT OR NOT)
	MOVEM TAC,LOCORE	;SAVE POINTER TO FIRST 4 WORD BLOCK
	ADDI TAC,MINCOR		;MINIMUM REQUIRED FOR DISK DDBS
	IORI TAC,1777		;FORCE TO 1K BOUNDARY
	ADDI TAC,1
	MOVEM TAC,SYSSIZ	;STORE SIZE OF MONITOR (FIRST FREE LOC)
	SUB TAC,LOCORE		;FORM LENGTH OF EXCESS CORE
	IDIVI TAC,^D144		;MUST BE MULTIPLE OF 144. WORDS (SEE DDBTAB)
	MOVN TAC,TAC		; -N
	HRLM TAC,CRINIT		;STORE USEABLE LENGTH OF DDBTAB
>
LINKED:	JRST .			;RETURN TO SYSINI

DESONC:	0			;FLAG =0 IF CALLED BY JSP TAC,CNTDB
				; (DO NOT DESTROY ONCE)
				; FLAG NON-ZERO IF CALLED BY JRST LINKDB
				; (OK TO DESTROY ONCE CODE)
DDBNUM:	POINT 8,INTTAB(TAC),8	;POINTER TO DDB NUMBER
PHYNAM:	POINT 6,DEVNAM(DEVDAT),17	;BYTE POINTER TO DB PHYSICAL NAME

;MACRO TO DEFINE PI CHANNEL NUMBER AND GENERATE INTERRUPT CHAINNING
;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
;WHICH HAS A DEVICE DATA BLOC(0-7)
;FIRST WORD: BIT 0==1 IF DECTAPE,BITS 1-9==NO. OF DDBS,BITS 9-17==PI CHANNEL(0-7)
;0 MEANS NO PI CHANNEL (EG PTY)
;SECOND WORD:LH==0 IF SINGLE DEVICE,==LENGTH OF DDB IF MULTIPLE,RH==DDB ADDRESS

;MACRO FOR DEVICES WHICH ARE ALWAYS PRESENT(AND WHICH DO NOT USE A CHANNEL SAVE ROUTINE
;AND HAVE NO DDB (EX-APR,CTY,PEN,CLK)


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

DEFINE	ASGINT (DEV,PI)<
	IFG DEV'N,<IFG PI,<
	IFE <PI-.CH>,<.CHAS==1	;CHANNEL PI IN USE>
	INTERN DEV'CHN
		DEV'CHN==PI
	EXTERN DEV'INT		;INTERRUPT SERVICE CONSO INSTRUCTION
		XWD PI,DEV'INT	;GENERATE INTERRUPT ENTRY POINT FOR ONCE
		XWD 0,0		;NO DDB TO CHAIN TOGETHER
	ASGIN1 (DEV,\PI)
>
>>

DEFINE ASGIN1 (DEV,PI)<
	IFDEF	CH'PI,<		;WAIT TILL PASS 2 TO DEFINE
			DEV'CHL==CH'PI
		INTERN DEV'CHL
>>
;MACRO FOR OPTIONAL DEVICES (ALWAYS USE CHANNEL SAVE ROUTINE)
	; (EXAMPLE: CR, DSK, PTR, ETC.  ALSO PTY WITH 0 PI)

DEFINE	SPASGSAV (DEV,PI,NUM) <
	DEV'N==NUM
	ASGSAV DEV,PI
>


DEFINE	ASGSAV (DEV,PI) <
	IFG DEV'N, <IFG PI, <
		EXTERN DEV'INT		;INTERRUPT SERVICE CONSO INSTRUCTION
		>
	EXTERN DEV'DDB
	ASGSV1 (DEV,\PI)
	>>

;MACRO FOR:	1. COMPLETION OF THE DEFINITION REQUIRED FOR THOSE
;		   DEVICES INVOKING THE ASGSAV MACRO
;
;		2. COMPLETE DEFINITION FOR THOSE DEVICES WITH THEIR
;		   INTERRUPT ENTRY POINT AND DDB'S IN COMMON
;		   (EXAMPLE: LPT'S)

DEFINE ASGSV1 (DEV,PI) <
	IFG PI, <
		IFE <PI-.CH>,<.CHAS==1		;CHANNEL PI IN USE>
		DEV'CHN==PI		;DEFINE DEVICE CHANNEL NUMBER
		INTERN DEV'CHN		;DECLARE INTERNAL - ONLY IF DEVICE WANTED
		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==SAVAC'PI	;STARTING CHANNEL SAVE LOCATION FOR AC'S

		INTERN DEV'SAV, DEV'RET, DEV'CHL, DEV'SAC
	>>

	DTBIT==0			;ASSUME THIS IS NOT A DECTAPE

	IFIDN <DEV>,<DTA>,<DTBIT==1>	;IS IT PDP-10 DECTAPES?
	IFIDN <DEV>,<DTC>,<DTBIT==1>	; OF PDP-6 DECTAPES?

	IFE PI, <
		XWD DEV'N*1000+0,0	;NO PI CHANNEL FOR THIS DEVICE
	>

	IFG PI, <
		XWD DTBIT*400000+DEV'N*1000+PI,DEV'INT	;FIRST WORD
	>

	IFG DEV'N-1, <
		XWD DEV'DDS,DEV'DDB	;MULTIPLE DEVICE SECOND WORD
		EXTERN DEV'DDS
	>

	IFE DEV'N-1, <
		XWD 0,DEV'DDB		;SINGLE DEVICE SECOND WORD
	>>
IFG ECMN,<

DEFINE DA25DEF(DEV,PI)
<
	EXTERN DEV'INT

	IFG PI, <
		IFE <PI-.CH>,<.CHAS==1		;CHANNEL PI IN USE>
		DEV'CHN==PI		;DEFINE DEVICE CHANNEL NUMBER
		INTERN DEV'CHN		;DECLARE INTERNAL - ONLY IF DEVICE WANTED
		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==SAVAC'PI	;STARTING CHANNEL SAVE LOCATION FOR AC'S

		INTERN DEV'SAV, DEV'RET, DEV'CHL, DEV'SAC
	>>

	XWD 1000+PI,DEV'INT		;INTERRUPT ROUTINE FOR DEVICE
	XWD 0,0			;NO DDB FOR THIS DEVICE
>>
;MACRO'S TO ALLOW GENERATION OF MULTIPLE INTTAB ENTRIES FOR MULTIPLE
; DEVICES SUCH AS LINE PRINTERS

DEFINE MULASG (DEV,DE,PI) <

	IFG DEV'N, <
		ZZ==0
		REPEAT DEV'N, <
			DEVASG DE,\ZZ,PI
			ZZ==ZZ+1
		>
	>
>

DEFINE DEVASG (DE,X,PI) <

	DE'X'N==1
	ASGSV1 DE'X,\PI
>

;MACROS TO CONTROL ASSIGNMENT OF PI CHANNELS TO DEVICES

DEFINE NEXTCH<	.CH==.CH+1
.CHAS==0
NEXTCU (\.CH)
>
DEFINE NEXTCQ<	IFN .CHAS,<NEXTCH>>
DEFINE NEXTCU (N) <IFDEF UNIQ'N,<IFN UNIQ'N,<NEXTCH>>>
;ASSUME NO PI CHANNEL SAVE ROUTINES NEEDED

	USED1==0
	USED2==0
	USED3==0
	USED4==0
	USED5==0
	USED6==0
	USED7==0

;NOW GENERATE THE TABLE FOR ONCE AND DEFINE PI CHANNEL ASSIGNMENTS

	INTERN INTTAB,INTTB1,INTNUM,SCNN,CTYN
		CTYN==1		;ALWAYS ONE CTY
		SCNN==JOBN	;NUMBER OF SCN DDB
				; ONE FOR EACH JOB + NULL JOB(EXTRA ONE)
		APRN==1		;ALWAYS AN APR
		CLKN==1		;ALWAYS LOWEST PRIORITY CLOCK


INTTAB:			;TABLE OF DATA FOR DEFINING PI CHAN AND NO. OF DOB
	INTTB1==INTTAB+1
	ASGSAV PTY,0
	ASGSAV ECM,0

.CHAS==0
.CH==0
NEXTCH

;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.

	;DATA PRODUCTS DISK BLKO/BLKI PI CHANNEL
	IFNDEF DCBCHN,<IFG DPDN,<XP DCBCHN,.CH
	NEXTCH>>
	;PDP-6 OR PDP-10 MAGTAPE BLKI/BLKO PI CHANNEL:
	IFNDEF MTDCHN,<IFG MTAN,<XP MTDCHN,.CH
	NEXTCH>>
	IFNDEF DCTCHN,<IFG MTCN,<XP DCTCHN,.CH
	NEXTCH>>
	;PDP6 OR PDP10 DECTAPE BLKI/BLKO PI CHANNEL:
	IFNDEF DTDCHN,<IFG DTAN,<XP DTDCHN,.CH
	NEXTCH>>
	IFNDEF DCTCHN,<IFG DTCN,<XP DCTCHN,.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 CHANNEL FOR HIGH-PRIORITY DEVICES
	ASGSAV CDR,.CH
	ASGINT APR,.CH

NEXTCQ
;THE FOLLOWING ARE MEDIUM-PRIORITY DEVICES, AS A GROUP
	ASGSAV SCN,.CH
	ASGSAV PTR,.CH
	MULASG LPT,LP,.CH
	ASGSAV DTA,.CH
	ASGSAV DTC,.CH
	ASGSAV MTA,.CH
	ASGSAV MTC,.CH
	ASGINT CTY,.CH
	DA25DEF(DVB,\.CH)

NEXTCQ

;THE FOLLOWING ARE LOWER-PRIORITY DEVICES,AS A GROUP
	ASGSAV DSK,.CH
	ASGSAV PEN,.CH
	ASGSAV PTP,.CH
	ASGSAV CDP,.CH
	ASGSAV PLT,.CH
	DA25DEF(DVA,\.CH)

NEXTCQ

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

NEXTCQ

;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 CLK,.CH
	SPCINT
				;GENERATE ANY SPECIAL DEVICES CUSTOMER IS SUPPLING
				; WHICH DO NOT USE A CHANNEL SAVE ROUTINE AND HAVE
				; NO DEVIC EDATA BLOCK
	SPCSAV
				;GENERATE ANY SPECIAL DEVICES CUSTOME IS SUPPLYING
				; WHICH DO NEED A CHANNEL SAVE ROUTINE
				; AND HAVE MULTIPLE DEVICE DATA BLOCKS(0 MEANS NONE)

;END OF THE ASSIGNMENT TABLE

	INTNUM==INTTAB-.	;-LENGTH OF INTERRUPT CHANNEL ASSIGNMENT TABLE

	IFLE .-SYSEND,<LOC SYSEND+1>
				; SET LOC UP TO SYSEND+1, UNLESS ONCE ONLY CODE
				; IS BIGGER
;SYSTEM CONSTATNS AND PARAMETERS

	INTERN CNFTBL,CNFMXL,CONFIG,SYSTAP,SYSDAT


CNFTBL:				;FIRST LOCATION 0F MONITOR DATA STORAGE
				; RETURNED BE GETTAB UUO(THESE LOCATIONS
				; NOT CLEARED BY SYSINI)
				; CNFTBL IS GETTAB TABLE 11(RH OF AC)
				; OCTAL NOS. IN () CORRESPOND TO GETTAB UUO
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

	INTERN TIME,THSDAT,SYSSIZ,DEVOPR,DEVLST,SEGPTR,TWOREG,STATES
	INTERN SERIAL
	EXTERN PATCH

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 PATCH		;(12)SIZE OF MONITOR(FIRST LOC NOT USED)
DEVOPR:	SIXBIT /CTY/		;(13)SIXBIT PHYSICAL NAME OF OPERATORS CONSOLE
				; (IF THIS LOCATION CONTAINS 0, NONE HAS
				;  BEEN DESIGNATED)
				;PUBLIC LOGICAL NAME "OPR" WILL BE THIS DEVICE
				;ALSO UNEXPLAINED MONITOR ERROR MESSAGE 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 FIRST HIGH SEG IN JBTXXX TABLES
				; LH=-NO. OF HIGH SEGS, RH=FIRST HIGH SEG NO.
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
	ZZ==0
	IFG DSKN,<ZZ==ZZ!1B0>	;1 IF DISK SYSTEM(ANALOGOUS TO FTDISK)
	IFG SYS50N,<ZZ==ZZ!1B1>	;1 IF SWAPPING SYSTEM(ANALOGOUS TO FTSWAP)
	IFG LOGINN,<ZZ==ZZ!1B2>	;1 IF LOGIN(ANALOGOUS TO FTLOGIN)
	IFN FTTTYSER,<ZZ==ZZ!1B3>	;1 IF FULL DUPLEX SOFTWARE
	IFN FTPRV,<ZZ==ZZ!1B4>	;1 IF PRIVILEGE FEATURE INCLUDED
	IFN FT2REL,<ZZ==ZZ!1B5>	;1 IF REENTRANT SOFTWARE
	IFE JIFSEC-^D50,<ZZ==ZZ!1B6>	;1 IF 50 CYCLE MACHINE, 0 OF 60 CYCLE
STATES:	EXP ZZ			;(17)BITS WHICH DEFINE TYPE OF SYSTEM IN LH
				; RH PATCHED BY MONITOR COMMAND TO
				; INDICATE OPERATIONAL STATE OF SYSTEM
				;INSERT NEW LOCATIONS OF INTEREST SETUP
				; BY ONCE ONLY CODE HERE
SERIAL:	EXP APRSN	;(20) SERIAL NUMBER OF APR
CNFMXL==<.-CNFTBL-1>B26	;MAX. ENTRY IN CNFTBL FOR GETTAB UUO
IFG DSKN,<
	INTERN ODPTBL,ODPMXL,SWPHGH,K4SWAP,PROT,PROT0

IFG SYS50N,<	EXTERN ICPROT,ICPRT1	;THESE ARE DEFINED ONLY IN
					; A SWAPPING SYSTEM>
IFLE SYS50N,<	XP ICPROT,0		;IF NON-SWAPPING, DECLARE
		XP ICPRT1,0		; INTERNAL IN COMMON>

ODPTBL:				;FIRST LOC IN MONITOR DATA AREA FOR DISK
				; LOCATION WHICH ARE NOT SET TO 0 WHEN SYSTEM
				; STARTED. ODPTBL IS GETTAB UUO TABLE 15

SWPHGH:	0			;(0) HIGHEST LOGICAL BLOCK # IN THE SWAPPING
				; SPACE ON THE DISK (SET BY SWPINI)
K4SWAP:	0			;(1)K OF DISK WORDS SET ASIDE FOR SWAPPING
				; ASSIGNED AT ONCE ONLY REFRESH TIME
PROT:	EXP ICPROT		;(2) IN-CORE PROTECT TIME PARAMETER USED TO
				; MULTIPLY TIMES (K-1) OF CORE
PROT0:	EXP ICPRT1		;(3) IN-CORE PROTECT TIME PARAMETER ADDED TO
				; ABOVE REULT TO COMPLETE COMPUTATION



				;INSERT NEW LOCATIONS OF INTEREST SETUP
				; BY ONCE ONLY CODE HERE FOR DISK SYSTEMS
ODPMXL==<.-ODPTBL-1>B26	;MAX. ENTRY IN ODPTBL FOR GETTAB UUO
>
;MORE DATA LOCATIONS SETUP AT ASSEMBLY TIME OR ONCE ONLY TIME
; BUT NOT OF INTEREST TO USER PROGRAMS

	INTERN XJBPFI,PMONTB,MONTAB,MIDNIT

XJBPFI:	XWD .,0			;LH FILLED IN WITH EXTERNAL JOBPFI (SEE JOBDAT)
					; JOBPFI==HIGHEST LOC, IN USER JOB DATA AREA
				; PROTECTED FROM IO
;MONTH TABLE FOR DAYTIME COMMAND PRINTING

PMONTB:	POINT 6,MONTAB(TAC),5	;POINTER TO NUMBER OF DAYS INMONTH
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 ^D60*^D60*^D24*JIFSEC	;NO OF JIFFIES TILL MIDNIGHT
;STOP PROCEDURE WHEN SHUTTING DOWN SYSTEM
;BECAUSE OF CATOSTROPHIC FAILURE OR ANY OTHER REASON
;WRITE OUT DIRECTORIES STILL IN CORE (DISK)
;TRANSFER HERE FROM LOC 147

;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 147
;  5. PUSH START(DO NOT PUSH IO RESET AS IT WILL CLEAR DEVICES)

INTERN APRSTS,PISTS,SYSTOP,CRASHX,SWTSTS,TTYSTS,PTRSTS,TMCSTS
INTERN PTPSTS,DLSSTS,DTSSTS,CRSTS,LPTSTS,PLTSTS,TMSSTS,DSKSTS,DSKDTI
EXTERN SYSPDL

EXTERN CRSHAC			;DEFINED IN SYSINI TO BE 143 RESTART CODE
				;SO MONITOR CANNOT BE RESTARTED AT 143 AFTER
				;BEING STARTED AT 147.

CRASHX:	MOVEM 17,CRSHAC+17	;SAVE AC17
	MOVE 17,TSTLOC
	CAME 17,SYSCRS		;IS LOC 147 WIPED OUT?
	HALT SYSTOP+1		;YES - LET OPERATOR DECIDE WHAT TO DO
	JRST SYSTOP+1		;NO - GO SAVE AC'S & DEVICE STATES
TSTLOC:	JRST SYSTOP

SYSTOP:	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


APRSTS:	CONI APR,.		;STORE APR STATUS HERE
PISTS:	CONI PI,.		;STORE PI STATUS HERE
SWTSTS:	DATAI APR,.
TTYSTS:	CONI TTY,.
PTRSTS:	CONI PTR,.
PTPSTS:	CONI PTP,.
DLSSTS:	CONI DLS,.
DTSSTS:	CONI DTS,.
CRSTS:	CONI CR,.
LPTSTS:	CONI LPT,.
PLTSTS:	CONI PLT,.
TMSSTS:	CONI TMS,.
TMCSTS:	CONI	TMC,.
DSKSTS:	CONI	DSK,.
DSKDTI:	DATAI	DSK,.
	CONO APR,APRRST		;RESET SYSTEM
	MOVEI	PDP,SYSPDL	;SETUP PDP TO SPARE AREA
	IFG DSKN,<
	EXTERN DSKSTP
	PUSHJ	PDP,DSKSTP>
	HALT	137400		;STOP AT TENDMP(READY TO READ IN ANYTHING)

;ERROR RECOVERY - TRY TO START NULL JOB

NULJB1:	MOVEI ITEM,0	;SET JOB NUMBER TO 0
	JRST NULJOB	;GO RESTORE NULL JOB
;COMMON SUBROUTINE RETURNS

	INTERN CPOPJ,CPOPJ1,DPOPJ,TPOPJ,TPOPJ1,CPOPJ2,IPOPJ1,IPOPJ
	INTERN CUXIT1,CUXIT,UXIT
	INTERN FTTIME,FTSWAP,FTSLEEP,FTKCT,FT2REL,FTPRV
CPOPJ2:	AOS	(PDP)		;DOUBLE SKIP SUBROUTINE RETURN
CUXIT1:				;OLD SKIP RETURN FOR UUOS
CPOPJ1:	AOSA	(PDP)		;SKIP SUBROUTINE RETURN
DPOPJ:	MOVEM	IOS,DEVIOS(DEVDAT) ;DEPOSIT IO STATUS WORD IN DDB
UXIT:
CUXIT:				;OLD RETURN FOR UUOS
CPOPJ:	POPJ	PDP,

TPOPJ1:	AOS	-1(PDP)		;RESTORE TAC THEN SKIP RETURN
TPOPJ:	POP	PDP,TAC		;RESTORE TAC
	POPJ	PDP,		;AND RETURN
IPOPJ1:	AOS -1(PDP)		;SET FOR SKIP RETURN
IPOPJ:	POP PDP,ITEM		;RESTORE ITEM (USUALLY JOB OR HIGH SEG NUMBER)
	POPJ PDP,

; SYSTEM BYTE POINTERS

	INTERN PUUOAC,PIOMOD,PJOBN,PUNIT,PJBSTS,PDVTIM,PDVCNT,PCORSZ,COREP
	INTERN IADPTR

PUUOAC:	POINT	4,UUO,12	;UUO AC FIELD
PIOMOD:	POINT	4,IOS,35	;MODE BITS
PJOBN:	POINT	6,DEVCHR(DEVDAT),5 ;DEVICE JOB ASSIGNMENT
PUNIT:	POINT	6,DEVCHR(DEVDAT),23 ;DEVICE UNIT NO.
PJBSTS:	POINT	JWSIZ,JBTSTS(ITEM),JWPOS ;JOB WAIT STATE(QUEUE) CODE
				;IN JOB STATUS WORD
PDVTIM:	POINT	6,DEVCHR(DEVDAT),17 ;TIME IN SECONDS BEFORE DEVICE
				;IS SAID TO BE HUNG
PDVCNT:	POINT	6,DEVCHR(DEVDAT),11 ;COUNTER DOWN EACH SECOND,
				;1 TO 0 TRANSITION MEANS HUNG DEVICE
IADPTR:	POINT	2,DEVIAD(DEVDAT),2	;COUNT OF NO. OF USER CHANNELS INITED
				; ON THIS DEVICE(DECTAPE ONLY)
PCORSZ:	POINT 8,JBTADR(ITEM),7	;BYTE POINTER TO LOW OR HIGH SEG CORE SIZE-1

COREP:	POINT	1,CORTAB	;1 BIT POINTER TO CORE ALLOCATION TABLE

	IFG SYS50N,<		;SWAPPING SYSTEM?
	INTERN IMGIN,IMGOUT,IMGINT,OUTMSK,INMSK,INLEFT
	INMSK=000377		;RH MASK TO IMGIN
	INLEFT=12		;NO. OF BITS TO SHIFT TO LEFT JUSTIFY IN RH

IMGIN:	POINT 8,JBTSWP(ITEM),35	;BYTE POINTER FOR # 1K BLOCKS OF CORE
				;WHEN JOB OR HIGH SEG NEXT SWAPPED IN
				;NON-ZERO ONLY WHEN SWAPPED OUT
IMGOUT:	POINT 8,JBTSWP(ITEM),26	;BYTE POINTER FOR # 1K BLOCK OF DISK
				;WHEN JOB OR HIGH SEG HAS IMAGE ON DISK
				;ZERO MEANS NO DISK SPACE ALLOCATED
	OUTMSK=377000		;RH MASK TO IMGOUT. USED TO TEST FOR 0
				; (IE NO DISK SPACE)
IMGINT:	POINT	8,JBTSWP(DEVDAT),35 ;POINTER TO INCORE IMAGE
>
;SPECIAL PROJECT-PROGRAMMER NOS.
	IFG DSKN,<		;DISK SYSTEM?
	INTERN CUSPPP,SYSPP,DUMPPP,HELPPP

CUSPPP:			;CUSP FILE DIRECTORY, MAKE SEPARATE TAG FROM
				; MFD(SYSPP)
SYSPP:	XWD	1,1	;THE MASTER FILE DIRECTORY PROJECT PROGRAMMER NO.
DUMPPP:	XWD	1,2	;THE FAILSAFE PROJ,PROG NO.(CAN READ OR WRITE ANYTHING)
HELPPP:	XWD	2,4	;SYSTAT AND HELP PROJECT,PROGRAMMER NOS IF JOB NOT LOGGED INALREADY
>
;DEFINE PI CHANNEL SAVE AND RESTORE ROUTINES IF A DEVICE IS ON THE CHANNEL

	HIGHAC==10	;HIGHEST AC SAVE ON A PI INTERRUPT
	PDL==25		;LENGTH OF INTERRUPT PI PUSH DOWN LIST

DEFINE CHAN (PI)<
	XLIST
	INTERN SAV'PI,RET'PI,CH'PI
CH'PI:	0		;PC STORED HERE BY JSR ON INTERRUPT TO CHANNEL PI
	JEN @CH'PI	;LAST INSTRUCTION ON CONSO DEV, CHAIN

;HERE FROM AN INTERRUPT ROUTINE WHICH HAS FOUND ITS DEVICE NEEDS SERVICE
;SAVE ACS 0 THRU HIGHAC, CALLED BY JSR, SETS UP PDP TO PUSH DOWN LIST FOR THIS PI

SAV'PI:	0		;CALLED BY JSR
	MOVEM HIGHAC,SAVAC'PI+HIGHAC	;SAVE AC HIGHAC
	MOVEI HIGHAC,SAVAC'PI	;SETUP TO SAVE 0 THRU HIGHAC-1
	BLT HIGHAC,SAVAC'PI+HIGHAC-1	;SAVE ACS
	MOVE PDP,SAVAC'PI+HIGHAC+1	;SETUP PUSH DOWN POINTER
	JRST @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 PDP,

RET'PI:	MOVSI HIGHAC,SAVAC'PI	;RESTORE ACS 0 THRU HIGHAC
	BLT HIGHAC,HIGHAC
	JEN @CH'PI		;DISMISS INTERRUPT ON THIS PI CHANNEL

SAVAC'PI:	BLOCK HIGHAC+1	;PLACE TO SAVE ACS 0 THRU HIGHAC
	XWD -PDL+1,.+1		;INITIAL PUSH DOWN POINTER
CH'PI'PD1:	EXP RET'PI	;FIRST WORD ON LIST,
				; POPJ WILL RETURN TO DISMISS INTERRUPT
	BLOCK PDL-1		;PUSHDOWN LIST SPACE
	LIST
>

;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>
;GENERATE NULL CHANNEL SAVE ROUTINES FOR THOSE CHANNEL NOT USED

DEFINE NULL (PI)<
	XLIST
	INTERN 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>
;HERE ON TRAPS TO LOC 60/61 - UNIMPLEMENTED INSTRUCTIONS(PDP-10 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

	INTERN UUO2

UUO2:	0			;USER PC STORE HERE BY JSR
	EXCH TAC,UUO2		;GET USER PC, SAVE TAC
IFN FTTRPSET,<
	TLNN TAC,UIOMOD		;USER IO MODE ON?
	JRST UUOER2		;NO, TREAT AS AN ILLEGAL INSTRUCTION AND PRINT MESS.
	HLL TAC,SIXTY		;YES, GET UNIMPLEMENTED OPCODE WHICH TRAPPED
	TLNE TAC,677777		;IS IT OPCODE 100(UJEN)?
	JRST UUOER1		;NO, TREAT AS ILLEGAL INSTRUCTION
	MOVE TAC,SIXTY		;YES, GET EFFECTIVE ADDRESS
	ADD TAC,JOBADR		;ADD RELOCATION FOR CURRENT JOB
	MOVE TAC,(TAC)		;GET PC STORED BY INTERRUPT JSR
	EXCH TAC,UUO2		;RESTORE TAC, AND STORE PC
	JEN @UUO2		;DISMISS INTERRUPT

UUOER1:	HRLI TAC,USRMOD!UIOMOD	;SET USER MODE AND USER IO MODE BACK ON
>
UUOER2:	MOVEM TAC,UUO0		;STORE PC AS IF AN ILLEGAL INSTR. HAD OCCURRED
	SETOM FORTY		;MAKE IT LOOK LIKE AN ILLEGAL INSTRUCTION
				; TRAPPED TO 40
	SKIPA TAC,UUO2		;RETORE TAC AND FALL INTO REGULAR UUO HANDLER
;HERE ON TRAPS TO EXEC LOC 40/41 - OPCODES 0,40-77(0-77 ON PDP-6)

	INTERN UUO0
	EXTERN UUOUSR,UUOSY1,ERROR

UUO0:	0			;JSR HERE FROM LOC 41
	MOVEM 17,USRSAV		;SAVE 17
	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?
	JSP DAT,ERROR		;NO, MUST BE UUO DURING NULL JOB
				; PRINT ERROR IN MONITOR
IFE PDP10N,<			;FOR PDP-6 OPCODES 1-37
	EXCH TAC,FORTY		;SAVE TAC, PICK UP UUO
	TLNN TAC,740000		;IS THIS SYSTEM UUO?
	TLNN TAC,077000		;NO, IS IT 0 UUO?
	JRST UUOSYS		;YES
	MOVEM TAC,40(17)	;STORE UUO IN USER'S 40
	HRRZ TAC,41(17)		;PICK UP ADR OF USER'S JSR
	JUMPE TAC,UUOSYS	;IF ADDRESS=0,ILLEGAL USER UUO
	HLL TAC,UUO0		;USER PD FLAGS(RESTORED ON RETURN)
	MOVEI 17,(TAC)		;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 TAC,1(TAC)		;YES, INCREMENT PC.
	EXCH TAC,UUO0		;SET UP RETURN TO USER IN UUO0
				; PICKUP USERS FLAGS,PC
	ADD 17,JOBADR		;MAKE REL. ADR. INTO ABS. ADR.
	MOVEM TAC,(17)		;STORE FLAGS AND PC LIKE JSR
	MOVE TAC,FORTY		;RESTORE TAC
	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 TAC,FORTY		;RESTORE USERS AC(TAC) AND USER'S UUO(FORTY)
>
	JRST UUOUSR		;GO SAVE USER'S ACS IN REL. LOC. 0-17
				; AND DISPATCH ON UUO
;GENERATE EXTERNAL GLOBALS TO CAUSE LOADING OF PROPER ROUT. FROM MONITOR LIBRARY TAPE
;IF THERE IS ONE


;ALWAYS LOAD CLOCK1,COMCON,CORE1,ERRCON,JOBDAT,ONCE,PATCH,SYSMAK,UUOCON
EXTERNAL CLOCK1,COMCON,CORE1,ERRCON,DATJOB,ONCE,PATCH,SYSMAK,UUOCON
;LOAD DDT
	IFG DDTN,<EXTERN DDTX>
	IFE DDTN,<XP DDTEND,0	;ONCE REFERENCES END OF DDT>
;LOAD APPROPRIATE SCHEDULER FOR NON-SWAP OR SWAPPING SYSTEMS
	IFG SYS40N,<EXTERN XCKCSS>	;CLKCSS
	IFG SYS50N,<EXTERN XCKCSW>	;SCHED

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

IFN FT2REL,<
	IFG KT10AN, <EXTERN SEGCON>
	IFE KT10AN, <EXTERN NULSEG>
>

;APR AND PI BITS
	INTERN	PION,PIOFF,REQCLK,PICLK,APRCLR,APRCLE,APRNUL,APRRST,NXM,APRFOV

	CLKBIT==1
	REPEAT 7-CLKCHN,<CLKBIT==CLKBIT*2>
	PION==200		;CONO PI,PION TURNS PI SYSTEM ON
	PIOFF==400		;TURN IT OFF
	REQCLK==1B24+CLKBIT	;REQUEST INTERRUPT ON LOW PRIORITY CLK CHANNEL
	PICLK=PION+REQCLK	;TURN ON PI,REQUEST INTERRUPT ON CLK CHANNEL
	APRCLR==1000+APRCHN	;TURN APR CLOCK FLAG OFF
	APRCLE==431550+APRCHN	;CLEAR ALL APR ERROR BITS
				; AND DISABLE FOV AND AR OVF
	APRNUL==433550+APRCHN	;RESET APR FOR NULL JOB
			; CLEAR EVERYTHING BUT DONT IO RESET
	APRRST==APRNUL+200000	;RESET APR FOR SYSINI(IO RESET TOO)
	NXM==10000		;NON-EX MEM I(APR STATUS WORD)
	IFG PDP10N,<APRFOV==100	;FLOADTING OVERFLOW CAN BE ENABLED ON PDP10
				; FOR USER TRAPPING>
	IFE PDP10N,<APRFOV==000	;PC CHANGE CANNOT BE ENABLED ON PDP-6, BEACUSE
				; IT MAKES MONITOR TRAP ALSO>

;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
	XP FTDISK,-DSKN
	XP FTSWAP,-SYS50N
	XP FTRC10,-RD10N

	IFG KT10AN,<XP FT2REL,-1>	;IF Z RELOC SOFTWARE, THEN FTZREL MUST BE -1
	IFE COREN,<COREN=^D256		;NO RESTRICTION IF 0 TYPED>
	XP USRLIM,COREN			;DEFINE GLOBAL RESTRICTING SIZE OF CORE FOR ANY SINGLE USER
				; ONCE ONLY CODE CAN ALTER THIS VALUE
				; (PATCH RH CORLIM IN SYSIM)
;SCANNER ENTRY POINTS AND BIT DEFINITIONS

	IFG DLSN,<EXTERN DLSINT>	;DATA LINE SCANNER
	IFG CCIN,<EXTERN CCIINT>	;DA-10 PDP-8 680
	IFG DCSN,<EXTERN DCSINT>	;630 DATA COMMUNICATIONS SYS

	IFG FULLN,<EXTERN SCNSRF>	;FULL DUPLEX SOFTWARE ENTRY POINT
	IFE FULLN,<EXTERN SCNSRH>	;HALF DUPLEX SOFTWARE ENTRY POINT
	IFG FULLN,<
	INTERN LINTAB	

LINTAB:		;LINE CHARACTERISTIC BITS (NOT CLEARED ON SYSTEM STARTUP)

;TELETYPE LINE CHARACTERISTICS(LH OF LINTAB)
;USED IN SCNSRF ALSO

	XP PTYLIN,400000	;PSEUDO TTY LINE
	XP CTYLIN,200000	;CONSOLE TTY
	XP DISLIN,100000	;KEYBOARD DISPLAY
	XP DSDTLN, 40000	;DATASET DATA LINE
	XP DSCTLN, 20000	;DATASET CONTROL LINE(DC10E)
	XP HLFDPX, 10000	;HALF DUPLEX LINE
	XP TTYRMT,  4000	;REMOTE TTY
	XP    T35,    10	;TTY HAS HARDWARE TABS
	XP FULTWX,     4	;SELF-ECHOING LINE
				;USED IN CCIINT,DCSINT,DLSINT & SCNSRF

IFG EDITN,<		;HAS COMMON.MAC BEEN EDITED TO DEFINE TTY LINE CHAR.
			; SO MONGEN TYPE-IN REDUCED?
;IF NO APR NUMBER, AND THIS IS NOT EDITED FOR THE CUSTOMER,
; MAKE ALL LINES JUST BE MODEL 33 TELETYPES

IFE APRSN,<REPEAT TTPLEN,<0>>
IFE APRSN-2,<
;FOLLOWING LINE DEFINITIONS FOR DEC PDP10 #2

	XWD T35,0	;TTY0
	XWD T35,0	;TTY1
	XWD T35,0	;TTY2
	XWD 0,0		;TTY3
REPEAT 3,<	XWD T35,0>	;TTY4-6
	XWD T35+TTYRMT,0	;TTY7 - REMOTE 35
	XWD DSDTLN,0	;TTY10
	XWD DSDTLN+HLFDPX,0	;TTY11
	XWD DSDTLN,0	;TTY12
REPEAT 4,<	XWD T35,0>	;TTY13-16
	XWD TTYRMT,0	;TTY17 - REMOTE
REPEAT 8,<XWD TTYRMT,0>
>
IFE APRSN-^D40,<
;THIS CONFIGURATION FOR DEC SYSTEM NUMBER 40

REPEAT ^D8,<0		;MODEL 33'S LOCALLY>

REPEAT ^D8,<	XWD DSDTLN,0	;DATASET>
>

; CTY AND PTY SET BY SCNSRF
>		;END PRE-EDITED LINE CHARACTERISTICS
IFE EDITN,<		;MONGEN DIALOG DEFINE TTY CONFIG?

DEFINE GENLIN (LIN)<
	IFNDEF DSD'LIN,<DSD'LIN=0>	;DATA SET?
	IFNDEF TAB'LIN,<TAB'LIN=0>	;HARDWARE TABS?
	IFNDEF RMT'LIN,<RMT'LIN=0>	;REMOTE?
	IFNDEF HLF'LIN,<HLF'LIN=0>	;HALF DUPLEX SCANNER?
	XWD DSD'LIN*DSDTLN+TAB'LIN*T35+RMT'LIN*TTYRMT+HLF'LIN*HLFDPX,0
>

REPEAT HGHLIN+1,<LINE=.-LINTAB		;DEFINE LINE NUMBER
	GENLIN \LINE>


>
	LOC LINTAB+TTPLEN	;MAKE SURE ENOUGH SPACE FOR CTY+PTY'S


>		;END OF FULL DUPLEX CONDITIONAL

	INTERN FSNCHN,SCNON,SCNOFF

	FSNCHN==SCNCHN*101	;CHANNEL ASSIGN. FOR FULL DUPLEX SCN.
	SCNBIT==1
	REPEAT 7-SCNCHN,<SCNBIT==SCNBIT*2>
	SCNON==2000+SCNBIT	;CONO PI, TURNS SCANNER PI CHANNEL ON
	SCNOFF==1000+SCNBIT	;CONO PI, TURNS SCANNER PI CHANNEL OFF
	IFG TABSN,<TTMODL=-1>	;HARDWARD TABS
	IFE TABSN,<TTMODL=0>
XP SCNNUM,HGHLIN+1		;NO. OF SCANNER LINES (USED BY ONCE FOR PRINTING CONFIG)

IFG ECMN,<
DEFINE GENETYTAB (ECMN)<
	REPEAT ECMN,<XWD 20000,0>>
ETYTAB:	GENETYTAB (ECMN)

	EXTERN ECMSER

	INTERNAL ECONLN,ETYTAB,ECMN

ECONLN=TCONLN-ECMN>
;MAGTAPE ENTRY POINT AND BIT DEFINITIONS

	IFG MTAN,<EXTERN MTASRX>	;TM10 ENTRY POINT
	IFG MTCN,<EXTERN MTCSR6>	;PDP-6 MAGTAPES ENTRY POINT

	IFG MTAN,<
	INTERN MTALOC,MTLOC1,MTBOTH,MTFLAG,MMTSIZ
		MMTSIZ==-MTSIZ
		MTALOC==40+2*MTDCHN		;BLKI/BLKO LOCATION
		MTLOC1==MTALOC+1		;NEXT LOCATION
		MTBOTH==MTACHN*10+MTDCHN	;BOTH PI CHANNELS
		MTFLAG==400+MTACHN*10
>
	IFG MTCN,<
	INTERN DCLOC,DCLOC1,DCON,DCOFF,DCIN,DCOUT
		DCLOC==40+2*DCTCHN	;EVEN DC PI CHANNEL LOC
		DCLOC1==DCLOC+1		;NEXT LOCATION
		DCBIT==1
		REPEAT 7-DCTCHN,<DCBIT==DCBIT*2>
		DCON==2000+DCBIT		;TURN DC PI CHANNEL ON
		DCOFF==1000+DCBIT		;TURN DC PI CHANNEL OFF
		DCIN==4010+DCTCHN		;SET DC FOR INPUT
		DCOUT==3410+DCTCHN	;SET DC FOR OUTPUT
>
;DECTAPE ENTRY POINT ADN BIT DEFINITIONS

	SAVN==1				;WE ONLY SUPPORT NEW FORMAT NOW
					;MONGEN NO LONGER ASKS QUESTION.

	IFG DTAN,<EXTERN DTASRN>	;TD10 WITH NEW FORMAT
	IFG DTCN,<
	IFG SAVN,<EXTERN DTCSRN>	;556 WITH NEW FORMAT
	IFE SAVN,<EXTERN DTCSRO>	;556 WITH OLD FORMAT
>
	IFG DTAN,<	;DEFINE SYMBOLS IF PDP-10 DECTAPES(TD10)
	INTERN DTALOC,DTALC2,DTBOTH,DTTURN
		DTALOC==40+2*DTDCHN	;BLKI/BLKO LOCATION
		DTALC2==DTALOC+1		;NEXT LOCATION
		DTBOTH==DTDCHN*10+DTACHN
		DTTURN==300200+DTBOTH
>
	IFG DTCN,<	;DEFINE SYMBOLS IF PDP-6 DECTAPES(556)
	INTERN DCLOC,DCLOC1,DCON,DCOFF,DCIN,DCOUT
		DCLOC==40+2*DCTCHN	;EVEN DC PI CHANNEL LOC
		DCLOC1==DCLOC+1		;NEXT LOCATION
		DCBIT==1
		REPEAT 7-DCTCHN,<DCBIT==DCBIT*2>
		DCON==2000+DCBIT		;TURN DC PI CHANNEL ON
		DCOFF==1000+DCBIT		;TURN DC PI CHANNEL OFF
		DCIN==4010+DCTCHN		;SET DC FOR INPUT
		DCOUT==3410+DCTCHN	;SET DC FOR OUTPUT
>
;DEFINE SAVE MODE AND EXTENSION FOR OLD OR NEW FORMAT

	INTERN SAVDMP
	IFE SAVN,<
		SAVDMP==<SIXBIT /   DMP/>	;EXTENSION FOR SAVED FILES == "DMP"
>
	IFN SAVN,<
		SAVDMP==<SIXBIT /   SAV/>	;EXTENSION FOR SAVED FILES == "SAV"
>
;DISPLAY AND LITE PEN

	IFG DISN,<
	IFG T340N,<EXTERN DIS340>	;TYPE 340 ENTRY POINT
	IFE T340N,<EXTERN DIST30>	;TYPE 30 ENTRY POINT
	INTERN DISBLK,DISJSR,ONDIS,NONDIS,OFFDIS,DISPON,DISPOF
		DISBLK==40+2*DISCHN	;BLKI/BLKO LOCATION
		DISJSR==DISBLK+1
		ONDIS==100+10*PENCHN+DISCHN
		NONDIS==10*PENCHN+DISCHN
		OFFDIS==0
		DISBIT==1
		REPEAT 7-DISCHN,<DISBIT==DISBIT*2>
		DISPON==2000+DISBIT	;CONO PI, TURNS DIS PI CHANNEL ON
		DISPOF==1000+DISBIT	;CONO PI, TURNS DIS PI CHANNEL OFF
>


;LINE PRINTER ENTRY POINT AND DDB DEFINITIONS

	IFG LPTN, <

;PROTOTYPE DEFINITION FOR LINE PRINTER DEVICE DATA BLOCKS

DEFINE	LPTDDB (N) <

	XLIST				;TURN OFF LISTING DURING EXPANSION

LP'N'SV1=LP'N'SAC+DEVDAT		;DEFINE DEVDAT SAVE LOCATION

LP'N'INT: CONSO LP'N,0			;(-4) SKIP IF INTERRUPT FOR THIS LPT
	  JRST .-1			;(-3)  GO TO NEXT SKIP CHAIN ELEMENT
	  MOVEM DEVDAT,LP'N'SV1		;(-2) SAVE DEVDAT IN CHANNEL SAVE AREA
	  JSP DEVDAT,LPTINT		;(-1) SET UP DDB ADDRESS AND BRANCH

LP'N'DDB:
LP'N'NAM: 
	 IFE LPTN-1, < SIXBIT /LPT/	;( 0) PHYSICAL DEVICE NAME >
	 IFN LPTN-1, < SIXBIT /LPT'N/	;( 0) PHYSICAL DEVICE NAME >
	  XWD ^D60*HUNGST,<N>B23+LPTSIZ ;( 1) DEVICE CHARACTERISTICS
	  0				;( 2) DEVICE I/O STATUS
	  XWD 0,LPTDSP			;( 3) LH=DDB LINK, RH=DSP TABLE ADDR.
LPTMOD==1_A+1_AL+1_I			;LPT LEGAL MODES
	  XWD DVOUT+DVLPT,LPTMOD	;( 4) DEVICE CHARACTERISTICS
	  0 				;( 5) LOGICAL DEVICE NAME
	  0				;( 6) BUFFER HEADER ADDRESSES
LP'N'PTR: 0				;( 7) BLOCK OUTPUT POINTER
	  XWD PROG,0			;(10) CURRENT OUTPUT BUFFER ADDRESS
	  EXP 11*LP'N'CHN		;(11) INTERRUPT CHANNEL ASSIGNMENTS

	  MOVE DEVDAT,LP'N'SV1		;(12) RESTORE DEVDAT, SAVE AC'S
	  JSR LP'N'SAV			;(13)  AND ESTABLISH PDP
	  MOVEI DEVDAT,LP'N'NAM		;(14) SET UP DDB ADDRESS AND RETURN
	  JRST LPTNXT			;(15)  TO COMMON INTERRUPT HANDLER

	  MOVE DEVDAT,LP'N'SV1		;(16) RESTORE DEVDAT AND
	  JEN @LP'N'CHL			;(17)  DISMISS INTERRUPT

	  0				;(20) SAVE LOCATION FOR TAC

	  CONSZ LP'N,LPTECM		;(21) THE REST OF THE DDB CONTAINS
	  CONSO LP'N,LPTDON		;(22)  THE ACTUAL I/O INSTRUCTIONS
					;      USED BY THE COMMON SERVICE
	  CONSO LP'N,(TAC)		;(23)  ROUTINE TO CONTROL A LINE
	  CONSZ LP'N,(TAC)		;(24)  PRINTER. THEY ARE EXECUTED
	  CONI  LP'N,TAC		;(25)  BY MEANS OF AN XCT INSTRUCTION
	  CONO  LP'N,(TAC)		;(26)  INDEXED TO THE PROPER DDB
	  DATAO LP'N,(TAC)		;(27)
	  BLKO  LP'N,LP'N'PTR		;(30)

	LIST				;TURN LISTING BACK ON DURING EXPANSION

>

		EXTERN LPTSER, LPTNXT, LPTECM, LPTDON, LPTINT, LPTDSP

		LPT2=524		;DEVICE SELECT CODE FOR SECOND LPT

		IFNDEF LP0, <LP0=LPT>	;DEFINE STANDARD MNEMONIC DEFINITIONS
		IFNDEF LP1, <LP1=LPT2>	; BUT ALLOW FOR OVERRIDE

		$LPNUM=0		;TEMPORARY SYMBOL USED TO FACILITATE
					; MACRO GENERATION


		REPEAT LPTN, <

			LPTDDB (\$LPNUM)
			$LPNUM=$LPNUM+1
		>


	>


;CARD READER ENTRY POINT AND BITS

	IFG CDRN,<
	IFG CR10N,<EXTERN CDRSRX>	;CR10 ENTRY POINT
	IFE CR10N,<EXTERN CDRSR6>	;PDP-6 CARD READER
	INTERN CDRBTS
		CDRBTS==1670+CDRCHN
	>


;CARD PUNCH ENTRY POINT

	IFG CDPN, <
		EXTERN CDPSER		;ENTRY POINT
	>
;PLOTTER ENTRY POINT

	IFG PLTN,<EXTERN PLTSER>


;PAPER TAPE READER ENTRY POINT AND MASK

	IFG PTRN,<EXTERN PTRSER	;SAME ROUTINE FOR PDP-6 AND PDP-10 READER
	INTERN PTRMSK
		IFG PDP10N,<PTRMSK==0>	;MASK==0 IF PDP-10 READER
		IFE PDP10N,<PTRMSK==777777>	;MASK==777777 FOR PDP-6 READER
>


;PAPER TAPE PUNCH ENTRY POINT

	IFG PTPN,<EXTERN PTPSER>


;DISK ENTRY POINTS AND BITS

	IFG DSKN,<
	INTERN DSKBIT,DCBBIT,DSKON,DSKOFF
		DCBBIT==0	;0 UNLESS DATA PRODUCTS DISK(SEE BELOW)
		DSKBIT==1	;LOW PRIORITY DISK PI CHANNEL
		REPEAT 7-DSKCHN,<DSKBIT==DSKBIT*2>
		DSKON==2000+DSKBIT	;CONO PI, TURN DISK CHANNEL ON
		DSKOFF==1000+DSKBIT	;CONO PI, TURN DISKCHANNEL OFF
	IFG RD10N,<	;BURROUGHS DISK
		EXTERN RCXINT,DSKSRB,RCXWNZ	;LOAD EARLIER VERSIONS OF
					; DSKINT,DSKSRB,ONCEB
		IFG SYS50N,<EXTERN RCXSKD>	;LOAD EARLIER VERSION OF SCHEDB
	>
	IFG DPDN,<	;IF DATA PRODUCTS DISK
		EXTERNAL LDDINT		;LOAD DPDINT
		EXTERNAL DSKSRD		;LOAD ONCE+DSKSR FOR DATA PROD DISK
		INTERN DCBBIT,DSKX8,DSKX9
			DCBBIT==1
			REPEAT 7-DCBCHN,<DCBBIT==DCBBIT*2>
			DSKX8==40+2*DCBCHN	;DATA-CONTROL BLKI/BLKO LOCS
			DSKX9==DSKX8+1
	>
	IFG RA10N,<	;IF BRYANT DISK
		EXTERN MDFINT,DSKSER,MDFWNZ
	IFG SYS50N,<EXTERN RCXSKD>
	>
>


;PSEUDO TTY ENTRY POINT

	IFE PTYN,<INTERN PTYPE,PTMNMZ,PTYOW,PTMNMD
PTYPE:PTMNMZ:PTYOW:PTMNMD:	HALT CPOPJ	;HALT IF SCNSER CALL PTY ROUTINES
						; BECAUSE NONE LOADED
>
	IFG PTYN,<
	IFE FULLN,<EXTERN PTYSRH>	;HALF DUPLEX SCANNER SOFTWARE
	IFG FULLN,<EXTERN PTYSRF>	;FULL DUPLEX SCANNER SOFTWARE
>
	LIT
	RELOC .-COMORG		;NOW MAKE RELOCATABLE SO NEXT PROGRAM WILL BE LOADED
				; IMMMEDIATELY AFTER THIS ONE

COMEND:	END