Subject: Re: Floating point in the kernel
To: Brian C. Grayson <bgrayson@marvin.ece.utexas.edu>
From: Chris G. Demetriou <cgd@netbsd.org>
List: tech-kern
Date: 09/18/1998 16:08:40
"Brian C. Grayson" <bgrayson@marvin.ece.utexas.edu> writes:
>   I don't know what I'm talking about :), but since the use of FP
> is going to be rare, would something based on the following
> work (after suitable extension to cover all the potential
> problems I'm missing, like avoiding corrupting the user's FP
> registers?):
> 
>   a)  upon entry into any device routines that use FP, you first
>       increment global_using_fpregs.
>   b)  upon exit from any device routines that use FP, you
>       decrement global_using_fpregs (and panic if it is already
>       zero).
>   c)  in the main interrupt handler, if global_using_fpregs > 0,
>       save the FP registers, otherwise you don't have to.
> 
>   Or is a scheme like this what you meant by ``very careful about
> saves and restores''?  :)

That's part of an example -- not complete, I don't think -- of being
'very careful.'

It's not just "global interrupt handler" for one.  It's also the
syscall handler, etc.  Also, even considering that, you have to be
very, very careful unless you want to save at every interrupt/syscall.
For instance:

Just compiling code with FPU instructions enabled on some
architectures will cause the compiler to emit FP instructions, _even
if you aren't doing FP calculations_!  (e.g. to move regions of
memory.


cgd
-- 
Chris Demetriou - cgd@netbsd.org - http://www.netbsd.org/People/Pages/cgd.html
Disclaimer: Not speaking for NetBSD, just expressing my own opinion.
Plug: Get your official NetBSD-1.3.2 CDROM set today! http://www.netbsd.com/