2 | gen_except.sa 3.7 1/16/92
4 | gen_except --- FPSP routine to detect reportable exceptions
6 | This routine compares the exception enable byte of the
7 | user_fpcr on the stack with the exception status byte
10 | Any routine which may report an exceptions must load
11 | the stack frame in memory with the exceptional operand(s).
13 | Priority for exceptions is:
24 | Note: The IEEE standard specifies that inex2 is to be
25 | reported if ovfl occurs and the ovfl enable bit is not
26 | set but the inex2 enable bit is.
29 | Copyright (C) Motorola, Inc. 1990
32 | For details on the license for this file, please see the
33 | file, README, in this same directory.
35 GEN_EXCEPT: |idnt 2,1 | Motorola 040 Floating Point Software Package
58 cmpib #IDLE_SIZE-4,1(%a7) |test for idle frame
59 beq do_check |go handle idle frame
60 cmpib #UNIMP_40_SIZE-4,1(%a7) |test for orig unimp frame
61 beqs unimp_x |go handle unimp frame
62 cmpib #UNIMP_41_SIZE-4,1(%a7) |test for rev unimp frame
63 beqs unimp_x |go handle unimp frame
64 cmpib #BUSY_SIZE-4,1(%a7) |if size <> $60, fmt error
66 leal BUSY_SIZE+LOCAL_SIZE(%a7),%a1 |init a1 so fpsp.h
68 | Fix up the new busy frame with entries from the unimp frame
70 movel ETEMP_EX(%a6),ETEMP_EX(%a1) |copy etemp from unimp
71 movel ETEMP_HI(%a6),ETEMP_HI(%a1) |frame to busy frame
72 movel ETEMP_LO(%a6),ETEMP_LO(%a1)
73 movel CMDREG1B(%a6),CMDREG1B(%a1) |set inst in frame to unimp
74 movel CMDREG1B(%a6),%d0 |fix cmd1b to make it
75 andl #0x03c30000,%d0 |work for cmd3b
76 bfextu CMDREG1B(%a6){#13:#1},%d1 |extract bit 2
79 orl %d1,%d0 |put it in the right place
80 bfextu CMDREG1B(%a6){#10:#3},%d1 |extract bit 3,4,5
83 orl %d1,%d0 |put them in the right place
84 movel %d0,CMDREG3B(%a1) |in the busy frame
86 | Or in the FPSR from the emulation with the USER_FPSR on the stack.
89 orl %d0,USER_FPSR(%a6)
90 movel USER_FPSR(%a6),FPSR_SHADOW(%a1) |set exc bits
91 orl #sx_mask,E_BYTE(%a1)
95 | Frame is an unimp frame possible resulting from an fmove <ea>,fp0
96 | that caused an exception
98 | a1 is modified to point into the new frame allowing fpsp equates
102 cmpib #UNIMP_40_SIZE-4,1(%a7) |test for orig unimp frame
104 leal UNIMP_40_SIZE+LOCAL_SIZE(%a7),%a1
107 cmpib #UNIMP_41_SIZE-4,1(%a7) |test for rev unimp frame
108 bnel fpsp_fmt_error |if not $28 or $30
109 leal UNIMP_41_SIZE+LOCAL_SIZE(%a7),%a1
113 | Fix up the new unimp frame with entries from the old unimp frame
115 movel CMDREG1B(%a6),CMDREG1B(%a1) |set inst in frame to unimp
117 | Or in the FPSR from the emulation with the USER_FPSR on the stack.
120 orl %d0,USER_FPSR(%a6)
124 | Frame is idle, so check for exceptions reported through
125 | USER_FPSR and set the unimp frame accordingly.
126 | A7 must be incremented to the point before the
127 | idle fsave vector to the unimp vector.
131 addl #4,%a7 |point A7 back to unimp frame
133 | Or in the FPSR from the emulation with the USER_FPSR on the stack.
136 orl %d0,USER_FPSR(%a6)
138 | On a busy frame, we must clear the nmnexc bits.
140 cmpib #BUSY_SIZE-4,1(%a7) |check frame type
141 bnes check_fr |if busy, clr nmnexc
142 clrw NMNEXC(%a6) |clr nmnexc & nmcexc
143 btstb #5,CMDREG1B(%a6) |test for fmove out
145 movel USER_FPSR(%a6),FPSR_SHADOW(%a6) |set exc bits
146 orl #sx_mask,E_BYTE(%a6)
149 cmpb #UNIMP_40_SIZE-4,1(%a7)
153 moveb FPCR_ENABLE(%a6),%d0 |get fpcr enable byte
154 andb FPSR_EXCEPT(%a6),%d0 |and in the fpsr exc byte
155 bfffo %d0{#24:#8},%d1 |test for first set bit
156 leal exc_tbl,%a0 |load jmp table address
157 subib #24,%d1 |normalize bit offset to 0-8
158 movel (%a0,%d1.w*4),%a0 |load routine address based
159 | ;based on first enabled exc
160 jmp (%a0) |jump to routine
162 | Bsun is not possible in unimp or unsupp
167 | The typical work to be done to the unimp frame to report an
168 | exception is to set the E1/E3 byte and clr the U flag.
169 | commonE1 does this for E1 exceptions, which are snan,
170 | operr, and dz. commonE3 does this for E3 exceptions, which
171 | are inex2 and inex1, and also clears the E1 exception bit
172 | left over from the unimp exception.
175 bsetb #E1,E_BYTE(%a6) |set E1 flag
176 bra commonE |go clean and exit
179 tstb UFLG_TMP(%a6) |test flag for unsup/unimp state
182 bsetb #E3,E_BYTE(%a6) |set E3 flag
183 bclrb #E1,E_BYTE(%a6) |clr E1 from unimp
190 bsetb #E3,E_BYTE(%a6) |set E3 flag
192 bclrb #E1,E_BYTE(%a6) |clr E1 flag
193 movel CMDREG1B(%a6),%d0
194 andl #0x03c30000,%d0 |work for cmd3b
195 bfextu CMDREG1B(%a6){#13:#1},%d1 |extract bit 2
198 orl %d1,%d0 |put it in the right place
199 bfextu CMDREG1B(%a6){#10:#3},%d1 |extract bit 3,4,5
202 orl %d1,%d0 |put them in the right place
203 movel %d0,CMDREG3B(%a6) |in the busy frame
206 bclrb #UFLAG,T_BYTE(%a6) |clr U flag from unimp
207 bra do_clean |go clean and exit
209 | No bits in the enable byte match existing exceptions. Check for
210 | the case of the ovfl exc without the ovfl enabled, but with
214 btstb #inex2_bit,FPCR_ENABLE(%a6) |check for ovfl/inex2 case
215 beqs no_exc |if clear, exit
216 btstb #ovfl_bit,FPSR_EXCEPT(%a6) |now check ovfl
217 beqs no_exc |if clear, exit
218 bras ovfl_unfl |go to unfl_ovfl to determine if
219 | ;it is an unsupp or unimp exc
221 | No exceptions are to be reported. If the instruction was
222 | unimplemented, no FPU restore is necessary. If it was
223 | unsupported, we must perform the restore.
225 tstb UFLG_TMP(%a6) |test flag for unsupp/unimp state
228 tstb RES_FLG(%a6) |check if frestore is needed
229 bne do_clean |if clear, no frestore needed
231 moveml USER_DA(%a6),%d0-%d1/%a0-%a1
232 fmovemx USER_FP0(%a6),%fp0-%fp3
233 fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
237 | Unsupported Data Type Handler:
239 | An fmoveout that results in an overflow is reported this way.
241 | An fmoveout that results in an underflow is reported this way.
243 | Unimplemented Instruction Handler:
245 | Only scosh, setox, ssinh, stwotox, and scale can set overflow in
248 | Stwotox, setox, and scale can set underflow in this manner.
249 | Any of the other Library Routines such that f(x)=x in which
250 | x is an extended denorm can report an underflow exception.
251 | It is the responsibility of the exception-causing exception
252 | to make sure that WBTEMP is correct.
254 | The exceptional operand is in FP_SCR1.
257 tstb UFLG_TMP(%a6) |test flag for unsupp/unimp state
260 | The caller was from an unsupported data type trap. Test if the
261 | caller set CU_ONLY. If so, the exceptional operand is expected in
262 | FPTEMP, rather than WBTEMP.
264 tstb CU_ONLY(%a6) |test if inst is cu-only
266 | move.w #$fe,CU_SAVEPC(%a6)
268 bsetb #E1,E_BYTE(%a6) |set E1 exception flag
269 movew ETEMP_EX(%a6),FPTEMP_EX(%a6)
270 movel ETEMP_HI(%a6),FPTEMP_HI(%a6)
271 movel ETEMP_LO(%a6),FPTEMP_LO(%a6)
272 bsetb #fptemp15_bit,DTAG(%a6) |set fpte15
273 bclrb #UFLAG,T_BYTE(%a6) |clr U flag from unimp
274 bra do_clean |go clean and exit
277 moveb (%a7),VER_TMP(%a6) |save version number
278 cmpib #BUSY_SIZE-4,1(%a7) |check for busy frame
279 beqs busy_fr |if unimp, grow to busy
280 cmpib #VER_40,(%a7) |test for orig unimp frame
281 bnes try_41 |if not, test for rev frame
282 moveql #13,%d0 |need to zero 14 lwords
285 cmpib #VER_41,(%a7) |test for rev unimp frame
286 bnel fpsp_fmt_error |if neither, exit with error
287 moveql #11,%d0 |need to zero 12 lwords
292 clrl -(%a7) |clear and dec a7
294 moveb VER_TMP(%a6),(%a7)
295 moveb #BUSY_SIZE-4,1(%a7) |write busy fmt word.
297 movel FP_SCR1(%a6),WBTEMP_EX(%a6) |write
298 movel FP_SCR1+4(%a6),WBTEMP_HI(%a6) |exceptional op to
299 movel FP_SCR1+8(%a6),WBTEMP_LO(%a6) |wbtemp
300 bsetb #E3,E_BYTE(%a6) |set E3 flag
301 bclrb #E1,E_BYTE(%a6) |make sure E1 is clear
302 bclrb #UFLAG,T_BYTE(%a6) |clr U flag
303 movel USER_FPSR(%a6),FPSR_SHADOW(%a6)
304 orl #sx_mask,E_BYTE(%a6)
305 movel CMDREG1B(%a6),%d0 |fix cmd1b to make it
306 andl #0x03c30000,%d0 |work for cmd3b
307 bfextu CMDREG1B(%a6){#13:#1},%d1 |extract bit 2
310 orl %d1,%d0 |put it in the right place
311 bfextu CMDREG1B(%a6){#10:#3},%d1 |extract bit 3,4,5
314 orl %d1,%d0 |put them in the right place
315 movel %d0,CMDREG3B(%a6) |in the busy frame
318 | Check if the frame to be restored is busy or unimp.
319 |** NOTE *** Bug fix for errata (0d43b #3)
320 | If the frame is unimp, we must create a busy frame to
321 | fix the bug with the nmnexc bits in cases in which they
322 | are set by a previous instruction and not cleared by
323 | the save. The frame will be unimp only if the final
324 | instruction in an emulation routine caused the exception
325 | by doing an fmove <ea>,fp0. The exception operand, in
326 | internal format, is in fptemp.
329 cmpib #UNIMP_40_SIZE-4,1(%a7)
331 moveql #13,%d0 |in orig, need to zero 14 lwords
334 cmpib #UNIMP_41_SIZE-4,1(%a7)
335 bnes do_restore |frame must be busy
336 moveql #11,%d0 |in rev, need to zero 12 lwords
339 moveb (%a7),VER_TMP(%a6)
342 clrl -(%a7) |clear and dec a7
345 | Use a1 as pointer into new frame. a6 is not correct if an unimp or
346 | busy frame was created as the result of an exception on the final
347 | instruction of an emulation routine.
349 | We need to set the nmcexc bits if the exception is E1. Otherwise,
350 | the exc taken will be inex2.
352 leal BUSY_SIZE+LOCAL_SIZE(%a7),%a1 |init a1 for new frame
353 moveb VER_TMP(%a6),(%a7) |write busy fmt word
354 moveb #BUSY_SIZE-4,1(%a7)
355 movel FP_SCR1(%a6),WBTEMP_EX(%a1) |write
356 movel FP_SCR1+4(%a6),WBTEMP_HI(%a1) |exceptional op to
357 movel FP_SCR1+8(%a6),WBTEMP_LO(%a1) |wbtemp
358 | btst.b #E1,E_BYTE(%a1)
360 bfextu USER_FPSR(%a6){#17:#4},%d0 |get snan/operr/ovfl/unfl bits
361 bfins %d0,NMCEXC(%a1){#4:#4} |and insert them in nmcexc
362 movel USER_FPSR(%a6),FPSR_SHADOW(%a1) |set exc bits
363 orl #sx_mask,E_BYTE(%a1)
366 moveml USER_DA(%a6),%d0-%d1/%a0-%a1
367 fmovemx USER_FP0(%a6),%fp0-%fp3
368 fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
370 tstb RES_FLG(%a6) |RES_FLG indicates a "continuation" frame
376 | If trace mode enabled, then go to trace handler. This handler
377 | cannot have any fp instructions. If there are fp inst's and an
378 | exception has been restored into the machine then the exception
379 | will occur upon execution of the fp inst. This is not desirable
380 | in the kernel (supervisor mode). See MC68040 manual Section 9.3.8.
383 btstb #7,(%a7) |test T1 in SR
385 btstb #6,(%a7) |test T0 in SR
389 | Change integer stack to look like trace stack
390 | The address of the instruction that caused the
391 | exception is already in the integer stack (is
392 | the same as the saved friar)
394 | If the current frame is already a 6-word stack then all
395 | that needs to be done is to change the vector# to TRACE.
396 | If the frame is only a 4-word stack (meaning we got here
397 | on an Unsupported data type exception), then we need to grow
398 | the stack an extra 2 words and get the FPIAR from the FPU.
401 bftst EXC_VEC-4(%sp){#0:#4}
404 subw #4,%sp | make room
409 fmovel %fpiar,BUSY_SIZE+EXC_EA-4(%sp)
414 movew #TRACE_VEC,EXC_VEC-4(%a7)
417 | This is a work-around for hardware bug 1384.
422 cmpib #0x41,(%sp) | check for correct frame
424 bgt nofix | if more advanced mask, do nada
427 tstb 1(%sp) | check to see if idle
430 clrl (%sp) | get rid of old fsave frame
431 movel %d1,USER_D1(%a6) | save d1
432 movew #8,%d1 | place unimp frame instead
435 movel USER_D1(%a6),%d1 | restore d1
436 movel #0x40280000,-(%sp)
442 tstb 1(%sp) | check to see if idle
445 clrl (%sp) | get rid of old fsave frame
446 movel %d1,USER_D1(%a6) | save d1
447 movew #10,%d1 | place unimp frame instead
450 movel USER_D1(%a6),%d1 | restore d1
451 movel #0x41300000,-(%sp)
457 bclrb #etemp15_bit,-40(%a5)