Skip to content

Instantly share code, notes, and snippets.

@dixyes
Created December 1, 2021 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dixyes/ff8f4ae96ad51b32d30632eb967601b9 to your computer and use it in GitHub Desktop.
Save dixyes/ff8f4ae96ad51b32d30632eb967601b9 to your computer and use it in GitHub Desktop.
/*
this is undocumented, to be confirmed
read id_aa64isar0_el1 from registry HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\x\CP 4030
*/
uint64_t getaa64isar0() {
const WCHAR cpus_key[] = L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\";
HKEY cpus_handle;
if (ERROR_SUCCESS != RegOpenKeyExW(HKEY_LOCAL_MACHINE, cpus_key, 0, KEY_ENUMERATE_SUB_KEYS, &cpus_handle)) {
printf("failed open reg\n");
return 0;
}
DWORD cpu_index = 0;
WCHAR cpu_num[256] = { 0 };
uint64_t CP4030 = 0;
WCHAR cpu_key[(sizeof(cpus_key) / sizeof(*cpus_key)) + 256] = L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\";
while (ERROR_SUCCESS == RegEnumKeyW(cpus_handle, cpu_index++, cpu_num, 255)) {
if (0 != wcscpy_s(&cpu_key[sizeof(cpus_key) / sizeof(*cpus_key) - 1], 256, cpu_num)) {
break;
}
wprintf(L"checking %s\n", cpu_key);
HKEY cpu_handle;
if (ERROR_SUCCESS != RegOpenKeyExW(HKEY_LOCAL_MACHINE, cpu_key, 0, KEY_READ, &cpu_handle)) {
printf("failed open reg\n");
break;
}
DWORD value_type;
uint64_t value;
DWORD value_size = sizeof(value);
if (ERROR_SUCCESS != RegQueryValueExW(cpu_handle, L"CP 4030", NULL, &value_type, (LPBYTE)&value, &value_size)) {
RegCloseKey(cpu_handle);
printf("failed read cp4030\n");
break;
}
if (value_type != REG_QWORD) {
RegCloseKey(cpu_handle);
printf("failed cp4030 is not qword\n");
break;
}
wprintf(L"cp4030 for cpu[%d] \"%s\" is %016zx\n", cpu_index-1, cpu_num, value);
CP4030 = value;
RegCloseKey(cpu_handle);
break;
}
RegCloseKey(cpus_handle);
return CP4030;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment