	.TITLE .FPP ROUTINES NEEDED FOR F4 COMPILER FPP INTERFACE AND ERROR HANDLING
/ 
/ 
/                   FIRST PRINTING, FEBRUARY 1974
/ 
/ THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO 
/ CHANGE WITHOUT NOTICE AND SHOULD NOT BE CONSTRUED
/ AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPON-
/ SIBILITY FOR ANY ERRORS THAT MAY APPEAR IN THIS
/ DOCUMENT.
/ 
/ THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FUR-
/ NISHED TO THE PURCHASER UNDER A LICENSE FOR USE ON
/ A SINGLE COMPUTER SYSTEM AND CAN BE COPIED (WITH
/ INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR 
/ USE IN SUCH SYSTEM, EXCEPT AS MAY OTHERWISE BE PRO-
/ VIDED IN WRITING BY DIGITAL.
/ 
/ DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/ FOR THE USE OR RELIABILITY OF ITS SOFTWARE ON EQUIP-
/ MENT THAT IS NOT SUPPLIED BY DIGITAL.
/ 
/ COPYRIGHT (C) 1974, BY DIGITAL EQUIPMENT CORPORATION
/ 
/ 
        .EJECT
	.GLOBL .AX,.AW,.ZA,.ZB,.ZC,.ZD,.ZE
	.GLOBL .FPP
/COPYRIGHT 1972,DIGITAL EQUIP CORP.,MAYNARD,MASS. 01754
/EDIT #018 1-14-72
/DEFINE RSX-----YEILDS RSX VERSION
	.IFDEF RSX
EV=ZPC
	.ENDC
	.GLOBL .ER,.DZERO,.OVUDF
	.GLOBL .SPC		/SET IN OTSER TO CONTROL PC OUTPUT
IST=713600		/INTEGER STR
URFXA=714670		/FIX FPP AC UNROUNDED
ILF=714010		/INTEGER LOAD AND FIX
/CALLING SEQUENCE
/JMS* .AX	FPP NUMBER IN FPP AC
/NXT. INSTR.	SUBR. RETURN WITH INTEGER IN AC
/JMS* .AW	INTEGER IN AC
/NEXT INSTR.	SUBR. RETR. WITH FP NO. IN FPP AC
/JMS* .ZA	LOADS HIGH ORD. FPP MANTISSA INTO AC
/NEXT INSTR.		SUBR. RETURN(RESULT IN AC)
/JMS* .ZB	SET ERROR JEA REG. FOR FPP
/NXT. INSTR.	SUBR. RETURN
	/JMS* .ZC  INTEGER TO EXT. INTEGER CONV.
	/NEXT INSTR.
	/JMS* .ZD EXT. INTEGER TO INTEGER CONV.
	/NEXT INSTR.
LJE=715400	/LOAD JEA REGISTER
UNDST=713770	/UNNORM. DOUBLE STORE
FZR=711200	/ZERO FPP AC
BPA=716604	/BR ON POS FPP AC
BZA=716601	/BR ON ZERO FPP AC
ILD=713000	/INTEGER LOAD
ELD=713100	/EXTENDED INTEGER LOAD
UNDLD=713170	/UNNORM. DOUBLE LOAD.
/
/.AX - FIX FPP AC AND LEAVE RESULT IN AC - SINGLE INTEGER
/.AW - FLOAT SINGLE INTEGER IN AC TO FPP AC
.FPP=.
.AX	0
	DZM AXF		/SET SINGLE FIX FLAG!!!!!
	URFXA	/FIX
AX1	0	/FOR STORAGE
	IST	/STORE INTEGER
	AX1	/INTO AX1
	LAC AX1	/LOAD AC
	JMP* .AX	/EXIT
.AW	0
	DAC AX1	/STORE FOR FLOAT
	ILF		/INTERGER LOAD AND FLOAT
	AX1		/INTO AX1
	JMP* .AW
AW1	0		/STORAGE FOR INTEGER
.ZA	0		/GET HIGH ORDER FPP MANT. INTO AC
	UNDST		/STORE FPP IN ZA0
	ZA0
	LAC ZA1	/GET HO MANT. INTO AC
	JMP* .ZA	/EXIT
ZA0	0		/STORAGE FOR FPP AC(H.O. INTEGER)
ZA1	0		/HO MANT.(L.O. INTEGER)
ZA2	0		/LO MANT.
AXF	1	/0=SINGLE FIX,NON ZERO=EXTENDED FIX (FOR TRAP COND.)
.ZB	0		/SET UP JEA ERROR EXIT
	.IFUND RSX
	LJE		/LOAD JEA REGISTER
	ZB0
	.ENDC
	.IFDEF RSX
	CAL	LJEA	/SET JEA EXIT ADDRESS.
	LAC	ZA0	/TEMP. USED FOR EV.  CHECK
	SMA		/FOR FPP CONFIG.  IF NEG.,NO
	JMP*	.ZB	/FPP CONFIG.  UNRECC. .OTS 52.
	JMS*	.ER	/IF POS.,OK.  JUST EXIT.
	52
/CAL PARAM. BLK. TO SET UP JEA REGISTER FOR FPP.
LJEA	17		/FUNCTION CODE.
	ZA0		/EV. ADDRESS.
	ZB1		/JEA EXIT ADDRESS.
/
/
	.ENDC
	JMP* .ZB	/EXIT
ZB0	ZB1		/ADDRESS TO BE LOAD INTO JEA
/CONVERTS INTEGER IN CPU AC TO EXT. INTEGER IN FPP AC
.ZC	0	/SHOULD BE FASTER THAN LRSS-22
	DAC ZA1	/STORE LO INTEGER
	SPA!CLA	/IF NEG,STORE HO 777777
	CLC	/777777 TO AC
	DAC ZA0	/IF POS.,STORE HO 000000
	ELD	/LOAD FPP AC
	ZA0
	JMP* .ZC	/EXIT
/
/CONVERTS EXTENDED INTEGER IN FPP AC TO INTEGER IN CPU AC
.ZD	0	/OVERFLOW CAUGHT BY FPP TRAP
	IST	/SINGLE INTGGER STORE--IF OVERFLOW,H.O DIGITS
	ZA0	/ARE LOST TO BE SOFTWARE COMPAT.
	LAC ZA0	/INTEGER TO CPU AC
	JMP* .ZD	/EXIT
/SUBROUTINE TO RETURN +,-,OR 0 IN AC DEPENDING ON
/ SIGN OF D.I.
.ZE	0
	CLA
	BZA
	LOGOUT
	IAC
	BPA
	LOGOUT
	LAC	(-1
LOGOUT	JMP*	.ZE
	.EJECT
/VIA THE FPP JEA ADDR THRO. A JMS* CONTROL IS TRANSFERRED AS FOLLOWS:
/ZB1-----OVERFLOW
/ZB4-----UNDERFLOW
/ZB5-----DIVISION BY ZERO OR AND UNNORM. OPERAND
/ZMPE----MEM. PROT. OR NON-EXIST. MEM. VIOL.
/SUBR. ENTRIES CONTAIN A PC THAT POINTS TO THE FPP INSTR. + 3
/ERRORS REPORTED AS FOLLOWS:
/OTS	30-	SINGLE INTEGER OVERFLOW
/OTS	31-	EXTENDED (DOUBLE) INTEGER OVERFLOW
/OTS	32-	SINGLE FLT. OVERFLOW
/OTS	33-	DOUBLE FLT. OVERFLOW
/OTS	34-	SINGLE FLT. UNDERFLOW
/OTS	35-	DOUBLE FLT UNDERFLOW
/OTS	36-	FLT. DIVIDE CHK
/OTS	37-	INTEGER DIVIDE CHK
/ALL ABOVE OTS ERRORS ARE RECOVERABLE AND ARE FOLLOWED
/WITH PRINT OUT OF PC OF FPP INSTR. (AUSTNG ERROR
/EXAMP;E:
/	.OTS	30-37
/	PC=0XXXXX		WHERE XXXXX IS 15-BIT PC
/FOR MEMORY PROTECT+NON-EXISTENT MEM. VIOLATIONS
/THE FOLLOWING HOLDS:
/	.OTS 50
/	PC=YXXXXX
/	WHERE	XXXXX=15-BIT PC
/		    Y=STATE OF LK, OPER MODE, AND ADDR MODE
/Y:BIT0=LK, BIT 1=USER MODE, BIT 2=PAGE OR BANK MODE
	.EJECT
/VIA THE HARDWARE JEA REGISTER CONTROL IS PASSED TO
/ZB1+1,ZB4+1,ZB5+1 OR ZMPE+1  (SEE ABOVE DISCUSSION)
ZB1	0
	JMP ZOVR
ZB4	0
	JMP ZUND
ZB5	0
	JMP ZDV0
ZMPE	0		/HERE ON MEM. PROT. VIOL. OR NON-EXIST. MEM
	LAC	ZMPE	/GET CORRECT 15-BIT PC FOR .MED
	TAD (-3)	/DECREMENT BY 3
	DAC ZB6	/STORE FOR PC PRINT OUT
	ISZ MVFLG	/SET MEM. VIOL. FLAG FOR ZEXT1
/.OTS 50  AND PC OUT IN ZEXT1,FOLLOWED BY .EXIT TO MONITOR
	JMS* .ER
	400050
	JMP ZEXT1
ZDV0	DAC ZB2		/SAVE AC
	RAL	/SAVE LINK
	DAC ZB3
	LAC ZB5
	TAD (-3)
	DAC ZB6		/PTR TO FLT. POINT INSTR.
	LAC* ZB6
	AND (40)	/TEST FOR INTEGER DIVIDE CHECK
	SZA
	JMP ZB9		/FLOATING DIVIDE CHECK
	JMS* .ER	/INTEGER DIVIDE CHECK
	400037		/OTS 37
	JMP ZB12
ZB9	DZM .DZERO	/SET FLAG ON FLT. DIVIDE CHK
	LAC* ZB6	/CHECK FOR SINGLE OR DOUBLE AND
	AND (100)	/SIGN OF RESULT. LOAD FPP AC WITH
	JMS ZB15	/PLUS OR MINUS THE LARGEST REPR.
	NOP		/VALUE FOR THE DATA MODE
	JMS* .ER	/FLOATING DIVIDE CHECK
	400036		/OTS 36
ZB12	LAC ZB5		/UP DATE ZB1 TO PROPER RETURN
	JMP ZEXT	/EXIT
	.EJECT
ZOVR	DAC ZB2	/SAVR LK,AC
	RAL
	DAC ZB3
	LAC ZB1
	TAD (-3)
	DAC ZB6		/PTR TO INSTR.
/FIRST TEST FOR SPEC. CASE OF FIX INSTR.  FPP INSTR. TYPE IN
/BITS 6-9 FOR FPP INSTR.  44 FOR FIX INSTRS.
	LAC* ZB6	/GET FPP INSTR.
	AND (7400)	/AND INSTR. TYPE BITS
	SAD (4400)	/A FIX INSTR. ?
	JMP ZB24	/YES
	LAC* ZB6	/TEST FOR INTEGER OVERFLOW
	AND (140)	
	SNA		/AC=0 INDICATES SINGLE INTEGER OVERFLOW
	JMP ZB19
	SAD (100
	JMP ZB20	/AC=100 INDICATES DOUBLE INTEGER OVERFLOW
	AND (100)	/MUST BE FLOATING - GET MODE BIT
	JMS ZB15	/ONLY INTO AC - GO LOAD FPP AC WITH
	ISZ ZBSW	/PLUS OR MINUS THE LARGEST REPR.
/VALUE PER DATA MODE--RETURN FROM ZB15 TO ISZ IF SNGL. FLT.
	LAC (777)	/SET .OVUDF FLAG FOR FLT. OVERFLOW
	DAC .OVUDF
	LAC* ZB6	/CHK. FOR FLT. STORE
	AND (777600)	
	SAD (713600)	/A FLT. STORE INSTR.?
	JMP ZB21	/YES.
ZB23	LAC ZBSW
	SZA
	JMP ZB22	/SINGLE FLT. OVERFLOW
	JMS* .ER	/DOUBLE FLT. OVERFLOW
	400033		/OTS 33
	JMP ZB13	/EXIT
ZB19	JMS* .ER	/SINGLE INTEGER OVF.
	400030		/RECOV. OTS 30
	JMP ZB13	/XIT
ZB20	JMS* .ER	/DOUBLE(EXTENDED) INTEGER OVF.
	400031		/RECOV. OTS 31
	JMP ZB13	/EXIT
ZB22	DZM ZBSW	/REINIT SWITCH
	JMS* .ER	/SINGLE FLT OVERFLOW
	400032		/OTS 32
	JMP ZB13	/EXIT
ZB21	LAC ZB6		/A STORE INSTR. - REDO IT BY
	JMS ZB10	/STORING PATCHED FPP AC
	JMP ZB23	/GO OUTPUT ERR MESSAGE + EXIT
ZB13	LAC ZB1
	JMP ZEXT
	.EJECT
ZB24	LAC AXF	/WAS FIX IN .AX ROUTINE(SINGLE ?)
	SZA	/ASSUMES IF NOT IN .AX, A EXT. INT. FIX
	LAC (100)	/NO,NOT IN .AX--BUILD ELD(=ILD+100)
	TAD (ILD)	/CONT.
	JMS ZB26	/AC PASSED TO ZB26--WILL SET FPPAC TO
/PLUS OR MINUS THE LARGEST INTEGER PER DATA MODE.
	LAC AXF		/DETERM. ERROR MESSG.
	SZA
	JMP ZB20	/EXT. INT. OVERFLOW .OTS 31
	ISZ	AXF	/CLEAR FLG
	JMP ZB19	/INT. OVERFLOW .OTS 30
	.EJECT
ZUND	DAC ZB2
	RAL
	DAC ZB3
	LAC (777774)	/SET .OVUDF TO NEG.
	DAC .OVUDF	/FOR UNDERFLOW INDICATJON
	FZR		/ZERO FPP AC FOR LATER
ZB6	0
	LAC ZB4
	TAD (-3)
	DAC ZB6		/PTR TO FPP INSTR.
	LAC* ZB6
	AND (777600)	/MASK INSTR. DESCRIPTOR
	SAD (713600)	/A SINGLE FLOATING STORE?
	JMP ZB7		/YES
	LAC* ZB6	/DOUBLE FLOATING UNDERFLOW AFTER
	AND (100)	/MAKING RESULT ZERO
	SNA		/IF BIT 11=0, SINGLE FLOATING
	JMP ZB8		/IF BIT 11=1, DOUBLE FLOATING
	JMS* .ER		/DOUBLE FLOATING UNDERFLOW
	400035		/OTS 35
	JMP ZB14	/EXIT
ZB7	LAC ZB6		/A STORE INSTR. - REDO IT BY
	JMS ZB10	/STORING PATCHED FPP AC
ZB8	JMS* .ER		/SINGLE FLOATING UNDERFLOW
	400034		/OTS 34
ZB14	LAC ZB4		/UPDATE ZB1 TO PROPER RETURN
ZEXT	TAD (-1)
	DAC ZB1
ZEXT1	LAC	ZB6	/GET 15-BIT PC OF FPP INST. CAUSING TRAP
	AND	(77777)/CLEAR LINK
	RCL	/CLEAR LINK AND GIVE LOOP A PUSH
ZLOOP	RAL; RTL	/GET FIRST DIGIT OF PC
	DAC	ZPC	/TEMP STORE
	AND	(7)
	TAD	(260)	/MAKE 8-BIT ASCII
	DAC*	ZTEXTP	/STORE LEFT MOST CHAR FIRST
	ISZ	ZTEXTP
	LAC	ZTEXTP
	SAD	(ZEND) /DONE?
	JMP	ZDONE	/YES
	LAC	ZPC	/NO.  RELOAD AC WITH ZPC + RECYCLE
	JMP	ZLOOP
ZDONE	LAC	(ZTEXT6)/REINIT ZTEXTP
	DAC	ZTEXTP
	LAC* .SPC	/IF .SPC SET TO 0,SUPPRESS PC MSG.
	SZA
	JMP ZW		/OUTPUT
	ISZ* .SPC	/REINIT TO 000001
	JMP ZBYPAS	/SUPPRESS
ZW=.
	.IFUND RSX
	.WRITE -3,3,ZTEXT,10 /IMAGE ALPHA WRITE TO TTY SLOT -3
	.WAIT -3
	.ENDC
	.IFDEF RSX
	UNDST		/SAVE FPP AC.
	TFPAC
	CAL ZWRT	/WRITE
	CAL ZWTFOR	/WAITFOR EV
	UNDLD		/RESTORE FPP AC.
	TFPAC
	.ENDC
/IF MVFLG SET,HERE ON MEMORY VIOL.  PC OUTPUT AND RETURN TO MONITOR
	LAC MVFLG
	SNA
	JMP ZBYPAS	/NOT A MEMORY VIOL.  CONT.
	DZM MVFLG	/NOT NECESSARY TO CLEAR FLAG IF FATAL
	.IFUND RSX
	.EXIT		/HARDWARE FLAGS CLEARED BY FPP--GO TO MONITOR
	.ENDC
	.IFDEF RSX
	CAL (10)	/EXIT
	.ENDC
ZBYPAS	LAC ZB3		/RESTORE LINK
	RAR
	LAC ZB2	/RESTORE AC
	JMP* ZB1
ZB2	0	/TEMP
ZB3	0	/TEMP
ZB11	0	/TEMP
ZBSW	0	/SNGL.-DBLE. SWITCH
MVFLG	0	/MEM. VIOL FLAG--NON-ZERO IF MEM. VIOL.
.DZERO	777777		/SOFTWARE DIV. CHK. FLAG FOR IDZERO
.OVUDF	0		/SOFTW. UNDF-OVRF FLAG FOR IFLOW
/SUBR TO EXECUTE STORE INSTR. IN ORDER TO PATCH
/RESULTS IN MEMORY ON ERROR CONDITION - FPP AC ALL SET
/CALLING SEQUENCE - LAC PTR	- ADDR OF FPP INSTR
/		  - JMS ZB10	
/		    NEXT INSTR	- SUBR. RETURN
ZB10	0
	DAC ZB11	/TEMP
	LAC* ZB11	/GET FPP INSTR.
	DAC ZB10A
	ISZ ZB11
	LAC* ZB11	/GET ADDR.
	DAC ZB10B
ZB10A	0		/FPP INSTR.
ZB10B	0		/ADDR
	JMP* ZB10
	.EJECT
/SUBR TO SET FPP TO PLUS OR MINUS LARGEST REPRESENT. SINGLE
/FLT. PT. VALUE . SUBR MUST BE ENTERED
/WITH MODE BIT OF FPP INSTR. IN AC (0 IF SINGLE, 1 IF
/DOUBLE). FLT. MODE ASSUMED.
/CAL SEQUENCE
/		JMS ZB15	- MODE BIT IN AC
/		NEXT INSTR	- SUBR RETURN - IF SINGLE
/		NEXT INSTR	- SUBR RETURN - IF DOUBLE
ZB15	0
	SZA
	ISZ ZB15
	LAC ZB16A
	AND (777774)	/CLEAR BITS 16, 17
	BPA		/CHECK SIGN OF RESULT
	ZB17
	XOR (2)		/SET TO MAKE FPP NEG ON LOAD
ZB17	DAC ZB16A
ZB16A	713150		/DOUBLE FLOAT LOAD
ZB16B	ZBPS		/ADDR OF PATCH VALUE
	JMP* ZB15	/EXIT
ZBPS	000377		/LARGEST REPR. SINGLE FLT. NUMBER
	377777		/CARRYING EXTRA BITS 9-17 OF LOW ORDER MANTISSA.
	777000		/COULD CAUSE OVERFLOW ON SINGLE FLT. STORE.
/SUBR. TO SET FPP AC TO PLUS OR MINUS LARGEST SINGLE OR EXTENDED
/INTEGER MAGNITUDE.  THE FPP LOAD INSTR. IS IN AC ON ENTRY.
/CALLING SEQUENCE	LAC (ILD) OR LAC (ELD)
/			JMS ZB26
/			NEXT INSTR.   --RETURN
/
ZB26	0
	DAC ZB26A	/STORE FPP INSTR. IN-LINE
	AND (777774)	/CLEAR BITS 16,17
	BPA		/CHECK SIGN OF FPP AC TO MICROCODE
	ZB26B		/FPP POS.
	XOR (2)	/FPP NEG.  SET BITS TO NEG FPP AC ON LOAD
ZB26B	DAC ZB26A
ZB26A	0		/ILD OR ELD +2 OR +0
	ZB26C		/ADDR. FO PATCH VALUE
	JMP* ZB26
ZB26C	377777		/IF ILD,ONLY THIS WORD LOADED
	777777		/IF ELD,THIS WORD LOADED ALSO
	.EJECT
ZTEXT	7003		/WP CNT=7, DATA MODE = 3.
	0		/CHK-SUM
	320		/P
	303		/C
	275		/=
ZTEXT6	0		/SIX CHARACTER PC - CHAR1
	0		/		    - CHAR2
	0		/		    - CHAR3
	0		/		    - CHAR4
	0		/		    - CHAR5
	0		/		    - CHAR6
ZEND	215		/CR
	212		/LF
	212		/LF
ZTEXTP	ZTEXT6		/TEXT PTR
/CAL PARAM. BLOCKS FOR RSX.
	.IFDEF RSX
ZWRT	2700	/WRITE
	EV
	4	/TTY OUTPUT LUN
	3	/IMAGE ASCII
	ZTEXT	/BUFFER
/
ZWTFOR	20	/WAITFOR
	EV	/EV ADDRESS
/
/TEMP. STORAGE FOR FPP AC.
TFPAC	0	/EXPONENT.
	0	/HO MANTISSA.
	0	/LO MANTISSA.
	.ENDC
ZPC	0		/TEMP FOR PC
	.END
