	MACHINE	68030
	FPU
	IDNT	resetfpu.s

	INCDIR	"INCLUDE:"
	INCLUDE	"exec/funcdef.i"
	INCLUDE	"exec/exec_lib.i"
	INCLUDE	"exec/execbase.i"

	IFND	AFB_68060	; Define AFB_68060 if it is not defined
	BITDEF	AF,68060,7	; in exec/execbase.i. This is true for
	ENDIF			; at least version. 40.13 of the includes.

SysBase	EQU	4

	XDEF	__resetfpu

__resetfpu:
	MOVEM.L	A5-A6,-(SP)
	LEA	Lreset_fpu,A5
	MOVE.L	SysBase.W,A6
	JSR	_LVOSupervisor(A6)
	BRA	Lafter_reset_fpu

Lreset_fpu:	; is AFB_68060 set in SysBase->AttnFlags ??
	BTST	#AFB_68060,([SysBase],AttnFlags+1)
	BEQ	Lno_060fpu
	CLR.L	-(SP)
	CLR.L	-(SP)		; needs 2 additonal longs on stack

Lno_060fpu:
	CLR.L	-(SP)
	FRESTORE (SP)+

	; Note that after using frestore with a null state frame we have
	; to set up the control register to restore rounding to truncation
	; rather than round-to-nearest, as required by the ANSI C standard.

        MOVEQ	#72,D0
        ADD.L	D0,D0
        FMOVE.L	D0,FPCR
	RTE

Lafter_reset_fpu:
	MOVEM.L	(SP)+,A5-A6
	RTS

	END
