summaryrefslogtreecommitdiffhomepage
path: root/Private/Source
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-13 08:48:42 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-13 08:49:20 +0100
commitfb0d208bb2c6d8322ff1d483d92d143c6aaef9c1 (patch)
tree58874282f82d784bdea651dd9ef8e58426ee08ff /Private/Source
parent6926ed5c2da1e8928e14fe38ffd431fe37694fb1 (diff)
HCR-15: Improve kernel and bootloader.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/Source')
-rw-r--r--Private/Source/PEFCodeManager.cxx2
-rw-r--r--Private/Source/SMPManager.cxx16
-rw-r--r--Private/Source/UserHeap.cxx54
3 files changed, 35 insertions, 37 deletions
diff --git a/Private/Source/PEFCodeManager.cxx b/Private/Source/PEFCodeManager.cxx
index e7e0d9a0..530667cf 100644
--- a/Private/Source/PEFCodeManager.cxx
+++ b/Private/Source/PEFCodeManager.cxx
@@ -48,7 +48,7 @@ PEFLoader::PEFLoader(const char *path) : fCachedBlob(nullptr), fBad(false) {
if (StringBuilder::Equals(file->MIME(), this->MIME())) {
fPath = StringBuilder::Construct(path).Leak();
- fCachedBlob = file->ReadAll();
+ fCachedBlob = file->Read();
PEFContainer *container = reinterpret_cast<PEFContainer *>(fCachedBlob);
diff --git a/Private/Source/SMPManager.cxx b/Private/Source/SMPManager.cxx
index 0b3e1550..3db349fe 100644
--- a/Private/Source/SMPManager.cxx
+++ b/Private/Source/SMPManager.cxx
@@ -11,19 +11,19 @@
#include <KernelKit/ProcessManager.hpp>
#include <KernelKit/SMPManager.hpp>
-/// BUGS: 0
+///! BUGS: 0
///! @brief This file handles multi processing in HCore.
///! @brief Multi processing is needed for multi-tasking operations.
namespace HCore {
-// A HardwareThread class takes care of it's owned hardware thread.
-// It has a stack for it's core.
+///! A HardwareThread class takes care of it's owned hardware thread.
+///! It has a stack for it's core.
-// @brief constructor
+///! @brief constructor
HardwareThread::HardwareThread() = default;
-// @brief destructor
+///! @brief destructor
HardwareThread::~HardwareThread() = default;
//! @brief returns the id
@@ -110,14 +110,14 @@ bool SMPManager::Switch(HAL::StackFrame* stack) {
continue;
// to avoid any null deref.
- if (!stack, m_ThreadList[idx].Leak().Leak().m_Stack) continue;
+ if (!m_ThreadList[idx].Leak().Leak().m_Stack) continue;
+ if (m_ThreadList[idx].Leak().Leak().m_Stack->Rsp == 0) continue;
+ if (m_ThreadList[idx].Leak().Leak().m_Stack->Rbp == 0) continue;
m_ThreadList[idx].Leak().Leak().Busy(true);
m_ThreadList[idx].Leak().Leak().m_ID = idx;
- m_ThreadList[idx].Leak().Leak().Busy(true);
-
/// I figured out this:
/// Allocate stack
/// Set APIC base to stack
diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx
index 4690db9f..5b086111 100644
--- a/Private/Source/UserHeap.cxx
+++ b/Private/Source/UserHeap.cxx
@@ -45,12 +45,12 @@ Ref<Pmm> HeapManager::s_Pmm;
Boolean HeapManager::s_PoolsAreEnabled = true;
Array<Ref<PTEWrapper*>, kPoolMaxSz> HeapManager::s_Pool;
-STATIC voidPtr ke_find_unused_heap(Int flags);
-STATIC void ke_free_heap_internal(voidPtr vaddr);
-STATIC voidPtr ke_make_heap(voidPtr vaddr, Int flags);
-STATIC Boolean ke_check_and_free_heap(const SizeT& index, voidPtr ptr);
+STATIC VoidPtr ke_find_unused_heap(Int flags);
+STATIC void ke_free_heap_internal(VoidPtr vaddr);
+STATIC VoidPtr ke_make_heap(VoidPtr vaddr, Int flags);
+STATIC Boolean ke_check_and_free_heap(const SizeT& index, VoidPtr ptr);
-STATIC voidPtr ke_find_unused_heap(Int flags) {
+STATIC VoidPtr ke_find_unused_heap(Int flags) {
for (SizeT index = 0; index < kPoolMaxSz; ++index) {
if (HeapManager::The()[index] &&
!HeapManager::The()[index].Leak().Leak().Leak()->Present()) {
@@ -58,7 +58,7 @@ STATIC voidPtr ke_find_unused_heap(Int flags) {
HeapManager::The()[index].Leak().Leak(), true);
kcout << "[ke_find_unused_heap] Done, trying now to make a pool\r\n";
- return ke_make_heap((voidPtr)HeapManager::The()[index]
+ return ke_make_heap((VoidPtr)HeapManager::The()[index]
.Leak()
.Leak()
.Leak()
@@ -70,21 +70,21 @@ STATIC voidPtr ke_find_unused_heap(Int flags) {
return nullptr;
}
-STATIC voidPtr ke_make_heap(voidPtr virtualAddress, Int flags) {
+STATIC VoidPtr ke_make_heap(VoidPtr virtualAddress, Int flags) {
if (virtualAddress) {
- HeapHeader* pool_hdr = reinterpret_cast<HeapHeader*>(virtualAddress);
+ HeapHeader* poolHdr = reinterpret_cast<HeapHeader*>(virtualAddress);
- if (!pool_hdr->Free) {
- kcout << "[ke_make_heap] pool_hdr->Free, Pool already exists\n";
+ if (!poolHdr->Free) {
+ kcout << "[ke_make_heap] poolHdr->Free, Pool already exists\n";
return nullptr;
}
- pool_hdr->Flags = flags;
- pool_hdr->Magic = kPoolMag;
- pool_hdr->Free = false;
+ poolHdr->Flags = flags;
+ poolHdr->Magic = kPoolMag;
+ poolHdr->Free = false;
kcout << "[ke_make_heap] New allocation has been done.\n";
- return reinterpret_cast<voidPtr>(
+ return reinterpret_cast<VoidPtr>(
(reinterpret_cast<UIntPtr>(virtualAddress) + sizeof(HeapHeader)));
}
@@ -92,13 +92,13 @@ STATIC voidPtr ke_make_heap(voidPtr virtualAddress, Int flags) {
return nullptr;
}
-STATIC void ke_free_heap_internal(voidPtr virtualAddress) {
- HeapHeader* pool_hdr = reinterpret_cast<HeapHeader*>(
+STATIC void ke_free_heap_internal(VoidPtr virtualAddress) {
+ HeapHeader* poolHdr = reinterpret_cast<HeapHeader*>(
reinterpret_cast<UIntPtr>(virtualAddress) - sizeof(HeapHeader));
- if (pool_hdr->Magic == kPoolMag) {
- pool_hdr->Free = false;
- pool_hdr->Flags = 0;
+ if (poolHdr->Magic == kPoolMag) {
+ poolHdr->Free = false;
+ poolHdr->Flags = 0;
kcout << "[ke_free_heap_internal] Successfully marked header as free!\r\n";
}
@@ -111,11 +111,11 @@ STATIC void ke_free_heap_internal(voidPtr virtualAddress) {
* @param ptr The ptr to check.
* @return Boolean true if successful.
*/
-STATIC Boolean ke_check_and_free_heap(const SizeT& index, voidPtr ptr) {
+STATIC Boolean ke_check_and_free_heap(const SizeT& index, VoidPtr ptr) {
if (HeapManager::The()[index]) {
// ErrorOr<>::operator Boolean
- /// if address matches
- /// -> Free Pool.
+ /// if (address matches)
+ /// -> Free Pool.
if (HeapManager::The()[index].Leak().Leak().Leak()->VirtualAddress() ==
(UIntPtr)ptr) {
HeapManager::Leak().Leak().FreePage(
@@ -136,12 +136,12 @@ STATIC Boolean ke_check_and_free_heap(const SizeT& index, voidPtr ptr) {
/// @brief Creates a new pool pointer.
/// @param flags the flags attached to it.
/// @return a pool pointer with selected permissions.
-voidPtr ke_new_heap(Int32 flags) {
+VoidPtr ke_new_heap(Int32 flags) {
if (!HeapManager::IsEnabled()) return nullptr;
if (HeapManager::Count() > kPoolMaxSz) return nullptr;
- if (voidPtr ret = ke_find_unused_heap(flags)) return ret;
+ if (VoidPtr ret = ke_find_unused_heap(flags)) return ret;
// this wasn't set to true
auto ref_page = HeapManager::Leak().Leak().RequestPage(((flags & kPoolUser)),
@@ -154,11 +154,9 @@ voidPtr ke_new_heap(Int32 flags) {
++ref; // increment the number of addresses we have now.
- ref_page->NoExecute(true);
-
// finally make the pool address.
return ke_make_heap(
- reinterpret_cast<voidPtr>(ref_page.Leak()->VirtualAddress()), flags);
+ reinterpret_cast<VoidPtr>(ref_page.Leak()->VirtualAddress()), flags);
}
return nullptr;
@@ -167,7 +165,7 @@ voidPtr ke_new_heap(Int32 flags) {
/// @brief free a pool pointer.
/// @param ptr The pool pointer to free.
/// @return status code
-Int32 ke_free_heap(voidPtr ptr) {
+Int32 ke_free_heap(VoidPtr ptr) {
if (!HeapManager::IsEnabled()) return -1;
if (ptr) {