Reputation: 33
I am developing an x86 bootloader and have come across this problem (which I guess should be pretty straightforward, but so far I haven't been able to solve): I want to detect the bitness of the CPU host (e.g. if it's 16bit-only, or supports 32bit or 64bit).
I have used the CPUID instruction, but it was introduced with 486 so doesn't help for detecting 16-bit-only vs. a 386-compatible CPU that supports 32-bit protected mode (or 32-bit operand-size in real mode with prefixes).
Upvotes: 2
Views: 360
Reputation: 18523
Checking for 32-bits (see http://www.rcollins.org/ddj/Sep96/Sep96.html):
pushf
pushf
(when running in real mode)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
:
cpuid
instruction is supported.Upvotes: 1