Add CPU features and fix CPU vendor #2

Kapalı
Ghost (silindi): prcb-cpu-features içindeki 5 işlemeyi master ile birleştirmek istiyor

Fixed CPU vendor name code which was bugged, and
Extracted CPU vendor name code to ArpSetCpuVendor

Added CPU features field onto CPU_IDENTIFICATION struct

Added few debugging utilities

Fixed CPU vendor name code which was bugged, and Extracted CPU vendor name code to `ArpSetCpuVendor` Added CPU features field onto `CPU_IDENTIFICATION` struct Added few debugging utilities
belliash 2023-11-21 20:09:39 +01:00 değişiklik istedi
@@ -187,0 +188,4 @@
typedef struct _CPU_FEATURES {
union {
struct {
unsigned int SSE3 : 1;
Sahibi

UINT, or maybe something smaller if just one bit used.

UINT, or maybe something smaller if just one bit used.

Using BYTE instead of unsigned int for the bitfield

Using BYTE instead of unsigned int for the bitfield
Ghost bu konuşmayı çözümlenmiş olarak işaretledi
@@ -138,0 +139,4 @@
typedef struct _CPU_FEATURES {
union {
struct {
unsigned int SSE3 : 1;
Sahibi

UINT, or maybe something smaller if just one bit used.

UINT, or maybe something smaller if just one bit used.

Using BYTE instead of unsigned int for the bitfield

Using BYTE instead of unsigned int for the bitfield
Ghost bu konuşmayı çözümlenmiş olarak işaretledi
@@ -152,6 +225,7 @@ typedef struct _CPU_IDENTIFICATION
USHORT Stepping;
CPU_VENDOR Vendor;
UCHAR VendorName[13];
CPU_FEATURES Features;
Sahibi

IMHO this should go to PROCESSOR_CONTROL_BLOCK.

IMHO this should go to PROCESSOR_CONTROL_BLOCK.

Moved to PROCESSOR_CONTROL_BLOCK

Moved to PROCESSOR_CONTROL_BLOCK
Ghost bu konuşmayı çözümlenmiş olarak işaretledi
@@ -21,9 +21,12 @@
#ifdef DBG
#define DEBUG 1
#define DebugPrint(Format, ...) if(KeDbgPrint) KeDbgPrint(Format, __VA_ARGS__);
#define DebugPrintSeparator() DebugPrint(L"===============================================================================\n");
Sahibi

Why need this? What would you like to separate?
Only debug messages are printed to serial console.

Why need this? What would you like to separate? Only debug messages are printed to serial console.

Just being fancy, but pretty much unnecessary.
Being removed now.

Just being fancy, but pretty much unnecessary. Being removed now.
Ghost bu konuşmayı çözümlenmiş olarak işaretledi
@@ -12,6 +12,7 @@ list(APPEND XTOSKRNL_SOURCE
${XTOSKRNL_SOURCE_DIR}/ar/${ARCH}/globals.c
${XTOSKRNL_SOURCE_DIR}/ar/${ARCH}/procsup.c
${XTOSKRNL_SOURCE_DIR}/ar/${ARCH}/traps.c
${XTOSKRNL_SOURCE_DIR}/ar/arcommon.c
Sahibi

AR is architecture specific library, so I believe it should not contain any common points. Especially, there are architectures different than x86.

AR is architecture specific library, so I believe it should not contain any common points. Especially, there are architectures different than x86.

Removed

Removed
Ghost bu konuşmayı çözümlenmiş olarak işaretledi
@@ -8,6 +8,11 @@
Sahibi

xtoskrnl/ar/i686/procsup.c missing in this PR

xtoskrnl/ar/i686/procsup.c missing in this PR

Implemented on i686

Implemented on i686
Ghost bu konuşmayı çözümlenmiş olarak işaretledi
@@ -9,2 +9,4 @@
#include <xtos.h>
#ifdef DEBUG
WCHAR VendorName[13];
Sahibi

All global variables should be placed in globals.c and globals.h

All global variables should be placed in globals.c and globals.h

Removed debug stuff

Removed debug stuff
Ghost bu konuşmayı çözümlenmiş olarak işaretledi
@@ -11,0 +12,4 @@
WCHAR VendorName[13];
#endif
extern const WCHAR ArCpuFeatureNames[64][16];
Sahibi

All global variables should be placed in globals.c and globals.h

All global variables should be placed in globals.c and globals.h

Removed debug stuff

Removed debug stuff
Ghost bu konuşmayı çözümlenmiş olarak işaretledi
@@ -110,0 +127,4 @@
*/
XTAPI
VOID
ArpSetCpuVendor(IN PKPROCESSOR_CONTROL_BLOCK Prcb,
Sahibi

Why this needs to be so over-complicated? It should be possible to simply store data read from EBX, EDX and ECX registers.

Why this needs to be so over-complicated? It should be possible to simply store data read from EBX, EDX and ECX registers.

Simplified

XTAPI
VOID ArpSetCpuVendor(IN PKPROCESSOR_CONTROL_BLOCK Prcb,
                     IN CPUID_REGISTERS CpuRegisters) 
{
    *((UINT32 *)(Prcb->CpuId.VendorName))     = CpuRegisters.Ebx;
    *((UINT32 *)(Prcb->CpuId.VendorName + 4)) = CpuRegisters.Edx;
    *((UINT32 *)(Prcb->CpuId.VendorName + 8)) = CpuRegisters.Ecx;
    Prcb->CpuId.VendorName[12]                = '\0';
}
Simplified ```c XTAPI VOID ArpSetCpuVendor(IN PKPROCESSOR_CONTROL_BLOCK Prcb, IN CPUID_REGISTERS CpuRegisters) { *((UINT32 *)(Prcb->CpuId.VendorName)) = CpuRegisters.Ebx; *((UINT32 *)(Prcb->CpuId.VendorName + 4)) = CpuRegisters.Edx; *((UINT32 *)(Prcb->CpuId.VendorName + 8)) = CpuRegisters.Ecx; Prcb->CpuId.VendorName[12] = '\0'; } ```
Ghost bu konuşmayı çözümlenmiş olarak işaretledi
@@ -123,8 +168,14 @@ ArpIdentifyProcessor(VOID)
CPUID_REGISTERS CpuRegisters;
CPUID_SIGNATURE CpuSignature;
#ifdef DEBUG
Sahibi

All these ifdef statements are completely useless, as DebugPrint on non-debug build is just a NOP.

All these `ifdef ` statements are completely useless, as DebugPrint on non-debug build is just a NOP.
Ghost bu konuşmayı çözümlenmiş olarak işaretledi
@@ -0,0 +1,25 @@
/**
Sahibi

AR is architecture specific library, so I believe it should not contain any common points. Especially, there are architectures different than x86 that might get supported in the future.

AR is architecture specific library, so I believe it should not contain any common points. Especially, there are architectures different than x86 that might get supported in the future.
Ghost bu konuşmayı çözümlenmiş olarak işaretledi
@@ -0,0 +9,4 @@
#include <xtos.h>
/* CPU feature names */
const WCHAR ArCpuFeatureNames[64][16] = {
Sahibi

What is this needed for?
This is a kernel and it needs information about CPU supported features, for example to check minimal requirements and panic if they are not met. They should be stored somewhere in PROCESSOR_CONTROL_BLOCK probably.

Why WCHAR (wide character) needs to be used here?

What is this needed for? This is a kernel and it needs information about CPU supported features, for example to check minimal requirements and panic if they are not met. They should be stored somewhere in PROCESSOR_CONTROL_BLOCK probably. Why WCHAR (wide character) needs to be used here?

These are actually debug messages. Stored there temporarily. Removed.

These are actually debug messages. Stored there temporarily. Removed.
Ghost bu konuşmayı çözümlenmiş olarak işaretledi
Ghost başlığı Add PRCB CPU features and fixes iken WIP: Add PRCB CPU features and fixes olarak 2023-11-21 22:37:38 +01:00 değiştirdi
Ghost başlığı WIP: Add PRCB CPU features and fixes iken Add PRCB CPU features and fixes olarak 2023-11-22 01:13:28 +01:00 değiştirdi
Ghost başlığı Add PRCB CPU features and fixes iken Add CPU features and fix CPU vendor olarak 2023-11-22 01:14:03 +01:00 değiştirdi
Ghost belliash tarafından 2023-11-22 17:11:16 +01:00 inceleme istedi
Ghost başlığı Add CPU features and fix CPU vendor iken WIP: Add CPU features and fix CPU vendor olarak 2023-11-23 16:34:48 +01:00 değiştirdi
Ghost prcb-cpu-features 9ae270c241 hedefinden a270c08dcf hedefine zorla gönderildi 2023-11-23 23:28:07 +01:00 Karşılaştır

Reopening a clean PR

Reopening a clean PR
Ghost 2023-11-23 23:28:46 +01:00 değişiklik isteğini kapattı
Ghost 2023-11-24 00:36:18 +01:00 değişiklik isteğini yeniden açtı
Ghost başlığı WIP: Add CPU features and fix CPU vendor iken Add CPU features and fix CPU vendor olarak 2023-11-24 00:36:23 +01:00 değiştirdi
Sahibi

Could you update your source branch to match the destination?

Could you update your source branch to match the destination?
Ghost 1 işlemeyi 2023-11-26 18:53:30 +01:00 ekledi
Ghost 1 işlemeyi 2023-11-27 19:12:11 +01:00 ekledi

Updated

Updated
belliash 2023-11-27 19:34:56 +01:00 değişiklik istedi
@@ -113,4 +117,3 @@
/* CPU vendor enumeration list */
typedef enum _CPU_VENDOR
{
CPU_VENDOR_AMD = 0x68747541,
Sahibi

Why do we change the values in CPU_VENDOR enum?

Why do we change the values in CPU_VENDOR enum?

The modifications were made to enhance code readability and maintainability, I specifically targeted removing magic numbers, and, to introduce a specific value (CPU_VENDOR_INVALID) to handle cases where the CPU vendor is in an invalid state.

The modifications were made to enhance code readability and maintainability, I specifically targeted removing magic numbers, and, to introduce a specific value (CPU_VENDOR_INVALID) to handle cases where the CPU vendor is in an invalid state.
Sahibi

That magic numbers have some meaning: HEX(68747541) = STR(Auth)

That magic numbers have some meaning: HEX(68747541) = STR(Auth)

I know. Why shouldn't we change the values in CPU_VENDOR enum?

I know. Why shouldn't we change the values in CPU_VENDOR enum?
@@ -187,0 +193,4 @@
typedef struct _CPU_FEATURES {
union {
struct {
BOOLEAN SSE3 : 1;
Sahibi

It is not guaranteed that enum has unsigned underlying type.

It is not guaranteed that enum has unsigned underlying type.

You pointed the struct in this case, was this a mis-comment?

You pointed the struct in this case, was this a mis-comment?
Sahibi

No, it's not a mistake. BOOLEAN is defined as enum.

No, it's not a mistake. BOOLEAN is defined as enum.
May we define `BOOLEAN as enum : BYTE`? https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types

Swapped all BOOLEAN on the structure with BYTE

Swapped all BOOLEAN on the structure with BYTE
@@ -187,0 +263,4 @@
BOOLEAN Reserved4 : 1; // Bit 30 is reserved
BOOLEAN PBE : 1;
};
UINT64 Features;
Sahibi

Any reason for using UINT64 here?

Any reason for using UINT64 here?

I've specifically added that to access the whole value AsUINT64, maybe it's unnecesary right now, but added it as a plus. I took some inspiration from this code, that does the same:
xtchain/binaries/x86_64-w64-mingw32/include/winhvplatformdefs.h:29
(look for typedef union WHV_CAPABILITY_FEATURES)

I've specifically added that to access the whole value AsUINT64, maybe it's unnecesary right now, but added it as a plus. I took some inspiration from this code, that does the same: xtchain/binaries/x86_64-w64-mingw32/include/winhvplatformdefs.h:29 (look for typedef union WHV_CAPABILITY_FEATURES)

Swapped all BOOLEAN on the structure with BYTE

Swapped all BOOLEAN on the structure with BYTE
@@ -64,4 +68,3 @@
/* CPU vendor enumeration list */
typedef enum _CPU_VENDOR
{
CPU_VENDOR_AMD = 0x68747541,
Sahibi

Why do we change the values in CPU_VENDOR enum?

Why do we change the values in CPU_VENDOR enum?

The modifications were made to enhance code readability and maintainability, I specifically targeted removing magic numbers, and, to introduce a specific value (CPU_VENDOR_INVALID) to handle cases where the CPU vendor is in an invalid state.

The modifications were made to enhance code readability and maintainability, I specifically targeted removing magic numbers, and, to introduce a specific value (CPU_VENDOR_INVALID) to handle cases where the CPU vendor is in an invalid state.
Sahibi

That magic numbers have some meaning, eg: HEX(68747541) = STR(Auth)

That magic numbers have some meaning, eg: HEX(68747541) = STR(Auth)

I know. Why shouldn't we change the values in CPU_VENDOR enum?

I know. Why shouldn't we change the values in CPU_VENDOR enum?
@@ -138,0 +144,4 @@
typedef struct _CPU_FEATURES {
union {
struct {
BOOLEAN SSE3 : 1;
Sahibi

It is not guaranteed that enum has unsigned underlying type.

It is not guaranteed that enum has unsigned underlying type.

You pointed the struct in this case, was this a mis-comment?

You pointed the struct in this case, was this a mis-comment?
@@ -138,0 +209,4 @@
BOOLEAN Reserved4 : 1; // Bit 30 is reserved
BOOLEAN PBE : 1;
};
UINT64 AsUINT64;
Sahibi

Any reason for using UINT64 here?

Any reason for using UINT64 here?

I've specifically added that to access the whole value AsUINT64, maybe it's unnecesary right now, but added it as a plus. I took some inspiration from this code, that does the same:
xtchain/binaries/x86_64-w64-mingw32/include/winhvplatformdefs.h:29
(look for typedef union WHV_CAPABILITY_FEATURES)

I've specifically added that to access the whole value `AsUINT64`, maybe it's unnecesary right now, but added it as a plus. I took some inspiration from this code, that does the same: xtchain/binaries/x86_64-w64-mingw32/include/winhvplatformdefs.h:29 (look for `typedef union WHV_CAPABILITY_FEATURES`)
Sahibi

I didn't notice the difference between i686 and amd64. In one case it is a structure containing 2 unions. Here we got 1 bit structure. Does it mean, that CPUID returns different data across archs?

I didn't notice the difference between i686 and amd64. In one case it is a structure containing 2 unions. Here we got 1 bit structure. Does it mean, that CPUID returns different data across archs?

This is a small regression on local commits, I'll push the final structure.

This is a small regression on local commits, I'll push the final structure.

Fixed on last commit.

Fixed on last commit.
@@ -154,3 +186,3 @@
/* CPU vendor specific quirks */
if(Prcb->CpuId.Vendor == CPU_VENDOR_AMD)
if (Prcb->CpuId.Vendor == CPU_VENDOR_AMD)
Sahibi

Please don't mix code changes with formatting.

Please don't mix code changes with formatting.

Do you expect to just copy and paste the code from one side to another without giving it proper format? Notice it's placed on another function (Diff does not help here)

Do you expect to just copy and paste the code from one side to another without giving it proper format? Notice it's placed on another function (Diff does not help here)
Sahibi

It does not look like copied from one place into another. There is additional space between if and parenthesis. If it gets removed, git won't see any change in this place.

It is placed in another function, because ArpIdentifyProcessor() got divided.

It does not look like copied from one place into another. There is additional space between if and parenthesis. If it gets removed, git won't see any change in this place. It is placed in another function, because ArpIdentifyProcessor() got divided.

In the process of moving the code from ArpIdentifyProcessor to ArpSetCpuVendor I formatted the whole function, as it makes sense to tidy up and reformat the function I've touched.

In the process of moving the code from `ArpIdentifyProcessor` to `ArpSetCpuVendor` I formatted the whole function, as it makes sense to tidy up and reformat the function I've touched.
@@ -163,3 +199,3 @@
{
/* Intel CPU */
if(Prcb->CpuId.Family == 0xF)
if (Prcb->CpuId.Family == 0xF)
Sahibi

Please don't mix code changes with formatting.

Please don't mix code changes with formatting.

Do you expect to just copy and paste the code from one side to another without giving it proper format? Notice it's placed on another function (Diff does not help here)

Do you expect to just copy and paste the code from one side to another without giving it proper format? Notice it's placed on another function (Diff does not help here)
Sahibi

It does not look like copied from one place into another. There is additional space between if and parenthesis. If it gets removed, git won't see any change in this place.

It is placed in another function, because ArpIdentifyProcessor() got divided.

It does not look like copied from one place into another. There is additional space between if and parenthesis. If it gets removed, git won't see any change in this place. It is placed in another function, because ArpIdentifyProcessor() got divided.

In the process of moving the code from ArpIdentifyProcessor to ArpSetCpuVendor I formatted the whole function, as it makes sense to tidy up and reformat the function I've touched.

In the process of moving the code from `ArpIdentifyProcessor` to `ArpSetCpuVendor` I formatted the whole function, as it makes sense to tidy up and reformat the function I've touched.
Ghost 1 işlemeyi 2023-11-27 22:06:49 +01:00 ekledi
Ghost 2023-11-27 22:51:01 +01:00 değişiklik isteğini kapattı

Değişiklik isteği kapatıldı

Bu konuşmaya katılmak için oturum aç.