3 #include "lib\wtest\wtest.h"
5 static unsigned char detectcpu()
10 PUSHF ; we gonna modify flags, so back them up
11 ; first check if its 8086/8088 or 80186/80188
12 PUSHF ; FLAGS -> STACK
14 AND AX, 00FFFh ; clear 12-15 bits (they are always 1 on 8086/8088 and 80186/80188)
17 ; this is where magic happen
18 PUSHF ; FLAGS -> STACK
20 AND AX, 0F000h ; 0-11 bits aren't important to us
21 CMP AX, 0F000h ; check if all 12-15 bits are set (simple comparision)
22 JNE _286p ; if no, 286+ CPU
23 MOV cputype, 0 ; if yes, we are done, set cputype to 0 and end this
26 ; now check if its 286 or newer
27 PUSHF ; FLAGS -> STACK
29 OR AX, 07000h ; set 12-14 bits (they are always cleared by 286 if its real mode)
32 ; this is where magic happen
33 PUSHF ; FLAGS -> STACK
35 TEST AX, 07000h ; check if at least 1 bit in 12-14 bits range is set (15th won't be set anyway)
36 JNZ _386p ; not all bits clear, its 386+
37 MOV cputype, 1 ; all bits clear, its 286, we are done
40 MOV cputype, 2 ; its 386 or newer, but we don't care if its newer at this point
42 POPF ; restore flags we backed up earlier
47 /*int main(int argc, char **argv)
55 case 0: cpus = "8086/8088 or 186/88"; break;
56 case 1: cpus = "286"; break;
57 case 2: cpus = "386 or newer"; break;
58 default: cpus = "internal error"; break;
60 printf("detected CPU type: %s\n", cpus);