[OpenBIOS] [PATCH] PPC: Add "real" CPU timebase-frequency override NVRAM variable

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Sat Jun 29 13:27:28 CEST 2013

Some older OS (particularly Darwin) will get stuck in a timing loop upon
boot if the CPU clock-frequency and timebase-frequency aren't set close
enough to "real" values.

The clock-frequency property is already fairly realistic, so create a new
boolean NVRAM variable "force-real-tbfreq?" which when set to true will
override the timebase-frequency value supplied by QEMU/KVM with that similar
to a real Mac.

Hence it is possible to boot these old OS from QEMU by adding the following
to the QEMU command line: -prom-env 'force-real-tbfreq?=true' (although of
course the guest timing may be inaccurate).

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
CC: Alexander Graf <agraf at csgraf.de>
 openbios-devel/arch/ppc/qemu/init.c |   10 +++++++++-
 openbios-devel/forth/admin/nvram.fs |    1 +
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/openbios-devel/arch/ppc/qemu/init.c b/openbios-devel/arch/ppc/qemu/init.c
index fcbd04d..60a5303 100644
--- a/openbios-devel/arch/ppc/qemu/init.c
+++ b/openbios-devel/arch/ppc/qemu/init.c
@@ -258,7 +258,15 @@ cpu_generic_init(const struct cpudef *cpu)
-    PUSH(fw_cfg_read_i32(FW_CFG_PPC_TBFREQ));
+    /* Some OS (early Darwin) require a value of timebase-frequency
+       that closely matches real hardware in order to prevent a
+       timing loop hang. Use CLOCKFREQ / 16 as a good approximation. */
+    fword("force-real-tbfreq?");
+    if (POP()) {
+        PUSH(fw_cfg_read_i32(FW_CFG_PPC_CLOCKFREQ) / 0x10);
+    } else {
+        PUSH(fw_cfg_read_i32(FW_CFG_PPC_TBFREQ));
+    }
diff --git a/openbios-devel/forth/admin/nvram.fs b/openbios-devel/forth/admin/nvram.fs
index 20f6462..cf3e905 100644
--- a/openbios-devel/forth/admin/nvram.fs
+++ b/openbios-devel/forth/admin/nvram.fs
@@ -336,6 +336,7 @@ s" -1"       s" real-size"            int-config
 s" 4000000"  s" load-base"          int-config
 s" -1"       s" virt-base"            int-config
 s" -1"       s" virt-size"            int-config
+s" false"    s" force-real-tbfreq?"   bool-config

More information about the OpenBIOS mailing list