我正在尝试在qemu-system-x86_64
中运行自定义内核。此内核要求在其引导周期的早期使用rdrand
指令,如果CPU不支持,则无法引导。我在the answer to this question中读到rdrand
至少需要一个Ivy Bridge处理器。但是,当我使用-cpu SandyBridge
参数(它应该告诉它模拟支持rdrand
的Sandy Bridge CPU)运行QEMU时,我的内核仍然无法启动。我试过-cpu Broadwell
,大概是因为它是一个较新的CPU,但没有任何变化。
以下是正在运行的程序集,用于检查cpuid
并执行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