How to tell whether CPU supports x64?

Devin Teske dteske at vicor.com
Thu Mar 17 22:15:13 UTC 2011


On Thu, 2011-03-17 at 14:33 -0700, Tait wrote:

> I have a remote server, and I'd like to know if it will support
> 64-bit instructions.


I wrote this for the job (please, suggestions/comments very welcome):


############################################################ BEGIN FILE
/* -*- tab-width:  4 -*- ;; Emacs  */
/* vi: set tabstop=4     :: Vi/ViM */

/* Devin Teske (c)2010, July 26, 11:42:38. All Rights Reserved. */

/* system includes */
#include <stdio.h>				/* printf(3) */
#include <stdlib.h>				/* EXIT_SUCCESS exit(3) */
#include <string.h>				/* strncmp(3) */
#include <sys/types.h>			/* u_int/register_t (for machine/cpufunc.h) */
#include <machine/cpufunc.h>	/* read_e/rflags() write_e/rflags()
                            	 * do_cpuid() */
#include <machine/psl.h>		/* PSL_ID */
#include <machine/specialreg.h>	/* AMDID_LM */

/* Preprocessor Macros */

#ifndef AMDID_LM
#define AMDID_LM 0x20000000
#endif

int
main (int argc, char *argv[])
{
	int has_lm = 0;
	char *cpu_vendor;
	int vendor[3];
#ifdef __amd64__
	register_t rflags;
#else
	u_int eflags;
#endif
	u_int regs[4];

	/* Check for presence of "cpuid". */
#ifdef __amd64__
	rflags = read_rflags();
	write_rflags(rflags ^ PSL_ID);
	if (((rflags ^ read_rflags()) & PSL_ID) != 0)
#else
	eflags = read_eflags();
	write_eflags(eflags ^ PSL_ID);
	if (((eflags ^ read_eflags()) & PSL_ID) != 0)
#endif
	{
		/* Fetch the vendor string. */
		do_cpuid(0, regs);
		vendor[0] = regs[1];
		vendor[1] = regs[3];
		vendor[2] = regs[2];
		cpu_vendor = (char *)vendor;

		/* check for vendors that support AMD features. */
		if (strncmp(cpu_vendor, "GenuineIntel", 12) == 0 ||
		    strncmp(cpu_vendor, "AuthenticAMD", 12) == 0)
		{
			/* Has to support AMD features. */
			do_cpuid(0x80000000, regs);
			has_lm = (regs[3] & AMDID_LM);
		}
	}

	printf("x86_64 support: %s\n", has_lm ? "YES" : "NO" );
	exit(EXIT_SUCCESS);
}
############################################################ END FILE

Save the text above into a file named "x86_64.c" and then execute "make
x86_64" without arguments (or, if you prefer to have a static binary,
instead execute "cc -static -Wall -O -pipe -I. x86_64.c -o x86_64".

After you've compiled the utility, execute "./x86_64" and the results
will be either:

    x86_64 support: YES

or

    x86_64 support: NO

--
Devin

(full sig at bottom)


>  Is there some way I can tell? It's running 32-bit
> FreeBSD right now.
> 
> >From dmesg.boot:
> 	Timecounter "i8254" frequency 1193182 Hz quality 0
> 	CPU: Intel(R) Xeon(TM) CPU 2.40GHz (2387.76-MHz 686-class CPU)
> 	Origin = "GenuineIntel"  Id = 0xf29  Stepping = 9
> 	Features=0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
> 	Features2=0x4400<CNTX-ID,<b14>>
> 	Logical CPUs per core: 2
> 	real memory  = 1073676288 (1023 MB)
> 	avail memory = 1041502208 (993 MB)
> 	ACPI APIC Table: <DELL   PE1750  >
> 	FreeBSD/SMP: Multiprocessor System Detected: 2 CPUs
> 	cpu0 (BSP): APIC ID:  0
> 	cpu1 (AP): APIC ID:  1
> 
> I've had no luck trying to search for the id/stepping. Would the
> feature list show x64 support?
> 
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"


-- 
Cheers,
Devin Teske

-> FUN STUFF <-
-----BEGIN GEEK CODE BLOCK-----
Version 3.12
GAT/CS/B/CC/E/IT/MC/M/MU/P/S/TW d+(++) s: a- C+++@$ UB++++$ P++++@$ L
++++$ E-
W+++ N? o? K? w@ O M++$ V- PS+>++ PE@ Y+ PGP-> t(+) 5? X(+) R(-) tv+ b
+>++ DI+
D+(++) G++ e>++++ h r+++ z+++
------END GEEK CODE BLOCK------
Learn about the "Geek Code": http://www.geekcode.com/

-> LEGAL DISCLAIMER <-
This message  contains confidential  and proprietary  information
of the sender,  and is intended only for the person(s) to whom it
is addressed. Any use, distribution, copying or disclosure by any
other person  is strictly prohibited.  If you have  received this
message in error,  please notify  the e-mail sender  immediately,
and delete the original message without making a copy.

-> END TRANSMISSION <-


More information about the freebsd-questions mailing list