Get the supported “bitness” of an x86 CPU when booted in 16-bit mode

筅森魡賤 提交于 2019-12-02 00:56:11

Checking for 32-bits (see http://www.rcollins.org/ddj/Sep96/Sep96.html):

  • 16-bit CPUs without protected mode (8088/8086/80186) will always have the upper 4 bits (15-12) of the flags register set when doing pushf
  • 80286 will always have the upper 4 bits clear on pushf (when running in real mode)
  • CPUs supporting 32-bit allow modifying the upper 4 bits in real mode using popf (however all 4 bits should have the same value - all set or all clear)

By using pushf, popf and modifying the data on the stack you check if it is possible to modify the upper 4 bits; if yes, it must be a 32-bit CPU.

Checking for CPUID:

  • Ensure the CPU supports 32-bit (see above)
  • Switch to 32-bits mode
  • Check if bit 21 of EFLAGS can be modified (set and cleared); if the value of that bit is not fixed (it can be changed from 0 to 1 or vice versa) the cpuid instruction is supported.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!