diff options
| author | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-21 22:22:54 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-21 22:22:54 +0100 |
| commit | 223aad0fd3f8af6f69eb6429e5514bc888afe0d9 (patch) | |
| tree | 7de1e607423f3af6791d659a8f72556ecc798f72 /Private/Source | |
| parent | 44b7347157830e17fdb376d27a5d1cd402d2bd6f (diff) | |
Kernel: fixes and improvements.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/Source')
| -rw-r--r-- | Private/Source/FileManager.cxx | 2 | ||||
| -rw-r--r-- | Private/Source/KernelHeap.cxx | 16 | ||||
| -rw-r--r-- | Private/Source/KernelMain.cxx | 5 | ||||
| -rw-r--r-- | Private/Source/PageManager.cxx | 48 | ||||
| -rw-r--r-- | Private/Source/RuntimeCheck.cxx | 7 |
5 files changed, 19 insertions, 59 deletions
diff --git a/Private/Source/FileManager.cxx b/Private/Source/FileManager.cxx index 860a8808..ba5d6bfd 100644 --- a/Private/Source/FileManager.cxx +++ b/Private/Source/FileManager.cxx @@ -33,7 +33,7 @@ IFilesystemManager* IFilesystemManager::Unmount() { } bool IFilesystemManager::Mount(IFilesystemManager* pMount) { - if (pMount) { + if (kMounted == nullptr) { kMounted = pMount; return true; } diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx index a967b003..358330f0 100644 --- a/Private/Source/KernelHeap.cxx +++ b/Private/Source/KernelHeap.cxx @@ -9,6 +9,8 @@ #include <NewKit/KernelHeap.hpp> +#include "KernelKit/DebugOutput.hpp" + //! @file KernelHeap.cpp //! @brief Kernel allocator. @@ -47,16 +49,12 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) { Ref<PTEWrapper *> wrapper = kPageManager.Request(user, rw, false); - if (wrapper) { - kLastWrapper = wrapper; - - kWrapperList[kWrapperCount] = wrapper; - ++kWrapperCount; + kLastWrapper = wrapper; - return reinterpret_cast<voidPtr>(wrapper->VirtualAddress()); - } + kWrapperList[kWrapperCount] = wrapper; + ++kWrapperCount; - return nullptr; + return reinterpret_cast<voidPtr>(wrapper->VirtualAddress()); } /// @brief Declare pointer as free. @@ -124,7 +122,5 @@ Boolean kernel_valid_ptr(voidPtr ptr) { Void ke_init_ke_heap() noexcept { kWrapperCount = 0UL; Ref<PTEWrapper *> kLastWrapper = Ref<PTEWrapper *>(nullptr); - - kcout << "KernelHeap: Init [OK]\r\n"; } } // namespace HCore diff --git a/Private/Source/KernelMain.cxx b/Private/Source/KernelMain.cxx index ea6e0c1d..171deff1 100644 --- a/Private/Source/KernelMain.cxx +++ b/Private/Source/KernelMain.cxx @@ -24,9 +24,6 @@ EXTERN_C void RuntimeMain( kKernelPhysicalSize = HandoverHeader->f_VirtualSize; kKernelPhysicalStart = HandoverHeader->f_VirtualStart; - /// Setup base page. - HCore::HAL::hal_page_base((HCore::UIntPtr)kKernelVirtualStart); - /// Init memory managers. HCore::ke_init_ke_heap(); HCore::ke_init_heap(); @@ -35,7 +32,7 @@ EXTERN_C void RuntimeMain( MUST_PASS(HCore::ke_init_hal()); /// Mount a New partition. - HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager()); + // HCore::IFilesystemManager::Mount(new HCore::NewFilesystemManager()); HCore::PEFLoader img("/System/HCoreShell.exe"); /// Run the shell. diff --git a/Private/Source/PageManager.cxx b/Private/Source/PageManager.cxx index b3a168d3..c520da78 100644 --- a/Private/Source/PageManager.cxx +++ b/Private/Source/PageManager.cxx @@ -10,8 +10,6 @@ #include <KernelKit/DebugOutput.hpp> #include <NewKit/PageManager.hpp> -#include "NewKit/String.hpp" - #ifdef __x86_64__ #include <HALKit/AMD64/HalPageAlloc.hpp> #endif // ifdef __x86_64__ @@ -45,7 +43,8 @@ PTEWrapper::~PTEWrapper() { PTE *raw = reinterpret_cast<PTE *>(m_VirtAddr); MUST_PASS(raw); - if (raw->Present) raw->Present = false; + raw->Present = false; + raw->Rw = false; } void PTEWrapper::FlushTLB(Ref<PageManager> &pm) { @@ -80,14 +79,14 @@ PTEWrapper *PageManager::Request(Boolean Rw, Boolean User, HCore::HAL::hal_alloc_page(sizeof(PTEWrapper), Rw, User)); if (PageTableEntry == nullptr) { - kcout << "PTEWrapper : Page table is nullptr!, ke_new_ke_heap failed!"; + kcout << "PTEWrapper : Page table is nullptr!, ke_new_ke_heap failed!\n"; return nullptr; } PageTableEntry->NoExecute(ExecDisable); - *PageTableEntry = - PTEWrapper{Rw, User, ExecDisable, Detail::create_page_wrapper(Rw, User)}; + *PageTableEntry = PTEWrapper{Rw, User, ExecDisable, + reinterpret_cast<UIntPtr>(PageTableEntry)}; return PageTableEntry; } @@ -116,42 +115,11 @@ const UIntPtr &PTEWrapper::VirtualAddress() { return m_VirtAddr; } //////////////////////////// -bool PTEWrapper::Shareable() { - auto raw = reinterpret_cast<PTE *>(m_VirtAddr); - - if (raw->Present) { - m_Shareable = raw->Rw; - kcout << m_Shareable ? "[PTEWrapper::Shareable] page is sharable!\n" - : "[PTEWrapper::Shareable] page is not sharable!\n"; - - return m_Shareable; - } else { - kcout << "[PTEWrapper::Shareable] page is not present!\n"; - return false; - } -} - -bool PTEWrapper::Present() { - auto raw = reinterpret_cast<PTE *>(m_VirtAddr); +bool PTEWrapper::Shareable() { return m_Shareable; } - if (raw->Present) { - m_Present = raw->Present; - return m_Present; - } else { - kcout << "[PTEWrapper::Present] page is not present!"; - return false; - } -} - -bool PTEWrapper::Access() { - auto raw = reinterpret_cast<PTE *>(m_VirtAddr); +bool PTEWrapper::Present() { return m_Present; } - if (raw->Present) { - m_Accessed = raw->Accessed; - } - - return m_Accessed; -} +bool PTEWrapper::Access() { return m_Accessed; } //////////////////////////// diff --git a/Private/Source/RuntimeCheck.cxx b/Private/Source/RuntimeCheck.cxx index 664e3d75..03660076 100644 --- a/Private/Source/RuntimeCheck.cxx +++ b/Private/Source/RuntimeCheck.cxx @@ -25,7 +25,7 @@ extern "C" [[noreturn]] void ke_wait_for_debugger() { namespace HCore { void ke_stop(const HCore::Int &id) { kcout << "*** STOP *** \r\n"; - kcout << "*** HCoreKrnl.exe has trigerred a runtime breakpoint. *** \r\n"; + kcout << "*** HCoreKrnl.exe has trigerred a runtime stop. *** \r\n"; switch (id) { case RUNTIME_CHECK_PROCESS: { @@ -72,9 +72,8 @@ void ke_stop(const HCore::Int &id) { void ke_runtime_check(bool expr, const char *file, const char *line) { if (!expr) { #ifdef __DEBUG__ - kcout << "[KERNEL] Check Failed!\n"; - kcout << "[KERNEL] File: " << file << "\n"; - kcout << "[KERNEL] Where: " << line << "\n"; + kcout << "Krnl: File: " << file << "\n"; + kcout << "Krnl: Line: " << line << "\n"; #endif // __DEBUG__ |
