OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libcpu/] [m68k/] [m68040/] [fpsp/] [gen_except.S] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
//
2
//      $Id: gen_except.S,v 1.2 2001-09-27 12:01:22 chris Exp $
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
 
38
GEN_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
 
48
exc_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
60
gen_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 ,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
//
104
unimp_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
109
test_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
 
114
unimp_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
 
133
do_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
151
check_fr:
152
        cmpb    #UNIMP_40_SIZE-4,1(%a7)
153
        beqs    frame_com
154
        clrw    NMNEXC(%a6)
155
frame_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
//
167
bsun_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
//
177
commonE1:
178
        bsetb   #E1,E_BYTE(%a6)         //set E1 flag
179
        bra     commonE                 //go clean and exit
180
 
181
commonE3:
182
        tstb    UFLG_TMP(%a6)           //test flag for unsup/unimp state
183
        bnes    unsE3
184
uniE3:
185
        bsetb   #E3,E_BYTE(%a6)         //set E3 flag
186
        bclrb   #E1,E_BYTE(%a6)         //clr E1 from unimp
187
        bra     commonE
188
 
189
unsE3:
190
        tstb    RES_FLG(%a6)
191
        bnes    unsE3_0
192
unsE3_1:
193
        bsetb   #E3,E_BYTE(%a6)         //set E3 flag
194
unsE3_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
 
208
commonE:
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
//
216
no_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.
227
no_exc:
228
        tstb    UFLG_TMP(%a6)   //test flag for unsupp/unimp state
229
        beqs    uni_no_exc
230
uns_no_exc:
231
        tstb    RES_FLG(%a6)    //check if frestore is needed
232
        bne     do_clean        //if clear, no frestore needed
233
uni_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
//
259
ovfl_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
 
279
ofuf_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
287
try_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
 
292
ofuf_fin:
293
        clrl    (%a7)
294
loop1:
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.
299
busy_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 ,fp0.  The exception operand, in
329
// internal format, is in fptemp.
330
//
331
do_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
336
do_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
 
341
do_build:
342
        moveb   (%a7),VER_TMP(%a6)
343
        clrl    (%a7)
344
loop2:
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
 
368
do_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
376
cont:
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
//
385
finish_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
//
403
g_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
 
416
g_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
//
422
bug1384:
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
 
429
frame_40:
430
        tstb    1(%sp)          // check to see if idle
431
        bne     notidle
432
idle40:
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
436
loop40: 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
 
444
frame_41:
445
        tstb    1(%sp)          // check to see if idle
446
        bne     notidle
447
idle41:
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
451
loop41: 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
 
459
notidle:
460
        bclrb   #etemp15_bit,-40(%a5)
461
        frestore (%sp)+
462
        unlk    %a5
463
        rts
464
 
465
nofix:
466
        frestore (%sp)+
467
        unlk    %a5
468
        rts
469
 
470
        |end

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.