[comp.sys.m68k] Context switching with FPP

m5@lynx.uucp (Mike McNally) (05/27/89)

Are there any clever things an OS can do to avoid the overhead of saving
the status of the 6888[12] on each context switch?  It would be nice
if there were a hook like in the 386/387 such that the CPU would get
an interrupt upon the first FP instruction after a context switch.  I
realize that the situation is somewhat more complex because the 68K
can (in theory) have several coprocessors.


-- 
Mike McNally                                    Lynx Real-Time Systems
uucp: {voder,athsys}!lynx!m5                    phone: 408 370 2233

            Where equal mind and contest equal, go.

rab@rosemary.Berkeley.EDU (Robert A. Bruce) (05/27/89)

In article <5664@lynx.UUCP> m5@lynx.UUCP (Mike McNally) writes:
>Are there any clever things an OS can do to avoid the overhead of saving
>the status of the 6888[12] on each context switch?

When a process is created, set the internal fpu state to null.  Then
on each context switch you can check to see if it is still null.  If
so, there is no need to save the registers. 

	| Save the fpu context
	| a0 contains the address of the pcb
		fsave	a0@(FP_STATE_OFFSET)  	| Save the internal state.
		tstb	a0@(FP_STATE_OFFSET)	| See if the state is null.
		beq	1f			| Skip if null.
		fmovem	#0xff, a0@(FP_REGS_OFFSET) | Save the registers.	
		fmovem	fpc/fps/fpi, a0@(FP_CTRL_REGS_OFFSET) | Save ctrl regs.
	 1:

For more infomation see section 6.4 in the MC68881/2 Users Manual.
It has an excellent discussion of context switching, and state
frames.