From b459090d41ee4b75ad5fd957e6ef9912189e1605 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 31 May 2024 09:06:54 +0200 Subject: meta: Fix bootloader makefile. Signed-off-by: Amlal El Mahrouss --- Boot/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Boot/makefile') diff --git a/Boot/makefile b/Boot/makefile index 63883321..6c38208d 100644 --- a/Boot/makefile +++ b/Boot/makefile @@ -27,7 +27,7 @@ IMG=epm.img IMG_2=epm-slave.img EMU_FLAGS=-net none -smp 4,sockets=1,cores=4,threads=1 -m 4G -M q35 \ - -bios Sources/$(BIOS) -device piix3-ide,id=ide \ + -bios $(BIOS) -device piix3-ide,id=ide \ -drive id=disk,file=$(IMG),format=raw,if=none \ -device ide-hd,drive=disk,bus=ide.0 -drive \ file=fat:rw:Sources/Root,index=2,format=raw -d int -hdd $(IMG_2) -- cgit v1.2.3 From fc0d38259fd6670966b916b1f28a11f3cb2a4c45 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 1 Jun 2024 09:29:31 +0200 Subject: MHR-23: SMP: Add hal_send_start_ipi and hal_send_end_ipi, as well as DMA utilities. Signed-off-by: Amlal El Mahrouss --- Boot/makefile | 2 +- Drv/DynamicLoader/DynamicLoader.c | 6 +- Kernel/ArchKit/ArchKit.hpp | 41 +++ Kernel/Builtins/ACPI/ACPI.hxx | 23 +- Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx | 29 +- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp | 2 +- .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 67 ++++- Kernel/HALKit/AMD64/HalKernelMain.cxx | 2 +- Kernel/HALKit/AMD64/HalSMPCore.cxx | 2 +- Kernel/HALKit/AMD64/Processor.hpp | 65 +++++ Kernel/KernelKit/KernelHeap.hpp | 5 + Kernel/KernelKit/ProcessScheduler.hpp | 303 --------------------- Kernel/KernelKit/ProcessScheduler.hxx | 303 +++++++++++++++++++++ Kernel/KernelKit/ThreadLocalStorage.inl | 2 +- Kernel/Sources/AppMain.cxx | 26 +- Kernel/Sources/CodeManager.cxx | 2 +- Kernel/Sources/KernelHeap.cxx | 27 +- Kernel/Sources/PEFCodeManager.cxx | 2 +- Kernel/Sources/PEFSharedObjectRT.cxx | 2 +- Kernel/Sources/ProcessScheduler.cxx | 6 +- Kernel/Sources/ProcessTeam.cxx | 2 +- Kernel/Sources/SMPManager.cxx | 6 +- Kernel/Sources/Semaphore.cxx | 2 +- Kernel/Sources/ThreadLocalStorage.cxx | 2 +- Kernel/Sources/UserHeap.cxx | 2 +- Kernel/makefile | 2 +- 26 files changed, 579 insertions(+), 354 deletions(-) delete mode 100644 Kernel/KernelKit/ProcessScheduler.hpp create mode 100644 Kernel/KernelKit/ProcessScheduler.hxx (limited to 'Boot/makefile') diff --git a/Boot/makefile b/Boot/makefile index 6c38208d..5b1ab16b 100644 --- a/Boot/makefile +++ b/Boot/makefile @@ -26,7 +26,7 @@ BIOS=OVMF.fd IMG=epm.img IMG_2=epm-slave.img -EMU_FLAGS=-net none -smp 4,sockets=1,cores=4,threads=1 -m 4G -M q35 \ +EMU_FLAGS=-net none -smp 2 -m 4G -M q35 \ -bios $(BIOS) -device piix3-ide,id=ide \ -drive id=disk,file=$(IMG),format=raw,if=none \ -device ide-hd,drive=disk,bus=ide.0 -drive \ diff --git a/Drv/DynamicLoader/DynamicLoader.c b/Drv/DynamicLoader/DynamicLoader.c index 45083a5c..f7eb9458 100644 --- a/Drv/DynamicLoader/DynamicLoader.c +++ b/Drv/DynamicLoader/DynamicLoader.c @@ -7,19 +7,23 @@ #include #include +/// @brief Start function +/// @return status code int __ImageStart(void) { kernelPrintStr("SDLD: Starting up...\r"); return 0; } +/// @brief End function. +/// @return status code int __ImageEnd(void) { kernelPrintStr("SDLD: Shutting down...\r"); return 0; } -///! @brief Use this to check your stack, if using MinGW/MSVC. +///! @brief Check if stack has enough space. void ___chkstk_ms(void) { (void)0; diff --git a/Kernel/ArchKit/ArchKit.hpp b/Kernel/ArchKit/ArchKit.hpp index 83770272..fa899984 100644 --- a/Kernel/ArchKit/ArchKit.hpp +++ b/Kernel/ArchKit/ArchKit.hpp @@ -34,6 +34,47 @@ namespace NewOS return hash; } + + /// @brief write to mapped memory register + /// @param base the base address. + /// @param reg the register. + /// @param value the write to write on it. + inline void ke_dma_write(UInt32 base, UInt32 reg, UInt32 value) noexcept + { + *(volatile UInt32*)((UInt64)base + reg) = value; + } + + /// @brief read from mapped memory register. + /// @param base base address + /// @param reg the register. + /// @return the value inside the register. + inline UInt32 ke_dma_read(UInt32 base, UInt32 reg) noexcept + { + return *(volatile UInt32*)((UInt64)base + reg); + } + + /// @brief Print a region of memory. + /// @param start + /// @param length + inline void ke_print_raw_memory(const void* start, Size length) + { + const UInt8* ptr = (const UInt8*)start; + for (Size i = 0; i < length; i++) + { + if (i % 16 == 0) + { + kcout << hex_number((UIntPtr)ptr + i); + } + else + { + kcout << hex_number(ptr[i]); + } + + kcout << " "; + } + + kcout << "\r"; + } } // namespace NewOS #define kKernelMaxSystemCalls (256) diff --git a/Kernel/Builtins/ACPI/ACPI.hxx b/Kernel/Builtins/ACPI/ACPI.hxx index 13ea6ecc..d9bfeaca 100644 --- a/Kernel/Builtins/ACPI/ACPI.hxx +++ b/Kernel/Builtins/ACPI/ACPI.hxx @@ -15,7 +15,7 @@ namespace NewOS { - class SDT + class PACKED SDT { public: Char Signature[4]; @@ -29,7 +29,7 @@ namespace NewOS UInt32 CreatorRevision; }; - class RSDP : public SDT + class PACKED RSDP : public SDT { public: UInt32 RsdtAddress; @@ -38,7 +38,7 @@ namespace NewOS UInt8 Reserved0[3]; }; - class ConfigHeader + class PACKED ConfigHeader { public: UInt64 BaseAddress; @@ -59,7 +59,7 @@ namespace NewOS Invalid = 0xFF, }; - class Address + class PACKED Address { public: AddressSpace AddressSpaceId; @@ -68,6 +68,21 @@ namespace NewOS UInt8 Reserved; UIntPtr Address; }; + + class PACKED RSDT + { + public: + Char Signature[4]; + UInt32 Length; + UInt8 Revision; + Char Checksum; + Char OemId[6]; + Char OemTableId[8]; + UInt32 OemRev; + UInt32 CreatorID; + UInt32 CreatorRevision; + UInt64 AddressArr[]; + }; } // namespace NewOS #endif // !__ACPI__ diff --git a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx index ff5372f4..f92554f8 100644 --- a/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx +++ b/Kernel/HALKit/AMD64/HalACPIFactoryInterface.cxx @@ -7,6 +7,8 @@ #include #include #include +#include +#include namespace NewOS { @@ -73,28 +75,37 @@ namespace NewOS return ErrorOr{-4}; } - SDT* xsdt = (SDT*)(rsdPtr->XsdtAddress >> (rsdPtr->XsdtAddress & 0xFFF)); + /// FIXME + RSDT* xsdt = (RSDT*)rsdPtr->XsdtAddress; - SizeT num = -(xsdt->Length - sizeof(SDT)) / 8; + if (NewOS::HAL::ke_map_address((PDE*)hal_read_cr3(), rsdPtr->XsdtAddress, (UIntPtr)xsdt, NewOS::HAL::eFlagsRw)) + return ErrorOr{-5}; + + Int64 num = (xsdt->Length - sizeof(SDT)) / sizeof(UInt64); + + if (num < 1) + { + return ErrorOr{-6}; + } this->fEntries = num; - kcout << "ACPI: Number of entries: " << number(num) << endl; + kcout << "ACPI: Number of entries: " << number(this->fEntries) << endl; kcout << "ACPI: Address of XSDT: " << hex_number((UIntPtr)xsdt) << endl; - constexpr short ACPI_SIGNATURE_LENGTH = 4; + const short cAcpiSignatureLength = 4; for (Size index = 0; index < this->fEntries; ++index) { - SDT& sdt = xsdt[index]; + SDT* sdt = (SDT*)(xsdt->AddressArr[index]); - for (short signature_index = 0; signature_index < ACPI_SIGNATURE_LENGTH; ++signature_index) + for (short signature_index = 0; signature_index < cAcpiSignatureLength; ++signature_index) { - if (sdt.Signature[signature_index] != signature[signature_index]) + if (sdt->Signature[signature_index] != signature[signature_index]) break; - if (signature_index == 4) - return ErrorOr(reinterpret_cast(&sdt)); + if (signature_index == (cAcpiSignatureLength - 1)) + return ErrorOr(reinterpret_cast(sdt)); } } diff --git a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp index 0ac7a50e..d06dc6a6 100644 --- a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include #include /// @brief Handle GPF fault. diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index abd19586..287b1882 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -7,6 +7,12 @@ #include #include #include +#include + +#define kAPIC_ICR_Low 0x300 +#define kAPIC_ICR_High 0x310 +#define kAPIC_SIPI_Vector 0x00500 +#define kAPIC_EIPI_Vector 0x00400 /////////////////////////////////////////////////////////////////////////////////////// @@ -62,7 +68,7 @@ namespace NewOS::HAL struct MadtProcessorLocalApic final { Char AcpiProcessorId; - Char Reserved; + Char ApicId; UInt32 Flags; }; @@ -102,15 +108,66 @@ namespace NewOS::HAL /////////////////////////////////////////////////////////////////////////////////////// - void hal_system_get_cores(voidPtr rsdPtr) + /// @brief Send start IPI for CPU. + /// @param apicId + /// @param vector + /// @param targetAddress + /// @return + Void hal_send_start_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress) + { + NewOS::ke_dma_write(targetAddress, kAPIC_ICR_High, apicId << 24); + NewOS::ke_dma_write(targetAddress, kAPIC_ICR_Low, kAPIC_SIPI_Vector | vector); + } + + /// @brief Send end IPI for CPU. + /// @param apicId + /// @param vector + /// @param targetAddress + /// @return + Void hal_send_end_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress) + { + NewOS::ke_dma_write(targetAddress, kAPIC_ICR_High, apicId << 24); + NewOS::ke_dma_write(targetAddress, kAPIC_ICR_Low, kAPIC_EIPI_Vector | vector); + } + + Void hal_system_get_cores(voidPtr rsdPtr) { auto acpi = ACPIFactoryInterface(rsdPtr); kApicMadt = acpi.Find(kApicSignature).Leak().Leak(); - if (kApicMadt) + if (kApicMadt != nullptr) { - kcout << "New OS: APIC is present...\r"; - kApicInfoBlock = (MadtType*)kApicMadt; + auto madt = (SDT*)kApicMadt; + + const UInt8* madt_end = (const UInt8*)madt + madt->Length; + const UInt8* entry_ptr = (const UInt8*)(madt + 1); + + while (entry_ptr < madt_end) + { + const MadtType::MadtAddress* entry_header = (const MadtType::MadtAddress*)entry_ptr; + + switch (entry_header->Flags) + { + case 0: { + const MadtProcessorLocalApic* local_apic = (const MadtProcessorLocalApic*)entry_ptr; + if (local_apic->Flags & 1) + { + // Processor is enabled + kcout << "Processor ID: %d, APIC ID: %d\n" + << number(local_apic->AcpiProcessorId) << number(local_apic->ApicId); + } + break; + } + default: + break; + } + + entry_ptr += entry_header->RecordLen; + } + + while (true) + { + } } else { diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx index 07656060..3136bf76 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include diff --git a/Kernel/HALKit/AMD64/HalSMPCore.cxx b/Kernel/HALKit/AMD64/HalSMPCore.cxx index 90703e13..7aa13068 100644 --- a/Kernel/HALKit/AMD64/HalSMPCore.cxx +++ b/Kernel/HALKit/AMD64/HalSMPCore.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include using namespace NewOS; Void ProcessHeader::SetEntrypoint(UIntPtr& imageStart) noexcept diff --git a/Kernel/HALKit/AMD64/Processor.hpp b/Kernel/HALKit/AMD64/Processor.hpp index 235e425d..608a502f 100644 --- a/Kernel/HALKit/AMD64/Processor.hpp +++ b/Kernel/HALKit/AMD64/Processor.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #ifdef kCPUBackendName #undef kCPUBackendName @@ -53,6 +54,68 @@ namespace NewOS namespace NewOS::HAL { + + enum + { + eFlagsUser, + eFlagsRw, + eFlagsExecDisable + }; + + /// @brief Map address to PDE. + /// @param pde a valid page directory. + /// @param phys_addr a valid phyiscal address. + /// @param virt_addr a valid virtual address. + /// @param flags the flags to put on the page. + inline Int32 ke_map_address(PDE* pde, UIntPtr phys_addr, UIntPtr virt_addr, UInt32 flags) + { + UInt16 pml4_index = (virt_addr >> 39) & 0x1FF; + + if (!pde->Pte[pml4_index].Present) + { + pde->Pte[pml4_index].Present = true; + kcout << "PM: It is present now.\r"; + } + else + { + kcout << "PM: It is already present.\r"; + kcout << "Address? " << hex_number(pde->Pte[pml4_index].PhysicalAddress) << endl; + kcout << "User? " << (pde->Pte[pml4_index].User ? "yes" : "no") << "\r"; + kcout << "RW? " << (pde->Pte[pml4_index].Rw ? "yes" : "no") << "\r"; + + return 1; + } + + pde->Pte[pml4_index].PhysicalAddress = phys_addr; + pde->Pte[pml4_index].Rw = flags & eFlagsRw; + pde->Pte[pml4_index].User = flags & eFlagsUser; + pde->Pte[pml4_index].ExecDisable = flags & eFlagsExecDisable; + + return 0; + } + + /// @brief Map address to PDE. + /// @param pde + /// @param phys_addr + /// @param virt_addr + /// @param flags + inline void ke_unmap_address(PDE* pde, UIntPtr phys_addr, UIntPtr virt_addr, UInt32 flags) + { + UInt16 pml4_index = (virt_addr >> 39) & 0x1FF; + UInt16 pdpt_index = (virt_addr >> 30) & 0x1FF; + UInt16 pd_index = (virt_addr >> 21) & 0x1FF; + UInt16 pt_index = (virt_addr >> 12) & 0x1FF; + + if (pde->Pte[pml4_index].Present) + { + pde->Pte[pml4_index].Present = false; + pde->Pte[pml4_index].PhysicalAddress = 0; + pde->Pte[pml4_index].Rw = 0; + pde->Pte[pml4_index].User = 0; + pde->Pte[pml4_index].ExecDisable = 0; + } + } + EXTERN_C UChar In8(UInt16 port); EXTERN_C UShort In16(UInt16 port); EXTERN_C UInt In32(UInt16 port); @@ -162,6 +225,8 @@ namespace NewOS::HAL }; Void hal_system_get_cores(VoidPtr rsdPtr); + Void hal_send_start_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress); + Void hal_send_end_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress); /// @brief Processor specific structures. namespace Detail diff --git a/Kernel/KernelKit/KernelHeap.hpp b/Kernel/KernelKit/KernelHeap.hpp index c7b898ed..e2ab19b5 100644 --- a/Kernel/KernelKit/KernelHeap.hpp +++ b/Kernel/KernelKit/KernelHeap.hpp @@ -36,4 +36,9 @@ namespace NewOS /// @param heapPtr HIB pointer. /// @return if it valid: point has crc now., otherwise fail. Boolean ke_protect_ke_heap(VoidPtr heapPtr); + + /// @brief Makes a kernel heap page. + /// @param heapPtr + /// @return + Int32 ke_make_ke_page(VoidPtr heapPtr); } // namespace NewOS diff --git a/Kernel/KernelKit/ProcessScheduler.hpp b/Kernel/KernelKit/ProcessScheduler.hpp deleted file mode 100644 index 9adaac0d..00000000 --- a/Kernel/KernelKit/ProcessScheduler.hpp +++ /dev/null @@ -1,303 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#ifndef __PROCESS_SCHEDULER__ -#define __PROCESS_SCHEDULER__ - -#include -#include -#include -#include -#include -#include - -#define kSchedMinMicroTime AffinityKind::kHartStandard -#define kSchedInvalidPID (-1) - -#define kSchedProcessLimitPerTeam (100U) - -//////////////////////////////////////////////////// - -// LAST REV: Mon Feb 12 13:52:01 CET 2024 - -//////////////////////////////////////////////////// - -namespace NewOS -{ - class ProcessHeader; - class ProcessTeam; - class ProcessScheduler; - - //! @brief Process identifier. - typedef Int64 ProcessID; - - //! @brief Process name length. - inline constexpr SizeT kProcessLen = 256U; - - //! @brief Forward declaration. - class ProcessHeader; - class ProcessScheduler; - class ProcessHelper; - - //! @brief Process status enum. - enum class ProcessStatus : Int32 - { - kStarting, - kRunning, - kKilled, - kFrozen, - kDead - }; - - //! @brief Affinity is the amount of nano-seconds this process is going - //! to run. - enum class AffinityKind : Int32 - { - kInvalid = 300, - kVeryHigh = 250, - kHigh = 200, - kHartStandard = 150, - kLowUsage = 100, - kVeryLowUsage = 50, - }; - - // operator overloading. - - inline bool operator<(AffinityKind lhs, AffinityKind rhs) - { - Int32 lhs_int = static_cast(lhs); - Int32 rhs_int = static_cast(rhs); - - return lhs_int < rhs_int; - } - - inline bool operator>(AffinityKind lhs, AffinityKind rhs) - { - Int32 lhs_int = static_cast(lhs); - Int32 rhs_int = static_cast(rhs); - - return lhs_int > rhs_int; - } - - inline bool operator<=(AffinityKind lhs, AffinityKind rhs) - { - Int32 lhs_int = static_cast(lhs); - Int32 rhs_int = static_cast(rhs); - - return lhs_int <= rhs_int; - } - - inline bool operator>=(AffinityKind lhs, AffinityKind rhs) - { - Int32 lhs_int = static_cast(lhs); - Int32 rhs_int = static_cast(rhs); - - return lhs_int >= rhs_int; - } - - // end of operator overloading. - - enum ProcessSubsystemEnum - { - eProcessSubsystemLogin, - eProcessSubsystemNative, - eProcessSubsystemInvalid, - eProcessSubsystemCount, - }; - - using ProcessSubsystem = ProcessSubsystemEnum; - using ProcessTime = UInt64; - using PID = Int64; - - // for permission manager, tells where we run the code. - enum class ProcessSelector : Int - { - kRingUser, /* user ring (or ring 3 in x86) */ - kRingDriver, /* ring 2 in x86, hypervisor privileges in other archs */ - kRingKernel, /* machine privileges */ - }; - - // Helper types. - using ImagePtr = VoidPtr; - using HeapPtr = VoidPtr; - - // @name ProcessHeader - // @brief Process Header (PH) - // Holds information about the running process. - // Thread execution is being abstracted away. - class ProcessHeader final - { - public: - explicit ProcessHeader(VoidPtr startImage = nullptr) - : Image(startImage) - { - MUST_PASS(startImage); - } - - ~ProcessHeader() = default; - - NEWOS_COPY_DEFAULT(ProcessHeader) - - public: - void SetEntrypoint(UIntPtr& imageStart) noexcept; - - public: - Char Name[kProcessLen] = {"NewOS Process"}; - ProcessSubsystem SubSystem{ProcessSubsystem::eProcessSubsystemInvalid}; - ProcessSelector Selector{ProcessSelector::kRingUser}; - HAL::StackFramePtr StackFrame{nullptr}; - AffinityKind Affinity; - ProcessStatus Status; - - // Memory, images. - HeapPtr HeapCursor{nullptr}; - ImagePtr Image{nullptr}; - HeapPtr HeapPtr{nullptr}; - - // memory usage - SizeT UsedMemory{0}; - SizeT FreeMemory{0}; - - enum - { - kAppKind = 3, - kLibKind = 3, - kDriverKind = 0, - kKindCount, - }; - - enum - { - kRingUserKind = 3, - kRingDriverKind = 0, - }; - - ProcessTime PTime; - PID ProcessId{kSchedInvalidPID}; - Int32 Ring{kRingDriverKind}; - Int32 Kind{kAppKind}; - - public: - //! @brief boolean operator, check status. - operator bool() - { - return Status != ProcessStatus::kDead; - } - - //! @brief Crash the app, exits with code ~0. - void Crash(); - - //! @brief Exits app. - void Exit(Int32 exitCode = 0); - - //! @brief TLS Allocate - VoidPtr New(const SizeT& sz); - - //! @brief TLS Free. - Boolean Delete(VoidPtr ptr, const SizeT& sz); - - //! @brief Wakes up threads. - void Wake(const bool wakeup = false); - - // ProcessHeader getters. - public: - //! @brief ProcessHeader name getter, example: "C RunTime" - const Char* GetName(); - - const ProcessSelector& GetSelector(); - const ProcessStatus& GetStatus(); - const AffinityKind& GetAffinity(); - - private: - friend ProcessScheduler; - friend ProcessHelper; - }; - - /// \brief Processs Team (contains multiple processes inside it.) - /// Equivalent to a process batch - class ProcessTeam final - { - public: - explicit ProcessTeam() = default; - ~ProcessTeam() = default; - - NEWOS_COPY_DEFAULT(ProcessTeam); - - MutableArray>& AsArray(); - Ref& AsRef(); - - public: - MutableArray> mProcessList; - Ref mCurrentProcess; - }; - - using ProcessHeaderRef = ProcessHeader*; - - /// @brief ProcessHeader manager class. - /// The main class which you call to schedule an app. - class ProcessScheduler final - { - private: - explicit ProcessScheduler() = default; - - public: - ~ProcessScheduler() = default; - - NEWOS_COPY_DEFAULT(ProcessScheduler) - - operator bool() - { - return mTeam.AsArray().Count() > 0; - } - - bool operator!() - { - return mTeam.AsArray().Count() == 0; - } - - public: - ProcessTeam& CurrentTeam(); - - public: - SizeT Add(Ref& headerRef); - bool Remove(SizeT headerIndex); - - public: - Ref& GetCurrent(); - SizeT Run() noexcept; - - public: - static Ref The(); - - private: - ProcessTeam mTeam; - }; - - /* - * Just a helper class, which contains some utilities for the scheduler. - */ - - class ProcessHelper final - { - public: - static bool Switch(HAL::StackFrame* newStack, const PID& newPid); - static bool CanBeScheduled(Ref& process); - static PID& GetCurrentPID(); - static bool StartScheduling(); - }; - - const Int32& rt_get_exit_code() noexcept; -} // namespace NewOS - -#include - -//////////////////////////////////////////////////// - -// END - -//////////////////////////////////////////////////// - -#endif /* ifndef __PROCESS_SCHEDULER__ */ diff --git a/Kernel/KernelKit/ProcessScheduler.hxx b/Kernel/KernelKit/ProcessScheduler.hxx new file mode 100644 index 00000000..33c9f313 --- /dev/null +++ b/Kernel/KernelKit/ProcessScheduler.hxx @@ -0,0 +1,303 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#ifndef __PROCESS_SCHEDULER__ +#define __PROCESS_SCHEDULER__ + +#include +#include +#include +#include +#include +#include + +#define kSchedMinMicroTime AffinityKind::kHartStandard +#define kSchedInvalidPID (-1) + +#define kSchedProcessLimitPerTeam (100U) + +//////////////////////////////////////////////////// + +// LAST REV: Mon Feb 12 13:52:01 CET 2024 + +//////////////////////////////////////////////////// + +namespace NewOS +{ + class ProcessHeader; + class ProcessTeam; + class ProcessScheduler; + + //! @brief Process identifier. + typedef Int64 ProcessID; + + //! @brief Process name length. + inline constexpr SizeT kProcessLen = 256U; + + //! @brief Forward declaration. + class ProcessHeader; + class ProcessScheduler; + class ProcessHelper; + + //! @brief Process status enum. + enum class ProcessStatus : Int32 + { + kStarting, + kRunning, + kKilled, + kFrozen, + kDead + }; + + //! @brief Affinity is the amount of nano-seconds this process is going + //! to run. + enum class AffinityKind : Int32 + { + kInvalid = 300, + kVeryHigh = 250, + kHigh = 200, + kHartStandard = 150, + kLowUsage = 100, + kVeryLowUsage = 50, + }; + + // operator overloading. + + inline bool operator<(AffinityKind lhs, AffinityKind rhs) + { + Int32 lhs_int = static_cast(lhs); + Int32 rhs_int = static_cast(rhs); + + return lhs_int < rhs_int; + } + + inline bool operator>(AffinityKind lhs, AffinityKind rhs) + { + Int32 lhs_int = static_cast(lhs); + Int32 rhs_int = static_cast(rhs); + + return lhs_int > rhs_int; + } + + inline bool operator<=(AffinityKind lhs, AffinityKind rhs) + { + Int32 lhs_int = static_cast(lhs); + Int32 rhs_int = static_cast(rhs); + + return lhs_int <= rhs_int; + } + + inline bool operator>=(AffinityKind lhs, AffinityKind rhs) + { + Int32 lhs_int = static_cast(lhs); + Int32 rhs_int = static_cast(rhs); + + return lhs_int >= rhs_int; + } + + // end of operator overloading. + + enum ProcessSubsystemEnum + { + eProcessSubsystemLogin, + eProcessSubsystemNative, + eProcessSubsystemInvalid, + eProcessSubsystemCount, + }; + + using ProcessSubsystem = ProcessSubsystemEnum; + using ProcessTime = UInt64; + using PID = Int64; + + // for permission manager, tells where we run the code. + enum class ProcessSelector : Int + { + kRingUser, /* user ring (or ring 3 in x86) */ + kRingDriver, /* ring 2 in x86, hypervisor privileges in other archs */ + kRingKernel, /* machine privileges */ + }; + + // Helper types. + using ImagePtr = VoidPtr; + using HeapPtr = VoidPtr; + + // @name ProcessHeader + // @brief Process Header (PH) + // Holds information about the running process. + // Thread execution is being abstracted away. + class ProcessHeader final + { + public: + explicit ProcessHeader(VoidPtr startImage = nullptr) + : Image(startImage) + { + MUST_PASS(startImage); + } + + ~ProcessHeader() = default; + + NEWOS_COPY_DEFAULT(ProcessHeader) + + public: + void SetEntrypoint(UIntPtr& imageStart) noexcept; + + public: + Char Name[kProcessLen] = {"NewOS Process"}; + ProcessSubsystem SubSystem{ProcessSubsystem::eProcessSubsystemInvalid}; + ProcessSelector Selector{ProcessSelector::kRingUser}; + HAL::StackFramePtr StackFrame{nullptr}; + AffinityKind Affinity; + ProcessStatus Status; + + // Memory, images. + HeapPtr HeapCursor{nullptr}; + ImagePtr Image{nullptr}; + HeapPtr HeapPtr{nullptr}; + + // memory usage + SizeT UsedMemory{0}; + SizeT FreeMemory{0}; + + enum + { + kAppKind = 1, + kShLibKind = 2, + kDriverKind = 3, + kKindCount, + }; + + enum + { + kRingUserKind = 3, + kRingDriverKind = 0, + }; + + ProcessTime PTime; + PID ProcessId{kSchedInvalidPID}; + Int32 Ring{kRingDriverKind}; + Int32 Kind{kAppKind}; + + public: + //! @brief boolean operator, check status. + operator bool() + { + return Status != ProcessStatus::kDead; + } + + //! @brief Crash the app, exits with code ~0. + void Crash(); + + //! @brief Exits app. + void Exit(Int32 exitCode = 0); + + //! @brief TLS Allocate + VoidPtr New(const SizeT& sz); + + //! @brief TLS Free. + Boolean Delete(VoidPtr ptr, const SizeT& sz); + + //! @brief Wakes up threads. + void Wake(const bool wakeup = false); + + // ProcessHeader getters. + public: + //! @brief ProcessHeader name getter, example: "C RunTime" + const Char* GetName(); + + const ProcessSelector& GetSelector(); + const ProcessStatus& GetStatus(); + const AffinityKind& GetAffinity(); + + private: + friend ProcessScheduler; + friend ProcessHelper; + }; + + /// \brief Processs Team (contains multiple processes inside it.) + /// Equivalent to a process batch + class ProcessTeam final + { + public: + explicit ProcessTeam() = default; + ~ProcessTeam() = default; + + NEWOS_COPY_DEFAULT(ProcessTeam); + + MutableArray>& AsArray(); + Ref& AsRef(); + + public: + MutableArray> mProcessList; + Ref mCurrentProcess; + }; + + using ProcessHeaderRef = ProcessHeader*; + + /// @brief ProcessHeader manager class. + /// The main class which you call to schedule an app. + class ProcessScheduler final + { + private: + explicit ProcessScheduler() = default; + + public: + ~ProcessScheduler() = default; + + NEWOS_COPY_DEFAULT(ProcessScheduler) + + operator bool() + { + return mTeam.AsArray().Count() > 0; + } + + bool operator!() + { + return mTeam.AsArray().Count() == 0; + } + + public: + ProcessTeam& CurrentTeam(); + + public: + SizeT Add(Ref& headerRef); + bool Remove(SizeT headerIndex); + + public: + Ref& GetCurrent(); + SizeT Run() noexcept; + + public: + static Ref The(); + + private: + ProcessTeam mTeam; + }; + + /* + * Just a helper class, which contains some utilities for the scheduler. + */ + + class ProcessHelper final + { + public: + static bool Switch(HAL::StackFrame* newStack, const PID& newPid); + static bool CanBeScheduled(Ref& process); + static PID& GetCurrentPID(); + static bool StartScheduling(); + }; + + const Int32& rt_get_exit_code() noexcept; +} // namespace NewOS + +#include + +//////////////////////////////////////////////////// + +// END + +//////////////////////////////////////////////////// + +#endif /* ifndef __PROCESS_SCHEDULER__ */ diff --git a/Kernel/KernelKit/ThreadLocalStorage.inl b/Kernel/KernelKit/ThreadLocalStorage.inl index e2137ed6..a8269a14 100644 --- a/Kernel/KernelKit/ThreadLocalStorage.inl +++ b/Kernel/KernelKit/ThreadLocalStorage.inl @@ -7,7 +7,7 @@ //! @brief Allocates a pointer from the process's tls. #ifndef __PROCESS_MANAGER__ -#include +#include #endif template diff --git a/Kernel/Sources/AppMain.cxx b/Kernel/Sources/AppMain.cxx index 692d4376..62795893 100644 --- a/Kernel/Sources/AppMain.cxx +++ b/Kernel/Sources/AppMain.cxx @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -182,31 +182,31 @@ namespace NewOS::Detail /// @brief System loader entrypoint. /// @param void no parameters. /// @return void no return value. - STATIC NewOS::Void AppSystemLoader(NewOS::Void) + STATIC NewOS::Void AppSystem(NewOS::Void) { - NewOS::PEFLoader coreGraphicsShLib("/System/WindowServer"); + NewOS::PEFLoader wndServer("/System/WindowServer"); - if (!coreGraphicsShLib.IsLoaded()) + if (!wndServer.IsLoaded()) { NewOS::ke_stop(RUNTIME_CHECK_FAILED); } - NewOS::Utils::execute_from_image(coreGraphicsShLib, - NewOS::ProcessHeader::kLibKind); + NewOS::Utils::execute_from_image(wndServer, + NewOS::ProcessHeader::kAppKind); - NewOS::PEFLoader logonService("/System/Login"); + NewOS::PEFLoader launchServer("/System/Launcher"); - if (!logonService.IsLoaded()) + if (!launchServer.IsLoaded()) { NewOS::ke_stop(RUNTIME_CHECK_FAILED); } - NewOS::Utils::execute_from_image(logonService, + NewOS::Utils::execute_from_image(launchServer, NewOS::ProcessHeader::kAppKind); - NewOS::kcout << "SystemLoader: Exiting process, we're done initializing stuff..."; + NewOS::kcout << "System: done, sleeping..."; - NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Exit(0); + while (true) {} } } // namespace NewOS::Detail @@ -218,8 +218,8 @@ EXTERN_C NewOS::Void AppMain(NewOS::Void) /// Now run kernel loop, until no process are running. NewOS::Detail::FilesystemWizard wizard; // automatic. - auto cLoaderName = "SystemLoader"; - NewOS::execute_from_image(NewOS::Detail::AppSystemLoader, cLoaderName); + auto cLoaderName = "System"; + NewOS::execute_from_image(NewOS::Detail::AppSystem, cLoaderName); while (NewOS::ProcessScheduler::The().Leak().Run() > 0) {} } diff --git a/Kernel/Sources/CodeManager.cxx b/Kernel/Sources/CodeManager.cxx index 7483b32f..10de3512 100644 --- a/Kernel/Sources/CodeManager.cxx +++ b/Kernel/Sources/CodeManager.cxx @@ -6,7 +6,7 @@ #include #include -#include +#include namespace NewOS { diff --git a/Kernel/Sources/KernelHeap.cxx b/Kernel/Sources/KernelHeap.cxx index a8ca467e..93f0c164 100644 --- a/Kernel/Sources/KernelHeap.cxx +++ b/Kernel/Sources/KernelHeap.cxx @@ -38,7 +38,10 @@ namespace NewOS SizeT fTargetPtrSize; /// @brief 64-bit target pointer. UIntPtr fTargetPtr; - UInt8 fPadding[kKernelHeapHeaderPaddingSz]; + /// @brief Is this a page pointer? + Boolean fPagePtr; + /// @brief Padding bytes for header. + UInt8 fPadding[kKernelHeapHeaderPaddingSz]; }; typedef HeapInformationBlock* HeapInformationBlockPtr; @@ -64,6 +67,7 @@ namespace NewOS heapInfo->fMagic = kKernelHeapMagic; heapInfo->fCRC32 = 0; // dont fill it for now. heapInfo->fTargetPtr = wrapper.VirtualAddress(); + heapInfo->fPagePtr = 0; ++kHeapCount; @@ -71,6 +75,27 @@ namespace NewOS sizeof(Detail::HeapInformationBlock)); } + /// @brief Makes a page heap. + /// @param heapPtr + /// @return + Int32 ke_make_ke_page(VoidPtr heapPtr) + { + if (kHeapCount < 1) + return -kErrorInternal; + if (((IntPtr)heapPtr - sizeof(Detail::HeapInformationBlock)) <= 0) + return -kErrorInternal; + if (((IntPtr)heapPtr - kBadPtr) < 0) + return -kErrorInternal; + + Detail::HeapInformationBlockPtr virtualAddress = + reinterpret_cast( + (UIntPtr)heapPtr - sizeof(Detail::HeapInformationBlock)); + + virtualAddress->fPagePtr = 1; + + return 0; + } + /// @brief Declare pointer as free. /// @param heapPtr the pointer. /// @return diff --git a/Kernel/Sources/PEFCodeManager.cxx b/Kernel/Sources/PEFCodeManager.cxx index c0997dff..a84730e9 100644 --- a/Kernel/Sources/PEFCodeManager.cxx +++ b/Kernel/Sources/PEFCodeManager.cxx @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Kernel/Sources/PEFSharedObjectRT.cxx b/Kernel/Sources/PEFSharedObjectRT.cxx index 33df8857..3ddef245 100644 --- a/Kernel/Sources/PEFSharedObjectRT.cxx +++ b/Kernel/Sources/PEFSharedObjectRT.cxx @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx index 32e1fbde..bf088cc6 100644 --- a/Kernel/Sources/ProcessScheduler.cxx +++ b/Kernel/Sources/ProcessScheduler.cxx @@ -9,7 +9,7 @@ /// @brief MicroKernel process scheduler. /***********************************************************************************/ -#include +#include #include #include #include @@ -206,7 +206,7 @@ namespace NewOS if (!process.Leak().Image) { - if (process.Leak().Kind != ProcessHeader::kLibKind) + if (process.Leak().Kind != ProcessHeader::kShLibKind) { return -kErrorNoEntrypoint; } @@ -223,7 +223,7 @@ namespace NewOS /// Create heap according to type of process. if (process.Leak().Kind == ProcessHeader::kAppKind) process.Leak().HeapPtr = rt_new_heap(kUserHeapUser | kUserHeapRw); - else if (process.Leak().Kind == ProcessHeader::kLibKind) + else if (process.Leak().Kind == ProcessHeader::kShLibKind) process.Leak().HeapPtr = rt_new_heap(kUserHeapUser | kUserHeapRw | kUserHeapShared); else process.Leak().HeapPtr = rt_new_heap(kUserHeapDriver | kUserHeapRw); diff --git a/Kernel/Sources/ProcessTeam.cxx b/Kernel/Sources/ProcessTeam.cxx index 7e311399..068e0dbb 100644 --- a/Kernel/Sources/ProcessTeam.cxx +++ b/Kernel/Sources/ProcessTeam.cxx @@ -9,7 +9,7 @@ /// @brief Process teams implementation. /***********************************************************************************/ -#include +#include namespace NewOS { diff --git a/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx index b2f239e3..29e0fa26 100644 --- a/Kernel/Sources/SMPManager.cxx +++ b/Kernel/Sources/SMPManager.cxx @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include #include ///! BUGS: 0 @@ -95,7 +95,6 @@ namespace NewOS { /// Keep the arguments, switch the base pointer, stack pointer /// fs and gs registers. - fStack->Rbp = stack->Rbp; fStack->Rsp = stack->Rsp; fStack->Fs = stack->Fs; @@ -103,6 +102,7 @@ namespace NewOS } rt_do_context_switch(fStack); + return true; } @@ -172,6 +172,8 @@ namespace NewOS rt_copy_memory(stack, fThreadList[idx].Leak().Leak().fStack, sizeof(HAL::StackFrame)); + fThreadList[idx].Leak().Leak().Switch(fThreadList[idx].Leak().Leak().fStack); + fThreadList[idx].Leak().Leak().fPID = ProcessHelper::GetCurrentPID(); fThreadList[idx].Leak().Leak().Busy(false); diff --git a/Kernel/Sources/Semaphore.cxx b/Kernel/Sources/Semaphore.cxx index 7bd1d513..e2e135d0 100644 --- a/Kernel/Sources/Semaphore.cxx +++ b/Kernel/Sources/Semaphore.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include #include #include diff --git a/Kernel/Sources/ThreadLocalStorage.cxx b/Kernel/Sources/ThreadLocalStorage.cxx index 2d7e61eb..00305006 100644 --- a/Kernel/Sources/ThreadLocalStorage.cxx +++ b/Kernel/Sources/ThreadLocalStorage.cxx @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include ///! BUGS: 0 diff --git a/Kernel/Sources/UserHeap.cxx b/Kernel/Sources/UserHeap.cxx index da5d7b5a..64b75641 100644 --- a/Kernel/Sources/UserHeap.cxx +++ b/Kernel/Sources/UserHeap.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include #include #include diff --git a/Kernel/makefile b/Kernel/makefile index b7749100..14bd1cae 100644 --- a/Kernel/makefile +++ b/Kernel/makefile @@ -69,7 +69,7 @@ link-amd64-epm: .PHONY: all all: newos-amd64-epm link-amd64-epm - @echo "NewKernel => OK." + @echo "NewOSKrnl => OK." .PHONY: help help: -- cgit v1.2.3 From 39415bb759f7eb67fb393385c28c3d2e5d7f6857 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 2 Jun 2024 09:25:18 +0200 Subject: MHR-23: Porting to ARM64 now. Signed-off-by: Amlal El Mahrouss --- Boot/BootKit/BootKit.hxx | 4 +- Boot/ReadMe.md | 2 +- Boot/Sources/BootloaderRsrc.rsrc | 6 +- Boot/Sources/HEL/AMD64/BootATA.cxx | 2 +- Boot/Sources/HEL/AMD64/BootFileReader.cxx | 8 +- Boot/Sources/HEL/AMD64/BootMain.cxx | 4 +- Boot/Sources/HEL/POWER/CoreBootStartup.S | 2 +- Boot/Sources/HEL/RISCV/BootRISCV.S | 4 +- Boot/Sources/Root/SplashScreen.fmt | 4 +- Boot/makefile | 6 +- Drv/DynamicLoader/DriverRsrc.rsrc | 25 ----- Drv/DynamicLoader/DynamicLoader.c | 30 ------ Drv/DynamicLoader/x86_64.mk | 51 ---------- Kernel/Docs/SPECIFICATION.md | 2 +- Kernel/Docs/TODO-LIST.md | 2 +- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp | 18 ++-- .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 3 +- Kernel/HALKit/AMD64/Storage/AHCI.cxx | 2 +- Kernel/KernelKit/DriveManager.hxx | 2 +- Kernel/KernelRsrc.rsrc | 2 +- Kernel/Linker/16x0.json | 2 +- Kernel/Linker/32x0.json | 2 +- Kernel/Linker/64x0.json | 2 +- Kernel/NetworkKit/NetworkDevice.inl | 4 +- Kernel/Sources/CxxAbi.cxx | 2 +- Kernel/Sources/FS/NewFS.cxx | 53 +++++----- Kernel/Sources/IndexableProperty.cxx | 2 +- Kernel/Sources/KernelCheck.cxx | 4 +- Kernel/Sources/PEFSharedObject.cxx | 106 ++++++++++++++++++++ Kernel/Sources/PEFSharedObjectRT.cxx | 107 --------------------- Kernel/Sources/ThreadLocalStorage.cxx | 6 +- Kernel/makefile | 2 +- 32 files changed, 184 insertions(+), 287 deletions(-) delete mode 100644 Drv/DynamicLoader/DriverRsrc.rsrc delete mode 100644 Drv/DynamicLoader/DynamicLoader.c delete mode 100644 Drv/DynamicLoader/x86_64.mk create mode 100644 Kernel/Sources/PEFSharedObject.cxx delete mode 100644 Kernel/Sources/PEFSharedObjectRT.cxx (limited to 'Boot/makefile') diff --git a/Boot/BootKit/BootKit.hxx b/Boot/BootKit/BootKit.hxx index 77badc23..311d6c7f 100644 --- a/Boot/BootKit/BootKit.hxx +++ b/Boot/BootKit/BootKit.hxx @@ -284,7 +284,7 @@ private: EFI::ThrowError(L"Developer-Error", L"This is caused by the developer of the bootloader."); } - writer.Write((catalogKind->Kind == kNewFSCatalogKindFile) ? L"New Boot: Write-File: " : L"New Boot: Write-Directory: ").Write(blob->fFileName).Write(L"\r"); + writer.Write((catalogKind->Kind == kNewFSCatalogKindFile) ? L"newosldr: Write-File: " : L"newosldr: Write-Directory: ").Write(blob->fFileName).Write(L"\r"); memcpy(catalogKind->Name, blob->fFileName, strlen(blob->fFileName)); @@ -360,7 +360,7 @@ inline Boolean BDiskFormatFactory::Format(const char* partName, fDiskDev.Write(buf, sectorSz); BTextWriter writer; - writer.Write(L"New Boot: Write-Partition: OK.\r"); + writer.Write(L"newosldr: Write-Partition: OK.\r"); return true; } diff --git a/Boot/ReadMe.md b/Boot/ReadMe.md index d5f2b89e..ce5b30cd 100644 --- a/Boot/ReadMe.md +++ b/Boot/ReadMe.md @@ -1,4 +1,4 @@ -# NewBoot +# newosldr You need: diff --git a/Boot/Sources/BootloaderRsrc.rsrc b/Boot/Sources/BootloaderRsrc.rsrc index 0282192b..857e08e4 100644 --- a/Boot/Sources/BootloaderRsrc.rsrc +++ b/Boot/Sources/BootloaderRsrc.rsrc @@ -13,10 +13,10 @@ BEGIN VALUE "CompanyName", "SoftwareLabs" VALUE "FileDescription", "New OS multi-platform bootloader." VALUE "FileVersion", BOOTLOADER_VERSION - VALUE "InternalName", "NewBoot" + VALUE "InternalName", "newosldr" VALUE "LegalCopyright", "Copyright SoftwareLabs, all rights reserved." - VALUE "OriginalFilename", "NewOSLdr.exe" - VALUE "ProductName", "NewBoot" + VALUE "OriginalFilename", "newosldr.exe" + VALUE "ProductName", "newosldr" VALUE "ProductVersion", BOOTLOADER_VERSION END END diff --git a/Boot/Sources/HEL/AMD64/BootATA.cxx b/Boot/Sources/HEL/AMD64/BootATA.cxx index c82cb2ea..d2753110 100644 --- a/Boot/Sources/HEL/AMD64/BootATA.cxx +++ b/Boot/Sources/HEL/AMD64/BootATA.cxx @@ -81,7 +81,7 @@ ATAInit_Retry: if (statRdy & ATA_SR_ERR) { writer.Write( - L"New Boot: ATA: Select error, not an IDE based hard-drive.\r"); + L"newosldr: ATA: Select error, not an IDE based hard-drive.\r"); return false; } diff --git a/Boot/Sources/HEL/AMD64/BootFileReader.cxx b/Boot/Sources/HEL/AMD64/BootFileReader.cxx index 7ec6b7ab..e6e70509 100644 --- a/Boot/Sources/HEL/AMD64/BootFileReader.cxx +++ b/Boot/Sources/HEL/AMD64/BootFileReader.cxx @@ -57,13 +57,13 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path, if (BS->HandleProtocol(ImageHandle, &guidImg, (void**)&img) != kEfiOk) { - mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Protocol").Write(L"\r"); + mWriter.Write(L"newosldr: Fetch-Protocol: No-Such-Protocol").Write(L"\r"); this->mErrorCode = kNotSupported; } if (BS->HandleProtocol(img->DeviceHandle, &guidEfp, (void**)&efp) != kEfiOk) { - mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Protocol").Write(L"\r"); + mWriter.Write(L"newosldr: Fetch-Protocol: No-Such-Protocol").Write(L"\r"); this->mErrorCode = kNotSupported; return; } @@ -72,7 +72,7 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path, if (efp->OpenVolume(efp, &rootFs) != kEfiOk) { - mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Volume").Write(L"\r"); + mWriter.Write(L"newosldr: Fetch-Protocol: No-Such-Volume").Write(L"\r"); this->mErrorCode = kNotSupported; return; } @@ -82,7 +82,7 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path, if (rootFs->Open(rootFs, &kernelFile, mPath, kEFIFileRead, kEFIReadOnly) != kEfiOk) { - mWriter.Write(L"New Boot: Fetch-Protocol: No-Such-Path: ") + mWriter.Write(L"newosldr: Fetch-Protocol: No-Such-Path: ") .Write(mPath) .Write(L"\r"); this->mErrorCode = kNotSupported; diff --git a/Boot/Sources/HEL/AMD64/BootMain.cxx b/Boot/Sources/HEL/AMD64/BootMain.cxx index 7609c1af..cb8bccba 100644 --- a/Boot/Sources/HEL/AMD64/BootMain.cxx +++ b/Boot/Sources/HEL/AMD64/BootMain.cxx @@ -68,7 +68,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, /// Splash screen stuff - writer.Write(L"SoftwareLabs (R) New Boot: ") + writer.Write(L"SoftwareLabs (R) newosldr: ") .Write(BVersionString::The()); writer.Write(L"\rNew Boot: Firmware Vendor: ") @@ -99,7 +99,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, vendorTable[4] == 'P' && vendorTable[5] == 'T' && vendorTable[6] == 'R' && vendorTable[7] == ' ') { - writer.Write(L"New Boot: Found ACPI RSD PTR!\r"); + writer.Write(L"newosldr: Found ACPI RSD PTR!\r"); handoverHdrPtr->f_HardwareTables.f_RsdPtr = (VoidPtr)vendorTable; break; diff --git a/Boot/Sources/HEL/POWER/CoreBootStartup.S b/Boot/Sources/HEL/POWER/CoreBootStartup.S index f8ff99d7..ed39c3b5 100644 --- a/Boot/Sources/HEL/POWER/CoreBootStartup.S +++ b/Boot/Sources/HEL/POWER/CoreBootStartup.S @@ -13,7 +13,7 @@ boot_hdr_mag: .ascii "CB" boot_hdr_name: // it has to match ten bytes. - .asciz "NewBoot\0\0\0" + .asciz "newosldr\0\0" boot_hdr_ver: .word 0x104 boot_hdr_proc: diff --git a/Boot/Sources/HEL/RISCV/BootRISCV.S b/Boot/Sources/HEL/RISCV/BootRISCV.S index 7a7e7db0..b682d597 100644 --- a/Boot/Sources/HEL/RISCV/BootRISCV.S +++ b/Boot/Sources/HEL/RISCV/BootRISCV.S @@ -13,10 +13,10 @@ k_hdr_mag: .ascii "LX" k_hdr_name: // it has to match ten bytes. - .asciz "New OS\0\0\0\0" + .asciz "newosldr\0\0" k_hdr_ver: .word 0x104 k_hdr_proc: - .long __bootloader_start + .long bootloader_start /* end */ \ No newline at end of file diff --git a/Boot/Sources/Root/SplashScreen.fmt b/Boot/Sources/Root/SplashScreen.fmt index 863d7b62..42005568 100644 --- a/Boot/Sources/Root/SplashScreen.fmt +++ b/Boot/Sources/Root/SplashScreen.fmt @@ -1,7 +1,7 @@ ================================================================== Welcome to NeWS. Brought to you by: Amlal EL Mahrouss. -* NewBoot, NewKernel: Amlal EL Mahrouss. -This copy can boot directly to NewKernel (Unified System). +* newosldr, newoskrnl: Amlal EL Mahrouss. +This copy can boot directly to newoskrnl (Unified System). Copyright SoftwareLabs, all rights reserved. ================================================================== diff --git a/Boot/makefile b/Boot/makefile index 5b1ab16b..e979c309 100644 --- a/Boot/makefile +++ b/Boot/makefile @@ -50,8 +50,8 @@ FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mno-red-zone -D__KERNEL__ -D__NEWBOOT__ -DEFI_FUNCTION_WRAPPER -I./ -I../Kernel -I./ -c -nostdlib -fno-rtti -fno-exceptions \ -std=c++20 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./ -BOOT_LOADER=NewOSLdr.exe -KERNEL=NewOSKrnl.exe +BOOT_LOADER=newosldr.exe +KERNEL=newoskrnl.exe .PHONY: invalid-recipe invalid-recipe: @@ -92,7 +92,7 @@ download-edk: $(HTTP_GET) https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd BINS=*.bin -EXECUTABLES=NewOSLdr.exe NewOSKrnl.exe OVMF.fd +EXECUTABLES=newosldr.exe newoskrnl.exe OVMF.fd TARGETS=$(REM_FLAG) $(OBJ) $(BIN) $(IMG) $(IMG_2) $(EXECUTABLES) diff --git a/Drv/DynamicLoader/DriverRsrc.rsrc b/Drv/DynamicLoader/DriverRsrc.rsrc deleted file mode 100644 index 565895b0..00000000 --- a/Drv/DynamicLoader/DriverRsrc.rsrc +++ /dev/null @@ -1,25 +0,0 @@ -1 ICON "../../Kernel/Root/Boot/Icons/driver-logo.ico" - -1 VERSIONINFO -FILEVERSION 1,0,0,0 -PRODUCTVERSION 1,0,0,0 -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "080904E4" - BEGIN - VALUE "CompanyName", "SoftwareLabs" - VALUE "FileDescription", "SoftwareLabs Dynamic Loader Driver." - VALUE "FileVersion", "1.00" - VALUE "InternalName", "DynamicLoader" - VALUE "LegalCopyright", "Copyright SoftwareLabs, all rights reserved." - VALUE "OriginalFilename", "DynamicLoader.exe" - VALUE "ProductName", "SDLD" - VALUE "ProductVersion", "1.00" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x809, 1252 - END -END diff --git a/Drv/DynamicLoader/DynamicLoader.c b/Drv/DynamicLoader/DynamicLoader.c deleted file mode 100644 index f7eb9458..00000000 --- a/Drv/DynamicLoader/DynamicLoader.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ------------------------------------------- - - Copyright SoftwareLabs - -------------------------------------------- */ - -#include -#include - -/// @brief Start function -/// @return status code -int __ImageStart(void) -{ - kernelPrintStr("SDLD: Starting up...\r"); - return 0; -} - -/// @brief End function. -/// @return status code -int __ImageEnd(void) -{ - kernelPrintStr("SDLD: Shutting down...\r"); - return 0; -} - -///! @brief Check if stack has enough space. -void ___chkstk_ms(void) -{ - (void)0; -} diff --git a/Drv/DynamicLoader/x86_64.mk b/Drv/DynamicLoader/x86_64.mk deleted file mode 100644 index 54ee54f0..00000000 --- a/Drv/DynamicLoader/x86_64.mk +++ /dev/null @@ -1,51 +0,0 @@ -################################################## -# (C) SoftwareLabs, all rights reserved. -# This is the sample driver makefile. -################################################## - -CC_GNU=x86_64-w64-mingw32-gcc -LD_GNU=x86_64-w64-mingw32-ld - -WINDRES=x86_64-w64-mingw32-windres - -ADD_FILE=touch -COPY=cp -HTTP_GET=wget - -LD_FLAGS=-e __ImageStart --subsystem=17 - -OBJ=*.o - - -REM=rm -REM_FLAG=-f - -FLAG_ASM=-f win64 -FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mgeneral-regs-only -mno-red-zone -D__KERNEL__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -std=c17 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./ - -.PHONY: invalid-recipe -invalid-recipe: - @echo "invalid-recipe: Use make all instead." - -.PHONY: all -all: compile-amd64 - $(LD_GNU) $(OBJ) $(LD_FLAGS) -o SampleDriver.exe - -ifneq ($(DEBUG_SUPPORT), ) -DEBUG = -D__DEBUG__ -endif - -.PHONY: compile-amd64 -compile-amd64: - $(WINDRES) DriverRsrc.rsrc -O coff -o DriverRsrc.o - $(CC_GNU) $(FLAG_GNU) $(DEBUG) $(wildcard *.c) $(wildcard ../../DDK/*.c) $(wildcard ../../DDK/*.S) - -.PHONY: clean -clean: - $(REM) $(REM_FLAG) $(OBJ) SampleDriver.exe - -.PHONY: help -help: - @echo "=== HELP ===" - @echo "clean: Clean driver." - @echo "compile-amd64: Build driver." diff --git a/Kernel/Docs/SPECIFICATION.md b/Kernel/Docs/SPECIFICATION.md index e218947e..6f9ac3d3 100644 --- a/Kernel/Docs/SPECIFICATION.md +++ b/Kernel/Docs/SPECIFICATION.md @@ -51,7 +51,7 @@ =================================== -# 4: The NewBoot +# 4: The newosldr =================================== diff --git a/Kernel/Docs/TODO-LIST.md b/Kernel/Docs/TODO-LIST.md index b7780b9f..ed7b1cf9 100644 --- a/Kernel/Docs/TODO-LIST.md +++ b/Kernel/Docs/TODO-LIST.md @@ -18,6 +18,6 @@ Status: -NewBoot: Need to boot from EPM partition. +newosldr: Need to boot from EPM partition.
NewKernel: New Filesystem in progress. diff --git a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp index d06dc6a6..6d831d3b 100644 --- a/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp @@ -14,11 +14,11 @@ EXTERN_C void idt_handle_gpf(NewOS::UIntPtr rsp) { MUST_PASS(NewOS::ProcessScheduler::The().Leak().GetCurrent()); - NewOS::kcout << "New OS: Stack Pointer: " + NewOS::kcout << "newoskrnl: Stack Pointer: " << NewOS::StringBuilder::FromInt("rsp{%}", rsp); NewOS::kcout - << "New OS: General Protection Fault, caused by " + << "newoskrnl: General Protection Fault, caused by " << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); @@ -31,14 +31,14 @@ EXTERN_C void idt_handle_scheduler(NewOS::UIntPtr rsp) NewOS::kcout << NewOS::StringBuilder::FromInt("rsp{%}", rsp); NewOS::kcout - << "New OS: Will be scheduled back later " + << "newoskrnl: Will be scheduled back later " << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName() << NewOS::end_line(); /// schedule another process. if (!NewOS::ProcessHelper::StartScheduling()) { - NewOS::kcout << "New OS: Continue schedule this process...\r"; + NewOS::kcout << "newoskrnl: Continue schedule this process...\r"; } } @@ -50,7 +50,7 @@ EXTERN_C void idt_handle_pf(NewOS::UIntPtr rsp) NewOS::kcout << NewOS::StringBuilder::FromInt("rsp{%}", rsp); NewOS::kcout - << "New OS: Segmentation Fault, caused by " + << "newoskrnl: Segmentation Fault, caused by " << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); @@ -64,7 +64,7 @@ EXTERN_C void idt_handle_math(NewOS::UIntPtr rsp) NewOS::kcout << NewOS::StringBuilder::FromInt("rsp{%}", rsp); NewOS::kcout - << "New OS: Math error, caused by " + << "newoskrnl: Math error, caused by " << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); @@ -78,7 +78,7 @@ EXTERN_C void idt_handle_generic(NewOS::UIntPtr rsp) NewOS::kcout << NewOS::StringBuilder::FromInt("sp{%}", rsp); NewOS::kcout - << "New OS: Execution error, caused by " + << "newoskrnl: Execution error, caused by " << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); @@ -90,11 +90,11 @@ EXTERN_C void idt_handle_ud(NewOS::UIntPtr rsp) { MUST_PASS(NewOS::ProcessScheduler::The().Leak().GetCurrent()); - NewOS::kcout << "New OS: Stack Pointer: " + NewOS::kcout << "newoskrnl: Stack Pointer: " << NewOS::StringBuilder::FromInt("rsp{%}", rsp); NewOS::kcout - << "New OS: Invalid interrupt, caused by " + << "newoskrnl: Invalid interrupt, caused by " << NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().GetName(); NewOS::ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index 5ab40532..a184efc2 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -146,12 +146,13 @@ namespace NewOS::HAL if (madt->MadtRecords[i].Flags == 0x01) // if local apic. { // then register as a core for scheduler. + kcout << "newoskrnl: register core as scheduler thread.\r"; } } } else { - kcout << "New OS: APIC is not present! it is a vital component.\r"; + kcout << "newoskrnl: APIC is not present! it is a vital component.\r"; ke_stop(RUNTIME_CHECK_FAILED); } } diff --git a/Kernel/HALKit/AMD64/Storage/AHCI.cxx b/Kernel/HALKit/AMD64/Storage/AHCI.cxx index 93cef10c..a8045617 100644 --- a/Kernel/HALKit/AMD64/Storage/AHCI.cxx +++ b/Kernel/HALKit/AMD64/Storage/AHCI.cxx @@ -43,7 +43,7 @@ NewOS::Boolean drv_std_init(NewOS::UInt16& PortsImplemented) iterator[devIndex].Leak().EnableMmio(); /// enable the memory i/o for this ahci device. kAhciDevice = iterator[devIndex].Leak(); /// and then leak the reference. - kcout << "New Kernel: [PCI] Found AHCI controller.\r"; + kcout << "newoskrnl: [PCI] Found AHCI controller.\r"; return true; } diff --git a/Kernel/KernelKit/DriveManager.hxx b/Kernel/KernelKit/DriveManager.hxx index 019812a3..01058d00 100644 --- a/Kernel/KernelKit/DriveManager.hxx +++ b/Kernel/KernelKit/DriveManager.hxx @@ -113,7 +113,7 @@ namespace NewOS return &mD; default: { DbgLastError() = kErrorNoSuchDisk; - kcout << "New OS: No such disk.\n"; + kcout << "newoskrnl: No such disk.\n"; break; } diff --git a/Kernel/KernelRsrc.rsrc b/Kernel/KernelRsrc.rsrc index 91699b63..56c94a06 100644 --- a/Kernel/KernelRsrc.rsrc +++ b/Kernel/KernelRsrc.rsrc @@ -15,7 +15,7 @@ BEGIN VALUE "FileVersion", KERNEL_VERSION VALUE "InternalName", "NeXUS" VALUE "LegalCopyright", "SoftwareLabs" - VALUE "OriginalFilename", "NewOSKrnl.exe" + VALUE "OriginalFilename", "newoskrnl.exe" VALUE "ProductName", "NewOSKrnl" VALUE "ProductVersion", KERNEL_VERSION END diff --git a/Kernel/Linker/16x0.json b/Kernel/Linker/16x0.json index 40cee7c9..77235537 100644 --- a/Kernel/Linker/16x0.json +++ b/Kernel/Linker/16x0.json @@ -1,6 +1,6 @@ { "executable_type": "kernel", - "output_name": "NewOSKrnl.exe", + "output_name": "newoskrnl.exe", "start_proc": "__ImageStart", "format": "PEF" } diff --git a/Kernel/Linker/32x0.json b/Kernel/Linker/32x0.json index 40cee7c9..77235537 100644 --- a/Kernel/Linker/32x0.json +++ b/Kernel/Linker/32x0.json @@ -1,6 +1,6 @@ { "executable_type": "kernel", - "output_name": "NewOSKrnl.exe", + "output_name": "newoskrnl.exe", "start_proc": "__ImageStart", "format": "PEF" } diff --git a/Kernel/Linker/64x0.json b/Kernel/Linker/64x0.json index 40cee7c9..77235537 100644 --- a/Kernel/Linker/64x0.json +++ b/Kernel/Linker/64x0.json @@ -1,6 +1,6 @@ { "executable_type": "kernel", - "output_name": "NewOSKrnl.exe", + "output_name": "newoskrnl.exe", "start_proc": "__ImageStart", "format": "PEF" } diff --git a/Kernel/NetworkKit/NetworkDevice.inl b/Kernel/NetworkKit/NetworkDevice.inl index 614ccadf..750520ff 100644 --- a/Kernel/NetworkKit/NetworkDevice.inl +++ b/Kernel/NetworkKit/NetworkDevice.inl @@ -15,7 +15,7 @@ namespace NewOS void (*on_cleanup)(void)) : DeviceInterface(out, in), fCleanup(on_cleanup) { - kcout << "New OS: NetworkDevice initialized.\r"; + kcout << "newoskrnl: NetworkDevice initialized.\r"; MUST_PASS(out && in && on_cleanup); } @@ -24,7 +24,7 @@ namespace NewOS { MUST_PASS(fCleanup); - kcout << "New OS: NetworkDevice cleanup.\r"; + kcout << "newoskrnl: NetworkDevice cleanup.\r"; if (fCleanup) fCleanup(); } diff --git a/Kernel/Sources/CxxAbi.cxx b/Kernel/Sources/CxxAbi.cxx index 9aea8db7..0b01928a 100644 --- a/Kernel/Sources/CxxAbi.cxx +++ b/Kernel/Sources/CxxAbi.cxx @@ -14,7 +14,7 @@ uarch_t __atexit_func_count; extern "C" void __cxa_pure_virtual() { - NewOS::kcout << "New OS: C++ placeholder method.\n"; + NewOS::kcout << "newoskrnl: C++ placeholder method.\n"; } extern "C" void ___chkstk_ms() diff --git a/Kernel/Sources/FS/NewFS.cxx b/Kernel/Sources/FS/NewFS.cxx index 6f19c8ed..5e07fef8 100644 --- a/Kernel/Sources/FS/NewFS.cxx +++ b/Kernel/Sources/FS/NewFS.cxx @@ -73,11 +73,11 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, drv->fInput(&drv->fPacket); - kcout << "New OS: Next-Fork: " << hex_number(curFork.NextSibling) << endl; + kcout << "newoskrnl: Next-Fork: " << hex_number(curFork.NextSibling) << endl; if (curFork.Flags == kNewFSFlagCreated) { - kcout << "New OS: Fork already exists.\r"; + kcout << "newoskrnl: Fork already exists.\r"; /// sanity check. if (StringBuilder::Equals(curFork.ForkName, theFork.ForkName) && @@ -126,10 +126,10 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, drv->fOutput(&drv->fPacket); /// log what we have now. - kcout << "New OS: Wrote fork data at: " << hex_number(theFork.DataOffset) + kcout << "newoskrnl: Wrote fork data at: " << hex_number(theFork.DataOffset) << endl; - kcout << "New OS: Wrote fork at: " << hex_number(lba) << endl; + kcout << "newoskrnl: Wrote fork at: " << hex_number(lba) << endl; return &theFork; } @@ -372,9 +372,9 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, drive->fOutput(&drive->fPacket); - kcout << "New OS: Create new catalog, status: " + kcout << "newoskrnl: Create new catalog, status: " << hex_number(catalogChild->Flags) << endl; - kcout << "New OS: Create new catalog, status: " << catalogChild->Name + kcout << "newoskrnl: Create new catalog, status: " << catalogChild->Name << endl; drive->fPacket.fPacketContent = sectorBufPartBlock; @@ -449,7 +449,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) partBlock->Version = kNewFSVersionInteger; - const auto cUntitledHD = "New OS HD\0"; + const auto cUntitledHD = "newoskrnl HD\0"; rt_copy_memory((VoidPtr)kNewFSIdent, (VoidPtr)partBlock->Ident, kNewFSIdentLen); @@ -475,14 +475,14 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) drive->fOutput(&drive->fPacket); - kcout << "Drive-Kind: " << drive->fDriveKind() << endl; + kcout << "newoskrnl: drive kind: " << drive->fDriveKind() << endl; - kcout << "Partition-Name: " << partBlock->PartitionName << endl; - kcout << "Start-Catalog: " << hex_number(partBlock->StartCatalog) << endl; - kcout << "Catalog-Count: " << hex_number(partBlock->CatalogCount) << endl; - kcout << "Free-Catalog: " << hex_number(partBlock->FreeCatalog) << endl; - kcout << "Free-Sectors: " << hex_number(partBlock->FreeSectors) << endl; - kcout << "Sector-Size: " << hex_number(partBlock->SectorSize) << endl; + kcout << "newoskrnl: partition name: " << partBlock->PartitionName << endl; + kcout << "newoskrnl: start: " << hex_number(partBlock->StartCatalog) << endl; + kcout << "newoskrnl: number of catalogs: " << hex_number(partBlock->CatalogCount) << endl; + kcout << "newoskrnl: free catalog: " << hex_number(partBlock->FreeCatalog) << endl; + kcout << "newoskrnl: free sectors: " << hex_number(partBlock->FreeSectors) << endl; + kcout << "newoskrnl: sector size: " << hex_number(partBlock->SectorSize) << endl; /// write the root catalog. this->CreateCatalog(kNewFSRoot, 0, kNewFSCatalogKindDir); @@ -490,7 +490,7 @@ bool NewFSParser::Format(_Input _Output DriveTrait* drive) return true; } - kcout << "New OS: PartitionBlock already exists.\r"; + kcout << "newoskrnl: PartitionBlock already exists.\r"; /// return success as well, do not ignore that partition. return true; @@ -531,14 +531,14 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, drive->fInput(&drive->fPacket); - kcout << "Fork-Name: " << forkData->ForkName << endl; + kcout << "newoskrnl: forkName: " << forkData->ForkName << endl; /// sanity check the fork. if (forkData->DataOffset <= kNewFSCatalogStartAddress) { DbgLastError() = kErrorDiskIsCorrupted; - kcout << "New OS: Invalid fork offset.\r"; + kcout << "newoskrnl: Invalid fork offset.\r"; delete forkData; return false; @@ -552,7 +552,8 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, drive->fPacket.fPacketContent = data; drive->fPacket.fPacketSize = sizeOfData; drive->fPacket.fLba = forkData->DataOffset; - kcout << "Fork-Offset: " << hex_number(forkData->DataOffset) << endl; + + kcout << "newoskrnl: data offset: " << hex_number(forkData->DataOffset) << endl; drive->fOutput(&drive->fPacket); @@ -563,10 +564,12 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, catalog == nullptr) { delete catalog; + drive->fPacket.fPacketContent = data; drive->fPacket.fPacketSize = sizeOfData; drive->fPacket.fLba = forkData->DataOffset; - kcout << "Fork-Offset: " << hex_number(forkData->DataOffset) << endl; + + kcout << "newoskrnl: data offset: " << hex_number(forkData->DataOffset) << endl; drive->fOutput(&drive->fPacket); @@ -670,7 +673,7 @@ _NewFSSearchThroughCatalogList: NewCatalog* catalogPtr = new NewCatalog(); rt_copy_memory(catalog, catalogPtr, sizeof(NewCatalog)); - kcout << "New OS: Found catalog at: " << hex_number(startCatalogList) << endl; + kcout << "newoskrnl: found catalog at: " << hex_number(startCatalogList) << endl; outLba = startCatalogList; delete[] sectorBuf; @@ -809,8 +812,8 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, Lba dataForkLba = catalog->DataFork; Size dataForkSize = catalog->DataForkSize; - kcout << "Found-Catalog: " << catalog->Name - << ", Data-Fork: " << hex_number(dataForkLba) << endl; + kcout << "newoskrnl: catalog " << catalog->Name + << ", fork: " << hex_number(dataForkLba) << endl; Char* sectorBuf = new Char[sizeof(NewFork)]; auto drive = sMountpointInterface.GetAddressOf(this->fDriveIndex); @@ -830,7 +833,7 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, forkData = (NewFork*)sectorBuf; - kcout << "Fork-Name: " << forkData->ForkName << endl; + kcout << "newoskrnl: name: " << forkData->ForkName << endl; if (forkData->DataOffset <= kNewFSCatalogStartAddress) { @@ -930,11 +933,11 @@ namespace NewOS::Detail if (!StringBuilder::Equals(partBlock->Ident, kNewFSIdent)) { - kcout << "New OS: New FS Partition is corrupt.\r"; + kcout << "newoskrnl: New FS Partition is corrupt.\r"; return false; } - kcout << "New OS: Read partition: " << partBlock->PartitionName << ", with success!\r"; + kcout << "newoskrnl: Read partition: " << partBlock->PartitionName << ", with success!\r"; return true; } diff --git a/Kernel/Sources/IndexableProperty.cxx b/Kernel/Sources/IndexableProperty.cxx index 16694f52..6c773b9a 100644 --- a/Kernel/Sources/IndexableProperty.cxx +++ b/Kernel/Sources/IndexableProperty.cxx @@ -50,7 +50,7 @@ namespace NewOS indexer.AddFlag(kIndexerClaimed); rt_copy_memory((VoidPtr)indexer.LeakProperty().Path, (VoidPtr)filename, filenameLen); - kcout << "New OS: FSKit: index new file: " << filename << endl; + kcout << "newoskrnl: FSKit: index new file: " << filename << endl; } } } // namespace Indexer diff --git a/Kernel/Sources/KernelCheck.cxx b/Kernel/Sources/KernelCheck.cxx index b59417d4..6b355011 100644 --- a/Kernel/Sources/KernelCheck.cxx +++ b/Kernel/Sources/KernelCheck.cxx @@ -98,8 +98,8 @@ namespace NewOS if (!expr) { #ifdef __DEBUG__ - kcout << "New Kernel: File: " << file << "\r"; - kcout << "New Kernel: Line: " << line << "\r"; + kcout << "newoskrnl: File: " << file << "\r"; + kcout << "newoskrnl: Line: " << line << "\r"; #endif // __DEBUG__ diff --git a/Kernel/Sources/PEFSharedObject.cxx b/Kernel/Sources/PEFSharedObject.cxx new file mode 100644 index 00000000..06825a3c --- /dev/null +++ b/Kernel/Sources/PEFSharedObject.cxx @@ -0,0 +1,106 @@ +/* + * ======================================================== + * + * NewOS + * Copyright SoftwareLabs, all rights reserved. + * + * ======================================================== + */ + +#include +#include +#include +#include +#include +#include + +/* ------------------------------------------- + + Revision History: + + 01/02/24: Rework shared library ABI, except a rt_library_init and + rt_library_free (amlel) 15/02/24: Breaking changes, changed the name of the + routines. (amlel) + + ------------------------------------------- */ + +using namespace NewOS; + +/***********************************************************************************/ +/// @file SharedObjectRT.cxx +/// @brief Shared Object runtime. +/***********************************************************************************/ + +/***********************************************************************************/ +/* @brief Library runtime initializer. */ +/***********************************************************************************/ + +EXTERN_C SharedObjectPtr rt_library_init(void) +{ + SharedObjectPtr library = tls_new_class(); + + if (!library) + { + ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Mount(tls_new_class()); + + if (!library->Get()) + { + ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Get()->fImageObject = + ProcessScheduler::The().Leak().GetCurrent().Leak().Image; + + if (!library->Get()->fImageObject) + { + ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Get()->fImageEntrypointOffset = + library->Load(kPefStart, rt_string_len(kPefStart, 0), kPefCode); + + return library; +} + +/***********************************************************************************/ +/* @brief Ends the library. */ +/* @note Please check if the lib got freed! */ +/* @param SharedObjectPtr the library to free. */ +/***********************************************************************************/ + +EXTERN_C Void rt_library_free(SharedObjectPtr lib, bool* successful) +{ + MUST_PASS(successful); + + // sanity check (will also trigger a bug check if this fails) + if (lib == nullptr) + { + *successful = false; + ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + } + + delete lib->Get(); + delete lib; + + lib = nullptr; + + *successful = true; +} + +/***********************************************************************************/ + +/// @brief Unimplemented function (crashes by default) +/// @param +EXTERN_C void __mh_purecall(void) +{ + kcout << "newoskrnl: unimplemented symbol!\r"; +} diff --git a/Kernel/Sources/PEFSharedObjectRT.cxx b/Kernel/Sources/PEFSharedObjectRT.cxx deleted file mode 100644 index 3ddef245..00000000 --- a/Kernel/Sources/PEFSharedObjectRT.cxx +++ /dev/null @@ -1,107 +0,0 @@ -/* - * ======================================================== - * - * NewOS - * Copyright SoftwareLabs, all rights reserved. - * - * ======================================================== - */ - -#include -#include -#include -#include -#include -#include - -/* ------------------------------------------- - - Revision History: - - 01/02/24: Rework shared library ABI, except a rt_library_init and - rt_library_free (amlel) 15/02/24: Breaking changes, changed the name of the - routines. (amlel) - - ------------------------------------------- */ - -using namespace NewOS; - -/***********************************************************************************/ -/// @file SharedObjectRT.cxx -/// @brief Shared Object runtime. -/***********************************************************************************/ - -/***********************************************************************************/ -/* @brief Library runtime initializer. */ -/***********************************************************************************/ - -EXTERN_C SharedObjectPtr rt_library_init(void) -{ - SharedObjectPtr library = tls_new_class(); - - if (!library) - { - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); - - return nullptr; - } - - library->Mount(tls_new_class()); - - if (!library->Get()) - { - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); - - return nullptr; - } - - library->Get()->fImageObject = - ProcessScheduler::The().Leak().GetCurrent().Leak().Image; - - if (!library->Get()->fImageObject) - { - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); - - return nullptr; - } - - library->Get()->fImageEntrypointOffset = - library->Load(kPefStart, rt_string_len(kPefStart, 0), kPefCode); - - return library; -} - -/***********************************************************************************/ -/* @brief Ends the library. */ -/* @note Please check if the lib got freed! */ -/* @param SharedObjectPtr the library to free. */ -/***********************************************************************************/ - -EXTERN_C Void rt_library_free(SharedObjectPtr lib, bool* successful) -{ - MUST_PASS(successful); - - // sanity check (will also trigger a bug check if this fails) - if (lib == nullptr) - { - *successful = false; - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); - } - - delete lib->Get(); - delete lib; - - lib = nullptr; - - *successful = true; -} - -/***********************************************************************************/ - -/// @brief Unimplemented function (crashes by default) -/// @param -EXTERN_C void __mh_purecall(void) -{ - ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); - return; -} diff --git a/Kernel/Sources/ThreadLocalStorage.cxx b/Kernel/Sources/ThreadLocalStorage.cxx index 00305006..f72bab67 100644 --- a/Kernel/Sources/ThreadLocalStorage.cxx +++ b/Kernel/Sources/ThreadLocalStorage.cxx @@ -33,7 +33,7 @@ Boolean tls_check_tib(ThreadInformationBlock* tib) Encoder encoder; const char* tibAsBytes = encoder.AsBytes(tib); - kcout << "New OS: Checking for a valid cookie...\r"; + kcout << "newoskrnl: Checking for a valid cookie...\r"; return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 && tibAsBytes[2] == kCookieMag2; @@ -50,9 +50,9 @@ EXTERN_C Void tls_check_syscall_impl(NewOS::HAL::StackFramePtr stackPtr) noexcep if (!tls_check_tib(tib)) { - kcout << "New OS: Verification failed, Crashing...\r"; + kcout << "newoskrnl: Verification failed, Crashing...\r"; ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); } - kcout << "New OS: Verification succeeded! Keeping on...\r"; + kcout << "newoskrnl: Verification succeeded! Keeping on...\r"; } diff --git a/Kernel/makefile b/Kernel/makefile index 14bd1cae..c550956a 100644 --- a/Kernel/makefile +++ b/Kernel/makefile @@ -37,7 +37,7 @@ LDFLAGS = -e __ImageStart --subsystem=17 LDOBJ = Objects/*.obj # This file is the kernel, responsible of task management and memory. -KERNEL = NewOSKrnl.exe +KERNEL = newoskrnl.exe .PHONY: error error: -- cgit v1.2.3