diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-05-17 22:25:04 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-05-17 22:25:04 +0200 |
| commit | c0428f8e5feba9573e572a1a1b3c66cfa1f29108 (patch) | |
| tree | a0ecdb03c667558133a23cd7cb546a3e84489659 | |
| parent | 9ebaf586257bf42996881b70a79cb2d57d8fd1ef (diff) | |
MHR-23: Improve scheduler code.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
| -rw-r--r-- | Boot/BootKit/BootKit.hxx | 2 | ||||
| -rw-r--r-- | Boot/BootKit/Vendor/Qr.hxx | 14 | ||||
| -rw-r--r-- | Boot/BootKit/Vendor/Shared/base.h (renamed from Boot/BootKit/Vendor/QrVendor/base.h) | 0 | ||||
| -rw-r--r-- | Boot/BootKit/Vendor/Shared/bit.h (renamed from Boot/BootKit/Vendor/QrVendor/bit.h) | 0 | ||||
| -rw-r--r-- | Boot/BootKit/Vendor/Support.hxx | 17 | ||||
| -rw-r--r-- | Boot/makefile | 8 | ||||
| -rw-r--r-- | Kernel/KernelKit/ProcessScheduler.hpp | 12 | ||||
| -rw-r--r-- | Kernel/Source/ProcessScheduler.cxx | 46 |
8 files changed, 65 insertions, 34 deletions
diff --git a/Boot/BootKit/BootKit.hxx b/Boot/BootKit/BootKit.hxx index 179ca141..6ddecca1 100644 --- a/Boot/BootKit/BootKit.hxx +++ b/Boot/BootKit/BootKit.hxx @@ -360,7 +360,7 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const char* partName, fDiskDev.Write(buf, sectorSz); BTextWriter writer; - writer.Write(L"New Boot: Write-Partition, OK.\r"); + writer.Write(L"New Boot: Write-Partition: OK.\r"); return true; } diff --git a/Boot/BootKit/Vendor/Qr.hxx b/Boot/BootKit/Vendor/Qr.hxx index 1df0bdaf..3bafc09f 100644 --- a/Boot/BootKit/Vendor/Qr.hxx +++ b/Boot/BootKit/Vendor/Qr.hxx @@ -5,14 +5,16 @@ #include <stddef.h> #include <stdint.h> -#include <BootKit/Vendor/QrVendor/base.h> -#include <BootKit/Vendor/QrVendor/bit.h> +#include <BootKit/Vendor/Shared/base.h> +#include <BootKit/Vendor/Shared/bit.h> #include <BootKit/Vendor/QrPrelude.hxx> #include <Builtins/Toolbox/Toolbox.hxx> #include <BootKit/Vendor/Support.hxx> #include <CompilerKit/Detail.hxx> +/// @note the QR code is still code 128, it utilizes the same concept of having it's own character set. + namespace qr { inline uint8_t min_poly = @@ -285,14 +287,6 @@ namespace qr { return SIDE; } - constexpr auto data_size() const - { - return N_BITS; - } - constexpr auto data_ptr() const - { - return code; - } bool module(int x, int y); bool encode(const char* str, size_t len, Ecc ecc, int mask = -1); diff --git a/Boot/BootKit/Vendor/QrVendor/base.h b/Boot/BootKit/Vendor/Shared/base.h index a98ae4f0..a98ae4f0 100644 --- a/Boot/BootKit/Vendor/QrVendor/base.h +++ b/Boot/BootKit/Vendor/Shared/base.h diff --git a/Boot/BootKit/Vendor/QrVendor/bit.h b/Boot/BootKit/Vendor/Shared/bit.h index 94ab0bf2..94ab0bf2 100644 --- a/Boot/BootKit/Vendor/QrVendor/bit.h +++ b/Boot/BootKit/Vendor/Shared/bit.h diff --git a/Boot/BootKit/Vendor/Support.hxx b/Boot/BootKit/Vendor/Support.hxx index d8075152..a2c2af65 100644 --- a/Boot/BootKit/Vendor/Support.hxx +++ b/Boot/BootKit/Vendor/Support.hxx @@ -6,7 +6,8 @@ #pragma once -/// @file Purpose of this file is to help port libs into the bootloader. +/// @file Support.hxx +/// @brief Purpose of this file is to help port libs into the bootloader. #include <BootKit/BootKit.hxx> @@ -18,7 +19,7 @@ #define CopyMem(dst, src, sz) memcpy(dst, src, sz) #define StrLen(src) strlen(src) -inline int isspace(int c) +inline int IsSpace(int c) { return c == ' '; } @@ -27,16 +28,21 @@ inline long StringToLong(const char* nptr, char** endptr, int base) { const char *p = nptr, *endp; bool is_neg = 0, overflow = 0; + /* Need unsigned so (-cLongMin) can fit in these: */ unsigned long n = 0UL, cutoff; int cutlim; + if (base < 0 || base == 1 || base > 36) { return 0L; } + endp = nptr; - while (isspace(*p)) + + while (IsSpace(*p)) p++; + if (*p == '+') { p++; @@ -81,8 +87,10 @@ inline long StringToLong(const char* nptr, char** endptr, int base) { base = 10; } + cutoff = (is_neg) ? -(cLongMin / base) : cLongMax / base; cutlim = (is_neg) ? -(cLongMin % base) : cLongMax % base; + while (1) { int c; @@ -110,11 +118,14 @@ inline long StringToLong(const char* nptr, char** endptr, int base) } n = n * base + c; } + if (endptr) *endptr = (char*)endp; + if (overflow) { return ((is_neg) ? cLongMin : cLongMax); } + return (long)((is_neg) ? -n : n); } diff --git a/Boot/makefile b/Boot/makefile index 878cee2a..8eef2dba 100644 --- a/Boot/makefile +++ b/Boot/makefile @@ -12,7 +12,7 @@ ADD_FILE=touch COPY=cp HTTP_GET=wget -ifeq ($(shell uname), Windows_NT) +ifneq ($(shell uname), Darwin) EMU=qemu-system-x86_64w else EMU=qemu-system-x86_64 @@ -28,9 +28,9 @@ IMG_2=epm-slave.img EMU_FLAGS=-net none -smp 4,sockets=1,cores=4,threads=1 -m 8G -M q35 \ -bios Source/$(BIOS) -device piix3-ide,id=ide \ - -drive id=disk,file=Source/$(IMG),format=raw,if=none \ + -drive id=disk,file=$(IMG),format=raw,if=none \ -device ide-hd,drive=disk,bus=ide.0 -drive \ - file=fat:rw:Source/Root,index=2,format=raw -d int -hdd Source/$(IMG_2) + file=fat:rw:Source/Root,index=2,format=raw -d int -hdd $(IMG_2) LD_FLAGS=-e Main --subsystem=10 @@ -59,7 +59,7 @@ invalid-recipe: .PHONY: all all: compile-amd64 - mkdir -p Root/EFI/BOOT + mkdir -p Source/Root/EFI/BOOT $(LD_GNU) $(OBJ) $(LD_FLAGS) -o Source/$(BOOT_LOADER) $(COPY) Source/$(BOOT_LOADER) Source/Root/EFI/BOOT/BOOTX64.EFI $(COPY) Source/$(BOOT_LOADER) Source/Root/EFI/BOOT/NEWBOOT.EFI diff --git a/Kernel/KernelKit/ProcessScheduler.hpp b/Kernel/KernelKit/ProcessScheduler.hpp index 243857ae..9768d56a 100644 --- a/Kernel/KernelKit/ProcessScheduler.hpp +++ b/Kernel/KernelKit/ProcessScheduler.hpp @@ -252,23 +252,25 @@ namespace NewOS { return mTeam.AsArray().Count() > 0; } + bool operator!() { return mTeam.AsArray().Count() == 0; } - ProcessTeam& CurrentTeam() - { - return mTeam; - } + public: + ProcessTeam& CurrentTeam(); + public: SizeT Add(Ref<ProcessHeader>& headerRef); bool Remove(SizeT headerIndex); + public: Ref<ProcessHeader>& GetCurrent(); SizeT Run() noexcept; - static Ref<ProcessScheduler> Shared(); + public: + static Ref<ProcessScheduler&> Shared(); private: ProcessTeam mTeam; diff --git a/Kernel/Source/ProcessScheduler.cxx b/Kernel/Source/ProcessScheduler.cxx index 555dfe07..22e1fb4d 100644 --- a/Kernel/Source/ProcessScheduler.cxx +++ b/Kernel/Source/ProcessScheduler.cxx @@ -150,16 +150,16 @@ namespace NewOS /***********************************************************************************/ /** -@brief Affinity is the time slot allowed for the process. -*/ + @brief Affinity is the time slot allowed for the process. + */ const AffinityKind& ProcessHeader::GetAffinity() { return this->Affinity; } /** -@brief Standard exit proc. -*/ + @brief Standard exit proc. + */ void ProcessHeader::Exit(Int32 exit_code) { if (this->ProcessId != @@ -196,6 +196,9 @@ namespace NewOS ProcessScheduler::Shared().Leak().Remove(this->ProcessId); } + /// @brief Add process to list. + /// @param process + /// @return SizeT ProcessScheduler::Add(Ref<ProcessHeader>& process) { if (!process) @@ -238,6 +241,9 @@ namespace NewOS return mTeam.AsArray().Count() - 1; } + /// @brief Remove process from list. + /// @param process + /// @return bool ProcessScheduler::Remove(SizeT process) { if (process > mTeam.AsArray().Count()) @@ -248,6 +254,8 @@ namespace NewOS return mTeam.AsArray().Remove(process); } + /// @brief Run scheduler. + /// @return SizeT ProcessScheduler::Run() noexcept { SizeT processIndex = 0; //! we store this guy to tell the scheduler how many @@ -284,7 +292,16 @@ namespace NewOS return processIndex; } - Ref<ProcessScheduler> ProcessScheduler::Shared() + /// @brief Gets the current scheduled team. + /// @return + ProcessTeam& ProcessScheduler::CurrentTeam() + { + return mTeam; + } + + /// @brief Shared instance of the process scheduler. + /// @return + Ref<ProcessScheduler&> ProcessScheduler::Shared() { static ProcessScheduler ref; return {ref}; @@ -297,12 +314,18 @@ namespace NewOS return mTeam.AsRef(); } + /// @brief Current proccess id getter. + /// @return Process ID integer. PID& ProcessHelper::GetCurrentPID() { kcout << "ProcessHelper::GetCurrentPID: Leaking ProcessId...\r"; return ProcessScheduler::Shared().Leak().GetCurrent().Leak().ProcessId; } + /// @brief Check if process can be schedulded. + /// @param process the process reference. + /// @retval true can be schedulded. + /// @retval false cannot be schedulded. bool ProcessHelper::CanBeScheduled(Ref<ProcessHeader>& process) { if (process.Leak().Status == ProcessStatus::kFrozen || @@ -326,8 +349,9 @@ namespace NewOS } /** - * @brief Spin scheduler class. - */ + * @brief Spin scheduler class. + */ + bool ProcessHelper::StartScheduling() { if (ProcessHelper::CanBeScheduled( @@ -351,10 +375,10 @@ namespace NewOS } /** - * \brief Does a context switch in a CPU. - * \param the_stack the stackframe of the running app. - * \param new_pid the process's PID. -*/ + * \brief Does a context switch in a CPU. + * \param the_stack the stackframe of the running app. + * \param new_pid the process's PID. + */ bool ProcessHelper::Switch(HAL::StackFrame* the_stack, const PID& new_pid) { |
