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")
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")
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")
set(IS_OS_MAC TRUE)
message("Building for the Mac operating system.")
message("Building on the Mac operating system.")
endif ()
# Source files
@ -73,7 +73,7 @@ set(KERNEL_SOURCE_FILES
set(UTIL_SOURCE_FILES
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/Version.h src/Version.cpp
src/Serializer.h
@ -95,13 +95,13 @@ set(UTIL_SOURCE_FILES
src/Mat4.h
src/Mat3.h
src/Mat2.h
)
add_executable(ClassicOS
${GRUB_SOURCE_FILES}
${DRIVERS_SOURCE_FILES}
${KERNEL_SOURCE_FILES}
${UTIL_SOURCE_FILES}
)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@ -115,6 +115,7 @@ target_link_libraries(ClassicOS PRIVATE)
set(CMAKE_SYSTEM_PROCESSOR i386)
set(CMAKE_SYSTEM_NAME None)
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(CMAKE_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)

View File

@ -2,8 +2,6 @@
#include "Math.h"
{
Color4::Color4()
: r(0.0f), g(0.0f), b(0.0f), a(1.0f)
{
@ -94,4 +92,3 @@
{
return {r * color.r, g * color.g, b * color.b, a};
}
}

View File

@ -1,16 +1,5 @@
#include "CPU.h"
#include "../Log.h"
#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)
@ -42,31 +31,8 @@
#endif
}
UInt_64 CPU::GetTSC_Freq()
{
#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;
RDTSCP(&tsc);
@ -84,7 +50,6 @@
return result;
#elif defined(ARCH_X86)
return tsc.lowPart;
#endif
#endif
return 0;
@ -465,98 +430,3 @@
"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
{
private:
#ifdef OS_LINUX
static UInt_64 TSC_Freq;
#endif
public:
static Architecture GetArchitecture();
@ -42,8 +37,6 @@ public:
static void RDTSCP(TSC* tsc);
static UInt_64 GetTSC_Freq();
static UInt_64 GetTSC();
/// Retrieves the CPU manufacturer id as a null-terminated ASCII string.
@ -207,9 +200,4 @@ public:
static void GetBrand(Char_8* input);
//static Str_8 ToStr();
private:
static UInt_64 RetrieveTSC_Freq();
static UInt_64 CalculateTSC_Freq();
};