From 8260fa6f57d378fbd4ef23fdf82d72c0890bbf20 Mon Sep 17 00:00:00 2001 From: Unam3dd Date: Mon, 24 Jun 2024 08:18:34 +0200 Subject: [PATCH] update cpuid --- inc/eth-cpuid-flag.h | 82 ++------- inc/eth-cpuid-lut.h | 345 ------------------------------------ inc/eth-cpuid.h | 39 ++-- inc/eth-types.h | 31 +++- meson.build | 6 +- src/cpuid/cpuid.c | 122 ------------- src/cpuid/manufacturer_id.c | 39 ++++ tests/cpuid/cpuid_test.c | 68 ------- 8 files changed, 108 insertions(+), 624 deletions(-) delete mode 100644 inc/eth-cpuid-lut.h delete mode 100644 src/cpuid/cpuid.c create mode 100644 src/cpuid/manufacturer_id.c delete mode 100644 tests/cpuid/cpuid_test.c diff --git a/inc/eth-cpuid-flag.h b/inc/eth-cpuid-flag.h index 3acd281..dacaea8 100644 --- a/inc/eth-cpuid-flag.h +++ b/inc/eth-cpuid-flag.h @@ -19,8 +19,9 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" -typedef enum eth_cpuid_eax_flag_t +typedef enum eth_cpuid_flag_t { + ETH_CPUID_HIGHEST_FEAT = 0x0, ETH_CPUID_PROC_INFO_FEAT = 0x1, ETH_CPUID_CACHE_TLB_INFO = 0x2, ETH_CPUID_CPU_SERIAL_NUMBER = 0x3, @@ -53,25 +54,21 @@ typedef enum eth_cpuid_eax_flag_t ETH_CPUID_ENCRYPTED_MEM_CAP = 0x8000001F, ETH_CPUID_EXT_FEAT_ID = 0x80000021, ETH_CPUID_HIGHEST_CENTAUR_EXT_FEAT = 0xC0000000, - ETH_CPUID_CENTAUR_FEAT = 0xC0000001, -} eth_cpuid_eax_flag_t; + ETH_CPUID_CENTAUR_FEAT = 0xC0000001, + ETH_CPUID_FEAT_PAGE_1 = 0x1, + ETH_CPUID_FEAT_PAGE_2 = 0x2, + ETH_CPUID_XSAVE_FEAT_PAGE_1 = 0x0, + ETH_CPUID_XSAVE_FEAT_PAGE_2 = 0x1, + ETH_CPUID_SGX_PAGE_1 = 0x0, + ETH_CPUID_SGX_PAGE_2 = 0x1, + ETH_CPUID_SGX_PAGE_3 = 0x2, + ETH_CPUID_PTRACE = 0x0, + ETH_CPUID_SOC_VENDOR = 0x0, + ETH_CPUID_AVX10 = 0x0, + ETH_CPUID_DISCRET_AVX10 = 0x1 +} eth_cpuid_flag_t; #pragma GCC diagnostic pop -typedef enum eth_cpuid_ecx_flag_t -{ - FEAT_ECX_PAGE_1 = 0x1, - FEAT_ECX_PAGE_2 = 0x2, - XSAVE_FEAT_ECX_PAGE_1 = 0x0, - XSAVE_FEAT_ECX_PAGE_2 = 0x1, - SGX_ECX_PAGE_1 = 0x0, - SGX_ECX_PAGE_2 = 0x1, - SGX_ECX_PAGE_3 = 0x2, - PROC_TRACE_ECX = 0x0, - SOC_VENDOR_ATTRIB_ECX = 0x0, - AVX10_FEAT_ECX = 0x0, - DISCRET_AVX10_FEAT_ECX = 0x1 -} eth_cpuid_ecx_flag_t; - typedef enum eth_cpuid_reg_index_t { EAX, // EAX: 0x0 @@ -281,53 +278,4 @@ typedef enum eth_cpuid_feat_flag_t } eth_cpuid_feat_flag_t; #pragma GCC diagnostic pop -/////////////////////////////////////// -// -// TYPEDEFS STRUCT CPUID -// -////////////////////////////////////// - -typedef struct eth_cpuid_reg_t eth_cpuid_reg_t; -typedef struct eth_cpuid_feat_ext_t eth_cpuid_feat_ext_t; - -/////////////////////////////////////// -// -// STRUCT CPUID REG -// -////////////////////////////////////// - -struct eth_cpuid_reg_t -{ - u32_t eax; - u32_t ecx; - u32_t edx; - u32_t ebx; -} __attribute__ ((__packed__)); - - -/////////////////////////////////////// -// -// CPUID FEAT EXT STRUCT -// -////////////////////////////////////// - -struct eth_cpuid_feat_ext_t -{ - const char *str; - eth_cpuid_eax_flag_t eax_flg; - eth_cpuid_ecx_flag_t ecx_flg; - eth_cpuid_feat_flag_t flg; - eth_cpuid_reg_index_t reg; -}; - -/////////////////////////////////////// -// -// CPUID FEAT MACRO -// -////////////////////////////////////// - - -#define DEF_BASIC_FEAT(n,index) const eth_cpuid_feat_ext_t *n = e_cpuid_feat(index,0,0) -#define DEF_EXT_FEAT(n, index, page) const eth_cpuid_feat_ext_t *n = e_cpuid_feat(index, 1, page) - #endif diff --git a/inc/eth-cpuid-lut.h b/inc/eth-cpuid-lut.h deleted file mode 100644 index 67b874e..0000000 --- a/inc/eth-cpuid-lut.h +++ /dev/null @@ -1,345 +0,0 @@ -#ifndef ETH_CPUID_LUT_H -#define ETH_CPUID_LUT_H - -/////////////////////////////////////// -// -// INCLUDES -// -////////////////////////////////////// - -#include "eth-cpuid-flag.h" - -/////////////////////////////////////// -// -// CPUID FEAT LOOK UP TABLE -// -////////////////////////////////////// - -#define DEF_CPUID_PROC_INFO(name) static const eth_cpuid_feat_ext_t \ - _eth_LUT_EDX_##name[] = { \ - {"fpu", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_FPU, EDX }, \ - {"vme", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_VME, EDX }, \ - {"de", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_DE, EDX }, \ - {"pse", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_PSE, EDX }, \ - {"tsc", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_TSC, EDX }, \ - {"msr", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_MSR, EDX }, \ - {"pae", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_PAE, EDX }, \ - {"mce", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_MCE, EDX }, \ - {"cx8", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_CX8, EDX }, \ - {"apic", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_APIC, EDX }, \ - {"sep", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_SEP, EDX }, \ - {"mtrr", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_MTRR, EDX }, \ - {"pge", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_PGE, EDX }, \ - {"mca", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_MCA, EDX }, \ - {"cmov", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_CMOV, EDX }, \ - {"pat", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_PAT, EDX }, \ - {"pse-36", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_PSE36, EDX }, \ - {"psn", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_PSN, EDX }, \ - {"clfsh", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_CLFSH, EDX }, \ - {"nx", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_NX, EDX }, \ - {"ds", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_DS, EDX }, \ - {"acpi", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_ACPI, EDX }, \ - {"mmx", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_MMX, EDX }, \ - {"fxsr", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_FXSR, EDX }, \ - {"sse", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_SSE, EDX }, \ - {"sse2", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_SSE2, EDX }, \ - {"ss", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_SS, EDX }, \ - {"htt", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_HTT, EDX }, \ - {"tm", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_TM, EDX }, \ - {"ia64", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_IA64, EDX }, \ - {"pbe", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_PBE, EDX }, \ - }; \ - static const eth_cpuid_feat_ext_t \ - _eth_LUT_ECX_##name[] = { \ - {"sse3", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_SSE3, ECX },\ - {"pclmulqdq", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_PCLMULQDQ, ECX },\ - {"dtes64", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_DTES64, ECX },\ - {"monitor", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_MONITOR, ECX },\ - {"ds-cpl", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_DS_CPL, ECX },\ - {"vmx", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_VMX, ECX },\ - {"smx", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_SMX, ECX },\ - {"est", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_EST, ECX },\ - {"tm2", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_TM2, ECX },\ - {"ssse3", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_SSSE3, ECX },\ - {"cnxt-id", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_CNXT_ID, ECX },\ - {"sdbg", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_SDBG, ECX },\ - {"fma", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_FMA, ECX },\ - {"cx16", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_CX16, ECX },\ - {"xtpr", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_XTPR, ECX },\ - {"pdcm", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_PDCM, ECX },\ - {"pcid", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_PCID, ECX },\ - {"dca", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_DCA, ECX },\ - {"sse4.1", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_SSE41, ECX },\ - {"sse4.2", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_SSE42, ECX },\ - {"x2apic", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_X2APIC, ECX },\ - {"movbe", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_MOVBE, ECX },\ - {"popcnt", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_POPCNT, ECX },\ - {"tsc-deadline",ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_TSC_DLINE, ECX },\ - {"aes", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_AES_NI, ECX },\ - {"xsave", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_XSAVE, ECX },\ - {"osxsave", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_OSXSAVE, ECX },\ - {"avx", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_AVX, ECX },\ - {"f16c", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_F16C, ECX },\ - {"rdrnd", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_RDRND, ECX },\ - {"hypervisor", ETH_CPUID_PROC_INFO_FEAT, 0, ETH_CPUID_FEAT_HYPERVISOR,ECX },\ - }; - - -#define DEF_CPUID_EXT_FEAT(name) static const eth_cpuid_feat_ext_t \ - _eth_LUT_ext_EBX##name[] = { \ - { "fsgsbase", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_FSGSBASE, EBX }, \ - { "tsc-adj-msr", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_IA32_TSC_ADJUST_MSR, EBX }, \ - { "sgx", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_SGX, EBX }, \ - { "bmi1", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_BMI1, EBX }, \ - { "hle", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_HLE, EBX }, \ - { "avx2", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX2, EBX }, \ - { "fdp", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_FDP, EBX }, \ - { "smep", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_SMEP, EBX }, \ - { "bmi2", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_BMI2, EBX }, \ - { "erms", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_ERMS, EBX }, \ - { "invpcid", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_INVPCID, EBX }, \ - { "rtm", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_RTM, EBX }, \ - { "rdt-m", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_RDTM_PQM, EBX }, \ - { "fpu", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_X87_FPU, EBX }, \ - { "mpx", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_MPX, EBX }, \ - { "rdt-a", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_RDTA_PQE, EBX }, \ - { "avx512-f", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512F, EBX }, \ - { "avx512-dq", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512DQ, EBX }, \ - { "rdseed", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_RDSEED, EBX }, \ - { "adx", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_ADX, EBX }, \ - { "smap", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_SMAP, EBX }, \ - { "avx512-ifma", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_IFMA, EBX }, \ - { "pcommit", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_PCOMMIT, EBX }, \ - { "clflushopt", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_CLFLUSHOPT, EBX }, \ - { "clwb", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_CLWB, EBX }, \ - { "pt", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_PT, EBX }, \ - { "avx512-pf", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_PF, EBX }, \ - { "avx512-er", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_ER, EBX }, \ - { "avx512-cd", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_CD, EBX }, \ - { "sha", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_SHA, EBX }, \ - { "avx512-bw", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_BW, EBX }, \ - { "avx512-vl", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_VL, EBX }, \ - }; \ - static const eth_cpuid_feat_ext_t \ - _eth_LUT_ext_ECX##name[] = { \ - { "prefetchwt1", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_PREFETCHWT1, ECX }, \ - { "avx512-vbmi", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_VBMI, ECX }, \ - { "umip", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_UMIP, ECX }, \ - { "pku", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_PKU, ECX }, \ - { "ospke", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_OSPKE, ECX }, \ - { "waitpkg", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_WAITPKG, ECX }, \ - { "avx512-vbmi2", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_VBMI2, ECX }, \ - { "cet_ss", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_CET_SS, ECX }, \ - { "gfni", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_GFNI, ECX }, \ - { "vaes", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_VAES, ECX }, \ - { "vpclmulqdq", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_VPCLMULQDQ, ECX }, \ - { "avx512-vnni", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_VNNI, ECX }, \ - { "avx512-bitalg", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_BITALG, ECX }, \ - { "tme-en", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_TME_EN, ECX }, \ - { "vpopcntdq", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_VPOPCNTDQ, ECX }, \ - { "fzm", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_FZM, ECX }, \ - { "la57", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_LA57, ECX }, \ - { "mawau", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_MAWAU, ECX }, \ - { NULL, 0, 0, 0, 0}, \ - { NULL, 0, 0, 0, 0}, \ - { NULL, 0, 0, 0, 0}, \ - { NULL, 0, 0, 0, 0}, \ - { "rdpid", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_RDPID, ECX }, \ - { "kl", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_KL, ECX }, \ - { "bus-lock-detect", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_BUS_LOCK_DETECT, ECX }, \ - { "cldemote", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_CLDEMOTE, ECX }, \ - { "mprr", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_MPRR, ECX }, \ - { "movdiri", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_MOVDIRI, ECX }, \ - { "movdir64b", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_MOVDIR64B, ECX }, \ - { "enqcmd", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_ENQCMD, ECX }, \ - { "sgx-lc", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_SGX_LC, ECX }, \ - { "pks", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_PKS, ECX }, \ - }; \ - static const eth_cpuid_feat_ext_t \ - _eth_LUT_ext_EDX##name[] = { \ - { "sgx-term", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_SGX_TERM, EDX }, \ - { "sgx-keys", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_SGX_KEYS, EDX }, \ - { "avx512-4vnniw", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_4VNNIW, EDX }, \ - { "avx512-4fmaps", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_4FMAPS, EDX }, \ - { "fsrm", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_FSRM, EDX }, \ - { "uintr", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_UINTR, EDX }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { "vp2intersect", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_VP2INTERSECT, EDX }, \ - { "srdbs-ctrl", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_SRBDS_CTRL, EDX }, \ - { "md-clear", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_MD_CLEAR, EDX }, \ - { "rtm-always", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_RTM_ALWAYS_ABORT, EDX }, \ - { NULL, 0, 0, 0, 0 }, \ - { "rtm-force", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_RTM_FORCE_ABORT, EDX }, \ - { "serialize", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_SERIALIZE, EDX }, \ - { "hybrid", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_HYBRID, EDX }, \ - { "tsxldtrk", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_TSXLDTRK, EDX }, \ - { "pconfig", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_PCONFIG, EDX }, \ - { "lbr", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_LBR, EDX }, \ - { "cet-ibt", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_CET_IBT, EDX }, \ - { "amx-bf16", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AMX_BF16, EDX }, \ - { "avx512-fp16", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AVX512_FP16, EDX }, \ - { "amx-tile", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AMX_TILE, EDX }, \ - { "amx-int8", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_AMX_INT8, EDX }, \ - { "ibrs", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_IBRS, EDX }, \ - { "stibp", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_STIBP, EDX }, \ - { "l1d_flush", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_L1D_FLUSH, EDX }, \ - { "arch-cap-msr", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_IA32_ARCH_CAP_MSR, EDX }, \ - { "core-cap-msr", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_IA32_CORE_CAP_MSR, EDX }, \ - { "ssbd", ETH_CPUID_EXT_FEAT, 0, ETH_CPUID_EXT_FEAT_SSBD, EDX }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - }; \ - static const eth_cpuid_feat_ext_t \ - _eth_LUT_ext_one_EAX##name[] = { \ - { "sha512", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, \ - ETH_CPUID_EXT_FEAT_SHA512, EAX }, \ - { "sm3", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_SM3, EAX },\ - { "sm4", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_SM4, EAX },\ - { "rao-int", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_RAO_INT, EAX },\ - { "avx-vnni", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_AVX_VNNI, EAX},\ - { "avx512-bf16", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2,\ - ETH_CPUID_EXT_FEAT_AVX512_BF16, EAX },\ - { "lass", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_LASS, EAX },\ - { "cmpccxadd", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_CMPCCXADD, EAX },\ - { "archperfmonext", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, \ - ETH_CPUID_EXT_FEAT_ARCHPERFMONEXT, EAX },\ - { "dedup", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_DEDUP, EAX }, \ - { "fzrm", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_FZRM, EAX }, \ - { "fsrs", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_FSRS, EAX }, \ - { "rsrcs", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_RSRCS, EAX }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { "fred", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_FRED, EAX }, \ - { "lkgs", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_LKGS, EAX }, \ - { "wrmsrns", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_WRMSRNS, EAX }, \ - { "nmi_src", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_NMI_SRC, EAX }, \ - { "amx-fp16", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_AMX_FP16, EAX }, \ - { "hreset", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_HRESET, EAX }, \ - { "avx-ifma", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_AVX_IFMA, EAX }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { "Lam", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_LAM, EAX }, \ - { "msrlist", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_MSRLIST, EAX }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { "invd_pst_bios", \ - ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, \ - ETH_CPUID_EXT_FEAT_INVD_DISABLE_POST_BIOS_DONE, EAX }, \ - { NULL, 0, 0, 0, 0 }, \ - };\ - static const eth_cpuid_feat_ext_t \ - _eth_LUT_ext_one_EBX##name[] = { \ - { "ia32-ppin-ctl", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_IA32_PPIN_CTL, EBX },\ - { "pbndkb", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_PBNDKB, EBX }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - };\ - static const eth_cpuid_feat_ext_t\ - _eth_LUT_ext_one_ECX##name[] = { \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { "legacy-risa", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2,\ - ETH_CPUID_EXT_FEAT_LEGACY_REDUCED_ISA, ECX },\ - { NULL, 0, 0, 0, 0 }, \ - { "sipi64", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2,\ - ETH_CPUID_EXT_FEAT_SIPI_64, ECX }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - };\ - static const eth_cpuid_feat_ext_t \ - _eth_LUT_ext_one_EDX##name[] = { \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { "avx-vnni-int8", ETH_CPUID_EXT_FEAT, \ - FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_AVX_VNNI_INT8, EDX }, \ - { "avx-ne-convert", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_AVX_NE_CONVERT, EDX },\ - { NULL, 0, 0, 0, 0 }, \ - { NULL, 0, 0, 0, 0 }, \ - { "amx-complex", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_AMX_COMPLEX, EDX},\ - { NULL, 0, 0, 0, 0 },\ - { "avx-vnni-int16", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2,\ - ETH_CPUID_EXT_FEAT_AVX_VNNI_INT16, EDX}, \ - { NULL, 0, 0, 0, 0 },\ - { NULL, 0, 0, 0, 0 },\ - { "utmr", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_UTMR, EDX }, \ - { "prefetchi", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, \ - ETH_CPUID_EXT_FEAT_PREFETCHI, EDX },\ - { "user-msr", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_USER_MSR, EDX },\ - { NULL, 0, 0, 0, 0 },\ - { "uiret-rflags", ETH_CPUID_EXT_FEAT, \ - FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_UIRET_UIF_FROM_RFLAGS, EDX },\ - {"cet-sss", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_CET_SS, EDX },\ - { "avx10", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_AVX10, EDX },\ - { NULL, 0, 0, 0, 0 },\ - { "apx-f", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_APX_F, EDX },\ - { NULL, 0, 0, 0, 0 },\ - { "mwait", ETH_CPUID_EXT_FEAT, FEAT_ECX_PAGE_2, ETH_CPUID_EXT_FEAT_MWAIT, EDX },\ - { NULL, 0, 0, 0, 0 },\ - { NULL, 0, 0, 0, 0 },\ - { NULL, 0, 0, 0, 0 },\ - { NULL, 0, 0, 0, 0 },\ - { NULL, 0, 0, 0, 0 },\ - { NULL, 0, 0, 0, 0 },\ - { NULL, 0, 0, 0, 0 },\ - { NULL, 0, 0, 0, 0 },\ - }; - -#endif diff --git a/inc/eth-cpuid.h b/inc/eth-cpuid.h index ab6d3be..b8e8e62 100644 --- a/inc/eth-cpuid.h +++ b/inc/eth-cpuid.h @@ -1,10 +1,9 @@ #ifndef ETH_CPUID_H #define ETH_CPUID_H -#include -#if !defined (__x86_64__) +#if !defined (__x86_64__) && !defined (__amd64__) -#error "Error Etheria CPUID is only supported on x86 architecture" +#error "Error Etheria CPUID is only supported on x86 or amd architecture" #else @@ -24,34 +23,52 @@ #include "eth-cpuid-flag.h" +/////////////////////////////////////// +// +// TYPEDEFS STRUCT CPUID +// +////////////////////////////////////// + +typedef struct eth_cpuid_reg_t eth_cpuid_reg_t; /////////////////////////////////////// // -// CPUID +// STRUCT CPUID REG // ////////////////////////////////////// -STATIC_INLINE eth_cpuid_reg_t *eth_cpuid(u32_t eax, u32_t ecx) +struct eth_cpuid_reg_t { - static eth_cpuid_reg_t r; + u32_t eax; + u32_t ecx; + u32_t edx; + u32_t ebx; +} __attribute__ ((__packed__)); + +/////////////////////////////////////// +// +// CPUID INLINE INSTRUCTION +// +////////////////////////////////////// +STATIC_ALWAYS_INLINE_NONNULL eth_cpuid_reg_t *eth_cpuid(u32_t eax, u32_t ecx, eth_cpuid_reg_t *r) +{ __asm__ volatile ("cpuid" - : "=a" (r.eax), "=b" (r.ebx), "=c" (r.ecx), "=d" (r.edx) + : "=a" (r->eax), "=b" (r->ebx), "=c" (r->ecx), "=d" (r->edx) : "a" (eax), "c" (ecx) : "memory" ); - return (&r); + return (r); } /////////////////////////////////////// // -// CPU SUPPORTS +// ETH CPUID FUNCTION // ////////////////////////////////////// -eth_bool_t eth_cpu_support(const char *name); +const char *eth_cpuid_get_cpu_manufacturer_id(void); #endif - #endif diff --git a/inc/eth-types.h b/inc/eth-types.h index 8d41991..71c4148 100644 --- a/inc/eth-types.h +++ b/inc/eth-types.h @@ -12,6 +12,7 @@ #endif #define GET_(x) #x +#define CONCAT(x,y) x##y /////////////////////////////////////// // @@ -20,13 +21,13 @@ ////////////////////////////////////// #define BIN_NUM_1(x) (1<<(x)) -#define BIN_NUM_2(x) (BIN_NUM_1(x))|(BIN_NUM_1(x+1)) -#define BIN_NUM_3(x) (BIN_NUM_2(x))|(BIN_NUM_1(x+2)) -#define BIN_NUM_4(x) (BIN_NUM_2(x))|(BIN_NUM_2(x+2)) -#define BIN_NUM_5(x) (BIN_NUM_4(x))|(BIN_NUM_1(x+4)) -#define BIN_NUM_6(x) (BIN_NUM_4(x))|(BIN_NUM_2(x+4)) -#define BIN_NUM_7(x) (BIN_NUM_4(x))|(BIN_NUM_3(x+4)) -#define BIN_NUM_8(x) (BIN_NUM_4(x))|(BIN_NUM_4(x+4)) +#define BIN_NUM_2(x) (BIN_NUM_1(x))|(BIN_NUM_1(x|1)) +#define BIN_NUM_3(x) (BIN_NUM_2(x))|(BIN_NUM_1(x|2)) +#define BIN_NUM_4(x) (BIN_NUM_2(x))|(BIN_NUM_2(x|2)) +#define BIN_NUM_5(x) (BIN_NUM_4(x))|(BIN_NUM_1(x|4)) +#define BIN_NUM_6(x) (BIN_NUM_4(x))|(BIN_NUM_2(x|4)) +#define BIN_NUM_7(x) (BIN_NUM_4(x))|(BIN_NUM_3(x|4)) +#define BIN_NUM_8(x) (BIN_NUM_4(x))|(BIN_NUM_4(x|4)) #define ETH_AND(a, b) a & b #define ETH_OR(a, b) a | b @@ -36,6 +37,17 @@ #define ETH_RSH(a, b) (a >> b) #define ETH_ZERO(x) ETH_XOR(x, x) #define GET_SIZE(x, y) (sizeof(x)/sizeof(y)) +#define SIZEOF_BITS(x) (sizeof(x) << 3) +#define ETH_SWAP_BITS(x) (x >> (SIZEOF_BITS(x)>>1)) | (x << (SIZEOF_BITS(x)>>1)) +#define ETH_SWAP(a, b) (a ^= b; b ^= a; a ^= b;) +#define ETH_UBYTE(x) (x & 0xFF) +#define ETH_BYTE(x) (x & 0x7F) +#define ETH_UWORD(x) (x & 0xFFFF) +#define ETH_WORD(x) (x & 0x7FFF) +#define ETH_UDWORD(x) (x & 0xFFFFFFFF) +#define ETH_DWORD(x) (x & 0x7FFFFFFF) +#define ETH_UQWORD(x) (x & 0xFFFFFFFFFFFFFFFF) +#define ETH_QWORD(x) (x & 0x7FFFFFFFFFFFFFFF) /////////////////////////////////////// // @@ -43,7 +55,10 @@ // ////////////////////////////////////// -#define STATIC_INLINE static inline __attribute__((always_inline)) +#define STATIC_INLINE static inline +#define STATIC_ALWAYS_INLINE_NONNULL static inline __attribute__((always_inline, nonnull)) +#define STATIC_ALWAYS_INLINE static inline __attribute__((always_inline)) +#define STATIC_NOINLINE static __attribute__((noinline)) /////////////////////////////////////// // diff --git a/meson.build b/meson.build index 44899c1..799f309 100644 --- a/meson.build +++ b/meson.build @@ -53,7 +53,8 @@ incdir = include_directories('inc') ###################################### MEMCPY_FILES = files('src/memory/memcpy/memcpy.c') -CPUID_FILES = files('src/cpuid/cpuid.c') + +CPUID_FILES = files('src/cpuid/manufacturer_id.c') SRCS = MEMCPY_FILES + CPUID_FILES @@ -67,7 +68,6 @@ SRCS = MEMCPY_FILES + CPUID_FILES types_tests = files('tests/types/types_basic_test.c') -cpuid_tests = files('tests/cpuid/cpuid_test.c') memory_memcpy_naive = files('tests/memory/memcpy/memcpy_naive/memcpy_naive.c', 'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_small.c', @@ -77,7 +77,7 @@ memory_memcpy_naive = files('tests/memory/memcpy/memcpy_naive/memcpy_naive.c', 'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_mid.c', 'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_big.c') -tests = types_tests + memory_memcpy_naive + cpuid_tests +tests = types_tests + memory_memcpy_naive summary({ 'CPU': build_machine.cpu(), diff --git a/src/cpuid/cpuid.c b/src/cpuid/cpuid.c deleted file mode 100644 index 386394e..0000000 --- a/src/cpuid/cpuid.c +++ /dev/null @@ -1,122 +0,0 @@ -#include "eth-cpuid-flag.h" -#include "eth-cpuid-lut.h" -#include "eth-cpuid.h" -#include "eth-types.h" -#include "eth-types.h" -#include - -static const eth_cpuid_feat_ext_t * -e_cpuid_feat(eth_cpuid_ri_t idx, eth_bool_t ext, u32_t x_page) -{ - DEF_CPUID_PROC_INFO(info); - DEF_CPUID_EXT_FEAT(_sup); - - if (ext) { - if (!x_page && idx == EBX) - return (_eth_LUT_ext_EBX_sup); - if (!x_page && idx == ECX) - return (_eth_LUT_ext_ECX_sup); - if (!x_page && idx == EDX) - return (_eth_LUT_ext_EDX_sup); - if (x_page == FEAT_ECX_PAGE_1 && idx == EAX) - return (_eth_LUT_ext_one_EAX_sup); - if (x_page == FEAT_ECX_PAGE_1 && idx == EBX) - return (_eth_LUT_ext_one_EBX_sup); - if (x_page == FEAT_ECX_PAGE_1 && idx == ECX) - return (_eth_LUT_ext_one_ECX_sup); - if (x_page == FEAT_ECX_PAGE_1 && idx == EDX) - return (_eth_LUT_ext_one_EDX_sup); - return (NULL); - } - - return (idx == EDX - ? _eth_LUT_EDX_info - : idx == ECX - ? _eth_LUT_ECX_info - : NULL); -} - -/////////////////////////////////////// -// -// COMPARE STRING -// -////////////////////////////////////// - -static __attribute__((noinline)) i32_t fast_cmp_str(const char *s1, const char *s2) -{ - i32_t r = 0; - - if (!s1 || !s2) return (-1); - - __asm__ volatile ( - "movdqu xmm0, xmmword ptr [rdi]\n\t" - "movdqu xmm1, xmmword ptr [rsi]\n\t" - "pcmpistrm xmm0, xmm1, 0x18\n\t" - "movq rax, xmm0\n\t" - : "=a" (r) - : "D" (s1), "S" (s2) - : "memory" - ); - - return (r); -} - -/////////////////////////////////////// -// -// CPU SUPPORTS -// -////////////////////////////////////// - -eth_bool_t eth_cpu_support(const char *name) -{ - eth_cpuid_reg_t *reg = NULL; - eth_cpuid_feat_ext_t *ptr = NULL; - u32_t *offset = NULL; - size_t i = 0; - - DEF_BASIC_FEAT(basic_feat_edx, EDX); - DEF_BASIC_FEAT(basic_feat_ecx, ECX); - - DEF_EXT_FEAT(ext_feat_ebx, EBX, 0); - DEF_EXT_FEAT(ext_feat_ecx, ECX, 0); - DEF_EXT_FEAT(ext_feat_edx, EDX, 0); - DEF_EXT_FEAT(ext_feat_one_eax, EAX, 1); - DEF_EXT_FEAT(ext_feat_one_ebx, EBX, 1); - DEF_EXT_FEAT(ext_feat_one_ecx, ECX, 1); - DEF_EXT_FEAT(ext_feat_one_edx, EDX, 1); - - if (!name || *name == 0) return (FALSE); - - for (i = 0; i < 32; i++) { - - if (!ptr && !fast_cmp_str(basic_feat_edx[i].str, name)) - ptr = (eth_cpuid_feat_ext_t*)&basic_feat_edx[i]; - if (!ptr && !fast_cmp_str(basic_feat_ecx[i].str, name)) - ptr = (eth_cpuid_feat_ext_t*)&basic_feat_ecx[i]; - if (!ptr && !fast_cmp_str(ext_feat_ebx[i].str, name)) - ptr = (eth_cpuid_feat_ext_t*)&ext_feat_ebx[i]; - if (!ptr && !fast_cmp_str(ext_feat_ecx[i].str, name)) - ptr = (eth_cpuid_feat_ext_t*)&ext_feat_ecx[i]; - if (!ptr && !fast_cmp_str(ext_feat_edx[i].str, name)) - ptr = (eth_cpuid_feat_ext_t*)&ext_feat_edx[i]; - if (!ptr && !fast_cmp_str(ext_feat_one_eax[i].str, name)) - ptr = (eth_cpuid_feat_ext_t*)&ext_feat_one_eax[i]; - if (!ptr && !fast_cmp_str(ext_feat_one_ebx[i].str, name)) - ptr = (eth_cpuid_feat_ext_t *)&ext_feat_one_ebx[i]; - if (!ptr && !fast_cmp_str(ext_feat_one_ecx[i].str, name)) - ptr = (eth_cpuid_feat_ext_t *)&ext_feat_one_ecx[i]; - if (!ptr && !fast_cmp_str(ext_feat_one_edx[i].str, name)) - ptr = (eth_cpuid_feat_ext_t *)&ext_feat_one_edx[i]; - if (ptr) break ; - } - - if (!ptr) return (FALSE); - - reg = eth_cpuid(ptr->eax_flg, ptr->ecx_flg); - - if (!reg) return (FALSE); - - offset = (u32_t*)(((u64_t)reg) + (sizeof(u32_t)*ptr->reg)); - - return (offset && (ETH_AND(*offset, ptr->flg)) == (u32_t)ptr->flg); -} diff --git a/src/cpuid/manufacturer_id.c b/src/cpuid/manufacturer_id.c new file mode 100644 index 0000000..00320f5 --- /dev/null +++ b/src/cpuid/manufacturer_id.c @@ -0,0 +1,39 @@ +/* @file manufacturer_id.c + * @brief That file contain the manufacturer_id function code + * So this is a simple function which return manufacturer ID + * String from CPUID instruction on x86 Architecture + * @note no note + * @bugs no bugs known + * @date 23/06/2024 16:37:16 + * @author Unam3dd (sam0verfl0w) + */ + +/////////////////////////////////////// +// +// INCLUDES +// +////////////////////////////////////// + +#include "eth-cpuid-flag.h" +#include "eth-cpuid.h" +#include "eth-types.h" + +/////////////////////////////////////// +// +// MANUFACTURER ID +// +////////////////////////////////////// + +const char *eth_cpuid_get_cpu_manufacturer_id(void) +{ + static eth_cpuid_reg_t r = { 0, 0, 0, 0 }; + static u32_t d[0x4] = { 0, 0, 0, 0 }; + + if (d[0] && d[1] && d[2]) return ((const char *)d); + + eth_cpuid(ETH_CPUID_HIGHEST_FEAT, 0, &r); + + d[0] = r.ebx; d[1] = r.edx; d[2] = r.ecx; + + return ((const char *)d); +} diff --git a/tests/cpuid/cpuid_test.c b/tests/cpuid/cpuid_test.c deleted file mode 100644 index 3c47409..0000000 --- a/tests/cpuid/cpuid_test.c +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include "eth-cpuid.h" -#include "eth-types.h" - -Test(test_etheria_cpuid_basic, cpuid_basic_test_sse) -{ - cr_expect(eth_cpu_support("sse") == (eth_bool_t)(__builtin_cpu_supports("sse") ? 1 : 0)); -} - -Test(test_etheria_cpuid_basic, cpuid_basic_test_avx) -{ - cr_expect(eth_cpu_support("avx") == (eth_bool_t)(__builtin_cpu_supports("avx") ? 1 : 0)); -} - -Test(test_etheria_cpuid_basic, cpuid_basic_test_sse2) -{ - cr_expect(eth_cpu_support("sse2") == (eth_bool_t)(__builtin_cpu_supports("sse2") ? 1 : 0)); -} - -Test(test_etheria_cpuid_basic, cpuid_basic_test_sse41) -{ - cr_expect(eth_cpu_support("sse4.1") == (eth_bool_t)(__builtin_cpu_supports("sse4.1") ? 1 : 0)); -} - -Test(test_etheria_cpuid_basic, cpuid_basic_test_sse42) -{ - cr_expect(eth_cpu_support("sse4.2") == (eth_bool_t)(__builtin_cpu_supports("sse4.2") ? 1 : 0)); -} - -Test(test_etheria_cpuid_basic, cpuid_basic_test_aes) -{ - cr_expect(eth_cpu_support("aes") == (eth_bool_t)(__builtin_cpu_supports("aes") ? 1 : 0)); -} - -Test(test_etheria_cpuid_basic, cpuid_basic_test_sse3) -{ - cr_expect(eth_cpu_support("sse3") == (eth_bool_t)(__builtin_cpu_supports("sse3") ? 1 : 0)); -} - -Test(test_etheria_cpuid_basic, cpuid_basic_test_popcnt) -{ - cr_expect(eth_cpu_support("popcnt") == (eth_bool_t)(__builtin_cpu_supports("popcnt") ? 1 : 0)); -} - -Test(test_etheria_cpuid_basic, cpuid_basic_test_ssse3) -{ - cr_expect(eth_cpu_support("ssse3") == (eth_bool_t)(__builtin_cpu_supports("ssse3") ? 1 : 0)); -} - -Test(test_etheria_cpuid_basic, cpuid_basic_test_cmov) -{ - cr_expect(eth_cpu_support("cmov") == (eth_bool_t)(__builtin_cpu_supports("cmov") ? 1 : 0)); -} - -Test(test_etheria_cpuid_basic, cpuid_basic_test_null) -{ - char *str = ""; - - cr_expect(eth_cpu_support(NULL) == 0); - cr_expect(eth_cpu_support(str) == 0); -} - -Test(test_etheria_cpuid_basic, cpuid_basic_bad_feat) -{ - cr_expect(eth_cpu_support("fejfizjefijzefiozejfiojzeifzeifjzeodjzefijzeofjzeuijzzeofjzeiodjeiodjz") == 0); - cr_expect(eth_cpu_support("ssed") == 0); - cr_expect(eth_cpu_support("fefefefef") == 0); -}