summaryrefslogtreecommitdiffhomepage
path: root/Private/Source
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-02 14:26:01 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-02 14:26:01 +0100
commit800977c96cd64b3beeccaa7d373daed3987b1c2a (patch)
treed97b5788f92b416f8f7f386ed9f179ab792b6f72 /Private/Source
parente559cf01834340d0a4dfcb45f7bdf081e8994032 (diff)
Kernel: Improvements and fixes regarding the VMMers and assembly code.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/Source')
-rw-r--r--Private/Source/Framebuffer.cxx18
-rw-r--r--Private/Source/GUIDWizard.cxx18
-rw-r--r--Private/Source/PageAllocator.cxx2
-rw-r--r--Private/Source/RuntimeCheck.cxx2
-rw-r--r--Private/Source/RuntimeMain.cxx10
-rw-r--r--Private/Source/SMPManager.cxx2
-rw-r--r--Private/Source/Storage/ATA.cxx2
-rw-r--r--Private/Source/Stream.cxx18
-rw-r--r--Private/Source/URL.cxx6
-rw-r--r--Private/Source/UserHeap.cxx99
10 files changed, 106 insertions, 71 deletions
diff --git a/Private/Source/Framebuffer.cxx b/Private/Source/Framebuffer.cxx
index 3b8fa229..61f946a7 100644
--- a/Private/Source/Framebuffer.cxx
+++ b/Private/Source/Framebuffer.cxx
@@ -3,20 +3,32 @@
Copyright Mahrouss Logic
File: Framebuffer.cxx
- Purpose: EFI C++ library
+ Purpose: Framebuffer object
Revision History:
01/02/24: Added file (amlel)
+ 02/02/24: Add documentation (amlel)
------------------------------------------- */
#include <KernelKit/Framebuffer.hpp>
+/**
+ * @brief Framebuffer object implementation.
+ *
+ */
+
using namespace HCore;
-volatile UIntPtr *Framebuffer::operator[](const UIntPtr &width_and_height) {
- return (UIntPtr *)(m_FrameBufferAddr->m_Base * width_and_height);
+/**
+ * @brief Get Pixel at
+ *
+ * @param pos position of pixel.
+ * @return volatile*
+ */
+volatile UIntPtr *Framebuffer::operator[](const UIntPtr &pos) {
+ return (UIntPtr *)(m_FrameBufferAddr->m_Base * pos);
}
const FramebufferColorKind &Framebuffer::Color(
diff --git a/Private/Source/GUIDWizard.cxx b/Private/Source/GUIDWizard.cxx
index 96c00efc..8befb071 100644
--- a/Private/Source/GUIDWizard.cxx
+++ b/Private/Source/GUIDWizard.cxx
@@ -1,11 +1,13 @@
-/*
- * ========================================================
- *
- * HCore
- * Copyright Mahrouss Logic, all rights reserved.
- *
- * ========================================================
- */
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+ File: GUIDWizard.cxx
+ Purpose: GUID helper code
+
+ Revision History:
+
+------------------------------------------- */
#include <CFKit/GUIDWizard.hpp>
#include <NewKit/Ref.hpp>
diff --git a/Private/Source/PageAllocator.cxx b/Private/Source/PageAllocator.cxx
index c2de0232..060ce011 100644
--- a/Private/Source/PageAllocator.cxx
+++ b/Private/Source/PageAllocator.cxx
@@ -7,7 +7,7 @@
* ========================================================
*/
-#include <ArchKit/Arch.hpp>
+#include <ArchKit/ArchKit.hpp>
#include <KernelKit/DebugOutput.hpp>
#include <NewKit/PageAllocator.hpp>
diff --git a/Private/Source/RuntimeCheck.cxx b/Private/Source/RuntimeCheck.cxx
index bbeecb74..a84a0b7a 100644
--- a/Private/Source/RuntimeCheck.cxx
+++ b/Private/Source/RuntimeCheck.cxx
@@ -7,7 +7,7 @@
* ========================================================
*/
-#include <ArchKit/Arch.hpp>
+#include <ArchKit/ArchKit.hpp>
#include <KernelKit/DebugOutput.hpp>
#include <NewKit/RuntimeCheck.hpp>
#include <NewKit/String.hpp>
diff --git a/Private/Source/RuntimeMain.cxx b/Private/Source/RuntimeMain.cxx
index 8c18c0a3..0cbdac1c 100644
--- a/Private/Source/RuntimeMain.cxx
+++ b/Private/Source/RuntimeMain.cxx
@@ -7,7 +7,7 @@
* ========================================================
*/
-#include <ArchKit/Arch.hpp>
+#include <ArchKit/ArchKit.hpp>
#include <EFIKit/BootProtocol.hxx>
#include <KernelKit/FileManager.hpp>
#include <KernelKit/PEFCodeManager.hxx>
@@ -20,6 +20,14 @@ extern "C" void RuntimeMain(
HCore::ke_init_heap();
HCore::ke_init_ke_heap();
+ kKernelVirtualSize = HandoverHeader->f_VirtualSize;
+ kKernelVirtualStart = HandoverHeader->f_VirtualStart;
+
+ kKernelPhysicalSize = HandoverHeader->f_VirtualSize;
+ kKernelPhysicalStart = HandoverHeader->f_VirtualStart;
+
+ HCore::HAL::hal_set_page_ptr((HCore::UIntPtr)kKernelVirtualStart);
+
MUST_PASS(HCore::ke_init_hal());
HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager());
diff --git a/Private/Source/SMPManager.cxx b/Private/Source/SMPManager.cxx
index 37c2e592..87e82da1 100644
--- a/Private/Source/SMPManager.cxx
+++ b/Private/Source/SMPManager.cxx
@@ -7,7 +7,7 @@
* ========================================================
*/
-#include <ArchKit/Arch.hpp>
+#include <ArchKit/ArchKit.hpp>
#include <KernelKit/ProcessManager.hpp>
#include <KernelKit/SMPManager.hpp>
diff --git a/Private/Source/Storage/ATA.cxx b/Private/Source/Storage/ATA.cxx
index 184bb043..9d7a204e 100644
--- a/Private/Source/Storage/ATA.cxx
+++ b/Private/Source/Storage/ATA.cxx
@@ -7,7 +7,7 @@
* ========================================================
*/
-#include <ArchKit/Arch.hpp>
+#include <ArchKit/ArchKit.hpp>
#include <StorageKit/ATA.hpp>
//! @brief ATA DMA Driver
diff --git a/Private/Source/Stream.cxx b/Private/Source/Stream.cxx
index 668d5aee..ab1ca742 100644
--- a/Private/Source/Stream.cxx
+++ b/Private/Source/Stream.cxx
@@ -1,10 +1,12 @@
-/*
- * ========================================================
- *
- * HCore
- * Copyright Mahrouss Logic, all rights reserved.
- *
- * ========================================================
- */
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+ File: Stream.cxx
+ Purpose: Stream object
+
+ Revision History:
+
+------------------------------------------- */
#include <NewKit/Stream.hpp>
diff --git a/Private/Source/URL.cxx b/Private/Source/URL.cxx
index f1df4ee1..ab289a66 100644
--- a/Private/Source/URL.cxx
+++ b/Private/Source/URL.cxx
@@ -18,7 +18,7 @@ Url::Url(StringView &strUrl) : m_urlView(strUrl, false) {}
Url::~Url() = default;
-constexpr const char *kProtos[] = {
+constexpr const char *kURLProtocols[] = {
"https", // http with the secure.
"http", // http without the secure
"file", // filesystem protocol
@@ -43,8 +43,8 @@ static ErrorOr<StringView> url_extract_location(const char *url) {
for (; i < string_length(url); ++i) {
if (!scheme_found) {
for (int y = 0; kProtosCount; ++y) {
- if (rt_string_in_string(view.CData(), kProtos[y])) {
- i += string_length(kProtos[y]) + kUrlOutSz;
+ if (rt_string_in_string(view.CData(), kURLProtocols[y])) {
+ i += string_length(kURLProtocols[y]) + kUrlOutSz;
scheme_found = true;
break;
diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx
index 0b6680a3..e22fe4f9 100644
--- a/Private/Source/UserHeap.cxx
+++ b/Private/Source/UserHeap.cxx
@@ -11,25 +11,30 @@
#include <NewKit/UserHeap.hpp>
/// @file Heap.cxx
-/// @brief Heap Manager, user mode allocator.
-/// @note if you want to look at kernel allocs, please look for KHeap.cxx
+/// @brief Heap Manager, Process heap allocator.
+/// @note if you want to look at the kernel allocator, please look for KernelHeap.cxx
/// bugs: 0
namespace HCore {
+/**
+ * @brief Heap Manager class, takes care of allocating the process pools.
+ * @note This rely on Virtual Memory! Consider adding good vmem support when
+ * @note porting to a new arch.
+ */
class HeapManager final {
public:
- static SizeT& GetCount() { return s_NumPools; }
- static Ref<Pmm>& GetPmm() { return s_Pmm; }
- static Boolean& IsEnabled() { return s_PoolsAreEnabled; }
- static Array<Ref<PTEWrapper*>, kPoolMaxSz>& The() { return s_Pool; }
+ STATIC SizeT& Count() { return s_NumPools; }
+ STATIC Ref<Pmm>& Leak() { return s_Pmm; }
+ STATIC Boolean& IsEnabled() { return s_PoolsAreEnabled; }
+ STATIC Array<Ref<PTEWrapper*>, kPoolMaxSz>& The() { return s_Pool; }
private:
- static Size s_NumPools;
- static Ref<Pmm> s_Pmm;
+ STATIC Size s_NumPools;
+ STATIC Ref<Pmm> s_Pmm;
private:
- static Boolean s_PoolsAreEnabled;
- static Array<Ref<PTEWrapper*>, kPoolMaxSz> s_Pool;
+ STATIC Boolean s_PoolsAreEnabled;
+ STATIC Array<Ref<PTEWrapper*>, kPoolMaxSz> s_Pool;
};
//! declare fields
@@ -39,16 +44,16 @@ 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 bool 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()) {
- HeapManager::GetPmm().Leak().TogglePresent(
+ HeapManager::Leak().Leak().TogglePresent(
HeapManager::The()[index].Leak().Leak(), true);
kcout << "[ke_find_unused_heap] Done, trying now to make a pool\r\n";
@@ -64,7 +69,7 @@ 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);
@@ -86,7 +91,7 @@ static voidPtr ke_make_heap(voidPtr virtualAddress, Int flags) {
return nullptr;
}
-static void ke_free_heap_internal(voidPtr virtualAddress) {
+STATIC void ke_free_heap_internal(voidPtr virtualAddress) {
HeapHeader* pool_hdr = reinterpret_cast<HeapHeader*>(
reinterpret_cast<UIntPtr>(virtualAddress) - sizeof(HeapHeader));
@@ -98,23 +103,29 @@ static void ke_free_heap_internal(voidPtr virtualAddress) {
}
}
-static bool ke_check_and_free_heap(const SizeT& index, voidPtr ptr) {
+/**
+ * @brief Check for the ptr and frees it.
+ *
+ * @param index Where to look at.
+ * @param ptr The ptr to check.
+ * @return Boolean true if successful.
+ */
+STATIC Boolean ke_check_and_free_heap(const SizeT& index, voidPtr ptr) {
if (HeapManager::The()[index]) {
- // ErrorOr<>::operator bool
- if (!HeapManager::The()[index].Leak().Leak().IsStrong()) {
- // we want them to be weak
- // because we allocated it.
- if (HeapManager::The()[index].Leak().Leak().Leak()->VirtualAddress() ==
- (UIntPtr)ptr) {
- HeapManager::GetPmm().Leak().FreePage(
- HeapManager::The()[index].Leak().Leak());
- --HeapManager::GetCount();
-
- ke_free_heap_internal(ptr);
- ptr = nullptr;
-
- return true;
- }
+ // ErrorOr<>::operator Boolean
+ /// if address matches
+ /// -> Free Pool.
+ if (HeapManager::The()[index].Leak().Leak().Leak()->VirtualAddress() ==
+ (UIntPtr)ptr) {
+ HeapManager::Leak().Leak().FreePage(
+ HeapManager::The()[index].Leak().Leak());
+
+ --HeapManager::Count();
+
+ ke_free_heap_internal(ptr);
+ ptr = nullptr;
+
+ return true;
}
}
@@ -127,20 +138,20 @@ static bool ke_check_and_free_heap(const SizeT& index, voidPtr ptr) {
voidPtr ke_new_heap(Int32 flags) {
if (!HeapManager::IsEnabled()) return nullptr;
- if (HeapManager::GetCount() > kPoolMaxSz) return nullptr;
+ if (HeapManager::Count() > kPoolMaxSz) return nullptr;
if (voidPtr ret = ke_find_unused_heap(flags)) return ret;
// this wasn't set to true
- auto ref_page = HeapManager::GetPmm().Leak().RequestPage(
+ auto ref_page = HeapManager::Leak().Leak().RequestPage(
((flags & kPoolUser)), (flags & kPoolRw));
+
if (ref_page) {
///! reserve page.
- HeapManager::The()[HeapManager::GetCount()].Leak() = ref_page;
- auto& ref = HeapManager::GetCount();
- ++ref; // increment the number of addresses we have now.
+ HeapManager::The()[HeapManager::Count()].Leak() = ref_page;
+ auto& ref = HeapManager::Count();
- kcout << "[ke_new_heap] New Address found!\r\n";
+ ++ref; // increment the number of addresses we have now.
// finally make the pool address.
return ke_make_heap(
@@ -157,7 +168,7 @@ Int32 ke_free_heap(voidPtr ptr) {
if (!HeapManager::IsEnabled()) return -1;
if (ptr) {
- SizeT base = HeapManager::GetCount();
+ SizeT base = HeapManager::Count();
if (ke_check_and_free_heap(base, ptr)) return 0;
@@ -171,10 +182,10 @@ Int32 ke_free_heap(voidPtr ptr) {
return -1;
}
-/// @brief Init HeapManager, set GetCount to zero and IsEnabled to true.
-/// @return
+/// @brief Init HeapManager, set Count to zero and IsEnabled to true.
+/// @return
Void ke_init_heap() {
- HeapManager::GetCount() = 0UL;
+ HeapManager::Count() = 0UL;
HeapManager::IsEnabled() = true;
}
} // namespace HCore