[comp.sys.ibm.pc.hardware] How to tell an 80286 from an 80386

rcollins@altos86.Altos.COM (Robert Collins) (09/14/90)

In article <1990Sep11.014731.20641@hitech.ht.oz.au> clyde@hitech.ht.oz.au (Clyde Smith-Stubbs) writes:
>Can anybody offer suggestions on how a program can tell if it is running
>on an 80286 or an 80386 WITHOUT setting up an illegal instruction trap?
>

There are currently three methods of determining CPU type under discusion
in this newsgroup:  trapping invalid opcodes; using the Intel algorithm;
and using the prefetch queue.

Using the prefetch queue is not reliable due to bus timing differences,
and memory timing differences between machines.  This can easily be verified
by writing an algorithm that works on 16Mhz 386's and then try the same
algorithm on a 33Mhz 386.  It will fail.

Another technique involves using an algorithm supplied by Intel in the
486 Programmer's Reference Manual.  Intel states that this algorithm is
only intended for real mode, and they are right.  The algorithm fails
in protrected mode when IOPL is not 0.	But this algorithm works in
V86 mode by accident.  (Actually it fails, but due to the technique
used by Intel, i appears to properly detect the '386.)  If you need
your algorithm to work in protected mode, then don't use the Intel
algorithm.

The third algorithm traps invalid opcodes.  This will work in real or
protected mode, provided the proper interrupt interception method is
applied to the mode being run.	In other words, if you're intending
to run in protected mode, then you handle it in a protected mode manner,
if you run in real mode, then handle it in a real mode manner.	The
problem with this algorithm is V86 mode.  Some kernals running in V86
mode don't pass control of the invalid opcode handler to the V86 task,
but instead reboot the computer, or something else.  These kernals are
obviously not 100% IBM compatible, and won't run software that issues
invalid opcodes to extend the CPU instruction set (the original '386
programmer's reference manual mentions executing invalid opcodes as
a legitimate means to extend the CPU instruction set).


I hope this helps you decide which algorithm to use.



-- 
"Worship the Lord your God, and serve him only."  Mat. 4:10
Robert Collins                 UUCP:  ...!sun!altos86!rcollins
HOME:  (408) 225-8002
WORK:  (408) 432-6200 x4356