1 * $NetBSD: netbsd.sa,v 1.4 2001/09/16 16:34:32 wiz Exp $
3 * MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
4 * M68000 Hi-Performance Microprocessor Division
5 * M68040 Software Package
7 * M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
10 * THE SOFTWARE is provided on an "AS IS" basis and without warranty.
11 * To the maximum extent permitted by applicable law,
12 * MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
13 * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
14 * PARTICULAR PURPOSE and any warranty against infringement with
15 * regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
16 * and any accompanying written materials.
18 * To the maximum extent permitted by applicable law,
19 * IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
20 * (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
21 * PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
22 * OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
23 * SOFTWARE. Motorola assumes no responsibility for the maintenance
24 * and support of the SOFTWARE.
26 * You are hereby granted a copyright license to use, modify, and
27 * distribute the SOFTWARE so long as this entire notice is retained
28 * without alteration in any modified and/or redistributed versions,
29 * and that such modified versions are clearly identified as such.
30 * No licenses are granted by implication, estoppel or otherwise
31 * under any patents or trademarks of Motorola, Inc.
34 * skeleton.sa 3.2 4/26/91
36 * This file contains code that is system dependent and will
37 * need to be modified to install the FPSP.
39 * Each entry point for exception 'xxxx' begins with a 'jmp fpsp_xxxx'.
40 * Put any target system specific handling that must be done immediately
41 * before the jump instruction. If there no handling necessary, then
42 * the 'fpsp_xxxx' handler entry point should be placed in the exception
43 * table so that the 'jmp' can be eliminated. If the FPSP determines that the
44 * exception is one that must be reported then there will be a
45 * return from the package by a 'jmp real_xxxx'. At that point
46 * the machine state will be identical to the state before
47 * the FPSP was entered. In particular, whatever condition
48 * that caused the exception will still be pending when the FPSP
49 * package returns. Thus, there will be system specific code
50 * to handle the exception.
52 * If the exception was completely handled by the package, then
53 * the return will be via a 'jmp fpsp_done'. Unless there is
54 * OS specific work to be done (such as handling a context switch or
55 * interrupt) the user program can be resumed via 'rte'.
57 * In the following skeleton code, some typical 'real_xxxx' handling
58 * code is shown. This code may need to be moved to an appropriate
59 * place in the target system, or rewritten.
62 SKELETON IDNT 2,1 Motorola 040 Floating Point Software Package
66 * The following counters are used for standalone testing
74 * XXX Note, this is NOT valid Motorola syntax, but what else can we do?
76 #include <machine/asm.h>
79 xref _C_LABEL(mmutype)
82 * Divide by Zero exception
84 * All dz exceptions are 'real', hence no fpsp_dz entry point.
89 cmp.l #-2,_C_LABEL(mmutype)
90 bne.l _C_LABEL(fpfault)
102 * All inexact exceptions are real, but the 'real' handler
103 * will probably want to clear the pending exception.
104 * The provided code will clear the E3 exception (if pending),
105 * otherwise clear the E1 exception. The frestore is not really
106 * necessary for E1 exceptions.
108 * Code following the 'inex' label is to handle bug #1232. In this
109 * bug, if an E1 snan, ovfl, or unfl occurred, and the process was
110 * swapped out before taking the exception, the exception taken on
111 * return was inex, rather than the correct exception. The snan, ovfl,
112 * and unfl exception to be taken must not have been enabled. The
113 * fix is to check for E1, and the existence of one of snan, ovfl,
114 * or unfl bits set in the fpsr. If any of these are set, branch
115 * to the appropriate handler for the exception in the fpsr. Note
116 * that this fix is only for d43b parts, and is skipped if the
117 * version number is not $40.
123 cmp.l #-2,_C_LABEL(mmutype)
124 bne.l _C_LABEL(fpfault)
127 cmpi.b #VER_40,(sp) ;test version number
130 btst.b #E1,E_BYTE(a6) ;test for E1 set
132 btst.b #snan_bit,2(sp) ;test for snan
139 btst.b #ovfl_bit,2(sp) ;test for ovfl
146 btst.b #unfl_bit,2(sp) ;test for unfl
154 * We do not have the bug 1232 case. Clean up the stack and call
166 bclr.b #E3,E_BYTE(a6) ;clear and test E3 flag
169 * Clear dirty bit on dest resister in the frame before branching
172 movem.l d0/d1,USER_DA(a6)
173 bfextu CMDREG1B(a6){6:3},d0 ;get dest reg no
174 bclr.b d0,FPR_DIRTY_BITS(a6) ;clr dest dirty bit
175 bsr.l b1238_fix ;test for bug1238 case
176 movem.l USER_DA(a6),d0/d1
179 bclr.b #E1,E_BYTE(a6)
183 jmp _C_LABEL(fpfault)
192 cmp.l #-2,_C_LABEL(mmutype)
194 jmp _C_LABEL(fpfault)
198 bclr.b #E3,E_BYTE(a6) ;clear and test E3 flag
200 bclr.b #E1,E_BYTE(a6)
204 jmp _C_LABEL(fpfault)
207 * Underflow exception
213 cmp.l #-2,_C_LABEL(mmutype)
215 jmp _C_LABEL(fpfault)
219 bclr.b #E3,E_BYTE(a6) ;clear and test E3 flag
221 bclr.b #E1,E_BYTE(a6)
225 jmp _C_LABEL(fpfault)
228 * Signalling NAN exception
234 cmp.l #-2,_C_LABEL(mmutype)
236 jmp _C_LABEL(fpfault)
240 bclr.b #E1,E_BYTE(a6) ;snan is always an E1 exception
243 jmp _C_LABEL(fpfault)
246 * Operand Error exception
252 cmp.l #-2,_C_LABEL(mmutype)
254 jmp _C_LABEL(fpfault)
258 bclr.b #E1,E_BYTE(a6) ;operr is always an E1 exception
261 jmp _C_LABEL(fpfault)
266 * This sample handler simply clears the nan bit in the FPSR.
272 cmp.l #-2,_C_LABEL(mmutype)
274 jmp _C_LABEL(fpfault)
278 bclr.b #E1,E_BYTE(a6) ;bsun is always an E1 exception
284 jmp _C_LABEL(fpfault)
289 * A 'real' F-line exception is one that the FPSP isn't supposed to
290 * handle. E.g. an instruction with a co-processor ID that is not 1.
297 cmp.l #-2,_C_LABEL(mmutype)
299 jmp _C_LABEL(fpfault)
301 jmp _C_LABEL(fpfault)
304 * Unsupported data type exception
310 cmp.l #-2,_C_LABEL(mmutype)
312 jmp _C_LABEL(fpfault)
316 bclr.b #E1,E_BYTE(a6) ;unsupp is always an E1 exception
319 jmp _C_LABEL(fpfault)
329 * fpsp_fmt_error --- exit point for frame format error
331 * The fpu stack frame does not match the frames existing
332 * or planned at the time of this writing. The fpsp is
333 * unable to handle frame sizes not in the following
334 * version:size pairs:
336 * {4060, 4160} - busy frame
337 * {4028, 4130} - unimp frame
338 * {4000, 4100} - idle frame
340 * This entry point simply holds an f-line illegal value.
341 * Replace this with a call to your kernel panic code or
342 * code to handle future revisions of the fpu.
348 dc.l $f27f0000 ;f-line illegal
350 .asciz "bad floating point stack frame"
354 * fpsp_done --- FPSP exit point
356 * The exception has been handled by the package and we are ready
357 * to return to user mode, but there may be OS specific code
358 * to execute before we do. If there is, do it now.
367 * mem_write --- write to user or supervisor address space
369 * Writes to memory while in supervisor mode. copyout accomplishes
370 * this via a 'moves' instruction. copyout is a UNIX SVR3 (and later) function.
371 * If you don't have copyout, use the local copy of the function below.
373 * a0 - supervisor source address
374 * a1 - user destination address
375 * d0 - number of bytes to write (maximum count is 12)
377 * The supervisor source address is guaranteed to point into the supervisor
378 * stack. The result is that a UNIX
379 * process is allowed to sleep as a consequence of a page fault during
380 * copyout. The probability of a page fault is exceedingly small because
381 * the 68040 always reads the destination address and thus the page
382 * faults should have already been handled.
384 * If the EXC_SR shows that the exception was from supervisor space,
385 * then just do a dumb (and slow) memory move. In a UNIX environment
386 * there shouldn't be any supervisor mode floating point exceptions.
390 btst.b #5,EXC_SR(a6) ;check for supervisor state
398 move.l d1,-(sp) ;preserve d1 just in case
402 jsr _C_LABEL(copyout)
408 * mem_read --- read from user or supervisor address space
410 * Reads from memory while in supervisor mode. copyin accomplishes
411 * this via a 'moves' instruction. copyin is a UNIX SVR3 (and later) function.
412 * If you don't have copyin, use the local copy of the function below.
414 * The FPSP calls mem_read to read the original F-line instruction in order
415 * to extract the data register number when the 'Dn' addressing mode is
419 * a0 - user source address
420 * a1 - supervisor destination address
421 * d0 - number of bytes to read (maximum count is 12)
423 * Like mem_write, mem_read always reads with a supervisor
424 * destination address on the supervisor stack. Also like mem_write,
425 * the EXC_SR is checked and a simple memory copy is done if reading
426 * from supervisor space is indicated.
430 btst.b #5,EXC_SR(a6) ;check for supervisor state
438 move.l d1,-(sp) ;preserve d1 just in case