Quantcast
Channel: George – UlduzSoft
Viewing all articles
Browse latest Browse all 55

Running Mac OS X under qemu/KVM on AMD CPU

$
0
0

Due to the excellent work of Gabriel L.Somlo it is possible to run the emulated Mac OS X on Linux under Qemu/KVM. The changes seem to be minimal, and the operating system emulation works well – as long as you have the Intel CPU, that’s it.

If you have only the AMD CPU, the emulation only works without the KVM, i.e. when you run qemu without the -enable-kvm option. With this option the emulation hangs on the grey screen with Apple logo. Enabling the verbose boot (-v option to Chameleon) shows an empty black screen instead.

This happens because Qemu does not properly pass the CPU vendor to the virtualized CPU when using KVM. For example, booting the Linux DVD installation with the following options:

qemu-system-x86_64 -cpu core2duo openSUSE-13.1-DVD-x86_64.iso

and running cat /proc/cpuinfo | grep vendor prints the following:

vendor_id    : GenuineIntel

As you see, despite your host CPU being AMD, qemu properly emulates the Intel CPU and sets the options correctly.

However if you add -enable-kvm switch, and run:

qemu-system-x86_64 -enable-kvm -cpu core2duo openSUSE-13.1-DVD-x86_64.iso

and run cat /proc/cpuinfo | grep vendor you’ll see a rather ridiculous picture:

vendor_id    : AuthenticAMD

So the CPU model does not change. Since Mac OS X is supposed to only run on Intel CPU, we can assume Mac OS gets really confused when it does cpuid, and halts.

Now, there is a reason why Qemu is doing this. The reason is that the syscall emulation uses different instructions on AMD and Intel CPUs. So if the virtualized guest is specific to the CPU, and This is likely a bug in qemu for which the patch is submitted, but until it makes it upstream, you can apply the patch yourself:

+++ a/target-i386/cpu.c   2014-03-10 23:47:32.433412520 -0700
--- b/target-i386/cpu.c    2014-03-10 23:47:08.965411258 -0700
@@ -1863,7 +1863,7 @@
     const char *vendor = def->vendor;
     char host_vendor[CPUID_VENDOR_SZ + 1];
-    if (kvm_enabled()) { 
+    if (kvm_enabled() && def->name[0] == 'q' && def->name[1] == 'e' && def->name[2] == 'm' && def->name[3] == 'u' ) {
         uint32_t  ebx = 0, ecx = 0, edx = 0;
         host_cpuid(0, 0, NULL, &ebx, &ecx, &edx);
         x86_cpu_vendor_words2str(host_vendor, ebx, edx, ecx);

This patch forces the CPU vendor copy even when KVM is being used and a non-Qemu CPU is specified. With this patch Mac OS X installs and runs on the AMD CPU under kvm.

Update: the patch is not needed, as Hin-Tak Leung pointed out in comments, you can pass the vendor as string, and KVM would respect that:

qemu-system-x86_64 -enable-kvm -cpu core2duo,vendor=GenuineIntel openSUSE-13.1-DVD-x86_64.iso

 


Viewing all articles
Browse latest Browse all 55

Trending Articles