bobuhiro11 / gokvm

KVM based tiny x86 hypervisor written in pure golang, which can boot Linux
https://blog.bobuhiro11.net/tags/gokvm.html
MIT License
206 stars 21 forks source link

Add package CPUID #158

Closed ChriMarMe closed 1 year ago

ChriMarMe commented 1 year ago

Add package CPUID for handling requests of CPUID of the host system and providing a mechanism to patch vCPU CPUIDs

ChriMarMe commented 1 year ago

Thanks for separating the PR. We need a test like this.

$ cat cpuid/cpuid_test.go
package cpuid_test

import (
        "testing"

        "github.com/bobuhiro11/gokvm/cpuid"
)

func TestCPUID(t *testing.T) {
        eax, ebx, ecx, edx := cpuid.CPUID(0)

        t.Logf("eax:0x%x ebx:0x%x ecx:0x%x edx:0x%x",
                eax, ebx, ecx, edx)

        s := []rune{}
        for _, x := range []uint32{ebx, edx, ecx} {
                s = append(s, rune(x>>0)&0xff)
                s = append(s, rune(x>>8)&0xff)
                s = append(s, rune(x>>16)&0xff)
                s = append(s, rune(x>>24)&0xff)
        }

        if string(s) != "GenuineIntel" && string(s) != "AuthenticAMD" {
                t.Fatalf("Unknown CPU vender found: %s", string(s))
        }
}

Added the test as well.