From bdea875e181d58b22bb93e18b4d3fd50054af154 Mon Sep 17 00:00:00 2001 From: psyq321 Date: Wed, 12 Jan 2022 22:28:25 +0100 Subject: [PATCH] Release 0.1.9 Added support for clang (CLANDWARF in edk2) --- PowerMonkeyApp/ASMx64/ComboHell_AVX2.h | 2 +- PowerMonkeyApp/ASMx64/ComboHell_AVX2.nasm | 2 +- PowerMonkeyApp/ASMx64/SaferAsm.nasm | 54 +++++++++++++++++++- PowerMonkeyApp/CONFIGURATION.c | 2 +- PowerMonkeyApp/CONFIGURATION.h | 2 +- PowerMonkeyApp/Constants.h | 8 ++- PowerMonkeyApp/CpuData.c | 2 +- PowerMonkeyApp/CpuData.h | 2 +- PowerMonkeyApp/CpuDataVR.c | 2 +- PowerMonkeyApp/CpuInfo.c | 25 ++++++---- PowerMonkeyApp/CpuInfo.h | 2 +- PowerMonkeyApp/CpuMailboxes.c | 2 +- PowerMonkeyApp/CpuMailboxes.h | 2 +- PowerMonkeyApp/DelayX86.c | 9 ++-- PowerMonkeyApp/DelayX86.h | 2 +- PowerMonkeyApp/FixedPoint.c | 10 ++-- PowerMonkeyApp/FixedPoint.h | 2 +- PowerMonkeyApp/InterruptHook.c | 2 +- PowerMonkeyApp/InterruptHook.h | 2 +- PowerMonkeyApp/LowLevel.c | 20 ++++---- PowerMonkeyApp/LowLevel.h | 18 +++---- PowerMonkeyApp/MiniLog.c | 2 +- PowerMonkeyApp/MiniLog.h | 12 +++-- PowerMonkeyApp/MpDispatcher.c | 2 +- PowerMonkeyApp/MpDispatcher.h | 4 +- PowerMonkeyApp/OcMailbox.c | 2 +- PowerMonkeyApp/OcMailbox.h | 2 +- PowerMonkeyApp/Platform.c | 20 ++++---- PowerMonkeyApp/Platform.h | 2 +- PowerMonkeyApp/PowerLimits.c | 4 +- PowerMonkeyApp/PowerLimits.h | 2 +- PowerMonkeyApp/PowerMonkey.c | 6 +-- PowerMonkeyApp/PrintStats.c | 2 +- PowerMonkeyApp/PrintStats.h | 2 +- PowerMonkeyApp/SaferAsmHdr.h | 61 +++++++++++++++++------ PowerMonkeyApp/SelfTest.c | 2 +- PowerMonkeyApp/SelfTest.h | 2 +- PowerMonkeyApp/TimeWindows.c | 2 +- PowerMonkeyApp/TimeWindows.h | 2 +- PowerMonkeyApp/TurboRatioLimits.c | 2 +- PowerMonkeyApp/TurboRatioLimits.h | 2 +- PowerMonkeyApp/VFTuning.c | 2 +- PowerMonkeyApp/VFTuning.h | 2 +- PowerMonkeyApp/VisualUefi.c | 2 +- PowerMonkeyApp/VoltTables.c | 2 +- PowerMonkeyApp/VoltTables.h | 2 +- README.MD | 25 +++++++++- 47 files changed, 234 insertions(+), 108 deletions(-) diff --git a/PowerMonkeyApp/ASMx64/ComboHell_AVX2.h b/PowerMonkeyApp/ASMx64/ComboHell_AVX2.h index 8948fb60..f1aed705 100644 --- a/PowerMonkeyApp/ASMx64/ComboHell_AVX2.h +++ b/PowerMonkeyApp/ASMx64/ComboHell_AVX2.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/ASMx64/ComboHell_AVX2.nasm b/PowerMonkeyApp/ASMx64/ComboHell_AVX2.nasm index cac5f271..285aaaa7 100644 --- a/PowerMonkeyApp/ASMx64/ComboHell_AVX2.nasm +++ b/PowerMonkeyApp/ASMx64/ComboHell_AVX2.nasm @@ -9,7 +9,7 @@ BITS 64 ; | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | ; |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | ; (____/ -; Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +; Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. ; ; All trademarks, logos and brand names are the property of their respective ; owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/ASMx64/SaferAsm.nasm b/PowerMonkeyApp/ASMx64/SaferAsm.nasm index 40d43d0d..a0d6254c 100644 --- a/PowerMonkeyApp/ASMx64/SaferAsm.nasm +++ b/PowerMonkeyApp/ASMx64/SaferAsm.nasm @@ -6,7 +6,7 @@ ; | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | ; |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | ; (____/ -; Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +; Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. ; ; All trademarks, logos and brand names are the property of their respective ; owners. All company, product and service names used are for identification @@ -861,7 +861,59 @@ smo_done: pop rdi ret +;------------------------------------------------------------------------------ + +; void +; _pm_cpuid ( +; in u32 func, +; out u32 *regs // EAX EBX ECX EDX, as array of 32-bit integers +; ); +;------------------------------------------------------------------------------ + + global _pm_cpuid + _pm_cpuid: + + push rbx + + mov r10, rdx + mov eax, ecx + + cpuid + + mov dword [r10], eax + mov dword [r10+4 ], ebx + mov dword [r10+8 ], ecx + mov dword [r10+12], edx + + pop rbx + ret +;------------------------------------------------------------------------------ +; void +; _pm_cpuid_ex ( +; in u32 func, +; in u32 subfunc, +; out u32 *regs // EAX EBX ECX EDX, as array of 32-bit integers +; ); +;------------------------------------------------------------------------------ + + global _pm_cpuid_ex + _pm_cpuid_ex: + + push rbx + + mov eax, ecx + mov ecx, edx + + cpuid + + mov dword [r8], eax + mov dword [r8+4 ], ebx + mov dword [r8+8 ], ecx + mov dword [r8+12], edx + + pop rbx + ret section .data global safer_c_isr_fptr diff --git a/PowerMonkeyApp/CONFIGURATION.c b/PowerMonkeyApp/CONFIGURATION.c index dc9fce46..bbf88081 100644 --- a/PowerMonkeyApp/CONFIGURATION.c +++ b/PowerMonkeyApp/CONFIGURATION.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/CONFIGURATION.h b/PowerMonkeyApp/CONFIGURATION.h index 2f9d41f0..2693ce43 100644 --- a/PowerMonkeyApp/CONFIGURATION.h +++ b/PowerMonkeyApp/CONFIGURATION.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/Constants.h b/PowerMonkeyApp/Constants.h index 9b84f712..abf5073a 100644 --- a/PowerMonkeyApp/Constants.h +++ b/PowerMonkeyApp/Constants.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification @@ -30,9 +30,15 @@ * ******************************************************************************/ +#if defined(_MSC_VER) #define ALIGN8 __declspec(align(8)) #define ALIGN16 __declspec(align(16)) #define ALIGN32 __declspec(align(32)) +#else +#define ALIGN8 __attribute((aligned(8))) +#define ALIGN16 __attribute((aligned(16))) +#define ALIGN32 __attribute((aligned(32))) +#endif #define IUNUSED(x) (void)x; /******************************************************************************* diff --git a/PowerMonkeyApp/CpuData.c b/PowerMonkeyApp/CpuData.c index 6249d1bd..6079620c 100644 --- a/PowerMonkeyApp/CpuData.c +++ b/PowerMonkeyApp/CpuData.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/CpuData.h b/PowerMonkeyApp/CpuData.h index 95a4f33f..67d12002 100644 --- a/PowerMonkeyApp/CpuData.h +++ b/PowerMonkeyApp/CpuData.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/CpuDataVR.c b/PowerMonkeyApp/CpuDataVR.c index 7e8f4ca2..c49551de 100644 --- a/PowerMonkeyApp/CpuDataVR.c +++ b/PowerMonkeyApp/CpuDataVR.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/CpuInfo.c b/PowerMonkeyApp/CpuInfo.c index 49cbf1a0..8e06c9d4 100644 --- a/PowerMonkeyApp/CpuInfo.c +++ b/PowerMonkeyApp/CpuInfo.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification @@ -34,8 +34,6 @@ * ******************************************************************************/ -#pragma intrinsic(__cpuid) -#pragma intrinsic(__cpuidex) extern void* memset(void* str, int c, UINTN n); /******************************************************************************* @@ -54,9 +52,9 @@ void GetCpuInfo(CPUINFO* ci) UINT32* venstr = (UINT32 *)ci->venString; UINT32* brandstr = (UINT32*)ci->brandString; - __cpuid(venstr, 0x80000002); - __cpuid(venstr+4, 0x80000003); - __cpuid(venstr+12, 0x80000004); + _pm_cpuid(0x80000002, venstr); + _pm_cpuid(0x80000003, venstr+4); + _pm_cpuid(0x80000004, venstr+12); /////////////////// // Vendor String // @@ -64,15 +62,17 @@ void GetCpuInfo(CPUINFO* ci) UINT32 args[4] = {0}; - __cpuid(args, 0x00000000); + _pm_cpuid(0, args); + UINT32 hscall = ci->maxf = args[0]; + brandstr[0] = args[1]; brandstr[1] = args[3]; brandstr[2] = args[2]; - memset(args, 0, sizeof(args)); - __cpuid(args, 0x01); + + _pm_cpuid(0x01, args); ci->f1 = args[0]; ci->stepping = args[0] & 0x0000000F; @@ -90,15 +90,18 @@ void GetCpuInfo(CPUINFO* ci) /////////////////////////////////// memset(args, 0, sizeof(args)); - __cpuid(args, 0x7); + + _pm_cpuid(0x7, args); ci->HybridArch = (args[3] & bit15u32) ? 1 : 0; if (ci->HybridArch) { if (hscall >= 0x1A) { + memset(args, 0, sizeof(args)); - __cpuid(args, 0x1A); + + _pm_cpuid(0x1A, args); UINT32 ct = ((args[0] & 0xFF000000) >> 24); diff --git a/PowerMonkeyApp/CpuInfo.h b/PowerMonkeyApp/CpuInfo.h index 7b2f3e41..3b78b380 100644 --- a/PowerMonkeyApp/CpuInfo.h +++ b/PowerMonkeyApp/CpuInfo.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/CpuMailboxes.c b/PowerMonkeyApp/CpuMailboxes.c index fd9adb9c..a0b03862 100644 --- a/PowerMonkeyApp/CpuMailboxes.c +++ b/PowerMonkeyApp/CpuMailboxes.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/CpuMailboxes.h b/PowerMonkeyApp/CpuMailboxes.h index 75c2b64c..2e61343a 100644 --- a/PowerMonkeyApp/CpuMailboxes.h +++ b/PowerMonkeyApp/CpuMailboxes.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/DelayX86.c b/PowerMonkeyApp/DelayX86.c index 4b1ff1f6..9577bd5e 100644 --- a/PowerMonkeyApp/DelayX86.c +++ b/PowerMonkeyApp/DelayX86.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification @@ -30,10 +30,11 @@ #include #include "CpuInfo.h" #include "CpuData.h" +#include "SaferAsmHdr.h" +#include #pragma intrinsic(__rdtsc) // At this point, code will look so #pragma intrinsic(_mm_pause) // fugly that writing it in pure SMM -#pragma intrinsic(__cpuid) // assembly would count as beautify /******************************************************************************* * Globals that must be initialized @@ -52,7 +53,7 @@ EFI_STATUS EFIAPI InitializeTscVars(VOID) UINT32 regs[4] = { 0 }; if(gCpuInfo.maxf >= 0x15) - __cpuid(regs, 0x15); + _pm_cpuid(0x15, regs); gXtalFreq = regs[2]; @@ -73,7 +74,7 @@ EFI_STATUS EFIAPI InitializeTscVars(VOID) UINT32 regs2[4] = { 0 }; if (gCpuInfo.maxf >= 0x15) - __cpuid(regs2, 0x16); + _pm_cpuid(0x16, regs2); gXtalFreq = (UINT64)regs2[0] * 1000000 * (UINT64)regs[0] / (UINT64)regs[1]; diff --git a/PowerMonkeyApp/DelayX86.h b/PowerMonkeyApp/DelayX86.h index 1e5b40b1..1b947d72 100644 --- a/PowerMonkeyApp/DelayX86.h +++ b/PowerMonkeyApp/DelayX86.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/FixedPoint.c b/PowerMonkeyApp/FixedPoint.c index d6a0a49c..0d79e420 100644 --- a/PowerMonkeyApp/FixedPoint.c +++ b/PowerMonkeyApp/FixedPoint.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification @@ -56,7 +56,7 @@ UINT16 cvrt_offsetvolts_i16_tofix(const INT16 in) /// you will need to replace the code in this routine /// - UINT64 nvolts = sizeof(OffsetVolts_S11) / sizeof(VOLTS16); + UINT64 nvolts = sizeof(OffsetVolts_S11) / (sizeof(VOLTS16)); VOLTS16* vtbl = (VOLTS16*)&OffsetVolts_S11[0]; if (in == 0) @@ -82,7 +82,7 @@ INT16 cvrt_offsetvolts_fxto_i16(const UINT16 in) /// you will need to replace the code in this routine /// - UINT64 nvolts = sizeof(OffsetVolts_S11) / sizeof(VOLTS16); + UINT64 nvolts = sizeof(OffsetVolts_S11) / (sizeof(VOLTS16)); VOLTS16* vtbl = (VOLTS16*)&OffsetVolts_S11[0]; if (in == 0) @@ -109,7 +109,7 @@ UINT16 cvrt_ovrdvolts_fxto_i16(const UINT16 in) /// you will need to replace the code in this routine /// - UINT64 nvolts = sizeof(OverrdVolts_U12) / sizeof(VOLTS16); + UINT64 nvolts = sizeof(OverrdVolts_U12) / (sizeof(VOLTS16)); VOLTS16* vtbl = (VOLTS16*)&OverrdVolts_U12[0]; if (in == 0) @@ -135,7 +135,7 @@ UINT16 cvrt_ovrdvolts_i16_tofix(const UINT16 in) /// you will need to replace the code in this routine /// - UINT64 nvolts = sizeof(OverrdVolts_U12) / sizeof(VOLTS16); + UINT64 nvolts = sizeof(OverrdVolts_U12) / (sizeof(VOLTS16)); VOLTS16* vtbl = (VOLTS16*)&OverrdVolts_U12[0]; if (in == 0) diff --git a/PowerMonkeyApp/FixedPoint.h b/PowerMonkeyApp/FixedPoint.h index b1054cb9..a2defe3a 100644 --- a/PowerMonkeyApp/FixedPoint.h +++ b/PowerMonkeyApp/FixedPoint.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/InterruptHook.c b/PowerMonkeyApp/InterruptHook.c index 10e93736..70b3e9f6 100644 --- a/PowerMonkeyApp/InterruptHook.c +++ b/PowerMonkeyApp/InterruptHook.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/InterruptHook.h b/PowerMonkeyApp/InterruptHook.h index 79b28260..17ced63f 100644 --- a/PowerMonkeyApp/InterruptHook.h +++ b/PowerMonkeyApp/InterruptHook.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/LowLevel.c b/PowerMonkeyApp/LowLevel.c index 860882aa..abc6c2b2 100644 --- a/PowerMonkeyApp/LowLevel.c +++ b/PowerMonkeyApp/LowLevel.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification @@ -27,11 +27,13 @@ #include #include #include +#include #include "SaferAsmHdr.h" #include "LowLevel.h" #include "MiniLog.h" + /******************************************************************************* * Compiler Overrides ******************************************************************************/ @@ -52,7 +54,7 @@ UINT32 gMCHBAR = 0; typedef struct _MINISTAT { - UINT8 errtxt[128]; + CHAR8 errtxt[128]; UINT64 param1; UINT64 param2; @@ -149,7 +151,7 @@ VOID EFIAPI InitializeMMIO(VOID) * Below routines are wrappers for ASM + Error Handling ******************************************************************************/ -UINT64 pm_rdmsr64(const UINT32 msr_idx) +UINT64 EFIAPI pm_rdmsr64(const UINT32 msr_idx) { UINT32 err = 0; UINT64 val = safer_rdmsr64(msr_idx, &err); @@ -176,7 +178,7 @@ UINT64 pm_rdmsr64(const UINT32 msr_idx) * ******************************************************************************/ -UINT32 pm_wrmsr64(const UINT32 msr_idx, const UINT64 value) +UINT32 EFIAPI pm_wrmsr64(const UINT32 msr_idx, const UINT64 value) { MiniTrace(MINILOG_OPID_WRMSR64, 1, (UINT32)msr_idx, value); @@ -202,7 +204,7 @@ UINT32 pm_wrmsr64(const UINT32 msr_idx, const UINT64 value) * ******************************************************************************/ -UINT32 pm_mmio_read32(const UINT32 addr) +UINT32 EFIAPI pm_mmio_read32(const UINT32 addr) { UINT32 err = 0; UINT32 val = safer_mmio_read32(addr, &err); @@ -229,7 +231,7 @@ UINT32 pm_mmio_read32(const UINT32 addr) * ******************************************************************************/ -UINT32 pm_mmio_or32(const UINT32 addr, const UINT32 value) +UINT32 EFIAPI pm_mmio_or32(const UINT32 addr, const UINT32 value) { MiniTrace(MINILOG_OPID_MMIO_OR32, 0, (UINT64)value | (UINT64)addr<<32, 1); @@ -255,7 +257,7 @@ UINT32 pm_mmio_or32(const UINT32 addr, const UINT32 value) * ******************************************************************************/ -UINT32 pm_mmio_write32(const UINT32 addr, const UINT32 value) +UINT32 EFIAPI pm_mmio_write32(const UINT32 addr, const UINT32 value) { MiniTrace(MINILOG_OPID_MMIO_WRITE32, 0, (UINT64)value | (UINT64)addr << 32, 1); @@ -281,7 +283,7 @@ UINT32 pm_mmio_write32(const UINT32 addr, const UINT32 value) * pm_xio_read64 ******************************************************************************/ -UINT64 pm_xio_read64(const UINT8 tgtype, const UINT32 addr) +UINT64 EFIAPI pm_xio_read64(const UINT8 tgtype, const UINT32 addr) { if (tgtype == IO_MSR) { return pm_rdmsr64(addr); @@ -305,7 +307,7 @@ UINT64 pm_xio_read64(const UINT8 tgtype, const UINT32 addr) * pm_xio_write64 ******************************************************************************/ -UINT32 pm_xio_write64(const UINT8 tgtype, const UINT32 addr, const UINT64 val) +UINT32 EFIAPI pm_xio_write64(const UINT8 tgtype, const UINT32 addr, const UINT64 val) { if (tgtype == IO_MSR) { return pm_wrmsr64(addr, val); diff --git a/PowerMonkeyApp/LowLevel.h b/PowerMonkeyApp/LowLevel.h index a2a42a8f..447179b6 100644 --- a/PowerMonkeyApp/LowLevel.h +++ b/PowerMonkeyApp/LowLevel.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification @@ -51,37 +51,37 @@ VOID EFIAPI SetCpuGSBase(const void* addr); * InitializeMMIO ******************************************************************************/ -void InitializeMMIO(VOID); +void EFIAPI InitializeMMIO(VOID); /******************************************************************************* * pm_wrmsr64 ******************************************************************************/ -UINT32 pm_wrmsr64(const UINT32 msr_idx, const UINT64 value); +UINT32 EFIAPI pm_wrmsr64(const UINT32 msr_idx, const UINT64 value); /******************************************************************************* * pm_rdmsr64 ******************************************************************************/ -UINT64 pm_rdmsr64(const UINT32 msr_idx); +UINT64 EFIAPI pm_rdmsr64(const UINT32 msr_idx); /******************************************************************************* * pm_mmio_or32 ******************************************************************************/ -UINT32 pm_mmio_or32(const UINT32 addr, const UINT32 value); +UINT32 EFIAPI pm_mmio_or32(const UINT32 addr, const UINT32 value); /******************************************************************************* * pm_mmio_write32 ******************************************************************************/ -UINT32 pm_mmio_write32(const UINT32 addr, const UINT32 value); +UINT32 EFIAPI pm_mmio_write32(const UINT32 addr, const UINT32 value); /******************************************************************************* * pm_mmio_read32 ******************************************************************************/ -UINT32 pm_mmio_read32(const UINT32 addr); +UINT32 EFIAPI pm_mmio_read32(const UINT32 addr); /******************************************************************************* * @@ -97,10 +97,10 @@ enum XioType * pm_xio_read64 ******************************************************************************/ -UINT64 pm_xio_read64(const UINT8 tgtype, const UINT32 addr); +UINT64 EFIAPI pm_xio_read64(const UINT8 tgtype, const UINT32 addr); /******************************************************************************* * pm_xio_write64 ******************************************************************************/ -UINT32 pm_xio_write64(const UINT8 tgtype, const UINT32 addr, const UINT64 val); \ No newline at end of file +UINT32 EFIAPI pm_xio_write64(const UINT8 tgtype, const UINT32 addr, const UINT64 val); \ No newline at end of file diff --git a/PowerMonkeyApp/MiniLog.c b/PowerMonkeyApp/MiniLog.c index e2967e53..5a6b403d 100644 --- a/PowerMonkeyApp/MiniLog.c +++ b/PowerMonkeyApp/MiniLog.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/MiniLog.h b/PowerMonkeyApp/MiniLog.h index 8196a180..fbe2c500 100644 --- a/PowerMonkeyApp/MiniLog.h +++ b/PowerMonkeyApp/MiniLog.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification @@ -24,6 +24,12 @@ * *******************************************************************************/ +#if defined(_MSC_VER) +#define UNUSED +#else +#define UNUSED __attribute__((unused)) +#endif + /******************************************************************************* * Configuration ******************************************************************************/ @@ -85,11 +91,11 @@ void MiniTraceEx( #define InitTrace() #define MiniTrace(a, b, c, d) -static void MiniTraceEx( +static void UNUSED MiniTraceEx( IN CONST CHAR8* format, ... ) { - + } diff --git a/PowerMonkeyApp/MpDispatcher.c b/PowerMonkeyApp/MpDispatcher.c index f9311145..1f42d33e 100644 --- a/PowerMonkeyApp/MpDispatcher.c +++ b/PowerMonkeyApp/MpDispatcher.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/MpDispatcher.h b/PowerMonkeyApp/MpDispatcher.h index 41d35f63..b4aa6f2d 100644 --- a/PowerMonkeyApp/MpDispatcher.h +++ b/PowerMonkeyApp/MpDispatcher.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification @@ -32,7 +32,7 @@ EFI_STATUS EFIAPI RunOnPackageOrCore( const IN PLATFORM *Platform, const IN UINTN CpuNumber, const IN EFI_AP_PROCEDURE proc, - const IN VOID *param OPTIONAL + IN VOID *param OPTIONAL ); EFI_STATUS EFIAPI RunOnAllProcessors( diff --git a/PowerMonkeyApp/OcMailbox.c b/PowerMonkeyApp/OcMailbox.c index 7e0a2a9a..394737f5 100644 --- a/PowerMonkeyApp/OcMailbox.c +++ b/PowerMonkeyApp/OcMailbox.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/OcMailbox.h b/PowerMonkeyApp/OcMailbox.h index 2866e1ff..e7ed080e 100644 --- a/PowerMonkeyApp/OcMailbox.h +++ b/PowerMonkeyApp/OcMailbox.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/Platform.c b/PowerMonkeyApp/Platform.c index e55b1f92..50acee03 100644 --- a/PowerMonkeyApp/Platform.c +++ b/PowerMonkeyApp/Platform.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification @@ -194,7 +194,7 @@ BOOLEAN VoltageDomainExists(const UINT8 didx) * ProbePackage ******************************************************************************/ -EFI_STATUS ProbePackage(IN OUT PACKAGE* pkg) +EFI_STATUS EFIAPI ProbePackage(IN OUT PACKAGE* pkg) { EFI_STATUS status = EFI_SUCCESS; @@ -269,7 +269,7 @@ EFI_STATUS ProbePackage(IN OUT PACKAGE* pkg) * ProgramPackageOrCore ******************************************************************************/ -EFI_STATUS ProgramPackageOrCore(IN OUT PACKAGE* pkg) +EFI_STATUS EFIAPI ProgramPackageOrCore(IN OUT PACKAGE* pkg) { EFI_STATUS status = EFI_SUCCESS; @@ -376,7 +376,7 @@ EFI_STATUS ProgramPackageOrCore(IN OUT PACKAGE* pkg) * Program package locks in the separate stage, after everything else is done ******************************************************************************/ -EFI_STATUS ProgramPackage_Stage2(IN OUT PACKAGE* pkg) +EFI_STATUS EFIAPI ProgramPackage_Stage2(IN OUT PACKAGE* pkg) { EFI_STATUS status = EFI_SUCCESS; @@ -394,7 +394,7 @@ EFI_STATUS ProgramPackage_Stage2(IN OUT PACKAGE* pkg) * ProgramPackage_Stage1 ******************************************************************************/ -EFI_STATUS ProgramPackage_Stage1(IN OUT PACKAGE* pkg) +EFI_STATUS EFIAPI ProgramPackage_Stage1(IN OUT PACKAGE* pkg) { EFI_STATUS status = EFI_SUCCESS; @@ -544,7 +544,7 @@ EFI_STATUS EFIAPI ProbePackages(IN OUT PLATFORM* ppd) { PACKAGE* pac = ppd->packages + pidx; - status = RunOnPackageOrCore(ppd, pac->FirstCoreNumber, ProbePackage, pac); + status = RunOnPackageOrCore(ppd, pac->FirstCoreNumber, (EFI_AP_PROCEDURE)ProbePackage, pac); if (EFI_ERROR(status)) { Print(L"[ERROR] CPU package %u, status code: 0x%x\n", @@ -751,7 +751,7 @@ EFI_STATUS EFIAPI ApplyPolicy(IN EFI_SYSTEM_TABLE* SystemTable, for (UINTN cidx = 0; cidx < pk->LogicalCores; cidx++) { CPUCORE* core = pk->Core + cidx; - RunOnPackageOrCore(sys, core->AbsIdx, ProgramPackageOrCore, pk); + RunOnPackageOrCore(sys, core->AbsIdx, (EFI_AP_PROCEDURE)ProgramPackageOrCore, pk); } } @@ -765,7 +765,7 @@ EFI_STATUS EFIAPI ApplyPolicy(IN EFI_SYSTEM_TABLE* SystemTable, for (UINTN pidx = 0; pidx < sys->PkgCnt; pidx++) { PACKAGE* pk = sys->packages + pidx; - RunOnPackageOrCore(sys, pk->FirstCoreNumber, ProgramPackage_Stage1, pk); + RunOnPackageOrCore(sys, pk->FirstCoreNumber, (EFI_AP_PROCEDURE)ProgramPackage_Stage1, pk); } ///////////////// @@ -775,7 +775,7 @@ EFI_STATUS EFIAPI ApplyPolicy(IN EFI_SYSTEM_TABLE* SystemTable, // // MSR Locks - RunOnAllProcessors(ProgramCoreKnobs, FALSE, (void *)sys); + RunOnAllProcessors((EFI_AP_PROCEDURE)ProgramCoreKnobs, FALSE, (void *)sys); // // MMIO locks @@ -783,7 +783,7 @@ EFI_STATUS EFIAPI ApplyPolicy(IN EFI_SYSTEM_TABLE* SystemTable, for (UINTN pidx = 0; pidx < sys->PkgCnt; pidx++) { PACKAGE* pk = sys->packages + pidx; - RunOnPackageOrCore(sys, pk->FirstCoreNumber, ProgramPackage_Stage2, pk); + RunOnPackageOrCore(sys, pk->FirstCoreNumber, (EFI_AP_PROCEDURE)ProgramPackage_Stage2, pk); } //////////////////// diff --git a/PowerMonkeyApp/Platform.h b/PowerMonkeyApp/Platform.h index bfbf3dae..1cbd37f8 100644 --- a/PowerMonkeyApp/Platform.h +++ b/PowerMonkeyApp/Platform.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/PowerLimits.c b/PowerMonkeyApp/PowerLimits.c index ac9a3ef0..36b5fe72 100644 --- a/PowerMonkeyApp/PowerLimits.c +++ b/PowerMonkeyApp/PowerLimits.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification @@ -28,7 +28,7 @@ #include #include -#include "VfTuning.h" +#include "VFTuning.h" #include "LowLevel.h" #include "DelayX86.h" #include "TimeWindows.h" diff --git a/PowerMonkeyApp/PowerLimits.h b/PowerMonkeyApp/PowerLimits.h index 3e253f92..7e0ecb78 100644 --- a/PowerMonkeyApp/PowerLimits.h +++ b/PowerMonkeyApp/PowerLimits.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/PowerMonkey.c b/PowerMonkeyApp/PowerMonkey.c index dad1671c..082d0eec 100644 --- a/PowerMonkeyApp/PowerMonkey.c +++ b/PowerMonkeyApp/PowerMonkey.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification @@ -262,11 +262,11 @@ VOID PrintBanner(VOID) " | ____// _ \\ | | | | / _ ) / __)| || || | / _ \\ | _ \\ | | / )/ _ )| | | |\n" " | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| |\n" " |_| \\___/ \\____| \\____)|_| |_||_||_| \\___/ |_| |_||_| \\_)\\____) \\__ |\n" - " Version 0.1.8 (____/\n" + " Version 0.1.9 (____/\n" ); AsciiPrint( - " Copyright (C) 2021 Ivan Dimkovic. All rights reserved.\n" + " Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved.\n" "\n" " SPDX-License-Identifier: Apache-2.0\n" "\n" diff --git a/PowerMonkeyApp/PrintStats.c b/PowerMonkeyApp/PrintStats.c index 3c86a202..6b50325e 100644 --- a/PowerMonkeyApp/PrintStats.c +++ b/PowerMonkeyApp/PrintStats.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/PrintStats.h b/PowerMonkeyApp/PrintStats.h index 960a668f..3b594fab 100644 --- a/PowerMonkeyApp/PrintStats.h +++ b/PowerMonkeyApp/PrintStats.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/SaferAsmHdr.h b/PowerMonkeyApp/SaferAsmHdr.h index 0eb8496f..f24a72d2 100644 --- a/PowerMonkeyApp/SaferAsmHdr.h +++ b/PowerMonkeyApp/SaferAsmHdr.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification @@ -34,38 +34,71 @@ extern "C" { * Below calls are implemented in SaferAsm.asm ******************************************************************************/ -VOID stop_interrupts_on_this_cpu(VOID); -VOID resume_interrupts_on_this_cpu(VOID); +// +// CLI -UINT64 safer_rdmsr64( +VOID EFIAPI stop_interrupts_on_this_cpu(VOID); + +// +// STI + +VOID EFIAPI resume_interrupts_on_this_cpu(VOID); + +// +// RDMSR + +UINT64 EFIAPI safer_rdmsr64( const UINT32 msr_idx, UINT32* is_err); -UINT32 safer_wrmsr64( +// +// WRMSR + +UINT32 EFIAPI safer_wrmsr64( const UINT32 msr_idx, const UINT64 value); -UINT32 safer_mmio_read32( +// +// MMIO_READ32 + +UINT32 EFIAPI safer_mmio_read32( const UINT32 addr, UINT32* is_err); -UINT32 safer_mmio_or32( +// +// MMIO_OR32 + +UINT32 EFIAPI safer_mmio_or32( const UINT32 addr, const UINT32 value); -UINT32 safer_mmio_write32( +// +// MMIO_WRITE32 + +UINT32 EFIAPI safer_mmio_write32( const UINT32 addr, const UINT32 value); -VOID get_current_idtr(VOID* pidtr); +// +// SIDT + +VOID EFIAPI get_current_idtr(VOID* pidtr); + +// +// CPUID + +VOID EFIAPI _pm_cpuid(const UINT32 func, UINT32 *regs); +VOID EFIAPI _pm_cpuid_ex(const UINT32 func, const UINT32 subfunc, UINT32 *regs); + + +UINT32 EFIAPI get_pciex_base_addr(VOID); -UINT32 get_pciex_base_addr(VOID); +UINT64 EFIAPI hlp_atomic_increment_u64(UINT64 *val); +UINT64 EFIAPI hlp_atomic_decrement_u64(UINT64* val); -UINT64 hlp_atomic_increment_u64(UINT64 *val); -UINT64 hlp_atomic_decrement_u64(UINT64* val); +UINT32 EFIAPI hlp_atomic_increment_u32(UINT32* val); +UINT32 EFIAPI hlp_atomic_decrement_u32(UINT32* val); -UINT32 hlp_atomic_increment_u32(UINT32* val); -UINT32 hlp_atomic_decrement_u32(UINT32* val); /******************************************************************************* * ISR entry points in SaferAsm.asm diff --git a/PowerMonkeyApp/SelfTest.c b/PowerMonkeyApp/SelfTest.c index 5e1154b5..64405da8 100644 --- a/PowerMonkeyApp/SelfTest.c +++ b/PowerMonkeyApp/SelfTest.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/SelfTest.h b/PowerMonkeyApp/SelfTest.h index 570c4fdb..e61d9713 100644 --- a/PowerMonkeyApp/SelfTest.h +++ b/PowerMonkeyApp/SelfTest.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/TimeWindows.c b/PowerMonkeyApp/TimeWindows.c index f820441f..baaacc14 100644 --- a/PowerMonkeyApp/TimeWindows.c +++ b/PowerMonkeyApp/TimeWindows.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/TimeWindows.h b/PowerMonkeyApp/TimeWindows.h index b9cdd936..d6fefb7a 100644 --- a/PowerMonkeyApp/TimeWindows.h +++ b/PowerMonkeyApp/TimeWindows.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/TurboRatioLimits.c b/PowerMonkeyApp/TurboRatioLimits.c index c7eb48e5..46764736 100644 --- a/PowerMonkeyApp/TurboRatioLimits.c +++ b/PowerMonkeyApp/TurboRatioLimits.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/TurboRatioLimits.h b/PowerMonkeyApp/TurboRatioLimits.h index bad50ef9..46411271 100644 --- a/PowerMonkeyApp/TurboRatioLimits.h +++ b/PowerMonkeyApp/TurboRatioLimits.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/VFTuning.c b/PowerMonkeyApp/VFTuning.c index bdf493c5..c3cfdcd1 100644 --- a/PowerMonkeyApp/VFTuning.c +++ b/PowerMonkeyApp/VFTuning.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/VFTuning.h b/PowerMonkeyApp/VFTuning.h index cf4900d9..283cb5ca 100644 --- a/PowerMonkeyApp/VFTuning.h +++ b/PowerMonkeyApp/VFTuning.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/VisualUefi.c b/PowerMonkeyApp/VisualUefi.c index 478b4872..a8704667 100644 --- a/PowerMonkeyApp/VisualUefi.c +++ b/PowerMonkeyApp/VisualUefi.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/VoltTables.c b/PowerMonkeyApp/VoltTables.c index 222f36e7..35075823 100644 --- a/PowerMonkeyApp/VoltTables.c +++ b/PowerMonkeyApp/VoltTables.c @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/PowerMonkeyApp/VoltTables.h b/PowerMonkeyApp/VoltTables.h index 059d1cf1..3cecf41e 100644 --- a/PowerMonkeyApp/VoltTables.h +++ b/PowerMonkeyApp/VoltTables.h @@ -6,7 +6,7 @@ * | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | * |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | * (____/ -* Copyright (C) 2021 Ivan Dimkovic. All rights reserved. +* Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. * * All trademarks, logos and brand names are the property of their respective * owners. All company, product and service names used are for identification diff --git a/README.MD b/README.MD index 2ace8f40..622bb096 100644 --- a/README.MD +++ b/README.MD @@ -8,7 +8,7 @@ | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| | |_| \___/ \____| \____)|_| |_||_||_| \___/ |_| |_||_| \_)\____) \__ | (____/ - Copyright (C) 2021 Ivan Dimkovic. All rights reserved. + Copyright (C) 2021-2022 Ivan Dimkovic. All rights reserved. WARNING: This code is a proof of concept for educative purposes. It can modify internal computer configuration parameters and cause malfunctions or @@ -38,6 +38,7 @@ - [Extra 650 MHz and energy saved? Where is the catch?](#extra-650-mhz-and-energy-saved-where-is-the-catch) - [Moving onto Hyper-V](#moving-onto-hyper-v) - [**Even Better Undervolting: V/F Point Adjustment**](#even-better-undervolting-vf-point-adjustment) + - [**Click Here for Detailed Recipe with 12900K Results**](#click-here-for-detailed-recipe-with-12900k-results) ## What is PowerMonkey? @@ -158,6 +159,26 @@ This route is based on Alex Ionescu's excellent [VisualUEFI project](https://git #### **Building - EDK2 route:** +NOTE: Only MSVC (VS2019) and CLANG (CLANGDWARF) toolchains are validated. For CLANGDWARF toolchain, you will need to add: + +`DEBUG_CLANGDWARF_X64_DLINK_FLAGS =`**` -z notext ... `**

`RELEASE_CLANGDWARF_X64_DLINK_FLAGS =`**` -z notext ... `**

`NOOPT_CLANGDWARF_X64_DLINK_FLAGS =`**` -z notext ... `** + +```lang-makefile +DEBUG_CLANGDWARF_X64_CC_FLAGS = DEF(CLANG38_ALL_CC_FLAGS) -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -fpie -Oz -flto DEF(CLANG38_X64_TARGET) -g +DEBUG_CLANGDWARF_X64_DLINK_FLAGS = DEF(CLANGDWARF_IA32_X64_DLINK_FLAGS) ``` **` -z notext `** ``` -flto -Wl,-O3 -Wl,-melf_x86_64 -Wl,--oformat,elf64-x86-64 -Wl,-pie -mcmodel=small -Wl,--apply-dynamic-relocs +DEBUG_CLANGDWARF_X64_DLINK2_FLAGS = DEF(CLANGDWARF_X64_DLINK2_FLAGS) -O3 -fuse-ld=lld + +RELEASE_CLANGDWARF_X64_CC_FLAGS = DEF(CLANG38_ALL_CC_FLAGS) -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -fpie -Oz -flto DEF(CLANG38_X64_TARGET) +RELEASE_CLANGDWARF_X64_DLINK_FLAGS = DEF(CLANGDWARF_IA32_X64_DLINK_FLAGS) -z notext -flto -Wl,-O3 -Wl,-melf_x86_64 -Wl,--oformat,elf64-x86-64 -Wl,-pie -mcmodel=small -Wl,--apply-dynamic-relocs +RELEASE_CLANGDWARF_X64_DLINK2_FLAGS = DEF(CLANGDWARF_X64_DLINK2_FLAGS) -O3 -fuse-ld=lld + +NOOPT_CLANGDWARF_X64_CC_FLAGS = DEF(CLANG38_ALL_CC_FLAGS) -m64 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -fpie -O0 DEF(CLANG38_X64_TARGET) -g +NOOPT_CLANGDWARF_X64_DLINK_FLAGS = DEF(CLANGDWARF_IA32_X64_DLINK_FLAGS) -z notext -Wl,-O0 -Wl,-melf_x86_64 -Wl,--oformat,elf64-x86-64 -Wl,-pie -mcmodel=small -Wl,--apply-dynamic-relocs +NOOPT_CLANGDWARF_X64_DLINK2_FLAGS = DEF(CLANGDWARF_X64_DLINK2_FLAGS) -O0 -fuse-ld=lld +``` + +**EDK2 Build Steps:** + 1. Download EDK2 source from [https://github.com/tianocore/edk2](https://github.com/tianocore/edk2) - ideally, the EDK2 version shall match your computer firmware “baseline EDK2 version” in case your UEFI firmware is based on TianoCore. 2. Store PowerMonkeyApp directory (and its subdirectories) in the ```/MdeModulePkg/Application``` subdirectory of EDK2 workspace. The result shall look something like this (there will be more directories): @@ -315,6 +336,8 @@ Differences are less drastic compared to Cinebench, which is to be expected as L ### **Even Better Undervolting: V/F Point Adjustment** +#### [**Click Here for Detailed Recipe with 12900K Results**](docs/vfpoint_tuning.md) + Unlocked CML, RKL, TGL and ADL chips offer even more advanced tweaking of voltages: per individual points on Voltage/frequency curve. While there will be a separate guide on this, here is a quick preview of V/F Point Adjustment in action, with Alder Lake CPU: ![AlderRun](img/alder_run.png)