diff options
| author | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-05 11:12:42 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlalelmahrouss@icloud.com> | 2024-02-05 11:12:42 +0100 |
| commit | 81144dd05a7c01701c3bf7b04e345dccfef2bf82 (patch) | |
| tree | 163bd79816e97ca31484df86c008af3f9a803ffd | |
| parent | f8c9b81ff120160af60af6e9d44cba338aceb65a (diff) | |
HCR-11:
Kernel: Improvements and more.
Bootloader: Now works on real hardware (previous commit.)
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
| -rw-r--r-- | Private/KernelKit/FileManager.hpp | 12 | ||||
| -rw-r--r-- | Private/KernelKit/PEF.hpp | 4 | ||||
| -rw-r--r-- | Private/KernelKit/SMPManager.hpp | 8 | ||||
| -rw-r--r-- | Private/KernelKit/ThreadLocalStorage.hxx | 12 | ||||
| -rw-r--r-- | Private/NewKit/OwnPtr.hpp | 77 | ||||
| -rw-r--r-- | Private/Source/PEFCodeManager.cxx | 2 | ||||
| -rw-r--r-- | Private/Source/ProcessManager.cxx | 8 | ||||
| -rw-r--r-- | Private/Source/SMPManager.cxx | 11 |
8 files changed, 83 insertions, 51 deletions
diff --git a/Private/KernelKit/FileManager.hpp b/Private/KernelKit/FileManager.hpp index a52daa7d..d31cdf68 100644 --- a/Private/KernelKit/FileManager.hpp +++ b/Private/KernelKit/FileManager.hpp @@ -162,7 +162,7 @@ class NewFilesystemManager final : public IFilesystemManager { template <typename Encoding = char, typename FSClass = IFilesystemManager> class FileStream final { public: - explicit FileStream(const Encoding *path); + explicit FileStream(const Encoding *path, const Encoding *restrict_type); ~FileStream(); public: @@ -224,12 +224,18 @@ class FileStream final { const Char *fMime{"application-type/*"}; }; +#define kRestrictRW "r+" +#define kRestrictRWB "r+b" +#define kRestrictR "r" +#define kRestrictRB "rb" + using FileStreamUTF8 = FileStream<char>; using FileStreamUTF16 = FileStream<wchar_t>; template <typename Encoding, typename Class> -FileStream<Encoding, Class>::FileStream(const Encoding *path) - : fFile(Class::GetMounted()->Open(path, "r+")) {} +FileStream<Encoding, Class>::FileStream(const Encoding *path, + const Encoding *restrict_type) + : fFile(Class::GetMounted()->Open(path, restrict_type)) {} template <typename Encoding, typename Class> FileStream<Encoding, Class>::~FileStream() = default; diff --git a/Private/KernelKit/PEF.hpp b/Private/KernelKit/PEF.hpp index 1add45f8..2ffc057f 100644 --- a/Private/KernelKit/PEF.hpp +++ b/Private/KernelKit/PEF.hpp @@ -37,8 +37,8 @@ enum { kPefArchIntel86S, kPefArchAMD64, kPefArchRISCV, - kPefArch64x0, /* 64x000. */ - kPefArch32x0, + kPefArch64x0, /* 64x0. ISA */ + kPefArch32x0, /* 32x0. ISA */ kPefArchCount = (kPefArch32x0 - kPefArchIntel86S) + 1, kPefArchInvalid = 0xFF, }; diff --git a/Private/KernelKit/SMPManager.hpp b/Private/KernelKit/SMPManager.hpp index 0a71a165..8cbe3259 100644 --- a/Private/KernelKit/SMPManager.hpp +++ b/Private/KernelKit/SMPManager.hpp @@ -14,6 +14,8 @@ #include <CompilerKit/CompilerKit.hpp> #include <NewKit/Ref.hpp> +#include "NewKit/Defines.hpp" + #define kMaxHarts 8 namespace HCore { @@ -25,6 +27,8 @@ enum ThreadKind { kFallback, // fallback thread, cannot be used by user if not clear or used by // kernel. kBoot, // The core we booted from, the mama. + kInvalidThread, + kThreadCount, }; /// @@ -100,7 +104,9 @@ class SMPManager final { private: Array<HardwareThread, kMaxHarts> m_ThreadList; - ThreadID m_CurrentThread; + ThreadID m_CurrentThread{0}; + SizeT m_UsedThreads{0}; + SizeT m_MaxThreads{0}; }; // @brief wakes up thread. diff --git a/Private/KernelKit/ThreadLocalStorage.hxx b/Private/KernelKit/ThreadLocalStorage.hxx index 5db78ca3..e7c55ee7 100644 --- a/Private/KernelKit/ThreadLocalStorage.hxx +++ b/Private/KernelKit/ThreadLocalStorage.hxx @@ -27,16 +27,16 @@ bool hcore_tls_delete_ptr(T *ptr); template <typename T, typename... Args> T *hcore_tls_new_class(Args &&...args); -typedef char rt_cookie_type[3]; +typedef HCore::Char rt_cookie_type[3]; /// @brief Thread Information Block for Local Storage. /// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64) struct ThreadInformationBlock final { - HCore::Char Name[255]; // Module Name - HCore::UIntPtr StartCode; // Start Address - HCore::UIntPtr StartData; // Allocation Heap - HCore::UIntPtr StartStack; // Stack Pointer. - HCore::Int32 Arch; // Architecture and/or platform. + HCore::Char Name[kNameLen]; // Module Name + HCore::UIntPtr StartCode; // Start Address + HCore::UIntPtr StartData; // Allocation Heap + HCore::UIntPtr StartStack; // Stack Pointer. + HCore::Int32 Arch; // Architecture and/or platform. rt_cookie_type Cookie; // Not shown in public header, this is the way we tell // something went wrong. }; diff --git a/Private/NewKit/OwnPtr.hpp b/Private/NewKit/OwnPtr.hpp index 72a37244..e24eba3e 100644 --- a/Private/NewKit/OwnPtr.hpp +++ b/Private/NewKit/OwnPtr.hpp @@ -11,57 +11,60 @@ #pragma once #include <NewKit/Defines.hpp> -#include <NewKit/RuntimeCheck.hpp> #include <NewKit/Ref.hpp> +#include <NewKit/RuntimeCheck.hpp> -namespace HCore -{ -template <typename T> class OwnPtr; +namespace HCore { +template <typename T> +class OwnPtr; -template <typename T> class NonNullRefPtr; +template <typename T> +class NonNullRefPtr; -template <typename T> class OwnPtr final -{ - public: - OwnPtr() {} - ~OwnPtr() { this->Delete(); } +template <typename T> +class OwnPtr final { + public: + OwnPtr() {} + ~OwnPtr() { this->Delete(); } - OwnPtr &operator=(const OwnPtr &) = default; - OwnPtr(const OwnPtr &) = default; + OwnPtr &operator=(const OwnPtr &) = default; + OwnPtr(const OwnPtr &) = default; - public: - template <typename... Args> bool New(Args &&...arg) - { - m_Cls = new T(arg...); - return m_Cls; + public: + template <typename... Args> + bool New(Args &&...arg) { + if (m_Cls) { + return false; } - void Delete() - { - if (m_Cls) - delete m_Cls; + m_Cls = new T(arg...); + return m_Cls; + } - m_Cls = nullptr; - } + void Delete() { + if (m_Cls) delete m_Cls; + + m_Cls = nullptr; + } - T *operator->() const { return m_Cls; }; - T *Raw() { return m_Cls; } + T *operator->() const { return m_Cls; }; + T *Raw() { return m_Cls; } - Ref<T> AsRef() { return Ref<T>(m_Cls); } + Ref<T> AsRef() { return Ref<T>(m_Cls); } - operator bool() { return m_Cls; } - bool operator!() { return !m_Cls; } + operator bool() { return m_Cls; } + bool operator!() { return !m_Cls; } - private: - T *m_Cls; + private: + T *m_Cls; }; -template <typename T, typename... Args> OwnPtr<T> make_ptr(Args... args) -{ - OwnPtr<T> ret; - ret.template New<Args...>(forward(args)...); - MUST_PASS(ret); +template <typename T, typename... Args> +OwnPtr<T> make_ptr(Args... args) { + OwnPtr<T> ret; + ret.template New<Args...>(forward(args)...); + MUST_PASS(ret); - return ret; + return ret; } -} // namespace HCore +} // namespace HCore diff --git a/Private/Source/PEFCodeManager.cxx b/Private/Source/PEFCodeManager.cxx index efebef48..347f7f7a 100644 --- a/Private/Source/PEFCodeManager.cxx +++ b/Private/Source/PEFCodeManager.cxx @@ -43,7 +43,7 @@ PEFLoader::PEFLoader(const VoidPtr blob) : fCachedBlob(nullptr) { PEFLoader::PEFLoader(const char *path) : fCachedBlob(nullptr), fBad(false) { OwnPtr<FileStream<char>> file; - file.New(const_cast<Char *>(path)); + file.New(const_cast<Char *>(path), kRestrictRB); if (StringBuilder::Equals(file->MIME(), this->MIME())) { fPath = StringBuilder::Construct(path).Leak(); diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx index 0c552b7f..ea9ba1f5 100644 --- a/Private/Source/ProcessManager.cxx +++ b/Private/Source/ProcessManager.cxx @@ -241,6 +241,9 @@ bool ProcessHelper::CanBeScheduled(Ref<Process> &process) { return process.Leak().PTime > static_cast<Int>(kMinMicroTime); } +/** + * @brief Scheduler spin code. + */ bool ProcessHelper::StartScheduling() { if (ProcessHelper::CanBeScheduled( ProcessManager::Shared().Leak().GetCurrent())) { @@ -256,7 +259,7 @@ bool ProcessHelper::StartScheduling() { SizeT ret = process_ref.Run(); kcout << StringBuilder::FromInt( - "ProcessHelper::StartScheduling() iterated over: % processes\r\n", ret); + "ProcessHelper::StartScheduling() Iterated over: % processes.\r\n", ret); return true; } @@ -265,6 +268,9 @@ bool ProcessHelper::Switch(HAL::StackFrame *the_stack, const PID &new_pid) { if (!the_stack || new_pid < 0) return false; for (SizeT index = 0UL; index < kMaxHarts; ++index) { + if (SMPManager::Shared().Leak()[index].Leak().Kind() == kInvalidThread) + continue; + if (SMPManager::Shared().Leak()[index].Leak().StackFrame() == the_stack) { SMPManager::Shared().Leak()[index].Leak().Busy(false); continue; diff --git a/Private/Source/SMPManager.cxx b/Private/Source/SMPManager.cxx index 87e82da1..d3c7a4c8 100644 --- a/Private/Source/SMPManager.cxx +++ b/Private/Source/SMPManager.cxx @@ -128,6 +128,17 @@ bool SMPManager::Switch(HAL::StackFrame* stack) { * @return the reference to the hardware thread. */ Ref<HardwareThread> SMPManager::operator[](const SizeT& idx) { + if (idx == 0) { + if (m_ThreadList[idx].Leak().Leak().Kind() != kSystemReserved) { + m_ThreadList[idx].Leak().Leak().m_Kind = kBoot; + } + } else if (idx >= kMaxHarts) { + HardwareThread fakeThread; + fakeThread.m_Kind = kInvalidThread; + + return {fakeThread}; + } + return m_ThreadList[idx].Leak(); } |
