Google
 

Trailing-Edge - PDP-10 Archives - AP-4178E-RM - swskit-sources/mexec.mac
There are 53 other files named mexec.mac in the archive. Click here to see a list.
;<3A.MONITOR>MEXEC.MAC.36, 17-Aug-78 13:38:12, Edit by LCAMPBELL
;<3A.MONITOR>MEXEC.MAC.35, 17-Aug-78 12:28:41, EDIT BY LCAMPBELL
;FIX RACE IN CRJOB WHICH CAUSES WRONG AC'S TO BE PASSED OCCASIONALLY
; (MISSING MEXEC.MAC.34 HEADER LINE OMITTED BY cower)
;<3A.MONITOR>MEXEC.MAC.33, 16-Aug-78 14:43:43, EDIT BY COWER
;put check into getji to check that word number (ac3) not negative
;<3A.MONITOR>MEXEC.MAC.32, 28-Jul-78 15:20:51, Edit by ENGEL
;FIX TYPO
;<3A.MONITOR>MEXEC.MAC.31, 28-Jul-78 15:18:35, Edit by ENGEL
;ELIMINATE NOSKED AT LDTAC2+7 - FIXES ARPA DETACH PROBLEM
;<3A.MONITOR>MEXEC.MAC.30, 27-Jul-78 13:15:20, Edit by PORCHER
;FIX ILL WRITE TO CHECKPOINT PAGE AT USGIN7...
;<3A.MONITOR>MEXEC.MAC.29, 20-Jul-78 09:53:23, Edit by ENGEL
;FIX PROBLEM AT STCJB1 (HRRZM->MOVEM) ALSO CHANGE CAMN TO USE T3
;<3A.MONITOR>MEXEC.MAC.28, 11-Jul-78 13:42:09, Edit by PORCHER
;TCO # 1902 - MAKE JOB 0 UPDATE FULL PAGES IN CHECKPOINT FILE
;<3A.MONITOR>MEXEC.MAC.27, 13-Jun-78 13:30:07, EDIT BY MILLER
;SHUFFLE CODE AROUND GSMLER TO MAP MMAP INTO BOOT SPACE BEFORE LOCKING IT
;<3A.MONITOR>MEXEC.MAC.26,  3-Jun-78 17:03:20, Edit by GILBERT
;Suppress SSAVE flags to DDT typeout
;<3A.MONITOR>MEXEC.MAC.25, 31-May-78 15:09:01, EDIT BY BOSACK
;ADD XBIO GETTAB, NO MONSYM ENTRY (TEMP, 3A ONLY)
;<3A.MONITOR>MEXEC.MAC.24, 31-May-78 13:40:31, Edit by KIRSCHEN
;MAKE RESTART SYSERR ENTRY EVEN IF NO OPERATOR INPUT OF TIME AND DATE
;<3A-NEW>MEXEC.MAC.23, 30-May-78 10:29:04, Edit by FORTMILLER
;START BOOT AT LAST INSTRUCTION ON LAST PAGE
;<3A.MONITOR>MEXEC.MAC.21, 16-May-78 13:07:48, EDIT BY MILLER
;TCO 1887. ADD NSWPGS GETAB ENTRY
;<3A.MONITOR>MEXEC.MAC.20, 20-Apr-78 14:40:01, EDIT BY MILLER
;MAKE SURE T3 HAS DIR # IN IT AT ATACH6
;<3A.MONITOR>MEXEC.MAC.19,  9-Apr-78 01:56:47, Edit by BORCHEK
;CRJOB FIXES AT STCJB1
;<3A.MONITOR>MEXEC.MAC.18,  3-Mar-78 09:56:09, EDIT BY MILLER
;DETERMINE "LOW" MESSAGE BY COMPARING AGAINST SYWRND
;CLEAR THE WHOLE JSBSTK WHEN TERMINAL IS HUNG-UP
;<3A.MONITOR>MEXEC.MAC.16, 25-Jan-78 13:30:14, EDIT BY MILLER
;FIX TYPEO IN SYSJOB CHANGE
;<3A.MONITOR>MEXEC.MAC.15, 25-Jan-78 13:26:13, EDIT BY MILLER
;USE NEW RUNDIR ROUTINE TO RUN SYSJOB
;<3A.MONITOR>MEXEC.MAC.14, 25-Jan-78 12:48:19, EDIT BY MILLER
;RUN MOS DIAG IN JOB 0 AND AT SYSTEM STARTUP
;<3.SM10-RELEASE-3>MEXEC.MAC.13,  3-Jan-78 16:15:05, EDIT BY MILLER
;<3.SM10-RELEASE-3>MEXEC.MAC.12,  3-Jan-78 16:12:46, EDIT BY MILLER
;FIX MAPPING OF EPT FOR BOOT TO USE SETMPG
;<3-MONITOR>MEXEC.MAC.287, 13-Dec-77 16:23:59, Edit by HESS
;TCO 1889 - FIX TO SESSION END LOGGING
;<3.SM10-RELEASE-3>MEXEC.MAC.10,  6-Dec-77 20:50:30, EDIT BY MCCLURE
;CALL DUPINI
;<3.SM10-RELEASE-3>MEXEC.MAC.9,  5-Dec-77 12:59:52, EDIT BY MILLER
;DON'T RECORD "ALLOCATED BUT ZERO" PAGES
;<3.SM10-RELEASE-3>MEXEC.MAC.8,  5-Dec-77 12:18:05, EDIT BY MILLER
;MOVE SET UP FRO REQUEST TIME AND DATE TO DTESRV
;<3.SM10-RELEASE-3>MEXEC.MAC.7,  5-Dec-77 10:33:20, EDIT BY MILLER
;DON'T SAVE ALL ZERO PAGES.
;<3.SM10-RELEASE-3>MEXEC.MAC.6, 18-Nov-77 11:31:45, EDIT BY MURPHY
;<3.SM10-RELEASE-3>MEXEC.MAC.5, 10-Nov-77 23:48:37, EDIT BY BOSACK
;UPDATE DDTPRS IN ULKINI
;<3.SM10-RELEASE-3>MEXEC.MAC.4,  6-Nov-77 16:13:11, Edit by MCLEAN
;ADD CODE FOR RELOAD ON KS
;<3.SM10-RELEASE-3>MEXEC.MAC.3,  6-Nov-77 16:05:36, Edit by MCLEAN
;<3.SM10-RELEASE-3>MEXEC.MAC.2, 26-Oct-77 17:36:16, EDIT BY CROSSLAND
;FIX SO THAT SYSTEM GOING DOWN IN 2 HOURS MESSAGES OCCURS ONLY ONCE
;<3-MONITOR>MEXEC.MAC.282, 26-Oct-77 17:27:39, EDIT BY HURLEY
;INCREASE OVERHEAD PAGES DURING BOOT PHASE TO ALLOW MONMIN TO WORK
;<3.SM10-RELEASE-3>MEXEC.MAC.1, 24-Oct-77 17:11:33, EDIT BY MURPHY
;DON'T REQUEST TAD FROM FE
;<3-MONITOR>MEXEC.MAC.281, 20-Oct-77 16:37:01, EDIT BY CROSSLAND
;MAKE HALT MESSAGE ONLY COME OUT 2 HOURS BEFORE HALT
;<3-MONITOR>MEXEC.MAC.280, 20-Oct-77 13:10:58, EDIT BY HURLEY
;FIX ATTACH AC CLOBBERAGE
;<3-MONITOR>MEXEC.MAC.279, 12-Oct-77 13:58:54, EDIT BY KIRSCHEN
;UPDATE COPYRIGHT FOR RELEASE 3
;<3-MONITOR>MEXEC.MAC.278, 28-Sep-77 18:06:13, Edit by MCLEAN
;<3-MONITOR>MEXEC.MAC.277, 28-Sep-77 16:33:39, Edit by HESS
;TCO 1864 - FIX TO CHECKPOINT (LOST INFO)
;<3-MONITOR>MEXEC.MAC.276, 23-Sep-77 04:17:47, EDIT BY CROSSLAND
;FIX ATACH TO NOT CLOBBER FLAGS AND REPORT CORRECT TTY ON AT%NAT
;<3-MONITOR>MEXEC.MAC.275, 22-Sep-77 10:31:44, EDIT BY HURLEY
;FIX ATACH TO NOT WAIT 3 SECS IF NO PASSWORD WAS GIVEN
;<3-MONITOR>MEXEC.MAC.274, 21-Sep-77 23:35:28, EDIT BY CROSSLAND
;FIX CRJOB TO PASS ERROR FROM LSTERR BACK IF ERROR NOT IN AC1.
;<3-MONITOR>MEXEC.MAC.273,  9-Sep-77 17:32:52, EDIT BY HURLEY
;MAKE SYSERF BE A BUGCHK
;<3-MONITOR>MEXEC.MAC.272,  2-Sep-77 14:03:21, Edit by HESS
;TCO 1859 - FIX RACE AT CHKHSY FOR SYSTEM SHUTDOWN
;<3-MONITOR>MEXEC.MAC.271,  1-Sep-77 11:29:15, EDIT BY HURLEY
;MAKE RUNDDI SET PROCESS PRIORITY WORD
;<3-MONITOR>MEXEC.MAC.270, 25-Aug-77 13:26:04, EDIT BY HURLEY
;<3-MONITOR>MEXEC.MAC.269, 23-Aug-77 09:35:28, EDIT BY MILLER
;MORE Q3 FIX UPS
;<3-MONITOR>MEXEC.MAC.268, 23-Aug-77 09:33:15, EDIT BY MILLER
;FIX ALL REFERENCES TO Q3 BY INCLUDING ACVAR
;<3BOSACK>MEXEC.MAC.267, 22-Aug-77 23:54:20, EDIT BY BOSACK
;REPLACE LK/ULKDDT WITH LCK/ULKINI
;<3-MONITOR>MEXEC.MAC.266, 17-Aug-77 12:18:16, EDIT BY HURLEY
;<3-MONITOR>MEXEC.MAC.265, 15-Aug-77 18:47:37, EDIT BY HURLEY
;<3-MONITOR>MEXEC.MAC.264, 15-Aug-77 10:00:45, Edit by HESS
;FIX CPOINT TO CALL SETJSB WHILE NOSKED, CORRECT CHECKPOINT TIME
;<3-MONITOR>MEXEC.MAC.263, 11-Aug-77 17:13:17, EDIT BY HURLEY
;MAKE MEXEC LOOK UP X-SETSPD WHERE X IS THE RELEASE NUMBER
;<3-MONITOR>MEXEC.MAC.262, 11-Aug-77 09:51:13, EDIT BY HURLEY
;<3-MONITOR>MEXEC.MAC.261, 11-Aug-77 09:30:08, EDIT BY HURLEY
;MAKE SETSPD, EXEC, SYSJOB, AND MONNAM.TXT COME FROM SYSTEM:
;<3-MONITOR>MEXEC.MAC.260,  4-Aug-77 19:05:20, Edit by HESS
;CLEAR FB%NOD ON USAGE FILE UPON CLOSE
;<3-MONITOR>MEXEC.MAC.259,  4-Aug-77 18:43:00, EDIT BY HURLEY
;<3-MONITOR>MEXEC.MAC.258,  3-Aug-77 23:52:00, EDIT BY CROSSLAND
;RELEASE TIMER BLOCKS WHEN FORK 0 IS KILLED
;<3-MONITOR>MEXEC.MAC.257,  3-Aug-77 16:10:52, Edit by MACK
;MAKE THE CALL TO ENACT AT RUNDI1 GIVE CORRECT ERROR RETURN
;<3-MONITOR>MEXEC.MAC.256,  2-Aug-77 15:30:29, EDIT BY CROSSLAND
;FIX ILLEGAL MONITOR REFERENCE IN GET
;<3-MONITOR>MEXEC.MAC.255,  2-Aug-77 09:35:26, Edit by HESS
;ADD SETUP FOR CTIMON , CORRECT RECORD TYPE FOR CHECKPOINT MERGE
;<3-MONITOR>MEXEC.MAC.254,  2-Aug-77 01:51:36, EDIT BY CROSSLAND
;ADD FIFTH ARGUMENT TO GETAB MACROS SO NETWORK TABLE NAMES COULD STAY
; THE SAME
;<3-MONITOR>MEXEC.MAC.253, 30-Jul-77 01:46:15, EDIT BY CROSSLAND
;FIX RACE OF CRJANS BEING SET BY WRONG JOB
;<3-MONITOR>MEXEC.MAC.252, 29-Jul-77 11:03:57, Edit by HESS
;ADD MONITOR NAME & VERSION TO RESTART RECORD
;<3-MONITOR>MEXEC.MAC.251, 27-Jul-77 23:17:55, EDIT BY CLEMENTS.CALVIN
; Changed XBLTMU to BLTMU in STCRJB
;<3-MONITOR>MEXEC.MAC.250, 27-Jul-77 15:10:41, Edit by MACK
;CALL INTERNAL ROUTINE ENACT AT RUNDI1:
;<3-MONITOR>MEXEC.MAC.249, 24-Jul-77 22:31:25, EDIT BY CLEMENTS
;<3-MONITOR>MEXEC.MAC.248, 24-Jul-77 18:51:27, EDIT BY CLEMENTS
;<3-MONITOR>MEXEC.MAC.247, 24-Jul-77 13:24:38, EDIT BY CLEMENTS
;<3-NSW-MONITOR>MEXEC.MAC.2, 24-Jul-77 12:12:54, EDIT BY CLEMENTS
; Further editting repairs for CRJOB
;<3-NSW-MONITOR>MEXEC.MAC.1, 22-Jul-77 21:07:42, EDIT BY CLEMENTS
; Atach fixes
; Added logic to remember reason for LOGO
; Added logic to do PRARG for EXEC in startup of created job
; Add code to call LOGOMO at logout time
; Added LSTLGN (get last login D&T) to GETJI
; JSYS trap code support & CASHOF/CASHON around GETSWM
; Changes for TIMER
;<3-MONITOR>MEXEC.MAC.245, 21-Jul-77 12:18:05, Edit by HESS
;TCO 1844 - CHANGE TO SHUTDOWN MESSAGES
;<3-MONITOR>MEXEC.MAC.244, 20-Jul-77 15:41:29, Edit by MCLEAN
;ATTCH3'S CALL TO TTYDAS LOST THE ERROR CODE ON FAILURE RETURN
;<3-MONITOR>MEXEC.MAC.243, 20-Jul-77 14:59:24, Edit by HESS
;<3-MONITOR>MEXEC.MAC.242, 19-Jul-77 18:02:08, EDIT BY HURLEY
;<3-MONITOR>MEXEC.MAC.241, 15-Jul-77 15:31:58, Edit by HESS
;<3-MONITOR>MEXEC.MAC.240, 15-Jul-77 15:09:16, Edit by HESS
;<3-MONITOR>MEXEC.MAC.239, 15-Jul-77 12:05:58, Edit by HESS
;<3-MONITOR>MEXEC.MAC.238, 15-Jul-77 11:33:06, Edit by HESS
;MAKE EXPUNGE PROCESS A SEPARATE FORK, CHANGE IT TO USE RCDIR
;<3-MONITOR>MEXEC.MAC.237, 14-Jul-77 15:59:29, Edit by HESS
;USAGE FIXES
;<3-MONITOR>MEXEC.MAC.236, 14-Jul-77 12:13:57, Edit by HESS
;TURN NEW ACCOUNTING ON
;<3-MONITOR>MEXEC.MAC.235, 13-Jul-77 19:37:06, EDIT BY HURLEY
;<3-MONITOR>MEXEC.MAC.234, 13-Jul-77 13:35:32, Edit by HESS
;<3-MONITOR>MEXEC.MAC.233, 13-Jul-77 10:40:38, Edit by HESS
;<3-MONITOR>MEXEC.MAC.232, 12-Jul-77 17:45:58, Edit by HESS
;<3-MONITOR>MEXEC.MAC.230, 12-Jul-77 17:20:13, EDIT BY MILLER
;MADE LDET2 LOAD T2 BEFORE CALLING LCKTTY
;<3-MONITOR>MEXEC.MAC.229, 12-Jul-77 17:15:52, Edit by HESS
;<3-MONITOR>MEXEC.MAC.228, 11-Jul-77 16:42:40, Edit by HESS
;<3-MONITOR>MEXEC.MAC.227, 11-Jul-77 11:41:52, Edit by HESS
;ADD JOB 0 CHECKPOINT TIMER
;<3-MONITOR>MEXEC.MAC.226, 11-Jul-77 04:48:51, EDIT BY CROSSLAND
;MORE FIXES TO CRJOB
;<3-MONITOR>MEXEC.MAC.225,  8-Jul-77 12:00:00, Edit by HESS
;<3-MONITOR>MEXEC.MAC.224,  8-Jul-77 11:13:12, Edit by HESS
;<3-MONITOR>MEXEC.MAC.223,  7-Jul-77 16:18:55, Edit by HESS
;<3-MONITOR>MEXEC.MAC.222,  7-Jul-77 13:41:10, Edit by HESS
;<3-MONITOR>MEXEC.MAC.221,  7-Jul-77 13:13:33, Edit by HESS
;<3-MONITOR>MEXEC.MAC.220,  7-Jul-77 11:29:56, Edit by HESS
;<3-MONITOR>MEXEC.MAC.219,  7-Jul-77 09:49:50, Edit by HESS
;<3-MONITOR>MEXEC.MAC.218,  7-Jul-77 08:57:26, Edit by HESS
;<3-MONITOR>MEXEC.MAC.217,  7-Jul-77 08:10:34, Edit by HESS
;<3-MONITOR>MEXEC.MAC.216,  7-Jul-77 08:00:44, Edit by HESS
;<3-MONITOR>MEXEC.MAC.215,  6-Jul-77 15:51:09, Edit by HESS
;<3-MONITOR>MEXEC.MAC.214,  6-Jul-77 13:10:00, EDIT BY MILLER
;ADD CALL TO NSPINI IN START UP CODE
;<3-MONITOR>MEXEC.MAC.213,  5-Jul-77 16:48:08, EDIT BY HURLEY
;<3-MONITOR>MEXEC.MAC.212,  3-Jul-77 18:00:07, Edit by HESS
;<3-MONITOR>MEXEC.MAC.211,  1-Jul-77 14:32:11, Edit by MACK
;TCO 1822 - ENABLE ACCOUNT VALIDATION AT RUNDI1
;<3-MONITOR>MEXEC.MAC.210,  1-Jul-77 11:35:33, Edit by HESS
;<3-MONITOR>MEXEC.MAC.209, 30-Jun-77 17:03:49, Edit by HESS
;FIX ATTACH FOUL UP WITH LOGBUF REMOVAL
;<3-MONITOR>MEXEC.MAC.208, 30-Jun-77 07:17:46, EDIT BY CROSSLAND
;FIX BUG IN PROXY ATTACH AGAIN
;<3-MONITOR>MEXEC.MAC.207, 29-Jun-77 15:47:08, Edit by HESS
;<3-MONITOR>MEXEC.MAC.206, 27-Jun-77 17:02:22, Edit by HESS
;REMOVE LOGBUF AND ACCTPT AND CALLS TO EFACT
;<3-MONITOR>MEXEC.MAC.204, 27-Jun-77 12:03:33, EDIT BY HURLEY
;MOVED RESIDENT BUGHLT INFO TO APRSRV
;<3-MONITOR>MEXEC.MAC.203, 27-Jun-77 09:31:55, Edit by HESS
;<3-MONITOR>MEXEC.MAC.202, 27-Jun-77 09:20:18, Edit by HESS
;<3-MONITOR>MEXEC.MAC.201, 23-Jun-77 20:58:46, Edit by HESS
;MORE USAGE STUFF
;<3-MONITOR>MEXEC.MAC.200, 21-Jun-77 20:21:17, EDIT BY CROSSLAND
;FIX BUGS IN PROXY ATTACH AND CRJOB
;<3-MONITOR>MEXEC.MAC.199, 20-Jun-77 22:28:35, Edit by HESS
;TCO 1821 - JOB 0 PART OF USAGE FILE
;<3-MONITOR>MEXEC.MAC.198, 20-Jun-77 18:07:46, Edit by MACK
;TCO 1822 - ACTOFN AND ACTLCK INITIALIZED AT JBI0:
;<3-MONITOR>MEXEC.MAC.197, 20-Jun-77 12:28:14, Edit by MACK
;TCO 1822 - ADDED GETJI FUNCTION GETJSR TO RETRIEVE JOB SESSION REMARK
;<3-MONITOR>MEXEC.MAC.196, 13-Jun-77 03:12:19, EDIT BY CROSSLAND
;<3-MONITOR>MEXEC.MAC.195, 11-Jun-77 03:34:19, EDIT BY CROSSLAND
;MORE TCO 1742 ARPANET MERGING DEBUGING
;<2-PERF>MEXEC.MAC.154,  1-Jun-77 16:07:35, EDIT BY MURPHY
;<2-PERF>MEXEC.MAC.153, 26-May-77 14:44:09, EDIT BY HURLEY
;ADDED CONNECTED DIRECTORY NAME STRING TO JSB
;<3-MONITOR>MEXEC.MAC.193, 24-May-77 10:22:56, EDIT BY MILLER
;REMOVE EXTRANEOUS OKINT FROM ATACH
;<3-MONITOR>MEXEC.MAC.192, 19-May-77 04:49:34, EDIT BY CROSSLAND
;<3-MONITOR>MEXEC.MAC.191, 12-May-77 10:33:27, EDIT BY HURLEY
;MAKE FULL VERSION NUMBER BE PUT IN SYSERR BLOCKS
;<3-MONITOR>MEXEC.MAC.190, 10-May-77 13:10:35, EDIT BY HURLEY
;REMOVE "SWAPPING SPACE LOW MESSAGE"
;<3-MONITOR>MEXEC.MAC.189,  4-May-77 14:25:57, EDIT BY MILLER
;MAKE TTSPWD SWAPPABLE
;<3-MONITOR>MEXEC.MAC.188,  3-May-77 18:10:00, EDIT BY CROSSLAND
;MORE OF TCO 1742 MERGE ARPANET SOURCES
;<3-MONITOR>MEXEC.MAC.187, 29-Apr-77 16:21:08, EDIT BY HURLEY
;TURN OFF CACHE DURING BOOTING OF SWAPPABLE MONITOR
;<3-MONITOR>MEXEC.MAC.186, 26-Apr-77 12:24:25, EDIT BY MILLER
;MOVE NOSKED IN LDTACH2 TO AFTER THE TLINK JSYS
;<3-MONITOR>MEXEC.MAC.185, 15-Apr-77 11:31:35, EDIT BY HALL
;TCO 1740 - MAKE DTACH DO A DOBE BEFORE RELEASING BUFFERS
;<3-MONITOR>MEXEC.MAC.184, 14-Apr-77 17:05:07, EDIT BY HALL
;TCO 1740- MAKE ATTACH AND DETACH LOCK DEVICE LOCK BEFORE CALLING TTYDAS
;<3-MONITOR>MEXEC.MAC.183, 13-Apr-77 17:24:18, EDIT BY MILLER
;MAKE UNATTACH INTERRUPTABLE
;<3-MONITOR>MEXEC.MAC.182,  4-Apr-77 09:52:36, EDIT BY HALL
;TCO 1740 - BUG FIX IN PREVIOUS EDIT
;<3-MONITOR>MEXEC.MAC.181,  1-Apr-77 17:09:58, EDIT BY HALL
;TCO 1740 - MAKE LOGJOB TAKE A LINE NUMBER SO DETACH WON'T CALL DETMSG NOSKED
;<3-MONITOR>MEXEC.MAC.180, 29-Mar-77 14:31:04, EDIT BY HALL
;CHANGE MS%ASG TO MI%ASG
;<3-MONITOR>MEXEC.MAC.179, 29-Mar-77 10:53:14, EDIT BY MILLER
;TCO 1766 . FIX GET FOR RANGE SPECIFIED
;<3-MONITOR>MEXEC.MAC.178, 16-Mar-77 14:07:19, Edit by MCLEAN
;CHANGE DTEINI TO PROINI --- SEE DTESRV
;<3-MONITOR>MEXEC.MAC.177, 14-Mar-77 16:10:34, EDIT BY HALL
;AT SYSINE WHEN TTYASN FAILS, SEND 'FULL' IF POSSIBLE
;<3-MONITOR>MEXEC.MAC.176, 13-Mar-77 03:00:54, Edit by MCLEAN
;INSERT CALL TO RQTAD1
;<3-MONITOR>MEXEC.MAC.175, 13-Mar-77 00:21:29, Edit by MCLEAN
;REMOVE SOME MORE DTFLG CONDITIONALS
;<3-MONITOR>MEXEC.MAC.174, 11-Mar-77 16:13:18, EDIT BY HALL
;TCO 1740 - BUG FIX IN GETJI WHEN TTY SPECIFIED
;<3-MONITOR>MEXEC.MAC.173, 10-Mar-77 15:11:25, EDIT BY HALL
;TCO 1740 - FIXED ATTACH TO SEND MESSAGE TO ONLY THE LINE THAT IT
;IS DETACHING (WAS SENDING TO ALL)
;<3-MONITOR>MEXEC.MAC.172,  9-Mar-77 16:04:28, EDIT BY HALL
;TCO 1740 - MAKE DETACH INTERRUPTIBLE WHEN WAITING FOR TELETYPE
;	LOCK COUNT TO GO TO ZERO
;<3-MONITOR>MEXEC.MAC.171,  5-Mar-77 16:47:27, Edit by MCLEAN
;<3-MONITOR>MEXEC.MAC.170, 28-Feb-77 04:44:04, EDIT BY CROSSLAND
;TCO 1745  EXTEND ATTACH TO ALLOW ATTACHING OF TERMINAL OTHER
;THAN CONTROLLING TERMINAL
;TCO 1743  ADD CRJOB
;TCO 1742 MERGE ARPANET SOURCES
;<3-MONITOR>MEXEC.MAC.169, 23-Feb-77 20:03:18, EDIT BY HALL
;TCO 1740 - MAJOR CHANGES TO ATACH, DTACH, SYSINE
;<3-MONITOR>MEXEC.MAC.168, 19-Feb-77 10:58:30, EDIT BY MILLER
;MAKE GTTAB ABLE TO TAKE A SUBROUTINE
;<3-MONITOR>MEXEC.MAC.167, 16-Feb-77 15:33:13, EDIT BY HURLEY
;<3-MONITOR>MEXEC.MAC.166, 14-Feb-77 15:15:24, EDIT BY HURLEY
;ADD CALLS TO LOCK OR UNLOCK RESIDENT FREE SPACE AS NEEDED
;<3-MONITOR>MEXEC.MAC.165,  8-Feb-77 01:47:58, Edit by MCLEAN
;REMOVE DTFLG CONDITIONALS
;<3-MONITOR>MEXEC.MAC.164,  7-Feb-77 19:16:16, EDIT BY HURLEY
;ADD SUPPORT FOR UTEST JSYS
;<3-MONITOR>MEXEC.MAC.163,  4-Feb-77 17:25:42, Edit by MCLEAN
;TCO 1723 SM10 ADDITIONS
;<3-MONITOR>MEXEC.MAC.162, 31-Jan-77 01:42:30, Edit by MCLEAN
;<3-MONITOR>MEXEC.MAC.161, 19-Jan-77 17:19:48, EDIT BY HURLEY
;TCO 1717 - MAKE JOB 0 ALWAYS STAY IN HIGHEST RUN QUEUE
;<3-MONITOR>MEXEC.MAC.160, 16-Jan-77 00:05:27, Edit by MCLEAN
;<3-MONITOR>MEXEC.MAC.159, 11-Jan-77 14:48:20, EDIT BY MILLER
;TCO 1709. FIX COMPUTATION AT GSMDSK FOR LOADING SWPMON.
;<3-MONITOR>MEXEC.MAC.158, 30-Dec-76 00:20:09, Edit by MCLEAN
;<3-MONITOR>MEXEC.MAC.157, 29-Dec-76 22:44:43, Edit by MCLEAN
;<3-MONITOR>MEXEC.MAC.156, 27-Dec-76 17:34:38, EDIT BY HURLEY
;<3-MONITOR>MEXEC.MAC.155, 20-Dec-76 14:25:32, EDIT BY MILLER
;MAKE GETJI NOSKED WHILE IT IS MAPPING OTHER JOB'S JSB
;<3-MONITOR>MEXEC.MAC.154,  9-Dec-76 13:12:04, EDIT BY MILLER
;IF DDMP FAILS BECAUSE OF STRLOK, RERUN ASAP
;<3-MONITOR>MEXEC.MAC.153,  6-Dec-76 00:58:04, Edit by MCLEAN
;<3-MONITOR>MEXEC.MAC.152, 27-Nov-76 23:33:00, Edit by MCLEAN
;<3-MONITOR>MEXEC.MAC.151, 27-Nov-76 22:07:00, Edit by MCLEAN
;<3-MONITOR>MEXEC.MAC.150, 26-Nov-76 19:45:10, Edit by MCLEAN
;TCO 1669 EXTENDED ADDRESSING
;<2-MONITOR>MEXEC.MAC.148, 23-Nov-76 10:29:45, Edit by MACK
;<2-MONITOR>MEXEC.MAC.147, 16-Nov-76 17:40:31, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.146, 16-Nov-76 16:18:17, EDIT BY BOSACK
;TCO 1664 - HANDLE FKHPTN NONSKIP RETURNS
;<2-MONITOR>MEXEC.MAC.145, 16-Nov-76 14:52:42, Edit by MACK
;TCO 1666 - INITIALIZE LOCAL TIME ZONE AT JBI0
;<2-MONITOR>MEXEC.MAC.144, 16-Nov-76 12:22:14, EDIT BY MILLER
;<2-MONITOR>MEXEC.MAC.143, 15-Nov-76 13:44:43, EDIT BY MILLER
;TCO 1662. DO UNMAP ON ALLOCTAED BUT ZERO PAGES
;<2-MONITOR>MEXEC.MAC.142, 15-Nov-76 11:41:34, Edit by MACK
;INTERRUPT SYSTEM CLEARED FIRST AT RUNDD1 IF ANYTHING GOES WRONG
;<2-MONITOR>MEXEC.MAC.141, 12-Nov-76 10:06:05, EDIT BY HALL
;MORE OF PREVIOUS EDIT
;<2-MONITOR>MEXEC.MAC.140, 11-Nov-76 16:44:44, EDIT BY HALL
;TCO 1615 - (CONTINUATION OF MACK'S EDITS) - CHECK FOR SF%CDE IN
; FACTSW BEFORE CALLING SETSPD TO DO THE DUMP FILE
;ALSO MASSIVE REARRANGEMENT OF STARTUP CODE
;<2-MONITOR>MEXEC.MAC.139,  8-Nov-76 11:47:12, EDIT BY KIRSCHEN
;MAKE EXCLUSIVELY MOUNTED STR'S AVAILABLE ON LOGOUT OF MOUNTING JOB
;<2-MONITOR>MEXEC.MAC.138,  5-Nov-76 12:46:56, EDIT BY HALL
;FIX IN LOGBUF TO RESTORE .PRIOU TO T1 WHEN DIRST FAILS
;<2-MONITOR>MEXEC.MAC.137,  3-Nov-76 17:20:10, EDIT BY HURLEY
;FIX PARITY ERROR REPORTING TO GET JOB #, DIR #, AND PGM NAME
;<2-MONITOR>MEXEC.MAC.136,  3-Nov-76 14:21:29, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.135, 31-Oct-76 16:07:01, EDIT BY HELLIWELL
;ADD ERJMP'S IN RUNDII
;<2-MONITOR>MEXEC.MAC.134, 29-Oct-76 10:56:30, EDIT BY MILLER
;TCO 1636. CHANGE JOBCOF TO INDIRECTLY FREEZE/RESUME INFERIORS
;<2-MONITOR>MEXEC.MAC.133, 29-Oct-76 09:00:46, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.132, 29-Oct-76 08:59:19, EDIT BY HURLEY
;FIXED AUTOMATIC EXPUNGING TO WORK WITH RELEASE 2
;<2-MONITOR>MEXEC.MAC.131, 26-Oct-76 14:25:47, EDIT BY HALL
;CHANGE MESSAGE FROM MEXEC WHEN RUNNING CHECKD - NOW INDICATES
; WHAT IT IS DOING
;<2-MONITOR>MEXEC.MAC.130, 26-Oct-76 12:13:05, EDIT BY HURLEY
;FIX MX TO NOT LOG JOB OUT IF IT WAS EVER IN THE MINI-EXEC
;<2-MONITOR>MEXEC.MAC.129, 22-Oct-76 08:39:24, Edit by MACK
;TCO 1615 AGAIN
;<2-MONITOR>MEXEC.MAC.128, 21-Oct-76 23:10:09, EDIT BY HURLEY
;FIX SECOND CALL TO SETSPD TO START IT A ENTRY VECTOR +3
;<2-MONITOR>MEXEC.MAC.127, 21-Oct-76 19:58:35, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.126, 21-Oct-76 17:41:51, EDIT BY MILLER
;CHANGE GET JSYS TO USE PMAP FOR PRE-FAULTING
;<2-MONITOR>MEXEC.MAC.125, 21-Oct-76 16:01:05, EDIT BY HALL
;CHECK FOR MS%ASG BEFORE DECIDING TO RUN CHECKD
;<2-MONITOR>MEXEC.MAC.124, 21-Oct-76 15:06:20, Edit by MACK
;TCO 1615 - RUN SETSPD AGAIN AT RUNDE1:
;<2-MONITOR>MEXEC.MAC.123, 18-Oct-76 13:48:03, EDIT BY HURLEY
;FIX THE "NO ATTACH" FEATURE OF ATACH TO WORK UNDER REL 2
;<2-MONITOR>MEXEC.MAC.122, 16-Oct-76 10:29:25, EDIT BY HALL
;CHANGES TO SYSTEM STARTUP TO USE STARTF, REMOVE STOKF
;<2-MONITOR>MEXEC.MAC.121, 15-Oct-76 13:21:20, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.120, 14-Oct-76 19:42:54, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.119, 13-Oct-76 16:16:33, EDIT BY HURLEY
;TCO 1593 - REMOVE CFOBF FROM LOGOUT SEQUENCE
;<2-MONITOR>MEXEC.MAC.118, 12-Oct-76 15:44:49, EDIT BY HURLEY
;INCREASE THE SIZE OF THE RELOAD BUFFER TO HOLD THE MAX STRING
;<2-MONITOR>MEXEC.MAC.117,  7-Oct-76 21:07:49, Edit by MCLEAN
;<2-MONITOR>MEXEC.MAC.116,  7-Oct-76 14:22:20, Edit by MCLEAN
;<2-MONITOR>MEXEC.MAC.115,  7-Oct-76 14:12:42, Edit by MCLEAN
;TCO 1559 -- FIX PEEK TO CHECK CORRECT MONITOR PAGES
;<2-MONITOR>MEXEC.MAC.114,  5-Oct-76 12:00:46, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.113,  4-Oct-76 14:15:48, EDIT BY HURLEY
;TCO 1562 - BREAK LOGOUT LINE BEFORE DATE SO IT FITS IN 72 COLUMNS
;TCO 1561 - ADD LOUTX5 ERROR RETURN FOR LGOUT JSYS.
;<2-MONITOR>MEXEC.MAC.112,  1-Oct-76 16:41:20, EDIT BY HURLEY
;MADE CHKAC TAKE A STRING POINTER TO USER NAME
;<2-MONITOR>MEXEC.MAC.111,  1-Oct-76 10:39:39, EDIT BY KIRSCHEN
;DECREMENT MOUNT COUNT OF MOUNTED STR'S ON .LGOUT
;<2-MONITOR>MEXEC.MAC.110, 29-Sep-76 15:58:21, Edit by HESS
;REMOVE REFERENCES TO JSSTR
;<2-MONITOR>MEXEC.MAC.109, 27-Sep-76 14:26:36, Edit by HESS
;REMOVE MINI-EXEC COMMANS "INIT" "FIX" AND "MOUNT"
;<2-MONITOR>MEXEC.MAC.108, 27-Sep-76 13:55:33, Edit by HESS
;<2-MONITOR>MEXEC.MAC.107, 23-Sep-76 16:36:19, EDIT BY HALL
;MADE DONSJ NO LONGER START A JOB IF STOKF IS -1; NO LONGER CHECK
;FOR SYSTEM DATE AND TIME; ALWAYS SET SF%PTY AND SF%CTY IN LAST JOB
;<2-MONITOR>MEXEC.MAC.106, 16-Sep-76 17:07:13, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.105, 16-Sep-76 13:34:37, EDIT BY HURLEY
;ALLOW CHKAC TO TAKE STRINGS FOR DIRECTORY NAMES
;<2-MONITOR>MEXEC.MAC.104,  9-Sep-76 10:56:57, EDIT BY MILLER
;TCO 1513. CHECK FOR GET OVERLAYING EXISTING PAGES
;<2-MONITOR>MEXEC.MAC.103,  7-Sep-76 16:56:28, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.102,  2-Sep-76 17:18:28, EDIT BY HALL
;MADE PFCPJ0 STORE USER NUMBER IN SEBDAT+PT%USR
;<2-MONITOR>MEXEC.MAC.101,  2-Sep-76 14:38:21, EDIT BY MURPHY
;TCO #1508 - REARRANGE GTTAB TABLE POINTERS ASSEMBLY
;<2-MONITOR>MEXEC.MAC.100, 25-Aug-76 15:36:58, Edit by HESS
;TCO 1496 - SET UP DEFAULT USER NAME (USRNAM)
;<2-MONITOR>MEXEC.MAC.99, 25-Aug-76 13:25:08, EDIT BY HALL
;FIXED COMMENTS IN CHKAC TO REFLECT NEW ARGUMENT BLOCK FORMAT
;<2-MONITOR>MEXEC.MAC.98, 25-Aug-76 12:34:08, EDIT BY OSMAN
;<2-MONITOR>MEXEC.MAC.97, 20-Aug-76 15:23:33, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.96, 16-Aug-76 17:07:56, EDIT BY MURPHY
;TCO #1479 - ADD HQLAV, LQLAV TO GTTAB
;<2-MONITOR>MEXEC.MAC.95, 11-Aug-76 11:53:40, EDIT BY HURLEY
;FIXED DELDF TO USE NEW FORMAT OF ARGUMENTS
;<2-MONITOR>MEXEC.MAC.94,  6-Aug-76 09:36:05, EDIT BY HURLEY
;CHANGED CHKAC AND ATACH TO RELEASE 2 FORMAT
;<2-MONITOR>MEXEC.MAC.93,  4-Aug-76 15:11:32, EDIT BY HURLEY
;ADD .JILNO FUNCTION TO GETJI
;<2-MONITOR>MEXEC.MAC.92,  4-Aug-76 14:07:57, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.91,  3-Aug-76 22:48:46, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.90,  3-Aug-76 22:14:00, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.89,  3-Aug-76 20:23:21, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.88,  3-Aug-76 19:13:09, EDIT BY HURLEY
;EXPAND DIRECTORY NUMBERS TO 36 BITS
;<HESS>MEXEC.MAC.2, 28-Jul-76 17:12:46, Edit by HESS
;TCO 1478 - QUOTA CHECKING
;<2-MONITOR>MEXEC.MAC.86, 25-Jul-76 12:51:52, EDIT BY HALL
;FIXED TYPE ON EDIT TO EXEC2
;<2-MONITOR>MEXEC.MAC.85, 24-Jul-76 14:03:44, EDIT BY HALL
;FIXED TYPO IN PREVIOUS EDIT
;<2-MONITOR>MEXEC.MAC.84, 24-Jul-76 13:55:23, EDIT BY HALL
;EDITS TO THE FOLLOWING TO CHANGE THE LOCATION OF CONNECTED DIRECTORY
;AND GET CONNECTED STRUCTURE, TOO: EXEC2,.GTDAL,.LGOUT,.GTDAL,.GJINF,
;.GETJI
;<2-MONITOR>MEXEC.MAC.83, 24-Jul-76 12:11:30, EDIT BY HALL
;IN SYSINE WHEN HANDLING SPECIAL JOBS, CONNECTS TO PS:<OPERATOR>
;<2-MONITOR>MEXEC.MAC.82, 15-Jul-76 14:31:48, EDIT BY MILLER
;TCO 1469. MAKE DUMP ON FILE DO SSAVE
;<2-MONITOR>MEXEC.MAC.81,  7-Jul-76 19:59:36, EDIT BY HURLEY
;MORE FIXES TO TCO 1391
;<2-MONITOR>MEXEC.MAC.80, 28-Jun-76 09:58:24, EDIT BY KIRSCHEN
;ADD ADDRESS OF BAT BLOCK PAGE TO CHKBAT CALLING SEQUENCE
;<2-MONITOR>MEXEC.MAC.18, 23-Jun-76 11:42:24, EDIT BY HALL
;MOVED TEST FOR BTBFLG IN RUNDI1 TO BEFORE TEST FOR DBUGSW
;<2-MONITOR>MEXEC.MAC.17, 22-Jun-76 18:07:23, EDIT BY HALL
;CHANGED RUNDII TO ACCEPT OFFSET IN ENTRY VECTOR.  MAKE RUNDI1 RUN
;CHECKD IF REBUILDING BIT TABLE
;<2-MONITOR>MEXEC.MAC.16, 21-Jun-76 15:38:05, EDIT BY MILLER
;PERFORM MANUAL MERGE OF 1B EDITS
;<2-MONITOR>MEXEC.MAC.15, 21-Jun-76 13:01:18, EDIT BY MILLER
;MORE MANUAL MERGES
;<2-MONITOR>MEXEC.NEW.2, 21-Jun-76 12:58:51, EDIT BY MILLER
;<1B-MONITOR>MEXEC.MAC.77, 17-Jun-76 19:47:12, EDIT BY HURLEY
;<1B-MONITOR>MEXEC.MAC.76, 17-Jun-76 19:24:55, EDIT BY HURLEY
;MORE OF TCO 1426
;<1B-MONITOR>MEXEC.MAC.75, 17-Jun-76 18:28:06, EDIT BY HURLEY
;<1B-MONITOR>MEXEC.MAC.74, 17-Jun-76 15:08:07, EDIT BY HURLEY
;<1B-MONITOR>MEXEC.MAC.73, 17-Jun-76 15:04:26, EDIT BY HURLEY
;TCO 1430 - CHANGE FORMAT OF SYSTEM NAME TEXT STRING
;<1B-MONITOR>MEXEC.MAC.72, 17-Jun-76 10:32:29, Edit by MACK
;<1B-MONITOR>MEXEC.MAC.71, 17-Jun-76 10:27:38, Edit by MACK
;FURTHER FIX TO TCO #1426
;<1B-MONITOR>MEXEC.MAC.70, 16-Jun-76 19:16:29, EDIT BY HURLEY
;MORE OF TCO 1357
;<1B-MONITOR>MEXEC.MAC.69, 16-Jun-76 17:53:46, EDIT BY HURLEY
;TCO 1440 - ALLOW ALL OPERATIONS TO BE SUCCESSFUL TO NUL DEVICE
;<1B-MONITOR>MEXEC.MAC.68, 16-Jun-76 17:13:05, EDIT BY HURLEY
;MORE OF TCO 1357
;<1B-MONITOR>MEXEC.MAC.67, 16-Jun-76 16:31:10, Edit by MACK
;<1B-MONITOR>MEXEC.MAC.66, 16-Jun-76 14:58:40, EDIT BY HURLEY
;TCO 1357 - ALLOW ONLY ENABLED WHEELS TO GET INTO THE MINI EXEC
;<1B-MONITOR>MEXEC.MAC.65, 16-Jun-76 11:52:13, Edit by MACK
;<1B-MONITOR>MEXEC.MAC.64, 16-Jun-76 10:51:42, Edit by MACK
;TCO 1426 - ADD MESSAGE TO INFORM A TTY WHEN IT'S LOSING ITS JOB
;<1B-MONITOR>MEXEC.MAC.63, 15-Jun-76 23:44:11, EDIT BY OSMAN
;MORE OF TCO 1408
;<1B-MONITOR>MEXEC.MAC.62, 15-Jun-76 22:42:00, EDIT BY OSMAN
;MORE OF TCO 1391
;<1B-MONITOR>MEXEC.MAC.61, 14-Jun-76 19:25:52, EDIT BY HURLEY
;<1B-MONITOR>MEXEC.MAC.60, 14-JUN-76 16:03:22, EDIT BY HURLEY
;<1B-MONITOR>MEXEC.MAC.59, 14-JUN-76 13:41:56, EDIT BY JMCCARTHY
;TCO 1408 - ALLOW LGOUT OF PTY JOB BY CONTROLLING JOB
;<1B-MONITOR>MEXEC.MAC.58, 11-JUN-76 15:50:43, Edit by HESS
;	TCO 1400 - Upper/lower case message edit
;<1B-MONITOR>MEXEC.MAC.57, 11-JUN-76 10:06:03, EDIT BY JMCCARTHY
;TCO 1391 - ATACH SHOULD'T HAVE DIFFERENT PASSWORD REQUIREMENTS THAN 
;LOGIN
;<1B-MONITOR>MEXEC.MAC.56, 11-JUN-76 09:50:06, EDIT BY JMCCARTHY
;MORE OF TCO 1352
;<1B-MONITOR>MEXEC.MAC.55, 10-JUN-76 16:08:35, EDIT BY MURPHY
;TCO #1396 - AUTOMATIC EXPUNGE * IF DISK SPACE LOW
;<1B-MONITOR>MEXEC.MAC.54,  9-JUN-76 15:03:04, EDIT BY HURLEY
;TCO 1377 - MAKE GTDAL ITRAP IF DIR NUMBER IS ILLEGAL
;<1B-MONITOR>MEXEC.MAC.53,  9-JUN-76 09:56:06, EDIT BY HALL
;TCO 1363 - FIXED TYPOS
;<1B-MONITOR>MEXEC.MAC.52,  8-JUN-76 12:41:32, EDIT BY HALL
;TCO 1363 -ADDED ERROR HANDLING FOR BIN'S AND SIN'S IN GET
;<1B-MONITOR>MEXEC.MAC.51,  7-JUN-76 16:09:39, EDIT BY HALL
;TCO 1358 - CHANGE 'DRUM SPACE LOW' TO 'SWAPPING SPACE LOW'
;<1B-MONITOR>MEXEC.MAC.50,  7-JUN-76 15:42:44, EDIT BY HALL
;TCO 1357 - ALLOW ONLY WHEELS TO GET INTO THE MINI-EXEC
;<1B-MONITOR>MEXEC.MAC.49,  7-JUN-76 15:32:37, EDIT BY HALL
;TCO #1355 - CHANGE GETDMS TO LOOK FOR RMS.EXE INSTEAD OF DMS.EXE
;<1B-MONITOR>MEXEC.MAC.48,  7-JUN-76 14:18:02, EDIT BY HURLEY
;TCO # 1352 - MAKE DETACHED FORK TO NO LONGER WAIT ON DETACHED TTY
;<1B-MONITOR>MEXEC.MAC.51,  7-JUN-76 16:09:39, EDIT BY HALL
;TCO 1358 - CHANGE 'DRUM SPACE LOW' TO 'SWAPPING SPACE LOW'
;<1B-MONITOR>MEXEC.MAC.50,  7-JUN-76 15:42:44, EDIT BY HALL
;TCO 1357 - ALLOW ONLY WHEELS TO GET INTO THE MINI-EXEC
;<1B-MONITOR>MEXEC.MAC.49,  7-JUN-76 15:32:37, EDIT BY HALL
;TCO #1355 - CHANGE GETDMS TO LOOK FOR RMS.EXE INSTEAD OF DMS.EXE
;<1B-MONITOR>MEXEC.MAC.47, 26-MAY-76 12:55:54, EDIT BY MILLER
;TCO 1320. REFUSE ADVICE AT JOB INIT
;<2-MONITOR>MEXEC.MAC.12, 24-MAY-76 19:23:43, EDIT BY HALL
;MADE GETNAM SET GJ%OLD FOR MONNAM.TXT
;<1B-MONITOR>MEXEC.MAC.46, 19-MAY-76 12:57:38, EDIT BY MILLER
;TCO 1303. FIX CALL TO PREPG IN GET JSYS
;<1A-MONITOR>MEXEC.MAC.45,  6-APR-76 15:28:21, EDIT BY HURLEY
;<2-MONITOR>MEXEC.MAC.10, 14-MAY-76 09:27:14, EDIT BY KIRSCHEN
;REMOVE REFERENCES TO LSTDRN (REMOVE FROM GETAB TABLE)
;<2-MONITOR>MEXEC.MAC.9, 10-MAY-76 11:36:20, EDIT BY KIRSCHEN
;ASSUME STRUCTURE # 0 IN CALLS TO SETDIR FROM .GTDAL AND .CHKAC
;<2-MONITOR>MEXEC.MAC.8, 10-MAY-76 10:24:22, EDIT BY HALL
;RESTORED CALL TO CHKBAT FOR STRUCTURE 0
;<2-MONITOR>MEXEC.MAC.7,  8-MAY-76 13:52:41, EDIT BY HALL
;TEMPORARY SETZ OF T1 BEFORE CALL TO DSKRBS
;<2-MONITOR>MEXEC.MAC.4, 19-APR-76 17:43:26, EDIT BY HALL
;MOVED CALLS TO CHKBT,CHKBAK,CHKBAT TO FILINI
;<2-MONITOR>MEXEC.MAC.3, 19-APR-76 15:57:30, EDIT BY MILLER
;CHANGED MINI-EXEC CALL TO SETBTF TO WRTBTB
;<2-MONITOR>MEXEC.MAC.2, 19-APR-76 15:07:38, EDIT BY HALL
;DELETED CALL TO MAPBTF
;<2-MONITOR>MEXEC.MAC.1,  5-APR-76 19:27:06, EDIT BY MILLER
;MADE SWPMWP CALL MMAPWP, SWPMWE CALL MMAPWE
;<1MONITOR>MEXEC.MAC.44, 23-MAR-76 15:00:41, EDIT BY HURLEY
;TCO 1204 - CLEAR TYPE AHEAD ON ERROR IN TIME AND DATE QUESTION
;<1MONITOR>MEXEC.MAC.43, 11-MAR-76 16:01:57, EDIT BY BOSACK
;TCO #1147 - PRINT SPACE LEFT IN DECIMAL.
;<1MONITOR>MEXEC.MAC.42,  5-MAR-76 18:38:06, EDIT BY MURPHY
;TCO #1097
;<1MONITOR>MEXEC.MAC.41,  2-MAR-76 13:53:57, EDIT BY MILLER
;TCO 1145. DISABLE DATASETS ON STARTUP
;<1MONITOR>MEXEC.MAC.40,  2-MAR-76 13:29:12, EDIT BY HURLEY
;TCO #1144 - CHANGE RETBAD TO RETERR IN CHKAC
;<1MONITOR>MEXEC.MAC.39,  1-MAR-76 17:57:11, EDIT BY HURLEY
;TCO 1138 - MAKE GTDAL HANDLE ERJMP'S
;<1MONITOR>MEXEC.MAC.38,  1-MAR-76 14:02:31, EDIT BY MILLER
;TCO 1133. CLEAR PAGE MODE ON LOGOUT AND DETACH
;<1MONITOR>MEXEC.MAC.37, 27-FEB-76 10:53:56, EDIT BY HALL
;cleanup of messages
;<1MONITOR>MEXEC.MAC.36, 26-FEB-76 17:32:08, EDIT BY MURPHY
;MORE #1097
;<1MONITOR>MEXEC.MAC.35, 26-FEB-76 15:27:26, EDIT BY HALL
;TCO #1110 - CHECK DEVICE FOR SAVE AND SSAVE
;<2MONITOR>MEXEC.MAC.34, 16-FEB-76 15:37:50, EDIT BY MURPHY
;TCO #1097 - INCREASE FREE MONITOR VAS
;<2MONITOR>MEXEC.MAC.33, 19-JAN-76 12:19:28, EDIT BY MURPHY
;<2MONITOR>MEXEC.MAC.32,  9-JAN-76 11:14:46, EDIT BY HALL
;<2MONITOR>MEXEC.MAC.31,  8-JAN-76 18:23:38, EDIT BY HURLEY

;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1977 BY DIGITAL EQUIPMENT CORPORATION

	SEARCH PROLOG,SERCOD,ACTSYM
	TTITLE MEXEC

;SWAPPABLE MONITOR ROUTINES, JSYS'S, ETC. - D. MURPHY


;AC DEFINITIONS USED HEREIN

DEFAC (FX,Q3)			;FORK INDEX

WRMSGF::-1			;SEND WARNING MESSAGES TO USERS IF NON-0
LOGDES::LOGTTY			;DESIGNATOR FOR LOG MSGS - DEF IN PARAMS
JB0TT::				;DESIG FOR JOB 0 AND ERR MSGS (STORED IN TTINIT)
SWCEN0::0			;END OF SWAP CODE, SET BY POSTLD
SWCEND::0			;END OF SWPMON SEGMENT, SET BY POSTLD

	SWAPCD

BUGTP::	0			;BUGTABLE POINTER, SET BY POSTLD

;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

	RESCD
;CODE TO INITIALIZE JOB ON FIRST STARTUP.  ALSO INVOKES SYSTEM
;INITIALIZATION IF FIRST JOB AFTER SYSTEM STARTED FROM SCRATCH
;SYSIFG IS 0 WHEN SYSTEM IS JUST STARTING

EXEC0::	MOVX 1,LOGIOB		;SAY JOB CREATION IN PROGRESS
	IORM 1,JOBBIT
	SETZM FPC
	MOVSI 1,(UMODF)		;SIMULATE CALL FROM USER
	MOVEM 1,FFL
	MCENTR
	SKIPE SYSIFG		;NEW SYSTEM?
	JRST GOTSWM		;NO
	CALL SEBINI		;INIT SYSERR FACILITY
	CALL FSIINI		;GO MOUNT THE PUBLIC STRUCTURE
	CALL SWPINI		;SWAPPER CAN NOW BE INITIALIZED
				;IT MUST BE CALLED AFTER NSSUN AND
				;  THE SDB FOR PS ARE SET UP BY FSIINI
	MOVEI T1,PSNUM		;T1/ STRUCTURE NUMBER (PUBLIC STRUCTURE)
	MOVEI T2,BUTPGA		;T2/ ADDRESS OF PAGE TO USE FOR BAT BLOCKS
	CALL CHKBAT		;AND NOW THE BAT BLOCKS CAN BE CHECKED
				; AND THE OVERFLOW SWAPPING ADDRESSES
				; IN THE BAT BLOCKS PROCESSED
REPEAT 1,<			;TEMPORARY UNTIL REV 10 IS IN
	PUSH P,CASHF		;TURN OFF THE CACHE
	CALL CASHOF		;THIS REDUCES PROBLEMS CAUSED BY MAP INST
>
	CALL GETSWM		;GET SWAPPABLE MONITOR
REPEAT 1,<			;TEMPORARY UNTIL REV 10 IS IN
	POP P,CASHF		;RESTORE CACHE 
	SKIPE CASHF		;WAS CASH ON BEFORE?
	CALL CASHON		;YES, TURN IT BACK ON
>
	CALL RESLCK		;LOCK DOWN SOME RESIDENT FREE SPACE

;AT THIS POINT THE SWAPPABLE MONITOR HAS BEEN LOADED. IF IT IS DESIRABLE
;  TO PATCH THE SWAPPABLE MONITOR A BREAKPOINT CAN BE PUT HERE.  NO
;  PART OF THE SWAPPABLE MONITOR WILL HAVE BEEN EXECUTED YET.

;INITIALIZE THE FORK STRUCTURE FOR THIS JOB. ASSIGN FIRST WORD OF FKPTRS
;AND SYSFK TO THIS FORK. MAKE EACH REMAINING WORD OF FKPTRS POINT TO NEXT
;AVAILABLE SLOT AND FREJFK POINT TO THE FIRST AVAILABLE SLOT
;INITIALIZE REMAINING WORDS OF SYSFK TO -1

GOTSWM:	MOVEI 1,FKPTRS		;1/NAME OF FORK STRUCTURE LIST
	MOVEI 2,NUFKS		;2/NUMBER OF WORDS IN LIST
	CALL ILIST		;INITIALIZE FREE WORDS IN FKPTRS
	MOVE 1,0(1)		;POINT TO SECOND FREE SLOT
	MOVEM 1,FREJFK		;MAKE FREE LIST START WITH SECOND SLOT
	SETZM FKPTRS		;TAKE FIRST SLOT FO THIS FORK
	MOVE 1,FORKX		;GET SYSTEM-WIDE INDEX FOR THIS FORK
	MOVEM 1,SYSFK		;STORE IN JOB STORAGE AREA
	MOVE 1,[XWD SYSFK+1,SYSFK+2]
	SETOM -1(1)		;INIT REMAINDER OF SYSFK TABLE
	BLT 1,SYSFK+NUFKS-1
	MOVE T1,[JTBIFR]	; Initialize JTB free bit table
	MOVEM T1,JTBFRE		;  ..
	SETOM FKLOCK		;INIT FORK LOCK FOR THIS JOB

;SET UP FOR INTERRUPTS TO BE PROCESSED BY THE MONITOR
;IF AN INTERRUPT OCCURS ON A CHANNEL WHOSE BIT IS SET IN MONCHN,
;THE MONITOR WILL GO TO EXECI
;CHANNELS 34 AND 35 ARE ACTIVATED HERE, AND CTRL/P IS ASSIGNED
;TO THEM IN THE MINI-EXEC

	SETOM TTJTIW
	MOVE 1,[XWD ITFFL,EXECI] ;GO TO EXECI ON INTERRUPT
	MOVEM 1,MONBK
	MOVEI 1,400000		;1/THIS FORK
	MOVEI 2,3		;2/CHANNELS 34 AND 35
	MOVEM 2,MONCHN		;MAKE THE MONITOR TAKE INTERRUPTS ON THEM
	AIC			;ACTIVATE CHANNELS 34 AND 35

	JRST JBI0		;CONTINUE IN SWAPPABLE CODE
;JOB INITIALIZATION...
;SYSIFG IS 0 IF SYSTEM IS BEING STARTED

	SWAPCD

JBI0:	CALL JBFINI		;INIT FILE SYS FOR THIS JOB
	SKIPE SYSIFG		;SYSTEM INITIALIZED?
	JRST SYSINE		;YES

;SYSTEM IS BEING STARTED. DO ONCE-ONLY INITIALIZATION

	SETOM SYLNLK		;INIT SYSTEM LOGICAL NAME LOCK
	SETOM CRJLCK		;INIT LOCK OF CRJOB DATA BASE
	CALL FILINI		;INIT FILE SYSTEM
	SETOM TIMLCK		;INIT LOCK ON TIMER Q'S
	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
	MOVE T1,[JOBONT,,JOBONT+1]
	SETOM JOBONT		;NO JOBS ARE YET OWNED BY ANYONE
	BLT T1,JOBONT+NJOBS-1	; ..
	CALL PIDINI		;INITIALIZE THE IPCF DATA BASE AND FORKS
	CALL SLNINI		;INITIALIZE SYSTEM LOGICAL NAMES
	SETOM UTLOCK		;INITIALIZE THE UTEST JSYS DATA BASE
	CALL GETNAM		;INITIALIZE STRING CONTAINING
				; MONITOR VERSION AND NAME
	MOVEI T1,TMZONE		;INITIALIZE TIMZON
	MOVEM T1,TIMZON	
	SETOM ACTLCK		;INITIALIZE LOCK ON ACCT WINDOW PAGES
	SETOM ACTOFN		;NO OFN FOR ACCT VALIDATION DATA FILE YET
	SETOM AVALON		;ALWAYS TURN ON ACCT VALIDATION TILL STATED OTHERWISE
	; ..
;JOB INITIALIZATION...
;THIS CODE IS REACHED FOR ALL JOBS, INCLUDING FIRST ONE AFTER SYSTEM
;STARTUP

SYSINE:	MOVE T1,JOBNO		;INITIALIZE THE PID QUOTA
	CALL PIDJBI		;  AND SEND QUOTA
	CALL ENQJBI		;INITIALIZE ENQ/DEQ QUOTA
	MOVE T1,JOBNO		;GET JOB NUMBER
	SETZM CRJFLG		;ASSUME NOT A CREATE-JOB STARTUP
	HLRZ T2,JOBPT(T1)	;CHECK FOR SPECIAL STARTUP FLAG
	CAIE T2,-2		;FROM CRJOB?
	JRST SYSIN1		;NO. NORMAL STARTUP.
	MOVE T2,CRJTTY		;CRJOB. HERE IS THE REQUESTED TTY.
	HRLM T2,JOBPT(T1)	;PUT IT IN JOBPT OF NEW JOB.
	MOVEM T2,CTRLTT		;AND IN THE JSB
	SETOM CRJFLG		;FLAG IN JSB THIS IS A CRJOB STARTUP
SYSIN1:	JUMPL T2,SYSIN2		;JUMP IF JOB IS DETACHED
	CALL TTYASN		;ASSIGN CONTROLLING TTY
	 JRST SYSIN9
	MOVE T2,CTRLTT		;GET TTY NUMBER
	CALL TTCKSP		;GO SEE IF SPEED SETTING NEEDED
SYSIN2:	MOVE T1,TODCLK
	MOVEM T1,CONSTO		;SET CONSOLE TIME ON
	CALL LGTAD
	MOVEM T1,CTIMON		;SET DATE/TIME CONNECT
	MOVX T1,LOGIOB		;SAY JOB CREATION FINISHED
	ANDCAM T1,JOBBIT

;JOBS 0 THROUGH NSPECJ-1 ARE SPECIAL. SPECJT CONTAINS ADDRESS TO WHICH
;TO TRANSFER. FOR NOW, ONLY JOB 0 IS SPECIAL, AND IT GOES TO RUNDD.
;SEE IF THIS IS A SPECIAL JOB

	MOVE 1,JOBNO		;FIRST FEW JOBS ARE SPECIAL,
	CAIGE 1,NSPECJ		;IS THIS ONE OF THEM?
	JRST [	MOVEI 2,OPERDN	;YES, GET DIRECTORY NUMBER OF <OPERATOR>
		HRRM 2,JOBDIR(1) ;INDICATE LOGGED IN AS <OPERATOR>
		STOR 2,JSDIR	;SAVE AS CONNECTED DIRECTORY
		SETZRO JSCDF	;NO STRING IN JSB
		MOVE 2,STRTAB+PSNUM ;GET SDB ADDRESS OF STRUCTURE PS:
		LOAD 2,STRUC,(2) ;GET ITS UNIQUE STRUCTURE CODE
		STOR 2,JSUC	;SAVE AS CONNECTED STRUCTURE CODE
		MOVE 2,[[3
			 ASCIZ "OPERATOR"],,USRNAM]
		BLT 2,USRNAM+2	;SET UP DEFAULT USER NAME STRING
		HRRZ 2,SPECJT(1)
		JRST 0(2)]	;GO DO THE SPECIAL FUNCTION

;NOT A SPECIAL JOB. SET UP TERMINAL INFORMATION 

	MOVE A,CTRLTT		; GET CONTROLLING TERMINAL
	JUMPL A,SYSINP		;NO TTY. DON'T INIT TTY PARAMETERS
	CALL CHKPTY		;IS IT A PTY?
	 SKIPA			;NO. INIT TTY PARAMETERS
	JRST SYSINP		;YES. DON'T INIT TTY PARAMETERS
	MOVEI 1,100
	MOVEI 2,3B33		;SET TO HDX HERE, SO SETTING TO FDX
	STPAR			;BELOW WILL FORCE OUT TELNET CONTROL
	MOVE 2,NORMTF		;GET TTY TO STANDARD STATE
	SFMOD
	STPAR			;SET DEVICE PARAMETERS TOO
	MOVE B,CTRLTT		;GET CONTROLLING TERMINAL
	CALL CHKNVT		;IS IT A NETWORK TTY,
	 SKIPA 2,NORMTY		;NO. INIT TERM TO STANDARD TYPE
	MOVE T2,[.TTIDL]	;MAKE IT "IDEAL" TERMINAL
	STTYP
	MOVE 2,TTICB1
	MOVE 3,TTICB2
	SFCOC
	HRLOI 1,(1B0+1B1+1B4+1B5+1B6)
	MOVEI 2,-1		;ALL REMOTE
	TLINK			;BREAK LINKS, CLEAR ACCEPT
	 JFCL

;GO START THE EXEC. IF SYSTEM IS STAND-ALONE, TELL THE USER

SYSINP:	SKIPE CRJFLG		;IF CREATED JOB, GO SET IT UP.
	JRST STCRJB		; ..
	MOVE T1,DBUGSW
	CAIGE 1,2		;DEBUG MODE OPERATION?
	JRST STEX		;NO, GO START EXEC
	TMSG <
[Caution--System is stand-alone]
>
	JRST STEX		;WARN USERS FIRST

SYSIN9:	PUSH P,CTRLTT
	SETOM CTRLTT		;INDICATE DETACHED SO LOGOUT WON'T
	MOVE T2,JOBNO		; TRY TO WRITE ON THIS TERMINAL
	HRROS JOBPT(T2)		;..
	POP P,T1		;RESTORE LINE NUMBER
	SETZM TTACTL(T1)	;INDICATE LINE IS NOT ACTIVE
	MOVEI T1,.TTDES(T1)	;T1/ TERMINAL DESIGNATOR
	HRROI T2,[ASCIZ/FULL
/]
	TTMSG			;INDICATE SYSTEM IF FULL
	SKIPL CRJFLG		;IS THIS JOB BEING CREATED BY CRJOB JSYS?
	JRST FLOGO		;NO. GO KILL THE JOB
	MOVEM T1,CRJANS		;YES. SAVE ERROR CODE FROM TTYASN
	JRST LOGO		;GO KILL THE JOB
;HERE AT STARTUP OF JOB BY CRJOB JSYS.

STCRJB:	MOVE Q1,JOBNO		;CARRY AROUND MY JOB NUMBER
	HRLM Q1,CRJONJ		;TELL CREATOR, IF WE GET THERE.
	MOVE Q2,CRJAC1		;AND CONTROL FLAGS OF CRJOB AC1
	MOVE T1,CRJONJ		;GET CREATOR'S JOB NUMBER
	TXNE Q2,CJ%OWN		;CREATOR WANTS TO OWN ME?
	MOVEM T1,JOBONT(Q1)	;YES. REMEMBER WHO HE IS.
	MOVE T1,CRJSLO		;SIGNAL ON LOGOUT?
	TXNN Q2,CJ%SLO		; ..
	MOVEI T1,0		;NO. CLEAR THE PID
	MOVEM T1,JSLOPD		;SAVE THE PID FOR THE SIGNAL
	JN CJ%LOG,Q2,STCJB1	;JUMP IF WANTS TO LOG IN
	HLLZ T1,JOBDIR(T1)	;NO LOGIN. CONNECT TO CREATOR'S CONN DIR
	HLLZM T1,JOBDIR(Q1)	;I AM CONNECTED THERE, NOT LOGGED IN.
	SETZM CAPENB		;MAKE SURE I HAVE NO CAPS ENABLED
	HLLZS CAPMSK		;OR POTENTIAL
	MOVE T1,CRJOJC		;GET OWNING JOB'S CAPS
	AND T1,CRJCAM		;MASKED, IF ASKED
	TXNE Q2,CJ%CAP		;DOES HE WANT TO GIVE ME HIS?
	HRRM T1,CAPMSK		;YES, I'LL TAKE THEM, UNTIL LOGIN JSYS
	JRST STCJ1A		;DONE WITH LOGIN-ISH STUFF

;HERE IF CJ%LOG IS ON IN CALL. I AM TO TRY TO LOG THIS JOB IN.

STCJB1:	HRROI B,CRJUSR		;POINT TO THE USER NAME STRING
	MOVX T1,RC%EMO		;EXACT MATCH ONLY
	RCUSR			; AND CONVERT TO USER NUMBER
	 ERJMP SCJXXX		;PASS FAILURE CODE BACK
	TXNE T1,RC%NOM!RC%AMB	;FILES ONLY, NO MATCH OR
	JRST SCJXX1		; AMBIGUOUS? FAIL. CAN'T LOG IN.
	MOVEM T3,CRJUSR		;STORE THE NUMBER
	HRRZ T3,T3		;FOR CAMN LATER
	MOVE T4,CRJOJC		;GET CREATOR'S CAPS
	HRRZ T1,CRJONJ		;AND JOB NUMBER
	HRRZ T1,JOBDIR(T1)	;CREATOR'S LOGIN DIRECTORY
	TRNN T4,SC%WHL!SC%OPR	;PRIVILEGED CREATOR?
	CAMN T1,T3		;OR LOGGING IN AS SAME USER?
	JRST STCJ1E		;YES. NO NEED FOR PSWD CHECK.
	TXZE Q2,<CJ%NPW!CJ%NUD>	;NO, SO REQUIRE PASSWORD, AND LOGIN DATE
	JRST [	MOVEI T1,CRJBX1	;ILLEGAL REQUEST
		JRST SCJXXX]
STCJ1E:	LOAD T1,CJ%ACT,Q2	;WHAT KIND OF ACCOUNT DO WE USE?
	CAIE T1,.CJUCA		;USE CURRENT ACCOUNT OF CREATOR
	CAIN T1,.CJUAA		;OR ARG BLOCK ACCOUNT?
	JRST STCJ1C		;YES, IT'S IN THE COMMON STORAGE.
	SETZM CRJACT		;USE DEFAULT
   ;FALL THRU
   ;CAN FALL IN
STCJ1C:	MOVEI T1,0		;BUILD FLAGS FOR LOGIN JSYS
	TXNE Q2,CJ%NPW		;NO PASSWORD NEEDED?
	TRO T1,1		;RIGHT.
	TXNE Q2,CJ%NUD		;NO UPDATE LOGIN DATE?
	TRO T1,2		;RIGHT. TELL LOGIN.
	HRRM T1,CRJFLG		;STORE FOR IT TO SEE
	MOVE T1,CRJUSR		;LET'S DO THE LOGIN NOW.
	HRROI T2,CRJPSW		;PASSWORD, IF ANY.
	MOVE T3,CRJACT		;AND ACCOUNT
	LOGIN			;SEE IF THIS IS ALL VALID.
	 JRST SCJXXX		;APPARENTLY NOT.
	HRRO T1,CRJCAM		;ASKED TO LIMIT CAPABILITIES?
	ANDM T1,CAPENB		;DO SO IF NOT -1
	ANDM T1,CAPMSK		; ..
STCJ1A:	MOVE T2,CRJCPU		;GET TIME LIMIT FOR THIS JOB
	JUMPE T2,SCJBNL		;JUMP IF NO LIMIT
	MOVE T1,[.FHJOB,,.TIMRT] ;SET TIME LIMIT FOR JOB
	MOVEI T3,.ICMSE		;ON MACHINE-SIZE EXC CHANNEL, SO PANIC
	TIMER			;DO IT
	 JRST SCJXXX		;GIVE BACK FAILURE
SCJBNL:	MOVEI T1,.FHSLF		;SET UP TO DO SPJFN
	MOVE T2,CRJPJF		;FROM THIS ARGUMENT
	TXNE Q2,CJ%FIL		;IS THERE BOTH AN EXEC AND AN INFERIOR?
	TXNN Q2,CJ%ETF		; ..
	SKIPA			;NO. DO THE SPJFN HERE.
	JRST STCJ1D		;YES. ONLY DO THE SPJFN ON THE INFERIOR
	TXNE Q2,CJ%SPJ		;REQUESTED TO DO SPJFN?
	SPJFN			;YES, DO IT.
STCJ1D:	HLLZS CRJFLG		;NO FLAGS FOR A LATER LOGIN
	TXNN Q2,CJ%FIL		;WANT TO RUN A FILE?
	JRST CJSTEX		;NO. JUST GO GET THE EXEC.
STCJB2:	TXNE Q2,CJ%ETF		;WANT A FILE. AN EXEC TOO?
	JRST STCJB3		;YES.
	MOVX T1,GJ%OLD!GJ%SHT	;GET THE REQUESTED FILE IN TOP FORK
	HRROI T2,CRJFIL		;POINT TO THE TEXT
	GTJFN			;GET JFN FOR REQUESTED FILE
	 JRST SCJXXX		;CAN'T
	HRLI T1,.FHSLF		;OK, GET IT INTO THIS FORK.
	GET
	ERJMP SCJXX4		;IF GET FAILS, QUIT.
	MOVEI T1,20		; Length of AC block
	HRRI T2,CRJFAC		; From there
	SETZ T3,
	TXNE Q2,CJ%ACS		;AC SET REQUESTED?
	CALL BLTMU
	MOVEI T1,.FHSLF		;GET THE ENTRY VECTOR
	GEVEC			;GET THE ENTRY VECTOR
	TLNN T2,777000		;TOPS10 STYLE?
	JRST STCJ2A		;NO. TOPS20 STYLE, IF ANYTHING.
	HRRZ T3,CRJEVO		;OLD STYLE. WHERE DOES START POINT?
	CAILE T3,1		;START OR REENTER, I HOPE.
	JRST SCJXX3		;NO. FAIL.
	UMOVE T2,120		;GET JOBSA
	TRNE T3,-1		;OR IF 1,
	UMOVE T2,124		;GET JOBREN
	SKIPA
STCJ2A:	ADD T2,CRJEVO		;NEW STYLE, ADD OFFSET TO BASE.
	HRRZM T2,-1(P)		;WHERE MRETN WILL GO.
	HRLI T2,1		;INDICATE JOB HAS ALREADY SET CRJANS
	HLLM T2,CRJFLG		; BY MAKING FLAG POSITIVE
	SETOM CRJANS		;SAY WE HAVE SUCCEEDED.
	PUSHJ P,SCJWTA		;WAIT FOR ATTACH, IF WANTED
	JRST MRETN		;AND GO TO USER MODE.
;HERE IF WANT BOTH A FILE AND AN EXEC.

STCJB3:	MOVX T1,GJ%OLD!GJ%SHT	;GET A JFN FOR THE FILE.
	HRROI T2,CRJFIL		;WITH SUPPLIED NAME
	GTJFN
	 JRST SCJXXX		;CAN'T FIND THE FILE.
	PUSH P,T1		;SAVE JFN A MOMENT
	MOVX T1,CR%CAP		;CREATE THE NEW FORK, MY CAPS.
	TXNE Q2,CJ%ACS		;WANT SOME AC'S LOADED?
	TXO T1,CR%ACS		;YES, HAVE CFORK LOAD THEM.
	MOVEI T2,CRJFAC		;HERE ARE THE AC'S
	CFORK			;MAKE ME A FORK! (YOU'RE A FORK)
	 JRST SCJXX2		;CAN'T DO IT.
	EXCH T1,0(P)		;GET BACK JFN, SAVE FHANDLE
	HRL A,0(P)		;SET UP FOR THE GET
	GET
	ERJMP SCJXX2		;CAN'T GET THE FILE
	MOVE T1,0(P)		;HANDLE OF INFERIOR
	MOVE T2,CRJPJF		;PRIMARY I/O FOR IT
	TXNE Q2,CJ%SPJ		;IF REQUESTED,
	SPJFN			;SET IT.
	POP P,T1		;INFERIOR FORK HANDLE.
	HRLZS T1		;FORK,,0
	HRR T1,CRJEVO		;WHERE TO START IT.
	CALL SCJPRA		;SET UP PRARG FOR EXEC
CJSTEX:	HRLI T2,1		;INDICATE JOB HAS ALREADY SET CRJANS
	HLLM T2,CRJFLG		; BY MAKING FLAG POSITIVE
	SETOM CRJANS		;DONE WITH THE JSYS
	PUSHJ P,SCJWTA		;WAIT FOR ATTACH, IF REQUESTED
	JRST STEX		;AND GO GET AND START THE EXEC.
;CALL THIS ROUTINE BEFORE GOING TO MRETN FROM CRJOB PATHS. IT WILL
;WAIT FOR JOB TO BECOME ATTACHED, IF THAT'S REQUESTED BY CALLER.

SCJWTA:	TXNN Q2,CJ%WTA		;WANT TO WAIT?
	RET			;NO.
	MOVE T1,JOBNO		;YES. GET MY JOB NUMBER
	MOVEI T1,JOBPT(T1)	;AND JOBPT SLOT FOR THIS JOB
	CALL DISGE		;WAIT FOR LH TO BECOME POSITIVE
	RET			;NOW ATTACHED. RETURN.

SCJXX3:	MOVEI T1,SFRVX1		;BAD ENTRY VECTOR OFFSET
	JRST SCJXXX		;RETURN THAT ERROR
SCJXX2:	POP P,0(P)		;ADJUST STACK POINTER
SCJXX4:	HRRZ T1,LSTERR		;AND RETURN THIS FORK'S LAST ERROR
	JRST SCJXXX		; TO CREATOR
SCJXX1:	MOVEI T1,CRJBX5		;UNKNOWN NAME FOR LOGIN
SCJXXX:	SKIPGE CRJFLG		;IS THIS JOB BEING CREATED
	HRRZM T1,CRJANS		;YES. SET RH NON-ZERO.
	MOVE T1,JOBNO		;MAKE SURE I'M NOT OWNED, SO
	SETOM JOBONT(T1)	;THIS LOGOUT CAN GO THROUGH
	JRST LOGO		;AND KILL OFF THIS STARTED JOB.

;ROUTINE TO SET UP PRARG FOR EXEC TO READ IN NEW JOB

NCJPRA==3			;NUMBER OF ARGUMENT ITEMS
LCJPRA==6			;LENGTH OF BLOCK TO SET

SCJPRA:	TRVAR <<SCJPRB,10>>	;SPACE TO BUILD PRARG BLOCK
	PUSH P,T1		;PRESERVE FORKX,,SFRKV OFFSET
	MOVEI T1,NCJPRA		;NUMBER OF ARGUMENTS
	MOVEM T1,SCJPRB		;INTO THE BLOCK
	MOVEI T1,SCJPRB		;POINT TO BLOCK WITH PUSH POINTER
	PUSH T1,[1B0+3B6+2B12+CR%PRA]	;I AM A CRJOB PRARG
	PUSH T1,[1B0+4]		;WORD 4 IS ANOTHER DATUM
	PUSH T1,[1B0+5]		;WORD 5 IS ANOTHER DATUM
	MOVE T2,CRJEXF		;FLAGS FOR EXEC IS ONE DATUM
	TXO T2,1B1		;TURN ON "THERE'S A FORK" BIT
	PUSH T1,T2		;FLAGS TO ARG BLOCK
	POP P,T2		;RESTORE FORKX,, ENT-VEC-OFFSET
	PUSH T1,T2		;PUT IT IN BLOCK
	MOVE T1,[.PRAST,,.FHSLF] ; SET MY OWN PRARG BLOCK
	MOVEI T2,SCJPRB		;HERE'S THE BLOCK TO SET
	MOVEI T3,LCJPRA		;HERE'S ITS LENGTH
	PRARG			;SET IT
	ERJMP SCJXX4		;CATCH TRAP IF FAILED
	RET			;SUCCESS.
;SYSTEM INITIALIZATION.  RUN ONCE ONLY BY JOB 0.

	SWAPCD

RUNDD::	MOVE T1,CTYLNO		;GET CTY LINE NUMBER
	MOVEI T1,.TTDES(T1)	;CONVERT TO 400000+N
	MOVEM T1,JB0TT		;CONTROLLING TERMINAL FOR JOB 0
	MOVSI 1,777
	ANDCAM 1,CAPENB		;FLUSH ANY SUPERIOR FORK CAPS
	SKIPN PROFLG		;WANT PRIMARY PROTOCOL?
	JRST RUNDI7		;NO. SKIP ALL PRIMARY STUFF
	MOVEI A,.PRIOU		;YES. FIRST WAIT FOR CTY TO STOP
	DOBE			;"
	CALL TTSPIN		;INITIALIZE TERMINAL SPEEDS TO NULL
	CALL PROINI		;TURN ON PRIMARY PROTOCOL
	CALL DTRMDS		;TELL -11 NOT TO ANSWER DATA SETS

;TRY TO GET TIME AND DATE FROM THE 11. DTE SERVICE SENDS THE REQUEST TO
;THE 11 AND STORES ITS ANSWER IN TAD11. IF THE 11 DOES NOT KNOW, IT
;RETURNS -1. IN THIS CASE, ASK THE OPERATOR FOR THE TIME. IF THE 11 HAS
;IT, DON'T ASK THE OPERATOR

	SETZM TAD11		;ZERO TIME CELL
	CALL RQTAD1		;REQUEST TIME/DATE FROM 11
	 JFCL			;SUPPOSEDLY CAN'T OCCUR
	SKIPN TAD11		;HAS 11 SENT TIME/DATE YET?
	JRST .-1		;NO. WAIT UNTIL IT DOES
	CALL TTMVSP		;GO MOVE THE SPEEDS
	SKIPE SMFLAG		;IF KS10 THEN WE HAVE TIME AND DATE CORRECT
	JRST RUNDD3
	MOVE B,TAD11		;GET TIME SENT FROM -11
	SETOM TAD11		;YES. RESET TO INDICATE NOT SET BY 11
	CAMN B,[-1]		;DOES THE -11 HAVE IT?
	JRST RUNDI7		;NO
	DMOVE C,TAD11+1		;YES. GET REST OF IDCNV ARGS
	IDCNV			;CONVERT TO INTERNAL
	 JRST RUNDI7		;FAILED. GET FROM OPERATOR THEN
	MOVEM B,CRSTAD		;LET IT FIND IT LATER

	;..
;RUNDD...
;SET SYSTEM TIME AND DATE IF THE 11 PROVIDED IT

	;..
RUNDI7:	MOVEI 1,101
	DOBE
	SKIPN 1,CRSTAD		;DO WE HAVE A SAVED TIME FROM CRASH?
	JRST [	MOVX A,SF%MST	;NO. SAY IS A MANUAL START
		IORM A,FACTSW	;""
		JRST RUNDD3]
	STAD			;YES, SET IT
	 JFCL
	SETZM CRSTAD

;RUN SETSPD TO SET LINE SPEEDS, SYSTEM LOGICAL NAMES, OTHER SYSTEM
;PARAMETERS

RUNDD3:	MOVE T1,[^D<10*60000>]	;SET DEFALUT CHECKPOINT INTERVAL
	MOVEM T1,CKPINV		;...
	MOVX T1,GJ%OLD!GJ%SHT!GJ%PHY ;YES. SET LINE SPEEDS
	HRROI T2,SETSPD		;GET POINTER TO "SYSTEM:X-SETSPD.EXE"
	SETZ T3,		;3/OFFSET 0 IN ENTRY VECTOR
	CALL RUNDII		;GO RUN IT
	 JRST [	HRROI T1,[ASCIZ/
%%No SETSPD
/]
		PSOUT
		MOVEI T1,.PRIOU ;WAIT UNTIL THE TERMINAL
		DOBE		; STOPS SO THE NEXT MESSAGE IS OK
		JRST .+1]	;SAY IT FAILED

;IF DBUGSW IS 0 OR 1, TELL ALL USERS THAT SYSTEM IS RESTARTING

RUNDD6:	MOVE 1,DBUGSW
	CAIE 1,0
	CAIN 1,1		;REGULAR STARTUP?
	SKIPA
	JRST RUNDI4		;NO, DON'T NOTIFY WORLD
	SETO 1,
	HRROI 2,[ASCIZ /
System restarting, wait.../]
	TTMSG
	;..
;RUNDD...

;GET DATE AND TIME FROM OPERATOR UNLESS 11 SENT IT EARLIER

	;..
RUNDI4:	CALL LGTAD		;DOES SYSTEM HAVE TIME AND DATE?
	CAME A,[-1]
	JRST RUNDI1		;YES
RUNDI3:	TMSG <
Enter current date and time: >
RUNDI2:	CALL RDDGTD		;GET TAD INTO 2
	PUSH P,2		;SAVE TAD JUST ENTERED
	TMSG <
You have entered >
	MOVEI 1,.PRIOU
	MOVE 2,0(P)
	MOVX 3,1B1+1B2+1B4+1B5+1B10+1B11+1B17
	ODTIM			;TYPE IT IN VERBOSE FORMAT
	MOVE 2,0(P)
	CAMGE 2,SYSTAD		;IS IT GREATER THAN SYSTEM LOAD TAD?
	JRST [	MOVEI 1,.PRIIN	;CLEAR TYPE AHEAD
		CFIBF
		MOVEI 1,.PRIOU
		DOBE		;WAIT FOR TYPE OUT TO STOP
		TMSG <,
that cannot be correct.
Please try again in form MMM-DD-YY HHMM >
		JRST RUNDI2]
	TMSG <,
 is this correct (Y,N) >
	CALL YESNO		;GET VERIFICATION
	JUMPE A,RUNDI3		;IF 'NO', TRY AGAIN
	POP P,1			;CONFIRMED, RECOVER IT
	STAD			;SET IT
	 JFCL
	; ..
;RUNDD...

;DECIDE WHETHER TO RUN CHECKD OR NOT. IF CHKBT FOUND ERRORS, FACTSW HAS
;SF%BTE SET; RUN CHECKD TO DO A BIT TABLE CONSISTENCY CHECK. IF BIT
;TABLE FILE DOESN'T EXIST, MI%ASG IS SET IN SDB. DON'T RUN CHECKD.
;(OPERATOR WILL HAVE TO RUN IT WITH THE REBUILD FUNCTION). IF DOING
;RECONSTRUCTION OF ROOT-DIRECTORY OR REBUILD OF BIT TABLE, STARTF HAS
;MI%BTB SET; RUN CHECKD TO DO A REBUILD OF THE BIT TABLE.  IF DOING
;A REFRESH OF THE FILE SYSTEM, DON'T TRY TO RUN CHECKD. IF NONE OF
;THE ABOVE, ASK THE OPERATOR UNLESS AUTO RELOADING. IN ALL CASES,
;ONLY PS IS MOUNTED AT THIS POINT, SO CHECKD IS ONLY RUN ON PS.

	;..
RUNDI1:	CALL LOGSST		;LOG RESTART IN SYSERR FILE
	MOVEI 1,RUNDD0		;BREAK TO RUNDD0 IF ANYTHING GOES WRONG
	HRRM 1,MONBK
	SKIPN AVALON		;RUNNING ACCOUNT VALIDATION?
	JRST RUNDI5		;NO, PROCEED
	CALL ENACT		;INITIALIZE THINGS FOR ACCT VALIDATION
	 JRST RUNDIX		;FAILED, TURN OFF VALIDATION
RUNDI5:	MOVX T4,MI%BTB		;IF REBUILDING THE BIT TABLE (BIT IS
	TDNE T4,STARTF		; SET BY FILINI)
	JRST RUNDC2		;ALWAYS RUN CHECKD IN REBUILD MODE
	MOVE 2,DBUGSW		;IF DEBUGGING,
	CAIN 2,2
	JRST RUNDD2		;DON'T RUN CHECKD
	MOVX T4,MI%RFS		;IF REFRESHING (BIT IS SET
	TDNE T4,STARTF		; BY FSIINI)	
	JRST RUNDD2		;DON'T RUN CHECKD (IT ISN'T THERE)
	MOVE T2,STRTAB+PSNUM	;POINT TO SDB FOR PS
	MOVE T2,SDBSTS(T2)	;GET STATUS BITS FOR PS
	MOVE T1,FACTSW
	TXNE T1,SF%BTE		;BIT TABLE ERRORS?
	TXNE T2,MI%ASG		;YES. ARE DISK ASSIGNMENTS PROHIBITED?
	SKIPA			;YES. DON'T RUN CHECKD
	JRST RUNDC1		;BIT TABLE ERRORS BUT BT FILE EXISTS. RUN CHECKD
	TXNN A,SF%MST		;MANUAL STARTUP?
	JRST RUNDD2		;NO. NO QUESTIONS AND NO CHECKD

;CHECKD NOT REQUIRED.  SEE IF OPERATOR WANTS IT

	TMSG <RUN CHECKD? >
	CALL YESNO
	JUMPE A,RUNDD2		;JUMP IF NO
RUNDC1:	SKIPA T1,[-1,,[ASCIZ/[CHECKING FILE CONSISTENCY]
/]]
RUNDC2:	HRROI T1,[ASCIZ/[REBUILDING BIT TABLE]
/]
	PSOUT
	MOVSI 1,(GJ%OLD!GJ%PHY!GJ%SHT)
	HRROI 2,[ASCIZ /SYSTEM:CHECKD.EXE/]
	MOVX T3,SF%CDR		;SAY CHECKD NOW RUNNING
	IORM T3,FACTSW		;DO IT
	SETZ T3,		;NORMAL ENTRY POINT
	MOVX T4,MI%BTB
	TDNE T4,STARTF		;REBUILDING BIT TABLE?
	MOVEI T3,3		;YES. START AT SPECIAL ENTRY POINT
	CALL RUNDII		;GO START IT
	 JRST [	MOVX T1,SF%CDR	;NOT RUNNING
		ANDCAM T1,FACTSW
		JRST RUNDD1]	;FAILED
	SETZM STARTF		;INDICATE STARTUP IS COMPLETE
	MOVX T1,SF%CDR		;SAY CHECKD NOT RUNNING ANYMORE
	ANDCAM T1,FACTSW	;""
	JRST RUNDD2		;PROCEED

;IF ENACT FAILS FOR ANY REASON, PRINT MSG AND TURN OFF ACCOUNT VALIDATION

RUNDIX:	TMSG <
<SYSTEM>ACCOUNTS-TABLE.BIN not found - Account validation is disabled
>
	SETZM AVALON		;TURN OFF VALIDATION
	JRST RUNDI5		;AND PROCEED

;FAILED TO FIND CHECKD WHEN RUNNING IT WAS REQUIRED BY THE SYSTEM
;OR REQUESTED BY THE OPERATOR. PRETEND THAT IT RAN AND FOUND
;ERRORS. IF IT IS RUN LATER AND FINDS PS TO BE OK, IT WILL CLEAR
;SF%CDE.
;IT ALSO CAUSES THE 'FILE STRUCTURE NEEDS REPAIR' MESSAGE BELOW
;AND PREVENTS SYSJOB FROM DOING ITS USUAL THING

RUNDD0:	CALL CLRINT		;CLEAR THE INTERRUPT SYSTEM
RUNDD1:	TMSG <
No CHECKD
>
	SETZM STARTF		;INDICATE STARTUP COMPLETED
	MOVX T4,SF%CDE		;PRETEND CHECKD FOUND ERRORS
	IORM T4,FACTSW
	;..
;RUNDD...

;IF DEBUGGING, TELL ALL USERS. IF CHECKD FOUND ERRORS, TELL ALL USERS
;THEN PROCEED AS USUAL

	;..
RUNDD2:	MOVEI 1,RUNDD7		;BREAK TO RUNDD8 IF ANY SCREWUP
	HRRM 1,MONBK
	MOVEI 1,101
	DOBE			;WAIT FOR ANY CHECKD OUTPUT
	MOVE 1,DBUGSW
	CAIL 1,2		;DEBUG MODE OPERATION?
	JRST [	SETO 1,		;YES, DIFFERENT MESSAGE
		HRROI 2,[ASCIZ /
[System is stand-alone]
/]
		TTMSG
		JRST RUNDE1]
	MOVX 1,SF%CDE
	TDNE 1,FACTSW		;DID CHECKD FIND DISK ERRORS?
	JRST [	HRROI 2,[ASCIZ /
[System not in operation - file structure needs repair]
/]
		SETO 1,
		TTMSG
		JRST RUNDE1]

;INITIALIZE SYSERR LOGGING

RUNDE1:	MOVE 1,JB0TT		;JOB 0 TTY
	CAIE 1,377777		;REAL TTY?
	JRST RUNDD4		;YES
	MOVSI 1,(GJ%FOU!GJ%PHY!GJ%SHT)	;NONE, SO OPEN FILE FOR MESSAGES
	HRROI 2,[ASCIZ /PS:<SYSTEM>ERROR.REPORT/]
	GTJFN
	 BUG(CHK,NOSERF,<CAN'T GTJFN ERROR REPORT FILE>)
	MOVE 2,[44B5+1B20]
	OPENF
	 BUG(CHK,SERFOF,<CAN'T OPENF ERROR REPORT FILE>)
RUNDD4:	HRRM 1,PRIMRY		;USE IT FOR OUTPUT 
	CALL SERINI		;START SYSERR LOGGING
	CALL USGINI		;START ACCOUNTING

;RUN SETSPD AGAIN. THIS TIME, START IT AT A SPECIAL PLACE TO MAKE
;IT COPY THE DUMP FILE.

	MOVX T1,SF%CDE		;DON'T CREATE DUMP.CPY IF THE BIT
	TDNE T1,FACTSW		; TABLE IS BAD
	JRST RUNDD7		;CHECKD FOUND ERRORS IN THE BT
	MOVX T1,GJ%OLD!GJ%PHY!GJ%SHT
	HRROI T2,SETSPD		;GET POINTER TO "SYSTEM:X-SETSPD.EXE"
	MOVEI T3,3		;3/ OFFSET 3 IN ENTRY VECTOR
	CALL RUNDII		;GO RUN IT
	JFCL			;IGNORE FAILURE
	;..
;RUNDD...

	;..

RUNDD7:	MOVEI T1,RUNDD5		;BREAK TO RUNDD5
	HRRM T1,MONBK		; IF ANYTHING GOES WRONG
	CALL IMPBEG		;START NCP FORK, IF ANY.
	CALL KDPINI		;INITIALIZE THE DUP11
	CALL NSPINI		;INIT DECNET FORK AND DATA BASE
	TMSG <
Running DDMP

>
	AOS SYSIFG		;INDICATE NO LONGER IN STARTUP
				; (NEXT JOB WON'T GO THROUGH RUNDD)
	CALL DONSJ		;START NEXT SPECIAL JOB

;CREATE FORK UNDER JOB 0 AND RUN SYSJOB IN IT. SYSJOB READS A COMMAND
;FILE, WHOSE NAME IS DETERMINED BY THE SETTING OF DBUGSW. IF CHECKD
;HAS NOT BLESSED PS (SF%CDE IS SET IN FACTSW), SYSJOB DOES NOT READ
;A COMMAND FILE.  AMONG OTHER THINGS, THIS WILL PREVENT LOGINS FROM
;TERMINALS OTHER THAN THE CTY

	MOVX T1,<GJ%OLD!GJ%PHY!GJ%SHT>
	HRROI T2,[ASCIZ /SYSTEM:SYSJOB.EXE/]
	SETZM T3		;MAIN ENTRY POINT
	CALL RUNDIR		;RUN SYSJOB AND RETURN
	 JRST [	 TMSG<
No SYSJOB
>
		JRST .+1]
RUNDD5:	MOVEI 1,1		;KEEP JOB 0 IN QUEUE 1 ALWAYS
	MOVEM 1,JOBBIT		;SET PRIORITY FOR CHKR
	MOVEI 1,CHKRI
	HRRM 1,MONBK		;SET DISPATCH FOR INTERRUPTS
	SETZM EXPFRK		;CLEAR FORK HANDLE
	CALL RUNMO1		;RUN MOS MEM DIAG
	JRST CHKR		;GO DO BACKGROUND

;CLEAR THE INTERRUPT SYSTEM

CLRINT:	MOVEI 1,400000		;DEACTIVATE SOFTWARE INTERRUPT CHANNELS
	SETO 2,			; FOR THIS PROCESS

	DIC
	CALL DTIALL		;IN CASE PROGRAM TURNED ANY ON
	MOVE 2,PSIBW	
	CIS			;CLEAR ALL INTERRUPTS IN PROGRESS
	RET
;COMMON ROUTINE TO START A FORK UNDER JOB 0 DURING SYSTEM 
;INITIALIZATION OR FRONT END REBOOT.
;ACCEPTS:
;	A/ GTJFN T1 ARGS
;	B/ GTJFN T2 ARGS
;	C/OFFSET IN ENTRY VECTOR WHERE WE START FORK

;	CALL RUNDII

;RETURNS:
;	+1/ FAILED, PROGRAM NOT RUN
;	+2/ PROGRAM RAN AND IS COMPLETE

;CREATES A FORK TO RUN THE SPECIFIED FILE, WAITS FOR IT TO FINISH
;RUNNING, KILLS THE FORK
;SPECIAL ENTRY RUNDIR DOES NOT WAIT FOR FORK TO COMPLETE AND
;DOES NOT KILL FORK. RETURNS IN T1 THE FORK HANDLE

RUNDIR:	TDZA T4,T4		;NO WAIT FLAG
RUNDII::SETOM T4		;WAIT FLAG
	STKVAR<EVEC,WFLAG,FKHNDL,FILJFN>
	MOVEM C,EVEC		;SAVE OFFSET IN ENTRY VECTOR
	MOVEM T4,WFLAG		;SAVE WAIT FLAG
	GTJFN
	 RET			;FAILED
	MOVEM T1,FILJFN		;SAVE JFN
	MOVX T1,CR%CAP		;XMIT CAPABILITIES
	CFORK			;CREATE A FORK FOR CHECKD
	 BUG(HLT,CKDFRK,<JOB 0 CFORK FAILED>)
	MOVEM T1,FKHNDL		;SAVE FORK HANDLE
	PUSH P,CAPENB		;SAVE ENABLED CAPABILITIES
	HLLOS CAPENB		;MAKE THIS A WHEEL
	MOVE T2,JOBBIT		;SET TO SAME AS OURS
	SPRIW			;BY SETTING PRIORITY WORD
	ERJMP .+1		;JUST IN CASE
	POP P,CAPENB		;RESTORE CAPABILITIES
	HRL T1,FKHNDL		;FOR HANDLE TO LH
	HRR T1,FILJFN		;JFN TO LH
	GET
	 ERJMP [MOVE T1,FKHNDL	;GET FORK HANDLE
		KFORK		;KILL THE FORK
		RET]		;AND DONE
	MOVE T1,FKHNDL		;GET FORK HANDLE
	MOVE 2,EVEC		;2/OFFSET IN ENTRY VECTOR
	SFRKV			;START AT MAIN ENTRY
	 ERJMP [MOVE T1,FKHNDL	;GET HANDLE
		KFORK		;KILL FORK
		RET]
	SKIPN WFLAG		;WANT TO WAIT?
	RETSKP			;NO. RETURN NOW
	WFORK
	KFORK
	RETSKP			;ALL DONE
;ROUTINE TO MAKE RESTART ENTRY IN SYSERR FILE

LOGSST:	TRVAR <<RDDBFR,.RLBSZ>>
	SAVEQ
	JE SF%MST,FACTSW,LOGSS1	;JUMP IF AUTO RESTART
LOGSS2:	TMSG <Why reload? >	;MANUAL RESTART, FIND OUT WHY
	HRROI T1,RDDBFR
	MOVX T2,RD%BRK+RD%BEL+RD%CRF+20*5
	MOVEI T3,0
	RDTTY			;GET ANSWER
	 JFCL
	LDB T3,[POINT 7,RDDBFR,6] ;GET FIRST CHAR OF ANSWER
	CAIN T3,"?"		;HELP WANTED?
	JRST [	HRROI T1,LOGSMG	;YES, TYPE MESSAGE
		PSOUT
		JRST LOGSS2]	;TRY AGAIN
	CAIN T3,.CHLFD		;NULL ANSWER?
	JRST [	HRROI T1,[ASCIZ/? Null answer is not allowed!
/]
		PSOUT
		JRST LOGSS2]
	SETZ T3,		;FLUSH TERMINATOR (PRESUMABLY NL)
	DPB T3,T1
LOGSS1:	MOVX T1,RL%LEN
	MOVX T2,RL%SIZ
	CALL ALCSEB		;GET SYSERR STORAGE
	 JRST [BUG(CHK,SYSERF,<LOGSST-NO SYSERR STORAGE FOR RESTART ENTRY>)
		RET]
	MOVEM T1,Q1
	MOVE T2,[-NWHYIT,,WHYIT]
	CALL SEBCPY		;COPY DATA INTO BLOCK
	 JFCL
	MOVE T2,[-1,,[SEBPTR RL%OPR,SBTSTR,RDDBFR]]
	MOVE T3,FACTSW
	TXNN T3,SF%MST		;USE OPR ANSWER IF MANUAL START
	MOVE T2,[-1,,[SEBPTR RL%HLT,SBTWD,BUGHLT]]
	MOVE T1,Q1		;USE BUGHLT ADDRESS OTHERWISE
	CALL SEBCPY
	 JFCL
	MOVE T1,Q1
	CALL QUESEB		;QUEUE BLOCK FOR SYSERR FILE
	RET

LOGSMG:	ASCIZ \One of the following:
  SA - Machine was being used for standalone
  PM - Machine was down for preventive maintenance
  CM - Machine was down for corrective maintenance
  CR - Crash
or any one-line statement of the reason for this reload.
\

;POINTER TABLE TO BUILD RELOAD ENTRY

WHYIT:	SEBPTR 0,SBTEVC,SEC%RL	;EVENT CODE (IMMEDIATE)
	SEBPTR RL%SVN,SBTSTR,SVN ;SYSTEM NAME
	SEBPTR RL%STD,SBTWD,SYSTAD ;BUILD TAD
	SEBPTR RL%VER,SBTWD,[EXP SVNM] ;SYSTEM VERSION NUMBER
	SEBPTR RL%SER,SBTWD,APRSER ;APR SERIAL NUMBER
NWHYIT==.-WHYIT
;LOCAL ROUTINE TO READ TAD FROM CTY
;	CALL RDDTAD
; RETURN +1 ALWAYS, 2/ TAD

RDDGTD:	STKVAR <<RDDBFR,20>>
RDDGT1:	HRROI 1,RDDBFR
	MOVE 2,[RD%BRK+RD%BEL+RD%RAI+20*5]
	MOVEI 3,0
	RDTTY			;READ LINE FROM CTY
	 JRST RDDGT2		;FAILED, REPROMPT
	TXNN 2,RD%BTM		;BREAK CHAR TERMINATED INPUT?
	JRST RDDGT2		;NO, GARBAGE INPUT
	HRROI 1,RDDBFR
	MOVEI 2,0
	IDTIM			;CONVERT STRING TO TAD
	 JRST RDDGT2		;INVALID, REPROMPT
	RET			;OK, RETURN IT

RDDGT2:	TMSG <
? Invalid, please try again in form MMM-DD-YY HHMM: >
	JRST RDDGT1		;TRY AGAIN

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

DONSJ:	CALL LOGONM		;RECORD START OF CURRENT JOB ON LOGGING TERMINAL
	MOVE 4,CTRLTT		;SAVE THIS JOB'S CONTROLLING TERMINAL
	DTACH			;DETACH THE CURRENT JOB
	MOVE 1,JB0TT
	HRRM 1,PRIMRY		;USE JOB 0 TTY FOR ANY OUTPUT
	MOVE 1,JOBNO		;GET CURRENT JOB NUMBER
	CAIL 1,NSPECJ-1		;MORE SPECIAL JOBS TO DO?
	JRST [	MOVX T1,SF%PTY!SF%CTY ;NO. ALLOW CTY AND PTY LOGINS
		IORM T1,FACTSW
		RET]		; AND DON'T CREATE ANOTHER JOB
	MOVE 2,4		;YES. GET LINE NUMBER FOR CALL
	CALLRET SPCSTJ		;START ANOTHER JOB ON SAME TTY

SPCSTJ:	NOSKED
	PUSH P,T2		;SAVE LINE NUMBER
	CALL STADYN		;GET ADDRESS OF DYNAMIC DATA
	 SKIPA			;NOT FULLY ACTIVE
	JRST [	POP P,2
		OKSKED
		RET]
	JUMPG T2,SPCST1		;IF TEMPORARILY ACTIVE, WAIT
	POP P,2			;GET LINE NUMBER BACK
	SETOM TTACTL(T2)	;INDICATE JOB STARTING
	MOVEI 1,JOBSRT		;REQUEST JOB STARTUP FROM SCHED
	HRL 1,2
	CALL SCDRQ7
	OKSKED
	RET

;LINE IS TEMPORARILY IN USE. WAIT UNTIL IT'S AVAILABLE

SPCST1:	POP P,1			;RESTORE LINE NUMBER
	OKSKED
	HRLZS T1		;T1/ (LINE NUMBER,,ROUTINE)
	HRRI T1,TSACT1		;ROUTINE TO WAIT FOR LINE
	MDISMS
	JRST SPCSTJ
;GET SWAPPABLE MONITOR

	RESCD

;BOOT DEVICE TABLE--DISPATCH ON CONTENTS OF BOOTFL TO SELECT DEVICE

BOOTD:	PHASE 0
	JRST GSMDSK		;0 - DSK (VBOOT)
	REPEAT 2,<JRST GSMDSK>	;EVERYTHING IS DISK
IRBOOT::!JRST GSMIRB		;INTERNAL REBOOT
	DEPHASE
NBOOTD==.-BOOTD

GETSWM::SKIPN EDDTF		;KEEP EDDT?
	CALL ULKINI		;NO, UNLOCK IT
	HRR T1,SWCEND		;BUILD SWPMON BOUND PAIR
	LSH T1,PGSFT
	HRLI T1,SWPMPG_PGSFT
	MOVEM T1,SWPMBP		;STORE
	SETZM SWPMWF		; INITIALIZE SWAPPABLE MON WRITERS FLAG
	SETOM SWPMLF		; INIT COUNT OF LOCKERS OF SWP MON
	NOSKED
	MOVE 1,BOOTFL		;GET DEVICE SELECTOR
	CAIL 1,NBOOTD		;LEGAL?
	BUG(HLT,ILBOOT,<GETSWM-ILLEGAL VALUE OF BOOTFL>)
	JRST BOOTD(1)		;GO TO SELECTED BOOTSTRAP

;COMMON EXIT POINT FOR ALL DEVICES

LOKSM3:	SETZ T1,
	MOVEI T2,BUTPGA
	CALL SETMPG		;CLEAR BOOT PAGE
	MOVE T1,DBUGSW		;WRITE PROTECT?
	CAIE T1,2		;?
	CALL SWPMWP		;YES - IF NOT DEBUGGING
	OKSKED
	SKIPE SMLKF		;KEEP SWPMON LOCKED?
	CALL SWPMLK		;YES, RE-LOCK IT
	RET

RS(SWPMBP,1)			;STORAGE FOR SWPMON BOUND PAIR
RS(BOOTST,^D20)			;STORAGE FOR VBOOT COMMAND
;INTERNAL REBOOT - ASSUMES SWAP MON MAP FROM PREVIOUS RUN IS
;SAVED IN LOW CORE

GSMIRB:	CALL RESSMM		;RESTORE MON MAP
	JRST LOKSM3		;DONE

;THE DECTAPE BOOTSTRAP
;HERE TO BOOTSTRAP THE SWAPABLE MONITOR FROM DISK

GSMDSK:	HRRZ T1,BUTPGS		;GET END PAGE OF VBOOT AREA
	HLRZ T2,BUTPGS		;GET START PAGE OF VBOOT AREA
	SUB T1,T2		;COMPUTE # OF PAGES IN VBOOT AREA
	LSH T1,-PGSFT		;GET PAGES
	ADDI T1,12		;ALLOW FOR OVERHEAD AND MISC
	CAMLE T1,TOTRC		;ENOUGH?
	BUG(HLT,BOOTCR,<GETSWM - NOT ENOUGH CORE FOR SWPMON>)
	MOVE T2,TOTRC		;GET TOTAL FREE
	SUB T2,T1		;COMPUTE FREE WORDS AFTER VBOOT
	SUB T2,BALSHC		;SUBTRACT OFF ANY LOCKED PAGES
	MOVE P1,T2		;SAVE IN P1
	LSH P1,PGSFT		;CONVERT TO WORDS

; MAP BOOTSTRAP PAGES

	HRRZ P2,BUTPHY		;GET CORE ADDRESS OF FIRST PAGE
	LSH P2,-^D9		;CONVERT TO CORE PAGE #
	HLL P2,BUTPHY		;GET - # OF PAGES TO MAP
	MOVE P3,BUTVIR		;GET FIRST VIRTUAL ADR TO MAP
GSMD1:	HRRZ T1,P2		;GET PAGE # TO MAP
	MOVE T2,P3		;GET VIRTUAL ADDRESS
	CALL MAPPHA		;GO MAP A PHYSICAL PAGE
	 BUG(HLT,BOOTMP,<GSMDSK - CANNOT MAP BOOTSTRAP PAGES>)
	ADDI P3,PGSIZ		;NEXT VIRTUAL ADDRESS
	AOBJN P2,GSMD1		;MAP REMAINING PAGES

	HRL T1,MMSPTN		;GET SPTN OF MONITOR MAP
	HRRI T1,KIEPT/PGSIZ	;FORM I.D. OF EPT
	HLRZ T2,BUTEPT		;GET VIRTUAL ADDRESS OF BOOT'S EPT
	TXO T2,PTRW		;ACCESS BITS
	CALL SETMPG		;GET INDIRECT POINTER TO EPT
	MOVEI T1,MMAP		;BUILD POINTER FOR VBOOT TO PAGE TABLE
	LSH T1,-PGSFT		; ...
	HRL T1,MMSPTN		; ...
	HRRZ T2,BUTEPT		;GET ADDRESS OF VBOOT PAGE TABLE PAGE
	TXO T2,PTRW		;TURN ON ACCESS BITS
	CALL SETMPG		;SET MAP

	HLLZ T1,BUTPGS		;GET STARTING ADDRESS FOR VBOOT
	HRR T1,BUTEPT		;GET ADDRESS OF VBOOT EPT PAGE
	CALL CGPLK		;CREATE A GROUP OF PAGES AND LOCK
GSMLER:	 BUG(HLT,BOOTLK,<GSMDSK - FAILED TO LOCK NEEDED PAGES>)
	HRRZ T1,BUTEPT		;GET ADDRESS OF VBOOT EPT PAGE
	HRLZI T1,PGSIZ(T1)	;GET FIRST ADDRESS TO LOCK ABOVE EPT
	HRR T1,BUTPGS		;GET ADDRESS OF LAST PAGE TO LOCK
	CALL CGPLK		;CREATE AND LOCK
	 JRST GSMLER
	MOVEM T1,BOOTST		;SAVE PHYSICAL ADDR OF VBEND

	;..
;HERE TO LOAD THE SWAPABALE MONITOR. IT IS READ IN SECTIONS
;AS LARGE AS THE AMOUNT OF FREE CORE AFTER THE BOOTSTRAP.

	MOVEI P2,SWPMA-1000	;INITIALIZE SWPMON LOAD LOOP
GSMD2:	MOVEI T1,1000(P2)	;FIRST PAGE IN CURRENT GROUP
	ADD T1,P1		;PLUS AVAILABLE CORE
	LSH T1,-PGSFT		;AS A PAGE #
	CAMLE T1,SWCEND		;UNDER END OF SWPMON?
	MOVE T1,SWCEND		;NO USE END INSTEAD
	LSH T1,PGSFT		;CONVERT BACK TO ADDR
	HRLI T1,1000(P2)	;NEW FROM PAGE
	MOVE P2,T1		;SAVE BOUND PAIR
	CALL CGPLK		;CREATE AND LOCK
	 JRST GSMLER		; LOCK FAILURE

	MOVE P3,[POINT 7,BOOTST] ;BUILD VBOOT COMMAND STRING
	MOVE T1,[POINT 7,BUTCMD]	;POINTER TO FILE SPEC
	CALL BSCPY		;COPY TO OUTPUT STRING
	MOVE T1,[POINT 7,[ASCIZ '/L(']] ;LOAD ONLY
	CALL BSCPY
	HLRZ T1,P2		;LOWER BOUND
	LSH T1,-PGSFT		;AS A PAGE NUMBER
	CALL BSOCT		;CONVERT TO STRING
	MOVEI T1,","
	IDPB T1,P3
	HRRZ T1,P2		;UPPER BOUND
	LSH T1,-PGSFT		;AS A PAGE NUMBER
	CALL BSOCT		; ...
	MOVE T1,[POINT 7,[ASCIZ /)
/]]
	CALL BSCPY		;END OF COMMAND
	;...
;WE ARE NOW READY TO LOAD A SECTION OF THE SWAPABLE MONITOR.
;CALL VBOOT TO DO THE IO.

	PUSH P,P1		;SAVE FREE CORE
	PUSH P,P2		;SAVE BOUND PAIR
	HLRZ T1,BUTEPT		;GET ADDRESS OF VBOOT EPT PAGE
	SETMM (T1)		;INSURE EPT UPDATED
	CALL PHYIOW		;WAIT FOR ALL IO TO FINISH
	PIOFF			;DISABLE INTERRUPT SYSTEM
	MOVEM P,FPC		;SAVE STACK POINTER
	MOVE T1,[POINT 7,BOOTST] ;GET POINTER TO COMMAND STRING
	HRRZ T2,BUTPGS		;GET ADDRESS OF LAST PAGE IN VBOOT AREA
VBCALL::JSP 16,777(T2)		;GO LOAD SOME MONITOR
				; CALL BOOT AT LAST INSTRUCTION ON
				; LAST PAGE WHICH IS A JRST TO VBOOT
	 BUG(HLT,BOOTER,<GETSWM - ERROR LOADING SWPMON>)
	MOVE P,FPC		;RECOVER STACK
	XCT SETPPI		;RESTORE APR PI ASSMT
	PION

	POP P,P2		;RESTORE BOUND PAIR
	POP P,P1		;RESTORE FREE CORE
	MOVE T1,P2		;UNLOCK SWPMON PAGES
	CALL GPULK		;...
	HRRZ T1,P2		;ARE WE DONE?
	LSH T1,-PGSFT		;...
	CAME T1,SWCEND		;...
	JRST GSMD2		;NO - ANOTHER CYCLE
	CALL GSMDX		;RESET VBOOT AREA
	JRST LOKSM3		;YES - ADJUST SWPMON

;SUBROUTINE TO RELEASE VBOOT AREA

GSMDX:	HLLZ T1,BUTPGS		;GET START ADDRESS OF VBOOT AREA
	HRRZ T2,BUTEPT		;GET ADDRESS OF VBOOT EPT PAGE
	HRRI T1,-PGSIZ(T2)	;GET LAST ADDRESS TO UNLOCK
	CALL GPULK		;...
	HRRZ T2,BUTEPT		;GET ADDRESS OF VBOOT EPT PAGE
	HRLZI T1,PGSIZ(T2)	;GET FIRST ADDRESS TO UNLOCK
	HRR T1,BUTPGS		;GET LAST ADDRESS TO UNLOCK
	CALL GPULK		;...
	HLRZ P1,BUTPGS		;GET START ADDRESS OF VBOOT PAGES
	HRRZ P2,BUTPGS		;GET ENDING ADDRESS OF VBOOT PAGES
GSMD3:	HRRZ T2,P1		;GET ADDRESS
	SETZ T1,		;DESTROY PAGE
	CALL SETMPG		; ...
	ADDI P1,1000		;NEXT PAGE
	CAMG P1,P2		;DONE ?
	JRST GSMD3		;NO - LOOP
	RET			;DONE
;SUBROUTINES FOR BOOTSTRAP MANIPULATION

;SUBROUTINE TO COPY FROM BP IN T1 TO BP IN P3

BSCPY:	ILDB T2,T1		;GET A CHAR
	JUMPE T2,R		;DONE?
	IDPB T2,P3		;NO - COPY CHAR
	JRST BSCPY		;LOOP

;SUBROUTINE TO OUTPUT T1 TO BP IN P3 AS A DECIMAL NUMBER

BSDEC:	MOVEI T3,^D10		;DECIMAL
	CALL BSRAD		;CONVERT
	RET

;SUBROUTINE TO OUTPUT T1 TO BP IN P3 AS AN OCTAL NUMBER

BSOCT:	MOVEI T3,^D8		;OCTAL
	CALL BSRAD		;CONVERT
	RET

;COMMON/CONVENTIONAL PDP10 UNSIGNED RADIX PRINT

BSRAD:	IDIV T1,T3		;GET Q & R
	MOVEI T2,"0"(T2)	;CONVERT TO ASCII
	HRLM T2,(P)		;SAVE
	SKIPE T1		;DONE?
	CALL BSRAD		;NO - RECURSE
	HLR T2,(P)		;GET CHAR
	IDPB T2,P3		;OUTPT
	RET

;CREATE A GROUP OF PAGES AND LOCK IN CORE
;CALL
;T1/ START ADDR,,END ADDR
;	CALL CGPLK
;RETURNS+1: ERROR IN LOCKING A PAGE
;	+2: ALL OK

CGPLK:	PUSH P,P2		;SAVE AC
	MOVEI P2,[SKIP (P4)	;CREATE PAGE
		CALL MLKPG	;LOCK IT
		JUMPE T1,[POP P,(P) ;SCRAP RETURN
			JRST BSMGPX] ;EXIT
		RET]
	CALL BSMGP		;MAP THE REGION ONTO SUBR IN P2
	POP P,P2		;RESTORE AC
	JUMPE T1,R		;FAILURE?
	RETSKP			;NO.

;SUBROUTINE TO UNLOCK A GROUP OF PAGES
;T1/ START ADDR,,END ADDR
;	CALL GPULK
;RETURNS+1:	ALWAYS

GPULK:	PUSH P,P2		;SAVE AC
	MOVEI P2,MULKPG		;SUBR TO CALL
	CALL BSMGP		; MAP ONTO SUBR
	POP P,P2		;RESTORE AC
	RET

;COMMON SUBROUTINE TO MAP A GROUP OF PAGES FROM LH(T1) TO RH(T1)
;ONTO A SUBR. WHOSE ADDRESS IN IN P2. WHEN ENTERED, 
;T1/ MMSPTN,,CURRENT PAGE
;P2/ SUBR ADDRESS
;P3/ ORIGINAL ADDRESS PAIR
;P4/ CURRENT PAGE ADDRESS

BSMGP:	PUSH P,P3		;SAVE ACS
	PUSH P,P4		; ...
	MOVE P3,T1		;COPY ARG
	HLRZ P4,T1		;INITIALIZE CURRENT PAGE
BSMGP1:	HRRZ T1,P4		;BUILD PT.PN
	LSH T1,-PGSFT		; ...
	HRL T1,MMSPTN		; ...
	CALL (P2)		;CALL SUBR
	CAIGE P4,(P3)		;DONE?
	JRST [	ADDI P4,1000	;NO - GO TO NEXT PAGE
		JRST BSMGP1]
BSMGPX:	POP P,P4		;RESTORE ACS
	POP P,P3		; ...
	RET
;ROUTINES TO ADJUST SWPMON (THESE ROUTINES MUST BE INTERLOCKED)

RS (SWPMLF,1)			;COUNT OF LOCKERS OF SWP MON
RS (SWPMWF,1)			;COUNT OF WRITE ENABLERS OF SWP MON

;LOCK/UNLOCK SWPMON IN CORE

SWPMLK::AOSE SWPMLF		;FIRST LOCKER?
	RET			;NO, DONT LOCK IT AGAIN
	PUSH P,P2		;SAVE AC
	MOVEI P2,MLKPG		;SUBR TO MAP
SWPML1:	MOVE T1,SWPMBP		;GET BOUND PAIR
	CALL BSMGP		;MAP PAGES
	POP P,P2		;RESTORE AC
	RET

SWPMUL::SKIPL SWPMLF		;ALREADY UNLOCKED?
	SOSL SWPMLF		;NO, LAST ONE TO UNLOCK SWP MON?
	RET			;NO, LEAVE IT LOCKED
	PUSH P,P2		;SAVE AC
	MOVEI P2,MULKPG		;UNLOCK PAGES
	JRST SWPML1		;JOIN ABOVE

;WRITE ENABLE/PROTECT SWPMON

SWPMWE::AOSE SWPMWF		;FIRST TIME THRU
	RET			;NO, DONT NEED TO GO ON
	MOVEI 4,MMAPWE		;4/ADDRESS FOR WRITE-ENABLING
	JRST SWPM0		;GO WRITE ENABLE

SWPMWP::SKIPL SWPMWF		;ALREADY WRITE PROTECTED?
	SOSL SWPMWF		;NO, LAST TIME THRU?
	RET			;NO, LEAVE IT WRITE ENABLED
	MOVEI 4,MMAPWP		;4/ADDRESS FOR WRITE-PROTECTING

;AC 4 HAS ADDRESS FOR FUNCTION DESIRED.  SET UP ARGUMENTS FOR MMAPWP OR MMAPWE

SWPM0:	MOVEI 1,SWPMPG*PGSIZ	;1/STARTING ADDRESS OF SWAPPABLE MONITOR
	MOVE 2,SWCEND		;2/LENGTH OF SWAPPABLE MONITOR
	SUBI 2,SWPMPG-1
	CALL 0(D)		;CALL MMAPWE OR MMAPWP TO DO FUNCTION REQUESTED
	RET
;LOCK/UNLOCK EDDT, SYMTAB, AND INITIALIZATION CODE

ULKINI::SETZM DDTPRS		;INDICATE NO EDDT
	MOVEI T1,MULKPG		;ROUTINE TO USE
	JRST LKINI0		;JOIN COMMON CODE
LCKINI::MOVEI T1,MLKPG		; ROUTINE TO LOCK
	SETOM DDTPRS		;INDICATE EDDT PRESENT
LKINI0:	PUSH P,P2		;SAVE AC
	MOVE P2,T1		;COPY ARG
	PUSH P,Q1		;SAVE LOOP AC
	MOVE Q1,INIMAP		;GET AOBJN POINTER TO REGION TABLE
LKINI1:	SKIPN T1,(Q1)		;GET NEXT REGION BOUND PAIR
	JRST LKINI2		;EMPTY SLOT
	CALL BSMGP		;MAP PAGES ONTO ROUTINE DECIDED ABOVE
LKINI2:	AOBJN Q1,LKINI1		;LOOP
	POP P,Q1		;RESTORE ACS
	POP P,P2		; ...
	RET
;'MINI-EXEC' - SIMPLE COMMAND INTERPRETER FOR SPECIAL FUNCTIONS

	SWAPCD
EXEC2:	MOVEI 1,100		;ESTABLISH CORRECT TTY MODES
	MOVE 2,NORMTF
	SFMOD
	MOVE 2,TTICB1
	MOVE 3,TTICB2
	SFCOC
	CALL DTIALL
	MOVE 1,[XWD 20,^D34]
	ATI			;ASSIGN CONTROL-P FOR INTERRUPTS
	MOVE 1,[ITFFL,,EXECI]	;SETUP TO GET INTERRUPTS IN MON
	MOVEM 1,MONBK
	MOVEI 1,.FHSLF
	MOVEI 2,3		;ON CHNS 34 AND 35
	MOVEM 2,MONCHN
	AIC
	MOVE 2,JOBNO
	HRRZ 1,JOBDIR(2)
	JUMPE 1,[SETZM CAPMSK	;IF NOT LOGGED, FLUSH ALL CAPS
		SETZM CAPENB
		MOVE 3,CTRLTT
		CAME 3,CTYLNO	;ALLOW MINI-EXEC ONLY ON CTY
		JRST .+1
		HRLOI 3,777000	;GIVE ALL CAPS
		MOVEM 3,CAPMSK
		MOVEM 3,CAPENB
		MOVEI 3,OPERDN	;YES, GET DIRECTORY NUMBER OF <OPERATOR>
		MOVEM 3,JOBDIR(2) ;INDICATE LOGGED IN AS <OPERATOR>
		STOR 3,JSDIR	;SAVE AS CONNECTED DIRECTORY
		SETZRO JSCDF	;NO STRING IN JSB
		MOVE 3,STRTAB+PSNUM ;GET SDB ADDRESS OF STRUCTURE 0 (PUBLIC)
		LOAD 3,STRUC,(3) ;GET ITS UNIQUE STRUCTURE CODE
		STOR 3,JSUC	;SAVE AS CONNECTED STRUCTURE CODE
		MOVE 3,[[3
			 ASCIZ "OPERATOR"],,USRNAM]
		BLT 3,USRNAM+2	;SET DEFAULT USER NAME TO OPERATOR
		JRST .+1]
	JN JBMX,,EXECT0		;IF BEEN IN MX BEFORE, DONT CHECK CAPS
	MOVE 1,CAPENB		;LOOK AT CAPS, ALLOW MINI-EXEC
	TRNN 1,SC%WHL		;ONLY IFWHEEL
	JRST [	SKIPE FORKN	;OTHERWISE,
		HALTF		;HALTF IF BELOW EXEC
		SETONE JSFLO	;REMEMBER THE FORCED LOGOUT
		JRST LOGO]	;LOGOUT IF TOP FORK
	SETONE JBMX		;REMEMBER THAT JOB WAS IN MINI-EXEC
	; ..
;MINI-EXEC...

EXECT0:	HRROI 1,[ASCIZ /MX>/]
	PSOUT			;DO PROMPT
EXECT1:	PBIN			;GET USER INPUT
	CAIN T1,.CHCRT		;FLUSH CR
	JRST EXECT1
	CAIL 1,"A"+40		;LC CHAR?
	CAILE 1,"Z"+40
	SKIPA			;NO
	SUBI 1,40		;YES, CONVERT
	CAIN T1,.CHLFD		;IGNORE BLANK LINE
	JRST EXECT0
	MOVSI 4,-NXCMD		;SCAN COMMAND TABLE
EXECT2:	HLRZ 2,XCMD(4)		;GET KEY LETTER FOR THIS COMMAND
	CAMN 1,2		;SAME AS JUST TYPED?
	JRST [	HRRZ 2,XCMD(4)	;YES, GET DISPATCH ADDRESS
		JRST 0(2)]	;GO TO IT
	AOBJN 4,EXECT2		;TRY ALL COMMANDS
	JRST EXERR		;NOT FOUND, INDICATE ERROR

;MINI-EXEC COMMANDS

DEFINE CM (NAM,LOC)<
	XWD "NAM",LOC>

XCMD:	CM B,EBLT		;BLT SWP MON
	CM D,EDMP		;DUMP ON FILE
	CM E,GEX		;EXEC
	CM G,EGET		;GET FILE
	CM J,EJMP		;JUMP TO ADDRESS
	CM R,EREST		;RESET
	CM S,EST		;START
	CM <^>,MRETN		;DO MRETN
	CM </>,TODDT		;GO TO MDDT
NXCMD==.-XCMD
;'/' - ENTER MDDT

TODDT:	MOVE 1,.JBSYM		;MOVE MONITOR SYMBOL POINTER
	SKIPN @DDTSYM		;HAVE SYMTAB PTR ALREADY?
	MOVEM 1,@DDTSYM		;NO, SET ONE UP
	MOVE 1,.JBUSY
	SKIPN @DDTUSY		;DDT ALREADY HAS IT?
	MOVEM 1,@DDTUSY		;NO, SET IT UP
	JRST MDDT		;GO TO DDT

;'BLT SWP MON' - BLT SWAPPABLE CODE TO USER SPACE.  SHOULD DO RESET FIRST,
;THEN DUMP ON DTA--

EBLT:	TMSG <LT SWP MON>
	CALL OKGO
	MOVE 2,SWCEND		;LST PAGE
	LSH 2,^D9
	MOVEI 1,SWPMPG		;FIRST PAGE
	LSH 1,^D9
	HRLI 1,0(1)
	XBLTMU [BLT 1,777(2)]
	JRST EXEC2
;'RESET'

EREST:	TMSG <ESET>
	CALL OKGO
	MOVEI 1,-4
	KFORK			;KILL ALL FORKS
	MOVNI 1,1
	MOVSI 2,400000
	MOVE 3,[1B0+1000]	;CLEAR ALL PAGES FROM USER MAP
	PMAP
	MOVNI 1,1		;CLOSE ALL FILES
	CLOSF
	JFCL
	JRST EXEC2

;OKGO - ROUTINE TO LOOK FOR CONFIRMATION AFTER MINI-EXEC HAS 
;TYPED THE COMPLETION OF THE COMMAND. 

;	CALL OKGO

;RETURNS +1: CONFIRMATION FOUND
;IF NO CONFIRMATION WAS FOUND, GOES TO ERROR ROUTINE

OKGO:	PBIN
	CAIN T1,.CHCRT		;FLUSH CR
	JRST OKGO
	CAIN T1,.CHLFD		;CRLF MEANS GO
	RET
NODD1:	POP P,1			;ANYTHING ELSE MEANS ABORT
	JRST EXERR

;'EXEC'

GEX:	TMSG <XEC>
	CALL OKGO		;CONFIRM

;HERE TO GET A NEW COPY OF THE EXEC. REACHED FROM MINI-EXEC 'EXEC'
;COMMAND OR WHEN A NEW JOB IS BEING CREATED.  IF FILE EXISTS,
;GOES TO START IT. IF NOT, PRINTS MESSAGE AND GOES TO MINI-EXEC

STEX:	MOVSI 1,(GJ%OLD!GJ%PHY!GJ%SHT)	;OLD FILE+SHORT FORM
	HRROI 2,[ASCIZ /SYSTEM:EXEC.EXE/]
	GTJFN
STEXF:	JRST [	SKIPE CRJFLG	;IS THIS A CRJOB FAILURE?
		JRST CRJMEX	;YES. GO GIVE FAIL CODE
		HRROI T1,[ASCIZ /NO EXEC/]
		PSOUT
		JRST EXCRR]
	HRLI 1,.FHSLF
	GET
	ERJMP STEXF		;CATCH FAILURE OF GET
	SKIPN CRJFLG		;CREATED JOB?
	JRST GEX1
	HRLI T2,1		;INDICATE JOB HAS ALREADY SET CRJANS
	HLLM T2,CRJFLG		; BY MAKING FLAG POSITIVE
	JRST GEX1

CRJMEX:	MOVEI T1,CRJBX2		;PREVENT CRJOB GETTING INTO MINIEXEC
	SKIPGE CRJFLG		;JOB STILL BEING CREATED
	MOVEM T1,CRJANS		;YES.  GIVE FAIL CODE TO CREATOR,
	JRST LOGO		;AND FLUSH OUT THIS JOB.
;'JUMP TO ADDRESS' - JUMP TO USER ADDRESS

EJMP:	TMSG <UMP TO >
	MOVEI 1,100
	MOVEI 3,^D8		;GET OCTAL ADDRESS
	NIN
	 JRST EXERR
	HRRZM 2,-1(P)		;SAVE ADDRESS
	BKJFN			;BACKUP TO READ TERMINATOR
	 JFCL
	CALL OKGO
	JRST MRETN		;RETURN TO USER ADDRESS ON STACK
;'GET FILE'

EGET:	TMSG <ET FILE >
	MOVSI 1,(1B2+1B4+1B16+1B17) ;OLD FILE,CONFIRM,IFOF,SHORT
	MOVE 2,[XWD 100,101]
	GTJFN
	JRST EXERR
	HRLI 1,400000		;THIS FORK
	GET
	JRST EXEC2

;'START' - STARTS PROGRAM GOTTEN VIA 'GET'

EST:	TMSG <TART>
	CALL OKGO
GEX1:	HRRZ 1,ENTVEC
	JUMPN 1,.+2
	UMOVE 1,120		;USE JOBSA
	HRRZM 1,-1(P)
	JRST MRETN

;'DUMP ON FILE'

EDMP:	TMSG <UMP ON FILE >
	MOVSI 1,(1B0+1B3+1B4+3B17) ;NEW V,PNT O/N,CONFRM,IFOF,SHRT
	MOVE 2,[XWD 100,101]
	GTJFN
	JRST EXERR
	HRLI 1,400000		;THIS FORK
	MOVE 2,[XWD -1000,520000] ;SAVE ALL ADDRESS SPACE
	SETZ 3,
	SSAVE
	JRST EXEC2

;ERROR CONDITION - PRINT A QUESTION MARK AND GO BACK TO START OF
;MINI-EXEC

EXERR:	TMSG <  ?>
	MOVEI 1,100
	CFIBF			;CLEAR INPUT BUFFER

;PRINT CARRIAGE RETURN/LINE FEED

EXCRR:	SKIPE CRJFLG		;IS THIS A CRJOB?
	JRST CRJMEX		;YES. GET OUT OF MINIEXEC.
	TMSG <
>
	JRST EXEC2

EXCRRW:	TMSG <
>
	JRST EXEC2
;PSI TRAPPED TO HERE

EXECI::	EXCH 1,ITFFL		;SAVE 1, GET TRAP FL
	TLNN 1,(UMODF)		;USER?
	JRST EXECI1		;NO
	HLLZM 1,FFL		;SET FLAGS
	MOVE 1,ITFPC		;SET PC
	MOVEM 1,FPC		;YES, ENTER MONITOR AT THAT LOC
	MOVE 1,ITFFL		;RESTORE AC1
EXECI2:	MCENTR
	SETOM PRIMRY
	MOVEI 1,-4
	FFORK			;FREEZE FORKS
	SKIPE CRJFLG		;IS THIS A CRJOB?
	JRST CRJMEX		;YES. GET OUT OF MINIEXEC.
	MOVEI 1,100
	CFIBF			;CLEAR INPUT BUFFER
	CALL CLRINT		;CLEAR THE SOFTWARE INTERRUPT SYSTEM
	TRNN 2,2		;CHANNEL 34?
	JRST EXECI3
	MOVEI 1,101
	CFOBF			;CLEAR OUTPUT BUFFER
	TMSG <
ABORT
>
	JRST EXEC2

EXECI1:	MOVE P,UPP		;RESTORE TOP OF PDL
	MOVE 2,1(P)		;GET USER PC
	MOVEM 2,FPC		;STORE PC
	HRLI 1,(UMODF)
	MOVEM 1,FFL
	JRST EXECI2

EXECI3:	TMSG <
INTERRUPT AT >
	MOVEI 1,101
	HRRZ 2,UPP
	HRRZ 2,1(2)		;GET TOP PC
	MOVEI 3,10		;RADIX
	NOUT			;PRINT ADDRESS
	 JFCL
	JRST EXCRRW		;TO MINI-EXEC IF SC%WHL
;JSYS TO ENTER MDDT

.EXEC::	MCENT
	MOVEI 1,SC%WHL+SC%OPR
	TDNN 1,CAPENB
	JRST UJSYS		;UNDEFINED JSYS IF USER NOT SC%WHL
	JRST TODDT

	RESCD

;BUGHLT IN JOB CONTEXT TRAPS TO HERE

EXBUGH::MOVE 1,UPDL		;RESET STACK, ETC.
	MOVEM 1,FPC		;SET PC
	MOVSI 1,(UMODF)
	MOVEM 1,FFL
	MCENTR
	SETOM TRAPC
	SETZM NSKED
	SETZM INTDF
	SKIPN JOBNO		;JOB 0?
	JRST CHKRI		;YES, INTERRUPT
	HRRZ 1,PRIMRY
	HRROI 2,[ASCIZ /
BUGHLT at /]
	SETZ 3,
	SOUT
	HRRZ 2,BUGHLT
	MOVEI 3,^D8
	NOUT
	JFCL
	TMSG <
>
	JRST ITRAP

	SWAPCD
;HALT SYSTEM - REQUIRES SC%MNT (OR SC%WHL ETC.) CAPABILITY
;ACCEPTS TIME OF SYSTEM SHUTDOWN AND INITIATES SHUTDOWN PROCESS,
;INCLUDING NOTIFYING USERS, ETC.  ALSO ACCEPTS TIME WHEN SYSTEM
;WILL BE BACK UP WHICH IS AVAILABLE FOR USER INFORMATION ONLY.
; 1/ SHUTDOWN TIME (GTAD FORMAT)
; 2/ EXPECTED UP TIME (GTAD FORMAT)
;	HSYS
; RETURNS +1: ERROR
; RETURNS +2: SUCCESS

.HSYS::	MCENT
	MOVE 2,CAPENB		;CHECK USER CAPABILITIES
	TXNN 2,SC%WHL+SC%OPR+SC%MNT ;USER ALLOWED TO DO HALT?
	RETERR(CAPX2)		;NO, RETURN BAD
	JUMPG 1,HSYS1		;JUMP UNLESS ABORTING SHUTDOWN
	MOVE T1,HSYST1		;GET OLD TIME
	JUMPE T1,HSYS0		;IF NONE, DONT TYPE MESSAGE
	SETZM HSYST1		;CLEAR OLD TIME
	CALL TADDIF		;GET MILLISECONDS TO SHUTDOWN
	HRROI T2,[ASCIZ/
[Shutdown cancelled]
/]
	SKIPL HSYST3		;WAS A MESSAGE EVER PRINTED
	CALL ALLMSG		;YES, INFORM USERS OF CANCELLATION
HSYS0:	SMRETN			;SUCCESSFUL RETURN

HSYS1:	PUSH P,1		;HOLD THE DESIRED SHUTDOWN
	CALL TADDIF		;COMPUTE MILLISECONDS TO SHUTDOWN
	TLNE 1,770000		;OVER A WEEK AHEAD, OR NEGATIVE?
	RETERR(TIMEX2)		;YES, GIVE BAD TIME FAILURE
	POP P,2			;RECOVER SHUTDOWN TIME
	MOVEM 2,HSYST1		;STORE FOR EXEC TO SEE
	SETOM HSYST3		;FLAG FOR FIRST MESSAGE
	UMOVE 2,2		;GET EXPECTED UP TIME
	CAMG 2,HSYST1		;CHECK RANGE
	SETZ 2,			;JUNK, ASSUME UNKNOWN
	MOVEM 2,HSYST4		;SAVE FOR EXEC TO TELL USERS
	AOS JB0FLG		;POKE JOB 0 TO DO MSG
	SMRETN

;COMPUTE TIME UNTIL SHUTDOWN IN MILLISECONDS
; A/ TAD OF SHUTDOWN
;	CALL TADDIF
; RETURN +1, A/ MILLISECONDS TO SHUTDOWN

TADDIF:	PUSH P,1
	CALL LGTAD		;GET CURRENT TIME AND DATE
	POP P,2
	SUBM 2,1		;GET POSITIVE DIFFERENCE OF TIMES
	CAML T1,[^D8,,0]	;WITHIN 8 DAYS?
	JRST [	MOVSI T1,377777	;NO, RETURN VERY LARGE NUMBER
		RET]
	MUL T1,[^D<24*3600*1000>]	;MILLISECONDS/DAY
	DIV T1,[1B17]		;SHIFT BINARY POINT
	RET
;HSYST1 AND HSYST4 ARE A GETAB TABLE

NHSYST==2			;NUMBER OF VALUES IN GETAB TABLE
NR HSYST1,1			;SYSTEM SHUTDOWN TIME OR 0
NR HSYST4,1			;EXPECTED UP TIME

NR HSYST2,1			;INTERVAL (IN MS) TO NEXT MSG TIME
NR HSYST3,1			;TIME OF NXT MSG IN MS BEFORE SHUTDOWN

;POINTS (IN MINUTES BEFORE SHUTDOWN) AT WHICH TO DO NOTIFICATION

CTIMS:	^D<BYTE (9) 60,30,15,10>
	^D<BYTE (9) 5,1,0>
;ROUTINE TO TYPE SYSTEM SHUTDOWN MESSAGE IF NECESSARY.
;CALLED ONLY BY JOB 0 CHKR.

CHKHSY:	SKIPN A,HSYST1		;SHUTDOWN ABORTED?
	RET			;YES
	CALL TADDIF		;COMPUTE TIME UNTIL SHUTDOWN
	MOVE 3,HSYST3		;DUE TIME FOR MESSAGE
	CAMN 3,[-1]		;FIRST TIME HERE?
	JRST CHKHS3		;YES - GIVE MESSAGE ANYWAY
	CAMLE 1,HSYST3		;NO - MESSAGE DUE NOW?
	JRST [	SUB 1,HSYST3	;NO, COMPUTE INTERVAL TO NEXT MSG
		MOVEM 1,HSYST2	;LEAVE IT FOR CHKR
		RET]		;RETURN QUIETLY
CHKHS3:	ADDI 1,^D30000		;ROUND TO NEAREST MINUTE
	IDIVI 1,^D60000		;CONVERT TO INTEGER MINUTES
	JUMPLE 1,CHKHS4		;IF NO TIME LEFT, GO KILL SYSTEM
	CALL THSYS		;SEND MSG TO ALL TTYS
	CAILE 1,^D60		;LESS THAN AN HOUR?
	JRST [	MOVEI 2,^D60	;NO - SET NEXT MESSAGE FOR 1 HOUR NOW
		CAILE 1,^D120	;BETWEEN 1 AND 2 HOURS
		MOVEI 2,^D120	;MAKE FIRST NOTICE BE AT 1 HOUR
		JRST CHKHS5]
	MOVE 3,[POINT 9,CTIMS]	;SETUP TO FIND NEXT NOTIFY TIME
	ILDB 2,3		;GET A TIME FROM LIST
	CAMG 1,2		;SHORTER THAN ACTUAL TIME REMAINING?
	JRST .-2		;NO, KEEP LOOKING
CHKHS5:	IMULI 2,^D60000		;CONVERT MINUTES TO MILLISECONDS
	MOVEM 2,HSYST3		;SET AS NEXT MESSAGE TIME
	JRST CHKHSY		;FINAL CHECK AND RETURN

;SHUTDOWN TIME HAS ARRIVED, COMMENCE SHUTDOWN.

CHKHS4:	MOVX T1,SF%RMT!SF%LCL!SF%PTY
	ANDCAM T1,FACTSW	;ONLY ALLOW CTY TO LOGIN
	CALL DWNMSG		;SEND LAST MESSAGE
	SETZM HSYST1		;CLEAR FLAGS IN CASE RESTARTED
	MOVSI 1,(1B1)		;CREATE FORK WITH SAME CAPS
	CFORK
	 BUG(HLT,HSYFRK,<HSYS-JOB 0 CFORK FAILED>)
	MOVEI 2,HSYS4		;SET IT TO START NEXT SHUTDOWN PHASE
	MSFRK			;START FORK IN MONITOR MODE
	RET
;FORK STARTED AT SHUTDOWN TIME
;COMMENCE SHUTDOWN. PREVENT NEW JOBS, LOGOUT EXISTING JOBS, HALT.

HSYS4:	MOVSI 1,(UMODF)
	MOVEM 1,FFL		;ESTABLISH USUAL JSYS CONTEXT
	SETZM FPC		;SET PC
	MCENTR
	MOVX T1,SF%RMT!SF%LCL!SF%PTY
	ANDCAM T1,FACTSW	;ONLY ALLOW CTY TO LOGIN
	MOVE 6,[XWD -NJOBS+1,1]	;START WITH JOB 1
	SKIPGE JOBRT(6)		;LOOK FOR EXISTING JOB
HSYS41:	AOBJN 6,.-1
	JUMPGE 6,HSYS7		;JUMP IF DONE
	HLRZ 1,JOBPT(6)		;CHECK CTRLTT FOR JOB
	CAMN 1,CTYLNO		;CTY?
	JRST HSYS41		;YES, DON'T FLUSH
	MOVEI 1,0(6)		;GET JOB NUMBER
	LGOUT			;LOG IT OUT
	 JFCL
	JRST HSYS41

HSYS7:	MOVEI 5,^D120000	;MAX TIME TO WAIT FOR JOBS TO FINISH
	ADD 5,TODCLK		;LOGGING OUT
HSYS8:	CAMG 5,TODCLK		;WAITED MAX TIME?
	JRST HSYS9		;YES, PROCEED WITH SHUTDOWN
	MOVE T2,HSYST4		;GET TIME BACK UP
	MOVEI T1,0		;SHOULD BE CODE FOR REASON FOR HALT
	CALL IMPHLT		;TELL THE NETWORK WE ARE GOING AWAY
	MOVE 6,[XWD -NJOBS+1,1]	;START WITH JOB 1
	SKIPGE JOBRT(6)		;SEE IF ANY JOBS STILL EXIST
HSYS81:	AOBJN 6,.-1
	JUMPGE 6,HSYS9		;NONE FOUND, PROCEED
	HLRZ 1,JOBPT(6)		;CHECK FOR CTY JOB
	CAMN 1,CTYLNO
	JRST HSYS81		;YES, IGNORE
	MOVEI 1,^D1000		;NO, WAIT 1 SEC., THEN CHECK AGAIN
	DISMS
	JRST HSYS8

HSYS9:	SETZM DDTIME		;POKE DDMP
	AOS JB0FLG
	MOVEI 5,^D10		;WAIT 10 SEC MAX FOR JOB 0
HSYS91:	MOVEI 1,^D1000		;WAIT 1 SEC
	DISMS
	SKIPN DDTIME		;DDMP FINISHED?
	SOJG 5,HSYS91		;NO, WAIT MORE
	JUMPLE 5,HSYS9		;IF TIMED OUT, TRY AGAIN
	SKIPE IOIP		;WRITES IN PROGRESS?
	JRST .-1		;YES, WAIT FOR COMPLETION
	MOVE 1,CTYLNO
	HRROI 2,[ASCIZ /
Shutdown complete
/]
	TTMSG			;NOTIFY OPERATOR
	MOVEI 1,^D15000
	DISMS
	HALTF
;ROUTINE TO SEND GOING DOWN MESSAGE TO ALL LINES

THSYS:	STKVAR <TIM,<MSG,20>>
	MOVEM T1,TIM		;SAVE NUMBER OF MINUTES
	HRROI T1,MSG		;INIT PTR TO MSG
	HRROI T2,[ASCIZ /
[System going down/]
	SETZ T3,
	SOUT
	MOVE T2,TIM		;GET TIME
	CAILE T2,^D60		;LESS THAN ONE HOUR?
	JRST THSYS1		;NO - SPECIAL MESSAGE
	HRROI T2,[ASCIZ / in /]
	SETZ T3,
	SOUT
	MOVE T2,TIM		;GET TIME
	CAIN T2,1		;THE 'ONE' CASE?
	JRST [	HRROI T2,[ASCIZ /one minute!!]
/]
		JRST HSYS51]	;YES, SPECIAL MESSAGE
	MOVEI T3,^D10
	NOUT
	 JFCL
	HRROI T2,[ASCIZ / minutes/]
	SETZ T3,
	SOUT			;APPEND TO MESSAGE
THSYS1:	HRROI T2,[ASCIZ / at /]
	SETZ T3,0
	SOUT
	MOVE T2,HSYST1		;TELL ACTUAL TIME
	MOVEI T3,0
	ODTIM			;IN MESSAGE
	HRROI T2,[ASCIZ /]
/]
HSYS51:	SETZ T3,
	SOUT
	HRROI T2,MSG		;POINT TO CONSTRUCTED MSG
	CALL ALLMSG		;SEND TO ALL LINES
	MOVE T1,TIM		;RESTORE TIME
	RET

;ROUTINE TO SEND LAST MESSAGE, INCLUDING EXPECTED UPTIME.

DWNMSG:	STKVAR <<MSG,20>>
	HRROI T1,MSG
	HRROI T2,[ASCIZ /
[System down/]
	SETZ T3,
	SOUT
	SKIPN HSYST4		;HAVE AN UPTIME?
	JRST DWNMS1		;NO
	HRROI T2,[ASCIZ /, up again at /]
	SOUT
	MOVE T2,HSYST4		;GET UPTIME
	MOVEI T3,0		;STANDARD FORMAT
	ODTIM			;CONVERT TIME TO TEXT
DWNMS1:	HRROI T2,[ASCIZ /]
/]
	SETZ T3,
	SOUT
	HRROI T2,MSG		;HAVE TEXT, NOW SEND IT TO ALL LINES
	CALL ALLMSG
	RET
;PERIODIC (10 SEC) CHECK OF THINGS

CHKR::	SETZM JB0FLG		;CLEAR REQUEST FLAG
	MOVE 1,TODCLK
	ADD T1,CHKPER		;NOW PLUS MAX CHECK PERIOD
	MOVEM 1,CHKTIM		;LEAVE FOR SCHED TO CHECK
	CALL RESLCK		;LOCK OR UNLOCK RESIDENT FREE SPACE
	CALL DTEPOL		;GO SEE IF ANY DTE'S NEED ATTENTION
	SKIPL DRMJ0R		;DRUM JOB 0 REQUEST?
	CALL CHKDRM		;YES
	MOVE 1,DSKRCE		;DISK RECOVERABLE ERRORS
	CAME 1,CHKDRE		;DIFFERENT THAN LAST CHECK?
	CALL CHKDE1		;YES, GO PRINT INFO
	MOVE 1,DSKNRE		;DISK NON-REC ERRORS
	CAME 1,CHKDNE		;DIFFERENT?
	CALL CHKDSK		;PRINT INFO
	SKIPE USGBEG		;CHECK USAGE QUEUE
	CALL USGMES		;HAVE SOMETHING - EMPTY QUEUE
	CALL CHKCKP		;CHECK ON CHECKPOINT
	CALL DDMP0		;DISK BACKUP
	SKIPE HSYST1		;SHUTDOWN PROCESS ACTIVE?
	CALL CHKHSY		;YES, CHECK IT
	MOVE A,TODCLK
	CAMGE A,UMSGTM		;TIME FOR USER MESSAGES?
	JRST CHKUM1		;NO
	CALL CHKDKS		;CHECK DISK SPACE
	CALL CHKDMS		;CHECK DRUM SPACE
	CALL CHKSPT		;CHECK SPT SPACE
	MOVE A,TODCLK		;SET TIME FOR NEXT MSG
	ADD A,[^D<5*60000>]	;IN 5 MINUTES
	MOVEM A,UMSGTM
CHKUM1:	CALL CHKNET		;CHECK STATE OF ARPANET
	CALL CHKMOS		;CHECK IF MEMORY DIAG NEEDS TO RUN
	MOVEI 1,^D30000		;SETUP TO DISMISS FOR 30 SEC
	SKIPE HSYST1		;IS SHUTDOWN ACTIVE?
	JRST [	CAMLE 1,HSYST2	;YES, NXT MSG DUE WITHIN 30 SEC?
		MOVE 1,HSYST2	;YES, DISMISS UNTIL MSG DUE
		JRST .+1]
	CALL SETBKT		;SETUP TIME FOR DISMISS TEST
	HRRI 1,JB0TST		;OR JB0FLG
	MDISMS
	JRST CHKR

;MAXIMUM CHECK PERIOD - USED TO SET SCHEDULER ALARM

CHKPER:	^D<4*60000>		;4 MINUTES

	RESCD

JB0TST:	SKIPE JB0FLG		;EXPLICIT REQUEST?
	JRST 1(4)		;YES, WAKEUP
	JRST BLOCKT		;NO, GO TEST TIME

	SWAPCD

NR UMSGTM,1			;TIME OF NEXT USER MESSAGES
NR MOSFRK,1			;FORK I.D. OF MEM DIAG FORK
CHKH1:	CALL TTDECP		;OUTPUT DECIMAL
	MOVEI 2," "
	BOUT
CHKR1:	CALL LGTAD		;CURRENT TIME AND DATE
	JUMPL 1,CHKR2		;IF NOT SET
	MOVE 2,1
	MOVEI 1,101
	SETZ 3,
	ODTIM			;INCLUDE TAD WITH MESSAGE
CHKR2:	TMSG <
>
	RET

;INITIATE PAGE MOVEMENT TO DISK IF APPROPRIATE

DDMP0:	MOVE A,DRMFRE		;DRUM SPACE LOW?
	CAMGE A,DRMIN0
	JRST [	TMSG <DDMP: SWAP SPACE LOW ACTION.
>
		JRST DDMPA]
	MOVE A,TODCLK		;TIME FOR NEXT CYCLE?
	CAMGE A,DDTIME
	RET			;NO
DDMPA:	CALL DDMP		;DO THE WORK
	 RET			;DDMP FAILED. RUN IT AGAIN ASAP
	MOVX A,^D60000		;SET TIME FOR NEXT CYCLE AS 1 MINUTE
	ADD A,TODCLK		; FROM NOW.
	MOVEM A,DDTIME
	RET
;ROUTINE CALLED BY CHKR TO SEE IF ANY ACTION NEEDED FOR THE
;MOS MEMORY DIAGNOSTIC

CHKMOS:	SKIPN T1,MOSFRK		;NOW RUNNING?
	JRST CHKMO1		;NO. SEE IF WE SHOULD RUN IT
	RFSTS			;YES. SEE WHAT IT IS DOING
	LOAD T1,RF%STS,T1	;GET ITS STATUS
	CAIE T1,.RFHLT		;HALTED?
	CAIN T1,.RFFPT		;OR ERROR?
	SKIPA T1,MOSFRK		;YES.
	RET			;NO. ALL DONE THEN
	KFORK			;KILL THE PROCESS
	SETZM MOSFRK		;NO MORE FORK HERE

;HERE IF NO FORK NOW RUNNING. SEE IF ONE NEEDED

CHKMO1:	SKIPE ERRTBL		;HAVE SOME ENTRIES TO PROCESS
	CALL RUNMOS		;YES. START THE DIAG
	RET			;DONE

;ROUTINE TO RUN THE MOS MEM DIAGNOSTIC

RUNMOS:	TDZA T3,T3		;MAIN ENTRY POINT
RUNMO1:	MOVEI T3,1		;SYS START UP ENTRY
	MOVX T1,<GJ%OLD!GJ%SHT!GJ%PHY>
	HRROI T2,[ASCIZ /SYSTEM:TGHA.EXE/] ;THE DIAG
	CALL RUNDIR		;RUN TGHA
	 RET			;DIDN'T DO IT.
	MOVEM T1,MOSFRK		;SAVE FORK HANDLE FOR LATER
	RET			;AND DONE
;ROUTINE CALLED BY JOB 0 TO FINISH LOADING UP SYSERR BLOCK
;  FOR BUGHLT'S AND BUGCHK'S
;ACCEPTS IN T1/	ADDRESS OF SYSERR BLOCK
;RETURNS +1:	ALWAYS

LOGBUG::SAVEQ			;SAVE PERMANENT ACS
	TRVAR <BUGSP,BUGPNM,BUGTAD>
	MOVEM T1,Q1		;SAVE POINTER TO SYSERR BLOCK
	MOVEI T1,.PRIOU		;SEND MESSAGE TO CTY
	MOVE T4,SEBDAT+BG%FLG(Q1) ;GET TYPE OF BUG CHECK
	HRROI T2,[ASCIZ/
********************
*BUG/]
	SETZ T3,
	SOUT			;START MESSAGE
	HRROI T2,[ASCIZ/HLT "/]
	CAIN T4,BG%CHK		;BUGCHK?
	HRROI T2,[ASCIZ/CHK "/]	;YES
	CAIN T4,BG%INF		;INFORMATIONAL BUG CHECK?
	HRROI T2,[ASCIZ/INF "/]	;YES
	SOUT
	MOVE T4,[POINT 6,SEBDAT+BG%NAM(Q1)]
LOGBF1:	ILDB T2,T4		;NOW TYPE OUT 6 CHAR NAME
	JUMPE T2,LOGBF2		;IF AT END, STOP TYPING
	ADDI T2," "		;TRANSLATE SIXBIT TO ASCII
	BOUT			;OUTPUT CHARACTER
	TLNE T4,770000		;AT END OF NAME YET?
	JRST LOGBF1		;NO, LOOP BACK FOR REST OF CHARS
LOGBF2:	HRROI T2,[ASCIZ/" at /]
	SOUT
	MOVE T2,SEBDAT+BG%DAT(Q1) ;GET TIME AND DATE OF BUG CHECK
	ODTIM			;TYPE OUT TIME AND DATE
	HRROI T2,[ASCIZ/
*/]
	SOUT
	SKIPN Q2,BUGTP		;TABLE POINTER EXIST?
	JRST [	HRROI T2,[ASCIZ/Message table not available/]
		JRST LOGBF4]
LOGBF3:	MOVE T4,0(Q2)		;SEARCH FOR ADDRESS IN TABLE
	HLRZ T2,T4		;GET ADDRESS
	CAME T2,SEBDAT+BG%ADR(Q1)	;FOUND IT?
	AOBJN Q2,LOGBF3		;NO, LOOP BACK TIL WE DO
	JUMPGE Q2,[HRROI T2,[ASCIZ/Message not found for this address/]
		JRST LOGBF4]
	HRROI T2,0(T4)		;GET POINTER TO MESSAGE STRING
	HRRZM T2,BUGSP		;SAVE IT FOR SYSERR BLOCK
LOGBF4:	SOUT			;TYPE OUT STRING
	SETZM BUGPNM		;START WITH A NULL PROGRAM NAME
	SKIPGE SEBDAT+BG%JOB(Q1)	;IS THERE A JOB?
	JRST LOGBF5		;NO, SKIP JOB/USER LINE
	HRROI T2,[ASCIZ/
*Job: /]
	SOUT
	HRRZ T2,SEBDAT+BG%JOB(Q1)	;GET JOB NUMBER
	MOVEI T3,12		;TYPE IT IN DECIMAL
	NOUT
	 JFCL
	MOVE T2,JOBPNM(T2)	;GET PROGRAM NAME
	MOVEM T2,BUGPNM		;SAVE NAME OF PROGRAM
	HRROI T2,[ASCIZ/, User: /]
	SETZ T3,
	SOUT
	HRRZ T2,SEBDAT+BG%USR(Q1)	;GET USER LOGGED IN DIR NUMBER
	HRLI T2,USRLH		;TURN IT INTO PROPER FORMAT USER NUMBER
	DIRST			;TYPE OUT USER NAME
	 MOVEI T1,.PRIOU	;FAILED. RESTORE DESTINATION ADDRESS
LOGBF5:	SKIPG Q2,SEBDAT+BG%RCT(Q1)	;GET COUNT OF REGISTERS SAVED
	JRST LOGBF7		;NO REGISTERS TO BE TYPED
	HRROI T2,[ASCIZ/
*Additional data: /]
	SOUT
	MOVEI T4,SEBDAT+BG%REG(Q1)	;GET POINTER TO REGISTER AREA
LOGBF6:	MOVE T3,[NO%MAG+10]	;TYPE THEM IN UNSIGNED OCTAL
	MOVE T2,0(T4)		;GET NEXT REG TO TYPE
	NOUT
	 JFCL
	SOJLE Q2,LOGBF7		;DONE?
	HRROI T2,[ASCIZ/, /]	;NO
	SETZ T3,
	SOUT
	AOJA T4,LOGBF6		;GO TYPE OUT REST

LOGBF7:	HRROI T2,[ASCIZ/
********************
/]
	SETZ T3,
	SOUT
	MOVE T1,CRSTD1		;GET DATE OF BUGCHK
	CAMN T1,[-1]		;IS THERE ONE SET?
	CALL LGTAD		;NO, SEE IF IT IS SET NOW
	MOVEM T1,BUGTAD		;SAVE DATE AND TIME OF BUGCHK
	MOVE T1,Q1		;GO COPY REST OF DATA TO BLOCK
	MOVE T2,[-NBUGET,,BUGET]
	CALL SEBCPY
	 JFCL
	SOS BUGCNT		;COUNT DOWN THE QUEUED UP BLOCK COUNT
	SETZM BUGCHK		;CLEAR OUT LAST BUGCHK ADR
	RET			;FINISHED

BUGET:	SEBPTR BG%SVN,SBTSTR,SVN ;SYSTEM NAME
	SEBPTR BG%PNM,SBTWD,BUGPNM ;PROGRAM NAME
	SEBPTR BG%DAT,SBTWD,BUGTAD ;TIME AND DATE OF CRASH
	SEBPTR BG%MSG,SBTSTR,@BUGSP ;BUG MESSAGE
NBUGET==.-BUGET
;SEND TEXT TO ALL LINES, WAIT FOR COMPLETION
; 2/ PTR TO ASCIZ MESSAGE
;	CALL ALLMSG
; RETURN +1 ALWAYS, WAIT LONG ENOUGH FOR MESSAGE TO APPEAR ON 110 BAUD
;LINES.

ALLMSG::SETO 1,			;SAY ALL LINES
	HLRZ 3,2		;CHECK LH OF POINTER
	CAIN 3,-1		;DEFAULT?
	HRLI 2,(<POINT 7,0>)	;YES, DO IT
	TTMSG			;TYPE THE STUFF
	RET			; AND RETURN
CHKDRM:	HRROI 1,[ASCIZ /
*****DRUM ERR: /]
	PSOUT
	MOVSI 6,-NDRMEW		;# OF DRUM ERROR WORDS
	HRRI 6,DRMCFE		;FINISH AOBJN PTR
CHKD1:	MOVE B,0(6)		;GET WORD
	CALL TTOCTP		;PRINT IT
	TMSG <
	>
	AOBJN 6,CHKD1
	SETOM DRMJ0R		;RESET REQUEST FLAG
	RET			;RETURN

CHKDMS:	MOVE 1,DRMFRE
	CAMLE 1,DRMIN0		;DRUM SPACE LOW?
	RET			;NO
	HRROI 2,[ASCIZ /
[Caution--Swapping space low]
/]
;	SKIPE WRMSGF		;WARN USERS?
;	CALL ALLMSG		;YES, DO IT
	HRROI 1,[ASCIZ /
*****Swapping space low, /]
	PSOUT
	MOVE 2,DRMFRE
	JRST CHKH1		;PRINT FREE COUNT

CHKSPT:	MOVE 1,SPTC
	CAMGE 1,SPC1		;SPT LOW?
	RET			;NO
	HRROI 2,[ASCIZ /
[Caution--SPT space low]
/]
;	SKIPE WRMSGF		;WARN USERS?
;	CALL ALLMSG		;YES, DO IT
	HRROI 1,[ASCIZ /
*****SPT space low, /]
	PSOUT
	MOVN 2,[NOFN-SSPT]
	SUB 2,SPTC		;SPACE LEFT
	JRST CHKH1
;CHECK DSK SPACE

CHKDKS:	SKIPGE T1,EXPFRK	;EXPUNGE FORK RUNNING?
	RET			;YES - EXIT QUIETLY
	JUMPE T1,CKDKS1		;NO - EXISTS?
	SETZM EXPFRK		;YES - KILL IT
	KFORK			;...
CKDKS1:	SETZM T1		;ASSUME PUBLIC STRUCTURE
	CALL GSTRPG		;GET COUNT OF USED AND FREE PAGES ON STRUCTURE
	MOVE T1,T2		;GET FREE COUNT
	SUB 1,SYSSPC		;LESS 'BUFFER'
	CAILE 1,SYWRND		;LOW?
	RET			;NO
	PUSH P,2		;SAVE FREE COUNT
	HRROI 2,[ASCIZ /
[Caution--Disk space low on PS:]
/]
	SKIPE WRMSGF		;WARN USERS?
	CALL ALLMSG		;YES, DO IT
	SKIPN T1,EXPTIM		;ENOUGH TIME SINCE LAST EXPUNGE?
	MOVX T1,<^D<30*60000>>	;DONT DO EXPUNGES IN FIRST 30 MIN 
	CAMG T1,TODCLK
	CALL EXPALL		;YES, DO EXPUNGE *
	HRROI 1,[ASCIZ /
*****Disk space low on PS:, /]
	PSOUT
	POP P,2			;RESTORE COUNT OF FREE PAGES
	CALLRET CHKH1

;ROUTINE TO DO EXPUNGE * WHEN DISK SPACE LOW
;START FORK AND MARK IT RUNNING
;	CALL EXPALL
;RETURNS +1 ALWAYS

NR EXPTIM,1		;TIME OF LAST EXPUNGE PLUS MIN INTERVAL
NR EXPFRK,1		;        0 := NO EXPUNGE FORK
			; -1,,FRKH := FORK RUNNING
			;  0,,FRKH := EXPUNGE DONE

EXPALL:	MOVX T1,CR%CAP		;PASS CAPABILITIES DOWN
	CFORK			;CREATE FORK
	 BUG (HLT,EXPAFK,<EXPALL: JOB 0 CFORK FAILED>)
	HRROM T1,EXPFRK		;MARK FORK RUNNING
	MOVEI T2,EXPAL0		;START INFERIOR
	MSFRK			; IN MONITOR MODE
	RET			;RETURN (WAIT TILL DONE)

;EXPUNGE FORK STARTS HERE

EXPAL0:	MOVSI T1,(UMODF)	;SET FUNNY JSYS CONTEXT
	MOVEM T1,FFL
	SETZM FPC		;SET PC
	MCENTR
	CALL EXPAL1		;AWAY WE GO
	HRRZS EXPFRK		;SAY WE ARE DONE
	HALTF			;AND STOP

EXPAL1:	MOVX T2,SF%CDE!SF%BTE
	TDNE T2,FACTSW		;ANY BIT TABLE ERRORS?
	RET			;YES. DON'T EXPUNGE
	HRROI T2,[ASCIZ /
[Deleted files will be expunged in 30 seconds]
/]
	CALL ALLMSG
	MOVEI T1,^D30000
	DISMS			;GIVE USERS TIME TO UNDELETE
	MOVX T1,RC%AWL		;ALLOW WILD CARDS
	HRROI T2,[ASCIZ "PS:<*>"]
	RCDIR			;GET FIRST DIRECTORY NUMBER
	 ERJMP [BUG (CHK,EXPRCD,<EXPALL: RCDIR FAILURE>)
		JRST EXPAL3]	;WE TRIED
EXPAL2:	SETZ T1,		;NOTHING SPECIAL
	MOVE T2,T3		;PUT DIRECTORY NUMBER IN RIGHT PLACE
	DELDF			;EXPUNGE
	 ERJMP .+1		;IGNORE FAILURES
	MOVX T1,RC%STP!RC%AWL	;STEP TO NEXT
	MOVE T3,T2		;WHERE WE LEFT OFF
	HRROI T2,[ASCIZ "PS:<*>"] ;WHERE WE STARTED
	RCDIR			;...
	 ERJMP EXPAL3		;QUIT ON FAILURE
	TXNN T1,RC%NMD		;DONE?
	JRST EXPAL2		;NO - KEEP GOING

EXPAL3:	MOVX T1,<^D<30*60000>>	;DONE, SET NEXT POSSIBLE TIME
	ADD T1,TODCLK
	MOVEM T1,EXPTIM
	HRROI T2,[ASCIZ /
[System expunge completed]
/]
	SKIPE WRMSGF
	CALL ALLMSG		;NOTIFY USERS
	RET			;DONE
CHKDSK:	RET			;NOP

CHKDE1:	RET			;NOP

;UTILITY NUMBER PRINTERS
;DECIMAL PRINT FOR LESS THAN 18 BIT NUMBERS
;OCTAL PRINT FOR MORE THAN 18 BIT NUMBERS DOES DDT HALFWORD FORMAT.

;B/ NUMBER TO PRINT
;	CALL TTXXXP	;XXX=(DEC,OCT)
;NUMBER PRINTED TO PRIMARY OUTPUT

TTDECP:	SKIPA C,[EXP ^D10]	;IN DECIMAL
TTOCTP::MOVEI C,^D8		;IN OCTAL
	MOVEI A,.PRIOU		;OUTPUT TO PRIMARY
	TLNN B,-1		;LH NON-0?
	JRST TTOCT1		;NO, SIMPLE PRINT
	PUSH P,B		;SAVE DATA
	HLRZ B,B		;PRINT LH
	NOUT
	 JFCL
	MOVEI B,","		;PRINT ,,
	BOUT
	BOUT
	POP P,B			;RECOVER DATA
	HRRZ B,B
TTOCT1:	NOUT			;PRINT RH
	 JFCL
	RET

;ANY INTERRUPT WILL EVENTUALLY TRAP TO HERE

CHKRI:	MOVE P,UPP
	ADD P,BHC+2		;RESET STACK
	SETZM SLOWF
	SETOM INTDF
	SETZM PSIBW
	HRROI 1,[ASCIZ /
*****Job 0 crash, continuing
/]
	PSOUT
	JRST CHKR

NR CHKDRE,1			;COUNT OF REC. ERRORS AT LAST REPORT
NR CHKDNE,1			; "" NON-REC. ""
NR CHKDMC,1
;ROUTINE TO FINISH LOGGING OF PARITY ERROR - RUN IN JOB 0 CONTEXT

; T1/ ADDRESS OF SYSERR BLOCK

PFCPJ0::SAVEQ
	HLRZ FX,SEBDAT+PT%JOB(T1) ;GET FORKX AT TRAP
	CAIE FX,-1
	SKIPGE FKPT(FX)
	RET			;IN SCHED OR FORK KILLED, NO DATA
	LOAD T2,FKJOBN		;GET JOB NUMBER
	HRRM T2,SEBDAT+PT%JOB(T1) ;REPORT IT
	HRRZ T3,JOBDIR(T2)	;GET LOGGED-IN DIRECTORY
	HRLI T3,USRLH		;MAKE IT A USER NUMBER
	MOVEM T3,SEBDAT+PT%USR(T1) ;REPORT IT
	MOVE T3,JOBPNM(T2)	;GET PROGRAM NAME
	MOVEM T3,SEBDAT+PT%PGM(T1) ;REPORT IT
	RET
;HERE ON FIRST OCCURRANCE OF MUUO IN FORK.  MAP TOPS10 COMPATIBILITY
;MODULE INTO USER ADDRESS SPACE.
;THIS CODE ALSO IMPLEMENTS THE VIROS/TOPS10 TEST UUO.  IF
;THE USER DOES A GETTAB (CALLI 41) WITH ARGUMENT 112,,11 (TABLE
;11, WORD 112) THEN BITS 18-23 TELL WHAT KIND OF MONITOR IT IS.
;IN PARTICULAR, 4 MEANS VIROS.
;THIS CODE CHECKS FOR THIS SPECIFIC CALLI AND ARGUMENT SO THAT
;THE USER PROGRAM CAN EXECUTE IT WITHOUT ACTUALLY INVOKING THE
;COMPATIBILITY MODULE.

GETPAT::MOVE 7,1		;SAVE LOGICAL 40
	MCENTR			;GETS HERE FROM UUO HANDLER
	MOVE 1,7		;GET UUO
	TLZ 1,(777B17)		;DON'T LOOK AT AC, I, X
	CAME 1,[047000,,41]	;WAS IT A CALLI 41 ?
	JRST GETPA1		;NO, CONTINUE
	LDB 2,[POINT 4,7,12]	;YES, CHECK ARGUMENT
	UMOVE 1,0(2)		;GET CONTENTS OF DESIGNATED AC
	CAME 1,[112,,11]	;IS IT MAGIC NUMBER?
	JRST GETPA1		;NO, CONTINUE
	MOVEI 1,4B23		;YES, RETURN ANOTHER MAGIC NUMBER
	UMOVEM 1,0(2)		;RETURN IT IN DESIGNATED AC
	SMRETN

GETPA1:	SKIPGE PATADR		;FORCED INCOMPATABLILITY?
	ITERR(ILINS4)		;YES - GIVE ERROR.
	PUSH P,ENTVEC		;SAVE CURRENT ENTRY VECTOR
	MOVX 1,GJ%OLD!GJ%SHT
	HRROI 2,[ASCIZ /SYS:PA1050.EXE/]
	GTJFN
	ITERR(ILINS3)		;NO FILE
	HRLI 1,400000		;LOAD IT INTO THIS FORK
	GET
	MOVE 1,ENTVEC		;COMPATIBILITY ENTRY VECTOR
	MOVEM 1,PATADR		;PUT IT IN RESERVED PLACE
	POP P,ENTVEC		;RESTORE REGULAR VECTOR
	UMOVE 2,3(1)		;VIRTUAL 40 FOR PAT
	HRRM 2,PATU40
	UMOVE 2,4(1)		;PC WORD FOR PAT
	HRRM 2,PATUPC
	AOJ 1,			;INITIAL ENTRY IS 1, REGULAR 0
	HRLI T2,(UMODF)
	EXCH T2,0(P)		;GET FLAGS
	MOVE T3,-1(P)		;FIND PC
	HRRZM T1,-1(P)		;SET PC
	MOVE T1,T3		;SET PC IN USER MEMORY
	HLL T1,T2
	XCTU PATUPC
	MOVE 1,7
	XCTU PATU40
	JRST MRETN		;GO TO COMPATIBILITY
;HERE ON FIRST RAF JSYS TO LOAD RMS.EXE INTO FORK ADDRESS SPACE

GETDMS::MOVE 7,1		;SAVE LOGICAL 40
	MCENTR			;ENTER MONITOR CONTEXT
	PUSH P,ENTVEC		;SAVE PREVIOUS ENTRY VECTOR
	MOVX T1,GJ%OLD!GJ%SHT	;GET A JFN FOR RMS.EXE
	HRROI T2,[ASCIZ/SYS:RMS.EXE/]
	GTJFN
	ITERR(ILINS5)		;NO FILE
	HRLI 1,400000		;LOAD IT INTO THIS FORK
	GET
	MOVE 1,ENTVEC		;GET DMS ENTRY VECTOR
	MOVEM 1,DMSADR		;PUT IT IN RESERVED PLACE
	POP P,ENTVEC		;RESTORE REGULAR VECTOR
	UMOVE 2,3(1)		;VIRTUAL 40 FOR DMS
	HRRM 2,DMSU40
	UMOVE 2,4(1)		;PC WORD FOR DMS
	HRRM 2,DMSUPC
	AOJ 1,			;INITIAL ENTRY IS 1, REGULAR 0
	HRLI T2,(UMODF)
	EXCH T2,0(P)		;SET NEW PAC, GET OLD ONE
	MOVE T3,-1(P)		;GET PC
	HRRZM T1,-1(P)		;SET PC
	MOVE T1,T3
	HLL T1,T2
	XCTU DMSUPC
	MOVE 1,7
	XCTU DMSU40
	JRST MRETN		;GO TO DMS
;THE CHKAC JSYS - CHECK THE ACCESSABILITY OF A FILE OR DIRECTORY

;ACCEPTS IN 1/	COUNT OF ARGUMENTS
;	    2/	LOCATION OF ARGUMENT BLOCK
;	CHKAC
;RETURNS +1:	ERROR - ERROR CODE IN AC 1
;	 +2:	AC 1 = 0	ACCESS NOT ALLOWED
;		AC 1 = -1	ACCESS IS ALLOWED

;ARGUMENT BLOCK:
;	.CKAAC	DESIRED ACCESS CODE
;	.CKALD	LOGGED IN USER NUMBER OF THE USER DOING THE ACCESSING
;	.CKACD	CONNECTED STRUCTURE,,DIRECTORY OR POINTER TO STRUCTURE/
;		DIRECTORY STRING
;	.CKAEC	ENABLED CAPABILITIES OF THE USER
;	.CKAUD	STRUCTURE,,DIRECTORY OR POINTER TO STRUCTURE/DIRECTORY STRING
;		FOR FILE BEING ACCESSED
;		IF CK%JFN IS SET IN AC1, THIS IS JFN FOR FILE
;	.CKAPR	PROTECTION OF FILE BEING ACCESSED

.CHKAC::MCENT			;ENTER JSYS
	UMOVE Q1,2		;GET LOCATION OF ARGUMENT BLOCK
	XCTU [HRRZ T1,1]	;GET LENGTH OF ARGUMENT BLOCK
	XCTU [HLL Q1,1]		;GET THE FLAGS
	TXNN Q1,CK%JFN		;SPECIFIING A JFN?
	CAIG T1,.CKAPR		;NO, NEED A PROTECTION
	CAILE T1,.CKAUD		;YES, DO NOT NEED THE PROTECTION WORD
	XCTU [SKIPA T1,.CKAEC(Q1)] ;LENGTH IS OK, GET CAPABILITIES
	RETERR (CKAX1)		;LENGTH IS TOO SHORT
	TRNE T1,SC%WHL!SC%OPR	;IS THIS USER A WHEEL?
	JRST CHKACT		;YES, ACCESS IS LEGAL ALWAYS
	XCTU [HRRZ P1,.CKAAC(Q1)] ;GET ACCESS CODE
	UMOVE T1,.CKAUD(Q1)	;GET THE JFN OR DIRECTORY DESIGNATOR
	TXNE Q1,CK%JFN		;IS USER GIVING A JFN?
	JRST CHKAC2		;YES
	CALL CNVSTD		;CONVERT TO A DIRECTORY NUMBER
	 RETERR ()		;ILLEGAL FORMAT OF STRING
CHKAC2:	MOVE P2,T1		;SAVE JFN OR DIR NUMBER IN P2
	UMOVE T1,.CKALD(Q1)	;GET THE LOGGED IN USER NUMBER
	LOAD T2,NMFLG,T1	;GET BITS 0-2
	CAIN T2,NUMVAL		;IS THIS A NUMBER?
	JRST CHKAC3		;YES, DONT NEED TO CONVERT THE STRING
	CALL CNVSTU		;CONVERT STRING TO USER NUMBER
	 RETERR ()		;FAILED
CHKAC3:	CALL CNVDIR		;CONVERT IT TO A DIR NUMBER
	MOVE P3,T1		;SAVE DIRECTORY # IN P3
	UMOVE T1,.CKACD(Q1)	;GET CONNECTED DIR # INTO P4
	CALL CNVSTD		;GET DIR NUMBER FROM STRING
	 RETERR ()		;FAILED TO GET A DIRECTORY NUMBER
	MOVE P4,T1		;SAVE DIR NUMBER FOR LATER
	TXNN Q1,CK%JFN		;GIVING A JFN?
	XCTU [HRLZ P5,.CKAPR(Q1)] ;NO, GET PROTECTION
	TXNE Q1,CK%JFN		;USER GIVING A JFN?
	JRST [	HRRZ T1,P2	;YES, GET IT
		CALL GETFPD	;GET PROT AND DIR #
		 RETERR (CKAX4)	;BAD JFN
		MOVE P2,T1	;SAVE DIR #
		HRLZ P5,T2	;SAVE PROTECTION
		JRST .+1]
	MOVE T1,P2		;MAP IN DIRECTORY OF FILE
	CALL SETDIR		;FIRST CHECK LEGALITY OF DIR #
	 RETERR (CKAX2)		;ILLEGAL DIR # 
	ULKDIR			;UNLOCK DIR, BUT STAY NOINT
	CAIL P1,.CKADR		;IS THIS A DIRECTORY ACCESS CHECK?
	JRST CHKDIR		;YES, GO SET UP DIR PROTECTION VALUE
	MOVEI T4,<DP%RD>B35	;MUST ALSO CHECK READ ACCESS TO DIR
CHKAC0:	MOVSI Q2,40		;SET UP MASK WORD
	MOVN T1,P1		;GET CODE
	LSH Q2,0(T1)		;FORM THE ACCESS CHECK MASK
	TDNE Q2,P5		;IS THIS MODE ALLOWED FOR WORLD?
	JRST [	MOVE T1,DIRORA	;YES, NOW SEE IF LEGAL TO REF DIR
		LOAD T1,DRPRT,(T1) ;GET DIRECTORY PROTECTION
		TDNE T4,T1	;LEGAL TO REFERENCE IT?
		JRST CHKACT	;YES, THIS IS LEGAL THEN
		JRST .+1]	;NO, GO SEE IF THIS IS OWNER OR GROUP
	HLLZ T1,P5		;MAKE OWNER SUPERSET OF GROUP
	LSH T1,6
	IORM T1,P5		;DONT ALLOW GROUP MORE PRIVS THAN OWNER
	LSH Q2,^D12		;NOW SEE IF LEGAL FOR OWNER
	LSH T4,^D12		;DO SAME FOR DIR PROTECTION MASK
	MOVE T3,DIRORA		;GET BASE ADR OF MAPPED DIR
	LOAD T3,DRPRT,(T3)	;GET DIR PROTECTION
	MOVE T2,T3
	LSH T2,6		;MAKE OWNER SUPERSET OF GROUP
	IORM T2,T3		;T3 = DIR PROTECTION
	TDNE T4,T3		;LEGAL ACCESS FOR OWNER IN DIRECTORY?
	TDNN Q2,P5		;YES, IS FILE ACCESS LEGAL?
	JRST CHKACF		;IF NOT LEGAL FOR OWNER, THEN FALSE
	CAME P3,P2		;IS THIS FILE IN SAME DIR AS USER?
	CAMN P4,P2		;EITHER LOGGED IN OR CONNECTED
	JRST CHKACT		;YES, RETURN TRUE
	LSH Q2,-6		;NO, NOW SEE IF THIS IS SAME GROUP
	LSH T4,-6		;SAME FOR GROUP
	TDNE T4,T3		;LEGAL ACCESS TO DIR BY GROUPS?
	TDNN Q2,P5		;YES, LEGAL FOR GROUP?
	JRST CHKACF		;NO, RETURN FALSE
	CALL CPYDGP		;COPY DIR GROUPS INTO JSB
	 JRST CHKACF		;NO GROUPS
	MOVE P6,T1		;SAVE THE JSB POINTER
	MOVE T1,P3		;GET USER GROUP MEMBERSHIP OF USER
	CALL SETDIR		;GET INFO ABOUT THIS USER
	 RETERR (CKAX2)		;ILLEGAL DIRECTORY NUMBER
	ULKDIR			;UNLOCK THE DIRECTORY LOCK FROM GETDDB
	MOVE Q1,P6		;GET AOBJN POINTER TO DIR GROUP LIST
CHKAC1:	HLRZ T1,0(Q1)		;GET FIRST MEMBER OF GROUP
	CALL CHKUGP		;CHECK IT AGAINST USER GROUPS
	 SKIPA			;NO MATCH
	JRST [	MOVE A,P6	;MATCH FOUND
		CALL RELGRP	;RELEASE THE SPACE IN THE JSB
		JRST CHKACT]	;RETURN TRUE
	HRRZ T1,0(Q1)		;GET NEXT MEMBER OF GROUP
	CALL CHKUGP		;CHECK FOR MATCH
	 SKIPA			;NO MATCH
	JRST [	MOVE A,P6	;MATCHED!
		CALL RELGRP	;RELEASE THE JSB SPACE
		JRST CHKACT]	;RETURN TRUE
	AOBJN Q1,CHKAC1		;LOOP UNTIL LIST IS FINISHED
	MOVE A,P6		;RELEASE THE SPACE IN JSB
	CALL RELGRP
CHKACF:	TDZA T1,T1		;RETURN FALSE
CHKACT:	SETO T1,		;TRUE
	UMOVEM T1,1		;STORE ANSWER
	SMRETN			;AND RETURN

CHKDIR:	CAIL P1,.CKADR		;IS THIS A LEGAL FUNCTION CODE
	CAILE P1,.CKACF
	RETERR (CKAX3)		;NO, ILLEGAL ACCESS CODE
	SUBI P1,.CKADR		;SET UP FOR MASK BUILDING
	MOVE T4,DIRORA		;GET BASE OF DIR AREA
	LOAD T4,DRPRT,(T4)	;GET DIR PROTECTION
	HRL P5,T4		;ONLY WANT 18 BITS
	MOVEI T4,77		;DONT CARE ABOUT DIR PROTECTION CHECK
	JRST CHKAC0		;GO FINISH JSYS


;ROUTINE TO COPY A LIST OF GROUPS TO THE JSB
;	CALL CPYDGP	OR	CALL CPYUGP
;RETURNS +1:	NO GROUPS
;	 +2:	AOBJN POINTER TO LIST IN JSB RETURNED IN T1

CPYDGP::SE1CAL			;ENTER SEC 1
	MOVE D,DIRORA		;GET BASE OF DIR AREA
	LOAD D,DRDGP,(D)	;GET DIR GROUP LIST
	JRST CPYUG0		;ENTER COMMON CODE

CPYUGP::SE1CAL			;ENTER SEC 1
	MOVE D,DIRORA		;GET BASE OF DIR AREA
	LOAD D,DRUGP,(D)	;GET USER GROUP LIST
CPYUG0:	JUMPE D,R		;IF 0, NO LIST
	STKVAR <CPYUGA>
	ADD D,DIRORA		;GET ABS ADR OF LIST
	LOAD C,BLKTYP,(D)	;GET TYPE OF THIS BLOCK
	CAIE C,.TYGDB		;MUST BE A DIRECTORY GROUP BLOCK
	RET			;DIR IS SCREWED UP
	LOAD B,BLKLEN,(D)	;GET LENGTH OF BLOCK
	SOS B			;SKIP OVER HEADER
	MOVEM D,CPYUGA		;SAVE ADR OF LIST
	CALL ASGJFR		;GET A BLOCK FROM JSB
	 RET			;NO ROOM
	MOVE D,CPYUGA		;GET BACK ADR OF LIST
	HRRZ B,0(A)		;GET LENGTH OF DIR LIST
	MOVNS B			;SET UP AN AOBJN POINTER TO JSB
	HRL A,B
	MOVE C,A		;LEAVE POINTER IN A
CPYUGL:	MOVE B,1(D)		;GET NEXT ELEMENT IN LIST
	MOVEM B,0(C)		;STORE IN JSB
	AOS D			;STEP TO NEXT ELEMENT IN LIST
	AOBJN C,CPYUGL		;LOOP TIL LIST IS COPIED
	RETSKP			;RETURN SUCCESSFUL WITH POINTER IN A


;ROUTINE TO RELEASE A GROUP LIST FROM JSB
;ACCEPTS IN A/	POINTER TO LIST
;	CALL RELGRP
;RETURNS +1:	ALWAYS

RELGRP::HLRE B,A		;GET LENGTH OF BLOCK
	HRRZS	A		;INSURE IN THIS SECTION
	MOVNM B,(A)		;STORE LENGTH IN BLOCK
	HRRZ B,A		;GET ADR OF BLOCK
	MOVEI A,JSBFRE
	CALLRET RELFRE		;RELEASE THE BLOCK
;LOGOUT

.LGOUT::MCENT
	CAME 1,[-1]		;SELF?
	JRST ELOGO		;NO
	MOVSI 1,(SC%LOG)
	TDNN 1,CAPMSK		;LOG PERMITTED?
	RETERR (LOUTX4)		;NO, ERROR RETURN
	SETONE JSELO		;FLAG THAT JOB EXECUTED ITS OWN LGOUT
LOGO:	SKIPN FORKN		;TOP FORK?
	JRST FLOGO1		;YES
	NOINT
	HLRZ 1,FORKN		;NO, GET ITS NUMBER
	HRRZ 2,SYSFK(1)
	NOSKED
	MOVSI 1,400000+PSILOB
	IORM 1,FKINT(2)		;REQUEST LOGOUT
	CALL PSIR4
	OKSKED
	OKINT
	JRST HALTF1		;HALT THIS ONE
;THE FOLLOWING CODE DOES THE ACTUAL LOGOUT.  IT RUNS ONLY IN
;THE TOP FORK OF THE JOB BEING LOGGED OUT

FLOGO1:	MOVX 1,LOGIOB		;SAY JOB DESTRUCTION IN PROGRESS
	IORM 1,JOBBIT
	MOVEI 1,400000
	SETO 2,
	DIC			;DEACTIVATE INTERRUPTS AND KEYS
	CALL DTIALL
	CALL NETLGO		;RELEASE ANY JOB-WIDE NETWORK RESOURCES
	MOVEI T1,-4
	KFORK			;DELETE FORKS
	MOVE T1,JOBNO		;MARK THAT I AM NO LONGER OWNED
	SETOM JOBONT(T1)		; ..
	MOVSI T3,-NJOBS		;LOG OUT ANY JOBS WHICH I OWN
SJLGO1:	HRRZ T2,JOBONT(3)	;DO I OWN THIS ONE?
	CAME T2,JOBNO		; ..
	JRST SJLGO2		;NO.
	MOVEI T1,0(T3)		;YES. LOG IT OUT.
	LGOUT
	 JFCL			;SHOULD HAVE WORKED.
	SETOM JOBONT(T3)		;MAKE IT UNOWNED, SO IT FINISHES
SJLGO2:	AOBJN T3,SJLGO1		;SEE IF I OWN ANY MORE JOBS
;FALL THRU
;FALLS THRU FROM ABOVE
SJLGO4:	SETO T1,			;CLEAR USER MAP OF TOP FORK
	MOVSI 2,400000
	MOVE 3,[1B0+1000]	;REQUEST 1000 PAGES
	PMAP
	MOVE FX,FORKX
	LOAD 1,FKJSB		;GET JSB
	CALL WTSPT		;WAIT FOR SHR CNT OF 1
	SKIPL CTRLTT
	RESET			;RESET TTY MODES, ETC.
	CALL UNPAGE		;CLEAR PAGE MODE
	MOVE 1,[CZ%ARJ+CZ%ABT+400000] ;WAIT+FLUSH NONX + THIS FORK
	CLZFF
	MOVE 1,FORKX		;NOW KILL PIDS OF THIS FORK
	CALL PIDKFK		; INCLUDING JOB WIDE PIDS
	CALL CLKREL		;RELEASE TIMER BLOCKS
	MOVE 4,JOBNO
	HRRZ 1,JOBDIR(4)	;GET LOGIN DIR
	JUMPE 1,LOG1		;DON'T EXPUNGE IF NOT LOGGED IN
	HRLI T1,USRLH		;GET USER NUMBER
	CALL CNVDIR		;CONVERT IT TO A DIRECTORY NUMBER
	MOVE T2,T1		;SET UP FOR DELDF
	MOVX T1,DD%DTF		;DELETE TEMPORARY FILES
	PUSH P,T2		;SAVE DIR NUMBER
	DELDF			;EXPUNGE LOGIN DIR
	 ERJMP .+1		;DONT STOP ON ERRORS
	CALL GTCSCD		;GET CONNECTED STRUCTURE,,DIRECTORY
	POP P,T3		;GET BACK DIR # FROM LAST DELDF
	CAMN T2,T3		;ARE THEY THE SAME?
	JRST LOG0		;YES, DO NO EXPUNGE AGAIN
	MOVE T2,T1		;GET DIR NUMBER INTO 2
	MOVX T1,DD%DTF		;DELETE TEMPORARY FILES
	DELDF			;EXPUNGE CONNECTED DIR
	 ERJMP .+1		;DONT STOP ON ERRORS
LOG0:	CALL LOGSTR		;GO DECREMENT MOUNT COUNT FOR ALL STR'S
				; THIS JOB HAS MOUNTED
	MOVNI 1,1		;NOW RELEASE ALL ASSIGNED DEVICES
	RELD
	 JFCL
	MOVE 1,LOGDES
	DOBE			;WAIT FOR LOG TTY INACTIVE
	CALL LOGTOT		;SUMMARY TO LOG TTY
LOG1:	HRRE 1,CTRLTT
	JUMPL 1,LOG2		;CONTROL TTY?
	MOVEI 1,400000(1)	;YES, PRINT LOGOUT MESSAGE
	RFMOD			;TURN OFF PAGE MODE
	TXZ 2,TT%PGM		;TO ALLOW THE MESSAGE TO COME OUT
	STPAR
	CALL LOGTOT
	HRLOI 1,(1B0+1B1+1B4+1B5)
	MOVEI 2,-1
	TLINK			;BREAK LINKS, SET ACCEPT
	 JFCL
	HRRE 1,CTRLTT		;GET TTY #
	JUMPL LOG2		;NONE
	MOVEI 1,400000(1)	;GET DESIGNATOR
	DOBE			;WAIT FOR THE MESSAGE TO COMPLETE
	MOVE 1,JOBNO
	HRRZ 1,JOBDIR(1)
	JUMPN 1,LOG2		;HANG UP LINE IF JOB WAS NOT LOGGED IN
	MOVE 2,CTRLTT
	CALL TTHNGU		;HANG UP LINE
LOG2:	SKIPE SPIDTB+.SPQSR	;IS QUASAR RUNNING?
	CALL LOGOMS		;YES, SEND IT A MESSAGE
	 JFCL
	SKIPE T1,JSLOPD		;IS THERE A PID IN JSB FOR LGOUT MSG?
	CALL LOGOMO		;YES. SEND THE LOGOUT MESSAGE TO CREATOR
	 JFCL
	JRST HLTJB
;LOGSTR - ROUTINE TO DECREMENT MOUNT COUNT FOR ALL STRUCTURES THIS
;	  JOB HAS MOUNTED.
;
;CALL:		CALL LOGSTR
;RETURNS: +1 ALWAYS

LOGSTR:	SAVEP
	LOCK JSSTLK		;LOCK THE JSB STRUCTURE INFO DATA
	MOVSI P1,-STRN		;SET UP TO LOOP OVER STR INFO BLOCKS IN JSB
	MOVEI P2,JSSTRT		;GET ADDRESS OF FIRST BLOCK TO LOOK AT

LGST10:	JE <JSMCI,JSXCL>,(P2),LGST20 ;IF THIS JOB DIDN'T MOUNT THIS STR, CHECK NEXT
	LOAD T1,JSSTN,(P2)	;GET UNIQUE CODE FOR THIS STRUCTURE
	CALL CNVSTR		;GET STRUCTURE # AND LOCK THE STRUCTURE
	 JRST LGST20		;FAILED, MUST ALREADY BE DISMOUNTED, GO ON
	MOVEM T1,P3		;SAVE STRUCTURE NUMBER
	JN JSXCL,(P2),[	MOVX T1,D1%INI ;IF MOUNTED EXCLUSIVELY BY THIS JOB,
			ANDCAM T1,DEVCH1+DVXST0(P3) ; MAKE STR GENERALLY AVAILABLE
			JRST .+1]
	JE JSMCI,(P2),LGST15	;IF MOUNT COUNT NOT INCREMENTED, GO UNLOCK STR
	MOVE T1,P3		;GET STRUCTURE NUMBER AGAIN
	MOVE T2,P2		;GET ADDRESS OF STR INFO BLOCK IN JSB
	CALL DECMNT		;GO DECREMENT THE MOUNT COUNT FOR THIS STR
	 JFCL			;IGNORE FAILURE, GO ON
LGST15:	MOVE T1,P3		;RESTORE STRUCTURE NUMBER
	CALL ULKSTR		;UNLOCK THE STRUCTURE NOW
LGST20:	ADDI P2,JSSTMX		;GET ADDRESS OF NEXT STR INFO BLOCK IN JSB
	AOBJN P1,LGST10		;GO CHECK NEXT STR INFO BLOCK

	UNLOCK JSSTLK		;DONE, UNLOCK THE JSB STR INFO LOCK
	RET			;RETURN
;THE FOLLOWING IMPLEMENTS LOGOUT OF A JOB OTHER THAN SELF.
;LEGAL IF USER IS SC%WHL OR SC%OPR, OR IF OTHER JOB IS SAME USER

ELOGO:	NOINT
	MOVE T2,JOBNO		;GIVEN JOB NUMBER TO LOGOUT
	CAIN T2,0(T1)		;SELF?
	RETERR(LOUTX1)		;YES, CAN'T SAY IT THAT WAY
	JUMPE T1,[RETERR (LOUTX5)] ;CANNOT LOGOUT JOB 0
	CAIGE T1,NJOBS		;REASONABLE NUMBER?
	CAIG T1,0
LOGOE2:	RETERR(LOUTX2)		;NO
	SKIPGE JOBRT(T1)	;EXISTS?
	JRST LOGOE2
	HRRZ T3,JOBDIR(T1)	;LOGIN DIRECTORY OF OBJECT JOB
	XOR T3,JOBDIR(T2)
	TRNN T3,-1		;SAME AS THIS JOB?
	JRST ELOGO1		;YES, THAT'S OK
	HLRE T2,JOBPT(T1)	;GET TTY OF THE JOB BEING LOGGED OUT
	JUMPL T2,ELOGO3		;JUMP IF DETACHED
	PUSH P,T1		;SAVE JOB # BEING LOGGED OUT
	MOVE T1,T2		;PUT CONTROLLING TTY OF OBJECT JOB IN T1
	CALL PTGETJ		;GET CONTROLLING JOB # IF TTY IS A PTY
	MOVE T2,T1		;SAVE CONTROLLING JOB #
	POP P,T1		;RESTORE JOB # BEING LOGGED OUT
	JUMPL T2,ELOGO3		;JUMP IF NOT A PTY JOB
	CAMN T2,JOBNO		;JOB BEING CONTROLLED BY JOB DOING THE LGOUT
	JRST ELOGO1		;YES, SO DO IT
ELOGO3:	HRRZ T3,JOBONT(T1)	;DO I OWN THAT JOB IN CRJOB SENSE?
	CAMN T3,JOBNO		; ..
	JRST ELOGO1		;YES. OK TO LOG IT OUT.
	MOVEI T3,SC%WHL+SC%OPR	;OTHERWISE MUST BE SC%WHL
	TDNN T3,CAPENB
	RETERR (LOUTX3)		;ILLEGAL
ELOGO1:	SETOM JOBONT(T1)	;MAKE IT UNOWNED SO IT CAN LOG OUT
	PUSH P,T1		;SAVE THE JOB NUMBER
	CALL SETJSB		;MAP ITS JSB
	SETONE JSOLO,(T1)	;FLAG IN IT THAT SOMEONE LGOUT'ED IT
	MOVE T2,JOBNO		;AND WHO IT WAS
	MOVEM T2,JSLOJB(T1)	; ..
	CALL CLRJSB		;LET GO OF THE JSB
	POP P,T1		;RESTORE OTHER JOB NUMBER
	CALL ELOGOO		;LOG OUT THE TARGET JOB
	SMRETN			;AND DONE

;ROUTINE CALLED TO LOGOUT ANOTHER JOB.
;ACCEPTS:	A/ JOB NUMBER
;RETURNS:	+1 WITH LOGOUT REQUESTED

	RESCD			;MUST BE RESIDENT AS CALLED BY SCHEDULER
ELOGOO::HRRZ 2,JOBPT(1)		;TOP FORK OF OBJECT JOB
	NOSKD1			;PREVENT SCHEDULING
	MOVSI 1,400000+PSILOB
	IORM 1,FKINT(2)		;REQUEST LOGOUT
	CALL PSIR4
	OKSKD1			;ALLOWING SCHEDULING AGAIN
	RET			;AND DONE

;THE FOLLOWING IS RUN IN THE TOP FORK OF A JOB TO RESPOND TO
;A LOGOUT REQUEST FROM ANOTHER JOB

	SWAPCD			;IS SWAPPABLE
FLOGO::	MOVSI 1,(UMODF)		;FAKE USER PC
	MOVEM 1,FFL
	SETZM FPC
	MCENTR			;SIMULATE ENTRY FROM USER
	JRST FLOGO1		;NOW GO DO ORDINARY LOGOUT
;LOGGING FUNCTIONS

;TYPE LOGOUT MESSAGE, DESTINATION DESIGNATOR IN 1

LOGTOT::HRROI 2,[ASCIZ /Killed/]
	CALL LOGMES
	MOVE T2,CTRLTT		;T2/ LINE NUMBER
	CALL LOGJOB		;PRINTS JOB NO, TTY NO, TIME
	HRROI 2,[ASCIZ /,  Used /]
	CALL LOGMES
	PUSH P,1
	MOVNI 1,5		;FOR WHOLE JOB
	RUNTM
	MOVEM T1,JBRUNT		;SAVE RUNTIME
	MOVEM T3,CONCON		; AND CONSOLE CONNECT TIME
	MOVE 2,1
	POP P,1
	PUSH P,3
	CALL LOGTIM		;PRINT CPU TIME
	HRROI 2,[ASCIZ / in /]
	CALL LOGMES
	POP P,2
	CALL LOGTIM		;PRINT CONSOLE TIME
	CAME 1,LOGDES		;ON LOG TTY?
	CALLRET LOGCR		;NO - SKIP DOING THIS TWICE
	PUSH P,1
	MOVEI T1,.USLGO		;LOGOUT FUNCTION
	MOVEI T2,LOGLST
	USAGE			;USAGE JSYS
	 ERCAL XUSAGE		;REPORT FAILURE
	POP P,1			;RESTORE DESIGNATOR
	CALLRET LOGCR		;PRINT CRLF
;LOGON MESSAGE, CALLED FROM .LOGIN

LOGONM::SKIPL 1,LOGDES
	DOBE			;WAIT FOR OTHER USE OF TTY TO FINISH
	HRROI 2,[ASCIZ /Login/]
	CALL LOGMES
	MOVE T2,CTRLTT		;T2/ LINE NUMBER
	CALL LOGJOB
	PUSH P,1
	MOVEI T1,.USLGI		;LOGIN FUNCTION
	MOVEI T2,LOGLST		;POINT TO PARAMETERS
	USAGE
	 ERCAL XUSAGE		;REPORT USAGE FAILURE
	POP P,1
	CALLRET LOGCR		;AND CRLF

XUSAGE:	BUG (CHK,UXXFAI,<USAGE JSYS FAILURE>)
	RET			;CONTINUE

;PARAMETER BLOCK FOR LOGIN/LOGOUT/SESSION CHANGE CALLS

LOGLST:	USENT. (.UTSEN,1,1)	;SESSION ENTRY TYPE
	USRTM. (JBRUNT)		;RUN-TIME
	USACT. (<-1,,ACCTSR>)	;ACCOUNT
	USSST. (CTIMON)		;SESSION START DATE/TIME
	USJTY. (-1)		;BATCH T/S FLAG
	USBJN. (JBBNAM)		;BATCH JOB NAME
	USBSN. (JBBSEQ)		;BATCH SEQ NUMBER
	USCOM. (<-1,,JSSRM+1>)	;SESSION REMARK
	USCCT. (CONCON)		;CONSOLE CONNECT TIME
	USPNM. (<SIXBIT "MONITR">,US%IMM)
	USPVR. ([EXP SVNM])	;MONITOR NAME AND VERSION
	USNM2. (<-1,,USRNAM+1>)	;USER NAME
	0			;END OF LIST
;CHANGED ACCOUNT NUMBER MESSAGE

LOGCJM::SKIPL 1,LOGDES
	DOBE
	HRROI 2,[ASCIZ /Changed/]
	CALL LOGMES
	MOVE T2,CTRLTT		;T2/ LINE NUMBER
	CALL LOGJOB
	HRROI 2,[ASCIZ /,  Used /]
	CALL LOGMES
	PUSH P,1
	MOVNI 1,5
	RUNTM			;RUNTIME OF JOB
	MOVEM T1,JBRUNT		;SAVE RUNTIME
	MOVEM T3,CONCON		;CONSOLE CONNECT TIME
	MOVE 2,1
	POP P,1
	CALL LOGTIM		;PRINT ON LOG TTY
	PUSH P,1		;SAVE OUTPUT DESIGNATOR
	MOVEI T1,.USSEN		;SESSION ENTRY CODE
	MOVEI T2,LOGLST		;PARAMS
	USAGE
	 ERCAL XUSAGE
	POP P,1			;RESTORE
	CALLRET LOGCR		;RETURN AND PRINT CRLF

;PRINT TIME FROM 2

LOGTIM:	JUMPL 1,R
	IDIVI 2,^D1000		;MS TO SECS
	IDIVI 2,^D60		;PEEL OFF SECONDS
	PUSH P,3
	IDIVI 2,^D60		;PEEL OFF MINUTES
	PUSH P,3
	CALL LOGNUM		;PRINT HOURS
	MOVEI 2,":"
	BOUT
	POP P,2
	CALL LOGNUM		;PRINT MINUTES
	MOVEI 2,":"
	BOUT
	POP P,2
	CALL LOGNUM		;PRINT SECONDS
	RET
;ATACH AND DETACH MESSAGES

;DETMSG - RECORD DETACHING OF JOB

;ACCEPTS:
;	T2/ LINE NUMBER

DETMSG:	STKVAR <DETMLN>
	MOVEM T2,DETMLN		;SAVE LINE NUMBER
	HRROI 2,[ASCIZ /Detached/] ;WORD FOR LOG TTY
	SKIPL 1,LOGDES
	DOBE
	CALL LOGMES
	MOVE T2,DETMLN		;T2/ LINE NUMBER
	CALL LOGJOB
				;*** DETACH ***
	CALLRET LOGCR		;CRLF AND RETURN

DETMS0:	ASUBR <ATAJN,ATALN>	;JOB # , LINE #
	HRROI 2,[ASCIZ /Detached job /]
	SKIPL 1,LOGDES
	DOBE
	CALL LOGMES
	MOVE 2,ATAJN		;GET REMOTE JOB NUMBER
	CALL LOGNUM
	HRROI 2,[ASCIZ / from TTY /]
	JRST ATAMS3

ATAMSG:	ASUBR <ATAJN,ATALN>	;JOB # , LINE #
	SKIPL 1,LOGDES
	DOBE
	HRROI 2,[ASCIZ /Attached job /]
	CALL LOGMES
	MOVE T2,ATAJN		;GET JOB NUMBER
	CALL LOGNUM		;PRINT IT
	HRROI 2,[ASCIZ / to TTY /]
ATAMS3:	CALL LOGMES
	MOVE T2,ATALN		;LINE NUMBER
	MOVEI 3,^D8		;PRINT IN OCTAL
	CALL LGNOUT
	CALL LOGJ2		;PRINT AND STORE TOD
				;*** ATTACH ***
	CALLRET LOGCR		; END WITH CRLF
;PRINTS  JOB 1, TTY 40, AT 12:34:56
;  OR    JOB 1, DETACHED, AT 12:34:56

;ACCEPTS:
;	T2/ LINE NUMBER

LOGJOB:	STKVAR <LOGJLN>
	MOVEM T2,LOGJLN		;T2/ LINE NUMBER
	HRROI 2,[ASCIZ / Job /]
	CALL LOGMES
	MOVE 2,JOBNO
	CALL LOGNUM
	MOVE 2,JOBNO
	HRRZ 2,JOBDIR(2)
	JUMPE 2,LOGJ3		;LOGGED IN NOW?
	HRROI 2,[ASCIZ /, User /]
	CALL LOGMES
	MOVE 2,JOBNO
	HRRZ 2,JOBDIR(2)
	HRLI 2,USRLH		;TURN IT INTO A 36 BIT USER NUMBER
	MOVE 3,1		;SAVE OUTPUT DESIGNATOR
	CAIL 1,0
	DIRST			;DIRECTORY NAME
	 MOVE 1,3		;IF ERROR, RESTORE OUTPUT DESIGNATOR
	HRROI 2,[ASCIZ /, Account /]
	CALL LOGMES
	CALL LOGACC
LOGJ3:	MOVE 2,LOGJLN
	JUMPL 2,LOGJ1		;IF NO CTRL TTY (DETACHED JOB)
	HRROI 2,[ASCIZ /, TTY /]
	CALL LOGMES
	MOVE 2,LOGJLN
	MOVEI 3,^D8		;PRINT TTY NUMBER IN OCTAL
	CALL LGNOUT
LOGJ2:	HRROI 2,[ASCIZ /,
  at /]
	CALL LOGMES
	PUSH P,1		;SAVE DESIGNATOR
	CALL LGTAD		;DO LOCAL GTAD
	MOVE 2,1
	POP P,1			;RESTORE DESTINATION
	JUMPL 1,R
	SETZ 3,			;STANDARD DATE AND TIME
	CAIL 2,0
	ODTIM
	RET

LOGJ1:	HRROI 2,[ASCIZ /, Detached/]
	CALL LOGMES
	JRST LOGJ2
LOGACC:	HRROI T2,ACCTSR		;POINT TO STRING
	MOVEI T3,0		;TERMINATE ON NULL
	CAIL T1,0		;VALID PNTR
	SOUT			;YES - OUTPUT STRING
	RET			;RETURN

LOGMES:	SETZ 3,
	SOUT
	RET

LOGNUM:	MOVEI 3,^D10		;DECIMAL FOR TIMES, ETC.
LGNOUT:	NOUT
	 JFCL
	RET

LOGCR:	HRROI 2,[ASCIZ /
/]
	SETZ 3,
	SOUT
	RET

;PRINTS   [JOB N DETACHED BY NAME] TO TTY OF JOB BEING ATTACHED
; OR UNATTACHED.
;ACCEPTS:	1/JOB # OF JOB BEING UNATTACHED
;		2/LINE # OF JOB BEING UNATTACHED
;		3/DIR # OF USER UNATTACHING THE JOB
;		4/TTY # OF USER UNATTACHING THE JOB

DETMS1:	TRVAR <<MSGBUF,25>,JOB,LINE,DIRN,DTTYN,TMPPTR>
	MOVEM 1,JOB		;SAVE INPUTS
	MOVEM 2,LINE
	MOVEM 3,DIRN
	MOVEM 4,DTTYN		;SAVE TTY # OF DETACHER
	HRROI 1,MSGBUF		;START FILLING BUFFER
	CALL LOGCR		;CRLF
	HRROI 2,[ASCIZ/[Job /]
	CALL LOGMES
	HRRZ 2,JOB		;JOB # TO BE PRINTED
	CALL LOGNUM
	HRROI 2,[ASCIZ/ detached by /]
	CALL LOGMES
	MOVE 2,DIRN
	MOVEM 1,TMPPTR		;SAVE PLACE IN BUFFER IN CASE DIRST FAILS
	DIRST			;GET USER WHO'S UNATTACHING THE JOB
	ERJMP DIRFIX
DETMS2:	SKIPGE DTTYN		;IS DETACHER ON A TTY?
	JRST DETMS3		;NO
	HRROI 2,[ASCIZ/ on terminal /]
	CALL LOGMES
	MOVE 2,DTTYN		;Get the TTY number
	MOVEI 3,10		;OCTAL NUMBER
	CALL LGNOUT
DETMS3:	HRROI 2,[ASCIZ/]/]
	CALL LOGMES
	CALL LOGCR		;CLOSE WITH CRLF
	MOVEI 1,.FHSLF
	ADD 1,LINE		;TTY LINE NUMBER
	HRROI 2,MSGBUF		;POINT TO NOW-COMPLETED MESSAGE
	TTMSG			;SEND IT OUT
	RET

;UNATTACHER NOT LOGGED IN

DIRFIX:	MOVE 1,TMPPTR		;RESTORE BUFFER POINTER
	HRROI 2,[ASCIZ/user/]
	CALL LOGMES		;PLACE PSEUDO-NAME IN BUFFER
	JRST DETMS2		;FINISH ASSEMBLING THE MESSAGE
;INFO JSYS'S

.GJINF::MCENT
	CALL GTCSCD		;GET CONNECTED STRUCTURE CODE,,DIRECTORY
	MOVE 2,1		;RETURN CONNECTED STR/DIR NUMBER
	MOVE 3,JOBNO
	HRRZ 1,JOBDIR(3)
	SKIPE 1			;IF NOT LOGGED IN, RETURN 0
	HRLI 1,USRLH		;TURN THIS INTO A 36 BIT USER NUMBER
	MOVE 4,CTRLTT
MR4:	UMOVEM 4,4
MR3:	UMOVEM 3,3
MR2:	UMOVEM 2,2
MR1:	UMOVEM 1,1
	JRST MRETN

.TIME::	MCENT
	MOVE 1,TODCLK		;TIME SINCE SYSTEM STARTED
	MOVEI 2,^D1000		;DIVISOR FOR SECONDS
	JRST MR2		;RETURN 2 AC'S

.RUNTM::MCENT
	NOSKED
	CALL UCLOCK		;UPDATE CLOCKS
	OKSKED
	CALL FLOCK		;LOCK THE FORK STRUCTURE
	XCTU [HRRZ 1,1]	;FORK HANDLE
	CAIN 1,-5		;WHOLE JOB?
	JRST RUNTM1		;YES
	CALL SETJFK
	CALL SETLF1
	MOVE 1,FKRT(1)		;FORK RUN TIME FROM PSB
	JRST RUNTM2

RUNTM1:	NOINT
	MOVE 1,JOBNO
	MOVE 1,JOBRT(1)
RUNTM2:	MOVE 3,TODCLK		;CURRENT TIME
	SUB 3,CONSTO		;LESS TIME ON, FOR CONSOLE TIME USED
	MOVEI 2,^D1000		;MILLISECONDS
RETA3:	UMOVEM 1,1		;RETURN VALUES IN 1,2,3
	UMOVEM 2,2
	UMOVEM 3,3
	JRST CLFRET

.GTRPI::MCENT
	CALL FLOCK		;LOCK THE FORK STRUCTURE
	CALL SETLFK
	MOVE 2,USWPCT(1)
	MOVE 3,PTTIM(1)
	MOVE 1,UTRPCT(1)
	JRST RETA3
;GET DIRECTORY ALLOCATION
;ACCEPTS IN 1/	DIR # OR -1 FOR CONNECTED DIR
;	GTDAL
;RETURNS +1:	1/	LOGGED IN QUOTA
;		2/	CURRENT ALLOCATION
;		3/	LOGGED OUT QUOTA

.GTDAL::MCENT
	UMOVE T1,1		;GET DIR #
	CAMN T1,[-1]		;-1 MEANS CONNECTED DIRECTORY
	CALL GTCSCD		;GET CONNECTED DIR NUMBER
	CALL IGTDAL		;USE INTERNAL ROUTINE
	 ITERR()		;FAILED
	JRST MR3		;RETURN 1, 2 AND 3

;INTERNAL GTDAL, 1/ DIRECTORY #

IGTDAL::STKVAR <IGTDN>
	MOVEM T1,IGTDN		;SAVE DIR #
	CALL SETDIR		;MAP THE DIRECTORY IN
	 RETBAD ()		;FAILED
	HRRZ T1,IGTDN		;DIRECTORY NUMBER
	LOAD T2,CURSTR		;STRUCTURE NUMBER
	CALL GETCAL		;GET CURRENT ALLOCATION
	 JRST [	MOVE T3,DIRORA	;DIR NOT OPENED
		LOAD T1,DRLIQ,(T3) ;LOGGED IN QUOTA
		LOAD T2,DRDCA,(T3) ;CURRENT ALLOCATION
		LOAD T3,DRLOQ,(T3) ;LOGGED OUT QUOTA
		JRST IGTDX]	;EXIT
	MOVE T3,DIRORA		;GET BASE ADR OF MAPPED DIR
	MOVN T2,T1		;NEGATE PAGES LEFT
	LOAD T1,DRLIQ,(T3)	;GET LOGGED IN QUOTA
	ADD T2,T1		;ACTUAL USED
	LOAD T3,DRLOQ,(T3)	;GET LOGGED OUT QUOTA
IGTDX:	CALL USTDIR		;UNLOCK THE DIR
	RETSKP			;GOOD RETURN

;HIGH PRECISION TIME JSYS
;MADE RESIDENT FOR SPEED

	RESCD

.HPTIM::MCENT
	CAIL 1,0		;CHECK RANGE OF ARG
	CAIL 1,NHPTIM
	RETERR(HPTX1)		;UNDEFINED CLOCK
	JRST HPTTAB(1)

HPTTAB:	JRST HPT0		;ELAPSED TIME
	JRST HPT1		;FORK RUNTIME
NHPTIM==.-HPTTAB

HPT0:	NOSKED
	JSP 4,MTIME		;READ TODCLK IN 1E-5 SECOND UNITS
	OKSKED
	UMOVEM 1,1
	SMRETN

HPT1:	NOSKED
	CALL UCLOCK		;UPDATE USER RUNTIMES
	OKSKED
	MOVE 1,FKRT		;GET MILLISECOND PART
	IMULI 1,NTMS		;CONVERT TO HP UNITS
	ADD 1,RUNT2		;INCLUDE FRACTION OF MILLISECOND
	UMOVEM 1,1
	SMRETN

	SWAPCD

;GET NUMBER OF TABLE AND FIRST WORD GIVEN SIXBIT SYMBOL
; 1/ SIXBIT 'TABLENAME'
;	SYSGT
; RETURN +1 ALWAYS, 
;  1/ -LENGTH,,TABLENUMBER  OR 0

.SYSGT::MCENT
	MOVSI 4,-GTBSIZ
	CAMN 1,SYMTAB(4)
	JRST SYSGT1
	AOBJN 4,.-2
	XCTU [SETZM 2]		;NOT FOUND RETURN 0
	JRST MRETN

SYSGT1:	HLRZ 2,GTTAB(4)		;SIZE
	MOVN 2,2		;NEGATE IT
	HRLI 4,0(2)		;COMBINE WITH TABLE NUMBER
	UMOVEM 4,2		;GIVE TO USER
	HRRZ T3,T4		;GET TABLE NUMBER
	SETZ T2,		;GET OFFSET ZERO
	XCT GTGET(T3)		;GO GET THE FIRST ENTRY
	UMOVEM 1,1		;GIVE FIRST WORD TO USER
	JRST MRETN

;GET TABLE ENTRY
; 1/ INDEX,,TABLENUMBER
;	GETAB
; RETURN +1: ERROR
; RETURN +2: 1/ DATA

.GETAB::MCENT
	MOVSI 2,(1B1)
	TDNN 2,CAPMSK		;GETAB CAPABILITY EXISTS?
	RETERR(GTABX3)		;NO
	HLRZ 2,1		;INDEX OR -1
	MOVEI 3,0(1)		;TABLE NUMBER
	CAIL 3,GTBSIZ		;LEGAL NUMBER?
	RETERR(GTABX1)		;NO
	HLRZ 1,GTTAB(3)		;GET SIZE OF TABLE
	CAIN 2,-1		;INDEX OF -1?
	JRST RETN1		;YES, RETURN NEG OF TABLE SIZE
	CAIL 2,0(1)		;INDEX WITHIN BOUNDS?
	RETERR(GTABX2)
	XCT GTGET(T3)		;GET WORD
	UMOVEM 1,1		;RETURN IT TO USER
	SMRETN

RETN1:	XCTU [MOVNM 1,1]	;RETURN NEG OF LENGTH
	SMRETN
;TABLES FOR GTTAB
;ALL TABLES DEFINED WITH FOLLOWING MACRO WHICH TAKES NAME OF
;ANOTHER MACRO TO CALL FOR EACH TABLE.
;*NOTE* TABLE INDICES ARE DEFINED IN MONSYM - ORDER AND PLACE
;MUST BE PRESERVED IF TABLES ARE ADDED OR DELETED.  PLACE
;MAY BE HELD BY CALL WITH NO ARGS.

;THE ARGUMENT TO GTABS IS A MACRO TO BE CALLED FOR EACH TABLE.
;FIVE ARGUMENTS ARE GIVEN, SIXBIT TABLE NAME, LOCATION, LENGTH, ROUTINE,
;SYMBOLIC VALUE FOR TABLE NUMBER (FROM MONSYM)

DEFINE GTABS (XXX)<
	XXX JOBTTY,JOBPT,NJOBS
	XXX JOBRT,JOBRT,NJOBS
	XXX TICKPS,[^D1000],1
	XXX			;;FORMERLY JOBDIR
	XXX TTYJOB,0,NLINES,GTBTTF
	XXX NCPGS,TOTRC,1
	XXX DEVNAM,DEVNAM,NDEV
	XXX DEVCHR,DEVCHR,NDEV
	XXX DEVUNT,DEVUNT,NDEV
	XXX DSKERR,DSKRCE,NDSKEW
	XXX DRMERR,DRMCFE,NDRMEW
	XXX SYSVER,SVN,NSVNT
	XXX SYSTAT,SKDTM0,NSTAT
	XXX QTIMES,QSUM,MAXQ+1
	XXX JOBNAM,JOBNAM,NJOBS
	XXX SNAMES,SNAMES,NNAMES
	XXX STIMES,STIMES,NNAMES
	XXX SPFLTS,SPFLTS,NNAMES
	XXX SSIZE,SSIZE,NNAMES
	XXX SNBLKS,SNBLKS,NNAMES
	XXX DBUGSW,DBUGSW,2
	XXX LOGDES,LOGDES,2
	XXX PTYPAR,0,1,GTBPTY
	XXX SYMTAB,SYMTAB,GTBSIZ
	XXX DWNTIM,HSYST1,NHSYST
	XXX JOBPNM,JOBPNM,NJOBS
	XXX BLDTD,SYSTAD,1
	XXX			;;FORMERLY LSTDRN
	XXX APRID,APRSER,1
	XXX HQLAV,HQLAV,NRJAVS
	XXX LQLAV,LQLAV,NRJAVS
	XXX NETRDY,IMPRDY,IMPGTN	;ARPANET
	XXX IMPHRT,IMPHRT,IMPLBT	;ARPANET
	XXX HSTSTS,HSTSTS,<NHOSTS/2>	;ARPANET
	XXX HSTNAM,HSTNAM,NHSTN		;ARPANET
	XXX HOSTN,HOSTN,NHOSTS		;ARPANET
	XXX NETLSK,LSKT,NSKT		;ARPANET
	XXX NETFSK,FSKT,NSKT		;ARPANET
	XXX NETAWD,NETAWD,NSKT		;ARPANET
	XXX NETBAL,NETBAL,NSKT		;ARPANET
	XXX NETSTS,NETSTS,NSKT		;ARPANET
	XXX NETBUF,NETBUF,NSKT		;ARPANET
	XXX NETBTC,NETBTC,NSKT		;ARPANET
	XXX IMPLT1,IMPLT1,IMPNLK,,.IMPL1 ;ARPANET
	XXX IMPLT2,IMPLT2,IMPNLK,,.IMPL2 ;ARPANET
	XXX IMPLT3,IMPLT3,IMPNLK,,.IMPL3 ;ARPANET
	XXX IMPLT4,IMPLT4,IMPNLK,,.IMPL4 ;ARPANET
	XXX LHOSTN,NLHOST,2		;ARPA HOST NUMBER, NVT COUNTER
	XXX JBONT,JOBONT,NJOBS		;OWNING JOB
	XXX NSWPGS,NSWPGS,1		;DEFAULT SWAPPING PAGES
	XXX XBIO,XB2RED,2		;**TEMP** 3A ONLY, SECOND LEVEL XBIO
   >

;ASSEMBLE SYMBOL TABLE

DEFINE SYMT (NAM,LOC,SIZ,ROUT,VALUE)<
   IFB <NAM>,<0>		;;LEAVE 0 IF PLACE RESERVED
   IFNB <NAM>,<
      IFB <VALUE>,<		;;IF VALUE WAS NOT SPECIFIED
	..X==.'NAM		;;GET NAME FROM MONSYM
.'NAM::!SIXBIT /NAM/>		;;CHECK TABLE INDEX, ASSEMBLE SIXBIT
      IFNB <VALUE>,<		;;IF VALUE WAS SPECIFIED
	..X==VALUE		;;GET NAME FROM MONSYM
VALUE::!SIXBIT /NAM/>>>		;;CHECK TABLE INDEX, ASSEMBLE SIXBIT

SYMTAB::!PHASE 0			;;MAKE TAGS BE RELATIVE TO 0
	GTABS SYMT		;;ASSEMBLE SYMTAB, CHECK INDEX MNEMONICS
GTBSIZ::DEPHASE

;ASSEMBLE POINTERS AND SIZES

DEFINE LOCT (NAM,LOC,SIZ,ROUT,VALUE)<
   IFB <NAM>,<0>		;;LEAVE 0 IF PLACE RESERVED
   IFNB <NAM>,<
	XWD SIZ,LOC>>

GTTAB::	GTABS LOCT

;DEFINE PROCESSING ROUTINE

DEFINE ACTR (NAM,LOC,SIZ,ROUT,VALUE)<
   IFB <NAM>, <SETZM T1>	;;NULL TABLE GIVES NULL ANSWER
   IFNB <NAM>,< IFB <ROUT>, <CALL GTGETR> ;;DFAULT PROCESSOR
   IFNB <ROUT>, <CALL ROUT> 	;;DO SPECIFIED PROCESS
        >
   >

GTGET:	GTABS ACTR		;DEFINE PROCESSING TABLES

;GENERAL GETTAB ROUTINE.
;	3/ TABLE NUMBER
;	2/ TABLE OFFSET
;RETURNS: +1 WITH T1/ ANSWER

GTGETR:	ADD T2,GTTAB(T3)	;GET TABLE BASE
	HRRZS T2		;CLEAR INDEX
	MOVE T1,0(T2)		;FETCH TABLE ENTRY
	RET			;AND DONE
;SUBSYSTEM STATISTICS LOGIC
; 1/ SIXBIT NAME OF SYSTEM PROGRAM BEING RUN OR (PRIV)
; 2/ SIXBIT NAME OF PROGRAM
;	SETSN
; RETURN +1: ALWAYS, NAME SET IN STATISTICS TABLE

.SETSN::MCENT
	NOINT
	MOVE 3,JOBNO
	MOVEM 2,JOBPNM(3)	;SET JOB PROGRAM NAME
	AOSE SNMLCK		;LOCK TABLE
	CBLK1			;OR WAIT TILL LOCKABLE
	HRLZ 3,SNMPT		;NEG COUNT OF ENTRIES
	CAMN 1,SNAMES(3)	;DESIRED NAME?
	JRST SNM1		;YES
	AOBJN 3,.-2		;NO, LOOKED AT ALL?
	MOVEI 3,0(3)
	CAIL 3,NNAMES-1		;TABLE NOW FULL?
	SKIPA 1,[SIXBIT /.OTHER/] ;YES, USE CATCH-ALL NAME
	SOS SNMPT		;UPDATE POINTER
	MOVEM 1,SNAMES(3)	;ADD NAME TO TABLE
SNM1:	MOVE 2,JOBNO
	HRRM 3,JOBNAM(2)	;PUT INDEX IN JOB TABLE
	SETOM SNMLCK		;UNLOCK TABLE
	OKINT
	SMRETN

NR SNMPT,1			;NEG COUNT OF ENTRIES IN SNAMES
NR SNMLCK,1			;LOCK FOR SNAMES TABLE

;PROGRAM NAME LOGIC

;SET NAME
; 1/ SIXBIT NAME OF PROGRAM
;	SETNM
; RETURN +1: ALWAYS, NAME SET AS PROGRAM NAME FOR JOB

.SETNM::MCENT
	MOVE 3,JOBNO		;GET THIS JOB NUMBER
	MOVEM 1,JOBPNM(3)	;SET THE NAME
	JRST MRETN

;GET NAME
;	GETNM
; RETURN +1: ALWAYS, 1/ SIXBIT NAME OF PROGRAM

.GETNM::MCENT
	MOVE 1,JOBNO
	MOVE 1,JOBPNM(1)
	JRST MR1		;RETURN 1 AC
;GETNAM -- SUBROUTINE TO CONSTRUCT VERSION AND SYSTEM NAME FROM TEXT
; IN THE FILE SYSTEM:MONNAM.TXT, OR IF THE FILE DOES NOT EXIST,
; TO USE THE DEFAULT TEXT ASSEMBLED INTO THE MONITOR IN THE BLOCK
; LABLED TSVN.  THE FORMAT OF THE RESULTING  TEXT IS:

; V D.DD.DD <TEXT>

; WHERE THE FIRST SEVERAL CHARACTERS IDENTIFY THE MONITOR VERSION AND ALWAYS
; COME FROM THE PREASSEMBLED STRING; AND THE <TEXT> COMES EITHER FROM
; THE FILE OR FROM THE PREASSEMBLED STRING.  THE ENTIRE STRING MAY
; BE UP TO 132(10) CHARACTERS LONG, SO <TEXT> MAY BE 122(10),
; OR 172(8) CHARACTERS LONG.  <TEXT> IN THE FILE SHOULD BE TERMINATED BY 
; EOL.


GETNAM:	STKVAR <A1>		;RESERVE SPACE FOR ONE TEMP
	MOVE T1,[POINT 7,SVN]	;BYTE POINTER TO DESTINATION
	MOVEM T1,A1		;SAVE UPDATED PTR. TO DEST. STRING
	MOVX T1,GJ%SHT!GJ%OLD	;FLAG FOR SHORT GTJFN CALL AND OLD FILE ONLY
	HRROI T2,[ASCIZ /SYSTEM:MONNAM.TXT/] ;IMPLICIT STRING PTR TO FILE NAME	
	GTJFN			;IS THERE A FILE?
	 JRST GETNA1		;NO FILE - DOESN'T MATTER WHY
	MOVX T2,<OF%RD+FLD(7,OF%BSZ)> ;FILE EXISTS, SET UP OPENF CALL
	OPENF			; ..
	 JRST GETNA1		;UNSUCCESFUL FOR ANY REASON, USE 
				; DEFAULT STRING
	MOVEI T3,<NSVNT-VTSVNT>*5-1	;MAX. # OF BYTES WE CAN MOVE
	MOVE T4,A1		;RECALL BYTE PTR TO BUFFER
GETNA2:	BIN			;GET NEXT CHARACTER FROM FILE
	CAIE T2,.CHCRT		;IS IT A CARRIAGE RETURN?
	CAIN T2,.CHLFD		;NO, IS IT A LINE FEED?
	JRST GETNA3		;A CR OR A LF WAS ENCOUNTERED
	JUMPE T2,GETNA3		;JUMP ALSO IF IT'S A NULL
	IDPB T2,T4		;IT'S A GOOD CHARACTER, PUT INTO BUFFER
	SOJG T3,GETNA2		;JUMP IF WE HAVN'T EXHAUSTED ALL BUT
				; ONE BYTE POSITION IN BUFFER.
;MANUAL MERGE OF 1B CHANGES
GETNA3:	CLOSF			;YES, CLOSE FILE, RELEASE JFN
	 JFCL			;IGNORE FAILURE
	MOVE T1,T4		;GET STRING POINTER AGAIN
	HRROI T2,VTSVN		;IMPLICIT STRING POINTER TO VERSION
	SETZ T3,		;STOP ON A NULL
	SOUT			;MOVE PREASSEMBLED VERSION TO BUFFER
	RET			;EXIT

GETNA1:	HRROI T1,SVN		;IMPLICIT BYTE POINTER OF DESTINATION
	HRROI T2,TSVN		;IMPLICIT BYTE POINTER TO PREASSEMBLED
				; MONITOR NAME
GETNA5:	SETZ T3,		;SPECIFY TERMINATION ON A NULL
	SOUT			;MOVE PREASSEMBLED STRING TO BUFFER
				; THE MOVE INCLUDED A TERMINATING NULL 
	RET			; SO -- WE'RE DONE
		
;GET JOB INFORMATION
; 1/ JOB #, OR -1 FOR SELF, OR TTY # + 400000
; 2/ -N,,USER ADR
; 3/ FIRST ENTRY DESIRED
;	GETJI
; RETURN +1: FAILURE
; RETURN +2: SUCCESS, ENTRIES STORED IN USER ARRAY
;REQUIRES GETAB CAPABILITY IF JOB OTHER THAN SELF

.GETJI::MCENT
	UMOVE P2,3		;GET NUMBER OF FIRST ENTRY DESIRED
	HRL P2,P2		;DUPLICATE IN BOTH HAVLES
	JUMPL P2,[RETERR (GTJIX1)] ;DO NOT ALLOW NEGATIVE VALUES
	ADD P2,[-NGTJIT,,0]	;SETUP AOBJN PTR TO FIRST ENTRY
	JUMPGE P2,[RETERR (GTJIX1)] ;ALREADY BEYOND END OF TABLE
	UMOVE P3,2		;GET USER 'S ADR POINTER
	CAMN 1,[-1]		;SELF?
	JRST [	MOVE 1,JOBNO	;YES, GET THIS JOB NUMBER
		JRST GETJI5]	;SKIP CAPABILITY CHECK
	MOVX 2,SC%GTB
	TDNN 2,CAPMSK		;HAS GETAB CAPABILITY?
	RETERR (GTABX3)		;NO
	TRZE 1,400000		;TTY DESIGNATOR?
	JRST [	CAIL 1,0	;YES, LEGAL LINE NUMBER?
		CAIL 1,NLINES
		RETERR (GTJIX2)	;NO
		MOVE T2,T1	;T2/ LINE NUMBER
		CALL GTCJOB	;GET OWNING JOB NUMBER
	 	 JRST GETJI6	;JUMP IF NOT ACTIVE
		CAIN T3,-1	;IS THERE AN OWNING JOB?
		JRST GETJI6	;NO.
		MOVE T2,T3	;YES. PRESERVE JOB NUMBER
		HLRZ T3,JOBPT(T2) ;GET CONTROLLING TTY FOR JOB
		CAME 3,1	;SAME AS GIVEN TTY?
		JRST GETJI1	;NO, TTY IS ASSIGNED NOT CONTROLLING
		MOVE 1,2	;SETUP JOB NUMBER
		JRST .+1]	;CONTINUE WITH JOB NUMBER
	CAIL 1,0		;LEGAL JOB NUMBER?
	CAIL 1,NJOBS
	RETERR (GTJIX3)		;NO
GETJI5:	NOSKED			;DON'T ALLOW JOB TO LOG OUT
	SKIPGE JOBRT(T1)	;JOB EXISTS?
	RETERR (GTJIX4,<OKSKED>) ;NO. GIVE APPROPRIATE ERROR
	MOVEM 1,P1		;SAVE JOB NUMBER
	CALL SETJSB		;MAP IN JSB OF OBJECT JOB
	OKSKED			;OK TO ALLOW SCHEDULING. JOB CAN'T LOGOUT
				; SINCE ITS JSB IS MAPPED
	MOVEM T1,P4		;SAVE JSB OFFSET
GETJI2:	XCT GETJIT(P2)		;GET ITEM
	UMOVEM 1,0(P3)		;GIVE IT TO USER
	AOBJP P3,GETJI3		;COUNT USER'S COUNT AND ADR
	AOBJN P2,GETJI2		;COUNT OUR COUNT AND ADR
GETJI3:	CALL CLRJSB		;UNMAP JSB OF OBJECT JOB
GETJIX:	UMOVEM P3,2		;UPDATE USERS PTR
	SMRETN
;GETJI...
;HERE IF TTY GIVEN AND NO CONTROLLING JOB
;GETJI6 - NO JOB OWNS THIS TERMINAL; GETJI1 - A JOB OWNS THIS TERMINAL
;BUT IT IS NOT THE JOB'S CONTROLLING TERMINAL

GETJI6:	SETOM T2		;INDICATE NO OWNING JOB
	SKIPA
GETJI1:	TLO 2,(1B1)		;SAY ASSIGNED
GETJI4:	XCTU [SKIPE 3]		;DOES USER WANT FIRST ENTRY?
	JRST GETJIX		;NO, NOTHING TO DO
	UMOVEM 2,0(P3)		;YES, STORE IT
	AOBJN P3,.+1		;UPDATE HIS POINTER
	JRST GETJIX		;RETURN

;TABLE OF GETJI ITEMS - WORD IS EXECUTED TO GET ITEM IN AC1

GETJIT:	MOVE 1,P1		;JOB NUMBER
	HLRE 1,JOBPT(P1)	;TTY NUMBER OR -1 IF DETACHED
	CALL GETSN5		;GET LOGIN DIRECTORY NUMBER
	CALL GETSN4		;GET CONNECTED STRUCTURE,,DIRECTORY
	CALL GETSN1		;SUBSYSTEM NAME
	MOVE 1,JOBPNM(P1)	;PROGRAM NAME
	MOVE 1,JOBRT(P1)	;RUN TIME
	CALL GETSN3		;JOB NUMBER OF OWNER OF PTY IF ANY
	CALL GETRTL		;GET RUNTIME LIMIT OF JOB
	CALL GETBB		;GET BATCH BIT
	CALL GETJID		;GET DENSITY
	LOAD T1,JSMTP,(P4)	;GET MAGTAPE PARITY DEFAULT
	CALL GETJIM		;GET MAGTAPE DATA MODE
	CALL GETJRS		;GET MAGTAPE RECORD SIZE
	LOAD T1,JSDFS,(P4)	;GET DEFERRED SPOOLING BIT
	CALL GETSN6		;GET THE LOGGED IN DIRECTORY NUMBER
	CALL GETJSR		;GET SESSION REMARK
	MOVE T1,LSTLGN		;PICK UP LAST LOGIN D&T
NGTJIT==.-GETJIT

;ACTION ROUTINES FOR ITEMS NOT AVAILABLE IN SINGLE MOVE

;GET CONNECTED STRUCTURE,,DIRECTORY

;GET CONNECTED STRUCTURE,,DIRECTORY

GETSN4:	MOVE T1,P4		;T1/OFFSET FOR ADDRESSING JSB
	CALL GTOJCD		;GET CONNECTED STRUCTURE CODE,,DIRECTORY
	RET

;GET LOGGED DIR NUMBER

GETSN5:	HRRZ T1,JOBDIR(P1)	;GET DIR NUMBER
	SKIPE T1		;IF NOT LOGGED IN, RETURN 0
	HRLI T1,USRLH		;MAKE IT BE A 36 BIT USER NUMBER
	RET

;GET THE LOGGED IN DIRECTORY NUMBER

GETSN6:	MOVEI T1,PSNUM		;DIR IS ON PUBLIC STR
	CALL STRCNV		;CONVERT IT
	 RETERR (,<CALL CLRJSB>)
	HRLZS T1		;GET UNIQUE CODE IN THE LEFT HALF
	HRR T1,JOBDIR(P1)	;GET THE DIRECTORY NUMBER
	RET			;AND RETURN

;GET SUBSYSTEM NAME

GETSN1:	HRRZ 1,JOBNAM(P1)	;GET STATISTICS INDEX
	MOVE 1,SNAMES(1)	;GET NAME
	RET

;GET JOB NUMBER OF OWNER OF PTY

GETSN3:	HLRE 1,JOBPT(P1)	;GET CONTROLLING TTY
	JUMPL 1,RETO		;RETURN -1 IF DETACHED
	CALL PTYGFK		;GET FORK WHICH OWNS PTY
	 JRST RETO		;NO PTY, RETURN -1
	MOVEM 1,FX
	LOAD 1,FKJOBN		;GET JOB NUMBER WHICH OWNS FORK
	RET


;GET BATCH BIT

GETBB:	HLRE T1,JOBPT(P1)	;GET CONTROLING TTY
	JUMPL T1,RETZ		;IF NONE, JOB NOT CONTROLLED BY BATCH
	CALL PTYGBB		;GET BATCH BIT
	 JRST RETZ		;NOT A PTY
	RET			;ANSWER IS IN T1


;GET MAGTAPE DENSITY

GETJID:	LOAD T1,JSMTD,(P4)	;GET DEFAULT DENSITY
	SKIPN T1		;USING SYSTEM DEFAULT?
	MOVEI T1,MTDFDN		;YES
	RET


;GET MAGTAPE DATA MODE

GETJIM:	LOAD T1,JSMTM,(P4)	;GET DEFAULT DATA MODE
	SKIPN T1		;USING SYSTEM DEFAULT
	MOVEI T1,MTDFDM		;YES
	RET


;GET MAGTAPE RECORD SIZE

GETJRS:	LOAD T1,JSMTR,(P4)	;GET RECORD SIZE
	SKIPN T1		;USING SYSTEM DEFAULT?
	MOVEI T1,MTDFRS		;YES
	RET
;GET RUNTIME LIMIT FOR THIS JOB

GETRTL:	LOAD T1,JOBRTP,(P1)	;GET POINTER TO RUNTIME LIMIT BLK
	JUMPE T1,R		;WAS NONE
	LOAD T1,TIMTIM,(T1)	;GET ACTUAL LIMIT
	RET

;GET SESSION REMARK

GETJSR:	MOVEI T2,JSSRM(P4)	;ADDRESS OF REMARK IN JSB
	UMOVE T1,0(P3)		;PLACE WHERE USER WANTS REMARK PUT
	CALL CPYTUS		;COPY REMARK TO USER SPACE
	RET			;AND RETURN
;CONVERT ASCIZ PTR TO SIXBIT WORD
; 1/ BYTE PTR TO ASCIZ STRING
;	CALL ASZSIX
; RETURN +1: FAILURE, ILLEGAL CHARACTER
; RETURN +2: 1/ WORD OF SIXBIT
;  ASCIZ STRING LONGER THAN 6 CHARACTERS IS TRUNCATED

ASZSIX::STKVAR <WSIX>		;DECLARE LOCAL VAR FOR SIXBIT WORD
	SETZM WSIX		;CLEAR SIXBIT WORD
	MOVE 3,[POINT 6,WSIX]
	MOVEI 4,6		;6 CHARS MAX
SNM3:	XCTBU [ILDB 2,1]	;GET CHAR FROM USER
	JUMPE 2,SNM4		;END OF STRING IF NULL
	CAIL 2,40		;LEGAL CHARACTER?
	CAIL 2,140
	RET			;NO, DO +1 RETURN
	SUBI 2,40		;CONVERT TO SIXBIT
	IDPB 2,3		;BUILD SIXBIT
	SOJG 4,SNM3		;COUNT CHARS
SNM4:	MOVE 1,WSIX		;GET SIXBIT
	RETSKP
;LIGHTS, SWITCHES, AND OTHER MAINTENANCE STUFF

.SWTCH:: MCENT
	MOVE 2,CAPENB
	TXNN 2,SC%WHL+SC%OPR+SC%MNT ;SUFFICIENT CAPABILITIES?
	JRST CAPXR		;NO
	SETZ T1,		;INIT ANSWER
	UMOVEM 1,1
	SMRETN

.LITES::MCENT
	MOVE 2,CAPENB
	TRNN 2,SC%WHL+SC%OPR+SC%MNT ;REQUIRES STATUS
	JRST CAPXR
	SMRETN

.USRIO::MCENT
	MOVEI 1,SC%WHL+SC%OPR+SC%MNT
	TDNN 1,CAPENB		;REQUIRES STATUS
CAPXR:	RETERR(CAPX2)		;RETURN BAD, USER LACKS CAPABILITIES
	MOVSI 1,(1B6)		;USER IO BIT
	IORM 1,0(P)		;PUT IT ON
	SMRETN
;PEEK - AC1:  N,,MONLOC
;       AC2:     USRLOC

.PEEK::	MCENT
	MOVEI 3,SC%WHL+SC%OPR+SC%MNT
	TDNN 3,CAPENB		;HAS NECESSARY CAPS?
	RETERR(CAPX2)		;NO
	MOVSI 5,0(1)		;SETUP BLT ARGS - FROM
	HRRI 5,0(2)		; .. TO
	MOVEI 6,0(2)
	HLRZ 3,1		;COUNT
	HRRZ T4,T1		; FIND MONITOR LIMIT
	ADD T4,T3
	ADDI 6,-1(3)		; .. TO LIMIT

;CHECK ALL PAGES OF SOURCE BLOCK FOR PROPER ACCESS

	MOVEI 1,0(1)		;GET MONITOR ADDRESS
PEEK1:	PUSH P,1
	MRPAC			;GET ACCESS OF MONITOR PAGE
	TLNN T1,-1		;LEGAL RANGE? ** TO BE CHANGED FOR XADR **
	TLNN 2,(PA%RD)		;READABLE?
	RETERR(PEEKX2)		;NO
	POP P,1
	IORI 1,777		;BUMP ADDRESS TO NEXT PAGE
	ADDI 1,1
	CAMGE 1,T4		;CHECKED ALL PAGES?
	JRST PEEK1		;NO, GO CHECK NEXT ONE
	UMOVE T3,T2		;GET TO ADDRESS FROM USER
	UMOVE T2,T1		;GET FROM ADDRESS AGAIN
	HLRZ T1,T2		;FIND SIZE
	HRLI T2,MSEC1		;SECTION 1 IN MONITOR
	CALL BLTMU		;TRANSFER FROM MONITOR TO USER
	SMRETN

;ERROR - SC%WHL OR SC%OPR REQUIRED BUT NOT ENABLED

WHEELX:	ITERR(WHELX1)
;DETACH FROM CONTROLLING TTY

.DTACH::MCENT
	MOVEI T1,-1		;FINISH OUTPUT ON CONTROLLING TERMINAL
	DOBE			; BECAUSE TTYDAS WILL RELEASE BUFFERS
	CALL LDTACH		;DO THE WORK
	JRST MRETN

;DTACH CALLED INTERNALLY

LDTACH:	STKVAR <LDTALN>
LDTAC2:	SKIPGE CTRLTT		;DOES JOB HAVE A CONTROLLING TERMINAL?
	RET			;NO. DON'T DO ANYTHING
	HRLOI 1,(1B0+1B1+1B4+1B5)
	MOVEI 2,-1
	TLINK			;BREAK LINKS
	 JFCL
	CALL LCKDVL		;LOCK DEVICE LOCK, NO NOINT
	MOVE T2,CTRLTT		;GET JOB'S CONTROLLING TERMINAL
	MOVEM T2,LDTALN		;SAVE LINE NUMBER
	CALL STADYN		;POINT TO DYNAMIC DATA
	 JRST LDTAC3		;NOT ACTIVE. SHOULDN'T HAPPEN
	CALL TTFWAK		;WAKE UP PROCESS IN INPUT WAIT ON THIS LINE
	MOVE T2,LDTALN		;T2/ LINE NUMBER
	CALL TTYDAS		;DEASSIGN DYNAMIC DATA
	 JRST [	UNLOCK DEVLCK	;FAILED - UNLOCK DEVICE LOCK
		OKINT		;LCKDVL WENT NOINT
		TXZN T1,1B0	;ERROR OR WAIT?
		RET		;ERROR. CURRENTLY NO WAY TO HANDLE THIS
		HRL T1,LDTALN	;T1/(LINE NUMBER,,ADDRESS OF TEST ROUTINE)
		MDISMS		;WAIT UNTIL DEALLOCATION IS POSSIBLE
		JRST LDTAC2]	;TRY AGAIN
LDTAC3:	SETOM CTRLTT		;INDICATE JOB DOESN'T HAVE CONTROLLING TERMINAL
	MOVE T1,JOBNO
	HRROS JOBPT(T1)
	UNLOCK DEVLCK		;UNLOCK DEVICE LOCK
	HRRE T1,JOBDIR(T1)
	CAIE T1,0		;LOGGED IN?
	JRST [	MOVE T2,LDTALN	;T2/ LINE NUMBER
		CALL DETMSG	;YES. NOTE EVENT ON LOGGING TERMINAL
		JRST .+1]
	OKINT
	RET

;LDET2 - DETACH JOB FROM TERMINAL WITHOUT DEALLOCATING TERMINAL DATA

;RETURNS +1: ALWAYS

;PRESERVES T2

LDET2:	STKVAR<LDETSV>
	HRLOI 1,(1B0+1B1+1B4+1B5)
	MOVEI 2,-1
	TLINK			;BREAK LINKS
	 JFCL
	CALL UNPAGE		;CLEAR PAGING
	MOVE 2,CTRLTT		;T2/ CONTROLLING TERMINAL NUMBER
	MOVEM T2,LDETSV		;SAVE IT
	MOVE 1,JOBNO
	HRRE T1,JOBDIR(T1)	;GET LOGGED IN DIRECTORY
	CAIE T1,0		;LOGGED IN?
	CALL DETMSG		;YES, DO MESSAGE AND EFACT
	SETOM CTRLTT		;INDICATE NO CONTROLLING TERMINAL
	MOVE T1,JOBNO		;GET JOB NUMBER
	HRROS JOBPT(T1)		;INDICATE NO CONTROLLING TERMINAL
	MOVE T2,LDETSV		;T2/ LINE NUMBER
	CALL LCKTTY		;POINT TO DYNAMIC DATA
	 SKIPA			;NOT ACTIVE
	CALL TTFWAK		;WAKE FORK IN INPUT WAIT ON THIS LINE
	CALL ULKTTY		;ALLOW DEALLOCATION
	MOVE T2,LDETSV		;RESTORE LINE NUMBER
	RET

;ROUTINE TO TURN OFF PAGE MODE FOR CONTROLLING TERMINAL.
;CLOBBERS A AND B

UNPAGE:	MOVEI A,.PRIOU		;THE CONTROLLING TERMINAL
	RFMOD			;GET MODE
	TXZE B,TT%PGM		;PAGING NOW ON?
	STPAR			;YES. CLEAR IT
	RET			;AND DONE
;PROCEDURE TO HANDLE DATASET CARRIER OFF OR PTY CLOSED.
;DETACH JOB IMMEDIATELY, LOGOUT AFTER 5 MINUTES IF NOT REATTACHED.
;INVOKED ON REQUEST BY PSI SERVICE

JOBCOF::SKIPGE SLOWF		;IN JSYS CONTEXT?
	JRST [	MCENTR		;NO, GET THERE
		PUSH P,[MRETN]	;SETUP RETURN
		JRST .+1]
	SAVET
	MOVE 1,JOBNO
	SKIPGE B,CTRLTT		;HAVE A CONTROLLING TTY?
	JRST JOBCF1		;NO
	CALL GTCJOB		;GET ITS OWNING JOB
	 JRST JOBCF2		;NONE. GO ON
	CAIN C,0(A)		;SAME AS THIS ONE?
	JRST JOBCF1		;YES. GO ON
JOBCF2:	SETOM CTRLTT		;NO. CLEAR THIS ASSIGNMENT
	HRROS JOBPT(A)		;ALSO CLEAR CONTROLLING TTY HERE
JOBCF1:	HRRZ 1,JOBDIR(1)	;SEE IF NOW LOGGED IN
	JUMPE 1,FLOGO		;LOGOUT IMMEDIATELY IF NOT
	MOVE T1,FORKX		;GET OUT FORK INDEX
	SETZ 2,			;CLEAR THE WHOLE STACK
	CALL JSBSTF		;AND GO PROCESS THE JSB STACK
	CALL LDTACH		;DO LOCAL DETACH
	CALL FFORKI		;INDIRECTLY FREEZE ALL INFERIORS
	MOVE 1,[^D<5*60000>]	;SETUP TO WAIT 5 MINUTES
	CALL SETBKT		;COMPUTE BLOCKT DATA
	HRRI 1,COFTST		;SETUP SPECIAL TEST
	MDISMS			;WAIT UNTIL ATTACHED OR 5 MINUTES
	MOVE 1,JOBNO		;SEE IF NOW ATTACHED
	SKIPGE JOBPT(1)
	JRST FLOGO		;NOT ATTACHED, SO LOGOUT
	NOINT			;KEEP CONTROL
	HLRZ T2,JOBPT(T1)	;GET CONTROLLING TTY
	MOVEI T3,"C"-100	;FAKE A CONTROL-C
	CALL TTPSRQ		;""
	CALL RFORKI		;RESUME ALL INDIRECTLY FROZEN INFERIORS
	OKINT			;ALLOW INTS AGAIN
	RET

;SCHEDULER TEST FOR ABOVE. WAITS UNTIL JOB ATTACHED OR SPECIFIED TIME
;ELAPSED

	RESCD

COFTST:	LOAD 2,FKJOBN		;GET JOB NUMBER
	SKIPL JOBPT(2)		;NOW ATTACHED?
	JRST 1(4)		;YES, WAKEUP
	JRST BLOCKT		;NO, GO TEST TIME

	SWAPCD
;ATTACH JOB TO TTY

;ACCEPTS:
;	T1/ FLAGS,,JOB NUMBER TO ATTACH TO
;	T2/ USER NUMBER OF JOB IN AC 1
;	T3/ POINTER TO PASSWORD STRING
;	T4/ DESIGNATOR FOR TERMINAL TO BE USED IF AT%TRM FUNCTION OF 1
;	    IS ON.

;	ATACH

;RETURN +1: FAILURE, ERROR CODE IN 1
;RETURN +2: SUCESS.

.ATACH::MCENT
	ACVAR <Q1,Q2,Q3>	;DEFINE ALL Q'S TO USE AS WORK REGS
	STKVAR <ATACJN,ATACDR,ATACLN>
	UMOVE Q1,1		;BITS MODIFYING THE ATACH
	TXNE Q1,AT%TRM		;PROXY ATTACH
	JRST ATACH1		;YES.  DO NOT CARE ABOUT USER NUMBER
	HLRZ T3,T2		;GET UNIQUE CODE OF USER NUMBER
	CAIE T3,USRLH		;IS THIS A LEGAL USER NUMBER?
	RETERR (ATACX3)		;NO, GIVE ERROR RETURN
ATACH1:	MOVEI T1,0(T1)		;GET OBJECT JOB NUMBER
	JUMPE T1,[RETERR (ATACX1)] ;CAN'T ATTACH TO JOB 0
	MOVEM T1,ATACJN		;SAVE JOB NUMBER TO ATTACH TO
	CAIGE T1,NJOBS		;REASONABLE JOB NUMBER?
	SKIPGE JOBRT(T1)	;AND JOB EXISTS?
ATACH5:	RETERR(ATACX1)		;NO
	TXNN Q1,AT%TRM		;PROXY ATTACH
	JRST ATACH8		;NO.
	UMOVE Q3,4		;GET TTY NUMBER TO ATACH THE JOB TO
	ANDI Q3,377777		;JUST LINE NUMBER PART
	CAIL Q3,NLINES		;EXISTANT LINE?
	RETERR ATACX1		;NO. FAIL.
ATACH8:	HRRZ T3,JOBDIR(T1)	;DIRECTORY OF  OTHER JOB
	MOVEM T3,ATACDR		;SAVE DIRECTORY NO. FOR FACT FILE
	CAIE T3,0(T2)		;SAME AS SPECIFIED?
	RETERR(ATACX3)		;NO

;SEE IF USER CAN LEGALLY ATTACH OTHER JOB.  ATTACH IS LEGAL IF
;BOTH JOBS ARE SAME USER, IF THIS USER IS SC%WHL, OR IF
;USER GIVES PROPER PASSWORD
;ALSO, ATACH IS LEGAL IF JOB BEING ATTACHED IS OWNED BY THE
;SAME USER AS THE OWNER OF THE PTY CONTROLLING THE JOB DOING THE
;ATACH AND THE JOB DOING THE ATACH IS NOT YET LOGGED IN.
;ALSO, IF OWNER OF PTY IS AN ENABLED WHEEL OR OPR, JOB
;ON PTY MAY ALWAYS DO ATACH.
;ALSO, LEGAL IF OBJECT JOB IS OWNED BY ATACH-ER, DUE TO CRJOB.

	MOVE T2,JOBNO		;GET THIS JOB NUMBER
	HRRZ T2,JOBDIR(T2)	;GET USER NUMBER FOR THIS JOB
	CAMN T2,T3		;SAME AS OTHER JOB?
	JRST ATACH3		;YES, NO FURTHER LEGALITY CHECKS
	JUMPN T2,ATACH6		;PTY OWNER IS IRRELEVANT IF NOT LOGGED IN
	MOVE T1,CTRLTT		;SEE IF I AM ON A PTY
	CALL PTGETJ		;GET CONROLLING JOB # OR -1
	JUMPL T1,ATACH6		;NON-PTY DOING THE ATACH IF -1
	HRRZ T4,JOBDIR(T1)	;T4 GETS OWNER OF PTY
	XCTU [HRRZ T3,T2]	;GET OWNER OF JOB BEING ATACHED
	CAMN T3,T4		;THE SAME?
	JRST ATACH3		;YES, SO NO PASSWORD NEEDED
	CALL GJCAPS		;GET CAPABILITIES OF OWNER OF PTY
	TXNE T1,SC%WHL+SC%OPR	;PRIVILEGED?
	JRST ATACH3		;YES, SO NO PASSWORD NEEDED
ATACH6:	MOVE T3,ATACDR		;GET DIR NUMBER
	MOVEI T1,SC%WHL+SC%OPR
	TDNE T1,CAPENB		;THIS USER HAS CAPS?
	JRST ATACH3		;YES, NO FURTHER CHECKS
	MOVE T1,ATACJN		;SEE IF I OWN THE JOB
	HRRZ T1,JOBONT(T1)	;OWNER FIELD
	CAMN T1,JOBNO		;IS IT ME?
	JRST ATACH3		;YES, THEN IT'S LEGAL.
	UMOVE T1,2		;GET USER NUMBER FOR PASSWORD CHECK
	CALL CNVDIR		;GET USER'S LOGGED-IN DIRECTORY NUMBER
	UMOVE T2,T3		;GET PTR TO PASSWORD STRING
	TRNE T3,-1		;FAIL IF JOB NOT LOGGED IN
	CALL PASSWC		;PROPER PASSWORD?
	 JRST [	MOVE T2,T1	;SAVE FLAG
		MOVEI T1,^D3000	;NO, DELAY TO FOIL PASSWORD THIEVES
		SKIPN T2	;NEED TO SLEEP?
		DISMS
		RETERR(ATACX4)]	;NOW BOMB OUT
;USER HAS PROVEN RIGHT TO DO THIS. THE FOLLOWING DATA IS AVAILABLE:
;	JOBNO/ JOB NUMBER OF CALLER OF JSYS
;	CTRLTT/ TERMINAL AT WHICH CALLER IS RUNNING
;	ATACJN/ JOB NUMBER TO BE ATTACHED TO THIS TERMINAL

;USER WANTS TO ASSOCIATE THE JOB IN ATACJN WITH THE TERMINAL IN CTRLTT
;IF THE JOB IS CURRENTLY ATTACHED, IT MUST BE DETACHED FIRST

ATACH3:	TXNE Q1,AT%TRM+AT%NAT	;IS MY TTY TO BE USED?
	JRST ATACH9		;NOT BY DEFAULT, ANYWAY.
	SKIPGE Q3,CTRLTT	;YES. GET MY TTY
	RETERR ATACX2		;I DON'T HAVE ONE. FAIL.
ATACH9:	TXNN Q1,AT%TRM		;USING A DIFFERENT LINE?
	JRST ATACHB		;NO
	HRRZ T2,Q3		;YES, BETTER ASSIGN SOME DYNAMIC DATA
	CALL TTYASC		;ASSIGN AS CONSOLE
	 RETERR
ATACHB:	MOVE T1,ATACJN		;GET BACK OBJECT JOB NUMBER
	CALL SETJSB		;SETUP OTHER JOB'S JSB
	MOVEI Q2,0(T1)		;SAVE OFFSET FOR OTHER JOB'S JSB
	SKIPGE T2,CTRLTT(Q2)	;OTHER JOB NOW ATTACHED?
	JRST ATACH2		;NO. DON'T DETACH IT

;OBJECT JOB IS ATTACHED. DETACH IT FROM ITS CURRENT CONTROLLING
;TERMINAL AND DEALLOCATE THAT TERMINAL'S DATA

	MOVEM T2,ATACLN		;SAVE ITS CONTROLLING TERMINAL
	CALL LCKDVL		;LOCK DEVICE LOCK, GO NOINT
	NOSKED			;MUST DETACH IT FIRST
	CALL STADYN		;POINT TO DYNAMIC DATA
	 JRST ATACH7		;NOT ACTIVE. DON'T DEASSIGN IT
	CALL TTFWAK		;WAKE FORK IN INPUT WAIT ON THIS LINE
	MOVE T2,ATACLN		;T2/ LINE NUMBER
	CALL TTYDAS		;DEASSIGN THE LINE
	 JRST [	PUSH P,T1	;SAVE THE ERROR CODE
		OKSKED
		CALL CLRLFK	;UNMAP THE JSB
		UNLOCK DEVLCK	;UNLOCK DEVICE LOCK
		OKINT		;LCKDVL WENT NOINT
		POP P,T1	;GET THE CODE BACK
		TXZN T1,1B0	;NEED TO WAIT?
		RETERR		;NO. RETURN FAILURE
		HRL T1,ATACLN	;T1/(LINE NUMBER,,ADDRESS OF TEST ROUTINE)
		MDISMS		;WAIT UNTIL DEALLOCATION IS POSSIBLE
		JRST ATACH3]	;TRY AGAIN
ATACH7:	UNLOCK DEVLCK		;UNLOCK DEVICE LOCK
	OKINT			;LCKDVL WENT NOINT
	SETOM CTRLTT(Q2)	;INDICATE JOB HAS NO CONTROLLING TERMINAL
	MOVE T1,ATACJN		;GET OBJECT JOB NUMBER
	HRROS JOBPT(T1)		;NO CONTROLLING TERMINAL AGAIN
	OKSKED
	MOVE T2,ATACLN		;T2/ LINE NUMBER OF DETACHED JOB
	MOVE T3,JOBNO		;GET THIS JOB NUMBER
	HRRZ T3,JOBDIR(T3)	;GET USER NUMBER FOR THIS JOB
	HRLI T3,USRLH		;MAKE IT BE A USER NUMBER
	MOVE T4,CTRLTT		;AND TTY # OF DETACHER
	CALL DETMS1		;TELL JOB IT'S BEING DETACHED
	; ..
;OBJECT JOB HAS BEEN DETACHED. DETACH CALLER FROM CONTROLLING TERMINAL
;AND ATTACH OBJECT JOB TO THAT TERMINAL. DON'T DEALLOCATE THE DYNAMIC
;DATA FOR THE TERMINAL

	;..
ATACH2:	TXNE Q1,AT%NAT		;REQUESTED NO ATTACH?
	JRST ATACH4		;YES
	MOVEM Q3,ATACLN		;NO, MAKE SURE LINE RIGHT
	MOVE T2,Q3		;prepare for LDET2
	NOINT			; ..
	CAMN Q3,CTRLTT		;NEED TO GIVE AWAY MY TERMINAL?
	CALL LDET2		;YES, DETACH THIS JOB BUT KEEP DYNAMIC DATA 
	NOSKED

;ASSIGN OBJECT JOB TO CORRECT TERMINAL

	MOVE T4,ATACJN		;GET OBJECT JOB
	MOVEM Q3,CTRLTT(Q2)	;SET CTRLTT IN DEST JOB
	HRLM Q3,JOBPT(T4)
	MOVEI T1,.TTDES(Q3)	;T1/ DEVICE DESIGNATOR FOR TERMINAL
	CALL CHKDES 		;GET INDEX TO DEVICE TABLES
	 BUG(HLT,TTBAD1,<BAD DEVICE DESIGNATOR FOR TERMINAL AT ATACH2>)
	MOVE T1,ATACJN		;GET OTHER JOB NUMBER
	HRLM T1,DEVUNT(T2)	;INDICATE OTHER JOB OWNS THE TERMINAL
	MOVE T2,ATACLN		;T2/ TERMINAL NUMBER
	MOVE T1,TTSPSI(Q2)	;T1/ INTERRUPT WORD FOR OTHER JOB
	MOVE T3,TTSDPS(Q2)	;T3/ DEFERRED INTERRUPT WORD FOR OTHER JOB
	CALL TTSINT		;SET INTERRUPT WORDS FOR THIS TERMINAL
	MOVE T1,ATACJN		;T1/ OTHER JOB
	CALL STCJOB		;SET THIS AS CONTROLLING THE TERMINAL
	OKSKED
	OKINT
	CALL CLRLFK		;CLEAR MAPPING OF JSB
	MOVE T1,ATACJN
	MOVE T2,ATACLN		;SET UP JOB/LINE INFO
	CALL ATAMSG		;DO LOGGING STUFF
	MOVE T1,JOBNO
	HRRE T1,JOBDIR(T1)
	JUMPE T1,LOGO		;VANISH IF NOT LOGGED IN
	SMRETN

;HERE IF CALLER REQUESTED "NO ATTACH", I.E. DETACHING REMOTE JOB

ATACH4:	CALL CLRLFK		;CLEAR MAPPING OF JSB
	MOVE T1,ATACJN		;SET JOB #
	MOVE T2,ATACLN		; AND LINE #
	CALL DETMS0		;DO LOG MSG AND FACT FILE ENTRY
	SMRETN
;GET AND SAVE ROUTINES
;AC USAGE:
; P1 - FORK HANDLE,,JFN (AC1 ARG AFTER CHECKING)
; P5 - PTN OF UPT,,0
; P4 - COUNT IN SGET
; P3 - UPPER LIMIT PAGE
; P2 - LOWER LIMIT PAGE
;  F - FLAGS FROM CALL
;FPG0A USED AS WINDOW TO USER SPACE

.GET::	MCENT
	ACVAR <Q1,Q2,Q3>	;NEED TO USE ALL OF THE Q REGS
	MOVEI F,0(1)		;SAVE FLAGS FROM CALL
	MOVEI P3,777		;SETUP DEFAULT LIMITS
	MOVEI P2,0
	TXNE F,GT%ADR		;USER GIVING LIMITS?
	JRST [	XCTU [HLRZ P2,2] ;YES, GET THEM
		XCTU [HRRZ P3,2]
		JRST .+1]
	CALL GTSVI		;CHECK PARAMETERS, ETC.
	MOVE P1,P6		;GET JFN
	HRRI 2,1B19		;READ BIT
	TLNN 3,777		;DISK?
	HRRI 2,5B21		;YES, REQUEST READ AND XCT
	OPENF			;OPEN FILE FOR INPUT
	 ITERR			;WON'T OPEN
GET2:	HRRZ 1,P1		;JFN
	GTSTS
	TLNE 2,(1B8)		;END OF FILE?
	JRST GETE1		;YES, ERROR
	BIN			;GET IOWD COUNT,ADR
	 ERJMP GETE3		;FAILED. GO CLEAN UP AND GIVE ERROR RETURN
	MOVE 6,2
	HLRZ 2,2
	CAIN 2,EXEFIL		;AN EXE FILE?
	JRST GETEXE		;YES. GO DO IT THEN
	CAIL 2,1000		;CHECK FOR SHARE SAVE FILE
	CAIL 2,10000
	JRST .+2
	JRST SGET		;SHARE SAVE
	JUMPGE 6,GET1		;POSITIVE MEANS END

;FILE IS ZERO-COMPRESSED

	ADDI 6,1
	NOINT			;BE NOINT WHILE PAGE MAPPED
	CALL GET3		;SET MAP FOR PAGE
	JRST GET5

GET4:	TRNN 6,777		;JUST CROSSED PAGE BOUNDARY?
	CALL GET3		;YES, REMAP
GET5:	JUMPL 5,[TLNE 5,(1B1)	;GET A LOAD ERROR?
		JRST GETE5	;YES.
		BIN		;NO. USE BIN TO SKIP THIS BLOCK
		 ERJMP GETE4	;FAILED. GO CLEAN UP AND GIVE ERROR RETURN
		AOBJN 6,GET4	;THROW WORD AWAY
		JRST GET5A]
	HRRZ 2,6		;COMPUTE (NEG) NO. WDS LEFT ON PAGE
	ANDI 2,PGSIZ-1
	SUBI 2,PGSIZ
	HLRE 3,6		;GET (NEG) NO. WDS LEFT IN PTR
	CAMGE 3,2		;GET 'MINIMUM'
	MOVE 3,2
	PUSH P,3		;SAVE IT
	MOVE 2,5		;CONSTRUCT IFIW FOR @
	TXO 2,IFIW
	MOVEI 2,@2		;CONSTRUCT PTR TO DEST
	HRLI 2,(<POINT 36,0>)
	SIN			;MOVE WORDS TO DEST
	 ERJMP GETE4		;FAILED. GO CLEAN UP AND GIVE ERROR RETURN
	POP P,2			;RECOVER STARTING COUNT
	SUB 3,2			;COMPUTE WORDS MOVED
	JUMPE 3,[GTSTS		;IF NONE, MAY BE EOF
		TXNN 2,1B8	;IS EOF?
		JRST .+1	;NO, CONTINUE
		OKINT	 	;ALLOW INTERRUPTS
		JRST GETE1]	;YES, BOMB OUT
	HRL 3,3			;PUT COUNT IN BOTH HALVES
	ADD 6,3			;UPDATE AOBJN PTR
	JUMPL 6,GET4		;LOOP UNLESS PTR EXHAUSTED
GET5A:	CALL GET3X		;CLEAN UP MAPPINGS
	JRST GET2		;NEXT BLOCK
;HERE WHEN READ ENTRY VECTOR WORD (LAST WORD IN FILE)

GET1:	CALL VECSET		;SET THE ENTRY VECTOR
DONEG:	HRRZ 1,P1		;JFN
	CLOSF
	 JFCL
	JRST MRETN

;COMMON ROUTINE TO SET THE ENTRY VECTOR
;6/ VECTOR

VECSET:	CALL FLOCK
	HLRZ 1,P1		;FORK HANDLE
	CALL SETLFK		;MAP PSB
	MOVEM 6,ENTVEC(1)	;STORE ENTRY VECTOR DATA
	CALL CLRLFK
	CALL FUNLK
	RET			;AND DONE

;COMMON SETUP FOR GET, SAVE, SSAVE

GTSVI:	UMOVE P6,1		;SAVE ARG
	TRZ P6,770000		;FLUSH MISC BITS FROM JFN
	HRRZ 1,P6		;JFN
	DVCHR			;GET DEVICE CHARACTERISTICS
	PUSH P,2
	HLLZ 1,P6		;GET FORK HANDLE
	CALL FKHPTN		;CONVERT TO PTN
	  ITERR ()		;ILL FORMED RFH
	MOVEM 1,P5		;KEEP IT AROUND
	HRRZ 1,P6		;JFN
	POP P,3			;RECOVER DEVICE BITS
	MOVSI 2,(^D36B5)	;BYTE SIZE FOR BIN/BOUT XFER
	RET
;CHECK AND REMAP PAGE

GET3:	CALL GET3X		;UNDO PREVIOUS MAPPING IF ANY
	NOINT			;BE NOINT WHILE PAGES MAPPED
	LDB 2,[POINT 9,6,26]	;PAGE NUMBER NEXT REFERENCE
	CAMG 2,P3		;PAGE WITHIN LIMITS?
	CAMGE 2,P2
	JRST [	MOVSI 5,(1B0)	;NO, SET FLAG TO PREVENT STORE
		RET]
	MOVE 1,2		;PAGE NUMBER
	TXNN F,GT%NOV		;WANT TO AVOID OVERLAYS?
	JRST GET3N		;NO. GO ON THEN
	HLL 1,P1		;YES. GET FH
	RPACS			;GET ACCESS INFO FOR THIS PAGE
	TXNN 2,PA%PEX!PA%IND	;DOES THIS PAGE EXIST?
	JRST GET3N		;NO. GO ON THEN
	MOVSI 5,(3B1)		;YES. GIVE ERROR
	RET			;AND DONE
GET3N:	HLL 1,P5		;GET PTN OF USER PAGE TABLE
	MOVE 2,[PTRW+FPG0A]
	CALL SETMPG		;SETUP WINDOW TO USER PAGE
	MOVE 5,6		;MAKE @5 POINT TO FPG0A
	ANDI 5,777000		; I.E. FPG0-USERPAGE
	MOVN 5,5
	ADDI 5,FPG0A
	HRLI 5,6		;GIVE IT AN INDEX
	HRRZ 1,P1		;RESTORE JFN TO 1
	RET

;UNMAP WINDOW PAGE

GET3X:	SETZ 1,
	MOVEI 2,FPG0A
	CALL SETMPG
	OKINT
	RET

;UNKNOWN ERROR DURING GET.  GO OKINT IF NOW NOINT AND SAVE ERROR CODE

GETE5:	MOVEI 1,GETX3		;SAY OVERLAY ERROR
	MOVEM 1,LSTERR		;MAKE THIS THE ERROR
GETE4:	OKINT			;ALLOW INTERRUPTS
GETE3:	MOVE 5,LSTERR		;GET MOST RECENT ERROR
	JRST GETE2		;GO CLEAN UP AND TAKE ERROR RETURN

;UNEXPECTED END OF FILE DURING GET

GETE1:	MOVEI 5,IOX4		;FORCE RETURN OF ILLEGAL FILE FORMAT ERROR

;AN ERROR OCCURRED. AC 5 HAS THE ERROR CODE. CLEAN UP AND TAKE ERROR RETURN

GETE2:	HRRZ 1,P1		;GET JFN
	CLOSF			;CLOSE THE FILE
	 JFCL
	SETZ 1,
	MOVEI 2,FPG0A
	CALL SETMPG		;ENSURE TEMP PAGE CLEARED
	CAIN 5,IOX4		;DID WE GET END OF FILE?
	ITERR (GETX1)		;YES. RETURN ILLEGAL SAVE FILE FORMAT
	MOVE 1,5		;NO. RETURN THE REAL ERROR
	ITERR
;THE FILE IS AN EXE FILE. THE FIRST BLOCK MUST BE A DIRECTORY IN
;ORDER FOR CONTROL TO REACH THIS CODE

;DEFINITIONS FOR EXE FILES

EXEFIL==1776			;BLOCK TYPE FOR DIR AND FOR GETTING
				;TO THIS CODE
EXEEND==1777			;END OF ALL BLOCKS
EXEVEC==1775			;ENTRY VECTOR BLOCK
EXEWRB==1B2			;WRITE REQUEST IN FLAG BITS
EXESHR==1B1			;PAGE IS SHARABLE
EXEZRO==1B3			;PAGE EXISTS BUT IS ZERO

;BITS IN Q1 REMEMBERED DURING PROCESSING

EXEDIR==1B0			;SAW A DIRECTORY BLOCK
EXVEC==1B1			;SAW AN ENTRY BLOCK
NDSK==1B2			;IF ON, NOT A DISK

;FIELD DEFINITIONS FOR THE BLOCK CONTENTS

DEFSTR(EXADR,,35,27)		;FILE PAGE ADDRESS
DEFSTR(EXCNT,,8,9)		;COUNT FIELD
DEFSTR(EXPAG,,35,27)		;PROCESS PAGE ADDRESS

GETEXE:	TRVAR <DIRPAG,WRKPAG,DIRLPR,DIRCNT,CURPAG> ;VARIABLES FOR NON-DISK DEVICES
	MOVX Q1,EXEDIR		;SAW A DIR
	MOVEI 6,0(6)		;GET COUNT OF DIR WORDS
	SOS 6			;DISCOUNT THE HEADER
	LSH 6,-1		;2 WORDS PER ENTRY
	MOVEM 6,DIRCNT		;NUMBER OF PAIRS
	CALL CHECKG		;MUST BE ON DISK
	 SKIPA			;NOT DISK
	JRST DOEN1		;GO SEE ABOUT DIR ENTRIES
	NOINT			;MUST BE NOINT FOR REMAINDER OF JSYS
	TXO Q1,NDSK		;NOT A DISK
	CALL ASGPGS		;GET DIR PAGE
	 ITERR (GJFX22,OKINT)	;JSB MUST BE FULL
	MOVEM A,DIRPAG		;SAVE PAGE
	SOS A			;LOOPER WORD IS ONE LESS
	HRLI A,-1000		;# OF WORDS 
	MOVEM A,DIRLPR		;SET UP LOOP VALUE
	CALL ASGPGS		;GET PAGE FOR THE SIN
	 JRST [	MOVE A,DIRPAG
		CALL RELPGS	;CLEAN UP
		ITERR (GJFX22,OKINT)] ;NO ROOM
	MOVEM A,WRKPAG		;SAVE WORK PAGE ADDRESS
	OKINT			;ALLOW INTS NOW
	MOVE B,DIRPAG		;THE DIRECTORY PAGE
	HRLI B,(POINT ^D36,)	;MAKE IT A BYTE POINTER
	MOVNI C,777		;REST OF PAGE
	CALL SINN		;READ IT IN
	MOVEI A,1		;THE CURRENT PAGE
	MOVEM A,CURPAG		;REMEMBER THIS
DOEN1:	JUMPE 6,DOCAT		;IF NO DIR ENTRIES, GO AWAY
;LOOP TO PROCESS ALL OF THE DIRECTORY ENTRIES. EACH ENTRY IS TWO
;WORDS THE FIRST OF WHICH DESCRIBES THE FILE AND THE SECOND,
;DESCRIBING THE PROCESS

DOENT:	CALL GTWRD		;GET NEXT DIR WORD
	MOVE Q3,B		;SAVE IT
	CALL GTWRD		;GET NEXT DIR WORD
	JE <EXEZRO,EXADR>,Q3,ALLZER ;IF NON-EX, IGNORE IT
	SETZ C,			;CLEAR ACCESS BITS
	TXO C,PM%RD!PM%EX	;TURN ON READ AND EXECUTE
	TXNE Q3,EXEWRB!EXESHR	;WANT SOME FLAVOR OF WRITE?
	TXO C,PM%CPY		;YES. GIVE HIM COPY ON WRITE
	LOAD A,EXPAG,B		;GET PROCESS PAGE ADDRESS
	LOAD D,EXCNT,B		;GET REPEAT COUNT
	ADD D,A			;CALCULATE LAST PAGE TO AFFECT
	CAML D,P2		;WITHIN BOUNDS?
	CAMLE A,P3		;?
	JRST ALLZER		;NO. DONT LOAD IT THEN
	LOAD B,EXADR,Q3		;STARTING FILE PAGE
	CAMLE D,P3		;VERIFY UPPER BOUND
	MOVE D,P3		;TOO LARGE. USE USER'S
	CAMGE A,P2		;VERIFY LOWER BOUND
	CALL [	ADD B,P2	;TOO LOW. COMPUTE PROPER FILE PAGE
		SUB B,A		;""
		MOVE A,P2	;AND USE USER'S LIMIT
		RET]		;AND PROCEED
	SUB D,A			;GET NEW REPEAT COUNT
	AOS D			;ONE MORE FOR GOOD MEASURE
	JXE Q3,EXADR,[	SETOM B	;IF ALL ZERO, MAKE DELETE ARG
			JRST DOENT0] ;AND PROCEED
	TXNE Q1,NDSK		;IS THIS A DISK?
	JRST [	CALL NTDISK	;NOT DISK
		JRST ALLZER]	;DONE
DOENT0:	EXCH A,B		;MAKE ARGS CORRECT
	CALL MAPIT		;GET IT MAPPED
	 JRST [	MOVE 5,1	;GET THE ERROR
		JRST GETE2]	;AND GO ERROR OUT
ALLZER:	SOSLE DIRCNT		;MORE TO DO?
	JRST DOENT		;YES. GO DO THEM
	JRST DOCAT		;ALL DONE

;ROUTINE TO GET NEXT WORD FROM DIRECTORY

GTWRD:	TXNE Q1,NDSK		;A DISK?
	JRST GTWRD1		;NO
	MOVEI A,0(P1)		;JFN
	BIN 			;GET ENTRY
	 ERJMP GETE3		;FAILURE. GO CLEAN UP AND TAKE ERROR RETURN
	JUMPN B,R		;GOT IT?
	GTSTS			;GET STATUS
	TXNE B,GS%EOF		;END OF FILE?
	JRST GETE1		;YES
	SETZ B,			;NO
	RET			;ALL DONE

GTWRD1:	MOVE A,DIRLPR		;CURRENT POINTER
	AOBJP A,DIREOF		;MORE?
	MOVE B,0(A)		;GET DATUM
	MOVEM A,DIRLPR		;SAVE POINTER
	RET			;AND DONE
;ROUTINE TO GET IN FILE PAGE FOR NON-DISK DEVICE AND TO PUT
;DATA IN PROPER USER'S PAGE
;ACCEPTS:
;	A/ FIRST PROCESS PAGE NUMBER
;	B/ FIRST FILE PAGE NUMBER
;	D/ REPEAT COUNT

NTDISK:	STKVAR <SAVA,SAVB,SAVD>	;WORK REGISTERS
	MOVEM A,SAVA		;SAVE ARGS
	MOVEM B,SAVB		;SAVE B
	MOVEM D,SAVD
	CAME B,CURPAG		;AT PROPER FILE PAGE?
	JRST [	CAMG B,CURPAG	;NO. WANT TO MOVE FORWARD?
		JRST DIREOF	;NO. ERROR
		SUB B,CURPAG	;GET # OF PAGES TO WASTE
		ADDM B,CURPAG	;NEW CURRENT
		LSH B,^D9	;*512
		MOVNI C,0(B)	;NEGATIVE COUNT
		MOVEI B,B	;DUMMY POINTER
		MOVEI A,0(P1)	;JFN
		CALL SINN	;GET DATA
		JRST .+1]	;GO INLINE
RDPAGE:	MOVE A,SAVA		;GET CURRENT PROCESS PAGE
	HLL A,P1		;FORK HANDLE
	RPACS			;SEE ABOUT IT
	TXNE F,GT%NOV		;WANT TO CHECK FOR OVERLAYS?
	TXNN B,PA%PEX!PA%IND	;YES. IS THIS ONE?
	SKIPA			;NO. GO ON
	JRST DIREO3		;YES. GO ERROR OUT
	TLNE B,(1B5)		;NON-EX?
	TXNE B,PA%WT!PA%CPY	;HAVE WRITE ACCESS?
	SKIPA			;YES. ALLOW IT
	JRST WASTE		;NO. FORGET IT THEN
	HLL A,P5		;GET PTN OF PROCESS'S UPT
	MOVE B,WRKPAG		;GET WORK PAGE
	TXO B,PA%WT		;NEED WRITE ACCESS
	CALL SETMPG		;DO MAPPING
WASTE:	MOVE B,WRKPAG
	HRLI B,(POINT ^D36,)	;MAKE IT A POINTER
	MOVNI C,1000		;COUNT
	CALL SINN		;GET PAGE
	SETZ A,			;FOR THE UNMAP
	MOVE B,WRKPAG		;THE PAGE ADDRESS
	CALL SETMPG		;UNMAP WORK PAGE
	AOS CURPAG		;HAVE STEPPED A PAGE
	AOS SAVA		;NEXT PROCESS
	AOS SAVB		;NEXT FILE PAGE
	SOSG SAVD			;MORE?
	RET			;NO
	JRST RDPAGE		;YES

;ROUTINE TO EXECUTE A SIN AND CHECK FOR EOF AND ERROR
;ACCEPTS:
;	B/ BP
;	C/COUNT

SINN:	MOVEI A,0(P1)		;GET JFN
	SIN			;SO THE SIN
	 ERJMP DIRERR		;FAILED. GO CLEAN UP AND TAKE ERROR RETURN
	SKIPN C			;MADE IT?
	RET			;YES
	GTSTS			;GET FILE STATUS
	TXNE B,GS%EOF!GS%ERR	;EXCEPTION?
	JRST DIREOF		;YES
	RET			;NO
;LOOP TO READ THE NEXT BLOCK TYPE AND DISPATCH TO THE PROPER
;ACTION

DOCAT:	CALL GTWRD		;GET NEXT DIR WORD
	MOVE 6,B		;SAVE IT
	HLRZ B,6		;TYPE
	CAIN B,EXEVEC		;VECTOR BLOCK?
	JRST SETVEC		;YES. GO DO IT
	CAIE B,EXEEND		;END OF INFORMATION?
	JRST SKPBLK		;NO. UNKNOWN BLOCK
	TXNE Q1,EXVEC		;AT THE END. SEEN A VECTOR TYPE YET?
	JRST DONEG1		;YES. ALL DONE THEN
	MOVSI 6,(JRST)		;NO. MAKE UP ONE
	CALL VECSET		;AND GO SET IT
DONEG1:	TXNN Q1,NDSK		;A DISK?
	JRST DONEG		;YES. ALL DONE
	MOVE A,WRKPAG		;NO. RELEASE STORAGE
	NOINT			;PROTECT STRUCTURES
	CALL RELPGS		;RELEASE
	MOVE A,DIRPAG		;THE OTHER PAGE
	CALL RELPGS
	OKINT			;ALLOW INTS
	HRRZ A,P1		;GET JFN
	MOVEI B,.MOFWF		;SPACE FORWARD OVER TAPE MARK
	MTOPR
	 ERJMP .+1		;DONT CARE ABOUT ERRORS
	JRST DONEG		;AND DONE

;UNKNOWN BLOCK TYPE. SKIP THE BLOCK

SKPBLK:	MOVEI D,-1(6)		;NUMBER TO SKIP
	JUMPE D,DOCAT		;IF NONE, ALL DONE
	CALL GTWRD		;GET ONE
	SOJG D,.-1		;DO ALL
	JRST DOCAT		;NO. GET NEXT CATEGORY

;ERROR OCCURRED IN READING THE FILE. SAVE ERROR CODE IN AC 5 AND GO 
;CLEAN UP

DIREO3:	SKIPA 5,[GETX3]		;SAY HAD OVERLAY ERROR
DIRERR:	MOVE 5,LSTERR		;GET LAST ERROR
	JRST DIREO1

;UNEXPECTED END OF FILE OCCURRED IN READING THE FILE.  

DIREOF:	MOVEI 5,IOX4		;FORCE BAD FILE FORMAT ERROR

;AN ERROR OCCURRED DURING READING OF THE FILE. AC 5 CONTAINS THE ERROR CODE.
;CLEAN UP AND TAKE ERROR RETURN

DIREO1:	MOVE A,WRKPAG		;FREE WORK PAGE
	NOINT			;PROTECT STRUCTURES
	CALL RELPGS
	MOVE A,DIRPAG		;FREE DIR PAGE
	CALL RELPGS		;FREE THIS ONE TOO
	OKINT			;ALLOW INTS
	JRST GETE2		;AND GO ERROR OUT
;ROUTINE TO SET THE ENTRY VECTOR FROM AN EXE VECTOR BLOCK

SETVEC:	TXOE Q1,EXVEC		;SEEN ONE YET?
	JRST GETE1		;YES. BOMB HIM THEN
	HRRZ B,6		;GET COUNT
	CAIGE B,3		;PROPER TYPE?
	JRST SKPBLK		;NO. FORGET IT THEN
	PUSH P,B		;SAVE THE COUNT
	CALL GTWRD		;GET NEXT WORD
	MOVSI 6,0(B)		;THE COUNT
	CALL GTWRD		;GET NEXT WORD
	HRRI 6,0(B)		;GET ADDRESS
	CALL VECSET		;SET IT IN THE PROCESS
	POP P,6			;RESTORE THE COUNT
	MOVEI 6,-2(6)		;GET COUNT MINUS TWO
	JRST SKPBLK		;SKIP THE REST
;ENCOUNTERED CODE FOR SHARED SAVE.  EACH PAGE TO BE PUT IN THE
;FORK IS INDICATED BY ONE WORD WHERE:
; B0-8: ACCESS BITS, B0=WRITE COPY
; B9-17: FORK PAGE NUMBER TO RECEIVE PAGE
; B18-35: FILE PAGE NUMBER OF SOURCE PAGE

;IN ORDER TO USE THE MULTI-PAGE PMAP AND SAVE TIME, THIS
;ROUTINE SCANS THE INPUT FOR SUCCESSIVE FORK/FILE PAGES AND
;DOES AS MANY AS POSSIBLE WITH EACH PMAP

SGET:	CAIE 2,1000		;CORRECT TYPE NUMBER?
	JRST GETE1		;NO, STRANGE FILE
	MOVEI P4,0(6)		;SAVE COUNT
	CALL CHECKG		;MAKE SURE IS DISK
	 ITERR(SSAVX1)		;MUST BE DISK
	HRRZ 1,P1		;JFN
SGT5:	BIN			;GET FIRST WORD
	 ERJMP GETE3		;FAILED. GO CLEAN UP AND TAKE ERROR RETURN
SGT4:	CALL SGCHKL		;CHECK LIMITS
	 JRST [	SOJG P4,SGT5	;NOT WITHIN LIMITS, SKIP PAGE
		JRST GET2]	;COUNT DONE
	PUSH P,2		;SAVE FIRST WORD OF THIS GROUP
	PUSH P,2		;SAVE COPY OF IT FOR INCREMENTING
	JRST SGT2		;ENTER LOOP TO SCAN FOR SEQUENTIAL PAGES

;GET NEXT INPUT WORD, SEE IF BOTH FORK AND FILE PAGE ARE 1
;BEYOND LAST INPUT WORD

SGT1:	BIN
	 ERJMP GETE3		;FAILED. GO CLEAN UP AND TAKE ERROR RETURN
	CAMN 2,0(P)		;THIS PAGE SAME AS EXPECTED ONE?
	CALL SGCHKL		;AND WITHIN LIMITS?
	 JRST SGT3		;NO, MUST GO DO PREVIOUS INPUT
SGT2:	MOVE 2,[1,,1]		;BUMP FORK AND FILE PAGE NUMBERS
	ADDM 2,0(P)
	SOJG P4,SGT1		;COUNT TOTAL PAGES
	POP P,4			;COUNT DONE, ALL INPUT NOW READ
	POP P,2			;RECOVER FIRST WORD OF GROUP
	SUBI 4,0(2)		;COMPUTE COUNT OF PAGES IN GROUP
	CALL SGTDO		;DO PMAP
	 JRST [	MOVE 5,1	;GET THE ERROR
		JRST GETE2]	;AND GIVE IT
	JRST GET2		;CONTINUE WITH FILE

SGT3:	POP P,4			;RECOVER INCREMENTED PAGE NUMBERS
	EXCH 2,0(P)		;RECOVER FIRST WORD OF GROUP, SAVE NEXT
	SUBI 4,0(2)		;COMPUTE COUNT OF PAGES IN GROUP
	CALL SGTDO		;DO PMAP
	 JRST [	MOVE 1,5	;GET THE ERROR
		JRST GETE2]	;AND GIVE IT
	POP P,2			;RECOVER LAST INPUT
	HRRZ 1,P1		;RESTORE JFN
	JRST SGT4		;GO START SCAN OF NEXT GROUP
;ROUTINE USED BY ABOVE TO SETUP AND DO PMAP

SGTDO:	MOVEI 1,0(2)		;FILE PAGE NUMBER
	LDB 3,[POINT 9,2,8]	;ACCESS
	LDB 2,[POINT 9,2,17]	;MEMORY PAGE
	ROT 3,-^D9
	TLZE 3,(1B0)		;WRITE COPY REQUEST?
	TLO 3,(PM%CPY)		;YES, SET APPROPRIATE BITS

;ENTRY FOR EXE FILES
MAPIT:	CALL CHKLOD		;SEE IF OVERLAY CHECKS WANTED
	 RETBAD (GETX3)		;YES. AND IT DID
	SKIPL T1		;DOING DELETE?
	HRL 1,P1		;NO, JFN TO LH
	HLL 2,P1		;FORK HANDLE TO LH
	HRRI 3,0(4)		;COUNT OF SUCCESSIVE PAGES TO DO
	TXO 3,1B0		;SAY DO MULTIPLE PAGES
	TXNE F,GT%PRL		;WANT PRELOADING?
	TXO T3,PM%PLD		;YES. TURN ON BIT FOR PMAP
	PMAP
	RETSKP

;LOCAL ROUTINE TO CHECK PAGE AGAINST LIMITS

SGCHKL:	LDB 3,[POINT 9,2,17]	;GET PAGE NUMBER
	CAMG 3,P3		;TOO HIGH?
	CAMGE 3,P2		;OR TOO LOW?
	SOS 0(P)		;YES, CAUSE FAIL RETURN
	RETSKP

;LOCAL ROUTINE TO VERIFY FILE IS FROM DISK

CHECKG:	HRRZ 1,P1		;JFN
	DVCHR
	TLNE 2,777		;DISK FILE?
	RET			;NO
	RETSKP			;YES

;LOCAL ROUTINE TO CHECK FOR OVERLAYS

CHKLOD:	SAVET			;SAVE ALL REGS
	TXNN F,GT%NOV		;WANT TO PREVENT OVERLAYS?
	RETSKP			;NO. RETURN GOOD AND ALLOW MAP
	MOVE 1,2		;STARTING PAGE IN PROCESS
	HLL 1,P5		;PTN OF THE PROCESS
	MOVEI 2,0(4)		;NUMBER OF PAGES
	CALL MSCANP		;SEE IF ANY EXIST IN THIS RANGE
	JUMPN 2,R		;YES. ERROR THEN
	RETSKP			;NO. ALLOW MAP
;SAVE, GIVEN LIST OF BLOCK DESCRIPTORS OR ONE BLOCK DESCRIPTOR
;AC USAGE:
; P6 - FORK HANDLE,,JFN (AC1 ARG AFTER CHECKING, ETC)
; P5 - PTN OF UPT,,0
; P1 - DESCRIPTOR LIST
;  7 - CURRENT DESCRIPTOR

.SAVE::	MCENT
	MOVE P1,2		;SAVE DESCRIPTOR
	CALL GTSVI
	CALL GTSVDV		;SEE IF THE DEVICE IS LEGAL (DISK, MAGTAPE OR DECTAPE)
	 ITERR (SAVX1)		;ILLEGAL DEVICE TO SAVE ONTO; ABORT THE JSYS
	HRRI 2,1B20		;WRITE FILE
	OPENF
	 ITERR			;OPENF FAILED. ABORT THE JSYS
	TLNE P1,-1		;SOMETHING IN LH?
	JRST SAVE3		;YES, IT'S ONE DESCRIPTOR
SAVE2:	UMOVE 7,0(P1)		;GET NEXT DESCRIPTOR
	JUMPE 7,SAVE1		;CHECK FOR END OF LIST OF DESCRIPTORS
	CALL SAVEB		;WRITE BLOCK
	AOJA P1,SAVE2

SAVE3:	MOVE 7,P1
	CALL SAVEB
SAVE1:	HLRZ 1,P6		;FORK HANDLE
	CALL FLOCK		;LOCK THE FORK STRUCTURE
	CALL SETLFK
	PUSH P,ENTVEC(1)	;GET ENTRY VECTOR POINTER
	CALL CLRLFK		;CLEAR PSB MAPPING
	CALL FUNLK		;UNLOCK FORKS
	POP P,2			;RECOVER ENTRY VECTOR
	HRRZ 1,P6		;JFN
	BOUT			;WRITE ENTRY VECTOR POINTER
	CLOSF
	 JFCL
	JRST MRETN
;SAVE, PROCESS ONE BLOCK

SAVEB:	HLRZ 6,7		;MAKE LH COUNT NEGATIVE
	TRZE 6,400000		;LARGER THAN 377777?
	PUSH P,[SAVEBL]		;YES, DO IN TWO PARTS
	MOVNI 6,0(6)
	HRLI 7,0(6)
	SETO 4,			;SAY NO PAGE NOW MAPPED
	NOINT			;BE NOINT WHILE PAGE MAPPED
SAVEB1:	JUMPGE 7,[SETZ 1,	;DONE, CLEAN UP
		MOVEI 2,FPG0A
		CALL SETMPG
		OKINT
		RET]
	MOVE 6,7		;SETUP TO SCAN FOR NON-0'S
	LDB 1,[POINT 9,6,26]	;GET PAGE NUMBER
	CAIN 1,0(4)		;DIFFERENT FROM CURRENT MAPPING?
	JRST SAVE3A		;NO, SAME
	MOVEI 4,0(1)
	HLL 1,P5		;FORK HANDLE
	PUSH P,1
	SETZ 1,
	MOVEI 2,FPG0A
	CALL SETMPG		;REMOVE EXISTING CONTENTS OF WINDOW
	OKINT
	MOVE 1,0(P)
	CALL MRPACS		;SEE IF PAGE EXISTS
	POP P,2
	NOINT			;BE NOINT WHILE PAGE MAPPED
	TLNN 1,(PA%RD)		;CAN IT BE READ?
	JRST SAVE3B		;NO, FORGET IT
	MOVE 1,2
	MOVE 2,[PTRW+FPG0A]
	CALL SETMPG		;MAP PAGE
SAVE3A:	HRRZ 5,6		;SETUP RELATIVE ADDRESS IN WINDOW
	ANDI 5,PGSIZ-1
	ADDI 5,FPG0A
	JRST SAVE8

SAVE3B:	ANDI 6,777000
	ADDI 6,1000		;TO NEXT PAGE
	SUBI 6,0(7)
	HRLI 6,0(6)		;COUNT OF WORDS SKIPPED IN BOTH HALVES
	ADD 7,6			;UPDATE COUNT AND ADDRESS
	JRST SAVEB1

SAVEBL:	HRLI 7,400000		;DID N-400000 BEFORE, DO LAST 400000 NOW
	NOINT
	JRST SAVEB1
SAVE12:	TRNN 6,777		;NEW PAGE?
	JRST SAVE5		;YES
SAVE8:	SKIPN 0(5)		;NON-0 WORD?
	JRST SAVE6		;NO, GO CHECK FOR MORE
SAVE7:	ADDI 5,1
	AOBJN 6,SAVE12
	MOVE 6,7		;END OF BLOCK
	CALL SAVED
	JRST SAVEB1

;WRITE ALL OR PART OF ONE PAGE.

SAVED:	HLRE 2,6		;COUNT OF WORDS JUST SCANNED
	ADD 5,2			;RESET WINDOW POINTER
	HRRZ 1,P6		;JFN
	MOVE 2,6
	SUBI 2,1		;OUTPUT IOWD CNT,ADR
	BOUT
	HLRE 3,6		;GET (NEG) COUNT
	PUSH P,3		;SAVE IT
	HRRZ 2,5		;GET STARTING ADR
	HRLI 2,(<POINT 36,0>)	;CONSTRUCT BYTE PTR TO IT
	SOUT			;OUTPUT THE BLOCK
	POP P,2			;RECOVER STARTING COUNT
	SUB 3,2			;COMPUTE NO. WDS MOVED
	ADDM 3,5		;UPDATE WINDOW PTR
	HRL 3,3			;PUT COUNT IN BOTH HALVES
	ADDM 3,7		;UPDATE AOBJN PTR
	RET
;FOUND 0 WORD, CHECK FOR MORE

SAVE6:	MOVEI 2,0(6)
	CAIN 2,0(7)		;FIRST WORD OF BLOCK OR PAGE?
	JRST SAVE9		;YES
	HLRZ 2,6
	SETCMI 3,0(6)
	CAIE 2,-1		;END OF BLOCK, OR
	TRNN 3,777		;END OF PAGE?
	JRST SAVE5		;YES, FINISH BLOCK
	SKIPE 1(5)		;SUCCESSIVE 0?
	JRST SAVE7		;NO, CONTINUE SCAN
SAVE5:	MOVNI 6,0(6)		;COMPUTE NUMBER OF WORD TO DUMP
	ADDI 6,0(7)		;(-CURRENT)+OLD = -DIFFERENCE
	MOVSI 6,0(6)
	HRRI 6,0(7)		;FIRST ADDRESS
	CALL SAVED		;WRITE BLOCK
	JRST SAVEB1

;SCAN OVER BLOCK OF 0'S

SAVE10:	TRNE 6,777		;END OF PAGE?
	SKIPE 0(5)		;OR NON-0 WORD?
	JRST SAVE11		;YES
SAVE9:	ADDI 5,1
	AOBJN 6,SAVE10
SAVE11:	MOVE 7,6		;UPDATE POINTER
	JRST SAVEB1		;RECHECK PAGE, ETC.
;GTSVDV - ROUTINE TO CHECK FOR LEGAL DEVICE FOR SAVE AND SSAVE

;ACCEPTS IN T3: DEVICE CHARACTERISTICS AS RETURNED IN T2 BY DVCHR

;RETURNS +1: ILLEGAL DEVICE
;	 +2: LEGAL DEVICE

;ALLOWS DISK, NUL, MAGTAPE AND DECTAPE
;CLOBBERS T4

GTSVDV:
	LDB T4,[POINTR (T3,DV%TYP)] ;GET THE DEVICE TYPE
	CAIE T4,.DVDSK		;IS IT A DISK?
	CAIN T4,.DVNUL		;OR NUL DEVICE?
	RETSKP			;YES. GOOD
	CAIE T4,.DVMTA		;NO. IS IT A MAGTAPE?
	CAIN T4,.DVDTA		;NO. IS IT A DECTAPE?
	RETSKP			;GOOD CHOICE.  TAKE THE SKIP RETURN
	RET			;NOT DISK, MAGTAPE OR DECTAPE. NONSKIP RETURN.
;SSAVE - CREATES EXE FILES

;ACCEPTS FROM USER:
;  1/ (FORK HANDLE,,JFN)
;  2/ EITHER (0,,ADDRESS OF TABLE) IF TABLE IS MORE THAN 1 WORD OR
;     TABLE WORD
;  3/ FLAGS - NOT IMPLEMENTED
;  A TABLE OF WORDS OF THE FORM
;       (- NUMBER OF PAGES IN GROUP,,ACCESS+1ST CORE PAGE)
;    EACH OF WHICH REPRESENTS A GROUP OF CONTIGUOUS PAGES

; CALL:	SSAVE

;RETURN + 1:ALWAYS
;           ITERR HANDLES ERRORS

;SAVES USER'S CORE IMAGE (LH T1) INTO FILE (RH T1)
;HEADER GOES INTO PAGES 0, 1, AND 2 (IF NEEDED)

;AC USAGE:
;  ALL REGISTERS EXCEPT Q3 ARE USED. SEE INDIVIDUAL ROUTINES FOR
;   COMMENTS

; STRINGS IN DIRECTORY WORDS.  IF COMMENT, DEFINED IN GET

	DEFSTR(EXFLG,,8,9)	;ACCESS BITS 1ST WORD
;	DEFSTR(EXPAG,,35,27)	;FILE PAGE NUMBER 1 ST WORD
;	DEFSTR(EXCNT,,8,9)	;REPEAT COUNT 2ND WORD
;	DEFSTR(EXADR,,35,27)	;CORE PAGE NUMBER 2ND WORD

; ACCESS BITS INPUT AND SHIFTED TO LH
	SSCPY==1B0		;COPY ON WRITE
	SSACC==1B1		;TAKE ACCESS FROM PAGE
	SSWRT==1B3		;ALLOW WRITE

; ACCESS FOR EXE FILE

	EXEWRB==1B2		;WRITABLE
	EXESHR==1B1		;SHARABLE

; BLOCK TYPES  (DEFINED IN GET)

;	EXEFIL=1776		;DIRECTORY
;	EXEEND=1777		;END
;	EXEVEC=1775		;ENTRY VECTOR

;NOTE: THE EXE FILE FORMAT ALLOWS UP TO THREE PAGES OF DIRECTORY.
;HOWEVER, SSAVE IS CURRENTLY LIMITED TO ONE PAGE.

	SSDATA==1		;FIRST DATA PAGE IN OUTPUT FILE

.SSAVE::MCENT
	CALL SSAVA		;CALL ROUTINE TO DO THE SSAVE
	 ITERR			;ERROR RETURN FROM SSAVA
	JRST MRETN		;RETURN FROM SSAVE
;SSAVA - DOES THE WORK FOR SSAVE

;ACCEPTS:
;  SAME AS FOR .SSAVE ABOVE

;CALL:	CALL SSAVA

;RETURN + 1:ERROR CODE IN T1
;       + 2:SUCCESS

;FUNCTION:
;  1) READS THE USER'S INPUT
;  2) SETS UP TO PROCESS EACH GROUP OF PAGES AND CALLS SSAVB
;  3) WRITES THE FILE HEADER INFO

;CALLED BY SSAVE

;AC USAGE:
;  P1/ LOCATION OF CURRENT ENTRY IN DIRECTORY
;  P3/ NEXT FILE PAGE
;  P4/ CURRENT TABLE WORD
;  P6/ (FORK HANDLE,,JFN) AS INPUT IN AC 1
;  T1-T4/ TEMPORARY STORAGE

;TEMPORARY STORAGE: 
;  SSDIR - ADDRESS OF START OF SCRATCH PAGE IN WHICH DIRECTORY IS BUILT
;  SSAC2 - AC2 AS SPECIFIED BY THE USER'S CALLING ROUTINE
;  SSDEV - INDICATES TYPE OF OUTPUT DEVICE AND STATE OF PROCESSING

SSAVA:	STKVAR <SSDIR,SSAC2,SSCORE,SSDEV>
	SETOM SSDEV  		;INITIALIZE TO INDICATE DISK
	CALL GTSVI		;INPUT: USER'S T1/ (FORK HANDLE,,JFN)
				; OUTPUT: T1/JFN, T2/^D36B5, 
				; T3/ DEVICE CHARACTERISTICS,
				; P5/PTN FOR PAGE 0 OF FORK,P6/FORK HANDLE,,JFN
	CALL GTSVDV		;SEE IF THIS IS A LEGAL DEVICE
	 RETBAD (SSAVX1)	;NO. RETURN AN ERROR AND ABORT THE JSYS
	TLNE T3,777		;LEGAL. DISK?
	AOS SSDEV		;NO. INDICATE FIRST PASS ON SEQUENTIAL
	HRRI T2,OF%WR		;WRITE ACCESS - LEFT HALF SET UP FOR
				; 36-BIT BYTES IN GTSVI
	OPENF			;OPEN OUTPUT FILE FOR WRITE
	 RETBAD			;ERROR ON OPEN - CODE IN T1
	SKIPGE SSDEV		;WORKING ON DISK?
	JRST [	HRRZ T1,P6	;YES. T1/JFN
		MOVEI T2,SSDATA*1000 ;T2/POINTER TO START OF 1ST DATA PAGE
		SFPTR		;SET FILE POINTER 
	 	 RETBAD		;FAILED. ERROR IN T1
		JRST .+1]
	NOINT
	CALL ASGPGS		;GET SCRATCH PAGE TO BUILD DIRECTORY IN
	 JRST [	OKINT
	 	RETBAD(SSAVX3)]	;FAILED
	MOVEM T1,SSDIR		;SAVE ADDRESS OF FREE PAGE
	CALL ASGPGS		;GET A PAGE TO MAP USER'S PAGE INTO
	JRST [	MOVEI P4,SSAVX3	;FAILED. SET ERROR CODE
		JRST SSAV6]
	MOVEM T1,SSCORE		;SAVE ADDRESS OF THE PAGE 
	OKINT			;ALLOW INTERRUPTS
	MOVEI P3,SSDATA		;P3/START OF DATA AREA IN FILE
	;..
;HERE BEGINS A LOOP THAT IS PROCESSED ONCE FOR DISK AND TWICE FOR SEQUENTIAL
;DEVICES.  IN THE CASE OF DISK, SSAVB IS CALLED ONCE FOR EACH ENTRY IN THE 
;CALLER'S TABLE.  SSAVB COPIES THE CORE PAGES ONTO DISK (IF NON-ZERO) AND
;BUILDS THE DIRECTORY.  WHEN ALL THE GROUPS HAVE BEEN DONE, THIS ROUTINE WRITES
;THE HEADER PAGES.  FOR A SEQUENTIAL DEVICE, THE FIRST PASS SIMPLY CREATES THE
;DIRECTORY AND WRITES THE HEADER PAGES, SINCE THEY PRECEDE ALL DATA.  SSAVB IS
;CALLED AGAIN TO WRITE THE DATA PAGES.

	;..
SSAV7:	MOVE P1,SSDIR		;P1/START OF DIRECTORY AREA. 
	UMOVE T1,2		;T1 / INPUT AC2 - TABLE WORD OR ADDRESS OF TABLE
	MOVEM T1,SSAC2		;SAVE INPUT AC2 IN TEMPORARY STORAGE
	JUMPL T1,SSAV3		;NEGATIVE IF SINGLE DESCRIPTOR

;TABLE HAS MORE THAN ONE WORD.  T1 POINTS TO CURRENT WORD

SSAV2:	UMOVE P4,0(T1)		;GET NEXT DESCRIPTOR
	JUMPE P4,SSAV1		;0 INDICATES END OF TABLE
	MOVE T2,SSDIR		;PASS ADDRESS OF DIRECTORY SCRATCH  PAGE 
	MOVE T3,SSCORE		;PASS ADDRESS OF CORE SCRATCH PAGE
	MOVE T4,SSDEV		;PASS DEVICE FLAG 
	CALL SSAVB		;GO PROCESS THIS GROUP OF PAGES
	 JRST SSAV5			;ERROR FROM SSAVB - CODE IN T1
	AOS T1,SSAC2		;INCREMENT ADDRESS AND LOAD INTO T1
	JRST SSAV2		;GO GET THE NEXT TABLE WORD

;TABLE HAS ONE WORD. T1 CONTAINS IT.

SSAV3:	MOVE P4,T1		;SINGLE DESCRIPTOR INPUT IN AC 2
	MOVE T2,SSDIR		;PASS ADDRESS OF CORE SCRATCH PAGE 
	MOVE T3,SSCORE		;PASS ADDRESS OF CORE SCRATCH PAGE
	MOVE T4,SSDEV		;PASS DEVICE FLAG
	CALL SSAVB		;GO PROCESS THIS GROUP OF PAGES
	 JRST SSAV5
	;..
;ALL GROUPS HAVE BEEN PROCESSED.  SSDEV INDICATES STATE:
; -1: WORKING ON DISK.  DIRECTORY HAS BEEN BUILT IN SCRATCH PAGE,
;     AND DATA PAGES HAVE BEEN WRITTEN.  WRITE DIRECTORY AND QUIT.
;  0: FIRST PASS ON A SEQUENTIAL DEVICE.  DIRECTORY HAS BEEN BUILT
;     IN SCRATCH PAGE.  WRITE IT AND GO START OVER TO WRITE THE
;     DATA PAGES
;  1: SECOND PASS ON A SEQUENTIAL DEVICE.  DIRECTORY WAS WRITTEN ON
;     FIRST PASS, DATA PAGES ON SECOND.  QUIT.

;NOTE:WHEN SSAVE SUPPORTS MULTIPLE-PAGE DIRECTORIES, THIS CODE
;SHOULD, WHEN SSDEV=0, DETERMINE THE NUMBER OF PAGES IN THE
;DIRECTORY.  IF IT IS LESS THAN 3, IT SHOULD REDUCE ALL THE FILE
;PAGE NUMBERS IN THE DIRECTORY APPROPRIATELY AND SET P3 TO POINT
;TO THE FIRST PAGE AFTER THE DIRECTORY (I.E,. 1 OR 2)

	;..
SSAV1:	SKIPLE SSDEV		;SECOND PASS FOR SEQUENTIAL?
	JRST SSAV8		;YES. ALL DONE. FILE POINTER IS AT END
	SKIPE SSDEV		;NO. PROCESSING DISK?
	JRST [	HRRZ T1,P6	;YES. T1/JFN
		RFPTR		;GET PRESENT FILE POINTER
	 	 JRST SSAV5	;FAILED
		MOVEM T2,P4	;SAVE FILE POINTER
		SETZ T2,	;POINT TO BEGINNING OF FILE
		SFPTR		;SET FILE POINTER TO START DIRECTORY
	 	 JRST SSAV5	;FAILED
		JRST .+1]

;WRITE THE DIRECTORY BLOCK

	SUB P1,SSDIR		;SUBTRACT START OF SCRATCH PAGE FROM CURRENT LOC
	MOVE T2,P1		;NUMBER OF SUBGROUPS DONE *2
	JUMPE T2,SSAV4		;DON'T WRITE DIRECTORY IF NO SUBGROUPS
	ADDI T2,1		;NUMBER OF WORDS IN DIRECTORY (INCLUDES TITLE)
	HRLI T2,EXEFIL		;T2/ (TYPE NO.,,NUMBER WORDS)
	HRRZ T1,P6		;T1/ JFN FOR FILE
	BOUT			;WRITE FIRST WORD OF DIRECTORY
	HRRZ T3,P1		;T3/ (-NUMBER SUBGROUPS IN DIRECTORY)
	MOVNS T3
	MOVX T2,<POINT 36,0>	;T2/POINTER FOR 36-BIT BYTES
	HRR T2,SSDIR		; IN SCRATCH PAGE
	SOUT			;WRITE DIRECTORY
	;..
;ENTRY VECTOR BLOCK

	;..
	HRRI T2,3		;WORD COUNT FOR ENTRY VECTOR BLOCK
	HRLI T2,EXEVEC		;T2/(TYPE NO,,NUMBER WORDS)
	BOUT			;WRITE FIRST WORD OF ENTRY VECTOR BLOCK
	HLRZ T1,P6		;FORK HANDLE
	CALL FLOCK		;LOCK THE FORK STRUCTURE
	CALL SETLFK		;MAP PSB OF FORK (RETURNS OFFSET IN T1)
	MOVE T2,ENTVEC(T1)	;GET THIS FORK'S ENTRY VECTOR WORD
	MOVEM T2,P5		;SAVE ENTRY VECTOR WORD
	CALL CLRLFK		;UNMAP THE PSB
	CALL FUNLK		;UNLOCK THE FORK STRUCTURE
	MOVE T2,P5		;T2/ ENTRY VECTOR WORD
	MOVE T4,T2		;T4/ (ENTRY VECTOR COUNT,,ADDRESS)
	HLRZS T2		;MOVE ENTRY VECTOR COUNT FOR OUTPUT
	HRRZ T1,P6		;JFN FOR OUTPUT FILE
	BOUT			;WRITE ENTRY VECTOR COUNT
	HRRZ T2,T4		;ADDRESS OF ENTRY VECTOR FOR OUTPUT
	BOUT			;WRITE ENTRY VECTOR ADDRESS

;END BLOCK

	HRLI T2,EXEEND
	HRRI T2,1		;T2/ (TYPE NUMBER,,NUMBER WORDS)
	BOUT			;WRITE END BLOCK

;HEADER WRITTEN (DIRECTORY, ENTRY VECTOR, ETC.).  EITHER WORKING
;ON DISK (SSDEV=-1) OR FIRST PASS FOR SEQUENTIAL DEVICE (SSDEV=0)

SSAV4:	SKIPGE SSDEV		;WORKING ON DISK?
	JRST [	HRRZ T1,P6	;YES. T1/JFN
		MOVE T2,P4	;T2/ORIGINAL FILE POINTER (AFTER DATA)
		SFPTR		;SET FILE POINTER AFTER ALL EXISTING PAGES
	 	 JRST SSAV5	;ERROR FROM SFPTR - CODE IN T1
		JRST SSAV8]	;DONE. GO CLOSE THE FILE

;FIRST PASS FOR SEQUENTIAL DEVICE.  WRITE THE REST OF THE PAGE AND
;GO REPEAT THE BUILDING PROCESS TO WRITE THE DATA

	HRRZ T1,P6		;T1/JFN FOR FILE
	SETZM T2		;T2/DATA TO BE WRITTEN
	MOVEI T4,-1000+5	;NEGATIVE SPACE AVAILABLE FOR DIRECTORY
	ADD T4,P1		;NEGATIVE SPACE REMAINING
	HRLZ T4,T4		;TO LEFT HALF FOR COUNTING
	JUMPGE T4,SSAV10	;DON'T WRITE IF PAGE IS FULL
SSAV9:	BOUT			;WRITE A WORD
	AOBJN T4,SSAV9		;CONTINUE UNTIL PAGE COMPLETED
	
SSAV10:	MOVEI P3,SSDATA		;YES. P3/ADDRESS OF 1ST DATA PAGE
	AOS SSDEV		;INDICATE SECOND PASS
	JRST SSAV7		;GO WRITE THE DATA PAGES
;ALL OUTPUT DONE.  CLOSE FILE AND RELEASE SCRATCH PAGES

SSAV8:	HRRZ T1,P6		;JFN
	CLOSF			;CLOSE FILE
	 JFCL
	MOVE T1,SSDIR		;T1/ADDRESS OF DIRECTORY SCRATCH PAGE
	NOINT			;NO INTERRUPTS WHILE RELEASING PAGES
	CALL RELPGS		;RELEASE THE SCRATCH PAGE
	MOVE T1,SSCORE		;T1/ADDRESS OF CORE SCRATCH PAGE
	CALL RELPGS		;RELEASE THE PAGE
	OKINT			;ALLOW INTERRUPTS
	RETSKP			;SUCCESSFUL RETURN

;ERROR OCCURRED AFTER EITHER OR BOTH PAGES WERE OBTAINED.  RELEASE THEM.
;THE FAILING ROUTINE SET THE ERROR CODE IN T1.

SSAV5:	MOVEM T1,P4		;SAVE THE ERROR CODE
	NOINT			;NO INTERRUPTS WHILE RELEASING PAGES
	MOVE T1,SSCORE		;T1/ADDRESS OF CORE SCRATCH PAGE
	CALL RELPGS		;RELEASE THE PAGE

SSAV6:	MOVE T1,SSDIR		;T1/ADDRESS OF DIRECTORY SCRATCH PAGE
	CALL RELPGS		;RELEASE THE PAGE
	MOVE T1,P4		;RESTORE THE ERROR CODE
	OKINT
	RETBAD			;ERROR RETURN
;SSAVB - PROCESSES ONE WORD FROM USER TABLE

;ACCEPTS:
; T2/STARTING ADDRESS OF SCRATCH PAGE TO CONTAIN DIRECTORY
; T3/STARTING ADDRESS OF SCRATCH PAGE TO CONTAIN USER'S CORE PAGE
; T4/-1 OR 1 IF DATA PAGES SHOULD BE WRITTEN. 0 IF BUILD DIRECTORY ONLY
; P1/ADDRESS OF NEXT ENTRY IN THE DIRECTORY
; P3/ NEXT FILE PAGE
; P4/ TABLE WORD AS ENTERED (ACCESS IN 18-26) (SAVED IN SSWORD)
; P6/ FORK HANDLE,,JFN 

;CALL:	CALL SSAVB

;RETURN + 1:ERROR - CODE IN T1
;       + 2:SUCCESS

; SSAVB PROCESSES ONE GROUP OF PAGES AS REQUESTED BY ONE WORD IN
;  THE INPUT TABLE. CONTIGUOUS PAGES FORM ONE SUBGROUP (AND
; THUS ONE ENTRY IN THE DIRECTORY) UNTIL A PAGE DIFFERS FROM ITS
; PREDECESSOR IN ONE OF THE FOLLOWING WAYS:
;  A. PAGE N EITHER
;     1. IS ALL ZERO
;     2. DOES NOT EXIST, OR
;     3. IS NOT READABLE
;     AND N-1 IS NONE OF THE ABOVE
;  B. PAGE N-1 IS ANY OF THE ABOVE AND PAGE N IS NONE
;  C. PAGES N-1 AND N HAVE DIFFERENT ACCESS
; AT THAT POINT THE DIRECTORY ENTRY FOR N-1 IS COMPLETED AND A
; NEW SUBGROUP BEGINS WITH N.

;EACH DIRECTORY ENTRY IS TWO WORDS AS FOLLOWS:
;  - - - - - - - - - - - - - - - - - - - -
;  !ACCESS	  	!FILE PAGE NUMBER!
;  !REPEAT COUNT	!CORE PAGE NUMBER!
;  - - - - - - - - - - - - - - - - - - - -

;WHERE THE PAGE NUMBERS EACH OCCUPY 27 BITS AND REPRESENT THE STARTING PAGES
;IN A GROUP.  THE REPEAT COUNT IS 1 LESS THAN THE NUMBER OF PAGES
;IN A GROUP

;AC USAGE:
; P1/ADDRESS IN SCRATCH PAGE OF FIRST WORD OF CURRENT DIRECTORY ENTRY
; P2/ NUMBER OF PAGES PROCESSED THIS SUBGROUP
; P4/ ADDRESS OF FIRST WORD OF SCRATCH PAGE FOR DIRECTORY
; P5/ ACCESS TO GO WITH PAGE IN FILE
; Q1/ -NUMBER OF PAGES IN GROUP AS INPUT BY USER
; Q2/ NEXT CORE PAGE
; T1-T3/ TEMPORARY STORAGE

;TEMPORARY STORAGE:
; SSWORD - TABLE WORD CURRENTLY BEING DONE (SPECIFIED BY USER IN CALL)
; SSFLAG - FIRST TIME FLAG (0 ON FIRST ENTRY TO ROUTINE)
; SSCORE - SCRATCH PAGE FOR MAPPING USER'S CORE PAGE
; SSDEV -  CONTENTS OF T4 AS PASSED ON ENTRY
SSAVB:	STKVAR <SSFLAG,SSWORD,SSCORE,SSDEV,SSPACC>
	MOVEM T3,SSCORE		;SAVE ADDRESS OF CORE SCRATCH PAGE
	MOVEM T4,SSDEV		;SAVE DEVICE FLAG
	TLC P4,777000		;MAKE SURE COUNT .L. 1000 PAGES
	TLCE P4,777000		;I.E. BITS 0-8 SHOULD BE 1
	RETBAD(SSAVX2)		;LOSE - RETURN CODE IN T1

	MOVEM P4,SSWORD		;SAVE TABLE WORD
	MOVEM T2,P4		;P4/ADDRESS OF DIRECTORY SCRATCH PAGE
	SETZ P2,		;CLEAR COUNT OF PAGES IN SUBGROUP
	SETZM SSFLAG		;CLEAR FIRST TIME FLAG
	HRRZ Q2,SSWORD		;Q2/ NEXT CORE PAGE
	TRZ Q2,777000		;CLEAR ACCESS BITS
	HLRO Q1,SSWORD		;-COUNT OF PAGES

	;..
;SSB10 BEGINS LOOP THROUGH ALL PAGES IN A GROUP AS DESCRIBED BY ONE 
;WORD IN INPUT TABLE. ENDS BEYOND SSAVB5.
 
	;..
SSB10:	HLLZ T1