Fixed some errors.

This commit is contained in:
Arron David Nelson 2023-10-26 23:38:54 -07:00
parent 3c993d7d69
commit 2c1c9f6a57
4 changed files with 507 additions and 651 deletions

View File

@ -7,13 +7,13 @@ set(IS_OS_MAC FALSE)
if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
set(IS_OS_WINDOWS TRUE) set(IS_OS_WINDOWS TRUE)
message("Building for the Windows operating system.") message("Building on the Windows operating system.")
elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux") elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
set(IS_OS_LINUX TRUE) set(IS_OS_LINUX TRUE)
message("Building for the Linux operating system.") message("Building on the Linux operating system.")
elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin") elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
set(IS_OS_MAC TRUE) set(IS_OS_MAC TRUE)
message("Building for the Mac operating system.") message("Building on the Mac operating system.")
endif () endif ()
# Source files # Source files
@ -73,7 +73,7 @@ set(KERNEL_SOURCE_FILES
set(UTIL_SOURCE_FILES set(UTIL_SOURCE_FILES
src/EHS.h src/EHS.h
src/sys/cpu.h src/sys/cpu.cpp src/sys/CPU_GCC_AMD64.asm src/sys/CPU.h src/sys/CPU.cpp src/sys/CPU_GCC_AMD64.asm
src/Util.h src/Util.cpp src/Util.h src/Util.cpp
src/Version.h src/Version.cpp src/Version.h src/Version.cpp
src/Serializer.h src/Serializer.h
@ -95,13 +95,13 @@ set(UTIL_SOURCE_FILES
src/Mat4.h src/Mat4.h
src/Mat3.h src/Mat3.h
src/Mat2.h src/Mat2.h
) )
add_executable(ClassicOS add_executable(ClassicOS
${GRUB_SOURCE_FILES} ${GRUB_SOURCE_FILES}
${DRIVERS_SOURCE_FILES} ${DRIVERS_SOURCE_FILES}
${KERNEL_SOURCE_FILES} ${KERNEL_SOURCE_FILES}
${UTIL_SOURCE_FILES}
) )
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@ -115,6 +115,7 @@ target_link_libraries(ClassicOS PRIVATE)
set(CMAKE_SYSTEM_PROCESSOR i386) set(CMAKE_SYSTEM_PROCESSOR i386)
set(CMAKE_SYSTEM_NAME None) set(CMAKE_SYSTEM_NAME None)
set(CMAKE_C_STANDARD 17) set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(CMAKE_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build) set(CMAKE_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)

View File

@ -2,96 +2,93 @@
#include "Math.h" #include "Math.h"
Color4::Color4()
: r(0.0f), g(0.0f), b(0.0f), a(1.0f)
{ {
Color4::Color4() }
: r(0.0f), g(0.0f), b(0.0f), a(1.0f)
{
}
Color4::Color4(const float scalar, const float a) Color4::Color4(const float scalar, const float a)
: r(Math::Clamp(scalar, 0.0f, 1.0f)), g(Math::Clamp(scalar, 0.0f, 1.0f)), b(Math::Clamp(scalar, 0.0f, 1.0f)), a(a) : r(Math::Clamp(scalar, 0.0f, 1.0f)), g(Math::Clamp(scalar, 0.0f, 1.0f)), b(Math::Clamp(scalar, 0.0f, 1.0f)), a(a)
{ {
} }
Color4::Color4(const float r, const float g, const float b, const float a) Color4::Color4(const float r, const float g, const float b, const float a)
: r(Math::Clamp(r, 0.0f, 1.0f)), g(Math::Clamp(g, 0.0f, 1.0f)), b(Math::Clamp(b, 0.0f, 1.0f)), a(Math::Clamp(a, 0.0f, 1.0f)) : r(Math::Clamp(r, 0.0f, 1.0f)), g(Math::Clamp(g, 0.0f, 1.0f)), b(Math::Clamp(b, 0.0f, 1.0f)), a(Math::Clamp(a, 0.0f, 1.0f))
{ {
} }
Color4::Color4(const Color4& color) Color4::Color4(const Color4& color)
: r(color.r), g(color.g), b(color.b), a(color.a) : r(color.r), g(color.g), b(color.b), a(color.a)
{ {
} }
Color4& Color4::operator=(const Color4& color)
{
if (this == &color)
return *this;
r = color.r;
g = color.g;
b = color.b;
a = color.a;
return *this;
}
bool Color4::operator==(const Color4& color) const
{
return r == color.r && g == color.g && b == color.b && a == color.a;
}
bool Color4::operator!=(const Color4& color) const
{
return r != color.r || g != color.g || b != color.b || a != color.a;
}
float Color4::operator[](const UInt_64 i) const
{
switch (i)
{
case 0:
return r;
case 1:
return g;
case 2:
return b;
case 3:
return a;
default:
return r;
}
}
float& Color4::operator[](const UInt_64 i)
{
switch (i)
{
case 0:
return r;
case 1:
return g;
case 2:
return b;
case 3:
return a;
default:
return r;
}
}
Color4& Color4::operator*=(const Color4& color)
{
r *= color.r;
g *= color.g;
b *= color.b;
Color4& Color4::operator=(const Color4& color)
{
if (this == &color)
return *this; return *this;
}
Color4 Color4::operator*(const Color4& color) const r = color.r;
g = color.g;
b = color.b;
a = color.a;
return *this;
}
bool Color4::operator==(const Color4& color) const
{
return r == color.r && g == color.g && b == color.b && a == color.a;
}
bool Color4::operator!=(const Color4& color) const
{
return r != color.r || g != color.g || b != color.b || a != color.a;
}
float Color4::operator[](const UInt_64 i) const
{
switch (i)
{ {
return {r * color.r, g * color.g, b * color.b, a}; case 0:
return r;
case 1:
return g;
case 2:
return b;
case 3:
return a;
default:
return r;
} }
}
float& Color4::operator[](const UInt_64 i)
{
switch (i)
{
case 0:
return r;
case 1:
return g;
case 2:
return b;
case 3:
return a;
default:
return r;
}
}
Color4& Color4::operator*=(const Color4& color)
{
r *= color.r;
g *= color.g;
b *= color.b;
return *this;
}
Color4 Color4::operator*(const Color4& color) const
{
return {r * color.r, g * color.g, b * color.b, a};
} }

View File

@ -1,562 +1,432 @@
#include "CPU.h" #include "CPU.h"
#include "../Log.h" Architecture CPU::GetArchitecture()
#include "../IO/File.h"
#include "../Json/Json.h"
#include "Thread.h"
{ {
#ifdef OS_LINUX #if defined(ARCH_X64)
UInt_64 CPU::TSC_Freq = 0; return Architecture::X64;
#endif #elif defined(ARCH_ARM64)
return Architecture::ARM64;
#else
return Architecture::UNKNOWN;
#endif
}
Architecture CPU::GetArchitecture() UInt_8 CPU::PointerSize()
{ {
#if defined(ARCH_X64) return sizeof(void*);
return Architecture::X64; }
#elif defined(ARCH_ARM64)
return Architecture::ARM64;
#else
return Architecture::UNKNOWN;
#endif
}
UInt_8 CPU::PointerSize() Endianness CPU::GetEndianness()
{ {
return sizeof(void*); #if defined(LITTLE_ENDIAN)
} return Endianness::LE;
#elif defined(BIG_ENDIAN)
return Endianness::BE;
#else
UInt_16 tmp = 1;
if (((Byte*)&tmp)[0] == 1)
return Endianness::LE;
Endianness CPU::GetEndianness() return Endianness::BE;
{ #endif
#if defined(LITTLE_ENDIAN) }
return Endianness::LE;
#elif defined(BIG_ENDIAN)
return Endianness::BE;
#else
UInt_16 tmp = 1;
if (((Byte*)&tmp)[0] == 1)
return Endianness::LE;
return Endianness::BE; UInt_64 CPU::GetTSC()
#endif {
} TSC tsc;
RDTSCP(&tsc);
UInt_64 CPU::GetTSC_Freq() #if defined(ARCH_X64)
{ UInt_64 result = 0;
#if defined(OS_WINDOWS)
LARGE_INTEGER frequency = {};
QueryPerformanceFrequency(&frequency);
return frequency.QuadPart; #if defined(LITTLE_ENDIAN)
#elif defined(OS_LINUX) ((UInt_32*)&result)[0] = tsc.lowCount;
if (!TSC_Freq) ((UInt_32*)&result)[1] = tsc.highCount;
TSC_Freq = RetrieveTSC_Freq(); #elif defined(BIG_ENDIAN)
((UInt_32*)&result)[0] = tsc.highCount;
return TSC_Freq; ((UInt_32*)&result)[1] = tsc.lowCount;
#endif #endif
return 0; return result;
} #elif defined(ARCH_X86)
return tsc.lowPart;
UInt_64 CPU::GetTSC() #endif
{
#if defined(OS_WINDOWS) return 0;
LARGE_INTEGER count = {}; }
QueryPerformanceCounter(&count);
UInt_8 CPU::GetSteppingId()
return count.QuadPart; {
#elif defined(OS_LINUX) return (UInt_8)GetInfoBits() & 0x00001111;
TSC tsc; }
RDTSCP(&tsc);
UInt_8 CPU::GetModelId()
#if defined(ARCH_X64) {
UInt_64 result = 0; return (UInt_8)GetInfoBits() & 0x11110000;
}
#if defined(LITTLE_ENDIAN)
((UInt_32*)&result)[0] = tsc.lowCount; UInt_8 CPU::GetFamilyId()
((UInt_32*)&result)[1] = tsc.highCount; {
#elif defined(BIG_ENDIAN) return (UInt_8)(GetInfoBits() >> 8) & 0x00001111;
((UInt_32*)&result)[0] = tsc.highCount; }
((UInt_32*)&result)[1] = tsc.lowCount;
#endif UInt_8 CPU::GetProcessorTypeId()
{
return result; return (UInt_8)(GetInfoBits() >> 12) & 0x00000011;
#elif defined(ARCH_X86) }
return tsc.lowPart;
#endif UInt_8 CPU::GetExtModelId()
#endif {
return (UInt_8)(GetInfoBits() >> 16) & 0x00001111;
return 0; }
}
UInt_8 CPU::GetExtFamilyId()
UInt_8 CPU::GetSteppingId() {
{ return (UInt_8)(GetInfoBits() >> 20);
return (UInt_8)GetInfoBits() & 0x00001111; }
}
bool CPU::HasFPU()
UInt_8 CPU::GetModelId() {
{ return GetFeatureBits_1() & 0b00000000000000000000000000000001;
return (UInt_8)GetInfoBits() & 0x11110000; }
}
bool CPU::HasVME()
UInt_8 CPU::GetFamilyId() {
{ return GetFeatureBits_1() & 0b00000000000000000000000000000010;
return (UInt_8)(GetInfoBits() >> 8) & 0x00001111; }
}
bool CPU::HasDE()
UInt_8 CPU::GetProcessorTypeId() {
{ return GetFeatureBits_1() & 0b00000000000000000000000000000100;
return (UInt_8)(GetInfoBits() >> 12) & 0x00000011; }
}
bool CPU::HasPSE()
UInt_8 CPU::GetExtModelId() {
{ return GetFeatureBits_1() & 0b00000000000000000000000000001000;
return (UInt_8)(GetInfoBits() >> 16) & 0x00001111; }
}
bool CPU::HasTSC()
UInt_8 CPU::GetExtFamilyId() {
{ return GetFeatureBits_1() & 0b00000000000000000000000000010000;
return (UInt_8)(GetInfoBits() >> 20); }
}
bool CPU::HasMSR()
bool CPU::HasFPU() {
{ return GetFeatureBits_1() & 0b00000000000000000000000000100000;
return GetFeatureBits_1() & 0b00000000000000000000000000000001; }
}
bool CPU::HasPAE()
bool CPU::HasVME() {
{ return GetFeatureBits_1() & 0b00000000000000000000000001000000;
return GetFeatureBits_1() & 0b00000000000000000000000000000010; }
}
bool CPU::HasMCE()
bool CPU::HasDE() {
{ return GetFeatureBits_1() & 0b00000000000000000000000010000000;
return GetFeatureBits_1() & 0b00000000000000000000000000000100; }
}
bool CPU::HasCX8()
bool CPU::HasPSE() {
{ return GetFeatureBits_1() & 0b00000000000000000000000100000000;
return GetFeatureBits_1() & 0b00000000000000000000000000001000; }
}
bool CPU::HasAPIC()
bool CPU::HasTSC() {
{ return GetFeatureBits_1() & 0b00000000000000000000001000000000;
return GetFeatureBits_1() & 0b00000000000000000000000000010000; }
}
bool CPU::HasSEP()
bool CPU::HasMSR() {
{ return GetFeatureBits_1() & 0b00000000000000000000100000000000;
return GetFeatureBits_1() & 0b00000000000000000000000000100000; }
}
bool CPU::HasMTRR()
bool CPU::HasPAE() {
{ return GetFeatureBits_1() & 0b00000000000000000001000000000000;
return GetFeatureBits_1() & 0b00000000000000000000000001000000; }
}
bool CPU::HasPGE()
bool CPU::HasMCE() {
{ return GetFeatureBits_1() & 0b00000000000000000010000000000000;
return GetFeatureBits_1() & 0b00000000000000000000000010000000; }
}
bool CPU::HasMCA()
bool CPU::HasCX8() {
{ return GetFeatureBits_1() & 0b00000000000000000100000000000000;
return GetFeatureBits_1() & 0b00000000000000000000000100000000; }
}
bool CPU::HasCMOV()
bool CPU::HasAPIC() {
{ return GetFeatureBits_1() & 0b00000000000000001000000000000000;
return GetFeatureBits_1() & 0b00000000000000000000001000000000; }
}
bool CPU::HasPAT()
bool CPU::HasSEP() {
{ return GetFeatureBits_1() & 0b00000000000000010000000000000000;
return GetFeatureBits_1() & 0b00000000000000000000100000000000; }
}
bool CPU::HasPSE_36()
bool CPU::HasMTRR() {
{ return GetFeatureBits_1() & 0b00000000000000100000000000000000;
return GetFeatureBits_1() & 0b00000000000000000001000000000000; }
}
bool CPU::HasPSN()
bool CPU::HasPGE() {
{ return GetFeatureBits_1() & 0b00000000000001000000000000000000;
return GetFeatureBits_1() & 0b00000000000000000010000000000000; }
}
bool CPU::HasCLFSH()
bool CPU::HasMCA() {
{ return GetFeatureBits_1() & 0b00000000000010000000000000000000;
return GetFeatureBits_1() & 0b00000000000000000100000000000000; }
}
bool CPU::HasDS()
bool CPU::HasCMOV() {
{ return GetFeatureBits_1() & 0b00000000001000000000000000000000;
return GetFeatureBits_1() & 0b00000000000000001000000000000000; }
}
bool CPU::HasACPI()
bool CPU::HasPAT() {
{ return GetFeatureBits_1() & 0b00000000010000000000000000000000;
return GetFeatureBits_1() & 0b00000000000000010000000000000000; }
}
bool CPU::HasMMX()
bool CPU::HasPSE_36() {
{ return GetFeatureBits_1() & 0b00000000100000000000000000000000;
return GetFeatureBits_1() & 0b00000000000000100000000000000000; }
}
bool CPU::HasFXSR()
bool CPU::HasPSN() {
{ return GetFeatureBits_1() & 0b00000001000000000000000000000000;
return GetFeatureBits_1() & 0b00000000000001000000000000000000; }
}
bool CPU::HasSSE()
bool CPU::HasCLFSH() {
{ return GetFeatureBits_1() & 0b00000010000000000000000000000000;
return GetFeatureBits_1() & 0b00000000000010000000000000000000; }
}
bool CPU::HasSSE2()
bool CPU::HasDS() {
{ return GetFeatureBits_1() & 0b00000100000000000000000000000000;
return GetFeatureBits_1() & 0b00000000001000000000000000000000; }
}
bool CPU::HasSS()
bool CPU::HasACPI() {
{ return GetFeatureBits_1() & 0b00001000000000000000000000000000;
return GetFeatureBits_1() & 0b00000000010000000000000000000000; }
}
bool CPU::HasHTT()
bool CPU::HasMMX() {
{ return GetFeatureBits_1() & 0b00010000000000000000000000000000;
return GetFeatureBits_1() & 0b00000000100000000000000000000000; }
}
bool CPU::HasTM()
bool CPU::HasFXSR() {
{ return GetFeatureBits_1() & 0b00100000000000000000000000000000;
return GetFeatureBits_1() & 0b00000001000000000000000000000000; }
}
bool CPU::HasIA64()
bool CPU::HasSSE() {
{ return GetFeatureBits_1() & 0b01000000000000000000000000000000;
return GetFeatureBits_1() & 0b00000010000000000000000000000000; }
}
bool CPU::HasPBE()
bool CPU::HasSSE2() {
{ return GetFeatureBits_1() & 0b10000000000000000000000000000000;
return GetFeatureBits_1() & 0b00000100000000000000000000000000; }
}
bool CPU::HasSSE3()
bool CPU::HasSS() {
{ return GetFeatureBits_2() & 0b00000000000000000000000000000001;
return GetFeatureBits_1() & 0b00001000000000000000000000000000; }
}
bool CPU::HasPCLMULQDQ()
bool CPU::HasHTT() {
{ return GetFeatureBits_2() & 0b00000000000000000000000000000010;
return GetFeatureBits_1() & 0b00010000000000000000000000000000; }
}
bool CPU::HasDTES64()
bool CPU::HasTM() {
{ return GetFeatureBits_2() & 0b00000000000000000000000000000100;
return GetFeatureBits_1() & 0b00100000000000000000000000000000; }
}
bool CPU::HasMONITOR()
bool CPU::HasIA64() {
{ return GetFeatureBits_2() & 0b00000000000000000000000000001000;
return GetFeatureBits_1() & 0b01000000000000000000000000000000; }
}
bool CPU::HasDS_CPL()
bool CPU::HasPBE() {
{ return GetFeatureBits_2() & 0b00000000000000000000000000010000;
return GetFeatureBits_1() & 0b10000000000000000000000000000000; }
}
bool CPU::HasVMX()
bool CPU::HasSSE3() {
{ return GetFeatureBits_2() & 0b00000000000000000000000000100000;
return GetFeatureBits_2() & 0b00000000000000000000000000000001; }
}
bool CPU::HasSMX()
bool CPU::HasPCLMULQDQ() {
{ return GetFeatureBits_2() & 0b00000000000000000000000001000000;
return GetFeatureBits_2() & 0b00000000000000000000000000000010; }
}
bool CPU::HasEST()
bool CPU::HasDTES64() {
{ return GetFeatureBits_2() & 0b00000000000000000000000010000000;
return GetFeatureBits_2() & 0b00000000000000000000000000000100; }
}
bool CPU::HasTM2()
bool CPU::HasMONITOR() {
{ return GetFeatureBits_2() & 0b00000000000000000000000100000000;
return GetFeatureBits_2() & 0b00000000000000000000000000001000; }
}
bool CPU::HasSSSE3()
bool CPU::HasDS_CPL() {
{ return GetFeatureBits_2() & 0b00000000000000000000001000000000;
return GetFeatureBits_2() & 0b00000000000000000000000000010000; }
}
bool CPU::HasCNXT_ID()
bool CPU::HasVMX() {
{ return GetFeatureBits_2() & 0b00000000000000000000010000000000;
return GetFeatureBits_2() & 0b00000000000000000000000000100000; }
}
bool CPU::HasSDBG()
bool CPU::HasSMX() {
{ return GetFeatureBits_2() & 0b00000000000000000000100000000000;
return GetFeatureBits_2() & 0b00000000000000000000000001000000; }
}
bool CPU::HasFMA()
bool CPU::HasEST() {
{ return GetFeatureBits_2() & 0b00000000000000000001000000000000;
return GetFeatureBits_2() & 0b00000000000000000000000010000000; }
}
bool CPU::HasCX16()
bool CPU::HasTM2() {
{ return GetFeatureBits_2() & 0b00000000000000000010000000000000;
return GetFeatureBits_2() & 0b00000000000000000000000100000000; }
}
bool CPU::HasXTPR()
bool CPU::HasSSSE3() {
{ return GetFeatureBits_2() & 0b00000000000000000100000000000000;
return GetFeatureBits_2() & 0b00000000000000000000001000000000; }
}
bool CPU::HasPDCM()
bool CPU::HasCNXT_ID() {
{ return GetFeatureBits_2() & 0b00000000000000001000000000000000;
return GetFeatureBits_2() & 0b00000000000000000000010000000000; }
}
bool CPU::HasPCID()
bool CPU::HasSDBG() {
{ return GetFeatureBits_2() & 0b00000000000000100000000000000000;
return GetFeatureBits_2() & 0b00000000000000000000100000000000; }
}
bool CPU::HasDCA()
bool CPU::HasFMA() {
{ return GetFeatureBits_2() & 0b00000000000001000000000000000000;
return GetFeatureBits_2() & 0b00000000000000000001000000000000; }
}
bool CPU::HasSSE4_1()
bool CPU::HasCX16() {
{ return GetFeatureBits_2() & 0b00000000000010000000000000000000;
return GetFeatureBits_2() & 0b00000000000000000010000000000000; }
}
bool CPU::HasSSE4_2()
bool CPU::HasXTPR() {
{ return GetFeatureBits_2() & 0b00000000000100000000000000000000;
return GetFeatureBits_2() & 0b00000000000000000100000000000000; }
}
bool CPU::HasX2APIC()
bool CPU::HasPDCM() {
{ return GetFeatureBits_2() & 0b00000000001000000000000000000000;
return GetFeatureBits_2() & 0b00000000000000001000000000000000; }
}
bool CPU::HasMOVBE()
bool CPU::HasPCID() {
{ return GetFeatureBits_2() & 0b00000000010000000000000000000000;
return GetFeatureBits_2() & 0b00000000000000100000000000000000; }
}
bool CPU::HasPOPCNT()
bool CPU::HasDCA() {
{ return GetFeatureBits_2() & 0b00000000100000000000000000000000;
return GetFeatureBits_2() & 0b00000000000001000000000000000000; }
}
bool CPU::HasTSC_DEADLINE()
bool CPU::HasSSE4_1() {
{ return GetFeatureBits_2() & 0b00000001000000000000000000000000;
return GetFeatureBits_2() & 0b00000000000010000000000000000000; }
}
bool CPU::HasAES()
bool CPU::HasSSE4_2() {
{ return GetFeatureBits_2() & 0b00000010000000000000000000000000;
return GetFeatureBits_2() & 0b00000000000100000000000000000000; }
}
bool CPU::HasXSAVE()
bool CPU::HasX2APIC() {
{ return GetFeatureBits_2() & 0b00000100000000000000000000000000;
return GetFeatureBits_2() & 0b00000000001000000000000000000000; }
}
bool CPU::HasOSXSAVE()
bool CPU::HasMOVBE() {
{ return GetFeatureBits_2() & 0b00001000000000000000000000000000;
return GetFeatureBits_2() & 0b00000000010000000000000000000000; }
}
bool CPU::HasAVX()
bool CPU::HasPOPCNT() {
{ return GetFeatureBits_2() & 0b00010000000000000000000000000000;
return GetFeatureBits_2() & 0b00000000100000000000000000000000; }
}
bool CPU::HasF16C()
bool CPU::HasTSC_DEADLINE() {
{ return GetFeatureBits_2() & 0b00100000000000000000000000000000;
return GetFeatureBits_2() & 0b00000001000000000000000000000000; }
}
bool CPU::HasRDRND()
bool CPU::HasAES() {
{ return GetFeatureBits_2() & 0b01000000000000000000000000000000;
return GetFeatureBits_2() & 0b00000010000000000000000000000000; }
}
bool CPU::HasHYPERVISOR()
bool CPU::HasXSAVE() {
{ return GetFeatureBits_2() & 0b10000000000000000000000000000000;
return GetFeatureBits_2() & 0b00000100000000000000000000000000; }
}
bool CPU::HasAVX2()
bool CPU::HasOSXSAVE() {
{ return GetExtFeatureBits_1() & 0b00000000000000000000000000100000;
return GetFeatureBits_2() & 0b00001000000000000000000000000000; }
}
bool CPU::HasRDSEED()
bool CPU::HasAVX() {
{ return GetExtFeatureBits_1() & 0b00000000000001000000000000000000;
return GetFeatureBits_2() & 0b00010000000000000000000000000000; }
}
bool CPU::HasADX()
bool CPU::HasF16C() {
{ return GetExtFeatureBits_1() & 0b00000000000010000000000000000000;
return GetFeatureBits_2() & 0b00100000000000000000000000000000; }
}
/*
bool CPU::HasRDRND() Str_8 CPU::ToStr()
{ {
return GetFeatureBits_2() & 0b01000000000000000000000000000000; return "Manufacturer: " + GetManufacturer() + "\r\n" +
} "Brand: " + GetBrand() + "\r\n" +
"Stepping Id: " + Str_8::FromNum(GetSteppingId()) + "\r\n" +
bool CPU::HasHYPERVISOR() "GpuModel Id: " + Str_8::FromNum(GetModelId()) + "\r\n" +
{ "Family Id: " + Str_8::FromNum(GetFamilyId()) + "\r\n" +
return GetFeatureBits_2() & 0b10000000000000000000000000000000; "Processor Type Id: " + Str_8::FromNum(GetProcessorTypeId()) + "\r\n" +
} "Extended GpuModel Id: " + Str_8::FromNum(GetExtModelId()) + "\r\n" +
"Extended Family Id: " + Str_8::FromNum(GetExtFamilyId()) + "\r\n" +
bool CPU::HasAVX2() "Has FPU: " + Str_8::FromNum((UInt_8)HasFPU()) + "\r\n" +
{ "Has SSE: " + Str_8::FromNum((UInt_8)HasSSE()) + "\r\n" +
return GetExtFeatureBits_1() & 0b00000000000000000000000000100000; "Has SSE 2: " + Str_8::FromNum((UInt_8)HasSSE2()) + "\r\n" +
} "Has SSE 3: " + Str_8::FromNum((UInt_8)HasSSE3()) + "\r\n" +
"Has SSSE 3: " + Str_8::FromNum((UInt_8)HasSSSE3()) + "\r\n" +
bool CPU::HasRDSEED() "Has SSE 4.1: " + Str_8::FromNum((UInt_8)HasSSE4_1()) + "\r\n" +
{ "Has SSE 4.2: " + Str_8::FromNum((UInt_8)HasSSE4_2()) + "\r\n" +
return GetExtFeatureBits_1() & 0b00000000000001000000000000000000; "Has AVX: " + Str_8::FromNum((UInt_8)HasAVX()) + "\r\n" +
} "Has RDRND: " + Str_8::FromNum((UInt_8)HasRDRND()) + "\r\n" +
"Has AVX 2: " + Str_8::FromNum((UInt_8)HasAVX2()) + "\r\n" +
bool CPU::HasADX() "Has ADX: " + Str_8::FromNum((UInt_8)HasADX()) + "\r\n" +
{ "Has RDSEED: " + Str_8::FromNum((UInt_8)HasRDSEED());
return GetExtFeatureBits_1() & 0b00000000000010000000000000000000; }
} */
/*
Str_8 CPU::ToStr()
{
return "Manufacturer: " + GetManufacturer() + "\r\n" +
"Brand: " + GetBrand() + "\r\n" +
"Stepping Id: " + Str_8::FromNum(GetSteppingId()) + "\r\n" +
"GpuModel Id: " + Str_8::FromNum(GetModelId()) + "\r\n" +
"Family Id: " + Str_8::FromNum(GetFamilyId()) + "\r\n" +
"Processor Type Id: " + Str_8::FromNum(GetProcessorTypeId()) + "\r\n" +
"Extended GpuModel Id: " + Str_8::FromNum(GetExtModelId()) + "\r\n" +
"Extended Family Id: " + Str_8::FromNum(GetExtFamilyId()) + "\r\n" +
"Has FPU: " + Str_8::FromNum((UInt_8)HasFPU()) + "\r\n" +
"Has SSE: " + Str_8::FromNum((UInt_8)HasSSE()) + "\r\n" +
"Has SSE 2: " + Str_8::FromNum((UInt_8)HasSSE2()) + "\r\n" +
"Has SSE 3: " + Str_8::FromNum((UInt_8)HasSSE3()) + "\r\n" +
"Has SSSE 3: " + Str_8::FromNum((UInt_8)HasSSSE3()) + "\r\n" +
"Has SSE 4.1: " + Str_8::FromNum((UInt_8)HasSSE4_1()) + "\r\n" +
"Has SSE 4.2: " + Str_8::FromNum((UInt_8)HasSSE4_2()) + "\r\n" +
"Has AVX: " + Str_8::FromNum((UInt_8)HasAVX()) + "\r\n" +
"Has RDRND: " + Str_8::FromNum((UInt_8)HasRDRND()) + "\r\n" +
"Has AVX 2: " + Str_8::FromNum((UInt_8)HasAVX2()) + "\r\n" +
"Has ADX: " + Str_8::FromNum((UInt_8)HasADX()) + "\r\n" +
"Has RDSEED: " + Str_8::FromNum((UInt_8)HasRDSEED());
}
*/
UInt_64 CPU::RetrieveTSC_Freq()
{
File tscDatabase("TSC_Frequencies.json", Mode::READ_WRITE, Disposition::CREATE_PERSISTENT);
if (tscDatabase.Size())
{
Json json(tscDatabase.ReadStr_8(tscDatabase.Size()), 5);
JsonObj* root = (JsonObj*)json.GetValue();
Char_8 manu[13];
manu[12] = 0;
GetManufacturer(manu);
JsonVar* jManu = root->GetVar(manu);
if (jManu)
{
JsonObj* joManu = (JsonObj*)jManu->GetValue();
Char_8 brand[49];
brand[48] = 0;
GetBrand(brand);
JsonVar* jBrand = joManu->GetVar(brand);
if (jBrand)
{
tscDatabase.Release();
return (UInt_64)*(JsonNum*)jBrand->GetValue();
}
else
{
UInt_64 tscFreq = CalculateTSC_Freq();
joManu->AddVar({brand, tscFreq});
tscDatabase.WriteStr_8(json.ToStr(false));
tscDatabase.Release();
return tscFreq;
}
}
else
{
UInt_64 tscFreq = CalculateTSC_Freq();
Char_8 brand[49];
brand[48] = 0;
GetBrand(brand);
JsonObj cpus(1, 0);
cpus[0] = JsonVar(brand, tscFreq);
JsonVar tmp({brand, cpus});
root->AddVar(tmp);
tscDatabase.WriteStr_8(json.ToStr(false));
tscDatabase.Release();
return tscFreq;
}
}
UInt_64 tscFreq = CalculateTSC_Freq();
Char_8 manu[13];
manu[12] = 0;
GetManufacturer(manu);
Char_8 brand[49];
brand[48] = 0;
GetBrand(brand);
JsonObj jManu(1, 0);
jManu[0] = JsonVar(brand, tscFreq);
JsonObj root(1, 0);
root[0] = JsonVar(manu, jManu);
Json json(root);
tscDatabase.WriteStr_8(json.ToStr(false));
tscDatabase.Release();
return tscFreq;
}
UInt_64 CPU::CalculateTSC_Freq()
{
UInt_64 result = GetTSC();
Thread::SleepFor(10000);
return (GetTSC() - result) / 10;
}
}

View File

@ -28,11 +28,6 @@ struct TSC
class CPU class CPU
{ {
private:
#ifdef OS_LINUX
static UInt_64 TSC_Freq;
#endif
public: public:
static Architecture GetArchitecture(); static Architecture GetArchitecture();
@ -42,8 +37,6 @@ public:
static void RDTSCP(TSC* tsc); static void RDTSCP(TSC* tsc);
static UInt_64 GetTSC_Freq();
static UInt_64 GetTSC(); static UInt_64 GetTSC();
/// Retrieves the CPU manufacturer id as a null-terminated ASCII string. /// Retrieves the CPU manufacturer id as a null-terminated ASCII string.
@ -207,9 +200,4 @@ public:
static void GetBrand(Char_8* input); static void GetBrand(Char_8* input);
//static Str_8 ToStr(); //static Str_8 ToStr();
private:
static UInt_64 RetrieveTSC_Freq();
static UInt_64 CalculateTSC_Freq();
}; };