Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 984caf0

Browse files
committed
improved CPU check
1 parent 4a0c8db commit 984caf0

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

src/main.cpp

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <Windows.h>
22
#include <powerbase.h>
33
#include <tbs.h>
4+
#include <intrin.h>
45
#include <string>
56
#include <iostream>
67
#include <fstream>
@@ -118,7 +119,7 @@ int main(int, char* argv[])
118119
std::cout << "S Mode check passed!" << std::endl;
119120
}
120121

121-
// 1 Ghz, 64-bit, dual core CPU
122+
// 1 Ghz, 64-bit, dual core, known CPU
122123
{
123124
std::cout << "CPU checking..." << std::endl;
124125

@@ -190,16 +191,65 @@ int main(int, char* argv[])
190191
nSpeedCheckCounter++;
191192
}
192193
}
194+
HeapFree(hProcHeap, 0, lpBuffer);
193195

194196
if (nSpeedCheckCounter < 2)
195197
{
196-
HeapFree(hProcHeap, 0, lpBuffer);
197198
std::cerr << "System processor speed is less than minimum requirement!" << std::endl;
198199
std::system("PAUSE");
199200
return EXIT_FAILURE;
200201
}
201202

202-
HeapFree(hProcHeap, 0, lpBuffer);
203+
const auto dwRevision = sysInfo.wProcessorRevision >> 8;
204+
const auto byRevision = LOBYTE(sysInfo.wProcessorRevision);
205+
206+
int CPUIDINF[4]{ 0 };
207+
__cpuid(CPUIDINF, 0);
208+
209+
std::string stVendor;
210+
stVendor += std::string(reinterpret_cast<const char*>(&CPUIDINF[1]), sizeof(CPUIDINF[1]));
211+
stVendor += std::string(reinterpret_cast<const char*>(&CPUIDINF[3]), sizeof(CPUIDINF[3]));
212+
stVendor += std::string(reinterpret_cast<const char*>(&CPUIDINF[2]), sizeof(CPUIDINF[2]));
213+
214+
std::cout << "\tProcessor level: " << sysInfo.wProcessorLevel << " revision: " << dwRevision << " " << byRevision << " vendor: " << stVendor << std::endl;
215+
216+
// Reversed checks from Windows's tool
217+
if (stVendor == "AuthenticAMD")
218+
{
219+
if (sysInfo.wProcessorLevel < 0x17 || sysInfo.wProcessorLevel == 23 && !((dwRevision - 1) & 0xFFFFFFEF))
220+
{
221+
std::cerr << "Unsupported AMD CPU detected!" << std::endl;
222+
std::system("PAUSE");
223+
return EXIT_FAILURE;
224+
}
225+
}
226+
else if (stVendor == "GenuineIntel")
227+
{
228+
if (sysInfo.wProcessorLevel == 6)
229+
{
230+
if ((dwRevision < 0x5F && dwRevision != 85) ||
231+
(dwRevision == 142 && byRevision == 9) ||
232+
(dwRevision == 158 && byRevision == 9))
233+
{
234+
std::cerr << "Unsupported Intel CPU detected!" << std::endl;
235+
std::system("PAUSE");
236+
return EXIT_FAILURE;
237+
}
238+
}
239+
}
240+
else if (stVendor.find("Qualcomm") == std::string::npos)
241+
{
242+
std::cerr << "Unknown CPU vendor detected!" << std::endl;
243+
std::system("PAUSE");
244+
return EXIT_FAILURE;
245+
}
246+
else if (!IsProcessorFeaturePresent(PF_ARM_V81_ATOMIC_INSTRUCTIONS_AVAILABLE))
247+
{
248+
std::cerr << "Unsupported Qualcomm CPU detected!" << std::endl;
249+
std::system("PAUSE");
250+
return EXIT_FAILURE;
251+
}
252+
203253
std::cout << "CPU check passed!" << std::endl;
204254
}
205255

0 commit comments

Comments
 (0)