1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
|
// Windows/SystemInfo.cpp
#include "StdAfx.h"
#include "../../C/CpuArch.h"
#include "../Common/IntToString.h"
#ifdef _WIN32
#include "Registry.h"
#else
#include <unistd.h>
#include <sys/utsname.h>
#ifdef __APPLE__
#include <sys/sysctl.h>
#elif !defined(_AIX)
#include <sys/auxv.h>
// #undef AT_HWCAP // to debug
// #undef AT_HWCAP2 // to debug
/* the following patch for some debian systems.
Is it OK to define AT_HWCAP and AT_HWCAP2 here with these constant numbers? */
/*
#if defined(__FreeBSD_kernel__) && defined(__GLIBC__)
#ifndef AT_HWCAP
#define AT_HWCAP 16
#endif
#ifndef AT_HWCAP2
#define AT_HWCAP2 26
#endif
#endif
*/
#ifdef MY_CPU_ARM_OR_ARM64
#include <asm/hwcap.h>
#endif
#endif
#ifdef __linux__
#include "../Windows/FileIO.h"
#endif
#endif // WIN32
#include "SystemInfo.h"
#include "System.h"
using namespace NWindows;
#ifdef __linux__
static bool ReadFile_to_Buffer(CFSTR fileName, CByteBuffer &buf)
{
NWindows::NFile::NIO::CInFile file;
if (!file.Open(fileName))
return false;
/*
UInt64 size;
if (!file.GetLength(size))
{
// GetLength() doesn't work "/proc/cpuinfo"
return false;
}
if (size >= ((UInt32)1 << 29))
return false;
*/
size_t size = 0;
size_t addSize = ((size_t)1 << 12);
for (;;)
{
// printf("\nsize = %d\n", (unsigned)size);
buf.ChangeSize_KeepData(size + addSize, size);
size_t processed;
if (!file.ReadFull(buf + size, addSize, processed))
return false;
if (processed == 0)
{
buf.ChangeSize_KeepData(size, size);
return true;
}
size += processed;
addSize *= 2;
}
}
#endif
#if defined(_WIN32) || defined(AT_HWCAP) || defined(AT_HWCAP2)
static void PrintHex(AString &s, UInt64 v)
{
char temp[32];
ConvertUInt64ToHex(v, temp);
s += temp;
}
#endif
#ifdef MY_CPU_X86_OR_AMD64
Z7_NO_INLINE
static void PrintCpuChars(AString &s, UInt32 v)
{
for (unsigned j = 0; j < 4; j++)
{
Byte b = (Byte)(v & 0xFF);
v >>= 8;
if (b == 0)
break;
if (b >= 0x20 && b <= 0x7f)
s += (char)b;
else
{
s += '[';
char temp[16];
ConvertUInt32ToHex(b, temp);
s += temp;
s += ']';
}
}
}
static void x86cpuid_to_String(AString &s)
{
s.Empty();
UInt32 a[4];
// cpuid was called already. So we don't check for cpuid availability here
z7_x86_cpuid(a, 0x80000000);
if (a[0] >= 0x80000004) // if (maxFunc2 >= hi+4) the full name is available
{
for (unsigned i = 0; i < 3; i++)
{
z7_x86_cpuid(a, 0x80000002 + i);
for (unsigned j = 0; j < 4; j++)
PrintCpuChars(s, a[j]);
}
}
s.Trim();
if (s.IsEmpty())
{
z7_x86_cpuid(a, 0);
for (unsigned i = 1; i < 4; i++)
{
const unsigned j = (i ^ (i >> 1));
PrintCpuChars(s, a[j]);
}
s.Trim();
}
}
/*
static void x86cpuid_all_to_String(AString &s)
{
Cx86cpuid p;
if (!x86cpuid_CheckAndRead(&p))
return;
s += "x86cpuid maxFunc = ";
s.Add_UInt32(p.maxFunc);
for (unsigned j = 0; j <= p.maxFunc; j++)
{
s.Add_LF();
// s.Add_UInt32(j); // align
{
char temp[32];
ConvertUInt32ToString(j, temp);
unsigned len = (unsigned)strlen(temp);
while (len < 8)
{
len++;
s.Add_Space();
}
s += temp;
}
s += ":";
UInt32 d[4] = { 0 };
MyCPUID(j, &d[0], &d[1], &d[2], &d[3]);
for (unsigned i = 0; i < 4; i++)
{
char temp[32];
ConvertUInt32ToHex8Digits(d[i], temp);
s.Add_Space();
s += temp;
}
}
}
*/
#endif
#ifdef _WIN32
static const char * const k_PROCESSOR_ARCHITECTURE[] =
{
"x86" // "INTEL"
, "MIPS"
, "ALPHA"
, "PPC"
, "SHX"
, "ARM"
, "IA64"
, "ALPHA64"
, "MSIL"
, "x64" // "AMD64"
, "IA32_ON_WIN64"
, "NEUTRAL"
, "ARM64"
, "ARM32_ON_WIN64"
};
#define Z7_WIN_PROCESSOR_ARCHITECTURE_INTEL 0
#define Z7_WIN_PROCESSOR_ARCHITECTURE_AMD64 9
#define Z7_WIN_PROCESSOR_INTEL_PENTIUM 586
#define Z7_WIN_PROCESSOR_AMD_X8664 8664
/*
static const CUInt32PCharPair k_PROCESSOR[] =
{
{ 2200, "IA64" },
{ 8664, "x64" }
};
#define PROCESSOR_INTEL_386 386
#define PROCESSOR_INTEL_486 486
#define PROCESSOR_INTEL_PENTIUM 586
#define PROCESSOR_INTEL_860 860
#define PROCESSOR_INTEL_IA64 2200
#define PROCESSOR_AMD_X8664 8664
#define PROCESSOR_MIPS_R2000 2000
#define PROCESSOR_MIPS_R3000 3000
#define PROCESSOR_MIPS_R4000 4000
#define PROCESSOR_ALPHA_21064 21064
#define PROCESSOR_PPC_601 601
#define PROCESSOR_PPC_603 603
#define PROCESSOR_PPC_604 604
#define PROCESSOR_PPC_620 620
#define PROCESSOR_HITACHI_SH3 10003
#define PROCESSOR_HITACHI_SH3E 10004
#define PROCESSOR_HITACHI_SH4 10005
#define PROCESSOR_MOTOROLA_821 821
#define PROCESSOR_SHx_SH3 103
#define PROCESSOR_SHx_SH4 104
#define PROCESSOR_STRONGARM 2577 // 0xA11
#define PROCESSOR_ARM720 1824 // 0x720
#define PROCESSOR_ARM820 2080 // 0x820
#define PROCESSOR_ARM920 2336 // 0x920
#define PROCESSOR_ARM_7TDMI 70001
#define PROCESSOR_OPTIL 18767 // 0x494f
*/
/*
static const char * const k_PF[] =
{
"FP_ERRATA"
, "FP_EMU"
, "CMPXCHG"
, "MMX"
, "PPC_MOVEMEM_64BIT"
, "ALPHA_BYTE"
, "SSE"
, "3DNOW"
, "RDTSC"
, "PAE"
, "SSE2"
, "SSE_DAZ"
, "NX"
, "SSE3"
, "CMPXCHG16B"
, "CMP8XCHG16"
, "CHANNELS"
, "XSAVE"
, "ARM_VFP_32"
, "ARM_NEON"
, "L2AT"
, "VIRT_FIRMWARE"
, "RDWRFSGSBASE"
, "FASTFAIL"
, "ARM_DIVIDE"
, "ARM_64BIT_LOADSTORE_ATOMIC"
, "ARM_EXTERNAL_CACHE"
, "ARM_FMAC"
, "RDRAND"
, "ARM_V8"
, "ARM_V8_CRYPTO"
, "ARM_V8_CRC32"
, "RDTSCP"
, "RDPID"
, "ARM_V81_ATOMIC"
, "MONITORX"
};
*/
#endif
static void PrintPage(AString &s, UInt64 v)
{
const char *t = "B";
if ((v & 0x3ff) == 0)
{
v >>= 10;
t = "KB";
}
s.Add_UInt64(v);
s += t;
}
#ifdef _WIN32
static AString TypeToString2(const char * const table[], unsigned num, UInt32 value)
{
char sz[16];
const char *p = NULL;
if (value < num)
p = table[value];
if (!p)
{
ConvertUInt32ToString(value, sz);
p = sz;
}
return (AString)p;
}
// #if defined(Z7_LARGE_PAGES) || defined(_WIN32)
// #ifdef _WIN32
void PrintSize_KMGT_Or_Hex(AString &s, UInt64 v)
{
char c = 0;
if ((v & 0x3FF) == 0) { v >>= 10; c = 'K';
if ((v & 0x3FF) == 0) { v >>= 10; c = 'M';
if ((v & 0x3FF) == 0) { v >>= 10; c = 'G';
if ((v & 0x3FF) == 0) { v >>= 10; c = 'T';
}}}}
else
{
// s += "0x";
PrintHex(s, v);
return;
}
s.Add_UInt64(v);
if (c)
s += c;
s += 'B';
}
// #endif
// #endif
static void SysInfo_To_String(AString &s, const SYSTEM_INFO &si)
{
s += TypeToString2(k_PROCESSOR_ARCHITECTURE, Z7_ARRAY_SIZE(k_PROCESSOR_ARCHITECTURE), si.wProcessorArchitecture);
if (!( (si.wProcessorArchitecture == Z7_WIN_PROCESSOR_ARCHITECTURE_INTEL && si.dwProcessorType == Z7_WIN_PROCESSOR_INTEL_PENTIUM)
|| (si.wProcessorArchitecture == Z7_WIN_PROCESSOR_ARCHITECTURE_AMD64 && si.dwProcessorType == Z7_WIN_PROCESSOR_AMD_X8664)))
{
s.Add_Space();
// s += TypePairToString(k_PROCESSOR, Z7_ARRAY_SIZE(k_PROCESSOR), si.dwProcessorType);
s.Add_UInt32(si.dwProcessorType);
}
s.Add_Space();
PrintHex(s, si.wProcessorLevel);
s.Add_Dot();
PrintHex(s, si.wProcessorRevision);
if ((UInt64)si.dwActiveProcessorMask + 1 != ((UInt64)1 << si.dwNumberOfProcessors))
if ((UInt64)si.dwActiveProcessorMask + 1 != 0 || si.dwNumberOfProcessors != sizeof(UInt64) * 8)
{
s += " act:";
PrintHex(s, si.dwActiveProcessorMask);
}
s += " cpus:";
s.Add_UInt32(si.dwNumberOfProcessors);
if (si.dwPageSize != 1 << 12)
{
s += " page:";
PrintPage(s, si.dwPageSize);
}
if (si.dwAllocationGranularity != 1 << 16)
{
s += " gran:";
PrintPage(s, si.dwAllocationGranularity);
}
s.Add_Space();
const DWORD_PTR minAdd = (DWORD_PTR)si.lpMinimumApplicationAddress;
UInt64 maxSize = (UInt64)(DWORD_PTR)si.lpMaximumApplicationAddress + 1;
const UInt32 kReserveSize = ((UInt32)1 << 16);
if (minAdd != kReserveSize)
{
PrintSize_KMGT_Or_Hex(s, minAdd);
s += "-";
}
else
{
if ((maxSize & (kReserveSize - 1)) == 0)
maxSize += kReserveSize;
}
PrintSize_KMGT_Or_Hex(s, maxSize);
}
#ifndef _WIN64
EXTERN_C_BEGIN
typedef VOID (WINAPI *Func_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo);
EXTERN_C_END
#endif
#endif
#ifdef __APPLE__
#ifndef MY_CPU_X86_OR_AMD64
static void Add_sysctlbyname_to_String(const char *name, AString &s)
{
size_t bufSize = 256;
char buf[256];
if (z7_sysctlbyname_Get(name, &buf, &bufSize) == 0)
s += buf;
}
#endif
#endif
void GetSysInfo(AString &s1, AString &s2);
void GetSysInfo(AString &s1, AString &s2)
{
s1.Empty();
s2.Empty();
#ifdef _WIN32
SYSTEM_INFO si;
GetSystemInfo(&si);
{
SysInfo_To_String(s1, si);
// s += " : ";
}
#if !defined(_WIN64) && !defined(UNDER_CE)
const
Func_GetNativeSystemInfo fn = Z7_GET_PROC_ADDRESS(
Func_GetNativeSystemInfo, GetModuleHandleA("kernel32.dll"),
"GetNativeSystemInfo");
if (fn)
{
SYSTEM_INFO si2;
fn(&si2);
// if (memcmp(&si, &si2, sizeof(si)) != 0)
{
// s += " - ";
SysInfo_To_String(s2, si2);
}
}
#endif
#endif
}
void GetCpuName(AString &s);
static void AddBracedString(AString &dest, AString &src)
{
if (!src.IsEmpty())
{
AString s;
s += '(';
s += src;
s += ')';
dest.Add_OptSpaced(s);
}
}
struct CCpuName
{
AString CpuName;
AString Revision;
AString Microcode;
AString LargePages;
void Fill();
void Get_Revision_Microcode_LargePages(AString &s)
{
s.Empty();
AddBracedString(s, Revision);
AddBracedString(s, Microcode);
s.Add_OptSpaced(LargePages);
}
};
void CCpuName::Fill()
{
CpuName.Empty();
Revision.Empty();
Microcode.Empty();
LargePages.Empty();
AString &s = CpuName;
#ifdef MY_CPU_X86_OR_AMD64
{
#if !defined(MY_CPU_AMD64)
if (!z7_x86_cpuid_GetMaxFunc())
s += "x86";
else
#endif
{
x86cpuid_to_String(s);
{
UInt32 a[4];
z7_x86_cpuid(a, 1);
char temp[16];
ConvertUInt32ToHex(a[0], temp);
Revision += temp;
}
}
}
#elif defined(__APPLE__)
{
Add_sysctlbyname_to_String("machdep.cpu.brand_string", s);
}
#endif
if (s.IsEmpty())
{
#ifdef MY_CPU_LE
s += "LE";
#elif defined(MY_CPU_BE)
s += "BE";
#endif
}
#ifdef __APPLE__
{
AString s2;
UInt32 v = 0;
if (z7_sysctlbyname_Get_UInt32("machdep.cpu.core_count", &v) == 0)
{
s2.Add_UInt32(v);
s2 += 'C';
}
if (z7_sysctlbyname_Get_UInt32("machdep.cpu.thread_count", &v) == 0)
{
s2.Add_UInt32(v);
s2 += 'T';
}
if (!s2.IsEmpty())
{
s.Add_Space_if_NotEmpty();
s += s2;
}
}
#endif
#ifdef _WIN32
{
NRegistry::CKey key;
if (key.Open(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), KEY_READ) == ERROR_SUCCESS)
{
LONG res[2];
CByteBuffer bufs[2];
{
for (unsigned i = 0; i < 2; i++)
{
UInt32 size = 0;
res[i] = key.QueryValue(i == 0 ?
TEXT("Previous Update Revision") :
TEXT("Update Revision"), bufs[i], size);
if (res[i] == ERROR_SUCCESS)
if (size != bufs[i].Size())
res[i] = ERROR_SUCCESS + 1;
}
}
if (res[0] == ERROR_SUCCESS || res[1] == ERROR_SUCCESS)
{
for (unsigned i = 0; i < 2; i++)
{
if (i == 1)
Microcode += "->";
if (res[i] != ERROR_SUCCESS)
continue;
const CByteBuffer &buf = bufs[i];
if (buf.Size() == 8)
{
UInt32 high = GetUi32(buf);
if (high != 0)
{
PrintHex(Microcode, high);
Microcode += ".";
}
PrintHex(Microcode, GetUi32(buf + 4));
}
}
}
}
}
#endif
#ifdef Z7_LARGE_PAGES
Add_LargePages_String(LargePages);
#endif
}
void AddCpuFeatures(AString &s);
void AddCpuFeatures(AString &s)
{
#ifdef _WIN32
// const unsigned kNumFeatures_Extra = 32; // we check also for unknown features
// const unsigned kNumFeatures = Z7_ARRAY_SIZE(k_PF) + kNumFeatures_Extra;
const unsigned kNumFeatures = 64;
UInt64 flags = 0;
for (unsigned i = 0; i < kNumFeatures; i++)
{
if (IsProcessorFeaturePresent(i))
{
flags += (UInt64)1 << i;
// s.Add_Space_if_NotEmpty();
// s += TypeToString2(k_PF, Z7_ARRAY_SIZE(k_PF), i);
}
}
s.Add_OptSpaced("f:");
PrintHex(s, flags);
#elif defined(__APPLE__)
{
UInt32 v = 0;
if (z7_sysctlbyname_Get_UInt32("hw.pagesize", &v) == 0)
{
s.Add_OptSpaced("PageSize:");
PrintPage(s, v);
}
}
#else
const long v = sysconf(_SC_PAGESIZE);
if (v != -1)
{
s.Add_OptSpaced("PageSize:");
PrintPage(s, (unsigned long)v);
}
#if !defined(_AIX)
#ifdef __linux__
CByteBuffer buf;
if (ReadFile_to_Buffer("/sys/kernel/mm/transparent_hugepage/enabled", buf))
// if (ReadFile_to_Buffer("/proc/cpuinfo", buf))
{
s.Add_OptSpaced("THP:");
AString s2;
s2.SetFrom_CalcLen((const char *)(const void *)(const Byte *)buf, (unsigned)buf.Size());
const int pos = s2.Find('[');
if (pos >= 0)
{
const int pos2 = s2.Find(']', (unsigned)pos + 1);
if (pos2 >= 0)
{
s2.DeleteFrom((unsigned)pos2);
s2.DeleteFrontal((unsigned)pos + 1);
}
}
s += s2;
}
// else throw CSystemException(MY_SRes_HRESULT_FROM_WRes(errno));
#endif
#ifdef AT_HWCAP
s.Add_OptSpaced("hwcap:");
{
unsigned long h = getauxval(AT_HWCAP);
PrintHex(s, h);
#ifdef MY_CPU_ARM64
if (h & HWCAP_CRC32) s += ":CRC32";
if (h & HWCAP_SHA1) s += ":SHA1";
if (h & HWCAP_SHA2) s += ":SHA2";
if (h & HWCAP_AES) s += ":AES";
if (h & HWCAP_ASIMD) s += ":ASIMD";
#elif defined(MY_CPU_ARM)
if (h & HWCAP_NEON) s += ":NEON";
#endif
}
#endif // AT_HWCAP
#ifdef AT_HWCAP2
{
unsigned long h = getauxval(AT_HWCAP2);
#ifndef MY_CPU_ARM
if (h != 0)
#endif
{
s += " hwcap2:";
PrintHex(s, h);
#ifdef MY_CPU_ARM
if (h & HWCAP2_CRC32) s += ":CRC32";
if (h & HWCAP2_SHA1) s += ":SHA1";
if (h & HWCAP2_SHA2) s += ":SHA2";
if (h & HWCAP2_AES) s += ":AES";
#endif
}
}
#endif // AT_HWCAP2
#endif // _AIX
#endif // _WIN32
}
#ifdef _WIN32
#ifndef UNDER_CE
EXTERN_C_BEGIN
typedef void (WINAPI * Func_RtlGetVersion) (OSVERSIONINFOEXW *);
EXTERN_C_END
static BOOL My_RtlGetVersion(OSVERSIONINFOEXW *vi)
{
const HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll");
if (!ntdll)
return FALSE;
const
Func_RtlGetVersion func = Z7_GET_PROC_ADDRESS(
Func_RtlGetVersion, ntdll,
"RtlGetVersion");
if (!func)
return FALSE;
func(vi);
return TRUE;
}
#endif
#endif
void GetOsInfoText(AString &sRes)
{
sRes.Empty();
AString s;
#ifdef _WIN32
#ifndef UNDER_CE
// OSVERSIONINFO vi;
OSVERSIONINFOEXW vi;
vi.dwOSVersionInfoSize = sizeof(vi);
// if (::GetVersionEx(&vi))
if (My_RtlGetVersion(&vi))
{
s += "Windows";
if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT)
s.Add_UInt32(vi.dwPlatformId);
s.Add_Space(); s.Add_UInt32(vi.dwMajorVersion);
s.Add_Dot(); s.Add_UInt32(vi.dwMinorVersion);
s.Add_Space(); s.Add_UInt32(vi.dwBuildNumber);
if (vi.wServicePackMajor != 0 || vi.wServicePackMinor != 0)
{
s += " SP:"; s.Add_UInt32(vi.wServicePackMajor);
s.Add_Dot(); s.Add_UInt32(vi.wServicePackMinor);
}
// s += " Suite:"; PrintHex(s, vi.wSuiteMask);
// s += " Type:"; s.Add_UInt32(vi.wProductType);
// s.Add_Space(); s += GetOemString(vi.szCSDVersion);
}
/*
{
s += " OEMCP:"; s.Add_UInt32(GetOEMCP());
s += " ACP:"; s.Add_UInt32(GetACP());
}
*/
#endif
#else // _WIN32
if (!s.IsEmpty())
s.Add_LF();
struct utsname un;
if (uname(&un) == 0)
{
s += un.sysname;
// s += " : "; s += un.nodename; // we don't want to show name of computer
s += " : "; s += un.release;
s += " : "; s += un.version;
s += " : "; s += un.machine;
#ifdef __APPLE__
// Add_sysctlbyname_to_String("kern.version", s);
// it's same as "utsname.version"
#endif
}
#endif // _WIN32
sRes += s;
#ifdef MY_CPU_X86_OR_AMD64
{
AString s2;
GetVirtCpuid(s2);
if (!s2.IsEmpty())
{
sRes += " : ";
sRes += s2;
}
}
#endif
}
void GetSystemInfoText(AString &sRes)
{
GetOsInfoText(sRes);
sRes.Add_LF();
{
AString s, s1, s2;
GetSysInfo(s1, s2);
if (!s1.IsEmpty() || !s2.IsEmpty())
{
s = s1;
if (s1 != s2 && !s2.IsEmpty())
{
s += " - ";
s += s2;
}
}
{
AddCpuFeatures(s);
if (!s.IsEmpty())
{
sRes += s;
sRes.Add_LF();
}
}
}
{
AString s;
GetCpuName(s);
if (!s.IsEmpty())
{
sRes += s;
sRes.Add_LF();
}
}
/*
#ifdef MY_CPU_X86_OR_AMD64
{
AString s;
x86cpuid_all_to_String(s);
if (!s.IsEmpty())
{
printCallback->Print(s);
printCallback->NewLine();
}
}
#endif
*/
}
void GetCpuName(AString &s);
void GetCpuName(AString &s)
{
CCpuName cpuName;
cpuName.Fill();
s = cpuName.CpuName;
AString s2;
cpuName.Get_Revision_Microcode_LargePages(s2);
s.Add_OptSpaced(s2);
}
void GetCpuName_MultiLine(AString &s);
void GetCpuName_MultiLine(AString &s)
{
CCpuName cpuName;
cpuName.Fill();
s = cpuName.CpuName;
AString s2;
cpuName.Get_Revision_Microcode_LargePages(s2);
if (!s2.IsEmpty())
{
s.Add_LF();
s += s2;
}
}
#ifdef MY_CPU_X86_OR_AMD64
void GetVirtCpuid(AString &s)
{
const UInt32 kHv = 0x40000000;
Z7_IF_X86_CPUID_SUPPORTED
{
UInt32 a[4];
z7_x86_cpuid(a, kHv);
if (a[0] < kHv || a[0] >= kHv + (1 << 16))
return;
{
{
for (unsigned j = 1; j < 4; j++)
PrintCpuChars(s, a[j]);
}
}
if (a[0] >= kHv + 1)
{
UInt32 d[4];
z7_x86_cpuid(d, kHv + 1);
s += " : ";
PrintCpuChars(s, d[0]);
if (a[0] >= kHv + 2)
{
z7_x86_cpuid(d, kHv + 2);
s += " : ";
s.Add_UInt32(d[1] >> 16);
s.Add_Dot(); s.Add_UInt32(d[1] & 0xffff);
s.Add_Dot(); s.Add_UInt32(d[0]);
s.Add_Dot(); s.Add_UInt32(d[2]);
s.Add_Dot(); s.Add_UInt32(d[3] >> 24);
s.Add_Dot(); s.Add_UInt32(d[3] & 0xffffff);
}
/*
if (a[0] >= kHv + 5)
{
z7_x86_cpuid(d, kHv + 5);
s += " : ";
s.Add_UInt32(d[0]);
s += "p";
s.Add_UInt32(d[1]);
s += "t";
}
*/
}
}
}
#endif
void GetCompiler(AString &s)
{
#ifdef __VERSION__
s += __VERSION__;
#endif
#ifdef __GNUC__
s += " GCC ";
s.Add_UInt32(__GNUC__);
s.Add_Dot();
s.Add_UInt32(__GNUC_MINOR__);
s.Add_Dot();
s.Add_UInt32(__GNUC_PATCHLEVEL__);
#endif
#ifdef __clang__
s += " CLANG ";
s.Add_UInt32(__clang_major__);
s.Add_Dot();
s.Add_UInt32(__clang_minor__);
#endif
#ifdef __xlC__
s += " XLC ";
s.Add_UInt32(__xlC__ >> 8);
s.Add_Dot();
s.Add_UInt32(__xlC__ & 0xFF);
#ifdef __xlC_ver__
s.Add_Dot();
s.Add_UInt32(__xlC_ver__ >> 8);
s.Add_Dot();
s.Add_UInt32(__xlC_ver__ & 0xFF);
#endif
#endif
#ifdef _MSC_VER
s += " MSC ";
s.Add_UInt32(_MSC_VER);
#endif
#if defined(__AVX2__)
#define MY_CPU_COMPILE_ISA "AVX2"
#elif defined(__AVX__)
#define MY_CPU_COMPILE_ISA "AVX"
#elif defined(__SSE2__)
#define MY_CPU_COMPILE_ISA "SSE2"
#elif defined(_M_IX86_FP) && (_M_IX86_FP >= 2)
#define MY_CPU_COMPILE_ISA "SSE2"
#elif defined(__SSE__)
#define MY_CPU_COMPILE_ISA "SSE"
#elif defined(_M_IX86_FP) && (_M_IX86_FP >= 1)
#define MY_CPU_COMPILE_ISA "SSE"
#elif defined(__i686__)
#define MY_CPU_COMPILE_ISA "i686"
#elif defined(__i586__)
#define MY_CPU_COMPILE_ISA "i586"
#elif defined(__i486__)
#define MY_CPU_COMPILE_ISA "i486"
#elif defined(__i386__)
#define MY_CPU_COMPILE_ISA "i386"
#elif defined(_M_IX86_FP)
#define MY_CPU_COMPILE_ISA "IA32"
#endif
#ifdef MY_CPU_COMPILE_ISA
s += ':';
s.Add_OptSpaced(MY_CPU_COMPILE_ISA);
#endif
}
|