Google
 

Trailing-Edge - PDP-10 Archives - AP-D543V_SB - sysini.mac
There are 13 other files named sysini.mac in the archive. Click here to see a list.
TITLE	SYSINI - SYSTEM INITIALIZATION AND RESTART - V5664
SUBTTL	TH/RCC/TL/AF/PH/DAL/BGE/RLD	12 SEP 78
	SEARCH	F,S
	$RELOC
	$LOW



;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1969,1970,1971,1972,1973,1974,1975,1976,1977,1978 BY DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
XP VSYSII,5664
		;PUT VERSION NUMBER IN GLOB LISTING AND LOADER STORAGE MAP
EXTERNAL NXM
EXTERNAL NULJB1,ONCE,SYSBEG,SYSBG1,SYSEND
EXTERNAL CORTAB,COREP,CORLST,CORTAL,CORBLK,SYSSIZ,LINKSR
	CLK==70		;MACRO 47 DOESNT KNOW ABOUT CLK.
EXTERNAL SYSTOP,SYSDSP,DSKDSP,SCNDSP

;NOTE THAT SYSINI MAY INCLUDE INITIALIZATION ROUTINES WHICH SHOULD NOT
;BE CALLED. THIS HAPPENS IF THE FEATURE TEST SWITCH FOR A FEATURE IS ON,
;BUT THE MODULE IS NOT LOADED BECAUSE OF THE ANSWER TO A MONGEN QUESTION.
;TO SOLVE THIS PROBLEM, COMMON DEFINES SYMBOLS =0 IF THE ROUTINE IS
;NOT TO BE CALLED, = NON-0 IF IT IS TO BE CALLED.


;SYSINI HAS BEEN MADE SELF RELOCATING SO THAT IT CAN BE MOVED
;IN CASE IT IS TO BE OVERLAYED AFTER SYSTEM STARTUP.  IF IT IS,
;IT MIGHT BE CLOBBERED BEFORE INITIALIZATION WAS COMPLETE, HENCE
;IT WOULD HAVE TO BE MOVED.
;ACCUMULATOR P2 CONTAINS THE RELOCATION.
;INITIALIZE SYSTEM DATA STORAGE

INTERNAL FTDISK,SYSINI,FTSWAP,JSR2,ENDSYS

ENTRY SYSINI
SYSINI:	CONO	APR,200000	;IO RESET
IFN FTKL10,<
	MOVEI	P,ONCPDL##	;SET UP A PDL FOR THIS
	MOVEI	T1,0		;FOR CPU 0
	PUSHJ	P,DTEINI##	;INITIALIZE DTE'S EARLY
	PUSHJ	P,ENTSPC##	;START SECONDARY PROTOCOL ON MASTER DTE
>
IFN FTMETR,<
	JSR	METINI##	;TURN OFF METER POINTS
>
	SETZ	P2,		;CLEAR RELOCATION REGISTER FOR SUBROUTINE
IFN FTMS,<	EXTERNAL SPRINI
	SKPCPU	(0)
	JRST	SPRINI		;SLAVE! GO START IT GOING
	JSP	T1,TWOCHK##	;GO CHECK IF OTHER CPU ALSO IN SYSINI
				; DO NOT USE A PD LIST HERE SINCE BOTH CPUS CAN GET HERE
>
				; IF OFFSET SWITCH SET THE SAME
JSR1:	JSR	ONCE		;DO ONCE ONLY CODE ONCE
JSR2:	JSR	LINKSR		;DO MANDATORY ONCE ONLY CODE ONCE FOR SURE
				;LINK IO SERVICE ROUTINES AND OVERLAY ONCE
				; ONLY CODE WITH DEVICE DATA BLOCKS
;*** SYSINI MAY BE MOVED TO HIGH CORE
;BY LINKSR BECAUSE SYSINI COULD GET
;CLOBBERED BY BEING OVERLAYED BEFORE
;IT IS FINISHED.  THEREFORE THE CODE
;IS SELF RELOCATING, USING P2 AS A
;RELOCATION REGISTER.  NOTE THAT LOCATION
;SYSINA WILL CONTAIN THE CURRENT ADDRESS
;OF SYSINI (SET A FEW INSTRUCTIONS DOWN
;THIS PAGE AND IS OCCASSIONALLY USED TO
;COMPUTE THE RELOCATION CONTENTS (RH(SYSINA))-SYSINI
;CALLS TO SUBROUTINES IN SYSINI BEFORE THIS
;POINT SHOULD SET P2=0 FIRST.  THIS WORKS
;BECAUSE SYSINI WILL NOT YET HAVE BEEN MOVED.
	MOVSI	P2+1,(JRST (P2)) ;RETURN INSTRUCTION FOR JSR
	JSR	P2		;FIND OUT WHERE WE ARE
	SUBI	P2,.		;OFFSET FOR RELOCATED LOADING INTO ORIGINAL SPOT
IFN FTVM,<
	HRLZ	T1,[MSWPMX##](P2)  ;CAN'T HAVE SWAP SPACE
	MOVNI	T2,4		; START AT BLOCK0,
	SKIPE	T3,SWPTAB##(T1)	; SO DECREMENT UNISLB
	ADDM	T2,UNISLB##(T3)	; AND START AT LOGICAL
	AOBJN	T1,.-2(P2)	; SWAP BLOCK1
>
IFN FTDISK,<
	MOVEI	T1,DSKINI(P2)	;NEW LOCATION OF DSKINI
	HRRM	T1,DSKDSP+DINI	;STORE IN DISPATCH TABLE
>
	MOVEI	T1,JSR2(P2)	;NEW LOCATION OF JSR2
	HRRM	T1,SYSIN2##	;STORE IN SYSTEM DISPATCH TABLE
	MOVEI	T1,SYSINI(P2)	;NEW LOCATION OF SYSINI
	HRRM	T1,SYSINA##	;SYSINI MOVED, CAN'T DO 403 RESTART
	MOVS	T1,.+1(P2)
	SETZM	JOB		;CLEAR CURRENT JOB
	SETZB	P1,SYSBEG	;CLEAR P1 FOR NEXT PAGE
	MOVSM	T1,JSR1(P2)	;CLEAR SYSTEM DATA STORAGE
	MOVSM	T1,JSR2(P2)
	MOVE	T1,[XWD SYSBEG,SYSBG1](P2) ;CLEAR SYSTEM DATA STORAGE
	BLT	T1,SYSEND
	MOVE	T1,[XWD NULPDL##,NULPDL##+1](P2) ;CLEAR SYSTEM PDL'S, ETC., ABOVE
	SETZM	NULPDL##	; TRAP LOCATIONS
	BLT	T1,137		; AND UP TO BASE OF COMMON
IFN FTMS,<	EXTERNAL .C0SCD,.C0OK,CP1INC
	SKIPE	[CP1INC](P2)	;DOES THIS SYSTEM HAVE A DUAL PROCESSOR?
	JSP	T1,CP1INI(P2)	;YES, INITIALIZE MASTER VARIABLE AREA AND
				;SLAVE DEPENDENT VARIABLES
	SETOM	.C0SCD		;INITIALIZE MASTER SCHEDULER INTERLOCK
>
	MOVSI	T1, DVDIRIN+TTYATC+TTYUSE
	HRRI	T1,ASSCON+ASSPRG
	HLRZ	F,DEVLST	;SCAN ALL DEVICES
SYS1:	ANDCAM	T1, DEVMOD(F)	;CLEAR DIRECTORY IN CORE BIT,
				;ASSIGNED BY CONSOLE & PROGRAM
	SETZB	U,DEVLOG(F)	;CLEAR LOGICAL NAME AND U
				; FOR NXM LOOP BELOW(SYS2-SYS3)

	HLRZ	F, DEVSER(F)
	JUMPN	F, SYS1(P2)
	SUBTTL	SORT DDB CHAIN AND SET UP GENERIC DEVICE TABLE

;WE MUST NOW SORT ALL DDB'S SO THAT ALL DDB'S
; OF A GIVEN DEVICE CLASS (DTA, LPT, CDR, ...) ARE CONTIGUOUS
; ON THE CHAIN. THAN, WE SET UP THE GENERIC DEVICE TABLE TO POINT
; TO THE 1ST DDB IN EACH SUCH DEVICE CLASS. THIS WILL SPEED UP THE
; GENERIC SEARCH

	HLRZ	F,DEVLST##		;GET START OF CHAIN
GNSRC0:	MOVEI	T1,GENTAB##	;GET START OF GENERIC DEVICE TABLE
GNSRC1:	HLRZ	T2,(T1)		;GET DEVICE NAME FROM TABLE
	HLRZ	T3,DEVNAM(F)	; AND NAME FROM DDB
	CAME	T2,T3		;FOUND DEVICE IN TABLE?
	JRST	GNSRC2(P2)	;NO, CONTINUE THE SEARCH
	HRRZ	T2,(T1)		;YES, GET THE POINTER IN THE RH
	JUMPN	T2,GNSC2A(P2)	;IF ALREADY SET UP, EXIT
	HRRM	F,(T1)		;NO, PUT DDB ADDRESS IN TABLE
	JRST	GNSC2A(P2)	;LEAVE THIS SEARCH ROUTINE
GNSRC2:
	CAIE	T1,GTEND##-1	;THRU?
	AOJA	T1,GNSRC1(P2)	;NO, KEEP GOING
	JRST	GNSRC5(P2)	;NOT FOUND IN GENTAB - TRY NEXT DDB


;FROM HERE ON, WE MUST SORT ALL DDB'S ACCORDING TO DEVICE TYPES
;AC USAGE:
;	F = CURRENT DDB
;	T1 = PTR TO "LAST" DDB IN DEVICE GROUP
;	T2 = MOVING PTR WITHIN DEVICE GROUP

GNSC2A:	MOVE	T2,F		;INIT MOVING PTR
GNSRC3:	MOVE	T1,T2		;INIT "LAST" DDB IN DEVICE GROUP
	HLRZ	T2,DEVSER(T2)	;GET NEXT DDB
	JUMPE	T2,GNSRC6(P2)	;END OF CHAIN, WE'RE THRU
	HLRZ	T3,DEVNAM(F)	;GET DEVICE NAME OF CURRENT DDB
	HLRZ	T4,DEVNAM(T2)	; AND OF THIS DDB
	CAMN	T3,T4		;SAME DEVICE?
	JRST	GNSRC3(P2)	;YES, GO UNTIL WE GET OUT OF DEVICE GOURP
GNSRC4:	MOVE	P3,T2		;SAVE THIS ADDRESS
	HLRZ	T2,DEVSER(T2)	;NOW, WE START SEARCH TO FIND ANOTHER
	JUMPE	T2,GNSRC6(P2)	;..DEVICE IN THIS GROUP
	HLRZ	T3,DEVNAM(F)	;FETCH NAME AGAIN
	HLRZ	T4,DEVNAM(T2)	;AND NEW NAME
	CAME	T3,T4		;IS THIS DDB OUT OF ORDER?
	JRST	GNSRC4(P2)	;NO

;WE HAVE NOW FOUND A DDB WHICH IS NOT CONTIGUOUS WITH OTHER DDB'S
; OF ITS DEVICE GROUP. WE MUST RE-LINK THEM SO THAT IT BECOMES
; CONTIGUOUS.
	HLRZ	T3,DEVSER(T2)	;GET NEXT DDB PTR
	HRLM	T3,DEVSER(P3)	;REMOVE THIS DDB FROM CHAIN
	HLRZ	T3,DEVSER(T1)	;GET NEXT PTR FROM "LAST" DDB IN GROUP
	HRLM	T3,DEVSER(T2)	;MAKE US POINT TO NEXT DDB
	HRLM	T2,DEVSER(T1)	;MAKE LAST DDB POINT TO US
	MOVE	T1,T2		;CONTINUE SEARCH 
	JRST	GNSRC4(P2)
GNSRC5:	MOVE	T1,F		;NOT IN GENTAB, TRY NEXT DDB
GNSRC6:	HLRZ	F,DEVSER(T1)	;GO TO NEXT DDB AFTER THIS GROUP
	JUMPN	F,GNSRC0(P2)	;CONTINUE SEARCH IF MORE

;AT THIS POINT, ALL DDB'S SHOULD BE SORTED, SO FALL THRU TO NEXT PAGE.........
IFN FTNET,<

	EXTERNAL LOCSTA,JBTLOC

	MOVEI	T1,LOCSTA	;GET CENTRAL SITE STATION NUMBER
	MOVEM	T1,JBTLOC	;AND SAVE IN JOB LOCATION TBL

>
;SETUP CORE USE BIT TABLE(CORTAB)
;1 BIT FOR EACH 1K OF POSSIBLE MEMORY
; BIT=0 IF AVAILABLE TO USERS
; BIT=1 IF USED BY MONITOR,USER PROGRAM, OR NON-EXISTENT
; EXISTENT MEMORY MUST BE CONTIGUOUS(OR ELSE CORE SHUFFLER WON'T WORK)
; IF NOT CONTIGUOUS, BANKS ABOVE FIRST NON-EXISTENT ONE ARE IGNORED

	INTERN	SYSLIM
	EXTERN	USRLIM,CORMAX,MEMSIZ,CTNMCI,CORE2P,MAXMAX,CORLIM
	EXTERN PAGSIZ

SYSLIM:	MOVEI	T1,CORBLK	;NO. OF BIT BYTES IN CORTAB
IFN FTKI10!FTKL10,<IFN FT22BIT,<
	SKIPN	FLG256##
	MOVEI	T1,COR256##
>>
	MOVE	R,COREP		;1 BIT BYTE POINTER TO FIRST K-1
	MOVEI	F,PAGSIZ	;CORE SIZE INCREMENT TO UPDATE CORMAX
	MOVE	P3,[POINT 1,NXMTAB##](P2)
SYS2:	IBP	R		;MOVE BYTE POINTER UP BY 1K
	ILDB	T4,P3
	CAML	U,SYSSIZ	;STILL IN MONITOR(FIRST LOC NOT USED BY MON)?
	SKIPE	T4		;NO, SEEN ANY NON-EX 1K YET?
	JRST	SYS3(P2)	;YES, GO STORE 1 BIT IN CORTAB INDICATING
				; 1K NOT AVAILABLE
	MOVEM	R,CORLST	;NO, SET LAST AVAILABLE BLOCK EVEN HIGHER
	MOVEM	U,MEMSIZ	;SET SIZE OF PHYSICAL MEMORY EVEN HIGHER
	HRRZ	T3,CORLIM##	;MAXIMUM CORE AVAILABLE TO A SINGLE USER.  DEFINED
				; BY MONGEN, MODIFIED BY ONCE
	CAMGE	P1,T3		;REACHED MAX YET FOR SINGLE USER?
	ADDM	F,CORMAX	;NO, INCREASE MAX SIZE CORE AVAIL. TO A USER
	ADDM	F,MAXMAX	;INCREMENT HIGHEST LEGAL CORMAX
	AOS	P1,CORTAL	;INCREMENT NO. OF FREE 1K BLOCKS
	JRST	SYS4(P2)	; AND LEAVE 0 BIT IN CORTAB TO FLAG IT AS FREE
SYS3:	MOVEI	T2,CTNMCI##	;ASSUME MONITOR CORE
	SKIPE	T4		;MONITOR OR NXM?
	MOVEI	T2,CTNXMI##	;NXM
	DPB	T2,R		;YES, FLAG THIS 1K AS NOT AVAILABLE(1 BIT IN CORATB)
SYS4:	ADDI	U,PAGSIZ	;INCREMENT MEMORY REF
	CAMN	U,SYSSIZ	;AT SYSSIZ?
	MOVEM	R,CORE2P	;YES, SAVE BYTE POINTER TO CORTAB
	SOJG	T1,SYS2(P2)	;FINISHED CORTAB YET?
	IBP	CORLST		;SET TO FIRST UNAVAILABLE BLOCK
	ADDM	F,MEMSIZ	;SET SIZE OF PHYSICAL MEMORY SO EQUAL
				; TO THE FIRST NON-EX MEM ADR
	DPB	T2,CORLST	;IN CASE CORBLK DEFORMED.6.LT.256
	MOVEI	P,SYSPDL##	;SETUP PUSH DOWN LIST
IFN FTLOCK, <
	MOVE	P1,MEMSIZ##	;SIZE OF MEMORY =
	MOVEM	P1,HOLTOP##	; TOP OF LARGEST UNLOCKED HOLE
>

IFN FTDISK,<
				;RECLAIM MONITOR CORE (SIZE OF MONITOR INCREASED
	PUSHJ	P,ACCINI(P2)	;AT ONCE ONLY TIME) USED BY DISK DEVICE DATA BLOCKS
				; (IF THIS IS RESTART)
>
IFE FTPDBS,< ;IF PDB'S STAY IN CORE THE WE NEED TO BUILD ONE FOR THE NULL JOB
	SETZ	J,		;CLEAR J TO SET UP A PDB FOR THE NULL JOB
	PUSHJ	P,CREPDB##	;ALLOCATE A PDB
	  HALT	.		;NO SPACE!
IFN FTTRACK,<
	PUSHJ	P,SETPDB##	;INITIALIZE THE PDB
>>
IFN FTSWAP, <
	PUSHJ	P,SWPINI(P2)	;INIT SWAPPING SPACE ALLOCATION
>

	INTERN	FTTMP
IFN FTTMP,<
	EXTERN	TMPINC
	SKIPE	[TMPINC](P2)	;SKIP IF TMPCOR INITIALIZATION NOT TO BE CALLED
	PUSHJ	P,TMPINI(P2)	;FLUSH ALL TEMPORARY (CCL) IN CORE FILES
	>
IFN FTSPL,<
	MOVE	T1,TIME##	;INITIALIZE SPOOL NAME GENERATOR TO RANDOM START
	IDIVI	T1,^D3600	;START WITH MINUTES SINCE MIDNIGHT
	ADD	T1,THSDAT##	;PLUS DATE
	MOVEM	T1,SPLGEN##	;SAVE FOR FILSER
>

IFN FTEQDQ,<
	SKIPN	[HSHTAB](P2)	;SKIP IF INITIALISATION IS TO BE DONE
	JRST	IOGOA(P2)
	MOVNI	T1,HSHLEN##	;GET LENGTH OF HASH TABLE
	JUMPE	T1,ENQX(P2)	;DONE IF NO ENQ/DEQ
	HRLS	T1		;PUT IN LEFT HALF
	HRRI	T1,HSHTAB##	;SET POINTER TO HASH TABLE
ENQLUP:	HRRM	T1,(T1)		;MAKE RIGHT HALF POINT TO ITSELF
	HRLM	T1,(T1)		;AND LEFT HALF TOO
	AOBJN	T1,ENQLUP(P2)	;BUMP POINTER AND COUNTER

ENQX:

>
IOGOA:	MOVEI	T1,IOGO(P2)
	HRRM	T1,SYSDSA##	;FALL INTO IOGO

;INITIALIZE ALL IO DEVICES

	INTERNAL IOGO
	EXTERNAL DEVLST,  JBTADR,JBTSTS,JOB,.C0CDB
	EXTERNAL SYSPDL,JOBMAX,CLRJOB,AP0RST,IADPTR,CRSHWD,SYSSNP,CURJOB

	PIBITS==PI.CPI!PI.TFP!PI.OFF	;COMMON BITS TO ALL PROCESSORS
IFN FTKA10!FTKI10,<PIBITS==PIBITS!II.ACO!II.CPP!PI.CPE> ;KA,KI BITS
IFN FTKL10,<PIBITS==PIBITS!LI.ACO!LI.CPP> ;DON'T LIGHT PI.CPE - IT MAKES KL WRITE EVEN PARITY!!

IOGO:	CONO	PI,PIBITS	;CLEAR PI SYSTEM (AND MEM PARITY)
IFN FTKL10,<
	CONO	APR,LP.CSF!LP.PAR
>
				; DO NOT CLEAR POWER FAIL AS THIS DISABLES
				; POWER FAILURE INTERRUPTS
IFN FTMS,<	EXTERNAL SPRINI
	SKPCPU	(0)
	JRST	SPRINI		;SLAVE! GO START IT GOING
	JSP	T1,TWOCHK##	;GO CHECK IF OTHER CPU ALSO IN SYSINI
>
	CONO	APR,AP0RST	;APR RESET (IO RESET)
IFN FTKL10,<
	PUSHJ	P,ENTSPC	;START SECONDARY PROTOCOL UP
>;END IFN FTKL10
	MOVEI	P4,.C0CDB##	;SET UP P4
	PUSHJ	P,SETIME##	; TO INITILIZE GETIME
	MOVE	T2,DDTUSY##	;PRESERVE SYMBOL POINTERS
	MOVE	T3,DDTSYM##	; ..
IFN <FTKI10!FTKL10>&FTMS,<
	MOVE	T4,BOOTWD##	;PRESERVE BOOTWD FOR CPU0,CPU1 CHECK
>
	SETZM	20		;CLEAR 20-37
	MOVSI	T1,20		; ..
	HRRI	T1,21		; ..
	BLT	T1,37		;40 UP CLEARED BY BOOT STRAPS
	MOVEM	T2,DDTUSY	;RESTORE SYMBOL POINTERS
	MOVEM	T3,DDTSYM	; ..
IFN <FTKI10!FTKL10>&FTMS,<
	MOVEM	T4,BOOTWD##	;RESTORE BOOTWD
>
	HRRZS	.C0MPC##	;CLEAR SERIOUS PARITY ERROR FLAG WHICH
				; CAUSES HALT AFTER CTY PRINTING
	SETZM	HNGLST##	;ZERO ADDRESS OF DEVICES WHICH SHOULD BE HUNG CHECKED
	HLRZ	F, DEVLST	;CHAIN OF DEVICE DATA BLOKS
IOG0:	MOVEI	T2,ASSPRG	;CLEAR ASSIGNED BY PROGRAM BIT
	ANDCAB	T2,DEVMOD(F)
	HRLOI	J,777701	;DO NOT CLEAR HUNG DEVICE COUNT SETTING
	TRNE	T2,ASSCON	;ASSIGNED BY CONSOLE?
	TLO	J,774000	;YES, DO NOT CLEAR JOB NO.
	ANDM	J,DEVCHR(F)	;CLEAR HUNG DEVICE COUNT.
	SETZM	DEVIOS(F)	;CLEAR IO STATUS WORD
	SETZB	U, DEVBUF(F)	;CLEAR BUFFER ADDRESSES
	TLNE	T2,DVDTA	;IS THIS A DECTAPE?
	DPB	U,IADPTR	;YES, SET NO. OF USER CHANNELS INITED
				; ON THIS DEVICE TO 0
	LDB	T1,PDVTYP##	;DEVICE TYPE
	CAIE	T1,.TYTTY/.TYEST	;A TTY?
	CAIN	T1,.TYPTY/.TYEST  ;OR A PTY?
	JRST	IOG00(P2)	;YES
	SKIPN	HNGLST##	;NO, ALREADY SEEN A DEVICE?
	HRLM	F,HNGLST##	;NO, STORE ADDRESS OF FIRST DEVICE TO HUNG CHECK
IOG00:	HLRZ	F, DEVSER(F)
	JUMPN	F, IOG0(P2)
	MOVEI	P,ONCPDL##	;REUSABLE SPACE(SEE IOINI1)
	PUSHJ	P,NXTINI(P2)	;ALWAYS INITILIZE SCHEDULER FIST
				;SO DEVICES MAY RESET QUEUES IF DESIRED
	HLRZ	P3,DEVLST	;ADDR OF FIRST DDB
	SETZM	S,SAVITM
IOG01:	MOVE	F,P3		;SET UP F FOR INITIALIZATION CODE
				; (NOT ALWAYS USED)
	MOVE	P3,DEVSER(P3)
	HRRZ	T1,P3
	CAIE	T1,@SAVITM	;SAME DEVICE
	PUSHJ	P,DINI(P3)	;NO. INITIALIZE IT.
	HRRZM	P3,SAVITM	;SKIP RETURN IF INITIALIZATION CODE IS TO BE CALLED
				; FOR EACH DEVICE (I.E. MULTIPLE LINE PRINTERS)
	HLRZS	P3
	JUMPN	P3,IOG01(P2)	;INITILIZE CLOCK
	PUSHJ	P,CLKINI(P2)	;YES,INITILIZE CLOCK

	INTERN	FTRTTRP
IFN FTRTTRP,<
	EXTERN	RTINIC
	SKIPE	[RTINIC](P2)	;SKIP IF REAL TIME INITIALIZATION NOT TO BE CALLED
	PUSHJ	P,RTINI(P2)	;INITIALIZE PI CHANNELS AND RT DEVICES
	>
	INTERN	FTLOCK
IFN FTLOCK,<
	EXTERN	LOKINC
	SKIPE	[LOKINC](P2)	;SKIP IF LOCK INITIALIZATION NOT TO BE CALLED
	PUSHJ	P,LOKINI(P2)	;INITIALIZATION FOR LOCK UUO
>
IFN FTSWAP,<
	PUSHJ	P,QINI(P2)	;PUT ALL JOBS IN NULL QUEUE IF SWAPPER
>
IFN FTNSCHED,<
	MOVEI	T1,^D10		;TEN PERCENT
	MOVEM	T1,SCDJIL##	;INITIAL RESPONSE FAIRNESS FACTOR
	MOVEI	T1,^D50		;FIFTY PERCENT
	MOVEM	T1,SCDIOF##	;INITIAL INCORE FAIRNESS FACTOR
	MOVEI	T1,^D360/2	;SIX SECONDS IN TICK PAIRS
	MOVEM	T1,SCDCOR##	;INITIALIZE
	SETOM	BBSUBQ##	;NO BACKGROUND BATCH CLASS
>

	SETZM	JOB
	MOVEI	J,JOBMAX	;MAX INDEX IN JOB AND HIGH SEG TABLES
IOG2:	HRLOI	T2,JNA+JLOG+SWP	;CLEAR  ALL BUT JOB NO. ASSIGNED,
	ANDM	T2,JBTSTS(J)	;JOB LOGGED IN(SHRSEG, IF HIGH SEG)
				; AND JOB SWAPPED BITS
	SKIPE	R,JBTADR(J)	;DOES THIS JOB HAVE CORE IN MEMORY?
	PUSHJ	P,CLRJOB	;YES, CLEAR JOB DATA AREA PROTECTED
IOG3:	SOJG	J,IOG2(P2)	;FROM IO SERVICE(DEVICE ASSIGNMENT TABLE)
				;AND SET JERR BIT SO JOB CANNOT CONT
				; FINISH WITH J=0 FOR NULL JOB
IFN FTMS,<
	JSP	T1,TWOCHK##	;CHECK AGAIN FOR OTHER CPU IN SYSINI
>
	TRNN	P2,-1		;SKIP IF SYSINI WAS OVERLAYED
	JRST	IOG4(P2)	;JUMP IF SYSINI WILL BE SAVED
	MOVSI	T1,(HALT)	;NO, PATCH OUT CALLS TO SYSINI
	HRRI	T1,SYSDSA##	;MAKE ALL HALTS NOT BE CONTINUABLE
	MOVEM	T1,SYSDSA##	;IOGO
	MOVEM	T1,SYSINA	;SYSINI
	MOVEM	T1,SYSIN2	;JRS2
IFN FTDISK,<
	MOVEM	T1,DSKDSP##+DINI	;DSKINI
>
	MOVEM	T1,SCNDSP##+DINI	;TTYINI
	SKIPE	[DTADSP##](P2)
	MOVEM	T1,DTADSP##+DINI
	SKIPE	[PTYDSP##](P2)
	MOVEM	T1,PTYDSP##+DINI
IOG4:
	MOVSI	T1,(CAI)	;SETUP NO-OP IN CASE NO EDDT
IOG5::	HLLM	T1,SYSDDT##	;TURN 401 INTO A CAI UNLESS EDDT STILL AROUND
	MOVE	T1,TIME##	;GET TIME OF DAY AS UPDATED DURING TTY LOOP
	MOVEM	T1,TIMLST##	;STORE CURRENT TIME FOR UDT CALCULATION
	MOVE	T2,TICSEC##	;TICS PER SECOND
	LSH	T2,-1		;DIVIDE BY 2
	ADD	T1,T2		;AND ROUND
	IDIV	T1,TICMIN##	;MINUTES IN T1, REMAINDER IN TICS
	PUSH	P,T2		;SAVE REMAINDER
	IDIVI	T1,^D60		;HOURS IN T1, MINUTES IN T2
	MOVEM	T1,LOCHOR##	;UPDATE GETTAB HOURS
	MOVEM	T2,LOCMIN##	;AND MINUTES
	POP	P,T1		;GET BACK REMAINING TICS
	IDIV	T1,TICSEC##	;AND ROUND TO SECONDS
	MOVEM	T1,LOCSEC##	;AND STORE
	PUSHJ	P,SUDATE##	;SET UP UNIVERSAL DATE-TIME
IFN FTKL10,<
	MOVE	T1,.CPEBS##(P4) ;GET EBOX TICKS/SECOND
	IDIV	T1,TICSEC##	;AND NOW GET EBOX COUNTS/JIFFY
	IMULI	T1,.EBCPT	;MULITPLY BY EBOX COUNTS/TICK
	MOVEM	T1,.CPEBJ##(P4)	;STORE IN CDB VARIABLE

	MOVE	T1,.CPMBS##(P4)	;GET MBOX TICKS/SECOND
	IDIV	T1,TICSEC##	;GET MBOX COUNTS/JIFFY
	IMULI	T1,.MBCPT	;MULTIPLY BY MBOX COUNTS/TICK
	MOVEM	T1,.CPMBJ##(P4)	;SAVE

	PUSHJ	P,TIMINI(P2)	;START JIFFIES COMING
IFN FTEMRT,<
	PUSHJ	P,ACCMON##	;START UP ACCOUNTING METERS
	PUSHJ	P,CLREBT##	;CLEAR OUT E AND MBOX ACCOUNTING METERS
	PUSHJ	P,CLRMBT##
>;END IFN FTEMRT
>;END IFN FTKL10

IFN FTKI10!FTKL10,<
	EXTERN	KIINC
	SKIPE	[KIINC](P2)
	PUSHJ	P,KIINI(P2)
>
IFN FTKL10,<
;	EXECAC			;MAKE SURE AC BLOCKS ARE OK
	DATAO	PAG,[LG.LAB+01B11](P2) ;BUT CAN'T USE MACRO SINCE WE MUST RELOCATE
	MOVEI	T1,LG.CSL!LG.CSW
	IORM	T1,.C0EBR
	CONO	APR,LP.CSF+LP.CSD
	DATAI	CCA,0
	CONSO	APR,LP.CSD
	JRST	.-1(P2)
	CONO	APR,LP.CSF+LP.CSD
	CONO	PAG,@.C0EBR
>
	CONO	APR,AP0NUL##	;CLEAR ALL APR ERRORS (DO NOT DO RESET)
	CONO	PI,PI.EPE!PI.CPI!PI.TNP!PI.ON!II.ACO  ;TURN ON ALL PI CHANNELS (ENABLE MEM PARITY)
IFN FTKL10,<
PPCPAT::PUSHJ	P,STMPPC##	;INITIALIZE PRIMARY PROTOCOL
	  JFCL			;IGNORE POSSIBLE ERROR
>
IFN FTDAEM,<
	MOVEI	T1,.ERWHY	;MONITOR RELOAD CODE
	PUSHJ	P,DAERPT##	;TELL DAEMON MONITOR WAS RELOADED
>
	SJSP	U,NULJB1	;START THE NULL JOB (J ZERO, U NON-ZERO)

SAVITM=40

SUBTTL FILUUO INITIALIZATION
IFN FTDISK,<
;ROUTINE TO RESTORE DDB CHAIN
;CALLED BY SYSINI ON 143 RESTART ONLY

	EXTERN	DINITF,DSKDDB,SYSPPB,SYSDOR,FREPTR,SYSBG3
	EXTERN	TABSTR

ACCINI:	SETZM	DINITF		;CLEAR "IN ONCE-ONLY CODE" FLAG
	PUSHJ	P,DSKINI(P2)	;CLEAN UP ALL DISK DDBS
	MOVSI	T1,DVDSK	;SET TO TEST DEVICE DISK
	MOVEI	F,DSKDDB	;PROTOTYPE DDB (SWPDDB COMES BEFORE DSKDDB
				; AND SO IS NOT REMOVED
ACCIN2:	HLRZ	F,DEVSER(F)	;STEP TO NEXT DDB IN CHAIN
	JUMPE	F,ACCIN3(P2)	;THROUGH IF 0
	TDNE	T1,DEVMOD(F)	;IS IT A DISK?
	JRST	ACCIN2(P2)	;NO. LOOK AT NEXT
ACCIN3:	HRLM	F,DSKDDB+DEVSER	;YES. SAVE LINK TO NON-DSK IN PROTO.
	SETZM	SYSPPB		;INSURE THAT SYSPPB
	SETZM	SYSDOR		;AND SYSDOR ARE 0
	MOVE	T1,FREPTR	;FREE-CORE WORD
	TRNE	T1,-1		;HAS IT BEEN SET UP YET?
	SETZM	(T1)		;YES, ZERO THE FREE CORE TABLE
	AOBJN	T1,.-2(P2)
	MOVEI	T1,SYSBG3+1	;SET UP TO ZERO JOB TABLES
	CAILE	T1,SYSEN3
	JRST	ACCIN6(P2)
	HRLI	T1,SYSBG3	; WHICH ARE STORED IN COMMOD
	SETZM	SYSBG3
	BLT	T1,SYSEN3	;ZAP - THEY'RE ZERO

ACCIN6:
IFN FTSTR,<
;-------NOTE THAT THE FOLLOWING CODE USES P1 AS THE BASE REGISTER-----------
	MOVE	P1,P2
	MOVE	T1,STRAOB##	;INITIZE ALL STR DATA BLOCKS
ACCIN4:	MOVE	T3,TABSTR(T1)	;SETT2=STR D.B.ADDR.
	JUMPE	T3,ACCIN5(P1)	;   IF 0 THEN NO F.S. FOR THIS #
	SETZM	STRJOB##(T3)	;CLEAR STRJOB
	SETZM	STRMNT##(T3)	;SET MOUNT COUNT 0
	MOVE	P2,SYSSRC##	;IN SYSTEM SEARCH LIST?
	PUSHJ	P,SLFNA##
	  JRST	ACCIN5(P1)	;NO
	AOS	STRMNT(T3)	;YES - BUMP MOUNT COUNT
ACCIN5:	AOBJN	T1,ACCIN4(P1)	;CHECK ALL STRS
	MOVE	P2,P1
;------END OF P1=BASE REGISTER CODE---------
>
	POPJ	P,		;AND RETURN
;INITIALIZE DISK CALLED BY 140 START, RESTART, 143 RESTART
;CALLED FROM ONCE ONLY CODE, ACCINI, SYSINI(DEVICE INIT.)

	EXTERN	DEVQUE,DEVUNI,DSKDDB,DEVMBF,GVMNBF,DEVACC,ACCSTS,ACMCNT,DECRDR
	EXTERN	ATRMOV,CLRDDB,BUFLST,CHNQUE,IOSRDC,KONCHN,KONTAB,MBFNUM,MQREQ
	EXTERN	KONUPA,SYSEN3,UNIKON,UNIQUE,UNISTS,UNVDWN,UNYUST,ACMCNM,SAVE2
	INTERN	DSKINI

DSKINI:	MOVEI	F,DSKDDB	;PROTO. DDB LOC
	PUSHJ	P,SAVE2		;SAVE P2 AND P1
	HRRZ	P2,SYSINA	;SETUP RELOCATION REGISTER
	SUBI	P2,SYSINI	;ACTUAL SYSINI-LOADED SYSINI
DSKIN1:	HLRZ	F,DEVSER(F)	;STEP TO NEXT DDB
	JUMPE	F,DSKIN2(P2)	;NOT A DISK IF 0
	MOVE	T1,DEVMOD(F)	;CHARACTERISTICS WORD
	TLNN	T1,DVDSK	;DISK?
	JRST	DSKIN2(P2)	;NO
	SETZM	DEVQUE(F)	;YES. ZERO SOME DDB STUFF
	SETZM	DEVUNI(F)
	SKIPE	T1,DEVMBF(F)	;HAVE A MON BUF?
	PUSHJ	P,GVMNBF	;YES. CLEAR IT
	HRRZ	T1,DEVACC(F)	;LOC OF A.T.
	JUMPE	T1,DSKIN4(P2)	;NO A.T. IF 0
	MOVE	T2,ACCSTS(T1)	;STATUS OF FILE
	TRNN	T2,ACMCNT	;BEING READ (DEVIOS HAS BEEN ZEROED)
	JRST	DSKIN6(P2)	;NO. FILE MUST BE WRITING
	TLNE	S,IOSRDC
	PUSHJ	P,DECRDR	;YES, DECREASE NUMBER OF READERS
	  TRNN	T2,ACMCNM	;UPDATE, ONLY USER IF COUNT NOW=1

DSKIN6:	PUSHJ	P,ATRMOV	;NO MORE READERS - REMOVE A.T.
DSKIN4:	MOVE	T1,DEVMOD(F)
	TRNN	T1,ASSCON	;DDB ASIGNED BY CONSOLE?
	PUSHJ	P,CLRDDB	;NO. CLEAR IT OUT
	JRST	DSKIN1(P2)	;AND CONTINUE
DSKIN2:	HLRZ	U,SYSUNI	;LOC OF 1ST UNIT IN SYS
	SKIPN	U		;IS THERE ONE?
	STOPCD	TSTHRU(P2),DEBUG,NFU,	;++NO FIRST UNIT
DSKIN3:	MOVE	T1,UNISTS##(U)
	CAIE	T1,O2COD##
	SETZM	UNISTS(U)	;CLEAR OUT SOME STUFF
	SETZM	UNIQUE(U)
	HRRZ	J,UNIKON(U)	;GET ADR. OF KONTROLLER DATA BLOCK FOR THIS UNIT
	HRRZS	KONTAB(J)	;INDICATE KONTROLLER IS FREE
	LDB	T1,UNYUST	;GET UNIT STATUS
	SKIPN	DINITF		;DONT CHECK FOR KONTROLLER UP IF IN ONCE-ONLY CODE
	CAIN	T1,UNVDWN	;IS IT DOWN?
	JRST	DSKIN5(P2)	;YES - DON'T CHECK WHETHER KONTROLLER IS UP OR DOWN
	PUSHJ	P,@KONUPA(J)	;CHECK WHETHER KONTROLLER FOR THIS UNIT IS UP
	  STOPCD .-1(P2),HALT,KID,	;KONTROLLER IS DOWN
	SETOM	@KONCHN(J)	;SET CHAN AVAILABLE
	HRRZ	T1,KONCHN(J)	;LOC OF CHAN DATA BLOCK
	SETZM	CHNQUE(T1)	;INDICATE CHAN QUEUE IS EMPTY
DSKIN5:	HLRZ	U,UNISYS(U)	;STEP TO NEXT UNIT IN SYSTEM
	JUMPN	U,DSKIN3(P2)	;FIX IT UP
TSTHRU:	MOVN	T1,MBFNUM	;NUMBER OF MON BUFFERS
	MOVEM	T1,MQREQ	;SAVE IN MQREQ
IFN FTDUFC,<
	SETOM	MQ2WAT##	;INITIALIZE NO. OF JOBS WAITING FOR 2 MON BUFS
>
	HRRZ	T2,BUFLST	;LOC OF 1ST MON BUFFER
	HRRZS	(T2)		;SET IT AVAILABLE
	SETZM	MBFJOB##(T2)	;THE SCHEDULAR LOOKS AT THIS
	MOVE	T2,(T2)		;STEP TO NEXT
	AOJL	T1,.-3(P2)	;MAKE IT AVAILABLE IF THERE
	SKIPN	DINITF		;IN ONCE ONLY CODE?
	PUSHJ	P,WTSATS(P2)	;NO. WRITE SATS WHICH HAVE CHANGED
	SETZM	DSKDDB+DEVIOS	;ZERO THE S WORD IN PROTOTYPE DDB
	POPJ	P,		;AND RETURN

;SUBROUTINE TO WRITE ALL SATS FOR ALL UNITS IF THEY HAVE CHANGED
;THIS IS ONLY USED AT RESTART (140,143)
;THEN FIX IT UP AND RETURN)

	EXTERN	SYSSIZ,SAVT,DSKPIN,ONCWAT,DSKDDB,SYSUNI,WTUSAT,UNISYS,PWAIT1,PWAITZ
	INTERN	RSPWT1

WTSATS:	MOVEM	P,@SYSSIZ	;SINCE SYSPDL ISNT LONG ENOUGH, SAVE P
	MOVE	P,SYSSIZ	;AT LEAST THE NEXT 40 LOCS ARE USABLE AS PD LIST
	PUSHJ	P,SAVT		;SAVE ALL ACS
	CONO	PI,DSKPIN+200	;TURN ON PI
	MOVE	T1,[JRST ONCWAT](P2) ;SET UP A FAKE PWAIT1
	MOVEM	T1,PWAIT1	;TO USE DURING WRITING OF SATS
	MOVEI	F,DSKDDB	;USE THE PROTOTYPE DDB TO  WRITE FROM
	HLRZ	U,SYSUNI	;LOC OF 1ST UNIT DB
WTSAT2:	PUSHJ	P,WTUSAT	;WRITE SATS FOR UNIT WHICH HAVE CHANGED
	HLRZ	U,UNISYS(U)	;STEP TO NEXT
	JUMPN	U,WTSAT2(P2)	;GO IF THERE IS A UNIT
	MOVE	P,@SYSSIZ	;RESTORE P
RSPWT1:	MOVE	T1,PWAITZ	;RESTORE REAL PWAIT1
	MOVEM	T1,PWAIT1
	POPJ	P,


;HERE TO SEE IF AN RC-10 KONTROLLER IS UP
; AND IF SO, LEAVE PI SET UP FOR TIMESHARING.
; IF NOT, LEAVE ERRORS IN THE LIGHTS
	INTERN FHXUPA

FHXUPA:	LDB	T1,KOYPI##	;GET PI FOR THIS KONTROLLER
	TRO	T1,FHALCL##	;CLEAR ALL ERROR FLAGS
	XCT	FHXCOT##(J)	;CONO FH'N,(T1)
	XCT	FHXCI1##(J)	;CONI FH'N,T2
	TRNN	T2,1B23!1B31!1B32	;ANYTHING WRONG
	TRNN	T2,7		;ARE THE PI BITS THERE?
	POPJ	P,		;YES - ERROR RETURN
	JRST	CPOPJ1		;OK RETURN

;HERE TO SEE IF AN RP-10 KONTROLLER IS UP
	INTERN DPXUPA

DPXUPA:	PUSHJ	P,SAVE2##	;SAVE P1-P2
	HRRZ	P2,SYSINA##	;SETUP RELOCATION REGISTER FOR SYSINI
	SUBI	P2,SYSINI	;ACTUAL SYSINI - LOADED SYSINI
	LDB	T2,KOYPI##	;PI CHANNEL FOR THIS KONTROLLER
	TRO	T2,DPCLR##	;CLEAR ALL ERROR FLAGS
	XCT	DPXCO1##(J)	;DO THE CONO
	MOVE	T1,[XWD 500000,DPATTN##](P2)
	XCT	DPXDOT##(J)
	XCT	DPXCIT##(J)
	TRNE	T1,7		;CONTROLLER ON-LINE?
	TRNE	T1,175770	;YES. TEST ALL BUT DISK NRDY
	POPJ	P,
	XCT	DPXDI1##(J)	;DATAI DP'N, T2
	TLNN	T2,1		;WRITE-HEADER LOCKOUT ON?
	SETZ	T1,		;NO, SO INDICATE
	JRST	CPOPJ1

;HERE TO SEE IF AN RH-10 KONTROLLER IS UP
RPXUPA::PUSHJ	P,SAVE2##
	SETOM	RPXFLG##(J) 
	LDB	T4,KOYPI##	;PI
IFN FTKL10,<
	PUSHJ	P,RPXSTW##	;SET P1=0 IF RH10, =1 IF RH20
	SKIPE	P1		;IF AN RH20,
	TROA	T4,4410		; CLEAR THESE BITS
>
	TRO	T4,RPALCL##+40	;CLEAR ALL ERROR BITS, ATTEN ENABLE
	XCT	RPXCO4##(J)	;CONO RPX,(T4)
	XCT	RPXCI2##(J)	;CONI RPX,T2
IFE FTKL10,<
	TRNN	T2,2030		;PS FAIL, BUSY OR DONE UP?
>
IFN FTKL10,<
	HRRZ	P2,SYSINA##
	SUBI	P2,SYSINI
	ADDI	P1,(P2)
	TDNN	T2,[2030
		515020](P1)
>
	TRNN	T2,7		;NO, PI UP?
	POPJ	P,		;DOWN
	PJSP	T1,CPOPJ1	;UP, SET T1 NON-0 (WH LOCKOUT), AND RETURN
FSXUPA::LDB	T4,KOYPI##	;PI
	TRO	T4,FSALCL##	;CLEAR ALL ERROR BITS
	XCT	FSXCO4##(J)	;CONO FSX,(T4)
	XCT	FSXCI2##(J)	;CONI FSX,T2
	TRNN	T2,2030		;PS FAIL, BUSY OR DONE UP?
	TRNN	T2,7		;NO, PI UP?
	POPJ	P,		;DOWN
	PJSP	T1,CPOPJ1	;UP, SET T1 NON-0 (WH LOCKOUT), AND RETURN

>	;END CONDITIONAL ON FTDISK
SUBTTL SWPSER
IFN FTSWAP,<
;ROUTINE TO RE-INITIALIZE THE SWAPPING AVAILABILITY TABLE.  CALLED AT 
; SYSTEM INITIALIZATION TIME.

	EXTERNAL VIRTAL,TPOPJ,K4SWAP,SATCN
	EXTERN	CPOPJ,SWPUNI,SQREQ,SERA,UNIFKS,UNIPTR,UNISWP,SWPDDB,PJOBN

SWPINI:	MOVEI	T1,ASSCON	;FLAG SWAPPER DDB AS ASSIGNED BY CONSOLE
	IORM	T1,SWPDDB+DEVMOD ;SINCE IT APPEARS IN SYSTEM DDB LIST (BEFORE PROTOTYPE
				; ELSE USERS COULD INIT IT.
	MOVEI	T1,0		;MAKE SURE ASSIGNED TO JOB 0
	DPB	T1,PJOBN
	HLRZ	U,SWPUNI	;GET ADDR OF FIRST UNIT FOR SWAPPING
	JUMPE	U,CPOPJ		;EXIT IF NOT A UNIT DATA BLOCK
	SETZM	SQREQ		;CLEAR SWAPPPING LOCS
	SETZM	SERA
	SETZM	VIRTAL		;START TOTAL VIRTUAL CORE FOR SYSTEM AT 0
SWPIN1:	SETZM	UNIFKS(U)	;CLEAR FREE J FOR SWAP
	SKIPL	T1,UNIPTR(U)	;SKIP IF SWAPPING SPACE ON THIS UNIT
	JRST	SWPIN2(P2)	;NONE
	HLRE	T2,T1		;T2=-LENGTH OF SWAPPING SAT
	HRLS	T1		;T1=ADDR IN BOTH HALVES
	SUBB	T1,T2		;T1=BLT PTR
	MOVSS	T1
	BLT	T1,-1(T2)	;COPY INITIAL SWAPPING SAT
	MOVE	T1,UNIPTR(U)	;PTR TO SWAPPING SAT
IFN FTVM,<
	MOVSI	T2,400000	;MAKE LOGICAL BLOCK 0 BE UNAVAILABLE
	IORM	T2,(T1)		; SINCE SLOT=0 MEANS PAGE NOT IN USE AT ALL
>
	PUSHJ	P,SATCN		;COUNT 0 BITS=FREE K
	ADDM	T2,VIRTAL	;COUNT TOTAL IN SYSTEM
	MOVEM	T2,UNIFKS(U)	;AND GET FOR UNIT
SWPIN2:	HLRZ	U,UNISWP(U)	;NEXT UNIT IN SWAP LIST
	JUMPN	U,SWPIN1(P2)	;LOOP FOR ALL UNITS IN SWAP LIST
	MOVE	T1,VIRTAL	;GET #K VIRTUAL CORE IN SYSTEM
	MOVEM	T1,K4SWAP	;AS #K FOR SWAPPING IN SYSTEM
IFN FTVM,<
	MOVEM	T1,VMCMAX##	;SAVE AS MAX K FOR VIRTUAL JOBS
>
	POPJ	P,
>	;END CONDITIONAL ON FTSWAP
SUBTTL TMPUUO INITIALIZATION
IFN FTTMP,<
;SUBROUTINE TO INITIALIZE TMPCOR UUO'S

	EXTERN	TMPTAB,MJOBN,JBTTMP

TMPINI:	HLLZ	T2,TMPTAB+1	;LIMIT OF TEMP FILES PER USER
	MOVSI	T1,MJOBN
	MOVEM	T2,JBTTMP(T1)
	AOBJN	T1,.-1(P2)

	MOVE	T1,TMPTAB	;FREE DATA SPACE,ADDRESS OF TABLE
	MOVEM	T1,JBTTMP	;SET UP SPACE, ADDR OF NULL LIST
	HRRZ	T2,TMPTAB+1	;COUNT OF BLOCKS
TMPIN1:	ADDI	T1,TMPBL+1	;LINK ALL BLOCKS TO NULL LIST
	HRRZM	T1,-TMPBL-1(T1)
	SOJG	T2,TMPIN1(P2)

	HLLZS	-TMPBL-1(T1)	;DONT LINK LAST BLOCK
	POPJ	P,
>	;END CONDITIONAL ON FTTMP
SUBTTL SCHED1 INITIALIZATION
IFN FTSWAP,<
;INITIALIZE SCHEDULER  (CALLED FROM SYSINI BEFORE ALL OTHER
;	DEVICES ARE INITIALIZED)

	EXTERN	AVALTB,REQTAB,XJOB,AVLNUM,USRTAB

NXTINI:	MOVEI	T1,AVLNUM	;MAXIMUM NUMBER OF QUEUES
	SETZM	AVALTB(T1)	;CLEAR SHARABLE DEVICE AVAIL. FLAGS
	SETZM	USRTAB(T1)	;CLEAR SHARABLE RESOURCE OWNER
	SETOM	REQTAB(T1)	;SET SHARABLE DEVICE REQUEST COUNT
				; TO -1,  I.E. NO JOB WAITING OR
				; USING DEVICE OTHER THAN INITIALIZATION
	SOJGE	T1,.-3(P2)
	SETZM	XJOB		;CLEAR NUMBER OF JOBS NEEDING EXPANDING
	POPJ	P,

;QUEUE INITIALIZATION
;PUT ALL JOBS IN NULL QUEUE(JOB NO. NOT ASSIGNED)
;CALLED ON RESTART AT LOC. 143

EXTERNAL CPOPJ,JOBMAX,MXQUE,NULQ
EXTERNAL JBTCQ,MXQUE2,NCNULQ,JBCQP1,JBCQM1,JBCQMN

QINI:	MOVNI	T1,MXQUE2	;SET UP DOUBLE QUE HEADERS
	HRL	T1,T1		;BOTH HALVES POINT TO EMPTY SELF
	MOVEM	T1,JBTCQ(T1)
	AOBJN	T1,.-1(P2)
	MOVNI	T1,OBQ##	;MAKE JBTOLS HEADERS POINT TO THEMSELVES
	HRL	T1,T1		;BACK POINTER ALSO
	MOVEM	T1,JBTOLS##(T1)
	AOBJN	T1,.-1(P2)
	MOVNI	T1,BBQ##	;MAKE JBTJIL HEADERS POINT TO THEMSELVES
	HRL	T1,T1		;BACK POINTER ALSO
	MOVEM	T1,JBTJIL##(T1)
	AOBJN	T1,.-1(P2)
IFN FTNSCHED,<
	MOVNI	T1,M.CLSN##	;MAKE CORE/NO-CORE SUBQUEUES POINT TO SELVES
	ASH	T1,1		;DOUBLE HEADERS
	HRL	T1,T1		;BOTH HALVES
	MOVEM	T1,JBTCSQ##(T1)
	AOBJN	T1,.-1(P2)
>;END FTNSCHED
	MOVEI	J,JOBMAX	;MAX. JOB NO.
	MOVNI	T1,NCNULQ	;PUT ALL JOBS IN NO CORE QUE
	MOVSM	T1,JBCQP1	;BACK POINTER FOR JOB 1
	MOVEM	T1,JBTCQ(J)	;FOR. POINTER OF JOBMAX JOB NO.
	HRLM	J,JBCQMN	;SET NO CORE QUE HEADER TO POINT TO JOB 1
	MOVEI	T1,1		;AND JOBMAX
	HRRM	T1,JBCQMN	;FORWARD POINTER
	MOVEI	T2,NULQ		;SET UP QUE NUMBER
	SETZM	JBTCQ
QINI1:	DPB	T2,PJBST2##	;STORE INITIAL QUE NUMBER
	HRRM	J,JBCQM1(J)	;JOB I-1 POINT TO JOB I
	SOJLE	J,CPOPJ		;FINISHED?
	HRLM	J,JBCQP1(J)	;BACK POINTER JOB I+1 POINTS TO JOB I
	JRST	QINI1(P2)
>	;END CONDITIONAL ON FTSWAP
SUBTTL CLOCK1 INITIALIZATION
	EXTERN	CIPWTM,CLOCK

CLKINI:	MOVEI	T1,CIPWTM	;SETUP CLOCK QUEUE BYTE POINTER
	HRRM	T1,CLOCK	;LH NEVER CHANGES(36 BIT BYTE)
	POPJ	P,

SUBTTL KL10 60HZ INTERRUPT INITIALIZATION

;THIS ROUTINE CALLED AT THE POINT AT WHICH WE WOULD
; LIKE CLOCK TICKS TO START HAPPENING.

IFN FTKL10,<
TIMINI:
REPEAT 0,<
	MOVSI	T1,(ST%ITA)
	TDNE	T1,CNFST2##
	JRST	TIMIN1(P2)
>;END REPEAT 0
	CONI	MTR,T1
	CONO	MTR,AP0CHN##(T1)  ;SETUP METER PI ASSIGNMENT
	MOVE	T1,[JSR	TM0INT##](P2)	;GET TIMER INTERRUPT INST.
	MOVEM	T1,.EPTII##	;MOVE INTO EPT TRAP LOC
	MOVEI	T1,^D1666	;ASSUME 60HZ
	MOVE	T2,STATES##
	TLNE	T2,(ST.CYC)	;IS OUR ASSUMPTION CORRECT?
	MOVEI	T1,^D2000	;NO, 2000 IS INTERVAL
	CONO	TIM,TO.CTD!TO.CIT!TO.SIT(T1) ;START TIMER GOING
	POPJ	P,		;RETURN

REPEAT 0,<
;HERE IF 11 IS TO BE USED FOR 60HZ INTERRUPTS

TIMIN1:	MOVEI	T1,.DTCLK+1	;CLOCK CONTROL, ON
	SETZM	.C0IPI##	;INTERNAL TIMER HAS NO PI ASSIGNMENT
	JSR	SPCCMD##	;TURN ON INTERRUPTS
	POPJ	P,
>;END REPEAT 0

>;END IFN FTKL10
SUBTTL KI10 OR KL10 INITIALIZATION

IFN FTKI10!FTKL10,<
KIINI:
	MOVEI	T1,NUPMPP##	;ADDRESS OF THE NULL JOB'S UPMP
	MOVEM	T1,JBTUPM##+0	;STORE IT
	MOVE	T1,[JSR LUUOPC##](P2)
	MOVEM	T1,.EPIL##+1	;PREPARE FOR EXEC MODE LUUOS
	MOVEI	T1,PAGTAB-400000;MAKE PAGTAB ADDRESSABLE VIA THE EXEC MAP
	ROT	T1,W2PLSH##-1	;SLOT IN THE EXEC MAP (BIT 0 DETERMINES RIGHT
				; OR LEFT HALF WORD)
	TLZN	T1,400000	;IS BIT ZERO ON OR OFF?
	TDOA	T1,[POINT 18,.EPPM##](P2)
	TDO	T1,[POINT 18,.EPPM##,17](P2)
	LDB	T2,[POINT 9,SYSSIZ##,26](P2)
	TRO	T2,PM.ACC+PM.WRT!<IFN FTKL10,<PM.CSH>>;ACCESS ALLOWED PLUS WRITABLE
	MOVE	T4,MEMSIZ##	;HIGHEST ADDRESS + 1
IFN FTMONL,<
	CAMGE	T4,NWCORE##	;GREATER THAN HIGHEST ADDRESS SYSTEM WAS MONGENED FOR?
	MOVE	T4,NWCORE##	;NO, USE THAT TO SETUP PAGTAB AND MEMTAB
	MOVEM	T4,NWCORE##	;SAVE LARGER AS MAX CORE WHICH CAN BE SET ON LINE
>
	LDB	T3,[POINT 5,T4,17](P2)
	TRNE	T4,-1		;IF NOT A 256K BOUNDARY,
	ADDI	T3,1		;ANOTHER PAGE IS NEEDED
	PUSH	P,T3		;SAVE NUMBER OF PAGES REQUIRED FOR PAGTAB
	IDPB	T2,T1		;MAKE PAGTAB ADDRESSABLE THROUGH THE EXEC MAP
	ADDI	T2,1		;NEXT PAGE IN THE EXEC MAP
	SOJG	T3,.-2(P2)	;MAP THE REQUIRED NUMBER OF PAGES
IFN FTVM,<
	MOVEI	T1,MEMTAB-400000;MAKE MEMTAB ADDRESSABLE VIA THE EXEC MAP
	ROT	T1,W2PLSH##-1	;SLOT IN THE EXEC MAP
	TLZN	T1,400000	;LEFT OR RIGHT HALF WORD SLOT?
	TDOA	T1,[POINT 18,.EPPM##](P2)
	TDO	T1,[POINT 18,.EPPM##,17](P2)
	MOVE	T3,(P)		;NUMBER OF PAGES REQUIRED FOR MEMTAB
	IDPB	T2,T1		;MAKE A PAGE ADDRESSABLE VIA THE EXEC MAP
	ADDI	T2,1		;NEXT PAGE IN EXEC ADDRESS SPACE
	SOJG	T3,.-2(P2)	;MAP IT
>
	MOVE	T3,(P)		;NUMBER OF PAGES ALLOCATED FOR STORAGE
				; ALLOCATION TABLES
IFN FTVM,<
	LSH	T3,P2WLSH##+1	;CONVERT TO WORDS * 2>
IFE FTVM,<
	LSH	T3,P2WLSH##	;CONVERT TO WORDS>
	ADDM	T3,SYSSIZ##	;UPDATE THE SIZE OF THE MONITOR
IFN FTLOCK,<
	ADDM	T3,HOLEF1##	;SO CORMAX CALCULATIONS WILL COME OUT RIGHT>
	CLRPGT	(0)	;CLEAR THE AM SO NEW MAPPING IS USED
	MOVE	T1,(P)		;NUMBER OF PAGES FOR PAGTAB
	LSH	T1,P2WLSH##	;NUMBER OF WORDS
	SETZM	PAGTAB		;ZERO THE FIRST WORD OF PAGTAB
	MOVE	T2,[PAGTAB,,PAGTAB+1](P2)
	BLT	T2,PAGTAB-1(T1)	;ZERO ALL OF PAGTAB
IFN FTVM,<
	SETOM	MEMTAB		;SET MEMTAB TO - 1 WHICH DOESN'T LOOK LIKE A DSK ADDRESS
	MOVE	T2,[MEMTAB,,MEMTAB+1](P2)
	BLT	T2,MEMTAB-1(T1)	;ZAP, ITS ALL - 1
>
IFN FT2SEGMON,<
	MOVEI	T1,MONORG-400000;FIRST SLOT IN THE EXEC MAP USED FOR MAPPING THE MONITOR
	LSH	T1,W2PLSH##-1	;PAGE NUMBER
	TLZN	T1,400000	;SETUP BYTE POINTER TO THAT SLOT
	TDOA	T1,[POINT 18,.EPPM##](P2)
	TDO	T1,[POINT 18,.EPPM##,17](P2)
> ;END FT2SEGMON
	LDB	T2,[POINT 14,SYSSIZ##,26](P2)
	MOVSI	T3,MONTRB	;BIT WHICH SAYS THIS PAGE CONTAINS THE MONITOR
	HRRI	T3,1		;STARTING AT PAGE 1,
KIINI1:	MOVEM	T3,PAGTAB-1(T3)	;TURN IT ON
	CAIE	T2,IFN FT2SEGMON,<1>(T3)  ;FOR ALL PAGES UP TO SYSSIZ
	AOJA	T3,KIINI1(P2)	; ..
IFN FT2SEGMON,<
	LDB	T4,[POINT 14,SYSLEN##,26](P2)
KIINI2:	ILDB	T2,T1		;GET PHYSICAL PAGE CONTAINING THE MONITOR
WRTLOK:	SKIPL	DEBUGF##	;PATCH TO JFCL IF DEBUGGING WITH MONITOR WRITE-LOCKED
	TRZ	T2,PM.WRT	;CLEAR WRITE ENABLE
	DPB	T2,T1		;STORE IT BACK IN THE MAP
	ANDI	T2,17777	;CLEAR THE ACCESS BITS
	TLO	T2,MONTRB	;INDICATE THIS PHYSICAL PAGE CONTAINS THE MONITOR
	MOVEM	T2,PAGTAB(T3)	; IN PAGTAB
	MOVE	T3,T2		;SAVE LAST MONITOR PAGE SEEN
	SOJG	T4,KIINI2(P2)	;LOOP OVER ALL THE MONITORS PAGES
> ;END FT2SEGMON
	HLLZM	T2,PAGTAB(T2)	;INDICATE THE LAST PAGE OF THE MONITOR
	MOVE	T1,SYSSIZ##
	HRRZ	T3,DDTSYM##	;ADDRESS OF THE DDT SYMBOL TABLE
	SUB	T1,T3
	SKIPGE	DEBUGF##	;DEBUGGING?
	SKIPG	T1		;YES, DOES THE SYMBOL TABLE OVERLAP THE MONITOR?
	JRST	KIIN2A(P2)	;NO, ALL IS WELL

;HERE IF THE MONITOR AND DDTS SYMBOL TABLE OVERLAP.  SIGH, DISCARD SOME SYMBOLS
	HRLZ	T2,T1		;SET TO ADJUST SYMBOL TABLE POINTER
	ADD	T2,DDTSYM##	;NEW LENGTH IN THE LEFT HALF
	HRR	T2,SYSSIZ##	;NEW START ADDRESS IN THE RIGHT HALF
	MOVEM	T2,DDTSYM##	;STORE NEW POINTER TO THE SYMBOL TABLE
	TRNE	T1,PG.BDY##	;AN INTEGRAL NUMBER OF PAGES?
	ADDI	T1,PAGSIZ##	;NO, ROUND UP
	LSH	T1,W2PLSH##	;CONVERT TO NUMBER OF PAGES
	MOVE	T2,NXMPTR##	;AOBJN POINTER TO NXMTAB
	LSH	T3,W2PLSH##	;STARTING PAGE NUMBER
	PUSHJ	P,ZERBTS##	;MAKE DISCARDED S.T. PAGES APPEAR TO EXIST AGAIN
KIIN2A:	MOVE	U,[POINT 1,NXMTAB##](P2)
	MOVE	T1,(P)		;NUMBER OF PAGES IN PAGTAB
	LSH	T1,P2WLSH##	;NUMBER OF WORDS IN PAGTAB
	SETZB	T2,T3		;INITIALIZE
KIINI3:	ILDB	T4,U		;NEXT PAGE IN NXMTAB
	JUMPE	T4,KIINI5(P2)	;JUMP IF PAGE EXISTS
	SKIPE	PAGTAB(T3)	;IS THE PAGE FREE?
	STOPCD	.,STOP,MNM,	;++MONITOR IN NON-EXISTANT MEMORY
	JUMPE	T2,KIINI4(P2)	;JUMP IF NO PREDECESSOR
	TLO	T3,NXMBIT	;INDICATE NON-EXISTANT PAGE
	MOVEM	T3,PAGTAB(T2)	;STORE THAT IN PAGTAB
KIINI4:	MOVE	T2,T3		;PREDESSOR TO THIS PAGE
KIINI5:	CAIE	T1,1(T3)	;LOOKED AT EVERY PAGE IN PAGTAB?
	AOJA	T3,KIINI3(P2)	;NO, LOOP OVER ALL PAGES
	SKIPE	T2		;ANY NON-EXISTANT PAGES AT ALL
	HLLZM	T3,PAGTAB(T2)	;YES, INDICATE THE LAST ONE
	SETZB	T1,T2		;STARTING AT THE BEGINNING OF PAGTAB
	MOVEI	T3,0		;NO FREE PAGES SEEN YET
	LDB	T4,[POINT 14,MEMSIZ##,26](P2)
KIINI6:	SKIPE	PAGTAB(T1)	;IS THIS PAGE FREE?
	JRST	KIINI8(P2)	;NO
	SKIPN	T2		;FIRST FREE PAGE?
	MOVEM	T1,PAGPTR##	;YES, STORE ORIGIN OF THE FREE CORE LIST
	JUMPE	T2,KIINI7(P2)	;JUMP IF FIRST FREE PAGE
	TLO	T1,FREPAG	;INDICATE A FREE PAGE
	MOVEM	T1,PAGTAB(T2)	;STORE THAT IN PAGTAB
KIINI7:	MOVE	T2,T1		;SAVE PREDECESSOR
	ADDI	T3,1		;NEXT PAGE
KIINI8:	CAIE	T4,1(T1)	;LOOKED AT ALL PAGES IN PAGTAB?
	AOJA	T1,KIINI6(P2)	;NO
	HLLZM	T1,PAGTAB(T2)	;TERMINATE LINKED LIST OF FREE PAGES
	MOVEM	T3,BIGHOL##	;STORE THE NUMBER OF EXISTANT PHYSICAL PAGES
	MOVEM	T3,CORTAL##	; OF USER CORE SEEN
	LSH	T3,P2WLSH##	;CONVERT TO NUMBER OF WORDS
	MOVEM	T3,MAXMAX##	;MAX CORMAX CAN BE SET TO
	HRRZ	T1,CORLIM##	;MAXIMUM NUMBER OF PAGES ALLOWED A SINGLE
				; USER (MONGEN SPECIFIED)
	LSH	T1,P2WLSH##	;CONVERT TO NUMBER OF WORDS
	CAMGE	T1,T3		;.GE. THE NUMBER OF PAGES AVAILABLE TO USERS?
	MOVE	T3,T1		;NO, MAXIMUM AVAILABLE TO USERS
	MOVEM	T3,CORMAX##	;NOONE CAN GET LARGER THAN THIS (HOPEFULLY)
	LDB	T1,[POINT 9,SYSSIZ##,26](P2)
	MOVEI	T1,PAGTAB-1(T1)	;HIGHEST PAGE IN THE MONITOR - 1
	HRLI	T1,4400		;ILDB A 36 BIT BYTE POINTER TO PAGTAB
	MOVEM	T1,CORE2P##	;STORE THAT FOR CHKTAL
	LDB	T1,[POINT 14,MEMSIZ##,26](P2)
	MOVEI	T1,PAGTAB-1(T1)	;HIGHEST EXISTANT PAGE - 1
	HRLI	T1,4400		;LAST BYTE IN PAGTAB
	MOVEM	T1,CORLST##	;STORE THAT FOR CHKTAL
	MOVEI	T1,.C0DBL##	;ADDRESS OF CPU0'S DOORBELL
	LSH	T1,W2PLSH##	;CONVERT TO PAGE NUMBER
	TRO	T1,PM.ACC+PM.PUB;ACCESS ALLOWED AND PUBLIC (NULL JOB RUNS IN
				; PUBLIC USER MODE)
	MOVEI	T2,400000+.C0DBL##
	ROT	T2,W2PLSH##-1	;MAP SLOT IN THE NULL JOB'S MAP WHICH WILL
				; MAP THE DOORBELL FOR CPU0'S NULL JOB
	MOVEI	T3,NLUPMP##(T2)	;ADDRESS OF THE NULL JOB'S UPMP+DOORBELL OFFSET
	HRLI	T3,222200	;ASSUME LEFT HALF WORD MAPS THE DOORBELL
	SKIPGE	T2		;DOES IT
	HRLI	T3,002200	;NO, RIGHT WORD MAP THE DOORBELL
	DPB	T1,T3		;MAKE THE DOORBELL ADDRESSABLE FOR CPU0'S NULL JOB
	MOVE	T1,EVMPTR##	;AOBJN POINTER TO EVBTAB
	SETZM	(T1)		;INITIALIZE TO ALL BITS OFF
	AOBJN	T1,.-1(P2)	;SET EVERY WORD IN THE TABLE
	HRLOI	T1,-1_-<^D<256-36*<256/36>+18>>
	MOVEM	T1,EVBTAB##+^D<256/36>
	MOVE	T3,(P)		;NUMBER OF PAGES ALLOCATED TO PAGTAB
	ADDI	T3,RHWEVM	;NUMBER OF RESERVED PAGES
	MOVSI	T4,^D36		;WORD AND BIT POSITION
	HRR	T4,EVMPTR##	;SET AOBJN POINTER
	PUSHJ	P,CSETOS##	;MARK THOSE PAGES AS UNAVAILABLE AS EVM
	MOVEI	T3,MEMTAB-400000;VIRTUAL ADDRESS OF MEMTAB RELATIVE TO THE EXEC MAP
	LSH	T3,W2PLSH##	;PAGE NUMBER
	IDIVI	T3,^D36		;WORD NUMBER AND BIT POSITION
	SUBI	T4,^D36
	MOVNS	T4		;MAKE AN AOBJN POINTER
	MOVSS	T4
	HRRI	T4,EVBTAB##(T3)
	POP	P,T3		;NUMBER OF BITS TO SET
	PUSHJ	P,CSETOS##	;MAKE THOSE PAGES UNAVAILABLE FOR EVM
IFN FT2SEGMON,<
	MOVEI	T3,MONORG-400000;VIRTUAL ADDRESS OF THE MONITOR RELATIVE TO THE EXEC MAP
	LSH	T3,W2PLSH##	;PAGE NUMBER
	IDIVI	T3,^D36		;WORD NUMBER AND BIT POSITION
	SUBI	T4,^D36
	MOVNS	T4		;MAKE AN AOBJN POINTER
	MOVSS	T4
	HRRI	T4,EVBTAB##(T3)
	MOVE	T3,SYSLEN##
	LSH	T3,W2PLSH##	;NUMBER OF BITS TO SET
	PUSHJ	P,CSETOS##	;MONITOR PAGES ARE NOT AVAILABLE AS EVM
> ;END FT2SEGMON
	PUSH	P,P2		;SAVE SYSINI'S RELOCATION
	MOVE	P1,EVMPTR##	;AOBJN POINTER TO EVM TABLE
	MOVEI	P2,0
	MOVEI	P3,-1
	PUSHJ	P,GETZ##	;FIND THE LARGEST CONTIGUOUS PIECE OF EVM
	  MOVEM	P2,EVBMAX##	;STORE THAT AS THE LARGEST IOWD SIZE
	POP	P,P2		;RESTORE SYSINI'S RELOCATION
IFN FTKL10,<
	MOVEI	T1,1
	MOVEI	T2,EVMPTR##
	PUSHJ	P,GETBIT##
	  STOPCD SYSINA,HALT,NMS, ;++NO MAP SLOT
	MOVE	T2,T1
	ROT	T2,-1
	TLZN	T2,400000
	TDOA	T2,[POINT 18,.EPPM##,17](P2)
	TDO	T2,[POINT 18,.EPPM##,35](P2)
	MOVEI	T3,PM.ACC+PM.WRT+.EPMPP##
	DPB	T3,T2
	MOVEI	T1,400(T1)
	PUSHJ	P,RH2INI(P2)
	MOVEI	P4,.C0CDB##	;GET CPU DATA BLOCK IN P4
	PUSHJ	P,RELPMR##	;INITIALIZE PERFORMANCE METER

	SETOM	.C0PTF##	;INITIALIZE FLAG WHICH ALLOWS IO PAGE TABLE
				;PARITY ERROR/CLOCK TICK
IFN FTMS,<
	MOVE	P1,[CPUN##](P2)	;GET NUMBER OF CPUS MONITOR WAS BUILT FOR
	SOJLE	P1,KIIN9A(P2)	;IF ONE CPU, TURN OFF CACHE FOR A FEW
				; PAGES
	SETZ	T1,		;ON 1088 SYSTEMS, MUST TURN OFF
				; CACHE FOR ENTIRE LOWSEG
	MOVEI	T2,340000-1
	PUSHJ	P,CCBRNG(P2)	;CLEAR
IFN FTKL10,<
	MOVEI	T1,CSHFIR##	;SET TO
	MOVEI	T2,CSHLAS##	; CACHE
	PUSHJ	P,CSBRNG(P2)	; PDL'S
>
	JRST	KII10A(P2)	;CONTINUE
KIIN9A:>;END IFN FTMS
	SETZ	P1,		;CLEAR LTINIT INDEX
KIINI9:	SKIPN	T1,LTINIT##(P1)	;LTINIT ENDS WITH A ZERO
	JRST	KIIN10(P2)	;DONE
	HLRZ	T2,T1		;GET NUMBER OF 4 WORD BLOCKS
	LSH	T2,2		;MAKE IT NUMBER OF WORDS
	ADDI	T2,-1(T1)	;GET END ADDRESS OF THIS CHUNK
	HRRZS	T1		;CLEAR LEFT HALF FOR CCBRNG
	PUSHJ	P,CCBRNG(P2)	;CLEAR CACHE BITS IN EXEC MAP
	AOJA	P1,KIINI9(P2)	;AND GET NEXT ENTRY IN LTINIT

KIIN10:	MOVEI	T1,.EPMP##	;CLEAR CACHE BIT FOR EPT
	MOVEI	T2,.EPMPE##
	PUSHJ	P,CCBRNG(P2)	;CLEAR
	MOVEI	T1,LOCOCW##	;NOW CLEAR CACHE BITS FOR LOCOCW
	MOVEI	T2,LOCOCE##	;AND END OF LOCOCW IN T2
	MOVEI	T1,.C0UPT##	;DC76 LOOKS AT UPTIME FOR CPU0
	MOVE	T2,T1		;UNCACHE JUST THIS
	PUSHJ	P,CCBRNG(P2)	;CLEAR OUT CACHE FOR UPTIME
	MOVEI	T1,DLXFST##	;CLEAR OUT CACHE BITS FOR DC75
	MOVEI	T2,DLXLST##
	PUSHJ	P,CCBRNG(P2)
	MOVEI	T1,DLXFS1##
	MOVEI	T2,DLXLS1##
	PUSHJ	P,CCBRNG(P2)
	REPEAT	0,<
	SKIPL	DEBUGF##	;IF DEBUGGING WITH EDDT
	JRST	.+4		;NO-DONT BOTHER
	MOVEI	T1,DDT##	;CLEAR THE CACHE BITS FOR EDDT
	MOVEI	T2,DDTEND##	;TO DDTEND, SYMBOL TABLE IS NEVER WRITTEN
>	;END REPEAT 0
;THE ABOVE CODE, IF ALLOWED TO ASSEMBLE (PUT ";" IN FRONT OF THE REPEAT
;AND THE CLOSING ANGLE BRACKET ABOVE) WILL KEEP DDT OUT OF THE CACHE. THIS IS HANDY IF YOU
;ARE DEBUGGING MONITOR PORTIONS WHICH HANDLE CACHE!!!
	MOVEI	T1,APRPAR##	;KEEP THE APR PARITY RECOVERY CODE
	MOVEI	T2,APPCP2##	;OUT OF THE CACHE UNTIL
				;THE CACHE HAS BEEN SWEPT BACK TO CORE
				;THIS WILL CLOSE DOWN (BUT NOT SHUT) THE WINDOW
				;OF RECURSIVE FAILURES
	PUSHJ	P,CCBRNG(P2)	;AND SHOULD IMPROVE RECOVERY CHANCES
	MOVE	T1,SYSSIZ##	;NOW CLEAR CACHE BITS FROM
	MOVEI	T2,337777	; SYSSIZ - 112K FOR LOCK/REAL TIME
	CAMG	T1,T2
	PUSHJ	P,CCBRNG(P2)

KII10A:>;END IFN FTKL10
	MOVSI	T1,(CAIA)	;SETUP A SKIP AND A NON-SKIP
	MOVSI	T2,(CAI)	; IN T1 AND T2
	MOVEM	T2,$SCPA##	;ASSUME NOTH7NG SKIPS
	MOVEM	T2,$SCPI##	; ..
	MOVEM	T2,$SCPL##	; ..
IFN FTKA10,< MOVEM T1,$SCPA##>
IFN FTKI10,< MOVEM T1,$SCPI##>
IFN FTKL10,< MOVEM T1,$SCPL##>
IFN FTKI10,< MOVEM T1,$SCPI##>
IFN FTKL10,< MOVEM T1,$SCPL##>
IFN FTLOCK,<
	SKIPN	[LOKINC](P2)	;LOCK UUO INCLUDED AT MONGEN TIME?
	JRST	KIIN11(P2)	;NO, SKIP ON
	MOVEI	T1,EVLN##	;NUMBER OF PAGES AVAILABLE FOR LOCKING IN EVM
	MOVEM	T1,.C0EVM##	;STORE THAT FOR USER'S REFERENCE
	SETZM	.C0EVU##	;NUMBER OF PAGES IN USE FOR LOCKING IN EVM
>
KIIN11:	MOVEI	T1,0		;USER APR ENABLE BITS
	MOVEI	P4,.C0CDB##	;ADDRESS OF CPU0'S CDB
	PJRSTF	@[EXP IC.UOU+SETCNA##](P2) ;LIGHT USER IOT IN THE PC AND
				; SETUP APR ENABLE BITS AND CONSO MASK

IFN FTKL10,<
;SUBROUTINE TO FIX UP ICWA LOCS FOR DISKS AND MAGTAPES
;ENTER WITH T1=VIRTUAL PAGE OF EPT
RH2INI::SETZ	T2,		;SET SO WILL DO 1ST ONE
	HLRZ	T4,SYSUNI##	;START AT 1ST UNIT IN SYSTEM
RH2IN1:	HRRZ	J,UNIKON##(T4)	;KONTROLLER THE UNIT POINTS AT
	CAIN	J,(T2)		;SAME AS LAST?
	JRST	RH2IN3(P2)	;YES, TRY NEXT
	MOVE	T2,KONCHN##(J)	;NO, GET LOC OF CDB
	MOVE	T2,CHB22B##(T2);IS IT AN RH20?
	TLNN	T2,CP.RH2##
	JRST	RH2IN2(P2)	;NO, TRY NEXT
	DPB	T1,[POINT 9,KONIOC##(J),26](P2) ;YES, FIX UP KONIOC
	LDB	T2,KOYPI##	;SET UP INTERRUPT VECTOR ADDRESS
	LSH	T2,1		; EARLY IN CASE OF AN ERROR
	ADDI	T2,40
	HRLI	T2,744400	;INTRPT VECTOR = 40+2*N
	XCT	RPXDO2##(J)
	LDB	T2,KOYPI##	;SET UP INTERRUPT CONDITIONS
	TRO	T2,440		; MASSBUS ENABLE+ATTN
	XCT	RPXCO2##(J)
RH2IN2:	MOVE	T2,J		;RESET T2 TO THIS KONTROL
RH2IN3:	HLRZ	T4,UNISYS##(T4);STEP TO NEXT UNIT IN SYSTEM
	JUMPN	T4,RH2IN1(P2)	;TEST IT
	MOVEI	T4,MT0KDB##	;START AT 1ST MAGTAPE
RH2IN4:	MOVE	J,TKBCDB##(T4)
	MOVE	J,CHB22B##(J)	;RH20?
	TLNE	J,CP.RH2##
	DPB	T1,[POINT 9,TKBICP##(T4),26](P2) ;YES, FIX ICWA
	HRRZ	T4,TKBKDB##(T4);STEP TO NEXT KDB
	JUMPN	T4,RH2IN4(P2)	;TEST IT
	POPJ	P,		;DONE, RETURN
>
>
SUBTTL RTTRP INITIALIZATION
IFN FTRTTRP,<
;RTINI IS THE INITIALIZATION ROUTINE TO SET UP THE RT BLOCKS.
;IT IS CALLED EVERY TIME A 140 OR 143 RESTART IS DONE.
;THE FIRST TIME THROUGH RTINI, CHAINT IS LOADED WITH THE
;VALUES OF T4'PI+1.  THIS IS USED TO RESTORE THE PI CHAINS
;ON A 140 RESTART.
;THE RT BLOCK AREA IS ZEROED AND ALL OF THE BLOCKS
;ARE PUT ON THE FREE LIST.

	EXTERN	CHAINT,CHNTAB,RTBLK,RTBSIZ,RTTRPN,RTLINK,SAV61,SAV41,MJOBN
	EXTERN	JBTRTD,TRPFLG,BLKENB

RTINI:	PUSHJ	P,LOADTB(P2)	;FIRST TIME THROUGH, LOAD CHAINT
	MOVE	T1,[JRST RTINI1(P2)](P2) ;CHANGE FLOW OF PROGRAM
	MOVEM	T1,RTINI(P2)	;TO AVOID CALL TO LOADTB
RTINI1:	MOVSI	T1,-6		;SET UP COUNTER
INILOP:	MOVE	T2,CHAINT(T1)	;GET NEXT ENTRY IN CHAINT
	SKIPE	T3,CHNTAB(T1)	;IS THERE AN ENTRY IN CHNTAB
	MOVEM	T2,1(T3)	;YES, RELOAD T4'PI + 1
	AOBJN	T1,INILOP(P2)	;GO BACK FOR REST OF TABLE
	SETZM	RTBLK		;SET UP TO ZERO RTBLOCK AREA
	MOVE	T1,[XWD RTBLK,RTBLK+1](P2)
	MOVEI	T2,RTBSIZ	;GET LENGTH OF A BLOCK
	IMULI	T2,RTTRPN	;CALCULATE LENGTH OF RT BLOCK AREA
	BLT	T1,RTBLK-1(T2)	;ZERO THE AREA
	MOVEI	T1,RTBLK	;NOW LINK THE BLOCKS TOGETHER
	MOVEI	T2,RTTRPN	;GET NUMBER OF BLOCKS AVAILABLE
	MOVEM	T1,RTLINK	;SET UP FIRST ENTRY
INILP1:	MOVEI	T3,RTBSIZ(T1)	;GET ADDRESS OF NEXT BLOCK
	MOVEM	T3,(T1)		;STORE IN CURRENT BLOCK
	EXCH	T3,T1		;GET NEXT BLOCKADR IN T1
	SOJG	T2,INILP1(P2)	;GO FINISH LOOP
	SETZM	(T3)		;MAKE THE LAST BLOCK IN LIST HAVE 0 POINTER
	MOVSI	T1,-6		;RESTORE CHNTAB TO ORIGINAL STATE
INILP2:	SKIPE	T2,CHNTAB(T1)	;GET TABLE ENTRY
	TLNN	T2,BLKENB	;ARE BLKI/O INSTRUCTIONS ALLOWED
	JRST	.+3(P2)		;NO, IGNORE
	HRLI	T2,400000+BLKENB ;RESTORE WORD
	MOVEM	T2,CHNTAB(T1)	;PUT BACK FRESH ENTRY
	AOBJN	T1,INILP2(P2)	;DO REST OF TABLE
	HRROI	T1,SAV61	;RESTORE 41 AND 61
	POP	T1,61
	POP	T1,41
	MOVSI	T1,MJOBN	;GET NEGATIVE JOB NUMBER
	SETZM	JBTRTD(T1)	;CLEAR OUT TABLE
	AOBJN	T1,.-1(P2)	;DO REST OF TABLE
	SETZM	TRPFLG		;CLEAR TRPFLG
	POPJ	P,		;RETURN
LOADTB:	MOVSI	T2,-6		;SET UP COUNTER
LOADT1:	SKIPE	T1,CHNTAB(T2)	;IS THERE AN ENTRY
	MOVE	T1,1(T1)	;YES, PICK UP T4'PI + 1
	MOVEM	T1,CHAINT(T2)	;STORE IN CHAINT
	AOBJN	T2,LOADT1(P2)	;GO DO REST OF TABLE
	MOVEI	T1,SAV41-1	;SET UP TO SAVE 41 AND 61
	PUSH	T1,41		;SAVE 41
	PUSH	T1,61		;SAVE 61
	POPJ	P,		;RETURN
>	;END CONDITIONAL ON RTTRP
SUBTTL LOKCON INITIALIZATION
IFN FTLOCK,<
;CALLED FROM SYSINI ON 140 RESTARTS
;UNLOCKS ALL JOBS AND FREES UP THE CORE THEY OCCUPY

IFN FTSWAP,<
INTERNAL LOKLIM
EXTERNAL CORMIN,LOKMAX,SYSSIZ
>
EXTERNAL SYSINA,LOCK,JBTADR,JBTMAX,JBTSTS,UNLOCK,LOKMAX,MEMSIZ,CORMAX,HOLEF1,HOLTOP

LOKINI:	SKIPN	J,LOCK		;WAS A JOB BEING LOCKED ON THE RESTART?
	JRST	LOKI00(P2)	;NO
	SKIPN	JBTADR(J)	;WAS IT BEING MOVED?
	STOPCD	SYSINA,HALT,JIT,	;++JOB IN TRANSIT
				;CONTINUE WILL TRY A 143 RESTART
	SETZM	LOCK		;SIGNAL NO JOB IS BEING LOCKED
LOKI00:	MOVEI	J,JBTMAX	;UNLOCK ALL LOCKED JOBS
LOKI10:	MOVE	T1,JBTSTS(J)	;IS THIS SEGMENT LOCKED?
	TLNE	T1,NSHF!NSWP
	PUSHJ	P,UNLOCK	;YES, UNLOCK IT
	SOJG	J,LOKI10(P2)	;LOOK AT ALL SEGMENTS
IFN FTSWAP,<
LOKLIM:	HRREI	T1,LOKMAX	;SET GUARANTEED CORE FOR T-S JOBS
				;MODIFIED BY ONCE
	JUMPL	T1,LOKI20(P2)
	ASH	T1,P2WLSH##	;MAKE PAGES INTO WORDS
	CAML	T1,MEMSIZ
LOKI20:	MOVE	T1,CORMAX	;CORMIN_CORMAX
	MOVEM	T1,CORMIN	;SAVE IT FOR TESTING
	MOVE	T1,SYSSIZ	;INITIALIZE SIZE OF LARGEST CONTIGOUS HOLE
	MOVEM	T1,HOLEF1	;TOP
>	;END CONDITIONAL ON FTSWAP
	POPJ	P,		;RETURN
>	;END CONDITIONAL ON FTLOCK
SUBTTL PTYSER INITIALIZATION
;INITIALIZATION CODE. CALLED ON SYSTEM STARTS AND RESTARTS.
;CALLED BY PUSHJ FROM IOGO, WITH F SET UP.
;GIVE NON-SKIP RETURN SINCE ONLY WANT TO BE CALLED ONCE FOR ALL PTYS
;MUST RESPECT P3
;DDB'S EXIST AND HAVE 0 IN IOS.

EXTERN PTYOFS,PTYTAB,TTPLEN,PTYLST
INTERN	PTYINI

PTYINI:	MOVNI	T1,M.PTY##	;COMPUTE NUMBER OF PTY DDB'S
	HRLZS	T1		;MAKE AOBJN COUNTER
	MOVEI	F,PTYLST	;FIRST IN LIST OF PTY DDB'S
PTYIIL:	MOVEM	F,PTYTAB(T1)	;MAKE UP TABLE OF PTY DDB ADDRESSES
	MOVEI	T2,DEPEVM	;GET "DEVICE DOESN'T NEED EVM" BIT
	IORM	T2,DEVTYP(F)	;SET BIT
	HLRZ	F,DEVSER(F)	;FOLLOW CHAIN TO NEXT ONE.
	AOBJN	T1,PTYIIL(P2)	;GO STORE NEXT IF STILL A PTY
	POPJ	P,0		;DONE. RETURN TO IOGO
SUBTTL DTASRN INITIALIZATION
;SUBROUTINE TO INITIALIZE DTC

	INTERN	DTAINI

DTAINI:	MOVEI	T1,DTADDB##	;START AT FIRST CONTROL
DTAIN0:	XCT	DTXINI##(T1)	;CLEAR THE TD10
	SETZM	DSCON##(T1)	;ZERO SOME FLAGS
	SETZM	LVFLAG##(T1)
	SETZM	USEWRD##(T1)
	ADDI	T1,DCONS##	;STEP TO NEXT CONTROL
	CAIGE	T1,KONEND##	;AT END?
	JRST	DTAIN0(P2)	;NO, CLEAR NEXT CONTROL
	POPJ	P,		;YES, EXIT
;TAPSER INITIATION

TPMINI::
IFN FTKL10,<		
	MOVEI	T1,TAPDST##	;START OF DATA BASE
	MOVEI	T2,TAPDEN##	;END OF DATA BASE
	PUSHJ	P,CCBRNG(P2)	;MAKE IT UNCACHED
	MOVEI	T1,LOCODW##	;START OF 4 WORD BLOCKS FOR DX10S
	MOVEI	T2,LOCODE##	;END OF 4 WORD BLOCKS
	PUSHJ	P,CCBRNG(P2)	;UNCACHED THEM ALSO
>
	HRRZ	W,TDVKDB##(F)	;GET ADDRS OF KDB
	HRRZ	T4,TKBDSP##(W)	;GET KONTROLLER SERVICE ROUT ADDRS
	PUSHJ	P,TPKINI##(T4)	;CALL INITIATION ROUTINE
TPMIN1:	LDB	T2,PUNIT##	;GET UNIT #
	ADDI	T2,TKBUDB##(W)	;PLUS INDEX INTO TABLE
	HRRZ	U,(T2)
	HRLM	U,TDVUDB##(F)	;STASH IN DDB
	HRRZM	F,TUBDDB##(U)	;PNTR TO DDB
	MOVEI	T1,TUBQUE##(U)	;QUEUE HEADER ADDRS
	HRLZM	T1,TUBQUE##(U)	;INITIATE EMPTY QUE
	HLRZ	F,DEVSER(F)	;PEEK AT NEXT DDB
	JUMPE	F,CPOPJ##
	MOVSI	T1,DVMTA	;CHECK FOR MTA
	TDNN	T1,DEVMOD(F)	;IS IT
	POPJ	P,		;NO -RETURN
	HRRZ	T1,TDVKDB##(F)	;YES - SEE IF SAME KDB
	CAMN	T1,W		;IS IT?
	JRST	TPMIN1(P2)	;YES - LOOP TO NEXT
	HRLZ	P3,F		;FAKE OUT IOGO
	POPJ	P,
SUBTTL SCNSER INITIALIZATION

;CODE CALLED ON A 140 RESTART. CLEAR ANY UUO-LEVEL ACTIVITY, AND ALL
; LINKED CHARACTER BUFFERS AND THEIR POINTERS IN THE LDB'S.
;RE-INITIALIZES ALL OF TTCLST TO BE BLANK AND ALL LINKED TO TTFREE.

;CALLED BY PUSHJ FROM IOGO, WITH F SET UP.
; GIVE NON-SKIP RETURN, SINCE DON'T NEED TO CALL THIS ROUTINE AGAIN
; FOR EVERY TTY DDB
;MUST RESPECT P3
;DEVICE DATA BLOCKS EXIST, AND HAVE BEEN CLEARED TO 0 IN DEVIOS.

EXTERN SCNCHN,MTTYLN,TCONLN,DEVOPR,LINTAB,LDPLNO,LDBINI,LDICLR,LDICLE,LINSAV
EXTERN	CCTYI,COMTIA,CCTYO,COMTOA,TTYLST,TTYREL,LDRPTY
INTERN	TTYINI

IFNDEF FTGPO2B,<XP FTGPO2B,0>	;MUST AGREE WITH SCNSER
CTY=120	;HARDWARE DEVICE NUMBER OF THE KA10 CONSOLE TTY

TTYINI:	CONO	PI,PIOFF##

;INITIALIZE LINE DATA BLOCKS (ASSUMED TO EXIST, POINTED TO BY LINTAB,
; BUT NOT TO CONTAIN ANYTHING USEFUL EXCEPT LDPLNO AND SOME OF LDBDCH)

	MOVSI	J,MTTYLN	;MINUS LENGTH OF LINTAB, I.E., THE
					; SCANNER(S), CTY, PTY'S, AND REMOTES
TTII1L:	HRRZ	U,LINTAB(J)	;GET ADDRESS OF LINE DATA BLOCK
	DPB	J,LDPLNO	;STORE LINE NUMBER
	PUSHJ	P,LDBINI	;CALL ROUTINE WHICH CLEARS IT UP
	MOVSI	T1,LDICLR(U)	;CLEAR OUT ALL POINTERS AND T2'S
	HRRI	T1,LDICLR+1(U)	;IN THE LDB POINTER AREA
	SETZM	LDICLR(U)	; ..
	BLT	T1,LDICLE(U)	;..
	AOBJN	J,TTII1L(P2)	;LOOP FOR ALL LDB'S
	SETZM	LINSAV		;IN CASE JUNK GOT IN LINSAV
	MOVEI	T1,CCTYI	;SET COMMAND DISPATCHERS
	MOVEM	T1,COMTIA
	MOVEI	T1,CCTYO	;FOR INPUT AND OUTPUT
	MOVEM	T1,COMTOA	; ..

;NOW GO THROUGH ALL THE TTY DDB'S VIA CHAIN, AND KILL ALL THOSE WHICH
; HAVE TTYATC AND ASSCON OFF, BY CALLING TTYREL

	SETOM	DINITF##	;TTYREL BEING CALLED FROM SYSINI
	MOVEI	F,TTYLST	;FIRST TTY DDB IN DEVICE CHAIN
TTII2L:	PUSHJ	P,TTYREL	;TTYREL WILL KILL IT (TTYKIL)
					; UNLESS TTYATC OR ASSCON ARE ON
	MOVEI	T2,DEPEVM	;GET "DEVICE DOESN'T NEED EVM" BIT
	IORM	T2,DEVTYP(F)	;SET BIT
	HLRZ	F,DEVSER(F)	;DO SAME FOR ALL TTY DDB'S
	MOVSI	T1,DVTTY	;IS THIS A TTY TOO?
	TDNE	T1,DEVMOD(F)	;CHECK IN DEVICE MODE WORD
	JUMPN	F,TTII2L(P2)	;JUMP IF YES.
;NOW CLEAR ANY PHONY LINKS IN THE LDB'S. I.E., ANY WHICH THINK
; THEY ARE POINTING TO DDB'S BUT THE DDB'S HAVE BEEN KILLED (TTYUSE=0)

EXTERN TTVINI,TTVSLV,LDBCLR,LDBDCH,TTFCXR,LDRCTY,LDBDDB,TTFORC

	MOVSI	J,MTTYLN	;COUNT OF LDB'S
TTII3L:	HRRZ	U,LINTAB(J)	;GET LDB ADDRESS
	PUSHJ	P,LDBCLR	;NO DDB. CLEAR THIS LDB FROM
					; THE TOP. INITIALIZE ITS BITS
					; FROM LINTAB.
	MOVE	T1,LDBDCH(U)	;GET DEVICE BITS
	TRNN	T1,LDRREM##	;REMOTE STATION LINE?
	TRNE	T1,LDRPTY	;NO, PTY-DRIVEN LINE?
	JRST	TTII3N(P2)	;YES. NO COMMAND FOR IT
	HRRZ	T1,J		;GET LINE # IN T1
	PUSHJ	P,XTCTTY##	;SEE IF DA28
	  JRST	TTII3N(P2)	;INACTIVE - IGNORE
	  JFCL			;ACTIVE - TREAT AS REGULAR
	MOVEI	T1,TTFCXR	;RESTART COMMAND FORCE INDEX
	MOVE	T3,LDBDCH(U)	;GET DEVICE CHARACTERISTICS
	HLL	T3,LINTAB(J)	;AND INITIAL CHARACTERISTICS
IFN FTDISK,<EXTERN REFLAG
IFN FTCCLX,<
	TLNE	T3,TTVINI	;DOES IT WANT STARTUP CUSP
	MOVEI	T1,TTFCXI##	;YES, SET FOR STARTUP CUSP
>
	SKIPE	REFLAG		;BUT IF DISK IS BEING REFRESHED?
	MOVEI	T1,TTFCXR	;JUST GIVE NORMAL MESSAGE
>
	TLNN	T3,TTVSLV	;UNLESS DEVICE IS A SLAVE,
	PUSHJ	P,TTFORC	;FORCE THIS COMMAND
TTII3N:	AOBJN	J,TTII3L(P2)	;DO SAME FOR ALL LDB'S

TTYIOP:	SKIPN	T1,DEVOPR	;SET UP OPERATOR FOR ERROR MESSAGES
TTIOP1:	MOVSI	T1,(SIXBIT /CTY/)	;IF NONE, ASSUME CTY.
	PUSHJ	P,STDOPR##	;GET A DDB AND LDB FOR OPR AND SET OPRLDB
	  JRST	TTIOP1(P2)	;NO SUCH GUY. TRY CTY.
				; DONT REALLY WANT IT NOW
	SETZM	DINITF##	;DONE WITH TTYREL
IFN FTMODM,<
;NOW INITIALIZE THE DATAPHONE HANDLING TABLE

EXTERN DSCPTR,DSTREQ,DSCTAB,LDPDSC,DSTON,DSTOFF,DSCICL,DSCIC1,DSCIC2

TTIDSC:	SKIPL	J,DSCPTR	;GET THE DATAPHONE INDEX, IF ANY
	JRST	TTIDSX(P2)	;NONE IN THIS CONFIGURATION
IFN FTDIAL,<
	SETZM	TTYDDA##	;CLEAR TTY DIALLER DATA ADDRESS CELL (4 WD BLOCK)
>
	HLLZS	J		;CLEAR RIGHT HALF OF POINTER
TTIDSL:	MOVEI	T3,DSTREQ	;TRANSACTION CODE FOR REQUEST
	MOVE	U,DSCTAB(J)	;SET UP BACK POINTERS TO DATASET TABLE
	MOVE	U,LINTAB(U)	;IN THE LDB'S
	DPB	J,LDPDSC	;STORE THE INDEX
IFE FTGPO2B,<
;CAN'T BELIEVE THE CARRIER FLAG ON A GPO 2B MODEM, SO MUST CLEAR IT FROM LINE
	MOVEI	U,0(J)		;TABLE INDEX AS LINE NUMBER
	PUSHJ	P,DSCCAL##	;GO GET STATE OF LINE
	CAIN	T3,DSTNAC##	;DC76 NO-ACTION?
	JRST	TTIDSN(P2)	;YES.  DC76 WILL TELL US ABOUT ALL LINES
				; (MAY HAVE ALREADY)
	CAIN	T3,DSTON	;IS CARRIER ON?
	JRST	TTIDS1(P2)	;YES. GO SET ON STATE IN TABLE
>					;END OF 2B COND
	MOVSI	T1,DSCICL	;HWC+SWC+FAI+TMM
	ANDCAM	T1,DSCTAB(J)	;CLEAR ALL BITS. HE'S OFF
	MOVEI	T3,DSTOFF	;SEND OFF CODE IN CASE WAS ON
	MOVEI	U,0(J)		;USING TABLE INDEX AS LINE
	PUSHJ	P,DSCCAL##	;SEND THE OFF CODE
TTIDSN:	AOBJN	J,TTIDSL(P2)	;COUNT THRU ALL DATAPHONES
	JRST	TTIDSX(P2)	;END OF TABLE

TTIDS1:	MOVSI	T1,DSCIC1	;LINE IS ON. SET HWC+SWC BITS IN TABLE
	IORM	T1,DSCTAB(J)	; ..
	MOVSI	T1,DSCIC2	;AND CLEAR FAIL AND TIME BYTE TMM+FAI
	ANDCAM	T1,DSCTAB(J)	; ..
	JRST	TTIDSN(P2)	;ON TO NEXT LINE

TTIDSX:!					;END OF ROUTINE
>;FTMODM
;NOW SET UP THE CHARACTER CHUNKS IN TTCLST TO BE ALL FREE. THE FIRST IS
; POINTED TO BY TTFREE. ASSUME FOLLOWING DATA IS AVAILABLE
EXTERN	TTCHKS,TTFREN,TT2CHK,GETDDB,OPRLDB,CPOPJ1,TTBASE

EXTERN TTCLST		;XWD # OF CHUNKS , ADDRESS OF FIRST CHUNK
EXTERN TTFREE		;WHERE TO PUT POINTER TO FREE LIST.

	HRRZ	T1,TTCLST	;GET START OF LIST AREA
	MOVEM	T1,TTBASE	;SAVE FOR SCNSER
	SETZM	0(T1)		;CLEAR OUT ALL CHUNK LINKS AND DATA
	MOVEI	J,TTCHKS(T1)	;SET INITIAL BYTE TO SKIP ZEROTH CHUNK
	MOVEM	J,TTFREE	;STORE IN FREE LIST POINTER
	MOVEI	J,1(T1)		;MAKE BLT POINTER TO CLEAR LIST
	HRLI	J,0(T1)		; ..
	HLRZ	T3,TTCLST	;GET END ADDRESS FROM NUMBER OF CHUNKS
	MOVEM	T3,TTFREN	;SAVE THAT NUMBER
	IMULI	T3,TTCHKS	;WORDS PER CHUNK
	ADDI	T3,0(T1)	;ADD BASE ADDRESS
	BLT	J,-1(T3)	;CLEAR LIST
	HRRZ	T3,TTCLST	;FIRST CHUNK
	HLRZ	J,TTCLST	;GET NUMBER OF CHUNKS TO COUNT
	SOJA	J,TTII4A(P2)	;SKIP ZEROTH CHUNK, GO START STORING
TTII4L:	SETOM	(T3)		;FLAG AS FREE
TTII4A:
	ADDI	T3,TTCHKS	;NEXT CHUNK
	SOJGE	J,TTII4L(P2)	;COUNT CHUNKS

	SOS	TTFREN		;COMPENSATE FOR NOT USING BLOCK ZERO
	HLRZ	T1,TTCLST##	;NUMBER OF CHUNKS
	LSH	T1,2		;CONVERT TO WORDS
				;4 BYTES/WORD=2**4
	ADD	T1,TTCLST##	;ADD TO BASE
	HRRZM	T1,RCCMAX##	;SAVE FOR RANGE CHECK
	MOVEI	J,TCONLN##	;START WITH CTY
TTII0L:	MOVEI	T1,ISRINI##	;FUNCTION TO INIT A LINE
	MOVE	U,LINTAB##(J)	;POINT TO LDB
	DPB	J,LDPLNO##	;MAKE SURE LDPLNO SET UP
	PUSH	P,J
	PUSHJ	P,@LDBISR##(U)	;INIT THE LINE
	POP	P,J
	SOJGE	J,TTII0L(P2)	;LOOP OVER ALL LINES
					; HARDWARE FIRST, SINCE PI IS OFF
	CONO	CTY,1200+SCNCHN	;ALSO CLEAR THE CTY, AND GIVE IT ITS PI
	CONO	PI,PION##
	POPJ	P,0		;END OF TTYINI

;HERE FROM SYSINI (MASTER PROCESSOR INITIALIZATION) TO
;CLEAR INTERLOCK WORDS (SET TO -1'S)
;CALL:	JSP	T1,CP1INI
;PATCH "PATCP1" TO BE MOVSI T2,400000 TO DISABLE ?CPU1 NOT RUNNING
; FROM HAPPENING ONCE A MINUTE. (FOR EX. DURING DEBUGGING SESSION)
;CALLED ONLY IF HAVE A SLAVE SLVINC NON-ZERO

IFN FTMS,<
	INTERNAL CP1INI,PATCP1
	EXTERNAL .C0SCD,.C0VAR,.C0EVA,TICSEC,.C1OK,.C1SCD,SPTRAP,SVMES,.C0OK,.C0VAR,.C0EVA
	EXTERN DEDTIM

CP1INI:	SOS	.C1OK		;FORCE DUAL PROCESSOR BACK TO BEGINNING OF AC LOOP
				; BY CHANGING OK WORD BUT NOT BY +1
				; LEAVE A FEW INSTRUCTIONS BEFORE
				; SETTING OK TO A SMALL NEGATIVE NUMBER
	SETOM	.C1SCD		;INITIALIZE DUAL PROCESSOR INTERLOCK
	SETZM	.E1IL##		;MAKE DUAL PROCESSOR START OVER AT RESTART ADR
	SETZM	SVMES		;INITIALIZE ALL DUAL PROCESSOR MESSAGES
PATCP1:	MOVN	T2,TICSEC	;MAKE DUAL PROCESSOR WAIT TWO JIFFIES TO START
				; PATCH TO MOVSI T2,400000 TO DISABLE
				; ONE A MINUTE CPU1 NOT RUNNING MESSAGE
	MOVEM	T2,.C1OK	;AND MASTER TO NOT TYPE MESSAGE FOR ONE MINUTE
	MOVEI	T2,DEDTIM+1	;MAKE DUAL PROCESSOR WAIT UNTIL MASTER IS GOING
	MOVEM	T2,.C0OK
	SETZM	.C0VAR		;ZERO MASTER VARIABLE AREA
	MOVE	T2,[XWD .C0VAR,.C0VAR+1](P2)
	BLT	T2,.C0EVA	;DUAL PROCESSOR AREA IS CLEARED IN SYSINI
	JRST	(T1)		;RETURN TO SYSINI

>	;END FTMS
;SUBROUTINE TO REFERENCE A MEMORY LOCATION IN PHYSICAL MEMORY
;CALLING SEQUENCE:
;	MOVE	U,ABSOLUTE ADDRESS TO REFERENCE
;	PUSHJ	P,REFMEM
;	...	RETURN HERE
;T1 CONTAINS THE CONTENTS OF THE LOCATION SPECIFIED BY U

REFMEM::PUSH	P,P1		;CAN'T USE SAVE1
	MOVE	P1,.C0TYP##
	CAIL	P1,CT.KI
	JRST	REFME1(P2)
	MOVES	T1,(U)
	JRST	REFME3(P2)
REFME1:	MOVE	P1,U
	LSH	P1,W2PLSH##
	MOVEI	P1,PM.ACC+PM.WRT(P1)
	HRLM	P1,.EPPM##
	CLRPGT	(0,.EUPMP)
	MOVE	P1,U
	ANDI	P1,PG.BDY##
	IORI	P1,.EUPMP
IFN FTKL10,<
	PUSH	P,P3
	MOVEI	P3,REFME2(P2)
	HRLI	P3,(XC.UIO)
	EXCH	P3,.UPMP+.LMPFN
	SETZ	T1,
>
	MOVES	T1,(P1)
IFN FTKL10,<
REFME2:	MOVEM	P3,.UPMP+.LMPFN
	POP	P,P3
>
REFME3:	POP	P,P1
	POPJ	P,
IFN FTKL10,<

;ROUTINE TO SET OR CLEAR CACHE BITS FOR A RANGE OF EXEC ADDRESSES.
; THE RANGE IS C(T1)R THROUGH C(T2)R INCLUSIVE.
; USES ALL T ACS, AC U WITHOUT RESTORING THEM. ORIGINAL ARGUMENTS
; IN T1 AND T2 ARE LOST.
; ARGUMENTS MUST BE IN LOWER 112 K.

CSBRNG:	SKIPA	U,[TRO T1,PM.CSH](P2)	;SET BITS
CCBRNG:	MOVE	U,[TRZ T1,PM.CSH](P2)	;CLEAR BITS
	LSH	T2,W2PLSH##	;CONVERT TO PAGES
	LSH	T1,W2PLSH##
	HRRZ	T3,T1		;SAVE STARTING VIRTUAL PAGE
	ROT	T1,-1		;GET ODD/EVEN BIT IN SIGN BIT
	TLZE	T1,400000	;SKIP IF THIS IS AN EVEN PAGE
	SKIPA	T4,[POINT 18,.EPLM##,17](P2) ;POINTER FOR ODD PAGES
	MOVE	T4,[POINT 18,.EPLM##](P2)  ;POINTER FOR EVEN PAGES
	ADDI	T4,(T1)		;MAKE BYTE POINTER TO PROPER SLOT

CCBRN1:	ILDB	T1,T4		;GET CONTENTS OF SLOT
	XCT	U		;SET OR CLEAR CACHE BIT ACCORDINGLY
	DPB	T1,T4		;AND PUT IT IN MAP
	CAIE	T3,(T2)		;DID WE JUST DO LAST PAGE?
	AOJA	T3,CCBRN1(P2)	;LOOP, WE HAVE MORE TO DO.
	POPJ	P,		;YES, BYE.
>


;LIT AND VAR
XLIST
LIT
VAR
LIST


	INTERNAL ENDSYS,ENDSYL
ENDSYL==ENDSYS-SYSINI
ENDSYS:	END			;STARTING ADDRESS OF MONITOR ON NORMAL LOADING