Patch diff between commits for Clover bootloader

Mac OS on a PC


Booting Mac OS on non-Apple hardware presents unique challenges, particularly when bugs appear with your specific hardware configuration

Intro: Basics of Booting Mac OS

In a typical configuration, a UEFI bootloader called Clover is used to emulate Mac OS ACPI tables, and patch ACPI source language where required so that Mac OS can correctly enumerate the devices installed in a PC. Further, clover can inject "mission critical" drivers, called kernel extensions (KEXTs) into the Mac OS kernel cache. The primary KEXT Clover must inject is called VirtualSMC, and is responsible for emulating the system management controller present in every authentic Mac.

Typical Challenges

Very few hardware configurations work out of the box with Mac OS. In particular, newer versions of Mac OS have no support for Nvidia graphics cards, and very few wifi cards besides a select few Broadcom chips are supported. Typically a computer will need KEXTs installed for it's network controller, as well as audio and Intel or AMD graphics. A more nuanced issue with modern hardware is that Apple does not implement automatic power state transition for Nvme drives, resulting in higher temperatures and power consumption.

Unique Challenges on HP Spectre

When installing Mac OS on my PC, an HP Spectre Laptop, I was not able to boot into Mac OS, reaching a panic before the kernel even loaded. After some debugging, I found that the issue was only occurring when the UEFI executable for Clover was stored on the Internal SSD, and that if I booted Clover in "Fast Boot" mode, I would be able to boot into Mac OS

Resolution, and Future Projects

After some debugging within Clover's source code, I discovered that calling the "ReadKeyStroke" function, intended to get keyboard input in an UEFI environment, resulted in HP's firmware entering a Debug state that locked out specific memory locations Mac OS required to boot. The cover image of this page shows the relatively simple patch required to disable this method, and allow Mac OS to boot using Clover.

Although the patch required was somewhat simple, working with Clover taught me a lot about programming in a UEFI environment, and enabled me to produce a customizable Linux Kernel stubloader, useful for computers that are unable to boot the Linux Kernel directly from UEFI, or unable to pass arguments to it. You can view the code for my Clover fork here, or the code for my UEFI stubloader here.