|
|
1.1 root 1: /*-
2: * Copyright (c) 1990 William Jolitz.
3: * Copyright (c) 1991 The Regents of the University of California.
4: * All rights reserved.
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: * 1. Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: * 2. Redistributions in binary form must reproduce the above copyright
12: * notice, this list of conditions and the following disclaimer in the
13: * documentation and/or other materials provided with the distribution.
14: * 3. All advertising materials mentioning features or use of this software
15: * must display the following acknowledgement:
16: * This product includes software developed by the University of
17: * California, Berkeley and its contributors.
18: * 4. Neither the name of the University nor the names of its contributors
19: * may be used to endorse or promote products derived from this software
20: * without specific prior written permission.
21: *
22: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32: * SUCH DAMAGE.
33: *
34: * @(#)npx.c 7.2 (Berkeley) 5/12/91
35: */
1.1.1.2 ! root 36: static char rcsid[] = "$Header: /usr/bill/working/sys/i386/isa/RCS/npx.c,v 1.2 92/01/21 14:34:27 william Exp $";
1.1 root 37: #include "npx.h"
38: #if NNPX > 0
39:
40: #include "param.h"
41: #include "systm.h"
42: #include "conf.h"
43: #include "file.h"
44: #include "proc.h"
45: #include "machine/cpu.h"
46: #include "machine/pcb.h"
47: #include "machine/trap.h"
48: #include "ioctl.h"
49: #include "machine/specialreg.h"
50: #include "i386/isa/isa_device.h"
51: #include "icu.h"
52: /*
53: * 387 and 287 Numeric Coprocessor Extension (NPX) Driver.
54: */
55:
56: int npxprobe(), npxattach(), npxintr();
57: struct isa_driver npxdriver = {
58: npxprobe, npxattach, "npx",
59: };
60:
61: struct proc *npxproc; /* process who owns device, otherwise zero */
62: struct pcb *npxpcb; /* owners context structure */
63: static npxexists;
64: extern long npx0mask;
65:
66: /*
67: * Probe routine - look device, otherwise set emulator bit
68: */
69: npxprobe(dvp)
70: struct isa_device *dvp;
71: { static status, control;
72:
73: #ifdef lint
74: npxintr();
75: #endif
76:
77: /* insure EM bit off */
1.1.1.2 ! root 78: load_cr0(rcr0() & ~CR0_EM); /* stop emulating */
! 79: /*pg("init");*/
1.1 root 80: asm(" fninit "); /* put device in known state */
81:
82: /* check for a proper status of zero */
1.1.1.2 ! root 83: status = 0x5a5a;
1.1 root 84: asm (" fnstsw %0 " : "=m" (status) : "m" (status) );
85:
1.1.1.2 ! root 86: if ((status&0xff) == 0) {
1.1 root 87:
88: /* good, now check for a proper control word */
1.1.1.2 ! root 89: asm (" fnstcw %0 " : "=m" (status) : "m" (status));
1.1 root 90:
1.1.1.2 ! root 91: if ((status&0x103f) == 0x3f) {
1.1 root 92: /* then we have a numeric coprocessor */
93: /* XXX should force an exception here to generate an intr */
94: return (1);
95: }
96: }
97:
98: /* insure EM bit on */
1.1.1.2 ! root 99: load_cr0(rcr0() | CR0_EM); /* start emulating */
1.1 root 100: return (0);
101: }
102:
103: /*
104: * Attach routine - announce which it is, and wire into system
105: */
106: npxattach(dvp)
107: struct isa_device *dvp;
108: {
109:
110: npxinit(0x262);
111: /*outb(0xb1,0); /* reset processor */
112: npxexists++;
113: npx0mask = dvp->id_irq;
114: }
115:
116: /*
117: * Initialize floating point unit, usually after an error
118: */
119: npxinit(control) {
1.1.1.2 ! root 120: static short wd;
1.1 root 121:
122: if (npxexists == 0) return;
123:
124:
1.1.1.2 ! root 125: wd = control;
1.1 root 126: load_cr0(rcr0() & ~CR0_EM); /* stop emulating */
1.1.1.2 ! root 127: #ifndef NOINTEL_COMPAT
! 128: asm (" fninit");
! 129: asm(" fldcw %0" : : "g" (wd));
1.1 root 130: asm(" fnsave %0 " : : "g" (curpcb->pcb_savefpu) );
131: #else
132: asm("fninit");
133: asm(" fnsave %0 " : : "g" (curpcb->pcb_savefpu) );
134: #endif
135: load_cr0(rcr0() | CR0_EM); /* start emulating */
136:
137: }
138:
139: /*
140: * Load floating point context and record ownership to suite
141: */
142: npxload() {
143:
144: if (npxproc) panic ("npxload");
145: npxproc = curproc;
146: npxpcb = curpcb;
147: asm(" frstor %0 " : : "g" (curpcb->pcb_savefpu) );
148: }
149:
150: /*
151: * Unload floating point context and relinquish ownership
152: */
153: npxunload() {
154:
155: if (npxproc == 0) panic ("npxunload");
156: asm(" fsave %0 " : : "g" (npxpcb->pcb_savefpu) );
157: npxproc = 0 ;
158: }
159:
160: /*
161: * Record information needed in processing an exception and clear status word
162: */
163: npxintr(frame) struct intrframe frame; {
164: struct trapframe tf;
165:
1.1.1.2 ! root 166: /*pg("npxintr");*/
1.1 root 167: outb(0xf0,0); /* reset processor */
168:
169: /* sync state in process context structure, in advance of debugger/process looking for it */
170: if (npxproc == 0 || npxexists == 0) panic ("npxintr");
171: asm (" fnsave %0 " : : "g" (npxpcb->pcb_savefpu) );
172:
173: /*
174: * Prepair a trap frame for our generic exception processing routine, trap()
175: */
176: bcopy(&frame.if_es, &tf, sizeof(tf));
177: tf.tf_trapno = T_ARITHTRAP;
178: #ifdef notyet
179: /* encode the appropriate code for detailed information on this exception */
180: tf.tf_err = ???;
181: #endif
182: trap(tf);
183:
184: /*
185: * Restore with any changes to superior frame
186: */
187: bcopy(&tf, &frame.if_es, sizeof(tf));
188:
189: /* clear the exception so we can catch others like it */
190: asm (" fnclex");
191: }
192:
193: /*
194: * Implement device not available (DNA) exception
195: */
196: npxdna() {
1.1.1.2 ! root 197: /*pg("npxdna");*/
! 198:
1.1 root 199:
200: if (npxexists == 0) return(0);
1.1.1.2 ! root 201: load_cr0(rcr0() & ~CR0_EM); /* stop emulating */
! 202: if (curpcb->pcb_flags & FP_NEEDSRESTORE)
1.1 root 203: asm(" frstor %0 " : : "g" (curpcb->pcb_savefpu));
1.1.1.2 ! root 204: curpcb->pcb_flags |= FP_WASUSED | FP_NEEDSSAVE;
! 205: curpcb->pcb_flags &= ~FP_NEEDSRESTORE;
! 206: npxproc = curproc;
! 207: npxpcb = curpcb;
! 208: return (1);
1.1 root 209: }
210: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.