1 * $NetBSD: skeleton.sa,v 1.3 1994/10/26 07:49:50 cgd 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
85 * Divide by Zero exception
87 * All dz exceptions are 'real', hence no fpsp_dz entry point.
99 add.l #1,sigdz ;for standalone testing
105 * All inexact exceptions are real, but the 'real' handler
106 * will probably want to clear the pending exception.
107 * The provided code will clear the E3 exception (if pending),
108 * otherwise clear the E1 exception. The frestore is not really
109 * necessary for E1 exceptions.
111 * Code following the 'inex' label is to handle bug #1232. In this
112 * bug, if an E1 snan, ovfl, or unfl occurred, and the process was
113 * swapped out before taking the exception, the exception taken on
114 * return was inex, rather than the correct exception. The snan, ovfl,
115 * and unfl exception to be taken must not have been enabled. The
116 * fix is to check for E1, and the existence of one of snan, ovfl,
117 * or unfl bits set in the fpsr. If any of these are set, branch
118 * to the appropriate handler for the exception in the fpsr. Note
119 * that this fix is only for d43b parts, and is skipped if the
120 * version number is not $40.
128 cmpi.b #VER_40,(sp) ;test version number
131 btst.b #E1,E_BYTE(a6) ;test for E1 set
133 btst.b #snan_bit,2(sp) ;test for snan
140 btst.b #ovfl_bit,2(sp) ;test for ovfl
147 btst.b #unfl_bit,2(sp) ;test for unfl
155 * We do not have the bug 1232 case. Clean up the stack and call
165 add.l #1,siginex ;for standalone testing
170 bclr.b #E3,E_BYTE(a6) ;clear and test E3 flag
173 * Clear dirty bit on dest resister in the frame before branching
176 movem.l d0/d1,USER_DA(a6)
177 bfextu CMDREG1B(a6){6:3},d0 ;get dest reg no
178 bclr.b d0,FPR_DIRTY_BITS(a6) ;clr dest dirty bit
179 bsr.l b1238_fix ;test for bug1238 case
180 movem.l USER_DA(a6),d0/d1
183 bclr.b #E1,E_BYTE(a6)
199 add.l #1,sigovfl ;for standalone testing
203 bclr.b #E3,E_BYTE(a6) ;clear and test E3 flag
205 bclr.b #E1,E_BYTE(a6)
212 * Underflow exception
221 add.l #1,sigunfl ;for standalone testing
225 bclr.b #E3,E_BYTE(a6) ;clear and test E3 flag
227 bclr.b #E1,E_BYTE(a6)
234 * Signalling NAN exception
244 bclr.b #E1,E_BYTE(a6) ;snan is always an E1 exception
248 add.l #1,sigsnan ;for standalone testing
252 * Operand Error exception
262 bclr.b #E1,E_BYTE(a6) ;operr is always an E1 exception
266 add.l #1,sigoperr ;for standalone testing
273 * This sample handler simply clears the nan bit in the FPSR.
283 bclr.b #E1,E_BYTE(a6) ;bsun is always an E1 exception
290 add.l #1,sigbsun ;for standalone testing
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.
308 add.l #1,sigunimp ;for standalone testing
313 * Unsupported data type exception
323 bclr.b #E1,E_BYTE(a6) ;unsupp is always an E1 exception
327 add.l #1,sigunsupp ;for standalone testing
339 * fpsp_fmt_error --- exit point for frame format error
341 * The fpu stack frame does not match the frames existing
342 * or planned at the time of this writing. The fpsp is
343 * unable to handle frame sizes not in the following
344 * version:size pairs:
346 * {4060, 4160} - busy frame
347 * {4028, 4130} - unimp frame
348 * {4000, 4100} - idle frame
350 * This entry point simply holds an f-line illegal value.
351 * Replace this with a call to your kernel panic code or
352 * code to handle future revisions of the fpu.
357 dc.l $f27f0000 ;f-line illegal
360 * fpsp_done --- FPSP exit point
362 * The exception has been handled by the package and we are ready
363 * to return to user mode, but there may be OS specific code
364 * to execute before we do. If there is, do it now.
372 * mem_write --- write to user or supervisor address space
374 * Writes to memory while in supervisor mode. copyout accomplishes
375 * this via a 'moves' instruction. copyout is a UNIX SVR3 (and later) function.
376 * If you don't have copyout, use the local copy of the function below.
378 * a0 - supervisor source address
379 * a1 - user destination address
380 * d0 - number of bytes to write (maximum count is 12)
382 * The supervisor source address is guaranteed to point into the supervisor
383 * stack. The result is that a UNIX
384 * process is allowed to sleep as a consequence of a page fault during
385 * copyout. The probability of a page fault is exceedingly small because
386 * the 68040 always reads the destination address and thus the page
387 * faults should have already been handled.
389 * If the EXC_SR shows that the exception was from supervisor space,
390 * then just do a dumb (and slow) memory move. In a UNIX environment
391 * there shouldn't be any supervisor mode floating point exceptions.
395 btst.b #5,EXC_SR(a6) ;check for supervisor state
403 move.l d1,-(sp) ;preserve d1 just in case
412 * mem_read --- read from user or supervisor address space
414 * Reads from memory while in supervisor mode. copyin accomplishes
415 * this via a 'moves' instruction. copyin is a UNIX SVR3 (and later) function.
416 * If you don't have copyin, use the local copy of the function below.
418 * The FPSP calls mem_read to read the original F-line instruction in order
419 * to extract the data register number when the 'Dn' addressing mode is
423 * a0 - user source address
424 * a1 - supervisor destination address
425 * d0 - number of bytes to read (maximum count is 12)
427 * Like mem_write, mem_read always reads with a supervisor
428 * destination address on the supervisor stack. Also like mem_write,
429 * the EXC_SR is checked and a simple memory copy is done if reading
430 * from supervisor space is indicated.
434 btst.b #5,EXC_SR(a6) ;check for supervisor state
442 move.l d1,-(sp) ;preserve d1 just in case
452 * Use these routines if your kernel doesn't have copyout/copyin equivalents.
453 * Assumes that D0/D1/A0/A1 are scratch registers. copyout overwrites DFC,
454 * and copyin overwrites SFC.
457 move.l 4(sp),a0 ; source
458 move.l 8(sp),a1 ; destination
459 move.l 12(sp),d0 ; count
460 sub.l #1,d0 ; dec count by 1 for dbra
462 movec d1,DFC ; set dfc for user data space
464 move.b (a0)+,d1 ; fetch supervisor byte
465 moves.b d1,(a1)+ ; write user byte
470 move.l 4(sp),a0 ; source
471 move.l 8(sp),a1 ; destination
472 move.l 12(sp),d0 ; count
473 sub.l #1,d0 ; dec count by 1 for dbra
475 movec d1,SFC ; set sfc for user space
477 moves.b (a0)+,d1 ; fetch user byte
478 move.b d1,(a1)+ ; write supervisor byte