Skip to content

Commit

Permalink
fix: make cpuid compatable with various architectures
Browse files Browse the repository at this point in the history
- 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`
  • Loading branch information
Laisky committed Sep 21, 2023
1 parent a6bdd4c commit 030b761
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
8 changes: 8 additions & 0 deletions abi/cpuid.go
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions abi/cpuid_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build amd64 || !gccgo

package abi

func asmCpuid(op uint32) (eax, ebx, ecx, edx uint32)

func init() {
cpuid = asmCpuid
}

0 comments on commit 030b761

Please sign in to comment.