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