2 | skeleton.sa 3.2 4/26/91
4 | This file contains code that is system dependent and will
5 | need to be modified to install the FPSP.
7 | Each entry point for exception 'xxxx' begins with a 'jmp fpsp_xxxx'.
8 | Put any target system specific handling that must be done immediately
9 | before the jump instruction. If there no handling necessary, then
10 | the 'fpsp_xxxx' handler entry point should be placed in the exception
11 | table so that the 'jmp' can be eliminated. If the FPSP determines that the
12 | exception is one that must be reported then there will be a
13 | return from the package by a 'jmp real_xxxx'. At that point
14 | the machine state will be identical to the state before
15 | the FPSP was entered. In particular, whatever condition
16 | that caused the exception will still be pending when the FPSP
17 | package returns. Thus, there will be system specific code
18 | to handle the exception.
20 | If the exception was completely handled by the package, then
21 | the return will be via a 'jmp fpsp_done'. Unless there is
22 | OS specific work to be done (such as handling a context switch or
23 | interrupt) the user program can be resumed via 'rte'.
25 | In the following skeleton code, some typical 'real_xxxx' handling
26 | code is shown. This code may need to be moved to an appropriate
27 | place in the target system, or rewritten.
30 | Copyright (C) Motorola, Inc. 1990
33 | THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MOTOROLA
34 | The copyright notice above does not evidence any
35 | actual or intended publication of such source code.
38 | Modified for Linux-1.3.x by Jes Sorensen (jds@kom.auc.dk)
41 #include <linux/linkage.h>
42 #include <asm/entry.h>
44 |SKELETON idnt 2,1 | Motorola 040 Floating Point Software Package
48 | The following counters are used for standalone testing
58 | Divide by Zero exception
60 | All dz exceptions are 'real', hence no fpsp_dz entry point.
74 movel %sp,%sp@- | stack frame pointer argument
75 bsrl SYMBOL_NAME(trap_c)
77 bral SYMBOL_NAME(ret_from_exception)
82 | All inexact exceptions are real, but the 'real' handler
83 | will probably want to clear the pending exception.
84 | The provided code will clear the E3 exception (if pending),
85 | otherwise clear the E1 exception. The frestore is not really
86 | necessary for E1 exceptions.
88 | Code following the 'inex' label is to handle bug #1232. In this
89 | bug, if an E1 snan, ovfl, or unfl occurred, and the process was
90 | swapped out before taking the exception, the exception taken on
91 | return was inex, rather than the correct exception. The snan, ovfl,
92 | and unfl exception to be taken must not have been enabled. The
93 | fix is to check for E1, and the existence of one of snan, ovfl,
94 | or unfl bits set in the fpsr. If any of these are set, branch
95 | to the appropriate handler for the exception in the fpsr. Note
96 | that this fix is only for d43b parts, and is skipped if the
97 | version number is not $40.
103 link %a6,#-LOCAL_SIZE
105 cmpib #VER_40,(%sp) |test version number
108 btstb #E1,E_BYTE(%a6) |test for E1 set
110 btstb #snan_bit,2(%sp) |test for snan
117 btstb #ovfl_bit,2(%sp) |test for ovfl
124 btstb #unfl_bit,2(%sp) |test for unfl
132 | We do not have the bug 1232 case. Clean up the stack and call
142 link %a6,#-LOCAL_SIZE
145 bclrb #E3,E_BYTE(%a6) |clear and test E3 flag
148 | Clear dirty bit on dest resister in the frame before branching
151 moveml %d0/%d1,USER_DA(%a6)
152 bfextu CMDREG1B(%a6){#6:#3},%d0 |get dest reg no
153 bclrb %d0,FPR_DIRTY_BITS(%a6) |clr dest dirty bit
154 bsrl b1238_fix |test for bug1238 case
155 moveml USER_DA(%a6),%d0/%d1
158 bclrb #E1,E_BYTE(%a6)
165 movel %sp,%sp@- | stack frame pointer argument
166 bsrl SYMBOL_NAME(trap_c)
168 bral SYMBOL_NAME(ret_from_exception)
180 link %a6,#-LOCAL_SIZE
182 bclrb #E3,E_BYTE(%a6) |clear and test E3 flag
184 bclrb #E1,E_BYTE(%a6)
191 movel %sp,%sp@- | stack frame pointer argument
192 bsrl SYMBOL_NAME(trap_c)
194 bral SYMBOL_NAME(ret_from_exception)
197 | Underflow exception
206 link %a6,#-LOCAL_SIZE
208 bclrb #E3,E_BYTE(%a6) |clear and test E3 flag
210 bclrb #E1,E_BYTE(%a6)
217 movel %sp,%sp@- | stack frame pointer argument
218 bsrl SYMBOL_NAME(trap_c)
220 bral SYMBOL_NAME(ret_from_exception)
223 | Signalling NAN exception
231 link %a6,#-LOCAL_SIZE
233 bclrb #E1,E_BYTE(%a6) |snan is always an E1 exception
239 movel %sp,%sp@- | stack frame pointer argument
240 bsrl SYMBOL_NAME(trap_c)
242 bral SYMBOL_NAME(ret_from_exception)
245 | Operand Error exception
253 link %a6,#-LOCAL_SIZE
255 bclrb #E1,E_BYTE(%a6) |operr is always an E1 exception
261 movel %sp,%sp@- | stack frame pointer argument
262 bsrl SYMBOL_NAME(trap_c)
264 bral SYMBOL_NAME(ret_from_exception)
270 | This sample handler simply clears the nan bit in the FPSR.
278 link %a6,#-LOCAL_SIZE
280 bclrb #E1,E_BYTE(%a6) |bsun is always an E1 exception
289 movel %sp,%sp@- | stack frame pointer argument
290 bsrl SYMBOL_NAME(trap_c)
292 bral SYMBOL_NAME(ret_from_exception)
297 | A 'real' F-line exception is one that the FPSP isn't supposed to
298 | handle. E.g. an instruction with a co-processor ID that is not 1.
310 movel %sp,%sp@- | stack frame pointer argument
311 bsrl SYMBOL_NAME(trap_c)
313 bral SYMBOL_NAME(ret_from_exception)
316 | Unsupported data type exception
324 link %a6,#-LOCAL_SIZE
326 bclrb #E1,E_BYTE(%a6) |unsupp is always an E1 exception
332 movel %sp,%sp@- | stack frame pointer argument
333 bsrl SYMBOL_NAME(trap_c)
335 bral SYMBOL_NAME(ret_from_exception)
343 bral SYMBOL_NAME(trap)
346 | fpsp_fmt_error --- exit point for frame format error
348 | The fpu stack frame does not match the frames existing
349 | or planned at the time of this writing. The fpsp is
350 | unable to handle frame sizes not in the following
351 | version:size pairs:
353 | {4060, 4160} - busy frame
354 | {4028, 4130} - unimp frame
355 | {4000, 4100} - idle frame
357 | This entry point simply holds an f-line illegal value.
358 | Replace this with a call to your kernel panic code or
359 | code to handle future revisions of the fpu.
361 .global fpsp_fmt_error
364 .long 0xf27f0000 |f-line illegal
367 | fpsp_done --- FPSP exit point
369 | The exception has been handled by the package and we are ready
370 | to return to user mode, but there may be OS specific code
371 | to execute before we do. If there is, do it now.
377 btst #0x5,%sp@ | supervisor bit set in saved SR?
383 tstl %curptr@(LTASK_NEEDRESCHED)
384 jne SYMBOL_NAME(ret_from_exception) | deliver signals,
389 | mem_write --- write to user or supervisor address space
391 | Writes to memory while in supervisor mode. copyout accomplishes
392 | this via a 'moves' instruction. copyout is a UNIX SVR3 (and later) function.
393 | If you don't have copyout, use the local copy of the function below.
395 | a0 - supervisor source address
396 | a1 - user destination address
397 | d0 - number of bytes to write (maximum count is 12)
399 | The supervisor source address is guaranteed to point into the supervisor
400 | stack. The result is that a UNIX
401 | process is allowed to sleep as a consequence of a page fault during
402 | copyout. The probability of a page fault is exceedingly small because
403 | the 68040 always reads the destination address and thus the page
404 | faults should have already been handled.
406 | If the EXC_SR shows that the exception was from supervisor space,
407 | then just do a dumb (and slow) memory move. In a UNIX environment
408 | there shouldn't be any supervisor mode floating point exceptions.
412 btstb #5,EXC_SR(%a6) |check for supervisor state
420 movel %d1,-(%sp) |preserve d1 just in case
429 | mem_read --- read from user or supervisor address space
431 | Reads from memory while in supervisor mode. copyin accomplishes
432 | this via a 'moves' instruction. copyin is a UNIX SVR3 (and later) function.
433 | If you don't have copyin, use the local copy of the function below.
435 | The FPSP calls mem_read to read the original F-line instruction in order
436 | to extract the data register number when the 'Dn' addressing mode is
440 | a0 - user source address
441 | a1 - supervisor destination address
442 | d0 - number of bytes to read (maximum count is 12)
444 | Like mem_write, mem_read always reads with a supervisor
445 | destination address on the supervisor stack. Also like mem_write,
446 | the EXC_SR is checked and a simple memory copy is done if reading
447 | from supervisor space is indicated.
451 btstb #5,EXC_SR(%a6) |check for supervisor state
459 movel %d1,-(%sp) |preserve d1 just in case
469 | Use these routines if your kernel doesn't have copyout/copyin equivalents.
470 | Assumes that D0/D1/A0/A1 are scratch registers. copyout overwrites DFC,
471 | and copyin overwrites SFC.
474 movel 4(%sp),%a0 | source
475 movel 8(%sp),%a1 | destination
476 movel 12(%sp),%d0 | count
477 subl #1,%d0 | dec count by 1 for dbra
481 | movec %d1,%DFC | set dfc for user data space
483 moveb (%a0)+,%d1 | fetch supervisor byte
485 movesb %d1,(%a1)+ | write user byte
490 movel 4(%sp),%a0 | source
491 movel 8(%sp),%a1 | destination
492 movel 12(%sp),%d0 | count
493 subl #1,%d0 | dec count by 1 for dbra
496 | movec %d1,%SFC | set sfc for user space
499 movesb (%a0)+,%d1 | fetch user byte
500 moveb %d1,(%a1)+ | write supervisor byte
504 .section .fixup,#alloc,#execinstr
507 jbra SYMBOL_NAME(fpsp040_die)
509 .section __ex_table,#alloc