mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-16 09:41:42 +00:00
QoL and bug fixes
This commit is contained in:
155
Tests/CPUID.cpp
Normal file
155
Tests/CPUID.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#include <types.h>
|
||||
#include <memory.hpp>
|
||||
#include <debug.h>
|
||||
|
||||
extern bool DebuggerIsAttached;
|
||||
|
||||
__constructor void TestCPUIDStructs()
|
||||
{
|
||||
if (!DebuggerIsAttached)
|
||||
return;
|
||||
|
||||
if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_AMD) == 0)
|
||||
{
|
||||
CPU::x86::AMD::CPUID0x00000000 cpuid0;
|
||||
CPU::x86::AMD::CPUID0x00000001 cpuid1;
|
||||
CPU::x86::AMD::CPUID0x00000005 cpuid5;
|
||||
CPU::x86::AMD::CPUID0x00000006 cpuid6;
|
||||
CPU::x86::AMD::CPUID0x00000007 cpuid7;
|
||||
CPU::x86::AMD::CPUID0x0000000B_ECX_0 cpuidB_C_0;
|
||||
CPU::x86::AMD::CPUID0x0000000B_ECX_1 cpuidB_C_1;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_0 cpuidD_C_0;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_1 cpuidD_C_1;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_2 cpuidD_C_2;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_11 cpuidD_C_11;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_12 cpuidD_C_12;
|
||||
CPU::x86::AMD::CPUID0x0000000D_ECX_3E cpuidD_C_3E;
|
||||
CPU::x86::AMD::CPUID0x80000000 cpuid80000000;
|
||||
CPU::x86::AMD::CPUID0x80000001 cpuid80000001;
|
||||
CPU::x86::AMD::CPUID0x80000002 cpuid80000002;
|
||||
CPU::x86::AMD::CPUID0x80000003 cpuid80000003;
|
||||
CPU::x86::AMD::CPUID0x80000004 cpuid80000004;
|
||||
CPU::x86::AMD::CPUID0x80000005 cpuid80000005;
|
||||
CPU::x86::AMD::CPUID0x80000006 cpuid80000006;
|
||||
CPU::x86::AMD::CPUID0x80000007 cpuid80000007;
|
||||
CPU::x86::AMD::CPUID0x80000008 cpuid80000008;
|
||||
CPU::x86::AMD::CPUID0x8000000A cpuid8000000A;
|
||||
CPU::x86::AMD::CPUID0x80000019 cpuid80000019;
|
||||
CPU::x86::AMD::CPUID0x8000001A cpuid8000001A;
|
||||
CPU::x86::AMD::CPUID0x8000001B cpuid8000001B;
|
||||
CPU::x86::AMD::CPUID0x8000001C cpuid8000001C;
|
||||
CPU::x86::AMD::CPUID0x8000001D cpuid8000001D;
|
||||
CPU::x86::AMD::CPUID0x8000001E cpuid8000001E;
|
||||
CPU::x86::AMD::CPUID0x8000001F cpuid8000001F;
|
||||
CPU::x86::AMD::CPUID0x80000020 cpuid80000020;
|
||||
CPU::x86::AMD::CPUID0x80000021 cpuid80000021;
|
||||
CPU::x86::AMD::CPUID0x80000022 cpuid80000022;
|
||||
CPU::x86::AMD::CPUID0x80000023 cpuid80000023;
|
||||
CPU::x86::AMD::CPUID0x80000026 cpuid80000026;
|
||||
|
||||
cpuid0.Get();
|
||||
cpuid1.Get();
|
||||
cpuid5.Get();
|
||||
cpuid6.Get();
|
||||
cpuid7.Get();
|
||||
cpuidB_C_0.Get();
|
||||
cpuidB_C_1.Get();
|
||||
cpuidD_C_0.Get();
|
||||
cpuidD_C_1.Get();
|
||||
cpuidD_C_2.Get();
|
||||
cpuidD_C_11.Get();
|
||||
cpuidD_C_12.Get();
|
||||
cpuidD_C_3E.Get();
|
||||
cpuid80000000.Get();
|
||||
cpuid80000001.Get();
|
||||
cpuid80000002.Get();
|
||||
cpuid80000003.Get();
|
||||
cpuid80000004.Get();
|
||||
cpuid80000005.Get();
|
||||
cpuid80000006.Get();
|
||||
cpuid80000007.Get();
|
||||
cpuid80000008.Get();
|
||||
cpuid8000000A.Get();
|
||||
cpuid80000019.Get();
|
||||
cpuid8000001A.Get();
|
||||
cpuid8000001B.Get();
|
||||
cpuid8000001C.Get();
|
||||
cpuid8000001D.Get();
|
||||
cpuid8000001E.Get();
|
||||
cpuid8000001F.Get();
|
||||
cpuid80000020.Get();
|
||||
cpuid80000021.Get();
|
||||
cpuid80000022.Get();
|
||||
cpuid80000023.Get();
|
||||
cpuid80000026.Get();
|
||||
|
||||
// asmv("int3");
|
||||
}
|
||||
else if (strcmp(CPU::Vendor(), x86_CPUID_VENDOR_INTEL) == 0)
|
||||
{
|
||||
CPU::x86::Intel::CPUID0x00000000 cpuid0;
|
||||
CPU::x86::Intel::CPUID0x00000001 cpuid1;
|
||||
CPU::x86::Intel::CPUID0x00000002 cpuid2;
|
||||
CPU::x86::Intel::CPUID0x00000003 cpuid3;
|
||||
CPU::x86::Intel::CPUID0x00000004_1 cpuid4_1;
|
||||
CPU::x86::Intel::CPUID0x00000005 cpuid5;
|
||||
CPU::x86::Intel::CPUID0x00000006 cpuid6;
|
||||
CPU::x86::Intel::CPUID0x00000007_0 cpuid7_0;
|
||||
CPU::x86::Intel::CPUID0x00000007_1 cpuid7_1;
|
||||
CPU::x86::Intel::CPUID0x0000000A cpuidA;
|
||||
CPU::x86::Intel::CPUID0x00000015 cpuid15;
|
||||
CPU::x86::Intel::CPUID0x00000016 cpuid16;
|
||||
CPU::x86::Intel::CPUID0x80000000 cpuid80000000;
|
||||
CPU::x86::Intel::CPUID0x80000001 cpuid80000001;
|
||||
CPU::x86::Intel::CPUID0x80000002 cpuid80000002;
|
||||
CPU::x86::Intel::CPUID0x80000003 cpuid80000003;
|
||||
CPU::x86::Intel::CPUID0x80000004 cpuid80000004;
|
||||
CPU::x86::Intel::CPUID0x80000006 cpuid80000006;
|
||||
CPU::x86::Intel::CPUID0x80000008 cpuid80000008;
|
||||
CPU::x86::Intel::CPUID0x8000000A cpuid8000000A;
|
||||
|
||||
cpuid0.Get();
|
||||
cpuid1.Get();
|
||||
cpuid2.Get();
|
||||
cpuid3.Get();
|
||||
cpuid4_1.Get();
|
||||
cpuid5.Get();
|
||||
cpuid6.Get();
|
||||
cpuid7_0.Get();
|
||||
cpuid7_1.Get();
|
||||
cpuidA.Get();
|
||||
cpuid15.Get();
|
||||
cpuid16.Get();
|
||||
cpuid80000000.Get();
|
||||
cpuid80000001.Get();
|
||||
cpuid80000002.Get();
|
||||
cpuid80000003.Get();
|
||||
cpuid80000004.Get();
|
||||
cpuid80000006.Get();
|
||||
cpuid80000008.Get();
|
||||
cpuid8000000A.Get();
|
||||
|
||||
// asmv("int3");
|
||||
}
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
@@ -15,6 +15,8 @@
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#include <types.h>
|
||||
#include <memory.hpp>
|
||||
#include <debug.h>
|
||||
@@ -23,54 +25,71 @@ __constructor void TestMacros()
|
||||
{
|
||||
{
|
||||
int a = TO_PAGES(4096);
|
||||
int b = FROM_PAGES(2);
|
||||
int b = FROM_PAGES(1);
|
||||
|
||||
debug("a: 4096 -> %d", a);
|
||||
debug("b: a -> %d", b);
|
||||
|
||||
if (a != 1)
|
||||
{
|
||||
error("t1: TO_PAGES is not equal to 1");
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
if (b != 4096)
|
||||
{
|
||||
error("t1: FROM_PAGES is not equal to 4096");
|
||||
inf_loop;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int a = TO_PAGES(4097);
|
||||
int b = FROM_PAGES(2);
|
||||
|
||||
debug("a: 4097 -> %d", a);
|
||||
debug("b: a -> %d", b);
|
||||
|
||||
if (a != 2)
|
||||
{
|
||||
error("TO_PAGES is not equal to 2");
|
||||
while (1)
|
||||
;
|
||||
error("t2: TO_PAGES is not equal to 2");
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
if (b != 8192)
|
||||
{
|
||||
error("FROM_PAGES is not equal to 8192");
|
||||
while (1)
|
||||
;
|
||||
error("t2: FROM_PAGES is not equal to 8192");
|
||||
inf_loop;
|
||||
}
|
||||
}
|
||||
|
||||
debug("-------------------------");
|
||||
|
||||
{
|
||||
uint64_t actual = PAGE_SIZE;
|
||||
uint64_t expected = 1;
|
||||
uint64_t bytes = PAGE_SIZE;
|
||||
uint64_t pgs = 1;
|
||||
|
||||
for (int i = 0; i < 128; i++)
|
||||
{
|
||||
uint64_t a = TO_PAGES(actual);
|
||||
uint64_t b = FROM_PAGES(expected);
|
||||
uint64_t cnv_to_pgs = TO_PAGES(bytes);
|
||||
uint64_t cnv_from_pgs = FROM_PAGES(pgs);
|
||||
|
||||
/* TODO: This is a workaround for now. */
|
||||
if (a != expected + 1)
|
||||
if (cnv_to_pgs != pgs)
|
||||
{
|
||||
error("TO_PAGES is not equal to %d (actual: %d)", expected, a);
|
||||
while (1)
|
||||
;
|
||||
error("TO_PAGES is not equal to %d (pages: %d)", pgs, cnv_to_pgs);
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
if (b != actual)
|
||||
if (cnv_from_pgs != bytes)
|
||||
{
|
||||
error("FROM_PAGES is not equal to %d (actual: %d)", actual, b);
|
||||
while (1)
|
||||
;
|
||||
error("FROM_PAGES is not equal to %d (bytes: %d)", bytes, cnv_from_pgs);
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
actual += PAGE_SIZE;
|
||||
expected++;
|
||||
bytes += PAGE_SIZE;
|
||||
pgs++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
||||
|
@@ -38,32 +38,29 @@ __constructor void TestMemoryOperations()
|
||||
char str2[] = "World";
|
||||
|
||||
memcpy_unsafe(arr2, arr1, sizeof(arr1));
|
||||
debug("memcpy: arr2[0]=%d, arr2[1]=%d, arr2[2]=%d, arr2[3]=%d, arr2[4]=%d\n",
|
||||
debug("memcpy: arr2[0]=%d, arr2[1]=%d, arr2[2]=%d, arr2[3]=%d, arr2[4]=%d",
|
||||
arr2[0], arr2[1], arr2[2], arr2[3], arr2[4]);
|
||||
if (memcmp(arr1, arr2, sizeof(arr1)) != 0)
|
||||
{
|
||||
error("memcpy failed!\n");
|
||||
while (1)
|
||||
;
|
||||
error("memcpy failed!");
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
memset_unsafe(arr2, 0, sizeof(arr2));
|
||||
debug("memset: arr2[0]=%d, arr2[1]=%d, arr2[2]=%d, arr2[3]=%d, arr2[4]=%d\n",
|
||||
debug("memset: arr2[0]=%d, arr2[1]=%d, arr2[2]=%d, arr2[3]=%d, arr2[4]=%d",
|
||||
arr2[0], arr2[1], arr2[2], arr2[3], arr2[4]);
|
||||
if (memcmp(arr1, arr2, sizeof(arr1)) == 0)
|
||||
{
|
||||
error("memset failed!\n");
|
||||
while (1)
|
||||
;
|
||||
error("memset failed!");
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
memmove_unsafe(str1 + 3, str1, strlen(str1) + 1);
|
||||
debug("memmove: str1=%s\n", str1);
|
||||
debug("memmove: str1=%s", str1);
|
||||
if (strcmp(str1, "HelHello") != 0)
|
||||
{
|
||||
error("memmove failed!\n");
|
||||
while (1)
|
||||
;
|
||||
error("memmove failed!");
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
char carr[1024];
|
||||
@@ -82,7 +79,7 @@ __constructor void TestMemoryOperations()
|
||||
{
|
||||
if (carr[i] != 'a')
|
||||
{
|
||||
error("memcpy failed!\n");
|
||||
error("memcpy failed!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
@@ -97,7 +94,7 @@ __constructor void TestMemoryOperations()
|
||||
{
|
||||
if (carr[i] != 'b')
|
||||
{
|
||||
error("memcpy failed!\n");
|
||||
error("memcpy failed!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
@@ -113,7 +110,7 @@ __constructor void TestMemoryOperations()
|
||||
{
|
||||
if (carr[i] != 'c')
|
||||
{
|
||||
error("memcpy failed!\n");
|
||||
error("memcpy failed!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
@@ -128,7 +125,7 @@ __constructor void TestMemoryOperations()
|
||||
{
|
||||
if (carr[i] != 'd')
|
||||
{
|
||||
error("memset failed!\n");
|
||||
error("memset failed!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ __constructor void TestRandom()
|
||||
if (strcmp(CPU::Hypervisor(), x86_CPUID_VENDOR_TCG) == 0)
|
||||
RDRANDFlag = 0;
|
||||
|
||||
#if defined(a64) || defined(a32)
|
||||
#if defined(a86)
|
||||
if (RDRANDFlag)
|
||||
{
|
||||
uint64_t RDSEEDValue = 0;
|
||||
|
@@ -31,8 +31,7 @@ void TestString()
|
||||
else
|
||||
{
|
||||
error("String comparison doesn't work! \"%s\"", hw.c_str());
|
||||
while (1)
|
||||
;
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
std::string hi("Hi");
|
||||
@@ -45,8 +44,7 @@ void TestString()
|
||||
else
|
||||
{
|
||||
error("String indexing doesn't work! \"%s\" \"%s\"", chi, hi.c_str());
|
||||
while (1)
|
||||
;
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
hi << " there!";
|
||||
@@ -55,8 +53,7 @@ void TestString()
|
||||
else
|
||||
{
|
||||
error("String concatenation doesn't work! \"%s\"", hi.c_str());
|
||||
while (1)
|
||||
;
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
hi << " " << hw;
|
||||
@@ -65,8 +62,7 @@ void TestString()
|
||||
else
|
||||
{
|
||||
error("String concatenation doesn't work! \"%s\"", hi.c_str());
|
||||
while (1)
|
||||
;
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
std::string eq0("Hello, world!");
|
||||
@@ -78,8 +74,7 @@ void TestString()
|
||||
else
|
||||
{
|
||||
error("String equality doesn't work! \"%s\" \"%s\"", eq0.c_str(), eq1.c_str());
|
||||
while (1)
|
||||
;
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
if (eq0 != eq2)
|
||||
@@ -87,8 +82,7 @@ void TestString()
|
||||
else
|
||||
{
|
||||
error("String inequality doesn't work! \"%s\" \"%s\"", eq0.c_str(), eq2.c_str());
|
||||
while (1)
|
||||
;
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
char chw[14];
|
||||
@@ -105,8 +99,7 @@ void TestString()
|
||||
else
|
||||
{
|
||||
error("String iteration doesn't work! \"%s\" \"%s\" %d", chw, hw.c_str(), i);
|
||||
while (1)
|
||||
;
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
std::string a("Hello");
|
||||
@@ -119,8 +112,7 @@ void TestString()
|
||||
else
|
||||
{
|
||||
error("String addition doesn't work! \"%s\"", c.c_str());
|
||||
while (1)
|
||||
;
|
||||
inf_loop;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user