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