netbsd.sa revision 1.5 1 1.5 chs * $NetBSD: netbsd.sa,v 1.5 2001/10/02 06:34:52 chs Exp $
2 1.2 cgd
3 1.1 mycroft * MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
4 1.1 mycroft * M68000 Hi-Performance Microprocessor Division
5 1.1 mycroft * M68040 Software Package
6 1.1 mycroft *
7 1.1 mycroft * M68040 Software Package Copyright (c) 1993, 1994 Motorola Inc.
8 1.1 mycroft * All rights reserved.
9 1.1 mycroft *
10 1.1 mycroft * THE SOFTWARE is provided on an "AS IS" basis and without warranty.
11 1.1 mycroft * To the maximum extent permitted by applicable law,
12 1.1 mycroft * MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
13 1.1 mycroft * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A
14 1.1 mycroft * PARTICULAR PURPOSE and any warranty against infringement with
15 1.1 mycroft * regard to the SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF)
16 1.1 mycroft * and any accompanying written materials.
17 1.1 mycroft *
18 1.1 mycroft * To the maximum extent permitted by applicable law,
19 1.1 mycroft * IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
20 1.1 mycroft * (INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
21 1.1 mycroft * PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR
22 1.1 mycroft * OTHER PECUNIARY LOSS) ARISING OF THE USE OR INABILITY TO USE THE
23 1.1 mycroft * SOFTWARE. Motorola assumes no responsibility for the maintenance
24 1.1 mycroft * and support of the SOFTWARE.
25 1.1 mycroft *
26 1.1 mycroft * You are hereby granted a copyright license to use, modify, and
27 1.1 mycroft * distribute the SOFTWARE so long as this entire notice is retained
28 1.1 mycroft * without alteration in any modified and/or redistributed versions,
29 1.1 mycroft * and that such modified versions are clearly identified as such.
30 1.1 mycroft * No licenses are granted by implication, estoppel or otherwise
31 1.1 mycroft * under any patents or trademarks of Motorola, Inc.
32 1.1 mycroft
33 1.1 mycroft *
34 1.1 mycroft * skeleton.sa 3.2 4/26/91
35 1.1 mycroft *
36 1.1 mycroft * This file contains code that is system dependent and will
37 1.1 mycroft * need to be modified to install the FPSP.
38 1.1 mycroft *
39 1.1 mycroft * Each entry point for exception 'xxxx' begins with a 'jmp fpsp_xxxx'.
40 1.1 mycroft * Put any target system specific handling that must be done immediately
41 1.1 mycroft * before the jump instruction. If there no handling necessary, then
42 1.1 mycroft * the 'fpsp_xxxx' handler entry point should be placed in the exception
43 1.1 mycroft * table so that the 'jmp' can be eliminated. If the FPSP determines that the
44 1.1 mycroft * exception is one that must be reported then there will be a
45 1.1 mycroft * return from the package by a 'jmp real_xxxx'. At that point
46 1.1 mycroft * the machine state will be identical to the state before
47 1.1 mycroft * the FPSP was entered. In particular, whatever condition
48 1.1 mycroft * that caused the exception will still be pending when the FPSP
49 1.1 mycroft * package returns. Thus, there will be system specific code
50 1.1 mycroft * to handle the exception.
51 1.1 mycroft *
52 1.1 mycroft * If the exception was completely handled by the package, then
53 1.1 mycroft * the return will be via a 'jmp fpsp_done'. Unless there is
54 1.1 mycroft * OS specific work to be done (such as handling a context switch or
55 1.1 mycroft * interrupt) the user program can be resumed via 'rte'.
56 1.1 mycroft *
57 1.1 mycroft * In the following skeleton code, some typical 'real_xxxx' handling
58 1.1 mycroft * code is shown. This code may need to be moved to an appropriate
59 1.1 mycroft * place in the target system, or rewritten.
60 1.1 mycroft *
61 1.1 mycroft
62 1.1 mycroft SKELETON IDNT 2,1 Motorola 040 Floating Point Software Package
63 1.1 mycroft
64 1.1 mycroft section 15
65 1.1 mycroft *
66 1.1 mycroft * The following counters are used for standalone testing
67 1.1 mycroft *
68 1.1 mycroft
69 1.1 mycroft section 8
70 1.1 mycroft
71 1.1 mycroft include fpsp.h
72 1.1 mycroft
73 1.3 thorpej *
74 1.3 thorpej * XXX Note, this is NOT valid Motorola syntax, but what else can we do?
75 1.3 thorpej *
76 1.5 chs #include <machine/asm.h>
77 1.3 thorpej
78 1.1 mycroft xref b1238_fix
79 1.3 thorpej xref _C_LABEL(mmutype)
80 1.1 mycroft
81 1.1 mycroft *
82 1.1 mycroft * Divide by Zero exception
83 1.1 mycroft *
84 1.1 mycroft * All dz exceptions are 'real', hence no fpsp_dz entry point.
85 1.1 mycroft *
86 1.1 mycroft xdef dz
87 1.1 mycroft xdef real_dz
88 1.1 mycroft dz:
89 1.3 thorpej cmp.l #-2,_C_LABEL(mmutype)
90 1.3 thorpej bne.l _C_LABEL(fpfault)
91 1.1 mycroft real_dz:
92 1.1 mycroft link a6,#-LOCAL_SIZE
93 1.1 mycroft fsave -(sp)
94 1.1 mycroft bclr.b #E1,E_BYTE(a6)
95 1.1 mycroft frestore (sp)+
96 1.1 mycroft unlk a6
97 1.3 thorpej jmp _C_LABEL(fpfault)
98 1.1 mycroft
99 1.1 mycroft *
100 1.1 mycroft * Inexact exception
101 1.1 mycroft *
102 1.1 mycroft * All inexact exceptions are real, but the 'real' handler
103 1.1 mycroft * will probably want to clear the pending exception.
104 1.1 mycroft * The provided code will clear the E3 exception (if pending),
105 1.1 mycroft * otherwise clear the E1 exception. The frestore is not really
106 1.1 mycroft * necessary for E1 exceptions.
107 1.1 mycroft *
108 1.1 mycroft * Code following the 'inex' label is to handle bug #1232. In this
109 1.4 wiz * bug, if an E1 snan, ovfl, or unfl occurred, and the process was
110 1.1 mycroft * swapped out before taking the exception, the exception taken on
111 1.1 mycroft * return was inex, rather than the correct exception. The snan, ovfl,
112 1.1 mycroft * and unfl exception to be taken must not have been enabled. The
113 1.1 mycroft * fix is to check for E1, and the existence of one of snan, ovfl,
114 1.1 mycroft * or unfl bits set in the fpsr. If any of these are set, branch
115 1.1 mycroft * to the appropriate handler for the exception in the fpsr. Note
116 1.1 mycroft * that this fix is only for d43b parts, and is skipped if the
117 1.1 mycroft * version number is not $40.
118 1.1 mycroft *
119 1.1 mycroft *
120 1.1 mycroft xdef real_inex
121 1.1 mycroft xdef inex
122 1.1 mycroft inex:
123 1.3 thorpej cmp.l #-2,_C_LABEL(mmutype)
124 1.3 thorpej bne.l _C_LABEL(fpfault)
125 1.1 mycroft link a6,#-LOCAL_SIZE
126 1.1 mycroft fsave -(sp)
127 1.1 mycroft cmpi.b #VER_40,(sp) ;test version number
128 1.1 mycroft bne.b not_fmt40
129 1.1 mycroft fmove.l fpsr,-(sp)
130 1.1 mycroft btst.b #E1,E_BYTE(a6) ;test for E1 set
131 1.1 mycroft beq.b not_b1232
132 1.1 mycroft btst.b #snan_bit,2(sp) ;test for snan
133 1.1 mycroft beq inex_ckofl
134 1.1 mycroft addq.l #4,sp
135 1.1 mycroft frestore (sp)+
136 1.1 mycroft unlk a6
137 1.1 mycroft bra snan
138 1.1 mycroft inex_ckofl:
139 1.1 mycroft btst.b #ovfl_bit,2(sp) ;test for ovfl
140 1.1 mycroft beq inex_ckufl
141 1.1 mycroft addq.l #4,sp
142 1.1 mycroft frestore (sp)+
143 1.1 mycroft unlk a6
144 1.1 mycroft bra ovfl
145 1.1 mycroft inex_ckufl:
146 1.1 mycroft btst.b #unfl_bit,2(sp) ;test for unfl
147 1.1 mycroft beq not_b1232
148 1.1 mycroft addq.l #4,sp
149 1.1 mycroft frestore (sp)+
150 1.1 mycroft unlk a6
151 1.1 mycroft bra unfl
152 1.1 mycroft
153 1.1 mycroft *
154 1.1 mycroft * We do not have the bug 1232 case. Clean up the stack and call
155 1.1 mycroft * real_inex.
156 1.1 mycroft *
157 1.1 mycroft not_b1232:
158 1.1 mycroft addq.l #4,sp
159 1.1 mycroft frestore (sp)+
160 1.1 mycroft unlk a6
161 1.1 mycroft
162 1.1 mycroft real_inex:
163 1.1 mycroft link a6,#-LOCAL_SIZE
164 1.1 mycroft fsave -(sp)
165 1.1 mycroft not_fmt40:
166 1.1 mycroft bclr.b #E3,E_BYTE(a6) ;clear and test E3 flag
167 1.1 mycroft beq.b inex_cke1
168 1.1 mycroft *
169 1.1 mycroft * Clear dirty bit on dest resister in the frame before branching
170 1.1 mycroft * to b1238_fix.
171 1.1 mycroft *
172 1.1 mycroft movem.l d0/d1,USER_DA(a6)
173 1.1 mycroft bfextu CMDREG1B(a6){6:3},d0 ;get dest reg no
174 1.1 mycroft bclr.b d0,FPR_DIRTY_BITS(a6) ;clr dest dirty bit
175 1.1 mycroft bsr.l b1238_fix ;test for bug1238 case
176 1.1 mycroft movem.l USER_DA(a6),d0/d1
177 1.1 mycroft bra.b inex_done
178 1.1 mycroft inex_cke1:
179 1.1 mycroft bclr.b #E1,E_BYTE(a6)
180 1.1 mycroft inex_done:
181 1.1 mycroft frestore (sp)+
182 1.1 mycroft unlk a6
183 1.3 thorpej jmp _C_LABEL(fpfault)
184 1.1 mycroft
185 1.1 mycroft *
186 1.1 mycroft * Overflow exception
187 1.1 mycroft *
188 1.1 mycroft xref fpsp_ovfl
189 1.1 mycroft xdef real_ovfl
190 1.1 mycroft xdef ovfl
191 1.1 mycroft ovfl:
192 1.3 thorpej cmp.l #-2,_C_LABEL(mmutype)
193 1.1 mycroft beq.l fpsp_ovfl
194 1.3 thorpej jmp _C_LABEL(fpfault)
195 1.1 mycroft real_ovfl:
196 1.1 mycroft link a6,#-LOCAL_SIZE
197 1.1 mycroft fsave -(sp)
198 1.1 mycroft bclr.b #E3,E_BYTE(a6) ;clear and test E3 flag
199 1.1 mycroft bne.b ovfl_done
200 1.1 mycroft bclr.b #E1,E_BYTE(a6)
201 1.1 mycroft ovfl_done:
202 1.1 mycroft frestore (sp)+
203 1.1 mycroft unlk a6
204 1.3 thorpej jmp _C_LABEL(fpfault)
205 1.1 mycroft
206 1.1 mycroft *
207 1.1 mycroft * Underflow exception
208 1.1 mycroft *
209 1.1 mycroft xref fpsp_unfl
210 1.1 mycroft xdef real_unfl
211 1.1 mycroft xdef unfl
212 1.1 mycroft unfl:
213 1.3 thorpej cmp.l #-2,_C_LABEL(mmutype)
214 1.1 mycroft beq.l fpsp_unfl
215 1.3 thorpej jmp _C_LABEL(fpfault)
216 1.1 mycroft real_unfl:
217 1.1 mycroft link a6,#-LOCAL_SIZE
218 1.1 mycroft fsave -(sp)
219 1.1 mycroft bclr.b #E3,E_BYTE(a6) ;clear and test E3 flag
220 1.1 mycroft bne.b unfl_done
221 1.1 mycroft bclr.b #E1,E_BYTE(a6)
222 1.1 mycroft unfl_done:
223 1.1 mycroft frestore (sp)+
224 1.1 mycroft unlk a6
225 1.3 thorpej jmp _C_LABEL(fpfault)
226 1.1 mycroft
227 1.1 mycroft *
228 1.1 mycroft * Signalling NAN exception
229 1.1 mycroft *
230 1.1 mycroft xref fpsp_snan
231 1.1 mycroft xdef real_snan
232 1.1 mycroft xdef snan
233 1.1 mycroft snan:
234 1.3 thorpej cmp.l #-2,_C_LABEL(mmutype)
235 1.1 mycroft beq.l fpsp_snan
236 1.3 thorpej jmp _C_LABEL(fpfault)
237 1.1 mycroft real_snan:
238 1.1 mycroft link a6,#-LOCAL_SIZE
239 1.1 mycroft fsave -(sp)
240 1.1 mycroft bclr.b #E1,E_BYTE(a6) ;snan is always an E1 exception
241 1.1 mycroft frestore (sp)+
242 1.1 mycroft unlk a6
243 1.3 thorpej jmp _C_LABEL(fpfault)
244 1.1 mycroft
245 1.1 mycroft *
246 1.1 mycroft * Operand Error exception
247 1.1 mycroft *
248 1.1 mycroft xref fpsp_operr
249 1.1 mycroft xdef real_operr
250 1.1 mycroft xdef operr
251 1.1 mycroft operr:
252 1.3 thorpej cmp.l #-2,_C_LABEL(mmutype)
253 1.1 mycroft beq.l fpsp_operr
254 1.3 thorpej jmp _C_LABEL(fpfault)
255 1.1 mycroft real_operr:
256 1.1 mycroft link a6,#-LOCAL_SIZE
257 1.1 mycroft fsave -(sp)
258 1.1 mycroft bclr.b #E1,E_BYTE(a6) ;operr is always an E1 exception
259 1.1 mycroft frestore (sp)+
260 1.1 mycroft unlk a6
261 1.3 thorpej jmp _C_LABEL(fpfault)
262 1.1 mycroft
263 1.1 mycroft *
264 1.1 mycroft * BSUN exception
265 1.1 mycroft *
266 1.1 mycroft * This sample handler simply clears the nan bit in the FPSR.
267 1.1 mycroft *
268 1.1 mycroft xref fpsp_bsun
269 1.1 mycroft xdef real_bsun
270 1.1 mycroft xdef bsun
271 1.1 mycroft bsun:
272 1.3 thorpej cmp.l #-2,_C_LABEL(mmutype)
273 1.1 mycroft beq.l fpsp_bsun
274 1.3 thorpej jmp _C_LABEL(fpfault)
275 1.1 mycroft real_bsun:
276 1.1 mycroft link a6,#-LOCAL_SIZE
277 1.1 mycroft fsave -(sp)
278 1.1 mycroft bclr.b #E1,E_BYTE(a6) ;bsun is always an E1 exception
279 1.1 mycroft fmove.l FPSR,-(sp)
280 1.1 mycroft bclr.b #nan_bit,(sp)
281 1.1 mycroft fmove.l (sp)+,FPSR
282 1.1 mycroft frestore (sp)+
283 1.1 mycroft unlk a6
284 1.3 thorpej jmp _C_LABEL(fpfault)
285 1.1 mycroft
286 1.1 mycroft *
287 1.1 mycroft * F-line exception
288 1.1 mycroft *
289 1.1 mycroft * A 'real' F-line exception is one that the FPSP isn't supposed to
290 1.1 mycroft * handle. E.g. an instruction with a co-processor ID that is not 1.
291 1.1 mycroft *
292 1.1 mycroft *
293 1.1 mycroft xref fpsp_fline
294 1.1 mycroft xdef real_fline
295 1.1 mycroft xdef fline
296 1.1 mycroft fline:
297 1.3 thorpej cmp.l #-2,_C_LABEL(mmutype)
298 1.1 mycroft beq.l fpsp_fline
299 1.3 thorpej jmp _C_LABEL(fpfault)
300 1.1 mycroft real_fline:
301 1.3 thorpej jmp _C_LABEL(fpfault)
302 1.1 mycroft
303 1.1 mycroft *
304 1.1 mycroft * Unsupported data type exception
305 1.1 mycroft *
306 1.1 mycroft xref fpsp_unsupp
307 1.1 mycroft xdef real_unsupp
308 1.1 mycroft xdef unsupp
309 1.1 mycroft unsupp:
310 1.3 thorpej cmp.l #-2,_C_LABEL(mmutype)
311 1.1 mycroft beq.l fpsp_unsupp
312 1.3 thorpej jmp _C_LABEL(fpfault)
313 1.1 mycroft real_unsupp:
314 1.1 mycroft link a6,#-LOCAL_SIZE
315 1.1 mycroft fsave -(sp)
316 1.1 mycroft bclr.b #E1,E_BYTE(a6) ;unsupp is always an E1 exception
317 1.1 mycroft frestore (sp)+
318 1.1 mycroft unlk a6
319 1.3 thorpej jmp _C_LABEL(fpfault)
320 1.1 mycroft
321 1.1 mycroft *
322 1.1 mycroft * Trace exception
323 1.1 mycroft *
324 1.1 mycroft xdef real_trace
325 1.1 mycroft real_trace:
326 1.1 mycroft rte
327 1.1 mycroft
328 1.1 mycroft *
329 1.1 mycroft * fpsp_fmt_error --- exit point for frame format error
330 1.1 mycroft *
331 1.1 mycroft * The fpu stack frame does not match the frames existing
332 1.1 mycroft * or planned at the time of this writing. The fpsp is
333 1.1 mycroft * unable to handle frame sizes not in the following
334 1.1 mycroft * version:size pairs:
335 1.1 mycroft *
336 1.1 mycroft * {4060, 4160} - busy frame
337 1.1 mycroft * {4028, 4130} - unimp frame
338 1.1 mycroft * {4000, 4100} - idle frame
339 1.1 mycroft *
340 1.1 mycroft * This entry point simply holds an f-line illegal value.
341 1.1 mycroft * Replace this with a call to your kernel panic code or
342 1.1 mycroft * code to handle future revisions of the fpu.
343 1.1 mycroft *
344 1.1 mycroft xdef fpsp_fmt_error
345 1.1 mycroft fpsp_fmt_error:
346 1.1 mycroft pea 1f
347 1.3 thorpej jsr _C_LABEL(panic)
348 1.1 mycroft dc.l $f27f0000 ;f-line illegal
349 1.1 mycroft 1:
350 1.1 mycroft .asciz "bad floating point stack frame"
351 1.1 mycroft .even
352 1.1 mycroft
353 1.1 mycroft *
354 1.1 mycroft * fpsp_done --- FPSP exit point
355 1.1 mycroft *
356 1.1 mycroft * The exception has been handled by the package and we are ready
357 1.1 mycroft * to return to user mode, but there may be OS specific code
358 1.1 mycroft * to execute before we do. If there is, do it now.
359 1.1 mycroft *
360 1.1 mycroft *
361 1.3 thorpej xref _ASM_LABEL(rei)
362 1.1 mycroft xdef fpsp_done
363 1.1 mycroft fpsp_done:
364 1.3 thorpej jmp _ASM_LABEL(rei)
365 1.1 mycroft
366 1.1 mycroft *
367 1.1 mycroft * mem_write --- write to user or supervisor address space
368 1.1 mycroft *
369 1.1 mycroft * Writes to memory while in supervisor mode. copyout accomplishes
370 1.1 mycroft * this via a 'moves' instruction. copyout is a UNIX SVR3 (and later) function.
371 1.1 mycroft * If you don't have copyout, use the local copy of the function below.
372 1.1 mycroft *
373 1.1 mycroft * a0 - supervisor source address
374 1.1 mycroft * a1 - user destination address
375 1.1 mycroft * d0 - number of bytes to write (maximum count is 12)
376 1.1 mycroft *
377 1.1 mycroft * The supervisor source address is guaranteed to point into the supervisor
378 1.1 mycroft * stack. The result is that a UNIX
379 1.1 mycroft * process is allowed to sleep as a consequence of a page fault during
380 1.1 mycroft * copyout. The probability of a page fault is exceedingly small because
381 1.1 mycroft * the 68040 always reads the destination address and thus the page
382 1.1 mycroft * faults should have already been handled.
383 1.1 mycroft *
384 1.1 mycroft * If the EXC_SR shows that the exception was from supervisor space,
385 1.1 mycroft * then just do a dumb (and slow) memory move. In a UNIX environment
386 1.1 mycroft * there shouldn't be any supervisor mode floating point exceptions.
387 1.1 mycroft *
388 1.1 mycroft xdef mem_write
389 1.1 mycroft mem_write:
390 1.1 mycroft btst.b #5,EXC_SR(a6) ;check for supervisor state
391 1.1 mycroft beq.b user_write
392 1.1 mycroft super_write:
393 1.1 mycroft move.b (a0)+,(a1)+
394 1.1 mycroft subq.l #1,d0
395 1.1 mycroft bne.b super_write
396 1.1 mycroft rts
397 1.1 mycroft user_write:
398 1.1 mycroft move.l d1,-(sp) ;preserve d1 just in case
399 1.1 mycroft move.l d0,-(sp)
400 1.1 mycroft move.l a1,-(sp)
401 1.1 mycroft move.l a0,-(sp)
402 1.3 thorpej jsr _C_LABEL(copyout)
403 1.1 mycroft add.l #12,sp
404 1.1 mycroft move.l (sp)+,d1
405 1.1 mycroft rts
406 1.1 mycroft
407 1.1 mycroft *
408 1.1 mycroft * mem_read --- read from user or supervisor address space
409 1.1 mycroft *
410 1.1 mycroft * Reads from memory while in supervisor mode. copyin accomplishes
411 1.1 mycroft * this via a 'moves' instruction. copyin is a UNIX SVR3 (and later) function.
412 1.1 mycroft * If you don't have copyin, use the local copy of the function below.
413 1.1 mycroft *
414 1.1 mycroft * The FPSP calls mem_read to read the original F-line instruction in order
415 1.1 mycroft * to extract the data register number when the 'Dn' addressing mode is
416 1.1 mycroft * used.
417 1.1 mycroft *
418 1.1 mycroft *Input:
419 1.1 mycroft * a0 - user source address
420 1.1 mycroft * a1 - supervisor destination address
421 1.1 mycroft * d0 - number of bytes to read (maximum count is 12)
422 1.1 mycroft *
423 1.1 mycroft * Like mem_write, mem_read always reads with a supervisor
424 1.1 mycroft * destination address on the supervisor stack. Also like mem_write,
425 1.1 mycroft * the EXC_SR is checked and a simple memory copy is done if reading
426 1.1 mycroft * from supervisor space is indicated.
427 1.1 mycroft *
428 1.1 mycroft xdef mem_read
429 1.1 mycroft mem_read:
430 1.1 mycroft btst.b #5,EXC_SR(a6) ;check for supervisor state
431 1.1 mycroft beq.b user_read
432 1.1 mycroft super_read:
433 1.1 mycroft move.b (a0)+,(a1)+
434 1.1 mycroft subq.l #1,d0
435 1.1 mycroft bne.b super_read
436 1.1 mycroft rts
437 1.1 mycroft user_read:
438 1.1 mycroft move.l d1,-(sp) ;preserve d1 just in case
439 1.1 mycroft move.l d0,-(sp)
440 1.1 mycroft move.l a1,-(sp)
441 1.1 mycroft move.l a0,-(sp)
442 1.3 thorpej jsr _C_LABEL(copyin)
443 1.1 mycroft add.l #12,sp
444 1.1 mycroft move.l (sp)+,d1
445 1.1 mycroft rts
446 1.1 mycroft
447 1.1 mycroft end
448