1370b324cSopenharmony_ci// Windows/SystemInfo.cpp 2370b324cSopenharmony_ci 3370b324cSopenharmony_ci#include "StdAfx.h" 4370b324cSopenharmony_ci 5370b324cSopenharmony_ci#include "../../C/CpuArch.h" 6370b324cSopenharmony_ci 7370b324cSopenharmony_ci#include "../Common/IntToString.h" 8370b324cSopenharmony_ci 9370b324cSopenharmony_ci#ifdef _WIN32 10370b324cSopenharmony_ci 11370b324cSopenharmony_ci#include "Registry.h" 12370b324cSopenharmony_ci 13370b324cSopenharmony_ci#else 14370b324cSopenharmony_ci 15370b324cSopenharmony_ci#include <unistd.h> 16370b324cSopenharmony_ci#include <sys/utsname.h> 17370b324cSopenharmony_ci#ifdef __APPLE__ 18370b324cSopenharmony_ci#include <sys/sysctl.h> 19370b324cSopenharmony_ci#elif !defined(_AIX) 20370b324cSopenharmony_ci 21370b324cSopenharmony_ci#include <sys/auxv.h> 22370b324cSopenharmony_ci 23370b324cSopenharmony_ci// #undef AT_HWCAP // to debug 24370b324cSopenharmony_ci// #undef AT_HWCAP2 // to debug 25370b324cSopenharmony_ci 26370b324cSopenharmony_ci/* the following patch for some debian systems. 27370b324cSopenharmony_ci Is it OK to define AT_HWCAP and AT_HWCAP2 here with these constant numbers? */ 28370b324cSopenharmony_ci/* 29370b324cSopenharmony_ci#if defined(__FreeBSD_kernel__) && defined(__GLIBC__) 30370b324cSopenharmony_ci #ifndef AT_HWCAP 31370b324cSopenharmony_ci #define AT_HWCAP 16 32370b324cSopenharmony_ci #endif 33370b324cSopenharmony_ci #ifndef AT_HWCAP2 34370b324cSopenharmony_ci #define AT_HWCAP2 26 35370b324cSopenharmony_ci #endif 36370b324cSopenharmony_ci#endif 37370b324cSopenharmony_ci*/ 38370b324cSopenharmony_ci 39370b324cSopenharmony_ci#ifdef MY_CPU_ARM_OR_ARM64 40370b324cSopenharmony_ci#include <asm/hwcap.h> 41370b324cSopenharmony_ci#endif 42370b324cSopenharmony_ci#endif 43370b324cSopenharmony_ci 44370b324cSopenharmony_ci#ifdef __linux__ 45370b324cSopenharmony_ci#include "../Windows/FileIO.h" 46370b324cSopenharmony_ci#endif 47370b324cSopenharmony_ci 48370b324cSopenharmony_ci#endif // WIN32 49370b324cSopenharmony_ci 50370b324cSopenharmony_ci#include "SystemInfo.h" 51370b324cSopenharmony_ci#include "System.h" 52370b324cSopenharmony_ci 53370b324cSopenharmony_ciusing namespace NWindows; 54370b324cSopenharmony_ci 55370b324cSopenharmony_ci#ifdef __linux__ 56370b324cSopenharmony_ci 57370b324cSopenharmony_cistatic bool ReadFile_to_Buffer(CFSTR fileName, CByteBuffer &buf) 58370b324cSopenharmony_ci{ 59370b324cSopenharmony_ci NWindows::NFile::NIO::CInFile file; 60370b324cSopenharmony_ci if (!file.Open(fileName)) 61370b324cSopenharmony_ci return false; 62370b324cSopenharmony_ci /* 63370b324cSopenharmony_ci UInt64 size; 64370b324cSopenharmony_ci if (!file.GetLength(size)) 65370b324cSopenharmony_ci { 66370b324cSopenharmony_ci // GetLength() doesn't work "/proc/cpuinfo" 67370b324cSopenharmony_ci return false; 68370b324cSopenharmony_ci } 69370b324cSopenharmony_ci if (size >= ((UInt32)1 << 29)) 70370b324cSopenharmony_ci return false; 71370b324cSopenharmony_ci */ 72370b324cSopenharmony_ci size_t size = 0; 73370b324cSopenharmony_ci size_t addSize = ((size_t)1 << 12); 74370b324cSopenharmony_ci for (;;) 75370b324cSopenharmony_ci { 76370b324cSopenharmony_ci // printf("\nsize = %d\n", (unsigned)size); 77370b324cSopenharmony_ci buf.ChangeSize_KeepData(size + addSize, size); 78370b324cSopenharmony_ci size_t processed; 79370b324cSopenharmony_ci if (!file.ReadFull(buf + size, addSize, processed)) 80370b324cSopenharmony_ci return false; 81370b324cSopenharmony_ci if (processed == 0) 82370b324cSopenharmony_ci { 83370b324cSopenharmony_ci buf.ChangeSize_KeepData(size, size); 84370b324cSopenharmony_ci return true; 85370b324cSopenharmony_ci } 86370b324cSopenharmony_ci size += processed; 87370b324cSopenharmony_ci addSize *= 2; 88370b324cSopenharmony_ci } 89370b324cSopenharmony_ci} 90370b324cSopenharmony_ci 91370b324cSopenharmony_ci#endif 92370b324cSopenharmony_ci 93370b324cSopenharmony_ci 94370b324cSopenharmony_ci#if defined(_WIN32) || defined(AT_HWCAP) || defined(AT_HWCAP2) 95370b324cSopenharmony_cistatic void PrintHex(AString &s, UInt64 v) 96370b324cSopenharmony_ci{ 97370b324cSopenharmony_ci char temp[32]; 98370b324cSopenharmony_ci ConvertUInt64ToHex(v, temp); 99370b324cSopenharmony_ci s += temp; 100370b324cSopenharmony_ci} 101370b324cSopenharmony_ci#endif 102370b324cSopenharmony_ci 103370b324cSopenharmony_ci#ifdef MY_CPU_X86_OR_AMD64 104370b324cSopenharmony_ci 105370b324cSopenharmony_ciZ7_NO_INLINE 106370b324cSopenharmony_cistatic void PrintCpuChars(AString &s, UInt32 v) 107370b324cSopenharmony_ci{ 108370b324cSopenharmony_ci for (unsigned j = 0; j < 4; j++) 109370b324cSopenharmony_ci { 110370b324cSopenharmony_ci Byte b = (Byte)(v & 0xFF); 111370b324cSopenharmony_ci v >>= 8; 112370b324cSopenharmony_ci if (b == 0) 113370b324cSopenharmony_ci break; 114370b324cSopenharmony_ci if (b >= 0x20 && b <= 0x7f) 115370b324cSopenharmony_ci s += (char)b; 116370b324cSopenharmony_ci else 117370b324cSopenharmony_ci { 118370b324cSopenharmony_ci s += '['; 119370b324cSopenharmony_ci char temp[16]; 120370b324cSopenharmony_ci ConvertUInt32ToHex(b, temp); 121370b324cSopenharmony_ci s += temp; 122370b324cSopenharmony_ci s += ']'; 123370b324cSopenharmony_ci } 124370b324cSopenharmony_ci } 125370b324cSopenharmony_ci} 126370b324cSopenharmony_ci 127370b324cSopenharmony_ci 128370b324cSopenharmony_cistatic void x86cpuid_to_String(AString &s) 129370b324cSopenharmony_ci{ 130370b324cSopenharmony_ci s.Empty(); 131370b324cSopenharmony_ci 132370b324cSopenharmony_ci UInt32 a[4]; 133370b324cSopenharmony_ci // cpuid was called already. So we don't check for cpuid availability here 134370b324cSopenharmony_ci z7_x86_cpuid(a, 0x80000000); 135370b324cSopenharmony_ci 136370b324cSopenharmony_ci if (a[0] >= 0x80000004) // if (maxFunc2 >= hi+4) the full name is available 137370b324cSopenharmony_ci { 138370b324cSopenharmony_ci for (unsigned i = 0; i < 3; i++) 139370b324cSopenharmony_ci { 140370b324cSopenharmony_ci z7_x86_cpuid(a, 0x80000002 + i); 141370b324cSopenharmony_ci for (unsigned j = 0; j < 4; j++) 142370b324cSopenharmony_ci PrintCpuChars(s, a[j]); 143370b324cSopenharmony_ci } 144370b324cSopenharmony_ci } 145370b324cSopenharmony_ci 146370b324cSopenharmony_ci s.Trim(); 147370b324cSopenharmony_ci 148370b324cSopenharmony_ci if (s.IsEmpty()) 149370b324cSopenharmony_ci { 150370b324cSopenharmony_ci z7_x86_cpuid(a, 0); 151370b324cSopenharmony_ci for (unsigned i = 1; i < 4; i++) 152370b324cSopenharmony_ci { 153370b324cSopenharmony_ci const unsigned j = (i ^ (i >> 1)); 154370b324cSopenharmony_ci PrintCpuChars(s, a[j]); 155370b324cSopenharmony_ci } 156370b324cSopenharmony_ci s.Trim(); 157370b324cSopenharmony_ci } 158370b324cSopenharmony_ci} 159370b324cSopenharmony_ci 160370b324cSopenharmony_ci/* 161370b324cSopenharmony_cistatic void x86cpuid_all_to_String(AString &s) 162370b324cSopenharmony_ci{ 163370b324cSopenharmony_ci Cx86cpuid p; 164370b324cSopenharmony_ci if (!x86cpuid_CheckAndRead(&p)) 165370b324cSopenharmony_ci return; 166370b324cSopenharmony_ci s += "x86cpuid maxFunc = "; 167370b324cSopenharmony_ci s.Add_UInt32(p.maxFunc); 168370b324cSopenharmony_ci for (unsigned j = 0; j <= p.maxFunc; j++) 169370b324cSopenharmony_ci { 170370b324cSopenharmony_ci s.Add_LF(); 171370b324cSopenharmony_ci // s.Add_UInt32(j); // align 172370b324cSopenharmony_ci { 173370b324cSopenharmony_ci char temp[32]; 174370b324cSopenharmony_ci ConvertUInt32ToString(j, temp); 175370b324cSopenharmony_ci unsigned len = (unsigned)strlen(temp); 176370b324cSopenharmony_ci while (len < 8) 177370b324cSopenharmony_ci { 178370b324cSopenharmony_ci len++; 179370b324cSopenharmony_ci s.Add_Space(); 180370b324cSopenharmony_ci } 181370b324cSopenharmony_ci s += temp; 182370b324cSopenharmony_ci } 183370b324cSopenharmony_ci 184370b324cSopenharmony_ci s += ":"; 185370b324cSopenharmony_ci UInt32 d[4] = { 0 }; 186370b324cSopenharmony_ci MyCPUID(j, &d[0], &d[1], &d[2], &d[3]); 187370b324cSopenharmony_ci for (unsigned i = 0; i < 4; i++) 188370b324cSopenharmony_ci { 189370b324cSopenharmony_ci char temp[32]; 190370b324cSopenharmony_ci ConvertUInt32ToHex8Digits(d[i], temp); 191370b324cSopenharmony_ci s.Add_Space(); 192370b324cSopenharmony_ci s += temp; 193370b324cSopenharmony_ci } 194370b324cSopenharmony_ci } 195370b324cSopenharmony_ci} 196370b324cSopenharmony_ci*/ 197370b324cSopenharmony_ci 198370b324cSopenharmony_ci#endif 199370b324cSopenharmony_ci 200370b324cSopenharmony_ci 201370b324cSopenharmony_ci 202370b324cSopenharmony_ci#ifdef _WIN32 203370b324cSopenharmony_ci 204370b324cSopenharmony_cistatic const char * const k_PROCESSOR_ARCHITECTURE[] = 205370b324cSopenharmony_ci{ 206370b324cSopenharmony_ci "x86" // "INTEL" 207370b324cSopenharmony_ci , "MIPS" 208370b324cSopenharmony_ci , "ALPHA" 209370b324cSopenharmony_ci , "PPC" 210370b324cSopenharmony_ci , "SHX" 211370b324cSopenharmony_ci , "ARM" 212370b324cSopenharmony_ci , "IA64" 213370b324cSopenharmony_ci , "ALPHA64" 214370b324cSopenharmony_ci , "MSIL" 215370b324cSopenharmony_ci , "x64" // "AMD64" 216370b324cSopenharmony_ci , "IA32_ON_WIN64" 217370b324cSopenharmony_ci , "NEUTRAL" 218370b324cSopenharmony_ci , "ARM64" 219370b324cSopenharmony_ci , "ARM32_ON_WIN64" 220370b324cSopenharmony_ci}; 221370b324cSopenharmony_ci 222370b324cSopenharmony_ci#define Z7_WIN_PROCESSOR_ARCHITECTURE_INTEL 0 223370b324cSopenharmony_ci#define Z7_WIN_PROCESSOR_ARCHITECTURE_AMD64 9 224370b324cSopenharmony_ci 225370b324cSopenharmony_ci 226370b324cSopenharmony_ci#define Z7_WIN_PROCESSOR_INTEL_PENTIUM 586 227370b324cSopenharmony_ci#define Z7_WIN_PROCESSOR_AMD_X8664 8664 228370b324cSopenharmony_ci 229370b324cSopenharmony_ci/* 230370b324cSopenharmony_cistatic const CUInt32PCharPair k_PROCESSOR[] = 231370b324cSopenharmony_ci{ 232370b324cSopenharmony_ci { 2200, "IA64" }, 233370b324cSopenharmony_ci { 8664, "x64" } 234370b324cSopenharmony_ci}; 235370b324cSopenharmony_ci 236370b324cSopenharmony_ci#define PROCESSOR_INTEL_386 386 237370b324cSopenharmony_ci#define PROCESSOR_INTEL_486 486 238370b324cSopenharmony_ci#define PROCESSOR_INTEL_PENTIUM 586 239370b324cSopenharmony_ci#define PROCESSOR_INTEL_860 860 240370b324cSopenharmony_ci#define PROCESSOR_INTEL_IA64 2200 241370b324cSopenharmony_ci#define PROCESSOR_AMD_X8664 8664 242370b324cSopenharmony_ci#define PROCESSOR_MIPS_R2000 2000 243370b324cSopenharmony_ci#define PROCESSOR_MIPS_R3000 3000 244370b324cSopenharmony_ci#define PROCESSOR_MIPS_R4000 4000 245370b324cSopenharmony_ci#define PROCESSOR_ALPHA_21064 21064 246370b324cSopenharmony_ci#define PROCESSOR_PPC_601 601 247370b324cSopenharmony_ci#define PROCESSOR_PPC_603 603 248370b324cSopenharmony_ci#define PROCESSOR_PPC_604 604 249370b324cSopenharmony_ci#define PROCESSOR_PPC_620 620 250370b324cSopenharmony_ci#define PROCESSOR_HITACHI_SH3 10003 251370b324cSopenharmony_ci#define PROCESSOR_HITACHI_SH3E 10004 252370b324cSopenharmony_ci#define PROCESSOR_HITACHI_SH4 10005 253370b324cSopenharmony_ci#define PROCESSOR_MOTOROLA_821 821 254370b324cSopenharmony_ci#define PROCESSOR_SHx_SH3 103 255370b324cSopenharmony_ci#define PROCESSOR_SHx_SH4 104 256370b324cSopenharmony_ci#define PROCESSOR_STRONGARM 2577 // 0xA11 257370b324cSopenharmony_ci#define PROCESSOR_ARM720 1824 // 0x720 258370b324cSopenharmony_ci#define PROCESSOR_ARM820 2080 // 0x820 259370b324cSopenharmony_ci#define PROCESSOR_ARM920 2336 // 0x920 260370b324cSopenharmony_ci#define PROCESSOR_ARM_7TDMI 70001 261370b324cSopenharmony_ci#define PROCESSOR_OPTIL 18767 // 0x494f 262370b324cSopenharmony_ci*/ 263370b324cSopenharmony_ci 264370b324cSopenharmony_ci 265370b324cSopenharmony_ci/* 266370b324cSopenharmony_cistatic const char * const k_PF[] = 267370b324cSopenharmony_ci{ 268370b324cSopenharmony_ci "FP_ERRATA" 269370b324cSopenharmony_ci , "FP_EMU" 270370b324cSopenharmony_ci , "CMPXCHG" 271370b324cSopenharmony_ci , "MMX" 272370b324cSopenharmony_ci , "PPC_MOVEMEM_64BIT" 273370b324cSopenharmony_ci , "ALPHA_BYTE" 274370b324cSopenharmony_ci , "SSE" 275370b324cSopenharmony_ci , "3DNOW" 276370b324cSopenharmony_ci , "RDTSC" 277370b324cSopenharmony_ci , "PAE" 278370b324cSopenharmony_ci , "SSE2" 279370b324cSopenharmony_ci , "SSE_DAZ" 280370b324cSopenharmony_ci , "NX" 281370b324cSopenharmony_ci , "SSE3" 282370b324cSopenharmony_ci , "CMPXCHG16B" 283370b324cSopenharmony_ci , "CMP8XCHG16" 284370b324cSopenharmony_ci , "CHANNELS" 285370b324cSopenharmony_ci , "XSAVE" 286370b324cSopenharmony_ci , "ARM_VFP_32" 287370b324cSopenharmony_ci , "ARM_NEON" 288370b324cSopenharmony_ci , "L2AT" 289370b324cSopenharmony_ci , "VIRT_FIRMWARE" 290370b324cSopenharmony_ci , "RDWRFSGSBASE" 291370b324cSopenharmony_ci , "FASTFAIL" 292370b324cSopenharmony_ci , "ARM_DIVIDE" 293370b324cSopenharmony_ci , "ARM_64BIT_LOADSTORE_ATOMIC" 294370b324cSopenharmony_ci , "ARM_EXTERNAL_CACHE" 295370b324cSopenharmony_ci , "ARM_FMAC" 296370b324cSopenharmony_ci , "RDRAND" 297370b324cSopenharmony_ci , "ARM_V8" 298370b324cSopenharmony_ci , "ARM_V8_CRYPTO" 299370b324cSopenharmony_ci , "ARM_V8_CRC32" 300370b324cSopenharmony_ci , "RDTSCP" 301370b324cSopenharmony_ci , "RDPID" 302370b324cSopenharmony_ci , "ARM_V81_ATOMIC" 303370b324cSopenharmony_ci , "MONITORX" 304370b324cSopenharmony_ci}; 305370b324cSopenharmony_ci*/ 306370b324cSopenharmony_ci 307370b324cSopenharmony_ci#endif 308370b324cSopenharmony_ci 309370b324cSopenharmony_ci 310370b324cSopenharmony_cistatic void PrintPage(AString &s, UInt64 v) 311370b324cSopenharmony_ci{ 312370b324cSopenharmony_ci const char *t = "B"; 313370b324cSopenharmony_ci if ((v & 0x3ff) == 0) 314370b324cSopenharmony_ci { 315370b324cSopenharmony_ci v >>= 10; 316370b324cSopenharmony_ci t = "KB"; 317370b324cSopenharmony_ci } 318370b324cSopenharmony_ci s.Add_UInt64(v); 319370b324cSopenharmony_ci s += t; 320370b324cSopenharmony_ci} 321370b324cSopenharmony_ci 322370b324cSopenharmony_ci#ifdef _WIN32 323370b324cSopenharmony_ci 324370b324cSopenharmony_cistatic AString TypeToString2(const char * const table[], unsigned num, UInt32 value) 325370b324cSopenharmony_ci{ 326370b324cSopenharmony_ci char sz[16]; 327370b324cSopenharmony_ci const char *p = NULL; 328370b324cSopenharmony_ci if (value < num) 329370b324cSopenharmony_ci p = table[value]; 330370b324cSopenharmony_ci if (!p) 331370b324cSopenharmony_ci { 332370b324cSopenharmony_ci ConvertUInt32ToString(value, sz); 333370b324cSopenharmony_ci p = sz; 334370b324cSopenharmony_ci } 335370b324cSopenharmony_ci return (AString)p; 336370b324cSopenharmony_ci} 337370b324cSopenharmony_ci 338370b324cSopenharmony_ci// #if defined(Z7_LARGE_PAGES) || defined(_WIN32) 339370b324cSopenharmony_ci// #ifdef _WIN32 340370b324cSopenharmony_civoid PrintSize_KMGT_Or_Hex(AString &s, UInt64 v) 341370b324cSopenharmony_ci{ 342370b324cSopenharmony_ci char c = 0; 343370b324cSopenharmony_ci if ((v & 0x3FF) == 0) { v >>= 10; c = 'K'; 344370b324cSopenharmony_ci if ((v & 0x3FF) == 0) { v >>= 10; c = 'M'; 345370b324cSopenharmony_ci if ((v & 0x3FF) == 0) { v >>= 10; c = 'G'; 346370b324cSopenharmony_ci if ((v & 0x3FF) == 0) { v >>= 10; c = 'T'; 347370b324cSopenharmony_ci }}}} 348370b324cSopenharmony_ci else 349370b324cSopenharmony_ci { 350370b324cSopenharmony_ci // s += "0x"; 351370b324cSopenharmony_ci PrintHex(s, v); 352370b324cSopenharmony_ci return; 353370b324cSopenharmony_ci } 354370b324cSopenharmony_ci s.Add_UInt64(v); 355370b324cSopenharmony_ci if (c) 356370b324cSopenharmony_ci s += c; 357370b324cSopenharmony_ci s += 'B'; 358370b324cSopenharmony_ci} 359370b324cSopenharmony_ci// #endif 360370b324cSopenharmony_ci// #endif 361370b324cSopenharmony_ci 362370b324cSopenharmony_cistatic void SysInfo_To_String(AString &s, const SYSTEM_INFO &si) 363370b324cSopenharmony_ci{ 364370b324cSopenharmony_ci s += TypeToString2(k_PROCESSOR_ARCHITECTURE, Z7_ARRAY_SIZE(k_PROCESSOR_ARCHITECTURE), si.wProcessorArchitecture); 365370b324cSopenharmony_ci 366370b324cSopenharmony_ci if (!( (si.wProcessorArchitecture == Z7_WIN_PROCESSOR_ARCHITECTURE_INTEL && si.dwProcessorType == Z7_WIN_PROCESSOR_INTEL_PENTIUM) 367370b324cSopenharmony_ci || (si.wProcessorArchitecture == Z7_WIN_PROCESSOR_ARCHITECTURE_AMD64 && si.dwProcessorType == Z7_WIN_PROCESSOR_AMD_X8664))) 368370b324cSopenharmony_ci { 369370b324cSopenharmony_ci s.Add_Space(); 370370b324cSopenharmony_ci // s += TypePairToString(k_PROCESSOR, Z7_ARRAY_SIZE(k_PROCESSOR), si.dwProcessorType); 371370b324cSopenharmony_ci s.Add_UInt32(si.dwProcessorType); 372370b324cSopenharmony_ci } 373370b324cSopenharmony_ci s.Add_Space(); 374370b324cSopenharmony_ci PrintHex(s, si.wProcessorLevel); 375370b324cSopenharmony_ci s.Add_Dot(); 376370b324cSopenharmony_ci PrintHex(s, si.wProcessorRevision); 377370b324cSopenharmony_ci if ((UInt64)si.dwActiveProcessorMask + 1 != ((UInt64)1 << si.dwNumberOfProcessors)) 378370b324cSopenharmony_ci if ((UInt64)si.dwActiveProcessorMask + 1 != 0 || si.dwNumberOfProcessors != sizeof(UInt64) * 8) 379370b324cSopenharmony_ci { 380370b324cSopenharmony_ci s += " act:"; 381370b324cSopenharmony_ci PrintHex(s, si.dwActiveProcessorMask); 382370b324cSopenharmony_ci } 383370b324cSopenharmony_ci s += " cpus:"; 384370b324cSopenharmony_ci s.Add_UInt32(si.dwNumberOfProcessors); 385370b324cSopenharmony_ci if (si.dwPageSize != 1 << 12) 386370b324cSopenharmony_ci { 387370b324cSopenharmony_ci s += " page:"; 388370b324cSopenharmony_ci PrintPage(s, si.dwPageSize); 389370b324cSopenharmony_ci } 390370b324cSopenharmony_ci if (si.dwAllocationGranularity != 1 << 16) 391370b324cSopenharmony_ci { 392370b324cSopenharmony_ci s += " gran:"; 393370b324cSopenharmony_ci PrintPage(s, si.dwAllocationGranularity); 394370b324cSopenharmony_ci } 395370b324cSopenharmony_ci s.Add_Space(); 396370b324cSopenharmony_ci 397370b324cSopenharmony_ci const DWORD_PTR minAdd = (DWORD_PTR)si.lpMinimumApplicationAddress; 398370b324cSopenharmony_ci UInt64 maxSize = (UInt64)(DWORD_PTR)si.lpMaximumApplicationAddress + 1; 399370b324cSopenharmony_ci const UInt32 kReserveSize = ((UInt32)1 << 16); 400370b324cSopenharmony_ci if (minAdd != kReserveSize) 401370b324cSopenharmony_ci { 402370b324cSopenharmony_ci PrintSize_KMGT_Or_Hex(s, minAdd); 403370b324cSopenharmony_ci s += "-"; 404370b324cSopenharmony_ci } 405370b324cSopenharmony_ci else 406370b324cSopenharmony_ci { 407370b324cSopenharmony_ci if ((maxSize & (kReserveSize - 1)) == 0) 408370b324cSopenharmony_ci maxSize += kReserveSize; 409370b324cSopenharmony_ci } 410370b324cSopenharmony_ci PrintSize_KMGT_Or_Hex(s, maxSize); 411370b324cSopenharmony_ci} 412370b324cSopenharmony_ci 413370b324cSopenharmony_ci#ifndef _WIN64 414370b324cSopenharmony_ciEXTERN_C_BEGIN 415370b324cSopenharmony_citypedef VOID (WINAPI *Func_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo); 416370b324cSopenharmony_ciEXTERN_C_END 417370b324cSopenharmony_ci#endif 418370b324cSopenharmony_ci 419370b324cSopenharmony_ci#endif 420370b324cSopenharmony_ci 421370b324cSopenharmony_ci#ifdef __APPLE__ 422370b324cSopenharmony_ci#ifndef MY_CPU_X86_OR_AMD64 423370b324cSopenharmony_cistatic void Add_sysctlbyname_to_String(const char *name, AString &s) 424370b324cSopenharmony_ci{ 425370b324cSopenharmony_ci size_t bufSize = 256; 426370b324cSopenharmony_ci char buf[256]; 427370b324cSopenharmony_ci if (z7_sysctlbyname_Get(name, &buf, &bufSize) == 0) 428370b324cSopenharmony_ci s += buf; 429370b324cSopenharmony_ci} 430370b324cSopenharmony_ci#endif 431370b324cSopenharmony_ci#endif 432370b324cSopenharmony_ci 433370b324cSopenharmony_civoid GetSysInfo(AString &s1, AString &s2); 434370b324cSopenharmony_civoid GetSysInfo(AString &s1, AString &s2) 435370b324cSopenharmony_ci{ 436370b324cSopenharmony_ci s1.Empty(); 437370b324cSopenharmony_ci s2.Empty(); 438370b324cSopenharmony_ci 439370b324cSopenharmony_ci #ifdef _WIN32 440370b324cSopenharmony_ci SYSTEM_INFO si; 441370b324cSopenharmony_ci GetSystemInfo(&si); 442370b324cSopenharmony_ci { 443370b324cSopenharmony_ci SysInfo_To_String(s1, si); 444370b324cSopenharmony_ci // s += " : "; 445370b324cSopenharmony_ci } 446370b324cSopenharmony_ci 447370b324cSopenharmony_ci #if !defined(_WIN64) && !defined(UNDER_CE) 448370b324cSopenharmony_ci const 449370b324cSopenharmony_ci Func_GetNativeSystemInfo fn = Z7_GET_PROC_ADDRESS( 450370b324cSopenharmony_ci Func_GetNativeSystemInfo, GetModuleHandleA("kernel32.dll"), 451370b324cSopenharmony_ci "GetNativeSystemInfo"); 452370b324cSopenharmony_ci if (fn) 453370b324cSopenharmony_ci { 454370b324cSopenharmony_ci SYSTEM_INFO si2; 455370b324cSopenharmony_ci fn(&si2); 456370b324cSopenharmony_ci // if (memcmp(&si, &si2, sizeof(si)) != 0) 457370b324cSopenharmony_ci { 458370b324cSopenharmony_ci // s += " - "; 459370b324cSopenharmony_ci SysInfo_To_String(s2, si2); 460370b324cSopenharmony_ci } 461370b324cSopenharmony_ci } 462370b324cSopenharmony_ci #endif 463370b324cSopenharmony_ci #endif 464370b324cSopenharmony_ci} 465370b324cSopenharmony_ci 466370b324cSopenharmony_ci 467370b324cSopenharmony_civoid GetCpuName(AString &s); 468370b324cSopenharmony_ci 469370b324cSopenharmony_cistatic void AddBracedString(AString &dest, AString &src) 470370b324cSopenharmony_ci{ 471370b324cSopenharmony_ci if (!src.IsEmpty()) 472370b324cSopenharmony_ci { 473370b324cSopenharmony_ci AString s; 474370b324cSopenharmony_ci s += '('; 475370b324cSopenharmony_ci s += src; 476370b324cSopenharmony_ci s += ')'; 477370b324cSopenharmony_ci dest.Add_OptSpaced(s); 478370b324cSopenharmony_ci } 479370b324cSopenharmony_ci} 480370b324cSopenharmony_ci 481370b324cSopenharmony_cistruct CCpuName 482370b324cSopenharmony_ci{ 483370b324cSopenharmony_ci AString CpuName; 484370b324cSopenharmony_ci AString Revision; 485370b324cSopenharmony_ci AString Microcode; 486370b324cSopenharmony_ci AString LargePages; 487370b324cSopenharmony_ci 488370b324cSopenharmony_ci void Fill(); 489370b324cSopenharmony_ci 490370b324cSopenharmony_ci void Get_Revision_Microcode_LargePages(AString &s) 491370b324cSopenharmony_ci { 492370b324cSopenharmony_ci s.Empty(); 493370b324cSopenharmony_ci AddBracedString(s, Revision); 494370b324cSopenharmony_ci AddBracedString(s, Microcode); 495370b324cSopenharmony_ci s.Add_OptSpaced(LargePages); 496370b324cSopenharmony_ci } 497370b324cSopenharmony_ci}; 498370b324cSopenharmony_ci 499370b324cSopenharmony_civoid CCpuName::Fill() 500370b324cSopenharmony_ci{ 501370b324cSopenharmony_ci CpuName.Empty(); 502370b324cSopenharmony_ci Revision.Empty(); 503370b324cSopenharmony_ci Microcode.Empty(); 504370b324cSopenharmony_ci LargePages.Empty(); 505370b324cSopenharmony_ci 506370b324cSopenharmony_ci AString &s = CpuName; 507370b324cSopenharmony_ci 508370b324cSopenharmony_ci #ifdef MY_CPU_X86_OR_AMD64 509370b324cSopenharmony_ci { 510370b324cSopenharmony_ci #if !defined(MY_CPU_AMD64) 511370b324cSopenharmony_ci if (!z7_x86_cpuid_GetMaxFunc()) 512370b324cSopenharmony_ci s += "x86"; 513370b324cSopenharmony_ci else 514370b324cSopenharmony_ci #endif 515370b324cSopenharmony_ci { 516370b324cSopenharmony_ci x86cpuid_to_String(s); 517370b324cSopenharmony_ci { 518370b324cSopenharmony_ci UInt32 a[4]; 519370b324cSopenharmony_ci z7_x86_cpuid(a, 1); 520370b324cSopenharmony_ci char temp[16]; 521370b324cSopenharmony_ci ConvertUInt32ToHex(a[0], temp); 522370b324cSopenharmony_ci Revision += temp; 523370b324cSopenharmony_ci } 524370b324cSopenharmony_ci } 525370b324cSopenharmony_ci } 526370b324cSopenharmony_ci #elif defined(__APPLE__) 527370b324cSopenharmony_ci { 528370b324cSopenharmony_ci Add_sysctlbyname_to_String("machdep.cpu.brand_string", s); 529370b324cSopenharmony_ci } 530370b324cSopenharmony_ci #endif 531370b324cSopenharmony_ci 532370b324cSopenharmony_ci 533370b324cSopenharmony_ci if (s.IsEmpty()) 534370b324cSopenharmony_ci { 535370b324cSopenharmony_ci #ifdef MY_CPU_LE 536370b324cSopenharmony_ci s += "LE"; 537370b324cSopenharmony_ci #elif defined(MY_CPU_BE) 538370b324cSopenharmony_ci s += "BE"; 539370b324cSopenharmony_ci #endif 540370b324cSopenharmony_ci } 541370b324cSopenharmony_ci 542370b324cSopenharmony_ci #ifdef __APPLE__ 543370b324cSopenharmony_ci { 544370b324cSopenharmony_ci AString s2; 545370b324cSopenharmony_ci UInt32 v = 0; 546370b324cSopenharmony_ci if (z7_sysctlbyname_Get_UInt32("machdep.cpu.core_count", &v) == 0) 547370b324cSopenharmony_ci { 548370b324cSopenharmony_ci s2.Add_UInt32(v); 549370b324cSopenharmony_ci s2 += 'C'; 550370b324cSopenharmony_ci } 551370b324cSopenharmony_ci if (z7_sysctlbyname_Get_UInt32("machdep.cpu.thread_count", &v) == 0) 552370b324cSopenharmony_ci { 553370b324cSopenharmony_ci s2.Add_UInt32(v); 554370b324cSopenharmony_ci s2 += 'T'; 555370b324cSopenharmony_ci } 556370b324cSopenharmony_ci if (!s2.IsEmpty()) 557370b324cSopenharmony_ci { 558370b324cSopenharmony_ci s.Add_Space_if_NotEmpty(); 559370b324cSopenharmony_ci s += s2; 560370b324cSopenharmony_ci } 561370b324cSopenharmony_ci } 562370b324cSopenharmony_ci #endif 563370b324cSopenharmony_ci 564370b324cSopenharmony_ci 565370b324cSopenharmony_ci #ifdef _WIN32 566370b324cSopenharmony_ci { 567370b324cSopenharmony_ci NRegistry::CKey key; 568370b324cSopenharmony_ci if (key.Open(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), KEY_READ) == ERROR_SUCCESS) 569370b324cSopenharmony_ci { 570370b324cSopenharmony_ci LONG res[2]; 571370b324cSopenharmony_ci CByteBuffer bufs[2]; 572370b324cSopenharmony_ci { 573370b324cSopenharmony_ci for (unsigned i = 0; i < 2; i++) 574370b324cSopenharmony_ci { 575370b324cSopenharmony_ci UInt32 size = 0; 576370b324cSopenharmony_ci res[i] = key.QueryValue(i == 0 ? 577370b324cSopenharmony_ci TEXT("Previous Update Revision") : 578370b324cSopenharmony_ci TEXT("Update Revision"), bufs[i], size); 579370b324cSopenharmony_ci if (res[i] == ERROR_SUCCESS) 580370b324cSopenharmony_ci if (size != bufs[i].Size()) 581370b324cSopenharmony_ci res[i] = ERROR_SUCCESS + 1; 582370b324cSopenharmony_ci } 583370b324cSopenharmony_ci } 584370b324cSopenharmony_ci if (res[0] == ERROR_SUCCESS || res[1] == ERROR_SUCCESS) 585370b324cSopenharmony_ci { 586370b324cSopenharmony_ci for (unsigned i = 0; i < 2; i++) 587370b324cSopenharmony_ci { 588370b324cSopenharmony_ci if (i == 1) 589370b324cSopenharmony_ci Microcode += "->"; 590370b324cSopenharmony_ci if (res[i] != ERROR_SUCCESS) 591370b324cSopenharmony_ci continue; 592370b324cSopenharmony_ci const CByteBuffer &buf = bufs[i]; 593370b324cSopenharmony_ci if (buf.Size() == 8) 594370b324cSopenharmony_ci { 595370b324cSopenharmony_ci UInt32 high = GetUi32(buf); 596370b324cSopenharmony_ci if (high != 0) 597370b324cSopenharmony_ci { 598370b324cSopenharmony_ci PrintHex(Microcode, high); 599370b324cSopenharmony_ci Microcode += "."; 600370b324cSopenharmony_ci } 601370b324cSopenharmony_ci PrintHex(Microcode, GetUi32(buf + 4)); 602370b324cSopenharmony_ci } 603370b324cSopenharmony_ci } 604370b324cSopenharmony_ci } 605370b324cSopenharmony_ci } 606370b324cSopenharmony_ci } 607370b324cSopenharmony_ci #endif 608370b324cSopenharmony_ci 609370b324cSopenharmony_ci 610370b324cSopenharmony_ci #ifdef Z7_LARGE_PAGES 611370b324cSopenharmony_ci Add_LargePages_String(LargePages); 612370b324cSopenharmony_ci #endif 613370b324cSopenharmony_ci} 614370b324cSopenharmony_ci 615370b324cSopenharmony_civoid AddCpuFeatures(AString &s); 616370b324cSopenharmony_civoid AddCpuFeatures(AString &s) 617370b324cSopenharmony_ci{ 618370b324cSopenharmony_ci #ifdef _WIN32 619370b324cSopenharmony_ci // const unsigned kNumFeatures_Extra = 32; // we check also for unknown features 620370b324cSopenharmony_ci // const unsigned kNumFeatures = Z7_ARRAY_SIZE(k_PF) + kNumFeatures_Extra; 621370b324cSopenharmony_ci const unsigned kNumFeatures = 64; 622370b324cSopenharmony_ci UInt64 flags = 0; 623370b324cSopenharmony_ci for (unsigned i = 0; i < kNumFeatures; i++) 624370b324cSopenharmony_ci { 625370b324cSopenharmony_ci if (IsProcessorFeaturePresent(i)) 626370b324cSopenharmony_ci { 627370b324cSopenharmony_ci flags += (UInt64)1 << i; 628370b324cSopenharmony_ci // s.Add_Space_if_NotEmpty(); 629370b324cSopenharmony_ci // s += TypeToString2(k_PF, Z7_ARRAY_SIZE(k_PF), i); 630370b324cSopenharmony_ci } 631370b324cSopenharmony_ci } 632370b324cSopenharmony_ci s.Add_OptSpaced("f:"); 633370b324cSopenharmony_ci PrintHex(s, flags); 634370b324cSopenharmony_ci 635370b324cSopenharmony_ci #elif defined(__APPLE__) 636370b324cSopenharmony_ci { 637370b324cSopenharmony_ci UInt32 v = 0; 638370b324cSopenharmony_ci if (z7_sysctlbyname_Get_UInt32("hw.pagesize", &v) == 0) 639370b324cSopenharmony_ci { 640370b324cSopenharmony_ci s.Add_OptSpaced("PageSize:"); 641370b324cSopenharmony_ci PrintPage(s, v); 642370b324cSopenharmony_ci } 643370b324cSopenharmony_ci } 644370b324cSopenharmony_ci 645370b324cSopenharmony_ci #else 646370b324cSopenharmony_ci 647370b324cSopenharmony_ci const long v = sysconf(_SC_PAGESIZE); 648370b324cSopenharmony_ci if (v != -1) 649370b324cSopenharmony_ci { 650370b324cSopenharmony_ci s.Add_OptSpaced("PageSize:"); 651370b324cSopenharmony_ci PrintPage(s, (unsigned long)v); 652370b324cSopenharmony_ci } 653370b324cSopenharmony_ci 654370b324cSopenharmony_ci #if !defined(_AIX) 655370b324cSopenharmony_ci 656370b324cSopenharmony_ci #ifdef __linux__ 657370b324cSopenharmony_ci 658370b324cSopenharmony_ci CByteBuffer buf; 659370b324cSopenharmony_ci if (ReadFile_to_Buffer("/sys/kernel/mm/transparent_hugepage/enabled", buf)) 660370b324cSopenharmony_ci // if (ReadFile_to_Buffer("/proc/cpuinfo", buf)) 661370b324cSopenharmony_ci { 662370b324cSopenharmony_ci s.Add_OptSpaced("THP:"); 663370b324cSopenharmony_ci AString s2; 664370b324cSopenharmony_ci s2.SetFrom_CalcLen((const char *)(const void *)(const Byte *)buf, (unsigned)buf.Size()); 665370b324cSopenharmony_ci const int pos = s2.Find('['); 666370b324cSopenharmony_ci if (pos >= 0) 667370b324cSopenharmony_ci { 668370b324cSopenharmony_ci const int pos2 = s2.Find(']', (unsigned)pos + 1); 669370b324cSopenharmony_ci if (pos2 >= 0) 670370b324cSopenharmony_ci { 671370b324cSopenharmony_ci s2.DeleteFrom((unsigned)pos2); 672370b324cSopenharmony_ci s2.DeleteFrontal((unsigned)pos + 1); 673370b324cSopenharmony_ci } 674370b324cSopenharmony_ci } 675370b324cSopenharmony_ci s += s2; 676370b324cSopenharmony_ci } 677370b324cSopenharmony_ci // else throw CSystemException(MY_SRes_HRESULT_FROM_WRes(errno)); 678370b324cSopenharmony_ci 679370b324cSopenharmony_ci #endif 680370b324cSopenharmony_ci 681370b324cSopenharmony_ci 682370b324cSopenharmony_ci #ifdef AT_HWCAP 683370b324cSopenharmony_ci s.Add_OptSpaced("hwcap:"); 684370b324cSopenharmony_ci { 685370b324cSopenharmony_ci unsigned long h = getauxval(AT_HWCAP); 686370b324cSopenharmony_ci PrintHex(s, h); 687370b324cSopenharmony_ci #ifdef MY_CPU_ARM64 688370b324cSopenharmony_ci if (h & HWCAP_CRC32) s += ":CRC32"; 689370b324cSopenharmony_ci if (h & HWCAP_SHA1) s += ":SHA1"; 690370b324cSopenharmony_ci if (h & HWCAP_SHA2) s += ":SHA2"; 691370b324cSopenharmony_ci if (h & HWCAP_AES) s += ":AES"; 692370b324cSopenharmony_ci if (h & HWCAP_ASIMD) s += ":ASIMD"; 693370b324cSopenharmony_ci #elif defined(MY_CPU_ARM) 694370b324cSopenharmony_ci if (h & HWCAP_NEON) s += ":NEON"; 695370b324cSopenharmony_ci #endif 696370b324cSopenharmony_ci } 697370b324cSopenharmony_ci #endif // AT_HWCAP 698370b324cSopenharmony_ci 699370b324cSopenharmony_ci #ifdef AT_HWCAP2 700370b324cSopenharmony_ci { 701370b324cSopenharmony_ci unsigned long h = getauxval(AT_HWCAP2); 702370b324cSopenharmony_ci #ifndef MY_CPU_ARM 703370b324cSopenharmony_ci if (h != 0) 704370b324cSopenharmony_ci #endif 705370b324cSopenharmony_ci { 706370b324cSopenharmony_ci s += " hwcap2:"; 707370b324cSopenharmony_ci PrintHex(s, h); 708370b324cSopenharmony_ci #ifdef MY_CPU_ARM 709370b324cSopenharmony_ci if (h & HWCAP2_CRC32) s += ":CRC32"; 710370b324cSopenharmony_ci if (h & HWCAP2_SHA1) s += ":SHA1"; 711370b324cSopenharmony_ci if (h & HWCAP2_SHA2) s += ":SHA2"; 712370b324cSopenharmony_ci if (h & HWCAP2_AES) s += ":AES"; 713370b324cSopenharmony_ci #endif 714370b324cSopenharmony_ci } 715370b324cSopenharmony_ci } 716370b324cSopenharmony_ci #endif // AT_HWCAP2 717370b324cSopenharmony_ci #endif // _AIX 718370b324cSopenharmony_ci #endif // _WIN32 719370b324cSopenharmony_ci} 720370b324cSopenharmony_ci 721370b324cSopenharmony_ci 722370b324cSopenharmony_ci#ifdef _WIN32 723370b324cSopenharmony_ci#ifndef UNDER_CE 724370b324cSopenharmony_ci 725370b324cSopenharmony_ciEXTERN_C_BEGIN 726370b324cSopenharmony_citypedef void (WINAPI * Func_RtlGetVersion) (OSVERSIONINFOEXW *); 727370b324cSopenharmony_ciEXTERN_C_END 728370b324cSopenharmony_ci 729370b324cSopenharmony_cistatic BOOL My_RtlGetVersion(OSVERSIONINFOEXW *vi) 730370b324cSopenharmony_ci{ 731370b324cSopenharmony_ci const HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll"); 732370b324cSopenharmony_ci if (!ntdll) 733370b324cSopenharmony_ci return FALSE; 734370b324cSopenharmony_ci const 735370b324cSopenharmony_ci Func_RtlGetVersion func = Z7_GET_PROC_ADDRESS( 736370b324cSopenharmony_ci Func_RtlGetVersion, ntdll, 737370b324cSopenharmony_ci "RtlGetVersion"); 738370b324cSopenharmony_ci if (!func) 739370b324cSopenharmony_ci return FALSE; 740370b324cSopenharmony_ci func(vi); 741370b324cSopenharmony_ci return TRUE; 742370b324cSopenharmony_ci} 743370b324cSopenharmony_ci 744370b324cSopenharmony_ci#endif 745370b324cSopenharmony_ci#endif 746370b324cSopenharmony_ci 747370b324cSopenharmony_ci 748370b324cSopenharmony_civoid GetOsInfoText(AString &sRes) 749370b324cSopenharmony_ci{ 750370b324cSopenharmony_ci sRes.Empty(); 751370b324cSopenharmony_ci AString s; 752370b324cSopenharmony_ci 753370b324cSopenharmony_ci #ifdef _WIN32 754370b324cSopenharmony_ci #ifndef UNDER_CE 755370b324cSopenharmony_ci // OSVERSIONINFO vi; 756370b324cSopenharmony_ci OSVERSIONINFOEXW vi; 757370b324cSopenharmony_ci vi.dwOSVersionInfoSize = sizeof(vi); 758370b324cSopenharmony_ci // if (::GetVersionEx(&vi)) 759370b324cSopenharmony_ci if (My_RtlGetVersion(&vi)) 760370b324cSopenharmony_ci { 761370b324cSopenharmony_ci s += "Windows"; 762370b324cSopenharmony_ci if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT) 763370b324cSopenharmony_ci s.Add_UInt32(vi.dwPlatformId); 764370b324cSopenharmony_ci s.Add_Space(); s.Add_UInt32(vi.dwMajorVersion); 765370b324cSopenharmony_ci s.Add_Dot(); s.Add_UInt32(vi.dwMinorVersion); 766370b324cSopenharmony_ci s.Add_Space(); s.Add_UInt32(vi.dwBuildNumber); 767370b324cSopenharmony_ci 768370b324cSopenharmony_ci if (vi.wServicePackMajor != 0 || vi.wServicePackMinor != 0) 769370b324cSopenharmony_ci { 770370b324cSopenharmony_ci s += " SP:"; s.Add_UInt32(vi.wServicePackMajor); 771370b324cSopenharmony_ci s.Add_Dot(); s.Add_UInt32(vi.wServicePackMinor); 772370b324cSopenharmony_ci } 773370b324cSopenharmony_ci // s += " Suite:"; PrintHex(s, vi.wSuiteMask); 774370b324cSopenharmony_ci // s += " Type:"; s.Add_UInt32(vi.wProductType); 775370b324cSopenharmony_ci // s.Add_Space(); s += GetOemString(vi.szCSDVersion); 776370b324cSopenharmony_ci } 777370b324cSopenharmony_ci /* 778370b324cSopenharmony_ci { 779370b324cSopenharmony_ci s += " OEMCP:"; s.Add_UInt32(GetOEMCP()); 780370b324cSopenharmony_ci s += " ACP:"; s.Add_UInt32(GetACP()); 781370b324cSopenharmony_ci } 782370b324cSopenharmony_ci */ 783370b324cSopenharmony_ci #endif 784370b324cSopenharmony_ci #else // _WIN32 785370b324cSopenharmony_ci 786370b324cSopenharmony_ci if (!s.IsEmpty()) 787370b324cSopenharmony_ci s.Add_LF(); 788370b324cSopenharmony_ci struct utsname un; 789370b324cSopenharmony_ci if (uname(&un) == 0) 790370b324cSopenharmony_ci { 791370b324cSopenharmony_ci s += un.sysname; 792370b324cSopenharmony_ci // s += " : "; s += un.nodename; // we don't want to show name of computer 793370b324cSopenharmony_ci s += " : "; s += un.release; 794370b324cSopenharmony_ci s += " : "; s += un.version; 795370b324cSopenharmony_ci s += " : "; s += un.machine; 796370b324cSopenharmony_ci 797370b324cSopenharmony_ci #ifdef __APPLE__ 798370b324cSopenharmony_ci // Add_sysctlbyname_to_String("kern.version", s); 799370b324cSopenharmony_ci // it's same as "utsname.version" 800370b324cSopenharmony_ci #endif 801370b324cSopenharmony_ci } 802370b324cSopenharmony_ci #endif // _WIN32 803370b324cSopenharmony_ci 804370b324cSopenharmony_ci sRes += s; 805370b324cSopenharmony_ci #ifdef MY_CPU_X86_OR_AMD64 806370b324cSopenharmony_ci { 807370b324cSopenharmony_ci AString s2; 808370b324cSopenharmony_ci GetVirtCpuid(s2); 809370b324cSopenharmony_ci if (!s2.IsEmpty()) 810370b324cSopenharmony_ci { 811370b324cSopenharmony_ci sRes += " : "; 812370b324cSopenharmony_ci sRes += s2; 813370b324cSopenharmony_ci } 814370b324cSopenharmony_ci } 815370b324cSopenharmony_ci #endif 816370b324cSopenharmony_ci} 817370b324cSopenharmony_ci 818370b324cSopenharmony_ci 819370b324cSopenharmony_ci 820370b324cSopenharmony_civoid GetSystemInfoText(AString &sRes) 821370b324cSopenharmony_ci{ 822370b324cSopenharmony_ci GetOsInfoText(sRes); 823370b324cSopenharmony_ci sRes.Add_LF(); 824370b324cSopenharmony_ci 825370b324cSopenharmony_ci { 826370b324cSopenharmony_ci AString s, s1, s2; 827370b324cSopenharmony_ci GetSysInfo(s1, s2); 828370b324cSopenharmony_ci if (!s1.IsEmpty() || !s2.IsEmpty()) 829370b324cSopenharmony_ci { 830370b324cSopenharmony_ci s = s1; 831370b324cSopenharmony_ci if (s1 != s2 && !s2.IsEmpty()) 832370b324cSopenharmony_ci { 833370b324cSopenharmony_ci s += " - "; 834370b324cSopenharmony_ci s += s2; 835370b324cSopenharmony_ci } 836370b324cSopenharmony_ci } 837370b324cSopenharmony_ci { 838370b324cSopenharmony_ci AddCpuFeatures(s); 839370b324cSopenharmony_ci if (!s.IsEmpty()) 840370b324cSopenharmony_ci { 841370b324cSopenharmony_ci sRes += s; 842370b324cSopenharmony_ci sRes.Add_LF(); 843370b324cSopenharmony_ci } 844370b324cSopenharmony_ci } 845370b324cSopenharmony_ci } 846370b324cSopenharmony_ci { 847370b324cSopenharmony_ci AString s; 848370b324cSopenharmony_ci GetCpuName(s); 849370b324cSopenharmony_ci if (!s.IsEmpty()) 850370b324cSopenharmony_ci { 851370b324cSopenharmony_ci sRes += s; 852370b324cSopenharmony_ci sRes.Add_LF(); 853370b324cSopenharmony_ci } 854370b324cSopenharmony_ci } 855370b324cSopenharmony_ci /* 856370b324cSopenharmony_ci #ifdef MY_CPU_X86_OR_AMD64 857370b324cSopenharmony_ci { 858370b324cSopenharmony_ci AString s; 859370b324cSopenharmony_ci x86cpuid_all_to_String(s); 860370b324cSopenharmony_ci if (!s.IsEmpty()) 861370b324cSopenharmony_ci { 862370b324cSopenharmony_ci printCallback->Print(s); 863370b324cSopenharmony_ci printCallback->NewLine(); 864370b324cSopenharmony_ci } 865370b324cSopenharmony_ci } 866370b324cSopenharmony_ci #endif 867370b324cSopenharmony_ci */ 868370b324cSopenharmony_ci} 869370b324cSopenharmony_ci 870370b324cSopenharmony_ci 871370b324cSopenharmony_civoid GetCpuName(AString &s); 872370b324cSopenharmony_civoid GetCpuName(AString &s) 873370b324cSopenharmony_ci{ 874370b324cSopenharmony_ci CCpuName cpuName; 875370b324cSopenharmony_ci cpuName.Fill(); 876370b324cSopenharmony_ci s = cpuName.CpuName; 877370b324cSopenharmony_ci AString s2; 878370b324cSopenharmony_ci cpuName.Get_Revision_Microcode_LargePages(s2); 879370b324cSopenharmony_ci s.Add_OptSpaced(s2); 880370b324cSopenharmony_ci} 881370b324cSopenharmony_ci 882370b324cSopenharmony_ci 883370b324cSopenharmony_civoid GetCpuName_MultiLine(AString &s); 884370b324cSopenharmony_civoid GetCpuName_MultiLine(AString &s) 885370b324cSopenharmony_ci{ 886370b324cSopenharmony_ci CCpuName cpuName; 887370b324cSopenharmony_ci cpuName.Fill(); 888370b324cSopenharmony_ci s = cpuName.CpuName; 889370b324cSopenharmony_ci AString s2; 890370b324cSopenharmony_ci cpuName.Get_Revision_Microcode_LargePages(s2); 891370b324cSopenharmony_ci if (!s2.IsEmpty()) 892370b324cSopenharmony_ci { 893370b324cSopenharmony_ci s.Add_LF(); 894370b324cSopenharmony_ci s += s2; 895370b324cSopenharmony_ci } 896370b324cSopenharmony_ci} 897370b324cSopenharmony_ci 898370b324cSopenharmony_ci 899370b324cSopenharmony_ci#ifdef MY_CPU_X86_OR_AMD64 900370b324cSopenharmony_ci 901370b324cSopenharmony_civoid GetVirtCpuid(AString &s) 902370b324cSopenharmony_ci{ 903370b324cSopenharmony_ci const UInt32 kHv = 0x40000000; 904370b324cSopenharmony_ci 905370b324cSopenharmony_ci Z7_IF_X86_CPUID_SUPPORTED 906370b324cSopenharmony_ci { 907370b324cSopenharmony_ci UInt32 a[4]; 908370b324cSopenharmony_ci z7_x86_cpuid(a, kHv); 909370b324cSopenharmony_ci 910370b324cSopenharmony_ci if (a[0] < kHv || a[0] >= kHv + (1 << 16)) 911370b324cSopenharmony_ci return; 912370b324cSopenharmony_ci { 913370b324cSopenharmony_ci { 914370b324cSopenharmony_ci for (unsigned j = 1; j < 4; j++) 915370b324cSopenharmony_ci PrintCpuChars(s, a[j]); 916370b324cSopenharmony_ci } 917370b324cSopenharmony_ci } 918370b324cSopenharmony_ci if (a[0] >= kHv + 1) 919370b324cSopenharmony_ci { 920370b324cSopenharmony_ci UInt32 d[4]; 921370b324cSopenharmony_ci z7_x86_cpuid(d, kHv + 1); 922370b324cSopenharmony_ci s += " : "; 923370b324cSopenharmony_ci PrintCpuChars(s, d[0]); 924370b324cSopenharmony_ci if (a[0] >= kHv + 2) 925370b324cSopenharmony_ci { 926370b324cSopenharmony_ci z7_x86_cpuid(d, kHv + 2); 927370b324cSopenharmony_ci s += " : "; 928370b324cSopenharmony_ci s.Add_UInt32(d[1] >> 16); 929370b324cSopenharmony_ci s.Add_Dot(); s.Add_UInt32(d[1] & 0xffff); 930370b324cSopenharmony_ci s.Add_Dot(); s.Add_UInt32(d[0]); 931370b324cSopenharmony_ci s.Add_Dot(); s.Add_UInt32(d[2]); 932370b324cSopenharmony_ci s.Add_Dot(); s.Add_UInt32(d[3] >> 24); 933370b324cSopenharmony_ci s.Add_Dot(); s.Add_UInt32(d[3] & 0xffffff); 934370b324cSopenharmony_ci } 935370b324cSopenharmony_ci /* 936370b324cSopenharmony_ci if (a[0] >= kHv + 5) 937370b324cSopenharmony_ci { 938370b324cSopenharmony_ci z7_x86_cpuid(d, kHv + 5); 939370b324cSopenharmony_ci s += " : "; 940370b324cSopenharmony_ci s.Add_UInt32(d[0]); 941370b324cSopenharmony_ci s += "p"; 942370b324cSopenharmony_ci s.Add_UInt32(d[1]); 943370b324cSopenharmony_ci s += "t"; 944370b324cSopenharmony_ci } 945370b324cSopenharmony_ci */ 946370b324cSopenharmony_ci } 947370b324cSopenharmony_ci } 948370b324cSopenharmony_ci} 949370b324cSopenharmony_ci 950370b324cSopenharmony_ci#endif 951370b324cSopenharmony_ci 952370b324cSopenharmony_ci 953370b324cSopenharmony_civoid GetCompiler(AString &s) 954370b324cSopenharmony_ci{ 955370b324cSopenharmony_ci #ifdef __VERSION__ 956370b324cSopenharmony_ci s += __VERSION__; 957370b324cSopenharmony_ci #endif 958370b324cSopenharmony_ci 959370b324cSopenharmony_ci #ifdef __GNUC__ 960370b324cSopenharmony_ci s += " GCC "; 961370b324cSopenharmony_ci s.Add_UInt32(__GNUC__); 962370b324cSopenharmony_ci s.Add_Dot(); 963370b324cSopenharmony_ci s.Add_UInt32(__GNUC_MINOR__); 964370b324cSopenharmony_ci s.Add_Dot(); 965370b324cSopenharmony_ci s.Add_UInt32(__GNUC_PATCHLEVEL__); 966370b324cSopenharmony_ci #endif 967370b324cSopenharmony_ci 968370b324cSopenharmony_ci #ifdef __clang__ 969370b324cSopenharmony_ci s += " CLANG "; 970370b324cSopenharmony_ci s.Add_UInt32(__clang_major__); 971370b324cSopenharmony_ci s.Add_Dot(); 972370b324cSopenharmony_ci s.Add_UInt32(__clang_minor__); 973370b324cSopenharmony_ci #endif 974370b324cSopenharmony_ci 975370b324cSopenharmony_ci #ifdef __xlC__ 976370b324cSopenharmony_ci s += " XLC "; 977370b324cSopenharmony_ci s.Add_UInt32(__xlC__ >> 8); 978370b324cSopenharmony_ci s.Add_Dot(); 979370b324cSopenharmony_ci s.Add_UInt32(__xlC__ & 0xFF); 980370b324cSopenharmony_ci #ifdef __xlC_ver__ 981370b324cSopenharmony_ci s.Add_Dot(); 982370b324cSopenharmony_ci s.Add_UInt32(__xlC_ver__ >> 8); 983370b324cSopenharmony_ci s.Add_Dot(); 984370b324cSopenharmony_ci s.Add_UInt32(__xlC_ver__ & 0xFF); 985370b324cSopenharmony_ci #endif 986370b324cSopenharmony_ci #endif 987370b324cSopenharmony_ci 988370b324cSopenharmony_ci #ifdef _MSC_VER 989370b324cSopenharmony_ci s += " MSC "; 990370b324cSopenharmony_ci s.Add_UInt32(_MSC_VER); 991370b324cSopenharmony_ci #endif 992370b324cSopenharmony_ci 993370b324cSopenharmony_ci #if defined(__AVX2__) 994370b324cSopenharmony_ci #define MY_CPU_COMPILE_ISA "AVX2" 995370b324cSopenharmony_ci #elif defined(__AVX__) 996370b324cSopenharmony_ci #define MY_CPU_COMPILE_ISA "AVX" 997370b324cSopenharmony_ci #elif defined(__SSE2__) 998370b324cSopenharmony_ci #define MY_CPU_COMPILE_ISA "SSE2" 999370b324cSopenharmony_ci #elif defined(_M_IX86_FP) && (_M_IX86_FP >= 2) 1000370b324cSopenharmony_ci #define MY_CPU_COMPILE_ISA "SSE2" 1001370b324cSopenharmony_ci #elif defined(__SSE__) 1002370b324cSopenharmony_ci #define MY_CPU_COMPILE_ISA "SSE" 1003370b324cSopenharmony_ci #elif defined(_M_IX86_FP) && (_M_IX86_FP >= 1) 1004370b324cSopenharmony_ci #define MY_CPU_COMPILE_ISA "SSE" 1005370b324cSopenharmony_ci #elif defined(__i686__) 1006370b324cSopenharmony_ci #define MY_CPU_COMPILE_ISA "i686" 1007370b324cSopenharmony_ci #elif defined(__i586__) 1008370b324cSopenharmony_ci #define MY_CPU_COMPILE_ISA "i586" 1009370b324cSopenharmony_ci #elif defined(__i486__) 1010370b324cSopenharmony_ci #define MY_CPU_COMPILE_ISA "i486" 1011370b324cSopenharmony_ci #elif defined(__i386__) 1012370b324cSopenharmony_ci #define MY_CPU_COMPILE_ISA "i386" 1013370b324cSopenharmony_ci #elif defined(_M_IX86_FP) 1014370b324cSopenharmony_ci #define MY_CPU_COMPILE_ISA "IA32" 1015370b324cSopenharmony_ci #endif 1016370b324cSopenharmony_ci 1017370b324cSopenharmony_ci 1018370b324cSopenharmony_ci #ifdef MY_CPU_COMPILE_ISA 1019370b324cSopenharmony_ci s += ':'; 1020370b324cSopenharmony_ci s.Add_OptSpaced(MY_CPU_COMPILE_ISA); 1021370b324cSopenharmony_ci #endif 1022370b324cSopenharmony_ci} 1023