Skip to content

Commit c75a897

Browse files
committed
feat: add CPUID function
The CPUID function calls leaf with subleaf function and returns eax, ebx, ecx and edx. Signed-off-by: Christian Walter <christian.walter@9elements.com>
1 parent 7e0a5df commit c75a897

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

pkg/hwapi/cpuid_amd64.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,50 @@ import "github.com/intel-go/cpuid"
88

99
func cpuidLow(arg1, arg2 uint32) (eax, ebx, ecx, edx uint32) // implemented in cpuidlow_amd64.s
1010

11-
//VersionString returns the vendor ID
11+
// VersionString returns the vendor ID
1212
func (h HwAPI) VersionString() string {
1313
return cpuid.VendorIdentificatorString
1414
}
1515

16-
//HasSMX returns true if SMX is supported
16+
// HasSMX returns true if SMX is supported
1717
func (h HwAPI) HasSMX() bool {
1818
return cpuid.HasFeature(cpuid.SMX)
1919
}
2020

21-
//HasVMX returns true if VMX is supported
21+
// HasVMX returns true if VMX is supported
2222
func (h HwAPI) HasVMX() bool {
2323
return cpuid.HasFeature(cpuid.VMX)
2424
}
2525

26-
//HasMTRR returns true if MTRR are supported
26+
// HasMTRR returns true if MTRR are supported
2727
func (h HwAPI) HasMTRR() bool {
2828
return cpuid.HasFeature(cpuid.MTRR) || cpuid.HasExtraFeature(cpuid.MTRR_2)
2929
}
3030

31-
//ProcessorBrandName returns the CPU brand name
31+
// ProcessorBrandName returns the CPU brand name
3232
func (h HwAPI) ProcessorBrandName() string {
3333
return cpuid.ProcessorBrandString
3434
}
3535

36-
//CPUSignature returns CPUID=1 eax
36+
// CPUSignature returns CPUID=1 eax
3737
func (h HwAPI) CPUSignature() uint32 {
3838
eax, _, _, _ := h.CPUSignatureFull()
3939
return eax
4040
}
4141

42-
//CPUSignatureFull returns CPUID=1 eax, ebx, ecx, edx
42+
// CPUSignatureFull returns CPUID=1 eax, ebx, ecx, edx
4343
func (h HwAPI) CPUSignatureFull() (uint32, uint32, uint32, uint32) {
4444
return cpuidLow(1, 0)
4545
}
4646

47-
//CPULogCount returns number of logical CPU cores
47+
// CPULogCount returns number of logical CPU cores
4848
func (h HwAPI) CPULogCount() uint32 {
4949
return 0
50-
//return uint32(cpuid.MaxLogicalCPUId)
50+
// return uint32(cpuid.MaxLogicalCPUId)
51+
}
52+
53+
// CPUID executes the CPUID instruction with the given leaf (eax) and subleaf (ecx) values
54+
// Returns the resulting eax, ebx, ecx, and edx register values
55+
func (h HwAPI) CPUID(leaf, subleaf uint32) (eax, ebx, ecx, edx uint32) {
56+
return cpuidLow(leaf, subleaf)
5157
}

pkg/hwapi/cpuid_other.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,48 @@
44
// Package hwapi provides access to low level hardware
55
package hwapi
66

7-
//VersionString returns the vendor ID
7+
// VersionString returns the vendor ID
88
func (h HwAPI) VersionString() string {
99
return "null"
1010
}
1111

12-
//HasSMX returns true if SMX is supported
12+
// HasSMX returns true if SMX is supported
1313
func (h HwAPI) HasSMX() bool {
1414
return false
1515
}
1616

17-
//HasVMX returns true if VMX is supported
17+
// HasVMX returns true if VMX is supported
1818
func (h HwAPI) HasVMX() bool {
1919
return false
2020
}
2121

22-
//HasMTRR returns true if MTRR are supported
22+
// HasMTRR returns true if MTRR are supported
2323
func (h HwAPI) HasMTRR() bool {
2424
return false
2525
}
2626

27-
//ProcessorBrandName returns the CPU brand name
27+
// ProcessorBrandName returns the CPU brand name
2828
func (h HwAPI) ProcessorBrandName() string {
2929
return "not intel"
3030
}
3131

32-
//CPUSignature returns CPUID=1 eax
32+
// CPUSignature returns CPUID=1 eax
3333
func (h HwAPI) CPUSignature() uint32 {
3434
return 0
3535
}
3636

37-
//CPUSignatureFull returns CPUID=1 eax, ebx, ecx, edx
37+
// CPUSignatureFull returns CPUID=1 eax, ebx, ecx, edx
3838
func (h HwAPI) CPUSignatureFull() (uint32, uint32, uint32, uint32) {
3939
return 0, 0, 0, 0
4040
}
4141

42-
//CPULogCount returns number of logical CPU cores
42+
// CPULogCount returns number of logical CPU cores
4343
func (h HwAPI) CPULogCount() uint32 {
4444
return 0
4545
}
46+
47+
// CPUID executes the CPUID instruction with the given leaf (eax) and subleaf (ecx) values
48+
// Returns the resulting eax, ebx, ecx, and edx register values
49+
func (h HwAPI) CPUID(leaf, subleaf uint32) (eax, ebx, ecx, edx uint32) {
50+
return 0, 0, 0, 0
51+
}

0 commit comments

Comments
 (0)