From e2bbec91d70847cc5a2ff67eb84ca4a3c2d03e85 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 4 Feb 2024 10:59:24 +0100 Subject: Kernel: Depend less on NewFS, add support for FileSystem protocol in NewBoot. Signed-off-by: Amlal El Mahrouss --- Private/Source/HError.cxx | 10 ++++++++++ Private/Source/KernelHeap.cxx | 12 +++++------- Private/Source/NewFS-IO.cxx | 7 +++++-- Private/Source/NewFS-Journal.cxx | 7 ++++++- Private/Source/NewFS.cxx | 9 ++++++++- Private/Source/OSErr.cxx | 10 ---------- Private/Source/PEFSharedObjectRT.cxx | 4 +++- Private/Source/Storage/ATA.cxx | 8 ++++++++ Private/Source/UserHeap.cxx | 14 ++++++++------ 9 files changed, 53 insertions(+), 28 deletions(-) create mode 100644 Private/Source/HError.cxx delete mode 100644 Private/Source/OSErr.cxx (limited to 'Private/Source') diff --git a/Private/Source/HError.cxx b/Private/Source/HError.cxx new file mode 100644 index 00000000..000843df --- /dev/null +++ b/Private/Source/HError.cxx @@ -0,0 +1,10 @@ +/* + * ======================================================== + * + * HCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx index 3c3cb9ce..72aa2d67 100644 --- a/Private/Source/KernelHeap.cxx +++ b/Private/Source/KernelHeap.cxx @@ -21,7 +21,7 @@ static Ref kLastWrapper; static Pmm kPmm; namespace Detail { -static voidPtr find_ptr(const SizeT &sz, const bool rw, const bool user) { +STATIC voidPtr ke_find_heap(const SizeT &sz, const bool rw, const bool user) { for (SizeT indexWrapper = 0; indexWrapper < kMaxWrappers; ++indexWrapper) { if (!kWrapperList[indexWrapper]->Present()) { kWrapperList[indexWrapper] @@ -35,21 +35,19 @@ static voidPtr find_ptr(const SizeT &sz, const bool rw, const bool user) { } } // namespace Detail -/// @brief manual allocation +/// @brief Page allocation routine. /// @param sz size of pointer /// @param rw read write (true to enable it) /// @param user is it accesible by user processes? /// @return the pointer -VoidPtr ke_new_ke_heap(const SizeT &sz, const bool rw, const bool user) { - if (kWrapperCount < sz) return nullptr; +VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) { + if (sz == 0) ++sz; - if (auto ptr = Detail::find_ptr(sz, rw, user); ptr) return ptr; + if (auto ptr = Detail::ke_find_heap(sz, rw, user); ptr) return ptr; Ref wrapper = kPmm.RequestPage(user, rw); if (wrapper) { - wrapper->NoExecute(true); - kLastWrapper = wrapper; kWrapperList[kWrapperCount] = wrapper; diff --git a/Private/Source/NewFS-IO.cxx b/Private/Source/NewFS-IO.cxx index 2c044def..e90ed1a4 100644 --- a/Private/Source/NewFS-IO.cxx +++ b/Private/Source/NewFS-IO.cxx @@ -7,10 +7,13 @@ * ======================================================== */ -#include #include #include -/// @brief this implements NewFS with Device Abstraction in mind. +#ifdef __USE_NEWFS__ + +/// @brief This implements NewFS with Device Abstraction in mind. /// bugs 0 + +#endif // ifdef __USE_NEWFS__ diff --git a/Private/Source/NewFS-Journal.cxx b/Private/Source/NewFS-Journal.cxx index 029e051a..72812b6e 100644 --- a/Private/Source/NewFS-Journal.cxx +++ b/Private/Source/NewFS-Journal.cxx @@ -7,9 +7,12 @@ * ======================================================== */ -#include #include +#include +#ifdef __USE_NEWFS__ + +//! bugs: 0 //! @brief Journaling for NewFS. #define kOpCache (4) @@ -57,3 +60,5 @@ class NewFSJournalRunner final { } }; } // namespace HCore + +#endif // ifdef __USE_NEWFS__ diff --git a/Private/Source/NewFS.cxx b/Private/Source/NewFS.cxx index 114c1e6b..2cb4fae9 100644 --- a/Private/Source/NewFS.cxx +++ b/Private/Source/NewFS.cxx @@ -7,9 +7,10 @@ * ======================================================== */ -#include #include +#ifdef __USE_NEWFS__ + namespace HCore { NewFilesystemManager::NewFilesystemManager() = default; @@ -40,4 +41,10 @@ NodePtr NewFilesystemManager::CreateDirectory(const char* path) { NodePtr NewFilesystemManager::CreateAlias(const char* path) { return node_cast(fImpl->CreateCatalog(path, 0, kCatalogKindAlias)); } + +const char* NewFilesystemHelper::Root() { return kFilesystemRoot; } +const char* NewFilesystemHelper::UpDir() { return kFilesystemUpDir; } +const char NewFilesystemHelper::Separator() { return kFilesystemSeparator; } } // namespace HCore + +#endif // ifdef __USE_NEWFS__ diff --git a/Private/Source/OSErr.cxx b/Private/Source/OSErr.cxx deleted file mode 100644 index 26a9ae7e..00000000 --- a/Private/Source/OSErr.cxx +++ /dev/null @@ -1,10 +0,0 @@ -/* - * ======================================================== - * - * HCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include diff --git a/Private/Source/PEFSharedObjectRT.cxx b/Private/Source/PEFSharedObjectRT.cxx index 035b068f..c13314df 100644 --- a/Private/Source/PEFSharedObjectRT.cxx +++ b/Private/Source/PEFSharedObjectRT.cxx @@ -66,7 +66,7 @@ extern "C" SharedObject *__LibInit() { library->Get()->fImageEntrypointOffset = library->Load(kPefStart, string_length(kPefStart, 0), kPefCode); - kcout << "__LibInit: Task was successful... Returning library...\n"; + kcout << "__LibInit: Task was successful!\n"; return library; } @@ -94,6 +94,8 @@ extern "C" Void __LibFini(SharedObjectPtr lib, bool *successful) { lib = nullptr; + kcout << "__LibFini: Task was successful!\n"; + *successful = true; } diff --git a/Private/Source/Storage/ATA.cxx b/Private/Source/Storage/ATA.cxx index 7d8ce32f..47c05ac8 100644 --- a/Private/Source/Storage/ATA.cxx +++ b/Private/Source/Storage/ATA.cxx @@ -40,6 +40,8 @@ enum { }; const char* ata_read_28(ULong lba) { + if (!kPrdt) return nullptr; + static char buffer[512]; UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); @@ -56,6 +58,8 @@ const char* ata_read_28(ULong lba) { #define kBufferLen 512 const char* ata_read_48(ULong lba) { + if (!kPrdt) return nullptr; + static char buffer[kBufferLen]; rt_set_memory(buffer, 0, kBufferLen); @@ -71,6 +75,8 @@ const char* ata_read_48(ULong lba) { } Int32 ata_write_48(ULong lba, const char* buffer) { + if (!kPrdt) return kATAError; + UIntPtr* packet = reinterpret_cast(kPrdt.Leak()->PhysicalAddress()); packet[0] = k48BitWrite; @@ -83,6 +89,8 @@ Int32 ata_write_48(ULong lba, const char* buffer) { } Int32 ata_write_28(ULong lba, const char* text) { + if (!kPrdt) return kATAError; + UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); packet[0] = k28BitWrite; diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx index e22fe4f9..6a173a44 100644 --- a/Private/Source/UserHeap.cxx +++ b/Private/Source/UserHeap.cxx @@ -12,8 +12,8 @@ /// @file Heap.cxx /// @brief Heap Manager, Process heap allocator. -/// @note if you want to look at the kernel allocator, please look for KernelHeap.cxx -/// bugs: 0 +/// @note if you want to look at the kernel allocator, please look for +/// KernelHeap.cxx bugs: 0 namespace HCore { /** @@ -105,10 +105,10 @@ STATIC void ke_free_heap_internal(voidPtr virtualAddress) { /** * @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. + * @return Boolean true if successful. */ STATIC Boolean ke_check_and_free_heap(const SizeT& index, voidPtr ptr) { if (HeapManager::The()[index]) { @@ -143,8 +143,8 @@ voidPtr ke_new_heap(Int32 flags) { 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)), (flags & kPoolRw)); + auto ref_page = HeapManager::Leak().Leak().RequestPage(((flags & kPoolUser)), + (flags & kPoolRw)); if (ref_page) { ///! reserve page. @@ -153,6 +153,8 @@ 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(ref_page.Leak()->VirtualAddress()), flags); -- cgit v1.2.3