source: rtems/c/src/lib/libcpu/m68k/m68040/fpsp/gen_except.s @ 6f9c75c3

4.104.114.84.95
Last change on this file since 6f9c75c3 was 6f9c75c3, checked in by Joel Sherrill <joel.sherrill@…>, on 01/16/98 at 16:56:48

Ralf Corsepius reported a number of missing CVS Id's:

RTEMS is under CVS control and has been since rtems 3.1.16 which was
around May 1995. So I just to add the $Id$. If you notice other files
with missing $Id$'s let me know. I try to keep w\up with it.

Now that you have asked -- I'll attach a list of files lacking an RCS-Id to
this mail. This list has been generated by a little sh-script I'll also
enclose.

  • Property mode set to 100644
File size: 13.3 KB
Line 
1//
2//      $Id$
3//
4//      gen_except.sa 3.7 1/16/92
5//
6//      gen_except --- FPSP routine to detect reportable exceptions
7//     
8//      This routine compares the exception enable byte of the
9//      user_fpcr on the stack with the exception status byte
10//      of the user_fpsr.
11//
12//      Any routine which may report an exceptions must load
13//      the stack frame in memory with the exceptional operand(s).
14//
15//      Priority for exceptions is:
16//
17//      Highest:        bsun
18//                      snan
19//                      operr
20//                      ovfl
21//                      unfl
22//                      dz
23//                      inex2
24//      Lowest:         inex1
25//
26//      Note: The IEEE standard specifies that inex2 is to be
27//      reported if ovfl occurs and the ovfl enable bit is not
28//      set but the inex2 enable bit is. 
29//
30//
31//              Copyright (C) Motorola, Inc. 1990
32//                      All Rights Reserved
33//
34//      THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MOTOROLA
35//      The copyright notice above does not evidence any 
36//      actual or intended publication of such source code.
37
38GEN_EXCEPT:    //idnt    2,1 | Motorola 040 Floating Point Software Package
39
40        |section 8
41
42#include "fpsp.defs"
43
44        |xref   real_trace
45        |xref   fpsp_done
46        |xref   fpsp_fmt_error
47
48exc_tbl:
49        .long   bsun_exc
50        .long   commonE1
51        .long   commonE1
52        .long   ovfl_unfl
53        .long   ovfl_unfl
54        .long   commonE1
55        .long   commonE3
56        .long   commonE3
57        .long   no_match
58
59        .global gen_except
60gen_except:
61        cmpib   #IDLE_SIZE-4,1(%a7)     //test for idle frame
62        beq     do_check                //go handle idle frame
63        cmpib   #UNIMP_40_SIZE-4,1(%a7) //test for orig unimp frame
64        beqs    unimp_x                 //go handle unimp frame
65        cmpib   #UNIMP_41_SIZE-4,1(%a7) //test for rev unimp frame
66        beqs    unimp_x                 //go handle unimp frame
67        cmpib   #BUSY_SIZE-4,1(%a7)     //if size <> $60, fmt error
68        bnel    fpsp_fmt_error
69        leal    BUSY_SIZE+LOCAL_SIZE(%a7),%a1 //init a1 so fpsp.h
70//                                      ;equates will work
71// Fix up the new busy frame with entries from the unimp frame
72//
73        movel   ETEMP_EX(%a6),ETEMP_EX(%a1) //copy etemp from unimp
74        movel   ETEMP_HI(%a6),ETEMP_HI(%a1) //frame to busy frame
75        movel   ETEMP_LO(%a6),ETEMP_LO(%a1)
76        movel   CMDREG1B(%a6),CMDREG1B(%a1) //set inst in frame to unimp
77        movel   CMDREG1B(%a6),%d0               //fix cmd1b to make it
78        andl    #0x03c30000,%d0         //work for cmd3b
79        bfextu  CMDREG1B(%a6){#13:#1},%d1       //extract bit 2
80        lsll    #5,%d1                 
81        swap    %d1
82        orl     %d1,%d0                 //put it in the right place
83        bfextu  CMDREG1B(%a6){#10:#3},%d1       //extract bit 3,4,5
84        lsll    #2,%d1
85        swap    %d1
86        orl     %d1,%d0                 //put them in the right place
87        movel   %d0,CMDREG3B(%a1)               //in the busy frame
88//
89// Or in the FPSR from the emulation with the USER_FPSR on the stack.
90//
91        fmovel  %FPSR,%d0               
92        orl     %d0,USER_FPSR(%a6)
93        movel   USER_FPSR(%a6),FPSR_SHADOW(%a1) //set exc bits
94        orl     #sx_mask,E_BYTE(%a1)
95        bra     do_clean
96
97//
98// Frame is an unimp frame possible resulting from an fmove <ea>,fp0
99// that caused an exception
100//
101// a1 is modified to point into the new frame allowing fpsp equates
102// to be valid.
103//
104unimp_x:
105        cmpib   #UNIMP_40_SIZE-4,1(%a7) //test for orig unimp frame
106        bnes    test_rev
107        leal    UNIMP_40_SIZE+LOCAL_SIZE(%a7),%a1
108        bras    unimp_con
109test_rev:
110        cmpib   #UNIMP_41_SIZE-4,1(%a7) //test for rev unimp frame
111        bnel    fpsp_fmt_error          //if not $28 or $30
112        leal    UNIMP_41_SIZE+LOCAL_SIZE(%a7),%a1
113       
114unimp_con:
115//
116// Fix up the new unimp frame with entries from the old unimp frame
117//
118        movel   CMDREG1B(%a6),CMDREG1B(%a1) //set inst in frame to unimp
119//
120// Or in the FPSR from the emulation with the USER_FPSR on the stack.
121//
122        fmovel  %FPSR,%d0               
123        orl     %d0,USER_FPSR(%a6)
124        bra     do_clean
125
126//
127// Frame is idle, so check for exceptions reported through
128// USER_FPSR and set the unimp frame accordingly. 
129// A7 must be incremented to the point before the
130// idle fsave vector to the unimp vector.
131//
132       
133do_check:
134        addl    #4,%a7                  //point A7 back to unimp frame
135//
136// Or in the FPSR from the emulation with the USER_FPSR on the stack.
137//
138        fmovel  %FPSR,%d0               
139        orl     %d0,USER_FPSR(%a6)
140//
141// On a busy frame, we must clear the nmnexc bits.
142//
143        cmpib   #BUSY_SIZE-4,1(%a7)     //check frame type
144        bnes    check_fr                //if busy, clr nmnexc
145        clrw    NMNEXC(%a6)             //clr nmnexc & nmcexc
146        btstb   #5,CMDREG1B(%a6)                //test for fmove out
147        bnes    frame_com
148        movel   USER_FPSR(%a6),FPSR_SHADOW(%a6) //set exc bits
149        orl     #sx_mask,E_BYTE(%a6)
150        bras    frame_com
151check_fr:
152        cmpb    #UNIMP_40_SIZE-4,1(%a7)
153        beqs    frame_com
154        clrw    NMNEXC(%a6)
155frame_com:
156        moveb   FPCR_ENABLE(%a6),%d0    //get fpcr enable byte
157        andb    FPSR_EXCEPT(%a6),%d0    //and in the fpsr exc byte
158        bfffo   %d0{#24:#8},%d1         //test for first set bit
159        leal    exc_tbl,%a0             //load jmp table address
160        subib   #24,%d1                 //normalize bit offset to 0-8
161        movel   (%a0,%d1.w*4),%a0               //load routine address based
162//                                      ;based on first enabled exc
163        jmp     (%a0)                   //jump to routine
164//
165// Bsun is not possible in unimp or unsupp
166//
167bsun_exc:
168        bra     do_clean
169//
170// The typical work to be done to the unimp frame to report an
171// exception is to set the E1/E3 byte and clr the U flag.
172// commonE1 does this for E1 exceptions, which are snan,
173// operr, and dz.  commonE3 does this for E3 exceptions, which
174// are inex2 and inex1, and also clears the E1 exception bit
175// left over from the unimp exception.
176//
177commonE1:
178        bsetb   #E1,E_BYTE(%a6)         //set E1 flag
179        bra     commonE                 //go clean and exit
180
181commonE3:
182        tstb    UFLG_TMP(%a6)           //test flag for unsup/unimp state
183        bnes    unsE3
184uniE3:
185        bsetb   #E3,E_BYTE(%a6)         //set E3 flag
186        bclrb   #E1,E_BYTE(%a6)         //clr E1 from unimp
187        bra     commonE
188
189unsE3:
190        tstb    RES_FLG(%a6)
191        bnes    unsE3_0
192unsE3_1:
193        bsetb   #E3,E_BYTE(%a6)         //set E3 flag
194unsE3_0:
195        bclrb   #E1,E_BYTE(%a6)         //clr E1 flag
196        movel   CMDREG1B(%a6),%d0
197        andl    #0x03c30000,%d0         //work for cmd3b
198        bfextu  CMDREG1B(%a6){#13:#1},%d1       //extract bit 2
199        lsll    #5,%d1                 
200        swap    %d1
201        orl     %d1,%d0                 //put it in the right place
202        bfextu  CMDREG1B(%a6){#10:#3},%d1       //extract bit 3,4,5
203        lsll    #2,%d1
204        swap    %d1
205        orl     %d1,%d0                 //put them in the right place
206        movel   %d0,CMDREG3B(%a6)               //in the busy frame
207
208commonE:
209        bclrb   #UFLAG,T_BYTE(%a6)      //clr U flag from unimp
210        bra     do_clean                //go clean and exit
211//
212// No bits in the enable byte match existing exceptions.  Check for
213// the case of the ovfl exc without the ovfl enabled, but with
214// inex2 enabled.
215//
216no_match:
217        btstb   #inex2_bit,FPCR_ENABLE(%a6) //check for ovfl/inex2 case
218        beqs    no_exc                  //if clear, exit
219        btstb   #ovfl_bit,FPSR_EXCEPT(%a6) //now check ovfl
220        beqs    no_exc                  //if clear, exit
221        bras    ovfl_unfl               //go to unfl_ovfl to determine if
222//                                      ;it is an unsupp or unimp exc
223       
224// No exceptions are to be reported.  If the instruction was
225// unimplemented, no FPU restore is necessary.  If it was
226// unsupported, we must perform the restore.
227no_exc:
228        tstb    UFLG_TMP(%a6)   //test flag for unsupp/unimp state
229        beqs    uni_no_exc
230uns_no_exc:
231        tstb    RES_FLG(%a6)    //check if frestore is needed
232        bne     do_clean        //if clear, no frestore needed
233uni_no_exc:
234        moveml  USER_DA(%a6),%d0-%d1/%a0-%a1
235        fmovemx USER_FP0(%a6),%fp0-%fp3
236        fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
237        unlk    %a6
238        bra     finish_up
239//
240// Unsupported Data Type Handler:
241// Ovfl:
242//   An fmoveout that results in an overflow is reported this way.
243// Unfl:
244//   An fmoveout that results in an underflow is reported this way.
245//
246// Unimplemented Instruction Handler:
247// Ovfl:
248//   Only scosh, setox, ssinh, stwotox, and scale can set overflow in
249//   this manner.
250// Unfl:
251//   Stwotox, setox, and scale can set underflow in this manner.
252//   Any of the other Library Routines such that f(x)=x in which
253//   x is an extended denorm can report an underflow exception.
254//   It is the responsibility of the exception-causing exception
255//   to make sure that WBTEMP is correct.
256//
257//   The exceptional operand is in FP_SCR1.
258//
259ovfl_unfl:
260        tstb    UFLG_TMP(%a6)   //test flag for unsupp/unimp state
261        beqs    ofuf_con
262//
263// The caller was from an unsupported data type trap.  Test if the
264// caller set CU_ONLY.  If so, the exceptional operand is expected in
265// FPTEMP, rather than WBTEMP.
266//
267        tstb    CU_ONLY(%a6)            //test if inst is cu-only
268        beq     unsE3
269//      move.w  #$fe,CU_SAVEPC(%a6)
270        clrb    CU_SAVEPC(%a6)
271        bsetb   #E1,E_BYTE(%a6)         //set E1 exception flag
272        movew   ETEMP_EX(%a6),FPTEMP_EX(%a6)
273        movel   ETEMP_HI(%a6),FPTEMP_HI(%a6)
274        movel   ETEMP_LO(%a6),FPTEMP_LO(%a6)
275        bsetb   #fptemp15_bit,DTAG(%a6) //set fpte15
276        bclrb   #UFLAG,T_BYTE(%a6)      //clr U flag from unimp
277        bra     do_clean                //go clean and exit
278
279ofuf_con:
280        moveb   (%a7),VER_TMP(%a6)      //save version number
281        cmpib   #BUSY_SIZE-4,1(%a7)     //check for busy frame
282        beqs    busy_fr                 //if unimp, grow to busy
283        cmpib   #VER_40,(%a7)           //test for orig unimp frame
284        bnes    try_41                  //if not, test for rev frame
285        moveql  #13,%d0                 //need to zero 14 lwords
286        bras    ofuf_fin
287try_41:
288        cmpib   #VER_41,(%a7)           //test for rev unimp frame
289        bnel    fpsp_fmt_error          //if neither, exit with error
290        moveql  #11,%d0                 //need to zero 12 lwords
291
292ofuf_fin:
293        clrl    (%a7)
294loop1:
295        clrl    -(%a7)                  //clear and dec a7
296        dbra    %d0,loop1
297        moveb   VER_TMP(%a6),(%a7)
298        moveb   #BUSY_SIZE-4,1(%a7)             //write busy fmt word.
299busy_fr:
300        movel   FP_SCR1(%a6),WBTEMP_EX(%a6)     //write
301        movel   FP_SCR1+4(%a6),WBTEMP_HI(%a6)   //exceptional op to
302        movel   FP_SCR1+8(%a6),WBTEMP_LO(%a6)   //wbtemp
303        bsetb   #E3,E_BYTE(%a6)                 //set E3 flag
304        bclrb   #E1,E_BYTE(%a6)                 //make sure E1 is clear
305        bclrb   #UFLAG,T_BYTE(%a6)              //clr U flag
306        movel   USER_FPSR(%a6),FPSR_SHADOW(%a6)
307        orl     #sx_mask,E_BYTE(%a6)
308        movel   CMDREG1B(%a6),%d0               //fix cmd1b to make it
309        andl    #0x03c30000,%d0         //work for cmd3b
310        bfextu  CMDREG1B(%a6){#13:#1},%d1       //extract bit 2
311        lsll    #5,%d1                 
312        swap    %d1
313        orl     %d1,%d0                 //put it in the right place
314        bfextu  CMDREG1B(%a6){#10:#3},%d1       //extract bit 3,4,5
315        lsll    #2,%d1
316        swap    %d1
317        orl     %d1,%d0                 //put them in the right place
318        movel   %d0,CMDREG3B(%a6)               //in the busy frame
319
320//
321// Check if the frame to be restored is busy or unimp.
322//** NOTE *** Bug fix for errata (0d43b #3)
323// If the frame is unimp, we must create a busy frame to
324// fix the bug with the nmnexc bits in cases in which they
325// are set by a previous instruction and not cleared by
326// the save. The frame will be unimp only if the final
327// instruction in an emulation routine caused the exception
328// by doing an fmove <ea>,fp0.  The exception operand, in
329// internal format, is in fptemp.
330//
331do_clean:
332        cmpib   #UNIMP_40_SIZE-4,1(%a7)
333        bnes    do_con
334        moveql  #13,%d0                 //in orig, need to zero 14 lwords
335        bras    do_build
336do_con:
337        cmpib   #UNIMP_41_SIZE-4,1(%a7)
338        bnes    do_restore              //frame must be busy
339        moveql  #11,%d0                 //in rev, need to zero 12 lwords
340
341do_build:
342        moveb   (%a7),VER_TMP(%a6)
343        clrl    (%a7)
344loop2:
345        clrl    -(%a7)                  //clear and dec a7
346        dbra    %d0,loop2
347//
348// Use a1 as pointer into new frame.  a6 is not correct if an unimp or
349// busy frame was created as the result of an exception on the final
350// instruction of an emulation routine.
351//
352// We need to set the nmcexc bits if the exception is E1. Otherwise,
353// the exc taken will be inex2.
354//
355        leal    BUSY_SIZE+LOCAL_SIZE(%a7),%a1   //init a1 for new frame
356        moveb   VER_TMP(%a6),(%a7)      //write busy fmt word
357        moveb   #BUSY_SIZE-4,1(%a7)
358        movel   FP_SCR1(%a6),WBTEMP_EX(%a1)     //write
359        movel   FP_SCR1+4(%a6),WBTEMP_HI(%a1)   //exceptional op to
360        movel   FP_SCR1+8(%a6),WBTEMP_LO(%a1)   //wbtemp
361//      btst.b  #E1,E_BYTE(%a1)
362//      beq.b   do_restore
363        bfextu  USER_FPSR(%a6){#17:#4},%d0      //get snan/operr/ovfl/unfl bits
364        bfins   %d0,NMCEXC(%a1){#4:#4}  //and insert them in nmcexc
365        movel   USER_FPSR(%a6),FPSR_SHADOW(%a1) //set exc bits
366        orl     #sx_mask,E_BYTE(%a1)
367       
368do_restore:
369        moveml  USER_DA(%a6),%d0-%d1/%a0-%a1
370        fmovemx USER_FP0(%a6),%fp0-%fp3
371        fmoveml USER_FPCR(%a6),%fpcr/%fpsr/%fpiar
372        frestore (%a7)+
373        tstb    RES_FLG(%a6)    //RES_FLG indicates a "continuation" frame
374        beq     cont
375        bsr     bug1384
376cont:
377        unlk    %a6
378//
379// If trace mode enabled, then go to trace handler.  This handler
380// cannot have any fp instructions.  If there are fp inst's and an
381// exception has been restored into the machine then the exception
382// will occur upon execution of the fp inst.  This is not desirable
383// in the kernel (supervisor mode).  See MC68040 manual Section 9.3.8.
384//
385finish_up:
386        btstb   #7,(%a7)                //test T1 in SR
387        bnes    g_trace
388        btstb   #6,(%a7)                //test T0 in SR
389        bnes    g_trace
390        bral    fpsp_done
391//
392// Change integer stack to look like trace stack
393// The address of the instruction that caused the
394// exception is already in the integer stack (is
395// the same as the saved friar)
396//
397// If the current frame is already a 6-word stack then all
398// that needs to be done is to change the vector# to TRACE.
399// If the frame is only a 4-word stack (meaning we got here
400// on an Unsupported data type exception), then we need to grow
401// the stack an extra 2 words and get the FPIAR from the FPU.
402//
403g_trace:
404        bftst   EXC_VEC-4(%sp){#0:#4}
405        bne     g_easy
406
407        subw    #4,%sp          // make room
408        movel   4(%sp),(%sp)
409        movel   8(%sp),4(%sp)
410        subw    #BUSY_SIZE,%sp
411        fsave   (%sp)
412        fmovel  %fpiar,BUSY_SIZE+EXC_EA-4(%sp)
413        frestore (%sp)
414        addw    #BUSY_SIZE,%sp
415
416g_easy:
417        movew   #TRACE_VEC,EXC_VEC-4(%a7)
418        bral    real_trace
419//
420//  This is a work-around for hardware bug 1384.
421//
422bug1384:
423        link    %a5,#0
424        fsave   -(%sp)
425        cmpib   #0x41,(%sp)     // check for correct frame
426        beq     frame_41
427        bgt     nofix           // if more advanced mask, do nada
428
429frame_40:
430        tstb    1(%sp)          // check to see if idle
431        bne     notidle
432idle40:
433        clrl    (%sp)           // get rid of old fsave frame
434        movel  %d1,USER_D1(%a6)  // save d1
435        movew   #8,%d1          // place unimp frame instead
436loop40: clrl    -(%sp)
437        dbra    %d1,loop40
438        movel  USER_D1(%a6),%d1  // restore d1
439        movel   #0x40280000,-(%sp)
440        frestore (%sp)+
441        unlk    %a5     
442        rts
443
444frame_41:
445        tstb    1(%sp)          // check to see if idle
446        bne     notidle
447idle41:
448        clrl    (%sp)           // get rid of old fsave frame
449        movel  %d1,USER_D1(%a6)  // save d1
450        movew   #10,%d1         // place unimp frame instead
451loop41: clrl    -(%sp)
452        dbra    %d1,loop41
453        movel  USER_D1(%a6),%d1  // restore d1
454        movel   #0x41300000,-(%sp)
455        frestore (%sp)+
456        unlk    %a5     
457        rts
458
459notidle:
460        bclrb   #etemp15_bit,-40(%a5)
461        frestore (%sp)+
462        unlk    %a5     
463        rts
464
465nofix:
466        frestore (%sp)+
467        unlk    %a5     
468        rts
469
470        |end
Note: See TracBrowser for help on using the repository browser.