--- Net2/arch/i386/isa/npx.c 2018/04/24 18:04:01 1.1 +++ Net2/arch/i386/isa/npx.c 2018/04/24 18:05:01 1.1.1.2 @@ -33,6 +33,7 @@ * * @(#)npx.c 7.2 (Berkeley) 5/12/91 */ +static char rcsid[] = "$Header: /var/lib/cvsd/net2/Net2/arch/i386/isa/npx.c,v 1.1.1.2 2018/04/24 18:05:01 root Exp $"; #include "npx.h" #if NNPX > 0 @@ -74,19 +75,20 @@ npxprobe(dvp) #endif /* insure EM bit off */ + load_cr0(rcr0() & ~CR0_EM); /* stop emulating */ +/*pg("init");*/ asm(" fninit "); /* put device in known state */ /* check for a proper status of zero */ - status = 0xa5a5; + status = 0x5a5a; asm (" fnstsw %0 " : "=m" (status) : "m" (status) ); - if (status == 0) { + if ((status&0xff) == 0) { /* good, now check for a proper control word */ - control = 0xa5a5; - asm (" fnstcw %0 " : "=m" (control) : "m" (control)); + asm (" fnstcw %0 " : "=m" (status) : "m" (status)); - if ((control&0x103f) == 0x3f) { + if ((status&0x103f) == 0x3f) { /* then we have a numeric coprocessor */ /* XXX should force an exception here to generate an intr */ return (1); @@ -94,6 +96,7 @@ npxprobe(dvp) } /* insure EM bit on */ + load_cr0(rcr0() | CR0_EM); /* start emulating */ return (0); } @@ -105,7 +108,6 @@ npxattach(dvp) { npxinit(0x262); - /* check for ET bit to decide 387/287 */ /*outb(0xb1,0); /* reset processor */ npxexists++; npx0mask = dvp->id_irq; @@ -115,14 +117,16 @@ npxattach(dvp) * Initialize floating point unit, usually after an error */ npxinit(control) { +static short wd; if (npxexists == 0) return; +wd = control; load_cr0(rcr0() & ~CR0_EM); /* stop emulating */ -#ifdef INTEL_COMPAT - asm (" finit"); - asm(" fldcw %0" : : "g" (control)); +#ifndef NOINTEL_COMPAT + asm (" fninit"); + asm(" fldcw %0" : : "g" (wd)); asm(" fnsave %0 " : : "g" (curpcb->pcb_savefpu) ); #else asm("fninit"); @@ -159,6 +163,7 @@ npxunload() { npxintr(frame) struct intrframe frame; { struct trapframe tf; +/*pg("npxintr");*/ outb(0xf0,0); /* reset processor */ /* sync state in process context structure, in advance of debugger/process looking for it */ @@ -189,19 +194,17 @@ npxintr(frame) struct intrframe frame; { * Implement device not available (DNA) exception */ npxdna() { +/*pg("npxdna");*/ + if (npxexists == 0) return(0); - if (!(curpcb->pcb_flags & FP_WASUSED) - ||(curpcb->pcb_flags & FP_NEEDSRESTORE)) { - load_cr0(rcr0() & ~CR0_EM); /* stop emulating */ + load_cr0(rcr0() & ~CR0_EM); /* stop emulating */ + if (curpcb->pcb_flags & FP_NEEDSRESTORE) asm(" frstor %0 " : : "g" (curpcb->pcb_savefpu)); - curpcb->pcb_flags |= FP_WASUSED | FP_NEEDSSAVE; - curpcb->pcb_flags &= ~FP_NEEDSRESTORE; - npxproc = curproc; - npxpcb = curpcb; - - return(1); - } - return (0); + curpcb->pcb_flags |= FP_WASUSED | FP_NEEDSSAVE; + curpcb->pcb_flags &= ~FP_NEEDSRESTORE; + npxproc = curproc; + npxpcb = curpcb; + return (1); } #endif