I am trying to run a custom kernel in qemu-system-x86_64
. This kernel requires the usage of the rdrand
instruction early in its boot cycle, and will fail to boot if it is not supported by the CPU. I read in the answer to this question that rdrand
requires at least an Ivy Bridge processor. However, when I run QEMU with the -cpu SandyBridge
parameter (which should tell it to emulate a Sandy Bridge CPU, which supports rdrand
), my kernel still will not boot. I have tried -cpu Broadwell
, presumably because it is a newer CPU, but nothing changes.
Here is the assembly being run that checks cpuid
and executes rdrand
:
00025c79 xorl %ebp, %ebp
00025c7b movl $0x1, %eax
00025c80 xorl %ecx, %ecx
00025c82 cpuid
00025c84 testl $0x40000000, %ecx ## imm = 0x40000000
00025c8a jne 0x25c98
00025c8c movl $0x2d479, (%esp) ## 0x2D479 points to an error string
00025c93 calll _stop ## This function call does not return
00025c98 movl $0x2d4b1, (%esp) ## 0x2D4B1 points to a debugging message
00025c9f calll _printf
00025ca4 movb $0x0, 0x1b(%esp)
00025ca9 rdrandl %eax
00025cac setb 0x1b(%esp)
00025cb1 cmpb $0x0, 0x1b(%esp)
00025cb6 je 0x25ca9