2

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
Community
  • 1
  • 1
wjk
  • 1,219
  • 11
  • 27
  • 1
    As far as I can see, currently qemu does not support `RDRAND` unless you use hardware virtualization and your host cpu supports it. As a workaround you might want to look at `bochs` which does. – Jester Feb 12 '16 at 01:07
  • 1
    *...a Sandy Bridge CPU, which supports `rdrand`* What? Real SnB hardware doesn't support `rdrand`. (my desktop is a non-virtualized SnB, and it's not in /proc/cpuinfo). And you just said you found out that `rdrand` requires IvB or later. Anyway, this isn't a solution to your problem, since you say it doesn't work with `-cpu Broadwell` either. – Peter Cordes Feb 12 '16 at 01:59
  • 1
    According to wikipedia RDRand is part of the ivy brigde architecture, while on some ivy bridge versions RDRand creates an illegal instruction exception – Tommylee2k Feb 12 '16 at 14:21

0 Answers0