Cosmos.Core.CPU.GetCPUVendorName() returns weird string

Created on 18 Aug 2020  路  13Comments  路  Source: CosmosOS/Cosmos

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

Hardware Informaation

Expected Behaviour - What do you think that should happen?

Printing the hardware name. In this case: CPU

Actual Behaviour - What unexpectedly happens?

Weird String: "???u???l???l"
image

Reproduction - How did you get this error to appear?

Printing result of Cosmos.Core.CPU.GetCPUVendorName(); to console
Console.WriteLine(Cosmos.Core.CPU.GetCPUVendorName());

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

User Kit, version 20200708

Kernel Bug Medium Medium Up for Grabs

Most helpful comment

I will try to look further into this

All 13 comments

Could you get the individual chars in the string and cast them to bytes and post what you get?

Could you get the individual chars in the string and cast them to bytes and post what you get?

I have done what you have said and here's what I got:
71 101 110 117 105 110 101 73 110 116 101 108
Btw, that's all decimals
Do I have to convert back into hex ?

If you convert individual decimals to ASCII you get "GenuineIntel"

If you convert individual decimals to ASCII you get "GenuineIntel"

Indeed, with base 10. I think I should make a separate function for it.

Ok, so it seems somehow converting it to a string is the problem, what happens when you convert the individual chars into ints in Cosmos? My current hypothesis is that somehow the cast to char is not working correctly.

I looked in Cosmos's source code and found this:
internal static void ReadCPUID(uint type, ref int eax, ref int ebx, ref int ecx, ref int edx) => throw new NotImplementedException();

and

            if (CanReadCPUID() != 0)
            {
                int eax = 0;
                int ebx = 0;
                int ecx = 0;
                int edx = 0;
                ReadCPUID(0, ref eax, ref ebx, ref ecx, ref edx); // 0 is vendor name

                string s = "";
                s += (char)(ebx);
                s += (char)(ebx >> 8);
                s += (char)(ebx >> 16);
                s += (char)(ebx >> 24);
                s += (char)(edx);
                s += (char)(edx >> 8);
                s += (char)(edx >> 16);
                s += (char)(edx >> 24);
                s += (char)(ecx);
                s += (char)(ecx >> 8);
                s += (char)(ecx >> 16);
                s += (char)(ecx >> 24);

                return s;
            }

So I think it's not implemented

No the method work as expected and ReadCPUID is plugged, so the above throw new NotImplementedException is just a placeholder. I think the problem might be that (char)(ebx) etc might not be actually clearing the upper bits of the int, which would lead to the wrong values being stored for the string. Could you please check what the output is when you cast the char to int?

Nothing

Looks like some of the characters were being converted properly. ???u???I???l. Also here's a screenshot of mine:
authenticamdrendering
"AuthenticAMD"

Will adding [PlugMethod(PlugRequired = true)] above the function implementation help?

No, the function is working correctly, since when we convert the characters returned to bytes, we get the values expected. This means that either the writing of the string is broken (unlikely since otherwise there have been no problems with this) or that the values in the string are not actually correct above the lower byte (the higher bytes have some value) which would mean that the cast to char does not actually work (the higher bits (8-31) are not cleared). This is further confirmed by the fact that every 4th letter is displayed. I havnt had the time to confirm my suspision, and would appreciate if someone looked into this.

I will try to look further into this

@quajak You were right, I fixed it and I will open PR soon.
temp

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omerhijazi404 picture omerhijazi404  路  9Comments

365Tito picture 365Tito  路  10Comments

erikpro007 picture erikpro007  路  4Comments

fanoI picture fanoI  路  8Comments

365Tito picture 365Tito  路  11Comments