Skip to content

Commit

Permalink
update cpuid
Browse files Browse the repository at this point in the history
  • Loading branch information
Unam3dd committed Jun 24, 2024
1 parent f8179a8 commit 8260fa6
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 624 deletions.
82 changes: 15 additions & 67 deletions inc/eth-cpuid-flag.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
345 changes: 0 additions & 345 deletions inc/eth-cpuid-lut.h

This file was deleted.

39 changes: 28 additions & 11 deletions inc/eth-cpuid.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#ifndef ETH_CPUID_H
#define ETH_CPUID_H

#include <string.h>
#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

Expand All @@ -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
31 changes: 23 additions & 8 deletions inc/eth-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#endif

#define GET_(x) #x
#define CONCAT(x,y) x##y

///////////////////////////////////////
//
Expand All @@ -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
Expand All @@ -36,14 +37,28 @@
#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)

///////////////////////////////////////
//
// TYPES TYPEDEFS
//
//////////////////////////////////////

#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))

///////////////////////////////////////
//
Expand Down
6 changes: 3 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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',
Expand All @@ -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(),
Expand Down
122 changes: 0 additions & 122 deletions src/cpuid/cpuid.c

This file was deleted.

Loading

0 comments on commit 8260fa6

Please sign in to comment.