Home | History | Annotate | Line # | Download | only in fpsp
      1  1.4      wiz *	$NetBSD: x_snan.sa,v 1.4 2001/09/16 16:34:32 wiz Exp $
      2  1.3      cgd 
      3  1.1  mycroft *	MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
      4  1.1  mycroft *	M68000 Hi-Performance Microprocessor Division
      5  1.1  mycroft *	M68040 Software Package 
      6  1.1  mycroft *
      7  1.1  mycroft *	M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
      8  1.1  mycroft *	All rights reserved.
      9  1.1  mycroft *
     10  1.1  mycroft *	THE SOFTWARE is provided on an "AS IS" basis and without warranty.
     11  1.1  mycroft *	To the maximum extent permitted by applicable law,
     12  1.1  mycroft *	MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
     13  1.1  mycroft *	INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
     14  1.1  mycroft *	PARTICULAR PURPOSE and any warranty against infringement with
     15  1.1  mycroft *	regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
     16  1.1  mycroft *	and any accompanying written materials. 
     17  1.1  mycroft *
     18  1.1  mycroft *	To the maximum extent permitted by applicable law,
     19  1.1  mycroft *	IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
     20  1.1  mycroft *	(INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
     21  1.1  mycroft *	PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
     22  1.1  mycroft *	OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
     23  1.1  mycroft *	SOFTWARE.  Motorola assumes no responsibility for the maintenance
     24  1.1  mycroft *	and support of the SOFTWARE.  
     25  1.1  mycroft *
     26  1.1  mycroft *	You are hereby granted a copyright license to use, modify, and
     27  1.1  mycroft *	distribute the SOFTWARE so long as this entire notice is retained
     28  1.1  mycroft *	without alteration in any modified and/or redistributed versions,
     29  1.1  mycroft *	and that such modified versions are clearly identified as such.
     30  1.1  mycroft *	No licenses are granted by implication, estoppel or otherwise
     31  1.1  mycroft *	under any patents or trademarks of Motorola, Inc.
     32  1.1  mycroft 
     33  1.1  mycroft *
     34  1.1  mycroft *	x_snan.sa 3.3 7/1/91
     35  1.1  mycroft *
     36  1.1  mycroft * fpsp_snan --- FPSP handler for signalling NAN exception
     37  1.1  mycroft *
     38  1.1  mycroft * SNAN for float -> integer conversions (integer conversion of
     39  1.1  mycroft * an SNAN) is a non-maskable run-time exception.
     40  1.1  mycroft *
     41  1.1  mycroft * For trap disabled the 040 does the following:
     42  1.1  mycroft * If the dest data format is s, d, or x, then the SNAN bit in the NAN
     43  1.1  mycroft * is set to one and the resulting non-signaling NAN (truncated if
     44  1.1  mycroft * necessary) is transferred to the dest.  If the dest format is b, w,
     45  1.1  mycroft * or l, then garbage is written to the dest (actually the upper 32 bits
     46  1.1  mycroft * of the mantissa are sent to the integer unit).
     47  1.1  mycroft *
     48  1.1  mycroft * For trap enabled the 040 does the following:
     49  1.1  mycroft * If the inst is move_out, then the results are the same as for trap 
     50  1.1  mycroft * disabled with the exception posted.  If the instruction is not move_
     51  1.1  mycroft * out, the dest. is not modified, and the exception is posted.
     52  1.1  mycroft *
     53  1.1  mycroft 
     54  1.1  mycroft X_SNAN	IDNT    2,1 Motorola 040 Floating Point Software Package
     55  1.1  mycroft 
     56  1.1  mycroft 	section	8
     57  1.1  mycroft 
     58  1.1  mycroft 	include	fpsp.h
     59  1.1  mycroft 
     60  1.1  mycroft 	xref	get_fline
     61  1.1  mycroft 	xref	mem_write
     62  1.1  mycroft 	xref	real_snan
     63  1.1  mycroft 	xref	real_inex
     64  1.1  mycroft 	xref	fpsp_done
     65  1.1  mycroft 	xref	reg_dest
     66  1.1  mycroft 
     67  1.1  mycroft 	xdef	fpsp_snan
     68  1.1  mycroft fpsp_snan:
     69  1.1  mycroft 	link		a6,#-LOCAL_SIZE
     70  1.1  mycroft 	fsave		-(a7)
     71  1.1  mycroft 	movem.l		d0-d1/a0-a1,USER_DA(a6)
     72  1.1  mycroft 	fmovem.x	fp0-fp3,USER_FP0(a6)
     73  1.1  mycroft 	fmovem.l	fpcr/fpsr/fpiar,USER_FPCR(a6)
     74  1.1  mycroft 
     75  1.1  mycroft *
     76  1.1  mycroft * Check if trap enabled
     77  1.1  mycroft *
     78  1.1  mycroft 	btst.b		#snan_bit,FPCR_ENABLE(a6)
     79  1.1  mycroft 	bne.b		ena		;If enabled, then branch
     80  1.1  mycroft 
     81  1.1  mycroft 	bsr.l		move_out	;else SNAN disabled
     82  1.1  mycroft *
     83  1.1  mycroft * It is possible to have an inex1 exception with the
     84  1.1  mycroft * snan.  If the inex enable bit is set in the FPCR, and either
     85  1.4      wiz * inex2 or inex1 occurred, we must clean up and branch to the
     86  1.1  mycroft * real inex handler.
     87  1.1  mycroft *
     88  1.1  mycroft ck_inex:
     89  1.1  mycroft 	move.b	FPCR_ENABLE(a6),d0
     90  1.1  mycroft 	and.b	FPSR_EXCEPT(a6),d0
     91  1.1  mycroft 	andi.b	#$3,d0
     92  1.1  mycroft 	beq.w	end_snan
     93  1.1  mycroft *
     94  1.1  mycroft * Inexact enabled and reported, and we must take an inexact exception.
     95  1.1  mycroft *
     96  1.1  mycroft take_inex:
     97  1.1  mycroft 	move.b		#INEX_VEC,EXC_VEC+1(a6)
     98  1.1  mycroft 	movem.l		USER_DA(a6),d0-d1/a0-a1
     99  1.1  mycroft 	fmovem.x	USER_FP0(a6),fp0-fp3
    100  1.1  mycroft 	fmovem.l	USER_FPCR(a6),fpcr/fpsr/fpiar
    101  1.1  mycroft 	frestore	(a7)+
    102  1.1  mycroft 	unlk		a6
    103  1.1  mycroft 	bra.l		real_inex
    104  1.1  mycroft *
    105  1.1  mycroft * SNAN is enabled.  Check if inst is move_out.
    106  1.1  mycroft * Make any corrections to the 040 output as necessary.
    107  1.1  mycroft *
    108  1.1  mycroft ena:
    109  1.1  mycroft 	btst.b		#5,CMDREG1B(a6) ;if set, inst is move out
    110  1.1  mycroft 	beq.w		not_out
    111  1.1  mycroft 
    112  1.1  mycroft 	bsr.l		move_out
    113  1.1  mycroft 
    114  1.1  mycroft report_snan:
    115  1.1  mycroft 	move.b		(a7),VER_TMP(a6)
    116  1.1  mycroft 	cmpi.b		#VER_40,(a7)	;test for orig unimp frame
    117  1.1  mycroft 	bne.b		ck_rev
    118  1.1  mycroft 	moveq.l		#13,d0		;need to zero 14 lwords
    119  1.1  mycroft 	bra.b		rep_con
    120  1.1  mycroft ck_rev:
    121  1.1  mycroft 	moveq.l		#11,d0		;need to zero 12 lwords
    122  1.1  mycroft rep_con:
    123  1.1  mycroft 	clr.l		(a7)
    124  1.1  mycroft loop1:
    125  1.1  mycroft 	clr.l		-(a7)		;clear and dec a7
    126  1.1  mycroft 	dbra.w		d0,loop1
    127  1.1  mycroft 	move.b		VER_TMP(a6),(a7) ;format a busy frame
    128  1.1  mycroft 	move.b		#BUSY_SIZE-4,1(a7)
    129  1.1  mycroft 	move.l		USER_FPSR(a6),FPSR_SHADOW(a6)
    130  1.1  mycroft 	or.l		#sx_mask,E_BYTE(a6)
    131  1.1  mycroft 	movem.l		USER_DA(a6),d0-d1/a0-a1
    132  1.1  mycroft 	fmovem.x	USER_FP0(a6),fp0-fp3
    133  1.1  mycroft 	fmovem.l	USER_FPCR(a6),fpcr/fpsr/fpiar
    134  1.1  mycroft 	frestore	(a7)+
    135  1.1  mycroft 	unlk		a6
    136  1.1  mycroft 	bra.l		real_snan
    137  1.1  mycroft *
    138  1.1  mycroft * Exit snan handler by expanding the unimp frame into a busy frame
    139  1.1  mycroft *
    140  1.1  mycroft end_snan:
    141  1.1  mycroft 	bclr.b		#E1,E_BYTE(a6)
    142  1.1  mycroft 
    143  1.1  mycroft 	move.b		(a7),VER_TMP(a6)
    144  1.1  mycroft 	cmpi.b		#VER_40,(a7)	;test for orig unimp frame
    145  1.1  mycroft 	bne.b		ck_rev2
    146  1.1  mycroft 	moveq.l		#13,d0		;need to zero 14 lwords
    147  1.1  mycroft 	bra.b		rep_con2
    148  1.1  mycroft ck_rev2:
    149  1.1  mycroft 	moveq.l		#11,d0		;need to zero 12 lwords
    150  1.1  mycroft rep_con2:
    151  1.1  mycroft 	clr.l		(a7)
    152  1.1  mycroft loop2:
    153  1.1  mycroft 	clr.l		-(a7)		;clear and dec a7
    154  1.1  mycroft 	dbra.w		d0,loop2
    155  1.1  mycroft 	move.b		VER_TMP(a6),(a7) ;format a busy frame
    156  1.1  mycroft 	move.b		#BUSY_SIZE-4,1(a7) ;write busy size
    157  1.1  mycroft 	move.l		USER_FPSR(a6),FPSR_SHADOW(a6)
    158  1.1  mycroft 	or.l		#sx_mask,E_BYTE(a6)
    159  1.1  mycroft 	movem.l		USER_DA(a6),d0-d1/a0-a1
    160  1.1  mycroft 	fmovem.x	USER_FP0(a6),fp0-fp3
    161  1.1  mycroft 	fmovem.l	USER_FPCR(a6),fpcr/fpsr/fpiar
    162  1.1  mycroft 	frestore	(a7)+
    163  1.1  mycroft 	unlk		a6
    164  1.1  mycroft 	bra.l		fpsp_done
    165  1.1  mycroft 
    166  1.1  mycroft *
    167  1.1  mycroft * Move_out 
    168  1.1  mycroft *
    169  1.1  mycroft move_out:
    170  1.1  mycroft 	move.l		EXC_EA(a6),a0	;get <ea> from exc frame
    171  1.1  mycroft 
    172  1.1  mycroft 	bfextu		CMDREG1B(a6){3:3},d0 ;move rx field to d0{2:0}
    173  1.2  mycroft 	tst.l		d0		;check for long
    174  1.1  mycroft 	beq.b		sto_long	;branch if move_out long
    175  1.1  mycroft 	
    176  1.1  mycroft 	cmpi.l		#4,d0		;check for word
    177  1.1  mycroft 	beq.b		sto_word	;branch if move_out word
    178  1.1  mycroft 	
    179  1.1  mycroft 	cmpi.l		#6,d0		;check for byte
    180  1.1  mycroft 	beq.b		sto_byte	;branch if move_out byte
    181  1.1  mycroft 	
    182  1.1  mycroft *
    183  1.1  mycroft * Not byte, word or long
    184  1.1  mycroft *
    185  1.1  mycroft 	rts
    186  1.1  mycroft *	
    187  1.1  mycroft * Get the 32 most significant bits of etemp mantissa
    188  1.1  mycroft *
    189  1.1  mycroft sto_long:
    190  1.1  mycroft 	move.l		ETEMP_HI(a6),d1
    191  1.1  mycroft 	move.l		#4,d0		;load byte count
    192  1.1  mycroft *
    193  1.1  mycroft * Set signalling nan bit
    194  1.1  mycroft *
    195  1.1  mycroft 	bset.l		#30,d1			
    196  1.1  mycroft *
    197  1.1  mycroft * Store to the users destination address
    198  1.1  mycroft *
    199  1.1  mycroft 	tst.l		a0		;check if <ea> is 0
    200  1.1  mycroft 	beq.b		wrt_dn		;destination is a data register
    201  1.1  mycroft 	
    202  1.1  mycroft 	move.l		d1,-(a7)	;move the snan onto the stack
    203  1.1  mycroft 	move.l		a0,a1		;load dest addr into a1
    204  1.1  mycroft 	move.l		a7,a0		;load src addr of snan into a0
    205  1.1  mycroft 	bsr.l		mem_write	;write snan to user memory
    206  1.1  mycroft 	move.l		(a7)+,d1	;clear off stack
    207  1.1  mycroft 	rts
    208  1.1  mycroft *
    209  1.1  mycroft * Get the 16 most significant bits of etemp mantissa
    210  1.1  mycroft *
    211  1.1  mycroft sto_word:
    212  1.1  mycroft 	move.l		ETEMP_HI(a6),d1
    213  1.1  mycroft 	move.l		#2,d0		;load byte count
    214  1.1  mycroft *
    215  1.1  mycroft * Set signalling nan bit
    216  1.1  mycroft *
    217  1.1  mycroft 	bset.l		#30,d1			
    218  1.1  mycroft *
    219  1.1  mycroft * Store to the users destination address
    220  1.1  mycroft *
    221  1.1  mycroft 	tst.l		a0		;check if <ea> is 0
    222  1.1  mycroft 	beq.b		wrt_dn		;destination is a data register
    223  1.1  mycroft 
    224  1.1  mycroft 	move.l		d1,-(a7)	;move the snan onto the stack
    225  1.1  mycroft 	move.l		a0,a1		;load dest addr into a1
    226  1.1  mycroft 	move.l		a7,a0		;point to low word
    227  1.1  mycroft 	bsr.l		mem_write	;write snan to user memory
    228  1.1  mycroft 	move.l		(a7)+,d1	;clear off stack
    229  1.1  mycroft 	rts
    230  1.1  mycroft *
    231  1.1  mycroft * Get the 8 most significant bits of etemp mantissa
    232  1.1  mycroft *
    233  1.1  mycroft sto_byte:
    234  1.1  mycroft 	move.l		ETEMP_HI(a6),d1
    235  1.1  mycroft 	move.l		#1,d0		;load byte count
    236  1.1  mycroft *
    237  1.1  mycroft * Set signalling nan bit
    238  1.1  mycroft *
    239  1.1  mycroft 	bset.l		#30,d1			
    240  1.1  mycroft *
    241  1.1  mycroft * Store to the users destination address
    242  1.1  mycroft *
    243  1.1  mycroft 	tst.l		a0		;check if <ea> is 0
    244  1.1  mycroft 	beq.b		wrt_dn		;destination is a data register
    245  1.1  mycroft 	move.l		d1,-(a7)	;move the snan onto the stack
    246  1.1  mycroft 	move.l		a0,a1		;load dest addr into a1
    247  1.1  mycroft 	move.l		a7,a0		;point to source byte
    248  1.1  mycroft 	bsr.l		mem_write	;write snan to user memory
    249  1.1  mycroft 	move.l		(a7)+,d1	;clear off stack
    250  1.1  mycroft 	rts
    251  1.1  mycroft 
    252  1.1  mycroft *
    253  1.1  mycroft *	wrt_dn --- write to a data register
    254  1.1  mycroft *
    255  1.1  mycroft *	We get here with D1 containing the data to write and D0 the
    256  1.1  mycroft *	number of bytes to write: 1=byte,2=word,4=long.
    257  1.1  mycroft *
    258  1.1  mycroft wrt_dn:
    259  1.1  mycroft 	move.l		d1,L_SCR1(a6)	;data
    260  1.1  mycroft 	move.l		d0,-(a7)	;size
    261  1.1  mycroft 	bsr.l		get_fline	;returns fline word in d0
    262  1.1  mycroft 	move.l		d0,d1
    263  1.1  mycroft 	andi.l		#$7,d1		;d1 now holds register number
    264  1.1  mycroft 	move.l		(sp)+,d0	;get original size
    265  1.1  mycroft 	cmpi.l		#4,d0
    266  1.1  mycroft 	beq.b		wrt_long
    267  1.1  mycroft 	cmpi.l		#2,d0
    268  1.1  mycroft 	bne.b		wrt_byte
    269  1.1  mycroft wrt_word:
    270  1.1  mycroft 	or.l		#$8,d1
    271  1.1  mycroft 	bra.l		reg_dest
    272  1.1  mycroft wrt_long:
    273  1.1  mycroft 	or.l		#$10,d1
    274  1.1  mycroft 	bra.l		reg_dest
    275  1.1  mycroft wrt_byte:
    276  1.1  mycroft 	bra.l		reg_dest
    277  1.1  mycroft *
    278  1.1  mycroft * Check if it is a src nan or dst nan
    279  1.1  mycroft *
    280  1.1  mycroft not_out:
    281  1.1  mycroft 	move.l		DTAG(a6),d0	
    282  1.1  mycroft 	bfextu		d0{0:3},d0	;isolate dtag in lsbs
    283  1.1  mycroft 
    284  1.1  mycroft 	cmpi.b		#3,d0		;check for nan in destination
    285  1.1  mycroft 	bne.b		issrc		;destination nan has priority
    286  1.1  mycroft dst_nan:
    287  1.1  mycroft 	btst.b		#6,FPTEMP_HI(a6) ;check if dest nan is an snan
    288  1.1  mycroft 	bne.b		issrc		;no, so check source for snan
    289  1.1  mycroft 	move.w		FPTEMP_EX(a6),d0
    290  1.1  mycroft 	bra.b		cont
    291  1.1  mycroft issrc:
    292  1.1  mycroft 	move.w		ETEMP_EX(a6),d0
    293  1.1  mycroft cont:
    294  1.1  mycroft 	btst.l		#15,d0		;test for sign of snan
    295  1.1  mycroft 	beq.b		clr_neg
    296  1.1  mycroft 	bset.b		#neg_bit,FPSR_CC(a6)
    297  1.1  mycroft 	bra.w		report_snan
    298  1.1  mycroft clr_neg:
    299  1.1  mycroft 	bclr.b		#neg_bit,FPSR_CC(a6)
    300  1.1  mycroft 	bra.w		report_snan
    301  1.1  mycroft 
    302  1.1  mycroft 	end
    303