CCF
Loading...
Searching...
No Matches
hardware_info.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include <cstdint>
6#include <cstring>
7#include <set>
8
9namespace ccf::pal
10{
11 struct CpuidInfo
12 {
13 uint64_t eax;
14 uint64_t ebx;
15 uint64_t ecx;
16 uint64_t edx;
17 };
18
19 static void cpuid(CpuidInfo* info, uint64_t leaf, uint64_t subleaf)
20 {
21 asm volatile(
22 "cpuid"
23 : "=a"(info->eax), "=b"(info->ebx), "=c"(info->ecx), "=d"(info->edx)
24 : "a"(leaf), "c"(subleaf));
25 }
26
27 static bool is_intel_cpu()
28 {
29 thread_local int intel_cpu = -1;
30
31 if (intel_cpu == -1)
32 {
33 CpuidInfo info;
34 cpuid(&info, 0, 0);
35
36 if (
37 memcmp((char*)&info.ebx, "Genu", 4) ||
38 memcmp((char*)&info.edx, "ineI", 4) ||
39 memcmp((char*)&info.ecx, "ntel", 4))
40 {
41 intel_cpu = 1;
42 }
43 else
44 {
45 intel_cpu = 0;
46 }
47 }
48
49 return intel_cpu == 1;
50 }
51}
Definition attestation.h:28
Definition hardware_info.h:12
uint64_t ecx
Definition hardware_info.h:15
uint64_t ebx
Definition hardware_info.h:14
uint64_t eax
Definition hardware_info.h:13
uint64_t edx
Definition hardware_info.h:16