home *** CD-ROM | disk | FTP | other *** search
- WHATCPU
- =======
-
- From PC Magazine, July 1990, pp425-426
- --------------------------------------
-
- You can differentiate between protected-mode CPUs (286, 386,
- 486 and 386SX) and real-mode CPUs (8088, 8086, 80188, 80186 and
- the NEC V20 and V30) with a simple test that determines whether
- SP is decremented before or after a PUSH. Real-mode CPUs
- decrement SP before a value is PUSHed; protected-mode CPUs
- decrement it after they're running in real-mode. (The terms
- real-mode and protected-mode are used here only to distinguish
- between chip families.) The simple code sequence
-
- PUSH SP
- POP AX
- CMP SP,AX
- JNE IS_8086
-
- separates 286/386/486-class chips from 8086-class chips. If a
- branch occurs, then the CPU belongs to the 8086 family; if it
- doesn't, the CPU is a 286,386 or 486.
-
- Once you've gotten this far, another test is required to
- distinguish 286s from 386s and 486s. Here's the key: the NT
- (Nested Task) bit (bit 14) in the flags register can't be set in
- real mode on a 286, but it can on a 386 or 486. If the test
-
- PUSHP
- POP AX
- OR AX,4000
- PUSH AX
- POPF
- PUSHP
- POP AX
- TEST AX,4000
- JZ IS_286
-
- branches on the last line, then the CPU is a 286. If not, it's
- 386 or a 486.
-
- Differentiating between a 386 and a 486 requires one more
- step. If you're writing 386-specific software, you won't need
- this, because anything that will run on a 386 will also run on a
- 486. But soon we'll see 486-specific software as well.
-
- The following code sequence, which tests the CPU's ability to
- retain data in register CR0's cache write-through bit (bit 29),
- separates 386s from 486s.
-
- MOV EAX,CR0
- MOV EBX,EAX
- XOR EAX,20000000H
- MOV CR0,EAX
- MOV EAX,CR0
- CMP EAX,EBX
- JE IS_386
-
- The cache write-through bit isn't implemented on the 386 and thus
- can't be written to: on the 486, where it is implemented, it can.
-
- A branch in response to the JE (jump-if-equal) instruction on
- the last line means the CPU is a 386; if the execution falls
- through, then it's a 486. If you use this code sequence with
- MASM, remember to include a .386P directive in your source code
- to enable assembly of privileged 386 instructions.
-
- The following DEBUG listing (WHATCPU.SCR) creates a short
- program called WHATCPU.COM:
-
- A 0100
- JMP 0123
- DB 0D,0A,"CPU is an 80$"
- DB "86$"
- DB "286$"
- DB "386$"
- DB "486$"
- DB 0D,0A,"$"
- MOV AH,09 ;Print opening message
- MOV DX,0102
- INT 21
- MOV DX,0111 ;Test for 8088/8086
- PUSH SP
- POP AX
- CMP SP,AX
- JNZ 0166 ;Branch if test positive
- MOV DX,0114 ;Test for 286
- PUSHF
- POP AX
- OR AX,4000
- PUSH AX
- POPF
- PUSHF
- POP AX
- TEST AX,4000
- JZ 0166 ;Branch if test positive
- MOV DX,0118 ;Separate 386s from 486s
- DB 0F,20,C0 ;mov eax,cr0
- DB 66,8B,D8 ;mov ebx,eax
- DB 66,35,00,00,00,20 ;xor eax,20000000
- DB 0F,22,C0 ;mov cr0,eax
- DB 0F,20,C0 ;mov eax,cr0
- DB 66,3B,C3 ;cmp eax,ebx
- DB 0F,84,06,00 ;je 0166
- DB BA,1C,01 ;mov dx,011C
- DB 0F,22,C3 ;mov cr0,ebx
- MOV AH,09 ;Print CPU type
- INT 21
- MOV AH,09 ;Terminate line and exit
- MOV DX,0120
- INT 21
- RET
-
- N WHATCPU.COM
- RCX
- 72
- W
- Q
-
- This identifies a CPU as an 8086, 286, 386 or 486. An 8088,
- 8086, 80188, 80186, V20 or V30 is generically identified as an
- 8086. Since DEBUG won't assemble the 386 instructions necessary
- to distinguish between the 386 and the 486, 386-specific
- instructions are entered manually, using DEBUG's DB command.
- Alsom don't type in the comments on the right; doing so will
- cause errors on lines that begin with DB.
-