diff options
| author | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-08 08:18:37 +0200 |
|---|---|---|
| committer | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-08 08:18:37 +0200 |
| commit | df8a42aa1266d953a9ee473afe9f6349bd1837c7 (patch) | |
| tree | cad53c222ca90ee98ac82ee2d630a4ff0b0c3ee3 | |
| parent | 884ea5c2d43b6c8d4c2bb4fc33c11dc2313eeca2 (diff) | |
[dev/FeatureAdd] Add mm_new_class, as C++ new doesn't initialize class directly.
[dev/FeatureFix] CR2 set to invalid address due to stack corruption, fixing that.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
| -rw-r--r-- | dev/ZBA/amd64-efi.make | 2 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx | 6 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalProcessor.cxx | 32 | ||||
| -rw-r--r-- | dev/ZKA/KernelKit/FileMgr.hxx | 20 | ||||
| -rw-r--r-- | dev/ZKA/KernelKit/HardwareThreadScheduler.hxx | 5 | ||||
| -rw-r--r-- | dev/ZKA/KernelKit/Heap.hxx | 10 | ||||
| -rw-r--r-- | dev/ZKA/KernelKit/UserProcessScheduler.hxx | 19 | ||||
| -rw-r--r-- | dev/ZKA/Modules/MBCI/MBCI.hxx | 8 | ||||
| -rw-r--r-- | dev/ZKA/NewKit/Macros.hxx | 6 | ||||
| -rw-r--r-- | dev/ZKA/Sources/CodeMgr.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/Sources/ExeMain.cxx | 17 | ||||
| -rw-r--r-- | dev/ZKA/Sources/FileMgr.cxx | 8 | ||||
| -rw-r--r-- | dev/ZKA/Sources/HardwareThreadScheduler.cxx | 5 | ||||
| -rw-r--r-- | dev/ZKA/Sources/NeFS+FileMgr.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/Sources/UserProcessScheduler.cxx | 60 |
16 files changed, 117 insertions, 87 deletions
diff --git a/dev/ZBA/amd64-efi.make b/dev/ZBA/amd64-efi.make index 8da2b05a..d7d5132e 100644 --- a/dev/ZBA/amd64-efi.make +++ b/dev/ZBA/amd64-efi.make @@ -36,7 +36,7 @@ EMU_FLAGS=-net none -m 8G -M q35 \ file=fat:rw:Sources/Root/,index=2,format=raw \ -drive id=disk_2,file=$(IMG_2),if=none \ -device ahci,id=ahci \ - -device ide-hd,drive=disk_2,bus=ahci.0 -no-reboot -no-shutdown + -device ide-hd,drive=disk_2,bus=ahci.0 -no-reboot -no-shutdown -d int LD_FLAGS=-e Main --subsystem=10 diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx index df5317e5..e6d5d292 100644 --- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx +++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx @@ -122,7 +122,7 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept kcout << "Creating filesystem and such.\r"; - auto fs = new Kernel::NewFilesystemMgr(); + auto fs = Kernel::mm_new_class<Kernel::NewFilesystemMgr>(); MUST_PASS(fs); diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx index b0d444d9..3cd7ab0f 100644 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx +++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx @@ -31,9 +31,9 @@ #endif // !kAlign EXTERN_C void hal_flush_tlb(); -EXTERN_C void hal_invl_tlb(Kernel::UIntPtr addr); -EXTERN_C void hal_write_cr3(Kernel::UIntPtr pml4); -EXTERN_C void hal_write_cr0(Kernel::UIntPtr bit); +EXTERN_C void hal_invl_tlb(Kernel::VoidPtr addr); +EXTERN_C void hal_write_cr3(Kernel::VoidPtr cr3); +EXTERN_C void hal_write_cr0(Kernel::VoidPtr bit); EXTERN_C Kernel::VoidPtr hal_read_cr0(); // @brief CPU control register. EXTERN_C Kernel::VoidPtr hal_read_cr2(); // @brief Fault address. diff --git a/dev/ZKA/HALKit/AMD64/HalProcessor.cxx b/dev/ZKA/HALKit/AMD64/HalProcessor.cxx index fa634406..b31f58e2 100644 --- a/dev/ZKA/HALKit/AMD64/HalProcessor.cxx +++ b/dev/ZKA/HALKit/AMD64/HalProcessor.cxx @@ -25,33 +25,39 @@ namespace Kernel::HAL { VoidPtr pml4_base = hal_read_cr3(); - UIntPtr pd_idx = ((UIntPtr)virt_addr >> 22); - UIntPtr pte_idx = ((UIntPtr)virt_addr >> 12) & 0x3FFF; - // Now PD - volatile UInt64* pd_entry = (volatile UInt64*)(((UInt64)pml4_base) + pd_idx * sizeof(UIntPtr)); + UIntPtr pd_idx = ((UIntPtr)virt_addr >> 22); + UIntPtr pte_idx = ((UIntPtr)virt_addr >> 12) & 0x03FF; - kcout << (*pd_entry & 0x01 ? "Dir Present." : "Dir Not present.") << endl; + // Now get pd_entry + volatile UInt64* pd_entry = (volatile UInt64*)(((UInt64)pml4_base) + (pd_idx * kPTEAlign)); // Don't bother allocate directory. if (!(*pd_entry & 0x01)) { - ke_stop(RUNTIME_CHECK_PAGE); + ke_stop(RUNTIME_CHECK_PAGE); } - UInt64 pt_base = *pd_entry & ~0xFFF; // Remove flags + UInt64 pt_base = pd_entry[pd_idx] & ~0xFFF; // Remove flags // And then PTE - volatile UIntPtr* page_addr = (volatile UIntPtr*)(((UInt64)pt_base) + (pte_idx * sizeof(UIntPtr))); + volatile UIntPtr* pt_entry = (volatile UIntPtr*)(pt_base + (pte_idx * kPTEAlign)); - kcout << (*page_addr & 0x01 ? "Page Present." : "Page Not Present.") << endl; - kcout << (*page_addr & 0x04 ? "User." : "Not User.") << endl; + kcout << (pt_entry[pte_idx] & 0x01 ? "Page Present." : "Page Not Present.") << endl; + kcout << (pt_entry[pte_idx] & 0x02 ? "Page RW." : "Page Not RW.") << endl; + kcout << (pt_entry[pte_idx] & 0x04 ? "Page User." : "Page Not User.") << endl; - if (phys_addr == nullptr) + switch ((UIntPtr)phys_addr) { - phys_addr = (VoidPtr)((*page_addr & ~0xFFF) + ((UIntPtr)virt_addr & 0xFFF)); + case kBadAddress: { + phys_addr = (VoidPtr)((pt_entry[pte_idx] & ~0xFFF) + ((UIntPtr)virt_addr & 0xFFF)); + break; + } + default: { + break; + } } - (*page_addr) = ((UIntPtr)phys_addr) | (flags & 0xFFF) | 0x01; + pt_entry[pte_idx] = ((UIntPtr)phys_addr) | (flags & 0xFFF) | 0x01; return 0; } diff --git a/dev/ZKA/KernelKit/FileMgr.hxx b/dev/ZKA/KernelKit/FileMgr.hxx index 86eade6a..5b2b8fa8 100644 --- a/dev/ZKA/KernelKit/FileMgr.hxx +++ b/dev/ZKA/KernelKit/FileMgr.hxx @@ -74,28 +74,28 @@ namespace Kernel @brief Filesystem Mgr Interface class @brief Used to provide common I/O for a specific filesystem. */ - class FilesystemMgrInterface + class IFilesystemMgr { public: - explicit FilesystemMgrInterface() = default; - virtual ~FilesystemMgrInterface() = default; + explicit IFilesystemMgr() = default; + virtual ~IFilesystemMgr() = default; public: - ZKA_COPY_DEFAULT(FilesystemMgrInterface); + ZKA_COPY_DEFAULT(IFilesystemMgr); public: /// @brief Mounts a new filesystem into an active state. /// @param interface the filesystem interface /// @return - static bool Mount(FilesystemMgrInterface* interface); + static bool Mount(IFilesystemMgr* interface); /// @brief Unmounts the active filesystem /// @return - static FilesystemMgrInterface* Unmount(); + static IFilesystemMgr* Unmount(); /// @brief Getter, gets the active filesystem. /// @return - static FilesystemMgrInterface* GetMounted(); + static IFilesystemMgr* GetMounted(); public: virtual NodePtr Create(_Input const Char* path) = 0; @@ -137,10 +137,10 @@ namespace Kernel #ifdef __FSKIT_USE_NEFS__ /** - * @brief Based of FilesystemMgrInterface, takes care of managing NeFS + * @brief Based of IFilesystemMgr, takes care of managing NeFS * disks. */ - class NewFilesystemMgr final : public FilesystemMgrInterface + class NewFilesystemMgr final : public IFilesystemMgr { public: explicit NewFilesystemMgr(); @@ -192,7 +192,7 @@ namespace Kernel * @tparam FSClass Filesystem contract who takes care of it. */ template <typename Encoding = Char, - typename FSClass = FilesystemMgrInterface> + typename FSClass = IFilesystemMgr> class FileStream final { public: diff --git a/dev/ZKA/KernelKit/HardwareThreadScheduler.hxx b/dev/ZKA/KernelKit/HardwareThreadScheduler.hxx index f5b64883..e4b83659 100644 --- a/dev/ZKA/KernelKit/HardwareThreadScheduler.hxx +++ b/dev/ZKA/KernelKit/HardwareThreadScheduler.hxx @@ -88,11 +88,10 @@ namespace Kernel class HardwareThreadScheduler final { private: - explicit HardwareThreadScheduler(); - friend class UserProcessHelper; public: + explicit HardwareThreadScheduler(); ~HardwareThreadScheduler(); ZKA_COPY_DEFAULT(HardwareThreadScheduler); @@ -102,7 +101,7 @@ namespace Kernel public: Ref<HardwareThread*> operator[](const SizeT& idx); bool operator!() noexcept; - operator bool() noexcept; + operator bool() noexcept; public: /// @brief Shared instance of the MP Mgr. diff --git a/dev/ZKA/KernelKit/Heap.hxx b/dev/ZKA/KernelKit/Heap.hxx index 27c79c83..f9d2df06 100644 --- a/dev/ZKA/KernelKit/Heap.hxx +++ b/dev/ZKA/KernelKit/Heap.hxx @@ -44,8 +44,16 @@ namespace Kernel /// @brief Makes a Kernel page. /// @param heap_ptr the page pointer. - /// @return + /// @return status code Int32 mm_make_ke_page(VoidPtr heap_ptr); + + + template <typename T, typename... Args> + inline T* mm_new_class(Args&&... args) + { + T* ptr = new T(move(args)...); + return ptr; + } } // namespace Kernel #endif // !_INC_KERNEL_HEAP_HXX_ diff --git a/dev/ZKA/KernelKit/UserProcessScheduler.hxx b/dev/ZKA/KernelKit/UserProcessScheduler.hxx index c35b65e1..845c0081 100644 --- a/dev/ZKA/KernelKit/UserProcessScheduler.hxx +++ b/dev/ZKA/KernelKit/UserProcessScheduler.hxx @@ -150,7 +150,7 @@ namespace Kernel UInt8* StackReserve{nullptr}; // Memory, images pointers. - ImagePtr Image{nullptr}; + ImagePtr Image{nullptr}; SizeT StackSize{mib_cast(8)}; @@ -168,9 +168,9 @@ namespace Kernel { VoidPtr MemoryEntry; - struct PROCESS_MEMORY_ENTRY *MemoryPrev; - struct PROCESS_MEMORY_ENTRY *MemoryNext; - } * MemoryEntryList{nullptr}; + struct PROCESS_MEMORY_ENTRY* MemoryPrev; + struct PROCESS_MEMORY_ENTRY* MemoryNext; + }* MemoryEntryList{nullptr}; SizeT MemoryPD{0}; @@ -259,6 +259,8 @@ namespace Kernel /// The main class which you call to schedule processes. class UserProcessScheduler final { + friend class UserProcessHelper; + public: explicit UserProcessScheduler() = default; @@ -266,14 +268,14 @@ namespace Kernel ZKA_COPY_DEFAULT(UserProcessScheduler) - operator bool(); + operator bool(); bool operator!(); public: UserProcessTeam& CurrentTeam(); public: - SizeT Add(UserProcess& processRef); + SizeT Add(UserProcess processRef); Bool Remove(ProcessID processSlot); public: @@ -294,11 +296,10 @@ namespace Kernel class UserProcessHelper final { public: - STATIC bool Switch(VoidPtr image_ptr, UInt8* stack_ptr, HAL::StackFramePtr frame_ptr, const PID& new_pid); - STATIC bool CanBeScheduled(const UserProcess process); + STATIC bool Switch(VoidPtr image_ptr, UInt8* stack_ptr, HAL::StackFramePtr frame_ptr, const PID& new_pid); + STATIC bool CanBeScheduled(const UserProcess& process); STATIC PID& TheCurrentPID(); STATIC SizeT StartScheduling(); - }; const UInt32& sched_get_exit_code(void) noexcept; diff --git a/dev/ZKA/Modules/MBCI/MBCI.hxx b/dev/ZKA/Modules/MBCI/MBCI.hxx index 6e15762e..8f6a7f01 100644 --- a/dev/ZKA/Modules/MBCI/MBCI.hxx +++ b/dev/ZKA/Modules/MBCI/MBCI.hxx @@ -26,11 +26,11 @@ namespace Kernel { - struct MBCIHostInterface; - struct MBCIHostInterfacePacketFrame; + struct IMBCIHost; + struct IMBCIHostPacketFrame; /// @brief MBCI Packet frame header - struct PACKED MBCIHostInterfacePacketFrame final + struct PACKED IMBCIHostPacketFrame final { UInt32 Magic; UInt32 HostId; @@ -51,7 +51,7 @@ namespace Kernel }; /// @brief MBCI Host Interface header. - struct PACKED MBCIHostInterface final + struct PACKED IMBCIHost final { UInt32 Magic; UInt32 HostId; diff --git a/dev/ZKA/NewKit/Macros.hxx b/dev/ZKA/NewKit/Macros.hxx index b20ddb8a..9643ae67 100644 --- a/dev/ZKA/NewKit/Macros.hxx +++ b/dev/ZKA/NewKit/Macros.hxx @@ -94,10 +94,10 @@ #define CANT_REACH() __builtin_unreachable() #endif -#define kInvalidAddress 0xFBFBFBFBFBFBFBFB +#define kInvalidAddress 0xFBFBFBFBFBFBFBFB #define kBadAddress 0x00000000000000 #define kMaxAddr 0xFFFFFFFFFFFFFFFF -#define kPathLen 255 +#define kPathLen 256 #define PACKED ATTRIBUTE(packed) #define NO_EXEC ATTRIBUTE(noexec) @@ -126,3 +126,5 @@ /// @brief The main kernel file. #define kSysChime "\\System\\startup.wav" +/// @brief The main system loader. +#define kSysLdr "SystemLdr" diff --git a/dev/ZKA/Sources/CodeMgr.cxx b/dev/ZKA/Sources/CodeMgr.cxx index 8e560408..13bcd640 100644 --- a/dev/ZKA/Sources/CodeMgr.cxx +++ b/dev/ZKA/Sources/CodeMgr.cxx @@ -23,7 +23,7 @@ namespace Kernel proc.SetImageStart(reinterpret_cast<VoidPtr>(main)); proc.Kind = UserProcess::kExeKind; - proc.StackSize = mib_cast(4); + proc.StackSize = kib_cast(32); rt_set_memory(proc.Name, 0, kProcessLen); rt_copy_memory((VoidPtr)process_name, proc.Name, rt_string_len(process_name)); diff --git a/dev/ZKA/Sources/ExeMain.cxx b/dev/ZKA/Sources/ExeMain.cxx index 53865db7..e1b6afc1 100644 --- a/dev/ZKA/Sources/ExeMain.cxx +++ b/dev/ZKA/Sources/ExeMain.cxx @@ -50,17 +50,17 @@ namespace Kernel::Detail /// @brief wizard constructor. explicit FilesystemInstaller() { - if (Kernel::FilesystemMgrInterface::GetMounted()) + if (Kernel::IFilesystemMgr::GetMounted()) { CG::CGDrawStringToWnd(cKernelWnd, "NeFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); - fNeFS = reinterpret_cast<Kernel::NewFilesystemMgr*>(Kernel::FilesystemMgrInterface::GetMounted()); + fNeFS = reinterpret_cast<Kernel::NewFilesystemMgr*>(Kernel::IFilesystemMgr::GetMounted()); } else { // Mounts a NeFS from main drive. fNeFS = new Kernel::NewFilesystemMgr(); - Kernel::FilesystemMgrInterface::Mount(fNeFS); + Kernel::IFilesystemMgr::Mount(fNeFS); CG::CGDrawStringToWnd(cKernelWnd, "Mounted NeFS IFS (A:)", 10, 10, RGB(0, 0, 0)); } @@ -154,15 +154,12 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) CG::CGDrawWindowList(&cKernelWnd, 1); - CG::CGDrawStringToWnd(cKernelWnd, "Running System Component: ", 10, 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, kSysDrv, 10, 10 + (FONT_SIZE_X * Kernel::rt_string_len("Running System Component: ")), RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Running: ", 10, 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, kSysLdr, 10, 10 + (FONT_SIZE_X * Kernel::rt_string_len("Running: ")), RGB(0, 0, 0)); Kernel::UserProcessHelper::StartScheduling(); - Kernel::sched_execute_thread((Kernel::MainKind)HangCPU, "HANG TEST"); + Kernel::sched_execute_thread(HangCPU, kSysLdr); - while (Yes) - { - Kernel::UserProcessHelper::StartScheduling(); - } + Kernel::UserProcessHelper::StartScheduling(); } diff --git a/dev/ZKA/Sources/FileMgr.cxx b/dev/ZKA/Sources/FileMgr.cxx index 3e3977ab..eff3c334 100644 --- a/dev/ZKA/Sources/FileMgr.cxx +++ b/dev/ZKA/Sources/FileMgr.cxx @@ -12,18 +12,18 @@ namespace Kernel { - STATIC FilesystemMgrInterface* kMounted = nullptr; + STATIC IFilesystemMgr* kMounted = nullptr; /// @brief FilesystemMgr getter. /// @return The mounted filesystem. - _Output FilesystemMgrInterface* FilesystemMgrInterface::GetMounted() + _Output IFilesystemMgr* IFilesystemMgr::GetMounted() { return kMounted; } /// @brief Unmount filesystem. /// @return The unmounted filesystem. - _Output FilesystemMgrInterface* FilesystemMgrInterface::Unmount() + _Output IFilesystemMgr* IFilesystemMgr::Unmount() { if (kMounted) { @@ -39,7 +39,7 @@ namespace Kernel /// @brief Mount filesystem. /// @param mount_ptr The filesystem to mount. /// @return if it succeeded true, otherwise false. - bool FilesystemMgrInterface::Mount(_Input FilesystemMgrInterface* mount_ptr) + bool IFilesystemMgr::Mount(_Input IFilesystemMgr* mount_ptr) { if (mount_ptr != nullptr) { diff --git a/dev/ZKA/Sources/HardwareThreadScheduler.cxx b/dev/ZKA/Sources/HardwareThreadScheduler.cxx index 5b310fca..09eadefb 100644 --- a/dev/ZKA/Sources/HardwareThreadScheduler.cxx +++ b/dev/ZKA/Sources/HardwareThreadScheduler.cxx @@ -90,7 +90,10 @@ namespace Kernel if (!frame || !image || !stack_ptr) - return false; + return No; + + if (!this->IsWakeup()) + return No; fStack = frame; diff --git a/dev/ZKA/Sources/NeFS+FileMgr.cxx b/dev/ZKA/Sources/NeFS+FileMgr.cxx index b3ad381f..609f2ece 100644 --- a/dev/ZKA/Sources/NeFS+FileMgr.cxx +++ b/dev/ZKA/Sources/NeFS+FileMgr.cxx @@ -18,7 +18,7 @@ namespace Kernel NewFilesystemMgr::NewFilesystemMgr() { MUST_PASS(Detail::fs_init_newfs()); - fImpl = new NeFSParser(); + fImpl = mm_new_class<NeFSParser>(); MUST_PASS(fImpl); kcout << "We are done here... (NewFilesystemMgr).\r"; diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index eba81677..721bd02f 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -91,11 +91,11 @@ namespace Kernel { #ifdef __ZKA_AMD64__ auto pd = hal_read_cr3(); - hal_write_cr3(this->MemoryPD); + hal_write_cr3(reinterpret_cast<VoidPtr>(this->MemoryPD)); auto ptr = mm_new_ke_heap(sz, Yes, Yes); - hal_write_cr3(reinterpret_cast<UIntPtr>(pd)); + hal_write_cr3(reinterpret_cast<VoidPtr>(pd)); #else auto ptr = mm_new_ke_heap(sz, Yes, Yes); #endif @@ -143,10 +143,10 @@ namespace Kernel { #ifdef __ZKA_AMD64__ auto pd = hal_read_cr3(); - hal_write_cr3(this->MemoryPD); + hal_write_cr3(reinterpret_cast<VoidPtr>(this->MemoryPD)); bool ret = mm_delete_ke_heap(ptr); - hal_write_cr3(reinterpret_cast<UIntPtr>(pd)); + hal_write_cr3(reinterpret_cast<VoidPtr>(pd)); return ret; #else @@ -233,12 +233,17 @@ namespace Kernel /// @brief Add process to list. /// @param process the process *Ref* class. /// @return the process index inside the team. - SizeT UserProcessScheduler::Add(UserProcess& process) + SizeT UserProcessScheduler::Add(UserProcess process) { + if (mTeam.mProcessAmount > kSchedProcessLimitPerTeam) + return 0; + #ifdef __ZKA_AMD64__ process.MemoryPD = reinterpret_cast<UIntPtr>(hal_read_cr3()); #endif // __ZKA_AMD64__ + process.Status = ProcessStatusKind::kStarting; + process.StackFrame = (HAL::StackFramePtr)mm_new_ke_heap(sizeof(HAL::StackFrame), Yes, Yes); if (!process.StackFrame) @@ -268,21 +273,22 @@ namespace Kernel if (!process.StackReserve) { - process.Crash(); + mm_delete_ke_heap(process.StackFrame); + process.StackFrame = nullptr; return -kErrorProcessFault; } - if (mTeam.mProcessAmount > kSchedProcessLimitPerTeam) - mTeam.mProcessAmount = 0UL; - ++mTeam.mProcessAmount; process.ProcessId = mTeam.mProcessAmount; - process.Status = ProcessStatusKind::kStarting; + process.Status = ProcessStatusKind::kRunning; + + // avoid the pitfalls of moving process. + auto ret_pid = process.ProcessId; - mTeam.AsArray()[process.ProcessId] = process; + mTeam.AsArray()[process.ProcessId] = move(process); - return process.ProcessId; + return ret_pid; } /***********************************************************************************/ @@ -318,21 +324,21 @@ namespace Kernel SizeT process_index = 0; //! we store this guy to tell the scheduler how many //! things we have scheduled. - kcout << "Finding available process...\r"; - for (; process_index < mTeam.AsArray().Capacity(); ++process_index) { + kcout << "Grabbing available process...\r"; + auto& process = mTeam.AsArray()[process_index]; //! check if process needs to be scheduled. if (UserProcessHelper::CanBeScheduled(process)) { - // set the current process. - mTeam.AsRef() = process; + kcout << process.Name << ": will be runned.\r"; - process.PTime = static_cast<Int32>(process.Affinity); + // Set current process header. + this->CurrentProcess() = process; - kcout << process.Name << ": will be runned.\r"; + process.PTime = static_cast<Int32>(process.Affinity); // tell helper to find a core to schedule on. if (!UserProcessHelper::Switch(process.Image, &process.StackReserve[process.StackSize - 1], process.StackFrame, @@ -349,6 +355,8 @@ namespace Kernel } } + kcout << "Scheduled Process Count: " << number(process_index) << endl; + return process_index; } @@ -380,13 +388,17 @@ namespace Kernel /// @param process the process reference. /// @retval true can be schedulded. /// @retval false cannot be schedulded. - bool UserProcessHelper::CanBeScheduled(const UserProcess process) + bool UserProcessHelper::CanBeScheduled(const UserProcess& process) { + kcout << "Checking Status...\r"; + if (process.Status == ProcessStatusKind::kFrozen || process.Status == ProcessStatusKind::kDead) - return false; + return No; + + kcout << "Checking PTime...\r"; - return process.PTime < 1; + return process.PTime <= 0; } /** @@ -400,12 +412,14 @@ namespace Kernel { if (!cHardwareThreadScheduler) { - cHardwareThreadScheduler = new HardwareThreadScheduler(); + cHardwareThreadScheduler = mm_new_class<HardwareThreadScheduler>(); + MUST_PASS(cHardwareThreadScheduler); } if (!cProcessScheduler) { - cProcessScheduler = new UserProcessScheduler(); + cProcessScheduler = mm_new_class<UserProcessScheduler>(); + MUST_PASS(cProcessScheduler); } SizeT ret = cProcessScheduler->Run(); |
