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