Re: Floating point in kernel mode, Win2003 64-bit

From: Sergey Plotnikov (svplotnik_at_yahoo.com)
Date: 04/22/04


Date: Thu, 22 Apr 2004 06:01:02 -0700

I certainly don't mix up .mfh and .dfh.

You approach is correct. More precisely it looks like:

StartDevice(){
        PsCreateSystemThread(...,WorkingThread,...);
}

Save(){
        PSR.dfh = 0;
        save fh;
}

Restore(){
        Restore fh;
        PSR.dfh = 1;
}

InterruptHundler(){
        RequestDpc();
}

DPC(){
        KeSetEvent(event) ;
}

WorkingThread(){
        for(;;){
                KeWaitForSingleObject(event);
                Save();
                a_lot_of_integer_computation(); //it may take up to several milliseconds
                float_computation(); //crush is always here
                Restore();
        }
}

As you can see my function is called only from my thread in system context, always on PASSIVE level. But still something changes .dfh. The probability of crash is about 1/1000.

Sergey
     
     ----- nospam@cristalink.com wrote: -----
     
     You don't mistake .mfh for .dfh, do you? .mfh indicates fh was used, while
     ..dfh disables fh.
     
     As far as I got it, you have some function in your driver that uses fh:
     
     calc()
     {
        - You set PSR.dfh to 0 to enable fh
        - You save the fh registers you are going to use
       - Here you do some calculations.
     
         setf.d f33=r26
     Sometimes the above instruction crashes, and you see in the crash dump that
     PSR.dfh is 1.
     }
     
     Is the above correct?
     
     Is your function called in an arbitrary thread context, or from your own
     system thread only?
     
     
     
     "Sergey Plotnikov" <svplotnik@yahoo.com> wrote in message
     news:36F667C9-B752-4548-B332-CE851114C925@microsoft.com...
> Blue screen happens always in the same place, because I've removed all
> access to rotated FP registers except one. On this access bsod happens.
>> Illegal instruction - code c000001d (!!! second chance !!!)
> e0000165`db2c0a04 (p9) setf.d f33=r26
>> If I clear PSR.mfh before this, code will work fine.
>> Stack is usual, there are only my functions in it.
>> Sergey
>> ----- nospam@cristalink.com wrote: -----
>> Where exactly does the blue screen happen, in the same or random
> places?
> What's the exception code? What's the call stack look like?
>>>