Subject: Re: FPU Emulator
To: Ken Nakata <>
From: Chris G. Demetriou <>
List: macbsd-development
Date: 09/01/1994 11:10:06
> 	   (1) your emulator must be re-entrant
> I was aware of that, but didn't think it as a drawback.  A re-entrant
> program should use only stack and the registers provided that the processor
> status is properly saved... ?

That should be enough, but it's still an annoyance: it means your
stack will grow a bit larger, which means that you're ever closer to
that great big double bus fault in the sky...  8-)

It shouldn't really be a problem; i listed it as a warning.  One of
the most obvious ways to do this would be to keep the FP info in the
PCB (where currently, on machine with FP coprocessors, the FP state is
kept).  However, that's a bad idea, for the obvious reason.

> 	   (2) your emulator will be slow as snot (rather than just
> 		   'slow', as would be expected... 8-) for instructions
> 		   which aren't implemnted in the '040.
> I didn't think of this!  though I can't say I didn't have "FPU-less
> machine must be slow anyway" attitude 8-)

"no skin off my nose" -- i always buy machines with FPU's, because i
generally end up using them.  FP math actually happens "reasonably
often" in UN*X-like systems.

However, looking at the atan() case, you're talking around 20 or so
emulation traps that _it_ would have to take...  "ouch!"

> Oops, I almost forgot to ask this... Does context switch occur during
> the execution of f-line trap handler (i.e. the emulator) or do I have
> to explicitly control spl?  (Sorry if this is an obvious question)

Context switches (more-or-less) only happen when:
	(1) a process explicitly gives up control of the cpu, e.g. in
		sleep() or tsleep()
	(2) when returning to user mode, after a process rescheduling
		has been requested.

for an examples of (1), look in kern_synch.c.  for an example of (2),
look in your favorite port's trap.c.  (There are other places where
context switches can happen, e.g. during some signal handling, but
that's not really relevant here.)

In general, a process running in kernel mode won't be switched away
from...  Makes debugging infinite loops in the kernel rather annoying.