xref: /netbsd/sys/arch/m68k/fpsp/x_ovfl.sa (revision 456dff6c)
1*456dff6cSwiz*	$NetBSD: x_ovfl.sa,v 1.3 2001/09/16 16:34:32 wiz Exp $
257fb77a1Scgd
322ef5fa9Smycroft*	MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
422ef5fa9Smycroft*	M68000 Hi-Performance Microprocessor Division
522ef5fa9Smycroft*	M68040 Software Package
622ef5fa9Smycroft*
722ef5fa9Smycroft*	M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
822ef5fa9Smycroft*	All rights reserved.
922ef5fa9Smycroft*
1022ef5fa9Smycroft*	THE SOFTWARE is provided on an "AS IS" basis and without warranty.
1122ef5fa9Smycroft*	To the maximum extent permitted by applicable law,
1222ef5fa9Smycroft*	MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
1322ef5fa9Smycroft*	INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
1422ef5fa9Smycroft*	PARTICULAR PURPOSE and any warranty against infringement with
1522ef5fa9Smycroft*	regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
1622ef5fa9Smycroft*	and any accompanying written materials.
1722ef5fa9Smycroft*
1822ef5fa9Smycroft*	To the maximum extent permitted by applicable law,
1922ef5fa9Smycroft*	IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
2022ef5fa9Smycroft*	(INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
2122ef5fa9Smycroft*	PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
2222ef5fa9Smycroft*	OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
2322ef5fa9Smycroft*	SOFTWARE.  Motorola assumes no responsibility for the maintenance
2422ef5fa9Smycroft*	and support of the SOFTWARE.
2522ef5fa9Smycroft*
2622ef5fa9Smycroft*	You are hereby granted a copyright license to use, modify, and
2722ef5fa9Smycroft*	distribute the SOFTWARE so long as this entire notice is retained
2822ef5fa9Smycroft*	without alteration in any modified and/or redistributed versions,
2922ef5fa9Smycroft*	and that such modified versions are clearly identified as such.
3022ef5fa9Smycroft*	No licenses are granted by implication, estoppel or otherwise
3122ef5fa9Smycroft*	under any patents or trademarks of Motorola, Inc.
3222ef5fa9Smycroft
3322ef5fa9Smycroft*
3422ef5fa9Smycroft*	x_ovfl.sa 3.5 7/1/91
3522ef5fa9Smycroft*
3622ef5fa9Smycroft*	fpsp_ovfl --- FPSP handler for overflow exception
3722ef5fa9Smycroft*
3822ef5fa9Smycroft*	Overflow occurs when a floating-point intermediate result is
3922ef5fa9Smycroft*	too large to be represented in a floating-point data register,
4022ef5fa9Smycroft*	or when storing to memory, the contents of a floating-point
4122ef5fa9Smycroft*	data register are too large to be represented in the
4222ef5fa9Smycroft*	destination format.
4322ef5fa9Smycroft*
4422ef5fa9Smycroft* Trap disabled results
4522ef5fa9Smycroft*
4622ef5fa9Smycroft* If the instruction is move_out, then garbage is stored in the
4722ef5fa9Smycroft* destination.  If the instruction is not move_out, then the
4822ef5fa9Smycroft* destination is not affected.  For 68881 compatibility, the
4922ef5fa9Smycroft* following values should be stored at the destination, based
5022ef5fa9Smycroft* on the current rounding mode:
5122ef5fa9Smycroft*
5222ef5fa9Smycroft*  RN	Infinity with the sign of the intermediate result.
5322ef5fa9Smycroft*  RZ	Largest magnitude number, with the sign of the
5422ef5fa9Smycroft*	intermediate result.
5522ef5fa9Smycroft*  RM   For pos overflow, the largest pos number. For neg overflow,
5622ef5fa9Smycroft*	-infinity
5722ef5fa9Smycroft*  RP   For pos overflow, +infinity. For neg overflow, the largest
5822ef5fa9Smycroft*	neg number
5922ef5fa9Smycroft*
6022ef5fa9Smycroft* Trap enabled results
6122ef5fa9Smycroft* All trap disabled code applies.  In addition the exceptional
6222ef5fa9Smycroft* operand needs to be made available to the users exception handler
6322ef5fa9Smycroft* with a bias of $6000 subtracted from the exponent.
6422ef5fa9Smycroft*
6522ef5fa9Smycroft
6622ef5fa9SmycroftX_OVFL	IDNT    2,1 Motorola 040 Floating Point Software Package
6722ef5fa9Smycroft
6822ef5fa9Smycroft	section	8
6922ef5fa9Smycroft
7022ef5fa9Smycroft	include	fpsp.h
7122ef5fa9Smycroft
7222ef5fa9Smycroft	xref	ovf_r_x2
7322ef5fa9Smycroft	xref	ovf_r_x3
7422ef5fa9Smycroft	xref	store
7522ef5fa9Smycroft	xref	real_ovfl
7622ef5fa9Smycroft	xref	real_inex
7722ef5fa9Smycroft	xref	fpsp_done
7822ef5fa9Smycroft	xref	g_opcls
7922ef5fa9Smycroft	xref	b1238_fix
8022ef5fa9Smycroft
8122ef5fa9Smycroft	xdef	fpsp_ovfl
8222ef5fa9Smycroftfpsp_ovfl:
8322ef5fa9Smycroft	link		a6,#-LOCAL_SIZE
8422ef5fa9Smycroft	fsave		-(a7)
8522ef5fa9Smycroft	movem.l		d0-d1/a0-a1,USER_DA(a6)
8622ef5fa9Smycroft	fmovem.x	fp0-fp3,USER_FP0(a6)
8722ef5fa9Smycroft	fmovem.l	fpcr/fpsr/fpiar,USER_FPCR(a6)
8822ef5fa9Smycroft
8922ef5fa9Smycroft*
9022ef5fa9Smycroft*	The 040 doesn't set the AINEX bit in the FPSR, the following
9122ef5fa9Smycroft*	line temporarily rectifies this error.
9222ef5fa9Smycroft*
9322ef5fa9Smycroft	bset.b	#ainex_bit,FPSR_AEXCEPT(a6)
9422ef5fa9Smycroft*
9522ef5fa9Smycroft	bsr.l	ovf_adj		;denormalize, round & store interm op
9622ef5fa9Smycroft*
9722ef5fa9Smycroft*	if overflow traps not enabled check for inexact exception
9822ef5fa9Smycroft*
9922ef5fa9Smycroft	btst.b	#ovfl_bit,FPCR_ENABLE(a6)
10022ef5fa9Smycroft	beq.b	ck_inex
10122ef5fa9Smycroft*
10222ef5fa9Smycroft	btst.b		#E3,E_BYTE(a6)
10322ef5fa9Smycroft	beq.b		no_e3_1
10422ef5fa9Smycroft	bfextu		CMDREG3B(a6){6:3},d0	;get dest reg no
10522ef5fa9Smycroft	bclr.b		d0,FPR_DIRTY_BITS(a6)	;clr dest dirty bit
10622ef5fa9Smycroft	bsr.l		b1238_fix
10722ef5fa9Smycroft	move.l		USER_FPSR(a6),FPSR_SHADOW(a6)
10822ef5fa9Smycroft	or.l		#sx_mask,E_BYTE(a6)
10922ef5fa9Smycroftno_e3_1:
11022ef5fa9Smycroft	movem.l		USER_DA(a6),d0-d1/a0-a1
11122ef5fa9Smycroft	fmovem.x	USER_FP0(a6),fp0-fp3
11222ef5fa9Smycroft	fmovem.l	USER_FPCR(a6),fpcr/fpsr/fpiar
11322ef5fa9Smycroft	frestore	(a7)+
11422ef5fa9Smycroft	unlk		a6
11522ef5fa9Smycroft	bra.l		real_ovfl
11622ef5fa9Smycroft*
11722ef5fa9Smycroft* It is possible to have either inex2 or inex1 exceptions with the
11822ef5fa9Smycroft* ovfl.  If the inex enable bit is set in the FPCR, and either
119*456dff6cSwiz* inex2 or inex1 occurred, we must clean up and branch to the
12022ef5fa9Smycroft* real inex handler.
12122ef5fa9Smycroft*
12222ef5fa9Smycroftck_inex:
12322ef5fa9Smycroft*	move.b		FPCR_ENABLE(a6),d0
12422ef5fa9Smycroft*	and.b		FPSR_EXCEPT(a6),d0
12522ef5fa9Smycroft*	andi.b		#$3,d0
12622ef5fa9Smycroft	btst.b		#inex2_bit,FPCR_ENABLE(a6)
12722ef5fa9Smycroft	beq.b		ovfl_exit
12822ef5fa9Smycroft*
12922ef5fa9Smycroft* Inexact enabled and reported, and we must take an inexact exception.
13022ef5fa9Smycroft*
13122ef5fa9Smycrofttake_inex:
13222ef5fa9Smycroft	btst.b		#E3,E_BYTE(a6)
13322ef5fa9Smycroft	beq.b		no_e3_2
13422ef5fa9Smycroft	bfextu		CMDREG3B(a6){6:3},d0	;get dest reg no
13522ef5fa9Smycroft	bclr.b		d0,FPR_DIRTY_BITS(a6)	;clr dest dirty bit
13622ef5fa9Smycroft	bsr.l		b1238_fix
13722ef5fa9Smycroft	move.l		USER_FPSR(a6),FPSR_SHADOW(a6)
13822ef5fa9Smycroft	or.l		#sx_mask,E_BYTE(a6)
13922ef5fa9Smycroftno_e3_2:
14022ef5fa9Smycroft	move.b		#INEX_VEC,EXC_VEC+1(a6)
14122ef5fa9Smycroft	movem.l		USER_DA(a6),d0-d1/a0-a1
14222ef5fa9Smycroft	fmovem.x	USER_FP0(a6),fp0-fp3
14322ef5fa9Smycroft	fmovem.l	USER_FPCR(a6),fpcr/fpsr/fpiar
14422ef5fa9Smycroft	frestore	(a7)+
14522ef5fa9Smycroft	unlk		a6
14622ef5fa9Smycroft	bra.l		real_inex
14722ef5fa9Smycroft
14822ef5fa9Smycroftovfl_exit:
14922ef5fa9Smycroft	bclr.b	#E3,E_BYTE(a6)	;test and clear E3 bit
15022ef5fa9Smycroft	beq.b	e1_set
15122ef5fa9Smycroft*
15222ef5fa9Smycroft* Clear dirty bit on dest resister in the frame before branching
15322ef5fa9Smycroft* to b1238_fix.
15422ef5fa9Smycroft*
15522ef5fa9Smycroft	bfextu		CMDREG3B(a6){6:3},d0	;get dest reg no
15622ef5fa9Smycroft	bclr.b		d0,FPR_DIRTY_BITS(a6)	;clr dest dirty bit
15722ef5fa9Smycroft	bsr.l		b1238_fix		;test for bug1238 case
15822ef5fa9Smycroft
15922ef5fa9Smycroft	move.l		USER_FPSR(a6),FPSR_SHADOW(a6)
16022ef5fa9Smycroft	or.l		#sx_mask,E_BYTE(a6)
16122ef5fa9Smycroft	movem.l		USER_DA(a6),d0-d1/a0-a1
16222ef5fa9Smycroft	fmovem.x	USER_FP0(a6),fp0-fp3
16322ef5fa9Smycroft	fmovem.l	USER_FPCR(a6),fpcr/fpsr/fpiar
16422ef5fa9Smycroft	frestore	(a7)+
16522ef5fa9Smycroft	unlk		a6
16622ef5fa9Smycroft	bra.l		fpsp_done
16722ef5fa9Smycrofte1_set:
16822ef5fa9Smycroft	movem.l		USER_DA(a6),d0-d1/a0-a1
16922ef5fa9Smycroft	fmovem.x	USER_FP0(a6),fp0-fp3
17022ef5fa9Smycroft	fmovem.l	USER_FPCR(a6),fpcr/fpsr/fpiar
17122ef5fa9Smycroft	unlk		a6
17222ef5fa9Smycroft	bra.l		fpsp_done
17322ef5fa9Smycroft
17422ef5fa9Smycroft*
17522ef5fa9Smycroft*	ovf_adj
17622ef5fa9Smycroft*
17722ef5fa9Smycroftovf_adj:
17822ef5fa9Smycroft*
17922ef5fa9Smycroft* Have a0 point to the correct operand.
18022ef5fa9Smycroft*
18122ef5fa9Smycroft	btst.b	#E3,E_BYTE(a6)	;test E3 bit
18222ef5fa9Smycroft	beq.b	ovf_e1
18322ef5fa9Smycroft
18422ef5fa9Smycroft	lea	WBTEMP(a6),a0
18522ef5fa9Smycroft	bra.b	ovf_com
18622ef5fa9Smycroftovf_e1:
18722ef5fa9Smycroft	lea	ETEMP(a6),a0
18822ef5fa9Smycroft
18922ef5fa9Smycroftovf_com:
19022ef5fa9Smycroft	bclr.b	#sign_bit,LOCAL_EX(a0)
19122ef5fa9Smycroft	sne	LOCAL_SGN(a0)
19222ef5fa9Smycroft
19322ef5fa9Smycroft	bsr.l	g_opcls		;returns opclass in d0
19422ef5fa9Smycroft	cmpi.w	#3,d0		;check for opclass3
19522ef5fa9Smycroft	bne.b	not_opc011
19622ef5fa9Smycroft
19722ef5fa9Smycroft*
19822ef5fa9Smycroft* FPSR_CC is saved and restored because ovf_r_x3 affects it. The
19922ef5fa9Smycroft* CCs are defined to be 'not affected' for the opclass3 instruction.
20022ef5fa9Smycroft*
20122ef5fa9Smycroft	move.b	FPSR_CC(a6),L_SCR1(a6)
20222ef5fa9Smycroft 	bsr.l	ovf_r_x3	;returns a0 pointing to result
20322ef5fa9Smycroft	move.b	L_SCR1(a6),FPSR_CC(a6)
20422ef5fa9Smycroft	bra.l	store		;stores to memory or register
20522ef5fa9Smycroft
20622ef5fa9Smycroftnot_opc011:
20722ef5fa9Smycroft	bsr.l	ovf_r_x2	;returns a0 pointing to result
20822ef5fa9Smycroft	bra.l	store		;stores to memory or register
20922ef5fa9Smycroft
21022ef5fa9Smycroft	end
211