;Here to stop the current process. On the KC, new flags word for interrupt
;set the AC blocks to make monitor be current and user be previous. On the
;KL, we have to set them here.
PISC7A:
IFN KLFLG,<
DATAO PAG,SETMON ;SET MON CONTEXT
> ;END OF IFN KLFLG
MOVEM 17,PAC+17 ;SAVE PROCESS AC'S
MOVEI 17,PAC
BLT 17,PAC+16
DMOVE T1,PISC7R ;GET FLAGS AND PC
;On the KL, the process could be at GOUSR, in which case it would have set
;the current AC block to be user, in preparation for returning to the user.
;If so, back up the PC so that the DATAO can be executed again when the
;process is resumed. This isn't necessary on the KC since XJRSTF sets the
;block
IFN KLFLG,<
TXNE T1,UMODF ;MONITOR PC?
IFSKP.
HRRZ T3,T2 ;YES, AT POINT OF RETURN TO USER?
CAIN T3,GOUSR+1
HRRI T2,GOUSR ;YES, RE-EXECUTE DATAO PAG WHEN RESUMED
ENDIF.
> ;END OF IFN KLFLG
DMOVEM T1,PFL
MOVE 1,RSKEDN ;RESET NOSKED TRAP
MOVEM 1,RSKED
AOS INSKED
JSP FX,KISSAV ;SAVE APR-DEPENDENT STUFF
XJEN [MONENV
MSEC1,,SCHED0] ;GO DO THE MAIN SCHEDULER LOOP

SUBTTL Instruction trapping (ITRAP)
;INSTRUCTION TRAP - TRAP PC IN FPC, ASSUMED TO BE I +1
;Called via JSP T2,ITRAP1 (or JRST ITRAP) in process context
ITRAP1::MOVEM 1,LSTERR ;SAVE ERROR CODE GIVEN IN 1
ITRAP:: MOVEM T2,LSTIPC ;SAVE LAST ITRAP PC
;Check for illegal conditions
SKIPE INSKED
BUG.(HLT,SKDTRP,SCHED,SOFT,<Instruction trap while in scheduler>,<<KIMUPC,PC>,<LSTERR,LSTERR>,<LSTIPC,ERRPC>>,<
Cause: An error occurred, resulting in an illegal instruction trap. If a JSYS
is being executed by the monitor, the process normally receives an
error return when this happens. However, in this case the error
occurred in the scheduler, and there is no recovery.
Action: Although it is possible for bad hardware to cause this BUGHLT, it is
usually bad software. If the hardware checks out OK, send in an SPR
along with a dump and indicate how this problem can be reproduced.
Data: PC - PC of last MUUO, this may or may not be relevant
LSTERR - Last error code, this may indicate where error was generated
ERRPC - PC where ITRAP was called
>)
SKIPL FORKX ;NO FORK RUNNING, OR
CONSZ PI,177B27 ;PI IN PROGRESS?
BUG.(HLT,PIITRP,SCHED,HARD,<Instruction trap while PI in progress or in scheduler>,<<LSTERR,LSTERR>,<LSTIPC,ERRPC>>,<
Cause: An error occurred, resulting in an illegal instruction trap. If a JSYS
was being executed by the monitor, the process would receive an error
return. However, in this case the error occurred while a hardware
interrupt (PI) was being processed, or while the monitor was executing
code that starts the scheduler cycle.
Action: Although it is possible for bad hardware to cause this BUGHLT, it is
usually bad software. If the hardware checks out OK, send in an SPR
along with a dump and indicate how this problem can be reproduced.
Data: LSTERR - Last error code, this may indicate where error was generated.
ERRPC - PC at which error was generated.
>)

;Here if the previous level was user or monitor without ERJMP.
;We should not be NOSKED or CSKED. I.e., the JSYS code at this level should
;have cleaned up before going to ITRAP. If it didn't, the trap is probably
;unexpected.
SKIPN CRSKED
SKIPE NSKED ;CHECK FOR PROPER STATE
BUG.(HLT,NOSKTR,SCHED,SOFT,<ITRAP from NOSKED or CSKED context>,<<KIMUPC,MUUOPC>,<LSTERR,LSTERR>,<LSTIPC,LSTIPC>>,<
Cause: An illegal instruction trap has occurred while the process was NOSKED
or CSKED. This suggests that important resources may be left locked.
Action: This BUGHLT is normally seen with bad hardware. If the hardware checks
out OK, send in an SPR along with a dump and indicate how this problem
can be reproduced.
Data: MUUOPC - PC of last MUUO
LSTERR - Last error code
LSTIPC - PC from which ITRAP was called
>)

;See if previous context was user
TXNN T1,UMODF
IFSKP.
CALL ITRSIM ;YES, CHECK FOR ERJMP
JRST ITR2 ;NONE, GO DO INTERRUPT
MOVEM T3,-1(P) ;YES, DO IT
JRST MRETN
ENDIF.
;Here only if previous context is monitor without ERJMP.
BUG.(CHK,MONNEJ,SCHED,SOFT,<Nested JSYS without ERJMP>,<<T1,FLAGS>,<T2,PC>>,<
Cause: An illegal instruction trap has occurred and the previous context is
the monitor but no ERJMP is present following the nested JSYS call.
This violates required coding practice because the previous context may
have locks that need to be released.
Action: If this problem can be reproduced, set this bug dumpable and submit
an SPR along with the dump and instructions on reproducing the problem.
Data: FLAGS - Processor flags
PC - PC at which faulty nested JSYS was done
>)
JRST MRETN ;RETURN +1 ANYHOW
;Got to top of stack without an ERJMP. Give an interrupt to the user.
ITR2: MOVE 1,CHNSON
ANDCAM 1,PSIBW ;FLUSH PREVIOUS PANIC BREAKS
MOVEI 1,.ICILI ;INITIATE CHANNEL 15 INTERRUPT
CALL PSIRQ0
CHKINT ;GET THE INTERRUPT "SEEN"
OKINT ;INTERRUPT SHOULD TAKE HERE
JRST MRETN

;Check DDMP and CHKR
;[8923] DDMP is now checked first since it is usually the one that blocks
;trying to write on a disk, and the DDMPNR BUGHLT will therefore come out
;rather than blaming an innocent CHKR (which can be blocked by DDMP).
JB0CHK::
MOVEI T1,^D10000 ;WANT TO RUN AGAIN IN 10 SECONDS
MOVEM T1,JB0TIM ;SAVE FOR POSTERITY
CALL CKDDMP ;[8923] Check on DDMP
; CALLRET CKCHKR ;[8923] Check on CHKR and return

;[8923] Here to check on CHKR
CKCHKR: MOVE T1,TODCLK ;[8923] Get the current time
CAMGE T1,CHKTIM ;[8923] CHKR overdue?
RET ;[8923] Not overdue, return now
AOS T1,CHKDUE ;Bump the count of overdues
CAIL T1,CHKMAX ;Has it been overdue too long?
BUG.(HLT,CHKRNR,SCHED,HARD,<CHKR fork not run for too long>,,<
Cause: The monitor creates a fork in job zero that exists for the life of the
system. This fork runs periodically to perform essential system
functions. The BUGHLT occurs when the scheduler detects that the CHKR
fork has not run for too long a time.
Possible causes for CHKR not running include:
1. A disk failure that prevents job 0 from updating the disk
2. Removal of a disk that is mounted
3. An HSC or MSCP server disk is hung
4. Logic errors in the monitor.
Action: Check the console output from this system. Try to find out if any disk
problems are blocking DDMP. It is unlikely that this is a software
problem. Examination of the dump will probably show that some fork is
at the top of the go list and is blocked and NOSKED. If this fork is
DDMP then it is a disk problem. If CHKR is at the top of the go list
there is probably a software problem.
>) ;[8923]
CAIE T1,1 ;[8923] Is this the first time?
BUG.(CHK,NOCHKR,SCHED,HARD,<CHKR fork blocked>,<<T1,CHKDUE>>,<
Cause: The CHKR fork has not run in a while. The monitor is getting nervous.
If the CHKR fork continues to not run for a long time the a CHKRNR
BUGHLT will result.
Possible causes for CHKR not running include:
1. A disk failure that prevents fork 0 from updating the disk
2. Removal of a disk that is mounted
3. An HSC or MSCP server disk is hung
4. Logic errors in the monitor.
Action: Check the console output from this system. Try to find out if any disk
problems are blocking job 0. It is unlikely that this is a software
problem.
Data: CHKDUE - Count of times CHKR was found overdue
>,,<DB%NND>) ;[7.1210]
AOS JB0FLG ;[8923] Make sure CHKR will run soon
MOVE T1,TODCLK ;[8923] Get the current time
ADD T1,CHKPER ;[8923] Get the alarm time
MOVEM T1,CHKTIM ;[8923] Set the alarm time
RET ;[8923] and return

;[8923] Here to check on DDMP.
CKDDMP: MOVE T1,TODCLK ;[8923] Get the current time
CAMGE T1,DDPTIM ;[8923] Is DDMP overdue?
RET ;[8923] Not overdue, return now
AOS T1,DDPDUE ;Bump the overdue count
CAIL T1,DDPMAX ;Overdue too long?
BUG.(HLT,DDMPNR,SCHED,HARD,<DDMP fork not run for too long>,,<
Cause: The monitor creates a fork in job zero that exists for the life of the
system. This fork runs periodically to move pages from the swapping
space to files on disk. This is an essential system function. The
BUGHLT occurs when the scheduler detects that the DDMP fork has not run
in too long a time.
Possible causes for DDMP not running include:
1. A disk failure that prevents DDMP from updating the disk
2. Removal of a disk that is mounted causing DDMP to block
3. An HSC or MSCP server disk is hung causing DDMP to block
4. Logic errors in the monitor.
Action: Check the console output from this system. Try to find out if any disk
problems are blocking DDMP. It is unlikely that this is a software
problem. Examination of the dump will probably show that some fork is
at the top of the go list and is blocked and NOSKED. If this fork is
DDMP then it is a disk problem. If CHKR is at the top of the go list
there is probably a software problem.
>) ;[8923]
CAIE T1,1 ;Is this the first time?
BUG.(CHK,NODDMP,SCHED,HARD,<DDMP fork blocked>,<<T1,DDPDUE>>,<
Cause: The monitor creates a fork in job zero that exists for the life of the
system. This fork runs periodically to move pages from the swapping
space to files on disk. This is an essential system function. The
DDMP fork has not run in a while. The monitor is getting nervous. If
the DDMP fork continues to not run for a long time the a DDMPNR BUGHLT
will result.
Possible causes for DDMP not running include:
1. A disk failure that prevents DDMP from updating the disk
2. Removal of a disk that is mounted causing DDMP to block
3. An HSC or MSCP server disk is hung causing DDMP to block
4. Logic errors in the monitor.
Action: Check the console output from this system. Try to find out if any disk
problems are blocking DDMP. It is unlikely that this is a software
problem.
Data: DDPDUE - Count of times DDMP was found overdue
>,,<DB%NND>) ;[8923][7.1210]
MOVE T1,TODCLK ;Get the current time
ADD T1,DDPPER ;Get the next alarm time
MOVEM T1,DDPTIM ;Set the next alarm time
RET ;[8923] Return

;SCHEDULER REQUEST PROCESSOR
;MAY BE CALLED FROM SCHEDULER OR PROCESS CONTEXT
; T1/ DATA,,ADDRESS OF FUNCTION
; *MONUMENT*
;Once upon a time, this routine was called at interrupt level with
;several different arguments. At present, it is called only for
;JOBSRT and only in places where JOBSRT could be called directly.
;Therefore, this routine is now just a jacket for JOBSRT after
;verifying that the caller does indeed want JOBSRT.
SCDRQ7::SAVET
NOSKD1
HRRZ T2,T1 ;GET ROUTINE ADDRESS
CAIE T2,JOBSRT ;THE ONE LEGAL CASE?
BUG.(CHK,SRQBAD,SCHED,SOFT,<SCDRQ - Bad call to SCDRQ7>,,<
Cause: SCDRQ7 was called with a function it does not know about. Fix the
caller or fix SCDRQ7 to know about this function.
Action: If this bug can be reproduced, set it dumpable and submit an SPR along
with a dump and how to reproduce the problem.
>)
HLRZ T1,T1 ;GET DATA
CALL 0(T2) ;DO IT
OKSKD1
RET

;ROUTINE OF AJBALS TO HANDLE FIRST INSTANCE OF A FORK THAT
;WON'T FIT
SETPRP: SKIPN CLASSF ;CLASS SCHEDULING?
RET ;NO. NOTHING TO DO HERE THEN
CALL CORFCT ;YES. GET PRIROITY OF THIS PROCESS
CAMLE T1,[1.0] ;ONE OF THE COMPUTING PROCESSES?
JRST [ TXZ F,AJBYPF ;NO. IGNORE THE SKIP THEN
RET] ;AND DONE
MOVEM T1,PRIPST ;SAVE PRIORITY OF THIS PROCESS
RET ;AND DONE
;EXIT FROM AJBALS
AJBALX: SUB T4,AJBBSC ;REMOVE PAD AND ORIG BALSHC
PIOFF ;PREVENT CHANGE AT INT LEVEL
MOVE T3,SUMBNR
ADD T4,BALSHC ;INCLUDE CURRENT BALSHC
PION
CAMN T4,T3 ;CHECK SUM
IFSKP.
MOVE T3,SUMBNR
BUG.(CHK,SUMNR1,SCHED,SOFT,<AJBALX - SUMBNR incorrect>,<<T3,SUMBNR>,<T4,CHECK>>,<
Cause: The value of SUMBNR has been found to be incorrect by AJBALX. The
correct value of SUMBNR has been computed and stored in SUMBNR. This
problem is difficult to diagnose.
Action: If this BUGCHK can be reproduced, change it to a BUGHLT and submit an
SPR along with a dump and how to reproduce the problem.
Data: SUMBNR - Sum of working sets in balance set
CHECK - Correct computed value of SUMBNR
>)
MOVEM T4,SUMBNR
ENDIF.
MOVE T1,TODCLK ;SET TIME FOR NEXT PERIODIC CALL
ADD T1,AJBLCY
MOVEM T1,NXTAJB
MOVEM F,AJBFLG ;SAVE NEW SETTINGS
MOVE T1,AJLODN ;RETURN COUNT OF FORKS LOADED THIS CALL
RET

;HANDLE BAD FKCSIZ - RECOMPUTE COUNT AND REPORT VALUES
FIXWSP: MOVE T4,MONCOR ;SETUP TO SCAN CST3
SETZ T2, ; TO COUNT ASSIGNED PAGES
FIXWS1: LOAD T1,CSTOFK,+T4 ;GET FORK ASSIGNMENT
CAMN T1,FX ;THIS FORK?
AOS T2 ;YES, COUNT
CAME T4,NHIPG ;SCANNED ALL PAGES
AOJA T4,FIXWS1 ;NO
LOAD T1,FKWSS ;GET EXISTING VALUES
LOAD T3,FKCSIZ
BUG.(CHK,FKWSP1,SCHED,SOFT,<LOADBS - Unreasonable FKWSP>,<<T1,FKWSS>,<T2,COUNT>,<T3,FKCSIZ>,<FX,FORK>>,<
Cause: The value of FKCSIZ for this fork was found to be incorrect.
Specifically, the value of FKWSS was found to be less than the value of
FKCSIZ for this work. The correct value is being computed and saved in
FKCSIZ. This problem is difficult to diagnose.
Action: If this BUGCHK can be reproduced, change it to a BUGHLT and submit an
SPR along with a dump and how to reproduce the problem.
Data: FKWSS - Fork's reserve working set size
COUNT - Actual count of pages belonging to this fork
FKCSIZ - Saved count of pages belonging to this fork
FX - Fork number
>)
STOR T2,FKCSIZ ;FIX COUNT
CAMGE T1,T2 ;NOW LOOKS OK?
MOVE T1,T2 ;NO, RESET FKWSS ALSO
STOR T1,FKWSS
JRST LDJB5 ;NOW...

MOVE T2,TODCLK
CAMGE T2,HPSWRN ;TIME UP?
IFSKP.
ANDXE. T1,BSOVRD ;YES, NOT ALREADY NOTED?
MOVE T2,GBLJNO ;[8923] Yes, job probably stuck
;This bugchk is intended to detect forks which are running with priority (e.g.
;JP%SYS, NOSKED, CRKSED, or even PIBUMP) and using too much time. This is
;useful to know because such cases impact response for all ordinary users. The
;bugchk reports the job and fork number of the offending fork. DLM 10/28/81
HPSHOG: SKIPA ;[8923] JFCL here if you want this BUG output
BUG.(CHK,HPSCHK,SCHED,SOFT,<Excessive time in high priority>,<<T2,JOBNO>,<FX,FRKNO>>,<
Cause: A fork has entered a high priority scheduling condition (PIBMP, CSKED,
or JP%SYS), and has remained compute-bound for more than 5 seconds.
The fork has probably malfunctioned in some way, and the high
scheduling priority is affecting overall system response. The high
priority status is disabled until the fork itself clears the condition.
Action: The additional data contains the job number and system fork number.
The program should be changed to either not be so compute bound or not
set itself as high priority.
Data: GBLJNO - Job number
FRKNO - Fork number
>) ;[8923]
SETONE BSOVRD ;OVERRIDE PRIORITY
CALL GLREM ;FIND NEW POSITION ON GOLST
CALL GOCONC
ENDIF.
ENDIF.

;ROUTINE TO UNBLOCK SPECIFIC FORK
; FX/ FORK
UNBLK1::SAVEAC <Q2,F>
MOVE F,SCHFLG ;SETUP PERMANENT FLAGS
JE FKBLK,,UBBAD ;JUMP IF NOT BLOCKED
LOAD 1,FKWTL ;YES, GET POINTER TO IT
UNBLK2: HRRZ Q2,0(1) ;GET NEXT FORK ON LIST
JUMPE Q2,UBBAD ;COULDN'T FIND IT
MOVEI 2,-FKPT(Q2) ;GET INDEX FOR FORK
CAIE 2,0(FX) ;REQUESTED ONE?
JRST [ MOVEI 1,0(Q2) ;NO
JRST UNBLK2]
HRRZ 2,0(Q2) ;REMOVE FORK FROM LIST
HRRM 2,0(1)
CALL SCHEDJ ;ADJUST QUEUE AND PUT ON GOLST
UNBLK3: RET
UBBAD: BUG.(CHK,UNBFNF,SCHED,SOFT,<Fork not found>,,<
Cause: This BUG can be caused in one of three ways:
1. UNBLK1 was called to unblock a specific fork and the fork was
not blocked.
2. UNBLK1 was called to unblock a specific fork and the fork was
not on the wait list it claimed to be on.
3. RECONC was called to transfer a fork from one wait list to
another, but the fork was not on the list it claimed to be on.
Action: If this BUGCHK can be reproduced, set it dumpable and submit an SPR
along with a dump and how to reproduce the problem.
>)
JRST UNBLK3

;THE CLASS SCHEDULER IS ON. THE COMPUTED PRIORITY IS AS FOLLOWS:
; T1/ CLASS DISTANCE+MODIFIER
; OR T1/ SPECIAL VALUE
;WHERE THE SPECIALS ARE:
; 6.0 IF NOSKED
; 4.0 IF Q 0
; IF Q1 OR PI BOOST OR CRSKED OR SPECIAL SYSTEM FORK,
; 3.0 + VALUE (0 TO 1) FOR LENGTH OF TIME ON PRESENT QUEUE
;HOWEVER, IF THE CLASS IS PRESENTLY USING WINDFALL, Q1 PROCESSES
;RECEIVE CSLDST+.05 AS THE PRIORITY
;MODIFIERS IF NON-SPECIAL
; 0.5 IF ON INTQ1 AND CLASS NOT USING WINDFALL
; T2/ JOB DISTANCE + MODIFIER
;WHERE THESE MODIFERS ARE:
; 0.1(1-Q/LOWQ)
;OR T2/ Q NUMBER
; IF PROCESS IS SPECIAL

;HEURISTIC FOR ADJUSTING QUEUE LEVEL AFTER I/O WAIT
;THIS ROUTINE IS THE PRINCIPLE CONTROL OVER THE EXTENT TO WHICH
;'INTERACTIVE' OR 'COMPUTE-BOUND' JOBS ARE FAVORED. IT GIVES
;PRIORITY 'CREDIT' TO A FORK AS A RESULT OF WAITING. THE MORE
;CREDIT GIVEN FOR A CERTAIN LENGTH WAIT (OR THE SHORTER THE WAIT
;REQUIRED TO BECOME HIGH-Q), THE MORE THE SYSTEM WILL FAVOR
;INTERACTIVE FORKS, AND THE GREATER THE CHANCE THAT FREQUENT OR
;WELL-TIMED INTERACTIONS WILL GIVE A PROCESS AN EXCESSIVELY LARGE
;SHARE OF COMPUTE TIME. IT HAS BEEN DEMONSTRATED HOWEVER, THAT
;A COMPLETELY 'FAIR' ALGORITHM HERE, I.E. ONE WHICH PREVENTS AN
;INTERACTIVE FORK FROM GETTING ANY GREATER SHARE OF THE MACHINE
;THAN A COMPUTE-BOUND FORK, IS HIGHLY UNSATISFACTORY TO INTERACTIVE
;USERS UNDER MEDIUM AND HEAVY LOADS (AND ALL USERS ARE INTERACTIVE
;SOMETIMES), AND RESULTS IN EXPONENTIALLY INCREASING LEVELS OF
;FRUSTRATION, CURSING AND BEATING OF TERMINALS, ETC. THEREFORE
;THIS ROUTINE IS GENUINELY A HEURISTIC, MODIFIED AS A RESULT OF
;PRESSURES BROUGHT TO BEAR ON SYSTEM PROGRAMMERS.
;THE FOLLOWING DESCRIBES THE CURRENT PRACTICE:
; 1. TTY INPUT WAITS OF .GE. 1 SEC GIVE HIGH-Q. GREATLY REDUCES
; USER FRUSTRATION LEVEL.
; 2. WAITS BY FORKS ON QUEUE 0 RESULT IN NO CHANGE TO Q VALUE
; 3. FORKS ON QUEUES 1 TO MAXQ-1 WILL BE HIGH-Q IF WAITING TIME IS
; LONGER THAN LAST RUNTIME AS IMPLIED BY Q LEVEL.
; 4. FORKS ON MAXQ WILL BE HIGH-Q IF WAITING TIME IS LONGER THAN
; THE MAXQ QUANTUM, AND WILL BE MOVED UP TO MAXQ-1 IF WAITING
; TIME IS LONGER THAN SOME 'MINIMAL' TIME (500 MS)
;'WAITING TIME' ABOVE MEANS ACTUAL ELAPSED WAITING TIME
;DIVIDED BY THE 1-MINUTE LOAD AVERAGE. THIS KEEPS 'WELL-TIMED'
;INTERACTIONS FROM USING MORE THAN ABOUT 1/LDAV OF THE CPU.

LOAD 1,FKJSB ;SPT INDEX OF JSB
CALL WTSPT ;WAIT FOR IT TO BE UNSHARED
CALL WTFPGS ;WAIT FOR PSB AND UPT TO BE IN NO MAPS
MOVE T2,JOBNO ;RELEASE JOB NUMBER
SETZM JOBPNM(T2) ;[7113] CLEAR OUT OLD PROGRAM NAME
ENTSKD ;ENTER SCHED
SETZM JOBDIR(T2) ;CLEAR DIRECTORY NUMBER
SETOM JOBRT(T2) ;INDICATE JOB NUMBER NOT IN USE
HRRZ T1,@[EP. JOBCLS(T2)] ;SAVE CLASS OF JOB
ADDI T2,JOBPT
EXCH T2,FREJOB ;PUT SLOT ON FREE LIST
MOVEM T2,@FREJOB
SOS @[EP. CLSCNT(T1)] ;ONE LESS JOB IN THIS CLASS
MOVE T2,JOBNO ;GET THE JOB NUMBER
CAME T2,MJBUSE ;WAS THIS THE HIGHEST JOB IN USE?
IFSKP.
DO.
SOS T2,MJBUSE ;YES. NO LONGER IN USE
SKIPGE JOBRT(T2) ;PREVIOUS JOB IN USE?
LOOP. ;NO. DISCOUNT IT TOO
OD.
ENDIF.
SKIPE CLASSF ;DOING CLASS SCHEDULING?
CALL ADJCLS ;NOW UPDATE CLASS VALUES
JRST HLTFK2 ;FLUSH THIS LAST FORK
;LOCAL MSETPT - BUGCHK ON FAILURE
MSETP1: CALL MSETPT ;CLEAR ALL PAGES OF JOB MAP
BUG.(CHK,MAPCLF,SCHED,SOFT,<Failed to clear maps when killing job>,,<
Cause: A call to MSETPT to clear the job map or process map for the top fork
of a job being killed has failed.
Action: If this BUGCHK can be reproduced, set it dumpable and submit an SPR
along with a dump and how to reproduce the problem.
>)
RET

;HLTJB CONTINUED..
;DEASSIGN OF JOB CONTROLLING FAILED
HLTJB3: TXZN T1,1B0 ;FAILED. NEED TO WAIT?
BUG.(HLT,TTDAS1,SCHED,SOFT,<HLTJB - Unable to deassign controlling terminal>,,<
Cause: The monitor is killing the last (top) fork in a job and is trying to
deassign the job's controlling terminal. The attempt has failed for an
unexpected reason (one that will not be corrected if the fork waits a
while). This indicates inconsistency in the monitor's data base.
>)
UNLOKK DEVLKK ;YES. UNLOCK THE DEVICE LOCK
OKINT ;LCKDVL WENT NOINT
HRL T1,CTRLTT ;T1/(LINE NUMBER,,ADDRESS OF ROUTINE)
MDISMS ;WAIT UNTIL DEALLOCATION IS POSSIBLE
JRST HLTJB ; AND TRY AGAIN

LOAD 1,FKUPT ;UPT
CALL DESPT ;DELETE IT
LOAD T1,FKPS2 ;GET STACK I.D.
CALL DESPT ;RELEASE IT AS WELL
LOAD 1,FKPSB
CALL DESPT ;DEASSIGN PSB
SETOM FORKX
MOVEI T1,FKPT(FX)
EXCH T1,FREFK ;PUT FORK NUMBER ON FREE LIST
TLO T1,400000
MOVEM T1,@FREFK
CALL FKGC ;CLEAN UP ALL PAGES OF FORK
SETZM FKPGS(FX) ;ZERO FKPGS AS A FLAG OF NON ASSIGNED FORK
LOAD 1,FKCSIZ ;MAKE SURE FORK CLEANED UP
CAIE 1,0
BUG.(CHK,FRKNDL,SCHED,SOFT,<HLTFRK - Fork not properly deleted>,,<
Cause: HLTFRK was called to complete the deletion process for a fork but a
check of FKCSIZ showed that not all pages belonging to this fork have
been deleted. This indicates an inconsistency in the monitor's data
base.
Action: If this BUGCHK can be reproduced, set it dumpable and submit an SPR
along with a dump and how to reproduce the problem.
>)
CALL RDSIVL ;GET TIME SINCE ENTSKD
IDIVI T1,NTMS ;CONVERT TO MS
ADDM T1,USRTIM ;ACCUMULATE TOTAL USER TIME
JRST SCHED0 ;NOW THERE IS NOTHING LEFT OF JOB...

;PROCESS INTERRUPT(S) FOR THIS FORK AS SPECIFIED BY FKINTB
;THIS CODE *CAN* CAUSE PAGE FAULTS WHEN REFERENCING THE USER
;CHANNEL AND LEVEL TABLES.
;FX/ flags from FKINT
PSII: MOVE 1,MJRST0 ;NORMALIZE ALL DEFER TRAPS
MOVEM 1,MJRSTF
MOVE 1,INTDF0
MOVEM 1,INTDFF
XSFM T1 ;SEE IF CONTEXT BEING SETUP RIGHT
TXNE T1,PCU
TXNN T1,EXPCS
IFNSK.
IFN SKEDSW,<
BUG.(CHK,PSIIBE,SCHED,SOFT,<PSII - Flags not set properly>,<<T1,FLAGS>>,<
Cause: At PSII, the PC flags were not set properly. All paths to PSII should
ensure that PCU is 1 and PCS is non-0. This is under a debug
conditional and so should not be seen in the field.
Action: If this BUGCHK can be reproduced, set it dumpable and submit an SPR
along with a dump and how to reproduce the problem.
Data: FLAGS - Flags from XSFM.
>)
> ;END DEBUG CONDITIONAL
MOVX T1,MONENV
JSP T2,[XJRSTF T1] ;MAKE THEM RIGHT
ENDIF.

;These are two possible contents of MJRSTF. JSYS return executes this
;location. MJRST0 causes a return to the previous context. If a process
;is NOINT when an interrupt occurs, PSIDFR stores MJRST1 in MJRSTF (see
;above). WHen the process executes MJRSTF, the code at PSISV0 is executed.
MJRST0: XJRSTF FFL ;NORMAL CONTENTS OF MJRSTF
MJRST1: JRST PSISV0 ;TRY FOR INTERRUPT NOW
;These are two possible contents of INDTFF. The OKINT macro executes this
;location. INTDF0 decrements the noint count. If a process is NOINT when an
;interrupt occurs, PSIDFR stores INTDF1 in INTDFF (see above). When the
;process executes an OKINT, the code at PSISV1 is executed, and the flags
;and PC are stored in PIFL/PIPC.
INTDF0: SOS INTDF ;NORMAL CONTENTS OF INTDFF
INTDF1: XPCW PIFL ;CONTENTS OF INTDFF WHEN TRAP SET
;PIPC+1 CONTAINS JRST PSISV1
;HERE WHEN PROCESS DID AN OKINT AND THERE WAS AN INTERRUPT PENDING FOR
;THE PROCESS. DON'T LET IT TAKE IF PROCESS IS STILL NOINT.
PSISV1:
IFN KLFLG,<
DATAO PAG,SETMON ;SET MON AC BLOCK CURRENT
> ;END OF IFN KLFLG
SOSL INTDF
XJRSTF PIFL ;IF STILL NOINT, PROCEED
JRST PSISV2 ;GO ON

;RETURN TO THE NORMAL JSYS CODE
TRPSI6: SKIPL P5 ;HAS TRAP BEEN HANDLED AT ALL?
BUG.(CHK,TRPSIE,SCHED,SOFT,<TRAPSI - No monitor for trapped fork>,,<
Cause: A fork executed a JSYS that was marked as trapped, but there is no fork
monitoring this JSYS trap. The JSYS trap will be ignored.
Action: If this BUGCHK can be reproduced, set it dumpable and submit an SPR
along with a dump and how to reproduce the problem.
>)
LDB T1,[POINT 9,KIMUU1,26] ; Pick up opcode of trapped guy
CAIE T1,<JSYS>B62 ; Was a JSYS?
JRST TRPSI7 ; No, a UUO
LOAD T1,JTJNO
MOVE CX,JSTAB(T1) ;GET NORMAL DISPATCH
;Note: It may be necessary to work on this for the KC. It's not clear
;whether FFL has the right context always or not. But JSTAB no longer contains
;PCU, and FFL got PCU at MENTU, so this HLLZM no longer seems necessary. It
;also has the side-effect of clearing PCS.
; HLLZM CX,FFL ; Restore normal flags
; TXZ CX,EXFLBT
MOVEM CX,FPC ; And dispatch
XCTU [DMOVE T1,1] ;RESTORE STANDARD 4 ARGS
XCTU [DMOVE T3,3]
SETZM INTDF ;RESTORE STATE TO ENTRY AT TRAPSI
OKINT ;TURN PSIS BACK ON
XCT MJRSTF ;DO NORMAL DISP FOR THIS JSYS
TRPSI7: SETOM SLOWF ; Untangle ourselves
MOVE P,MPP ; in a state like this
POP P,FFL ; Reset flags
POP P,FPC ; And caller
MOVE P,UPP ; Reset the stack...
SETZM INTDF
OKINT
JRST U10501 ; Return to handle the UUO

;JSYS TRAP LOCK AND UNLOCK ROUTINES
;WHEN A FORK TRIES JTLOCK AND SOME OTHER FORK HAS THE
;LOCK, THE FORK ADDS ITSELF TO A QUEUE (FKJTQ) AND BECOMES BLOCKED.
;WHEN THE LOCK IS CLEARED (BY A MONITORING FORK) THE QUEUE IS
;SCANNED FOR THE FIRST FORK (IF ANY) WAITING ON THE LOCK. THAT
;FORK IS REMOVED FROM THE QUEUE AND ALLOWED TO RUN.
;LOCK ROUTINE
;ON ENTRY TO JTLOCK:
;P4/ JOB FORK INDEX (OF FORK TO FIELD TRAP)
;P6/ PTR TO ITS PSB
;RET + 1 IF SUSPENDED AND RESUMED WHILE QUEUED
;RET + 2 WITH LOCK SET
JTLOCK: NOSKED
STKVAR <KIMUP0,KIMUP1> ;[7290] SAVE KIMUU1 AND KIMUU1+1
AOSE JTLCK(P6) ;TRY TO SEIZE THE LOCK
JRST JTLOC2 ;SOMEONE ELSE HAS IT
OKSKED ;GOT IT
JTLOC1: RETSKP
;Here when lock was already locked. Go add this process to the queue
JTLOC2: DMOVE T1,KIMUU1 ;[7290]
MOVEM T1,KIMUP0 ;[7290] SAVE KIMUU1
MOVEM T2,KIMUP1 ;[7290] AND KIMUU1+1
JSP CX,JTENQ ;PUT SELF ON JSYS TRAP QUEUE
;RETURNS HERE WITH LOCK SEIZED
MOVE T1,KIMUP0 ;[7290] GET KIMUU1 (COULD HAVE BEEN TRASHED)
MOVE T2,KIMUP1 ;[7290] AND KIMUU1+1
DMOVEM T1,KIMUU1 ;[7290] AND RESTORE THEM
JRST JTLOC1 ;[7290] AND RETURN WITH LOCK SEIZED
ENDSV. ;[7290] END STORAGE
;IF FORK IS RESUMED AT JTRLCK, IT RETURNS + 1 TO TRAPSI ROUTINE
;FORCING ANOTHER CALL TO JTLOCK AFTER A CHECK TO SEE IF THE TRAP IS
;STILL TO GO TO THE SAME FORK.
JTRLCK: RET

;JTENQ - ROUTINE TO PLACE FORK ON QUEUE
;INVOKED VIA JSP CX,JTENQ (MAKES USE OF CX)
;This routine dismisses, with the process pointing to the instruction
;following the JSP that invoked it.
JTENQ: HRL T1,SYSFK(P4) ;1=FORK WAITING ON
ENTSKD ;ENTER SCHEDULER
TXZ CX,EXFLBT ;CLEAR FLAGS IN CASE SECTION 0 CALLED
MOVEM CX,PPC ; Save return for DISMSE
MOVE CX,ENSKR ;GET THE RIGHT FLAGS (ENTSKD STORED THEM)
MOVEM CX,PFL ;FOR RESUME AFTER DISMSE
SOSE NSKED ;MATCHED NOSKED IN JTLOCK
BUG.(HLT,JTENQE,SCHED,SOFT,<JTENQ with bad NSKED>,,<
Cause: A process has attempted to lock the JSYS trap lock and found it already
locked. The process will enter a queue and dismiss until the lock
becomes available. The BUGHLT occurs because when the process
decrements its NOSKED counter, the value does not go to 0. This means
that the process is still NOSKED or it was OKSKED when it should have
been NOSKED.
>)
MOVEI T2,FKJTQ(FX) ;FX=FORKX, SET BY ENSKED
HRRM T2,@JTLSTL ;ADD THIS FORK TO END OF QUEUE
EXCH T2,JTLSTL ;SET NEW END OF QUEUE PTR
MOVSM T2,FKJTQ(FX) ;SET BACK PTR TO OLD QUEUE END
HRRI T1,JTQWT
JRST DISMSE ;DISMS

;SLOW MONITOR CALL SETUP ROUTINE
;MENTM - Invoked via JRST from APRSRV with JSYS number in CX
;At this point,
;FFL, FPC - return flags and PC stored on MUUO.
MENTM:: LOAD CX,EXPCBT,JSTAB(CX) ;GET ROUTINE ADDRESS WITHOUT FLAGS
SETOM SLOWF
PUSH P,INTDF ;SAVE CONTEXT VARIABLES
PUSH P,MPP
PUSH P,FPC ;SAVE RETURN PC, FLAGS
PUSH P,FFL
MOVEM P,MPP ;SET NEW FRAME POINTER
XSFM FFL
MOVEM CX,FPC ;SETUP START PC FOR NEW JSYS
IFN SKEDSW,<
MOVE CX,-1(P) ;GET OLD PC
TXNN CX,EXSCBT ;CALLED FROM NON-0 SECTION?
BUG.(CHK,JSSEC0,SCHED,SOFT,<Nested JSYS call from section 0>,<<CX,PC>>,<
Cause: At entry to a JSYS called within the monitor, the return PC is in
section 0. This is a coding error which should be corrected. This is
under a debug conditional, so it should never occur in the field.
Action: If this BUGCHK can be reproduced, set it dumpable and submit an SPR
along with a dump and how to reproduce the problem.
Data: PC - PC of offending JSYS
>)
AOSGE INTDF ;CHECK STATE OF INTDF
BUG.(CHK,IDFOD1,SCHED,SOFT,<MENTR - INTDF overly decremented>,<<CX,PC>>,<
Cause: At the time of a nested JSYS call, INTDF was less than -1. Some code
in the calling context must have fouled it up. This is under a debug
conditional and so should not appear in the field.
Action: If this BUGCHK can be reproduced, set it dumpable and submit an SPR
along with a dump and how to reproduce the problem.
Data: PC - PC at which last JSYS was executed.
>)
SOS INTDF
> ;END OF IFN SKEDSW

;When running in the monitor, AC block 0 is current, 1 is previous
;Save the former "previous" AC block (block 1) in the PSB.
AOS P,ACBAS ;SETUP NEXT AC STACK BLOCK
CAIL P,<EUACB>B39 ;USED ALL BLOCKS?
BUG.(HLT,NOACB,SCHED,SOFT,<MENTR - No more AC blocks>,<<CX,PC>>,<
Cause: When a JSYS is executed from within the monitor, the AC's of the
current process are stored in a special area in the monitor. This area
consists of several 20-word blocks that are used successively as one
JSYS invokes another. The BUGHLT indicates that a JSYS has been called
but that no 20-word block is left in which to store the contents of the
AC's. This usually means that the counter that the monitor uses to
keep track of these blocks has been clobbered.
Data: PC - PC at which last JSYS was executed
>)
LSH P,4 ;MAKE INTO ADDRESS
;Copy the former "current" AC's (block 0) to the new "previous" AC's (block 1)
IFN KLFLG,<
SETPCS MSEC1A ;SET PCS SO PXCT [BLT] WORKS
MOVEI CX,0(P)
XCT 1,[BLT CX,17(P)] ;SAVE PREVIOUS CONTEXT AC'S
SETZ CX,
XCT 4,[BLT CX,CX-1] ;LOAD PREVIOUS CONTEXT AC'S 0-15 FROM CURRENT
> ;END OF IFN KLFLG
IFN KCFLG,<
STPAC. CX,(P) ;SAVE PREVIOUS CONTEXT AC'S
LDPAC <CX-1>,0 ;LOAD PREVIOUS CONTEXT AC'S 0-15 FROM CURRENT
> ;END OF IFN KCFLG
MOVE P,MPP ;RESTORE P
SETZM SLOWF
XCT MJRSTF ;RESUME MONITOR ROUTINE (NORMALLY XJRSTF FFL)

;Entry for MCENTR (JSP CX,MENT0). FFL and FPC have been setup by
;the caller, and may only be a user PC.
MENT0:: SETOM SLOWF
MOVE T1,FFL
TXNE T1,UMODF ;SIMULATING CALL FROM USER MODE?
IFSKP.
IFN SKEDSW,<
BUG.(HLT,MNTRNU,SCHED,SOFT,<MCENTR Without setup of user old PC>,<<CX,PC>>,<
Cause: MCENTR has been used without FFL setup to be a user PC. This is a
coding error.
Data: PC - PC at which MCENTR was executed
>) >
MOVX T1,UMODF ;DUMMY UP ONE
MOVEM T1,FFL
ENDIF.
MOVE P,UPP ;YES
PUSH P,FPC
PUSH P,FFL
PUSH P,FPC
PUSH P,FFL
XSFM T1 ;COOK UP PROPER FLAGS
TXO T1,PCU ;PCU MUST BE ON
LOAD T2,VSECNO,FPC ;SECTION NUMBER OF RETURN PC
STOR T2,EXPCS,T1 ;PUT IT WHERE HARDWARE SEES IT
MOVEM T1,FFL ;USE THAT AS NEW FLAGS
JRST MENT2 ;JOIN NORMAL USER CASE, PC IN CX

;Standard return from JSYS. MPP is stack pointer at time of entry.
;Make FFL and FPC point to caller's return address
;..
MRETN:: SETOM SLOWF ;RESET FLAG
IFN SKEDSW,<
AOSGE INTDF ;CHECK STATE OF INTDF
BUG.(CHK,IDFOD2,SCHED,SOFT,<MRETN - INTDF overly decremented>,,<
Cause: At MRETN, INTDF was found to be less than -1. This indicates that this
JSYS code did an unmatched OKINT and may have allowed interrupts when
it didn't intend to. This is a coding error.
Action: If this BUGCHK can be reproduced, set it dumpable and submit an SPR
along with a dump and how to reproduce the problem.
>)
>
MOVE P,MPP ;GO BACK TO LAST STACK FENCE
POP P,CX ;RETURN FLAGS
TLNN CX,(UMODF) ;RETURN TO USER?
JRST MRETN1 ;NO

;JSYS was called from user context. Set up FFL and FPC from the stack
MOVEM CX,FFL ;SET UP FLAGS
JSLKB2:: ;TAG FOR JSLOOK (SNOOP PGM)
POP P,FPC ;RESTORE PC
IFN SKEDSW,<
SKIPN CRSKED
SKIPE NSKED ;FAILED TO MATCH NOSKED, CSKED?
IFNSK.
SKIPN PNSKDC ;DIAG% NOSKED?
BUG.(HLT,RTNNSK,SCHED,SOFT,<Process is NOSKED or CSKED at MRETN>,,<
Cause: The process is NOSKED or CSKED at return from a monitor call. Probably
this JSYS went NOSKED or CSKED and forget to do the matching OKSKED or
ECSKED. This is a coding error.
>)
ENDIF.
SKIPGE FKLOCK ;FORK LOCK FREE?
IFSKP.
HRRZ CX,FORKN ;GET US
CAME CX,FLKOWN ;ARE WE THE OWNER?
ANSKP.
BUG.(CHK,INCFLK,SCHED,SOFT,<Fork lock set at return to user>,,<
Cause: Coding error has neglected to unlock the fork lock. The monitor
unlocks the fork lock before returning to the user. However, this
BUGCHK may be indicative of other failures to properly release
resources.
Action: If this BUGCHK can be reproduced, set it dumpable and submit an SPR
along with a dump and how to reproduce the problem.
>) ;YES. COMPLAIN THEN
SETOM FKLOCK ;FREE IT
SETZM FLKCNT ;AND FREE THIS TOO
ENDIF.
> ;END IFN SKEDSW
;ALL TRANSFERS TO USER MODE COME HERE. THE SCHEDULER RECOGNIZES
;THE PC AT GOUSR+1 AS A SINGULARITY (USER AC BLOCK BUT MONITOR PC)
;AND CORRECTS FOR IT.
GOUSR::
IFN KLFLG,<
DATAO PAG,SETUSR ;SETUP USER AC BLOCK AS CURRENT
> ;END OF IFN KLFLG
XCT MJRSTF ;RETURN TO USER (NORMALLY XJRSTF FFL)

;Here if returning to monitor context. Check for returning from IMCALL.
MRETN1:
XJRST [MSEC1,,.+1] ;FORCE CURRENT PC INTO SECTION ONE
POP P,FPC ;RESTORE PC
MOVEM CX,FFL ;STORE FLAGS
TXZE CX,IMCFLG ;INTERNAL CALL FLAG?
JRST IMCLL1 ;YES, DIFFERENT RETURN SEQUENCE
;Copy "previous" AC's to "current".
IFN KLFLG,<
SETPCS MSEC1A ;FUDGE PCS SO PXCT [BLT] WORKS
SETZ CX, ;MOVE PREV AC TO CURRENT
XCT 1,[BLT CX,CX-1] ;RESTORE CURRENT AC'S 0-15 FROM PREVIOUS
> ;END OF IFN KLFLG
IFN KCFLG,<
STPAC <CX-1>,0 ;RESTORE CURRENT AC'S 0-15 FROM PREVIOUS
> ;END OF IFN KCFLG
;Restore previous AC's from ACBAS block, stored at JSYS entry.
HRRZ CX,ACBAS ;POINT TO CURRENT LOCATION ON STACK
LSH CX,4
LDPAC. CX,0(CX) ;LOAD PREVIOUS CONTEXT AC'S FROM STACK
SOS CX,ACBAS ;DECREMENT ACBAS PTR
CAIGE CX,<UACB>B39-1
BUG.(HLT,OPOPAC,SCHED,SOFT,<MRETN - Tried to over-pop AC stack>,,<
Cause: When a JSYS is executed from within the monitor, the AC's of the
current process are stored in a special area in the monitor. This area
consists of several 20-word blocks that are used successively as one
JSYS calls another.
As each nested JSYS returns, the monitor's pointer to this area of
memory is decremented. The BUGHLT indicates that the pointer has been
decremented too far. This indicates either a clobbered pointer, or an
attempt to return from a JSYS without having entered one.
>)
;Restore variables stored on UPDL stack at JSYS entry.
POP P,MPP ;RESTORE VARIABLES
POP P,INTDF
SETZM SLOWF
XCT MJRSTF ;RETURN TO CALLER (NORMALLY XJRSTF FFL)