[comp.sys.intel] Telling the difference between a 287 and a 387 cleanly?

brad@looking.UUCP (10/26/87)

I would like to know the cleanest method for (on a 386) telling the
difference between the 80827 and 80387 math chips.  So far I have thought
of a few methods:

	1) Assuming you know you have a 386, examine the CR0 register bit
	   4, which is the "387" bit.

	2) Reset the processor (with output to I/O port) and examine the
	   status word.  The two processors supposedly differ on reset.

	3) Execute a 387 instruction and see what happens.

The problem with all three of these is that they could be highly hardware
and OS dependent.  For example, what will some of these do when in
"virtual 8086" mode on a 386?  We don't want to muck this up with
funny traps etc.

Is there an intel approved way to tell a 386 from 286 in virtual 8086 mode
as well?  Or will an attempt to set the IOPL flags work in that mode as
it does in real mode?
-- 
Brad Templeton, Looking Glass Software Ltd. - Waterloo, Ontario 519/884-7473

tr@wind.bellcore.com (tom reingold) (10/28/87)

In article <1076@looking.UUCP> brad@looking.UUCP (Brad Templeton) writes:
$ I would like to know the cleanest method for (on a 386) telling the
$ difference between the 80827 and 80387 math chips.  So far I have thought
$ of a few methods:
$ 
$ 	1) Assuming you know you have a 386, examine the CR0 register bit
$ 	   4, which is the "387" bit.
$ 
$ 	2) Reset the processor (with output to I/O port) and examine the
$ 	   status word.  The two processors supposedly differ on reset.
$ 
$ 	3) Execute a 387 instruction and see what happens.
$ 
$ The problem with all three of these is that they could be highly hardware
$ and OS dependent.  For example, what will some of these do when in
$ "virtual 8086" mode on a 386?  We don't want to muck this up with
$ funny traps etc.
$ 
$ Is there an intel approved way to tell a 386 from 286 in virtual 8086 mode
$ as well?  Or will an attempt to set the IOPL flags work in that mode as
$ it does in real mode?
$ -- 
$ Brad Templeton, Looking Glass Software Ltd. - Waterloo, Ontario 519/884-7473

; From PC Tech Journal, August 1987
; NDPTYPE -- Check for math coprocessor presence and type
code	segment public
assume cs:code,ds:code
	org	100h			;set up as a COM file
start:	jmp	begin
control	dw	0
msg_no	db	'No math coprocessor present $'
msg_87	db	'8087 math coprocessor present $'
msg_287	db	'80287 math coprocessor present $'
msg_387	db	'80387 math coprocessor present $'

;--------------------------------------	TEST FOR PRESENCE OF NDP
begin:	mov	dx,offset msg_no	;load not-present message
	fninit				;initialize math coprocessor
	mov	byte ptr control+1,0	;clear memory byte
	fnstcw	control			;store control wrd in memory
	mov	ah,byte ptr control+1	;upper byte is 03h if
	cmp	ah,03h			;  coprocessor is present
	jne	print			;no math coprocessor

;--------------------------------------	CHECK IF 8087
chk87:	mov	dx, offset msg_87	;load 8087 message
	and	control, NOT 0080h	;turn interrupts on (IEM=0)
	fldcw	control			;load control word
	fdisi				;disable interrupts (IEM=1)
	fstcw	control			;store control word
	test	control,0080h		;if IEM=1, then 8087
	jnz	print			;display 8087 message

;--------------------------------------	CHECK IF 80287 or 80387
chk287:	mov	dx,offset msg_287	;load 287 message
	finit				;use default infinity mode
	fld1				;generate infinity
	fldz				;  by diving 1 by zero
	fdiv				;
	fld	st			;form negative infinity
	fchs				;
	fcompp				;compare +/- infinity
	fstsw	control			;equal for 87/287
	fwait				;wait for fstsw to complete
	mov	ax,control		;get NDP control word
	sahf				;stor condition bits in flags
	jz	print			;it's 287 if infinities equal

;--------------------------------------	IT IS AN 80387
is387:	mov	dx,offset msg_387	;otherwise, it's a 387
print:	mov	ah,09h			;dos print string function
	int	21h			;call dos
	mov	ax,4c00h		;dos terminate program
	int	21h			;call dos
code	ends				;
	end	start			;start is the entry point


Tom Reingold 			INTERNET:       tr@bellcore.bellcore.com
Bell Communications Research	UUCP: 		<backbone>!bellcore!tr
435 South St room 2L350		SOUNDNET:	(201) 829-5119 [work]
Morristown, NJ 07960				(201) 287-2345 [home]