1|
2| gen_except.sa 3.7 1/16/92
3|
4| gen_except --- FPSP routine to detect reportable exceptions
5|
6| This routine compares the exception enable byte of the
7| user_fpcr on the stack with the exception status byte
8| of the user_fpsr.
9|
10| Any routine which may report an exceptions must load
11| the stack frame in memory with the exceptional operand(s).
12|
13| Priority for exceptions is:
14|
15| Highest: bsun
16| snan
17| operr
18| ovfl
19| unfl
20| dz
21| inex2
22| Lowest: inex1
23|
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.
27|
28|
29| Copyright (C) Motorola, Inc. 1990
30| All Rights Reserved
31|
32| For details on the license for this file, please see the
33| file, README, in this same directory.
34
35GEN_EXCEPT: |idnt 2,1 | Motorola 040 Floating Point Software Package
36
37 |section 8
38
39#include "fpsp.h"
40
41 |xref real_trace
42 |xref fpsp_done
43 |xref fpsp_fmt_error
44
45exc_tbl:
46 .long bsun_exc
47 .long commonE1
48 .long commonE1
49 .long ovfl_unfl
50 .long ovfl_unfl
51 .long commonE1
52 .long commonE3
53 .long commonE3
54 .long no_match
55
56 .global gen_except
57gen_except:
58 cmpib
59 beq do_check |go handle idle frame
60 cmpib
61 beqs unimp_x |go handle unimp frame
62 cmpib
63 beqs unimp_x |go handle unimp frame
64 cmpib
65 bnel fpsp_fmt_error
66 leal BUSY_SIZE+LOCAL_SIZE(%a7),%a1 |init a1 so fpsp.h
67| ;equates will work
68| Fix up the new busy frame with entries from the unimp frame
69|
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
76 bfextu CMDREG1B(%a6){
77 lsll
78 swap %d1
79 orl %d1,%d0 |put it in the right place
80 bfextu CMDREG1B(%a6){
81 lsll
82 swap %d1
83 orl %d1,%d0 |put them in the right place
84 movel %d0,CMDREG3B(%a1) |in the busy frame
85|
86| Or in the FPSR from the emulation with the USER_FPSR on the stack.
87|
88 fmovel %FPSR,%d0
89 orl %d0,USER_FPSR(%a6)
90 movel USER_FPSR(%a6),FPSR_SHADOW(%a1) |set exc bits
91 orl
92 bra do_clean
93
94|
95| Frame is an unimp frame possible resulting from an fmove <ea>,fp0
96| that caused an exception
97|
98| a1 is modified to point into the new frame allowing fpsp equates
99| to be valid.
100|
101unimp_x:
102 cmpib
103 bnes test_rev
104 leal UNIMP_40_SIZE+LOCAL_SIZE(%a7),%a1
105 bras unimp_con
106test_rev:
107 cmpib
108 bnel fpsp_fmt_error |if not $28 or $30
109 leal UNIMP_41_SIZE+LOCAL_SIZE(%a7),%a1
110
111unimp_con:
112|
113| Fix up the new unimp frame with entries from the old unimp frame
114|
115 movel CMDREG1B(%a6),CMDREG1B(%a1) |set inst in frame to unimp
116|
117| Or in the FPSR from the emulation with the USER_FPSR on the stack.
118|
119 fmovel %FPSR,%d0
120 orl %d0,USER_FPSR(%a6)
121 bra do_clean
122
123|
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.
128|
129
130do_check:
131 addl
132|
133| Or in the FPSR from the emulation with the USER_FPSR on the stack.
134|
135 fmovel %FPSR,%d0
136 orl %d0,USER_FPSR(%a6)
137|
138| On a busy frame, we must clear the nmnexc bits.
139|
140 cmpib
141 bnes check_fr |if busy, clr nmnexc
142 clrw NMNEXC(%a6) |clr nmnexc & nmcexc
143 btstb
144 bnes frame_com
145 movel USER_FPSR(%a6),FPSR_SHADOW(%a6) |set exc bits
146 orl
147 bras frame_com
148check_fr:
149 cmpb
150 beqs frame_com
151 clrw NMNEXC(%a6)
152frame_com:
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{
156 leal exc_tbl,%a0 |load jmp table address
157 subib
158 movel (%a0,%d1.w*4),%a0 |load routine address based
159| ;based on first enabled exc
160 jmp (%a0) |jump to routine
161|
162| Bsun is not possible in unimp or unsupp
163|
164bsun_exc:
165 bra do_clean
166|
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.
173|
174commonE1:
175 bsetb
176 bra commonE |go clean and exit
177
178commonE3:
179 tstb UFLG_TMP(%a6) |test flag for unsup/unimp state
180 bnes unsE3
181uniE3:
182 bsetb
183 bclrb
184 bra commonE
185
186unsE3:
187 tstb RES_FLG(%a6)
188 bnes unsE3_0
189unsE3_1:
190 bsetb
191unsE3_0:
192 bclrb
193 movel CMDREG1B(%a6),%d0
194 andl
195 bfextu CMDREG1B(%a6){
196 lsll
197 swap %d1
198 orl %d1,%d0 |put it in the right place
199 bfextu CMDREG1B(%a6){
200 lsll
201 swap %d1
202 orl %d1,%d0 |put them in the right place
203 movel %d0,CMDREG3B(%a6) |in the busy frame
204
205commonE:
206 bclrb
207 bra do_clean |go clean and exit
208|
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
211| inex2 enabled.
212|
213no_match:
214 btstb
215 beqs no_exc |if clear, exit
216 btstb
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
220
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.
224no_exc:
225 tstb UFLG_TMP(%a6) |test flag for unsupp/unimp state
226 beqs uni_no_exc
227uns_no_exc:
228 tstb RES_FLG(%a6) |check if frestore is needed
229 bne do_clean |if clear, no frestore needed
230uni_no_exc:
231 moveml USER_DA(%a6),%d0-%d1/%a0-%a1
232 fmovemx USER_FP0(%a6),%fp0-%fp3
233 fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
234 unlk %a6
235 bra finish_up
236|
237| Unsupported Data Type Handler:
238| Ovfl:
239| An fmoveout that results in an overflow is reported this way.
240| Unfl:
241| An fmoveout that results in an underflow is reported this way.
242|
243| Unimplemented Instruction Handler:
244| Ovfl:
245| Only scosh, setox, ssinh, stwotox, and scale can set overflow in
246| this manner.
247| Unfl:
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.
253|
254| The exceptional operand is in FP_SCR1.
255|
256ovfl_unfl:
257 tstb UFLG_TMP(%a6) |test flag for unsupp/unimp state
258 beqs ofuf_con
259|
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.
263|
264 tstb CU_ONLY(%a6) |test if inst is cu-only
265 beq unsE3
266| move.w
267 clrb CU_SAVEPC(%a6)
268 bsetb
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
273 bclrb
274 bra do_clean |go clean and exit
275
276ofuf_con:
277 moveb (%a7),VER_TMP(%a6) |save version number
278 cmpib
279 beqs busy_fr |if unimp, grow to busy
280 cmpib
281 bnes try_41 |if not, test for rev frame
282 moveql
283 bras ofuf_fin
284try_41:
285 cmpib
286 bnel fpsp_fmt_error |if neither, exit with error
287 moveql
288
289ofuf_fin:
290 clrl (%a7)
291loop1:
292 clrl -(%a7) |clear and dec a7
293 dbra %d0,loop1
294 moveb VER_TMP(%a6),(%a7)
295 moveb
296busy_fr:
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
301 bclrb
302 bclrb
303 movel USER_FPSR(%a6),FPSR_SHADOW(%a6)
304 orl
305 movel CMDREG1B(%a6),%d0 |fix cmd1b to make it
306 andl
307 bfextu CMDREG1B(%a6){
308 lsll
309 swap %d1
310 orl %d1,%d0 |put it in the right place
311 bfextu CMDREG1B(%a6){
312 lsll
313 swap %d1
314 orl %d1,%d0 |put them in the right place
315 movel %d0,CMDREG3B(%a6) |in the busy frame
316
317|
318| Check if the frame to be restored is busy or unimp.
319|** NOTE *** Bug fix for errata (0d43b
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.
327|
328do_clean:
329 cmpib
330 bnes do_con
331 moveql
332 bras do_build
333do_con:
334 cmpib
335 bnes do_restore |frame must be busy
336 moveql
337
338do_build:
339 moveb (%a7),VER_TMP(%a6)
340 clrl (%a7)
341loop2:
342 clrl -(%a7) |clear and dec a7
343 dbra %d0,loop2
344|
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.
348|
349| We need to set the nmcexc bits if the exception is E1. Otherwise,
350| the exc taken will be inex2.
351|
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
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
359| beq.b do_restore
360 bfextu USER_FPSR(%a6){
361 bfins %d0,NMCEXC(%a1){
362 movel USER_FPSR(%a6),FPSR_SHADOW(%a1) |set exc bits
363 orl
364
365do_restore:
366 moveml USER_DA(%a6),%d0-%d1/%a0-%a1
367 fmovemx USER_FP0(%a6),%fp0-%fp3
368 fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
369 frestore (%a7)+
370 tstb RES_FLG(%a6) |RES_FLG indicates a "continuation" frame
371 beq cont
372 bsr bug1384
373cont:
374 unlk %a6
375|
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.
381|
382finish_up:
383 btstb
384 bnes g_trace
385 btstb
386 bnes g_trace
387 bral fpsp_done
388|
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)
393|
394| If the current frame is already a 6-word stack then all
395| that needs to be done is to change the vector
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.
399|
400g_trace:
401 bftst EXC_VEC-4(%sp){
402 bne g_easy
403
404 subw
405 movel 4(%sp),(%sp)
406 movel 8(%sp),4(%sp)
407 subw
408 fsave (%sp)
409 fmovel %fpiar,BUSY_SIZE+EXC_EA-4(%sp)
410 frestore (%sp)
411 addw
412
413g_easy:
414 movew
415 bral real_trace
416|
417| This is a work-around for hardware bug 1384.
418|
419bug1384:
420 link %a5,
421 fsave -(%sp)
422 cmpib
423 beq frame_41
424 bgt nofix | if more advanced mask, do nada
425
426frame_40:
427 tstb 1(%sp) | check to see if idle
428 bne notidle
429idle40:
430 clrl (%sp) | get rid of old fsave frame
431 movel %d1,USER_D1(%a6) | save d1
432 movew
433loop40: clrl -(%sp)
434 dbra %d1,loop40
435 movel USER_D1(%a6),%d1 | restore d1
436 movel
437 frestore (%sp)+
438 unlk %a5
439 rts
440
441frame_41:
442 tstb 1(%sp) | check to see if idle
443 bne notidle
444idle41:
445 clrl (%sp) | get rid of old fsave frame
446 movel %d1,USER_D1(%a6) | save d1
447 movew
448loop41: clrl -(%sp)
449 dbra %d1,loop41
450 movel USER_D1(%a6),%d1 | restore d1
451 movel
452 frestore (%sp)+
453 unlk %a5
454 rts
455
456notidle:
457 bclrb
458 frestore (%sp)+
459 unlk %a5
460 rts
461
462nofix:
463 frestore (%sp)+
464 unlk %a5
465 rts
466
467 |end
468