*** fpcheck
*	Test for the existence of the fp chip
*	for Alcyon C
*
*	fpcheck()
*
*	(side effect: set fpexists to -1 if missing, 1 if there.)
*
*	By Allan Pratt, 7/20/88
***

	.include fpmacro

	.globl fpcheck, fpexists, _fpexist
fpcheck:
	move.l	d7,-(sp)		; save this so we can use it.

	; interrogate supervisor mode
	move.l	#1,-(sp)
	move.w	#$20,-(sp)
	trap	#1
	addq	#6,sp
	move.l	d0,d7
	bne	.nowsuper		; we're super already

	; get super mode
	clr.l	-(sp)
	move.w	#$20,-(sp)
	trap	#1
	addq	#6,sp
	move.l	d0,d7			; save old ssp here

.nowsuper:
	move.l	$8,sav_berr
	move.l	#berr,$8
	move.w	FPCIR,d0		; read the status register
	move.w	#$1,fpexists		; success! it's there!

; initialize the chip proper

	move.w	#3,FPCTL
	fpidle
	move.w	#$9000,FPCMD
	ckcir	#$9504
	move.l	#$7d00,FPOP
	bra.s	done

berr:					; getting here means no FP chip
	move.w	#-1,fpexists
	add.w	#$e,sp			; clean off exception frame

done:
	move.l	sav_berr,$8
	cmp.l	#-1,d7
	beq.s	.alldone		; we were already super
	move.l	d7,-(sp)
	move.w	#$20,-(sp)
	trap	#1
	addq	#6,sp
.alldone:
	move.l	(sp)+,d7
	rts

.bss
; note two names for this
_fpexist:
fpexists:	ds.w	1

sav_berr:	ds.l	1
