Implement HlCpuId() routine and corresponding structures for issueing CPUID instruction

This commit is contained in:
2022-12-11 17:40:56 +01:00
parent 2b679c11d4
commit 324a88cc01
9 changed files with 340 additions and 89 deletions

View File

@@ -9,6 +9,48 @@
#include "xtkmapi.h"
/**
* Retrieves a various amount of information about the CPU.
*
* @param Registers
* Supplies a pointer to the structure containing all the necessary registers and leafs for CPUID.
*
* @return TRUE if CPUID function could be executed, FALSE otherwise.
*
* @since XT 1.0
*/
XTAPI
BOOLEAN
HlCpuId(IN OUT PCPUID_REGISTERS Registers)
{
UINT32 MaxLeaf;
/* Get highest function ID available */
asm volatile("cpuid"
: "=a" (MaxLeaf)
: "a" (Registers->Leaf & 0x80000000)
: "rbx", "rcx", "rdx");
/* Check if CPU supports this command */
if(Registers->Leaf > MaxLeaf)
{
/* Cannot call it, return FALSE */
return FALSE;
}
/* Execute CPUID function */
asm volatile("cpuid"
: "=a" (Registers->Eax),
"=b" (Registers->Ebx),
"=c" (Registers->Ecx),
"=d" (Registers->Edx)
: "a" (Registers->Leaf),
"c" (Registers->SubLeaf));
/* Return TRUE */
return TRUE;
}
/**
* Reads the data from the specified I/O port.
*
@@ -50,8 +92,7 @@ HlIoPortOutByte(IN USHORT Port,
{
asm volatile("outb %0, %1"
:
:
"a"(Value),
: "a"(Value),
"Nd"(Port));
}
@@ -68,12 +109,9 @@ HlReadCR0()
{
ULONG_PTR Value;
asm volatile("mov %%cr0, %0"
: "=r" (Value)
:
"=r"
(Value)
:
:
"memory");
: "memory");
return Value;
}
@@ -90,12 +128,9 @@ HlReadCR2()
{
ULONG_PTR Value;
asm volatile("mov %%cr2, %0"
: "=r" (Value)
:
"=r"
(Value)
:
:
"memory");
: "memory");
return Value;
}
@@ -112,12 +147,9 @@ HlReadCR3()
{
ULONG_PTR Value;
asm volatile("mov %%cr3, %0"
: "=r" (Value)
:
"=r"
(Value)
:
:
"memory");
: "memory");
return Value;
}
@@ -134,12 +166,9 @@ HlReadCR4()
{
ULONG_PTR Value;
asm volatile("mov %%cr4, %0"
: "=r" (Value)
:
"=r"
(Value)
:
:
"memory");
: "memory");
return Value;
}
@@ -156,12 +185,9 @@ HlReadCR8()
{
ULONG_PTR Value;
asm volatile("mov %%cr8, %0"
: "=r" (Value)
:
"=r"
(Value)
:
:
"memory");
: "memory");
return Value;
}
@@ -181,10 +207,8 @@ HlWriteCR0(UINT_PTR Data)
{
asm volatile("mov %0, %%cr0"
:
:
"r"(Data)
:
"memory");
: "r"(Data)
: "memory");
}
/**
@@ -203,10 +227,8 @@ HlWriteCR2(UINT_PTR Data)
{
asm volatile("mov %0, %%cr2"
:
:
"r"(Data)
:
"memory");
: "r"(Data)
: "memory");
}
/**
@@ -225,10 +247,8 @@ HlWriteCR3(UINT_PTR Data)
{
asm volatile("mov %0, %%cr3"
:
:
"r"(Data)
:
"memory");
: "r"(Data)
: "memory");
}
/**
@@ -247,10 +267,8 @@ HlWriteCR4(UINT_PTR Data)
{
asm volatile("mov %0, %%cr4"
:
:
"r"(Data)
:
"memory");
: "r"(Data)
: "memory");
}
/**
@@ -269,8 +287,6 @@ HlWriteCR8(UINT_PTR Data)
{
asm volatile("mov %0, %%cr8"
:
:
"r"(Data)
:
"memory");
: "r"(Data)
: "memory");
}