** Revision Header * Header built automatically - do not edit! *************
*
*	(C) Copyright 1991 by Olaf `Olsen' Barthel, all rights reserved
*
*	Name .....: FPInit.asm
*	Created ..: Monday 26-Aug-91 11:20
*	Revision .: 1
*
*	Date            Author          Comment
*	=========       ========        ====================
*	26-Aug-91	Olsen		Created this file!
*
****************************************************************************

	include	"exec/types.i"
	include	"exec/execbase.i"

CALL	macro
	xref	_LVO\1
	jsr	_LVO\1(a6)
	endm

	XDEF	___fpinit
	XDEF	___fpterm

	XREF	_XCEXIT

	csect	text,0,0,1,2

	;	VOID __fpinit(VOID);
	;
	;		This routine is called by the c.o startup code
	;	in order to set up and initialize math libraries or, just
	;	like done here, to initialize the '881/'882/'040 chip.

___fpinit:	
	move.l	(4).w,a6		; Grab SysBase

	cmp.w	#37,LIB_VERSION(a6)	; Kickstart 2.x?
	blt.s	2$

	cmp.w	#175,SoftVer(a6)	; Kickstart 2.x, rev 37.175?
	blt.s	2$

	move.w	AttnFlags(a6),d0	; Get attention flags

	btst	#AFB_68020,d0		; '020 or higher installed?
	beq.s	2$

	btst	#AFB_68881,d0		; '881 or higher installed?
	bne.s	1$

	btst	#AFB_68040,d0		; If no '881 present, an '040
	beq.s	2$			; will do as well

1$	fmove.l	#00000010,fpcr		; Rounding  = to nearest,
					; Precision = extended
	rts

2$	move.l	#1,-(sp)		; Exit & fail
	jmp	_XCEXIT

	;	VOID __fpexit(VOID);
	;
	;		This routine is called by the c.o startup code
	;	in order to close and release math libraries or, just
	;	like done here, to reset the '881/'882/'040 chip.

___fpterm:
	rts

	pea	(a5)			; Save A5

	move.l	(4).w,a6		; Grab SysBase

	move.w	AttnFlags(a6),d0	; Get attention flags

	btst	#AFB_68881,d0		; '881 or higher installed?
	bne.s	3$

	btst	#AFB_68040,d0		; If no '881 present, an '040
	beq.s	5$			; will do as well

3$	lea	4$,a5			; Get address of FPU reset routine,
	CALL	Supervisor		; call it in supervisor mode,
	bra.s	5$			; and return

4$	clr.l	-(sp)
	frestore (sp)+
	rte

5$	move.l	(sp)+,a5		; Restore A5,
	rts				; and return

	end
