Google
 

Trailing-Edge - PDP-10 Archives - AP-4178E-RM - swskit-sources/jstrap.mac
There are 7 other files named jstrap.mac in the archive. Click here to see a list.
	TITLE	JSTRAP	PROGRAM TO WATCH JSYSES OF AN INFERIOR FORK


;NOTE:  THIS PROGRAM CAN ONLY RUN UNDER RELEASE 3 OR LATER.
;WRITTEN BY DAVID I. BELL, AT DIGITAL IN MARLBORO.
;THIS PROGRAM WILL WATCH THE JSYSES WHICH SOME INFERIOR FORK
;DOES, AND LOG THEM TO A LOG FILE.  THE LOG FILE CAN CONTAIN THE
;JSYS, THE PC IT WAS EXECUTED AT, AND THE ARGUMENTS TO THE JSYS.


	SEARCH	MACSYM,MONSYM	;GET SYMBOLS
	SALL			;NICE LOOKING MACROS


;VERSION INFORMATION:


	VMAJOR==1		;MAJOR VERSION
	VMINOR==0		;MINOR VERSION
	VEDIT==104		;EDIT NUMBER
	VWHO==1			;WHO LAST EDITED



;ACCUMULATORS:


	F=0			;FLAGS
	T1=1			;TEMPORARY AC'S
	T2=2
	T3=3
	T4=4
	T5=5
	C=6			;CHARACTER HOLDING
	P=17			;STACK



;FLAGS


	FR.INT==1		;USER HAS INTERRUPTED US
	FR.HDR==2		;HEADER LINE HAS BEEN TYPED
	FR.SAM==4		;ALL FORKS HAVE THE SAME ADDRESS SPACE
;JSYS CATAGORIES:


	JS.PRI==1		;JSYSES DOING PRIMARY I/O
	JS.FRK==2		;JSYSES HANDLING FORKS
	JS.FIL==4		;JSYSES HANDLING ANY FILE
	JS.INP==10		;JSYSES HANDLING INPUT
	JS.OUT==20		;JSYSES HANDLING OUTPUT
	JS.INT==40		;JSYSES HANDLING INTERRUPTS
	JS.SET==100		;JSYSES WHICH SET SOMETHING
	JS.STS==200		;JSYSES WHICH GET INFO
	JS.IPC==400		;JSYSES WHICH DO IPCF FUNCTIONS
	JS.ALL==1000		;ANY JSYS


;DEFAULT PARAMETERS:


	TXTLEN==^D100		;SIZE OF COMMAND BUFFERS
	PDLSIZ==40		;SIZE OF PUSHDOWN STACK
	SYMLEN==10000		;MAXIMUM NUMBER OF WORDS FOR SYMBOLS
	TTCHN==0		;CHANNEL FOR TTY INTERRUPTS
	JSCHN==1		;CHANNEL FOR JS TRAPPING INTERRUPTS
	BITSIZ==<1000+^D35>/^D36	;WORDS NEEDED FOR 1000 BITS




;MACROS AND OPDEFS:


	OPDEF	PJRST	[JRST]			;PUSHJ/POPJ
	OPDEF	PUTCHR	[PUSHJ	P,CHROUT]	;STORE A CHARACTER



	DEFINE	AA(NAME,DATA,FLAGS),<		;;MACRO FOR COMMAND TABLES
	XWD	[IFNB <FLAGS>,<EXP CM%FW!<FLAGS>>
		 ASCIZ/NAME/],DATA
>



	DEFINE	TEXT(STRING),<		;;MACRO FOR ASCIZ TEXT
	XLIST
	ASCIZ	@STRING@
	LIST
>
	SUBTTL	COMMAND SCANNER AND INITIALIZATION




ENTRY:	JRST	START		;NORMAL ENTRY
	JRST	START		;REENTER
	BYTE 	(3)VWHO(9)VMAJOR(6)VMINOR(18)VEDIT


START:	RESET			;CLEAR EVERYTHING
	MOVE	P,[IOWD PDLSIZ,PDL]	;SET UP A STACK
	SETZB	F,JFN		;CLEAR FLAGS AND INPUT JFN
	SETZM	JFNOUT		;AND OUTPUT JFN
	SETZM	HANDLE		;AND HANDLE OF INFERIOR
	SETZM	MAPCNT		;CLEAR NUMBER OF MAPPED PAGES
	MOVEI	T1,.JBSYM##	;GET NORMAL ADDRESS OF SYMBOLS
	MOVEM	T1,SYMADR	;AND SAVE IT
	MOVEI	T1,CORE		;GET ADDRESS OF PMAP BLOCK
	ADDI	T1,777		;ROUND UP TO NEXT PAGE
	ANDCMI	T1,777		;AND PUT ON EXACT BOUNDARY
	MOVEM	T1,PAGADR	;THEN SAVE POINTER
	MOVEI	T1,^D1000	;GET DEFAULT REPETITION COUNT
	MOVEM	T1,REPMAX	;AND INITIALIZE IT
	SETOM	BITS		;SET ALL THE BITS ON
	MOVE	T1,[BITS,,BITS+1]	;FOR DEFAULT CASE
	BLT	T1,BITS+BITSIZ-1	;WHICH IS TRAPPING OF ALL JSYSES
	MOVEI	T1,.TICCP	;GET DEFAULT TRAPPING CODE
	MOVEM	T1,INTCHR	;AND INITIALIZE IT
	MOVEI	T1,.FHSLF	;GET READY
	MOVE	T2,[LEVTAB,,CHNTAB]	;TO SET INTERRUPTS
	SIR			;TELL MONITOR WHERE THEY ARE
	MOVX	T2,1B<TTCHN>	;GET CHANNEL FOR TTY INTERRUPT
	AIC			;TURN IT ON
	MOVX	T2,1B<JSCHN>	;GET CHANNEL FOR JSYS TRAPPING
	AIC			;TURN IT ON
	EIR			;ENABLE THE INTERRUPTS
;HERE TO PROCESS A NEW COMMAND.  THIS IS ALSO THE PLACE THAT CONTROL
;IS PASSED WHEN WE ARE RUNNING AN INFERIOR FORK, AND A TERMINAL
;INTERRUPT OCCURRS.



NEWCMD:	MOVEI	T1,CMDBLK	;POINT TO COMMAND BLOCK
	MOVEI	T2,[FLDDB. (.CMINI)]	;INITIALIZATION FUNCTION
	PUSHJ	P,COMMND	;GO DO IT
	MOVEM	P,SAVEP		;SAVE STACK FOR REPARSING


NEWPAR:	MOVE	P,SAVEP		;RESTORE THE STACK
	MOVEI	T1,CMDBLK	;POINT TO THE COMMAND BLOCK
	MOVEI	T2,[FLDDB. (.CMKEY,,CMDTAB)]	;POINT TO COMMAND TABLE
	PUSHJ	P,COMMND	;READ THE COMMAND
	MOVE	T2,(T2)		;GET ADDRESS OF ROUTINE
	PUSHJ	P,(T2)		;CALL IT
	JRST	NEWCMD		;AND GET A NEW COMMAND




;TABLE OF COMMANDS:


CMDTAB:	CMDLEN,,CMDLEN			;HEADER
	AA	ALLOW,CMDALW		;ALLOW TRAPPING FOR JSYSES
	AA	CLOSE,CMDCLS		;CLOSE LOG FILE
	AA	DISALLOW,CMDDIS		;DISALLOW TRAPPING
	AA	EXIT,CMDXIT		;LEAVE PROGRAM
	AA	FORKS,CMDFRK		;FORKS HAVE SAME ADDRESS SPACE
	AA	GET,CMDGET		;READ IN THE PROGRAM TO WATCH
	AA	HELP,CMDHLP		;TYPE HELP MESSAGE
	AA	INTERRUPT,CMDINT	;SET INTERRUPT CHARACTER
	AA	LOG,CMDLOG		;BEGIN LOGGING JSYSES
	AA	MAXIMUM,CMDMAX		;SET MAXIMUM REPETITIONS
	AA	PROCEED,CMDPRO		;CONTINUE FROM INTERRUPT
	AA	RESET,CMDRES		;RESET EVERYTHING
	AA	S,STABBR,CM%ABR+CM%INV	;ABBREVIATION OF START
STABBR:	AA	START,CMDST		;START THE PROGRAM
	AA	SYMBOLS,CMDSYM		;GET SYMBOLS
	AA	TELL,CMDTEL		;TELL STATUS OF A JSYS

	CMDLEN==.-CMDTAB-1		;NUMBER OF COMMANDS
	SUBTTL	COMMAND TO SET WHAT ADDRESS TO GET SYMBOL TABLE FROM




;HERE TO READ IN THE ADDRESS OF THE SYMBOL POINTER TO USE IN
;READING IN THE SYMBOLS.  THE SYMBOLS ARE ALSO READ IN IF THE
;PROGRAM IS CURRENTLY IN CORE.




CMDSYM:	MOVEI	T2,[ASCIZ/READ USING POINTER AT LOCATION/]
	PUSHJ	P,NOISE		;PARSE NOISE
	MOVEI	T2,[FLDDB. (.CMNUM,,^D8,,<116>)]	;GET FUNCTION
	PUSHJ	P,COMMND	;READ NUMBER
	MOVE	T4,T2		;SAVE IT
	PUSHJ	P,CONFRM	;AND CONFIRM THE LINE
	CAIL	T4,20		;MAKE SURE NOT IN THE AC'S
	CAILE	T4,777777	;AND MAKE SURE NOT TOO LARGE
	  JRST	BADSYA		;BAD ADDRESS
	MOVEM	T4,SYMADR	;OK, SAVE THE ADDRESS
	SKIPN	HANDLE		;DO WE HAVE A FORK THERE?
	  POPJ	P,		;NO, THEN RETURN
	PJRST	GETSYM		;YES, THEN GET THE SYMBOLS



BADSYA:	HRROI	T1,[ASCIZ/
? Illegal address specified/]	;GET ERROR TEXT
	PSOUT			;OUTPUT IT
	JRST	LOSFIN		;AND FINISH UP
	SUBTTL	ROUTINE TO BEGIN LOGGING OF JSYSES




;HERE IS THE COMMAND WHICH DETERMINES THE OUTPUT SPEC FOR THE LOGGING,
;AND SETS UP THE TRAPPING FOR JSYSES.  USUALLY THE PROGRAM TO BE
;TRAPPING HASN'T STARTED YET, BUT IT COULD BE IF IT WAS INTERRUPTED.




CMDLOG:	MOVEI	T2,[ASCIZ/JSYSES TO FILE/]	;GET NOISE
	PUSHJ	P,NOISE		;PARSE NOISE TEXT
	HRROI	T2,[ASCIZ/JSTRAP/]	;GET DEFAULT FILE
	MOVEM	T2,JFNBLK+.GJNAM	;SAVE IT
	HRROI	T2,[ASCIZ/LOG/]		;GET DEFAULT EXTENSION
	MOVEM	T2,JFNBLK+.GJEXT	;SAVE IT TOO
	MOVX	T2,GJ%FOU+GJ%MSG	;GET FLAGS
	MOVEM	T2,JFNBLK	;AND SET THEM
	MOVEI	T2,[FLDDB. (.CMFIL)]	;GET READY
	PUSHJ	P,COMMND	;READ OUTPUT SPEC
	MOVE	T4,T2		;SAVE THIS JFN
	PUSHJ	P,CONFRM	;CONFIRM THE LINE
	PUSHJ	P,CLSLOG	;CLOSE ANY OLD LOG FILE
	HRRZM	T4,JFNOUT	;THEN SAVE AWAY THIS NEW ONE
	MOVE	T1,JFNOUT	;GET READY TO OPEN THE FILE
	MOVX	T2,7B5+OF%APP	;WANT TO APPEND TO THE FILE
	OPENF			;OPEN IT UP
	  ERJMP	LOSE		;CAN'T
	SETZM	REPCNT		;CLEAR THE REPEAT COUNT
	SETZM	JSJSYS		;AND PREVIOUS JSYS
	ANDCMI	F,FR.HDR	;REMEMBER WE NEED A NEW HEADER LINE
	POPJ	P,		;AND RETURN
	SUBTTL	SIMPLE COMMANDS



;HERE TO DO A RESET.  THIS IS ESSENTIALLY JUST THE SAME THING
;AS RESTARTING THE PROGRAM.



CMDRES:	PUSHJ	P,CONFRM	;CONFIRM THE COMMAND FIRST
	PUSHJ	P,CLRADR	;UNDO ANY MAPPINGS
	PUSHJ	P,CLSLOG	;CLOSE THE LOG FILE
	JRST	START		;THEN START THE PROGRAM OVER





;HERE TO EXIT FROM PROGRAM.  THE OUTPUT FILE IS CLOSED IF NECESSARY.


CMDXIT:	MOVEI	T2,[ASCIZ/FROM PROGRAM/]	;GET NOISE
	PUSHJ	P,NOISE		;EAT NOISE WORDS
	PUSHJ	P,CONFRM	;THEN CONFIRM THE COMMAND
	PUSHJ	P,CLRADR	;UNDO ANY MAPPING
	PUSHJ	P,CLSLOG	;CLOSE UP THE LOG FILE
	RESET			;RESET EVERYTHING
	HALTF			;QUIT FOR NOW
	JRST	START		;AND RESTART IF CONTINUED




;HERE TO GET THE NUMBER OF DUPLICATIONS OF A JSYS WHICH OCCUR
;IN A ROW.  LISTING OF THE JSYS AFTER THIS MANY TIMES IN A ROW
;WILL BE SUPPRESSED (SUCH AS BOUTS, PBOUTS, ETC.).




CMDMAX:	MOVEI	T2,[ASCIZ/NUMBER OF REPETITIONS IS/]
	PUSHJ	P,NOISE		;PARSE THE NOISE
	MOVEI	T2,[FLDDB. (.CMNUM,,^D10,,<1000>)]
	PUSHJ	P,COMMND	;READ THE NUMBER
	MOVE	T4,T2		;SAVE IT
	PUSHJ	P,CONFRM	;CONFIRM THE LINE
	SKIPG	T4		;IS THE RESULT NEGATIVE?
	HRLOI	T4,377777	;YES, MAKE IT LARGE AND POSITIVE
	MOVEM	T4,REPMAX	;SAVE THE VALUE
	POPJ	P,		;AND RETURN
;HERE TO STOP LOGGING OF JSYSES.  AS LONG AS WE DO NOT LOG THE
;JSYSES, NO JSYS TRAPPING CAN OCCUR, SINCE THAT IS USELESS.
;THE "CLOSE" COMMAND.




CMDCLS:	MOVEI	T2,[ASCIZ/LOG FILE AND STOP TRAPPING JSYSES/]
	PUSHJ	P,NOISE		;PARSE NOISE
	PUSHJ	P,CONFRM	;CONFIRM THE COMMAND

CLSLOG:	SKIPE	T1,JFNOUT	;GET OUTPUT JFN
	CLOSF			;CLOSE THE FILE IF IT WAS OPEN
	  ERJMP	.+1		;SHOULDN'T FAIL
	SETZM	JFNOUT		;CLEAR OUTPUT JFN
	POPJ	P,		;AND RETURN




;HERE TO SET WHETHER OR NOT ALL FORKS WILL HAVE THE SAME ADDRESSING
;SPACE OR NOT.  NEEDED FOR US TO KNOW WHETHER OR NOT TO GIVE SYMBOLS
;FOR LOWER FORKS.



CMDFRK:	MOVEI	T2,[ASCIZ/HAVE/]	;GET NOISE
	PUSHJ	P,NOISE		;PARSE IT
	MOVEI	T2,[FLDDB. (.CMKEY,,FRKTAB,,<DIFFERENT>)]
	PUSHJ	P,COMMND	;READ THE KEYWORD
	MOVE	T4,(T2)		;GET THE OFFSET
	MOVEI	T2,[ASCIZ/CORE IMAGES/]	;GET MORE NOISE
	PUSHJ	P,NOISE		;PARSE IT
	PUSHJ	P,CONFRM	;THEN CONFIRM IT
	XCT	[IORI	F,FR.SAM	;DO PROPER THING
		 ANDCMI	F,FR.SAM](T4)	;DEPENDING ON KEYWORD
	POPJ	P,		;THEN RETURN


FRKTAB:	FRKLEN,,FRKLEN		;NUMBER OF KEYWORDS
	AA	DIFFERENT,1	;DIFFERENT CORE IMAGES
	AA	IDENTICAL,0	;SAME CORE IMAGES

	FRKLEN==.-FRKTAB-1	;NUMBER OF KEYWORDS
	SUBTTL	THE HELP COMMAND


CMDHLP:	PUSHJ	P,CONFRM	;CONFIRM THE LINE
	HRROI	T1,HLPTXT	;POINT TO HELP MESSAGE
	PSOUT			;TYPE IT
	POPJ	P,		;AND RETURN


HLPTXT:	TEXT	<
Commands are the following:

  ALLOW arg		Add the set of JSYSes specified to the set
			which is being trapped and logged.

  DISALLOW arg		Remove the set of JSYSes specified from the
			set which is being trapped and logged.

  CLOSE			Close the log file and stop trapping of JSYSes.

  EXIT			Close log file and exit from program.

  FORKS arg		Tell whether or not you expect the core image
			of all forks to be the same.  This command only
			affects the symbolic listing in the log file.

  GET program		Read the specified program into an inferior fork.
			The program is not started.

  INTERRUPT char	Set which control character to use to interrupt
			the program being run.  The default is ^P.

  LOG spec		Begin logging of the JSYSes to the specified
			file.  The default file is JSTRAP.LOG.

  MAXIMUM number	Set how many identical JSYSes in a row can be
			logged.  Any further identical JSYSes are
			ignored.  Default value is 1000.

  PROCEED		Return from a terminal interrupt.

  RESET			Close the log file and restart the program.

  START			Begin execution of the program being watched.

  SYMBOLS addr		Set what address to use for reading in symbols.
			The default address is .JBSYM (116).

  TELL jsys		Tell whether or not a particular JSYS is being
			trapped.  The argument ALL will list all JSYSes
			which are being trapped.

>				;HELP MESSAGE
	SUBTTL	COMMAND TO TELL ABOUT WHICH JSYSES WE ARE TRAPPING



;THIS IS THE "TELL" COMMAND, WHICH WILL TELL THE STATUS OF A JSYS.
;IF THE ARGUMENT IS "*", WE TELL ABOUT ALL JSYSES.



CMDTEL:	MOVEI	T2,[ASCIZ/ABOUT JSYS/]	;GET NOISE
	PUSHJ	P,NOISE		;PARSE IT
	PUSHJ	P,READJS	;INPUT JSYS NAME AND VALUE
	JUMPL	T1,TELWLD	;TELL ABOUT THEM ALL IF WILDCARD
	MOVE	T5,JSTAB(T1)	;GET POINTER TO JSYS NAME
	IDIVI	T1,^D36		;SPLIT UP
	MOVNI	T2,(T2)		;GET READY
	MOVSI	T3,400000	;GET A BIT READY
	LSH	T3,(T2)		;SHIFT IT
	AND	T3,BITS(T1)	;SEE IF THIS JSYS IS BEING TRAPPED
	HRROI	T1,[ASCIZ/
/]				;GET A CRLF
	PSOUT			;PRINT IT
	HRROI	T1,(T5)		;POINT TO JSYS NAME
	PSOUT			;OUTPUT IT
	HRROI	T1,[ASCIZ/ is /]	;MORE
	PSOUT			;PRINT IT
	HRROI	T1,[ASCIZ/not /]	;GET TEXT
	SKIPN	T3		;ARE WE TRAPPING THIS JSYS?
	PSOUT			;NO, SAY SO
	HRROI	T1,[ASCIZ/being trapped

/]				;GET FINAL STUFF
	PSOUT			;TYPE IT
	POPJ	P,		;AND RETURN
;HERE WHEN HE WANTS TO HAVE A LIST OF ALL THE JSYSES WE ARE
;TRAPPING FOR.



TELWLD:	MOVE	T4,[POINT 1,BITS]	;GET A BYTE POINTER
	MOVSI	T5,-1000	;AND AN AOBJN POINTER
	SETZ	C,		;AND A COUNTER

TELLOP:	ILDB	T1,T4		;GET NEXT BIT
	JUMPN	T1,TELNXT	;JUMP IF ARE TRAPPING IT
	HRROI	T1,[ASCIZ/
The following JSYSes are not being trapped:
/]				;GET TEXT READY
	SKIPN	C		;FIRST TIME?
	PSOUT			;YES, PRINT THE HEADER
	HRROI	T1,[ASCIZ/
/]				;GET A CRLF READY
	TRNN	C,7		;TIME FOR A NEW LINE?
	PSOUT			;YES, DO A CRLF FIRST
	MOVEI	T1,"	"	;GET A TAB
	TRNE	C,7		;AT FRONT OF A LINE?
	PBOUT			;NO, THEN TYPE THE TAB
	MOVE	T3,JSTAB(T5)	;GET POINTER TO NAME
	MOVE	T2,(T3)		;GET NAME
	CAMN	T2,[ASCII/JSYS /]	;IS THIS JSYS UNNAMED?
	MOVE	T2,1(T3)	;YES, GET SECOND PART OF NAME
	SETZ	T3,		;MAKE IT ASCIZ
	HRROI	T1,T2		;POINT TO IT
	PSOUT			;TYPE IT
	ADDI	C,1		;ADD TO COUNT OF JSYSES
TELNXT:	AOBJN	T5,TELLOP	;LOOP OVER ALL BITS
	HRROI	T1,[ASCIZ/
All JSYSes are being trapped/]	;GET TEXT READY
	SKIPN	C		;NO JSYSES AT ALL?
	PSOUT			;RIGHT, TELL SO
	HRROI	T1,[ASCIZ/

/]				;GET A FINAL CRLF
	PSOUT			;OUTPUT IT
	POPJ	P,		;AND RETURN
	SUBTTL	COMMANDS TO SET WHAT CLASS OF JSYSES TO TRAP



;HERE ARE THE "ALLOW" AND "DISALLOW" COMMANDS, TO SET OR CLEAR TRAPS
;FOR PARTICULAR CLASSES OF JSYSES.  THIS ACTION IS JUST DIDDLING
;THE BIT TABLE OF JSYSES.



CMDDIS:	TDZA	T4,T4		;SET AC ZERO AS A FLAG
CMDALW:	MOVSI	T4,-1		;SET AC NEGATIVE AS A FLAG
	MOVEI	T2,[ASCIZ/TRAPS FOR/]	;GET NOISE
	PUSHJ	P,NOISE		;PARSE IT
	MOVEI	T2,[FLDDB. (.CMKEY,,CLSTAB,,<ALL>)]	;GET SET
	PUSHJ	P,COMMND	;LOOK FOR KEYWORD
	CAIN	T2,SPCLCL	;IS IT THE SPECIAL KEYWORD?
	JRST	SETSPL		;YES, HANDLE SPECIALLY
	HRR	T4,(T2)		;NO, NORMAL CASE, SAVE TABLE ADDRESS
	MOVEI	T2,[ASCIZ/CLASS OF JSYSES/]	;MORE NOISE
	PUSHJ	P,NOISE		;PARSE IT
	PUSHJ	P,CONFRM	;COMFIRM THE COMMAND
CLSAOB:	MOVSI	T1,-BITSIZ	;GET AN AOBJN POINTER

CLSLOP:	MOVE	T2,(T4)		;GET WORD OF BITS
	SKIPL	T4		;CLEARING BITS?
	ANDCAM	T2,BITS(T1)	;YES, DO SO
	SKIPGE	T4		;SETTING BITS?
	IORM	T2,BITS(T1)	;YES, DO SO
	ADDI	T4,1		;MOVE TO NEXT WORD
	AOBJN	T1,CLSLOP	;LOOP OVER ALL WORDS
	POPJ	P,		;DONE, RETURN


;HERE WHEN THE KEYWORD WAS "JSYS".  WE LOOK FOR A PARTICULAR NAME,
;OR A PARTICULAR NUMBER.


SETSPL:	PUSHJ	P,READJS	;READ THE JSYS NAME
	JUMPL	T1,[	HRRI	T4,BT.ALL	;IF WILDCARD, GET TABLE
			JRST	CLSAOB	]	;AND SET THEM BITS
	IDIVI	T1,^D36		;DIVIDE BY BITS TO A WORD
	MOVNI	T2,(T2)		;GET SHIFT VALUE READY
	MOVSI	T3,400000	;AND BIT
	LSH	T3,(T2)		;POSITION IT
	SKIPL	T4		;CLEARING THE BIT?
	ANDCAM	T3,BITS(T1)	;YES, DO IT
	SKIPGE	T4		;SETTING THE BIT?
	IORM	T3,BITS(T1)	;YES, DO IT
	POPJ	P,		;THEN RETURN
;SUBROUTINE TO READ IN A JSYS NAME, OR THE OCTAL VALUE OF A JSYS.
;LEFT HALF OF AC T4 IS PRESERVED, THE NAME OF THE JSYS IS IN AC T5,
;AND THE VALUE OF THE JSYS IS IN AC T1.  IF "ALL" WAS TYPED, T1 IS NEGATIVE.




READJS:	MOVEI	T2,[FLDDB. (.CMNUM,,^D8,,<ALL>,<[FLDDB. (.CMFLD,,,<JSYS name>)]>)]
	SETZM	ATMBUF		;CLEAR THE ATOM BUFFER
	PUSHJ	P,COMMND	;PARSE A NUMBER OR A NAME
	TSC	T3,T3		;SEE WHICH ONE IT WAS
	HRRI	T4,(T3)		;AND SAVE IT
	SKIPN	T3		;WAS THIS A NUMBER?
	SKIPA	T5,T2		;YES, SAVE NUMBER
	MOVE	T5,ATMBUF	;NO, SAVE TEXT
	PUSHJ	P,CONFRM	;THEN CONFIRM THE COMMAND
	MOVE	T1,T5		;RESTORE ARGUMENT
	TRNN	T4,-1		;WAS THIS THE NUMBER?
	JRST	READJN		;YES, JUST GO CHECK THE RANGE
	MOVSI	T1,-1000	;GET READY FOR A SEARCH
	CAMN	T5,[ASCIZ/ALL/]	;IS THIS THE SPECIAL WORD?
	POPJ	P,		;YES, RETURN WITH T1 NEGATIVE

JSYSRC:	MOVE	T2,JSTAB(T1)	;GET POINTER TO JSYS NAME
	CAME	T5,(T2)		;MATCH?
	AOBJN	T1,JSYSRC	;NO, KEEP LOOKING
	JUMPGE	T1,BADJSY	;JUMP IF NOT FOUND
	MOVEI	T1,(T1)		;THROW AWAY LEFT HALF

READJN:	JUMPL	T1,BADJSY	;ERROR IF NEGATIVE
	CAIGE	T1,1000		;IS THE VALUE ILLEGAL?
	POPJ	P,		;YES, RETURN




BADJSY:	HRROI	T1,[ASCIZ/
? Illegal JSYS specified/]	;GET TEXT
	PSOUT			;OUTPUT IT
	JRST	LOSFIN		;AND FINISH
;THE TABLE OF CLASSES THAT CAN BE SET OR CLEARED.



CLSTAB:	CLSLEN,,CLSLEN			;NUMBER OF ENTRIES
	AA	ALL,BT.ALL		;ALL JSYSES
	AA	FILE,BT.FIL		;FILE ORIENTED JSYSES
	AA	FORK,BT.FRK		;FORK RELATED JSYSES
	AA	INFORMATION,BT.STS	;INFORMATION JSYSES
	AA	INPUT,BT.INP		;INPUT RELATED JSYSES
	AA	INTERRUPT,BT.INT	;INTERRUPT RELATED JSYSES
	AA	IPCF,BT.IPC		;IPCF JSYSES
SPCLCL:	AA	JSYS,0			;PARTICULAR JSYS
	AA	OUTPUT,BT.OUT		;OUTPUT RELATED JSYSES
	AA	SETTING,BT.SET		;JSYSES WHICH SET THINGS
	AA	TERMINAL,BT.PRI		;TERMINAL RELATED JSYSES

	CLSLEN==.-CLSTAB-1		;NUMBER OF KEYWORDS
	SUBTTL	COMMAND TO SET WHAT CHARACTER TO INTERRUPT ON




;HERE TO SET WHAT CHARACTER WILL BE USED TO INTERRUPT THE PROGRAM
;WHEN WE ARE RUNNING IT.



CMDINT:	HRROI	T2,[ASCIZ/CHARACTER IS CONTROL/]	;GET NOISE
	PUSHJ	P,NOISE		;PARSE IT
	MOVEI	T2,[FLDDB. (.CMFLD,,,<LETTER, A - Z>,<P>)]	;GET READY
	PUSHJ	P,COMMND	;READ IT
	MOVE	T4,ATMBUF	;SAVE FIRST WORD OF ATOM BUFFER
	PUSHJ	P,CONFRM	;CONFIRM THE COMMAND
	MOVE	T1,[POINT 7,T4]	;GET A BYTE POINTER READY
	ILDB	T2,T1		;GET THE CHARACTER
	CAIL	T2,"A"		;IS IT LEGAL ALPHABETIC CHAR?
	CAILE	T2,"Z"		;WELL?
	  JRST	BADCHR		;NO, COMPLAIN
	ILDB	T3,T1		;GET NEXT CHAR TOO
	JUMPN	T3,BADCHR	;IT MUST BE NULL
	MOVEI	T2,.TICCA-"A"(T2)	;CONVERT TO INTERRUPT CODE
	MOVEM	T2,INTCHR	;AND SAVE IT
	POPJ	P,		;THEN RETURN


BADCHR:	HRROI	T1,[ASCIZ/
? Character must be from A - Z/]	;GET TEXT
	PSOUT			;TYPE IT
	JRST	LOSFIN		;AND FINISH THE ERROR
	SUBTTL	COMMAND TO LOAD IN A PROGRAM TO BE WATCHED


;THE "GET" COMMAND.  CREATES AN INFERIOR FORK AND READS IN THE GIVEN
;PROGRAM INTO IT.  THE PROGRAM IS NOT YET STARTED.  IF THERE ARE ANY
;SYMBOLS, THEY ARE EXTRACTED INTO OUR OWN CORE SO THAT WE CAN EASILY
;USE THEM.




CMDGET:	MOVEI	T2,[ASCIZ/PROGRAM/]	;GET NOISE
	PUSHJ	P,NOISE		;PARSE IT
	SETZM	JFNBLK+.GJNAM	;CLEAR ANY DEFAULT FILE NAME
	HRROI	T2,[ASCIZ/EXE/]	;GET DEFAULT EXTENSION
	MOVEM	T2,JFNBLK+.GJEXT	;AND SAVE IT
	MOVX	T2,GJ%OLD	;GET FLAGS
	MOVEM	T2,JFNBLK	;SET THEM FOR GTJFN
	MOVEI	T2,[FLDDB. (.CMFIL)]	;GET READY
	PUSHJ	P,COMMND	;READ THE SPEC
	HRRZ	T4,T2		;SAVE IT
	PUSHJ	P,CONFRM	;CONFIRM THE COMMAND
	TRNE	F,FR.INT	;DURING AN INTERRUPT?
	  JRST	NOGET		;YES, LOSE
	PUSHJ	P,CLRADR	;REMOVE ANY MAPPING FROM BEFORE
	SKIPE	T1,HANDLE	;GET FORK HANDLE IF HAVE ONE
	KFORK			;RELEASE IT
	  ERJMP	.+1		;CAN'T, IGNORE
	SETZM	HANDLE		;AND CLEAR IT
	SKIPE	T1,JFN		;GET INPUT JFN
	RLJFN			;RELEASE IT
	  ERJMP	.+1		;IGNORE ERROR
	MOVEM	T4,JFN		;SAVE THE JFN
	MOVX	T1,CR%CAP	;GET READY
	CFORK			;CREATE AN INFERIOR FORK
	  ERJMP	LOSE		;FAILED
	MOVEM	T1,HANDLE	;OK, SAVE HANDLE AWAY
	MOVSI	T1,(T1)		;PUT JFN IN RIGHT PLACE
	IOR	T1,JFN		;AND ADD IN JFN
	GET			;READ IN THE PROGRAM
	  ERJMP	LOSE		;FAILED
	SETZM	JSJSYS		;CLEAR OLD JSYS
	SETZM	REPCNT		;AND THE COUNTER
	PJRST	GETSYM		;READ IN SYMBOL TABLE



NOGET:	MOVE	T1,T4		;GET JFN
	RLJFN			;RELEASE IT
	  ERJMP	.+1		;FORGET IT
	JRST	INTST		;AND COMPLAIN
	SUBTTL	ROUTINE TO CONTINUE FROM INTERRUPTIONS




;HERE ON THE "PROCEED" COMMAND.  THIS CODE SHOULD ONLY BE REACHED
;WHEN A TERMINAL INTERRUPT IS IN PROGRESS.  WE RESTORE EVERYTHING AND
;RETURN TO WHERE WE WERE INTERRUPTED FROM SUCH A LONG TIME AGO.




CMDPRO:	MOVEI	T2,[ASCIZ/FROM INTERRUPTION/]	;GET TEXT
	PUSHJ	P,NOISE		;PARSE NOISE
	PUSHJ	P,CONFRM	;THEN END OF LINE
	TRNN	F,FR.INT	;INTERRUPTED FROM RUNNING THE PROG?
	  JRST	NOPRO		;NO, CAN'T DO THIS THEN
	HRROI	T1,[ASCIZ/
/]				;GET A CRLF
	PSOUT			;TYPE IT TO LOOK NICE
	MOVEI	T1,TTCHN	;GET CHANNEL FOR TERMINAL
	HRL	T1,INTCHR	;AND CODE FOR INTERRUPT
	ATI			;SET INTERRUPT CHARACTER
	SKIPE	JFNOUT		;DON'T TURN ON TRAPPING IF NOT LOGGING
	PUSHJ	P,TRAPON	;ALLOW TRAPPING AGAIN
	MOVE	T1,HANDLE	;GET PROCESS HANDLE
	RFORK			;RESUME THE INFERIORS
	MOVEI	T1,.FHSLF	;GET READY
	EIR			;ENABLE THE INTERRUPTS AGAIN
	MOVE	P,[SAVET1,,T1]	;GET READY
	BLT	P,P		;RESTORE AC'S, INCLUDING STACK
	ANDCMI	F,FR.INT	;CLEAR INTERRUPT FLAG
	DEBRK			;RETURN FROM INTERRUPT




NOPRO:	HRROI	T1,[ASCIZ/
? No interrupt was in progress/]	;GET TEXT
	PSOUT			;TYPE IT
	JRST	LOSFIN		;AND LOSE
	SUBTTL	ROUTINE TO START INFERIOR


;HERE TO START THE PROGRAM RUNNING THAT WAS READ INTO AN
;INFERIOR FORK.  WE MAY OR MAY NOT BE LOGGING THE JSYSES AT THIS
;POINT.  TERMINAL INTERRUPTS ARE ALWAYS ENABLED, SO THAT WE CAN
;HANDLE A COMMAND WHEN THE USER WANTS TO.



CMDST:	MOVEI	T2,[ASCIZ/PROGRAM/]	;NOISE
	PUSHJ	P,NOISE		;PARSE IT
	PUSHJ	P,CONFRM	;THEN CONFIRM IT
	SKIPN	HANDLE		;SEE IF HAVE A PROGRAM READ IN
	  JRST	NOST		;IF NONE, CAN'T DO THIS
	TRNE	F,FR.INT	;GET HERE DURING AN INTERRUPT?
	  JRST	INTST		;YES, LOSE
	HRROI	T1,[ASCIZ/
% Log file is not opened, thus no JSYS trapping will occur

/]				;GET TEXT
	SKIPN	JFNOUT		;HAVE OUTPUT FILE OPEN?
	PSOUT			;NO, WARN HIM
	MOVEI	T1,TTCHN	;GET CHANNEL FOR TERMINAL INTERRUPT
	HRL	T1,INTCHR	;AND GET INTERRUPT CODE
	ATI			;ALLOW INTERRUPTS
	MOVEI	T1,.FHSLF	;GET SET
	EIR			;ENABLE INTERRUPTS IN CASE WERE INTERRUPTED
	SKIPE	JFNOUT		;DON'T TURN ON TRAPPING UNLESS LOGGING
	PUSHJ	P,TRAPON	;TURN ON JSYS TRAPPING
	MOVE	T1,HANDLE	;GET FORK TO START
	SETZ	T2,		;START AT NORMAL ADDRESS
	SFRKV			;START THE PROGRAM
	  ERJMP	LOSE		;FAILED
	RFORK			;START FORK RUNNING
	WFORK			;NOW WAIT FOR IT TO TERMINATE
	MOVE	T1,INTCHR	;GET INTERRUPT CODE
	DTI			;REMOVE THE INTERRUPT
	PJRST	CLSLOG		;AND CLOSE THE LOG FILE



INTST:	HRROI	T1,[ASCIZ/
? Program currently interrupted.  Type "RESET" first/]
	SKIPA
NOST:	HRROI	T1,[ASCIZ/
? No program has been read in/]	;GET TEXT
	PSOUT			;TYPE IT
	JRST	LOSFIN		;AND FINISH UP
	SUBTTL	ROUTINE TO HANDLE INTERRUPT FROM A JSYS


;HERE ON AN INTERRUPT DUE TO A JSYS AN INFERIOR FORK HAS DONE.  WE
;MUST LOG IT IN THE LOG FILE AND THEN PROCEED.


JSYINT:	MOVEM	T1,SAV2T1	;SAVE AN AC
	MOVE	T1,[T2,,SAV2T1+1]	;GET READY
	BLT	T1,SAV2T1-T1+P	;SAVE THE REST
	RTFRK			;READ WHICH FORK TRAPPED
	MOVEM	T1,JSFORK	;REMEMBER WHICH FORK DID THE JSYS
	CAMN	T2,JSJSYS	;IS THIS JSYS THE SAME AS LAST ONE?
	AOSA	T3,REPCNT	;YES, ADD TO COUNTER
	SETZB	T3,REPCNT	;NO, CLEAR COUNTER
	MOVEM	T2,JSJSYS	;SAVE THIS JSYS NOW
	CAMGE	T3,REPMAX	;EXCEEDED OUR MAXIMUM?
	SKIPN	JFNOUT		;OR IS THERE NO OUTPUT JFN?
	  JRST	JSYDON		;YES, FORGET THIS THEN
	RFSTS			;READ THE FORK STATUS
	MOVEM	T2,JSPC		;SAVE THE PC
	MOVE	T1,JSFORK	;GET FORK AGAIN
	MOVEI	T2,ACS		;POINT TO STORAGE AREA
	RFACS			;READ THE FORK'S AC'S TOO
	MOVE	T1,[POINT 7,OUTBUF]	;GET A BYTE POINTER
	MOVEM	T1,OUTPTR	;INITIALIZE OUTPUT POINTER
	HRROI	T1,[ASCIZ/
FORK   PC     LABEL      JSYS         AC 1            AC 2            AC 3            AC 4

/]				;GET TEXT READY
	TRON	F,FR.HDR	;FIRST TIME THROUGH?
	PUSHJ	P,STROUT	;YES, TYPE HEADER LINE
	SETZM	OUTCNT		;NOW START COUNTER AT FRONT OF A LINE
	MOVE	T1,JSFORK	;GET FORK WHICH DID JSYS
	MOVEI	T1,-.FHSLF(T1)	;KEEP ONLY SMALL NUMBER
	MOVEI	C," "		;GET A SPACE
	CAIG	T1,7		;IS FORK NUMBER ONLY ONE DIGIT?
	PUTCHR			;YES, TYPE A SPACE
	PUSHJ	P,OCTOUT	;OUTPUT NUMBER
	MOVEI	T1,5		;GET COLUMN TO JUSTIFY TO
	PUSHJ	P,JUSTFY	;SPACE OVER TO IT
	MOVE	T1,JSPC		;GET THE PC OF THE FORK
	MOVEI	T1,-1(T1)	;BACK UP TO THE REAL PC
	PUSHJ	P,ADRTYP	;OUTPUT OCTAL AND SYMBOLIC ADDRESS
	MOVEI	T1,^D25		;GET COLUMN TO GO GO
	PUSHJ	P,JUSTFY	;MOVE TO IT
	MOVE	T1,JSJSYS	;GET THE JSYS THAT WAS DONE
	MOVE	T1,JSTAB(T1)	;POINT TO THE ASCIZ STRING
	PUSHJ	P,STROUT	;OUTPUT THE JSYS NAME
	MOVE	T5,JSJSYS	;GET JSYS AGAIN
	HLLZ	T5,JSTAB(T5)	;GET NEGATIVE NUMBER OF AC'S TO PRINT
	JUMPE	T5,ACDON	;SKIP ON IF NO AC'S GET PRINTED
	IORI	T5,T1		;AND FIRST AC TO PRINT
;HERE TO LOOP TYPING AS MANY AC'S AS IS NECESSARY FOR THIS JSYS.




ACTYP:	MOVEI	T1,-1(T5)	;GET WHICH AC WE ARE PRINTING
	IMULI	T1,^D16		;MULTIPLY BY WIDTH OF A COLUMN
	ADDI	T1,^D33		;ADD IN WIDTH USED BEFORE THE AC'S
	PUSHJ	P,JUSTFY	;MOVE TO THAT PLACE
	HLRZ	T1,ACS(T5)	;GET LEFT HALF OF AN AC
	PUSHJ	P,OCTSP6	;RIGHT JUSTIFY IN A FIELD OF 6
	PUSHJ	P,OCTOUT	;THEN OUTPUT IT
	MOVEI	T1,[ASCIZ/,,/]	;GET SOME COMMAS
	PUSHJ	P,STROUT	;OUTPUT THEM
	HRRZ	T1,ACS(T5)	;GET RIGHT HALF OF THE AC
	PUSHJ	P,OCTOUT	;OUTPUT IT
	AOBJN	T5,ACTYP	;LOOP OVER ALL THE AC'S WE TYPE


ACDON:	MOVEI	T1,[ASCIZ/
/]				;GET A CRLF
	PUSHJ	P,STROUT	;OUTPUT IT
	SETZB	C,T3		;GET A NULL CHARACTER
	PUTCHR			;STORE IT
	MOVE	T1,JFNOUT	;GET OUTPUT JFN
	HRROI	T2,OUTBUF	;POINT TO THE BUFFER
	SOUT			;THEN OUTPUT THE WHOLE LINE

JSYDON:	MOVE	T1,JSFORK	;GET FORK WHICH WAS STOPPED
	UTFRK			;RESTART IT
	MOVE	P,[SAV2T1,,T1]	;GET READY
	BLT	P,P		;RESTORE ALL AC'S
	DEBRK			;AND RETURN
	SUBTTL	INTERRUPT ROUTINE FOR THE TERMINAL




;HERE ON A TERMINAL INTERRUPT.  WE REMEMBER THE STATUS OF WHAT WE ARE
;DOING, SAVE THE AC'S AND STACK, FREEZE THE FORKS, AND TURN OFF THE
;TERMINAL INTERRUPTS.  THEN WE GO BACK TO THE COMMAND SCANNER FOR
;MORE COMMANDS.  ON A "PROCEED" COMMAND, WE WILL RETURN WHERE WE
;LEFT OFF.




TTYINT:	IORI	F,FR.INT	;REMEMBER WE ARE INTERRUPTED
	MOVEM	T1,SAVET1	;SAVE AN AC
	MOVE	T1,[T2,,SAVET1+1]	;GET READY
	BLT	T1,SAVET1-T1+P	;SAVE REST OF THEM TOO
	MOVEI	T1,.FHSLF	;GET SET
	DIR			;DISABLE ANY FURTHER INTERRUPTS
	PUSHJ	P,TRAPOF	;TURN OFF TRAPPING
	MOVE	T1,INTCHR	;GET THE INTERRUPT CODE
	DTI			;CLEAR IT
	HRROI	T1,[ASCIZ/
% Interrupting

/]				;GET TEXT
	PSOUT			;PRINT IT
	JRST	NEWCMD		;THEN JUMP BACK TO COMMAND SCANNER
	SUBTTL	ROUTINES TO TURN ON AND OFF JSYS TRAPPING



;HERE ARE THE ACTUAL ROUTINES TO INSERT ORE REMOVE JSYS TRAPS.
;THE FORKS ARE FROZEN WHEN WE RETURN, SINCE THAT IS A NECESSARY
;REQUIREMENT FOR THE TFORK JSYS.  IF NO FORK EXISTS, WE JUST RETURN.




TRAPON:	SKIPN	T1,HANDLE	;GET HANDLE FOR INFERIORS
	  POPJ	P,		;NONE, THEN RETURN
	FFORK			;FREEZE THEM ALL
	MOVX	T1,<.TFSET,,.FHINF>	;GET CODE FOR SETTING TRAPS
	MOVX	T2,<JSCHN,,1000>	;AND CHANNEL AND NUMBER OF BITS
	MOVEI	T3,BITS		;GET ADDRESS OF THE BITS
	TFORK			;SAY WHICH JSYSES TO TRAP
	HRLI	T1,.TFSPS	;GET CODE TO SET CHANNEL
	TFORK			;SET WHICH CHANNEL TO INTERRUPT
	POPJ	P,		;THEN RETURN




TRAPOF:	SKIPN	T1,HANDLE	;GET HANDLE
	  POPJ	P,		;IF NONE, RETURN
	FFORK			;FREEZE THE FORKS
	MOVX	T1,<.TFRES,,.FHINF>	;GET CODE TO UNDO ALL TRAPPING
	TFORK			;DO IT
	POPJ	P,		;ALL DONE
	SUBTTL	SUBROUTINE TO READ IN SYMBOL TABLE



;THIS ROUTINE IS CALLED TO PMAP THE PAGES OF THE INFERIOR FORK
;WHERE THE SYMBOL POINTER RESIDES, SO THAT WE CAN LOOK AT IT.
;ON A RETURN, SYMPTR IS EITHER ZERO, OR IS A SYMBOL POINTER.



GETSYM:	PUSHJ	P,CLRADR	;FIRST REMOVE PREVIOUS MAPPING
	HRRO	T1,SYMADR	;GET ADDRESS OF SYMBOL POINTER
	PUSHJ	P,MAPADR	;MAP THE PAGE WHERE IT IS
	  JRST	NOSYM		;CAN'T GET IT, NO SYMBOLS
	SKIPL	T1,(T1)		;GET THE SYMBOL POINTER
	  JRST	NOSYM		;IF NONNEGATIVE DON'T HAVE ONE
	HLRZ	T2,T1		;GET COUNT OF SYMBOLS
	CAIGE	T2,-SYMLEN	;TOO MANY FOR US?
	HRLI	T2,-SYMLEN	;YES, REDUCE COUNT TO MAXIMUM
	PUSHJ	P,MAPADR	;MAP THE ADDRESSES OF THE SYMBOLS
	  JRST	NOSYM		;CAN'T, FLICK IT
	MOVEM	T1,SYMPTR	;THEN SAVE THE POINTER FOR USE
	SETOM	LASADR		;CLEAR THE SAVED ADDRESS
	POPJ	P,		;AND RETURN


NOSYM:	SETZM	SYMPTR		;CLEAR THE SYMBOL POINTER
	HRROI	T1,[ASCIZ/
% No symbols available

/]				;GET TEXT
	PSOUT			;OUTPUT IT
	POPJ	P,		;AND RETURN
	SUBTTL	ROUTINE TO MAP IN PAGES OF INFERIOR FORK



;THIS ROUTINE IS CALLED WITH AN IOWD WHICH POINTS TO A LOCATION
;IN THE INFERIOR FORK.  WE MAP THE REQUIRED PAGES INTO OUR OWN
;CORE, AND DIDDLE THE IOWD SO THAT IT POINTS TO OUR OWN CORE.
;WE ALSO CHECK FOR THE GOODNESS OF THE PAGES WHICH WE HAVE MAPPED.
;SKIP RETURN IF SUCCESSFUL.



MAPADR:	MOVEM	T1,IWDSAV	;SAVE THE IOWD
	HLRE	T3,T1		;GET THE COUNT WHICH IS NEGATIVE
	MOVM	T3,T3		;MAKE POSITIVE
	HRRZS	T2,T1		;GET ADDRESS TO START FROM
	ADDI	T2,-1(T3)	;COMPUTE LAST ADDRESS
	LSH	T1,-^D9		;CONVERT FIRST ADDR TO PAGE
	LSH	T2,-^D9		;AND LAST ADDRESS TOO
	SUBI	T2,(T1)		;COMPUTE DIFFERENCE
	ADDI	T2,1		;ADD 1 TO GET NUMBER OF PAGES
	MOVEM	T2,MAPCNT	;SAVE NUMBER OF PAGES TO MAP
	HRL	T1,HANDLE	;SET UP HANDLE OF INFERIOR
	MOVE	T2,PAGADR	;GET ADDRESS OF OUR PAGES
	LSH	T2,-^D9		;CONVERT TO PAGE NUMBER
	HRLI	T2,.FHSLF	;PUT IN OUR OWN HANDLE
	HRRZ	T3,MAPCNT	;GET THE COUNT OF PAGES
	TXO	T3,PM%CNT+PM%RD	;SET FOR READ ACCESS ONLY
	PMAP			;MAP THE PAGES NECESSARY
	  ERJMP	CPOPJ		;RETURN IF ERROR
	MOVE	T1,@PAGADR	;TOUCH FIRST PAGE TO SEE IF OK
	  ERJMP	CPOPJ		;FAILURE
	MOVE	T1,IWDSAV	;RESTORE THE IOWD
	ANDCMI	T1,777000	;CLEAR PAGE NUMBER
	IOR	T1,PAGADR	;AND INSERT OUR OWN
	AOS	(P)		;SET FOR SKIP
	POPJ	P,		;RETURN
	SUBTTL	ROUTINE TO REMOVE MAPPING OF PAGES




;HERE TO UNMAP ANY PAGES WHICH WE HAD EARLIER MAPPED.



CLRADR:	SKIPN	T3,MAPCNT	;ANY PAGES THERE?
	  POPJ	P,		;NO, THEN RETURN
	SETO	T1,		;SET AC TO -1
	MOVE	T2,PAGADR	;GET ADDRESS OF PAGES
	LSH	T2,-^D9		;MAKE PAGE NUMBER
	HRLI	T2,.FHSLF	;PUT OUR HANDLE IN
	TXO	T3,PM%CNT	;ADD THE REPEAT BIT
	PMAP			;REMOVE THE PAGES
	  ERJMP	LOSE		;SHOULDN'T FAIL
	SETZM	MAPCNT		;CLEAR COUNT NOW
	POPJ	P,		;RETURN
	SUBTTL	SUBROUTINE TO LOOK FOR A SYMBOL




;THIS ROUTINE WILL SEARCH THE SYMBOL TABLE FOR THE SYMBOL NEAREST
;THE GIVEN VALUE WHICH IS SUPPLIED IN AC T1.  NON-SKIP RETURN IF
;NO SYMBOL WAS GOOD ENOUGH TO USE.  SKIP RETURN IF A SYMBOL WAS
;FOUND, WITH THE RADIX-50 IN AC T1 AND THE OFFSET FROM THAT SYMBOL
;IN AC T2.  USES AC'S T1-T4.



SYMLOK:	SKIPLE	T1		;SEE IF VALUE IS NONPOSITIVE
	SKIPL	T2,SYMPTR	;OR SEE IF HAVE NO SYMBOLS
	  POPJ	P,		;YES, JUST RETURN
	CAMN	T1,LASADR	;LOOKED FOR THIS ADDRESS LAST TIME?
	  JRST	SYMKNW		;YES, GO BE FAST
	MOVEM	T1,LASADR	;NO, SAVE NEW ADDRESS
	SETZM	LASSYM		;AND CLEAR IT'S SYMBOL
	MOVEI	T3,[-1]-1	;POINT TO A FAKE SMALL SYMBOL

SYMLLP:	SKIPLE	0(T2)		;SEE IF SYMBOL IS SUPPRESSED
	SKIPG	T4,1(T2)	;OR IF VALUE IS NON-POSITIVE
	  JRST	SYMLNX		;YES, SKIP THIS ONE
	CAMLE	T4,1(T3)	;VALUE SMALLER THAN PREVIOUS BEST ONE?
	CAMLE	T4,T1		;OR LARGER THAN OUR TARGET?
	  JRST	SYMLNX		;YES, DON'T USE IT
	HRROI	T3,(T2)		;A BETTER SYMBOL, REMEMBER IT
	CAMN	T4,T1		;HAVE AN EXACT MATCH?
	  JRST	SYMXCT		;YES, SKIP OUT OF LOOP NOW

SYMLNX:	AOBJN	T2,.+1		;BUMP POINTER PAST TWO WORDS
	AOBJN	T2,SYMLLP	;AND KEEP LOOKING
	JUMPGE	T3,CPOPJ	;RETURN IF NO SYMBOL FOUND

SYMXCT:	MOVE	T2,T1		;COPY VALUE LOOKING FOR
	SUB	T2,1(T3)	;THEN GENERATE OFFSET FROM FOUND SYMBOL
	CAIL	T2,1000		;IS OFFSET SMALL ENOUGH TO USE?
	  POPJ	P,		;NO, RETURN
	MOVEM	T2,LASOFF	;YES, SAVE IT
	MOVE	T1,0(T3)	;GET THE SYMBOL WHICH WE FOUND
	MOVEM	T1,LASSYM	;SAVE IT TOO
	AOS	(P)		;THEN SKIP
	POPJ	P,		;RETURN

SYMKNW:	SKIPE	T1,LASSYM	;GET LAST SYMBOL IF HAD ONE
	AOS	(P)		;WE DID, THEN SET FOR SUCCESS
	MOVE	T2,LASOFF	;GET OFFSET USED ALSO
	POPJ	P,		;THEN RETURN
	SUBTTL	ROUTINE TO PRINT OUT SYMBOL VALUE




;THIS ROUTINE IS CALLED TO PRINT OUT THE VALUE OF A SYMBOL BOTH IN
;OCTAL AND IN SYMBOLIC.  AC T1 CONTAINS THE ADDRESS TO BE PRINTED.
;SYMBOLS ARE USUALLY ONLY TYPED FOR THE IMMEDIATE INFERIOR, SINCE
;IN GENERAL WE HAVE NO IDEA WHAT THE OTHER FORK'S CORE IMAGES ARE LIKE.



ADRTYP:	MOVE	T4,T1		;SAVE VALUE FOR LATER
	PUSHJ	P,OCTSIX	;OUTPUT THE ADDRESS
	MOVE	T1,JSFORK	;GET FORK WE TRAPPED FOR
	TRNN	F