From 13d1bb5def5d0c663e98c655b1d410e4c3a6c299 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 | 10 ++++++++++ abi/cpuid_amd64.go | 10 ++++++++++ 3 files changed, 27 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..e6f7b8f --- /dev/null +++ b/abi/cpuid.go @@ -0,0 +1,10 @@ +//go:build !amd64 || gccgo +// +build !amd64 gccgo + +package abi + +func init() { + cpuid = func(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..c0e0297 --- /dev/null +++ b/abi/cpuid_amd64.go @@ -0,0 +1,10 @@ +//go:build amd64 && !gccgo +// +build amd64,!gccgo + +package abi + +func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32) + +func init() { + cpuid = asmCpuid +}