;DSK:<PEFMON>SYSINI.MAC;2 22-Apr-80 20:53:34, Edit by FRENCH
;REMOVE CALL TO MAPBTF.  DONE IN FILINI NOW.  IGNORE SEQUENTIAL OFN
;CROCK FOR BITTABLE SENSITIVE PAGE CHECKING.  WE DONT DO IT
;<134-TENEX>SYSINI.MAC;30    27-Jan-80 18:32:00    EDIT BY PETERS
; Fix F3AFLG to F3FLG
;ADDED CALL TO HSTINI IF ON FOONLEY FO GATEWAY STUFF
;<134-TENEX>SYSINI.MAC;28    11-Jun-79 21:23:46    EDIT BY PETERS
;<134-TENEX>SYSINI.MAC;27     3-Apr-79 18:04:15    EDIT BY PETERS
;<134-TENEX>SYSINI.MAC;26    20-Sep-78 21:42:00    EDIT BY PETERS
;<134-TENEX>SYSINI.MAC;25     1-Sep-78 19:36:40    EDIT BY PETERS
;<134-TENEX>SYSINI.MAC;24    13-DEC-77 17:11:25    EDIT BY PETERS
;<134-TENEX>SYSINI.MAC;23    16-Dec-76 08:29:42    EDIT BY UNTULIS
;added dbugsw check before delay for settim in specjl
;<134-TENEX>SYSINI.MAC;22     7-Oct-76 19:54:58    TVEDIT'd by Geoff
; Put in delay at SPECJL so SETTIM has 20 secs to get the time from the
; network before users are allowed on (and get free grabs at setting the time.)
;<134-TENEX>SYSINI.MAC;21    14-SEP-76 22:16:01    EDIT BY GEOFF
; added some lower caseing.
;<134-TENEX>SYSINI.MAC;20     5-AUG-76 09:39:22    EDIT BY LYNCH
; FIXED ERROR IN PLACING DEMO CODE...
;<134-TENEX>SYSINI.MAC;19    29-JUL-76 10:22:26    EDIT BY LYNCH
; PUT IN DEMO GROUP LOOKUP CODE.
;<134-TENEX>SYSINI.MAC;18     2-JUL-76 15:51:03    EDIT BY UNTULIS
;ADDED CODE TO JUMP OVER MAPBTF FOR INITIAL FILE SYSTEM BUILD
;<134-TENEX>SYSINI.MAC;17    18-APR-76 11:43:05    EDIT BY UNTULIS
;MOVED LOGDES INTO RESCD
;<134-TENEX>SYSINI.MAC;16    17-APR-76 22:20:28    EDIT BY OP
;<134-TENEX>SYSINI.MAC;14    16-APR-76 09:42:03    EDIT BY UNTULIS
;ADDED SILENT LOGIN AND DETACH CODE FOR SYSTEM JOBS
;<134-TENEX>SYSINI.MAC;9    15-MAR-76 15:04:41    EDIT BY UNTULIS
;ADDED STRING PERMISSION CODE TO LGNSYS
;<134-TENEX>SYSINI.MAC;7    24-FEB-76 13:06:56    EDIT BY UNTULIS
;DELETED DEMO JUNK
;<134-TENEX>SYSINI.MAC;3     9-FEB-76 16:40:32    EDIT BY UNTULIS
;ADDED LOGDES,SWPCOR CHECK AND ENTFLG CODE
;<134-TENEX>SYSINI.MAC;2     9-FEB-76 13:56:56    EDIT BY UNTULIS
;ADDED DEMO INIT CODE
;<135-TENEX>SYSINI.MAC;6    16-DEC-75 10:58:23    EDIT BY CALVIN
; Put in PLUMMER's IFN for IFDEF PIESLC
;<135-TENEX>SYSINI.MAC;5     8-DEC-75 16:29:30    EDIT BY ALLEN
; REUNITE CALLS TO FILINI AND MAPBTF SO THAT BIT TABLE OFN IMMEDIATELY
;FOLLOWS DIRECTORY PT OFNS
;<134-TENEX>SYSINI.MAC;4    22-MAY-75 12:28:45    EDIT BY ALLEN
; PARAMETERIZE INITIAL SETTING OF KFACT
;<134-TENEX>SYSINI.MAC;3    14-MAY-75 21:48:59    EDIT BY SYSTEM
; MAKE MONDSC RESIDENT SINCE IT'S STORED INTO BY DSKRST
;<134-TENEX>SYSINI.MAC;2    24-APR-75 12:30:52    EDIT BY CLEMENTS
;<134-TENEX>SYSINI.MAC;1    23-APR-75 14:06:10    EDIT BY CLEMENTS
; SPLITTING UP SWPMON.MAC INTO FINITE SIZE PIECES
; THIS IS SYSINI.MAC

	SEARCH PROLOG
	TITLE SYSINI

	SWAPCD

	DEFINE TMSG
<	PUSHJ P,TMSGQ##>

INTERNAL	WMST,SWCEND,GETDDT,SBSNMS,TNAMS1,DDTFSH,NMNDSC
INTERNAL	MKPGSA,MKPGSU,JB0TT,GETMST,OPTT,SAVE32,SAVE36
INTERNAL	GETSWM,RCADDT,LGNSYS,SPECJT,SPECJB
INTERNAL	NLGDES,SPCSTJ,LOGDES,NSPECJ,DONSJ

EXTERNAL	SWPCOR
EXTERNAL	ACCIFG,AUTONX,BHC,BUGCHK,BUGHLT,CAPENB,CAPMSK
EXTERNAL	CVDSK,DBUGSW,DCHKSW
EXTERNAL	DDTPRS,DDTSYM,DDTX,DIDSCA,DISKP
EXTERNAL	EDISMS,ENTFLG,FACTSW,FILINI,GOTDDT
EXTERNAL	JFNOFN,JOBONT,JOBSRT,LGNPAR,LOGLCK,LOGONM
EXTERNAL	MAKPGA,MAKPGU,MLKPG

EXTERNAL	MMSPTN,MONCOR,MRETN,MSTKOV,MULKPG
EXTERNAL	NODD1,NPMAX,NSECPG,PRIMRY
EXTERNAL	R,RUNDD,SCDRQ7,SETMPG,SNAMES,SNMLCK
EXTERNAL	PLCKT,SNMPT,SSTSIZ,SVNUM,SWPST,SWPSTP,SYMPRS
EXTERNAL	TENDMP,TOTRC,TTFORK,UDSKIO

IFDEF IMPCHN,<	EXTERNAL HSTINI>
IFNDEF IMPCHN,<IFN F3FLG,<EXTERNAL HSTINI>>

IFN PIESLC,<	EXTERNAL ACTINI,ACTONF,GRPFIL,GRPLOK>

;THE FOLLOWING IS THE MONITOR DESCRIPTOR GETAB TABLE ("MONDSC")
;CURRENT ASSIGNMENTS:
;WORD0, B0 = 0 MEANS NO PIE-SLICING
;	  = 1 MEANS PIE-SLICE SYSTEM
;WORD0, B1 = 0 MEANS CONTIGUOUS DISK SWAP AREA
;	  = 1 MEANS MULTI-PACK SWAPPING 

RESCD
MONDSC:: <PIESLC>B0

NMNDSC==.-MONDSC


; FOLLOWING IS A GETTAB TABLE
LOGDES:	LOGTTY			;DESIGNATOR FOR LOG MSGS - DEF IN PARAMS
JB0TT:	JB0TTY			;DESIG FOR JOB 0 AND ERR MSGS
OPTT:	OPTTY			; DESIGNATOR FOR OPERATOR
NLGDES==.-LOGDES
;END OF GETTAB
GS DEMO,1			; HOLDS INDEX FOR DEMO GROUP
SWAPCD



;FOLLOWING CODE ONLY EXECUTED FOR FIRST JOB IN SYSTEM
; THIS CODE CALLED FROM EXEC0 FOR THE FIRST JOB.

EXECSI::SKIPE DIDSCA		; REFRESHING DISK?
	 SETOM ACCIFG		; NO, ASSUME SPECIAL FILES SHOULD EXIST
	CALL FILINI		;INIT FILE SYSTEM, MAP BITTABLE
	IFN PIESLC,<SETZB 1,PIEFLG> ;ASSUME NO PIESLICE FOR NOW
	CALL ACTINI		; CALL ACCOUNT VERIFYING INITER
	 JFCL			; IT'LL DO THE BUGCHK ON FAIL
IFN PIESLC,<SETZB 1,PIEFLG##>	; ASSUME NO PIE-SLICE FOR NOW
	SKIPN ACCIFG		; SHOULD SPECIAL FILES EXIST?
	 JRST EXEC1		; NO, SKIP SOME THINGS

IFDEF IMPCHN,<
	CALL HSTINI		; INITIALIZE HOST NAME TABLE
	 BUG(CHK,<FAILURE TRYING TO INIT HOST NAME TABLES>)
>

IFNDEF IMPCHN,<IFN F3FLG,<
	CALL HSTINI		; INITIALIZE HOST NAME TABLE
	 BUG(CHK,<FAILURE TRYING TO INIT HOST NAME TABLES>)
>>

IFN PIESLC,<
	CALL MAPGRP		;MAP PIE-SLICE GROUP DATA FILE
	SKIPN 1,PIEFLG		;MAPPING SUCCESSFUL?
	 JRST EXEC1		;NO

	MOVE 1,[INIGP]		;GET DEFAULT GROUP NAME
	CALL GRPLUK##		;LOOK UP IN FILE
	BUG (HLT,<DEFAULT GROUP NAME NOT IN FILE>)
>
EXEC1:
IFN PIESLC,<
	MOVEM 1,DEFGP##		;RECORD DEFAULT GROUP INDEX FOR STARTING JOBS
	MOVEM 1,PIEGRP##	;USE FOR THIS JOB (JOB 0)
	SETZM NAPROC##		;CLEAR COUNTER INCREMENTED FOR FIRST FORK
	MOVSI 2,(1.0)		;AND SET THE CORRECT COUNTER
	MOVEM 2,NAPROC(1)

	MOVE 1,[SIXBIT /DEMO  /]
	CALL GRPLUK
	 SETO 1,		; NOT THERE...
	MOVEM 1,DEMO		; SAVE FOR SCHEDULER TO SEE

	MOVE 2,[KFINIT]		;INITIAL VALUE FOR KFACT
	MOVEM 2,KFACT##

	SETOM GRPLOK		;INITIALIZE PIE SLICE DATA LOCK
>

	MOVE 1,[XWD SBSNMS,SNAMES]
	BLT 1,SNAMES+NSBSNM-1	;MOVE REGULAR SUBSYSTEM NAMES TO TABLE
	MOVNI 1,NSBSNM		;INIT TABLE POINTER WITH NEG COUNT
	MOVEM 1,SNMPT
	SETOM SNMLCK		;AND INIT LOCK
	SETOM LOGLCK
	MOVE A,[JOBONT,,JOBONT+1] ;CLEAR BACK-POINTERS
	SETOM JOBONT		; TO OWNING JOBS. NOTE JOB 0
	BLT A,JOBONT+NJOBS-1	; IS NOT OWNED BY ANYBODY.
	CALL SWPINI##		;INITIALIZE THE SWAPPABLE FREE POOL
	POPJ P,0		;RETURN FROM EXECSI TO EXEC0

;REGULAR SUBSYSTEM NAMES FOR INCLUSION IN SNAMES TABLE AT STARTUP

SBSNMS:	SIXBIT /EXEC/
	SIXBIT /(PRIV)/
NSBSNM==.-SBSNMS

;TABLE DEFINES SPECIAL PURPOSE FOR FIRST FEW JOBS

SPECJT:	XWD 0,RUNDD		;JOB 0 IS ALWAYS DISK CHECKER, ETC.

NSPECJ==.-SPECJT		;NUMBER OF SPECIAL JOBS

;EACH SPECIAL JOB CALLS THIS TO DETACH AND START THE NEXT ONE

DONSJ:	PUSH P,LOGDES		;SAVE LOGDES
	MOVEI 1,377777		;SILENT
	MOVEM 1,LOGDES
	CALL LOGONM		;DO LOGIN STUFF
	MOVE 4,CTRLTT
	DTACH
	POP P,LOGDES		;RESET LOGDES
	MOVE 1,JB0TT
	HRRM 1,PRIMRY		;USE JOB 0 TTY FOR ANY OUTPUT
	MOVE 1,JOBNO
	CAIGE 1,NSPECJ-1		;MORE SPECIAL JOBS TO DO?
	JRST DONS1		;YES
	RET
DONS1:	MOVE 2,4
	CALL SPCSTJ		; START ANOTHER JOB ON THIS TTY
	RET

;THE FOLLOWING BLACK MAGIC IS TEMPORARY UNTIL CRJOB DOES ALL
; THE AUTOSTARTUP WORK. IT IS NEEDED TO CAUSE A LOGIN TO REALLY
; SET UP PROTECTION AND GROUP ACCESS RIGHT

LGNSYS:	MOVEI A,1(P)		;SPACE FOR A STRING ACCOUNT
	ADD P,BHC+10		; ..
	JUMPGE P,MSTKOV		; ..
	MOVEI B,1		;USER "SYSTEM"
	GDACC			;GET DEFAULT ACCOUNT FOR SYSTEM
	  MOVE A,[POINT 7,[ASCIZ /SYSJ/]]
	MOVE C,A
	MOVEI B,0		;NO PASSWORD STRING
	HRROI A,3		;FLAG LOGIN TO NOT CHECK PSWD, NOT
	MOVEM A,LGNPAR		; UPDATE LOGIN DATE
	PUSH P,LOGDES		; SAVE LOGDES
	MOVEI 1,377777		; SILENT
	MOVEM 1,LOGDES
	MOVEI A,1		;USER NUMBER 1 = SYSTEM
	LOGIN
	  BUG(HLT,<LGNSYS - CAN'T LOG IN AS SYSTEM>)
	POP P,LOGDES		; RESTORE LOGDES
	SETZM LGNPAR
	SUB P,BHC+10
	RET

; ALTERNATE STARTUP MECHANISM TO START JOBS FROM FILE "AUTOJOBS"

SPECJB:	PUSH P,3
IFE PIESLC,<
	MOVE 1,JOBNO
	MOVE 2,BHC+1
	MOVEM 2,JOBDIR(1)	; FAKE LOGIN AS SYSTEM
	PUSH P,LOGDES		; SAVE TRUE LOGDES
	MOVEI 3,377777
	MOVEM 3,LOGDES		; MAKE AUTOJOB LOGINS SILENT AND FAST
	MOVSI 3,200000		; SRI DIDDLE FOR ALPHANUMERIC ACCOUNTS
	MOVEM 3,MODES		; TO ALLOW ACCOUNT CHANGING BY AUTOJOB PROGRAMS.
	MOVE 3,FORKX
	MOVEM 2,FKDIR(3)
	PUSHJ P,LOGONM		; AND PRINT LOGIN MESSAGE
	POP P,LOGDES
>
IFN PIESLC,<
	CALL LGNSYS		;DO A LOGIN AS SYSTEM
>
	POP P,3
	MOVE 1,DBUGSW
	HRROI 2,[ASCIZ /<SYSTEM>AUTOJOBS.RUN/]
	CAIN 1,2
	HRROI 2,[ASCIZ /<SYSTEM>AUTOJOBS.DEBUG/]
	MOVSI 1,(1B2+1B17)	; OLD FILE & STRING & SHORT FORM
	GTJFN			; GET JFN OF AUTOJOBS FILE
	 JRST SPECJ5		; FILE NON-EXISTENT
	PUSH P,1		; SAVE IT
	PUSH P,LOGDES
	MOVEI 2,377777
	MOVEM 2,LOGDES
	DTACH			; DETACH THIS JOB
	POP P,LOGDES		; GO BAC TO LOGTTY BEING REAL
	MOVE 2,[7B5+1B19]
	OPENF			; OPEN TO READ
	 JRST [	POP P,1
		RLJFN
		 JFCL
		JRST SPECJ9]	; COULDN'T OPEN
	MOVE 2,3		; START POINT
	SFPTR
	 JRST SPECJ8		; HADN'T OUGHT TO HAPPEN
	HRLZ 2,1		; MAKE IT BE INPUT FOR GTJFN
	HRRI 2,377777		; NO OUTPUT
	MOVSI 1,(1B2+1B16+1B17)	; OLD FILE, FILE INPUT, SHORT FORM
	GTJFN
	 JRST SPECJ6		; FILE APPARENTLY NOT THERE
	EXCH 1,0(P)		; SAVE JFN OF TASK, GET JFN OF AUTOJOBS
	CALL SPECJN		; GET NEXT ONE STARTED
	MOVSI 1,(1B2+1B17)	;OLD FILE+SHORT FORM
	HRROI 2,[ASCIZ /<SYSTEM>EXEC.SAV/]
;FALL THRU

;FALLS THRU
	GTJFN
	JRST [	POP P,1		; NO EXEC?  GET RID OF JFN
		RLJFN
		JFCL
		JRST SPECLO]	; AND LOGOUT
	HRLI 1,400000
	GET			;GET CURRENT EXECUTIVE
	XCTMU [POP P,2]		; PUT JFN OF SAVE FILE IN AC2 OF EXEC
	HRRO 1,JB0TT		;GET JOB 0 TTY FOR PRIMARY
	UMOVEM 1,1		;GIVE IT TO EXEC TO USE.
	HRRZ 1,ENTVEC
	ADDI	1,2		;GO TO AUTO JOB ENTRY POINT
	HRRM 1,0(P)
	JRST MRETN

SPECJ6:	POP P,1
	CALL SPECJN		; SKIP TO NEXT TASK
SPECLO:	SETO 1,
	LGOUT			; LOG OURSELVES OUT
	 JFCL
	BUG(HLT,<IMPOSSIBLE FAILURE OF LGOUT(-1)>)

SPECJ8:	POP P,1
	CLOSF
	 JFCL
SPECJ9:	BUG(CHK,<SPECJB:  AUTOJOB FILE SCREWED UP>)
SPECJ5:	HRROI 1,[ASCIZ /NO AUTOJOBS FILE
/]
	PSOUT
	DTACH			; CAUSE SPECJL TO START A NEW EXEC
	CALL SPECJL		; PRETEND THIS WAS LAST TASK
	JRST SPECLO		; GO LOGOUT

SPECJN:	BIN			; SKIP TO NON-SEPARATOR
	JUMPE 2,SPECJ7		; NULL == EOF, FINISH UP
	CAIG 2,40		; SPACE OR LESS IS TO BE SKIPPED
	 JRST SPECJN
	RFPTR			; GET WHERE WE ARE AT
	 JFCL
	SOS 2			; MINUS ONE
	MOVEM 2,AUTONX		; IS NEXT PACE TO START
	CLOSF			; DONE WITH AUTOJOBS FILE
	 JFCL
	MOVEI 2,CTYLIN
	CALL SPCSTJ		; THEN START UP NEXT ON CTYLIN
	RET			; CONTINUE STARTING THIS TASK

SPECJ7:	CLOSF			; CLOSE AUTOJOBS FILE
	 JFCL
SPECJL:	move a,dbugsw
	cain 1,2		;let settim run if not debug
	 jrst specj1		;continue if debug
	movei	1, ^D20000	; This lets SETTIM do its thing before users
	disms			; have a chance to get on and set the time.
specj1:	MOVE 3,[CHKDSE]		;CHECK DEBUG AND ERROR CONDITIONS
	MOVE 1,DBUGSW
	TDZN 3,FACTSW		;IF DSK ERRORS, CLEAR 3 AND SKIP
	CAIN 1,2		;IF DEBUGSW AT 2, DONT ALLOW ON.
	JRST	.+4		;ONE OR THE OTHER FAILED *** SRI-AIC ***
	SETO	3,		;PERMIT ENTRIES NOW,	 *** SRI-AIC ***
	SKIPG	ENTFLG		;BUT NOT IF ENTFLG ALREADY SET *** SRI-AIC ***
	SETOM	ENTFLG		;OK			  *** SRI-AIC ***
	HRROI 2,TNAMS2		;NOT AVAIL MSG, DEBUGGING
	CAIE	1,2
	HRROI 2,TIOMSG		;TENEX IN OPERATION MSG
	SKIPN 3
	HRROI 2,TNAMS1
	SKIPL ENTFLG			;DISK ERRORS?
	HRROI 2,TNAMS2		;YES. NOT AVAIL MSG DSK ERRORS.
	SETO 1,
	TTMSG
	GTAD			;IF WE NEED TIME AND DATE
	JUMPGE 1,R
	MOVEI 2,CTYLIN		; START JOB ON CTY
	CALL SPCSTJ
	RET

SPCSTJ:	NOSKED			;PREVENT RACE ON TTY STARTUP
	SKIPGE 1,TTFORK(2)	;IS THERE A JOB EXTANT
	TLNN 1,1		; OR STARTING ON THIS LINE?
	JRST 	[OKSKED		; YES
		RET]		; NOT ANOTHER.
	MOVSI 1,-2		;NO.. FLAG STARTING ONE.
	HLLM 1,TTFORK(2)	; ..
	MOVEI 1,JOBSRT
	HRL 1,2
	CALL SCDRQ7		;START JOB ON CTY TO GET T&D
	OKSKED
	RET

TNAMS1:	ASCIZ /
**** Tenex not available: Disk needs fixing.
/
TNAMS2:	ASCIZ /
**** Tenex not available.
/
TIOMSG:	ASCIZ /
**** Tenex in operation!
/

;GET SWAPPABLE MONITOR

 RESCD

GETSWM:	PUSH P,NPMAX		;SAVE CURRENT MAX SIZE
	MOVE 1,TOTRC
	MOVEM 1,NPMAX		;ALLOW ALL OF CORE WHILE GETTING SWM
	MOVEI 7,SWPMP0		;FIRST PAGE OF SWM
	NOSKED
LOKSM1:	MOVEI 2,0(7)
	LSH 2,^D9
	SKIP 0(2)		;REF THE PAGE THEREBY ASSIGNING IT
	MOVEI 1,0(7)
	HRL 1,MMSPTN
	PUSH P,7
	CALL MLKPG		;LOCK THE PAGE
	POP P,7
	CAMGE 7,SWCEND		;HIGHEST PAGE OF SWM
	AOJA 7,LOKSM1
	MOVSI 1,1
	SOJG 1,.		;WAIT AWHILE FOR DRUM OPS TO COMPLETE
	PIOFF			;TO PREVENT DATA LATE
	MOVEM P,TW1
	JSR TENDMP		;CALL TO INTERPRET PRE-STORED STRING
	MOVE P,TW1
	PION

;GETSWM ...

LOKSM3:	MOVSI 6,WRITEB		;SET TO CLEAR WRITE BIT FROM MMAP
	MOVE 1,DBUGSW
	CAIN 1,2		;BUT IF DBUGSW = 2,
	SETZ 6,			;LEAVE IT WRITABLE
	MOVEI 7,SWPMP0
ULKSM1:	ANDCAM 6,MMAP(7)	;CLEAR ANY UNWANTED ACCESS
	MOVEI 1,0(7)
	HRL 1,MMSPTN
	CALL MULKPG		;UNLOCK THE PAGES
	CAMGE 7,SWCEND
	AOJA 7,ULKSM1
	OKSKED
	POP P,NPMAX		;RESTORE NORMAL MAX SIZE
	MOVE 1,DBUGSW		;SHOULD WE FLUSH DDT ?
	IOR 1,DCHKSW
	SKIPN 1
	CALL DDTFSH		;YES
	RET

;SWCEND IS SET BY POSTLD TO CONTAIN THE NUMBER OF THE HIGHEST
;PAGE CONTAINING SWAPPABLE CODE

SWCEND:	0
 SWAPCD

;FLUSH DDT AND SYMBOL TABLE AND MAKE PAGES AVAILABLE FOR SWAPPING
;RESIDENT DDT AND ITS SYMBOL TABLE CAN BE FLUSHED SEPARATELY
;THE CONTENTS OF CELL SYMDDT CONTROL WHAT GETS FLUSHED AS FOLLOWS
; C(SYMDDT)=0 MEANS FLUSH DDT AND SYMBOL TABLE
; C(SYMDDT)<>0 MEANS FLUSH SYMBOL TABLE ONLY
;THE FOLLOWING TWO CELLS DEFINE THE CURRENT STATUS
;  DDTPRS=0 MEANS DDT IS RESIDENT
;  SYMPRS=0 MEANS THE SYMBOL TABLE IS RESIDENT
;(NOTE THAT THE CODE WILL NOT ALLOW FOR A RESIDENT SYMBOL TABLE AND
;  A NON-RESIDENT DDT)

 RESCD
SYMDDT:	0
 SWAPCD

DDTFSH:	PUSH P,3		;SAVE REGISTERS
	PUSH P,2
	PUSH P,1
	NOINT			; PREVENT CONFUSION
	SETOM SYMPRS		; NO SYMBOLS
	SETZM SWPSTP		; CAUSE ANY MDDT'S TO TO FORGET SYMTAB
	SETZM 32		; NO RESIDENT SYMBOL TABLE
	SETZM 36
	SKIPE SYMDDT		;FLUSH SYMBOLS ONLY ?
	JRST [	HRRZ 1,SAVE36	;COMPUTE STARTING FLUSH ADDRESS
		MOVEI 3,777(1)	; AS FIRST PAGE .GE. SYMTAB BEG
		LSH 3,-^D9	; CONVERT ADDRESS TO PAGE NUMBER
		JRST DDTFS1]
	SETOM DDTPRS		; NO DDT
	MOVE 1,[JRST 4,100]	;CHANGE 100 DISPATCH
	MOVEM 1,100
	HRRZ 3,MONCOR		; START FLUSHING HERE
DDTFS1:	PUSH P,3		; SAVE FIRST PAGE
	MOVSI 2,(01B5)
DDTFSL:	SETZ 1,
	NOSKED			; INSURE CONSISTENT MMAP/CST0
	EXCH 1,MMAP(3)
	SKIPE 1
	MOVEM 2,CST0(3)		; MARK AS UNAVAILABLE
	OKSKED
	AOS 3
	CAMGE 3,RCADDT
	 JRST DDTFSL
	POP P,1			; FIRST PAGE FLUSHED
	MOVE 2,RCADDT
	SOS 2			; LAST PAGE FLUSHED
	CALL MKPGSA		; MAKE THEM ALL AVAILABLE
	OKINT
	POP P,1			;RESTORE REGISTERS
	POP P,2
	POP P,3
	RET			;RETURN

RCADDT:	0		;SAVE ADDRESS OF SWPCOR
SAVE36:	0		;SAVED LOCATION 36 (SYMBOL POINTER)
SAVE32:	0		;SAVED LOCATION 32 (UNDEF SYMBOL POINTER)

MKPGSA:	CALL MAKPGA		; CALL ROUTINE IN PAGEM
	RET

MKPGSU:	PUSH P,1		;SAVE ARGS
	PUSH P,2
	CALL MAKPGU		; ROUTINE IN PAGEM
	 JRST MKPSU1
	SUB P,BHC+2		;ADJUST STACK
	RET

MKPSU1:	HRRZ 2,1		;NUMBER OF PAGES LOCKED
	HLRZS 1			;LOCKED PAGE
	PUSH P,1		;STACK THE LOCKED PAGE
	MOVEI 1,101		;TTY OUTPUT
	MOVEI 3,12		;DECIMAL   ***SRI-AI***
	NOUT			;NUMBER OF LOCKED PAGES
	  JFCL
	HRROI 1,MKPSU2		;MESSAGE
	PSOUT
	POP P,2			;GET BACK LOCKED PAGE NUMBER
	MOVEI 1,101
	NOUT
	  JFCL
	HRROI 1,[ASCIZ /
/]
	PSOUT
	HRLZ 1,2		;SET UP DISMISS TILL PAGE UNLOCKED
	HRRI 1,PLCKT		; ..
	JSYS EDISMS		;WAIT
	POP P,2			;GET BACK ARGS
	POP P,1			; ..
	JRST MKPGSU		;TRY AGAIN
MKPSU2:	ASCIZ / PAGES LOCKED. WAITING FOR PAGE /

;MAP DDT FROM IMAGE FILE

GETDDT:	SKIPE GOTDDT		;GOT DDT NOW?
	RET			;YES
	MOVSI 1,(1B2+1B17)	;OLD FILE, SHORT FORM
	HRROI 2,[ASCIZ /<SYSTEM>MDDT2.SAV/]
	GTJFN
	JRST NODDT
	MOVE 2,[44B5+1B19]	;36-BIT READ
	OPENF
	JRST NODDT
	BIN			;FIRST WORD IS XWD -LENGTH,LOC
	HLRE 3,2		;GET LENGTH
	CAMGE 3,[-LMDDT]	;OUR SPACE BIG ENOUGH?
	JRST [	CLOSF		;NO
		JFCL
		MOVEI 1,[SIXBIT '$MDDT TOO BIG$/']
		JRST NODD2]
	HLLZ 7,2		;SETUP OUR AOBJN PTR
	MOVEI 2,0(2)		;SEE IF LOC IS CORRECT
	CAIE 2,MDDT
	JRST [	CLOSF		;WRONG-MUST BE REASSEMBLED
		JFCL
		MOVEI 1,[SIXBIT '$MDDT AT WRONG LOCATION$/']
		JRST NODD2]
	BIN
	MOVEM 2,MDDT(7)		;STORE MDDT CODE IN PRIVATE PAGE, BUT
	AOBJN 7,.-2		;CODE WILL BE USED BY ALL PROCESSES
	CLOSF
	JFCL
	NOINT
	MOVE 1,[XWD -LMDDT,MDDT]
	ASH 1,-^D9
	MOVSI 2,WRITEB
	ANDCAM 2,MMAP(1)	;WRITE-PROTECT ALL MDDT PAGES
	AOBJN 1,.-1
	AOS GOTDDT
	OKINT
	RET

NODDT:	MOVEI 1,[SIXBIT '$NO MDDT FILE$/']
NODD2:	TMSG
	JRST NODD1

;READ IN MONITOR SYMBOL TABLE FROM FILE

GETMST:	MOVE 1,SVNUM		; SYSTEM VERSION NUMBER
	HRLI 1,(1B2+1B17)	; OLD FILE & SHORT FORM STRING
	HRROI 2,[SYSNAM(<ASCIZ \<SYSTEM>MONSYMS.>,<\>)]
	GTJFN
	JRST NOSYMS		;NO FILE
	MOVE 2,[44B5+1B19]	;36 BIT READ
	OPENF
	JRST [	RLJFN
		JFCL
		JRST NOSYMS]
	NOINT
	BIN			;GET XWD -LENGTH,ADDRESS
	HLRE 3,2
	MOVNI 7,SSTSIZ		;PROBLEM WITH NEGATIVE EXTERN...
	HRLZS 7			; ..
	MOVM 3,3		;POSITIVE OF LENGTH
	CAILE 3,SSTSIZ		;TOO BIG?
	MOVE 2,7		;YES, READ ONLY TO MAX
	HRRI 2,SWPST		;ADDRESS WHERE TABLE TO BE PUT
	MOVEM 2,SWPSTP
	MOVE 7,2
	BIN
	MOVEM 2,0(7)
	AOBJN 7,.-2
	OKINT
	CLOSF
	JFCL
NOSYMS:	RET

;WRITE MONITOR SYMBOL TABLE ONTO FILE
;CALLED WITH JSP 4,WMST

WMST:	HRROI 1,[ASCIZ /
SYMBOL TABLE LARGER THAN SWAPPABLE STORAGE ALLOCATED FOR IT.
/]
	HLRE 2,SWPSTP
	MOVM 2,2
	CAILE 2,SSTSIZ		;TOO LARGE?
	PSOUT			;YES, PRINT MESSAGE
	HRROI 1,[ASCIZ /
SYMBOL TABLE WRITTEN ON FILE /]
	PSOUT
	MOVE 1,SVNUM		; VERSION NUMBER OF THIS SYSTEM
	HRLI 1,(1B0+1B17)	; FOR OUTPUT & SHORT FORM STRING
	HRROI 2,[SYSNAM(<ASCIZ \MONSYMS.>,<\>)]
	GTJFN
	0
	MOVE 2,[44B5+1B20]
	OPENF
	0
	MOVE 2,1
	MOVEI 1,101
	SETZ 3,
	JFNS			;TYPE THE FILE NAME
	MOVE 1,2
	MOVE 2,SWPSTP
	BOUT			;OUTPUT -LENGTH,,ADR
	HLRE 3,2		;SET UP A SOUT COUNT
	HRLI 2,444400		;AND POINTER
	SOUT
	MOVEI 2,0		;APPEND A ZERO AS ENT VECTOR
	BOUT			;FOR IDDT, EXEC MERGE
	CLOSF
	JFCL
	JRST 0(4)

IFN PIESLC,<
;ROUTINE TO MAP PIE-SLICE GROUP DATA FILE

MAPGRP:	MOVSI 1,(1B2+1B17)	;OLD FILE + SHORT FORM
	HRROI 2,GRPFNM
	GTJFN
	 JRST MAPGR2

	PUSH P,1		;SAVE JFN
	MOVEI 2,1B19+1B20+1B25	;READ, WRITE AND THAWED
	OPENF
	 BUG (HLT,<MAPGRP - FAILED TO OPENF PIE-SLICE-GROUP.DATA>)

	MOVSI 4,-NGRPPG
	MOVEI 5,GRPFIL		;ADDRESS TO START MAPPING FILE

MAPGR1:	HRLZ 1,0(P)		;GET JFN
	HRRI 1,0(4)		;FILE PAGE NUMBER
	CALL JFNOFN		;CONVERT JFN,,PN TO OFN,,PN
	 BUG (HLT,<MAPGRP - JFNOFN FAILED ON PIE-SLICE-GROUP.DATA>)

	MOVEI 2,0(5)
	HRLI 2,READB+WRITEB
	CALL SETMPG		;MAP THE PAGE

	ADDI 5,1000
	AOBJN 4,MAPGR1		;GO BACK AND DO NEXT

	SUB P,BHC+1
	AOS PIEFLG		;INDICATE SUCCESSFUL MAPPING
	RET

MAPGR2:	BUG (CHK,<MAPGRP - FAILED TO GTJFN FOR PIE-SLICE-GROUP.DATA>)
	RET

GRPFNM:	ASCIZ /<SYSTEM>PIE-SLICE-GROUP.DATA/
>

	END ; OF SYSINI.MAC

