1 1.2 cgd * $NetBSD: kernel_ex.sa,v 1.2 1994/10/26 07:49:12 cgd Exp $ 2 1.2 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 * kernel_ex.sa 3.3 12/19/90 35 1.1 mycroft * 36 1.1 mycroft * This file contains routines to force exception status in the 37 1.1 mycroft * fpu for exceptional cases detected or reported within the 38 1.1 mycroft * transcendental functions. Typically, the t_xx routine will 39 1.1 mycroft * set the appropriate bits in the USER_FPSR word on the stack. 40 1.1 mycroft * The bits are tested in gen_except.sa to determine if an exceptional 41 1.1 mycroft * situation needs to be created on return from the FPSP. 42 1.1 mycroft * 43 1.1 mycroft 44 1.1 mycroft KERNEL_EX IDNT 2,1 Motorola 040 Floating Point Software Package 45 1.1 mycroft 46 1.1 mycroft section 8 47 1.1 mycroft 48 1.1 mycroft include fpsp.h 49 1.1 mycroft 50 1.1 mycroft mns_inf dc.l $ffff0000,$00000000,$00000000 51 1.1 mycroft pls_inf dc.l $7fff0000,$00000000,$00000000 52 1.1 mycroft nan dc.l $7fff0000,$ffffffff,$ffffffff 53 1.1 mycroft huge dc.l $7ffe0000,$ffffffff,$ffffffff 54 1.1 mycroft 55 1.1 mycroft xref ovf_r_k 56 1.1 mycroft xref unf_sub 57 1.1 mycroft xref nrm_set 58 1.1 mycroft 59 1.1 mycroft xdef t_dz 60 1.1 mycroft xdef t_dz2 61 1.1 mycroft xdef t_operr 62 1.1 mycroft xdef t_unfl 63 1.1 mycroft xdef t_ovfl 64 1.1 mycroft xdef t_ovfl2 65 1.1 mycroft xdef t_inx2 66 1.1 mycroft xdef t_frcinx 67 1.1 mycroft xdef t_extdnrm 68 1.1 mycroft xdef t_resdnrm 69 1.1 mycroft xdef dst_nan 70 1.1 mycroft xdef src_nan 71 1.1 mycroft * 72 1.1 mycroft * DZ exception 73 1.1 mycroft * 74 1.1 mycroft * 75 1.1 mycroft * if dz trap disabled 76 1.1 mycroft * store properly signed inf (use sign of etemp) into fp0 77 1.1 mycroft * set FPSR exception status dz bit, condition code 78 1.1 mycroft * inf bit, and accrued dz bit 79 1.1 mycroft * return 80 1.1 mycroft * frestore the frame into the machine (done by unimp_hd) 81 1.1 mycroft * 82 1.1 mycroft * else dz trap enabled 83 1.1 mycroft * set exception status bit & accrued bits in FPSR 84 1.1 mycroft * set flag to disable sto_res from corrupting fp register 85 1.1 mycroft * return 86 1.1 mycroft * frestore the frame into the machine (done by unimp_hd) 87 1.1 mycroft * 88 1.1 mycroft * t_dz2 is used by monadic functions such as flogn (from do_func). 89 1.1 mycroft * t_dz is used by monadic functions such as satanh (from the 90 1.1 mycroft * transcendental function). 91 1.1 mycroft * 92 1.1 mycroft t_dz2: 93 1.1 mycroft bset.b #neg_bit,FPSR_CC(a6) ;set neg bit in FPSR 94 1.1 mycroft fmove.l #0,FPSR ;clr status bits (Z set) 95 1.1 mycroft btst.b #dz_bit,FPCR_ENABLE(a6) ;test FPCR for dz exc enabled 96 1.1 mycroft bne.b dz_ena_end 97 1.1 mycroft bra.b m_inf ;flogx always returns -inf 98 1.1 mycroft t_dz: 99 1.1 mycroft fmove.l #0,FPSR ;clr status bits (Z set) 100 1.1 mycroft btst.b #dz_bit,FPCR_ENABLE(a6) ;test FPCR for dz exc enabled 101 1.1 mycroft bne.b dz_ena 102 1.1 mycroft * 103 1.1 mycroft * dz disabled 104 1.1 mycroft * 105 1.1 mycroft btst.b #sign_bit,ETEMP_EX(a6) ;check sign for neg or pos 106 1.1 mycroft beq.b p_inf ;branch if pos sign 107 1.1 mycroft 108 1.1 mycroft m_inf: 109 1.1 mycroft fmovem.x mns_inf,fp0 ;load -inf 110 1.1 mycroft bset.b #neg_bit,FPSR_CC(a6) ;set neg bit in FPSR 111 1.1 mycroft bra.b set_fpsr 112 1.1 mycroft p_inf: 113 1.1 mycroft fmovem.x pls_inf,fp0 ;load +inf 114 1.1 mycroft set_fpsr: 115 1.1 mycroft or.l #dzinf_mask,USER_FPSR(a6) ;set I,DZ,ADZ 116 1.1 mycroft rts 117 1.1 mycroft * 118 1.1 mycroft * dz enabled 119 1.1 mycroft * 120 1.1 mycroft dz_ena: 121 1.1 mycroft btst.b #sign_bit,ETEMP_EX(a6) ;check sign for neg or pos 122 1.1 mycroft beq.b dz_ena_end 123 1.1 mycroft bset.b #neg_bit,FPSR_CC(a6) ;set neg bit in FPSR 124 1.1 mycroft dz_ena_end: 125 1.1 mycroft or.l #dzinf_mask,USER_FPSR(a6) ;set I,DZ,ADZ 126 1.1 mycroft st.b STORE_FLG(a6) 127 1.1 mycroft rts 128 1.1 mycroft * 129 1.1 mycroft * OPERR exception 130 1.1 mycroft * 131 1.1 mycroft * if (operr trap disabled) 132 1.1 mycroft * set FPSR exception status operr bit, condition code 133 1.1 mycroft * nan bit; Store default NAN into fp0 134 1.1 mycroft * frestore the frame into the machine (done by unimp_hd) 135 1.1 mycroft * 136 1.1 mycroft * else (operr trap enabled) 137 1.1 mycroft * set FPSR exception status operr bit, accrued operr bit 138 1.1 mycroft * set flag to disable sto_res from corrupting fp register 139 1.1 mycroft * frestore the frame into the machine (done by unimp_hd) 140 1.1 mycroft * 141 1.1 mycroft t_operr: 142 1.1 mycroft or.l #opnan_mask,USER_FPSR(a6) ;set NaN, OPERR, AIOP 143 1.1 mycroft 144 1.1 mycroft btst.b #operr_bit,FPCR_ENABLE(a6) ;test FPCR for operr enabled 145 1.1 mycroft bne.b op_ena 146 1.1 mycroft 147 1.1 mycroft fmovem.x nan,fp0 ;load default nan 148 1.1 mycroft rts 149 1.1 mycroft op_ena: 150 1.1 mycroft st.b STORE_FLG(a6) ;do not corrupt destination 151 1.1 mycroft rts 152 1.1 mycroft 153 1.1 mycroft * 154 1.1 mycroft * t_unfl --- UNFL exception 155 1.1 mycroft * 156 1.1 mycroft * This entry point is used by all routines requiring unfl, inex2, 157 1.1 mycroft * aunfl, and ainex to be set on exit. 158 1.1 mycroft * 159 1.1 mycroft * On entry, a0 points to the exceptional operand. The final exceptional 160 1.1 mycroft * operand is built in FP_SCR1 and only the sign from the original operand 161 1.1 mycroft * is used. 162 1.1 mycroft * 163 1.1 mycroft t_unfl: 164 1.1 mycroft clr.l FP_SCR1(a6) ;set exceptional operand to zero 165 1.1 mycroft clr.l FP_SCR1+4(a6) 166 1.1 mycroft clr.l FP_SCR1+8(a6) 167 1.1 mycroft tst.b (a0) ;extract sign from caller's exop 168 1.1 mycroft bpl.b unfl_signok 169 1.1 mycroft bset #sign_bit,FP_SCR1(a6) 170 1.1 mycroft unfl_signok: 171 1.1 mycroft lea.l FP_SCR1(a6),a0 172 1.1 mycroft or.l #unfinx_mask,USER_FPSR(a6) 173 1.1 mycroft * ;set UNFL, INEX2, AUNFL, AINEX 174 1.1 mycroft unfl_con: 175 1.1 mycroft btst.b #unfl_bit,FPCR_ENABLE(a6) 176 1.1 mycroft beq.b unfl_dis 177 1.1 mycroft 178 1.1 mycroft unfl_ena: 179 1.1 mycroft bfclr STAG(a6){5:3} ;clear wbtm66,wbtm1,wbtm0 180 1.1 mycroft bset.b #wbtemp15_bit,WB_BYTE(a6) ;set wbtemp15 181 1.1 mycroft bset.b #sticky_bit,STICKY(a6) ;set sticky bit 182 1.1 mycroft 183 1.1 mycroft bclr.b #E1,E_BYTE(a6) 184 1.1 mycroft 185 1.1 mycroft unfl_dis: 186 1.1 mycroft bfextu FPCR_MODE(a6){0:2},d0 ;get round precision 187 1.1 mycroft 188 1.1 mycroft bclr.b #sign_bit,LOCAL_EX(a0) 189 1.1 mycroft sne LOCAL_SGN(a0) ;convert to internal ext format 190 1.1 mycroft 191 1.1 mycroft bsr unf_sub ;returns IEEE result at a0 192 1.1 mycroft * ;and sets FPSR_CC accordingly 193 1.1 mycroft 194 1.1 mycroft bfclr LOCAL_SGN(a0){0:8} ;convert back to IEEE ext format 195 1.1 mycroft beq.b unfl_fin 196 1.1 mycroft 197 1.1 mycroft bset.b #sign_bit,LOCAL_EX(a0) 198 1.1 mycroft bset.b #sign_bit,FP_SCR1(a6) ;set sign bit of exc operand 199 1.1 mycroft 200 1.1 mycroft unfl_fin: 201 1.1 mycroft fmovem.x (a0),fp0 ;store result in fp0 202 1.1 mycroft rts 203 1.1 mycroft 204 1.1 mycroft 205 1.1 mycroft * 206 1.1 mycroft * t_ovfl2 --- OVFL exception (without inex2 returned) 207 1.1 mycroft * 208 1.1 mycroft * This entry is used by scale to force catastrophic overflow. The 209 1.1 mycroft * ovfl, aovfl, and ainex bits are set, but not the inex2 bit. 210 1.1 mycroft * 211 1.1 mycroft t_ovfl2: 212 1.1 mycroft or.l #ovfl_inx_mask,USER_FPSR(a6) 213 1.1 mycroft move.l ETEMP(a6),FP_SCR1(a6) 214 1.1 mycroft move.l ETEMP_HI(a6),FP_SCR1+4(a6) 215 1.1 mycroft move.l ETEMP_LO(a6),FP_SCR1+8(a6) 216 1.1 mycroft * 217 1.1 mycroft * Check for single or double round precision. If single, check if 218 1.1 mycroft * the lower 40 bits of ETEMP are zero; if not, set inex2. If double, 219 1.1 mycroft * check if the lower 21 bits are zero; if not, set inex2. 220 1.1 mycroft * 221 1.1 mycroft move.b FPCR_MODE(a6),d0 222 1.1 mycroft andi.b #$c0,d0 223 1.1 mycroft beq.w t_work ;if extended, finish ovfl processing 224 1.1 mycroft cmpi.b #$40,d0 ;test for single 225 1.1 mycroft bne.b t_dbl 226 1.1 mycroft t_sgl: 227 1.1 mycroft tst.b ETEMP_LO(a6) 228 1.1 mycroft bne.b t_setinx2 229 1.1 mycroft move.l ETEMP_HI(a6),d0 230 1.1 mycroft andi.l #$ff,d0 ;look at only lower 8 bits 231 1.1 mycroft bne.b t_setinx2 232 1.1 mycroft bra.w t_work 233 1.1 mycroft t_dbl: 234 1.1 mycroft move.l ETEMP_LO(a6),d0 235 1.1 mycroft andi.l #$7ff,d0 ;look at only lower 11 bits 236 1.1 mycroft beq.w t_work 237 1.1 mycroft t_setinx2: 238 1.1 mycroft or.l #inex2_mask,USER_FPSR(a6) 239 1.1 mycroft bra.b t_work 240 1.1 mycroft * 241 1.1 mycroft * t_ovfl --- OVFL exception 242 1.1 mycroft * 243 1.1 mycroft *** Note: the exc operand is returned in ETEMP. 244 1.1 mycroft * 245 1.1 mycroft t_ovfl: 246 1.1 mycroft or.l #ovfinx_mask,USER_FPSR(a6) 247 1.1 mycroft t_work: 248 1.1 mycroft btst.b #ovfl_bit,FPCR_ENABLE(a6) ;test FPCR for ovfl enabled 249 1.1 mycroft beq.b ovf_dis 250 1.1 mycroft 251 1.1 mycroft ovf_ena: 252 1.1 mycroft clr.l FP_SCR1(a6) ;set exceptional operand 253 1.1 mycroft clr.l FP_SCR1+4(a6) 254 1.1 mycroft clr.l FP_SCR1+8(a6) 255 1.1 mycroft 256 1.1 mycroft bfclr STAG(a6){5:3} ;clear wbtm66,wbtm1,wbtm0 257 1.1 mycroft bclr.b #wbtemp15_bit,WB_BYTE(a6) ;clear wbtemp15 258 1.1 mycroft bset.b #sticky_bit,STICKY(a6) ;set sticky bit 259 1.1 mycroft 260 1.1 mycroft bclr.b #E1,E_BYTE(a6) 261 1.1 mycroft * ;fall through to disabled case 262 1.1 mycroft 263 1.1 mycroft * For disabled overflow call 'ovf_r_k'. This routine loads the 264 1.1 mycroft * correct result based on the rounding precision, destination 265 1.1 mycroft * format, rounding mode and sign. 266 1.1 mycroft * 267 1.1 mycroft ovf_dis: 268 1.1 mycroft bsr ovf_r_k ;returns unsigned ETEMP_EX 269 1.1 mycroft * ;and sets FPSR_CC accordingly. 270 1.1 mycroft bfclr ETEMP_SGN(a6){0:8} ;fix sign 271 1.1 mycroft beq.b ovf_pos 272 1.1 mycroft bset.b #sign_bit,ETEMP_EX(a6) 273 1.1 mycroft bset.b #sign_bit,FP_SCR1(a6) ;set exceptional operand sign 274 1.1 mycroft ovf_pos: 275 1.1 mycroft fmovem.x ETEMP(a6),fp0 ;move the result to fp0 276 1.1 mycroft rts 277 1.1 mycroft 278 1.1 mycroft 279 1.1 mycroft * 280 1.1 mycroft * INEX2 exception 281 1.1 mycroft * 282 1.1 mycroft * The inex2 and ainex bits are set. 283 1.1 mycroft * 284 1.1 mycroft t_inx2: 285 1.1 mycroft or.l #inx2a_mask,USER_FPSR(a6) ;set INEX2, AINEX 286 1.1 mycroft rts 287 1.1 mycroft 288 1.1 mycroft * 289 1.1 mycroft * Force Inex2 290 1.1 mycroft * 291 1.1 mycroft * This routine is called by the transcendental routines to force 292 1.1 mycroft * the inex2 exception bits set in the FPSR. If the underflow bit 293 1.1 mycroft * is set, but the underflow trap was not taken, the aunfl bit in 294 1.1 mycroft * the FPSR must be set. 295 1.1 mycroft * 296 1.1 mycroft t_frcinx: 297 1.1 mycroft or.l #inx2a_mask,USER_FPSR(a6) ;set INEX2, AINEX 298 1.1 mycroft btst.b #unfl_bit,FPSR_EXCEPT(a6) ;test for unfl bit set 299 1.1 mycroft beq.b no_uacc1 ;if clear, do not set aunfl 300 1.1 mycroft bset.b #aunfl_bit,FPSR_AEXCEPT(a6) 301 1.1 mycroft no_uacc1: 302 1.1 mycroft rts 303 1.1 mycroft 304 1.1 mycroft * 305 1.1 mycroft * DST_NAN 306 1.1 mycroft * 307 1.1 mycroft * Determine if the destination nan is signalling or non-signalling, 308 1.1 mycroft * and set the FPSR bits accordingly. See the MC68040 User's Manual 309 1.1 mycroft * section 3.2.2.5 NOT-A-NUMBERS. 310 1.1 mycroft * 311 1.1 mycroft dst_nan: 312 1.1 mycroft btst.b #sign_bit,FPTEMP_EX(a6) ;test sign of nan 313 1.1 mycroft beq.b dst_pos ;if clr, it was positive 314 1.1 mycroft bset.b #neg_bit,FPSR_CC(a6) ;set N bit 315 1.1 mycroft dst_pos: 316 1.1 mycroft btst.b #signan_bit,FPTEMP_HI(a6) ;check if signalling 317 1.1 mycroft beq.b dst_snan ;branch if signalling 318 1.1 mycroft 319 1.1 mycroft fmove.l d1,fpcr ;restore user's rmode/prec 320 1.1 mycroft fmove.x FPTEMP(a6),fp0 ;return the non-signalling nan 321 1.1 mycroft * 322 1.1 mycroft * Check the source nan. If it is signalling, snan will be reported. 323 1.1 mycroft * 324 1.1 mycroft move.b STAG(a6),d0 325 1.1 mycroft andi.b #$e0,d0 326 1.1 mycroft cmpi.b #$60,d0 327 1.1 mycroft bne.b no_snan 328 1.1 mycroft btst.b #signan_bit,ETEMP_HI(a6) ;check if signalling 329 1.1 mycroft bne.b no_snan 330 1.1 mycroft or.l #snaniop_mask,USER_FPSR(a6) ;set NAN, SNAN, AIOP 331 1.1 mycroft no_snan: 332 1.1 mycroft rts 333 1.1 mycroft 334 1.1 mycroft dst_snan: 335 1.1 mycroft btst.b #snan_bit,FPCR_ENABLE(a6) ;check if trap enabled 336 1.1 mycroft beq.b dst_dis ;branch if disabled 337 1.1 mycroft 338 1.1 mycroft or.b #nan_tag,DTAG(a6) ;set up dtag for nan 339 1.1 mycroft st.b STORE_FLG(a6) ;do not store a result 340 1.1 mycroft or.l #snaniop_mask,USER_FPSR(a6) ;set NAN, SNAN, AIOP 341 1.1 mycroft rts 342 1.1 mycroft 343 1.1 mycroft dst_dis: 344 1.1 mycroft bset.b #signan_bit,FPTEMP_HI(a6) ;set SNAN bit in sop 345 1.1 mycroft fmove.l d1,fpcr ;restore user's rmode/prec 346 1.1 mycroft fmove.x FPTEMP(a6),fp0 ;load non-sign. nan 347 1.1 mycroft or.l #snaniop_mask,USER_FPSR(a6) ;set NAN, SNAN, AIOP 348 1.1 mycroft rts 349 1.1 mycroft 350 1.1 mycroft * 351 1.1 mycroft * SRC_NAN 352 1.1 mycroft * 353 1.1 mycroft * Determine if the source nan is signalling or non-signalling, 354 1.1 mycroft * and set the FPSR bits accordingly. See the MC68040 User's Manual 355 1.1 mycroft * section 3.2.2.5 NOT-A-NUMBERS. 356 1.1 mycroft * 357 1.1 mycroft src_nan: 358 1.1 mycroft btst.b #sign_bit,ETEMP_EX(a6) ;test sign of nan 359 1.1 mycroft beq.b src_pos ;if clr, it was positive 360 1.1 mycroft bset.b #neg_bit,FPSR_CC(a6) ;set N bit 361 1.1 mycroft src_pos: 362 1.1 mycroft btst.b #signan_bit,ETEMP_HI(a6) ;check if signalling 363 1.1 mycroft beq.b src_snan ;branch if signalling 364 1.1 mycroft fmove.l d1,fpcr ;restore user's rmode/prec 365 1.1 mycroft fmove.x ETEMP(a6),fp0 ;return the non-signalling nan 366 1.1 mycroft rts 367 1.1 mycroft 368 1.1 mycroft src_snan: 369 1.1 mycroft btst.b #snan_bit,FPCR_ENABLE(a6) ;check if trap enabled 370 1.1 mycroft beq.b src_dis ;branch if disabled 371 1.1 mycroft bset.b #signan_bit,ETEMP_HI(a6) ;set SNAN bit in sop 372 1.1 mycroft or.b #norm_tag,DTAG(a6) ;set up dtag for norm 373 1.1 mycroft or.b #nan_tag,STAG(a6) ;set up stag for nan 374 1.1 mycroft st.b STORE_FLG(a6) ;do not store a result 375 1.1 mycroft or.l #snaniop_mask,USER_FPSR(a6) ;set NAN, SNAN, AIOP 376 1.1 mycroft rts 377 1.1 mycroft 378 1.1 mycroft src_dis: 379 1.1 mycroft bset.b #signan_bit,ETEMP_HI(a6) ;set SNAN bit in sop 380 1.1 mycroft fmove.l d1,fpcr ;restore user's rmode/prec 381 1.1 mycroft fmove.x ETEMP(a6),fp0 ;load non-sign. nan 382 1.1 mycroft or.l #snaniop_mask,USER_FPSR(a6) ;set NAN, SNAN, AIOP 383 1.1 mycroft rts 384 1.1 mycroft 385 1.1 mycroft * 386 1.1 mycroft * For all functions that have a denormalized input and that f(x)=x, 387 1.1 mycroft * this is the entry point 388 1.1 mycroft * 389 1.1 mycroft t_extdnrm: 390 1.1 mycroft or.l #unfinx_mask,USER_FPSR(a6) 391 1.1 mycroft * ;set UNFL, INEX2, AUNFL, AINEX 392 1.1 mycroft bra.b xdnrm_con 393 1.1 mycroft * 394 1.1 mycroft * Entry point for scale with extended denorm. The function does 395 1.1 mycroft * not set inex2, aunfl, or ainex. 396 1.1 mycroft * 397 1.1 mycroft t_resdnrm: 398 1.1 mycroft or.l #unfl_mask,USER_FPSR(a6) 399 1.1 mycroft 400 1.1 mycroft xdnrm_con: 401 1.1 mycroft btst.b #unfl_bit,FPCR_ENABLE(a6) 402 1.1 mycroft beq.b xdnrm_dis 403 1.1 mycroft 404 1.1 mycroft * 405 1.1 mycroft * If exceptions are enabled, the additional task of setting up WBTEMP 406 1.1 mycroft * is needed so that when the underflow exception handler is entered, 407 1.1 mycroft * the user perceives no difference between what the 040 provides vs. 408 1.1 mycroft * what the FPSP provides. 409 1.1 mycroft * 410 1.1 mycroft xdnrm_ena: 411 1.1 mycroft move.l a0,-(a7) 412 1.1 mycroft 413 1.1 mycroft move.l LOCAL_EX(a0),FP_SCR1(a6) 414 1.1 mycroft move.l LOCAL_HI(a0),FP_SCR1+4(a6) 415 1.1 mycroft move.l LOCAL_LO(a0),FP_SCR1+8(a6) 416 1.1 mycroft 417 1.1 mycroft lea FP_SCR1(a6),a0 418 1.1 mycroft 419 1.1 mycroft bclr.b #sign_bit,LOCAL_EX(a0) 420 1.1 mycroft sne LOCAL_SGN(a0) ;convert to internal ext format 421 1.1 mycroft tst.w LOCAL_EX(a0) ;check if input is denorm 422 1.1 mycroft beq.b xdnrm_dn ;if so, skip nrm_set 423 1.1 mycroft bsr nrm_set ;normalize the result (exponent 424 1.1 mycroft * ;will be negative 425 1.1 mycroft xdnrm_dn: 426 1.1 mycroft bclr.b #sign_bit,LOCAL_EX(a0) ;take off false sign 427 1.1 mycroft bfclr LOCAL_SGN(a0){0:8} ;change back to IEEE ext format 428 1.1 mycroft beq.b xdep 429 1.1 mycroft bset.b #sign_bit,LOCAL_EX(a0) 430 1.1 mycroft xdep: 431 1.1 mycroft bfclr STAG(a6){5:3} ;clear wbtm66,wbtm1,wbtm0 432 1.1 mycroft bset.b #wbtemp15_bit,WB_BYTE(a6) ;set wbtemp15 433 1.1 mycroft bclr.b #sticky_bit,STICKY(a6) ;clear sticky bit 434 1.1 mycroft bclr.b #E1,E_BYTE(a6) 435 1.1 mycroft move.l (a7)+,a0 436 1.1 mycroft xdnrm_dis: 437 1.1 mycroft bfextu FPCR_MODE(a6){0:2},d0 ;get round precision 438 1.1 mycroft bne.b not_ext ;if not round extended, store 439 1.1 mycroft * ;IEEE defaults 440 1.1 mycroft is_ext: 441 1.1 mycroft btst.b #sign_bit,LOCAL_EX(a0) 442 1.1 mycroft beq.b xdnrm_store 443 1.1 mycroft 444 1.1 mycroft bset.b #neg_bit,FPSR_CC(a6) ;set N bit in FPSR_CC 445 1.1 mycroft 446 1.1 mycroft bra.b xdnrm_store 447 1.1 mycroft 448 1.1 mycroft not_ext: 449 1.1 mycroft bclr.b #sign_bit,LOCAL_EX(a0) 450 1.1 mycroft sne LOCAL_SGN(a0) ;convert to internal ext format 451 1.1 mycroft bsr unf_sub ;returns IEEE result pointed by 452 1.1 mycroft * ;a0; sets FPSR_CC accordingly 453 1.1 mycroft bfclr LOCAL_SGN(a0){0:8} ;convert back to IEEE ext format 454 1.1 mycroft beq.b xdnrm_store 455 1.1 mycroft bset.b #sign_bit,LOCAL_EX(a0) 456 1.1 mycroft xdnrm_store: 457 1.1 mycroft fmovem.x (a0),fp0 ;store result in fp0 458 1.1 mycroft rts 459 1.1 mycroft 460 1.1 mycroft * 461 1.1 mycroft * This subroutine is used for dyadic operations that use an extended 462 1.1 mycroft * denorm within the kernel. The approach used is to capture the frame, 463 1.1 mycroft * fix/restore. 464 1.1 mycroft * 465 1.1 mycroft xdef t_avoid_unsupp 466 1.1 mycroft t_avoid_unsupp: 467 1.1 mycroft link a2,#-LOCAL_SIZE ;so that a2 fpsp.h negative 468 1.1 mycroft * ;offsets may be used 469 1.1 mycroft fsave -(a7) 470 1.1 mycroft tst.b 1(a7) ;check if idle, exit if so 471 1.1 mycroft beq.w idle_end 472 1.1 mycroft btst.b #E1,E_BYTE(a2) ;check for an E1 exception if 473 1.1 mycroft * ;enabled, there is an unsupp 474 1.1 mycroft beq.w end_avun ;else, exit 475 1.1 mycroft btst.b #7,DTAG(a2) ;check for denorm destination 476 1.1 mycroft beq.b src_den ;else, must be a source denorm 477 1.1 mycroft * 478 1.1 mycroft * handle destination denorm 479 1.1 mycroft * 480 1.1 mycroft lea FPTEMP(a2),a0 481 1.1 mycroft btst.b #sign_bit,LOCAL_EX(a0) 482 1.1 mycroft sne LOCAL_SGN(a0) ;convert to internal ext format 483 1.1 mycroft bclr.b #7,DTAG(a2) ;set DTAG to norm 484 1.1 mycroft bsr nrm_set ;normalize result, exponent 485 1.1 mycroft * ;will become negative 486 1.1 mycroft bclr.b #sign_bit,LOCAL_EX(a0) ;get rid of fake sign 487 1.1 mycroft bfclr LOCAL_SGN(a0){0:8} ;convert back to IEEE ext format 488 1.1 mycroft beq.b ck_src_den ;check if source is also denorm 489 1.1 mycroft bset.b #sign_bit,LOCAL_EX(a0) 490 1.1 mycroft ck_src_den: 491 1.1 mycroft btst.b #7,STAG(a2) 492 1.1 mycroft beq.b end_avun 493 1.1 mycroft src_den: 494 1.1 mycroft lea ETEMP(a2),a0 495 1.1 mycroft btst.b #sign_bit,LOCAL_EX(a0) 496 1.1 mycroft sne LOCAL_SGN(a0) ;convert to internal ext format 497 1.1 mycroft bclr.b #7,STAG(a2) ;set STAG to norm 498 1.1 mycroft bsr nrm_set ;normalize result, exponent 499 1.1 mycroft * ;will become negative 500 1.1 mycroft bclr.b #sign_bit,LOCAL_EX(a0) ;get rid of fake sign 501 1.1 mycroft bfclr LOCAL_SGN(a0){0:8} ;convert back to IEEE ext format 502 1.1 mycroft beq.b den_com 503 1.1 mycroft bset.b #sign_bit,LOCAL_EX(a0) 504 1.1 mycroft den_com: 505 1.1 mycroft move.b #$fe,CU_SAVEPC(a2) ;set continue frame 506 1.1 mycroft clr.w NMNEXC(a2) ;clear NMNEXC 507 1.1 mycroft bclr.b #E1,E_BYTE(a2) 508 1.1 mycroft * fmove.l FPSR,FPSR_SHADOW(a2) 509 1.1 mycroft * bset.b #SFLAG,E_BYTE(a2) 510 1.1 mycroft * bset.b #XFLAG,T_BYTE(a2) 511 1.1 mycroft end_avun: 512 1.1 mycroft frestore (a7)+ 513 1.1 mycroft unlk a2 514 1.1 mycroft rts 515 1.1 mycroft idle_end: 516 1.1 mycroft add.l #4,a7 517 1.1 mycroft unlk a2 518 1.1 mycroft rts 519 1.1 mycroft end 520