CosmosOS / Cosmos

Cosmos is an operating system "construction kit". Build your own OS using managed languages such as C#, VB.NET, and more!
https://www.goCosmos.org
BSD 3-Clause "New" or "Revised" License
2.93k stars 554 forks source link

`CPU.GetCPUBrandString()` causes Cosmos CPU Exception despite `CPU.CanReadCPUID()` being a non-zero value #2716

Open jvyden opened 1 year ago

jvyden commented 1 year ago

Area of Cosmos - What area of Cosmos are we dealing with?

Cosmos' implementation of CPUID

Expected Behaviour - What do you think that should happen?

Cosmos returns the correct CPU brand string when invoking CPU.GetCPUBrandString().

Actual Behaviour - What unexpectedly happens?

A CPU Exception occurs, with an invalid opcode:

image

Reproduction - How did you get this error to appear?

A simple usage of the CPU brand function in BeforeRun, checking CanReadCPUID beforehand:


        Console.WriteLine("  Gathering SystemInformation");
        this._information = new SystemInformation
        {
            CPUVendor = CPU.GetCPUVendorName(),
            MemoryCountMegabytes = CPU.GetAmountOfRAM(),
        };

        Console.Write("  Checking if we can read CPUID... ");
        int canReadCpuIdResult = CPU.CanReadCPUID();
        bool canReadCpuId = canReadCpuIdResult != 0;
        Console.Write(canReadCpuId ? "Yes!" : "No.");
        Console.Write($" Result was {canReadCpuIdResult}.\n");

        if (canReadCpuId)
        {
            this._information.CPUBrand = CPU.GetCPUBrandString();
            this._information.EstimatedCycleSpeed = CPU.GetCPUCycleSpeed();
        }
        else
        {
            this._information.CPUBrand = "Unknown";
            this._information.EstimatedCycleSpeed = -1;
        }

Version - Were you using the User Kit or Dev Kit? And what User Kit version or Dev Kit commit (Cosmos, IL2CPU, X#)?

Dev Kit cd69dc2f4b6d8273d6476e3004bcdda7de55af88

QEMU emulator version 8.0.2

.NET SDK:
 Version:   7.0.304
 Commit:    7e794e2806

Runtime Environment:
 OS Name:     arch
 OS Version:  
 OS Platform: Linux
 RID:         arch-x64
 Base Path:   /usr/share/dotnet/sdk/7.0.304/

Host:
  Version:      7.0.7
  Architecture: x64
  Commit:       5b20af47d9

.NET SDKs installed:
  6.0.116 [/usr/share/dotnet/sdk]
  7.0.304 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.16 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.7 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Additional notes

ADev531 commented 2 days ago

Still happens on lastest devkit!