From 030b7616f7ffa0b549745f4a4ef6da653284b8ae Mon Sep 17 00:00:00 2001 From: Laisky Date: Thu, 21 Sep 2023 01:18:41 +0000 Subject: [PATCH] fix: make cpuid compatable with various architectures - Added new files `abi/cpuid_amd64.go` and `abi/cpuid.go` - Implemented the `asmCpuid` function in the `abi` package - Added tests for the `cpuid` function in `abi/abi_test.go` --- abi/abi_test.go | 7 +++++++ abi/cpuid.go | 8 ++++++++ abi/cpuid_amd64.go | 9 +++++++++ 3 files changed, 24 insertions(+) create mode 100644 abi/cpuid.go create mode 100644 abi/cpuid_amd64.go diff --git a/abi/abi_test.go b/abi/abi_test.go index aecdb64..10004d6 100644 --- a/abi/abi_test.go +++ b/abi/abi_test.go @@ -208,3 +208,10 @@ func TestSnpPlatformInfo(t *testing.T) { } } } + +func TestCpuid(t *testing.T) { + a, b, c, d := cpuid(1) + if (a | b | c | d) == 0 { + t.Errorf("cpuid(1) = 0, 0, 0, 0") + } +} diff --git a/abi/cpuid.go b/abi/cpuid.go new file mode 100644 index 0000000..6f4cd62 --- /dev/null +++ b/abi/cpuid.go @@ -0,0 +1,8 @@ +//go:build !amd64 || gccgo + +package abi + +// cpuid only works on amd64 +func cpuid(op uint32) (eax, ebx, ecx, edx uint32) { + return 0, 0, 0, 0 +} diff --git a/abi/cpuid_amd64.go b/abi/cpuid_amd64.go new file mode 100644 index 0000000..8f7ee25 --- /dev/null +++ b/abi/cpuid_amd64.go @@ -0,0 +1,9 @@ +//go:build amd64 || !gccgo + +package abi + +func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32) + +func init() { + cpuid = asmCpuid +}