1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123
4 * This file is part of Project 16.
6 * Project 16 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Project 16 is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
19 * Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "src/lib/wcpu/wcpu.h"
31 PUSHF ; we gonna modify flags, so back them up
32 ; first check if its 8086/8088 or 80186/80188
33 PUSHF ; FLAGS -> STACK
35 AND AX, 00FFFh ; clear 12-15 bits (they are always 1 on 8086/8088 and 80186/80188)
38 ; this is where magic happen
39 PUSHF ; FLAGS -> STACK
41 AND AX, 0F000h ; 0-11 bits aren't important to us
42 CMP AX, 0F000h ; check if all 12-15 bits are set (simple comparision)
43 JNE _286p ; if no, 286+ CPU
44 MOV cputype, 0 ; if yes, we are done, set cputype to 0 and end this
47 ; now check if its 286 or newer
48 PUSHF ; FLAGS -> STACK
50 OR AX, 07000h ; set 12-14 bits (they are always cleared by 286 if its real mode)
53 ; this is where magic happen
54 PUSHF ; FLAGS -> STACK
56 TEST AX, 07000h ; check if at least 1 bit in 12-14 bits range is set (15th won't be set anyway)
57 JNZ _386p ; not all bits clear, its 386+
58 MOV cputype, 1 ; all bits clear, its 286, we are done
61 MOV cputype, 2 ; its 386 or newer, but we don't care if its newer at this point
63 POPF ; restore flags we backed up earlier
69 int main(int argc, char **argv)
77 case 0: cpus = "8086/8088 or 186/88"; break;
78 case 1: cpus = "286"; break;
79 case 2: cpus = "386 or newer"; break;
80 default: cpus = "internal error"; break;
82 printf("detected CPU type: %s\n", cpus);