在32位操作系统下检测处理器是否为64位 [英] Detect if the processor is 64-bit under 32 bit OS

查看:22
本文介绍了在32位操作系统下检测处理器是否为64位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,x86-64 架构提供与 x86 的兼容性.32 位 Windows(或其他操作系统)可以在 x86-64 处理器上运行.(如果我错了,请纠正我).

Normally, x86-64 architecture offers compatibility with x86. A 32-bit Windows (or other OS) can run on an x86-64 processor. (Correct me if I am wrong).

我想知道 32 位 Windows 是否有可能(在 C++ 中)知道底层处理器是否为 64 位.例如,如果Windows 7 32位运行在Core i5上,我们应该能够知道处理器是64位的(虽然运行的是Windows 7 32位).

I would like to know if it is possible (in C++) for a 32-bit Windows to know that if underlying processor is 64-bit. For example, if Windows 7 32-bit running on Core i5, we should be able to know that processor is 64-bit (although Windows 7 32 bit is running).

您可能会质疑,即使处理器是 64 位,操作系统是 32 位,64 位进程也不能运行(如果我错了,请纠正我).但程序的目的是了解处理器,而不是操作系统.这个问题可能与此类似,但它没有给出任何C++程序提示.

You may question the requirement that even if processor is 64 bit and OS is 32 bit, 64 bit processes cannot run (Correct me if I am wrong). But the aim of the program to know the processor, not OS. This question may appear similar to this, but it does not give any hint of C++ program.

推荐答案

嗯,据我所知,你只能通过查看 CPU 信息本身来获得这个.我认为检查 CPU 是否支持 长模式应该就足够了(对于 x86 和 amd64).

Well, as far as I am aware, you can only get this through looking at the CPU information itself. I think it should be enough (for x86 & amd64) to check whether the CPU supports long mode.

为此,您可以在 x86 上使用 cpuid 指令.根据您的帖子的 Windows 特性,我猜测您正在使用 Microsoft C++ 编译器.为此,有一个 __cpuid 内在.可悲的是,微软页面上的描述以 PBE 标志结束,而我的 cpuinfo 中的 lm 标志是三个标志之后.

For that, you could use the cpuid instruction on x86. By Windows-ness of your post, I'll take a guess you're using the Microsoft C++ compiler. For that, there's a __cpuid intrinsic. Sadly, the description on Microsoft's page ends at PBE flag, while lm flag in my cpuinfo goes three flags later.

查看 CPUID 修改AMD 处理器,您可以使用 InfoType = 0x80000001 获得 LM,结果位于最后返回的整数的第 29 位.在 英特尔处理器的 CPUID 修改 相同的位指定 EM64T 标志,相当于 AFAIK.

Looking at CPUID Modifications for AMD Processors, you can get LM with InfoType = 0x80000001, with the result being at bit 29 of the last returned integer. In CPUID Modifications for Intel Processors the same bit specifies EM64T flag which is equivalent AFAIK.

在这两种情况下,您应该首先执行 InfoType = 0x80000000 以获得最大的有意义的 InfoType 值.如果它小于0x80000001,那么你不应该做上面的检查,而是假设不支持长模式.

In both cases, you should be doing InfoType = 0x80000000 first to get maximum meaningful InfoType value. If it's less than 0x80000001, then you should not do the above check and instead assume long mode is not supported.

这篇关于在32位操作系统下检测处理器是否为64位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆