From 06fe0d63a28fb6cb84a234ebaaf260aad80a46dd Mon Sep 17 00:00:00 2001 From: Mike Beaton Date: Tue, 25 Oct 2022 04:54:04 +0100 Subject: [PATCH] OcCpuLib: Cache InternalCalculateARTFrequencyIntel failure to avoid log loop --- Changelog.md | 1 + Library/OcCpuLib/FrequencyDetect.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index 3be4c229..fd29a32d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,7 @@ OpenCore Changelog - Fixed maximum click duration and double click speed for non-standard poll frequencies - Added support for pointer dwell-clicking - Prevented Apple firmware from adding additional security checks on top of emulated NVRAM driver +- Fixed recursive loop on first log protocol line on some systems #### v0.8.5 - Updated builtin firmware versions for SMBIOS and the rest diff --git a/Library/OcCpuLib/FrequencyDetect.c b/Library/OcCpuLib/FrequencyDetect.c index 2c4da147..49513b20 100644 --- a/Library/OcCpuLib/FrequencyDetect.c +++ b/Library/OcCpuLib/FrequencyDetect.c @@ -447,8 +447,9 @@ InternalCalculateARTFrequencyIntel ( // this frequency on module entry to initialise a TimerLib instance, and at // a later point in time to gather CPU information. // - STATIC UINT64 ARTFrequency = 0; - STATIC UINT64 CPUFrequencyFromART = 0; + STATIC BOOLEAN ObtainedARTFreq = FALSE; + STATIC UINT64 ARTFrequency = 0; + STATIC UINT64 CPUFrequencyFromART = 0; UINT32 MaxId; UINT32 CpuVendor; @@ -463,11 +464,14 @@ InternalCalculateARTFrequencyIntel ( UINT8 Model; if (Recalculate) { + ObtainedARTFreq = FALSE; ARTFrequency = 0; CPUFrequencyFromART = 0; } - if (ARTFrequency == 0) { + if (!ObtainedARTFreq) { + ObtainedARTFreq = TRUE; + // // Get vendor CPUID 0x00000000 // @@ -686,6 +690,11 @@ InternalCalculateVMTFrequency ( return CpuidEax * 1000ULL; } +// +// This function and everything called by it must not log (after the first early call +// to it, which can log and cache results), otherwise it will generate a loop when it +// gets called during first log line. +// UINT64 OcGetTSCFrequency ( VOID