Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 7d1a5c59c93c2b57935c814955c4d749a4740fa9 Mon Sep 17 00:00:00 2001
- From: Benjamin ROBIN <dev@benjarobin.fr>
- Date: Wed, 14 Oct 2015 13:22:31 +0200
- Subject: [PATCH] Add the cpuid_get_vendor() function to the interface.
- Signed-off-by: Benjamin ROBIN <dev@benjarobin.fr>
- ---
- libcpuid/cpuid_main.c | 49 ++++++++++++++++++++++++++++++++++++++-----------
- libcpuid/libcpuid.h | 8 ++++++++
- 2 files changed, 46 insertions(+), 11 deletions(-)
- diff --git a/libcpuid/cpuid_main.c b/libcpuid/cpuid_main.c
- index 0d7aed7..70b4707 100644
- --- a/libcpuid/cpuid_main.c
- +++ b/libcpuid/cpuid_main.c
- @@ -239,10 +239,8 @@ static void load_features_common(struct cpu_raw_data_t* raw, struct cpu_id_t* da
- }
- }
- -static int cpuid_basic_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* data)
- +static cpu_vendor_t cpuid_vendor_identify(const uint32_t *raw_vendor, char *vendor_str)
- {
- - int i, j, basic, xmodel, xfamily, ext;
- - char brandstr[64] = {0};
- const struct { cpu_vendor_t vendor; char match[16]; }
- matchtable[NUM_CPU_VENDORS] = {
- /* source: http://www.sandpile.org/ia32/cpuid.htm */
- @@ -257,18 +255,30 @@ static int cpuid_basic_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* dat
- { VENDOR_SIS , "SiS SiS SiS " },
- { VENDOR_NSC , "Geode by NSC" },
- };
- -
- - memcpy(data->vendor_str + 0, &raw->basic_cpuid[0][1], 4);
- - memcpy(data->vendor_str + 4, &raw->basic_cpuid[0][3], 4);
- - memcpy(data->vendor_str + 8, &raw->basic_cpuid[0][2], 4);
- - data->vendor_str[12] = 0;
- +
- + cpu_vendor_t vendor = VENDOR_UNKNOWN;
- +
- + memcpy(vendor_str + 0, &raw_vendor[1], 4);
- + memcpy(vendor_str + 4, &raw_vendor[3], 4);
- + memcpy(vendor_str + 8, &raw_vendor[2], 4);
- + vendor_str[12] = 0;
- +
- /* Determine vendor: */
- - data->vendor = VENDOR_UNKNOWN;
- for (i = 0; i < NUM_CPU_VENDORS; i++)
- - if (!strcmp(data->vendor_str, matchtable[i].match)) {
- - data->vendor = matchtable[i].vendor;
- + if (!strcmp(vendor_str, matchtable[i].match)) {
- + vendor = matchtable[i].vendor;
- break;
- }
- +
- + return vendor;
- +}
- +
- +static int cpuid_basic_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* data)
- +{
- + int i, j, basic, xmodel, xfamily, ext;
- + char brandstr[64] = {0};
- +
- + data->vendor = cpuid_vendor_identify(raw->basic_cpuid[0], data->vendor_str);
- if (data->vendor == VENDOR_UNKNOWN)
- return set_error(ERR_CPU_UNKN);
- basic = raw->basic_cpuid[0][0];
- @@ -348,6 +358,23 @@ void cpu_exec_cpuid_ext(uint32_t* regs)
- exec_cpuid(regs);
- }
- +cpu_vendor_t cpuid_get_vendor(void)
- +{
- + static cpu_vendor_t vendor = VENDOR_UNKNOWN;
- + uint32_t raw_vendor[4];
- + char vendor_str[VENDOR_STR_MAX];
- +
- + if (vendor == VENDOR_UNKNOWN) {
- + if (!cpuid_present())
- + set_error(ERR_NO_CPUID);
- + else {
- + cpu_exec_cpuid(0, raw_vendor);
- + vendor = cpuid_vendor_identify(raw_vendor, vendor_str);
- + }
- + }
- + return vendor;
- +}
- +
- int cpuid_get_raw_data(struct cpu_raw_data_t* data)
- {
- unsigned i;
- diff --git a/libcpuid/libcpuid.h b/libcpuid/libcpuid.h
- index 2e317b4..72d370c 100644
- --- a/libcpuid/libcpuid.h
- +++ b/libcpuid/libcpuid.h
- @@ -436,6 +436,14 @@ void cpu_exec_cpuid(uint32_t eax, uint32_t* regs);
- void cpu_exec_cpuid_ext(uint32_t* regs);
- /**
- + * @brief Obtains the cpu vendor from CPUID from the current CPU
- + * @note The result is cached.
- + * @returns VENDOR_UNKNOWN if failed, otherwise the cpu vendor type.
- + * @see cpu_vendor_t
- + */
- +cpu_vendor_t cpuid_get_vendor(void);
- +
- +/**
- * @brief Obtains the raw CPUID data from the current CPU
- * @param data - a pointer to cpu_raw_data_t structure
- * @returns zero if successful, and some negative number on error.
- --
- 2.6.1.windows.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement