Article View: comp.sys.intel
Article #854Re: Help!!! Need program to determine CPU!!
From: Roy Phillips
Date: Mon, 12 Oct 1992 15:30
Date: Mon, 12 Oct 1992 15:30
65 lines
2537 bytes
2537 bytes
In article <1992Oct5.184133.13502@mnemosyne.cs.du.edu> kconnors@nyx.cs.du.edu (Keith Connors) writes:
>
>Help! I think we've been ripped off! The family just purchased a
>486 33 MHz system, but there is reason to believe that it may be
>actually a 386 33 MHz machine!! Could someone please uuencode and mail
>me (or better yet, refer to an anonymous FTP site) a program that
>displays the CPU in the machine?! We'd rather not take it apart until
>we can be sure that we've been had!!!
>
>Thanks so much for your time......
The following program will test to see if the executing processor
is behaving like a 386 or like a 486, without resorting to
hardware methods (a dangerous thing is a software-engineer
with a screw-driver):
----------------------------------------------------------
#include <stdio.h>
#define UNKNOWN 2
char* cpu_names[] = { "i386", "i486", "????" };
main()
{
int cpu;
cpu = cpu_type();
if ( cpu < 0 || cpu > 1)
cpu = UNKNOWN;
printf ( "%s\n", cpu_names[cpu]);
}
/*
* cpu_type -- guess the type of the cpu by checking
* if the alignment-check flag gets set
* returns 1 if set (i.e., i486) or 0 if
* not set (i.e., i386)
*/
int
cpu_type()
{
asm("pushfl"); /* get flags into eax */
asm("mov 0(%esp),%eax");
asm("movl %eax,%ecx"); /* save flag register in ecx */
asm("xorl $0x40000,%eax"); /* toggle alignment-check (ac) flag */
asm("mov %eax,0(%esp)"); /* copy eax to flag register */
asm("popfl"); /* (potentially changes ac flag) */
asm("pushfl"); /* get flags into eax */
asm("mov 0(%esp),%eax");
asm("shrl $0x12,%eax"); /* ac flag -> LSbit */
asm("andl $0x1,%eax"); /* clear rest of register */
asm("mov %ecx,0(%esp)");
asm("popfl"); /* restore flag register from ecx */
}
----------------------------------------------------------
Roy
--
Roy Phillips
A+F System-Entwicklung
DW-4030 Ratingen
Germany
roy@alfrat.de
Technical Details
Message-ID:
<402@alfrat.uucp>Path:
arc1-ca.pugleaf.net!sparky!uunet!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!alfrat!royReferences:
<1992Oct5.184133.13502@mnemosyne.cs.du.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!alfrat!roy From: roy@alfrat.uucp (Roy Phillips) Newsgroups: comp.sys.intel Subject: Re: Help!!! Need program to determine CPU!! Message-ID: <402@alfrat.uucp> Date: 12 Oct 92 15:30:55 GMT References: <1992Oct5.184133.13502@mnemosyne.cs.du.edu> Reply-To: roy@alfrat.UUCP (Roy Phillips) Organization: A+F System-Entwicklung, W-Germany Lines: 65