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,30 +2,28 @@
#include "Math.h" #include "Math.h"
Color4::Color4()
{
Color4::Color4()
: r(0.0f), g(0.0f), b(0.0f), a(1.0f) : 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) Color4& Color4::operator=(const Color4& color)
{ {
if (this == &color) if (this == &color)
return *this; return *this;
@ -35,20 +33,20 @@
a = color.a; a = color.a;
return *this; return *this;
} }
bool Color4::operator==(const Color4& color) const bool Color4::operator==(const Color4& color) const
{ {
return r == color.r && g == color.g && b == color.b && a == color.a; return r == color.r && g == color.g && b == color.b && a == color.a;
} }
bool Color4::operator!=(const Color4& color) const bool Color4::operator!=(const Color4& color) const
{ {
return r != color.r || g != color.g || b != color.b || a != color.a; return r != color.r || g != color.g || b != color.b || a != color.a;
} }
float Color4::operator[](const UInt_64 i) const float Color4::operator[](const UInt_64 i) const
{ {
switch (i) switch (i)
{ {
case 0: case 0:
@ -62,10 +60,10 @@
default: default:
return r; return r;
} }
} }
float& Color4::operator[](const UInt_64 i) float& Color4::operator[](const UInt_64 i)
{ {
switch (i) switch (i)
{ {
case 0: case 0:
@ -79,19 +77,18 @@
default: default:
return r; return r;
} }
} }
Color4& Color4::operator*=(const Color4& color) Color4& Color4::operator*=(const Color4& color)
{ {
r *= color.r; r *= color.r;
g *= color.g; g *= color.g;
b *= color.b; b *= color.b;
return *this; return *this;
} }
Color4 Color4::operator*(const Color4& color) const Color4 Color4::operator*(const Color4& color) const
{ {
return {r * color.r, g * color.g, b * color.b, a}; return {r * color.r, g * color.g, b * color.b, a};
}
} }

View File

@ -1,18 +1,7 @@
#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
UInt_64 CPU::TSC_Freq = 0;
#endif
Architecture CPU::GetArchitecture()
{
#if defined(ARCH_X64) #if defined(ARCH_X64)
return Architecture::X64; return Architecture::X64;
#elif defined(ARCH_ARM64) #elif defined(ARCH_ARM64)
@ -20,15 +9,15 @@
#else #else
return Architecture::UNKNOWN; return Architecture::UNKNOWN;
#endif #endif
} }
UInt_8 CPU::PointerSize() UInt_8 CPU::PointerSize()
{ {
return sizeof(void*); return sizeof(void*);
} }
Endianness CPU::GetEndianness() Endianness CPU::GetEndianness()
{ {
#if defined(LITTLE_ENDIAN) #if defined(LITTLE_ENDIAN)
return Endianness::LE; return Endianness::LE;
#elif defined(BIG_ENDIAN) #elif defined(BIG_ENDIAN)
@ -40,33 +29,10 @@
return Endianness::BE; return Endianness::BE;
#endif #endif
} }
UInt_64 CPU::GetTSC_Freq() UInt_64 CPU::GetTSC()
{ {
#if defined(OS_WINDOWS)
LARGE_INTEGER frequency = {};
QueryPerformanceFrequency(&frequency);
return frequency.QuadPart;
#elif defined(OS_LINUX)
if (!TSC_Freq)
TSC_Freq = RetrieveTSC_Freq();
return TSC_Freq;
#endif
return 0;
}
UInt_64 CPU::GetTSC()
{
#if defined(OS_WINDOWS)
LARGE_INTEGER count = {};
QueryPerformanceCounter(&count);
return count.QuadPart;
#elif defined(OS_LINUX)
TSC tsc; TSC tsc;
RDTSCP(&tsc); RDTSCP(&tsc);
@ -84,365 +50,364 @@
return result; return result;
#elif defined(ARCH_X86) #elif defined(ARCH_X86)
return tsc.lowPart; return tsc.lowPart;
#endif
#endif #endif
return 0; return 0;
} }
UInt_8 CPU::GetSteppingId() UInt_8 CPU::GetSteppingId()
{ {
return (UInt_8)GetInfoBits() & 0x00001111; return (UInt_8)GetInfoBits() & 0x00001111;
} }
UInt_8 CPU::GetModelId() UInt_8 CPU::GetModelId()
{ {
return (UInt_8)GetInfoBits() & 0x11110000; return (UInt_8)GetInfoBits() & 0x11110000;
} }
UInt_8 CPU::GetFamilyId() UInt_8 CPU::GetFamilyId()
{ {
return (UInt_8)(GetInfoBits() >> 8) & 0x00001111; return (UInt_8)(GetInfoBits() >> 8) & 0x00001111;
} }
UInt_8 CPU::GetProcessorTypeId() UInt_8 CPU::GetProcessorTypeId()
{ {
return (UInt_8)(GetInfoBits() >> 12) & 0x00000011; return (UInt_8)(GetInfoBits() >> 12) & 0x00000011;
} }
UInt_8 CPU::GetExtModelId() UInt_8 CPU::GetExtModelId()
{ {
return (UInt_8)(GetInfoBits() >> 16) & 0x00001111; return (UInt_8)(GetInfoBits() >> 16) & 0x00001111;
} }
UInt_8 CPU::GetExtFamilyId() UInt_8 CPU::GetExtFamilyId()
{ {
return (UInt_8)(GetInfoBits() >> 20); return (UInt_8)(GetInfoBits() >> 20);
} }
bool CPU::HasFPU() bool CPU::HasFPU()
{ {
return GetFeatureBits_1() & 0b00000000000000000000000000000001; return GetFeatureBits_1() & 0b00000000000000000000000000000001;
} }
bool CPU::HasVME() bool CPU::HasVME()
{ {
return GetFeatureBits_1() & 0b00000000000000000000000000000010; return GetFeatureBits_1() & 0b00000000000000000000000000000010;
} }
bool CPU::HasDE() bool CPU::HasDE()
{ {
return GetFeatureBits_1() & 0b00000000000000000000000000000100; return GetFeatureBits_1() & 0b00000000000000000000000000000100;
} }
bool CPU::HasPSE() bool CPU::HasPSE()
{ {
return GetFeatureBits_1() & 0b00000000000000000000000000001000; return GetFeatureBits_1() & 0b00000000000000000000000000001000;
} }
bool CPU::HasTSC() bool CPU::HasTSC()
{ {
return GetFeatureBits_1() & 0b00000000000000000000000000010000; return GetFeatureBits_1() & 0b00000000000000000000000000010000;
} }
bool CPU::HasMSR() bool CPU::HasMSR()
{ {
return GetFeatureBits_1() & 0b00000000000000000000000000100000; return GetFeatureBits_1() & 0b00000000000000000000000000100000;
} }
bool CPU::HasPAE() bool CPU::HasPAE()
{ {
return GetFeatureBits_1() & 0b00000000000000000000000001000000; return GetFeatureBits_1() & 0b00000000000000000000000001000000;
} }
bool CPU::HasMCE() bool CPU::HasMCE()
{ {
return GetFeatureBits_1() & 0b00000000000000000000000010000000; return GetFeatureBits_1() & 0b00000000000000000000000010000000;
} }
bool CPU::HasCX8() bool CPU::HasCX8()
{ {
return GetFeatureBits_1() & 0b00000000000000000000000100000000; return GetFeatureBits_1() & 0b00000000000000000000000100000000;
} }
bool CPU::HasAPIC() bool CPU::HasAPIC()
{ {
return GetFeatureBits_1() & 0b00000000000000000000001000000000; return GetFeatureBits_1() & 0b00000000000000000000001000000000;
} }
bool CPU::HasSEP() bool CPU::HasSEP()
{ {
return GetFeatureBits_1() & 0b00000000000000000000100000000000; return GetFeatureBits_1() & 0b00000000000000000000100000000000;
} }
bool CPU::HasMTRR() bool CPU::HasMTRR()
{ {
return GetFeatureBits_1() & 0b00000000000000000001000000000000; return GetFeatureBits_1() & 0b00000000000000000001000000000000;
} }
bool CPU::HasPGE() bool CPU::HasPGE()
{ {
return GetFeatureBits_1() & 0b00000000000000000010000000000000; return GetFeatureBits_1() & 0b00000000000000000010000000000000;
} }
bool CPU::HasMCA() bool CPU::HasMCA()
{ {
return GetFeatureBits_1() & 0b00000000000000000100000000000000; return GetFeatureBits_1() & 0b00000000000000000100000000000000;
} }
bool CPU::HasCMOV() bool CPU::HasCMOV()
{ {
return GetFeatureBits_1() & 0b00000000000000001000000000000000; return GetFeatureBits_1() & 0b00000000000000001000000000000000;
} }
bool CPU::HasPAT() bool CPU::HasPAT()
{ {
return GetFeatureBits_1() & 0b00000000000000010000000000000000; return GetFeatureBits_1() & 0b00000000000000010000000000000000;
} }
bool CPU::HasPSE_36() bool CPU::HasPSE_36()
{ {
return GetFeatureBits_1() & 0b00000000000000100000000000000000; return GetFeatureBits_1() & 0b00000000000000100000000000000000;
} }
bool CPU::HasPSN() bool CPU::HasPSN()
{ {
return GetFeatureBits_1() & 0b00000000000001000000000000000000; return GetFeatureBits_1() & 0b00000000000001000000000000000000;
} }
bool CPU::HasCLFSH() bool CPU::HasCLFSH()
{ {
return GetFeatureBits_1() & 0b00000000000010000000000000000000; return GetFeatureBits_1() & 0b00000000000010000000000000000000;
} }
bool CPU::HasDS() bool CPU::HasDS()
{ {
return GetFeatureBits_1() & 0b00000000001000000000000000000000; return GetFeatureBits_1() & 0b00000000001000000000000000000000;
} }
bool CPU::HasACPI() bool CPU::HasACPI()
{ {
return GetFeatureBits_1() & 0b00000000010000000000000000000000; return GetFeatureBits_1() & 0b00000000010000000000000000000000;
} }
bool CPU::HasMMX() bool CPU::HasMMX()
{ {
return GetFeatureBits_1() & 0b00000000100000000000000000000000; return GetFeatureBits_1() & 0b00000000100000000000000000000000;
} }
bool CPU::HasFXSR() bool CPU::HasFXSR()
{ {
return GetFeatureBits_1() & 0b00000001000000000000000000000000; return GetFeatureBits_1() & 0b00000001000000000000000000000000;
} }
bool CPU::HasSSE() bool CPU::HasSSE()
{ {
return GetFeatureBits_1() & 0b00000010000000000000000000000000; return GetFeatureBits_1() & 0b00000010000000000000000000000000;
} }
bool CPU::HasSSE2() bool CPU::HasSSE2()
{ {
return GetFeatureBits_1() & 0b00000100000000000000000000000000; return GetFeatureBits_1() & 0b00000100000000000000000000000000;
} }
bool CPU::HasSS() bool CPU::HasSS()
{ {
return GetFeatureBits_1() & 0b00001000000000000000000000000000; return GetFeatureBits_1() & 0b00001000000000000000000000000000;
} }
bool CPU::HasHTT() bool CPU::HasHTT()
{ {
return GetFeatureBits_1() & 0b00010000000000000000000000000000; return GetFeatureBits_1() & 0b00010000000000000000000000000000;
} }
bool CPU::HasTM() bool CPU::HasTM()
{ {
return GetFeatureBits_1() & 0b00100000000000000000000000000000; return GetFeatureBits_1() & 0b00100000000000000000000000000000;
} }
bool CPU::HasIA64() bool CPU::HasIA64()
{ {
return GetFeatureBits_1() & 0b01000000000000000000000000000000; return GetFeatureBits_1() & 0b01000000000000000000000000000000;
} }
bool CPU::HasPBE() bool CPU::HasPBE()
{ {
return GetFeatureBits_1() & 0b10000000000000000000000000000000; return GetFeatureBits_1() & 0b10000000000000000000000000000000;
} }
bool CPU::HasSSE3() bool CPU::HasSSE3()
{ {
return GetFeatureBits_2() & 0b00000000000000000000000000000001; return GetFeatureBits_2() & 0b00000000000000000000000000000001;
} }
bool CPU::HasPCLMULQDQ() bool CPU::HasPCLMULQDQ()
{ {
return GetFeatureBits_2() & 0b00000000000000000000000000000010; return GetFeatureBits_2() & 0b00000000000000000000000000000010;
} }
bool CPU::HasDTES64() bool CPU::HasDTES64()
{ {
return GetFeatureBits_2() & 0b00000000000000000000000000000100; return GetFeatureBits_2() & 0b00000000000000000000000000000100;
} }
bool CPU::HasMONITOR() bool CPU::HasMONITOR()
{ {
return GetFeatureBits_2() & 0b00000000000000000000000000001000; return GetFeatureBits_2() & 0b00000000000000000000000000001000;
} }
bool CPU::HasDS_CPL() bool CPU::HasDS_CPL()
{ {
return GetFeatureBits_2() & 0b00000000000000000000000000010000; return GetFeatureBits_2() & 0b00000000000000000000000000010000;
} }
bool CPU::HasVMX() bool CPU::HasVMX()
{ {
return GetFeatureBits_2() & 0b00000000000000000000000000100000; return GetFeatureBits_2() & 0b00000000000000000000000000100000;
} }
bool CPU::HasSMX() bool CPU::HasSMX()
{ {
return GetFeatureBits_2() & 0b00000000000000000000000001000000; return GetFeatureBits_2() & 0b00000000000000000000000001000000;
} }
bool CPU::HasEST() bool CPU::HasEST()
{ {
return GetFeatureBits_2() & 0b00000000000000000000000010000000; return GetFeatureBits_2() & 0b00000000000000000000000010000000;
} }
bool CPU::HasTM2() bool CPU::HasTM2()
{ {
return GetFeatureBits_2() & 0b00000000000000000000000100000000; return GetFeatureBits_2() & 0b00000000000000000000000100000000;
} }
bool CPU::HasSSSE3() bool CPU::HasSSSE3()
{ {
return GetFeatureBits_2() & 0b00000000000000000000001000000000; return GetFeatureBits_2() & 0b00000000000000000000001000000000;
} }
bool CPU::HasCNXT_ID() bool CPU::HasCNXT_ID()
{ {
return GetFeatureBits_2() & 0b00000000000000000000010000000000; return GetFeatureBits_2() & 0b00000000000000000000010000000000;
} }
bool CPU::HasSDBG() bool CPU::HasSDBG()
{ {
return GetFeatureBits_2() & 0b00000000000000000000100000000000; return GetFeatureBits_2() & 0b00000000000000000000100000000000;
} }
bool CPU::HasFMA() bool CPU::HasFMA()
{ {
return GetFeatureBits_2() & 0b00000000000000000001000000000000; return GetFeatureBits_2() & 0b00000000000000000001000000000000;
} }
bool CPU::HasCX16() bool CPU::HasCX16()
{ {
return GetFeatureBits_2() & 0b00000000000000000010000000000000; return GetFeatureBits_2() & 0b00000000000000000010000000000000;
} }
bool CPU::HasXTPR() bool CPU::HasXTPR()
{ {
return GetFeatureBits_2() & 0b00000000000000000100000000000000; return GetFeatureBits_2() & 0b00000000000000000100000000000000;
} }
bool CPU::HasPDCM() bool CPU::HasPDCM()
{ {
return GetFeatureBits_2() & 0b00000000000000001000000000000000; return GetFeatureBits_2() & 0b00000000000000001000000000000000;
} }
bool CPU::HasPCID() bool CPU::HasPCID()
{ {
return GetFeatureBits_2() & 0b00000000000000100000000000000000; return GetFeatureBits_2() & 0b00000000000000100000000000000000;
} }
bool CPU::HasDCA() bool CPU::HasDCA()
{ {
return GetFeatureBits_2() & 0b00000000000001000000000000000000; return GetFeatureBits_2() & 0b00000000000001000000000000000000;
} }
bool CPU::HasSSE4_1() bool CPU::HasSSE4_1()
{ {
return GetFeatureBits_2() & 0b00000000000010000000000000000000; return GetFeatureBits_2() & 0b00000000000010000000000000000000;
} }
bool CPU::HasSSE4_2() bool CPU::HasSSE4_2()
{ {
return GetFeatureBits_2() & 0b00000000000100000000000000000000; return GetFeatureBits_2() & 0b00000000000100000000000000000000;
} }
bool CPU::HasX2APIC() bool CPU::HasX2APIC()
{ {
return GetFeatureBits_2() & 0b00000000001000000000000000000000; return GetFeatureBits_2() & 0b00000000001000000000000000000000;
} }
bool CPU::HasMOVBE() bool CPU::HasMOVBE()
{ {
return GetFeatureBits_2() & 0b00000000010000000000000000000000; return GetFeatureBits_2() & 0b00000000010000000000000000000000;
} }
bool CPU::HasPOPCNT() bool CPU::HasPOPCNT()
{ {
return GetFeatureBits_2() & 0b00000000100000000000000000000000; return GetFeatureBits_2() & 0b00000000100000000000000000000000;
} }
bool CPU::HasTSC_DEADLINE() bool CPU::HasTSC_DEADLINE()
{ {
return GetFeatureBits_2() & 0b00000001000000000000000000000000; return GetFeatureBits_2() & 0b00000001000000000000000000000000;
} }
bool CPU::HasAES() bool CPU::HasAES()
{ {
return GetFeatureBits_2() & 0b00000010000000000000000000000000; return GetFeatureBits_2() & 0b00000010000000000000000000000000;
} }
bool CPU::HasXSAVE() bool CPU::HasXSAVE()
{ {
return GetFeatureBits_2() & 0b00000100000000000000000000000000; return GetFeatureBits_2() & 0b00000100000000000000000000000000;
} }
bool CPU::HasOSXSAVE() bool CPU::HasOSXSAVE()
{ {
return GetFeatureBits_2() & 0b00001000000000000000000000000000; return GetFeatureBits_2() & 0b00001000000000000000000000000000;
} }
bool CPU::HasAVX() bool CPU::HasAVX()
{ {
return GetFeatureBits_2() & 0b00010000000000000000000000000000; return GetFeatureBits_2() & 0b00010000000000000000000000000000;
} }
bool CPU::HasF16C() bool CPU::HasF16C()
{ {
return GetFeatureBits_2() & 0b00100000000000000000000000000000; return GetFeatureBits_2() & 0b00100000000000000000000000000000;
} }
bool CPU::HasRDRND() bool CPU::HasRDRND()
{ {
return GetFeatureBits_2() & 0b01000000000000000000000000000000; return GetFeatureBits_2() & 0b01000000000000000000000000000000;
} }
bool CPU::HasHYPERVISOR() bool CPU::HasHYPERVISOR()
{ {
return GetFeatureBits_2() & 0b10000000000000000000000000000000; return GetFeatureBits_2() & 0b10000000000000000000000000000000;
} }
bool CPU::HasAVX2() bool CPU::HasAVX2()
{ {
return GetExtFeatureBits_1() & 0b00000000000000000000000000100000; return GetExtFeatureBits_1() & 0b00000000000000000000000000100000;
} }
bool CPU::HasRDSEED() bool CPU::HasRDSEED()
{ {
return GetExtFeatureBits_1() & 0b00000000000001000000000000000000; return GetExtFeatureBits_1() & 0b00000000000001000000000000000000;
} }
bool CPU::HasADX() bool CPU::HasADX()
{ {
return GetExtFeatureBits_1() & 0b00000000000010000000000000000000; return GetExtFeatureBits_1() & 0b00000000000010000000000000000000;
} }
/* /*
Str_8 CPU::ToStr() Str_8 CPU::ToStr()
{ {
return "Manufacturer: " + GetManufacturer() + "\r\n" + return "Manufacturer: " + GetManufacturer() + "\r\n" +
"Brand: " + GetBrand() + "\r\n" + "Brand: " + GetBrand() + "\r\n" +
"Stepping Id: " + Str_8::FromNum(GetSteppingId()) + "\r\n" + "Stepping Id: " + Str_8::FromNum(GetSteppingId()) + "\r\n" +
@ -463,100 +428,5 @@
"Has AVX 2: " + Str_8::FromNum((UInt_8)HasAVX2()) + "\r\n" + "Has AVX 2: " + Str_8::FromNum((UInt_8)HasAVX2()) + "\r\n" +
"Has ADX: " + Str_8::FromNum((UInt_8)HasADX()) + "\r\n" + "Has ADX: " + Str_8::FromNum((UInt_8)HasADX()) + "\r\n" +
"Has RDSEED: " + Str_8::FromNum((UInt_8)HasRDSEED()); "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();
}; };